29 #include <tqdatetime.h>
30 #include <tqcheckbox.h>
31 #include <tqwhatsthis.h>
32 #include <tqhgroupbox.h>
35 #include <tdelocale.h>
36 #include <kurlrequester.h>
37 #include <tdemessagebox.h>
38 #include <tdefiledialog.h>
40 #include <klineedit.h>
41 #include <kactivelabel.h>
43 #include <libtdepim/kdateedit.h>
47 #include "archivedialog.h"
48 #include "eventarchiver.h"
49 #include <knuminput.h>
50 #include <tqbuttongroup.h>
51 #include <tqradiobutton.h>
52 #include "archivedialog.moc"
54 ArchiveDialog::ArchiveDialog(
Calendar *cal,TQWidget *parent,
const char *name)
55 : KDialogBase (Plain,i18n(
"Archive/Delete Past Events and To-dos"),
56 User1|Cancel,User1,parent,name,false,true,
61 TQFrame *topFrame = plainPage();
62 TQVBoxLayout *topLayout =
new TQVBoxLayout(topFrame);
63 topLayout->setSpacing(spacingHint());
65 KActiveLabel *descLabel =
new KActiveLabel(
66 i18n(
"Archiving saves old items into the given file and "
67 "then deletes them in the current calendar. If the archive file "
68 "already exists they will be added. "
69 "(<a href=\"whatsthis:In order to add an archive "
70 "to your calendar, use the "Merge Calendar" function. "
71 "You can view an archive by opening it in KOrganizer like any "
72 "other calendar. It is not saved in a special format, but as "
73 "vCalendar.\">How to restore</a>)"),
75 topLayout->addWidget(descLabel);
77 TQButtonGroup* radioBG =
new TQButtonGroup(
this );
79 connect( radioBG, TQ_SIGNAL( clicked(
int ) ), TQ_SLOT( slotActionChanged() ) );
81 TQHBoxLayout *dateLayout =
new TQHBoxLayout(0);
82 mArchiveOnceRB =
new TQRadioButton(i18n(
"Archive now items older than:"),topFrame);
83 dateLayout->addWidget(mArchiveOnceRB);
84 radioBG->insert(mArchiveOnceRB);
85 mDateEdit =
new KDateEdit(topFrame);
86 TQWhatsThis::add(mDateEdit,
87 i18n(
"The date before which items should be archived. All older events and to-dos will "
88 "be saved and deleted, the newer (and events exactly on that date) will be kept."));
89 dateLayout->addWidget(mDateEdit);
90 topLayout->addLayout(dateLayout);
94 TQHBox* autoArchiveHBox =
new TQHBox(topFrame);
95 topLayout->addWidget(autoArchiveHBox);
96 mAutoArchiveRB =
new TQRadioButton(i18n(
"Automaticall&y archive items older than:"), autoArchiveHBox);
97 radioBG->insert(mAutoArchiveRB);
98 TQWhatsThis::add(mAutoArchiveRB,
99 i18n(
"If this feature is enabled, KOrganizer will regularly check if events and to-dos have to be archived; "
100 "this means you will not need to use this dialog box again, except to change the settings."));
102 mExpiryTimeNumInput =
new KIntNumInput(autoArchiveHBox);
103 mExpiryTimeNumInput->setRange(1, 500, 1,
false);
104 mExpiryTimeNumInput->setEnabled(
false);
105 mExpiryTimeNumInput->setValue(7);
106 TQWhatsThis::add(mExpiryTimeNumInput,
107 i18n(
"The age of the events and to-dos to archive. All older items "
108 "will be saved and deleted, the newer will be kept."));
110 mExpiryUnitsComboBox =
new TQComboBox(autoArchiveHBox);
112 mExpiryUnitsComboBox->insertItem(i18n(
"Day(s)"));
113 mExpiryUnitsComboBox->insertItem(i18n(
"Week(s)"));
114 mExpiryUnitsComboBox->insertItem(i18n(
"Month(s)"));
115 mExpiryUnitsComboBox->setEnabled(
false);
117 TQHBoxLayout *fileLayout =
new TQHBoxLayout(0);
118 fileLayout->setSpacing(spacingHint());
119 TQLabel *l =
new TQLabel(i18n(
"Archive &file:"),topFrame);
120 fileLayout->addWidget(l);
121 mArchiveFile =
new KURLRequester(KOPrefs::instance()->mArchiveFile,topFrame);
122 mArchiveFile->setMode(KFile::File);
123 mArchiveFile->setFilter(i18n(
"*.ics|iCalendar Files"));
124 TQWhatsThis::add(mArchiveFile,
125 i18n(
"The path of the archive. The events and to-dos will be added to the "
126 "archive file, so any events that are already in the file "
127 "will not be modified or deleted. You can later load or merge the "
128 "file like any other calendar. It is not saved in a special "
129 "format, it uses the iCalendar format. "));
130 l->setBuddy(mArchiveFile->lineEdit());
131 fileLayout->addWidget(mArchiveFile);
132 topLayout->addLayout(fileLayout);
134 TQHGroupBox *typeBox =
new TQHGroupBox( i18n(
"Type of Items to Archive"),
136 mEvents =
new TQCheckBox( i18n(
"&Events"), typeBox );
137 mTodos =
new TQCheckBox( i18n(
"Completed &To-dos"), typeBox );
138 topLayout->addWidget( typeBox );
139 TQWhatsThis::add( typeBox, i18n(
"Here you can select which items "
140 "should be archived. Events are archived if they "
141 "ended before the date given above; to-dos are archived if "
142 "they were finished before the date.") );
144 mDeleteCb =
new TQCheckBox(i18n(
"&Delete only, do not save"),
146 TQWhatsThis::add(mDeleteCb,
147 i18n(
"Select this option to delete old events and to-dos without saving them. "
148 "It is not possible to recover the events later."));
149 topLayout->addWidget(mDeleteCb);
150 connect(mDeleteCb, TQ_SIGNAL(toggled(
bool)), mArchiveFile, TQ_SLOT(setDisabled(
bool)));
151 connect(mDeleteCb, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(slotEnableUser1()));
152 connect(mArchiveFile->lineEdit(),TQ_SIGNAL(textChanged (
const TQString & )),
153 this,TQ_SLOT(slotEnableUser1()));
156 mExpiryTimeNumInput->setValue( KOPrefs::instance()->mExpiryTime );
157 mExpiryUnitsComboBox->setCurrentItem( KOPrefs::instance()->mExpiryUnit );
158 mDeleteCb->setChecked( KOPrefs::instance()->mArchiveAction == KOPrefs::actionDelete );
159 mEvents->setChecked( KOPrefs::instance()->mArchiveEvents );
160 mTodos->setChecked( KOPrefs::instance()->mArchiveTodos );
165 if ( KOPrefs::instance()->mAutoArchive ) {
166 mAutoArchiveRB->setChecked(
true );
167 mAutoArchiveRB->setFocus();
169 mArchiveOnceRB->setChecked(
true );
170 mArchiveOnceRB->setFocus();
175 ArchiveDialog::~ArchiveDialog()
179 void ArchiveDialog::slotEnableUser1()
181 bool state = ( mDeleteCb->isChecked() ||
182 !mArchiveFile->lineEdit()->text().isEmpty() );
183 enableButton(KDialogBase::User1,state);
186 void ArchiveDialog::slotActionChanged()
188 mDateEdit->setEnabled( mArchiveOnceRB->isChecked() );
189 mExpiryTimeNumInput->setEnabled( mAutoArchiveRB->isChecked() );
190 mExpiryUnitsComboBox->setEnabled( mAutoArchiveRB->isChecked() );
194 void ArchiveDialog::slotUser1()
197 connect( &archiver, TQ_SIGNAL( eventsDeleted() ),
this, TQ_SLOT( slotEventsDeleted() ) );
199 KOPrefs::instance()->mAutoArchive = mAutoArchiveRB->isChecked();
200 KOPrefs::instance()->mExpiryTime = mExpiryTimeNumInput->value();
201 KOPrefs::instance()->mExpiryUnit = mExpiryUnitsComboBox->currentItem();
203 if (mDeleteCb->isChecked()) {
204 KOPrefs::instance()->mArchiveAction = KOPrefs::actionDelete;
206 KOPrefs::instance()->mArchiveAction = KOPrefs::actionArchive;
209 KURL destUrl( mArchiveFile->url() );
210 if ( !destUrl.isValid() ) {
211 KMessageBox::sorry(
this,i18n(
"The archive file name is not valid.\n"));
215 TQString filename = destUrl.fileName();
216 if (!filename.endsWith(
".vcs") && !filename.endsWith(
".ics")) {
217 filename.append(
".ics");
218 destUrl.setFileName(filename);
221 KOPrefs::instance()->mArchiveFile = destUrl.url();
223 if ( KOPrefs::instance()->mAutoArchive ) {
224 archiver.
runAuto( mCalendar,
this,
true );
225 emit autoArchivingSettingsModified();
229 archiver.
runOnce( mCalendar, mDateEdit->date(),
this );
232 void ArchiveDialog::slotEventsDeleted()
234 emit eventsDeleted();
235 if ( !KOPrefs::instance()->mAutoArchive )
This class handles expiring and archiving of events.
void runOnce(Calendar *calendar, const TQDate &limitDate, TQWidget *widget)
Delete or archive events once.
void runAuto(Calendar *calendar, TQWidget *widget, bool withGUI)
Delete or archive events.