kdeprint Library API Documentation

kprintaction.cpp

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License version 2 as published by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 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 // emit the signal 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"
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:41:52 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003