10#include "archivedialog.h"
11#include "eventarchiver.h"
14#include <Akonadi/IncidenceChanger>
16#include <KDateComboBox>
18#include <KLocalizedString>
20#include <KUrlRequester>
25#include <QButtonGroup>
27#include <QDialogButtonBox>
32#include <QRadioButton>
37using namespace CalendarSupport;
43 setWindowTitle(
i18nc(
"@title:window",
"Archive/Delete Past Events and To-dos"));
48 mUser1Button->setDefault(
true);
50 mUser1Button->setText(
i18nc(
"@action:button",
"&Archive"));
54 auto topFrame =
new QFrame(
this);
55 mainLayout->addWidget(topFrame);
56 mainLayout->addWidget(buttonBox);
59 topLayout->setContentsMargins(0, 0, 0, 0);
60 auto descLabel =
new QLabel(topFrame);
61 descLabel->setText(
xi18nc(
"@info:whatsthis",
62 "Archiving saves old items into the given file and "
63 "then deletes them in the current calendar. If the archive file "
64 "already exists they will be added. "
65 "(<link url=\"#\">How to restore</link>)"));
66 descLabel->setWhatsThis(
i18nc(
"@info:whatsthis",
67 "In order to add an archive to your calendar, use the Merge Calendar "
68 "function. You can view an archive by opening it like you would any "
69 "other calendar. It is not saved in a special format, but as "
72 descLabel->setWordWrap(
true);
74 topLayout->addWidget(descLabel);
81 dateLayout->setContentsMargins(0, 0, 0, 0);
82 mArchiveOnceRB =
new QRadioButton(
i18nc(
"@option:radio",
"Archive now items older than:"), topFrame);
83 mArchiveOnceRB->setToolTip(
i18nc(
"@info:tooltip",
"Enable one time archiving or purging of older items"));
84 mArchiveOnceRB->setWhatsThis(
i18nc(
"@info:whatsthis",
85 "If you check this box, events and to-dos older than the specified age "
86 "will be archived or purged. The items will be archived unless the "
87 "\"Delete only\" option is enabled; else the items will be purged "
90 dateLayout->addWidget(mArchiveOnceRB);
91 radioBG->addButton(mArchiveOnceRB);
93 mDateEdit->setToolTip(
i18nc(
"@info:tooltip",
"Set the one time archiving cut-off date"));
94 mDateEdit->setWhatsThis(
i18nc(
"@info:whatsthis",
95 "The date before which items should be archived. All older events "
96 "and to-dos will be saved and deleted, the newer (and events "
97 "exactly on that date) will be kept."));
98 dateLayout->addWidget(mDateEdit);
99 topLayout->addLayout(dateLayout);
103 auto autoArchiveHBox =
new QWidget(topFrame);
104 auto autoArchiveHBoxHBoxLayout =
new QHBoxLayout(autoArchiveHBox);
105 autoArchiveHBoxHBoxLayout->setContentsMargins(0, 0, 0, 0);
106 topLayout->addWidget(autoArchiveHBox);
107 mAutoArchiveRB =
new QRadioButton(
i18nc(
"@option:radio",
"Automaticall&y archive items older than:"), autoArchiveHBox);
108 mAutoArchiveRB->setToolTip(
i18nc(
"@info:tooltip",
"Enable automatic archiving or purging of older items"));
109 mAutoArchiveRB->setWhatsThis(
i18nc(
"@info:whatsthis",
110 "If this feature is enabled, the application will regularly check if "
111 "events and to-dos have to be archived; this means you will not "
112 "need to use this dialog box again, except to change the settings."));
113 radioBG->addButton(mAutoArchiveRB);
114 autoArchiveHBoxHBoxLayout->addWidget(mAutoArchiveRB);
116 mExpiryTimeNumInput =
new QSpinBox(autoArchiveHBox);
117 autoArchiveHBoxHBoxLayout->addWidget(mExpiryTimeNumInput);
118 mExpiryTimeNumInput->setRange(1, 500);
119 mExpiryTimeNumInput->setSingleStep(1);
121 mExpiryTimeNumInput->setEnabled(
false);
122 mExpiryTimeNumInput->setValue(7);
123 mExpiryTimeNumInput->setToolTip(
i18nc(
"@info:tooltip",
"Set the archival age in days, weeks or months"));
124 mExpiryTimeNumInput->setWhatsThis(
i18nc(
"@info:whatsthis",
125 "The age of the events and to-dos to archive. All older items "
126 "will be saved and deleted, the newer will be kept."));
128 mExpiryUnitsComboBox =
new QComboBox(autoArchiveHBox);
129 autoArchiveHBoxHBoxLayout->addWidget(mExpiryUnitsComboBox);
130 mExpiryUnitsComboBox->setToolTip(
i18nc(
"@info:tooltip",
"Set the units for the automatic archive age"));
131 mExpiryUnitsComboBox->setWhatsThis(
i18nc(
"@info:whatsthis",
"Select the time units (days, weeks or months) for automatic archiving."));
133 mExpiryUnitsComboBox->addItem(
i18nc(
"@item:inlistbox expires in daily units",
"Day(s)"));
134 mExpiryUnitsComboBox->addItem(
i18nc(
"@item:inlistbox expiration in weekly units",
"Week(s)"));
135 mExpiryUnitsComboBox->addItem(
i18nc(
"@item:inlistbox expiration in monthly units",
"Month(s)"));
136 mExpiryUnitsComboBox->setEnabled(
false);
139 fileLayout->setContentsMargins(0, 0, 0, 0);
140 auto l =
new QLabel(
i18nc(
"@label",
"Archive &file:"), topFrame);
141 fileLayout->addWidget(l);
143 mArchiveFile->setMode(KFile::File);
144 mArchiveFile->setNameFilter(
i18nc(
"@label filter for KUrlRequester",
"iCalendar Files (*.ics)"));
145 mArchiveFile->setToolTip(
i18nc(
"@info:tooltip",
"Set the location of the archive"));
146 mArchiveFile->setWhatsThis(
i18nc(
"@info:whatsthis",
147 "The path of the archive file. The events and to-dos will be appended "
148 "to the specified file, so any events that are already in the file "
149 "will not be modified or deleted. You can later load or merge the "
150 "file like any other calendar. It is not saved in a special "
151 "format, it uses the iCalendar format."));
152 l->setBuddy(mArchiveFile->lineEdit());
153 fileLayout->addWidget(mArchiveFile);
154 topLayout->addLayout(fileLayout);
156 auto typeBox =
new QGroupBox(
i18nc(
"@title:group",
"Type of Items to Archive"));
157 typeBox->setWhatsThis(
i18nc(
"@info:whatsthis",
158 "Here you can select which items "
159 "should be archived. Events are archived if they "
160 "ended before the date given above; to-dos are archived if "
161 "they were finished before the date."));
163 topLayout->addWidget(typeBox);
166 mEvents =
new QCheckBox(
i18nc(
"@option:check",
"Archive &Events"));
167 mEvents->setToolTip(
i18nc(
"@option:check",
"Archive or purge events"));
168 mEvents->setWhatsThis(
i18nc(
"@info:whatsthis",
"Select this option to archive events if they ended before the date given above."));
171 mTodos =
new QCheckBox(
i18nc(
"@option:check",
"Archive Completed &To-dos"));
172 mTodos->setToolTip(
i18nc(
"@option:check",
"Archive or purge completed to-dos"));
173 mTodos->setWhatsThis(
i18nc(
"@info:whatsthis",
174 "Select this option to archive to-dos if they were completed "
175 "before the date given above."));
178 mDeleteCb =
new QCheckBox(
i18nc(
"@option:check",
"&Delete only, do not save"), topFrame);
179 mDeleteCb->setToolTip(
i18nc(
"@info:tooltip",
"Purge the old items without saving them"));
180 mDeleteCb->setWhatsThis(
i18nc(
"@info:whatsthis",
181 "Select this option to delete old events and to-dos without saving "
182 "them. It is not possible to recover the events later."));
183 topLayout->addWidget(mDeleteCb);
189 mExpiryTimeNumInput->setValue(KCalPrefs::instance()->mExpiryTime);
190 mExpiryUnitsComboBox->setCurrentIndex(KCalPrefs::instance()->mExpiryUnit);
191 mDeleteCb->setChecked(KCalPrefs::instance()->mArchiveAction == KCalPrefs::actionDelete);
192 mEvents->setChecked(KCalPrefs::instance()->mArchiveEvents);
193 mTodos->setChecked(KCalPrefs::instance()->mArchiveTodos);
198 if (KCalPrefs::instance()->mAutoArchive) {
199 mAutoArchiveRB->setChecked(
true);
200 mAutoArchiveRB->setFocus();
202 mArchiveOnceRB->setChecked(
true);
203 mArchiveOnceRB->setFocus();
209ArchiveDialog::~ArchiveDialog() =
default;
211void ArchiveDialog::slotEnableUser1()
213 const bool state = (mDeleteCb->
isChecked() || !mArchiveFile->
lineEdit()->
text().trimmed().isEmpty());
217void ArchiveDialog::slotActionChanged()
225void ArchiveDialog::slotUser1()
228 connect(&archiver, &EventArchiver::eventsDeleted,
this, &ArchiveDialog::slotEventsDeleted);
230 KCalPrefs::instance()->mAutoArchive = mAutoArchiveRB->
isChecked();
231 KCalPrefs::instance()->mExpiryTime = mExpiryTimeNumInput->
value();
232 KCalPrefs::instance()->mExpiryUnit = mExpiryUnitsComboBox->
currentIndex();
235 KCalPrefs::instance()->mArchiveAction = KCalPrefs::actionDelete;
237 KCalPrefs::instance()->mArchiveAction = KCalPrefs::actionArchive;
240 QUrl destUrl(mArchiveFile->
url());
241 if (!destUrl.isValid()) {
246 QString filename = destUrl.fileName();
248 filename.
append(
".ics"_L1);
250 destUrl.setPath(destUrl.path() + filename);
253 KCalPrefs::instance()->mArchiveFile = destUrl.url();
255 if (KCalPrefs::instance()->mAutoArchive) {
256 archiver.
runAuto(mCalendar, mChanger,
this,
true );
257 Q_EMIT autoArchivingSettingsModified();
260 archiver.
runOnce(mCalendar, mChanger, mDateEdit->
date(),
this);
265void ArchiveDialog::slotEventsDeleted()
268 if (!KCalPrefs::instance()->mAutoArchive) {
273void ArchiveDialog::showWhatsThis()
276 if (widget && !widget->
whatsThis().isEmpty()) {
281#include "moc_archivedialog.cpp"
This class handles expiring and archiving of events.
void runOnce(const Akonadi::ETMCalendar::Ptr &calendar, Akonadi::IncidenceChanger *changer, QDate limitDate, QWidget *widget)
Delete or archive events once.
void runAuto(const Akonadi::ETMCalendar::Ptr &calendar, Akonadi::IncidenceChanger *changer, QWidget *widget, bool withGUI)
Delete or archive events.
KLineEdit * lineEdit() const
QString xi18nc(const char *context, const char *text, const TYPE &arg...)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
void linkActivated(const QString &link)
void textChanged(const QString &text)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
QObject * sender() const const
QString & append(QChar ch)
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QUrl fromLocalFile(const QString &localFile)
void showText(const QPoint &pos, const QString &text, QWidget *w)