archivedialog.cpp
00001 /* 00002 This file is part of KOrganizer. 00003 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 00004 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 00025 // ArchiveDialog -- archive/delete past events. 00026 00027 #include <tqlabel.h> 00028 #include <tqlayout.h> 00029 #include <tqdatetime.h> 00030 #include <tqcheckbox.h> 00031 #include <tqwhatsthis.h> 00032 #include <tqhgroupbox.h> 00033 00034 #include <kdebug.h> 00035 #include <klocale.h> 00036 #include <kurlrequester.h> 00037 #include <kmessagebox.h> 00038 #include <kfiledialog.h> 00039 #include <kurl.h> 00040 #include <klineedit.h> 00041 #include <kactivelabel.h> 00042 00043 #include <libkdepim/kdateedit.h> 00044 00045 #include "koprefs.h" 00046 00047 #include "archivedialog.h" 00048 #include "eventarchiver.h" 00049 #include <knuminput.h> 00050 #include <tqbuttongroup.h> 00051 #include <tqradiobutton.h> 00052 #include "archivedialog.moc" 00053 00054 ArchiveDialog::ArchiveDialog(Calendar *cal,TQWidget *parent, const char *name) 00055 : KDialogBase (Plain,i18n("Archive/Delete Past Events and To-dos"), 00056 User1|Cancel,User1,parent,name,false,true, 00057 i18n("&Archive")) 00058 { 00059 mCalendar = cal; 00060 00061 TQFrame *topFrame = plainPage(); 00062 TQVBoxLayout *topLayout = new TQVBoxLayout(topFrame); 00063 topLayout->setSpacing(spacingHint()); 00064 00065 KActiveLabel *descLabel = new KActiveLabel( 00066 i18n("Archiving saves old items into the given file and " 00067 "then deletes them in the current calendar. If the archive file " 00068 "already exists they will be added. " 00069 "(<a href=\"whatsthis:In order to add an archive " 00070 "to your calendar, use the "Merge Calendar" function. " 00071 "You can view an archive by opening it in KOrganizer like any " 00072 "other calendar. It is not saved in a special format, but as " 00073 "vCalendar.\">How to restore</a>)"), 00074 topFrame); 00075 topLayout->addWidget(descLabel); 00076 00077 TQButtonGroup* radioBG = new TQButtonGroup( this ); 00078 radioBG->hide(); // just for the exclusive behavior 00079 connect( radioBG, TQT_SIGNAL( clicked( int ) ), TQT_SLOT( slotActionChanged() ) ); 00080 00081 TQHBoxLayout *dateLayout = new TQHBoxLayout(0); 00082 mArchiveOnceRB = new TQRadioButton(i18n("Archive now items older than:"),topFrame); 00083 dateLayout->addWidget(mArchiveOnceRB); 00084 radioBG->insert(mArchiveOnceRB); 00085 mDateEdit = new KDateEdit(topFrame); 00086 TQWhatsThis::add(mDateEdit, 00087 i18n("The date before which items should be archived. All older events and to-dos will " 00088 "be saved and deleted, the newer (and events exactly on that date) will be kept.")); 00089 dateLayout->addWidget(mDateEdit); 00090 topLayout->addLayout(dateLayout); 00091 00092 // Checkbox, numinput and combo for auto-archiving 00093 // (similar to kmail's mExpireFolderCheckBox/mReadExpiryTimeNumInput in kmfolderdia.cpp) 00094 TQHBox* autoArchiveHBox = new TQHBox(topFrame); 00095 topLayout->addWidget(autoArchiveHBox); 00096 mAutoArchiveRB = new TQRadioButton(i18n("Automaticall&y archive items older than:"), autoArchiveHBox); 00097 radioBG->insert(mAutoArchiveRB); 00098 TQWhatsThis::add(mAutoArchiveRB, 00099 i18n("If this feature is enabled, KOrganizer will regularly check if events and to-dos have to be archived; " 00100 "this means you will not need to use this dialog box again, except to change the settings.")); 00101 00102 mExpiryTimeNumInput = new KIntNumInput(autoArchiveHBox); 00103 mExpiryTimeNumInput->setRange(1, 500, 1, false); 00104 mExpiryTimeNumInput->setEnabled(false); 00105 mExpiryTimeNumInput->setValue(7); 00106 TQWhatsThis::add(mExpiryTimeNumInput, 00107 i18n("The age of the events and to-dos to archive. All older items " 00108 "will be saved and deleted, the newer will be kept.")); 00109 00110 mExpiryUnitsComboBox = new TQComboBox(autoArchiveHBox); 00111 // Those items must match the "Expiry Unit" enum in the kcfg file! 00112 mExpiryUnitsComboBox->insertItem(i18n("Day(s)")); 00113 mExpiryUnitsComboBox->insertItem(i18n("Week(s)")); 00114 mExpiryUnitsComboBox->insertItem(i18n("Month(s)")); 00115 mExpiryUnitsComboBox->setEnabled(false); 00116 00117 TQHBoxLayout *fileLayout = new TQHBoxLayout(0); 00118 fileLayout->setSpacing(spacingHint()); 00119 TQLabel *l = new TQLabel(i18n("Archive &file:"),topFrame); 00120 fileLayout->addWidget(l); 00121 mArchiveFile = new KURLRequester(KOPrefs::instance()->mArchiveFile,topFrame); 00122 mArchiveFile->setMode(KFile::File); 00123 mArchiveFile->setFilter(i18n("*.ics|iCalendar Files")); 00124 TQWhatsThis::add(mArchiveFile, 00125 i18n("The path of the archive. The events and to-dos will be added to the " 00126 "archive file, so any events that are already in the file " 00127 "will not be modified or deleted. You can later load or merge the " 00128 "file like any other calendar. It is not saved in a special " 00129 "format, it uses the iCalendar format. ")); 00130 l->setBuddy(mArchiveFile->lineEdit()); 00131 fileLayout->addWidget(mArchiveFile); 00132 topLayout->addLayout(fileLayout); 00133 00134 TQHGroupBox *typeBox = new TQHGroupBox( i18n("Type of Items to Archive"), 00135 topFrame); 00136 mEvents = new TQCheckBox( i18n("&Events"), typeBox ); 00137 mTodos = new TQCheckBox( i18n("Completed &To-dos"), typeBox ); 00138 topLayout->addWidget( typeBox ); 00139 TQWhatsThis::add( typeBox, i18n("Here you can select which items " 00140 "should be archived. Events are archived if they " 00141 "ended before the date given above; to-dos are archived if " 00142 "they were finished before the date.") ); 00143 00144 mDeleteCb = new TQCheckBox(i18n("&Delete only, do not save"), 00145 topFrame); 00146 TQWhatsThis::add(mDeleteCb, 00147 i18n("Select this option to delete old events and to-dos without saving them. " 00148 "It is not possible to recover the events later.")); 00149 topLayout->addWidget(mDeleteCb); 00150 connect(mDeleteCb, TQT_SIGNAL(toggled(bool)), mArchiveFile, TQT_SLOT(setDisabled(bool))); 00151 connect(mDeleteCb, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotEnableUser1())); 00152 connect(mArchiveFile->lineEdit(),TQT_SIGNAL(textChanged ( const TQString & )), 00153 this,TQT_SLOT(slotEnableUser1())); 00154 00155 // Load settings from KOPrefs 00156 mExpiryTimeNumInput->setValue( KOPrefs::instance()->mExpiryTime ); 00157 mExpiryUnitsComboBox->setCurrentItem( KOPrefs::instance()->mExpiryUnit ); 00158 mDeleteCb->setChecked( KOPrefs::instance()->mArchiveAction == KOPrefs::actionDelete ); 00159 mEvents->setChecked( KOPrefs::instance()->mArchiveEvents ); 00160 mTodos->setChecked( KOPrefs::instance()->mArchiveTodos ); 00161 00162 slotEnableUser1(); 00163 00164 // The focus should go to a useful field by default, not to the top richtext-label 00165 if ( KOPrefs::instance()->mAutoArchive ) { 00166 mAutoArchiveRB->setChecked( true ); 00167 mAutoArchiveRB->setFocus(); 00168 } else { 00169 mArchiveOnceRB->setChecked( true ); 00170 mArchiveOnceRB->setFocus(); 00171 } 00172 slotActionChanged(); 00173 } 00174 00175 ArchiveDialog::~ArchiveDialog() 00176 { 00177 } 00178 00179 void ArchiveDialog::slotEnableUser1() 00180 { 00181 bool state = ( mDeleteCb->isChecked() || 00182 !mArchiveFile->lineEdit()->text().isEmpty() ); 00183 enableButton(KDialogBase::User1,state); 00184 } 00185 00186 void ArchiveDialog::slotActionChanged() 00187 { 00188 mDateEdit->setEnabled( mArchiveOnceRB->isChecked() ); 00189 mExpiryTimeNumInput->setEnabled( mAutoArchiveRB->isChecked() ); 00190 mExpiryUnitsComboBox->setEnabled( mAutoArchiveRB->isChecked() ); 00191 } 00192 00193 // Archive old events 00194 void ArchiveDialog::slotUser1() 00195 { 00196 EventArchiver archiver; 00197 connect( &archiver, TQT_SIGNAL( eventsDeleted() ), this, TQT_SLOT( slotEventsDeleted() ) ); 00198 00199 KOPrefs::instance()->mAutoArchive = mAutoArchiveRB->isChecked(); 00200 KOPrefs::instance()->mExpiryTime = mExpiryTimeNumInput->value(); 00201 KOPrefs::instance()->mExpiryUnit = mExpiryUnitsComboBox->currentItem(); 00202 00203 if (mDeleteCb->isChecked()) { 00204 KOPrefs::instance()->mArchiveAction = KOPrefs::actionDelete; 00205 } else { 00206 KOPrefs::instance()->mArchiveAction = KOPrefs::actionArchive; 00207 00208 // Get destination URL 00209 KURL destUrl( mArchiveFile->url() ); 00210 if ( !destUrl.isValid() ) { 00211 KMessageBox::sorry(this,i18n("The archive file name is not valid.\n")); 00212 return; 00213 } 00214 // Force filename to be ending with vCalendar extension 00215 TQString filename = destUrl.fileName(); 00216 if (!filename.endsWith(".vcs") && !filename.endsWith(".ics")) { 00217 filename.append(".ics"); 00218 destUrl.setFileName(filename); 00219 } 00220 00221 KOPrefs::instance()->mArchiveFile = destUrl.url(); 00222 } 00223 if ( KOPrefs::instance()->mAutoArchive ) { 00224 archiver.runAuto( mCalendar, this, true /*with gui*/ ); 00225 emit autoArchivingSettingsModified(); 00226 accept(); 00227 } 00228 else 00229 archiver.runOnce( mCalendar, mDateEdit->date(), this ); 00230 } 00231 00232 void ArchiveDialog::slotEventsDeleted() 00233 { 00234 emit eventsDeleted(); 00235 if ( !KOPrefs::instance()->mAutoArchive ) 00236 accept(); 00237 }