00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
#include <qlabel.h>
00027
#include <qlayout.h>
00028
#include <qdatetime.h>
00029
#include <qcheckbox.h>
00030
#include <qwhatsthis.h>
00031
00032
#include <kdebug.h>
00033
#include <klocale.h>
00034
#include <kurlrequester.h>
00035
#include <kmessagebox.h>
00036
#include <kfiledialog.h>
00037
#include <kurl.h>
00038
#include <klineedit.h>
00039
#include <kactivelabel.h>
00040
00041
#include <libkdepim/kdateedit.h>
00042
00043
#include "koprefs.h"
00044
00045
#include "archivedialog.h"
00046
#include "eventarchiver.h"
00047
#include <knuminput.h>
00048
#include <qbuttongroup.h>
00049
#include <qradiobutton.h>
00050
#include "archivedialog.moc"
00051
00052 ArchiveDialog::ArchiveDialog(Calendar *cal,
QWidget *parent,
const char *name)
00053 : KDialogBase (Plain,i18n(
"Archive/Delete Past Events"),
00054 User1|Cancel,User1,parent,name,false,true,
00055 i18n(
"&Archive"))
00056 {
00057 mCalendar = cal;
00058
00059
QFrame *topFrame = plainPage();
00060
QVBoxLayout *topLayout =
new QVBoxLayout(topFrame);
00061 topLayout->setSpacing(spacingHint());
00062
00063 KActiveLabel *descLabel =
new KActiveLabel(
00064 i18n(
"Archiving saves old events into the given file and "
00065
"then deletes them in the current calendar. If the archive file "
00066
"already exists they will be added. "
00067
"(<a href=\"whatsthis:In order to add an archive "
00068
"to your calendar, use the "Merge Calendar" function. "
00069
"You can view an archive by opening it in KOrganizer like any "
00070
"other calendar. It is not saved in a special format, but as "
00071
"vCalendar.\">How to restore</a>)"),
00072 topFrame);
00073 topLayout->addWidget(descLabel);
00074
00075
QButtonGroup* radioBG =
new QButtonGroup(
this );
00076 radioBG->hide();
00077 connect( radioBG, SIGNAL( clicked(
int ) ), SLOT( slotActionChanged() ) );
00078
00079
QHBoxLayout *dateLayout =
new QHBoxLayout(0);
00080 mArchiveOnceRB =
new QRadioButton(i18n(
"Archive now events older than:"),topFrame);
00081 dateLayout->addWidget(mArchiveOnceRB);
00082 radioBG->insert(mArchiveOnceRB);
00083 mDateEdit =
new KDateEdit(topFrame);
00084 QWhatsThis::add(mDateEdit,
00085 i18n(
"The date before which events should be archived. All older events will "
00086
"be saved and deleted, the newer (and events exactly on that date) will be kept."));
00087 dateLayout->addWidget(mDateEdit);
00088 topLayout->addLayout(dateLayout);
00089
00090
00091
00092
QHBox* autoArchiveHBox =
new QHBox(topFrame);
00093 topLayout->addWidget(autoArchiveHBox);
00094 mAutoArchiveRB =
new QRadioButton(i18n(
"Automaticall&y archive events older than:"), autoArchiveHBox);
00095 radioBG->insert(mAutoArchiveRB);
00096 QWhatsThis::add(mAutoArchiveRB,
00097 i18n(
"If this feature is enabled, KOrganizer will regularly check if events have to be archived; "
00098
"this means you will not need to use this dialog box again, except to change the settings."));
00099
00100 mExpiryTimeNumInput =
new KIntNumInput(autoArchiveHBox);
00101 mExpiryTimeNumInput->setRange(1, 500, 1,
false);
00102 mExpiryTimeNumInput->setEnabled(
false);
00103 mExpiryTimeNumInput->setValue(7);
00104 QWhatsThis::add(mExpiryTimeNumInput,
00105 i18n(
"The age of the events to archive. All older events "
00106
"will be saved and deleted, the newer will be kept."));
00107
00108 mExpiryUnitsComboBox =
new QComboBox(autoArchiveHBox);
00109
00110 mExpiryUnitsComboBox->insertItem(i18n(
"Day(s)"));
00111 mExpiryUnitsComboBox->insertItem(i18n(
"Week(s)"));
00112 mExpiryUnitsComboBox->insertItem(i18n(
"Month(s)"));
00113 mExpiryUnitsComboBox->setEnabled(
false);
00114
00115
QHBoxLayout *fileLayout =
new QHBoxLayout(0);
00116 fileLayout->setSpacing(spacingHint());
00117
QLabel *l =
new QLabel(i18n(
"Archive &file:"),topFrame);
00118 fileLayout->addWidget(l);
00119 mArchiveFile =
new KURLRequester(KOPrefs::instance()->mArchiveFile,topFrame);
00120 mArchiveFile->setMode(KFile::File);
00121 mArchiveFile->setFilter(i18n(
"*.ics|ICalendars"));
00122 QWhatsThis::add(mArchiveFile,
00123 i18n(
"The path of the archive. The events will be added to the "
00124
"archive file, so any events that are already in the file "
00125
"will not be modified or deleted. You can later load or merge the "
00126
"file like any other calendar. It is not saved in a special "
00127
"format, it uses the vCalendar format. "));
00128 l->setBuddy(mArchiveFile->lineEdit());
00129 fileLayout->addWidget(mArchiveFile);
00130 topLayout->addLayout(fileLayout);
00131
00132 mDeleteCb =
new QCheckBox(i18n(
"&Delete only, do not save"),
00133 topFrame);
00134 QWhatsThis::add(mDeleteCb,
00135 i18n(
"Select this option to delete old events without saving them. "
00136
"It is not possible to recover the events later."));
00137 topLayout->addWidget(mDeleteCb);
00138 connect(mDeleteCb, SIGNAL(toggled(
bool)), mArchiveFile, SLOT(setDisabled(
bool)));
00139 connect(mDeleteCb, SIGNAL(toggled(
bool)),
this, SLOT(slotEnableUser1()));
00140 connect(mArchiveFile->lineEdit(),SIGNAL(textChanged (
const QString & )),
00141
this,SLOT(slotEnableUser1()));
00142
00143
00144 mExpiryTimeNumInput->setValue( KOPrefs::instance()->mExpiryTime );
00145 mExpiryUnitsComboBox->setCurrentItem( KOPrefs::instance()->mExpiryUnit );
00146 mDeleteCb->setChecked( KOPrefs::instance()->mArchiveAction == KOPrefs::actionDelete );
00147
00148 slotEnableUser1();
00149
00150
00151
if ( KOPrefs::instance()->mAutoArchive ) {
00152 mAutoArchiveRB->setChecked(
true );
00153 mAutoArchiveRB->setFocus();
00154 }
else {
00155 mArchiveOnceRB->setChecked(
true );
00156 mArchiveOnceRB->setFocus();
00157 }
00158 slotActionChanged();
00159 }
00160
00161 ArchiveDialog::~ArchiveDialog()
00162 {
00163 }
00164
00165
void ArchiveDialog::slotEnableUser1()
00166 {
00167
bool state = ( mDeleteCb->isChecked() ||
00168 !mArchiveFile->lineEdit()->text().isEmpty() );
00169 enableButton(KDialogBase::User1,state);
00170 }
00171
00172
void ArchiveDialog::slotActionChanged()
00173 {
00174 mDateEdit->setEnabled( mArchiveOnceRB->isChecked() );
00175 mExpiryTimeNumInput->setEnabled( mAutoArchiveRB->isChecked() );
00176 mExpiryUnitsComboBox->setEnabled( mAutoArchiveRB->isChecked() );
00177 }
00178
00179
00180
void ArchiveDialog::slotUser1()
00181 {
00182
EventArchiver archiver;
00183 connect( &archiver, SIGNAL( eventsDeleted() ),
this, SLOT( slotEventsDeleted() ) );
00184
00185 KOPrefs::instance()->mAutoArchive = mAutoArchiveRB->isChecked();
00186 KOPrefs::instance()->mExpiryTime = mExpiryTimeNumInput->value();
00187 KOPrefs::instance()->mExpiryUnit = mExpiryUnitsComboBox->currentItem();
00188
00189
if (mDeleteCb->isChecked()) {
00190 KOPrefs::instance()->mArchiveAction = KOPrefs::actionDelete;
00191 }
else {
00192 KOPrefs::instance()->mArchiveAction = KOPrefs::actionArchive;
00193
00194
00195 KURL destUrl( mArchiveFile->url() );
00196
if ( !destUrl.isValid() ) {
00197 KMessageBox::sorry(
this,i18n(
"The archive file name is not valid.\n"));
00198
return;
00199 }
00200
00201
QString filename = destUrl.fileName();
00202
if (!filename.endsWith(
".vcs") && !filename.endsWith(
".ics")) {
00203 filename.append(
".ics");
00204 destUrl.setFileName(filename);
00205 }
00206
00207 KOPrefs::instance()->mArchiveFile = destUrl.url();
00208 }
00209
if ( KOPrefs::instance()->mAutoArchive ) {
00210 archiver.
runAuto( mCalendar,
this,
true );
00211 emit autoArchivingSettingsModified();
00212 accept();
00213 }
00214
else
00215 archiver.
runOnce( mCalendar, mDateEdit->date(),
this );
00216 }
00217
00218
void ArchiveDialog::slotEventsDeleted()
00219 {
00220 emit eventsDeleted();
00221
if ( !KOPrefs::instance()->mAutoArchive )
00222 accept();
00223 }