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

calendarsupport

  • sources
  • kde-4.14
  • 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 <KLocalizedString>
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  descLabel->setContextMenuPolicy(Qt::NoContextMenu);
94  topLayout->addWidget( descLabel );
95  connect( descLabel, SIGNAL(linkActivated(QString)), SLOT(showWhatsThis()) );
96 #endif
97 
98  QButtonGroup *radioBG = new QButtonGroup( this );
99  connect( radioBG, SIGNAL(buttonClicked(int)), SLOT(slotActionChanged()) );
100 
101  QHBoxLayout *dateLayout = new QHBoxLayout();
102  dateLayout->setMargin( 0 );
103  mArchiveOnceRB = new QRadioButton( i18nc( "@option:radio",
104  "Archive now items older than:" ),
105  topFrame );
106  mArchiveOnceRB->setToolTip(
107  i18nc( "@info:tooltip",
108  "Enable one time archiving or purging of older items" ) );
109  mArchiveOnceRB->setWhatsThis(
110  i18nc( "@info:whatsthis",
111  "If you check this box, events and to-dos older than the specified age "
112  "will be archived or purged. The items will be archived unless the "
113  "\"Delete only\" option is enabled; else the items will be purged "
114  "and not saved." ) );
115 
116  dateLayout->addWidget( mArchiveOnceRB );
117  radioBG->addButton( mArchiveOnceRB );
118  mDateEdit = new KDateComboBox( topFrame );
119  mDateEdit->setToolTip(
120  i18nc( "@info:tooltip",
121  "Set the one time archiving cut-off date" ) );
122  mDateEdit->setWhatsThis(
123  i18nc( "@info:whatsthis",
124  "The date before which items should be archived. All older events "
125  "and to-dos will be saved and deleted, the newer (and events "
126  "exactly on that date) will be kept." ) );
127  dateLayout->addWidget( mDateEdit );
128  topLayout->addLayout( dateLayout );
129 
130  // Checkbox, numinput and combo for auto-archiving (similar to kmail's
131  // mExpireFolderCheckBox/mReadExpiryTimeNumInput in kmfolderdia.cpp)
132  KHBox *autoArchiveHBox = new KHBox( topFrame );
133  topLayout->addWidget( autoArchiveHBox );
134  mAutoArchiveRB = new QRadioButton( i18nc( "@option:radio",
135  "Automaticall&y archive items older than:" ),
136  autoArchiveHBox );
137  mAutoArchiveRB->setToolTip(
138  i18nc( "@info:tooltip",
139  "Enable automatic archiving or purging of older items" ) );
140  mAutoArchiveRB->setWhatsThis(
141  i18nc( "@info:whatsthis",
142  "If this feature is enabled, the application will regularly check if "
143  "events and to-dos have to be archived; this means you will not "
144  "need to use this dialog box again, except to change the settings." ) );
145  radioBG->addButton( mAutoArchiveRB );
146 
147  mExpiryTimeNumInput = new KIntNumInput( autoArchiveHBox );
148  mExpiryTimeNumInput->setRange( 1, 500, 1 );
149  mExpiryTimeNumInput->setSliderEnabled( false );
150  mExpiryTimeNumInput->setEnabled( false );
151  mExpiryTimeNumInput->setValue( 7 );
152  mExpiryTimeNumInput->setToolTip(
153  i18nc( "@info:tooltip",
154  "Set the archival age in days, weeks or months" ) );
155  mExpiryTimeNumInput->setWhatsThis(
156  i18nc( "@info:whatsthis",
157  "The age of the events and to-dos to archive. All older items "
158  "will be saved and deleted, the newer will be kept." ) );
159 
160  mExpiryUnitsComboBox = new KComboBox( autoArchiveHBox );
161  mExpiryUnitsComboBox->setToolTip(
162  i18nc( "@info:tooltip",
163  "Set the units for the automatic archive age" ) );
164  mExpiryUnitsComboBox->setWhatsThis(
165  i18nc( "@info:whatsthis",
166  "Select the time units (days, weeks or months) for automatic archiving." ) );
167  // Those items must match the "Expiry Unit" enum in the kcfg file!
168  mExpiryUnitsComboBox->addItem(
169  i18nc( "@item:inlistbox expires in daily units", "Day(s)" ) );
170  mExpiryUnitsComboBox->addItem(
171  i18nc( "@item:inlistbox expiration in weekly units", "Week(s)" ) );
172  mExpiryUnitsComboBox->addItem(
173  i18nc( "@item:inlistbox expiration in monthly units", "Month(s)" ) );
174  mExpiryUnitsComboBox->setEnabled( false );
175 
176  QHBoxLayout *fileLayout = new QHBoxLayout();
177  fileLayout->setMargin( 0 );
178  fileLayout->setSpacing( spacingHint() );
179  QLabel *l = new QLabel( i18nc( "@label", "Archive &file:" ), topFrame );
180  fileLayout->addWidget( l );
181  mArchiveFile = new KUrlRequester( KCalPrefs::instance()->mArchiveFile, topFrame );
182  mArchiveFile->setMode( KFile::File );
183  mArchiveFile->setFilter( i18nc( "@label filter for KUrlRequester", "*.ics|iCalendar Files" ) );
184  mArchiveFile->setToolTip(
185  i18nc( "@info:tooltip",
186  "Set the location of the archive" ) );
187  mArchiveFile->setWhatsThis(
188  i18nc( "@info:whatsthis",
189  "The path of the archive file. The events and to-dos will be appended "
190  "to the specified file, so any events that are already in the file "
191  "will not be modified or deleted. You can later load or merge the "
192  "file like any other calendar. It is not saved in a special "
193  "format, it uses the iCalendar format." ) );
194  mArchiveFile->fileDialog()->setOperationMode( KFileDialog::Saving );
195  l->setBuddy( mArchiveFile->lineEdit() );
196  fileLayout->addWidget( mArchiveFile );
197  topLayout->addLayout( fileLayout );
198 
199 #ifndef KDEPIM_MOBILE_UI
200  QGroupBox *typeBox = new QGroupBox( i18nc( "@title:group", "Type of Items to Archive" ) );
201  typeBox->setWhatsThis(
202  i18nc( "@info:whatsthis",
203  "Here you can select which items "
204  "should be archived. Events are archived if they "
205  "ended before the date given above; to-dos are archived if "
206  "they were finished before the date." ) );
207 
208  topLayout->addWidget( typeBox );
209  QBoxLayout *typeLayout = new QVBoxLayout( typeBox );
210 #else
211  QBoxLayout *typeLayout = new QHBoxLayout();
212  topLayout->addLayout( typeLayout );
213 #endif
214 
215  mEvents = new QCheckBox( i18nc( "@option:check", "Archive &Events" ) );
216  mEvents->setToolTip(
217  i18nc( "@option:check", "Archive or purge events" ) );
218  mEvents->setWhatsThis(
219  i18nc( "@info:whatsthis",
220  "Select this option to archive events if they ended before the date given above." ) );
221  typeLayout->addWidget( mEvents );
222 
223  mTodos = new QCheckBox( i18nc( "@option:check", "Archive Completed &To-dos" ) );
224  mTodos->setToolTip(
225  i18nc( "@option:check", "Archive or purge completed to-dos" ) );
226  mTodos->setWhatsThis(
227  i18nc( "@info:whatsthis",
228  "Select this option to archive to-dos if they were completed "
229  "before the date given above." ) );
230  typeLayout->addWidget( mTodos );
231 
232  mDeleteCb = new QCheckBox( i18nc( "@option:check", "&Delete only, do not save" ), topFrame );
233  mDeleteCb->setToolTip(
234  i18nc( "@info:tooltip",
235  "Purge the old items without saving them" ) );
236  mDeleteCb->setWhatsThis(
237  i18nc( "@info:whatsthis",
238  "Select this option to delete old events and to-dos without saving "
239  "them. It is not possible to recover the events later." ) );
240  topLayout->addWidget( mDeleteCb );
241  connect( mDeleteCb, SIGNAL(toggled(bool)), mArchiveFile, SLOT(setDisabled(bool)) );
242  connect( mDeleteCb, SIGNAL(toggled(bool)), this, SLOT(slotEnableUser1()) );
243  connect( mArchiveFile->lineEdit(), SIGNAL(textChanged(QString)),
244  this, SLOT(slotEnableUser1()) );
245 
246  // Load settings from KCalPrefs
247  mExpiryTimeNumInput->setValue( KCalPrefs::instance()->mExpiryTime );
248  mExpiryUnitsComboBox->setCurrentIndex( KCalPrefs::instance()->mExpiryUnit );
249  mDeleteCb->setChecked( KCalPrefs::instance()->mArchiveAction == KCalPrefs::actionDelete );
250  mEvents->setChecked( KCalPrefs::instance()->mArchiveEvents );
251  mTodos->setChecked( KCalPrefs::instance()->mArchiveTodos );
252 
253  slotEnableUser1();
254 
255  // The focus should go to a useful field by default, not to the top richtext-label
256  if ( KCalPrefs::instance()->mAutoArchive ) {
257  mAutoArchiveRB->setChecked( true );
258  mAutoArchiveRB->setFocus();
259  } else {
260  mArchiveOnceRB->setChecked( true );
261  mArchiveOnceRB->setFocus();
262  }
263  slotActionChanged();
264  connect( this, SIGNAL(user1Clicked()), this, SLOT(slotUser1()) );
265 }
266 
267 ArchiveDialog::~ArchiveDialog()
268 {
269 }
270 
271 void ArchiveDialog::slotEnableUser1()
272 {
273  const bool state = ( mDeleteCb->isChecked() || !mArchiveFile->lineEdit()->text().trimmed().isEmpty() );
274  enableButton( KDialog::User1, state );
275 }
276 
277 void ArchiveDialog::slotActionChanged()
278 {
279  mDateEdit->setEnabled( mArchiveOnceRB->isChecked() );
280  mExpiryTimeNumInput->setEnabled( mAutoArchiveRB->isChecked() );
281  mExpiryUnitsComboBox->setEnabled( mAutoArchiveRB->isChecked() );
282 }
283 
284 // Archive old events
285 void ArchiveDialog::slotUser1()
286 {
287  EventArchiver archiver;
288  connect( &archiver, SIGNAL(eventsDeleted()), this, SLOT(slotEventsDeleted()) );
289 
290  KCalPrefs::instance()->mAutoArchive = mAutoArchiveRB->isChecked();
291  KCalPrefs::instance()->mExpiryTime = mExpiryTimeNumInput->value();
292  KCalPrefs::instance()->mExpiryUnit = mExpiryUnitsComboBox->currentIndex();
293 
294  if ( mDeleteCb->isChecked() ) {
295  KCalPrefs::instance()->mArchiveAction = KCalPrefs::actionDelete;
296  } else {
297  KCalPrefs::instance()->mArchiveAction = KCalPrefs::actionArchive;
298 
299  // Get destination URL
300  KUrl destUrl( mArchiveFile->url() );
301  if ( !destUrl.isValid() ) {
302  KMessageBox::sorry( this, i18nc( "@info", "The archive file name is not valid." ) );
303  return;
304  }
305  // Force filename to be ending with vCalendar extension
306  QString filename = destUrl.fileName();
307  if ( !filename.endsWith( QLatin1String( ".vcs" ) ) &&
308  !filename.endsWith( QLatin1String( ".ics" ) ) ) {
309  filename.append( QLatin1String( ".ics" ) );
310  destUrl.setFileName( filename );
311  }
312 
313  KCalPrefs::instance()->mArchiveFile = destUrl.url();
314  }
315  if ( KCalPrefs::instance()->mAutoArchive ) {
316  archiver.runAuto( mCalendar, mChanger, this, true /*with gui*/);
317  emit autoArchivingSettingsModified();
318  accept();
319  } else {
320  archiver.runOnce( mCalendar, mChanger, mDateEdit->date(), this );
321  accept();
322  }
323 }
324 
325 void ArchiveDialog::slotEventsDeleted()
326 {
327  emit eventsDeleted();
328  if ( !KCalPrefs::instance()->mAutoArchive ) {
329  accept();
330  }
331 }
332 
333 void ArchiveDialog::showWhatsThis()
334 {
335  QWidget *widget = qobject_cast< QWidget * >( sender() );
336  if ( widget && !widget->whatsThis().isEmpty() ) {
337  QWhatsThis::showText( QCursor::pos(), widget->whatsThis() );
338  }
339 }
340 
QWhatsThis::showText
void showText(const QPoint &pos, const QString &text, QWidget *w)
QWidget
QString::append
QString & append(QChar ch)
CalendarSupport::ArchiveDialog::slotActionChanged
void slotActionChanged()
Definition: archivedialog.cpp:277
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
QButtonGroup::addButton
void addButton(QAbstractButton *button)
CalendarSupport::ArchiveDialog::slotEnableUser1
void slotEnableUser1()
Definition: archivedialog.cpp:271
CalendarSupport::ArchiveDialog::ArchiveDialog
ArchiveDialog(const Akonadi::ETMCalendar::Ptr &calendar, Akonadi::IncidenceChanger *changer, QWidget *parent=0)
Definition: archivedialog.cpp:57
QHBoxLayout
KDialog
archivedialog.h
QButtonGroup
kcalprefs.h
QLabel::setBuddy
void setBuddy(QWidget *buddy)
CalendarSupport::ArchiveDialog::slotUser1
void slotUser1()
Definition: archivedialog.cpp:285
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QGroupBox
QWidget::setFocus
void setFocus()
QCheckBox
QVBoxLayout
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QLabel::setText
void setText(const QString &)
eventarchiver.h
CalendarSupport::EventArchiver
This class handles expiring and archiving of events.
Definition: eventarchiver.h:53
QString
QLayout::setMargin
void setMargin(int margin)
CalendarSupport::KCalPrefs::instance
static KCalPrefs * instance()
Get instance of KCalPrefs.
Definition: kcalprefs.cpp:77
QWidget::setContextMenuPolicy
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
QFrame
QAbstractButton::setChecked
void setChecked(bool)
QLabel::setTextInteractionFlags
void setTextInteractionFlags(QFlags< Qt::TextInteractionFlag > flags)
QWidget::setWhatsThis
void setWhatsThis(const QString &)
QCursor::pos
QPoint pos()
QLatin1String
QRadioButton
CalendarSupport::ArchiveDialog::autoArchivingSettingsModified
void autoArchivingSettingsModified()
CalendarSupport::ArchiveDialog::~ArchiveDialog
~ArchiveDialog()
Definition: archivedialog.cpp:267
CalendarSupport::ArchiveDialog::slotEventsDeleted
void slotEventsDeleted()
Definition: archivedialog.cpp:325
QWidget::setToolTip
void setToolTip(const QString &)
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
QLabel
QBoxLayout
QLabel::setWordWrap
void setWordWrap(bool on)
QBoxLayout::setSpacing
void setSpacing(int spacing)
CalendarSupport::ArchiveDialog::eventsDeleted
void eventsDeleted()
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:31:15 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
  • pimprint

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