19 #include "foldertreebase.h"
21 #include "globalsettings.h"
23 #include "kmfolderdir.h"
24 #include "kmfoldertree.h"
25 #include "kmheaders.h"
26 #include "kmmainwidget.h"
27 #include "messagecopyhelper.h"
28 #include "folderstorage.h"
30 #include <libtdepim/maillistdrag.h>
32 using KPIM::MailListDrag;
34 #include <tdeconfig.h>
35 #include <kiconloader.h>
36 #include <tdepopupmenu.h>
40 using namespace KMail;
42 FolderTreeBase::FolderTreeBase(KMMainWidget *mainWidget, TQWidget * parent,
const char * name) :
43 KFolderTree( parent, name ),
44 mMainWidget( mainWidget )
46 addAcceptableDropMimetype(MailListDrag::format(),
false);
49 void FolderTreeBase::contentsDropEvent(TQDropEvent * e)
51 TQListViewItem *item = itemAt( contentsToViewport(e->pos()) );
52 KMFolderTreeItem *fti =
static_cast<KMFolderTreeItem*
>(item);
53 if ( fti && fti->folder() && e->provides( MailListDrag::format() ) ) {
54 if ( e->source() == mMainWidget->headers()->viewport() ) {
56 if ( mMainWidget->headers()->folder() && mMainWidget->headers()->folder()->isReadOnly() )
61 if ( action == DRAG_MOVE && fti->folder() )
62 emit folderDrop( fti->folder() );
63 else if ( action == DRAG_COPY && fti->folder() )
64 emit folderDropCopy( fti->folder() );
66 handleMailListDrop( e, fti->folder() );
70 KFolderTree::contentsDropEvent( e );
74 int FolderTreeBase::dndMode(
bool alwaysAsk)
77 int keybstate = kapp->keyboardModifiers();
78 if ( keybstate & TDEApplication::ControlModifier ) {
80 }
else if ( keybstate & TDEApplication::ShiftModifier ) {
83 if ( GlobalSettings::self()->showPopupAfterDnD() || alwaysAsk ) {
85 menu.insertItem( i18n(
"&Move Here"), DRAG_MOVE, 0 );
86 menu.insertItem( SmallIcon(
"edit-copy"), i18n(
"&Copy Here"), DRAG_COPY, 1 );
87 menu.insertSeparator();
88 menu.insertItem( SmallIcon(
"cancel"), i18n(
"C&ancel"), DRAG_CANCEL, 3 );
89 action = menu.exec( TQCursor::pos(), 0 );
97 bool FolderTreeBase::event(TQEvent * e)
99 if (e->type() == TQEvent::ApplicationPaletteChange) {
103 return KFolderTree::event(e);
106 void FolderTreeBase::readColorConfig()
108 TDEConfig* conf = KMKernel::config();
110 TDEConfigGroupSaver saver(conf,
"Reader");
111 TQColor c1=TQColor(kapp->palette().active().text());
112 TQColor c2=TQColor(
"blue");
113 TQColor c4=TQColor(kapp->palette().active().base());
114 TQColor c5=TQColor(
"red");
116 if (!conf->readBoolEntry(
"defaultColors",
true)) {
117 mPaintInfo.colFore = conf->readColorEntry(
"ForegroundColor",&c1);
118 mPaintInfo.colUnread = conf->readColorEntry(
"UnreadMessage",&c2);
119 mPaintInfo.colBack = conf->readColorEntry(
"BackgroundColor",&c4);
120 mPaintInfo.colCloseToQuota = conf->readColorEntry(
"CloseToQuotaColor",&c5);
123 mPaintInfo.colFore = c1;
124 mPaintInfo.colUnread = c2;
125 mPaintInfo.colBack = c4;
126 mPaintInfo.colCloseToQuota = c5;
128 TQPalette newPal = kapp->palette();
129 newPal.setColor( TQColorGroup::Base, mPaintInfo.colBack );
130 newPal.setColor( TQColorGroup::Text, mPaintInfo.colFore );
131 setPalette( newPal );
134 bool FolderTreeBase::hideLocalInbox()
const
136 if ( !GlobalSettings::self()->hideLocalInbox() )
138 KMFolder *localInbox = kmkernel->inboxFolder();
139 assert( localInbox );
141 localInbox->
open(
"foldertreebase" );
142 if ( localInbox->
count() > 0 ) {
143 localInbox->
close(
"foldertreebase" );
146 localInbox->
close(
"foldertreebase" );
148 if ( localInbox->
child() && !localInbox->
child()->isEmpty() )
157 void FolderTreeBase::slotUpdateCounts(
KMFolder * folder,
bool force )
160 TQListViewItem * current;
162 current = indexOfFolder(folder);
164 current = currentItem();
166 KMFolderTreeItem* fti =
static_cast<KMFolderTreeItem*
>(current);
170 if (!fti->folder()) fti->setTotalCount(-1);
178 count = fti->folder()->countUnread();
182 bool repaint =
false;
183 if (fti->unreadCount() != count) {
184 fti->adjustUnreadCount( count );
187 if (isTotalActive() || force)
190 if (fti->folder()->noContent())
194 count = fti->folder()->count( !fti->folder()->isOpened() );
197 if ( count != fti->totalCount() ) {
198 fti->setTotalCount(count);
202 if ( isSizeActive() || force ) {
203 if ( !fti->folder()->noContent()) {
204 TQ_INT64 size = folder->storage()->
folderSize();
205 if ( size != fti->folderSize() ) {
206 fti->setFolderSize( size );
211 if ( fti->folderIsCloseToQuota() != folder->storage()->
isCloseToQuota() ) {
212 fti->setFolderIsCloseToQuota( folder->storage()->
isCloseToQuota() );
215 if (fti->parent() && !fti->parent()->isOpen())
218 fti->setNeedsRepaint(
true );
219 emit triggerRefresh();
222 kmkernel->messageCountChanged();
225 void FolderTreeBase::handleMailListDrop(TQDropEvent * event,
KMFolder *destination )
228 if ( !MailListDrag::decode( event, list ) ) {
229 kdWarning() << k_funcinfo <<
"Could not decode drag data!" << endl;
231 TQValueList<TQ_UINT32> serNums = MessageCopyHelper::serNumListFromMailList( list );
233 if ( MessageCopyHelper::inReadOnlyFolder( serNums ) )
237 if ( action == DRAG_COPY || action == DRAG_MOVE ) {
243 #include "foldertreebase.moc"
virtual bool isCloseToQuota() const
Return whether the folder is close to its quota limit, which can be reflected in the UI.
TQ_INT64 folderSize() const
Total size of the contents of this folder.
KMFolderDir * child() const
Returns the folder directory associated with this node or 0 if no such directory exists.
void close(const char *owner, bool force=false)
Close folder.
int count(bool cache=false) const
Number of messages in 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.
bool hasAccounts() const
Returns TRUE if accounts are associated with this folder.
Helper class to copy/move a set of messages defined by their serial numbers from arbitrary folders in...