┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/panels/places
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2012-06-02 15:02:34 +0200
committerPeter Penz <[email protected]>2012-06-02 15:03:22 +0200
commit12215d6f0f7768fc943347a349d9817844e0528a (patch)
tree76db3b0f6c32900b397246de3c8f731c703708f3 /src/panels/places
parent665c44821e32ba4bdfcd94889eb17e08ac25a315 (diff)
Use PlacesItemModel instead of KFilePlacesModel
This allows inserting items to the corresponding group.
Diffstat (limited to 'src/panels/places')
-rw-r--r--src/panels/places/placesitem.cpp16
-rw-r--r--src/panels/places/placesitemmodel.cpp34
-rw-r--r--src/panels/places/placesitemmodel.h11
-rw-r--r--src/panels/places/placespanel.cpp20
4 files changed, 53 insertions, 28 deletions
diff --git a/src/panels/places/placesitem.cpp b/src/panels/places/placesitem.cpp
index 7a5daff8e..191f8b277 100644
--- a/src/panels/places/placesitem.cpp
+++ b/src/panels/places/placesitem.cpp
@@ -125,6 +125,7 @@ void PlacesItem::setBookmark(const KBookmark& bookmark)
delete m_volume;
delete m_disc;
+
const QString udi = bookmark.metaDataItem("UDI");
if (udi.isEmpty()) {
setIcon(bookmark.icon());
@@ -134,7 +135,18 @@ void PlacesItem::setBookmark(const KBookmark& bookmark)
initializeDevice(udi);
}
- switch (groupType()) {
+ const GroupType type = groupType();
+ if (icon().isEmpty()) {
+ switch (type) {
+ case RecentlyAccessedType: setIcon("package_utility_time"); break;
+ case SearchForType: setIcon("nepomuk"); break;
+ case PlacesType:
+ default: setIcon("folder");
+ }
+
+ }
+
+ switch (type) {
case PlacesType: setGroup(i18nc("@item", "Places")); break;
case RecentlyAccessedType: setGroup(i18nc("@item", "Recently Accessed")); break;
case SearchForType: setGroup(i18nc("@item", "Search For")); break;
@@ -158,7 +170,7 @@ PlacesItem::GroupType PlacesItem::groupType() const
return RecentlyAccessedType;
}
- if (protocol == QLatin1String("search")) {
+ if (protocol.contains(QLatin1String("search"))) {
return SearchForType;
}
diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp
index c1a5426af..02e1944bd 100644
--- a/src/panels/places/placesitemmodel.cpp
+++ b/src/panels/places/placesitemmodel.cpp
@@ -226,6 +226,32 @@ int PlacesItemModel::closestItem(const KUrl& url) const
return foundIndex;
}
+void PlacesItemModel::appendItemToGroup(PlacesItem* item)
+{
+ if (!item) {
+ return;
+ }
+
+ int i = 0;
+ while (i < count() && placesItem(i)->group() != item->group()) {
+ ++i;
+ }
+
+ bool inserted = false;
+ while (!inserted && i < count()) {
+ if (placesItem(i)->group() != item->group()) {
+ insertItem(i, item);
+ inserted = true;
+ }
+ ++i;
+ }
+
+ if (!inserted) {
+ appendItem(item);
+ }
+}
+
+
QAction* PlacesItemModel::ejectAction(int index) const
{
const PlacesItem* item = placesItem(index);
@@ -370,11 +396,7 @@ void PlacesItemModel::dropMimeData(int index, const QMimeData* mimeData)
text = url.host();
}
- KBookmark bookmark = PlacesItem::createBookmark(m_bookmarkManager,
- text,
- url,
- "folder");
- PlacesItem* newItem = new PlacesItem(bookmark);
+ PlacesItem* newItem = createPlacesItem(text, url);
const int dropIndex = groupedDropIndex(index, newItem);
insertItem(dropIndex, newItem);
}
@@ -567,7 +589,7 @@ void PlacesItemModel::updateBookmarks()
if (item->isHidden() && !m_hiddenItemsShown) {
m_bookmarkedItems.append(item);
} else {
- appendItem(item);
+ appendItemToGroup(item);
}
}
}
diff --git a/src/panels/places/placesitemmodel.h b/src/panels/places/placesitemmodel.h
index b850f356f..89a111730 100644
--- a/src/panels/places/placesitemmodel.h
+++ b/src/panels/places/placesitemmodel.h
@@ -69,7 +69,7 @@ public:
*/
PlacesItem* createPlacesItem(const QString& text,
const KUrl& url,
- const QString& iconName);
+ const QString& iconName = QString());
PlacesItem* placesItem(int index) const;
@@ -99,6 +99,15 @@ public:
*/
int closestItem(const KUrl& url) const;
+ /**
+ * Appends the item \a item as last element of the group
+ * the item belongs to. If no item with the same group is
+ * present, the item gets appended as last element of the
+ * model. PlacesItemModel takes the ownership
+ * of the item.
+ */
+ void appendItemToGroup(PlacesItem* item);
+
QAction* ejectAction(int index) const;
QAction* teardownAction(int index) const;
diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp
index 613046025..7016b039d 100644
--- a/src/panels/places/placespanel.cpp
+++ b/src/panels/places/placespanel.cpp
@@ -309,25 +309,7 @@ void PlacesPanel::addEntry()
dialog->setUrl(url);
if (dialog->exec() == QDialog::Accepted) {
PlacesItem* item = m_model->createPlacesItem(dialog->text(), dialog->url(), dialog->icon());
-
- // Insert the item as last item of the corresponding group.
- int i = 0;
- while (i < m_model->count() && m_model->placesItem(i)->group() != item->group()) {
- ++i;
- }
-
- bool inserted = false;
- while (!inserted && i < m_model->count()) {
- if (m_model->placesItem(i)->group() != item->group()) {
- m_model->insertItem(i, item);
- inserted = true;
- }
- ++i;
- }
-
- if (!inserted) {
- m_model->appendItem(item);
- }
+ m_model->appendItemToGroup(item);
}
delete dialog;