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 #ifndef KDECLARATIVEMAINVIEW_H
20 #define KDECLARATIVEMAINVIEW_H
22 #include "kdeclarativefullscreenview.h"
24 #include <QtGui/QItemSelectionModel>
26 class ExportHandlerBase
;
27 class GuiStateManager
;
28 class ImportHandlerBase
;
31 class QAbstractItemModel
;
32 class QAbstractProxyModel
;
35 class AgentActionManager
;
37 class EntityTreeModel
;
42 class KDeclarativeMainViewPrivate
;
45 * Main view for mobile applications. This class is just to share code and therefore
46 * should not be instantiated by itself.
48 class MOBILEUI_EXPORT KDeclarativeMainView
: public KDeclarativeFullScreenView
51 Q_PROPERTY( int numSelectedAccounts READ numSelectedAccounts NOTIFY numSelectedAccountsChanged
)
52 Q_PROPERTY( bool isLoadingSelected READ isLoadingSelected NOTIFY isLoadingSelectedChanged
)
53 Q_PROPERTY( QString version READ version CONSTANT
)
54 Q_PROPERTY( QString name READ name CONSTANT
)
55 Q_PROPERTY( QString state READ applicationState WRITE setApplicationState NOTIFY stateChanged
)
59 * Destroys the declarative main view.
61 virtual ~KDeclarativeMainView();
64 * Item fetch scope to specify how much data should be loaded for the list view.
65 * By default nothing is loaded.
67 Akonadi::ItemFetchScope
& itemFetchScope();
70 * Adds a mime type of the items handled by this application.
72 void addMimeType( const QString
&mimeType
);
75 * Returns the mime types of the items handled by this application.
77 QStringList
mimeTypes() const;
80 * Returns the number of selected accounts.
82 int numSelectedAccounts();
85 * Returns the version of the application.
87 QString
version() const;
90 * Returns the localized name of the application.
95 * Returns the monitor that is used by the application.
97 Akonadi::ChangeRecorder
* monitor() const;
100 * Returns the gui state manager that will be used to manage the visibility
101 * of the various gui elements of the application.
103 GuiStateManager
* guiStateManager() const;
106 * Sets the @p lineEdit that is used to filter the items in the listview.
108 void setFilterLineEdit( KLineEdit
*lineEdit
);
111 * Sets the @p lineEdit that is used to filter the items in the listview in bulk action mode.
113 void setBulkActionFilterLineEdit( KLineEdit
*lineEdit
);
115 QString
applicationState() const;
116 void setApplicationState( const QString
&state
);
119 void setSelectedAccount( int row
);
121 void setAgentInstanceListSelectedRow( int row
);
124 * Starts the account wizard to add and configure new resources.
126 void launchAccountWizard();
129 * Starts the synchronization of all collections.
131 void synchronizeAllItems();
134 * Opens the licenses.pdf in an external viewer
139 void loadFavorite( const QString
&name
);
140 void multipleSelectionFinished();
142 void persistCurrentSelection( const QString
&key
);
143 void clearPersistedSelection( const QString
&key
);
144 void restorePersistedSelection( const QString
&key
);
147 * Starts the import of items to the application.
149 * The actual work is done by the ImportHandlerBase objects returned
150 * by the importHandler() method.
155 * Starts the export of items from the application.
157 * The actual work is done by the ExportHandlerBase objects returned
158 * by the exportHandler() method.
163 * Starts the export of a single item from the application.
165 * The actual work is done by the ExportHandlerBase objects returned
166 * by the exportHandler() method.
168 void exportSingleItem();
171 * Opens the user manual of this application in an external web browser.
176 * Opens the HTML based documentation located at the given relative @p path.
178 void openDocumentation( const QString
&path
);
180 void openAttachment( const QString
&url
, const QString
&mimeType
);
181 void saveAttachment( const QString
&url
, const QString
&defaultFileName
= QString() );
185 void checkAllBulkActionItems( bool select
);
188 void numSelectedAccountsChanged();
189 void isLoadingSelectedChanged();
193 * This signal is emitted whenever the collection has been changed but
194 * before the item list is updated.
196 void collectionSelectionChanged();
200 * Creates a new main view for a mobile application.
202 * @param appName is used to find the QML file in ${DATA_DIR}/mobile/appname.qml
203 * @param listProxy proxy for the list view of the application. KDeclarativeMainView
204 * takes ownwership over the pointer.
205 * @param parent The parent widget.
207 KDeclarativeMainView( const QString
&appName
, ListProxy
*listProxy
, QWidget
*parent
= 0 );
210 * Returns the global entity tree model.
212 Akonadi::EntityTreeModel
* entityTreeModel() const;
215 * Returns the filtered and QML-adapted item model.
217 QAbstractItemModel
* itemModel() const;
220 * Returns whether the currently selected item is being loaded.
221 * Note that results appear asynchronously in chunks while loading the contents
222 * of a collection. That means that the number of items can be greater then zero
223 * while isLoadingSelected returns true.
225 bool isLoadingSelected();
228 * Initializes the standard action manager that will be used by the application.
229 * This is a point of extension to use a custom action manager.
231 * @param collectionSelectionModel The selection model for the collections.
232 * @param itemSelectionModel The selection model for the items.
234 virtual void setupStandardActionManager( QItemSelectionModel
*collectionSelectionModel
,
235 QItemSelectionModel
*itemSelectionModel
);
238 * Initializes the agent action manager that will be used by the application.
239 * This is a point of extension to use a custom action manager.
241 * @param selectionModel The selection model for the agent instances.
243 virtual void setupAgentActionManager( QItemSelectionModel
*selectionModel
) = 0;
246 * Returns the a proxy model that will be used on top of the entity tree model.
248 virtual QAbstractProxyModel
* createMainProxyModel() const;
251 * Returns the filter proxy model that will be used to filter the item list.
252 * If @c 0 is returned, no filtering is done.
254 * @note The model has to provide a public slot with the following signature:
255 * void setFilterString( const QString& )
257 virtual QAbstractProxyModel
* createItemFilterModel() const;
260 * Set the filter proxy model that will be used to filter the item list.
261 * Call this when calling createItemFilterModel() manually in your code.
263 void setItemFilterModel( QAbstractProxyModel
* model
);
266 * Returns the object that will be used for importing data.
267 * If @c 0 is returned, no import functionality is offered.
269 virtual ImportHandlerBase
* importHandler() const;
272 * Returns the object that will be used for exporting data.
273 * If @c 0 is returned, no export functionality is offered.
275 virtual ExportHandlerBase
* exportHandler() const;
278 * Returns the gui state manager that will be used by the application.
280 * Subclasses should returns its custom gui state managers here.
282 virtual GuiStateManager
* createGuiStateManager() const;
285 * This method is called when a single @p item has been selected to view.
287 virtual void viewSingleItem( const Akonadi::Item
&item
);
290 * Returns whether the application is in a state where the filter line edit
293 virtual bool useFilterLineEditInCurrentState() const;
296 * Returns whether the application is in a state where the filter line edit
299 virtual bool doNotUseFilterLineEditInCurrentState() const;
302 void breadcrumbsSelectionChanged();
303 void itemSelectionChanged();
307 * The selection model that belongs to the item model returned by entityTreeModel()
308 * or to the one returned by createMainProxyModel().
310 QItemSelectionModel
* regularSelectionModel() const;
313 * The selection model which provides the information about checked
314 * items in the bulk action screen.
316 QItemSelectionModel
* itemActionModel() const;
318 QAbstractProxyModel
* itemFilterModel() const;
319 QAbstractProxyModel
* listProxy() const;
320 QItemSelectionModel
* itemSelectionModel() const;
321 QAbstractItemModel
* selectedItemsModel() const;
323 Akonadi::Item
itemFromId( quint64 id
) const;
325 virtual void keyPressEvent( QKeyEvent
*event
);
327 virtual QAbstractItemModel
* createItemModelContext( QDeclarativeContext
*context
, QAbstractItemModel
*model
);
328 void setItemNaigationAndActionSelectionModels( QItemSelectionModel
*itemNavigationSelectionModel
, QItemSelectionModel
*itemActionSelectionModel
);
331 * Returns a newly created AgentActionMananger with standard setup.
332 * Use inside setupAgentActionManager();
334 Akonadi::AgentActionManager
*createAgentActionManager( QItemSelectionModel
* agentSelectionModel
);
337 void doDelayedInitInternal();
338 KDeclarativeMainViewPrivate
* const d
;
340 Q_PRIVATE_SLOT( d
, void filterLineEditChanged( const QString
& ) )
341 Q_PRIVATE_SLOT( d
, void bulkActionFilterLineEditChanged( const QString
& ) )
344 #endif // KDECLARATIVEMAINVIEW_H