From: Peter Penz Date: Wed, 25 Apr 2012 21:01:15 +0000 (+0200) Subject: Places panel: Internal cleanup X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/640696db728ad3163384e19f789ebc022d183da6 Places panel: Internal cleanup Move the bookmark handling into a custom model, so that the PlacesPanel only contains UI + controller code. --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 94ae5aa77..4d87ee0bf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -144,6 +144,7 @@ set(dolphin_SRCS panels/information/phononwidget.cpp panels/places/placespanel.cpp panels/places/placesitemlistgroupheader.cpp + panels/places/placesitemmodel.cpp panels/panel.cpp panels/folders/treeviewcontextmenu.cpp panels/folders/folderspanel.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 3eb9b7608..01cc62fce 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -1738,14 +1738,7 @@ void DolphinMainWindow::setupDockWidgets() placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); PlacesPanel* placesPanel = new PlacesPanel(placesDock); - QAction* separator = new QAction(placesPanel); - separator->setSeparator(true); - QList placesActions; - placesActions.append(separator); - placesActions.append(lockLayoutAction); - //placesPanel->addActions(placesActions); - //placesPanel->setModel(DolphinPlacesModel::instance()); - //placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + placesPanel->setCustomContextMenuActions(QList() << lockLayoutAction); placesDock->setWidget(placesPanel); QAction* placesAction = placesDock->toggleViewAction(); diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp new file mode 100644 index 000000000..219c76698 --- /dev/null +++ b/src/panels/places/placesitemmodel.cpp @@ -0,0 +1,299 @@ +/*************************************************************************** + * Copyright (C) 2012 by Peter Penz * + * * + * Based on KFilePlacesModel from kdelibs: * + * Copyright (C) 2007 Kevin Ottens * + * Copyright (C) 2007 David Faure * + * * + * 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 "placesitemmodel.h" + +#ifdef HAVE_NEPOMUK + #include + #include + #include + #include + #include + #include + #include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +PlacesItemModel::PlacesItemModel(QObject* parent) : + KStandardItemModel(parent), + m_nepomukRunning(false), + m_availableDevices(), + m_bookmarkManager(0), + m_defaultBookmarks(), + m_defaultBookmarksIndexes() +{ +#ifdef HAVE_NEPOMUK + m_nepomukRunning = (Nepomuk::ResourceManager::instance()->initialized()); +#endif + const QString file = KStandardDirs::locateLocal("data", "kfileplaces/bookmarks.xml"); + m_bookmarkManager = KBookmarkManager::managerForFile(file, "kfilePlaces"); + + createDefaultBookmarks(); + loadBookmarks(); +} + +PlacesItemModel::~PlacesItemModel() +{ +} + +void PlacesItemModel::loadBookmarks() +{ + KBookmarkGroup root = m_bookmarkManager->root(); + KBookmark bookmark = root.first(); + QSet devices = m_availableDevices; + + QSet missingDefaultBookmarks; + foreach (const DefaultBookmarkData& data, m_defaultBookmarks) { + missingDefaultBookmarks.insert(data.url); + } + + while (!bookmark.isNull()) { + const QString udi = bookmark.metaDataItem("UDI"); + const KUrl url = bookmark.url(); + const QString appName = bookmark.metaDataItem("OnlyInApp"); + const bool deviceAvailable = devices.remove(udi); + + const bool allowedHere = (appName.isEmpty() || appName == KGlobal::mainComponent().componentName()) + && (m_nepomukRunning || url.protocol() != QLatin1String("timeline")); + + if ((udi.isEmpty() && allowedHere) || deviceAvailable) { + KStandardItem* item = new KStandardItem(); + item->setIcon(KIcon(bookmark.icon())); + item->setDataValue("address", bookmark.address()); + item->setDataValue("url", url); + + if (missingDefaultBookmarks.contains(url)) { + missingDefaultBookmarks.remove(url); + // Apply the translated text to the default bookmarks, otherwise an outdated + // translation might be shown. + const int index = m_defaultBookmarksIndexes.value(url); + item->setText(m_defaultBookmarks[index].text); + + // The default bookmarks don't contain "real" queries stored as URLs, so + // they must be translated first. + item->setDataValue("url", translatedDefaultBookmarkUrl(url)); + } else { + item->setText(bookmark.text()); + } + + if (deviceAvailable) { + item->setDataValue("udi", udi); + item->setGroup(i18nc("@item", "Devices")); + } else { + item->setGroup(i18nc("@item", "Places")); + } + + appendItem(item); + } + + bookmark = root.next(bookmark); + } + + if (!missingDefaultBookmarks.isEmpty()) { + foreach (const DefaultBookmarkData& data, m_defaultBookmarks) { + if (missingDefaultBookmarks.contains(data.url)) { + KStandardItem* item = new KStandardItem(); + item->setIcon(KIcon(data.icon)); + item->setText(data.text); + item->setDataValue("url", translatedDefaultBookmarkUrl(data.url)); + item->setGroup(data.group); + appendItem(item); + } + } + } +} + +void PlacesItemModel::createDefaultBookmarks() +{ + Q_ASSERT(m_defaultBookmarks.isEmpty()); + Q_ASSERT(m_defaultBookmarksIndexes.isEmpty()); + + const QString placesGroup = i18nc("@item", "Places"); + const QString recentlyAccessedGroup = i18nc("@item", "Recently Accessed"); + const QString searchForGroup = i18nc("@item", "Search For"); + const QString timeLineIcon = "package_utility_time"; // TODO: Ask the Oxygen team to create + // a custom icon for the timeline-protocol + + m_defaultBookmarks.append(DefaultBookmarkData(KUrl(KUser().homeDir()), + "user-home", + i18nc("@item", "Home"), + placesGroup)); + m_defaultBookmarks.append(DefaultBookmarkData(KUrl("remote:/"), + "network-workgroup", + i18nc("@item", "Network"), + placesGroup)); + m_defaultBookmarks.append(DefaultBookmarkData(KUrl("/"), + "folder-red", + i18nc("@item", "Root"), + placesGroup)); + m_defaultBookmarks.append(DefaultBookmarkData(KUrl("trash:/"), + "user-trash", + i18nc("@item", "Trash"), + placesGroup)); + + if (m_nepomukRunning) { + m_defaultBookmarks.append(DefaultBookmarkData(KUrl("timeline:/today"), + timeLineIcon, + i18nc("@item Recently Accessed", "Today"), + recentlyAccessedGroup)); + m_defaultBookmarks.append(DefaultBookmarkData(KUrl("timeline:/yesterday"), + timeLineIcon, + i18nc("@item Recently Accessed", "Yesterday"), + recentlyAccessedGroup)); + m_defaultBookmarks.append(DefaultBookmarkData(KUrl("timeline:/thismonth"), + timeLineIcon, + i18nc("@item Recently Accessed", "This Month"), + recentlyAccessedGroup)); + m_defaultBookmarks.append(DefaultBookmarkData(KUrl("timeline:/lastmonth"), + timeLineIcon, + i18nc("@item Recently Accessed", "Last Month"), + recentlyAccessedGroup)); + m_defaultBookmarks.append(DefaultBookmarkData(KUrl("search:/documents"), + "folder-txt", + i18nc("@item Commonly Accessed", "Documents"), + searchForGroup)); + m_defaultBookmarks.append(DefaultBookmarkData(KUrl("search:/images"), + "folder-image", + i18nc("@item Commonly Accessed", "Images"), + searchForGroup)); + m_defaultBookmarks.append(DefaultBookmarkData(KUrl("search:/audio"), + "folder-sound", + i18nc("@item Commonly Accessed", "Audio"), + searchForGroup)); + m_defaultBookmarks.append(DefaultBookmarkData(KUrl("search:/videos"), + "folder-video", + i18nc("@item Commonly Accessed", "Videos"), + searchForGroup)); + } + + for (int i = 0; i < m_defaultBookmarks.count(); ++i) { + m_defaultBookmarksIndexes.insert(m_defaultBookmarks[i].url, i); + } +} + + +KUrl PlacesItemModel::translatedDefaultBookmarkUrl(const KUrl& url) const +{ + KUrl translatedUrl = url; + if (url.protocol() == QLatin1String("timeline")) { + translatedUrl = createTimelineUrl(url); + } else if (url.protocol() == QLatin1String("search")) { + translatedUrl = createSearchUrl(url); + } + + return translatedUrl; +} + +KUrl PlacesItemModel::createTimelineUrl(const KUrl& url) +{ + // TODO: Clarify with the Nepomuk-team whether it makes sense + // provide default-timeline-URLs like 'yesterday', 'this month' + // and 'last month'. + KUrl timelineUrl; + + const QString path = url.pathOrUrl(); + if (path.endsWith("yesterday")) { + const QDate date = QDate::currentDate().addDays(-1); + const int year = date.year(); + const int month = date.month(); + const int day = date.day(); + timelineUrl = "timeline:/" + timelineDateString(year, month) + + '/' + timelineDateString(year, month, day); + } else if (path.endsWith("thismonth")) { + const QDate date = QDate::currentDate(); + timelineUrl = "timeline:/" + timelineDateString(date.year(), date.month()); + } else if (path.endsWith("lastmonth")) { + const QDate date = QDate::currentDate().addMonths(-1); + timelineUrl = "timeline:/" + timelineDateString(date.year(), date.month()); + } else { + Q_ASSERT(path.endsWith("today")); + timelineUrl= url; + } + + return timelineUrl; +} + +QString PlacesItemModel::timelineDateString(int year, int month, int day) +{ + QString date = QString::number(year) + '-'; + if (month < 10) { + date += '0'; + } + date += QString::number(month); + + if (day >= 1) { + date += '-'; + if (day < 10) { + date += '0'; + } + date += QString::number(day); + } + + return date; +} + +KUrl PlacesItemModel::createSearchUrl(const KUrl& url) +{ + KUrl searchUrl; + +#ifdef HAVE_NEPOMUK + const QString path = url.pathOrUrl(); + if (path.endsWith("documents")) { + searchUrl = searchUrlForTerm(Nepomuk::Query::ResourceTypeTerm(Nepomuk::Vocabulary::NFO::Document())); + } else if (path.endsWith("images")) { + searchUrl = searchUrlForTerm(Nepomuk::Query::ResourceTypeTerm(Nepomuk::Vocabulary::NFO::Image())); + } else if (path.endsWith("audio")) { + searchUrl = searchUrlForTerm(Nepomuk::Query::ComparisonTerm(Nepomuk::Vocabulary::NIE::mimeType(), + Nepomuk::Query::LiteralTerm("audio"))); + } else if (path.endsWith("videos")) { + searchUrl = searchUrlForTerm(Nepomuk::Query::ComparisonTerm(Nepomuk::Vocabulary::NIE::mimeType(), + Nepomuk::Query::LiteralTerm("video"))); + } else { + Q_ASSERT(false); + } +#else + Q_UNUSED(url); +#endif + + return searchUrl; +} + +#ifdef HAVE_NEPOMUK +KUrl PlacesItemModel::searchUrlForTerm(const Nepomuk::Query::Term& term) +{ + const Nepomuk::Query::Query query(term); + return query.toSearchUrl(); +} +#endif + +#include "placesitemmodel.moc" diff --git a/src/panels/places/placesitemmodel.h b/src/panels/places/placesitemmodel.h new file mode 100644 index 000000000..635ad116c --- /dev/null +++ b/src/panels/places/placesitemmodel.h @@ -0,0 +1,112 @@ +/*************************************************************************** + * Copyright (C) 2012 by Peter Penz * + * * + * 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 PLACESITEMMODEL_H +#define PLACESITEMMODEL_H + +#include + +#include + +#include +#include +#include +#include + +class KBookmarkManager; + +#ifdef HAVE_NEPOMUK + namespace Nepomuk + { + namespace Query + { + class Term; + } + } +#endif + +class PlacesItemModel: public KStandardItemModel +{ + Q_OBJECT + +public: + explicit PlacesItemModel(QObject* parent = 0); + virtual ~PlacesItemModel(); + +private: + void loadBookmarks(); + + void createDefaultBookmarks(); + + KUrl translatedDefaultBookmarkUrl(const KUrl& url) const; + + /** + * @return URL using the timeline-protocol for searching. + */ + static KUrl createTimelineUrl(const KUrl& url); + + /** + * Helper method for createTimelineUrl(). + * @return String that represents a date-path in the format that + * the timeline-protocol expects. + */ + static QString timelineDateString(int year, int month, int day = 0); + + /** + * @return URL that can be listed by KIO and results in searching + * for a given term. The URL \a url represents a places-internal + * URL like e.g. "search:/documents" + */ + static KUrl createSearchUrl(const KUrl& url); + +#ifdef HAVE_NEPOMUK + /** + * Helper method for createSearchUrl(). + * @return URL that can be listed by KIO and results in searching + * for the given term. + */ + static KUrl searchUrlForTerm(const Nepomuk::Query::Term& term); +#endif + +private: + bool m_nepomukRunning; + + QSet m_availableDevices; + KBookmarkManager* m_bookmarkManager; + + struct DefaultBookmarkData + { + DefaultBookmarkData(const KUrl& url, + const QString& icon, + const QString& text, + const QString& group) : + url(url), icon(icon), text(text), group(group) {} + KUrl url; + QString icon; + QString text; + QString group; + }; + + QList m_defaultBookmarks; + QHash m_defaultBookmarksIndexes; +}; + +#endif + + diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp index 09287169c..016a736de 100644 --- a/src/panels/places/placespanel.cpp +++ b/src/panels/places/placespanel.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * Copyright (C) 2008-2012 by Peter Penz * * * - * Based on KFilePlacesModel from kdelibs: * + * Based on KFilePlacesView from kdelibs: * * Copyright (C) 2007 Kevin Ottens * * Copyright (C) 2007 David Faure * * * @@ -23,45 +23,23 @@ #include "placespanel.h" -#ifdef HAVE_NEPOMUK - #include - #include - #include - #include - #include - #include - #include -#endif - -#include -#include -#include -#include -#include +#include #include #include #include #include -#include #include -#include -#include -#include +#include #include "placesitemlistgroupheader.h" +#include "placesitemmodel.h" #include -#include #include #include PlacesPanel::PlacesPanel(QWidget* parent) : Panel(parent), - m_nepomukRunning(false), m_controller(0), - m_model(0), - m_availableDevices(), - m_bookmarkManager(0), - m_defaultBookmarks(), - m_defaultBookmarksIndexes() + m_model(0) { } @@ -85,17 +63,9 @@ void PlacesPanel::showEvent(QShowEvent* event) // Postpone the creating of the controller to the first show event. // This assures that no performance and memory overhead is given when the folders panel is not // used at all and stays invisible. -#ifdef HAVE_NEPOMUK - m_nepomukRunning = (Nepomuk::ResourceManager::instance()->initialized()); -#endif - createDefaultBookmarks(); - - const QString file = KStandardDirs::locateLocal("data", "kfileplaces/bookmarks.xml"); - m_bookmarkManager = KBookmarkManager::managerForFile(file, "kfilePlaces"); - m_model = new KStandardItemModel(this); + m_model = new PlacesItemModel(this); m_model->setGroupedSorting(true); m_model->setSortRole("group"); - loadBookmarks(); KStandardItemListView* view = new KStandardItemListView(); view->setGroupHeaderCreator(new KItemListGroupHeaderCreator()); @@ -120,7 +90,7 @@ void PlacesPanel::showEvent(QShowEvent* event) void PlacesPanel::slotItemActivated(int index) { - const KUrl url = urlForIndex(index); + const KUrl url = m_model->data(index).value("url").value(); if (!url.isEmpty()) { emit placeActivated(url); } @@ -128,7 +98,7 @@ void PlacesPanel::slotItemActivated(int index) void PlacesPanel::slotItemMiddleClicked(int index) { - const KUrl url = urlForIndex(index); + const KUrl url = m_model->data(index).value("url").value(); if (!url.isEmpty()) { emit placeMiddleClicked(url); } @@ -136,247 +106,66 @@ void PlacesPanel::slotItemMiddleClicked(int index) void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos) { - Q_UNUSED(index); - Q_UNUSED(pos); -} - -void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos) -{ - Q_UNUSED(pos); -} - -void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent) -{ - Q_UNUSED(parent); - DragAndDropHelper::dropUrls(KFileItem(), dest, event); -} - -void PlacesPanel::createDefaultBookmarks() -{ - Q_ASSERT(m_defaultBookmarks.isEmpty()); - Q_ASSERT(m_defaultBookmarksIndexes.isEmpty()); - - const QString placesGroup = i18nc("@item", "Places"); - const QString recentlyAccessedGroup = i18nc("@item", "Recently Accessed"); - const QString searchForGroup = i18nc("@item", "Search For"); - const QString timeLineIcon = "package_utility_time"; // TODO: Ask the Oxygen team to create - // a custom icon for the timeline-protocol - - m_defaultBookmarks.append(DefaultBookmarkData(KUrl(KUser().homeDir()), - "user-home", - i18nc("@item", "Home"), - placesGroup)); - m_defaultBookmarks.append(DefaultBookmarkData(KUrl("remote:/"), - "network-workgroup", - i18nc("@item", "Network"), - placesGroup)); - m_defaultBookmarks.append(DefaultBookmarkData(KUrl("/"), - "folder-red", - i18nc("@item", "Root"), - placesGroup)); - m_defaultBookmarks.append(DefaultBookmarkData(KUrl("trash:/"), - "user-trash", - i18nc("@item", "Trash"), - placesGroup)); - - if (m_nepomukRunning) { - m_defaultBookmarks.append(DefaultBookmarkData(KUrl("timeline:/today"), - timeLineIcon, - i18nc("@item Recently Accessed", "Today"), - recentlyAccessedGroup)); - m_defaultBookmarks.append(DefaultBookmarkData(KUrl("timeline:/yesterday"), - timeLineIcon, - i18nc("@item Recently Accessed", "Yesterday"), - recentlyAccessedGroup)); - m_defaultBookmarks.append(DefaultBookmarkData(KUrl("timeline:/thismonth"), - timeLineIcon, - i18nc("@item Recently Accessed", "This Month"), - recentlyAccessedGroup)); - m_defaultBookmarks.append(DefaultBookmarkData(KUrl("timeline:/lastmonth"), - timeLineIcon, - i18nc("@item Recently Accessed", "Last Month"), - recentlyAccessedGroup)); - m_defaultBookmarks.append(DefaultBookmarkData(KUrl("search:/documents"), - "folder-txt", - i18nc("@item Commonly Accessed", "Documents"), - searchForGroup)); - m_defaultBookmarks.append(DefaultBookmarkData(KUrl("search:/images"), - "folder-image", - i18nc("@item Commonly Accessed", "Images"), - searchForGroup)); - m_defaultBookmarks.append(DefaultBookmarkData(KUrl("search:/audio"), - "folder-sound", - i18nc("@item Commonly Accessed", "Audio"), - searchForGroup)); - m_defaultBookmarks.append(DefaultBookmarkData(KUrl("search:/videos"), - "folder-video", - i18nc("@item Commonly Accessed", "Videos"), - searchForGroup)); - } - - for (int i = 0; i < m_defaultBookmarks.count(); ++i) { - m_defaultBookmarksIndexes.insert(m_defaultBookmarks[i].url, i); - } -} - -void PlacesPanel::loadBookmarks() -{ - KBookmarkGroup root = m_bookmarkManager->root(); - KBookmark bookmark = root.first(); - QSet devices = m_availableDevices; - - QSet missingDefaultBookmarks; - foreach (const DefaultBookmarkData& data, m_defaultBookmarks) { - missingDefaultBookmarks.insert(data.url); - } - - while (!bookmark.isNull()) { - const QString udi = bookmark.metaDataItem("UDI"); - const KUrl url = bookmark.url(); - const QString appName = bookmark.metaDataItem("OnlyInApp"); - const bool deviceAvailable = devices.remove(udi); - - const bool allowedHere = (appName.isEmpty() || appName == KGlobal::mainComponent().componentName()) - && (m_nepomukRunning || url.protocol() != QLatin1String("timeline")); - - if ((udi.isEmpty() && allowedHere) || deviceAvailable) { - KStandardItem* item = new KStandardItem(); - item->setIcon(KIcon(bookmark.icon())); - item->setDataValue("address", bookmark.address()); - item->setDataValue("url", url); - - if (missingDefaultBookmarks.contains(url)) { - missingDefaultBookmarks.remove(url); - // Always apply the translated text to the default bookmarks, otherwise an outdated - // translation might be shown. - const int index = m_defaultBookmarksIndexes.value(url); - item->setText(m_defaultBookmarks[index].text); - } else { - item->setText(bookmark.text()); - } - - if (deviceAvailable) { - item->setDataValue("udi", udi); - item->setGroup(i18nc("@item", "Devices")); - } else { - item->setGroup(i18nc("@item", "Places")); - } - - m_model->appendItem(item); - } - - bookmark = root.next(bookmark); - } - - if (!missingDefaultBookmarks.isEmpty()) { - foreach (const DefaultBookmarkData& data, m_defaultBookmarks) { - if (missingDefaultBookmarks.contains(data.url)) { - KStandardItem* item = new KStandardItem(); - item->setIcon(KIcon(data.icon)); - item->setText(data.text); - item->setDataValue("url", data.url); - item->setGroup(data.group); - m_model->appendItem(item); - } - } - } -} - -KUrl PlacesPanel::urlForIndex(int index) const -{ - const KStandardItem* item = m_model->item(index); - if (!item) { - return KUrl(); - } + const QHash data = m_model->data(index); + const QString label = data.value("text").toString(); - KUrl url = item->dataValue("url").value(); - if (url.protocol() == QLatin1String("timeline")) { - url = createTimelineUrl(url); - } else if (url.protocol() == QLatin1String("search")) { - url = createSearchUrl(url); - } - - return url; -} + KMenu menu(this); -KUrl PlacesPanel::createTimelineUrl(const KUrl& url) -{ - // TODO: Clarify with the Nepomuk-team whether it makes sense - // provide default-timeline-URLs like 'yesterday', 'this month' - // and 'last month'. - KUrl timelineUrl; + QAction* emptyTrash = 0; + QAction* addEntry = 0; + QAction* mainSeparator = 0; + QAction* editEntry = 0; + QAction* hideEntry = 0; - const QString path = url.pathOrUrl(); - if (path.endsWith("yesterday")) { - const QDate date = QDate::currentDate().addDays(-1); - const int year = date.year(); - const int month = date.month(); - const int day = date.day(); - timelineUrl = "timeline:/" + timelineDateString(year, month) + - '/' + timelineDateString(year, month, day); - } else if (path.endsWith("thismonth")) { - const QDate date = QDate::currentDate(); - timelineUrl = "timeline:/" + timelineDateString(date.year(), date.month()); - } else if (path.endsWith("lastmonth")) { - const QDate date = QDate::currentDate().addMonths(-1); - timelineUrl = "timeline:/" + timelineDateString(date.year(), date.month()); + const bool isDevice = !data.value("udi").toString().isEmpty(); + if (isDevice) { } else { - Q_ASSERT(path.endsWith("today")); - timelineUrl= url; + if (data.value("url").value() == KUrl("trash:/")) { + emptyTrash = menu.addAction(KIcon("trash-empty"), i18nc("@action:inmenu", "Empty Trash")); + KConfig trashConfig("trashrc", KConfig::SimpleConfig); + emptyTrash->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); + menu.addSeparator(); + } + addEntry = menu.addAction(KIcon("document-new"), i18nc("@item:inmenu", "Add Entry...")); + mainSeparator = menu.addSeparator(); + editEntry = menu.addAction(KIcon("document-properties"), i18n("&Edit Entry '%1'...", label)); } - return timelineUrl; -} - -QString PlacesPanel::timelineDateString(int year, int month, int day) -{ - QString date = QString::number(year) + '-'; - if (month < 10) { - date += '0'; + if (!addEntry) { + addEntry = menu.addAction(KIcon("document-new"), i18nc("@item:inmenu", "Add Entry...")); } - date += QString::number(month); - if (day >= 1) { - date += '-'; - if (day < 10) { - date += '0'; - } - date += QString::number(day); + menu.addSeparator(); + foreach (QAction* action, customContextMenuActions()) { + menu.addAction(action); } - return date; + QAction* action = menu.exec(pos.toPoint()); + hideEntry = menu.addAction(i18n("&Hide Entry '%1'", label)); + hideEntry->setCheckable(true); + //hideEntry->setChecked(data.value("hidden").toBool()); + Q_UNUSED(action); } -KUrl PlacesPanel::createSearchUrl(const KUrl& url) +void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos) { - KUrl searchUrl; + KMenu menu(this); -#ifdef HAVE_NEPOMUK - const QString path = url.pathOrUrl(); - if (path.endsWith("documents")) { - searchUrl = searchUrlForTerm(Nepomuk::Query::ResourceTypeTerm(Nepomuk::Vocabulary::NFO::Document())); - } else if (path.endsWith("images")) { - searchUrl = searchUrlForTerm(Nepomuk::Query::ResourceTypeTerm(Nepomuk::Vocabulary::NFO::Image())); - } else if (path.endsWith("audio")) { - searchUrl = searchUrlForTerm(Nepomuk::Query::ComparisonTerm(Nepomuk::Vocabulary::NIE::mimeType(), - Nepomuk::Query::LiteralTerm("audio"))); - } else if (path.endsWith("videos")) { - searchUrl = searchUrlForTerm(Nepomuk::Query::ComparisonTerm(Nepomuk::Vocabulary::NIE::mimeType(), - Nepomuk::Query::LiteralTerm("video"))); - } else { - Q_ASSERT(false); + QAction* addEntry = menu.addAction(KIcon("document-new"), i18nc("@item:inmenu", "Add Entry...")); + menu.addSeparator(); + foreach (QAction* action, customContextMenuActions()) { + menu.addAction(action); } -#endif - return searchUrl; + QAction* action = menu.exec(pos.toPoint()); + Q_UNUSED(action); + Q_UNUSED(addEntry); } -#ifdef HAVE_NEPOMUK -KUrl PlacesPanel::searchUrlForTerm(const Nepomuk::Query::Term& term) +void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent) { - const Nepomuk::Query::Query query(term); - return query.toSearchUrl(); + Q_UNUSED(parent); + DragAndDropHelper::dropUrls(KFileItem(), dest, event); } -#endif #include "placespanel.moc" diff --git a/src/panels/places/placespanel.h b/src/panels/places/placespanel.h index ea05601e0..5758d2879 100644 --- a/src/panels/places/placespanel.h +++ b/src/panels/places/placespanel.h @@ -25,23 +25,9 @@ #include #include -#include -#include -#include -class KBookmarkManager; class KItemListController; -class KStandardItemModel; - -#ifdef HAVE_NEPOMUK -namespace Nepomuk -{ - namespace Query - { - class Term; - } -} -#endif +class PlacesItemModel; /** * @brief Combines bookmarks and mounted devices as list. @@ -70,62 +56,8 @@ private slots: void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent); private: - void createDefaultBookmarks(); - void loadBookmarks(); - KUrl urlForIndex(int index) const; - - /** - * @return URL using the timeline-protocol for searching. - */ - static KUrl createTimelineUrl(const KUrl& url); - - /** - * Helper method for createTimelineUrl(). - * @return String that represents a date-path in the format that - * the timeline-protocol expects. - */ - static QString timelineDateString(int year, int month, int day = 0); - - /** - * @return URL that can be listed by KIO and results in searching - * for a given term. The URL \a url represents a places-internal - * URL like e.g. "search:/documents" - */ - static KUrl createSearchUrl(const KUrl& url); - -#ifdef HAVE_NEPOMUK - /** - * Helper method for createSearchUrl(). - * @return URL that can be listed by KIO and results in searching - * for the given term. - */ - static KUrl searchUrlForTerm(const Nepomuk::Query::Term& term); -#endif - -private: - bool m_nepomukRunning; - KItemListController* m_controller; - KStandardItemModel* m_model; - - QSet m_availableDevices; - KBookmarkManager* m_bookmarkManager; - - struct DefaultBookmarkData - { - DefaultBookmarkData(const KUrl& url, - const QString& icon, - const QString& text, - const QString& group) : - url(url), icon(icon), text(text), group(group) {} - KUrl url; - QString icon; - QString text; - QString group; - }; - - QList m_defaultBookmarks; - QHash m_defaultBookmarksIndexes; + PlacesItemModel* m_model; }; #endif // PLACESPANEL_H