00001
00002 #include "expirypropertiesdialog.h"
00003 #include "folderrequester.h"
00004 #include "kmfolder.h"
00005 #include "kmfoldertree.h"
00006
00007 #include <qvariant.h>
00008 #include <qpushbutton.h>
00009 #include <qgroupbox.h>
00010 #include <qcheckbox.h>
00011 #include <qspinbox.h>
00012 #include <qlabel.h>
00013 #include <qradiobutton.h>
00014 #include <qbuttongroup.h>
00015 #include <qcombobox.h>
00016 #include <qlayout.h>
00017 #include <qtooltip.h>
00018 #include <qwhatsthis.h>
00019
00020 #include <klocale.h>
00021 #include <kmessagebox.h>
00022
00023 using namespace KMail;
00024
00025
00026
00027
00028
00029
00030 ExpiryPropertiesDialog::ExpiryPropertiesDialog( KMFolderTree* tree, KMFolder* folder )
00031 : KDialogBase( tree, "expiry_properties", false, i18n( "Mail Expiry Properties" ),
00032 KDialogBase::Ok|KDialogBase::Cancel,
00033 KDialogBase::Ok, true ),
00034 mFolder( folder )
00035 {
00036 setWFlags( getWFlags() | WDestructiveClose );
00037 QWidget* privateLayoutWidget = new QWidget( this, "globalVBox" );
00038 setMainWidget( privateLayoutWidget );
00039 privateLayoutWidget->setGeometry( QRect( 10, 20, 270, 138 ) );
00040 globalVBox = new QVBoxLayout( privateLayoutWidget, 11, 6, "globalVBox");
00041 globalVBox->setSpacing( 20 );
00042
00043 readHBox = new QHBoxLayout( 0, 0, 6, "readHBox");
00044
00045 expireReadMailCB = new QCheckBox( privateLayoutWidget, "expireReadMailCB" );
00046 expireReadMailCB->setText( i18n( "Expire read mails after" ) );
00047 connect( expireReadMailCB, SIGNAL( toggled( bool )),
00048 this, SLOT( slotUpdateControls() ) );
00049 readHBox->addWidget( expireReadMailCB );
00050
00051 expireReadMailSB = new QSpinBox( privateLayoutWidget, "expireReadMailSB" );
00052 expireReadMailSB->setMaxValue( 999999 );
00053 expireReadMailSB->setValue( 30 );
00054 readHBox->addWidget( expireReadMailSB );
00055
00056 labelDays = new QLabel( privateLayoutWidget, "labelDays" );
00057 labelDays->setText( i18n( "days" ) );
00058 readHBox->addWidget( labelDays );
00059 globalVBox->addLayout( readHBox );
00060
00061 unreadHBox = new QHBoxLayout( 0, 0, 6, "unreadHBox");
00062
00063 expireUnreadMailCB = new QCheckBox( privateLayoutWidget, "expireUnreadMailCB" );
00064 expireUnreadMailCB->setText( i18n( "Expire unread mails after" ) );
00065 connect( expireUnreadMailCB, SIGNAL( toggled( bool )),
00066 this, SLOT( slotUpdateControls() ) );
00067 unreadHBox->addWidget( expireUnreadMailCB );
00068
00069 expireUnreadMailSB = new QSpinBox( privateLayoutWidget, "expireUnreadMailSB" );
00070 expireUnreadMailSB->setMaxValue( 99999 );
00071 expireUnreadMailSB->setValue( 30 );
00072 unreadHBox->addWidget( expireUnreadMailSB );
00073
00074 labelDays2 = new QLabel( privateLayoutWidget, "labelDays2" );
00075 labelDays2->setText( i18n( "days" ) );
00076 labelDays2->setAlignment( int( QLabel::AlignTop ) );
00077 unreadHBox->addWidget( labelDays2 );
00078 globalVBox->addLayout( unreadHBox );
00079
00080 expiryActionHBox = new QHBoxLayout( 0, 0, 6, "expiryActionHBox");
00081
00082 expiryActionLabel = new QLabel( privateLayoutWidget, "expiryActionLabel" );
00083 expiryActionLabel->setText( i18n( "Expiry action:" ) );
00084 expiryActionLabel->setAlignment( int( QLabel::AlignVCenter ) );
00085 expiryActionHBox->addWidget( expiryActionLabel );
00086
00087 actionsHBox = new QVBoxLayout( 0, 0, 6, "actionsHBox");
00088 actionsGroup = new QButtonGroup( this );
00089 actionsGroup->hide();
00090
00091 moveToHBox = new QHBoxLayout( 0, 0, 6, "moveToHBox");
00092
00093 moveToRB = new QRadioButton( privateLayoutWidget, "moveToRB" );
00094 actionsGroup->insert( moveToRB );
00095 connect( moveToRB, SIGNAL( toggled( bool ) ),
00096 this, SLOT( slotUpdateControls() ) );
00097 moveToRB->setText( i18n( "Move to:" ) );
00098 moveToHBox->addWidget( moveToRB );
00099
00100 folderSelector = new KMail::FolderRequester( privateLayoutWidget, tree );
00101 folderSelector->setMustBeReadWrite( true );
00102 moveToHBox->addWidget( folderSelector );
00103 actionsHBox->addLayout( moveToHBox );
00104
00105 deletePermanentlyRB = new QRadioButton( privateLayoutWidget, "deletePermanentlyRB" );
00106 actionsGroup->insert( deletePermanentlyRB );
00107 deletePermanentlyRB->setText( i18n( "Delete permanently" ) );
00108 actionsHBox->addWidget( deletePermanentlyRB );
00109 expiryActionHBox->addLayout( actionsHBox );
00110 globalVBox->addLayout( expiryActionHBox );
00111
00112 note = new QLabel( privateLayoutWidget, "note" );
00113 note->setText( i18n( "Note: Expiry action will be applied immediately after confirming settings." ) );
00114 note->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) );
00115 globalVBox->addWidget( note );
00116
00117
00118 bool expiryGloballyOn = mFolder->isAutoExpire();
00119 int daysToExpireRead, daysToExpireUnread;
00120 mFolder->daysToExpire( daysToExpireUnread, daysToExpireRead);
00121
00122 if ( expiryGloballyOn
00123 && mFolder->getReadExpireUnits() != expireNever
00124 && daysToExpireRead >= 0 ) {
00125 expireReadMailCB->setChecked( true );
00126 expireReadMailSB->setValue( daysToExpireRead );
00127 }
00128 if ( expiryGloballyOn
00129 && mFolder->getUnreadExpireUnits() != expireNever
00130 && daysToExpireUnread >= 0 ) {
00131 expireUnreadMailCB->setChecked( true );
00132 expireUnreadMailSB->setValue( daysToExpireUnread );
00133 }
00134
00135 if ( mFolder->expireAction() == KMFolder::ExpireDelete )
00136 deletePermanentlyRB->setChecked( true );
00137 else
00138 moveToRB->setChecked( true );
00139
00140 QString destFolderID = mFolder->expireToFolderId();
00141 if ( !destFolderID.isEmpty() ) {
00142 KMFolder* destFolder = kmkernel->findFolderById( destFolderID );
00143 if ( destFolder )
00144 folderSelector->setFolder( destFolder );
00145 }
00146 slotUpdateControls();
00147 resize( QSize(295, 204).expandedTo(minimumSizeHint()) );
00148 clearWState( WState_Polished );
00149 }
00150
00151
00152
00153
00154 ExpiryPropertiesDialog::~ExpiryPropertiesDialog()
00155 {
00156
00157 }
00158
00159 void ExpiryPropertiesDialog::slotOk()
00160 {
00161 bool enableGlobally = expireReadMailCB->isChecked() || expireUnreadMailCB->isChecked();
00162 if ( enableGlobally && moveToRB->isChecked() && !folderSelector->folder() ) {
00163 KMessageBox::error( this, i18n("Please select a folder to expire messages into."),
00164 i18n( "No Folder Selected" ) );
00165 return;
00166 }
00167 mFolder->setAutoExpire( enableGlobally );
00168
00169 mFolder->setReadExpireAge( expireReadMailSB->value() );
00170 mFolder->setUnreadExpireAge( expireUnreadMailSB->value() );
00171 mFolder->setReadExpireUnits( expireReadMailCB->isChecked()? expireDays : expireNever );
00172 mFolder->setUnreadExpireUnits( expireUnreadMailCB->isChecked()? expireDays : expireNever );
00173
00174 if ( deletePermanentlyRB->isChecked() )
00175 mFolder->setExpireAction( KMFolder::ExpireDelete );
00176 else
00177 mFolder->setExpireAction( KMFolder::ExpireMove );
00178 KMFolder* expireToFolder = folderSelector->folder();
00179 if ( expireToFolder )
00180 mFolder->setExpireToFolderId( expireToFolder->idString() );
00181
00182
00183 if ( enableGlobally )
00184 mFolder->expireOldMessages( true );
00185 KDialogBase::slotOk();
00186 }
00187
00188 void ExpiryPropertiesDialog::slotUpdateControls()
00189 {
00190 bool showExpiryActions = expireReadMailCB->isChecked() || expireUnreadMailCB->isChecked();
00191 moveToRB->setEnabled( showExpiryActions );
00192 folderSelector->setEnabled( showExpiryActions && moveToRB->isChecked() );
00193 deletePermanentlyRB->setEnabled( showExpiryActions );
00194 }
00195
00196
00197 #include "expirypropertiesdialog.moc"