~ubuntu-branches/ubuntu/vivid/kdepim/vivid

« back to all changes in this revision

Viewing changes to messagelist/pane.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Jonathan Riddell, Rohan Garg, Scott Kitterman
  • Date: 2012-11-21 13:12:36 UTC
  • mfrom: (0.2.33)
  • Revision ID: package-import@ubuntu.com-20121121131236-32ijw9a2txrar80k
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Rohan Garg ]
* Add nepomuk-core-dev to build-deps

[ Scott Kitterman ]
* Add new package, libpimcommon4
  - Add libpimcommon4.install
  - Add to debian/control, including kdepim-dbg and kdepim-dev depends
  - Add to kdepim-dev.install
* Remove usr/bin/backupmail and related files from kmail.install as they are
  not provided by upstream anymore
* Add usr/bin/pimsettingexporter and related files to kmail.install
* Add libnepomukwidgets-dev to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <KToggleAction>
29
29
 
30
30
#include <QtCore/QAbstractItemModel>
31
 
#include <QtGui/QAbstractProxyModel>
32
 
#include <QtGui/QItemSelectionModel>
33
 
#include <QtGui/QTabBar>
34
 
#include <QtGui/QToolButton>
35
 
#include <QtGui/QMouseEvent>
 
31
#include <QAbstractProxyModel>
 
32
#include <QItemSelectionModel>
 
33
#include <QTabBar>
 
34
#include <QToolButton>
 
35
#include <QMouseEvent>
 
36
#include <QHeaderView>
 
37
 
 
38
#include <akonadi/etmviewstatesaver.h>
36
39
 
37
40
#include "storagemodel.h"
38
41
#include "widget.h"
153
156
  setTabsClosable( Core::Settings::self()->tabsHaveCloseButton() );
154
157
  connect( this, SIGNAL(closeRequest(QWidget*)), SLOT(closeTab(QWidget*)) );
155
158
 
156
 
  createNewTab();
 
159
  readConfig();
157
160
  setMovable( true );
158
161
 
159
162
  connect( d->mSelectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
178
181
 
179
182
Pane::~Pane()
180
183
{
 
184
  writeConfig();
181
185
  delete d;
182
186
}
183
187
 
205
209
    }
206
210
    d->mActionMenu = new KActionMenu( KIcon(), i18n( "Message List" ), this );
207
211
    d->mXmlGuiClient->actionCollection()->addAction( QLatin1String( "view_message_list" ), d->mActionMenu );
208
 
    const Widget * const w = static_cast<Widget*>( currentWidget() );
209
 
    w->view()->fillViewMenu( d->mActionMenu->menu() );
 
212
    MessageList::Util::fillViewMenu( d->mActionMenu->menu(), this );
210
213
 
211
214
    KAction *action = new KAction( i18n("Create new tab"), this );
212
215
    action->setShortcut( QKeySequence( Qt::ALT + Qt::Key_T ) );
404
407
 
405
408
void Pane::Private::onSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
406
409
{
407
 
  Widget *w = 0;
408
 
  QItemSelectionModel *s = 0;
409
410
  if ( mPreferEmptyTab ) {
410
411
    q->createNewTab();
411
412
  }
412
 
        
413
 
  w = static_cast<Widget*>( q->currentWidget() );
414
 
  s = mWidgetSelectionHash[w];
 
413
 
 
414
  Widget *w = static_cast<Widget*>( q->currentWidget() );
 
415
  QItemSelectionModel * s = mWidgetSelectionHash[w];
415
416
 
416
417
  s->select( mapSelectionToSource( selected ), QItemSelectionModel::Select );
417
418
  s->select( mapSelectionToSource( deselected ), QItemSelectionModel::Deselect );
418
419
 
419
420
  QString label;
420
 
  QIcon icon = KIcon( QLatin1String( "folder" ) );
 
421
  QIcon icon;
421
422
  QString toolTip;
422
423
  foreach ( const QModelIndex &index, s->selectedRows() ) {
423
424
    label+= index.data( Qt::DisplayRole ).toString()+QLatin1String( ", " );
435
436
      toolTip = idx.data().toString() + QLatin1Char( '/' ) + toolTip;
436
437
      idx = idx.parent();
437
438
    }
 
439
  } else {
 
440
     icon = KIcon( QLatin1String( "folder" ) );
438
441
  }
439
442
 
440
 
  int index = q->indexOf( w );
 
443
  const int index = q->indexOf( w );
441
444
  q->setTabText( index, label );
442
445
  q->setTabIcon( index, icon );
443
446
  q->setTabToolTip( index, toolTip);
591
594
  QTabBar *bar = q->tabBar();
592
595
  if ( q->count() <= 1 ) return;
593
596
 
594
 
  int index = bar->tabAt( bar->mapFrom( q, pos ) );
595
 
  if ( index == -1 ) return;
 
597
  const int indexBar = bar->tabAt( bar->mapFrom( q, pos ) );
 
598
  if ( indexBar == -1 ) return;
596
599
 
597
 
  Widget *w = qobject_cast<Widget *>( q->widget( index ) );
 
600
  Widget *w = qobject_cast<Widget *>( q->widget( indexBar ) );
598
601
  if ( !w ) return;
599
602
 
600
603
  KMenu menu( q );
614
617
 
615
618
  if ( action == allOther ) { // Close all other tabs
616
619
    QList<Widget *> widgets;
617
 
    int index = q->indexOf( w );
 
620
    const int index = q->indexOf( w );
618
621
 
619
622
    for ( int i=0; i<q->count(); i++ ) {
620
623
      if ( i==index) continue; // Skip the current one
664
667
  }
665
668
}
666
669
 
667
 
void Pane::createNewTab()
 
670
QItemSelectionModel *Pane::createNewTab()
668
671
{
669
672
  Widget * w = new Widget( this );
670
673
  w->setXmlGuiClient( d->mXmlGuiClient );
691
694
  connect( w, SIGNAL(fullSearchRequest()), this, SIGNAL(fullSearchRequest()) );
692
695
  d->updateTabControls();
693
696
  setCurrentWidget( w );
 
697
  return s;
694
698
}
695
699
 
696
700
QItemSelection Pane::Private::mapSelectionToSource( const QItemSelection &selection ) const
959
963
  }
960
964
}
961
965
 
 
966
void Pane::writeConfig()
 
967
{
 
968
  KConfigGroup conf( MessageList::Core::Settings::self()->config(),"MessageListPane");
 
969
 
 
970
  //Delete liste before
 
971
  const QStringList list = conf.groupList().filter( QRegExp( QLatin1String("MessageListTab\\d+") ) );
 
972
  foreach ( const QString &group, list ) {
 
973
    conf.deleteGroup( group );
 
974
  }
 
975
 
 
976
  conf.writeEntry(QLatin1String("currentIndex"),currentIndex());
 
977
  conf.writeEntry(QLatin1String("tabNumber"),count());
 
978
 
 
979
  for ( int i=0; i<count(); i++ ) {
 
980
    Widget *w = qobject_cast<Widget *>( widget( i ) );
 
981
    KConfigGroup grp(MessageList::Core::Settings::self()->config(),QString::fromLatin1("MessageListTab%1").arg(i));
 
982
    grp.writeEntry(QLatin1String("collectionId"),w->currentCollection().id());
 
983
    grp.writeEntry(QLatin1String("HeaderState"), w->view()->header()->saveState());
 
984
  }
 
985
  conf.sync();
 
986
}
 
987
 
 
988
 
 
989
void Pane::readConfig()
 
990
{
 
991
  if(MessageList::Core::Settings::self()->config()->hasGroup(QLatin1String("MessageListPane"))) {
 
992
    KConfigGroup conf( MessageList::Core::Settings::self()->config(),"MessageListPane");
 
993
    const int numberOfTab = conf.readEntry(QLatin1String("tabNumber"),0);
 
994
    if(numberOfTab == 0) {
 
995
      createNewTab();
 
996
    } else {
 
997
      for(int i = 0; i<numberOfTab; ++i)
 
998
      {
 
999
        KConfigGroup grp(MessageList::Core::Settings::self()->config(),QString::fromLatin1("MessageListTab%1").arg(i));
 
1000
        QItemSelectionModel *selectionModel = createNewTab();
 
1001
#if 0
 
1002
        Akonadi::Collection::Id id = grp.readEntry(QLatin1String("collectionId"),-1);
 
1003
        ETMViewStateSaver *saver = new ETMViewStateSaver;
 
1004
        saver->setSelectionModel(selectionModel);
 
1005
 
 
1006
        if(id != -1) {
 
1007
            ETMViewStateSaver *saver = new ETMViewStateSaver;
 
1008
            saver->setSelectionModel(selectionModel);
 
1009
            saver->restoreState( grp );
 
1010
            saver->selectCollections(Akonadi::Collection::List()<<Akonadi::Collection(id));
 
1011
        }
 
1012
#endif
 
1013
        Widget *w = qobject_cast<Widget *>( widget( i ) );
 
1014
        w->view()->header()->restoreState(grp.readEntry(QLatin1String("HeaderState"),QByteArray()));
 
1015
      }
 
1016
      setCurrentIndex(conf.readEntry(QLatin1String("currentIndex"),0));
 
1017
    }
 
1018
  } else {
 
1019
    createNewTab();
 
1020
  }
 
1021
}
 
1022
 
962
1023
 
963
1024
bool Pane::searchEditHasFocus() const
964
1025
{
968
1029
  return false;
969
1030
}
970
1031
 
 
1032
 
 
1033
void Pane::sortOrderMenuAboutToShow()
 
1034
{
 
1035
  KMenu * menu = dynamic_cast< KMenu * >( sender() );
 
1036
  if ( !menu )
 
1037
    return;
 
1038
  const Widget * const w = static_cast<Widget*>( currentWidget() );
 
1039
  w->view()->sortOrderMenuAboutToShow(menu);
 
1040
}
 
1041
 
 
1042
void Pane::aggregationMenuAboutToShow()
 
1043
{
 
1044
  KMenu * menu = dynamic_cast< KMenu * >( sender() );
 
1045
  if ( !menu )
 
1046
   return;
 
1047
  const Widget * const w = static_cast<Widget*>( currentWidget() );
 
1048
  w->view()->aggregationMenuAboutToShow(menu);
 
1049
}
 
1050
 
 
1051
void Pane::themeMenuAboutToShow()
 
1052
{
 
1053
  KMenu * menu = dynamic_cast< KMenu * >( sender() );
 
1054
  if ( !menu )
 
1055
    return;
 
1056
  const Widget * const w = static_cast<Widget*>( currentWidget() );
 
1057
  w->view()->themeMenuAboutToShow(menu);
 
1058
}
 
1059
 
 
1060
 
971
1061
#include "pane.moc"