28 #include <tdeapplication.h>
29 #include <tdeconfig.h>
32 #include <tdeglobal.h>
33 #include <kiconloader.h>
34 #include <tdelocale.h>
35 #include <tdeparts/part.h>
39 #include "summarywidget.h"
43 SummaryWidget::SummaryWidget(
Kontact::Plugin *plugin, TQWidget *parent,
const char *name )
44 : Kontact::Summary( parent, name ),
45 DCOPObject( TQCString(
"MailSummary") ),
48 TQVBoxLayout *mainLayout =
new TQVBoxLayout(
this, 3, 3 );
50 TQPixmap icon = TDEGlobal::iconLoader()->loadIcon(
"kontact_mail", TDEIcon::Desktop,
51 TDEIcon::SizeMedium );
52 TQWidget *header = createHeader(
this, icon, i18n(
"E-Mail"));
53 mLayout =
new TQGridLayout( 1, 3, 3 );
55 mainLayout->addWidget(header);
56 mainLayout->addLayout(mLayout);
58 slotUnreadCountChanged();
59 connectDCOPSignal( 0, 0,
"unreadCountChanged()",
"slotUnreadCountChanged()",
63 void SummaryWidget::selectFolder(
const TQString& folder )
65 if ( mPlugin->isRunningStandalone() )
66 mPlugin->bringToForeground();
68 mPlugin->core()->selectPlugin( mPlugin );
70 TQDataStream arg( data, IO_WriteOnly );
72 emitDCOPSignal(
"kmailSelectFolder(TQString)", data );
75 void SummaryWidget::updateSummary(
bool )
78 DCOPRef kmail(
"kmail",
"KMailIface" );
79 const int timeOfLastMessageCountChange =
80 kmail.call(
"timeOfLastMessageCountChange()" );
81 if ( timeOfLastMessageCountChange > mTimeOfLastMessageCountUpdate )
82 slotUnreadCountChanged();
85 void SummaryWidget::slotUnreadCountChanged()
87 DCOPRef kmail(
"kmail",
"KMailIface" );
88 DCOPReply reply = kmail.call(
"folderList" );
89 if ( reply.isValid() ) {
90 TQStringList folderList = reply;
91 updateFolderList( folderList );
94 kdDebug(5602) <<
"Calling kmail->KMailIface->folderList() via DCOP failed."
97 mTimeOfLastMessageCountUpdate = ::time( 0 );
100 void SummaryWidget::updateFolderList(
const TQStringList& folders )
102 mLabels.setAutoDelete(
true );
104 mLabels.setAutoDelete(
false );
106 TDEConfig config(
"kcmkmailsummaryrc" );
107 config.setGroup(
"General" );
109 TQStringList activeFolders;
110 if ( !config.hasKey(
"ActiveFolders" ) )
111 activeFolders <<
"/Local/inbox";
113 activeFolders = config.readListEntry(
"ActiveFolders" );
116 TQStringList::ConstIterator it;
117 DCOPRef kmail(
"kmail",
"KMailIface" );
118 for ( it = folders.begin(); it != folders.end(); ++it ) {
119 if ( activeFolders.contains( *it ) ) {
120 DCOPRef folderRef = kmail.call(
"getFolder(TQString)", *it );
121 const int numMsg = folderRef.call(
"messages()" );
122 const int numUnreadMsg = folderRef.call(
"unreadMessages()" );
124 if ( numUnreadMsg == 0 )
continue;
127 if ( config.readBoolEntry(
"ShowFullPath",
true ) )
128 folderRef.call(
"displayPath()" ).get( folderPath );
130 folderRef.call(
"displayName()" ).get( folderPath );
132 KURLLabel *urlLabel =
new KURLLabel( *it, folderPath,
this );
133 urlLabel->installEventFilter(
this );
134 urlLabel->setAlignment( AlignLeft );
136 connect( urlLabel, TQ_SIGNAL( leftClickedURL(
const TQString& ) ),
137 TQ_SLOT( selectFolder(
const TQString& ) ) );
138 mLayout->addWidget( urlLabel, counter, 0 );
139 mLabels.append( urlLabel );
142 new TQLabel( TQString( i18n(
"%1: number of unread messages "
143 "%2: total number of messages",
"%1 / %2") )
144 .arg( numUnreadMsg ).arg( numMsg ),
this );
145 label->setAlignment( AlignLeft );
147 mLayout->addWidget( label, counter, 2 );
148 mLabels.append( label );
154 if ( counter == 0 ) {
155 TQLabel *label =
new TQLabel( i18n(
"No unread messages in your monitored folders" ),
this );
156 label->setAlignment( AlignHCenter | AlignVCenter );
157 mLayout->addMultiCellWidget( label, 0, 0, 0, 2 );
159 mLabels.append( label );
163 bool SummaryWidget::eventFilter( TQObject *obj, TQEvent* e )
165 if ( obj->inherits(
"KURLLabel" ) ) {
166 KURLLabel* label =
static_cast<KURLLabel*
>( obj );
167 if ( e->type() == TQEvent::Enter )
168 emit message( i18n(
"Open Folder: \"%1\"" ).arg( label->text() ) );
169 if ( e->type() == TQEvent::Leave )
170 emit message( TQString() );
173 return Kontact::Summary::eventFilter( obj, e );
176 TQStringList SummaryWidget::configModules()
const
178 return TQStringList(
"kcmkmailsummary.desktop" );
181 #include "summarywidget.moc"
Base class for all Plugins in Kontact.