kmail Library API Documentation

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 Qt library by Trolltech AS, Norway (or with modified versions
00023     of Qt that use the same license as Qt), 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     Qt.  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 <klocale.h>
00038 #include <kmessagebox.h>
00039 
00040 #include "localsubscriptiondialog.h"
00041 #include "kmkernel.h"
00042 #include "kmacctmgr.h"
00043 #include "kmmessage.h"
00044 #include "imapaccountbase.h"
00045 #include "listjob.h"
00046 
00047 namespace KMail {
00048 
00049 LocalSubscriptionDialog::LocalSubscriptionDialog( QWidget *parent, const QString &caption,
00050     ImapAccountBase *acct, QString startPath )
00051   : SubscriptionDialog( parent, caption, acct, startPath ),
00052     mAccount( acct )
00053 {
00054 }
00055 
00056 /* virtual */
00057 LocalSubscriptionDialog::~LocalSubscriptionDialog()
00058 {
00059 
00060 }
00061 
00062 
00063 /*virtual*/
00064 void LocalSubscriptionDialog::listAllAvailableAndCreateItems()
00065 {
00066   // only do a complete listing (*) when the user did not enter a prefix
00067   // otherwise the complete listing will be done in second step
00068   bool complete = (mAccount->prefix() == "/") ? true : false;
00069   // get all available folders
00070   ImapAccountBase::ListType type = ImapAccountBase::List;
00071   if ( mAccount->onlySubscribedFolders() )
00072       type = ImapAccountBase::ListSubscribedNoCheck;
00073   ListJob* job = new ListJob( 0, mAccount, type, false,
00074                               complete, false, mAccount->prefix() );
00075   connect( job, SIGNAL(receivedFolders(const QStringList&, const QStringList&,
00076           const QStringList&, const QStringList&, const ImapAccountBase::jobData&)),
00077       this, SLOT(slotListDirectory(const QStringList&, const QStringList&,
00078           const QStringList&, const QStringList&, const ImapAccountBase::jobData&)));
00079   job->start();
00080 }
00081 
00082 /* virtual */
00083 void LocalSubscriptionDialog::processFolderListing()
00084 {
00085   uint done = 0;
00086   for (uint i = mCount; i < mFolderNames.count(); ++i) {
00087     // give the dialog a chance to repaint
00088     if (done == 1000) {
00089       emit listChanged();
00090       QTimer::singleShot(0, this, SLOT(processFolderListing()));
00091       return;
00092     }
00093     ++mCount;
00094     ++done;
00095     createListViewItem( i );
00096   }
00097   if ( mJobData.inboxOnly ) {
00098     // So far we've only listed the inbox, so list the rest of the
00099     // available folders and process them. We only get here if there
00100     // is a custom prefix. (secondStep=true)
00101     ImapAccountBase::ListType type = ImapAccountBase::List;
00102     if ( mAccount->onlySubscribedFolders() )
00103       type = ImapAccountBase::ListSubscribedNoCheck;
00104     ListJob* job = new ListJob( 0, mAccount, type, true, true,
00105                                 false, mAccount->prefix() );
00106     connect( job, SIGNAL(receivedFolders(const QStringList&, const QStringList&,
00107             const QStringList&, const QStringList&, const ImapAccountBase::jobData&)),
00108         this, SLOT(slotListDirectory(const QStringList&, const QStringList&,
00109             const QStringList&, const QStringList&, const ImapAccountBase::jobData&)));
00110     job->start();
00111   } else {
00112     // We only get here if we have processed all listed folders, either 
00113     // immediately, if there is no prefix, or after the second listing.
00114     setCheckedStateOfAllItems();
00115   }
00116 }
00117 
00118 void LocalSubscriptionDialog::setCheckedStateOfAllItems()
00119 {
00120    // iterate over all items and check them, unless they are
00121    // in the account's local subscription blacklist
00122    QDictIterator<GroupItem> it( mItemDict );
00123    for ( ; it.current(); ++it ) {
00124      GroupItem *item = it.current();
00125      QString path = it.currentKey();
00126      item->setOn( mAccount->locallySubscribedTo( path ) );
00127    }
00128    slotLoadingComplete();
00129 }
00130 
00131 /*virtual*/
00132 void LocalSubscriptionDialog::doSave()
00133 {
00134   bool somethingHappened = false;
00135   // subscribe
00136   QListViewItemIterator it(subView);
00137   for ( ; it.current(); ++it) {
00138     static_cast<ImapAccountBase*>(account())->changeLocalSubscription(
00139         static_cast<GroupItem*>(it.current())->info().path, true );
00140     somethingHappened = true;
00141   }
00142 
00143   // unsubscribe
00144   QListViewItemIterator it2(unsubView);
00145   if ( unsubView->childCount() > 0 ) {
00146     const QString message = i18n("Locally unsubscribing from folders will remove all "
00147         "information that is present locally about those folders. The folders will " 
00148         "not be changed on the server. Press cancel now if you want to make sure "
00149         "all local changes have been written to the server by checking mail first.");
00150     const QString caption = i18n("Local changes will be lost when unsubscribing");
00151     if ( KMessageBox::warningContinueCancel( this, message, caption )
00152         != KMessageBox::Cancel ) {
00153       somethingHappened = true;
00154       for ( ; it2.current(); ++it2) {
00155         static_cast<ImapAccountBase*>(account())->changeLocalSubscription(
00156             static_cast<GroupItem*>(it2.current())->info().path, false );
00157       }
00158 
00159     }
00160   }
00161   if ( somethingHappened ) {
00162     kmkernel->acctMgr()->singleCheckMail( mAccount, true);
00163   }
00164 }
00165 
00166 } // namespace
00167 
00168 #include "localsubscriptiondialog.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 23 18:21:32 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003