diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2017-07-13 12:16:43 +0200 |
---|---|---|
committer | Holger Freyther <holger+qt@freyther.de> | 2017-09-12 06:14:39 +0000 |
commit | df9402f361b521877fdc2b1ec23a1e205699224c (patch) | |
tree | 92d9fb35db9aba34f668ccae2a9eaf3d6ec8e8de /wayland/democompositor/apps/applistmodel.h | |
parent | c09aa96a136dd841e75b459d78ea27ad2bc4474c (diff) |
democompositor: Introduce an AppListModel to expose apps
Turn the AppEntry into a gadget and store the filename of where the
entry came from. Update the existing test to deal with it.
Introduce AppListModel as a QAbstractItemModel and expose the raw
AppEntry and its fields as role. Have some slow O(n) code to check
if an entry has already been added. The goal is to use a directory
watcher to automatically update this list.
Store the AppEntry as a pointer so we don't have to remove the
const from the field.
The next steps are to fully populate the AppListModel by scanning
and watching a directory and then replacing the LaunchButton code
with a Repeater on the application model. After starting of apps
will be done by passing the AppEntry to a launcher. Application
state should be stored outside the AppEntry and maybe in a different
model as well.
Change-Id: Ia933a09942ea8bb88eae5c101d13a30564d8c639
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'wayland/democompositor/apps/applistmodel.h')
-rw-r--r-- | wayland/democompositor/apps/applistmodel.h | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/wayland/democompositor/apps/applistmodel.h b/wayland/democompositor/apps/applistmodel.h new file mode 100644 index 0000000..f8fc3e0 --- /dev/null +++ b/wayland/democompositor/apps/applistmodel.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of Qt for Device Creation. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#pragma once + +#include <QtCore/QAbstractListModel> +#include <QtCore/QVector> + +class AppEntry; + +/** + * A model that holds all available applications and + * exports them to a QML scene + */ +class AppListModel : public QAbstractListModel { + Q_OBJECT +public: + + ~AppListModel(); + + enum Roles { + App = Qt::UserRole, + IconName, + ApplicationName, + ExeuctableName, + ExecutablePath, + SourceFileName, + }; + + int rowCount(const QModelIndex& parent) const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex& index, int role) const Q_DECL_OVERRIDE; + QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; + + void addFile(const QString& fileName); + +private: + void doAddFile(const QString& fileName); + + QVector<AppEntry*> m_rows; + static QHash<int, QByteArray> m_roles; +}; |