• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kaddressbook

printingwizard.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 <QtGui/QPushButton>
00026 #include <QtGui/QPrinter>
00027 
00028 #include <kabc/addresseelist.h>
00029 #include <kapplication.h>
00030 #include <kdebug.h>
00031 #include <kdialog.h>
00032 #include <kglobal.h>
00033 #include <klocale.h>
00034 
00035 // including the styles
00036 #include "detailledstyle.h"
00037 #include "mikesstyle.h"
00038 #include "ringbinderstyle.h"
00039 
00040 #include "kabprefs.h"
00041 #include "printprogress.h"
00042 #include "printstyle.h"
00043 #include "printsortmode.h"
00044 
00045 #include "printingwizard.h"
00046 
00047 using namespace KABPrinting;
00048 
00049 PrintingWizard::PrintingWizard( QPrinter *printer, KABC::AddressBook* ab,
00050                                 const QStringList& selection, QWidget *parent )
00051   : KAssistantDialog( parent ), mPrinter( printer ), mAddressBook( ab ),
00052     mSelection( selection ), mStyle( 0 )
00053 {
00054   mSelectionPage = new SelectionPage( this );
00055   mSelectionPage->setUseSelection( !selection.isEmpty() );
00056   KPageWidgetItem *mSelectionPageItem = new KPageWidgetItem( mSelectionPage, i18n("Choose Contacts to Print") );
00057   addPage( mSelectionPageItem );
00058 
00059   mFilters = Filter::restore( KGlobal::config().data(), "Filter" );
00060   QStringList filters;
00061   for ( Filter::List::ConstIterator it = mFilters.begin(); it != mFilters.end(); ++it )
00062     filters.append( (*it).name() );
00063 
00064   mSelectionPage->setFilters( filters );
00065 
00066   mSelectionPage->setCategories( KABPrefs::instance()->customCategories() );
00067 
00068   setAppropriate( mSelectionPageItem, true );
00069 
00070 
00071   mStylePage = new StylePage( mAddressBook, this );
00072   connect( mStylePage, SIGNAL( styleChanged(int) ), SLOT( slotStyleSelected(int) ) );
00073   addPage( mStylePage, i18n("Choose Printing Style") );
00074 
00075   registerStyles();
00076 
00077   if ( mStyleFactories.count() > 0 )
00078     slotStyleSelected( 0 );
00079 }
00080 
00081 PrintingWizard::~PrintingWizard()
00082 {
00083 }
00084 
00085 void PrintingWizard::accept()
00086 {
00087   print();
00088   close();
00089 }
00090 
00091 void PrintingWizard::registerStyles()
00092 {
00093   mStyleFactories.append( new DetailledPrintStyleFactory( this ) );
00094   mStyleFactories.append( new MikesStyleFactory( this ) );
00095   mStyleFactories.append( new RingBinderPrintStyleFactory( this ) );
00096 
00097   mStylePage->clearStyleNames();
00098   for ( int i = 0; i < mStyleFactories.count(); ++i )
00099     mStylePage->addStyleName( mStyleFactories.at( i )->description() );
00100 }
00101 
00102 void PrintingWizard::slotStyleSelected( int index )
00103 {
00104   if ( index < 0 || index >= mStyleFactories.count() )
00105     return;
00106 
00107   //enableButton( KDialog::User1, false ); // finish button
00108 
00109   if ( mStyle )
00110     mStyle->hidePages();
00111 
00112   mStyle = mStyleList.value( index );
00113   if ( !mStyle ) {
00114     PrintStyleFactory *factory = mStyleFactories.at( index );
00115     kDebug(5720) <<"PrintingWizardImpl::slotStyleSelected:"
00116                   << "creating print style"
00117                   << factory->description();
00118     mStyle = factory->create();
00119     mStyleList.insert( index, mStyle );
00120   }
00121 
00122   mStyle->showPages();
00123 
00124   mStylePage->setPreview( mStyle->preview() );
00125 
00126   //setFinishEnabled( page( pageCount() - 1 ), true );
00127 
00128   if ( mStyle->preferredSortField() != 0 ) {
00129     mStylePage->setSortField( mStyle->preferredSortField() );
00130     mStylePage->setSortAscending( mStyle->preferredSortType() );
00131   }
00132 }
00133 
00134 KABC::AddressBook* PrintingWizard::addressBook()
00135 {
00136   return mAddressBook;
00137 }
00138 
00139 QPrinter* PrintingWizard::printer()
00140 {
00141   return mPrinter;
00142 }
00143 
00144 void PrintingWizard::print()
00145 {
00146   // create and show print progress widget:
00147   PrintProgress *progress = new PrintProgress( this );
00148   KPageWidgetItem *progressItem = new KPageWidgetItem( progress, i18n( "Print Progress" ) );
00149   addPage( progressItem );
00150   setCurrentPage( progressItem );
00151   kapp->processEvents();
00152 
00153   // prepare list of contacts to print:
00154 
00155   KABC::AddresseeList list;
00156   if ( mStyle != 0 ) {
00157     if ( mSelectionPage->useSelection() ) {
00158       QStringList::ConstIterator it;
00159       for ( it = mSelection.begin(); it != mSelection.end(); ++it ) {
00160         KABC::Addressee addr = addressBook()->findByUid( *it );
00161         if ( !addr.isEmpty() )
00162           list.append( addr );
00163       }
00164     } else if ( mSelectionPage->useFilters() ) {
00165       // find contacts that can pass selected filter
00166       Filter::List::ConstIterator filterIt;
00167       for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt )
00168         if ( (*filterIt).name() == mSelectionPage->filter() )
00169           break;
00170 
00171       KABC::AddressBook::ConstIterator it;
00172       for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
00173         if ( (*filterIt).filterAddressee( *it ) )
00174           list.append( *it );
00175       }
00176 
00177     } else if ( mSelectionPage->useCategories() ) {
00178       QStringList categories = mSelectionPage->categories();
00179       KABC::AddressBook::ConstIterator it;
00180       for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
00181         const QStringList tmp( (*it).categories() );
00182         QStringList::ConstIterator tmpIt;
00183         for ( tmpIt = tmp.begin(); tmpIt != tmp.end(); ++tmpIt )
00184           if ( categories.contains( *tmpIt ) ) {
00185             list.append( *it );
00186             break;
00187           }
00188       }
00189     } else {
00190       // create a string list of all entries:
00191       KABC::AddressBook::ConstIterator it;
00192       for ( it = addressBook()->begin(); it != addressBook()->end(); ++it )
00193         list.append( *it );
00194     }
00195 
00196     list.setReverseSorting( !mStylePage->sortAscending() );
00197 
00198     PrintSortMode sortMode( mStylePage->sortField() );
00199     list.sortByMode( &sortMode );
00200   }
00201 
00202   kDebug(5720) <<"PrintingWizardImpl::print: printing"
00203                 << list.count() << "contacts.";
00204 
00205   // ... print:
00206   enableButton( KDialog::User3, false ); // back button
00207   enableButton( KDialog::Cancel, false );
00208   mStyle->print( list, progress );
00209 }
00210 
00211 #include "printingwizard.moc"

kaddressbook

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

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal