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 #include <qlabel.h>
00026 #include <qlayout.h>
00027
00028 #include <dcopref.h>
00029 #include <kapplication.h>
00030 #include <kconfig.h>
00031 #include <kdebug.h>
00032 #include <kdialog.h>
00033 #include <kglobal.h>
00034 #include <kiconloader.h>
00035 #include <klocale.h>
00036 #include <kparts/part.h>
00037
00038 #include "core.h"
00039 #include "summary.h"
00040 #include "summarywidget.h"
00041
00042 #include <time.h>
00043
00044 SummaryWidget::SummaryWidget( Kontact::Plugin *plugin, QWidget *parent, const char *name )
00045 : Kontact::Summary( parent, name ),
00046 DCOPObject( QCString("MailSummary") ),
00047 mPlugin( plugin )
00048 {
00049 QVBoxLayout *mainLayout = new QVBoxLayout( this, 3, 3 );
00050
00051 QPixmap icon = KGlobal::iconLoader()->loadIcon( "kontact_mail", KIcon::Desktop,
00052 KIcon::SizeMedium );
00053 QWidget *header = createHeader(this, icon, i18n("New Messages"));
00054 mLayout = new QGridLayout( 1, 3, 3 );
00055
00056 mainLayout->addWidget(header);
00057 mainLayout->addLayout(mLayout);
00058
00059 slotUnreadCountChanged();
00060 connectDCOPSignal( 0, 0, "unreadCountChanged()", "slotUnreadCountChanged()",
00061 false );
00062 }
00063
00064 void SummaryWidget::selectFolder( const QString& folder )
00065 {
00066 if ( mPlugin->isRunningStandalone() )
00067 mPlugin->bringToForeground();
00068 else
00069 mPlugin->core()->selectPlugin( mPlugin );
00070 QByteArray data;
00071 QDataStream arg( data, IO_WriteOnly );
00072 arg << folder;
00073 emitDCOPSignal( "kmailSelectFolder(QString)", data );
00074 }
00075
00076 void SummaryWidget::updateSummary( bool )
00077 {
00078
00079 DCOPRef kmail( "kmail", "KMailIface" );
00080 const int timeOfLastMessageCountChange =
00081 kmail.call( "timeOfLastMessageCountChange()" );
00082 if ( timeOfLastMessageCountChange > mTimeOfLastMessageCountUpdate )
00083 slotUnreadCountChanged();
00084 }
00085
00086 void SummaryWidget::slotUnreadCountChanged()
00087 {
00088 DCOPRef kmail( "kmail", "KMailIface" );
00089 DCOPReply reply = kmail.call( "folderList" );
00090 if ( reply.isValid() ) {
00091 QStringList folderList = reply;
00092 updateFolderList( folderList );
00093 }
00094 else {
00095 kdDebug(5602) << "Calling kmail->KMailIface->folderList() via DCOP failed."
00096 << endl;
00097 }
00098 mTimeOfLastMessageCountUpdate = ::time( 0 );
00099 }
00100
00101 void SummaryWidget::updateFolderList( const QStringList& folders )
00102 {
00103 mLabels.setAutoDelete( true );
00104 mLabels.clear();
00105 mLabels.setAutoDelete( false );
00106
00107 KConfig config( "kcmkmailsummaryrc" );
00108 config.setGroup( "General" );
00109
00110 QStringList activeFolders;
00111 if ( !config.hasKey( "ActiveFolders" ) )
00112 activeFolders << "/Local/inbox";
00113 else
00114 activeFolders = config.readListEntry( "ActiveFolders" );
00115
00116 int counter = 0;
00117 QStringList::ConstIterator it;
00118 DCOPRef kmail( "kmail", "KMailIface" );
00119 for ( it = folders.begin(); it != folders.end(); ++it ) {
00120 if ( activeFolders.contains( *it ) ) {
00121 DCOPRef folderRef = kmail.call( "getFolder(QString)", *it );
00122 const int numMsg = folderRef.call( "messages()" );
00123 const int numUnreadMsg = folderRef.call( "unreadMessages()" );
00124
00125 if ( numUnreadMsg == 0 ) continue;
00126
00127 QString folderPath;
00128 if ( config.readBoolEntry( "ShowFullPath", true ) )
00129 folderRef.call( "displayPath()" ).get( folderPath );
00130 else
00131 folderRef.call( "displayName()" ).get( folderPath );
00132
00133 KURLLabel *urlLabel = new KURLLabel( *it, folderPath, this );
00134 urlLabel->installEventFilter( this );
00135 urlLabel->setAlignment( AlignLeft );
00136 urlLabel->show();
00137 connect( urlLabel, SIGNAL( leftClickedURL( const QString& ) ),
00138 SLOT( selectFolder( const QString& ) ) );
00139 mLayout->addWidget( urlLabel, counter, 0 );
00140 mLabels.append( urlLabel );
00141
00142 QLabel *label =
00143 new QLabel( QString( i18n("%1: number of unread messages "
00144 "%2: total number of messages", "%1 / %2") )
00145 .arg( numUnreadMsg ).arg( numMsg ), this );
00146 label->setAlignment( AlignLeft );
00147 label->show();
00148 mLayout->addWidget( label, counter, 2 );
00149 mLabels.append( label );
00150
00151 counter++;
00152 }
00153 }
00154
00155 if ( counter == 0 ) {
00156 QLabel *label = new QLabel( i18n( "No unread messages in your monitored folders" ), this );
00157 label->setAlignment( AlignHCenter | AlignVCenter );
00158 mLayout->addMultiCellWidget( label, 0, 0, 0, 2 );
00159 label->show();
00160 mLabels.append( label );
00161 }
00162 }
00163
00164 bool SummaryWidget::eventFilter( QObject *obj, QEvent* e )
00165 {
00166 if ( obj->inherits( "KURLLabel" ) ) {
00167 KURLLabel* label = static_cast<KURLLabel*>( obj );
00168 if ( e->type() == QEvent::Enter )
00169 emit message( i18n( "Open Folder: \"%1\"" ).arg( label->text() ) );
00170 if ( e->type() == QEvent::Leave )
00171 emit message( QString::null );
00172 }
00173
00174 return Kontact::Summary::eventFilter( obj, e );
00175 }
00176
00177 QStringList SummaryWidget::configModules() const
00178 {
00179 return QStringList( "kcmkmailsummary.desktop" );
00180 }
00181
00182 #include "summarywidget.moc"