36 #include "subscriptiondialog.h"
37 #include "folderstorage.h"
39 #include "imapaccountbase.h"
41 #include <tdelocale.h>
43 #include <tdemessagebox.h>
48 SubscriptionDialogBase::SubscriptionDialogBase( TQWidget *parent,
const TQString &caption,
49 KAccount *acct, TQString startPath )
50 : KSubscription( parent, caption, acct, User1, TQString(), false ),
51 mStartPath( startPath ), mSubscribed( false ), mForceSubscriptionEnable( false)
55 hideNewOnlyCheckbox();
58 connect(
this, TQ_SIGNAL(okClicked()), TQ_SLOT(slotSave()));
61 connect(
this, TQ_SIGNAL(user1Clicked()), TQ_SLOT(slotLoadFolders()));
65 TQTimer::singleShot(0,
this, TQ_SLOT(slotLoadFolders()));
69 void SubscriptionDialogBase::slotListDirectory(
const TQStringList& subfolderNames,
70 const TQStringList& subfolderPaths,
71 const TQStringList& subfolderMimeTypes,
72 const TQStringList& subfolderAttributes,
73 const ImapAccountBase::jobData& jobData )
75 mFolderNames = subfolderNames;
76 mFolderPaths = subfolderPaths;
77 mFolderMimeTypes = subfolderMimeTypes;
78 mFolderAttributes = subfolderAttributes;
83 processFolderListing();
86 void SubscriptionDialogBase::moveChildrenToNewParent( GroupItem *oldItem, GroupItem *item )
88 if ( !oldItem || !item )
return;
90 TQPtrList<TQListViewItem> itemsToMove;
91 TQListViewItem * myChild = oldItem->firstChild();
94 itemsToMove.append(myChild);
95 myChild = myChild->nextSibling();
97 TQPtrListIterator<TQListViewItem> it( itemsToMove );
99 while ((cur = it.current()))
101 oldItem->takeItem(cur);
102 item->insertItem(cur);
103 if ( cur->isSelected() )
104 folderTree()->ensureItemVisible( cur );
111 void SubscriptionDialogBase::createListViewItem(
int i )
114 GroupItem *parent = 0;
117 GroupItem *oldItem = 0;
119 findParentItem( mFolderNames[i], mFolderPaths[i], parentPath, &parent, &oldItem );
121 if (!parent && parentPath !=
"/")
126 TQStringList folders = TQStringList::split(mDelimiter, parentPath);
128 for ( TQStringList::Iterator it = folders.begin(); it != folders.end(); ++it )
131 if (name.startsWith(
"/"))
132 name = name.right(name.length()-1);
133 if (name.endsWith(
"/"))
134 name.truncate(name.length()-1);
135 KGroupInfo info(name);
136 info.subscribed =
false;
138 TQStringList tmpPath;
139 for ( uint j = 0; j <= i; ++j )
140 tmpPath << folders[j];
141 TQString path = tmpPath.join(mDelimiter);
142 if (!path.startsWith(
"/"))
144 if (!path.endsWith(
"/"))
148 if (folders.count() > 1)
152 item = mItemDict[path];
158 item =
new GroupItem(parent, info,
this,
false);
160 item =
new GroupItem(folderTree(), info,
this,
false);
161 mItemDict.insert(info.path, item);
169 KGroupInfo info(mFolderNames[i]);
170 if (mFolderNames[i].upper() ==
"INBOX" &&
171 mFolderPaths[i] ==
"/INBOX/")
172 info.name = i18n(
"inbox");
173 info.subscribed =
false;
174 info.path = mFolderPaths[i];
176 bool checkable = ( mFolderMimeTypes[i] ==
"inode/directory" ) ?
false :
true;
179 item =
new GroupItem(parent, info,
this, checkable);
181 item =
new GroupItem(folderTree(), info,
this, checkable);
184 mItemDict.remove(info.path);
186 mItemDict.insert(info.path, item);
188 moveChildrenToNewParent( oldItem, item );
191 if ( mFolderPaths[i] == mStartPath )
193 item->setSelected(
true );
194 folderTree()->ensureItemVisible( item );
201 void SubscriptionDialogBase::findParentItem( TQString &name, TQString &path, TQString &parentPath,
202 GroupItem **parent, GroupItem **oldItem )
205 int start = path.length() - (name.length()+2);
206 int length = name.length()+1;
207 if (start < 0) start = 0;
209 parentPath.remove(start, length);
212 *parent = mItemDict[parentPath];
215 *oldItem = mItemDict[path];
219 void SubscriptionDialogBase::slotSave()
225 void SubscriptionDialogBase::slotLoadFolders()
227 ImapAccountBase* ai =
static_cast<ImapAccountBase*
>(account());
229 if ( ai->makeConnection() == ImapAccountBase::Error )
231 kdWarning(5006) <<
"SubscriptionDialog - got no connection" << endl;
233 }
else if ( ai->makeConnection() == ImapAccountBase::Connecting )
236 kdDebug(5006) <<
"SubscriptionDialog - waiting for connection" << endl;
237 connect( ai, TQ_SIGNAL( connectionResult(
int,
const TQString&) ),
238 this, TQ_SLOT( slotConnectionResult(
int,
const TQString&) ) );
242 KSubscription::slotLoadFolders();
249 listAllAvailableAndCreateItems();
253 void SubscriptionDialogBase::processNext()
255 if ( mPrefixList.isEmpty() )
261 if ( mPrefixList.isEmpty() )
272 ImapAccountBase* ai =
static_cast<ImapAccountBase*
>(account());
273 ImapAccountBase::ListType type = ( mSubscribed ?
274 ImapAccountBase::ListSubscribedNoCheck : ImapAccountBase::List );
276 bool completeListing =
true;
277 mCurrentNamespace = mPrefixList.first();
278 mDelimiter = ai->delimiterForNamespace( mCurrentNamespace );
279 mPrefixList.pop_front();
280 if ( mCurrentNamespace ==
"/INBOX/" )
283 ImapAccountBase::ListFolderOnlySubscribed : ImapAccountBase::ListFolderOnly;
284 completeListing =
false;
288 ListJob* job =
new ListJob( ai, type, 0, ai->addPathToNamespace( mCurrentNamespace ), completeListing );
289 connect( job, TQ_SIGNAL(receivedFolders(
const TQStringList&,
const TQStringList&,
290 const TQStringList&,
const TQStringList&,
const ImapAccountBase::jobData&)),
291 this, TQ_SLOT(slotListDirectory(
const TQStringList&,
const TQStringList&,
292 const TQStringList&,
const TQStringList&,
const ImapAccountBase::jobData&)));
296 void SubscriptionDialogBase::loadingComplete()
298 slotLoadingComplete();
306 SubscriptionDialog::SubscriptionDialog( TQWidget *parent,
const TQString &caption,
307 KAccount *acct, TQString startPath )
308 : SubscriptionDialogBase( parent, caption, acct, startPath )
313 SubscriptionDialog::~SubscriptionDialog()
319 void SubscriptionDialog::listAllAvailableAndCreateItems()
326 void SubscriptionDialogBase::initPrefixList()
328 ImapAccountBase* ai =
static_cast<ImapAccountBase*
>(account());
329 ImapAccountBase::nsMap map = ai->namespaces();
332 bool hasInbox =
false;
333 const TQStringList ns = map[ImapAccountBase::PersonalNS];
334 for ( TQStringList::ConstIterator it = ns.begin(); it != ns.end(); ++it )
336 if ( (*it).isEmpty() )
339 if ( !hasInbox && !ns.isEmpty() )
343 mPrefixList +=
"/INBOX/";
346 mPrefixList += map[ImapAccountBase::PersonalNS];
347 mPrefixList += map[ImapAccountBase::OtherUsersNS];
348 mPrefixList += map[ImapAccountBase::SharedNS];
351 void SubscriptionDialogBase::slotConnectionResult(
int errorCode,
const TQString& errorMsg )
353 Q_UNUSED( errorMsg );
358 void SubscriptionDialogBase::show()
365 void SubscriptionDialog::processFolderListing()
371 void SubscriptionDialog::doSave()
373 KMail::ImapAccountBase *a =
static_cast<KMail::ImapAccountBase*
>(mAcct);
374 if( !a->onlySubscribedFolders() ) {
375 int result = KMessageBox::questionYesNoCancel(
this,
376 i18n(
"Currently subscriptions are not used for server. %1\nDo you want to enable subscriptions?")
378 i18n(
"Enable Subscriptions?"), i18n(
"Enable"), i18n(
"Do Not Enable"));
380 case KMessageBox::Yes:
381 mForceSubscriptionEnable =
true;
383 case KMessageBox::No:
385 case KMessageBox::Cancel:
391 TQListViewItemIterator it(subView);
392 for ( ; it.current(); ++it)
394 static_cast<ImapAccountBase*
>(account())->changeSubscription(
true,
395 static_cast<GroupItem*
>(it.current())->info().path);
399 TQListViewItemIterator it2(unsubView);
400 for ( ; it2.current(); ++it2)
402 static_cast<ImapAccountBase*
>(account())->changeSubscription(
false,
403 static_cast<GroupItem*
>(it2.current())->info().path);
406 if ( mForceSubscriptionEnable ) {
407 a->setOnlySubscribedFolders(
true);
411 void SubscriptionDialog::processItems()
413 bool onlySubscribed = mJobData.onlySubscribed;
415 for (uint i = mCount; i < mFolderNames.count(); ++i)
421 TQTimer::singleShot(0,
this, TQ_SLOT(processItems()));
426 if (!onlySubscribed && mFolderPaths.size() > 0)
428 createListViewItem( i );
429 }
else if (onlySubscribed)
432 if ( mItemDict[mFolderPaths[i]] )
434 GroupItem* item = mItemDict[mFolderPaths[i]];
444 #include "subscriptiondialog.moc"