• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

korganizer

archivedialog.cpp

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

korganizer

Skip menu "korganizer"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal