30 #include <tqcombobox.h>
31 #include <tqgroupbox.h>
32 #include <tqcheckbox.h>
33 #include <tqpushbutton.h>
35 #include <tdelocale.h>
36 #include <keditlistbox.h>
37 #include <kdialogbase.h>
39 #include <tdemessagebox.h>
40 #include <kmcommands.h>
43 #include "mailinglist-magic.h"
44 #include "mailinglistpropertiesdialog.h"
46 using namespace KMail;
48 MailingListFolderPropertiesDialog::MailingListFolderPropertiesDialog( TQWidget* parent,
KMFolder *folder )
49 : KDialogBase( parent,
"mailinglist_properties", false, i18n(
"Mailinglist Folder Properties" ),
50 KDialogBase::
Ok|KDialogBase::Cancel,
51 KDialogBase::
Ok, true ),
54 setWFlags( getWFlags() | WDestructiveClose );
58 TQVBoxLayout *topLayout =
new TQVBoxLayout( layout(), spacingHint(),
61 TQGroupBox *mlGroup =
new TQGroupBox( i18n(
"Associated Mailing List" ),
this );
62 mlGroup->setColumnLayout( 0, TQt::Vertical );
63 TQGridLayout *groupLayout =
new TQGridLayout( mlGroup->layout(), 6, 3, spacingHint() );
64 topLayout->addWidget( mlGroup );
65 setMainWidget( mlGroup );
67 mHoldsMailingList =
new TQCheckBox( i18n(
"&Folder holds a mailing list"), mlGroup );
68 connect( mHoldsMailingList, TQ_SIGNAL(toggled(
bool)),
69 TQ_SLOT(slotHoldsML(
bool)) );
70 groupLayout->addMultiCellWidget( mHoldsMailingList, 0, 0, 0, 2 );
72 groupLayout->addItem(
new TQSpacerItem( 0, 10 ), 1, 0 );
74 mDetectButton =
new TQPushButton( i18n(
"Detect Automatically"), mlGroup );
75 mDetectButton->setEnabled(
false );
76 connect( mDetectButton, TQ_SIGNAL(pressed()), TQ_SLOT(slotDetectMailingList()) );
77 groupLayout->addWidget( mDetectButton, 2, 1 );
79 groupLayout->addItem(
new TQSpacerItem( 0, 10 ), 3, 0 );
81 label =
new TQLabel( i18n(
"Mailing list description:"), mlGroup );
82 label->setEnabled(
false );
83 connect( mHoldsMailingList, TQ_SIGNAL(toggled(
bool)),
84 label, TQ_SLOT(setEnabled(
bool)) );
85 groupLayout->addWidget( label, 4, 0 );
86 mMLId =
new TQLabel( label,
"", mlGroup );
87 groupLayout->addMultiCellWidget( mMLId, 4, 4, 1, 2 );
88 mMLId->setEnabled(
false );
91 label =
new TQLabel( i18n(
"Preferred handler:"), mlGroup );
92 label->setEnabled(
false);
93 connect( mHoldsMailingList, TQ_SIGNAL(toggled(
bool)),
94 label, TQ_SLOT(setEnabled(
bool)) );
95 groupLayout->addWidget( label, 5, 0 );
96 mMLHandlerCombo =
new TQComboBox( mlGroup );
97 mMLHandlerCombo->insertItem( i18n(
"KMail"), MailingList::KMail );
98 mMLHandlerCombo->insertItem( i18n(
"Browser"), MailingList::Browser );
99 mMLHandlerCombo->setEnabled(
false );
100 groupLayout->addMultiCellWidget( mMLHandlerCombo, 5, 5, 1, 2 );
101 connect( mMLHandlerCombo, TQ_SIGNAL(activated(
int)),
102 TQ_SLOT(slotMLHandling(
int)) );
103 label->setBuddy( mMLHandlerCombo );
105 label =
new TQLabel( i18n(
"&Address type:"), mlGroup );
106 label->setEnabled(
false);
107 connect( mHoldsMailingList, TQ_SIGNAL(toggled(
bool)),
108 label, TQ_SLOT(setEnabled(
bool)) );
109 groupLayout->addWidget( label, 6, 0 );
110 mAddressCombo =
new TQComboBox( mlGroup );
111 label->setBuddy( mAddressCombo );
112 groupLayout->addWidget( mAddressCombo, 6, 1 );
113 mAddressCombo->setEnabled(
false );
118 TQPushButton *handleButton =
new TQPushButton( i18n(
"Invoke Handler" ), mlGroup );
119 handleButton->setEnabled(
false );
122 connect( mHoldsMailingList, TQ_SIGNAL(toggled(
bool)),
123 handleButton, TQ_SLOT(setEnabled(
bool)) );
124 connect( handleButton, TQ_SIGNAL(clicked()),
125 TQ_SLOT(slotInvokeHandler()) );
127 groupLayout->addWidget( handleButton, 6, 2 );
129 mEditList =
new KEditListBox( mlGroup );
130 mEditList->setEnabled(
false );
131 groupLayout->addMultiCellWidget( mEditList, 7, 7, 0, 3 );
137 el << i18n(
"Post to List" )
138 << i18n(
"Subscribe to List" )
139 << i18n(
"Unsubscribe from List" )
140 << i18n(
"List Archives" )
141 << i18n(
"List Help" );
142 mAddressCombo->insertStringList( el );
143 connect( mAddressCombo, TQ_SIGNAL(activated(
int)),
144 TQ_SLOT(slotAddressChanged(
int)) );
147 resize( TQSize(295, 204).expandedTo(minimumSizeHint()) );
148 clearWState( WState_Polished );
151 void MailingListFolderPropertiesDialog::slotOk()
154 KDialogBase::slotOk();
157 void MailingListFolderPropertiesDialog::load()
159 if (mFolder) mMailingList = mFolder->mailingList();
160 mMLId->setText( (mMailingList.id().isEmpty() ? i18n(
"Not available") : mMailingList.id()) );
161 mMLHandlerCombo->setCurrentItem( mMailingList.handler() );
162 mEditList->insertStringList( mMailingList.postURLS().toStringList() );
164 mAddressCombo->setCurrentItem( mLastItem );
165 mHoldsMailingList->setChecked( mFolder && mFolder->isMailingListEnabled() );
169 bool MailingListFolderPropertiesDialog::save()
174 mFolder->setMailingListEnabled( mHoldsMailingList && mHoldsMailingList->isChecked() );
176 mFolder->setMailingList( mMailingList );
182 void MailingListFolderPropertiesDialog::slotHoldsML(
bool holdsML )
184 mMLHandlerCombo->setEnabled( holdsML );
185 if ( mFolder && mFolder->count() )
186 mDetectButton->setEnabled( holdsML );
187 mAddressCombo->setEnabled( holdsML );
188 mEditList->setEnabled( holdsML );
189 mMLId->setEnabled( holdsML );
193 void MailingListFolderPropertiesDialog::slotDetectMailingList()
195 if ( !mFolder )
return;
196 int num = mFolder->count();
198 kdDebug(5006)<<k_funcinfo<<
" Detecting mailing list"<<endl;
212 if ( !( mMailingList.features() & MailingList::Post ) ) {
213 const int maxchecks = 5;
214 for(
int i = --num; i > num-maxchecks; --i ) {
218 mMailingList = MailingList::detect( mes );
219 if ( mMailingList.features() & MailingList::Post )
223 if ( !(mMailingList.features() & MailingList::Post) ) {
224 KMessageBox::error(
this,
225 i18n(
"KMail was unable to detect a mailing list in this folder. "
226 "Please fill the addresses by hand.") );
228 mMLId->setText( (mMailingList.id().isEmpty() ? i18n(
"Not available.") : mMailingList.id() ) );
234 void MailingListFolderPropertiesDialog::slotMLHandling(
int element )
236 mMailingList.setHandler(
static_cast<MailingList::Handler
>( element ) );
240 void MailingListFolderPropertiesDialog::slotAddressChanged(
int i )
248 void MailingListFolderPropertiesDialog::fillMLFromWidgets()
250 if ( !mHoldsMailingList->isChecked() )
254 bool changed =
false;
255 TQStringList oldList = mEditList->items();
256 TQStringList newList;
257 for ( TQStringList::ConstIterator it = oldList.begin();
258 it != oldList.end(); ++it ) {
259 if ( !(*it).startsWith(
"http:") && !(*it).startsWith(
"https:") &&
260 !(*it).startsWith(
"mailto:") && ( (*it).find(
'@') != -1 ) ) {
262 newList <<
"mailto:" + *it;
270 mEditList->insertStringList( newList );
274 switch ( mLastItem ) {
276 mMailingList.setPostURLS( mEditList->items() );
279 mMailingList.setSubscribeURLS( mEditList->items() );
282 mMailingList.setUnsubscribeURLS( mEditList->items() );
285 mMailingList.setArchiveURLS( mEditList->items() );
288 mMailingList.setHelpURLS( mEditList->items() );
291 kdWarning( 5006 )<<
"Wrong entry in the mailing list entry combo!"<<endl;
295 void MailingListFolderPropertiesDialog::fillEditBox()
298 switch ( mAddressCombo->currentItem() ) {
300 mEditList->insertStringList( mMailingList.postURLS().toStringList() );
303 mEditList->insertStringList( mMailingList.subscribeURLS().toStringList() );
306 mEditList->insertStringList( mMailingList.unsubscribeURLS().toStringList() );
309 mEditList->insertStringList( mMailingList.archiveURLS().toStringList() );
312 mEditList->insertStringList( mMailingList.helpURLS().toStringList() );
315 kdWarning( 5006 )<<
"Wrong entry in the mailing list entry combo!"<<endl;
319 void MailingListFolderPropertiesDialog::slotInvokeHandler()
321 KMCommand *command =0;
322 switch ( mAddressCombo->currentItem() ) {
324 command =
new KMMailingListPostCommand(
this, mFolder );
327 command =
new KMMailingListSubscribeCommand(
this, mFolder );
330 command =
new KMMailingListUnsubscribeCommand(
this, mFolder );
333 command =
new KMMailingListArchivesCommand(
this, mFolder );
336 command =
new KMMailingListHelpCommand(
this, mFolder );
339 kdWarning( 5006 )<<
"Wrong entry in the mailing list entry combo!"<<endl;
341 if ( command ) command->start();
344 #include "mailinglistpropertiesdialog.moc"
@ Ok
The user rights/ACL have been fetched from the server sucessfully.