30 #include <Akonadi/Calendar/IncidenceChanger>
33 #include <KDateComboBox>
34 #include <KFileDialog>
37 #include <KMessageBox>
40 #include <KUrlRequester>
43 #include <QButtonGroup>
48 #include <QHBoxLayout>
51 #include <QRadioButton>
52 #include <QVBoxLayout>
55 using namespace CalendarSupport;
58 Akonadi::IncidenceChanger *changer,
62 setCaption( i18nc(
"@title:window",
"Archive/Delete Past Events and To-dos" ) );
63 setButtons( User1|Cancel );
64 setDefaultButton( User1 );
66 showButtonSeparator(
true );
67 setButtonText( User1, i18nc(
"@action:button",
"&Archive" ) );
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 );
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 "
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()) );
97 QButtonGroup *radioBG =
new QButtonGroup(
this );
100 QHBoxLayout *dateLayout =
new QHBoxLayout();
101 dateLayout->setMargin( 0 );
102 mArchiveOnceRB =
new QRadioButton( i18nc(
"@option:radio",
103 "Archive now items older than:" ),
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." ) );
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 );
131 KHBox *autoArchiveHBox =
new KHBox( topFrame );
132 topLayout->addWidget( autoArchiveHBox );
133 mAutoArchiveRB =
new QRadioButton( i18nc(
"@option:radio",
134 "Automaticall&y archive items older than:" ),
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 );
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." ) );
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." ) );
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 );
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 );
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." ) );
194 mArchiveFile->fileDialog()->setOperationMode( KFileDialog::Saving );
197 mArchiveFile->setOperationMode( KFileDialog::Saving );
199 l->setBuddy( mArchiveFile->lineEdit() );
200 fileLayout->addWidget( mArchiveFile );
201 topLayout->addLayout( fileLayout );
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." ) );
212 topLayout->addWidget( typeBox );
213 QBoxLayout *typeLayout =
new QVBoxLayout( typeBox );
215 QBoxLayout *typeLayout =
new QHBoxLayout();
216 topLayout->addLayout( typeLayout );
219 mEvents =
new QCheckBox( i18nc(
"@option:check",
"Archive &Events" ) );
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 );
227 mTodos =
new QCheckBox( i18nc(
"@option:check",
"Archive Completed &To-dos" ) );
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 );
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)),
261 mAutoArchiveRB->setChecked(
true );
262 mAutoArchiveRB->setFocus();
264 mArchiveOnceRB->setChecked(
true );
265 mArchiveOnceRB->setFocus();
268 connect(
this, SIGNAL(user1Clicked()),
this, SLOT(
slotUser1()) );
277 const bool state = ( mDeleteCb->isChecked() || !mArchiveFile->lineEdit()->text().isEmpty() );
278 enableButton( KDialog::User1, state );
283 mDateEdit->setEnabled( mArchiveOnceRB->isChecked() );
284 mExpiryTimeNumInput->setEnabled( mAutoArchiveRB->isChecked() );
285 mExpiryUnitsComboBox->setEnabled( mAutoArchiveRB->isChecked() );
298 if ( mDeleteCb->isChecked() ) {
304 KUrl destUrl( mArchiveFile->url() );
305 if ( !destUrl.isValid() ) {
306 KMessageBox::sorry(
this, i18nc(
"@info",
"The archive file name is not valid." ) );
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 );
320 archiver.
runAuto( mCalendar, mChanger,
this,
true );
324 archiver.
runOnce( mCalendar, mChanger, mDateEdit->date(), this );
337 void ArchiveDialog::showWhatsThis()
340 if ( widget && !widget->whatsThis().isEmpty() ) {
341 QWhatsThis::showText( QCursor::pos(), widget->whatsThis() );
345 #include "archivedialog.moc"
void runAuto(const Akonadi::ETMCalendar::Ptr &calendar, Akonadi::IncidenceChanger *changer, QWidget *widget, bool withGUI)
Delete or archive events.
ArchiveDialog(const Akonadi::ETMCalendar::Ptr &calendar, Akonadi::IncidenceChanger *changer, QWidget *parent=0)
This class handles expiring and archiving of events.
static KCalPrefs * instance()
Get instance of KCalPrefs.
void autoArchivingSettingsModified()
void runOnce(const Akonadi::ETMCalendar::Ptr &calendar, Akonadi::IncidenceChanger *changer, const QDate &limitDate, QWidget *widget)
Delete or archive events once.