]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Correction for exception about Crash on print functionality on in not corrected situa...
authornds <nds@opencascade.com>
Fri, 18 Apr 2008 10:45:48 +0000 (10:45 +0000)
committernds <nds@opencascade.com>
Fri, 18 Apr 2008 10:45:48 +0000 (10:45 +0000)
src/Plot2d/Plot2d_ViewWindow.cxx
src/Qtx/Qtx.cxx
src/Qtx/Qtx.h
src/SUIT/SUIT_ViewWindow.cxx
src/SUIT/resources/SUIT_msg_en.ts

index 82e49719e599bdc24141c4bfdb467416fc3e5f27..2d8f3d9dfac115101cb1efd8780b308f0dd29303 100755 (executable)
@@ -27,7 +27,9 @@
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_Session.h>
 #include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
 
+#include <Qtx.h>
 #include <QtxAction.h>
 #include <QtxMultiAction.h>
 
@@ -635,6 +637,16 @@ void Plot2d_ViewWindow::onPrintView()
   if ( !myViewFrame )
     return;
 
+#ifndef WIN32
+#if QT_VERSION < 0x040303
+  if ( !Qtx::hasAnyPrinters() ) {
+    SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
+                              tr( "WRN_NO_PRINTERS" ) );
+    return;
+  }
+#endif
+#endif
+
   // stored settings for further starts
   static QString aPrinterName;
   static int aColorMode = -1;
index 38f85882e8bad9daa1d977d67fe1d8b9e07c23e9..a5d77d03430c74d31be556f6a4e29cc8c3414b78 100755 (executable)
@@ -1258,3 +1258,35 @@ bool Qtx::stringToConicalGradient( const QString& str, QConicalGradient& gradien
   }
   return success;
 }
+
+/**
+ * Cheque for existing any system printers
+ */
+
+#ifndef WIN32
+#if QT_VERSION < 0x040303
+#include <QLibrary>
+#include <cups/cups.h>
+
+typedef int (*CupsGetDests)(cups_dest_t **dests);
+static CupsGetDests _cupsGetDests = 0;
+#endif
+#endif
+bool Qtx::hasAnyPrinters()
+{
+  bool aRes = true;
+#ifndef WIN32
+#if QT_VERSION < 0x040303
+  QLibrary aCupsLib( QString( "cups" ) );
+  if ( !aCupsLib.load() )
+    aRes = false;
+  else {
+    cups_dest_t *printers;
+    _cupsGetDests = (CupsGetDests) aCupsLib.resolve("cupsGetDests");
+    int prnCount = _cupsGetDests(&printers);
+    aRes = prnCount > 0;
+  }
+#endif
+#endif
+  return aRes;
+}
index e13edd2814604fef689c0e4ebfb4cfea64cee8df..c8c4f41d635d95d1e9ae822cf06318b6b3dfeb3e 100755 (executable)
@@ -148,6 +148,8 @@ public:
   static bool        stringToLinearGradient( const QString&, QLinearGradient& );
   static bool        stringToRadialGradient( const QString&, QRadialGradient& );
   static bool        stringToConicalGradient( const QString&, QConicalGradient& );
+
+  static bool        hasAnyPrinters();
 };
 
 #endif
index e26b6f143b0fd990980c2453a58c07643b7fe0b8..9cde13e929393773ff29747b8debb965c678bc5e 100755 (executable)
@@ -28,6 +28,8 @@
 #include "SUIT_Application.h"
 #include "SUIT_ViewManager.h"
 
+#include "Qtx.h"
+
 #include <QEvent>
 #include <QIcon>
 #include <QApplication>
@@ -227,6 +229,16 @@ void SUIT_ViewWindow::printImage( const QImage& theImage, QWidget* theWidget )
   if ( theImage.isNull() )
     return;
 
+#ifndef WIN32
+#if QT_VERSION < 0x040303
+  if ( !Qtx::hasAnyPrinters() ) {
+    SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
+                              tr( "WRN_NO_PRINTERS" ) );
+    return;
+  }
+#endif
+#endif
+
   // stored settings for further starts
   static QString aPrinterName;
   static int anOrientation = -1;
index 466cbaf44fe7b0f59a83497053dd3bb7b760e5e3..d698ea092e92f759794a309e187c25e17762c40c 100644 (file)
@@ -96,6 +96,10 @@ Do you want to overwrite it?</translation>
         <source>NAME_COLUMN</source>
         <translation>Name</translation>
     </message>
+    <message>
+        <source>WRN_NO_PRINTERS</source>
+        <translation>You have no printers.</translation>
+    </message>
 </context>
 <context>
     <name>SUIT_Study</name>