diff --git a/computermodel.h b/computermodel.h index 241b140ba..aeb918e9a 100644 --- a/computermodel.h +++ b/computermodel.h @@ -1,117 +1,119 @@ /*************************************************************************** * Copyright (C) 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 COMPUTERMODEL_H #define COMPUTERMODEL_H #include "forwardingmodel.h" #include "appentry.h" #include #include class FavoritesModel; class KConcatenateRowsProxyModel; class KFilePlacesModel; namespace Solid { class Device; } class FilteredPlacesModel : public QSortFilterProxyModel { Q_OBJECT public: FilteredPlacesModel(QObject *parent = 0); ~FilteredPlacesModel(); QUrl url(const QModelIndex &index) const; bool isDevice(const QModelIndex &index) const; Solid::Device deviceForIndex(const QModelIndex &index) const; protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE; bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE; private: KFilePlacesModel *m_placesModel; }; class RunCommandModel : public AbstractModel { + Q_OBJECT + public: RunCommandModel(QObject *parent = 0); ~RunCommandModel(); QString description() const Q_DECL_OVERRIDE; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; Q_INVOKABLE bool trigger(int row, const QString &actionId, const QVariant &argument) Q_DECL_OVERRIDE; }; class ComputerModel : public ForwardingModel { Q_OBJECT Q_PROPERTY(int appNameFormat READ appNameFormat WRITE setAppNameFormat NOTIFY appNameFormatChanged) Q_PROPERTY(QObject* appletInterface READ appletInterface WRITE setAppletInterface NOTIFY appletInterfaceChanged) Q_PROPERTY(QStringList systemApplications READ systemApplications WRITE setSystemApplications NOTIFY systemApplicationsChanged) public: explicit ComputerModel(QObject *parent = 0); ~ComputerModel(); QString description() const Q_DECL_OVERRIDE; int appNameFormat() const; void setAppNameFormat(int format); QObject *appletInterface() const; void setAppletInterface(QObject *appletInterface); QStringList systemApplications() const; void setSystemApplications(const QStringList &apps); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; Q_INVOKABLE bool trigger(int row, const QString &actionId, const QVariant &argument) Q_DECL_OVERRIDE; Q_SIGNALS: void appNameFormatChanged() const; void appletInterfaceChanged() const; void systemApplicationsChanged() const; private Q_SLOTS: void onSetupDone(Solid::ErrorType error, QVariant errorData, const QString &udi); private: KConcatenateRowsProxyModel *m_concatProxy; RunCommandModel *m_runCommandModel; FavoritesModel *m_systemAppsModel; FilteredPlacesModel *m_filteredPlacesModel; AppEntry::NameFormat m_appNameFormat; QObject *m_appletInterface; }; #endif diff --git a/containmentinterface.h b/containmentinterface.h index c75e4dac6..2700ad86f 100644 --- a/containmentinterface.h +++ b/containmentinterface.h @@ -1,59 +1,59 @@ /*************************************************************************** * Copyright (C) 2014 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 CONTAINMENTINTERFACE_H #define CONTAINMENTINTERFACE_H #include #include namespace Plasma { class Applet; class Containment; } class ContainmentInterface : public QObject { Q_OBJECT public: enum Target { Desktop = 0, Panel, TaskManager }; - Q_ENUMS(Target) + Q_ENUM(Target) ContainmentInterface(QObject *parent = 0); ~ContainmentInterface(); static Q_INVOKABLE bool mayAddLauncher(QObject *appletInterface, Target target, const QString &entryPath = QString()); static Q_INVOKABLE void addLauncher(QObject *appletInterface, Target target, const QString &entryPath); static Q_INVOKABLE QObject* screenContainment(QObject *appletInterface); static Q_INVOKABLE bool screenContainmentMutable(QObject *appletInterface); static Q_INVOKABLE void ensureMutable(Plasma::Containment *containment); private: static QStringList m_knownTaskManagers; }; #endif diff --git a/forwardingmodel.cpp b/forwardingmodel.cpp index 91099e6e6..6313ed72c 100644 --- a/forwardingmodel.cpp +++ b/forwardingmodel.cpp @@ -1,264 +1,265 @@ /*************************************************************************** * Copyright (C) 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 "forwardingmodel.h" ForwardingModel::ForwardingModel(QObject *parent) : AbstractModel(parent) { } ForwardingModel::~ForwardingModel() { } QString ForwardingModel::description() const { if (!m_sourceModel) { return QString(); } AbstractModel *abstractModel = qobject_cast(m_sourceModel); if (!abstractModel) { return QString(); } return abstractModel->description(); } QAbstractItemModel *ForwardingModel::sourceModel() const { return m_sourceModel; } void ForwardingModel::setSourceModel(QAbstractItemModel *sourceModel) { disconnectSignals(); beginResetModel(); m_sourceModel = sourceModel; connectSignals(); endResetModel(); emit countChanged(); emit sourceModelChanged(); emit descriptionChanged(); } bool ForwardingModel::canFetchMore(const QModelIndex &parent) const { if (!m_sourceModel) { return false; } return m_sourceModel->canFetchMore(indexToSourceIndex(parent)); } void ForwardingModel::fetchMore(const QModelIndex &parent) { if (m_sourceModel) { m_sourceModel->fetchMore(indexToSourceIndex(parent)); } } QModelIndex ForwardingModel::index(int row, int column, const QModelIndex &parent) const { Q_UNUSED(parent) if (!m_sourceModel) { return QModelIndex(); } return createIndex(row, column); } QModelIndex ForwardingModel::parent(const QModelIndex &index) const { Q_UNUSED(index) return QModelIndex(); } QVariant ForwardingModel::data(const QModelIndex &index, int role) const { if (!m_sourceModel) { return QVariant(); } return m_sourceModel->data(indexToSourceIndex(index), role); } int ForwardingModel::rowCount(const QModelIndex &parent) const { if (!m_sourceModel) { return 0; } return m_sourceModel->rowCount(indexToSourceIndex(parent)); } QModelIndex ForwardingModel::indexToSourceIndex(const QModelIndex& index) const { if (!m_sourceModel || !index.isValid()) { return QModelIndex(); } return m_sourceModel->index(index.row(), index.column(), index.parent().isValid() ? indexToSourceIndex(index.parent()) : QModelIndex()); } bool ForwardingModel::trigger(int row, const QString &actionId, const QVariant &argument) { if (!m_sourceModel) { return false; } AbstractModel *abstractModel = qobject_cast(m_sourceModel); if (!abstractModel) { return false; } return abstractModel->trigger(row, actionId, argument); } QString ForwardingModel::labelForRow(int row) { if (!m_sourceModel) { return QString(); } AbstractModel *abstractModel = qobject_cast(m_sourceModel); if (!abstractModel) { return QString(); } return abstractModel->labelForRow(row); } AbstractModel* ForwardingModel::modelForRow(int row) { if (!m_sourceModel) { return 0; } AbstractModel *abstractModel = qobject_cast(m_sourceModel); if (!abstractModel) { return 0; } return abstractModel->modelForRow(row); } AbstractModel* ForwardingModel::favoritesModel() { AbstractModel *sourceModel = qobject_cast(m_sourceModel); if (sourceModel) { return sourceModel->favoritesModel(); } return AbstractModel::favoritesModel(); } int ForwardingModel::separatorCount() const { if (!m_sourceModel) { return 0; } AbstractModel *abstractModel = qobject_cast(m_sourceModel); if (!abstractModel) { return 0; } return abstractModel->separatorCount(); } void ForwardingModel::reset() { - emit beginResetModel(); - emit endResetModel(); + beginResetModel(); + endResetModel(); + emit countChanged(); emit separatorCountChanged(); } void ForwardingModel::connectSignals() { if (!m_sourceModel) { return; } connect(m_sourceModel, SIGNAL(destroyed()), this, SLOT(reset())); connect(m_sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector)), this, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector)), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), this, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), this, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), this, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(layoutAboutToBeChanged(QList,QAbstractItemModel::LayoutChangeHint)), this, SIGNAL(layoutAboutToBeChanged(QList,QAbstractItemModel::LayoutChangeHint)), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(rowsInserted(QModelIndex,int,int)), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(countChanged()), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(rowsRemoved(QModelIndex,int,int)), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(countChanged()), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(modelAboutToBeReset()), this, SIGNAL(modelAboutToBeReset()), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(modelReset()), this, SIGNAL(modelReset()), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(modelReset()), this, SIGNAL(countChanged()), Qt::UniqueConnection); connect(m_sourceModel, SIGNAL(layoutChanged(QList,QAbstractItemModel::LayoutChangeHint)), this, SIGNAL(layoutChanged(QList,QAbstractItemModel::LayoutChangeHint)), Qt::UniqueConnection); } void ForwardingModel::disconnectSignals() { if (!m_sourceModel) { return; } disconnect(m_sourceModel, 0, this, 0); } diff --git a/funnelmodel.cpp b/funnelmodel.cpp index 467d36dda..476fec985 100644 --- a/funnelmodel.cpp +++ b/funnelmodel.cpp @@ -1,96 +1,96 @@ /*************************************************************************** * Copyright (C) 2014 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 "funnelmodel.h" FunnelModel::FunnelModel(QObject *parent) : ForwardingModel(parent) { } FunnelModel::~FunnelModel() { } void FunnelModel::setSourceModel(QAbstractItemModel *model) { if (model && m_sourceModel == model) { return; } if (!model) { reset(); return; } connect(model, SIGNAL(destroyed(QObject*)), this, SLOT(reset())); if (!m_sourceModel) { - emit beginResetModel(); + beginResetModel(); m_sourceModel = model; connectSignals(); - emit endResetModel(); + endResetModel(); emit countChanged(); emit sourceModelChanged(); emit descriptionChanged(); return; } int oldCount = m_sourceModel->rowCount(); int newCount = model->rowCount(); disconnectSignals(); m_sourceModel = model; connectSignals(); if (newCount > oldCount) { beginInsertRows(QModelIndex(), oldCount, newCount - 1); endInsertRows(); } else if (newCount < oldCount) { if (newCount == 0) { beginResetModel(); endResetModel(); } else { beginRemoveRows(QModelIndex(), newCount, oldCount - 1); endRemoveRows(); } } if (newCount > 0) { emit dataChanged(index(0, 0), index(qMin(oldCount, newCount) - 1, 0)); } if (oldCount != newCount) { emit countChanged(); } emit sourceModelChanged(); emit descriptionChanged(); } diff --git a/recentcontactsmodel.cpp b/recentcontactsmodel.cpp index 9d5a48618..dc030a52a 100644 --- a/recentcontactsmodel.cpp +++ b/recentcontactsmodel.cpp @@ -1,246 +1,246 @@ /*************************************************************************** * Copyright (C) 2012 by Aurélien Gâteau * * 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 "recentcontactsmodel.h" #include "actionlist.h" #include "contactentry.h" #include #include #include #include #include //FIXME TODO: Pretty include in KPeople broken. #include #include namespace KAStats = KActivities::Stats; using namespace KAStats; using namespace KAStats::Terms; RecentContactsModel::RecentContactsModel(QObject *parent) : ForwardingModel(parent) { refresh(); } RecentContactsModel::~RecentContactsModel() { } QString RecentContactsModel::description() const { return i18n("Contacts"); } QVariant RecentContactsModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } QString id = sourceModel()->data(index, ResultModel::ResourceRole).toString(); KPeople::PersonData *data = 0; if (m_idToData.contains(id)) { data = m_idToData[id]; } if (!data) { const_cast(this)->insertPersonData(id, index.row()); return QVariant(); } if (role == Qt::DisplayRole) { return data->name(); } else if (role == Qt::DecorationRole) { return data->presenceIconName(); } else if (role == Kicker::FavoriteIdRole) { return id; } else if (role == Kicker::HasActionListRole) { return true; } else if (role == Kicker::ActionListRole) { QVariantList actionList ; const QVariantMap &forgetAction = Kicker::createActionItem(i18n("Forget Contact"), "forget"); actionList << forgetAction; const QVariantMap &forgetAllAction = Kicker::createActionItem(i18n("Forget All Contacts"), "forgetAll"); actionList << forgetAllAction; actionList << Kicker::createSeparatorActionItem(); actionList << Kicker::createActionItem(i18n("Show Contact Information..."), "showContactInfo"); return actionList; } else if (role == Kicker::DescriptionRole) { return QString(); } return QVariant(); } bool RecentContactsModel::trigger(int row, const QString &actionId, const QVariant &argument) { Q_UNUSED(argument) bool withinBounds = row >= 0 && row < rowCount(); if (actionId.isEmpty() && withinBounds) { QString id = sourceModel()->data(sourceModel()->index(row, 0), ResultModel::ResourceRole).toString(); const QList actionList = KPeople::actionsForPerson(id, this); if (!actionList.isEmpty()) { QAction *chat = 0; foreach (QAction *action, actionList) { const QVariant &actionType = action->property("actionType"); if (!actionType.isNull() && actionType.toInt() == KPeople::ActionType::TextChatAction) { chat = action; } } if (chat) { chat->trigger(); return true; } } return false; } else if (actionId == "showContactInfo" && withinBounds) { ContactEntry::showPersonDetailsDialog(sourceModel()->data(sourceModel()->index(row, 0), ResultModel::ResourceRole).toString()); } else if (actionId == "forget" && withinBounds) { if (sourceModel()) { ResultModel *resultModel = static_cast(sourceModel()); resultModel->forgetResource(row); } return false; } else if (actionId == "forgetAll") { if (sourceModel()) { ResultModel *resultModel = static_cast(sourceModel()); resultModel->forgetAllResources(); } return false; } return false; } bool RecentContactsModel::hasActions() const { return rowCount(); } QVariantList RecentContactsModel::actions() const { QVariantList actionList; if (rowCount()) { actionList << Kicker::createActionItem(i18n("Forget All Contacts"), "forgetAll"); } return actionList; } void RecentContactsModel::refresh() { QObject *oldModel = sourceModel(); auto query = UsedResources | RecentlyUsedFirst | Agent("KTp") | Type::any() | Activity::current() | Url::startsWith("ktp") | Limit(15); ResultModel *model = new ResultModel(query); QModelIndex index; if (model->canFetchMore(index)) { model->fetchMore(index); } // FIXME TODO: Don't wipe entire cache on transactions. connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(buildCache()), Qt::UniqueConnection); connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(buildCache()), Qt::UniqueConnection); connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(buildCache()), Qt::UniqueConnection); connect(model, SIGNAL(modelReset()), this, SLOT(buildCache()), Qt::UniqueConnection); setSourceModel(model); buildCache(); delete oldModel; } void RecentContactsModel::buildCache() { - qDeleteAll(m_idToData.values()); + qDeleteAll(m_idToData); m_idToData.clear(); m_dataToRow.clear(); QString id; for(int i = 0; i < sourceModel()->rowCount(); ++i) { id = sourceModel()->data(sourceModel()->index(i, 0), ResultModel::ResourceRole).toString(); if (!m_idToData.contains(id)) { insertPersonData(id, i); } } } void RecentContactsModel::insertPersonData(const QString& id, int row) { KPeople::PersonData *data = new KPeople::PersonData(id); m_idToData[id] = data; m_dataToRow[data] = row; connect(data, SIGNAL(dataChanged()), this, SLOT(personDataChanged())); } void RecentContactsModel::personDataChanged() { KPeople::PersonData *data = static_cast(sender()); if (m_dataToRow.contains(data)) { int row = m_dataToRow[data]; QModelIndex idx = sourceModel()->index(row, 0); emit dataChanged(idx, idx); } } diff --git a/recentusagemodel.h b/recentusagemodel.h index fdbd1b293..89b721518 100644 --- a/recentusagemodel.h +++ b/recentusagemodel.h @@ -1,112 +1,114 @@ /*************************************************************************** * 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 #include class GroupSortProxy : public QSortFilterProxyModel { + Q_OBJECT + public: explicit GroupSortProxy(QAbstractItemModel *sourceModel); ~GroupSortProxy(); protected: bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE; }; 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 Q_DECL_OVERRIDE; private Q_SLOTS: void connectNewFavoritesModel(); private: QPointer m_parentModel; }; class RecentUsageModel : public ForwardingModel, public QQmlParserStatus { Q_OBJECT Q_INTERFACES(QQmlParserStatus) 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, int ordering = Recent); ~RecentUsageModel(); QString description() const Q_DECL_OVERRIDE; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; Q_INVOKABLE bool trigger(int row, const QString &actionId, const QVariant &argument) Q_DECL_OVERRIDE; bool hasActions() const Q_DECL_OVERRIDE; QVariantList actions() const Q_DECL_OVERRIDE; IncludeUsage usage() const; void setOrdering(int ordering); int ordering() const; void classBegin() override; void componentComplete() override; Q_SIGNALS: void orderingChanged(int ordering); private Q_SLOTS: void refresh() Q_DECL_OVERRIDE; 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; bool m_complete; }; #endif