Better wording
[kdepim.git] / calendarsupport / archivedialog.cpp
blob409e04c6bfcfe0bf049ec9b8eb4cacf39c39d325
1 /*
2 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
3 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
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.
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.
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.
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.
24 // ArchiveDialog -- archive/delete past events.
26 #include "archivedialog.h"
27 #include "eventarchiver.h"
28 #include "kcalprefs.h"
30 #include <KComboBox>
31 #include <KDateComboBox>
32 #include <KFileDialog>
33 #include <KLineEdit>
34 #include <KLocale>
35 #include <KMessageBox>
36 #include <KNumInput>
37 #include <KTextBrowser>
38 #include <KUrl>
39 #include <KUrlRequester>
40 #include <KVBox>
42 #include <QButtonGroup>
43 #include <QCheckBox>
44 #include <QDateTime>
45 #include <QFrame>
46 #include <QGroupBox>
47 #include <QHBoxLayout>
48 #include <QLabel>
49 #include <QLayout>
50 #include <QRadioButton>
51 #include <QVBoxLayout>
53 using namespace CalendarSupport;
55 ArchiveDialog::ArchiveDialog( CalendarSupport::Calendar *cal,
56 CalendarSupport::IncidenceChanger *changer,
57 QWidget *parent )
58 : KDialog (parent)
60 setCaption( i18nc( "@title:window", "Archive/Delete Past Events and To-dos" ) );
61 setButtons( User1|Cancel );
62 setDefaultButton( User1 );
63 setModal( false );
64 showButtonSeparator( true );
65 setButtonText( User1, i18nc( "@action:button", "&Archive" ) );
66 mCalendar = cal;
67 mChanger = changer;
69 QFrame *topFrame = new QFrame( this );
70 setMainWidget( topFrame );
71 QVBoxLayout *topLayout = new QVBoxLayout( topFrame );
72 topLayout->setSpacing( spacingHint() );
73 #ifndef KDEPIM_MOBILE_UI
74 KTextBrowser *descLabel = new KTextBrowser( topFrame );
75 descLabel->setText(
76 i18nc( "@info:whatsthis",
77 "Archiving saves old items into the given file and "
78 "then deletes them in the current calendar. If the archive file "
79 "already exists they will be added. "
80 "(<link url=\"whatsthis:In order to add an archive "
81 "to your calendar, use the Merge Calendar function. "
82 "You can view an archive by opening it like you would any "
83 "other calendar. It is not saved in a special format, but as "
84 "vCalendar.\">How to restore</link>)" ) );
85 descLabel->setTextInteractionFlags(
86 Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard |
87 Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard );
88 topLayout->addWidget( descLabel );
89 #endif
91 QButtonGroup *radioBG = new QButtonGroup( this );
92 connect( radioBG, SIGNAL(buttonClicked(int)), SLOT(slotActionChanged()) );
94 QHBoxLayout *dateLayout = new QHBoxLayout();
95 dateLayout->setMargin( 0 );
96 mArchiveOnceRB = new QRadioButton( i18nc( "@option:radio",
97 "Archive now items older than:" ),
98 topFrame );
99 mArchiveOnceRB->setToolTip(
100 i18nc( "@info:tooltip",
101 "Enable one time archiving or purging of older items" ) );
102 mArchiveOnceRB->setWhatsThis(
103 i18nc( "@info:whatsthis",
104 "If you check this box, events and to-dos older than the specified age "
105 "will be archived or purged. The items will be archived unless the "
106 "\"Delete only\" option is enabled; else the items will be purged "
107 "and not saved." ) );
109 dateLayout->addWidget( mArchiveOnceRB );
110 radioBG->addButton( mArchiveOnceRB );
111 mDateEdit = new KDateComboBox( topFrame );
112 mDateEdit->setToolTip(
113 i18nc( "@info:tooltip",
114 "Set the one time archiving cut-off date" ) );
115 mDateEdit->setWhatsThis(
116 i18nc( "@info:whatsthis",
117 "The date before which items should be archived. All older events "
118 "and to-dos will be saved and deleted, the newer (and events "
119 "exactly on that date) will be kept." ) );
120 dateLayout->addWidget( mDateEdit );
121 topLayout->addLayout( dateLayout );
123 // Checkbox, numinput and combo for auto-archiving (similar to kmail's
124 // mExpireFolderCheckBox/mReadExpiryTimeNumInput in kmfolderdia.cpp)
125 KHBox *autoArchiveHBox = new KHBox( topFrame );
126 topLayout->addWidget( autoArchiveHBox );
127 mAutoArchiveRB = new QRadioButton( i18nc( "@option:radio",
128 "Automaticall&y archive items older than:" ),
129 autoArchiveHBox );
130 mAutoArchiveRB->setToolTip(
131 i18nc( "@info:tooltip",
132 "Enable automatic archiving or purging of older items" ) );
133 mAutoArchiveRB->setWhatsThis(
134 i18nc( "@info:whatsthis",
135 "If this feature is enabled, the application will regularly check if "
136 "events and to-dos have to be archived; this means you will not "
137 "need to use this dialog box again, except to change the settings." ) );
138 radioBG->addButton( mAutoArchiveRB );
140 mExpiryTimeNumInput = new KIntNumInput( autoArchiveHBox );
141 mExpiryTimeNumInput->setRange( 1, 500, 1 );
142 mExpiryTimeNumInput->setSliderEnabled( false );
143 mExpiryTimeNumInput->setEnabled( false );
144 mExpiryTimeNumInput->setValue( 7 );
145 mExpiryTimeNumInput->setToolTip(
146 i18nc( "@info:tooltip",
147 "Set the archival age in days, weeks or months" ) );
148 mExpiryTimeNumInput->setWhatsThis(
149 i18nc( "@info:whatsthis",
150 "The age of the events and to-dos to archive. All older items "
151 "will be saved and deleted, the newer will be kept." ) );
153 mExpiryUnitsComboBox = new KComboBox( autoArchiveHBox );
154 mExpiryUnitsComboBox->setToolTip(
155 i18nc( "@info:tooltip",
156 "Set the units for the automatic archive age" ) );
157 mExpiryUnitsComboBox->setWhatsThis(
158 i18nc( "@info:whatsthis",
159 "Select the time units (days, weeks or months) for automatic archiving." ) );
160 // Those items must match the "Expiry Unit" enum in the kcfg file!
161 mExpiryUnitsComboBox->addItem(
162 i18nc( "@item:inlistbox expires in daily units", "Day(s)" ) );
163 mExpiryUnitsComboBox->addItem(
164 i18nc( "@item:inlistbox expiration in weekly units", "Week(s)" ) );
165 mExpiryUnitsComboBox->addItem(
166 i18nc( "@item:inlistbox expiration in monthly units", "Month(s)" ) );
167 mExpiryUnitsComboBox->setEnabled( false );
169 QHBoxLayout *fileLayout = new QHBoxLayout();
170 fileLayout->setMargin( 0 );
171 fileLayout->setSpacing( spacingHint() );
172 QLabel *l = new QLabel( i18nc( "@label", "Archive &file:" ), topFrame );
173 fileLayout->addWidget( l );
174 mArchiveFile = new KUrlRequester( KCalPrefs::instance()->mArchiveFile, topFrame );
175 mArchiveFile->setMode( KFile::File );
176 mArchiveFile->setFilter( i18nc( "@label filter for KUrlRequester", "*.ics|iCalendar Files" ) );
177 mArchiveFile->setToolTip(
178 i18nc( "@info:tooltip",
179 "Set the location of the archive" ) );
180 mArchiveFile->setWhatsThis(
181 i18nc( "@info:whatsthis",
182 "The path of the archive file. The events and to-dos will be appended "
183 "to the specified file, so any events that are already in the file "
184 "will not be modified or deleted. You can later load or merge the "
185 "file like any other calendar. It is not saved in a special "
186 "format, it uses the iCalendar format." ) );
187 #ifndef Q_OS_WINCE
188 mArchiveFile->fileDialog()->setOperationMode( KFileDialog::Saving );
189 #else
190 // There is no fileDialog instance availabe on WinCE systems.
191 mArchiveFile->setOperationMode( KFileDialog::Saving );
192 #endif
193 l->setBuddy( mArchiveFile->lineEdit() );
194 fileLayout->addWidget( mArchiveFile );
195 topLayout->addLayout( fileLayout );
197 #ifndef KDEPIM_MOBILE_UI
198 QGroupBox *typeBox = new QGroupBox( i18nc( "@title:group", "Type of Items to Archive" ) );
199 typeBox->setWhatsThis(
200 i18nc( "@info:whatsthis",
201 "Here you can select which items "
202 "should be archived. Events are archived if they "
203 "ended before the date given above; to-dos are archived if "
204 "they were finished before the date." ) );
206 topLayout->addWidget( typeBox );
207 QBoxLayout *typeLayout = new QVBoxLayout( typeBox );
208 #else
209 QBoxLayout *typeLayout = new QHBoxLayout();
210 topLayout->addLayout( typeLayout );
211 #endif
213 mEvents = new QCheckBox( i18nc( "@option:check", "Archive &Events" ) );
214 mEvents->setToolTip(
215 i18nc( "@option:check", "Archive or purge events" ) );
216 mEvents->setWhatsThis(
217 i18nc( "@info:whatsthis",
218 "Select this option to archive events if they ended before the date given above." ) );
219 typeLayout->addWidget( mEvents );
221 mTodos = new QCheckBox( i18nc( "@option:check", "Archive Completed &To-dos" ) );
222 mTodos->setToolTip(
223 i18nc( "@option:check", "Archive or purge completed to-dos" ) );
224 mTodos->setWhatsThis(
225 i18nc( "@info:whatsthis",
226 "Select this option to archive to-dos if they were completed "
227 "before the date given above." ) );
228 typeLayout->addWidget( mTodos );
230 mDeleteCb = new QCheckBox( i18nc( "@option:check", "&Delete only, do not save" ), topFrame );
231 mDeleteCb->setToolTip(
232 i18nc( "@info:tooltip",
233 "Purge the old items without saving them" ) );
234 mDeleteCb->setWhatsThis(
235 i18nc( "@info:whatsthis",
236 "Select this option to delete old events and to-dos without saving "
237 "them. It is not possible to recover the events later." ) );
238 topLayout->addWidget( mDeleteCb );
239 connect( mDeleteCb, SIGNAL(toggled(bool)), mArchiveFile, SLOT(setDisabled(bool)) );
240 connect( mDeleteCb, SIGNAL(toggled(bool)), this, SLOT(slotEnableUser1()) );
241 connect( mArchiveFile->lineEdit(), SIGNAL(textChanged(QString)),
242 this, SLOT(slotEnableUser1()) );
244 // Load settings from KCalPrefs
245 mExpiryTimeNumInput->setValue( KCalPrefs::instance()->mExpiryTime );
246 mExpiryUnitsComboBox->setCurrentIndex( KCalPrefs::instance()->mExpiryUnit );
247 mDeleteCb->setChecked( KCalPrefs::instance()->mArchiveAction == KCalPrefs::actionDelete );
248 mEvents->setChecked( KCalPrefs::instance()->mArchiveEvents );
249 mTodos->setChecked( KCalPrefs::instance()->mArchiveTodos );
251 slotEnableUser1();
253 // The focus should go to a useful field by default, not to the top richtext-label
254 if ( KCalPrefs::instance()->mAutoArchive ) {
255 mAutoArchiveRB->setChecked( true );
256 mAutoArchiveRB->setFocus();
257 } else {
258 mArchiveOnceRB->setChecked( true );
259 mArchiveOnceRB->setFocus();
261 slotActionChanged();
262 connect( this, SIGNAL(user1Clicked()), this, SLOT(slotUser1()) );
265 ArchiveDialog::~ArchiveDialog()
269 void ArchiveDialog::slotEnableUser1()
271 const bool state = ( mDeleteCb->isChecked() || !mArchiveFile->lineEdit()->text().isEmpty() );
272 enableButton( KDialog::User1, state );
275 void ArchiveDialog::slotActionChanged()
277 mDateEdit->setEnabled( mArchiveOnceRB->isChecked() );
278 mExpiryTimeNumInput->setEnabled( mAutoArchiveRB->isChecked() );
279 mExpiryUnitsComboBox->setEnabled( mAutoArchiveRB->isChecked() );
282 // Archive old events
283 void ArchiveDialog::slotUser1()
285 EventArchiver archiver;
286 connect( &archiver, SIGNAL(eventsDeleted()), this, SLOT(slotEventsDeleted()) );
288 KCalPrefs::instance()->mAutoArchive = mAutoArchiveRB->isChecked();
289 KCalPrefs::instance()->mExpiryTime = mExpiryTimeNumInput->value();
290 KCalPrefs::instance()->mExpiryUnit = mExpiryUnitsComboBox->currentIndex();
292 if ( mDeleteCb->isChecked() ) {
293 KCalPrefs::instance()->mArchiveAction = KCalPrefs::actionDelete;
294 } else {
295 KCalPrefs::instance()->mArchiveAction = KCalPrefs::actionArchive;
297 // Get destination URL
298 KUrl destUrl( mArchiveFile->url() );
299 if ( !destUrl.isValid() ) {
300 KMessageBox::sorry( this, i18nc( "@info", "The archive file name is not valid." ) );
301 return;
303 // Force filename to be ending with vCalendar extension
304 QString filename = destUrl.fileName();
305 if ( !filename.endsWith( QLatin1String( ".vcs" ) ) &&
306 !filename.endsWith( QLatin1String( ".ics" ) ) ) {
307 filename.append( QLatin1String( ".ics" ) );
308 destUrl.setFileName( filename );
311 KCalPrefs::instance()->mArchiveFile = destUrl.url();
313 if ( KCalPrefs::instance()->mAutoArchive ) {
314 archiver.runAuto( mCalendar, mChanger, this, true /*with gui*/);
315 emit autoArchivingSettingsModified();
316 accept();
317 } else {
318 archiver.runOnce( mCalendar, mChanger, mDateEdit->date(), this );
319 accept();
323 void ArchiveDialog::slotEventsDeleted()
325 emit eventsDeleted();
326 if ( !KCalPrefs::instance()->mAutoArchive ) {
327 accept();
331 #include "archivedialog.moc"