kmail
foldertreebase.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "foldertreebase.h"
00020
00021 #include "globalsettings.h"
00022 #include "kmfolder.h"
00023 #include "kmfolderdir.h"
00024 #include "kmfoldertree.h"
00025 #include "kmheaders.h"
00026 #include "kmmainwidget.h"
00027 #include "messagecopyhelper.h"
00028
00029 #include <libkdepim/maillistdrag.h>
00030 using KPIM::MailList;
00031 using KPIM::MailListDrag;
00032
00033 #include <kconfig.h>
00034 #include <kiconloader.h>
00035 #include <kpopupmenu.h>
00036
00037 #include <qcursor.h>
00038
00039 using namespace KMail;
00040
00041 FolderTreeBase::FolderTreeBase(KMMainWidget *mainWidget, QWidget * parent, const char * name) :
00042 KFolderTree( parent, name ),
00043 mMainWidget( mainWidget )
00044 {
00045 addAcceptableDropMimetype(MailListDrag::format(), false);
00046 }
00047
00048 void FolderTreeBase::contentsDropEvent(QDropEvent * e)
00049 {
00050 QListViewItem *item = itemAt( contentsToViewport(e->pos()) );
00051 KMFolderTreeItem *fti = static_cast<KMFolderTreeItem*>(item);
00052 if ( fti && fti->folder() && e->provides( MailListDrag::format() ) ) {
00053 int action = dndMode();
00054 if ( e->source() == mMainWidget->headers()->viewport() ) {
00055
00056 if ( action == DRAG_MOVE && fti->folder() )
00057 emit folderDrop( fti->folder() );
00058 else if ( action == DRAG_COPY && fti->folder() )
00059 emit folderDropCopy( fti->folder() );
00060 } else if ( action == DRAG_COPY || action == DRAG_MOVE ) {
00061 MailList list;
00062 if ( !MailListDrag::decode( e, list ) ) {
00063 kdWarning() << k_funcinfo << "Could not decode drag data!" << endl;
00064 } else {
00065 QValueList<Q_UINT32> serNums = MessageCopyHelper::serNumListFromMailList( list );
00066 new MessageCopyHelper( serNums, fti->folder(), action == DRAG_MOVE, this );
00067 }
00068 }
00069 e->accept( true );
00070 } else {
00071 KFolderTree::contentsDropEvent( e );
00072 }
00073 }
00074
00075 int FolderTreeBase::dndMode(bool alwaysAsk)
00076 {
00077 int action = -1;
00078 int keybstate = kapp->keyboardModifiers();
00079 if ( keybstate & KApplication::ControlModifier ) {
00080 action = DRAG_COPY;
00081 } else if ( keybstate & KApplication::ShiftModifier ) {
00082 action = DRAG_MOVE;
00083 } else {
00084 if ( GlobalSettings::self()->showPopupAfterDnD() || alwaysAsk ) {
00085 KPopupMenu *menu = new KPopupMenu( this );
00086 menu->insertItem( i18n("&Move Here"), DRAG_MOVE, 0 );
00087 menu->insertItem( SmallIcon("editcopy"), i18n("&Copy Here"), DRAG_COPY, 1 );
00088 menu->insertSeparator();
00089 menu->insertItem( SmallIcon("cancel"), i18n("C&ancel"), DRAG_CANCEL, 3 );
00090 action = menu->exec( QCursor::pos(), 0 );
00091 }
00092 else
00093 action = DRAG_MOVE;
00094 }
00095 return action;
00096 }
00097
00098 bool FolderTreeBase::event(QEvent * e)
00099 {
00100 if (e->type() == QEvent::ApplicationPaletteChange) {
00101 readColorConfig();
00102 return true;
00103 }
00104 return KFolderTree::event(e);
00105 }
00106
00107 void FolderTreeBase::readColorConfig()
00108 {
00109 KConfig* conf = KMKernel::config();
00110
00111 KConfigGroupSaver saver(conf, "Reader");
00112 QColor c1=QColor(kapp->palette().active().text());
00113 QColor c2=QColor("blue");
00114 QColor c4=QColor(kapp->palette().active().base());
00115 QColor c5=QColor("red");
00116
00117 if (!conf->readBoolEntry("defaultColors",true)) {
00118 mPaintInfo.colFore = conf->readColorEntry("ForegroundColor",&c1);
00119 mPaintInfo.colUnread = conf->readColorEntry("UnreadMessage",&c2);
00120 mPaintInfo.colBack = conf->readColorEntry("BackgroundColor",&c4);
00121 mPaintInfo.colCloseToQuota = conf->readColorEntry("CloseToQuotaColor",&c5);
00122 }
00123 else {
00124 mPaintInfo.colFore = c1;
00125 mPaintInfo.colUnread = c2;
00126 mPaintInfo.colBack = c4;
00127 mPaintInfo.colCloseToQuota = c5;
00128 }
00129 QPalette newPal = kapp->palette();
00130 newPal.setColor( QColorGroup::Base, mPaintInfo.colBack );
00131 newPal.setColor( QColorGroup::Text, mPaintInfo.colFore );
00132 setPalette( newPal );
00133 }
00134
00135 bool FolderTreeBase::hideLocalInbox() const
00136 {
00137 if ( !GlobalSettings::self()->hideLocalInbox() )
00138 return false;
00139 KMFolder *localInbox = kmkernel->inboxFolder();
00140 assert( localInbox );
00141
00142 localInbox->open( "foldertreebase" );
00143 if ( localInbox->count() > 0 ) {
00144 localInbox->close( "foldertreebase" );
00145 return false;
00146 }
00147 localInbox->close( "foldertreebase" );
00148
00149 if ( localInbox->child() && !localInbox->child()->isEmpty() )
00150 return false;
00151
00152 if ( localInbox->hasAccounts() )
00153 return false;
00154 return true;
00155 }
00156
00157 #include "foldertreebase.moc"
|