| # kdeprint Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kmwizard.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 "kmwizard.h"
    00021 #include "kmwizardpage.h"
    00022 #include "kmprinter.h"
    00023 #include "kmfactory.h"
    00024 #include "kmuimanager.h"
    00025
    00026 #include <kpushbutton.h>
    00027 #include <qlabel.h>
    00028 #include <qwidgetstack.h>
    00029 #include <kmessagebox.h>
    00030 #include <qlayout.h>
    00031 #include <klocale.h>
    00032 #include <kdebug.h>
    00033 #include <kseparator.h>
    00034 #include <kapplication.h>
    00035 #include <kstdguiitem.h>
    00036
    00037 #include "kmwinfopage.h"
    00038 #include "kmwpassword.h"
    00039 #include "kmwbackend.h"
    00040 #include "kmwsocket.h"
    00041 #include "kmwdriver.h"
    00042 #include "kmwdriverselect.h"
    00043 #include "kmwdrivertest.h"
    00044 #include "kmwname.h"
    00045 #include "kmwend.h"
    00046 #include "kmwclass.h"
    00047 #include "kmwlpd.h"
    00048 #include "kmwfile.h"
    00049 #include "kmwsmb.h"
    00050 #include "kmwlocal.h"
    00051 #include "sidepixmap.h"
    00052
    00053 KMWizard::KMWizard(QWidget *parent, const char *name)
    00054 : QDialog(parent,name,true)
    00055 {
    00056     m_start = KMWizard::Start;
    00057     m_end = KMWizard::End;
    00058     m_inclusive = true;
    00059     m_printer = new KMPrinter();
    00060
    00061     m_pagepool.setAutoDelete(false);
    00062
    00063     m_stack = new QWidgetStack(this);
    00064     m_next = new KPushButton(i18n("&Next >"), this);
    00065     m_next->setDefault(true);
    00066     m_prev = new KPushButton(i18n("< &Back"), this);
    00067     QPushButton *m_cancel = new KPushButton(KStdGuiItem::cancel(), this);
    00068     m_title = new QLabel(this);
    00069     QFont   f(m_title->font());
    00070     f.setBold(true);
    00071     m_title->setFont(f);
    00072     KSeparator* sep = new KSeparator( KSeparator::HLine, this);
    00073     sep->setFixedHeight(5);
    00074     KSeparator* sep2 = new KSeparator( KSeparator::HLine, this);
    00075     QPushButton *m_help = new KPushButton(KStdGuiItem::help(), this);
    00076
    00077     connect(m_cancel,SIGNAL(clicked()),SLOT(reject()));
    00078     connect(m_next,SIGNAL(clicked()),SLOT(slotNext()));
    00079     connect(m_prev,SIGNAL(clicked()),SLOT(slotPrev()));
    00080     connect(m_help, SIGNAL(clicked()), SLOT(slotHelp()));
    00081
    00082     m_side = new SidePixmap(this);
    00083     if (!m_side->isValid())
    00084     {
    00085         delete m_side;
    00086         m_side = 0;
    00087     }
    00088
    00089     // layout
    00090     QVBoxLayout *main0_ = new QVBoxLayout(this, 10, 10);
    00091     QVBoxLayout *main_ = new QVBoxLayout(0, 0, 0);
    00092     QHBoxLayout *main1_ = new QHBoxLayout(0, 0, 10);
    00093     QHBoxLayout *btn_ = new QHBoxLayout(0, 0, 10);
    00094     main0_->addLayout(main1_);
    00095     if (m_side)
    00096         main1_->addWidget(m_side);
    00097     main1_->addLayout(main_);
    00098     main_->addWidget(m_title);
    00099     main_->addWidget(sep);
    00100     main_->addSpacing(10);
    00101     main_->addWidget(m_stack,1);
    00102     main0_->addWidget(sep2);
    00103     main0_->addLayout(btn_);
    00104     btn_->addWidget(m_help);
    00105     btn_->addStretch(1);
    00106     btn_->addWidget(m_prev);
    00107     btn_->addWidget(m_next);
    00108     btn_->addWidget(m_cancel);
    00109
    00110     // create standard pages
    00111     addPage(new KMWInfoPage(this));
    00112     m_backend = new KMWBackend(this);
    00113     addPage(m_backend);
    00114     addPage(new KMWPassword(this));
    00115     addPage(new KMWSocket(this));
    00116     addPage(new KMWDriver(this));
    00117     addPage(new KMWDriverSelect(this));
    00118     addPage(new KMWDriverTest(this));
    00119     addPage(new KMWName(this));
    00120     addPage(new KMWEnd(this));
    00121     addPage(new KMWClass(this));
    00122     addPage(new KMWLpd(this));
    00123     addPage(new KMWFile(this));
    00124     addPage(new KMWSmb(this));
    00125     addPage(new KMWLocal(this));
    00126
    00127     // add other pages
    00128     KMFactory::self()->uiManager()->setupWizard(this);
    00129
    00130     setCurrentPage(m_start,false);
    00131     setCaption(i18n("Add Printer Wizard"));
    00132     resize(400,350);
    00133 }
    00134
    00135 KMWizard::~KMWizard()
    00136 {
    00137     delete m_printer;
    00138 }
    00139
    00140 void KMWizard::addPage(KMWizardPage *page)
    00141 {
    00142     m_stack->addWidget(page,page->id());
    00143     m_pagepool.insert(page->id(),page);
    00144 }
    00145
    00146 void KMWizard::setPrinter(KMPrinter *p)
    00147 {
    00148     if (p)
    00149     {
    00150         m_printer->copy(*p);
    00151         KMWizardPage    *page = (KMWizardPage*)m_stack->visibleWidget();
    00152         if (page)
    00153             page->initPrinter(m_printer);
    00154     }
    00155 }
    00156
    00157 void KMWizard::configure(int start, int end, bool inclusive)
    00158 {
    00159     m_start = start;
    00160     m_end = end;
    00161     m_inclusive = inclusive;
    00162     m_pagestack.clear();
    00163
    00164     // disable class if not starting from beginning
    00165     m_backend->enableBackend(KMWizard::Class,(m_start == KMWizard::Start));
    00166     setCaption((m_start == KMWizard::Start ? i18n("Add Printer Wizard") : i18n("Modify Printer")));
    00167
    00168     if (m_side)
    00169     {
    00170         if (start == KMWizard::Start && end == KMWizard::End)
    00171             m_side->show();
    00172         else
    00173             m_side->hide();
    00174     }
    00175
    00176     setCurrentPage(m_start,false);
    00177 }
    00178
    00179 void KMWizard::setNextPage(int page, int next)
    00180 {
    00181     KMWizardPage    *p = m_pagepool.find(page);
    00182     if (p)
    00183         p->setNextPage(next);
    00184 }
    00185
    00186 void KMWizard::setCurrentPage(int ID, bool back)
    00187 {
    00188     KMWizardPage    *page = m_pagepool.find(ID);
    00189     if (!page)
    00190     {
    00191         KMessageBox::error(this,i18n("Unable to find the requested page."),i18n("Add Printer Wizard"));
    00192         return;
    00193     }
    00194
    00195     // add current page to stack (only if going backward)
    00196     if (!back) m_pagestack.push(ID);
    00197
    00198     // raise page + initialize
    00199     m_stack->raiseWidget(page);
    00200     m_title->setText(page->title());
    00201     if (!back) page->initPrinter(m_printer);
    00202
    00203     // update buttons
    00204     if (ID == m_start) m_prev->setEnabled(false);
    00205     else m_prev->setEnabled(true);
    00206     if ((m_inclusive && ID == m_end) || (!m_inclusive && page->nextPage() == m_end))
    00207         m_next->setText(i18n("&Finish"));
    00208     else
    00209         m_next->setText(i18n("&Next >"));
    00210 }
    00211
    00212 void KMWizard::slotPrev()
    00213 {
    00214     // current page is on top of stack -> pop it and retrieve new top of stack
    00215     m_pagestack.pop();
    00216     int ID = m_pagestack.top();
    00217     setCurrentPage(ID,true);
    00218 }
    00219
    00220 void KMWizard::slotNext()
    00221 {
    00222     KMWizardPage    *page = (KMWizardPage*)m_stack->visibleWidget();
    00223     if (page)
    00224     {
    00225         QString msg;
    00226         if (!page->isValid(msg))
    00227         {
    00228             if (!msg.isEmpty())
    00229                 KMessageBox::error(this,msg.prepend("<qt>").append("</qt>"),page->title());
    00230         }
    00231         else
    00232         {
    00233             page->updatePrinter(m_printer);
    00234             if (m_next->text() == i18n("&Finish"))
    00235                 accept();
    00236             else
    00237             {
    00238                 int ID = page->nextPage();
    00239                 setCurrentPage(ID,false);
    00240             }
    00241         }
    00242     }
    00243 }
    00244
    00245 void KMWizard::slotHelp()
    00246 {
    00247     kapp->invokeHelp(QString::null, "kdeprint");
    00248 }
    00249
    00250 void KMWizard::enableWizard()
    00251 {
    00252     m_next->setEnabled( true );
    00253     m_prev->setEnabled( m_pagestack.top() != m_start );
    00254 }
    00255
    00256 void KMWizard::disableWizard()
    00257 {
    00258     m_next->setEnabled( false );
    00259     m_prev->setEnabled( false );
    00260 }
    00261
    00262 #include "kmwizard.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:03 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003