29 #include <tdeapplication.h>
30 #include <tdeconfig.h>
33 #include <tdeglobal.h>
34 #include <kiconloader.h>
35 #include <tdelocale.h>
36 #include <tdeparts/part.h>
40 #include "summarywidget.h"
44 SummaryWidget::SummaryWidget(
Kontact::Plugin *plugin, TQWidget *parent,
const char *name )
45 : Kontact::Summary( parent, name ),
46 DCOPObject( TQCString(
"MailSummary") ),
49 TQVBoxLayout *mainLayout =
new TQVBoxLayout(
this, 3, 3 );
51 TQPixmap icon = TDEGlobal::iconLoader()->loadIcon(
"kontact_mail", TDEIcon::Desktop,
52 TDEIcon::SizeMedium );
53 TQWidget *header =
createHeader(
this, icon, i18n(
"E-Mail"));
54 mLayout =
new TQGridLayout( 1, 3, 3 );
56 mainLayout->addWidget(header);
57 mainLayout->addLayout(mLayout);
59 slotUnreadCountChanged();
60 connectDCOPSignal( 0, 0,
"unreadCountChanged()",
"slotUnreadCountChanged()",
64 void SummaryWidget::selectFolder(
const TQString& folder )
66 if ( mPlugin->isRunningStandalone() )
67 mPlugin->bringToForeground();
69 mPlugin->core()->selectPlugin( mPlugin );
71 TQDataStream arg( data, IO_WriteOnly );
73 emitDCOPSignal(
"kmailSelectFolder(TQString)", data );
76 void SummaryWidget::updateSummary(
bool )
79 DCOPRef kmail(
"kmail",
"KMailIface" );
80 const int timeOfLastMessageCountChange =
81 kmail.call(
"timeOfLastMessageCountChange()" );
82 if ( timeOfLastMessageCountChange > mTimeOfLastMessageCountUpdate )
83 slotUnreadCountChanged();
86 void SummaryWidget::slotUnreadCountChanged()
88 DCOPRef kmail(
"kmail",
"KMailIface" );
89 DCOPReply reply = kmail.call(
"folderList" );
90 if ( reply.isValid() ) {
91 TQStringList folderList = reply;
92 updateFolderList( folderList );
95 kdDebug(5602) <<
"Calling kmail->KMailIface->folderList() via DCOP failed."
98 mTimeOfLastMessageCountUpdate = ::time( 0 );
101 void SummaryWidget::updateFolderList(
const TQStringList& folders )
103 mLabels.setAutoDelete(
true );
105 mLabels.setAutoDelete(
false );
107 TDEConfig config(
"kcmkmailsummaryrc" );
108 config.setGroup(
"General" );
110 TQStringList activeFolders;
111 if ( !config.hasKey(
"ActiveFolders" ) )
112 activeFolders <<
"/Local/inbox";
114 activeFolders = config.readListEntry(
"ActiveFolders" );
117 TQStringList::ConstIterator it;
118 DCOPRef kmail(
"kmail",
"KMailIface" );
119 for ( it = folders.begin(); it != folders.end(); ++it ) {
120 if ( activeFolders.contains( *it ) ) {
121 DCOPRef folderRef = kmail.call(
"getFolder(TQString)", *it );
122 const int numMsg = folderRef.call(
"messages()" );
123 const int numUnreadMsg = folderRef.call(
"unreadMessages()" );
125 if ( numUnreadMsg == 0 )
continue;
128 if ( config.readBoolEntry(
"ShowFullPath",
true ) )
129 folderRef.call(
"displayPath()" ).get( folderPath );
131 folderRef.call(
"displayName()" ).get( folderPath );
133 KURLLabel *urlLabel =
new KURLLabel( *it, folderPath,
this );
134 urlLabel->installEventFilter(
this );
135 urlLabel->setAlignment( AlignLeft );
137 connect( urlLabel, TQT_SIGNAL( leftClickedURL(
const TQString& ) ),
138 TQT_SLOT( selectFolder(
const TQString& ) ) );
139 mLayout->addWidget( urlLabel, counter, 0 );
140 mLabels.append( urlLabel );
143 new TQLabel( TQString( i18n(
"%1: number of unread messages "
144 "%2: total number of messages",
"%1 / %2") )
145 .arg( numUnreadMsg ).arg( numMsg ),
this );
146 label->setAlignment( AlignLeft );
148 mLayout->addWidget( label, counter, 2 );
149 mLabels.append( label );
155 if ( counter == 0 ) {
156 TQLabel *label =
new TQLabel( i18n(
"No unread messages in your monitored folders" ),
this );
157 label->setAlignment( AlignHCenter | AlignVCenter );
158 mLayout->addMultiCellWidget( label, 0, 0, 0, 2 );
160 mLabels.append( label );
164 bool SummaryWidget::eventFilter( TQObject *obj, TQEvent* e )
166 if ( obj->inherits(
"KURLLabel" ) ) {
167 KURLLabel* label =
static_cast<KURLLabel*
>( TQT_TQWIDGET(obj) );
168 if ( e->type() == TQEvent::Enter )
169 emit message( i18n(
"Open Folder: \"%1\"" ).arg( label->text() ) );
170 if ( e->type() == TQEvent::Leave )
171 emit message( TQString() );
174 return Kontact::Summary::eventFilter( obj, e );
177 TQStringList SummaryWidget::configModules()
const
179 return TQStringList(
"kcmkmailsummary.desktop" );
182 #include "summarywidget.moc"