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

kaddressbook

  • sources
  • kde-4.12
  • kdepim
  • kaddressbook
  • printing
printingwizard.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KAddressBook.
3  Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org>
4  Tobias Koenig <tokoe@kde.org>
5 
6  Copyright (c) 2009 Laurent Montel <montel@kde.org>
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, permission is given to link this program
22  with any edition of Qt, and distribute the resulting executable,
23  without including the source code for Qt in the source distribution.
24 */
25 
26 #include "printingwizard.h"
27 #include "settings.h"
28 
29 #include "contactselectionwidget.h"
30 #include "contactsorter.h"
31 #include "printprogress.h"
32 #include "printstyle.h"
33 #include "stylepage.h"
34 
35 // including the styles
36 #include "detailled/detailledstyle.h"
37 #include "mike/mikesstyle.h"
38 #include "ringbinder/ringbinderstyle.h"
39 #include "compact/compactstyle.h"
40 #include "printing/grantlee/grantleeprintstyle.h"
41 
42 #include <KApplication>
43 #include <KDebug>
44 #include <KDialog>
45 #include <KGlobal>
46 #include <KLocale>
47 #include <KStandardDirs>
48 
49 #include <QPushButton>
50 #include <QPrinter>
51 #include <QDirIterator>
52 
53 using namespace KABPrinting;
54 
55 PrintingWizard::PrintingWizard( QPrinter *printer, QItemSelectionModel *selectionModel,
56  QWidget *parent )
57  : KAssistantDialog( parent ), mPrinter( printer ), mStyle( 0 )
58 {
59  setCaption( i18n( "Print Contacts" ) );
60  showButton( Help, false );
61 
62  mSelectionPage = new ContactSelectionWidget( selectionModel, this );
63  mSelectionPage->setMessageText( i18n( "Which contacts do you want to print?" ) );
64 
65  KPageWidgetItem *mSelectionPageItem =
66  new KPageWidgetItem( mSelectionPage, i18n( "Choose Contacts to Print" ) );
67  addPage( mSelectionPageItem );
68  setAppropriate( mSelectionPageItem, true );
69 
70  mStylePage = new StylePage( this );
71  connect( mStylePage, SIGNAL(styleChanged(int)), SLOT(slotStyleSelected(int)) );
72  addPage( mStylePage, i18n( "Choose Printing Style" ) );
73 
74  registerStyles();
75 
76  if ( mStyleFactories.count() > Settings::self()->printingStyle() ) {
77  mStylePage->setPrintingStyle( Settings::self()->printingStyle() ); // should emit styleChanged
78  slotStyleSelected( Settings::self()->printingStyle() );
79  }
80 
81  mStylePage->setSortOrder( Settings::self()->sortOrder() == 0 ?
82  Qt::AscendingOrder :
83  Qt::DescendingOrder );
84  readConfig();
85 }
86 
87 PrintingWizard::~PrintingWizard()
88 {
89  writeConfig();
90 }
91 
92 void PrintingWizard::readConfig()
93 {
94  KConfigGroup grp( KGlobal::config(), "PrintingWizard" );
95  const QSize size = grp.readEntry( "Size", QSize(300, 200) );
96  if ( size.isValid() ) {
97  resize( size );
98  }
99 }
100 
101 void PrintingWizard::writeConfig()
102 {
103  KConfigGroup grp( KGlobal::config(), "PrintingWizard" );
104  grp.writeEntry( "Size", size() );
105  grp.sync();
106 }
107 
108 void PrintingWizard::setDefaultAddressBook( const Akonadi::Collection &addressBook )
109 {
110  mSelectionPage->setDefaultAddressBook( addressBook );
111 }
112 
113 void PrintingWizard::accept()
114 {
115  print();
116  close();
117  setResult(QDialog::Accepted);
118 }
119 
120 void PrintingWizard::loadGrantleeStyle()
121 {
122  const QString relativePath = QLatin1String("kaddressbook/printing/themes/");
123  QStringList themesDirectories = KGlobal::dirs()->findDirs("data", relativePath);
124  if (themesDirectories.count() < 2) {
125  //Make sure to add local directory
126  const QString localDirectory = KStandardDirs::locateLocal("data", relativePath);
127  if (!themesDirectories.contains(localDirectory)) {
128  themesDirectories.append(localDirectory);
129  }
130  }
131 
132  Q_FOREACH (const QString &directory, themesDirectories) {
133  QDirIterator dirIt( directory, QStringList(), QDir::AllDirs | QDir::NoDotAndDotDot );
134  QStringList alreadyLoadedThemeName;
135  while ( dirIt.hasNext() ) {
136  dirIt.next();
137  const QString themeInfoFile = dirIt.filePath() + QDir::separator() + QLatin1String("theme.desktop");
138  KConfig config( themeInfoFile );
139  KConfigGroup group( &config, QLatin1String( "Desktop Entry" ) );
140  QString name = group.readEntry( "Name", QString() );
141  if (name.isEmpty()) {
142  continue;
143  }
144  if (alreadyLoadedThemeName.contains(name)) {
145  int i = 2;
146  const QString originalName(name);
147  while (alreadyLoadedThemeName.contains(name)) {
148  name = originalName + QString::fromLatin1(" (%1)").arg(i);
149  ++i;
150  }
151  }
152  const QString printThemePath(dirIt.filePath() + QDir::separator());
153  if (!printThemePath.isEmpty()) {
154  alreadyLoadedThemeName << name;
155  mStyleFactories.append( new GrantleeStyleFactory(name, printThemePath, this) );
156  }
157  }
158  }
159 }
160 
161 void PrintingWizard::registerStyles()
162 {
163  mStyleFactories.append( new DetailledPrintStyleFactory( this ) );
164  mStyleFactories.append( new MikesStyleFactory( this ) );
165  mStyleFactories.append( new RingBinderPrintStyleFactory( this ) );
166  mStyleFactories.append( new CompactStyleFactory( this ) );
167 
168  loadGrantleeStyle();
169 
170  mStylePage->clearStyleNames();
171  for ( int i = 0; i < mStyleFactories.count(); ++i ) {
172  mStylePage->addStyleName( mStyleFactories.at( i )->description() );
173  }
174 }
175 
176 void PrintingWizard::slotStyleSelected( int index )
177 {
178  if ( index < 0 || index >= mStyleFactories.count() ) {
179  return;
180  }
181 
182  if ( mStyle ) {
183  mStyle->hidePages();
184  }
185 
186  mStyle = mStyleList.value( index );
187  if ( !mStyle ) {
188  PrintStyleFactory *factory = mStyleFactories.at( index );
189  kDebug() << "creating print style" << factory->description();
190 
191  mStyle = factory->create();
192  mStyleList.insert( index, mStyle );
193  }
194 
195  mStyle->showPages();
196 
197  mStylePage->setPreview( mStyle->preview() );
198 
199  mStylePage->setSortField( mStyle->preferredSortField() );
200  mStylePage->setSortOrder( mStyle->preferredSortOrder() );
201 }
202 
203 QPrinter *PrintingWizard::printer()
204 {
205  return mPrinter;
206 }
207 
208 int PrintingWizard::printingStyle() const
209 {
210  return mStylePage->printingStyle();
211 }
212 
213 int PrintingWizard::sortOrder() const
214 {
215  return mStylePage->sortOrder();
216 }
217 
218 void PrintingWizard::print()
219 {
220  // create and show print progress widget:
221  mProgress = new PrintProgress( this );
222  KPageWidgetItem *progressItem = new KPageWidgetItem( mProgress, i18n( "Print Progress" ) );
223  addPage( progressItem );
224  setCurrentPage( progressItem );
225  kapp->processEvents();
226 
227  KABC::Addressee::List contacts = mSelectionPage->selectedContacts();
228 
229  const ContactSorter sorter( mStylePage->sortField(), mStylePage->sortOrder() );
230  sorter.sort( contacts );
231 
232  kDebug() <<"printing" << contacts.count() << "contacts.";
233  // ... print:
234  enableButton( KDialog::User3, false ); // back button
235  enableButton( KDialog::Cancel, false );
236  mStyle->print( contacts, mProgress );
237 }
238 
239 #include "printingwizard.moc"
mikesstyle.h
KABPrinting::PrintingWizard::printingStyle
int printingStyle() const
Returns the index of the selected style.
Definition: printingwizard.cpp:208
StylePage
Definition: stylepage.h:37
KABPrinting::PrintingWizard::mStyleList
QList< PrintStyle * > mStyleList
Definition: printingwizard.h:115
KABPrinting::GrantleeStyleFactory
Definition: grantleeprintstyle.h:49
ContactSelectionWidget::setDefaultAddressBook
void setDefaultAddressBook(const Akonadi::Collection &addressBook)
Sets the default addressbook.
Definition: contactselectionwidget.cpp:67
compactstyle.h
KABPrinting::PrintStyle::showPages
void showPages()
Show all style specific pages in the printing wizard.
Definition: printstyle.cpp:93
KABPrinting::PrintStyleFactory::create
virtual PrintStyle * create() const =0
KABPrinting::PrintingWizard::setDefaultAddressBook
void setDefaultAddressBook(const Akonadi::Collection &addressBook)
Sets the default addressbook of the contact selection.
Definition: printingwizard.cpp:108
ContactSelectionWidget::selectedContacts
KABC::Addressee::List selectedContacts() const
Returns the list of selected contacts.
Definition: contactselectionwidget.cpp:72
ContactSorter
Definition: contactsorter.h:26
KABPrinting::PrintingWizard::accept
void accept()
Overloaded accept slot.
Definition: printingwizard.cpp:113
KABPrinting::PrintStyleFactory::description
virtual QString description() const =0
Overload this method to provide a one-liner description for your print style.
KABPrinting::RingBinderPrintStyleFactory
Definition: ringbinderstyle.h:47
StylePage::setPrintingStyle
void setPrintingStyle(int index)
Returns the sort order.
Definition: stylepage.cpp:210
KABPrinting::PrintingWizard::mStylePage
StylePage * mStylePage
Definition: printingwizard.h:120
KABPrinting::CompactStyleFactory
Definition: compactstyle.h:70
StylePage::setPreview
void setPreview(const QPixmap &pixmap)
Set a preview image.
Definition: stylepage.cpp:63
Settings::self
static Settings * self()
Definition: settings.cpp:19
KABPrinting::PrintStyle::preferredSortOrder
Qt::SortOrder preferredSortOrder() const
Returns the preferred order that shall be used for sorting.
Definition: printstyle.cpp:123
KAssistantDialog
StylePage::printingStyle
int printingStyle() const
Returns the sort order.
Definition: stylepage.cpp:205
KABPrinting::PrintingWizard::mStyleFactories
QList< PrintStyleFactory * > mStyleFactories
Definition: printingwizard.h:114
ContactSelectionWidget::setMessageText
void setMessageText(const QString &message)
Sets the message text.
Definition: contactselectionwidget.cpp:62
ContactSelectionWidget
A widget to select a group of contacts.
Definition: contactselectionwidget.h:42
KABPrinting::PrintingWizard::sortOrder
int sortOrder() const
Returns the sort order of addressBook.
Definition: printingwizard.cpp:213
KABPrinting::PrintStyle::hidePages
void hidePages()
Hides all style specific pages in the printing wizard.
Definition: printstyle.cpp:105
KABPrinting::MikesStyleFactory
Definition: mikesstyle.h:47
stylepage.h
KABPrinting::PrintingWizard::mProgress
PrintProgress * mProgress
Definition: printingwizard.h:118
printstyle.h
KABPrinting::PrintingWizard::registerStyles
void registerStyles()
Registers all available printing styles.
Definition: printingwizard.cpp:161
ringbinderstyle.h
StylePage::setSortOrder
void setSortOrder(Qt::SortOrder sortOrder)
Sets the sort order.
Definition: stylepage.cpp:87
StylePage::addStyleName
void addStyleName(const QString &name)
Add a style name.
Definition: stylepage.cpp:72
grantleeprintstyle.h
printprogress.h
contactselectionwidget.h
KABPrinting::PrintingWizard::~PrintingWizard
~PrintingWizard()
Destroys the printing wizard.
Definition: printingwizard.cpp:87
KABPrinting::PrintStyle::print
virtual void print(const KABC::Addressee::List &contacts, PrintProgress *progress)=0
This method must be reimplemented to actually print something.
printingwizard.h
Settings::printingStyle
static int printingStyle()
Get Printing style.
Definition: settings.h:86
KABPrinting::PrintingWizard::mSelectionPage
ContactSelectionWidget * mSelectionPage
Definition: printingwizard.h:121
StylePage::setSortField
void setSortField(ContactFields::Field field)
Set the sort criterion field.
Definition: stylepage.cpp:82
ContactSorter::sort
void sort(QList< KABC::Addressee > &contacts) const
Definition: contactsorter.cpp:85
settings.h
StylePage::clearStyleNames
void clearStyleNames()
Clear the style name list.
Definition: stylepage.cpp:77
StylePage::sortField
ContactFields::Field sortField() const
Returns the sort criterion field.
Definition: stylepage.cpp:96
KABPrinting::PrintingWizard::print
void print()
Performs the actual printing.
Definition: printingwizard.cpp:218
KABPrinting::PrintingWizard::mPrinter
QPrinter * mPrinter
Definition: printingwizard.h:116
contactsorter.h
StylePage::sortOrder
Qt::SortOrder sortOrder() const
Returns the sort order.
Definition: stylepage.cpp:105
KABPrinting::PrintProgress
This defines a simple widget to display print progress information.
Definition: printprogress.h:41
KABPrinting::PrintingWizard::mStyle
PrintStyle * mStyle
Definition: printingwizard.h:117
KABPrinting::DetailledPrintStyleFactory
Definition: detailledstyle.h:49
KABPrinting::PrintStyleFactory
The factories are used to have all object of the respective print style created in one place...
Definition: printstyle.h:171
KABPrinting::PrintStyle::preview
const QPixmap & preview() const
This method should be reimplemented to provide a preview of what the printed page will look like...
Definition: printstyle.cpp:46
KABPrinting::PrintingWizard::PrintingWizard
PrintingWizard(QPrinter *printer, QItemSelectionModel *selectionModel, QWidget *parent=0)
Creates a new printing wizard.
Definition: printingwizard.cpp:55
detailledstyle.h
KABPrinting::PrintingWizard::printer
QPrinter * printer()
Returns the printer to use for printing.
Definition: printingwizard.cpp:203
KABPrinting::PrintStyle::preferredSortField
ContactFields::Field preferredSortField() const
Returns the preferred contact field that shall be used for sorting.
Definition: printstyle.cpp:118
KABPrinting::PrintingWizard::slotStyleSelected
void slotStyleSelected(int)
A print style has been selected.
Definition: printingwizard.cpp:176
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kaddressbook

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal