Backport r950340 | aacid | 2009-04-06 23:21:18 +0200 (Mon, 06 Apr 2009) | 4 lines
[kdepim.git] / kmail / localsubscriptiondialog.cpp
blob1534a38db592c3150a3d81ffe1fe8e5858c08c88
1 /* -*- c++ -*-
2 localsubscriptiondialog.cpp
4 This file is part of KMail, the KDE mail client.
5 Copyright (C) 2006 Till Adam <adam@kde.org>
7 KMail is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License, version 2, as
9 published by the Free Software Foundation.
11 KMail is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 In addition, as a special exception, the copyright holders give
21 permission to link the code of this program with any edition of
22 the Qt library by Trolltech AS, Norway (or with modified versions
23 of Qt that use the same license as Qt), and distribute linked
24 combinations including the two. You must obey the GNU General
25 Public License in all respects for all of the code used other than
26 Qt. If you modify this file, you may extend this exception to
27 your version of the file, but you are not obligated to do so. If
28 you do not wish to do so, delete this exception statement from
29 your version.
32 #include "localsubscriptiondialog.h"
34 #include <kdebug.h>
35 #include <klocale.h>
36 #include <kmessagebox.h>
38 #include "kmkernel.h"
39 #include "accountmanager.h"
40 #include "kmmessage.h"
41 #include "imapaccountbase.h"
42 #include "listjob.h"
44 namespace KMail {
46 LocalSubscriptionDialog::LocalSubscriptionDialog( QWidget *parent, const QString &caption,
47 ImapAccountBase *acct, const QString &startPath )
48 : SubscriptionDialog( parent, caption, acct, startPath ),
49 mAccount( acct )
53 /* virtual */
54 LocalSubscriptionDialog::~LocalSubscriptionDialog()
59 void LocalSubscriptionDialog::listAllAvailableAndCreateItems()
61 if ( mAccount->onlySubscribedFolders() )
62 mSubscribed = true;
63 SubscriptionDialog::listAllAvailableAndCreateItems();
66 /* virtual */
67 void LocalSubscriptionDialog::processFolderListing()
69 uint done = 0;
70 for (int i = mCount; i < mFolderNames.count(); ++i)
72 // give the dialog a chance to repaint
73 if (done == 1000)
75 emit listChanged();
76 QTimer::singleShot(0, this, SLOT(processItems()));
77 return;
79 ++mCount;
80 ++done;
81 createListViewItem( i );
84 if ( mPrefixList.isEmpty() && !mSubscribed )
85 loadingComplete(); // no need to load subscribed folders
86 else
87 processNext();
90 void LocalSubscriptionDialog::setCheckedStateOfAllItems()
92 // iterate over all items and check them, unless they are
93 // in the account's local subscription blacklist
94 QMapIterator<QString, GroupItem*> it( mItemDict );
95 while ( it.hasNext() ) {
96 it.next();
97 QString path = it.key();
98 GroupItem *item = it.value();
99 item->setOn( mAccount->locallySubscribedTo( path ) );
103 /*virtual*/
104 void LocalSubscriptionDialog::doSave()
106 bool somethingHappened = false;
107 // subscribe
108 Q3ListViewItemIterator it(subView);
109 for ( ; it.current(); ++it) {
110 static_cast<ImapAccountBase*>(account())->changeLocalSubscription(
111 static_cast<GroupItem*>(it.current())->info().path, true );
112 somethingHappened = true;
115 // unsubscribe
116 Q3ListViewItemIterator it2(unsubView);
117 if ( unsubView->childCount() > 0 ) {
118 const QString message = i18n("Locally unsubscribing from folders will remove all "
119 "information that is present locally about those folders. The folders will "
120 "not be changed on the server. Press cancel now if you want to make sure "
121 "all local changes have been written to the server by checking mail first.");
122 const QString caption = i18n("Local changes will be lost when unsubscribing");
123 if ( KMessageBox::warningContinueCancel( this, message, caption )
124 != KMessageBox::Cancel ) {
125 somethingHappened = true;
126 for ( ; it2.current(); ++it2) {
127 static_cast<ImapAccountBase*>(account())->changeLocalSubscription(
128 static_cast<GroupItem*>(it2.current())->info().path, false );
133 if ( somethingHappened ) {
134 kmkernel->acctMgr()->singleCheckMail( mAccount, true);
138 void LocalSubscriptionDialog::loadingComplete()
140 setCheckedStateOfAllItems();
141 SubscriptionDialog::loadingComplete();
144 } // namespace
146 #include "localsubscriptiondialog.moc"