# kdeprint Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kprinterpropertydialog.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 "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 <kmessagebox.h>
    00029 #include <qtabwidget.h>
    00030 #include <klocale.h>
    00031 #include <kpushbutton.h>
    00032 #include <kguiitem.h>
    00033
    00034 KPrinterPropertyDialog::KPrinterPropertyDialog(KMPrinter *p, QWidget *parent, const char *name)
    00035 : KDialogBase(parent, name, true, QString::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 QTabWidget(this);
    00042     m_tw->setMargin(10);
    00043     connect(m_tw,SIGNAL(currentChanged(QWidget*)),SLOT(slotCurrentChanged(QWidget*)));
    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(QWidget *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     QString msg;
    00072     QPtrListIterator<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 QMap<QString,QString>& opts)
    00086 {
    00087     // merge the 2 options sets
    00088     for (QMap<QString,QString>::ConstIterator it=opts.begin(); it!=opts.end(); ++it)
    00089         m_options[it.key()] = it.data();
    00090     // update all existing pages
    00091     QPtrListIterator<KPrintDialogPage>  it(m_pages);
    00092     for (; it.current(); ++it)
    00093         it.current()->setOptions(m_options);
    00094 }
    00095
    00096 void KPrinterPropertyDialog::getOptions(QMap<QString,QString>& opts, bool incldef)
    00097 {
    00098     collectOptions(opts, incldef);
    00099 }
    00100
    00101 void KPrinterPropertyDialog::collectOptions(QMap<QString,QString>& opts, bool incldef)
    00102 {
    00103     QPtrListIterator<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         QMap<QString,QString>   opts;
    00120         collectOptions(opts, false);
    00121         m_printer->setDefaultOptions(opts);
    00122         m_printer->setEditedOptions(QMap<QString,QString>());
    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, QWidget *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         QMap<QString,QString>   opts;
    00142         dlg.collectOptions(opts, false);
    00143         pr->setEditedOptions(opts);
    00144         pr->setEdited(true);
    00145     }
    00146 }
    00147 #include "kprinterpropertydialog.moc"

This file is part of the documentation for kdeprint Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:04 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003