kaddressbook Library API Documentation

printingwizard.cpp

00001 /* -*- C++ -*-
00002    This file implements the printing wizard.
00003 
00004    the KDE addressbook
00005 
00006    $ Author: Mirko Boehm $
00007    $ Copyright: (C) 1996-2002, Mirko Boehm $
00008    $ Contact: mirko@kde.org
00009          http://www.kde.org $
00010    $ License: LGPL with the following explicit clarification:
00011          This code may be linked against any version of the Qt toolkit
00012          from Troll Tech, Norway. $
00013 
00014    $Revision: 1.9 $
00015 */
00016 
00017 #include <qradiobutton.h>
00018 #include <qcombobox.h>
00019 #include <qlayout.h>
00020 #include <qpixmap.h>
00021 #include <qlabel.h>
00022 #include <qpushbutton.h>
00023 
00024 #include <kdebug.h>
00025 #include <kprinter.h>
00026 #include <klocale.h>
00027 #include <kdialog.h>
00028 #include <kdialogbase.h>
00029 #include <kapplication.h>
00030 
00031 #include "printingwizard.h"
00032 #include "printstyle.h"
00033 #include "printprogress.h"
00034 #include "detailledstyle.h"
00035 #include "mikesstyle.h"
00036 
00037 namespace KABPrinting {
00038 
00039     PrintingWizardImpl::PrintingWizardImpl(KPrinter *printer,
00040                                            KABC::AddressBook* doc,
00041                                            const QStringList& selection,
00042                                            QWidget *parent,
00043                                            const char* name)
00044         : PrintingWizard(printer, doc, selection, parent, name),
00045           style(0)
00046     {
00047         mBasicPage=new BasicPage(this);
00048         mBasicPage->rbSelection->setEnabled(!selection.isEmpty());
00049         connect(mBasicPage->cbStyle, SIGNAL(activated(int)),
00050                 SLOT(slotStyleSelected(int)));
00051         insertPage(mBasicPage, i18n("General"), -1);
00052         setAppropriate(mBasicPage, true);
00053         registerStyles();
00054         if(mBasicPage->cbStyle->count()>0)
00055         {
00056             slotStyleSelected(0);
00057         }
00058     }
00059 
00060     PrintingWizardImpl::~PrintingWizardImpl()
00061     {
00062     }
00063 
00064     void PrintingWizardImpl::accept()
00065     {
00066         print();
00067         close();
00068     }
00069 
00070     void PrintingWizardImpl::registerStyles()
00071     {
00072         styleFactories.append(new DetailledPrintStyleFactory(this));
00073         styleFactories.append(new MikesStyleFactory(this));
00074 
00075         mBasicPage->cbStyle->clear();
00076         for(unsigned int i=0; i<styleFactories.count(); ++i)
00077         {
00078             mBasicPage->cbStyle->insertItem(styleFactories.at(i)->description());
00079         }
00080     }
00081 
00082     void PrintingWizardImpl::slotStyleSelected( int index )
00083     {
00084       if ( index < 0 || (unsigned)index >= styleFactories.count() )
00085         return;
00086 
00087       setFinishEnabled( mBasicPage, false );
00088 
00089       if ( style )
00090         style->hidePages();
00091 
00092       if ( mStyleList.at( index ) != 0 )
00093         style = mStyleList.at( index );
00094       else {
00095         PrintStyleFactory *factory = styleFactories.at( index );
00096         kdDebug() << "PrintingWizardImpl::slotStyleSelected: "
00097                   << "creating print style "
00098                   << factory->description() << endl;
00099         style = factory->create();
00100         mStyleList.insert( index, style );
00101       }
00102 
00103       style->showPages();
00104 
00105       const QPixmap& preview = style->preview();
00106       mBasicPage->plPreview->setPixmap( preview );
00107       if ( preview.isNull() )
00108         mBasicPage->plPreview->setText( i18n( "(No preview available.)" ) );
00109 
00110       setFinishEnabled( page( pageCount() - 1 ), true );
00111     }
00112 
00113     KABC::AddressBook* PrintingWizardImpl::document()
00114     {
00115         return mDocument;
00116     }
00117 
00118     KPrinter* PrintingWizardImpl::printer()
00119     {
00120         return mPrinter;
00121     }
00122 
00123     void PrintingWizardImpl::print()
00124     {
00125         // ----- create and show print progress widget:
00126         PrintProgress *progress=new PrintProgress(this);
00127         insertPage(progress, i18n("Print Progress"), -1);
00128         showPage(progress);
00129         kapp->processEvents();
00130         // ----- prepare list of contacts to print:
00131         QStringList contacts;
00132         if(style!=0)
00133         {
00134             if(mBasicPage->rbSelection->isChecked())
00135             {
00136                 contacts=mSelection;
00137             } else {
00138                 // create a string list of all entries:
00139                 KABC::AddressBook::Iterator iter;
00140                 for(iter=document()->begin(); iter!=document()->end(); ++iter)
00141                 {
00142                     contacts << (*iter).uid();
00143                 }
00144             }
00145         }
00146         kdDebug() << "PrintingWizardImpl::print: printing "
00147                   << contacts.count() << " contacts." << endl;
00148         // ... print:
00149         setBackEnabled(progress, false);
00150         cancelButton()->setEnabled(false);
00151         style->print(contacts, progress);
00152         // ----- done - all GUI elements will disappear
00153     }
00154 
00155 }
00156 
00157 #include "printingwizard.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:10 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001