6 #include "kmfoldertree.h"
8 #include "kmfoldermgr.h"
10 #include "kmfolderimap.h"
11 #include "kmfoldercachedimap.h"
12 #include "kmfolderdia.h"
13 #include "kmheaders.h"
14 #include "kmmainwidget.h"
15 #include "kmailicalifaceimpl.h"
16 #include "accountmanager.h"
18 #include "globalsettings.h"
19 #include "kmcommands.h"
20 #include "foldershortcutdialog.h"
21 #include "expirypropertiesdialog.h"
22 #include "newfolderdialog.h"
24 #include "messagecopyhelper.h"
26 #include "favoritefolderview.h"
27 #include "folderviewtooltip.h"
28 using KMail::FolderViewToolTip;
30 #include <maillistdrag.h>
33 #include <tdeapplication.h>
34 #include <tdeglobalsettings.h>
35 #include <kiconloader.h>
36 #include <tdemessagebox.h>
37 #include <tdeconfig.h>
38 #include <tdepopupmenu.h>
41 #include <tqpainter.h>
44 #include <tqpopupmenu.h>
54 KMFolderTreeItem::KMFolderTreeItem( KFolderTree *parent,
const TQString & name,
55 KFolderTreeItem::Protocol protocol )
56 : TQObject( parent, name.latin1() ),
57 KFolderTreeItem( parent, name, protocol, Root ),
58 mFolder( 0 ), mNeedsRepaint( true )
61 setPixmap( 0, normalIcon( iconSize() ) );
65 KMFolderTreeItem::KMFolderTreeItem( KFolderTree *parent,
const TQString & name,
67 : TQObject( parent, name.latin1() ),
68 KFolderTreeItem( parent, name ),
69 mFolder( folder ), mNeedsRepaint( true )
72 setPixmap( 0, normalIcon( iconSize() ) );
76 KMFolderTreeItem::KMFolderTreeItem( KFolderTreeItem *parent,
const TQString & name,
78 : TQObject( 0, name.latin1() ),
79 KFolderTreeItem( parent, name ),
80 mFolder( folder ), mNeedsRepaint( true )
83 setPixmap( 0, normalIcon( iconSize() ) );
86 KMFolderTreeItem::~KMFolderTreeItem()
90 static KFolderTreeItem::Protocol protocolFor( KMFolderType t ) {
92 case KMFolderTypeImap:
93 return KFolderTreeItem::Imap;
94 case KMFolderTypeCachedImap:
95 return KFolderTreeItem::CachedImap;
96 case KMFolderTypeMbox:
97 case KMFolderTypeMaildir:
98 return KFolderTreeItem::Local;
99 case KMFolderTypeSearch:
100 return KFolderTreeItem::Search;
102 return KFolderTreeItem::NONE;
106 TQPixmap KMFolderTreeItem::normalIcon(
int size)
const
109 if ( (!mFolder && type() == Root) || useTopLevelIcon() ) {
110 switch ( protocol() ) {
111 case KFolderTreeItem::Imap:
112 case KFolderTreeItem::CachedImap:
113 case KFolderTreeItem::News:
114 icon =
"server";
break;
115 case KFolderTreeItem::Search:
116 icon =
"viewmag";
break;
118 icon =
"folder";
break;
123 case Inbox: icon =
"folder_inbox";
break;
124 case Outbox: icon =
"folder_outbox";
break;
125 case SentMail: icon =
"folder_sent_mail";
break;
126 case Trash: icon =
"trashcan_empty";
break;
127 case Drafts: icon =
"edit";
break;
128 case Templates: icon =
"document-new";
break;
132 if(kmkernel->iCalIface().isResourceFolder( mFolder ))
133 icon = kmkernel->iCalIface().folderPixmap( type() );
138 if ( protocol() == KMFolderTreeItem::Search ) {
141 if ( mFolder && mFolder->noContent() ) {
142 icon =
"folder_grey";
146 if ( icon.isEmpty() )
149 if (mFolder && mFolder->useCustomIcons() ) {
150 icon = mFolder->normalIconPath();
152 TDEIconLoader * il = TDEGlobal::instance()->iconLoader();
153 TQPixmap pm = il->loadIcon( icon, TDEIcon::Small, size,
154 TDEIcon::DefaultState, 0,
true );
155 if ( mFolder && pm.isNull() ) {
156 pm = il->loadIcon( mFolder->normalIconPath(), TDEIcon::Small, size,
157 TDEIcon::DefaultState, 0,
true );
163 TQPixmap KMFolderTreeItem::unreadIcon(
int size)
const
167 if ( !mFolder || useTopLevelIcon() || mFolder->isSystemFolder() ||
168 kmkernel->folderIsTrash( mFolder ) ||
169 kmkernel->folderIsTemplates( mFolder ) ||
170 kmkernel->folderIsDraftOrOutbox( mFolder ) )
171 pm = normalIcon( size );
173 TDEIconLoader * il = TDEGlobal::instance()->iconLoader();
174 if ( mFolder && mFolder->useCustomIcons() ) {
175 pm = il->loadIcon( mFolder->unreadIconPath(), TDEIcon::Small, size,
176 TDEIcon::DefaultState, 0,
true );
178 pm = il->loadIcon( mFolder->normalIconPath(), TDEIcon::Small, size,
179 TDEIcon::DefaultState, 0,
true );
182 if ( mFolder && mFolder->noContent() ) {
183 pm = il->loadIcon(
"folder_grey_open", TDEIcon::Small, size,
184 TDEIcon::DefaultState, 0,
true );
186 if( kmkernel->iCalIface().isResourceFolder( mFolder ) )
187 pm = il->loadIcon( kmkernel->iCalIface().folderPixmap( type() ),
188 TDEIcon::Small, size, TDEIcon::DefaultState, 0,
true );
190 pm = il->loadIcon(
"folder_open", TDEIcon::Small, size,
191 TDEIcon::DefaultState, 0,
true );
198 void KMFolderTreeItem::init()
203 setProtocol( protocolFor( mFolder->folderType() ) );
205 if ( useTopLevelIcon() )
208 if ( mFolder == kmkernel->inboxFolder() )
210 else if ( kmkernel->folderIsDraftOrOutbox( mFolder ) ) {
211 if ( mFolder == kmkernel->outboxFolder() )
216 else if ( kmkernel->folderIsSentMailFolder( mFolder ) )
218 else if ( kmkernel->folderIsTrash( mFolder ) )
220 else if ( kmkernel->folderIsTemplates( mFolder ) )
221 setType( Templates );
222 else if( kmkernel->iCalIface().isResourceFolder(mFolder) )
223 setType( kmkernel->iCalIface().folderType(mFolder) );
226 if ( mFolder->isSystemFolder() &&
227 !kmkernel->iCalIface().isResourceFolder( mFolder) &&
228 ( mFolder->folderType() == KMFolderTypeImap
229 || mFolder->folderType() == KMFolderTypeCachedImap ) )
232 if ( !mFolder->isSystemFolder() )
233 setRenameEnabled( 0,
false );
235 KMFolderTree* tree =
dynamic_cast<KMFolderTree*
>( listView() );
237 tree->insertIntoFolderToItemMap( mFolder,
this );
240 void KMFolderTreeItem::adjustUnreadCount(
int newUnreadCount ) {
243 if ( newUnreadCount != 0 && unreadCount() == 0 )
244 setPixmap( 0, unreadIcon( iconSize() ) );
245 if ( unreadCount() != 0 && newUnreadCount == 0 )
246 setPixmap( 0, normalIcon( iconSize() ) );
248 setUnreadCount( newUnreadCount );
251 void KMFolderTreeItem::slotIconsChanged()
253 kdDebug(5006) << k_funcinfo << endl;
255 KFolderTreeItem::Type newType = type();
256 if( kmkernel->iCalIface().isResourceFolder( mFolder ) )
257 newType = kmkernel->iCalIface().folderType(mFolder);
261 if ( type() != newType )
262 static_cast<KMFolderTree*
>( listView() )->delayedReload();
265 if ( unreadCount() > 0 )
266 setPixmap( 0, unreadIcon( iconSize() ) );
268 setPixmap( 0, normalIcon( iconSize() ) );
269 emit iconChanged(
this );
273 void KMFolderTreeItem::slotNameChanged()
275 setText( 0, mFolder->label() );
276 emit nameChanged(
this );
280 void KMFolderTreeItem::slotNoContentChanged()
284 TQTimer::singleShot( 0,
static_cast<KMFolderTree*
>( listView() ), TQ_SLOT(reload()) );
288 bool KMFolderTreeItem::acceptDrag(TQDropEvent* e)
const
292 KMMainWidget *mainWidget =
static_cast<KMFolderTree*
>( listView() )->mainWidget();
293 assert( mainWidget );
294 if ( mainWidget->favoriteFolderView() &&
295 e->source() == mainWidget->favoriteFolderView()->viewport() )
298 if ( protocol() == KFolderTreeItem::Search )
301 if ( e->provides( KPIM::MailListDrag::format() ) ) {
302 if ( !mFolder || mFolder->moveInProgress() || mFolder->isReadOnly() ||
303 (mFolder->noContent() && childCount() == 0) ||
304 (mFolder->noContent() && isOpen()) ) {
310 }
else if ( e->provides(
"application/x-qlistviewitem") ) {
312 if ( !mFolder && protocol() == KFolderTreeItem::NONE && type() == KFolderTreeItem::Root )
314 if ( !mFolder || mFolder->isReadOnly() || mFolder->noContent() )
322 void KMFolderTreeItem::slotShowExpiryProperties()
327 KMFolderTree* tree =
static_cast<KMFolderTree*
>( listView() );
328 KMail::ExpiryPropertiesDialog *dlg =
329 new KMail::ExpiryPropertiesDialog( tree, mFolder );
335 void KMFolderTreeItem::properties()
340 KMail::FolderTreeBase* tree =
static_cast<KMail::FolderTreeBase*
>( listView() );
341 tree->mainWidget()->modifyFolder(
this );
346 void KMFolderTreeItem::assignShortcut()
351 KMail::FolderShortcutDialog *shorty =
352 new KMail::FolderShortcutDialog( mFolder,
353 kmkernel->getKMMainWidget(),
360 void KMFolderTreeItem::updateCount()
366 KMail::FolderTreeBase* tree =
dynamic_cast<KMail::FolderTreeBase*
>( listView() );
369 tree->slotUpdateCounts( folder(),
true );
376 KMFolderTree::KMFolderTree( KMMainWidget *mainWidget, TQWidget *parent,
378 :
KMail::FolderTreeBase( mainWidget, parent, name )
379 , mUpdateTimer( 0,
"mUpdateTimer" )
380 , autoopen_timer( 0,
"autoopen_timer" )
386 mMainWidget = mainWidget;
390 mUpdateCountTimer=
new TQTimer(
this,
"mUpdateCountTimer" );
392 setDragEnabled(
true );
393 addAcceptableDropMimetype(
"application/x-qlistviewitem",
false );
395 setSelectionModeExt( Extended );
397 int namecol = addColumn( i18n(
"Folder"), 250 );
398 header()->setStretchEnabled(
true, namecol );
399 setResizeMode( TQListView::NoColumn );
404 header()->setClickEnabled(
true);
405 header()->installEventFilter(
this);
406 mPopup =
new TDEPopupMenu(
this);
407 mPopup->insertTitle(i18n(
"View Columns"));
408 mPopup->setCheckable(
true);
409 mUnreadPop = mPopup->insertItem(i18n(
"Unread Column"),
this, TQ_SLOT(slotToggleUnreadColumn()));
410 mTotalPop = mPopup->insertItem(i18n(
"Total Column"),
this, TQ_SLOT(slotToggleTotalColumn()));
411 mSizePop = mPopup->insertItem(i18n(
"Size Column"),
this, TQ_SLOT(slotToggleSizeColumn()));
413 connect(
this, TQ_SIGNAL( triggerRefresh() ),
414 this, TQ_SLOT( refresh() ) );
416 new FolderViewToolTip(
this );
421 void KMFolderTree::connectSignals()
423 connect( mUpdateCountTimer, TQ_SIGNAL(timeout()),
424 this, TQ_SLOT(slotUpdateCountTimeout()) );
426 connect(&mUpdateTimer, TQ_SIGNAL(timeout()),
427 this, TQ_SLOT(delayedUpdate()));
429 connect(kmkernel->folderMgr(), TQ_SIGNAL(changed()),
430 this, TQ_SLOT(doFolderListChanged()));
432 connect(kmkernel->folderMgr(), TQ_SIGNAL(folderRemoved(
KMFolder*)),
433 this, TQ_SLOT(slotFolderRemoved(
KMFolder*)));
435 connect(kmkernel->folderMgr(), TQ_SIGNAL(folderMoveOrCopyOperationFinished()),
436 this, TQ_SLOT(slotFolderMoveOrCopyOperationFinished()));
438 connect(kmkernel->imapFolderMgr(), TQ_SIGNAL(changed()),
439 this, TQ_SLOT(doFolderListChanged()));
441 connect(kmkernel->imapFolderMgr(), TQ_SIGNAL(folderRemoved(
KMFolder*)),
442 this, TQ_SLOT(slotFolderRemoved(
KMFolder*)));
444 connect(kmkernel->dimapFolderMgr(), TQ_SIGNAL(changed()),
445 this, TQ_SLOT(doFolderListChanged()));
447 connect(kmkernel->dimapFolderMgr(), TQ_SIGNAL(folderRemoved(
KMFolder*)),
448 this, TQ_SLOT(slotFolderRemoved(
KMFolder*)));
450 connect(kmkernel->searchFolderMgr(), TQ_SIGNAL(changed()),
451 this, TQ_SLOT(doFolderListChanged()));
453 connect(kmkernel->acctMgr(), TQ_SIGNAL(accountRemoved(KMAccount*)),
454 this, TQ_SLOT(slotAccountRemoved(KMAccount*)));
456 connect(kmkernel->acctMgr(), TQ_SIGNAL(accountAdded(KMAccount*)),
457 this, TQ_SLOT(slotUnhideLocalInbox()));
459 connect(kmkernel->searchFolderMgr(), TQ_SIGNAL(folderRemoved(
KMFolder*)),
460 this, TQ_SLOT(slotFolderRemoved(
KMFolder*)));
462 connect( &autoopen_timer, TQ_SIGNAL( timeout() ),
463 this, TQ_SLOT( openFolder() ) );
465 connect(
this, TQ_SIGNAL( contextMenuRequested( TQListViewItem*,
const TQPoint &,
int ) ),
466 this, TQ_SLOT( slotContextMenuRequested( TQListViewItem*,
const TQPoint & ) ) );
468 connect(
this, TQ_SIGNAL( expanded( TQListViewItem* ) ),
469 this, TQ_SLOT( slotFolderExpanded( TQListViewItem* ) ) );
471 connect(
this, TQ_SIGNAL( collapsed( TQListViewItem* ) ),
472 this, TQ_SLOT( slotFolderCollapsed( TQListViewItem* ) ) );
474 connect(
this, TQ_SIGNAL( itemRenamed( TQListViewItem*,
int,
const TQString &)),
475 this, TQ_SLOT( slotRenameFolder( TQListViewItem*,
int,
const TQString &)));
477 connect(
this, TQ_SIGNAL(folderSelected(
KMFolder*)), TQ_SLOT(updateCopyActions()) );
481 void KMFolderTree::readConfig (
void)
483 TDEConfig* conf = KMKernel::config();
489 TDEConfigGroupSaver saver(conf,
"Fonts");
490 if (!conf->readBoolEntry(
"defaultFonts",
true)) {
491 TQFont folderFont( TDEGlobalSettings::generalFont() );
492 setFont(conf->readFontEntry(
"folder-font", &folderFont));
495 setFont(TDEGlobalSettings::generalFont());
499 restoreLayout(conf,
"Geometry");
504 void KMFolderTree::writeConfig()
507 for ( TQListViewItemIterator it(
this ) ; it.current() ; ++it ) {
508 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>(it.current());
510 writeIsListViewItemOpen(fti);
514 saveLayout(KMKernel::config(),
"Geometry");
520 void KMFolderTree::updateUnreadAll()
522 bool upd = isUpdatesEnabled();
523 setUpdatesEnabled(
false);
526 KMFolderNode* folderNode;
529 fdir = &kmkernel->folderMgr()->dir();
530 for (folderNode = fdir->first();
532 folderNode =fdir->next())
534 if (!folderNode->isDir()) {
535 folder =
static_cast<KMFolder*
>(folderNode);
537 folder->
open(
"updateunread");
539 folder->
close(
"updateunread");
543 setUpdatesEnabled(upd);
548 void KMFolderTree::reload(
bool openFolders)
552 kdDebug(5006) <<
"KMFolderTree::reload - already reloading" << endl;
557 int top = contentsY();
565 ( oldCurrent ?
static_cast<KMFolderTreeItem*
>(oldCurrent)->folder(): 0 );
566 for ( TQListViewItemIterator it(
this ) ; it.current() ; ++it ) {
567 KMFolderTreeItem * fti =
static_cast<KMFolderTreeItem*
>(it.current());
568 writeIsListViewItemOpen( fti );
569 if ( fti->isSelected() )
570 selected = fti->folder();
572 mFolderToItem.clear();
576 KMFolderTreeItem * root =
new KMFolderTreeItem(
this, i18n(
"Local Folders") );
577 root->setOpen( readIsListViewItemOpen(root) );
579 KMFolderDir * fdir = &kmkernel->folderMgr()->dir();
580 addDirectory(fdir, root);
582 fdir = &kmkernel->imapFolderMgr()->dir();
584 addDirectory(fdir, 0);
586 fdir = &kmkernel->dimapFolderMgr()->dir();
588 addDirectory(fdir, 0);
591 root =
new KMFolderTreeItem(
this, i18n(
"Searches"), KFolderTreeItem::Search );
592 root->setOpen( readIsListViewItemOpen( root ) );
594 fdir = &kmkernel->searchFolderMgr()->dir();
595 addDirectory(fdir, root);
600 mUpdateIterator = TQListViewItemIterator (
this);
601 TQTimer::singleShot( 0,
this, TQ_SLOT(slotUpdateOneCount()) );
604 for ( TQListViewItemIterator it(
this ) ; it.current() ; ++it ) {
605 KMFolderTreeItem * fti =
static_cast<KMFolderTreeItem*
>(it.current());
606 if ( !fti || !fti->folder() )
609 disconnect(fti->folder(),TQ_SIGNAL(iconsChanged()),
610 fti,TQ_SLOT(slotIconsChanged()));
611 connect(fti->folder(),TQ_SIGNAL(iconsChanged()),
612 fti,TQ_SLOT(slotIconsChanged()));
614 disconnect(fti->folder(),TQ_SIGNAL(nameChanged()),
615 fti,TQ_SLOT(slotNameChanged()));
616 connect(fti->folder(),TQ_SIGNAL(nameChanged()),
617 fti,TQ_SLOT(slotNameChanged()));
619 disconnect( fti->folder(), TQ_SIGNAL(noContentChanged()),
620 fti, TQ_SLOT(slotNoContentChanged()) );
621 connect( fti->folder(), TQ_SIGNAL(noContentChanged()),
622 fti, TQ_SLOT(slotNoContentChanged()) );
624 disconnect( fti->folder(), TQ_SIGNAL(syncStateChanged()),
625 this, TQ_SLOT(slotSyncStateChanged()) );
626 connect( fti->folder(), TQ_SIGNAL(syncStateChanged()),
627 this, TQ_SLOT(slotSyncStateChanged()) );
630 disconnect(fti->folder(), TQ_SIGNAL(msgAdded(
KMFolder*,TQ_UINT32)),
631 this,TQ_SLOT(slotUpdateCountsDelayed(
KMFolder*)));
632 connect(fti->folder(), TQ_SIGNAL(msgAdded(
KMFolder*,TQ_UINT32)),
633 this,TQ_SLOT(slotUpdateCountsDelayed(
KMFolder*)));
636 disconnect(fti->folder(), TQ_SIGNAL(numUnreadMsgsChanged(
KMFolder*)),
637 this,TQ_SLOT(slotUpdateCountsDelayed(
KMFolder*)));
638 connect(fti->folder(), TQ_SIGNAL(numUnreadMsgsChanged(
KMFolder*)),
639 this,TQ_SLOT(slotUpdateCountsDelayed(
KMFolder*)));
640 disconnect(fti->folder(), TQ_SIGNAL(msgRemoved(
KMFolder*)),
641 this,TQ_SLOT(slotUpdateCountsDelayed(
KMFolder*)));
642 connect(fti->folder(), TQ_SIGNAL(msgRemoved(
KMFolder*)),
643 this,TQ_SLOT(slotUpdateCountsDelayed(
KMFolder*)));
645 disconnect(fti->folder(), TQ_SIGNAL(folderSizeChanged(
KMFolder* )),
646 this,TQ_SLOT(slotUpdateCountsDelayed(
KMFolder*)));
647 connect(fti->folder(), TQ_SIGNAL(folderSizeChanged(
KMFolder* )),
648 this,TQ_SLOT(slotUpdateCountsDelayed(
KMFolder*)));
652 disconnect(fti->folder(), TQ_SIGNAL(shortcutChanged(
KMFolder*)),
653 mMainWidget, TQ_SLOT( slotShortcutChanged(
KMFolder*)));
654 connect(fti->folder(), TQ_SIGNAL(shortcutChanged(
KMFolder*)),
655 mMainWidget, TQ_SLOT( slotShortcutChanged(
KMFolder*)));
659 slotUpdateCounts(fti->folder());
662 fti->setFolderSize( 0 );
663 fti->setFolderIsCloseToQuota( fti->folder()->storage()->isCloseToQuota() );
666 ensureVisible(0, top + visibleHeight(), 0, 0);
668 for ( TQListViewItemIterator it(
this ) ; it.current() ; ++it )
671 static_cast<KMFolderTreeItem*
>( it.current() )->folder() == last )
673 mLastItem =
static_cast<KMFolderTreeItem*
>( it.current() );
674 setCurrentItem( it.current() );
677 static_cast<KMFolderTreeItem*
>( it.current() )->folder() == selected )
679 setSelected( it.current(),
true );
681 if ( oldCurrentFolder &&
682 static_cast<KMFolderTreeItem*
>( it.current() )->folder() == oldCurrentFolder )
684 oldCurrent = it.current();
692 void KMFolderTree::slotUpdateOneCount()
694 if ( !mUpdateIterator.current() )
return;
695 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>(mUpdateIterator.current());
697 if ( !fti->folder() ) {
699 TQTimer::singleShot( 0,
this, TQ_SLOT(slotUpdateOneCount()) );
704 bool open = fti->folder()->isOpened();
705 if (!open) fti->folder()->open(
"updatecount");
706 slotUpdateCounts(fti->folder());
708 if (!open) fti->folder()->close(
"updatecount");
710 TQTimer::singleShot( 0,
this, TQ_SLOT(slotUpdateOneCount()) );
715 void KMFolderTree::addDirectory(
KMFolderDir *fdir, KMFolderTreeItem* parent )
717 for ( KMFolderNode * node = fdir->first() ; node ; node = fdir->next() ) {
722 KMFolderTreeItem * fti = 0;
727 if ( kmkernel->iCalIface().hideResourceAccountRoot( folder ) )
730 fti =
new KMFolderTreeItem(
this, folder->
label(), folder );
731 fti->setExpandable(
true );
734 if (folder && folder->
child()) {
735 addDirectory( folder->
child(), fti );
739 if ( kmkernel->inboxFolder() == folder && hideLocalInbox() ) {
740 connect( kmkernel->inboxFolder(), TQ_SIGNAL(msgAdded(
KMFolder*,TQ_UINT32)), TQ_SLOT(slotUnhideLocalInbox()) );
745 fti =
new KMFolderTreeItem( parent, folder->
label(), folder );
749 if ( folder->storage()->
hasChildren() == FolderStorage::HasChildren ) {
750 fti->setExpandable(
true );
752 fti->setExpandable(
false );
756 if (folder && folder->
child()) {
757 addDirectory( folder->
child(), fti );
762 if ( (kmkernel->iCalIface().hideResourceFolder( folder ) || folder->
noContent())
763 && fti->childCount() == 0 ) {
765 removeFromFolderToItemMap( folder );
768 connect ( folder, TQ_SIGNAL(noContentChanged()), TQ_SLOT(delayedReload()) );
772 connect (fti, TQ_SIGNAL(iconChanged(KMFolderTreeItem*)),
773 this, TQ_SIGNAL(iconChanged(KMFolderTreeItem*)));
774 connect (fti, TQ_SIGNAL(nameChanged(KMFolderTreeItem*)),
775 this, TQ_SIGNAL(nameChanged(KMFolderTreeItem*)));
778 fti->setOpen( readIsListViewItemOpen(fti) );
784 void KMFolderTree::refresh()
786 mUpdateTimer.changeInterval(200);
791 void KMFolderTree::delayedUpdate()
793 bool upd = isUpdatesEnabled();
795 setUpdatesEnabled(
false);
797 for ( TQListViewItemIterator it(
this ) ; it.current() ; ++it ) {
798 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>(it.current());
799 if (!fti || !fti->folder())
802 if ( fti->needsRepaint() ) {
804 fti->setNeedsRepaint(
false );
807 setUpdatesEnabled(upd);
814 void KMFolderTree::doFolderListChanged()
820 void KMFolderTree::slotAccountRemoved(KMAccount *)
822 doFolderSelected( firstChild() );
826 void KMFolderTree::slotFolderMoveOrCopyOperationFinished()
828 setDragEnabled(
true );
831 void KMFolderTree::slotFolderRemoved(
KMFolder *aFolder)
833 TQListViewItem *item = indexOfFolder(aFolder);
835 KMFolderTreeItem *fti =
static_cast<KMFolderTreeItem*
> ( item );
836 if ( oldCurrent == fti )
838 if ( oldSelected == fti )
840 if (!fti || !fti->folder())
return;
841 if (fti == currentItem())
843 TQListViewItem *qlvi = fti->itemAbove();
844 if (!qlvi) qlvi = fti->itemBelow();
845 doFolderSelected( qlvi );
847 removeFromFolderToItemMap( aFolder );
849 if ( dropItem == fti ) {
859 void KMFolderTree::prepareItem( KMFolderTreeItem* fti )
861 for ( TQListViewItem * parent = fti->parent() ; parent ; parent = parent->parent() )
862 parent->setOpen(
true );
863 ensureItemVisible( fti );
867 void KMFolderTree::nextUnreadFolder()
869 nextUnreadFolder(
false );
873 void KMFolderTree::nextUnreadFolder(
bool confirm)
875 TQListViewItemIterator it( currentItem() ? currentItem() : firstChild() );
878 for ( ; it.current() ; ++it ) {
880 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>(it.current());
881 if (checkUnreadFolder(fti,confirm))
return;
887 for ( it = firstChild() ; it.current() ; ++it ) {
889 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>(it.current());
890 if (checkUnreadFolder(fti,confirm))
return;
896 bool KMFolderTree::checkUnreadFolder (KMFolderTreeItem* fti,
bool confirm)
898 if ( fti && fti->folder() && !fti->folder()->ignoreNewMail() &&
899 ( fti->folder()->countUnread() > 0 ) ) {
902 if (fti->type() == KFolderTreeItem::Trash ||
903 fti->type() == KFolderTreeItem::Outbox )
911 if ( fti->type() == KFolderTreeItem::Drafts ||
912 fti->type() == KFolderTreeItem::Templates ||
913 fti->type() == KFolderTreeItem::SentMail )
919 if ( KMessageBox::questionYesNo(
this,
920 i18n(
"<qt>Go to the next unread message in folder <b>%1</b>?</qt>" )
921 .arg( fti->folder()->label() ),
922 i18n(
"Go to Next Unread Message" ),
923 i18n(
"Go To"), i18n(
"Do Not Go To"),
926 == KMessageBox::No )
return true;
929 blockSignals(
true );
930 doFolderSelected( fti );
931 blockSignals(
false );
932 emit folderSelectedUnread( fti->folder() );
939 void KMFolderTree::prevUnreadFolder()
941 TQListViewItemIterator it( currentItem() ? currentItem() : lastItem() );
944 for ( ; it.current() ; --it ) {
945 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>(it.current());
946 if (checkUnreadFolder(fti,
false))
return;
951 void KMFolderTree::incCurrentFolder()
953 TQListViewItemIterator it( currentItem() );
955 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>(it.current());
959 setCurrentItem( fti );
964 void KMFolderTree::decCurrentFolder()
966 TQListViewItemIterator it( currentItem() );
968 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>(it.current());
972 setCurrentItem( fti );
977 void KMFolderTree::selectCurrentFolder()
979 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>( currentItem() );
982 doFolderSelected( fti );
987 KMFolder *KMFolderTree::currentFolder()
const
989 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>( currentItem() );
991 return fti->folder();
996 TQValueList<TQGuardedPtr<KMFolder> > KMFolderTree::selectedFolders()
998 TQValueList<TQGuardedPtr<KMFolder> > rv;
999 for ( TQListViewItemIterator it(
this ); it.current(); ++it ) {
1000 if ( it.current()->isSelected() ) {
1001 KMFolderTreeItem *fti =
static_cast<KMFolderTreeItem*
>( it.current() );
1002 rv.append( fti->folder() );
1012 void KMFolderTree::doFolderSelected( TQListViewItem* qlvi,
bool keepSelection )
1015 if ( mLastItem && mLastItem == qlvi && (keepSelection || selectedFolders().count() == 1) )
1018 KMFolderTreeItem* fti =
static_cast< KMFolderTreeItem*
>(qlvi);
1020 if (fti) folder = fti->folder();
1022 if (mLastItem && mLastItem != fti && mLastItem->folder()
1023 && (mLastItem->folder()->folderType() == KMFolderTypeImap))
1025 KMFolderImap *imapFolder =
static_cast<KMFolderImap*
>(mLastItem->folder()->storage());
1026 imapFolder->setSelected(
false);
1030 if ( !keepSelection )
1032 setCurrentItem( qlvi );
1033 if ( !keepSelection )
1034 setSelected( qlvi,
true );
1035 ensureItemVisible( qlvi );
1037 emit folderSelected(0);
1040 emit folderSelected(folder);
1041 slotUpdateCounts(folder);
1046 void KMFolderTree::resizeEvent(TQResizeEvent* e)
1048 TDEConfig* conf = KMKernel::config();
1050 TDEConfigGroupSaver saver(conf,
"Geometry");
1051 conf->writeEntry(name(), size().width());
1053 TDEListView::resizeEvent(e);
1058 void KMFolderTree::slotContextMenuRequested( TQListViewItem *lvi,
1063 setCurrentItem( lvi );
1065 if (!mMainWidget)
return;
1067 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>(lvi);
1068 if ( !isSelected( fti ) )
1069 doFolderSelected( fti );
1070 else if ( fti != mLastItem )
1071 doFolderSelected( fti,
true );
1076 TDEPopupMenu *folderMenu =
new TDEPopupMenu;
1077 bool multiFolder = selectedFolders().count() > 1;
1078 if (fti->folder()) folderMenu->insertTitle(fti->folder()->label());
1081 if ( (fti->folder() == kmkernel->outboxFolder()) && fti->folder()->count() )
1082 mMainWidget->action(
"send_queued")->plug( folderMenu );
1084 if ( fti->folder() && !fti->folder()->noContent() )
1085 mMainWidget->action(
"mark_all_as_read")->plug( folderMenu );
1088 if ((!fti->folder() || (fti->folder()->noContent()
1089 && !fti->parent())))
1091 TQString createChild = i18n(
"&New Subfolder...");
1092 if (!fti->folder()) createChild = i18n(
"&New Folder...");
1094 if ( ( fti->folder() || (fti->text(0) != i18n(
"Searches")) ) && !multiFolder)
1095 folderMenu->insertItem(SmallIconSet(
"folder-new"),
1097 TQ_SLOT(addChildFolder()));
1099 if (!fti->folder()) {
1100 mMainWidget->action(
"compact_all_folders")->plug(folderMenu);
1101 mMainWidget->action(
"expire_all_folders")->plug(folderMenu);
1102 }
else if (fti->folder()->folderType() == KMFolderTypeImap) {
1103 folderMenu->insertItem(SmallIconSet(
"mail_get"), i18n(
"Check &Mail"),
1105 TQ_SLOT(slotCheckMail()));
1109 folderMenu->insertSeparator();
1110 if ( !fti->folder()->noChildren() && !multiFolder ) {
1111 folderMenu->insertItem(SmallIconSet(
"folder-new"),
1112 i18n(
"&New Subfolder..."),
this,
1113 TQ_SLOT(addChildFolder()));
1117 TQPopupMenu *copyMenu =
new TQPopupMenu( folderMenu );
1118 folderToPopupMenu( CopyFolder,
this, &mMenuToFolder, copyMenu );
1119 folderMenu->insertItem( i18n(
"&Copy Folder To"), copyMenu );
1121 if ( fti->folder()->isMoveable() && fti->folder()->canDeleteMessages() )
1123 TQPopupMenu *moveMenu =
new TQPopupMenu( folderMenu );
1124 folderToPopupMenu( MoveFolder,
this, &mMenuToFolder, moveMenu );
1125 folderMenu->insertItem( i18n(
"&Move Folder To"), moveMenu );
1131 if (!fti->folder()->noContent())
1134 mMainWidget->action(
"search_messages")->plug(folderMenu);
1136 mMainWidget->action(
"archive_folder" )->plug( folderMenu );
1138 mMainWidget->action(
"compact")->plug(folderMenu);
1140 if ( GlobalSettings::self()->enableFavoriteFolderView() ) {
1141 folderMenu->insertItem( SmallIconSet(
"bookmark_add"), i18n(
"Add to Favorite Folders"),
1142 this, TQ_SLOT(slotAddToFavorites()) );
1145 folderMenu->insertSeparator();
1146 mMainWidget->action(
"empty")->plug(folderMenu);
1147 if ( !fti->folder()->isSystemFolder() ) {
1148 mMainWidget->action(
"delete_folder")->plug(folderMenu);
1150 folderMenu->insertSeparator();
1155 if (fti->folder() &&
1156 (fti->folder()->folderType() == KMFolderTypeImap ||
1157 fti->folder()->folderType() == KMFolderTypeCachedImap ))
1159 folderMenu->insertItem(SmallIconSet(
"bookmark_folder"),
1160 i18n(
"Serverside Subscription..."), mMainWidget,
1161 TQ_SLOT(slotSubscriptionDialog()));
1162 folderMenu->insertItem(SmallIcon(
"bookmark_folder"),
1163 i18n(
"Local Subscription..."), mMainWidget,
1164 TQ_SLOT(slotLocalSubscriptionDialog()));
1166 if (!fti->folder()->noContent())
1168 mMainWidget->action(
"refresh_folder")->plug(folderMenu);
1169 if ( fti->folder()->folderType() == KMFolderTypeImap && !multiFolder ) {
1170 folderMenu->insertItem(SmallIconSet(
"reload"), i18n(
"Refresh Folder List"),
this,
1171 TQ_SLOT(slotResetFolderList()));
1174 if ( fti->folder()->folderType() == KMFolderTypeCachedImap && !multiFolder ) {
1175 KMFolderCachedImap * folder =
static_cast<KMFolderCachedImap*
>( fti->folder()->storage() );
1176 folderMenu->insertItem( SmallIconSet(
"wizard"),
1177 i18n(
"&Troubleshoot IMAP Cache..."),
1178 folder, TQ_SLOT(slotTroubleshoot()) );
1180 folderMenu->insertSeparator();
1183 if ( fti->folder() && fti->folder()->isMailingListEnabled() && !multiFolder ) {
1184 mMainWidget->action(
"post_message")->plug(folderMenu);
1187 if (fti->folder() && fti->parent() && !multiFolder)
1189 folderMenu->insertItem(SmallIconSet(
"configure_shortcuts"),
1190 i18n(
"&Assign Shortcut..."),
1192 TQ_SLOT(assignShortcut()));
1194 if ( !fti->folder()->noContent() && fti->folder()->canDeleteMessages() ) {
1195 folderMenu->insertItem( i18n(
"Expire..."), fti,
1196 TQ_SLOT( slotShowExpiryProperties() ) );
1198 mMainWidget->action(
"modify")->plug(folderMenu);
1202 kmkernel->setContextMenuShown(
true );
1203 folderMenu->exec (p, 0);
1204 kmkernel->setContextMenuShown(
false );
1211 void KMFolderTree::contentsMousePressEvent(TQMouseEvent * e)
1214 TDEListView::contentsMousePressEvent( e );
1218 void KMFolderTree::contentsMouseReleaseEvent(TQMouseEvent* me)
1220 TQListViewItem *lvi = currentItem();
1221 ButtonState btn = me->button();
1222 doFolderSelected(lvi,
true);
1225 KMFolderTreeItem* fti =
dynamic_cast<KMFolderTreeItem*
>(lvi);
1227 if (!fti || !fti->folder()) {
1228 KFolderTree::contentsMouseReleaseEvent(me);
1233 if (btn != TQt::MidButton) {
1234 KFolderTree::contentsMouseReleaseEvent(me);
1238 if ( fti->folder()->isMailingListEnabled() ) {
1239 KMCommand *command =
new KMMailingListPostCommand(
this, fti->folder() );
1243 KFolderTree::contentsMouseReleaseEvent(me);
1247 static bool folderHasCreateRights(
const KMFolder *folder )
1249 bool createRights =
true;
1250 if ( folder && folder->
folderType() == KMFolderTypeImap ) {
1251 const KMFolderImap *imapFolder =
static_cast<const KMFolderImap*
>( folder->storage() );
1254 ( imapFolder->userRights() & KMail::ACLJobs::Create ) );
1255 }
else if ( folder && folder->
folderType() == KMFolderTypeCachedImap ) {
1256 const KMFolderCachedImap *dimapFolder =
static_cast<const KMFolderCachedImap*
>( folder->storage() );
1259 ( dimapFolder->userRights() & KMail::ACLJobs::Create ) );
1261 return createRights;
1267 void KMFolderTree::addChildFolder(
KMFolder *folder, TQWidget * parent )
1271 KMFolderTreeItem *fti =
static_cast<KMFolderTreeItem*
>(currentItem());
1274 aFolder = fti->folder();
1279 if ( !folderHasCreateRights( aFolder ) ) {
1280 const TQString message = i18n(
"<qt>Cannot create folder under <b>%1</b> because of insufficient "
1281 "permissions on the server. If you think you should be able to create "
1282 "subfolders here, ask your administrator to grant you rights to do so."
1283 "</qt> " ).arg(aFolder->
label());
1284 KMessageBox::error(
this, message );
1290 (
new KMail::NewFolderDialog( parent, aFolder ) )->exec();
1292 (
new KMail::NewFolderDialog(
this, aFolder ) )->show();
1322 bool KMFolderTree::readIsListViewItemOpen(KMFolderTreeItem *fti)
1324 TDEConfig* config = KMKernel::config();
1329 name =
"Folder-" + folder->
idString();
1330 }
else if (fti->type() == KFolderTreeItem::Root)
1332 if (fti->protocol() == KFolderTreeItem::NONE)
1333 name =
"Folder_local_root";
1334 else if (fti->protocol() == KFolderTreeItem::Search)
1335 name =
"Folder_search";
1341 TDEConfigGroupSaver saver(config, name);
1343 return config->readBoolEntry(
"isOpen",
false);
1348 void KMFolderTree::writeIsListViewItemOpen(KMFolderTreeItem *fti)
1350 TDEConfig* config = KMKernel::config();
1353 if (folder && !folder->
idString().isEmpty())
1355 name =
"Folder-" + folder->
idString();
1356 }
else if (fti->type() == KFolderTreeItem::Root)
1358 if (fti->protocol() == KFolderTreeItem::NONE)
1359 name =
"Folder_local_root";
1360 else if (fti->protocol() == KFolderTreeItem::Search)
1361 name =
"Folder_search";
1367 TDEConfigGroupSaver saver(config, name);
1368 config->writeEntry(
"isOpen", fti->isOpen() );
1373 void KMFolderTree::cleanupConfigFile()
1375 if ( childCount() == 0 )
1377 TDEConfig* config = KMKernel::config();
1378 TQStringList existingFolders;
1379 TQListViewItemIterator fldIt(
this);
1380 TQMap<TQString,bool> folderMap;
1381 KMFolderTreeItem *fti;
1382 for (TQListViewItemIterator fldIt(
this); fldIt.current(); fldIt++)
1384 fti =
static_cast<KMFolderTreeItem*
>(fldIt.current());
1385 if (fti && fti->folder())
1386 folderMap.insert(fti->folder()->idString(),
true);
1388 TQStringList groupList = config->groupList();
1390 for (TQStringList::Iterator grpIt = groupList.begin();
1391 grpIt != groupList.end(); grpIt++)
1393 if ((*grpIt).left(7) !=
"Folder-")
continue;
1394 name = (*grpIt).mid(7);
1395 if (folderMap.find(name) == folderMap.end())
1397 KMFolder* folder = kmkernel->findFolderById( name );
1399 if ( kmkernel->iCalIface().hideResourceFolder( folder )
1400 || kmkernel->iCalIface().hideResourceAccountRoot( folder ) )
1404 if ( folder == kmkernel->inboxFolder() )
1409 config->deleteGroup(*grpIt,
true);
1410 kdDebug(5006) <<
"Deleting information about folder " << name << endl;
1417 void KMFolderTree::openFolder()
1419 autoopen_timer.stop();
1420 if ( dropItem && !dropItem->isOpen() ) {
1421 dropItem->setOpen(
true );
1422 dropItem->repaint();
1426 static const int autoopenTime = 750;
1429 void KMFolderTree::contentsDragEnterEvent( TQDragEnterEvent *e )
1434 oldCurrent = currentItem();
1435 for ( TQListViewItemIterator it(
this ) ; it.current() ; ++it )
1436 if ( it.current()->isSelected() )
1437 oldSelected = it.current();
1441 TQListViewItem *i = itemAt( contentsToViewport(e->pos()) );
1444 autoopen_timer.start( autoopenTime );
1449 e->accept( acceptDrag(e) );
1453 void KMFolderTree::contentsDragMoveEvent( TQDragMoveEvent *e )
1455 TQPoint vp = contentsToViewport(e->pos());
1456 TQListViewItem *i = itemAt( vp );
1458 bool dragAccepted = acceptDrag( e );
1459 if ( dragAccepted ) {
1460 setCurrentItem( i );
1463 if ( i != dropItem ) {
1464 autoopen_timer.stop();
1466 autoopen_timer.start( autoopenTime );
1469 if ( dragAccepted ) {
1470 e->accept( itemRect(i) );
1472 switch ( e->action() ) {
1473 case TQDropEvent::Copy:
1475 case TQDropEvent::Move:
1478 case TQDropEvent::Link:
1489 autoopen_timer.stop();
1495 void KMFolderTree::contentsDragLeaveEvent( TQDragLeaveEvent * )
1497 if (!oldCurrent)
return;
1499 autoopen_timer.stop();
1502 setCurrentItem( oldCurrent );
1504 setSelected( oldSelected,
true );
1508 void KMFolderTree::contentsDropEvent( TQDropEvent *e )
1510 autoopen_timer.stop();
1512 TQListViewItem *item = itemAt( contentsToViewport(e->pos()) );
1513 KMFolderTreeItem *fti =
static_cast<KMFolderTreeItem*
>(item);
1515 for ( TQValueList<TQGuardedPtr<KMFolder> >::ConstIterator it = mCopySourceFolders.constBegin();
1516 it != mCopySourceFolders.constEnd(); ++it ) {
1522 if (fti && mCopySourceFolders.count() == 1)
1524 KMFolder *source = mCopySourceFolders.first();
1526 if (source == fti->folder() || source->parent()->owner() == fti->folder()) fti = 0;
1528 if (fti && acceptDrag(e) && ( fti != oldSelected || e->source() != mMainWidget->headers()->viewport() ) )
1530 if ( e->provides(
"application/x-qlistviewitem") ) {
1531 int action = dndMode(
true );
1532 if ( (action == DRAG_COPY || action == DRAG_MOVE) && !mCopySourceFolders.isEmpty() ) {
1533 for ( TQValueList<TQGuardedPtr<KMFolder> >::ConstIterator it = mCopySourceFolders.constBegin();
1534 it != mCopySourceFolders.constEnd(); ++it ) {
1535 if ( ! (*it)->isMoveable() )
1538 moveOrCopyFolder( mCopySourceFolders, fti->folder(), (action == DRAG_MOVE) );
1541 if ( e->source() == mMainWidget->headers()->viewport() ) {
1543 if ( mMainWidget->headers()->folder() && mMainWidget->headers()->folder()->isReadOnly() )
1548 if ( action == DRAG_MOVE && fti->folder() )
1549 emit folderDrop( fti->folder() );
1550 else if ( action == DRAG_COPY && fti->folder() )
1551 emit folderDropCopy( fti->folder() );
1553 handleMailListDrop( e, fti->folder() );
1562 setCurrentItem( oldCurrent );
1563 if ( oldCurrent) mLastItem =
static_cast<KMFolderTreeItem*
>(oldCurrent);
1567 setSelected( oldSelected,
true );
1570 mCopySourceFolders.clear();
1574 void KMFolderTree::slotFolderExpanded( TQListViewItem * item )
1576 KMFolderTreeItem *fti =
static_cast<KMFolderTreeItem*
>(item);
1577 if ( !fti || !fti->folder() || !fti->folder()->storage() )
return;
1579 fti->setFolderSize( fti->folder()->storage()->folderSize() );
1581 if( fti->folder()->folderType() == KMFolderTypeImap )
1583 KMFolderImap *folder =
static_cast<KMFolderImap*
>( fti->folder()->storage() );
1585 if ( !folder->account() || ( !folder->account()->listOnlyOpenFolders() &&
1588 if ( folder->getSubfolderState() == KMFolderImap::imapNoInformation )
1591 TQListViewItem *parent = item->parent();
1594 if ( !parent->isOpen() )
1596 parent = parent->parent();
1599 bool success = folder->listDirectory();
1600 if (!success) fti->setOpen(
false );
1601 if ( fti->childCount() == 0 && fti->parent() )
1602 fti->setExpandable(
false );
1609 void KMFolderTree::slotFolderCollapsed( TQListViewItem * item )
1611 slotResetFolderList( item,
false );
1612 KMFolderTreeItem *fti =
static_cast<KMFolderTreeItem*
>(item);
1613 if ( !fti || !fti->folder() || !fti->folder()->storage() )
return;
1615 fti->setFolderSize( fti->folder()->storage()->folderSize() );
1619 void KMFolderTree::slotRenameFolder(TQListViewItem *item,
int col,
1620 const TQString &text)
1623 KMFolderTreeItem *fti =
static_cast<KMFolderTreeItem*
>(item);
1625 if ((!fti) || (fti && fti->folder() && col != 0 && !currentFolder()->child()))
1628 TQString fldName, oldFldName;
1630 oldFldName = fti->name(0);
1632 if (!text.isEmpty())
1635 fldName = oldFldName;
1637 fldName.replace(
"/",
"");
1638 fldName.replace(TQRegExp(
"^\\."),
"");
1640 if (fldName.isEmpty())
1641 fldName = i18n(
"unnamed");
1643 fti->setText(0, fldName);
1644 fti->folder()->rename(fldName, &(kmkernel->folderMgr()->dir()));
1648 void KMFolderTree::slotUpdateCountsDelayed(
KMFolder * folder)
1651 if ( !mFolderToUpdateCount.contains( folder->
idString() ) )
1654 mFolderToUpdateCount.insert( folder->
idString(),folder );
1656 if ( !mUpdateCountTimer->isActive() )
1657 mUpdateCountTimer->start( 500 );
1661 void KMFolderTree::slotUpdateCountTimeout()
1665 TQMap<TQString,KMFolder*>::iterator it;
1666 for ( it= mFolderToUpdateCount.begin();
1667 it!=mFolderToUpdateCount.end();
1670 slotUpdateCounts( it.data() );
1672 mFolderToUpdateCount.clear();
1673 mUpdateCountTimer->stop();
1677 void KMFolderTree::updatePopup()
const
1679 mPopup->setItemChecked( mUnreadPop, isUnreadActive() );
1680 mPopup->setItemChecked( mTotalPop, isTotalActive() );
1681 mPopup->setItemChecked( mSizePop, isSizeActive() );
1685 void KMFolderTree::toggleColumn(
int column,
bool openFolders)
1687 if (column == unread)
1690 if ( isUnreadActive() )
1692 removeUnreadColumn();
1695 addUnreadColumn( i18n(
"Unread"), 70 );
1699 mPopup->setItemChecked( mUnreadPop, isUnreadActive() );
1701 }
else if (column == total) {
1703 if ( isTotalActive() )
1705 removeTotalColumn();
1708 addTotalColumn( i18n(
"Total"), 70 );
1709 reload(openFolders);
1711 mPopup->setItemChecked( mTotalPop, isTotalActive() );
1712 }
else if (column == foldersize) {
1714 if ( isSizeActive() )
1719 addSizeColumn( i18n(
"Size"), 70 );
1720 reload( openFolders );
1723 mPopup->setItemChecked( mSizePop, isSizeActive() );
1725 }
else kdDebug(5006) <<
"unknown column:" << column << endl;
1728 emit columnsChanged();
1732 void KMFolderTree::slotToggleUnreadColumn()
1734 toggleColumn(unread);
1738 void KMFolderTree::slotToggleTotalColumn()
1741 toggleColumn(total,
true);
1745 void KMFolderTree::slotToggleSizeColumn()
1748 toggleColumn(foldersize,
true);
1753 bool KMFolderTree::eventFilter( TQObject *o, TQEvent *e )
1755 if ( e->type() == TQEvent::MouseButtonPress &&
1756 static_cast<TQMouseEvent*
>(e)->button() == TQt::RightButton &&
1757 o->isA(
"TQHeader") )
1759 mPopup->popup(
static_cast<TQMouseEvent*
>(e)->globalPos() );
1762 return KFolderTree::eventFilter(o, e);
1766 void KMFolderTree::slotCheckMail()
1770 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>(currentItem());
1772 if (folder && folder->storage() ) {
1773 if ( KMAccount* acct = folder->storage()->account() ) {
1774 kmkernel->acctMgr()->singleCheckMail(acct,
true);
1780 void KMFolderTree::slotNewMessageToMailingList()
1782 KMFolderTreeItem* fti =
dynamic_cast<KMFolderTreeItem*
>( currentItem() );
1783 if ( !fti || !fti->folder() )
1785 KMCommand *command =
new KMMailingListPostCommand(
this, fti->folder() );
1790 void KMFolderTree::createFolderList( TQStringList *str,
1791 TQValueList<TQGuardedPtr<KMFolder> > *folders,
1796 bool includeNoContent,
1797 bool includeNoChildren )
1799 for ( TQListViewItemIterator it(
this ) ; it.current() ; ++it )
1801 KMFolderTreeItem * fti =
static_cast<KMFolderTreeItem*
>(it.current());
1802 if (!fti || !fti->folder())
continue;
1805 if (!imapFolders && folder->
folderType() == KMFolderTypeImap)
continue;
1806 if (!dimapFolders && folder->
folderType() == KMFolderTypeCachedImap)
continue;
1807 if (!localFolders && (folder->
folderType() == KMFolderTypeMbox ||
1808 folder->
folderType() == KMFolderTypeMaildir))
continue;
1809 if (!searchFolders && folder->
folderType() == KMFolderTypeSearch)
continue;
1810 if (!includeNoContent && folder->
noContent())
continue;
1811 if (!includeNoChildren && folder->
noChildren())
continue;
1813 prefix.fill(
' ', 2 * fti->depth() );
1814 str->append(prefix + fti->text(0));
1815 folders->append(fti->folder());
1820 void KMFolderTree::slotResetFolderList( TQListViewItem* item,
bool startList )
1823 item = currentItem();
1825 KMFolderTreeItem* fti =
dynamic_cast<KMFolderTreeItem*
>( item );
1826 if ( fti && fti->folder() &&
1827 fti->folder()->folderType() == KMFolderTypeImap )
1829 KMFolderImap *folder =
static_cast<KMFolderImap*
>( fti->folder()->storage() );
1830 folder->setSubfolderState( KMFolderImap::imapNoInformation );
1832 folder->listDirectory();
1837 void KMFolderTree::showFolder(
KMFolder* folder )
1839 if ( !folder )
return;
1840 TQListViewItem* item = indexOfFolder( folder );
1843 doFolderSelected( item );
1844 ensureItemVisible( item );
1849 void KMFolderTree::folderToPopupMenu( MenuAction action, TQObject *receiver,
1850 KMMenuToFolder *aMenuToFolder, TQPopupMenu *menu, TQListViewItem *item )
1852 while ( menu->count() )
1854 TQPopupMenu *popup = menu->findItem( menu->idAt( 0 ) )->popup();
1858 menu->removeItemAt( 0 );
1861 if ( action == MoveMessage || action == MoveFolder )
1863 disconnect( menu, TQ_SIGNAL(activated(
int)), receiver,
1864 TQ_SLOT(moveSelectedToFolder(
int)) );
1865 connect( menu, TQ_SIGNAL(activated(
int)), receiver,
1866 TQ_SLOT(moveSelectedToFolder(
int)) );
1868 disconnect( menu, TQ_SIGNAL(activated(
int)), receiver,
1869 TQ_SLOT(copySelectedToFolder(
int)) );
1870 connect( menu, TQ_SIGNAL(activated(
int)), receiver,
1871 TQ_SLOT(copySelectedToFolder(
int)) );
1874 item = firstChild();
1878 if ( childCount() == 2 && action != MoveFolder ) {
1879 KMFolderTreeItem *fti =
static_cast<KMFolderTreeItem*
>( item );
1880 if ( fti->protocol() == KFolderTreeItem::Search ) {
1882 item = item->nextSibling();
1883 fti =
static_cast<KMFolderTreeItem*
>( item );
1885 folderToPopupMenu( action, receiver, aMenuToFolder, menu, fti->firstChild() );
1892 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>( item );
1893 if ( fti->protocol() == KFolderTreeItem::Search )
1896 item = item->nextSibling();
1899 TQString label = fti->text( 0 );
1900 label.replace(
"&",
"&&" );
1901 if ( fti->firstChild() )
1904 TQPopupMenu* popup =
new TQPopupMenu( menu,
"subMenu" );
1905 folderToPopupMenu( action, receiver, aMenuToFolder, popup, fti->firstChild() );
1906 bool subMenu =
false;
1907 if ( ( action == MoveMessage || action == CopyMessage ) &&
1908 fti->folder() && !fti->folder()->noContent() )
1910 if ( ( action == MoveFolder || action == CopyFolder )
1911 && ( !fti->folder() || ( fti->folder() && !fti->folder()->noChildren() ) ) )
1914 TQString sourceFolderName;
1915 KMFolderTreeItem* srcItem =
dynamic_cast<KMFolderTreeItem*
>( currentItem() );
1917 sourceFolderName = srcItem->text( 0 );
1919 if ( (action == MoveFolder || action == CopyFolder)
1920 && fti->folder() && fti->folder()->child()
1921 && fti->folder()->child()->hasNamedFolder( sourceFolderName ) ) {
1928 if ( action == MoveMessage || action == MoveFolder )
1929 menuId = popup->insertItem( i18n(
"Move to This Folder"), -1, 0 );
1931 menuId = popup->insertItem( i18n(
"Copy to This Folder"), -1, 0 );
1932 popup->insertSeparator( 1 );
1933 aMenuToFolder->insert( menuId, fti->folder() );
1935 menu->insertItem( label, popup );
1939 int menuId = menu->insertItem( label );
1940 if ( fti->folder() )
1941 aMenuToFolder->insert( menuId, fti->folder() );
1942 bool enabled = (fti->folder() ? true :
false);
1943 if ( fti->folder() &&
1944 ( fti->folder()->isReadOnly() || fti->folder()->noContent() ) )
1946 menu->setItemEnabled( menuId, enabled );
1949 item = item->nextSibling();
1954 void KMFolderTree::moveSelectedToFolder(
int menuId )
1956 moveOrCopyFolder( selectedFolders(), mMenuToFolder[ menuId ],
true );
1960 void KMFolderTree::copySelectedToFolder(
int menuId )
1962 moveOrCopyFolder( selectedFolders(), mMenuToFolder[ menuId ],
false );
1966 void KMFolderTree::moveOrCopyFolder( TQValueList<TQGuardedPtr<KMFolder> > sources,
KMFolder* destination,
bool move )
1968 kdDebug(5006) << k_funcinfo <<
"source: " << sources <<
" destination: " << destination <<
" move: " << move << endl;
1971 setDragEnabled(
false );
1973 KMFolderDir* parent = &(kmkernel->folderMgr()->dir());
1977 TQStringList sourceFolderNames;
1980 for ( TQValueList<TQGuardedPtr<KMFolder> >::ConstIterator it = sources.constBegin(); it != sources.constEnd(); ++it ) {
1984 TQString sourceFolderName;
1986 sourceFolderName = source->
label();
1988 if ( parent->
hasNamedFolder( sourceFolderName ) || sourceFolderNames.contains( sourceFolderName ) ) {
1989 KMessageBox::error(
this, i18n(
"<qt>Cannot move or copy folder <b>%1</b> here because a folder with the same name already exists.</qt>")
1990 .arg( sourceFolderName ) );
1991 setDragEnabled(
true );
1994 sourceFolderNames.append( sourceFolderName );
2000 KMessageBox::error(
this, i18n(
"<qt>Cannot move or copy folder <b>%1</b> because it is not completely copied itself.</qt>")
2001 .arg( sourceFolderName ) );
2002 setDragEnabled(
true );
2006 f = f->parent()->owner();
2010 i18n(
"<qt>Cannot move or copy folder <b>%1</b> into a subfolder below itself.</qt>" ).
2011 arg( sourceFolderName );
2014 if ( source && source->
child() )
2016 while ( folderDir && ( folderDir != &kmkernel->folderMgr()->dir() ) &&
2017 ( folderDir != source->parent() ) )
2019 if ( folderDir->findRef( source ) != -1 )
2021 KMessageBox::error(
this, message );
2022 setDragEnabled(
true );
2025 folderDir = folderDir->parent();
2029 if( source && source->
child() && parent &&
2030 ( parent->
path().find( source->
child()->
path() +
"/" ) == 0 ) ) {
2031 KMessageBox::error(
this, message );
2032 setDragEnabled(
true );
2036 if( source && source->
child()
2037 && ( parent == source->
child() ) ) {
2038 KMessageBox::error(
this, message );
2039 setDragEnabled(
true );
2045 for ( TQValueList<TQGuardedPtr<KMFolder> >::ConstIterator it = sources.constBegin(); move && it != sources.constEnd(); ++it ) {
2049 for ( TQValueList<TQGuardedPtr<KMFolder> >::ConstIterator it2 = sources.constBegin(); it2 != sources.constEnd(); ++it2 ) {
2054 if ( parentDir == childDir || parentDir->findRef( childDir->
owner() ) != -1 ) {
2055 KMessageBox::error(
this, i18n(
"Moving the selected folders is not possible") );
2056 setDragEnabled(
true );
2059 childDir = childDir->parent();
2061 while ( childDir && childDir != &kmkernel->folderMgr()->dir() );
2067 doFolderSelected( indexOfFolder( destination ),
false );
2068 oldCurrent = currentItem();
2072 for ( TQValueList<TQGuardedPtr<KMFolder> >::ConstIterator it = sources.constBegin(); it != sources.constEnd(); ++it ) {
2075 kdDebug(5006) <<
"move folder " << (source ? source->
label():
"Unknown") <<
" to "
2076 << ( destination ? destination->
label() :
"Local Folders" ) << endl;
2077 kmkernel->folderMgr()->moveFolder( source, parent );
2079 kmkernel->folderMgr()->copyFolder( source, parent );
2084 TQDragObject * KMFolderTree::dragObject()
2086 KMFolderTreeItem *item =
static_cast<KMFolderTreeItem*
>
2087 (itemAt(viewport()->mapFromGlobal(TQCursor::pos())));
2088 if ( !item || !item->parent() || !item->folder() )
2090 mCopySourceFolders = selectedFolders();
2092 TQDragObject *drag = KFolderTree::dragObject();
2094 drag->setPixmap( SmallIcon(
"folder") );
2098 void KMFolderTree::copyFolder()
2100 KMFolderTreeItem *item =
static_cast<KMFolderTreeItem*
>( currentItem() );
2102 mCopySourceFolders = selectedFolders();
2105 updateCopyActions();
2108 void KMFolderTree::cutFolder()
2110 KMFolderTreeItem *item =
static_cast<KMFolderTreeItem*
>( currentItem() );
2112 mCopySourceFolders = selectedFolders();
2115 updateCopyActions();
2118 void KMFolderTree::pasteFolder()
2120 KMFolderTreeItem *item =
static_cast<KMFolderTreeItem*
>( currentItem() );
2121 if ( !mCopySourceFolders.isEmpty() && item && !mCopySourceFolders.contains( item->folder() ) ) {
2122 moveOrCopyFolder( mCopySourceFolders, item->folder(), mCutFolder );
2124 mCopySourceFolders.clear();
2126 updateCopyActions();
2129 void KMFolderTree::updateCopyActions()
2131 TDEAction *copy = mMainWidget->action(
"copy_folder");
2132 TDEAction *cut = mMainWidget->action(
"cut_folder");
2133 TDEAction *paste = mMainWidget->action(
"paste_folder");
2134 KMFolderTreeItem *item =
static_cast<KMFolderTreeItem*
>( currentItem() );
2136 if ( !item || !item->folder() ) {
2137 copy->setEnabled(
false );
2138 cut->setEnabled(
false );
2140 copy->setEnabled(
true );
2141 cut->setEnabled( item->folder()->isMoveable() );
2144 if ( mCopySourceFolders.isEmpty() )
2145 paste->setEnabled(
false );
2147 paste->setEnabled(
true );
2150 void KMFolderTree::slotSyncStateChanged()
2154 TQValueList< TQGuardedPtr<KMFolder> > folders = selectedFolders();
2155 TQValueList< TQGuardedPtr<KMFolder> >::const_iterator it = folders.constBegin();
2156 TQValueList< TQGuardedPtr<KMFolder> >::const_iterator end = folders.constEnd();
2157 while ( it != end ) {
2158 TQGuardedPtr<KMFolder> folder = *it;
2159 if ( folder == sender() ) {
2160 emit syncStateChanged();
2167 void KMFolderTree::slotAddToFavorites()
2169 KMail::FavoriteFolderView *favView = mMainWidget->favoriteFolderView();
2171 for ( TQListViewItemIterator it(
this ); it.current(); ++it ) {
2172 if ( it.current()->isSelected() )
2173 favView->addFolder(
static_cast<KMFolderTreeItem*
>( it.current() ) );
2177 void KMFolderTree::slotUnhideLocalInbox()
2179 disconnect( kmkernel->inboxFolder(), TQ_SIGNAL(msgAdded(
KMFolder*,TQ_UINT32)),
2180 this, TQ_SLOT(slotUnhideLocalInbox()) );
2184 void KMFolderTree::delayedReload()
2186 TQTimer::singleShot( 0,
this, TQ_SLOT(reload()) );
2189 #include "kmfoldertree.moc"
virtual ChildrenState hasChildren() const
Returns if the folder has children, has no children or we don't know.
KMail list that manages the contents of one directory that may contain folders and/or other directori...
virtual TQString path() const
Return full pathname of this directory.
virtual KMFolderNode * hasNamedFolder(const TQString &name)
Returns folder with given name or zero if it does not exist.
KMFolder * owner() const
Returns the folder whose children we are holding.
int countUnread()
Number of new or unread messages in this folder.
TQString idString() const
Returns a string that can be used to identify this folder.
bool moveInProgress() const
Returns true if there is currently a move or copy operation going on with this folder as target.
virtual TQString label() const
Returns the label of the folder for visualization.
KMFolderDir * child() const
Returns the folder directory associated with this node or 0 if no such directory exists.
bool noChildren() const
Returns, if the folder can't have children.
void close(const char *owner, bool force=false)
Close folder.
KMFolderDir * createChildFolder()
Create a child folder directory and associates it with this folder.
KMFolderType folderType() const
Returns the type of this folder.
int open(const char *owner)
Open folder for access.
bool noContent() const
Returns, if the folder can't contain mails, but only subfolder.
The account manager is responsible for creating accounts of various types via the factory method crea...
Helper class to copy/move a set of messages defined by their serial numbers from arbitrary folders in...
@ Ok
The user rights/ACL have been fetched from the server sucessfully.