kontact Library API Documentation

summarywidget.cpp

00001 /* -*- mode: C++; c-file-style: "gnu" -*- 00002 00003 This file is part of Kontact. 00004 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 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 mainLayout->addStretch(); 00059 00060 slotUnreadCountChanged(); 00061 connectDCOPSignal( 0, 0, "unreadCountChanged()", "slotUnreadCountChanged()", 00062 false ); 00063 } 00064 00065 void SummaryWidget::selectFolder( const QString& folder ) 00066 { 00067 if ( mPlugin->isRunningStandalone() ) 00068 mPlugin->bringToForeground(); 00069 else 00070 mPlugin->core()->selectPlugin( mPlugin ); 00071 QByteArray data; 00072 QDataStream arg( data, IO_WriteOnly ); 00073 arg << folder; 00074 emitDCOPSignal( "kmailSelectFolder(QString)", data ); 00075 } 00076 00077 void SummaryWidget::updateSummary( bool ) 00078 { 00079 // check whether we need to update the message counts 00080 DCOPRef kmail( "kmail", "KMailIface" ); 00081 const int timeOfLastMessageCountChange = 00082 kmail.call( "timeOfLastMessageCountChange()" ); 00083 if ( timeOfLastMessageCountChange > mTimeOfLastMessageCountUpdate ) 00084 slotUnreadCountChanged(); 00085 } 00086 00087 void SummaryWidget::slotUnreadCountChanged() 00088 { 00089 DCOPRef kmail( "kmail", "KMailIface" ); 00090 DCOPReply reply = kmail.call( "folderList" ); 00091 if ( reply.isValid() ) { 00092 QStringList folderList = reply; 00093 updateFolderList( folderList ); 00094 } 00095 else { 00096 kdDebug(5602) << "Calling kmail->KMailIface->folderList() via DCOP failed." 00097 << endl; 00098 } 00099 mTimeOfLastMessageCountUpdate = ::time( 0 ); 00100 } 00101 00102 void SummaryWidget::updateFolderList( const QStringList& folders ) 00103 { 00104 mLabels.setAutoDelete( true ); 00105 mLabels.clear(); 00106 mLabels.setAutoDelete( false ); 00107 00108 KConfig config( "kcmkmailsummaryrc" ); 00109 config.setGroup( "General" ); 00110 00111 QStringList activeFolders; 00112 if ( !config.hasKey( "ActiveFolders" ) ) 00113 activeFolders << "/Local/inbox"; 00114 else 00115 activeFolders = config.readListEntry( "ActiveFolders" ); 00116 00117 bool showFullPath = config.readBoolEntry( "ShowFullPath", false ); 00118 00119 int counter = 0; 00120 QStringList::ConstIterator it; 00121 DCOPRef kmail( "kmail", "KMailIface" ); 00122 for ( it = folders.begin(); it != folders.end() && counter < 9; ++it ) { 00123 if ( activeFolders.contains( *it ) ) { 00124 DCOPRef folderRef = kmail.call( "getFolder(QString)", *it ); 00125 const int numMsg = folderRef.call( "messages()" ); 00126 const int numUnreadMsg = folderRef.call( "unreadMessages()" ); 00127 00128 QString folderPath; 00129 if ( showFullPath ) 00130 folderRef.call( "displayPath()" ).get( folderPath ); 00131 else 00132 folderRef.call( "displayName()" ).get( folderPath ); 00133 00134 KURLLabel *urlLabel = new KURLLabel( *it, folderPath, 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" ), this ); 00157 label->show(); 00158 mLayout->addMultiCellWidget( label, 1, 1, 1, 2 ); 00159 mLabels.append( label ); 00160 } 00161 } 00162 00163 QStringList SummaryWidget::configModules() const 00164 { 00165 return QStringList( "kcmkmailsummary.desktop" ); 00166 } 00167 00168 #include "summarywidget.moc"
KDE Logo
This file is part of the documentation for kontact Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:36 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003