28 #include "kmailinterface.h"
30 #include <KontactInterface/Core>
31 #include <KontactInterface/Plugin>
33 #include <Akonadi/ChangeRecorder>
34 #include <Akonadi/CollectionFetchScope>
35 #include <Akonadi/CollectionStatistics>
36 #include <Akonadi/EntityTreeModel>
37 #include <Akonadi/ETMViewStateSaver>
39 #include <KMime/KMimeMessage>
41 #include <KCheckableProxyModel>
42 #include <KConfigGroup>
44 #include <KLocalizedString>
49 #include <QGridLayout>
50 #include <QVBoxLayout>
51 #include <QItemSelectionModel>
56 : KontactInterface::Summary( parent ), mPlugin( plugin )
71 mChangeRecorder =
new Akonadi::ChangeRecorder(
this );
72 mChangeRecorder->setMimeTypeMonitored( KMime::Message::mimeType() );
73 mChangeRecorder->fetchCollectionStatistics(
true );
74 mChangeRecorder->setAllMonitored(
true );
75 mChangeRecorder->collectionFetchScope().setIncludeStatistics(
true );
77 mModel =
new Akonadi::EntityTreeModel( mChangeRecorder,
this );
78 mModel->setItemPopulationStrategy( Akonadi::EntityTreeModel::NoItemPopulation );
81 mModelProxy =
new KCheckableProxyModel(
this );
82 mModelProxy->setSelectionModel( mSelectionModel );
83 mModelProxy->setSourceModel( mModel );
85 KSharedConfigPtr _config = KSharedConfig::openConfig(
QLatin1String(
"kcmkmailsummaryrc") );
88 new KViewStateMaintainer<Akonadi::ETMViewStateSaver>( _config->group(
"CheckState" ), this );
89 mModelState->setSelectionModel( mSelectionModel );
91 connect( mChangeRecorder, SIGNAL(collectionChanged(Akonadi::Collection)),
92 SLOT(slotCollectionChanged()) );
93 connect( mChangeRecorder, SIGNAL(collectionRemoved(Akonadi::Collection)),
94 SLOT(slotCollectionChanged()) );
95 connect( mChangeRecorder, SIGNAL(collectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)),
96 SLOT(slotCollectionChanged()));
100 void SummaryWidget::slotCollectionChanged()
111 void SummaryWidget::selectFolder(
const QString &folder )
113 if ( mPlugin->isRunningStandalone() ) {
114 mPlugin->bringToForeground();
116 mPlugin->core()->selectPlugin( mPlugin );
120 kmail.selectFolder( folder );
123 void SummaryWidget::displayModel(
const QModelIndex &parent,
125 const bool showFolderPaths,
128 const int nbCol = mModelProxy->rowCount( parent );
129 for (
int i = 0; i < nbCol; ++i ) {
130 const QModelIndex child = mModelProxy->index( i, 0, parent );
131 const Akonadi::Collection col =
132 mModelProxy->data( child,
133 Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
134 const int showCollection =
135 mModelProxy->data( child, Qt::CheckStateRole ).value<
int>();
137 if ( col.isValid() ) {
138 const Akonadi::CollectionStatistics stats = col.statistics();
139 if ( ( ( stats.unreadCount() ) != Q_INT64_C(0) ) && showCollection ) {
143 if ( showFolderPaths ) {
145 parentTreeNames.
insert( parentTreeNames.
size(), col.name() );
150 urlLabel =
new KUrlLabel(
QString::number( col.id() ), col.name(), this );
153 urlLabel->installEventFilter(
this );
154 urlLabel->setAlignment( Qt::AlignLeft );
155 urlLabel->setWordWrap(
true );
156 mLayout->
addWidget( urlLabel, counter, 1 );
157 mLabels.
append( urlLabel );
160 urlLabel->setToolTip( i18n(
"<qt><b>%1</b>"
161 "<br/>Total: %2<br/>"
165 stats.unreadCount() ) );
167 connect( urlLabel, SIGNAL(leftClickedUrl(
QString)),
171 QLabel *label =
new QLabel( i18nc(
"%1: number of unread messages "
172 "%2: total number of messages",
173 "%1 / %2", stats.unreadCount(), stats.count() ),
this );
180 QIcon icon = mModelProxy->data( child, Qt::DecorationRole ).value<
QIcon>();
181 label =
new QLabel(
this );
183 label->setMaximumWidth( label->minimumSizeHint().width() );
184 label->setAlignment( Qt::AlignVCenter );
190 parentTreeNames.
insert( parentTreeNames.
size(), col.name() );
191 displayModel( child, counter, showFolderPaths, parentTreeNames );
198 void SummaryWidget::slotUpdateFolderList()
200 qDeleteAll( mLabels );
202 mModelState->restoreState();
206 KConfigGroup config( &_config,
"General" );
207 const bool showFolderPaths = config.readEntry(
"showFolderPaths",
false );
210 if ( counter == 0 ) {
211 QLabel *label =
new QLabel( i18n(
"No unread messages in your monitored folders" ),
this );
212 label->
setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
219 for ( lit = mLabels.
constBegin(); lit != lend; ++lit ) {
226 if ( obj->
inherits(
"KUrlLabel" ) ) {
227 KUrlLabel* label =
static_cast<KUrlLabel*
>( obj );
228 if ( e->
type() == QEvent::Enter ) {
229 emit message( i18n(
"Open Folder: \"%1\"", label->text() ) );
230 }
else if ( e->
type() == QEvent::Leave ) {
231 emit message( QString::null );
235 return KontactInterface::Summary::eventFilter( obj, e );
void setAlignment(QFlags< Qt::AlignmentFlag >)
QDBusConnection sessionBus()
QString join(const QString &separator) const
void setSpacing(int spacing)
QPixmap pixmap(const QSize &size, Mode mode, State state) const
QString number(int n, int base)
void append(const T &value)
void setRowStretch(int row, int stretch)
bool inherits(const char *className) const
virtual void addItem(QLayoutItem *item)
void setMargin(int margin)
void setPixmap(const QPixmap &pixmap, Size size, Mode mode, State state)
void insert(int i, const T &value)
const_iterator constEnd() const
const_iterator constBegin() const
void setSpacing(int spacing)