kmail Library API Documentation

subscriptiondialog.cpp

00001 /* -*- c++ -*- 00002 subscriptiondialog.cpp 00003 00004 This file is part of KMail, the KDE mail client. 00005 Copyright (C) 2002 Carsten Burghardt <burghardt@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 "subscriptiondialog.h" 00037 #include "kmmessage.h" 00038 00039 #include <klocale.h> 00040 #include <kdebug.h> 00041 00042 00043 namespace KMail { 00044 00045 SubscriptionDialog::SubscriptionDialog( QWidget *parent, const QString &caption, 00046 KAccount * acct ) 00047 : KSubscription( parent, caption, acct, User1, QString::null, false ) 00048 { 00049 // hide unneeded checkboxes 00050 hideTreeCheckbox(); 00051 hideNewOnlyCheckbox(); 00052 00053 // connect to folderlisting 00054 ImapAccountBase* iaccount = static_cast<ImapAccountBase*>(acct); 00055 connect(iaccount, SIGNAL(receivedFolders(QStringList, QStringList, 00056 QStringList, const ImapAccountBase::jobData &)), 00057 this, SLOT(slotListDirectory(QStringList, QStringList, 00058 QStringList, const ImapAccountBase::jobData &))); 00059 00060 // ok-button 00061 connect(this, SIGNAL(okClicked()), SLOT(slotSave())); 00062 00063 // reload-list button 00064 connect(this, SIGNAL(user1Clicked()), SLOT(slotLoadFolders())); 00065 00066 // get the folders 00067 slotLoadFolders(); 00068 } 00069 00070 //------------------------------------------------------------------------------ 00071 void SubscriptionDialog::slotListDirectory( QStringList mSubfolderNames, 00072 QStringList mSubfolderPaths, 00073 QStringList mSubfolderMimeTypes, 00074 const ImapAccountBase::jobData & jobData ) 00075 { 00076 if (mSubfolderPaths.size() <= 0) return; 00077 bool onlySubscribed = jobData.onlySubscribed; 00078 GroupItem *parent = 0; 00079 mLoading = true; 00080 ImapAccountBase* ai = static_cast<ImapAccountBase*>(mAcct); 00081 00082 if (!onlySubscribed) 00083 { 00084 /* we need to find our root-item 00085 remove the name (and the separator) from the path */ 00086 int start = mSubfolderPaths[0].length() - (mSubfolderNames[0].length()+2); 00087 int length = mSubfolderNames[0].length()+1; 00088 if (start < 0) start = 0; 00089 QString compare = mSubfolderPaths[0]; 00090 compare.remove(start, length); 00091 00092 QListViewItemIterator it( groupView ); 00093 GroupItem *tmp; 00094 while ( it.current() != 0 ) 00095 { 00096 // compare it with each item to find the current root 00097 tmp = static_cast<GroupItem*>(it.current()); 00098 if (tmp->info().path == compare) { 00099 parent = tmp; 00100 break; 00101 } 00102 ++it; 00103 } 00104 } 00105 GroupItem *item = 0; 00106 QString text; 00107 for (uint i = 0; i < mSubfolderNames.count(); i++) 00108 { 00109 if (!onlySubscribed) 00110 { 00111 bool create = true; 00112 QListViewItem *start = folderTree()->firstChild(); 00113 if ( parent ) 00114 start = parent->firstChild(); 00115 if ( start ) 00116 { 00117 for ( QListViewItem *it = start; it; it = it->nextSibling() ) 00118 { 00119 // check if this item already exists in this hierarchy 00120 item = static_cast<GroupItem*>(it); 00121 if ( item->info().path == mSubfolderPaths[i] ) 00122 create = false; 00123 } 00124 } 00125 if ( create ) 00126 { 00127 KGroupInfo info(mSubfolderNames[i]); 00128 if ( mSubfolderNames[i].upper() == "INBOX" ) 00129 info.name = i18n("inbox"); 00130 info.subscribed = false; 00131 info.path = mSubfolderPaths[i]; 00132 // create a new item 00133 // only checkable when the folder is selectable 00134 bool checkable = ( mSubfolderMimeTypes[i] == "inode/directory" ) ? false : true; 00135 if ( parent ) 00136 item = new GroupItem(parent, info, this, checkable); 00137 else 00138 item = new GroupItem(folderTree(), info, this, checkable); 00139 } 00140 if ( item ) // reset 00141 item->setOn(false); 00142 00143 } else 00144 { 00145 // find the item 00146 QListViewItemIterator it( groupView ); 00147 while ( it.current() != 0 ) 00148 { 00149 item = static_cast<GroupItem*>(it.current()); 00150 if (item->info().path == mSubfolderPaths[i]) 00151 { 00152 // subscribed 00153 item->setOn(true); 00154 } 00155 ++it; 00156 } 00157 } 00158 if ( mSubfolderMimeTypes[i] == "message/directory" || 00159 mSubfolderMimeTypes[i] == "inode/directory" ) 00160 { 00161 // descend 00162 bool secondStep = (mSubfolderPaths[i] == ai->prefix()) ? true : false; 00163 static_cast<ImapAccountBase*>(mAcct)->listDirectory( mSubfolderPaths[i], 00164 onlySubscribed, secondStep ); 00165 } 00166 } 00167 if ( jobData.inboxOnly ) 00168 ai->listDirectory( ai->prefix(), onlySubscribed, true ); 00169 00170 // active buttons and stuff 00171 slotLoadingComplete(); 00172 } 00173 00174 //------------------------------------------------------------------------------ 00175 void SubscriptionDialog::slotSave() 00176 { 00177 if (!account()) 00178 return; 00179 // subscribe 00180 QListViewItemIterator it(subView); 00181 for ( ; it.current(); ++it) 00182 { 00183 static_cast<ImapAccountBase*>(account())->changeSubscription(true, 00184 static_cast<GroupItem*>(it.current())->info().path); 00185 } 00186 00187 // unsubscribe 00188 QListViewItemIterator it2(unsubView); 00189 for ( ; it2.current(); ++it2) 00190 { 00191 static_cast<ImapAccountBase*>(account())->changeSubscription(false, 00192 static_cast<GroupItem*>(it2.current())->info().path); 00193 } 00194 } 00195 00196 //------------------------------------------------------------------------------ 00197 void SubscriptionDialog::slotLoadFolders() 00198 { 00199 // clear the views 00200 KSubscription::slotLoadFolders(); 00201 if ( !account() ) 00202 return; 00203 ImapAccountBase* ai = static_cast<ImapAccountBase*>(account()); 00204 if ( ai->prefix().isEmpty() ) 00205 return; 00206 // get folders 00207 ai->listDirectory( ai->prefix(), false, false, 0, true ); 00208 ai->listDirectory( ai->prefix(), true ); 00209 } 00210 00211 } 00212 00213 #include "subscriptiondialog.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:04 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003