00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kprintaction.h"
00021
00022 #include <kprinter.h>
00023 #include <kdeprint/kmmanager.h>
00024 #include <kiconloader.h>
00025 #include <kpopupmenu.h>
00026 #include <klocale.h>
00027
00028 class KPrintAction::KPrintActionPrivate
00029 {
00030 public:
00031 KPrintActionPrivate()
00032 {
00033 type = All;
00034 parentWidget = 0;
00035 }
00036
00037 PrinterType type;
00038 QStringList printers;
00039 QWidget *parentWidget;
00040 };
00041
00042 KPrintAction::KPrintAction(const QString& text, PrinterType type, QWidget *parentWidget, QObject *parent, const char *name)
00043 : KActionMenu(text, parent, name)
00044 {
00045 d = new KPrintActionPrivate();
00046 initialize(type, parentWidget);
00047 }
00048
00049 KPrintAction::KPrintAction(const QString& text, const QIconSet& icon, PrinterType type, QWidget *parentWidget, QObject *parent, const char *name)
00050 : KActionMenu(text, icon, parent, name)
00051 {
00052 d = new KPrintActionPrivate();
00053 initialize(type, parentWidget);
00054 }
00055
00056 KPrintAction::KPrintAction(const QString& text, const QString& icon, PrinterType type, QWidget *parentWidget, QObject *parent, const char *name)
00057 : KActionMenu(text, icon, parent, name)
00058 {
00059 d = new KPrintActionPrivate();
00060 initialize(type, parentWidget);
00061 }
00062
00063 KPrintAction::~KPrintAction()
00064 {
00065 delete d;
00066 }
00067
00068 void KPrintAction::initialize(PrinterType type, QWidget *parentWidget)
00069 {
00070 connect(popupMenu(), SIGNAL(aboutToShow()), SLOT(slotAboutToShow()));
00071 connect(popupMenu(), SIGNAL(activated(int)), SLOT(slotActivated(int)));
00072
00073 d->type = type;
00074 d->parentWidget = parentWidget;
00075 }
00076
00077 void KPrintAction::slotAboutToShow()
00078 {
00079 popupMenu()->clear();
00080 d->printers.clear();
00081 QPtrList<KMPrinter> *prts = KMManager::self()->printerList();
00082 if (prts && !prts->isEmpty())
00083 {
00084 QPtrListIterator<KMPrinter> it(*prts);
00085 bool first(false);
00086 int ID(0);
00087 for (; it.current(); ++it)
00088 {
00089 if (d->type == All || (d->type == Specials && it.current()->isSpecial()) || (d->type == Regular && !it.current()->isSpecial()))
00090 {
00091 if (d->type == All && !first && it.current()->isSpecial())
00092 {
00093 if (popupMenu()->count() > 0)
00094 popupMenu()->insertSeparator();
00095 first = true;
00096 }
00097 popupMenu()->insertItem(SmallIconSet(it.current()->pixmap()), it.current()->name(), ID++);
00098 d->printers.append(it.current()->name());
00099 }
00100 }
00101 }
00102 }
00103
00104 void KPrintAction::slotActivated(int ID)
00105 {
00106 KPrinter printer(false);
00107 KMPrinter *mprt = KMManager::self()->findPrinter(d->printers[ID]);
00108 if (mprt && mprt->autoConfigure(&printer, d->parentWidget))
00109 {
00110
00111 emit print(&printer);
00112 }
00113 }
00114
00115 KPrintAction* KPrintAction::exportAll(QWidget *parentWidget, QObject *parent, const char *name)
00116 {
00117 return new KPrintAction(i18n("&Export..."), All, parentWidget, parent, (name ? name : "export_all"));
00118 }
00119
00120 KPrintAction* KPrintAction::exportRegular(QWidget *parentWidget, QObject *parent, const char *name)
00121 {
00122 return new KPrintAction(i18n("&Export..."), Regular, parentWidget, parent, (name ? name : "export_regular"));
00123 }
00124
00125 KPrintAction* KPrintAction::exportSpecial(QWidget *parentWidget, QObject *parent, const char *name)
00126 {
00127 return new KPrintAction(i18n("&Export..."), Specials, parentWidget, parent, (name ? name : "export_special"));
00128 }
00129
00130 #include "kprintaction.moc"