m_systemBookmarks(),
m_systemBookmarksIndexes(),
m_hiddenItems(),
- m_hiddenItemToRemove(-1)
+ m_hiddenItemToRemove(-1),
+ m_saveBookmarksTimer(0)
{
#ifdef HAVE_NEPOMUK
m_nepomukRunning = (Nepomuk::ResourceManager::instance()->initialized());
createSystemBookmarks();
initializeAvailableDevices();
loadBookmarks();
+
+ m_saveBookmarksTimer = new QTimer(this);
+ m_saveBookmarksTimer->setInterval(100);
+ m_saveBookmarksTimer->setSingleShot(true);
+ connect(m_saveBookmarksTimer, SIGNAL(timeout()), this, SLOT(saveBookmarks()));
}
PlacesItemModel::~PlacesItemModel()
{
+ saveBookmarks();
qDeleteAll(m_hiddenItems);
m_hiddenItems.clear();
}
+PlacesItem* PlacesItemModel::createPlacesItem(const QString& text,
+ const KUrl& url,
+ const QString& iconName)
+{
+ const KBookmark bookmark = PlacesItem::createBookmark(m_bookmarkManager, text, url, iconName);
+ PlacesItem* item = new PlacesItem(bookmark);
+ item->setGroup(groupName(url));
+ return item;
+}
+
PlacesItem* PlacesItemModel::placesItem(int index) const
{
return dynamic_cast<PlacesItem*>(item(index));
} else {
// Move all items of the model, where the "isHidden" property is true, to
// m_hiddenItems.
- //Q_ASSERT(m_hiddenItems.count() == count());
+ Q_ASSERT(m_hiddenItems.count() == count());
for (int i = count() - 1; i >= 0; --i) {
PlacesItem* visibleItem = placesItem(i);
if (visibleItem->isHidden()) {
}
}
-
-void PlacesItemModel::save()
-{
- // TODO: Temporary deactivated until 100 % backward compatibility is provided
- // m_bookmarkManager->emitChanged(m_bookmarkManager->root());
-}
-
void PlacesItemModel::onItemInserted(int index)
{
+ const PlacesItem* insertedItem = placesItem(index);
+ if (insertedItem) {
+ // Take care to apply the PlacesItemModel-order of the inserted item
+ // also to the bookmark-manager.
+ const KBookmark insertedBookmark = insertedItem->bookmark();
+
+ const PlacesItem* previousItem = placesItem(index - 1);
+ KBookmark previousBookmark;
+ if (previousItem) {
+ previousBookmark = previousItem->bookmark();
+ }
+
+ m_bookmarkManager->root().moveBookmark(insertedBookmark, previousBookmark);
+ }
+
if (index == count() - 1) {
// The item has been appended as last item to the list. In this
// case assure that it is also appended after the hidden items and
}
m_hiddenItems.insert(hiddenIndex, 0);
+ m_saveBookmarksTimer->start();
+
#ifdef PLACESITEMMODEL_DEBUG
kDebug() << "Inserted item" << index;
showModelState();
#endif
}
-void PlacesItemModel::onItemRemoved(int index)
+void PlacesItemModel::onItemRemoved(int index, KStandardItem* removedItem)
{
+ PlacesItem* placesItem = dynamic_cast<PlacesItem*>(removedItem);
+ if (placesItem) {
+ const KBookmark bookmark = placesItem->bookmark();
+ m_bookmarkManager->root().deleteBookmark(bookmark);
+ }
+
const int removeIndex = hiddenIndex(index);
Q_ASSERT(!m_hiddenItems[removeIndex]);
m_hiddenItems.removeAt(removeIndex);
+
+ m_saveBookmarksTimer->start();
+
#ifdef PLACESITEMMODEL_DEBUG
kDebug() << "Removed item" << index;
showModelState();
void PlacesItemModel::onItemChanged(int index, const QSet<QByteArray>& changedRoles)
{
+ const PlacesItem* changedItem = placesItem(index);
+ if (changedItem) {
+ // Take care to apply the PlacesItemModel-order of the inserted item
+ // also to the bookmark-manager.
+ const KBookmark insertedBookmark = changedItem->bookmark();
+
+ const PlacesItem* previousItem = placesItem(index - 1);
+ KBookmark previousBookmark;
+ if (previousItem) {
+ previousBookmark = previousItem->bookmark();
+ }
+
+ m_bookmarkManager->root().moveBookmark(insertedBookmark, previousBookmark);
+ }
+
if (changedRoles.contains("isHidden")) {
const PlacesItem* shownItem = placesItem(index);
Q_ASSERT(shownItem);
- const bool hide = shownItem->isHidden();
-
- if (!m_hiddenItemsShown && hide) {
+ if (!m_hiddenItemsShown && shownItem->isHidden()) {
m_hiddenItemToRemove = index;
QTimer::singleShot(0, this, SLOT(removeHiddenItem()));
}
}
+ m_saveBookmarksTimer->start();
}
void PlacesItemModel::slotDeviceAdded(const QString& udi)
PlacesItem* hiddenItem = new PlacesItem(*shownItem);
removeItem(m_hiddenItemToRemove);
m_hiddenItems.insert(newIndex, hiddenItem);
+ m_saveBookmarksTimer->start();
}
m_hiddenItemToRemove = -1;
}
+
+void PlacesItemModel::saveBookmarks()
+{
+ // TODO: Temporary deactivated until 100 % backward compatibility is provided
+ // m_bookmarkManager->emitChanged(m_bookmarkManager->root());
+}
+
void PlacesItemModel::loadBookmarks()
{
KBookmarkGroup root = m_bookmarkManager->root();
searchForGroup));
m_systemBookmarks.append(SystemBookmarkData(KUrl("search:/audio"),
"folder-sound",
- i18nc("@item Commonly Accessed", "Audio"),
+ i18nc("@item Commonly Accessed", "Audio Files"),
searchForGroup));
m_systemBookmarks.append(SystemBookmarkData(KUrl("search:/videos"),
"folder-video",