kmail

expirypropertiesdialog.cpp
1
2#include "expirypropertiesdialog.h"
3#include "folderrequester.h"
4#include "kmfolder.h"
5#include "kmfoldertree.h"
6
7#include <tqvariant.h>
8#include <tqpushbutton.h>
9#include <tqgroupbox.h>
10#include <tqcheckbox.h>
11#include <tqspinbox.h>
12#include <tqlabel.h>
13#include <tqradiobutton.h>
14#include <tqbuttongroup.h>
15#include <tqcombobox.h>
16#include <tqlayout.h>
17#include <tqtooltip.h>
18#include <tqwhatsthis.h>
19
20#include <tdelocale.h>
21#include <tdemessagebox.h>
22
23using namespace KMail;
24
25/*
26 * Constructs a ExpiryPropertiesDialog as a child of 'parent', with the
27 * name 'name'.
28 *
29 */
30ExpiryPropertiesDialog::ExpiryPropertiesDialog( KMFolderTree* tree, KMFolder* folder )
31 : KDialogBase( tree, "expiry_properties", false, i18n( "Mail Expiry Properties" ),
32 KDialogBase::Ok|KDialogBase::Cancel,
33 KDialogBase::Ok, true ),
34 mFolder( folder )
35{
36 setWFlags( getWFlags() | WDestructiveClose );
37 TQWidget* privateLayoutWidget = new TQWidget( this, "globalVBox" );
38 setMainWidget( privateLayoutWidget );
39 privateLayoutWidget->setGeometry( TQRect( 10, 20, 270, 138 ) );
40 globalVBox = new TQVBoxLayout( privateLayoutWidget, 11, 6, "globalVBox");
41 globalVBox->setSpacing( 20 );
42
43 readHBox = new TQHBoxLayout( 0, 0, 6, "readHBox");
44
45 expireReadMailCB = new TQCheckBox( privateLayoutWidget, "expireReadMailCB" );
46 expireReadMailCB->setText( i18n( "Expire read mails after" ) );
47 connect( expireReadMailCB, TQ_SIGNAL( toggled( bool )),
48 this, TQ_SLOT( slotUpdateControls() ) );
49 readHBox->addWidget( expireReadMailCB );
50
51 expireReadMailSB = new TQSpinBox( privateLayoutWidget, "expireReadMailSB" );
52 expireReadMailSB->setMaxValue( 999999 );
53 expireReadMailSB->setValue( 30 );
54 readHBox->addWidget( expireReadMailSB );
55
56 labelDays = new TQLabel( privateLayoutWidget, "labelDays" );
57 labelDays->setText( i18n( "days" ) );
58 readHBox->addWidget( labelDays );
59 globalVBox->addLayout( readHBox );
60
61 unreadHBox = new TQHBoxLayout( 0, 0, 6, "unreadHBox");
62
63 expireUnreadMailCB = new TQCheckBox( privateLayoutWidget, "expireUnreadMailCB" );
64 expireUnreadMailCB->setText( i18n( "Expire unread mails after" ) );
65 connect( expireUnreadMailCB, TQ_SIGNAL( toggled( bool )),
66 this, TQ_SLOT( slotUpdateControls() ) );
67 unreadHBox->addWidget( expireUnreadMailCB );
68
69 expireUnreadMailSB = new TQSpinBox( privateLayoutWidget, "expireUnreadMailSB" );
70 expireUnreadMailSB->setMaxValue( 99999 );
71 expireUnreadMailSB->setValue( 30 );
72 unreadHBox->addWidget( expireUnreadMailSB );
73
74 labelDays2 = new TQLabel( privateLayoutWidget, "labelDays2" );
75 labelDays2->setText( i18n( "days" ) );
76 labelDays2->setAlignment( int( TQLabel::AlignTop ) );
77 unreadHBox->addWidget( labelDays2 );
78 globalVBox->addLayout( unreadHBox );
79
80 expiryActionHBox = new TQHBoxLayout( 0, 0, 6, "expiryActionHBox");
81
82 expiryActionLabel = new TQLabel( privateLayoutWidget, "expiryActionLabel" );
83 expiryActionLabel->setText( i18n( "Expiry action:" ) );
84 expiryActionLabel->setAlignment( int( TQLabel::AlignVCenter ) );
85 expiryActionHBox->addWidget( expiryActionLabel );
86
87 actionsHBox = new TQVBoxLayout( 0, 0, 6, "actionsHBox");
88 actionsGroup = new TQButtonGroup( this );
89 actionsGroup->hide(); // for mutual exclusion of the radio buttons
90
91 moveToHBox = new TQHBoxLayout( 0, 0, 6, "moveToHBox");
92
93 moveToRB = new TQRadioButton( privateLayoutWidget, "moveToRB" );
94 actionsGroup->insert( moveToRB );
95 connect( moveToRB, TQ_SIGNAL( toggled( bool ) ),
96 this, TQ_SLOT( slotUpdateControls() ) );
97 moveToRB->setText( i18n( "Move to:" ) );
98 moveToHBox->addWidget( moveToRB );
99
100 folderSelector = new KMail::FolderRequester( privateLayoutWidget, tree );
101 folderSelector->setMustBeReadWrite( true );
102 moveToHBox->addWidget( folderSelector );
103 actionsHBox->addLayout( moveToHBox );
104
105 deletePermanentlyRB = new TQRadioButton( privateLayoutWidget, "deletePermanentlyRB" );
106 actionsGroup->insert( deletePermanentlyRB );
107 deletePermanentlyRB->setText( i18n( "Delete permanently" ) );
108 actionsHBox->addWidget( deletePermanentlyRB );
109 expiryActionHBox->addLayout( actionsHBox );
110 globalVBox->addLayout( expiryActionHBox );
111
112 note = new TQLabel( privateLayoutWidget, "note" );
113 note->setText( i18n( "Note: Expiry action will be applied immediately after confirming settings." ) );
114 note->setAlignment( int( TQLabel::WordBreak | TQLabel::AlignVCenter ) );
115 globalVBox->addWidget( note );
116
117 // Load the values from the folder
118 bool expiryGloballyOn = mFolder->isAutoExpire();
119 int daysToExpireRead, daysToExpireUnread;
120 mFolder->daysToExpire( daysToExpireUnread, daysToExpireRead);
121
122 if ( expiryGloballyOn
123 && mFolder->getReadExpireUnits() != expireNever
124 && daysToExpireRead >= 0 ) {
125 expireReadMailCB->setChecked( true );
126 expireReadMailSB->setValue( daysToExpireRead );
127 }
128 if ( expiryGloballyOn
129 && mFolder->getUnreadExpireUnits() != expireNever
130 && daysToExpireUnread >= 0 ) {
131 expireUnreadMailCB->setChecked( true );
132 expireUnreadMailSB->setValue( daysToExpireUnread );
133 }
134
135 if ( mFolder->expireAction() == KMFolder::ExpireDelete )
136 deletePermanentlyRB->setChecked( true );
137 else
138 moveToRB->setChecked( true );
139
140 TQString destFolderID = mFolder->expireToFolderId();
141 if ( !destFolderID.isEmpty() ) {
142 KMFolder* destFolder = kmkernel->findFolderById( destFolderID );
143 if ( destFolder )
144 folderSelector->setFolder( destFolder );
145 }
146 slotUpdateControls();
147 resize( TQSize(295, 204).expandedTo(minimumSizeHint()) );
148 clearWState( WState_Polished );
149}
150
151/*
152 * Destroys the object and frees any allocated resources
153 */
154ExpiryPropertiesDialog::~ExpiryPropertiesDialog()
155{
156 // no need to delete child widgets, TQt does it all for us
157}
158
159void ExpiryPropertiesDialog::slotOk()
160{
161 bool enableGlobally = expireReadMailCB->isChecked() || expireUnreadMailCB->isChecked();
162
163 KMFolder *expireToFolder = folderSelector->folder();
164 if ( enableGlobally && moveToRB->isChecked() && !expireToFolder ) {
165 KMessageBox::error(
166 this,
167 i18n( "Please select a folder to expire messages into." ),
168 i18n( "No Folder Selected" ) );
169 return;
170 }
171
172 if ( expireToFolder ) {
173 if ( expireToFolder->idString() == mFolder->idString() ) {
174 KMessageBox::error(
175 this,
176 i18n( "Please select a different folder than the current folder "
177 "to expire message into." ),
178 i18n( "Wrong Folder Selected" ) );
179 return;
180 } else {
181 mFolder->setExpireToFolderId( expireToFolder->idString() );
182 }
183 }
184
185 mFolder->setAutoExpire( enableGlobally );
186 // we always write out days now
187 mFolder->setReadExpireAge( expireReadMailSB->value() );
188 mFolder->setUnreadExpireAge( expireUnreadMailSB->value() );
189 mFolder->setReadExpireUnits( expireReadMailCB->isChecked()? expireDays : expireNever );
190 mFolder->setUnreadExpireUnits( expireUnreadMailCB->isChecked()? expireDays : expireNever );
191
192 if ( deletePermanentlyRB->isChecked() )
193 mFolder->setExpireAction( KMFolder::ExpireDelete );
194 else
195 mFolder->setExpireAction( KMFolder::ExpireMove );
196
197 // trigger immediate expiry if there is something to do
198 if ( enableGlobally )
199 mFolder->expireOldMessages( true /*immediate*/);
200 KDialogBase::slotOk();
201}
202
203void ExpiryPropertiesDialog::slotUpdateControls()
204{
205 bool showExpiryActions = expireReadMailCB->isChecked() || expireUnreadMailCB->isChecked();
206 moveToRB->setEnabled( showExpiryActions );
207 folderSelector->setEnabled( showExpiryActions && moveToRB->isChecked() );
208 deletePermanentlyRB->setEnabled( showExpiryActions );
209}
210
211
212#include "expirypropertiesdialog.moc"
Mail folder.
Definition: kmfolder.h:69
TQString idString() const
Returns a string that can be used to identify this folder.
Definition: kmfolder.cpp:705
A widget that contains a KLineEdit which shows the current folder and a button that fires a KMFolderS...
@ Ok
The user rights/ACL have been fetched from the server sucessfully.
Definition: acljobs.h:66
folderdiaquotatab.h
Definition: aboutdata.cpp:40