diff --git a/recentusagemodel.cpp b/recentusagemodel.cpp index 24874ff0a..6e908d79a 100644 --- a/recentusagemodel.cpp +++ b/recentusagemodel.cpp @@ -1,429 +1,446 @@ /*************************************************************************** * Copyright (C) 2014-2015 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "recentusagemodel.h" #include "actionlist.h" #include "appsmodel.h" #include "appentry.h" #include "favoritesmodel.h" #include #include #if HAVE_X11 #include #endif #include #include #include #include #include #include #include #include #include namespace KAStats = KActivities::Stats; using namespace KAStats; using namespace KAStats::Terms; GroupSortProxy::GroupSortProxy(QAbstractItemModel *sourceModel) : QSortFilterProxyModel(nullptr) { sourceModel->setParent(this); setSourceModel(sourceModel); sort(0); } GroupSortProxy::~GroupSortProxy() { } InvalidAppsFilterProxy::InvalidAppsFilterProxy(AbstractModel *parentModel, QAbstractItemModel *sourceModel) : QSortFilterProxyModel(nullptr) , m_parentModel(parentModel) { connect(parentModel, &AbstractModel::favoritesModelChanged, this, &InvalidAppsFilterProxy::connectNewFavoritesModel); connectNewFavoritesModel(); sourceModel->setParent(this); setSourceModel(sourceModel); } InvalidAppsFilterProxy::~InvalidAppsFilterProxy() { } void InvalidAppsFilterProxy::connectNewFavoritesModel() { FavoritesModel* favoritesModel = static_cast(m_parentModel->favoritesModel()); connect(favoritesModel, &FavoritesModel::favoritesChanged, this, &QSortFilterProxyModel::invalidate); invalidate(); } bool InvalidAppsFilterProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { Q_UNUSED(source_parent); const QString resource = sourceModel()->index(source_row, 0).data(ResultModel::ResourceRole).toString(); if (resource.startsWith(QLatin1String("applications:"))) { KService::Ptr service = KService::serviceByStorageId(resource.section(':', 1)); FavoritesModel* favoritesModel = m_parentModel ? static_cast(m_parentModel->favoritesModel()) : nullptr; return (service && (!favoritesModel || !favoritesModel->isFavorite(service->storageId()))); } return true; } bool GroupSortProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const { const QString &lResource = sourceModel()->data(left, ResultModel::ResourceRole).toString(); const QString &rResource = sourceModel()->data(right, ResultModel::ResourceRole).toString(); if (lResource.startsWith(QLatin1String("applications:")) && !rResource.startsWith(QLatin1String("applications:"))) { return true; } else if (!lResource.startsWith(QLatin1String("applications:")) && rResource.startsWith(QLatin1String("applications:"))) { return false; } return (left.row() < right.row()); } -RecentUsageModel::RecentUsageModel(QObject *parent, IncludeUsage usage) : ForwardingModel(parent) +RecentUsageModel::RecentUsageModel(QObject *parent, IncludeUsage usage, int ordering) +: ForwardingModel(parent) , m_usage(usage) +, m_ordering((Ordering)ordering) { refresh(); } RecentUsageModel::~RecentUsageModel() { } RecentUsageModel::IncludeUsage RecentUsageModel::usage() const { return m_usage; } QString RecentUsageModel::description() const { switch (m_usage) { case AppsAndDocs: return i18n("Recently Used"); case OnlyApps: return i18n("Applications"); case OnlyDocs: default: return i18n("Documents"); } } QString RecentUsageModel::resourceAt(int row) const { QSortFilterProxyModel *sourceProxy = qobject_cast(sourceModel()); if (sourceProxy) { return sourceProxy->sourceModel()->data(sourceProxy->mapToSource(sourceProxy->index(row, 0)), ResultModel::ResourceRole).toString(); } return sourceModel()->data(index(row, 0), ResultModel::ResourceRole).toString(); } QVariant RecentUsageModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } const QString &resource = resourceAt(index.row()); if (resource.startsWith(QLatin1String("applications:"))) { return appData(resource, role); } else { return docData(resource, role); } } QVariant RecentUsageModel::appData(const QString &resource, int role) const { const QString storageId = resource.section(':', 1); KService::Ptr service = KService::serviceByStorageId(storageId); QStringList allowedTypes({ QLatin1String("Service"), QLatin1String("Application") }); if (!service || !allowedTypes.contains(service->property(QLatin1String("Type")).toString()) || service->exec().isEmpty()) { return QVariant(); } if (role == Qt::DisplayRole) { AppsModel *parentModel = qobject_cast(QObject::parent()); if (parentModel) { return AppEntry::nameFromService(service, (AppEntry::NameFormat)qobject_cast(QObject::parent())->appNameFormat()); } else { return AppEntry::nameFromService(service, AppEntry::NameOnly); } } else if (role == Qt::DecorationRole) { return QIcon::fromTheme(service->icon(), QIcon::fromTheme("unknown")); } else if (role == Kicker::DescriptionRole) { return service->comment(); } else if (role == Kicker::GroupRole) { return i18n("Applications"); } else if (role == Kicker::FavoriteIdRole) { return service->storageId(); } else if (role == Kicker::HasActionListRole) { return true; } else if (role == Kicker::ActionListRole) { QVariantList actionList; const QVariantList &jumpList = Kicker::jumpListActions(service); if (jumpList.count()) { actionList << jumpList << Kicker::createSeparatorActionItem(); } const QVariantList &recentDocuments = Kicker::recentDocumentActions(service); if (recentDocuments.count()) { actionList << recentDocuments << Kicker::createSeparatorActionItem(); } const QVariantMap &forgetAction = Kicker::createActionItem(i18n("Forget Application"), "forget"); actionList << forgetAction; const QVariantMap &forgetAllAction = Kicker::createActionItem(forgetAllActionName(), "forgetAll"); actionList << forgetAllAction; return actionList; } return QVariant(); } QVariant RecentUsageModel::docData(const QString &resource, int role) const { QUrl url(resource); if (url.scheme().isEmpty()) { url.setScheme(QStringLiteral("file")); } const KFileItem fileItem(url); if (!url.isValid() || !(fileItem.isFile() || fileItem.isDir())) { return QVariant(); } if (role == Qt::DisplayRole) { return fileItem.text(); } else if (role == Qt::DecorationRole) { return QIcon::fromTheme(fileItem.iconName(), QIcon::fromTheme("unknown")); } else if (role == Kicker::GroupRole) { return i18n("Documents"); } else if (role == Kicker::FavoriteIdRole || role == Kicker::UrlRole) { return url.toString(); } else if (role == Kicker::UrlRole) { return url; } else if (role == Kicker::HasActionListRole) { return true; } else if (role == Kicker::ActionListRole) { QVariantList actionList = Kicker::createActionListForFileItem(fileItem); actionList << Kicker::createSeparatorActionItem(); const QVariantMap &forgetAction = Kicker::createActionItem(i18n("Forget Document"), "forget"); actionList << forgetAction; const QVariantMap &forgetAllAction = Kicker::createActionItem(forgetAllActionName(), "forgetAll"); actionList << forgetAllAction; return actionList; } return QVariant(); } bool RecentUsageModel::trigger(int row, const QString &actionId, const QVariant &argument) { Q_UNUSED(argument) bool withinBounds = row >= 0 && row < rowCount(); if (actionId.isEmpty() && withinBounds) { const QString &resource = resourceAt(row); if (!resource.startsWith(QLatin1String("applications:"))) { new KRun(docData(resource, Kicker::UrlRole).toUrl(), 0); return true; } const QString storageId = resource.section(':', 1); KService::Ptr service = KService::serviceByStorageId(storageId); if (!service) { return false; } quint32 timeStamp = 0; #if HAVE_X11 if (QX11Info::isPlatformX11()) { timeStamp = QX11Info::appUserTime(); } #endif // TODO Once we depend on KDE Frameworks 5.24 and D1902 is merged, use KRun::runApplication instead KRun::runService(*service, {}, nullptr, true, {}, KStartupInfo::createNewStartupIdForTimestamp(timeStamp)); KActivities::ResourceInstance::notifyAccessed(QUrl("applications:" + storageId), "org.kde.plasma.kicker"); return true; } else if (actionId == "forget" && withinBounds) { if (m_activitiesModel) { QModelIndex idx = sourceModel()->index(row, 0); QSortFilterProxyModel *sourceProxy = qobject_cast(sourceModel()); while (sourceProxy) { idx = sourceProxy->mapToSource(idx); sourceProxy = qobject_cast(sourceProxy->sourceModel()); } static_cast(m_activitiesModel.data())->forgetResource(idx.row()); } return false; } else if (actionId == "forgetAll") { if (m_activitiesModel) { static_cast(m_activitiesModel.data())->forgetAllResources(); } return false; } else if (withinBounds) { const QString &resource = resourceAt(row); if (resource.startsWith(QLatin1String("applications:"))) { const QString storageId = sourceModel()->data(sourceModel()->index(row, 0), ResultModel::ResourceRole).toString().section(':', 1); KService::Ptr service = KService::serviceByStorageId(storageId); if (service) { return Kicker::handleRecentDocumentAction(service, actionId, argument); } } else { bool close = false; QUrl url(sourceModel()->data(sourceModel()->index(row, 0), ResultModel::ResourceRole).toString()); KFileItem item(url); if (Kicker::handleFileItemAction(item, actionId, argument, &close)) { return close; } } } return false; } bool RecentUsageModel::hasActions() const { return rowCount(); } QVariantList RecentUsageModel::actions() const { QVariantList actionList; if (rowCount()) { actionList << Kicker::createActionItem(forgetAllActionName(), "forgetAll"); } return actionList; } QString RecentUsageModel::forgetAllActionName() const { switch (m_usage) { case AppsAndDocs: return i18n("Forget All"); case OnlyApps: return i18n("Forget All Applications"); case OnlyDocs: default: return i18n("Forget All Documents"); } } +void RecentUsageModel::setOrdering(int ordering) +{ + if (ordering == m_ordering) return; + + m_ordering = (Ordering)ordering; + refresh(); + + emit orderingChanged(ordering); +} + +int RecentUsageModel::ordering() const +{ + return m_ordering; +} + void RecentUsageModel::refresh() { QAbstractItemModel *oldModel = sourceModel(); auto query = UsedResources - | RecentlyUsedFirst + | (m_ordering == Recent ? RecentlyUsedFirst : HighScoredFirst) | Agent::any() | Type::any() | Activity::current(); switch (m_usage) { case AppsAndDocs: { query = query | Url::startsWith("applications:") | Url::file() | Limit(30); break; } case OnlyApps: { query = query | Url::startsWith("applications:") | Limit(15); break; } case OnlyDocs: default: { query = query | Url::file() | Limit(15); } } m_activitiesModel = new ResultModel(query); QAbstractItemModel *model = m_activitiesModel; QModelIndex index; if (model->canFetchMore(index)) { model->fetchMore(index); } if (m_usage != OnlyDocs) { model = new InvalidAppsFilterProxy(this, model); } if (m_usage == AppsAndDocs) { model = new GroupSortProxy(model); } setSourceModel(model); delete oldModel; } diff --git a/recentusagemodel.h b/recentusagemodel.h index 61760f798..1ac3dad50 100644 --- a/recentusagemodel.h +++ b/recentusagemodel.h @@ -1,91 +1,105 @@ /*************************************************************************** * Copyright (C) 2014-2015 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef RECENTUSAGEMODEL_H #define RECENTUSAGEMODEL_H #include "forwardingmodel.h" #include class GroupSortProxy : public QSortFilterProxyModel { public: explicit GroupSortProxy(QAbstractItemModel *sourceModel); ~GroupSortProxy(); protected: bool lessThan(const QModelIndex &left, const QModelIndex &right) const; }; class InvalidAppsFilterProxy : public QSortFilterProxyModel { Q_OBJECT public: explicit InvalidAppsFilterProxy(AbstractModel *parentModel, QAbstractItemModel *sourceModel); ~InvalidAppsFilterProxy(); protected: bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const; private Q_SLOTS: void connectNewFavoritesModel(); private: QPointer m_parentModel; }; class RecentUsageModel : public ForwardingModel { Q_OBJECT + Q_PROPERTY(int ordering READ ordering WRITE setOrdering NOTIFY orderingChanged) + public: enum IncludeUsage { AppsAndDocs, OnlyApps, OnlyDocs }; + enum Ordering { Recent, Popular }; - explicit RecentUsageModel(QObject *parent = 0, IncludeUsage usage = AppsAndDocs); + explicit RecentUsageModel( + QObject *parent = 0, + IncludeUsage usage = AppsAndDocs, + int ordering = Recent); ~RecentUsageModel(); QString description() const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; Q_INVOKABLE bool trigger(int row, const QString &actionId, const QVariant &argument); bool hasActions() const; QVariantList actions() const; IncludeUsage usage() const; + void setOrdering(int ordering); + int ordering() const; + + Q_SIGNALS: + void orderingChanged(int ordering); + private Q_SLOTS: void refresh(); private: QVariant appData(const QString &resource, int role) const; QVariant docData(const QString &resource, int role) const; QString resourceAt(int row) const; QString forgetAllActionName() const; IncludeUsage m_usage; QPointer m_activitiesModel; + + Ordering m_ordering; }; #endif diff --git a/rootmodel.cpp b/rootmodel.cpp index a36fa2be0..2260c681f 100644 --- a/rootmodel.cpp +++ b/rootmodel.cpp @@ -1,426 +1,453 @@ /*************************************************************************** * Copyright (C) 2014-2015 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "rootmodel.h" #include "actionlist.h" #include "favoritesmodel.h" #include "recentcontactsmodel.h" #include "recentusagemodel.h" #include "systemmodel.h" #include #include GroupEntry::GroupEntry(AppsModel *parentModel, const QString &name, const QString &iconName, AbstractModel *childModel) : AbstractGroupEntry(parentModel) , m_name(name) , m_iconName(iconName) , m_childModel(childModel) { QObject::connect(parentModel, &RootModel::cleared, childModel, &AbstractModel::deleteLater); QObject::connect(childModel, &AbstractModel::countChanged, [parentModel, this] { if (parentModel) { parentModel->entryChanged(this); } } ); } QString GroupEntry::name() const { return m_name; } QIcon GroupEntry::icon() const { return QIcon::fromTheme(m_iconName, QIcon::fromTheme("unknown")); } bool GroupEntry::hasChildren() const { return m_childModel && m_childModel->count() > 0; } AbstractModel *GroupEntry::childModel() const { return m_childModel; } RootModel::RootModel(QObject *parent) : AppsModel(QString(), parent) , m_complete(false) , m_favorites(new FavoritesModel(this)) , m_systemModel(nullptr) , m_autoPopulate(true) , m_showAllApps(false) , m_showRecentApps(true) , m_showRecentDocs(true) , m_showRecentContacts(false) +, m_recentOrdering(RecentUsageModel::Recent) , m_showPowerSession(true) , m_recentAppsModel(0) , m_recentDocsModel(0) , m_recentContactsModel(0) { } RootModel::~RootModel() { } QVariant RootModel::data(const QModelIndex& index, int role) const { if (!index.isValid() || index.row() >= m_entryList.count()) { return QVariant(); } if (role == Kicker::HasActionListRole || role == Kicker::ActionListRole) { const AbstractEntry *entry = m_entryList.at(index.row()); if (entry->type() == AbstractEntry::GroupType) { const GroupEntry *group = static_cast(entry); AbstractModel *model = group->childModel(); if (model == m_recentAppsModel || model == m_recentDocsModel || model == m_recentContactsModel) { if (role == Kicker::HasActionListRole) { return true; } else if (role == Kicker::ActionListRole) { QVariantList actionList; actionList << model->actions(); actionList << Kicker::createSeparatorActionItem(); actionList << Kicker::createActionItem(i18n("Hide %1", group->name()), "hideCategory"); return actionList; } } } } return AppsModel::data(index, role); } bool RootModel::trigger(int row, const QString& actionId, const QVariant& argument) { const AbstractEntry *entry = m_entryList.at(row); if (entry->type() == AbstractEntry::GroupType) { if (actionId == "hideCategory") { AbstractModel *model = entry->childModel(); if (model == m_recentAppsModel) { setShowRecentApps(false); return true; } else if (model == m_recentDocsModel) { setShowRecentDocs(false); return true; } else if (model == m_recentContactsModel) { setShowRecentContacts(false); return true; } } else if (entry->childModel()->hasActions()) { return entry->childModel()->trigger(-1, actionId, QVariant()); } } return AppsModel::trigger(row, actionId, argument); } bool RootModel::autoPopulate() const { return m_autoPopulate; } void RootModel::setAutoPopulate(bool populate) { if (m_autoPopulate != populate) { m_autoPopulate = populate; emit autoPopulateChanged(); } } bool RootModel::showAllApps() const { return m_showAllApps; } void RootModel::setShowAllApps(bool show) { if (m_showAllApps != show) { m_showAllApps = show; refresh(); emit showAllAppsChanged(); } } bool RootModel::showRecentApps() const { return m_showRecentApps; } void RootModel::setShowRecentApps(bool show) { if (show != m_showRecentApps) { m_showRecentApps = show; refresh(); emit showRecentAppsChanged(); } } bool RootModel::showRecentDocs() const { return m_showRecentDocs; } void RootModel::setShowRecentDocs(bool show) { if (show != m_showRecentDocs) { m_showRecentDocs = show; refresh(); emit showRecentDocsChanged(); } } bool RootModel::showRecentContacts() const { return m_showRecentContacts; } void RootModel::setShowRecentContacts(bool show) { if (show != m_showRecentContacts) { m_showRecentContacts = show; refresh(); emit showRecentContactsChanged(); } } +int RootModel::recentOrdering() const +{ + return m_recentOrdering; +} + +void RootModel::setRecentOrdering(int ordering) +{ + if (ordering != m_recentOrdering) { + m_recentOrdering = ordering; + + refresh(); + + emit recentOrderingChanged(); + } +} + bool RootModel::showPowerSession() const { return m_showPowerSession; } void RootModel::setShowPowerSession(bool show) { if (show != m_showPowerSession) { m_showPowerSession = show; refresh(); emit showPowerSessionChanged(); } } AbstractModel* RootModel::favoritesModel() { return m_favorites; } AbstractModel* RootModel::systemFavoritesModel() { if (m_systemModel) { return m_systemModel->favoritesModel(); } return nullptr; } void RootModel::classBegin() { } void RootModel::componentComplete() { m_complete = true; if (m_autoPopulate) { refresh(); } } void RootModel::refresh() { if (!m_complete) { return; } beginResetModel(); AppsModel::refreshInternal(); AppsModel *allModel = nullptr; m_recentAppsModel = nullptr; m_recentDocsModel = nullptr; m_recentContactsModel = nullptr; if (m_showAllApps) { QList groups; if (m_paginate) { m_favorites = new FavoritesModel(this); emit favoritesModelChanged(); QHash appsHash; QList apps; foreach (const AbstractEntry *groupEntry, m_entryList) { AbstractModel *model = groupEntry->childModel(); for (int i = 0; i < model->count(); ++i) { GroupEntry *subGroupEntry = static_cast(model->index(i, 0).internalPointer()); AbstractModel *subModel = subGroupEntry->childModel(); for (int j = 0; j < subModel->count(); ++j) { AppEntry *appEntry = static_cast(subModel->index(j, 0).internalPointer()); if (appEntry->name().isEmpty()) { continue; } appsHash.insert(appEntry->service()->menuId(), appEntry); } } } apps = appsHash.values(); QCollator c; std::sort(apps.begin(), apps.end(), [&c](AbstractEntry* a, AbstractEntry* b) { if (a->type() != b->type()) { return a->type() > b->type(); } else { return c.compare(a->name(), b->name()) < 0; } }); int at = 0; QList page; page.reserve(m_pageSize); foreach(AppEntry *app, apps) { page.append(app); if (at == (m_pageSize - 1)) { at = 0; AppsModel *model = new AppsModel(page, false, this); groups.append(new GroupEntry(this, QString(), QString(), model)); page.clear(); } else { ++at; } } if (!page.isEmpty()) { AppsModel *model = new AppsModel(page, false, this); groups.append(new GroupEntry(this, QString(), QString(), model)); } groups.prepend(new GroupEntry(this, QString(), QString(), m_favorites)); } else { QHash> m_categoryHash; foreach (const AbstractEntry *groupEntry, m_entryList) { AbstractModel *model = groupEntry->childModel(); for (int i = 0; i < model->count(); ++i) { AbstractEntry *appEntry = static_cast(model->index(i, 0).internalPointer()); if (appEntry->name().isEmpty()) { continue; } const QChar &first = appEntry->name().at(0).toUpper(); m_categoryHash[first.isDigit() ? QStringLiteral("0-9") : first].append(appEntry); } } QHashIterator> i(m_categoryHash); while (i.hasNext()) { i.next(); AppsModel *model = new AppsModel(i.value(), false, this); model->setDescription(i.key()); groups.append(new GroupEntry(this, i.key(), QString(), model)); } } allModel = new AppsModel(groups, true, this); allModel->setDescription(QStringLiteral("KICKER_ALL_MODEL")); // Intentionally no i18n. } int separatorPosition = 0; if (allModel) { m_entryList.prepend(new GroupEntry(this, i18n("All Applications"), QString(), allModel)); ++separatorPosition; } if (m_showRecentContacts) { m_recentContactsModel = new RecentContactsModel(this); m_entryList.prepend(new GroupEntry(this, i18n("Recent Contacts"), QString(), m_recentContactsModel)); ++separatorPosition; } if (m_showRecentDocs) { - m_recentDocsModel = new RecentUsageModel(this, RecentUsageModel::OnlyDocs); - m_entryList.prepend(new GroupEntry(this, i18n("Recent Documents"), QString(), m_recentDocsModel)); + m_recentDocsModel = new RecentUsageModel(this, RecentUsageModel::OnlyDocs, m_recentOrdering); + m_entryList.prepend(new GroupEntry(this, + m_recentOrdering == RecentUsageModel::Recent + ? i18n("Recent Documents") + : i18n("Often Used Documents"), + QString(), + m_recentDocsModel)); ++separatorPosition; } if (m_showRecentApps) { - m_recentAppsModel = new RecentUsageModel(this, RecentUsageModel::OnlyApps); - m_entryList.prepend(new GroupEntry(this, i18n("Recent Applications"), QString(), m_recentAppsModel)); + m_recentAppsModel = new RecentUsageModel(this, RecentUsageModel::OnlyApps, m_recentOrdering); + m_entryList.prepend(new GroupEntry(this, + m_recentOrdering == RecentUsageModel::Recent + ? i18n("Recent Applications") + : i18n("Often Used Applications"), + QString(), + m_recentAppsModel)); ++separatorPosition; } if (m_showSeparators && separatorPosition > 0) { m_entryList.insert(separatorPosition, new SeparatorEntry(this)); ++m_separatorCount; } m_systemModel = new SystemModel(this); if (m_showPowerSession) { m_entryList << new GroupEntry(this, i18n("Power / Session"), QString(), m_systemModel); } endResetModel(); m_favorites->refresh(); emit systemFavoritesModelChanged(); emit countChanged(); emit separatorCountChanged(); emit refreshed(); } diff --git a/rootmodel.h b/rootmodel.h index 0cedafa82..2e0f2ef04 100644 --- a/rootmodel.h +++ b/rootmodel.h @@ -1,131 +1,137 @@ /*************************************************************************** * Copyright (C) 2014-2015 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef ROOTMODEL_H #define ROOTMODEL_H #include "appsmodel.h" #include class FavoritesModel; class RecentContactsModel; class RecentUsageModel; class SystemModel; class RootModel; class GroupEntry : public AbstractGroupEntry { public: GroupEntry(AppsModel *parentModel, const QString &name, const QString &iconName, AbstractModel *childModel); QIcon icon() const; QString name() const; bool hasChildren() const; AbstractModel *childModel() const; private: QString m_name; QString m_iconName; QPointer m_childModel; }; class RootModel : public AppsModel, public QQmlParserStatus { Q_OBJECT Q_INTERFACES(QQmlParserStatus) Q_PROPERTY(bool autoPopulate READ autoPopulate WRITE setAutoPopulate NOTIFY autoPopulateChanged) Q_PROPERTY(QObject* systemFavoritesModel READ systemFavoritesModel NOTIFY systemFavoritesModelChanged) Q_PROPERTY(bool showAllApps READ showAllApps WRITE setShowAllApps NOTIFY showAllAppsChanged) Q_PROPERTY(bool showRecentApps READ showRecentApps WRITE setShowRecentApps NOTIFY showRecentAppsChanged) Q_PROPERTY(bool showRecentDocs READ showRecentDocs WRITE setShowRecentDocs NOTIFY showRecentDocsChanged) Q_PROPERTY(bool showRecentContacts READ showRecentContacts WRITE setShowRecentContacts NOTIFY showRecentContactsChanged) + Q_PROPERTY(int recentOrdering READ recentOrdering WRITE setRecentOrdering NOTIFY recentOrderingChanged) Q_PROPERTY(bool showPowerSession READ showPowerSession WRITE setShowPowerSession NOTIFY showPowerSessionChanged) public: explicit RootModel(QObject *parent = 0); ~RootModel(); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; Q_INVOKABLE virtual bool trigger(int row, const QString &actionId, const QVariant &argument); bool autoPopulate() const; void setAutoPopulate(bool populate); bool showAllApps() const; void setShowAllApps(bool show); bool showRecentApps() const; void setShowRecentApps(bool show); bool showRecentDocs() const; void setShowRecentDocs(bool show); bool showRecentContacts() const; void setShowRecentContacts(bool show); + int recentOrdering() const; + void setRecentOrdering(int ordering); + bool showPowerSession() const; void setShowPowerSession(bool show); AbstractModel* favoritesModel(); AbstractModel* systemFavoritesModel(); void classBegin() override; void componentComplete() override; Q_SIGNALS: void refreshed() const; void systemFavoritesModelChanged() const; void autoPopulateChanged() const; void showAllAppsChanged() const; void showRecentAppsChanged() const; void showRecentDocsChanged() const; void showRecentContactsChanged() const; void showPowerSessionChanged() const; + void recentOrderingChanged() const; void recentAppsModelChanged() const; protected Q_SLOTS: void refresh(); private: bool m_complete; FavoritesModel *m_favorites; SystemModel *m_systemModel; bool m_autoPopulate; bool m_showAllApps; bool m_showRecentApps; bool m_showRecentDocs; bool m_showRecentContacts; + int m_recentOrdering; bool m_showPowerSession; RecentUsageModel *m_recentAppsModel; RecentUsageModel *m_recentDocsModel; RecentContactsModel *m_recentContactsModel; }; #endif