diff --git a/recentappsmodel.cpp b/recentappsmodel.cpp index d8a21e531..592039736 100644 --- a/recentappsmodel.cpp +++ b/recentappsmodel.cpp @@ -1,170 +1,172 @@ /*************************************************************************** * 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 "recentappsmodel.h" #include "actionlist.h" #include "appsmodel.h" #include #include #if HAVE_X11 #include #endif #include #include #include #include #include #include #include #include namespace KAStats = KActivities::Experimental::Stats; using namespace KAStats; using namespace KAStats::Terms; RecentAppsModel::RecentAppsModel(QObject *parent) : ForwardingModel(parent) { refresh(); } RecentAppsModel::~RecentAppsModel() { } QVariant RecentAppsModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } const QString storageId = sourceModel()->data(index, ResultModel::ResourceRole).toString().section(':', 1); KService::Ptr service = KService::serviceByStorageId(storageId); if (!service || !service->isApplication()) { return QVariant(); } if (role == Qt::DisplayRole) { return AppsModel::nameFromService(service, (AppsModel::NameFormat)qobject_cast(QObject::parent())->appNameFormat()); } else if (role == Qt::DecorationRole) { return QIcon::fromTheme(service->icon(), QIcon::fromTheme("unknown")); } else if (role == Kicker::HasActionListRole) { return true; } else if (role == Kicker::ActionListRole) { QVariantList actionList; actionList << Kicker::recentDocumentActions(service); if (actionList.count()) { actionList << Kicker::createSeparatorActionItem(); } const QVariantMap &forgetAction = Kicker::createActionItem(i18n("Forget Application"), "forget"); actionList << forgetAction; const QVariantMap &forgetAllAction = Kicker::createActionItem(i18n("Forget All Applications"), "forgetAll"); actionList << forgetAllAction; return actionList; } return QVariant(); } bool RecentAppsModel::trigger(int row, const QString &actionId, const QVariant &argument) { Q_UNUSED(argument) if (row < 0 || row >= rowCount()) { return false; } if (actionId.isEmpty()) { const QString storageId = sourceModel()->data(sourceModel()->index(row, 0), ResultModel::ResourceRole).toString().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 new KRun(QUrl::fromLocalFile(service->entryPath()), 0, true, KStartupInfo::createNewStartupIdForTimestamp(timeStamp)); KActivities::ResourceInstance::notifyAccessed(QUrl("applications:" + storageId), "org.kde.plasma.kicker"); return true; } else if (actionId == "forget") { if (sourceModel()) { ResultModel *resultModel = static_cast(sourceModel()); - resultModel->forgetResource(sourceModel()->data(sourceModel()->index(row, 0), - ResultModel::ResourceRole).toString()); + resultModel->forgetResource(row); } return false; } else if (actionId == "forgetAll") { - // IVAN + if (sourceModel()) { + ResultModel *resultModel = static_cast(sourceModel()); + resultModel->forgetAllResources(); + } return true; } else { 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); } } return false; } void RecentAppsModel::refresh() { QObject *oldModel = sourceModel(); auto query = UsedResources | RecentlyUsedFirst | Agent::any() | Type::any() | Activity::current() | Url::startsWith("applications:"); ResultModel *model = new ResultModel(query); model->setItemCountLimit(15); setSourceModel(model); delete oldModel; } diff --git a/recentcontactsmodel.cpp b/recentcontactsmodel.cpp index b04390716..dcd052c30 100644 --- a/recentcontactsmodel.cpp +++ b/recentcontactsmodel.cpp @@ -1,220 +1,222 @@ /*************************************************************************** * 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 #include #include #include #include //FIXME TODO: Pretty include in KPeople broken. #include #include namespace KAStats = KActivities::Experimental::Stats; using namespace KAStats; using namespace KAStats::Terms; RecentContactsModel::RecentContactsModel(QObject *parent) : ForwardingModel(parent) { refresh(); } RecentContactsModel::~RecentContactsModel() { } 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::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; } return QVariant(); } bool RecentContactsModel::trigger(int row, const QString &actionId, const QVariant &argument) { Q_UNUSED(argument) if (row < 0 || row >= rowCount()) { return false; } if (actionId.isEmpty()) { 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") { QString id = sourceModel()->data(sourceModel()->index(row, 0), ResultModel::ResourceRole).toString(); KPeople::PersonDetailsDialog *view = new KPeople::PersonDetailsDialog(0); KPeople::PersonData *data = new KPeople::PersonData(id, view); view->setPerson(data); view->setAttribute(Qt::WA_DeleteOnClose); view->show(); } else if (actionId == "forget") { if (sourceModel()) { ResultModel *resultModel = static_cast(sourceModel()); - resultModel->forgetResource(sourceModel()->data(sourceModel()->index(row, 0), - ResultModel::ResourceRole).toString()); + resultModel->forgetResource(row); } return false; return false; } else if (actionId == "forgetAll") { - // IVAN + if (sourceModel()) { + ResultModel *resultModel = static_cast(sourceModel()); + resultModel->forgetAllResources(); + } return true; } return false; } void RecentContactsModel::refresh() { QObject *oldModel = sourceModel(); auto query = UsedResources | RecentlyUsedFirst | Agent("KTp") | Type::any() | Activity::current() | Url::startsWith("ktp"); ResultModel *model = new ResultModel(query); model->setItemCountLimit(15); model->fetchMore(QModelIndex()); // 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); setSourceModel(model); buildCache(); delete oldModel; } void RecentContactsModel::buildCache() { qDeleteAll(m_idToData.values()); 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/recentdocsmodel.cpp b/recentdocsmodel.cpp index 2e82a6579..cf8814972 100644 --- a/recentdocsmodel.cpp +++ b/recentdocsmodel.cpp @@ -1,138 +1,140 @@ /*************************************************************************** * 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 "recentdocsmodel.h" #include "actionlist.h" #include #include #include #include #include #include #include namespace KAStats = KActivities::Experimental::Stats; using namespace KAStats; using namespace KAStats::Terms; RecentDocsModel::RecentDocsModel(QObject *parent) : ForwardingModel(parent) { refresh(); } RecentDocsModel::~RecentDocsModel() { } QVariant RecentDocsModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } const QUrl url(sourceModel()->data(index, ResultModel::ResourceRole).toString()); const KFileItem fileItem(url); if (!url.isValid() || !fileItem.isFile()) { return QVariant(); } if (role == Qt::DisplayRole) { return url.fileName(); } else if (role == Qt::DecorationRole) { return QIcon::fromTheme(fileItem.iconName(), QIcon::fromTheme("unknown")); } else if (role == Kicker::HasActionListRole) { return true; } else if (role == Kicker::ActionListRole) { QVariantList actionList = Kicker::createActionListForFileItem(fileItem); actionList.prepend(Kicker::createSeparatorActionItem()); const QVariantMap &forgetAction = Kicker::createActionItem(i18n("Forget Document"), "forget"); actionList << forgetAction; const QVariantMap &forgetAllAction = Kicker::createActionItem(i18n("Forget All Documents"), "forgetAll"); actionList << forgetAllAction; return actionList; } return QVariant(); } bool RecentDocsModel::trigger(int row, const QString &actionId, const QVariant &argument) { if (row < 0 || row >= rowCount()) { return false; } QUrl url(sourceModel()->data(sourceModel()->index(row, 0), ResultModel::ResourceRole).toString()); if (actionId.isEmpty()) { new KRun(url, 0); return true; } else if (actionId == "forget") { if (sourceModel()) { ResultModel *resultModel = static_cast(sourceModel()); - resultModel->forgetResource(sourceModel()->data(sourceModel()->index(row, 0), - ResultModel::ResourceRole).toString()); + resultModel->forgetResource(row); } return false; } else if (actionId == "forgetAll") { - // IVAN + if (sourceModel()) { + ResultModel *resultModel = static_cast(sourceModel()); + resultModel->forgetAllResources(); + } return true; } bool close = false; KFileItem item(url); if (Kicker::handleFileItemAction(item, actionId, argument, &close)) { return close; } return false; } void RecentDocsModel::refresh() { QObject *oldModel = sourceModel(); auto query = UsedResources | RecentlyUsedFirst | Agent::any() | Type::any() | Activity::current() | Url::file(); ResultModel *model = new ResultModel(query); model->setItemCountLimit(15); setSourceModel(model); delete oldModel; }