summarywidget.cpp
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 SummaryWidget::SummaryWidget( Kontact::Plugin *plugin, QWidget *parent, const char *name )
00043 : Kontact::Summary( parent, name ),
00044 DCOPObject( QCString("MailSummary") ),
00045 mPlugin( plugin )
00046 {
00047 QVBoxLayout *mainLayout = new QVBoxLayout( this, 3, 3 );
00048
00049 QPixmap icon = KGlobal::iconLoader()->loadIcon( "kmail", KIcon::Desktop, KIcon::SizeMedium);
00050 QWidget *header = createHeader(this, icon, i18n("New Messages"));
00051 mLayout = new QGridLayout( 1, 3, 3 );
00052
00053 mainLayout->addWidget(header);
00054 mainLayout->addLayout(mLayout);
00055 mainLayout->addStretch();
00056
00057 slotUnreadCountChanged();
00058 connectDCOPSignal( 0, 0, "unreadCountChanged()", "slotUnreadCountChanged()",
00059 false );
00060 }
00061
00062
00063 void SummaryWidget::raisePart()
00064 {
00065
00066
00067 if ( mPlugin->isRunningStandalone() )
00068 mPlugin->bringToForeground();
00069 else
00070 mPlugin->core()->selectPlugin( mPlugin );
00071 }
00072
00073 void SummaryWidget::slotUnreadCountChanged()
00074 {
00075 DCOPRef kmail( "kmail", "KMailIface" );
00076 DCOPReply reply = kmail.call( "folderList" );
00077 if ( reply.isValid() ) {
00078 QStringList folderList = reply;
00079 updateFolderList( folderList );
00080 }
00081 else {
00082 kdDebug(5602) << "Calling kmail->KMailIface->folderList() via DCOP failed."
00083 << endl;
00084 }
00085 }
00086
00087 void SummaryWidget::updateFolderList( const QStringList& folders )
00088 {
00089 mLabels.setAutoDelete( true );
00090 mLabels.clear();
00091 mLabels.setAutoDelete( false );
00092
00093 int counter = 0;
00094 QStringList::ConstIterator it;
00095 DCOPRef kmail( "kmail", "KMailIface" );
00096 for ( it = folders.begin(); it != folders.end() && counter < 9; ++it ) {
00097 DCOPReply reply = kmail.call( "getFolder", *it );
00098 if ( reply.isValid() ) {
00099 DCOPRef folderRef = reply;
00100 int numUnreadMsg = -1;
00101 DCOPReply dcopReply = folderRef.call( "unreadMessages" );
00102 if ( dcopReply.isValid() ) {
00103 numUnreadMsg = dcopReply;
00104 }
00105 else {
00106 kdDebug(5602) << "Calling folderRef->unreadMessages() via DCOP failed."
00107 << endl;
00108 }
00109 if ( numUnreadMsg > 0 ) {
00110 QString folderPath( *it );
00111 if ( folderPath.startsWith("/") )
00112 folderPath = folderPath.mid( 1 );
00113 KURLLabel *urlLabel = new KURLLabel( QString::null, i18n( folderPath.local8Bit() ),
00114 this );
00115 urlLabel->setAlignment( AlignLeft );
00116 urlLabel->show();
00117
00118 connect( urlLabel, SIGNAL( leftClickedURL() ), SLOT( raisePart() ) );
00119 mLayout->addWidget( urlLabel, counter, 0 );
00120 mLabels.append( urlLabel );
00121 QLabel *label = new QLabel( QString::number( numUnreadMsg ), this );
00122
00123 label->setAlignment( AlignLeft );
00124 label->show();
00125 mLayout->addWidget( label, counter, 2 );
00126 mLabels.append( label );
00127 counter++;
00128 }
00129 }
00130 else {
00131 kdDebug(5602) << "Calling kmail->KMailIface->getFolder() via DCOP "
00132 "failed." << endl;
00133 }
00134 }
00135
00136 if ( counter == 0 ) {
00137 QLabel *label = new QLabel( i18n( "No unread messages" ), this );
00138 label->show();
00139 mLayout->addMultiCellWidget( label, 1, 1, 1, 2 );
00140 mLabels.append( label );
00141 }
00142 }
00143
00144 #include "summarywidget.moc"
This file is part of the documentation for kontact Library Version 3.2.2.