localsubscriptiondialog.cpp
00001 /* -*- c++ -*- 00002 localsubscriptiondialog.cpp 00003 00004 This file is part of KMail, the KDE mail client. 00005 Copyright (C) 2006 Till Adam <adam@kde.org> 00006 00007 KMail is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License, version 2, as 00009 published by the Free Software Foundation. 00010 00011 KMail is distributed in the hope that it will be useful, but 00012 WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 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 In addition, as a special exception, the copyright holders give 00021 permission to link the code of this program with any edition of 00022 the TQt library by Trolltech AS, Norway (or with modified versions 00023 of TQt that use the same license as TQt), and distribute linked 00024 combinations including the two. You must obey the GNU General 00025 Public License in all respects for all of the code used other than 00026 TQt. If you modify this file, you may extend this exception to 00027 your version of the file, but you are not obligated to do so. If 00028 you do not wish to do so, delete this exception statement from 00029 your version. 00030 */ 00031 00032 #ifdef HAVE_CONFIG_H 00033 #include <config.h> 00034 #endif 00035 00036 #include <kdebug.h> 00037 #include <tdelocale.h> 00038 #include <tdemessagebox.h> 00039 00040 #include "localsubscriptiondialog.h" 00041 #include "kmkernel.h" 00042 #include "accountmanager.h" 00043 #include "kmmessage.h" 00044 #include "imapaccountbase.h" 00045 #include "listjob.h" 00046 00047 namespace KMail { 00048 00049 LocalSubscriptionDialog::LocalSubscriptionDialog( TQWidget *parent, const TQString &caption, 00050 ImapAccountBase *acct, TQString startPath ) 00051 : SubscriptionDialog( parent, caption, acct, startPath ), 00052 mAccount( acct ) 00053 { 00054 } 00055 00056 /* virtual */ 00057 LocalSubscriptionDialog::~LocalSubscriptionDialog() 00058 { 00059 00060 } 00061 00062 void LocalSubscriptionDialog::listAllAvailableAndCreateItems() 00063 { 00064 if ( mAccount->onlySubscribedFolders() ) 00065 mSubscribed = true; 00066 SubscriptionDialog::listAllAvailableAndCreateItems(); 00067 } 00068 00069 /* virtual */ 00070 void LocalSubscriptionDialog::processFolderListing() 00071 { 00072 uint done = 0; 00073 for (uint i = mCount; i < mFolderNames.count(); ++i) 00074 { 00075 // give the dialog a chance to repaint 00076 if (done == 1000) 00077 { 00078 emit listChanged(); 00079 TQTimer::singleShot(0, this, TQT_SLOT(processItems())); 00080 return; 00081 } 00082 ++mCount; 00083 ++done; 00084 createListViewItem( i ); 00085 } 00086 00087 if ( mPrefixList.isEmpty() && !mSubscribed ) 00088 loadingComplete(); // no need to load subscribed folders 00089 else 00090 processNext(); 00091 } 00092 00093 void LocalSubscriptionDialog::setCheckedStateOfAllItems() 00094 { 00095 // iterate over all items and check them, unless they are 00096 // in the account's local subscription blacklist 00097 TQDictIterator<GroupItem> it( mItemDict ); 00098 for ( ; it.current(); ++it ) { 00099 GroupItem *item = it.current(); 00100 TQString path = it.currentKey(); 00101 item->setOn( mAccount->locallySubscribedTo( path ) ); 00102 } 00103 } 00104 00105 /*virtual*/ 00106 void LocalSubscriptionDialog::doSave() 00107 { 00108 bool somethingHappened = false; 00109 // subscribe 00110 TQListViewItemIterator it(subView); 00111 for ( ; it.current(); ++it) { 00112 static_cast<ImapAccountBase*>(account())->changeLocalSubscription( 00113 static_cast<GroupItem*>(it.current())->info().path, true ); 00114 somethingHappened = true; 00115 } 00116 00117 // unsubscribe 00118 TQListViewItemIterator it2(unsubView); 00119 if ( unsubView->childCount() > 0 ) { 00120 const TQString message = i18n("Locally unsubscribing from folders will remove all " 00121 "information that is present locally about those folders. The folders will " 00122 "not be changed on the server. Press cancel now if you want to make sure " 00123 "all local changes have been written to the server by checking mail first."); 00124 const TQString caption = i18n("Local changes will be lost when unsubscribing"); 00125 if ( KMessageBox::warningContinueCancel( this, message, caption ) 00126 != KMessageBox::Cancel ) { 00127 somethingHappened = true; 00128 for ( ; it2.current(); ++it2) { 00129 static_cast<ImapAccountBase*>(account())->changeLocalSubscription( 00130 static_cast<GroupItem*>(it2.current())->info().path, false ); 00131 } 00132 00133 } 00134 } 00135 if ( somethingHappened ) { 00136 kmkernel->acctMgr()->singleCheckMail( mAccount, true); 00137 } 00138 } 00139 00140 void LocalSubscriptionDialog::loadingComplete() 00141 { 00142 setCheckedStateOfAllItems(); 00143 SubscriptionDialog::loadingComplete(); 00144 } 00145 00146 } // namespace 00147 00148 #include "localsubscriptiondialog.moc"