22 #include <Akonadi/CollectionStatistics>
23 #include <Akonadi/CollectionStatisticsDelegate>
24 #include <Akonadi/EntityTreeModel>
26 #include <KConfigGroup>
31 #include <KMessageBox>
33 #include <QHeaderView>
34 #include <QMouseEvent>
36 namespace MailCommon {
39 : Akonadi::EntityTreeView( parent ),
40 mbDisableContextMenuAndExtraColumn( false ),
41 mbDisableSaveConfig( false )
43 init(showUnreadCount);
47 : Akonadi::EntityTreeView( xmlGuiClient, parent ),
48 mbDisableContextMenuAndExtraColumn( false ),
49 mbDisableSaveConfig( false )
51 init( showUnreadCount );
60 mbDisableSaveConfig =
true;
65 if ( mToolTipDisplayPolicy == policy ) {
69 mToolTipDisplayPolicy = policy;
76 mbDisableContextMenuAndExtraColumn =
true;
77 const int nbColumn = header()->count();
78 for (
int i = 1; i <nbColumn; ++i ) {
79 setColumnHidden( i,
true );
85 setIconSize( QSize( 22, 22 ) );
86 setUniformRowHeights(
true );
90 header()->setContextMenuPolicy( Qt::CustomContextMenu );
91 connect( header(), SIGNAL(customContextMenuRequested(QPoint)),
94 mCollectionStatisticsDelegate =
new Akonadi::CollectionStatisticsDelegate(
this );
95 mCollectionStatisticsDelegate->setProgressAnimationEnabled(
true );
96 setItemDelegate(mCollectionStatisticsDelegate);
97 mCollectionStatisticsDelegate->setUnreadCountShown(
98 showUnreadCount && !header()->isSectionHidden( 1 ) );
103 mCollectionStatisticsDelegate->setProgressAnimationEnabled( anim );
108 if ( mbDisableSaveConfig ) {
112 KConfigGroup myGroup(
KernelIf->config(),
"MainFolderView" );
113 myGroup.writeEntry(
"IconSize", iconSize().width() );
114 myGroup.writeEntry(
"ToolTipDisplayPolicy", (
int)mToolTipDisplayPolicy );
115 myGroup.writeEntry(
"SortingPolicy", (
int)mSortingPolicy );
120 KConfigGroup myGroup(
KernelIf->config(),
"MainFolderView" );
121 int iIconSize = myGroup.readEntry(
"IconSize", iconSize().width() );
122 if ( iIconSize < 16 || iIconSize > 32 ) {
125 setIconSize( QSize( iIconSize, iIconSize ) );
126 mToolTipDisplayPolicy =
128 myGroup.readEntry(
"ToolTipDisplayPolicy",
140 if ( mbDisableContextMenuAndExtraColumn ) {
148 menu.addTitle( i18n(
"View Columns" ) );
149 const int nbColumn = header()->count();
150 for (
int i = 1; i <nbColumn; ++i ) {
151 act = menu.addAction( model()->headerData( i, Qt::Horizontal ).toString() );
152 act->setCheckable(
true );
153 act->setChecked( !header()->isSectionHidden( i ) );
154 act->setData( QVariant( i ) );
155 connect( act, SIGNAL(triggered(
bool)),
159 menu.addTitle( i18n(
"Icon Size" ) );
161 static int icon_sizes[] = { 16, 22, 32 };
163 QActionGroup *grp =
new QActionGroup( &menu );
164 const int nbElement( (
int)(
sizeof( icon_sizes ) /
sizeof(
int ) ) );
165 for (
int i = 0; i < nbElement; ++i ) {
166 act = menu.addAction( QString::fromLatin1(
"%1x%2" ).arg( icon_sizes[ i ] ).arg( icon_sizes[ i ] ) );
167 act->setCheckable(
true );
168 grp->addAction( act );
169 if ( iconSize().width() == icon_sizes[ i ] ) {
170 act->setChecked(
true );
172 act->setData( QVariant( icon_sizes[ i ] ) );
174 connect( act, SIGNAL(triggered(
bool)),
177 menu.addTitle( i18n(
"Display Tooltips" ) );
179 grp =
new QActionGroup( &menu );
181 act = menu.addAction( i18nc(
"@action:inmenu Always display tooltips",
"Always" ) );
182 act->setCheckable(
true );
183 grp->addAction( act );
186 connect( act, SIGNAL(triggered(
bool)),
189 act = menu.addAction( i18nc(
"@action:inmenu Never display tooltips.",
"Never" ) );
190 act->setCheckable(
true );
191 grp->addAction( act );
194 connect( act, SIGNAL(triggered(
bool)),
197 menu.addTitle( i18nc(
"@action:inmenu",
"Sort Items" ) );
199 grp =
new QActionGroup( &menu );
201 act = menu.addAction( i18nc(
"@action:inmenu",
"Automatically, by Current Column" ) );
202 act->setCheckable(
true );
203 grp->addAction( act );
206 connect( act, SIGNAL(triggered(
bool)),
209 act = menu.addAction( i18nc(
"@action:inmenu",
"Manually, by Drag And Drop" ) );
210 act->setCheckable(
true );
211 grp->addAction( act );
214 connect( act, SIGNAL(triggered(
bool)),
217 menu.exec( header()->mapToGlobal( pnt ) );
222 QAction *act =
dynamic_cast< QAction *
>( sender() );
227 QVariant data = act->data();
230 int policy = data.toInt( &ok );
240 if ( mSortingPolicy == policy ) {
244 mSortingPolicy = policy;
245 switch ( mSortingPolicy ) {
247 header()->setClickable(
true );
248 header()->setSortIndicatorShown(
true );
249 setSortingEnabled(
true );
254 header()->setClickable(
false );
255 header()->setSortIndicatorShown(
false );
266 setSortingEnabled(
true );
267 header()->setSortIndicator( 0, Qt::AscendingOrder );
269 setSortingEnabled(
false );
277 if ( writeInConfig ) {
284 QAction *act =
dynamic_cast< QAction *
>( sender() );
289 QVariant data = act->data();
292 const int id = data.toInt( &ok );
301 QAction *act =
dynamic_cast< QAction *
>( sender() );
306 QVariant data = act->data();
309 const int id = data.toInt( &ok );
314 if (
id > header()->count() ) {
319 mCollectionStatisticsDelegate->setUnreadCountShown( !act->isChecked() );
322 setColumnHidden(
id, !act->isChecked() );
327 QAction *act =
dynamic_cast< QAction *
>( sender() );
332 QVariant data = act->data();
335 const int size = data.toInt( &ok );
340 const QSize newIconSize( QSize( size, size ) );
341 if ( newIconSize == iconSize() ) {
344 setIconSize( newIconSize );
351 if ( index.isValid() ) {
354 selectionModel()->setCurrentIndex( index, QItemSelectionModel::Rows );
360 if ( index.isValid() ) {
362 selectionModel()->select(
364 QItemSelectionModel::Rows | QItemSelectionModel::Select |
365 QItemSelectionModel::Current | QItemSelectionModel::Clear );
371 const QModelIndex index = currentIndex();
372 if ( index.isValid() ) {
373 setCurrentIndex( index );
381 if ( nextFolder.isValid() ) {
382 expand( nextFolder );
390 if ( current.isValid() ) {
391 model()->fetchMore( current );
392 if ( model()->hasChildren( current ) ) {
395 }
else if ( current.row() < model()->rowCount( model()->parent( current ) ) -1 ) {
396 below = model()->index( current.row()+1, current.column(), model()->parent( current ) );
406 const QModelIndex current = currentIndex();
407 if ( current.isValid() ) {
415 const QModelIndex first = moveCursor( QAbstractItemView::MoveHome, 0 );
416 if ( first.isValid() ) {
423 const QModelIndex last = moveCursor( QAbstractItemView::MoveEnd, 0 );
424 if ( last.isValid() ) {
442 if ( model->rowCount( current ) == 0 ) {
446 return lastChildOf( model, model->index( model->rowCount( current ) - 1, 0, current ) );
454 const QModelIndex index =
lastChildOf( model(), QModelIndex() );
459 bool FolderTreeView::trySelectNextUnreadFolder(
const QModelIndex ¤t,
463 QModelIndex index = current;
467 if ( !index.isValid() ) {
471 const Akonadi::Collection collection =
472 index.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
477 if ( ignoreUnreadFolder( collection, confirm ) ) {
481 if ( allowedToEnterFolder( collection, confirm ) ) {
483 setCurrentIndex( index );
494 bool FolderTreeView::ignoreUnreadFolder(
const Akonadi::Collection &collection,
bool confirm )
const
505 return ( collection ==
Kernel::self()->draftsCollectionFolder() ||
506 collection ==
Kernel::self()->templatesCollectionFolder() ||
510 bool FolderTreeView::allowedToEnterFolder(
const Akonadi::Collection &collection,
521 KMessageBox::questionYesNo(
522 const_cast<FolderTreeView*>(
this ),
523 i18n(
"<qt>Go to the next unread message in folder <b>%1</b>?</qt>", collection.name() ),
524 i18n(
"Go to Next Unread Message" ),
525 KGuiItem( i18n(
"Go To" ) ),
526 KGuiItem( i18n(
"Do Not Go To" ) ),
527 QLatin1String(
":kmail_AskNextFolder"), 0 );
529 return ( result == KMessageBox::Yes );
536 if ( current.isValid() ) {
544 if ( index.isValid() ) {
545 const Akonadi::Collection collection =
547 current, Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
549 if ( collection.isValid() ) {
550 if ( collection.statistics().unreadCount() > 0 ) {
560 if ( collection ==
Kernel::self()->draftsCollectionFolder() ||
561 collection ==
Kernel::self()->templatesCollectionFolder() ||
562 collection ==
Kernel::self()->sentCollectionFolder() ) {
569 if ( KMessageBox::questionYesNo(
571 i18n(
"<qt>Go to the next unread message in folder <b>%1</b>?</qt>",
573 i18n(
"Go to Next Unread Message" ),
574 KGuiItem( i18n(
"Go To" ) ),
575 KGuiItem( i18n(
"Do Not Go To" ) ),
576 QLatin1String(
":kmail_AskNextFolder"),
577 0 ) == KMessageBox::No ) {
593 const QModelIndex current = currentIndex();
594 if ( current.isValid() ) {
595 const Akonadi::Collection collection =
596 current.model()->data(
598 Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
601 return Akonadi::Collection();
606 const bool buttonPressedIsMiddle = ( e->button() == Qt::MidButton );
608 EntityTreeView::mousePressEvent( e );
613 if (data.isEmpty()) {
614 const int nbColumn = header()->count();
615 for (
int i = 1; i <nbColumn; ++i ) {
616 setColumnHidden( i,
true );
620 header()->restoreState( data );
621 mCollectionStatisticsDelegate->setUnreadCountShown( header()->isSectionHidden( 1 ) );
626 mCollectionStatisticsDelegate->updatePalette();
638 #include "foldertreeview.moc"
void slotFocusNextFolder()
void slotHeaderContextMenuChangeToolTipDisplayPolicy(bool)
void slotFocusLastFolder()
void slotHeaderContextMenuRequested(const QPoint &)
void setSortingPolicy(FolderTreeWidget::SortingPolicy policy, bool writeInConfig=false)
virtual void mousePressEvent(QMouseEvent *e)
Akonadi::Collection trashCollectionFolder()
static QModelIndex indexAbove(QAbstractItemModel *model, const QModelIndex ¤t)
Akonadi::Collection currentFolder() const
void selectPrevUnreadFolder(bool confirm=false)
void slotFocusPrevFolder()
void changeTooltipsPolicy(FolderTreeWidget::ToolTipDisplayPolicy)
void slotSelectFocusFolder()
void slotHeaderContextMenuChangeHeader(bool)
void slotHeaderContextMenuChangeSortingPolicy(bool)
void disableContextMenuAndExtraColumn()
SearchDirection
Describes the direction for searching next unread collection.
bool isUnreadFolder(const QModelIndex ¤t, QModelIndex &nextIndex, FolderTreeView::Move move, bool confirm)
void restoreHeaderState(const QByteArray &data)
void manualSortingChanged(bool actif)
void setCurrentModelIndex(const QModelIndex &)
void slotHeaderContextMenuChangeIconSize(bool)
virtual ~FolderTreeView()
QModelIndex selectNextFolder(const QModelIndex ¤t)
static QModelIndex indexBelow(QAbstractItemModel *model, const QModelIndex ¤t)
void showStatisticAnimation(bool anim)
void prefereCreateNewTab(bool)
void keyboardSearch(const QString &)
void setTooltipsPolicy(FolderTreeWidget::ToolTipDisplayPolicy)
FolderTreeView(QWidget *parent=0, bool showUnreadCount=true)
void selectModelIndex(const QModelIndex &)
static QModelIndex lastChildOf(QAbstractItemModel *model, const QModelIndex ¤t)
void slotFocusFirstFolder()
Akonadi::Collection outboxCollectionFolder()
MAILCOMMON_EXPORT QModelIndex nextUnreadCollection(QAbstractItemModel *model, const QModelIndex ¤t, SearchDirection direction, bool(*ignoreCollectionCallback)(const Akonadi::Collection &collection)=0)
Returns the index of the next unread collection following a given index.
void selectNextUnreadFolder(bool confirm=false)
void init(bool showUnreadCount)