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

calendarsupport

  • sources
  • kde-4.12
  • kdepim
  • calendarsupport
archivedialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
3  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  As a special exception, permission is given to link this program
20  with any edition of Qt, and distribute the resulting executable,
21  without including the source code for Qt in the source distribution.
22 */
23 
24 // ArchiveDialog -- archive/delete past events.
25 
26 #include "archivedialog.h"
27 #include "eventarchiver.h"
28 #include "kcalprefs.h"
29 
30 #include <Akonadi/Calendar/IncidenceChanger>
31 
32 #include <KComboBox>
33 #include <KDateComboBox>
34 #include <KFileDialog>
35 #include <KLineEdit>
36 #include <KLocale>
37 #include <KMessageBox>
38 #include <KNumInput>
39 #include <KUrl>
40 #include <KUrlRequester>
41 #include <KVBox>
42 
43 #include <QButtonGroup>
44 #include <QCheckBox>
45 #include <QDateTime>
46 #include <QFrame>
47 #include <QGroupBox>
48 #include <QHBoxLayout>
49 #include <QLabel>
50 #include <QLayout>
51 #include <QRadioButton>
52 #include <QVBoxLayout>
53 #include <QWhatsThis>
54 
55 using namespace CalendarSupport;
56 
57 ArchiveDialog::ArchiveDialog( const Akonadi::ETMCalendar::Ptr &cal,
58  Akonadi::IncidenceChanger *changer,
59  QWidget *parent )
60  : KDialog (parent)
61 {
62  setCaption( i18nc( "@title:window", "Archive/Delete Past Events and To-dos" ) );
63  setButtons( User1|Cancel );
64  setDefaultButton( User1 );
65  setModal( false );
66  showButtonSeparator( true );
67  setButtonText( User1, i18nc( "@action:button", "&Archive" ) );
68  mCalendar = cal;
69  mChanger = changer;
70 
71  QFrame *topFrame = new QFrame( this );
72  setMainWidget( topFrame );
73  QVBoxLayout *topLayout = new QVBoxLayout( topFrame );
74  topLayout->setSpacing( spacingHint() );
75 #ifndef KDEPIM_MOBILE_UI
76  QLabel *descLabel = new QLabel( topFrame );
77  descLabel->setText(
78  i18nc( "@info:whatsthis",
79  "Archiving saves old items into the given file and "
80  "then deletes them in the current calendar. If the archive file "
81  "already exists they will be added. "
82  "(<link url=\"#\">How to restore</link>)" ) );
83  descLabel->setWhatsThis(
84  i18nc( "@info:whatsthis",
85  "In order to add an archive to your calendar, use the Merge Calendar "
86  "function. You can view an archive by opening it like you would any "
87  "other calendar. It is not saved in a special format, but as "
88  "vCalendar." ) );
89  descLabel->setTextInteractionFlags(
90  Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard |
91  Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard );
92  descLabel->setWordWrap( true );
93  topLayout->addWidget( descLabel );
94  connect( descLabel, SIGNAL(linkActivated(QString)), SLOT(showWhatsThis()) );
95 #endif
96 
97  QButtonGroup *radioBG = new QButtonGroup( this );
98  connect( radioBG, SIGNAL(buttonClicked(int)), SLOT(slotActionChanged()) );
99 
100  QHBoxLayout *dateLayout = new QHBoxLayout();
101  dateLayout->setMargin( 0 );
102  mArchiveOnceRB = new QRadioButton( i18nc( "@option:radio",
103  "Archive now items older than:" ),
104  topFrame );
105  mArchiveOnceRB->setToolTip(
106  i18nc( "@info:tooltip",
107  "Enable one time archiving or purging of older items" ) );
108  mArchiveOnceRB->setWhatsThis(
109  i18nc( "@info:whatsthis",
110  "If you check this box, events and to-dos older than the specified age "
111  "will be archived or purged. The items will be archived unless the "
112  "\"Delete only\" option is enabled; else the items will be purged "
113  "and not saved." ) );
114 
115  dateLayout->addWidget( mArchiveOnceRB );
116  radioBG->addButton( mArchiveOnceRB );
117  mDateEdit = new KDateComboBox( topFrame );
118  mDateEdit->setToolTip(
119  i18nc( "@info:tooltip",
120  "Set the one time archiving cut-off date" ) );
121  mDateEdit->setWhatsThis(
122  i18nc( "@info:whatsthis",
123  "The date before which items should be archived. All older events "
124  "and to-dos will be saved and deleted, the newer (and events "
125  "exactly on that date) will be kept." ) );
126  dateLayout->addWidget( mDateEdit );
127  topLayout->addLayout( dateLayout );
128 
129  // Checkbox, numinput and combo for auto-archiving (similar to kmail's
130  // mExpireFolderCheckBox/mReadExpiryTimeNumInput in kmfolderdia.cpp)
131  KHBox *autoArchiveHBox = new KHBox( topFrame );
132  topLayout->addWidget( autoArchiveHBox );
133  mAutoArchiveRB = new QRadioButton( i18nc( "@option:radio",
134  "Automaticall&y archive items older than:" ),
135  autoArchiveHBox );
136  mAutoArchiveRB->setToolTip(
137  i18nc( "@info:tooltip",
138  "Enable automatic archiving or purging of older items" ) );
139  mAutoArchiveRB->setWhatsThis(
140  i18nc( "@info:whatsthis",
141  "If this feature is enabled, the application will regularly check if "
142  "events and to-dos have to be archived; this means you will not "
143  "need to use this dialog box again, except to change the settings." ) );
144  radioBG->addButton( mAutoArchiveRB );
145 
146  mExpiryTimeNumInput = new KIntNumInput( autoArchiveHBox );
147  mExpiryTimeNumInput->setRange( 1, 500, 1 );
148  mExpiryTimeNumInput->setSliderEnabled( false );
149  mExpiryTimeNumInput->setEnabled( false );
150  mExpiryTimeNumInput->setValue( 7 );
151  mExpiryTimeNumInput->setToolTip(
152  i18nc( "@info:tooltip",
153  "Set the archival age in days, weeks or months" ) );
154  mExpiryTimeNumInput->setWhatsThis(
155  i18nc( "@info:whatsthis",
156  "The age of the events and to-dos to archive. All older items "
157  "will be saved and deleted, the newer will be kept." ) );
158 
159  mExpiryUnitsComboBox = new KComboBox( autoArchiveHBox );
160  mExpiryUnitsComboBox->setToolTip(
161  i18nc( "@info:tooltip",
162  "Set the units for the automatic archive age" ) );
163  mExpiryUnitsComboBox->setWhatsThis(
164  i18nc( "@info:whatsthis",
165  "Select the time units (days, weeks or months) for automatic archiving." ) );
166  // Those items must match the "Expiry Unit" enum in the kcfg file!
167  mExpiryUnitsComboBox->addItem(
168  i18nc( "@item:inlistbox expires in daily units", "Day(s)" ) );
169  mExpiryUnitsComboBox->addItem(
170  i18nc( "@item:inlistbox expiration in weekly units", "Week(s)" ) );
171  mExpiryUnitsComboBox->addItem(
172  i18nc( "@item:inlistbox expiration in monthly units", "Month(s)" ) );
173  mExpiryUnitsComboBox->setEnabled( false );
174 
175  QHBoxLayout *fileLayout = new QHBoxLayout();
176  fileLayout->setMargin( 0 );
177  fileLayout->setSpacing( spacingHint() );
178  QLabel *l = new QLabel( i18nc( "@label", "Archive &file:" ), topFrame );
179  fileLayout->addWidget( l );
180  mArchiveFile = new KUrlRequester( KCalPrefs::instance()->mArchiveFile, topFrame );
181  mArchiveFile->setMode( KFile::File );
182  mArchiveFile->setFilter( i18nc( "@label filter for KUrlRequester", "*.ics|iCalendar Files" ) );
183  mArchiveFile->setToolTip(
184  i18nc( "@info:tooltip",
185  "Set the location of the archive" ) );
186  mArchiveFile->setWhatsThis(
187  i18nc( "@info:whatsthis",
188  "The path of the archive file. The events and to-dos will be appended "
189  "to the specified file, so any events that are already in the file "
190  "will not be modified or deleted. You can later load or merge the "
191  "file like any other calendar. It is not saved in a special "
192  "format, it uses the iCalendar format." ) );
193 #ifndef Q_OS_WINCE
194  mArchiveFile->fileDialog()->setOperationMode( KFileDialog::Saving );
195 #else
196  // There is no fileDialog instance availabe on WinCE systems.
197  mArchiveFile->setOperationMode( KFileDialog::Saving );
198 #endif
199  l->setBuddy( mArchiveFile->lineEdit() );
200  fileLayout->addWidget( mArchiveFile );
201  topLayout->addLayout( fileLayout );
202 
203 #ifndef KDEPIM_MOBILE_UI
204  QGroupBox *typeBox = new QGroupBox( i18nc( "@title:group", "Type of Items to Archive" ) );
205  typeBox->setWhatsThis(
206  i18nc( "@info:whatsthis",
207  "Here you can select which items "
208  "should be archived. Events are archived if they "
209  "ended before the date given above; to-dos are archived if "
210  "they were finished before the date." ) );
211 
212  topLayout->addWidget( typeBox );
213  QBoxLayout *typeLayout = new QVBoxLayout( typeBox );
214 #else
215  QBoxLayout *typeLayout = new QHBoxLayout();
216  topLayout->addLayout( typeLayout );
217 #endif
218 
219  mEvents = new QCheckBox( i18nc( "@option:check", "Archive &Events" ) );
220  mEvents->setToolTip(
221  i18nc( "@option:check", "Archive or purge events" ) );
222  mEvents->setWhatsThis(
223  i18nc( "@info:whatsthis",
224  "Select this option to archive events if they ended before the date given above." ) );
225  typeLayout->addWidget( mEvents );
226 
227  mTodos = new QCheckBox( i18nc( "@option:check", "Archive Completed &To-dos" ) );
228  mTodos->setToolTip(
229  i18nc( "@option:check", "Archive or purge completed to-dos" ) );
230  mTodos->setWhatsThis(
231  i18nc( "@info:whatsthis",
232  "Select this option to archive to-dos if they were completed "
233  "before the date given above." ) );
234  typeLayout->addWidget( mTodos );
235 
236  mDeleteCb = new QCheckBox( i18nc( "@option:check", "&Delete only, do not save" ), topFrame );
237  mDeleteCb->setToolTip(
238  i18nc( "@info:tooltip",
239  "Purge the old items without saving them" ) );
240  mDeleteCb->setWhatsThis(
241  i18nc( "@info:whatsthis",
242  "Select this option to delete old events and to-dos without saving "
243  "them. It is not possible to recover the events later." ) );
244  topLayout->addWidget( mDeleteCb );
245  connect( mDeleteCb, SIGNAL(toggled(bool)), mArchiveFile, SLOT(setDisabled(bool)) );
246  connect( mDeleteCb, SIGNAL(toggled(bool)), this, SLOT(slotEnableUser1()) );
247  connect( mArchiveFile->lineEdit(), SIGNAL(textChanged(QString)),
248  this, SLOT(slotEnableUser1()) );
249 
250  // Load settings from KCalPrefs
251  mExpiryTimeNumInput->setValue( KCalPrefs::instance()->mExpiryTime );
252  mExpiryUnitsComboBox->setCurrentIndex( KCalPrefs::instance()->mExpiryUnit );
253  mDeleteCb->setChecked( KCalPrefs::instance()->mArchiveAction == KCalPrefs::actionDelete );
254  mEvents->setChecked( KCalPrefs::instance()->mArchiveEvents );
255  mTodos->setChecked( KCalPrefs::instance()->mArchiveTodos );
256 
257  slotEnableUser1();
258 
259  // The focus should go to a useful field by default, not to the top richtext-label
260  if ( KCalPrefs::instance()->mAutoArchive ) {
261  mAutoArchiveRB->setChecked( true );
262  mAutoArchiveRB->setFocus();
263  } else {
264  mArchiveOnceRB->setChecked( true );
265  mArchiveOnceRB->setFocus();
266  }
267  slotActionChanged();
268  connect( this, SIGNAL(user1Clicked()), this, SLOT(slotUser1()) );
269 }
270 
271 ArchiveDialog::~ArchiveDialog()
272 {
273 }
274 
275 void ArchiveDialog::slotEnableUser1()
276 {
277  const bool state = ( mDeleteCb->isChecked() || !mArchiveFile->lineEdit()->text().isEmpty() );
278  enableButton( KDialog::User1, state );
279 }
280 
281 void ArchiveDialog::slotActionChanged()
282 {
283  mDateEdit->setEnabled( mArchiveOnceRB->isChecked() );
284  mExpiryTimeNumInput->setEnabled( mAutoArchiveRB->isChecked() );
285  mExpiryUnitsComboBox->setEnabled( mAutoArchiveRB->isChecked() );
286 }
287 
288 // Archive old events
289 void ArchiveDialog::slotUser1()
290 {
291  EventArchiver archiver;
292  connect( &archiver, SIGNAL(eventsDeleted()), this, SLOT(slotEventsDeleted()) );
293 
294  KCalPrefs::instance()->mAutoArchive = mAutoArchiveRB->isChecked();
295  KCalPrefs::instance()->mExpiryTime = mExpiryTimeNumInput->value();
296  KCalPrefs::instance()->mExpiryUnit = mExpiryUnitsComboBox->currentIndex();
297 
298  if ( mDeleteCb->isChecked() ) {
299  KCalPrefs::instance()->mArchiveAction = KCalPrefs::actionDelete;
300  } else {
301  KCalPrefs::instance()->mArchiveAction = KCalPrefs::actionArchive;
302 
303  // Get destination URL
304  KUrl destUrl( mArchiveFile->url() );
305  if ( !destUrl.isValid() ) {
306  KMessageBox::sorry( this, i18nc( "@info", "The archive file name is not valid." ) );
307  return;
308  }
309  // Force filename to be ending with vCalendar extension
310  QString filename = destUrl.fileName();
311  if ( !filename.endsWith( QLatin1String( ".vcs" ) ) &&
312  !filename.endsWith( QLatin1String( ".ics" ) ) ) {
313  filename.append( QLatin1String( ".ics" ) );
314  destUrl.setFileName( filename );
315  }
316 
317  KCalPrefs::instance()->mArchiveFile = destUrl.url();
318  }
319  if ( KCalPrefs::instance()->mAutoArchive ) {
320  archiver.runAuto( mCalendar, mChanger, this, true /*with gui*/);
321  emit autoArchivingSettingsModified();
322  accept();
323  } else {
324  archiver.runOnce( mCalendar, mChanger, mDateEdit->date(), this );
325  accept();
326  }
327 }
328 
329 void ArchiveDialog::slotEventsDeleted()
330 {
331  emit eventsDeleted();
332  if ( !KCalPrefs::instance()->mAutoArchive ) {
333  accept();
334  }
335 }
336 
337 void ArchiveDialog::showWhatsThis()
338 {
339  QWidget *widget = qobject_cast< QWidget * >( sender() );
340  if ( widget && !widget->whatsThis().isEmpty() ) {
341  QWhatsThis::showText( QCursor::pos(), widget->whatsThis() );
342  }
343 }
344 
345 #include "archivedialog.moc"
CalendarSupport::ArchiveDialog::slotActionChanged
void slotActionChanged()
Definition: archivedialog.cpp:281
CalendarSupport::EventArchiver::runAuto
void runAuto(const Akonadi::ETMCalendar::Ptr &calendar, Akonadi::IncidenceChanger *changer, QWidget *widget, bool withGUI)
Delete or archive events.
Definition: eventarchiver.cpp:83
QWidget
CalendarSupport::ArchiveDialog::slotEnableUser1
void slotEnableUser1()
Definition: archivedialog.cpp:275
CalendarSupport::ArchiveDialog::ArchiveDialog
ArchiveDialog(const Akonadi::ETMCalendar::Ptr &calendar, Akonadi::IncidenceChanger *changer, QWidget *parent=0)
Definition: archivedialog.cpp:57
CalendarSupport::KCalPrefsBase::actionDelete
Definition: kcalprefs_base.h:19
KDialog
archivedialog.h
kcalprefs.h
CalendarSupport::ArchiveDialog::slotUser1
void slotUser1()
Definition: archivedialog.cpp:289
CalendarSupport::KCalPrefsBase::mExpiryUnit
int mExpiryUnit
Definition: kcalprefs_base.h:779
CalendarSupport::KCalPrefsBase::actionArchive
Definition: kcalprefs_base.h:19
eventarchiver.h
CalendarSupport::EventArchiver
This class handles expiring and archiving of events.
Definition: eventarchiver.h:53
CalendarSupport::KCalPrefs::instance
static KCalPrefs * instance()
Get instance of KCalPrefs.
Definition: kcalprefs.cpp:75
CalendarSupport::KCalPrefsBase::mArchiveFile
QString mArchiveFile
Definition: kcalprefs_base.h:780
CalendarSupport::KCalPrefsBase::mArchiveAction
int mArchiveAction
Definition: kcalprefs_base.h:783
CalendarSupport::KCalPrefsBase::mAutoArchive
bool mAutoArchive
Definition: kcalprefs_base.h:777
CalendarSupport::ArchiveDialog::autoArchivingSettingsModified
void autoArchivingSettingsModified()
CalendarSupport::KCalPrefsBase::mExpiryTime
int mExpiryTime
Definition: kcalprefs_base.h:778
CalendarSupport::ArchiveDialog::~ArchiveDialog
~ArchiveDialog()
Definition: archivedialog.cpp:271
CalendarSupport::ArchiveDialog::slotEventsDeleted
void slotEventsDeleted()
Definition: archivedialog.cpp:329
CalendarSupport::EventArchiver::runOnce
void runOnce(const Akonadi::ETMCalendar::Ptr &calendar, Akonadi::IncidenceChanger *changer, const QDate &limitDate, QWidget *widget)
Delete or archive events once.
Definition: eventarchiver.cpp:76
CalendarSupport::ArchiveDialog::eventsDeleted
void eventsDeleted()
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

calendarsupport

Skip menu "calendarsupport"
  • 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