• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

kprinterpropertydialog.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <tdeprint@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., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include "kprinterpropertydialog.h"
00021 #include "kprintdialogpage.h"
00022 #include "kmfactory.h"
00023 #include "kmuimanager.h"
00024 #include "kmvirtualmanager.h"
00025 #include "kmprinter.h"
00026 #include "driver.h"
00027 
00028 #include <tdemessagebox.h>
00029 #include <tqtabwidget.h>
00030 #include <tdelocale.h>
00031 #include <kpushbutton.h>
00032 #include <kguiitem.h>
00033 
00034 KPrinterPropertyDialog::KPrinterPropertyDialog(KMPrinter *p, TQWidget *parent, const char *name)
00035 : KDialogBase(parent, name, true, TQString::null, KDialogBase::Ok|KDialogBase::Cancel|KDialogBase::User1, KDialogBase::Ok, false, KStdGuiItem::save()),
00036   m_printer(p), m_driver(0), m_current(0)
00037 {
00038     m_pages.setAutoDelete(false);
00039 
00040     // set a margin
00041     m_tw = new TQTabWidget(this);
00042     m_tw->setMargin(10);
00043     connect(m_tw,TQT_SIGNAL(currentChanged(TQWidget*)),TQT_SLOT(slotCurrentChanged(TQWidget*)));
00044     setMainWidget(m_tw);
00045 
00046     if (m_printer)
00047         m_options = (m_printer->isEdited() ? m_printer->editedOptions() : m_printer->defaultOptions());
00048 }
00049 
00050 KPrinterPropertyDialog::~KPrinterPropertyDialog()
00051 {
00052     delete m_driver;
00053 }
00054 
00055 void KPrinterPropertyDialog::slotCurrentChanged(TQWidget *w)
00056 {
00057     if (m_current) m_current->getOptions(m_options,true);
00058     m_current = (KPrintDialogPage*)w;
00059     if (m_current) m_current->setOptions(m_options);
00060 }
00061 
00062 void KPrinterPropertyDialog::addPage(KPrintDialogPage *page)
00063 {
00064     m_tw->addTab(page,page->title());
00065     m_pages.append(page);
00066 }
00067 
00068 bool KPrinterPropertyDialog::synchronize()
00069 {
00070     if (m_current) m_current->getOptions(m_options,true);
00071     TQString    msg;
00072     TQPtrListIterator<KPrintDialogPage> it(m_pages);
00073     for (;it.current();++it)
00074     {
00075         it.current()->setOptions(m_options);
00076         if (!it.current()->isValid(msg))
00077         {
00078             KMessageBox::error(this, msg.prepend("<qt>").append("</qt>"), i18n("Printer Configuration"));
00079             return false;
00080         }
00081     }
00082     return true;
00083 }
00084 
00085 void KPrinterPropertyDialog::setOptions(const TQMap<TQString,TQString>& opts)
00086 {
00087     // merge the 2 options sets
00088     for (TQMap<TQString,TQString>::ConstIterator it=opts.begin(); it!=opts.end(); ++it)
00089         m_options[it.key()] = it.data();
00090     // update all existing pages
00091     TQPtrListIterator<KPrintDialogPage> it(m_pages);
00092     for (; it.current(); ++it)
00093         it.current()->setOptions(m_options);
00094 }
00095 
00096 void KPrinterPropertyDialog::getOptions(TQMap<TQString,TQString>& opts, bool incldef)
00097 {
00098     collectOptions(opts, incldef);
00099 }
00100 
00101 void KPrinterPropertyDialog::collectOptions(TQMap<TQString,TQString>& opts, bool incldef)
00102 {
00103     TQPtrListIterator<KPrintDialogPage> it(m_pages);
00104     for (;it.current();++it)
00105         it.current()->getOptions(opts,incldef);
00106 }
00107 
00108 void KPrinterPropertyDialog::slotOk()
00109 {
00110     if (!synchronize())
00111         return;
00112     KDialogBase::slotOk();
00113 }
00114 
00115 void KPrinterPropertyDialog::slotUser1()
00116 {
00117     if (m_printer && synchronize())
00118     {
00119         TQMap<TQString,TQString>    opts;
00120         collectOptions(opts, false);
00121         m_printer->setDefaultOptions(opts);
00122         m_printer->setEditedOptions(TQMap<TQString,TQString>());
00123         m_printer->setEdited(false);
00124         KMFactory::self()->virtualManager()->triggerSave();
00125     }
00126 }
00127 
00128 void KPrinterPropertyDialog::enableSaveButton(bool state)
00129 {
00130     showButton(KDialogBase::User1, state);
00131 }
00132 
00133 void KPrinterPropertyDialog::setupPrinter(KMPrinter *pr, TQWidget *parent)
00134 {
00135     KPrinterPropertyDialog  dlg(pr,parent,"PropertyDialog");
00136     KMFactory::self()->uiManager()->setupPropertyDialog(&dlg);
00137     if (dlg.m_pages.count() == 0)
00138         KMessageBox::information(parent,i18n("No configurable options for that printer."),i18n("Printer Configuration"));
00139     else if (dlg.exec())
00140     {
00141         TQMap<TQString,TQString>    opts;
00142         dlg.collectOptions(opts, false);
00143         pr->setEditedOptions(opts);
00144         pr->setEdited(true);
00145     }
00146 }
00147 #include "kprinterpropertydialog.moc"

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.7.1
This website is maintained by Timothy Pearson.