┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2012-04-30 18:26:21 +0200
committerPeter Penz <[email protected]>2012-04-30 18:27:56 +0200
commitcb1f42a1eb3584742fa33e28759ed8fbab199c5b (patch)
tree84aee132d0fdb4d00abefb6b4ee4acdb3c6a36a0 /src
parentb419cfc5974192f3445b6a439b40bae4af119615 (diff)
Places Panel: Minor fixes/improvements
- Determine group of a new entry dependent from the protocol - Allow panels to forward error-messages to the view-container (also applied to Folders Panel)
Diffstat (limited to 'src')
-rw-r--r--src/dolphinmainwindow.cpp9
-rw-r--r--src/dolphinmainwindow.h6
-rw-r--r--src/panels/folders/folderspanel.cpp5
-rw-r--r--src/panels/folders/folderspanel.h1
-rw-r--r--src/panels/places/placesitemeditdialog.cpp8
-rw-r--r--src/panels/places/placesitemmodel.cpp50
-rw-r--r--src/panels/places/placesitemmodel.h18
-rw-r--r--src/panels/places/placespanel.cpp24
-rw-r--r--src/panels/places/placespanel.h1
9 files changed, 99 insertions, 23 deletions
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index 699a1a777..355bc6fd4 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -1431,6 +1431,11 @@ void DolphinMainWindow::slotControlButtonDeleted()
m_updateToolBarTimer->start();
}
+void DolphinMainWindow::slotPanelErrorMessage(const QString& error)
+{
+ activeViewContainer()->showMessage(error, DolphinViewContainer::Error);
+}
+
void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
{
Q_ASSERT(viewContainer);
@@ -1707,6 +1712,8 @@ void DolphinMainWindow::setupDockWidgets()
this, SLOT(changeUrl(KUrl)));
connect(foldersPanel, SIGNAL(folderMiddleClicked(KUrl)),
this, SLOT(openNewActivatedTab(KUrl)));
+ connect(foldersPanel, SIGNAL(errorMessage(QString)),
+ this, SLOT(slotPanelErrorMessage(QString)));
// Setup "Terminal"
#ifndef Q_OS_WIN
@@ -1757,6 +1764,8 @@ void DolphinMainWindow::setupDockWidgets()
this, SLOT(changeUrl(KUrl)));
connect(placesPanel, SIGNAL(placeMiddleClicked(KUrl)),
this, SLOT(openNewActivatedTab(KUrl)));
+ connect(placesPanel, SIGNAL(errorMessage(QString)),
+ this, SLOT(slotPanelErrorMessage(QString)));
connect(this, SIGNAL(urlChanged(KUrl)),
placesPanel, SLOT(setUrl(KUrl)));
connect(placesDock, SIGNAL(visibilityChanged(bool)),
diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h
index 722e3ab7a..0d14269ee 100644
--- a/src/dolphinmainwindow.h
+++ b/src/dolphinmainwindow.h
@@ -458,6 +458,12 @@ private slots:
void updateToolBar();
void slotControlButtonDeleted();
+ /**
+ * Is called if a panel emits an error-message and shows
+ * the error-message in the active view-container.
+ */
+ void slotPanelErrorMessage(const QString& error);
+
private:
/**
* Activates the given view, which means that
diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp
index 9b22aa5a0..78e437a41 100644
--- a/src/panels/folders/folderspanel.cpp
+++ b/src/panels/folders/folderspanel.cpp
@@ -223,7 +223,10 @@ void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* eve
event->buttons(),
event->modifiers());
- DragAndDropHelper::dropUrls(destItem, destItem.url(), &dropEvent);
+ const QString error = DragAndDropHelper::dropUrls(destItem, destItem.url(), &dropEvent);
+ if (!error.isEmpty()) {
+ emit errorMessage(error);
+ }
}
}
diff --git a/src/panels/folders/folderspanel.h b/src/panels/folders/folderspanel.h
index a14c7d4d0..14d8e8782 100644
--- a/src/panels/folders/folderspanel.h
+++ b/src/panels/folders/folderspanel.h
@@ -53,6 +53,7 @@ public:
signals:
void folderActivated(const KUrl& url);
void folderMiddleClicked(const KUrl& url);
+ void errorMessage(const QString& error);
protected:
/** @see Panel::urlChanged() */
diff --git a/src/panels/places/placesitemeditdialog.cpp b/src/panels/places/placesitemeditdialog.cpp
index 0fdd03060..f8b985f6f 100644
--- a/src/panels/places/placesitemeditdialog.cpp
+++ b/src/panels/places/placesitemeditdialog.cpp
@@ -25,6 +25,7 @@
#include <KAboutData>
#include <KComponentData>
+#include <KDebug>
#include <KFile>
#include <KIconButton>
#include <KLineEdit>
@@ -69,7 +70,12 @@ void PlacesItemEditDialog::setText(const QString& text)
QString PlacesItemEditDialog::text() const
{
- return m_textEdit->text().isEmpty() ? m_urlEdit->url().fileName() : m_textEdit->text();
+ QString text = m_textEdit->text();
+ if (text.isEmpty()) {
+ const KUrl url = m_urlEdit->url();
+ text = url.fileName().isEmpty() ? url.prettyUrl() : url.fileName();
+ }
+ return text;
}
void PlacesItemEditDialog::setUrl(const KUrl& url)
diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp
index ae6163e03..023e873eb 100644
--- a/src/panels/places/placesitemmodel.cpp
+++ b/src/panels/places/placesitemmodel.cpp
@@ -37,6 +37,7 @@
#include <KBookmarkGroup>
#include <KBookmarkManager>
#include <KComponentData>
+#include <KDebug>
#include <KIcon>
#include <kitemviews/kstandarditem.h>
#include <KLocale>
@@ -47,6 +48,7 @@
PlacesItemModel::PlacesItemModel(QObject* parent) :
KStandardItemModel(parent),
m_nepomukRunning(false),
+ m_hiddenItemsShown(false),
m_availableDevices(),
m_bookmarkManager(0),
m_systemBookmarks(),
@@ -71,6 +73,18 @@ int PlacesItemModel::hiddenCount() const
return 0;
}
+void PlacesItemModel::setHiddenItemsShown(bool show)
+{
+ if (m_hiddenItemsShown != show) {
+ m_hiddenItemsShown = show;
+ }
+}
+
+bool PlacesItemModel::hiddenItemsShown() const
+{
+ return m_hiddenItemsShown;
+}
+
bool PlacesItemModel::isSystemItem(int index) const
{
if (index >= 0 && index < count()) {
@@ -99,19 +113,19 @@ int PlacesItemModel::closestItem(const KUrl& url) const
return foundIndex;
}
-QString PlacesItemModel::placesGroupName() const
+QString PlacesItemModel::groupName(const KUrl &url) const
{
- return i18nc("@item", "Places");
-}
+ const QString protocol = url.protocol();
-QString PlacesItemModel::recentlyAccessedGroupName() const
-{
- return i18nc("@item", "Recently Accessed");
-}
+ if (protocol.contains(QLatin1String("search"))) {
+ return searchForGroupName();
+ }
-QString PlacesItemModel::searchForGroupName() const
-{
- return i18nc("@item", "Search For");
+ if (protocol == QLatin1String("timeline")) {
+ return recentlyAccessedGroupName();
+ }
+
+ return placesGroupName();
}
QAction* PlacesItemModel::ejectAction(int index) const
@@ -262,8 +276,22 @@ void PlacesItemModel::createSystemBookmarks()
}
}
+QString PlacesItemModel::placesGroupName()
+{
+ return i18nc("@item", "Places");
+}
+
+QString PlacesItemModel::recentlyAccessedGroupName()
+{
+ return i18nc("@item", "Recently Accessed");
+}
+
+QString PlacesItemModel::searchForGroupName()
+{
+ return i18nc("@item", "Search For");
+}
-KUrl PlacesItemModel::translatedSystemBookmarkUrl(const KUrl& url) const
+KUrl PlacesItemModel::translatedSystemBookmarkUrl(const KUrl& url)
{
KUrl translatedUrl = url;
if (url.protocol() == QLatin1String("timeline")) {
diff --git a/src/panels/places/placesitemmodel.h b/src/panels/places/placesitemmodel.h
index 330e754b0..f8f2b5bc8 100644
--- a/src/panels/places/placesitemmodel.h
+++ b/src/panels/places/placesitemmodel.h
@@ -50,6 +50,9 @@ public:
explicit PlacesItemModel(QObject* parent = 0);
virtual ~PlacesItemModel();
+ void setHiddenItemsShown(bool show);
+ bool hiddenItemsShown() const;
+
int hiddenCount() const;
/**
@@ -67,9 +70,11 @@ public:
*/
int closestItem(const KUrl& url) const;
- QString placesGroupName() const;
- QString recentlyAccessedGroupName() const;
- QString searchForGroupName() const;
+ /**
+ * @return Name of the group where the item with the URL
+ * \a URL belongs to.
+ */
+ QString groupName(const KUrl& url) const;
QAction* ejectAction(int index) const;
QAction* tearDownAction(int index) const;
@@ -79,7 +84,11 @@ private:
void createSystemBookmarks();
- KUrl translatedSystemBookmarkUrl(const KUrl& url) const;
+ static QString placesGroupName();
+ static QString recentlyAccessedGroupName();
+ static QString searchForGroupName();
+
+ static KUrl translatedSystemBookmarkUrl(const KUrl& url);
/**
* @return URL using the timeline-protocol for searching.
@@ -111,6 +120,7 @@ private:
private:
bool m_nepomukRunning;
+ bool m_hiddenItemsShown;
QSet<QString> m_availableDevices;
KBookmarkManager* m_bookmarkManager;
diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp
index bcdccf2a0..ea2ec3072 100644
--- a/src/panels/places/placespanel.cpp
+++ b/src/panels/places/placespanel.cpp
@@ -230,7 +230,11 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
{
Q_UNUSED(parent);
- DragAndDropHelper::dropUrls(KFileItem(), dest, event);
+ const QString error = DragAndDropHelper::dropUrls(KFileItem(), dest, event);
+ if (!error.isEmpty()) {
+ emit errorMessage(error);
+ }
+
}
void PlacesPanel::slotTrashUpdated(KJob* job)
@@ -273,11 +277,15 @@ void PlacesPanel::addEntry()
if (dialog->exec() == QDialog::Accepted) {
KStandardItem* item = createStandardItemFromDialog(dialog);
- // Insert the item as last item of the "Places" group
- bool inserted = false;
+ // Insert the item as last item of the corresponding group.
int i = 0;
+ while (i < m_model->count() && m_model->item(i)->group() != item->group()) {
+ ++i;
+ }
+
+ bool inserted = false;
while (!inserted && i < m_model->count()) {
- if (m_model->item(i)->group() != m_model->placesGroupName()) {
+ if (m_model->item(i)->group() != item->group()) {
m_model->insertItem(i, item);
inserted = true;
}
@@ -306,6 +314,9 @@ void PlacesPanel::editEntry(int index)
KStandardItem* oldItem = m_model->item(index);
if (oldItem) {
KStandardItem* item = createStandardItemFromDialog(dialog);
+ // Although the user might have changed the URL of the item in a way
+ // that another group should be assigned, we still apply the old
+ // group to keep the same position for the item.
item->setGroup(oldItem->group());
m_model->replaceItem(index, item);
}
@@ -327,11 +338,12 @@ KStandardItem* PlacesPanel::createStandardItemFromDialog(PlacesItemEditDialog* d
{
Q_ASSERT(dialog);
+ const KUrl newUrl = dialog->url();
KStandardItem* item = new KStandardItem();
item->setIcon(KIcon(dialog->icon()));
item->setText(dialog->text());
- item->setDataValue("url", dialog->url());
- item->setGroup(m_model->placesGroupName());
+ item->setDataValue("url", newUrl);
+ item->setGroup(m_model->groupName(newUrl));
return item;
}
diff --git a/src/panels/places/placespanel.h b/src/panels/places/placespanel.h
index 0b86ced1a..7baefd9e8 100644
--- a/src/panels/places/placespanel.h
+++ b/src/panels/places/placespanel.h
@@ -45,6 +45,7 @@ public:
signals:
void placeActivated(const KUrl& url);
void placeMiddleClicked(const KUrl& url);
+ void errorMessage(const QString& error);
protected:
virtual bool urlChanged();