~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to mobile/lib/kdeclarativemainview_p.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2010 Bertjan Broeksema <broeksema@kde.org>
 
3
 
 
4
    This library is free software; you can redistribute it and/or modify it
 
5
    under the terms of the GNU Library General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or (at your
 
7
    option) any later version.
 
8
 
 
9
    This library is distributed in the hope that it will be useful, but WITHOUT
 
10
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
11
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 
12
    License for more details.
 
13
 
 
14
    You should have received a copy of the GNU Library General Public License
 
15
    along with this library; see the file COPYING.LIB.  If not, write to the
 
16
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
17
    02110-1301, USA.
 
18
*/
 
19
#include "kdeclarativemainview_p.h"
 
20
 
 
21
#include <KDE/KConfigGroup>
 
22
#include <KDE/KGlobal>
 
23
#include <KDE/KLineEdit>
 
24
#include <KDE/KSharedConfig>
 
25
#include <KDE/KProcess>
 
26
 
 
27
#include <akonadi/etmviewstatesaver.h>
 
28
 
 
29
#include "guistatemanager.h"
 
30
 
 
31
KDeclarativeMainViewPrivate::KDeclarativeMainViewPrivate( KDeclarativeMainView *qq )
 
32
  : q( qq )
 
33
  , mChangeRecorder( 0 )
 
34
  , mCollectionFilter( 0 )
 
35
  , mItemFilterModel( 0 )
 
36
  , mBnf( 0 )
 
37
  , mAgentStatusMonitor( 0 )
 
38
  , mGuiStateManager( 0 )
 
39
  , mStateMachine( 0 )
 
40
  , mFavoritesEditor( 0 )
 
41
{ }
 
42
 
 
43
void KDeclarativeMainViewPrivate::initializeStateSaver()
 
44
{
 
45
  restoreState();
 
46
  connect( mEtm, SIGNAL( modelAboutToBeReset() ), this, SLOT( saveState() ) );
 
47
  connect( mEtm, SIGNAL( modelReset() ), this, SLOT( restoreState() ) );
 
48
}
 
49
 
 
50
void KDeclarativeMainViewPrivate::restoreState()
 
51
{
 
52
  Akonadi::ETMViewStateSaver *saver = new Akonadi::ETMViewStateSaver;
 
53
  saver->setSelectionModel( mBnf->selectionModel() );
 
54
  KConfigGroup cfg( KGlobal::config(), "SelectionState" );
 
55
  saver->restoreState( cfg );
 
56
}
 
57
 
 
58
void KDeclarativeMainViewPrivate::saveState()
 
59
{
 
60
  Akonadi::ETMViewStateSaver saver;
 
61
  saver.setSelectionModel( mBnf->selectionModel() );
 
62
 
 
63
  KConfigGroup cfg( KGlobal::config(), "SelectionState" );
 
64
  saver.saveState( cfg );
 
65
  cfg.sync();
 
66
}
 
67
 
 
68
void KDeclarativeMainViewPrivate::filterLineEditChanged( const QString &text )
 
69
{
 
70
  if ( !text.isEmpty() ) {
 
71
    mFilterLineEdit->setFixedHeight( 40 );
 
72
    mFilterLineEdit->show();
 
73
    mFilterLineEdit->setFocus();
 
74
  } else if ( text.isEmpty() ) {
 
75
    mFilterLineEdit->setFixedHeight( 0 );
 
76
    mFilterLineEdit->hide();
 
77
  }
 
78
}
 
79
 
 
80
void KDeclarativeMainViewPrivate::bulkActionFilterLineEditChanged( const QString &text )
 
81
{
 
82
  if ( !text.isEmpty() ) {
 
83
    mBulkActionFilterLineEdit->setFixedHeight( 40 );
 
84
    mBulkActionFilterLineEdit->show();
 
85
    mBulkActionFilterLineEdit->setFocus();
 
86
  } else if ( text.isEmpty() ) {
 
87
    mBulkActionFilterLineEdit->setFixedHeight( 0 );
 
88
    mBulkActionFilterLineEdit->hide();
 
89
  }
 
90
}
 
91
 
 
92
void KDeclarativeMainViewPrivate::searchStarted( const Akonadi::Collection &searchCollection )
 
93
{
 
94
  q->persistCurrentSelection( "SelectionBeforeSearchStarted" );
 
95
 
 
96
  const QStringList selection = QStringList() << QLatin1String( "c1" ) // the 'Search' collection
 
97
                                              << QString::fromLatin1( "c%1" ).arg( searchCollection.id() );
 
98
  Akonadi::ETMViewStateSaver *restorer = new Akonadi::ETMViewStateSaver;
 
99
 
 
100
  mGuiStateManager->pushState( GuiStateManager::SearchResultScreenState );
 
101
 
 
102
  QItemSelectionModel *selectionModel = mBnf->selectionModel();
 
103
  selectionModel->clearSelection();
 
104
 
 
105
  restorer->setSelectionModel( selectionModel );
 
106
  restorer->restoreSelection( selection );
 
107
}
 
108
 
 
109
void KDeclarativeMainViewPrivate::searchStopped()
 
110
{
 
111
  mGuiStateManager->popState();
 
112
 
 
113
  q->restorePersistedSelection( "SelectionBeforeSearchStarted" );
 
114
  q->clearPersistedSelection( "SelectionBeforeSearchStarted" );
 
115
}
 
116
 
 
117
void KDeclarativeMainViewPrivate::guiStateChanged( int oldState, int newState )
 
118
{
 
119
  /**
 
120
   * If we come back from the BulkActionScreen and we had a filter string
 
121
   * entered before we entered the BulkActionScreen, we'll refresh this
 
122
   * filter string now.
 
123
   */
 
124
  if ( oldState == GuiStateManager::BulkActionScreenState ) {
 
125
    if ( newState == GuiStateManager::AccountScreenState ||
 
126
         newState == GuiStateManager::SingleFolderScreenState ||
 
127
         newState == GuiStateManager::MultipleFolderScreenState ) {
 
128
 
 
129
      KLineEdit *lineEdit = mFilterLineEdit.data();
 
130
      if ( lineEdit && mItemFilterModel ) {
 
131
        const QString text = lineEdit->text();
 
132
        if ( text.isEmpty() ) {
 
133
          // just trigger a refresh of the item view
 
134
          QMetaObject::invokeMethod( mItemFilterModel, "setFilterString", Qt::DirectConnection, Q_ARG( QString, text ) );
 
135
        } else {
 
136
          // trigger a refresh of the line edit and item view
 
137
          lineEdit->clear();
 
138
          lineEdit->setText( text );
 
139
        }
 
140
      }
 
141
    }
 
142
  }
 
143
}
 
144
 
 
145
void KDeclarativeMainViewPrivate::openHtml( const QString &path )
 
146
{
 
147
#ifdef Q_WS_MAEMO_5
 
148
  // opening the browser with a website via desktop file is defect on maemo5
 
149
  // try to call the bowser directly
 
150
  KProcess::startDetached( QLatin1String("/usr/bin/browser"), QStringList() << QLatin1String("--url") << path );
 
151
#else
 
152
  q->openAttachment( path, QLatin1String( "text/html" ) );
 
153
#endif
 
154
}
 
155
 
 
156
DeclarativeBulkActionFilterLineEdit::DeclarativeBulkActionFilterLineEdit( QGraphicsItem *parent )
 
157
  : DeclarativeWidgetBase<KLineEdit, KDeclarativeMainView, &KDeclarativeMainView::setBulkActionFilterLineEdit>( parent )
 
158
{
 
159
}
 
160
 
 
161
DeclarativeBulkActionFilterLineEdit::~DeclarativeBulkActionFilterLineEdit()
 
162
{
 
163
}
 
164
 
 
165
void DeclarativeBulkActionFilterLineEdit::clear()
 
166
{
 
167
  widget()->clear();
 
168
}