subscriptiondialog.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
00050 hideTreeCheckbox();
00051 hideNewOnlyCheckbox();
00052
00053
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
00061 connect(this, SIGNAL(okClicked()), SLOT(slotSave()));
00062
00063
00064 connect(this, SIGNAL(user1Clicked()), SLOT(slotLoadFolders()));
00065
00066
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
00085
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
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
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
00133
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 )
00141 item->setOn(false);
00142
00143 } else
00144 {
00145
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
00153 item->setOn(true);
00154 }
00155 ++it;
00156 }
00157 }
00158 if ( mSubfolderMimeTypes[i] == "message/directory" ||
00159 mSubfolderMimeTypes[i] == "inode/directory" )
00160 {
00161
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
00171 slotLoadingComplete();
00172 }
00173
00174
00175 void SubscriptionDialog::slotSave()
00176 {
00177 if (!account())
00178 return;
00179
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
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
00200 KSubscription::slotLoadFolders();
00201 if ( !account() )
00202 return;
00203 ImapAccountBase* ai = static_cast<ImapAccountBase*>(account());
00204 if ( ai->prefix().isEmpty() )
00205 return;
00206
00207 ai->listDirectory( ai->prefix(), false, false, 0, true );
00208 ai->listDirectory( ai->prefix(), true );
00209 }
00210
00211 }
00212
00213 #include "subscriptiondialog.moc"
This file is part of the documentation for kmail Library Version 3.2.2.