kaddressbook Library API Documentation

printingwizard.cpp

00001 /*                                                                      
00002     This file is part of KAddressBook.
00003     Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org>
00004                             Tobias Koenig <tokoe@kde.org>
00005                                                                         
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or   
00009     (at your option) any later version.                                 
00010                                                                         
00011     This program is distributed in the hope that it will be useful,     
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of      
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the        
00014     GNU General Public License for more details.                        
00015                                                                         
00016     You should have received a copy of the GNU General Public License   
00017     along with this program; if not, write to the Free Software         
00018     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           
00019                                                                         
00020     As a special exception, permission is given to link this program    
00021     with any edition of Qt, and distribute the resulting executable,    
00022     without including the source code for Qt in the source distribution.
00023 */                                                                      
00024 
00025 #include <qcombobox.h>
00026 #include <qheader.h>
00027 #include <qlabel.h>
00028 #include <qlayout.h>
00029 #include <qlistview.h>
00030 #include <qpixmap.h>
00031 #include <qpushbutton.h>
00032 #include <qradiobutton.h>
00033 
00034 #include <kabc/addresseelist.h>
00035 #include <kapplication.h>
00036 #include <kdebug.h>
00037 #include <kdialog.h>
00038 #include <kdialogbase.h>
00039 #include <klocale.h>
00040 #include <kprinter.h>
00041 
00042 // including the styles
00043 #include "detailledstyle.h"
00044 #include "mikesstyle.h"
00045 #include "ringbinderstyle.h"
00046 
00047 #include "../kabprefs.h"
00048 #include "printprogress.h"
00049 #include "printstyle.h"
00050 
00051 #include "printingwizard.h"
00052 
00053 using namespace KABPrinting;
00054 
00055 PrintingWizard::PrintingWizard( KPrinter *printer, KABC::AddressBook* ab,
00056                                 const QStringList& selection, QWidget *parent,
00057                                 const char* name )
00058   : KWizard( parent, name ), mPrinter( printer ), mAddressBook( ab ),
00059     mSelection( selection ), mStyle( 0 )
00060 {
00061   mSelectionPage = new SelectionPage( this );
00062   mSelectionPage->setUseSelection( !selection.isEmpty() );
00063   insertPage( mSelectionPage, i18n("Choose Contacts to Print"), -1 );
00064 
00065   mFilters = Filter::restore( kapp->config(), "Filter" );
00066   QStringList filters;
00067   for ( Filter::List::iterator it = mFilters.begin(); it != mFilters.end(); ++it )
00068     filters.append( (*it).name() );
00069 
00070   mSelectionPage->setFilters( filters );
00071 
00072   mSelectionPage->setCategories( KABPrefs::instance()->mCustomCategories );
00073 
00074   setAppropriate( mSelectionPage, true );
00075 
00076 
00077   mStylePage = new StylePage( mAddressBook, this );
00078   connect( mStylePage, SIGNAL( styleChanged(int) ), SLOT( slotStyleSelected(int) ) );
00079   insertPage( mStylePage, i18n("Choose Printing Style"), -1 );
00080 
00081   registerStyles();
00082 
00083   if ( mStyleFactories.count() > 0 )
00084     slotStyleSelected( 0 );
00085 }
00086 
00087 PrintingWizard::~PrintingWizard()
00088 {
00089 }
00090 
00091 void PrintingWizard::accept()
00092 {
00093   print();
00094   close();
00095 }
00096 
00097 void PrintingWizard::registerStyles()
00098 {
00099   mStyleFactories.append( new DetailledPrintStyleFactory( this ) );
00100   mStyleFactories.append( new MikesStyleFactory( this ) );
00101   mStyleFactories.append( new RingBinderPrintStyleFactory( this ) );
00102 
00103   mStylePage->clearStyleNames();
00104   for ( uint i = 0; i < mStyleFactories.count(); ++i )
00105     mStylePage->addStyleName( mStyleFactories.at( i )->description() );
00106 }
00107 
00108 void PrintingWizard::slotStyleSelected( int index )
00109 {
00110   if ( index < 0 || (uint)index >= mStyleFactories.count() )
00111     return;
00112 
00113   setFinishEnabled( mStylePage, false );
00114 
00115   if ( mStyle )
00116     mStyle->hidePages();
00117 
00118   if ( mStyleList.at( index ) != 0 )
00119     mStyle = mStyleList.at( index );
00120   else {
00121     PrintStyleFactory *factory = mStyleFactories.at( index );
00122     kdDebug(5720) << "PrintingWizardImpl::slotStyleSelected: "
00123                   << "creating print style "
00124                   << factory->description() << endl;
00125     mStyle = factory->create();
00126     mStyleList.insert( index, mStyle );
00127   }
00128 
00129   mStyle->showPages();
00130 
00131   mStylePage->setPreview( mStyle->preview() );
00132 
00133   setFinishEnabled( page( pageCount() - 1 ), true );
00134 
00135   if ( mStyle->preferredSortField() != 0 ) {
00136     mStylePage->setSortField( mStyle->preferredSortField() );
00137     mStylePage->setSortAscending( mStyle->preferredSortType() );
00138   }
00139 }
00140 
00141 KABC::AddressBook* PrintingWizard::addressBook()
00142 {
00143   return mAddressBook;
00144 }
00145 
00146 KPrinter* PrintingWizard::printer()
00147 {
00148   return mPrinter;
00149 }
00150 
00151 void PrintingWizard::print()
00152 {
00153   // create and show print progress widget:
00154   PrintProgress *progress = new PrintProgress( this );
00155   insertPage( progress, i18n( "Print Progress" ), -1 );
00156   showPage( progress );
00157   kapp->processEvents();
00158 
00159   // prepare list of contacts to print:
00160 
00161   KABC::AddresseeList list;
00162   if ( mStyle != 0 ) {
00163     if ( mSelectionPage->useSelection() ) {
00164       QStringList::Iterator it;
00165       for ( it = mSelection.begin(); it != mSelection.end(); ++it ) {
00166         KABC::Addressee addr = addressBook()->findByUid( *it );
00167         if ( !addr.isEmpty() )
00168           list.append( addr );
00169       }
00170     } else if ( mSelectionPage->useFilters() ) {
00171       // find contacts that can pass selected filter
00172       Filter::List::Iterator filterIt;
00173       for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt )
00174         if ( (*filterIt).name() == mSelectionPage->filter() )
00175           break;
00176 
00177       KABC::AddressBook::Iterator it;
00178       for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
00179         if ( (*filterIt).filterAddressee( *it ) )
00180           list.append( *it );
00181       }
00182                 
00183     } else if ( mSelectionPage->useCategories() ) {
00184       QStringList categories = mSelectionPage->categories();
00185       KABC::AddressBook::Iterator it;
00186       for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
00187         QStringList tmp( (*it).categories() );
00188         QStringList::Iterator tmpIt;
00189         for ( tmpIt = tmp.begin(); tmpIt != tmp.end(); ++tmpIt )
00190           if ( categories.contains( *tmpIt ) ) {
00191             list.append( *it );
00192             break;
00193           }
00194       }
00195     } else {
00196       // create a string list of all entries:
00197       KABC::AddressBook::Iterator it;
00198       for( it = addressBook()->begin(); it != addressBook()->end(); ++it )
00199         list.append( *it );
00200     }
00201 
00202     list.setReverseSorting( !mStylePage->sortAscending() );
00203     list.sortByField( mStylePage->sortField() );
00204   }
00205 
00206   kdDebug(5720) << "PrintingWizardImpl::print: printing "
00207                 << list.count() << " contacts." << endl;
00208 
00209   // ... print:
00210   setBackEnabled( progress, false );
00211   cancelButton()->setEnabled( false );
00212   mStyle->print( list, progress );
00213 }
00214 
00215 #include "printingwizard.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:53 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003