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 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 // FIXME: select specific folder when 'selectFolder' dcop call is implemented 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 // ### FIXME emit dcop signal to jumo to actual folder 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"
KDE Logo
This file is part of the documentation for kontact Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:15 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003