From e3de9e782e868d0e4a44bd970c6b4c51acc9eee7 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 18 Apr 2008 10:45:48 +0000 Subject: [PATCH] Correction for exception about Crash on print functionality on in not corrected situation. --- src/Plot2d/Plot2d_ViewWindow.cxx | 12 ++++++++++++ src/Qtx/Qtx.cxx | 32 +++++++++++++++++++++++++++++++ src/Qtx/Qtx.h | 2 ++ src/SUIT/SUIT_ViewWindow.cxx | 12 ++++++++++++ src/SUIT/resources/SUIT_msg_en.ts | 4 ++++ 5 files changed, 62 insertions(+) diff --git a/src/Plot2d/Plot2d_ViewWindow.cxx b/src/Plot2d/Plot2d_ViewWindow.cxx index 82e49719e..2d8f3d9df 100755 --- a/src/Plot2d/Plot2d_ViewWindow.cxx +++ b/src/Plot2d/Plot2d_ViewWindow.cxx @@ -27,7 +27,9 @@ #include #include #include +#include +#include #include #include @@ -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; diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index 38f85882e..a5d77d034 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -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 +#include + +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; +} diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index e13edd281..c8c4f41d6 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -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 diff --git a/src/SUIT/SUIT_ViewWindow.cxx b/src/SUIT/SUIT_ViewWindow.cxx index e26b6f143..9cde13e92 100755 --- a/src/SUIT/SUIT_ViewWindow.cxx +++ b/src/SUIT/SUIT_ViewWindow.cxx @@ -28,6 +28,8 @@ #include "SUIT_Application.h" #include "SUIT_ViewManager.h" +#include "Qtx.h" + #include #include #include @@ -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; diff --git a/src/SUIT/resources/SUIT_msg_en.ts b/src/SUIT/resources/SUIT_msg_en.ts index 466cbaf44..d698ea092 100644 --- a/src/SUIT/resources/SUIT_msg_en.ts +++ b/src/SUIT/resources/SUIT_msg_en.ts @@ -96,6 +96,10 @@ Do you want to overwrite it? NAME_COLUMN Name + + WRN_NO_PRINTERS + You have no printers. + SUIT_Study -- 2.39.2