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
#include "folderstorage.h"
00039
#include "listjob.h"
00040
using KMail::ListJob;
00041
00042
#include <klocale.h>
00043
#include <kdebug.h>
00044
00045
00046
namespace KMail {
00047
00048 SubscriptionDialog::SubscriptionDialog(
QWidget *parent,
const QString &caption,
00049 KAccount *acct,
QString startPath )
00050 : KSubscription( parent, caption, acct, User1,
QString::null, false ),
00051 mStartPath( startPath )
00052 {
00053
00054 hideTreeCheckbox();
00055 hideNewOnlyCheckbox();
00056
00057
00058 connect(
this, SIGNAL(okClicked()), SLOT(slotSave()));
00059
00060
00061 connect(
this, SIGNAL(user1Clicked()), SLOT(slotLoadFolders()));
00062
00063
00064 slotLoadFolders();
00065 }
00066
00067
00068
void SubscriptionDialog::slotListDirectory(
const QStringList& subfolderNames,
00069
const QStringList& subfolderPaths,
00070
const QStringList& subfolderMimeTypes,
00071
const QStringList& subfolderAttributes,
00072
const ImapAccountBase::jobData& jobData )
00073 {
00074 mFolderNames = subfolderNames;
00075 mFolderPaths = subfolderPaths;
00076 mFolderMimeTypes = subfolderMimeTypes;
00077 mFolderAttributes = subfolderAttributes;
00078 mJobData = jobData;
00079
00080 mCount = 0;
00081 mCheckForExisting =
false;
00082
00083 createItems();
00084 }
00085
00086
00087
void SubscriptionDialog::createItems()
00088 {
00089
bool onlySubscribed = mJobData.onlySubscribed;
00090 ImapAccountBase* ai = static_cast<ImapAccountBase*>(mAcct);
00091 GroupItem *parent = 0;
00092 uint done = 0;
00093
for (uint i = mCount; i < mFolderNames.count(); ++i)
00094 {
00095
00096
if (done == 1000)
00097 {
00098 emit listChanged();
00099 QTimer::singleShot(0,
this, SLOT(createItems()));
00100
return;
00101 }
00102 ++mCount;
00103 ++done;
00104 GroupItem *item = 0;
00105
if (!onlySubscribed && mFolderPaths.size() > 0)
00106 {
00107
00108
if (mDelimiter.isEmpty())
00109 {
00110
int start = mFolderPaths[i].findRev(mFolderNames[i]);
00111
if (start > 1)
00112 mDelimiter = mFolderPaths[i].mid(start-1, 1);
00113 }
00114
00115
00116 GroupItem *oldItem = 0;
00117
QString parentPath;
00118 findParentItem( mFolderNames[i], mFolderPaths[i], parentPath, &parent, &oldItem );
00119
00120
if (!parent && parentPath !=
"/")
00121 {
00122
00123
00124
00125
00126 mCheckForExisting =
true;
00127
QStringList folders = QStringList::split(mDelimiter, parentPath);
00128 uint i = 0;
00129
for ( QStringList::Iterator it = folders.begin(); it != folders.end(); ++it )
00130 {
00131
QString name = *it;
00132
if (name.startsWith(
"/"))
00133 name = name.right(name.length()-1);
00134
if (name.endsWith(
"/"))
00135 name.truncate(name.length()-1);
00136 KGroupInfo info(name);
00137
if ((
"/"+name+
"/") == ai->prefix())
00138 {
00139 ++i;
00140
continue;
00141 }
00142 info.subscribed =
false;
00143
00144
QStringList tmpPath;
00145
for ( uint j = 0; j <= i; ++j )
00146 tmpPath << folders[j];
00147
QString path = tmpPath.join(mDelimiter);
00148
if (!path.startsWith(
"/"))
00149 path =
"/" + path;
00150
if (!path.endsWith(
"/"))
00151 path = path +
"/";
00152 info.path = path;
00153 item = 0;
00154
if (folders.count() > 1)
00155 {
00156
00157
00158 item = mItemDict[path];
00159 }
00160
00161
if (!item)
00162 {
00163
if (parent)
00164 item =
new GroupItem(parent, info,
this,
false);
00165
else
00166 item =
new GroupItem(folderTree(), info,
this,
false);
00167 mItemDict.insert(info.path, item);
00168 }
00169
00170 parent = item;
00171 ++i;
00172 }
00173 }
00174
00175 KGroupInfo info(mFolderNames[i]);
00176
if (mFolderNames[i].upper() ==
"INBOX" &&
00177 mFolderPaths[i] ==
"/INBOX/")
00178 info.name = i18n(
"inbox");
00179 info.subscribed =
false;
00180 info.path = mFolderPaths[i];
00181
00182
bool checkable = ( mFolderMimeTypes[i] ==
"inode/directory" ) ?
false :
true;
00183
00184
if (parent)
00185 item =
new GroupItem(parent, info,
this, checkable);
00186
else
00187 item =
new GroupItem(folderTree(), info,
this, checkable);
00188
00189
if (oldItem)
00190 mItemDict.remove(info.path);
00191
00192 mItemDict.insert(info.path, item);
00193
if (oldItem)
00194 {
00195
00196
QPtrList<QListViewItem> itemsToMove;
00197
QListViewItem * myChild = oldItem->firstChild();
00198
while (myChild)
00199 {
00200 itemsToMove.append(myChild);
00201 myChild = myChild->nextSibling();
00202 }
00203
QPtrListIterator<QListViewItem> it( itemsToMove );
00204
QListViewItem *cur;
00205
while ((cur = it.current()))
00206 {
00207 oldItem->takeItem(cur);
00208 item->insertItem(cur);
00209
if ( cur->isSelected() )
00210 folderTree()->ensureItemVisible( cur );
00211 ++it;
00212 }
00213
delete oldItem;
00214 itemsToMove.clear();
00215 }
00216
00217
if ( mFolderPaths[i] == mStartPath )
00218 {
00219 item->setSelected(
true );
00220 folderTree()->ensureItemVisible( item );
00221 }
00222
00223 }
else if (onlySubscribed)
00224 {
00225
00226
if ( mItemDict[mFolderPaths[i]] )
00227 {
00228 GroupItem* item = mItemDict[mFolderPaths[i]];
00229 item->setOn(
true );
00230 }
00231 }
00232 }
00233
if ( mJobData.inboxOnly )
00234 {
00235
00236 ImapAccountBase::ListType type = ImapAccountBase::List;
00237
if ( onlySubscribed )
00238 type = ImapAccountBase::ListSubscribedNoCheck;
00239
ListJob* job =
new ListJob( 0, ai, type,
true,
true,
00240
false, ai->prefix() );
00241 connect( job, SIGNAL(receivedFolders(
const QStringList&,
const QStringList&,
00242
const QStringList&,
const QStringList&,
const ImapAccountBase::jobData&)),
00243
this, SLOT(slotListDirectory(
const QStringList&,
const QStringList&,
00244
const QStringList&,
const QStringList&,
const ImapAccountBase::jobData&)));
00245 job->start();
00246 }
else if (!onlySubscribed)
00247 {
00248
00249
00250
00251
00252
00253
bool complete = (ai->prefix() ==
"/") ?
true :
false;
00254 ListJob* job =
new ListJob( 0, ai, ImapAccountBase::ListSubscribedNoCheck,
00255
false, complete,
false, ai->prefix() );
00256 connect( job, SIGNAL(receivedFolders(
const QStringList&,
const QStringList&,
00257
const QStringList&,
const QStringList&,
const ImapAccountBase::jobData&)),
00258
this, SLOT(slotListDirectory(
const QStringList&,
const QStringList&,
00259
const QStringList&,
const QStringList&,
const ImapAccountBase::jobData&)));
00260 job->start();
00261 }
else if (onlySubscribed)
00262 {
00263
00264 slotLoadingComplete();
00265 }
00266 }
00267
00268
00269
void SubscriptionDialog::findParentItem(
QString &name,
QString &path,
QString &parentPath,
00270 GroupItem **parent, GroupItem **oldItem )
00271 {
00272
00273
int start = path.length() - (name.length()+2);
00274
int length = name.length()+1;
00275
if (start < 0) start = 0;
00276 parentPath = path;
00277 parentPath.remove(start, length);
00278
00279
if (mDelimiter.isEmpty())
00280
return;
00281
00282
00283 *parent = mItemDict[parentPath];
00284
00285
00286
if (mCheckForExisting)
00287 *oldItem = mItemDict[path];
00288 }
00289
00290
00291
void SubscriptionDialog::slotSave()
00292 {
00293
if (!account())
00294
return;
00295
00296
QListViewItemIterator it(subView);
00297
for ( ; it.current(); ++it)
00298 {
00299 static_cast<ImapAccountBase*>(account())->changeSubscription(
true,
00300 static_cast<GroupItem*>(it.current())->info().path);
00301 }
00302
00303
00304
QListViewItemIterator it2(unsubView);
00305
for ( ; it2.current(); ++it2)
00306 {
00307 static_cast<ImapAccountBase*>(account())->changeSubscription(
false,
00308 static_cast<GroupItem*>(it2.current())->info().path);
00309 }
00310 }
00311
00312
00313
void SubscriptionDialog::slotLoadFolders()
00314 {
00315
00316 KSubscription::slotLoadFolders();
00317
if ( !account() )
00318
return;
00319 ImapAccountBase* ai = static_cast<ImapAccountBase*>(account());
00320
if ( ai->prefix().isEmpty() )
00321
return;
00322 mItemDict.clear();
00323
00324
00325
bool complete = (ai->prefix() ==
"/") ?
true :
false;
00326
00327 ListJob* job =
new ListJob( 0, ai, ImapAccountBase::List,
false,
00328 complete,
false, ai->prefix() );
00329 connect( job, SIGNAL(receivedFolders(
const QStringList&,
const QStringList&,
00330
const QStringList&,
const QStringList&,
const ImapAccountBase::jobData&)),
00331
this, SLOT(slotListDirectory(
const QStringList&,
const QStringList&,
00332
const QStringList&,
const QStringList&,
const ImapAccountBase::jobData&)));
00333 job->start();
00334 }
00335
00336
00337
void SubscriptionDialog::slotCancel()
00338 {
00339
if ( account() )
00340 {
00341 ImapAccountBase* ai = static_cast<ImapAccountBase*>(account());
00342 ai->killAllJobs();
00343 }
00344 KSubscription::slotCancel();
00345 }
00346
00347 }
00348
00349
#include "subscriptiondialog.moc"