┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/panels
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2012-05-01 23:11:06 +0200
committerPeter Penz <[email protected]>2012-05-01 23:14:52 +0200
commitd76b113ad10fe207ef23d5dd44c63ee076c71521 (patch)
tree2cda5384e4036f4f048392548ea75243ce6b7fc2 /src/panels
parent6a7cb5ff7d29cc636b432a96e0db9ef9f9030527 (diff)
Places Panel: Allow hiding of items
Related changes: - Animate changed items for the details-view in case it is not expandable - Remove the hardcoded "isHidden"-code in KStandardItemListWidget and allow derived widgets to define themselves what means "hidden" within their context. The current code needs a lot of bugfixing, but lets make this in smaller steps during the next days...
Diffstat (limited to 'src/panels')
-rw-r--r--src/panels/places/placesitemlistwidget.cpp36
-rw-r--r--src/panels/places/placesitemlistwidget.h39
-rw-r--r--src/panels/places/placesitemmodel.cpp66
-rw-r--r--src/panels/places/placesitemmodel.h11
-rw-r--r--src/panels/places/placespanel.cpp8
5 files changed, 155 insertions, 5 deletions
diff --git a/src/panels/places/placesitemlistwidget.cpp b/src/panels/places/placesitemlistwidget.cpp
new file mode 100644
index 000000000..3f4c92dfa
--- /dev/null
+++ b/src/panels/places/placesitemlistwidget.cpp
@@ -0,0 +1,36 @@
+/***************************************************************************
+ * Copyright (C) 2012 by Peter Penz <[email protected]> *
+ * *
+ * 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 "placesitemlistwidget.h"
+
+PlacesItemListWidget::PlacesItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) :
+ KStandardItemListWidget(informant, parent)
+{
+}
+
+PlacesItemListWidget::~PlacesItemListWidget()
+{
+}
+
+bool PlacesItemListWidget::isHidden() const
+{
+ return data().value("isHidden").toBool();
+}
+
+#include "placesitemlistwidget.moc"
diff --git a/src/panels/places/placesitemlistwidget.h b/src/panels/places/placesitemlistwidget.h
new file mode 100644
index 000000000..28e0f00e8
--- /dev/null
+++ b/src/panels/places/placesitemlistwidget.h
@@ -0,0 +1,39 @@
+/***************************************************************************
+ * Copyright (C) 2012 by Peter Penz <[email protected]> *
+ * *
+ * 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 PLACESITEMLISTWIDGET_H
+#define PLACESITEMLISTWIDGET_H
+
+#include <kitemviews/kstandarditemlistwidget.h>
+
+class PlacesItemListWidget : public KStandardItemListWidget
+{
+ Q_OBJECT
+
+public:
+ PlacesItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent);
+ virtual ~PlacesItemListWidget();
+
+protected:
+ virtual bool isHidden() const;
+};
+
+#endif
+
+
diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp
index 023e873eb..060c77f81 100644
--- a/src/panels/places/placesitemmodel.cpp
+++ b/src/panels/places/placesitemmodel.cpp
@@ -52,7 +52,8 @@ PlacesItemModel::PlacesItemModel(QObject* parent) :
m_availableDevices(),
m_bookmarkManager(0),
m_systemBookmarks(),
- m_systemBookmarksIndexes()
+ m_systemBookmarksIndexes(),
+ m_hiddenItems()
{
#ifdef HAVE_NEPOMUK
m_nepomukRunning = (Nepomuk::ResourceManager::instance()->initialized());
@@ -66,11 +67,40 @@ PlacesItemModel::PlacesItemModel(QObject* parent) :
PlacesItemModel::~PlacesItemModel()
{
+ qDeleteAll(m_hiddenItems);
+ m_hiddenItems.clear();
}
int PlacesItemModel::hiddenCount() const
{
- return 0;
+ int itemCount = 0;
+ foreach (const KStandardItem* item, m_hiddenItems) {
+ if (item) {
+ ++itemCount;
+ }
+ }
+
+ return itemCount;
+}
+
+void PlacesItemModel::setItemHidden(int index, bool hide)
+{
+ if (index >= 0 && index < count()) {
+ KStandardItem* shownItem = this->item(index);
+ shownItem->setDataValue("isHidden", hide);
+ if (!m_hiddenItemsShown && hide) {
+ KStandardItem* hiddenItem = new KStandardItem(*shownItem);
+ removeItem(index);
+ index = hiddenIndex(index);
+ Q_ASSERT(!m_hiddenItems[index]);
+ m_hiddenItems[index] = hiddenItem;
+ }
+ }
+}
+
+bool PlacesItemModel::isItemHidden(int index) const
+{
+ return (index >= 0 && index < count()) ? m_hiddenItems[index] != 0 : false;
}
void PlacesItemModel::setHiddenItemsShown(bool show)
@@ -140,6 +170,18 @@ QAction* PlacesItemModel::tearDownAction(int index) const
return 0;
}
+void PlacesItemModel::onItemInserted(int index)
+{
+ m_hiddenItems.insert(hiddenIndex(index), 0);
+}
+
+void PlacesItemModel::onItemRemoved(int index)
+{
+ const int removeIndex = hiddenIndex(index);
+ Q_ASSERT(!m_hiddenItems[removeIndex]);
+ m_hiddenItems.removeAt(removeIndex);
+}
+
void PlacesItemModel::loadBookmarks()
{
KBookmarkGroup root = m_bookmarkManager->root();
@@ -187,7 +229,11 @@ void PlacesItemModel::loadBookmarks()
item->setGroup(i18nc("@item", "Places"));
}
- appendItem(item);
+ if (bookmark.metaDataItem("IsHidden") == QLatin1String("true")) {
+ m_hiddenItems.append(item);
+ } else {
+ appendItem(item);
+ }
}
bookmark = root.next(bookmark);
@@ -276,6 +322,20 @@ void PlacesItemModel::createSystemBookmarks()
}
}
+int PlacesItemModel::hiddenIndex(int index) const
+{
+ int hiddenIndex = 0;
+ int visibleItemIndex = 0;
+ while (visibleItemIndex < index && hiddenIndex < m_hiddenItems.count()) {
+ if (!m_hiddenItems[hiddenIndex]) {
+ ++visibleItemIndex;
+ }
+ ++hiddenIndex;
+ }
+
+ return hiddenIndex;
+}
+
QString PlacesItemModel::placesGroupName()
{
return i18nc("@item", "Places");
diff --git a/src/panels/places/placesitemmodel.h b/src/panels/places/placesitemmodel.h
index f8f2b5bc8..50f2be9d4 100644
--- a/src/panels/places/placesitemmodel.h
+++ b/src/panels/places/placesitemmodel.h
@@ -55,6 +55,9 @@ public:
int hiddenCount() const;
+ void setItemHidden(int index, bool hide);
+ bool isItemHidden(int index) const;
+
/**
* @return True if the item is a default item created by
* the system (e.g. the places for home, root, trash etc.)
@@ -79,11 +82,17 @@ public:
QAction* ejectAction(int index) const;
QAction* tearDownAction(int index) const;
+protected:
+ virtual void onItemInserted(int index);
+ virtual void onItemRemoved(int index);
+
private:
void loadBookmarks();
void createSystemBookmarks();
+ int hiddenIndex(int index) const;
+
static QString placesGroupName();
static QString recentlyAccessedGroupName();
static QString searchForGroupName();
@@ -140,6 +149,8 @@ private:
QList<SystemBookmarkData> m_systemBookmarks;
QHash<KUrl, int> m_systemBookmarksIndexes;
+
+ QList<KStandardItem*> m_hiddenItems;
};
#endif
diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp
index ea2ec3072..dc0f2b8ba 100644
--- a/src/panels/places/placespanel.cpp
+++ b/src/panels/places/placespanel.cpp
@@ -40,6 +40,7 @@
#include <KNotification>
#include "placesitemeditdialog.h"
#include "placesitemlistgroupheader.h"
+#include "placesitemlistwidget.h"
#include "placesitemmodel.h"
#include <views/draganddrophelper.h>
#include <QVBoxLayout>
@@ -77,6 +78,7 @@ void PlacesPanel::showEvent(QShowEvent* event)
m_model->setSortRole("group");
KStandardItemListView* view = new KStandardItemListView();
+ view->setWidgetCreator(new KItemListWidgetCreator<PlacesItemListWidget>());
view->setGroupHeaderCreator(new KItemListGroupHeaderCreator<PlacesItemListGroupHeader>());
m_controller = new KItemListController(m_model, view, this);
@@ -167,7 +169,7 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
QAction* hideAction = menu.addAction(i18nc("@item:inmenu", "Hide Entry '%1'", label));
hideAction->setCheckable(true);
- //hideEntry->setChecked(data.value("hidden").toBool());
+ hideAction->setChecked(data.value("isHidden").toBool());
QAction* showAllAction = 0;
if (m_model->hiddenCount() > 0) {
@@ -176,7 +178,7 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
}
showAllAction = menu.addAction(i18nc("@item:inmenu", "Show All Entries"));
showAllAction->setCheckable(true);
- //showAllEntries->setChecked(showAll)
+ showAllAction->setChecked(m_model->hiddenItemsShown());
}
QAction* removeAction = 0;
@@ -200,7 +202,9 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
} else if (action == removeAction) {
m_model->removeItem(index);
} else if (action == hideAction) {
+ m_model->setItemHidden(index, hideAction->isChecked());
} else if (action == showAllAction) {
+ m_model->setHiddenItemsShown(showAllAction->isChecked());
} else if (action == tearDownAction) {
} else if (action == ejectAction) {
}