2
Copyright (c) 2010 Bertjan Broeksema <broeksema@kde.org>
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.
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.
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
19
#include "kdeclarativemainview_p.h"
21
#include <KDE/KConfigGroup>
22
#include <KDE/KGlobal>
23
#include <KDE/KLineEdit>
24
#include <KDE/KSharedConfig>
25
#include <KDE/KProcess>
27
#include <akonadi/etmviewstatesaver.h>
29
#include "guistatemanager.h"
31
KDeclarativeMainViewPrivate::KDeclarativeMainViewPrivate( KDeclarativeMainView *qq )
33
, mChangeRecorder( 0 )
34
, mCollectionFilter( 0 )
35
, mItemFilterModel( 0 )
37
, mAgentStatusMonitor( 0 )
38
, mGuiStateManager( 0 )
40
, mFavoritesEditor( 0 )
43
void KDeclarativeMainViewPrivate::initializeStateSaver()
46
connect( mEtm, SIGNAL( modelAboutToBeReset() ), this, SLOT( saveState() ) );
47
connect( mEtm, SIGNAL( modelReset() ), this, SLOT( restoreState() ) );
50
void KDeclarativeMainViewPrivate::restoreState()
52
Akonadi::ETMViewStateSaver *saver = new Akonadi::ETMViewStateSaver;
53
saver->setSelectionModel( mBnf->selectionModel() );
54
KConfigGroup cfg( KGlobal::config(), "SelectionState" );
55
saver->restoreState( cfg );
58
void KDeclarativeMainViewPrivate::saveState()
60
Akonadi::ETMViewStateSaver saver;
61
saver.setSelectionModel( mBnf->selectionModel() );
63
KConfigGroup cfg( KGlobal::config(), "SelectionState" );
64
saver.saveState( cfg );
68
void KDeclarativeMainViewPrivate::filterLineEditChanged( const QString &text )
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();
80
void KDeclarativeMainViewPrivate::bulkActionFilterLineEditChanged( const QString &text )
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();
92
void KDeclarativeMainViewPrivate::searchStarted( const Akonadi::Collection &searchCollection )
94
q->persistCurrentSelection( "SelectionBeforeSearchStarted" );
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;
100
mGuiStateManager->pushState( GuiStateManager::SearchResultScreenState );
102
QItemSelectionModel *selectionModel = mBnf->selectionModel();
103
selectionModel->clearSelection();
105
restorer->setSelectionModel( selectionModel );
106
restorer->restoreSelection( selection );
109
void KDeclarativeMainViewPrivate::searchStopped()
111
mGuiStateManager->popState();
113
q->restorePersistedSelection( "SelectionBeforeSearchStarted" );
114
q->clearPersistedSelection( "SelectionBeforeSearchStarted" );
117
void KDeclarativeMainViewPrivate::guiStateChanged( int oldState, int newState )
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
124
if ( oldState == GuiStateManager::BulkActionScreenState ) {
125
if ( newState == GuiStateManager::AccountScreenState ||
126
newState == GuiStateManager::SingleFolderScreenState ||
127
newState == GuiStateManager::MultipleFolderScreenState ) {
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 ) );
136
// trigger a refresh of the line edit and item view
138
lineEdit->setText( text );
145
void KDeclarativeMainViewPrivate::openHtml( const QString &path )
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 );
152
q->openAttachment( path, QLatin1String( "text/html" ) );
156
DeclarativeBulkActionFilterLineEdit::DeclarativeBulkActionFilterLineEdit( QGraphicsItem *parent )
157
: DeclarativeWidgetBase<KLineEdit, KDeclarativeMainView, &KDeclarativeMainView::setBulkActionFilterLineEdit>( parent )
161
DeclarativeBulkActionFilterLineEdit::~DeclarativeBulkActionFilterLineEdit()
165
void DeclarativeBulkActionFilterLineEdit::clear()