diff --git a/src/kbookmarkmodel/model.cpp b/src/kbookmarkmodel/model.cpp index 0a9b8d21a..b7002a27c 100644 --- a/src/kbookmarkmodel/model.cpp +++ b/src/kbookmarkmodel/model.cpp @@ -1,494 +1,494 @@ /* This file is part of the KDE project Copyright (C) 2005 Daniel Teske Copyright (C) 2010 David Faure This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 or at your option version 3 as published by the Free Software Foundation. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "model.h" #include "treeitem_p.h" #include "commands.h" #include "commandhistory.h" #include #include #include #include #include #include #include class KBookmarkModel::Private { public: Private(KBookmarkModel* qq, const KBookmark& root, CommandHistory* commandHistory) : q(qq), mRoot(root), mCommandHistory(commandHistory), mInsertionData(nullptr), mIgnoreNext(0) { mRootItem = new TreeItem(root, nullptr); } ~Private() { delete mRootItem; mRootItem = nullptr; } void _kd_slotBookmarksChanged(const QString &groupAddress, const QString &caller = QString()); KBookmarkModel* q; TreeItem * mRootItem; KBookmark mRoot; CommandHistory* mCommandHistory; class InsertionData { public: InsertionData(const QModelIndex& parent, int first, int last) : mFirst(first), mLast(last) { mParentItem = static_cast(parent.internalPointer()); } void insertChildren() { mParentItem->insertChildren(mFirst, mLast); } TreeItem* mParentItem; int mFirst; int mLast; }; InsertionData* mInsertionData; int mIgnoreNext; }; KBookmarkModel::KBookmarkModel(const KBookmark& root, CommandHistory* commandHistory, QObject* parent) : QAbstractItemModel(parent), d(new Private(this, root, commandHistory)) { connect(commandHistory, &CommandHistory::notifyCommandExecuted, this, &KBookmarkModel::notifyManagers); Q_ASSERT(bookmarkManager()); // update when the model updates after a D-Bus signal, coming from this // process or from another one connect(bookmarkManager(), SIGNAL(changed(QString,QString)), this, SLOT(_kd_slotBookmarksChanged(QString,QString))); } void KBookmarkModel::setRoot(const KBookmark& root) { d->mRoot = root; resetModel(); } KBookmarkModel::~KBookmarkModel() { delete d; } void KBookmarkModel::resetModel() { beginResetModel(); delete d->mRootItem; d->mRootItem = new TreeItem(d->mRoot, nullptr); endResetModel(); } QVariant KBookmarkModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); //Text if (role == Qt::DisplayRole || role == Qt::EditRole) { const KBookmark bk = bookmarkForIndex(index); if (bk.address().isEmpty()) { if (index.column() == NameColumnId) return QVariant(i18nc("name of the container of all browser bookmarks", "Bookmarks")); else return QVariant(); } switch(index.column()) { case NameColumnId: return bk.fullText(); case UrlColumnId: return bk.url().url(QUrl::PreferLocalFile); case CommentColumnId: return bk.description(); case StatusColumnId: { QString text1 = bk.metaDataItem(QStringLiteral("favstate")); // favicon state QString text2 = bk.metaDataItem(QStringLiteral("linkstate")); if (text1.isEmpty() || text2.isEmpty()) return QVariant( text1 + text2 ); else return QVariant( text1 + " -- " + text2 ); } default: return QVariant(); //can't happen } } //Icon if (role == Qt::DecorationRole && index.column() == NameColumnId) { KBookmark bk = bookmarkForIndex(index); if (bk.address().isEmpty()) return QIcon::fromTheme(QStringLiteral("bookmarks")); return QIcon::fromTheme(bk.icon()); } //Special roles if (role == KBookmarkRole) { KBookmark bk = bookmarkForIndex(index); return QVariant::fromValue(bk); } return QVariant(); } //FIXME QModelIndex KBookmarkModel::buddy(const QModelIndex & index) //return parent for empty folder padders // no empty folder padders atm Qt::ItemFlags KBookmarkModel::flags(const QModelIndex &index) const { const Qt::ItemFlags baseFlags = QAbstractItemModel::flags(index); if (!index.isValid()) return (Qt::ItemIsDropEnabled | baseFlags); static const Qt::ItemFlags groupFlags = Qt::ItemIsDropEnabled; static const Qt::ItemFlags groupDragEditFlags = groupFlags | Qt::ItemIsDragEnabled | Qt::ItemIsEditable; static const Qt::ItemFlags groupEditFlags = groupFlags | Qt::ItemIsEditable; static const Qt::ItemFlags rootFlags = groupFlags; static const Qt::ItemFlags bookmarkFlags = nullptr; static const Qt::ItemFlags bookmarkDragEditFlags = bookmarkFlags | Qt::ItemIsDragEnabled | Qt::ItemIsEditable; static const Qt::ItemFlags bookmarkEditFlags = bookmarkFlags | Qt::ItemIsEditable; Qt::ItemFlags result = baseFlags; const int column = index.column(); const KBookmark bookmark = bookmarkForIndex(index); if (bookmark.isGroup()) { const bool isRoot = bookmark.address().isEmpty(); result |= (isRoot) ? rootFlags : (column == NameColumnId) ? groupDragEditFlags : (column == CommentColumnId) ? groupEditFlags : /*else*/ groupFlags; } else { result |= (column == NameColumnId) ? bookmarkDragEditFlags : (column != StatusColumnId) ? bookmarkEditFlags /* else */ : bookmarkFlags; } return result; } bool KBookmarkModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.isValid() && role == Qt::EditRole) { qDebug() << value.toString(); d->mCommandHistory->addCommand(new EditCommand(this, bookmarkForIndex(index).address(), index.column(), value.toString())); return true; } return false; } QVariant KBookmarkModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { QString result; switch(section) { case NameColumnId: result = i18nc("@title:column name of a bookmark", "Name"); break; case UrlColumnId: result = i18nc("@title:column name of a bookmark", "Location"); break; case CommentColumnId: result = i18nc("@title:column comment for a bookmark", "Comment"); break; case StatusColumnId: result = i18nc("@title:column status of a bookmark", "Status"); break; } return result; } else return QVariant(); } QModelIndex KBookmarkModel::index(int row, int column, const QModelIndex &parent) const { if (!parent.isValid()) return createIndex(row, column, d->mRootItem); TreeItem * item = static_cast(parent.internalPointer()); if (row == item->childCount()) {// Received drop below last row, simulate drop on last row return createIndex(row-1, column, item->child(row-1)); } return createIndex(row, column, item->child(row)); } QModelIndex KBookmarkModel::parent(const QModelIndex &index) const { if (!index.isValid()) { // qt asks for the parent of an invalid parent // either we are in a inconsistent case or more likely // we are dragging and dropping and qt didn't check // what itemAt() returned return index; } KBookmark bk = bookmarkForIndex(index);; const QString rootAddress = d->mRoot.address(); if (bk.address() == rootAddress) return QModelIndex(); KBookmarkGroup parent = bk.parentGroup(); TreeItem * item = static_cast(index.internalPointer()); if (parent.address() != rootAddress) return createIndex(parent.positionInParent(), 0, item->parent()); else //parent is root return createIndex(0, 0, item->parent()); } int KBookmarkModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) return static_cast(parent.internalPointer())->childCount(); else //root case return 1; // Only one child: "Bookmarks" } int KBookmarkModel::columnCount(const QModelIndex &) const { return NoOfColumnIds; } QModelIndex KBookmarkModel::indexForBookmark(const KBookmark& bk) const { TreeItem *item = d->mRootItem->treeItemForBookmark(bk); if (!item) { qWarning() << "Bookmark not found" << bk.address(); Q_ASSERT(item); } return createIndex(KBookmark::positionInParent(bk.address()) , 0, item); } void KBookmarkModel::emitDataChanged(const KBookmark& bk) { QModelIndex idx = indexForBookmark(bk); qDebug() << idx; emit dataChanged(idx, idx.sibling(idx.row(), columnCount()-1)); } static const char* s_mime_bookmark_addresses = "application/x-kde-bookmarkaddresses"; QMimeData * KBookmarkModel::mimeData(const QModelIndexList & indexes) const { QMimeData *mimeData = new QMimeData; KBookmark::List bookmarks; QByteArray addresses; Q_FOREACH(const QModelIndex& it, indexes) { if (it.column() == NameColumnId) { bookmarks.push_back(bookmarkForIndex(it)); if (!addresses.isEmpty()) addresses.append(';'); addresses.append(bookmarkForIndex(it).address().toLatin1()); qDebug() << "appended" << bookmarkForIndex(it).address(); } } bookmarks.populateMimeData(mimeData); mimeData->setData(s_mime_bookmark_addresses, addresses); return mimeData; } Qt::DropActions KBookmarkModel::supportedDropActions() const { return Qt::CopyAction | Qt::MoveAction; } QStringList KBookmarkModel::mimeTypes() const { return KBookmark::List::mimeDataTypes(); } bool KBookmarkModel::dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) { QModelIndex dropDestIndex; bool isInsertBetweenOp = false; if (row == -1) { dropDestIndex = parent; } else { isInsertBetweenOp = true; dropDestIndex = index(row, column, parent); } KBookmark dropDestBookmark = bookmarkForIndex(dropDestIndex); if (dropDestBookmark.isNull()) { // Presumably an invalid index: assume we want to place this in the root bookmark // folder. dropDestBookmark = d->mRoot; } QString addr = dropDestBookmark.address(); if (dropDestBookmark.isGroup() && !isInsertBetweenOp) { addr += QLatin1String("/0"); } // bookmarkForIndex(...) does not distinguish between the last item in the folder // and the point *after* the last item in the folder (and its hard to see how to // modify it so it does), so do the check here. if (isInsertBetweenOp && row == dropDestBookmark.positionInParent() + 1) { // Attempting to insert underneath the last item in a folder; adjust the address. addr = KBookmark::nextAddress(addr); } if (action == Qt::CopyAction) { KEBMacroCommand * cmd = CmdGen::insertMimeSource(this, QStringLiteral("Copy"), data, addr); d->mCommandHistory->addCommand(cmd); } else if (action == Qt::MoveAction) { if (data->hasFormat(s_mime_bookmark_addresses)) { KBookmark::List bookmarks; QList addresses = data->data(s_mime_bookmark_addresses).split(';'); - qSort(addresses); + std::sort(addresses.begin(), addresses.end()); Q_FOREACH(const QByteArray& address, addresses) { KBookmark bk = bookmarkManager()->findByAddress(QString::fromLatin1(address)); qDebug() << "Extracted bookmark:" << bk.address(); bookmarks.prepend(bk); // reverse order, so that we don't invalidate addresses (#287038) } KEBMacroCommand * cmd = CmdGen::itemsMoved(this, bookmarks, addr, false); d->mCommandHistory->addCommand(cmd); } else { qDebug()<<"NO FORMAT"; KEBMacroCommand * cmd = CmdGen::insertMimeSource(this, QStringLiteral("Copy"), data, addr); d->mCommandHistory->addCommand(cmd); } } return true; } KBookmark KBookmarkModel::bookmarkForIndex(const QModelIndex& index) const { if (!index.isValid()) { return KBookmark(); } return static_cast(index.internalPointer())->bookmark(); } void KBookmarkModel::beginInsert(const KBookmarkGroup& group, int first, int last) { Q_ASSERT(!d->mInsertionData); const QModelIndex parent = indexForBookmark(group); d->mInsertionData = new Private::InsertionData(parent, first, last); beginInsertRows(parent, first, last); } void KBookmarkModel::endInsert() { Q_ASSERT(d->mInsertionData); d->mInsertionData->insertChildren(); delete d->mInsertionData; d->mInsertionData = nullptr; endInsertRows(); } #if 0 // Probably correct, but not needed at the moment void KBookmarkModel::removeBookmarks(KBookmarkGroup parent, int first, int last) { const QModelIndex parentIndex = indexForBookmark(parent); beginRemoveRows(parentIndex, first, last); TreeItem* parentItem = static_cast(parentIndex.internalPointer()); // Go to the last bookmark to remove KBookmark bk = parent.first(); for (int i = 1; i < last; ++i) bk = parent.next(bk); // Then remove bookmarks, iterating backwards until 'first' // (so that numbering still works) for (int i = last; i >= first; --i) { KBookmark prev = parent.previous(bk); parent.deleteBookmark(bk); bk = prev; } parentItem->deleteChildren(first, last); endRemoveRows(); } #endif void KBookmarkModel::removeBookmark(const KBookmark &bookmark) { KBookmarkGroup parentGroup = bookmark.parentGroup(); const QModelIndex parentIndex = indexForBookmark(parentGroup); Q_ASSERT(parentIndex.isValid()); const int pos = bookmark.positionInParent(); beginRemoveRows(parentIndex, pos, pos); TreeItem* parentItem = static_cast(parentIndex.internalPointer()); Q_ASSERT(parentItem); parentGroup.deleteBookmark(bookmark); parentItem->deleteChildren(pos, pos); endRemoveRows(); } CommandHistory* KBookmarkModel::commandHistory() { return d->mCommandHistory; } KBookmarkManager* KBookmarkModel::bookmarkManager() { return d->mCommandHistory->bookmarkManager(); } void KBookmarkModel::Private::_kd_slotBookmarksChanged(const QString& groupAddress, const QString& caller) { Q_UNUSED(groupAddress); Q_UNUSED(caller); //qDebug() << "_kd_slotBookmarksChanged" << groupAddress << "caller=" << caller << "mIgnoreNext=" << mIgnoreNext; if (mIgnoreNext > 0) { // We ignore the first changed signal after every change we did --mIgnoreNext; return; } //qDebug() << " setRoot!"; q->setRoot(q->bookmarkManager()->root()); mCommandHistory->clearHistory(); } void KBookmarkModel::notifyManagers(const KBookmarkGroup& grp) { ++d->mIgnoreNext; //qDebug() << "notifyManagers -> mIgnoreNext=" << d->mIgnoreNext; bookmarkManager()->emitChanged(grp); } #include "moc_model.cpp" diff --git a/src/toplevel.cpp b/src/toplevel.cpp index 620046281..9e0bb1f53 100644 --- a/src/toplevel.cpp +++ b/src/toplevel.cpp @@ -1,474 +1,474 @@ /* This file is part of the KDE project Copyright (C) 2000 David Faure Copyright (C) 2002-2003 Alexander Kellett This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 or at your option version 3 as published by the Free Software Foundation. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "toplevel.h" #include #include "globalbookmarkmanager.h" #include "kbookmarkmodel/model.h" #include "bookmarkinfowidget.h" #include "actionsimpl.h" #include "exporters.h" #include "settings.h" #include "kbookmarkmodel/commands.h" #include "kbookmarkmodel/commandhistory.h" #include "kebsearchline.h" #include "bookmarklistview.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include KEBApp *KEBApp::s_topLevel = nullptr; KEBApp::KEBApp( const QString &bookmarksFile, bool readonly, const QString &address, bool browser, const QString &caption, const QString &dbusObjectName ) : KXmlGuiWindow(), m_bookmarksFilename(bookmarksFile), m_caption(caption), m_dbusObjectName(dbusObjectName), m_readOnly(readonly),m_browser(browser) { QDBusConnection::sessionBus().registerObject(QStringLiteral("/keditbookmarks"), this, QDBusConnection::ExportScriptableSlots); Q_UNUSED(address);//FIXME sets the current item m_cmdHistory = new CommandHistory(this); m_cmdHistory->createActions(actionCollection()); connect(m_cmdHistory, &CommandHistory::notifyCommandExecuted, this, &KEBApp::notifyCommandExecuted); GlobalBookmarkManager::self()->createManager(m_bookmarksFilename, m_dbusObjectName, m_cmdHistory); s_topLevel = this; createActions(); if (m_browser) createGUI(); else createGUI(QStringLiteral("keditbookmarks-genui.rc")); connect(qApp->clipboard(), &QClipboard::dataChanged, this, &KEBApp::slotClipboardDataChanged); m_canPaste = false; mBookmarkListView = new BookmarkListView(); mBookmarkListView->setModel( GlobalBookmarkManager::self()->model() ); mBookmarkListView->setSelectionMode(QAbstractItemView::ExtendedSelection); mBookmarkListView->loadColumnSetting(); mBookmarkListView->loadFoldedState(); KViewSearchLineWidget *searchline = new KViewSearchLineWidget(mBookmarkListView, this); mBookmarkFolderView = new BookmarkFolderView(mBookmarkListView, this); mBookmarkFolderView->expandAll(); QWidget * rightSide = new QWidget; QVBoxLayout *listLayout = new QVBoxLayout(rightSide); listLayout->setContentsMargins(0, 0, 0, 0); rightSide->setLayout(listLayout); listLayout->addWidget(searchline); listLayout->addWidget(mBookmarkListView); m_bkinfo = new BookmarkInfoWidget(mBookmarkListView, GlobalBookmarkManager::self()->model()); listLayout->addWidget(m_bkinfo); QSplitter *hsplitter = new QSplitter(this); hsplitter->setOrientation(Qt::Horizontal); hsplitter->addWidget(mBookmarkFolderView); hsplitter->addWidget(rightSide); hsplitter->setStretchFactor(1,1); setCentralWidget(hsplitter); slotClipboardDataChanged(); setAutoSaveSettings(); connect(mBookmarkListView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &KEBApp::selectionChanged); connect(mBookmarkFolderView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &KEBApp::selectionChanged); setCancelFavIconUpdatesEnabled(false); setCancelTestsEnabled(false); updateActions(); } void KEBApp::expandAll() { mBookmarkListView->expandAll(); } void KEBApp::collapseAll() { mBookmarkListView->collapseAll(); } QString KEBApp::bookmarkFilename() { return m_bookmarksFilename; } void KEBApp::reset(const QString & caption, const QString & bookmarksFileName) { //FIXME check this code, probably should be model()->setRoot instead of resetModel() m_caption = caption; m_bookmarksFilename = bookmarksFileName; GlobalBookmarkManager::self()->createManager(m_bookmarksFilename, m_dbusObjectName, m_cmdHistory); //FIXME this is still a memory leak (iff called by slotLoad) GlobalBookmarkManager::self()->model()->resetModel(); updateActions(); } void KEBApp::startEdit( Column c ) { const QModelIndexList & list = mBookmarkListView->selectionModel()->selectedIndexes(); QModelIndexList::const_iterator it, end; end = list.constEnd(); for(it = list.constBegin(); it != end; ++it) if( (*it).column() == int(c) && (mBookmarkListView->model()->flags(*it) & Qt::ItemIsEditable) ) mBookmarkListView->edit( *it ); } //FIXME clean up and remove unneeded things SelcAbilities KEBApp::getSelectionAbilities() const { SelcAbilities selctionAbilities; selctionAbilities.itemSelected = false; selctionAbilities.group = false; selctionAbilities.separator = false; selctionAbilities.urlIsEmpty = false; selctionAbilities.root = false; selctionAbilities.multiSelect = false; selctionAbilities.singleSelect = false; selctionAbilities.notEmpty = false; selctionAbilities.deleteEnabled = false; KBookmark nbk; QModelIndexList sel = mBookmarkListView->selectionModel()->selectedIndexes(); int columnCount; if(sel.count()) { nbk = mBookmarkListView->bookmarkForIndex(sel.first()); columnCount = mBookmarkListView->model()->columnCount(); } else { sel = mBookmarkFolderView->selectionModel()->selectedIndexes(); if(sel.count()) nbk = mBookmarkFolderView->bookmarkForIndex(sel.first()); columnCount = mBookmarkFolderView->model()->columnCount(); } if ( sel.count() > 0) { selctionAbilities.deleteEnabled = true; selctionAbilities.itemSelected = true; selctionAbilities.group = nbk.isGroup(); selctionAbilities.separator = nbk.isSeparator(); selctionAbilities.urlIsEmpty = nbk.url().isEmpty(); selctionAbilities.root = nbk.address() == GlobalBookmarkManager::self()->root().address(); selctionAbilities.multiSelect = (sel.count() > columnCount); selctionAbilities.singleSelect = (!selctionAbilities.multiSelect && selctionAbilities.itemSelected); } //FIXME check next line, if it actually works selctionAbilities.notEmpty = GlobalBookmarkManager::self()->root().first().hasParent(); /* //qDebug() <<"\nsa.itemSelected "<action(*it)->setEnabled(true); } } KBookmark KEBApp::firstSelected() const { QModelIndex index; const QModelIndexList & list = mBookmarkListView->selectionModel()->selectedIndexes(); if(list.count()) // selection in main listview, return bookmark for firstSelected return mBookmarkListView->bookmarkForIndex(*list.constBegin()); // no selection in main listview, fall back to selection in left tree const QModelIndexList & list2 = mBookmarkFolderView->selectionModel()->selectedIndexes(); return mBookmarkFolderView->bookmarkForIndex(*list2.constBegin()); } QString KEBApp::insertAddress() const { KBookmark current = firstSelected(); return (current.isGroup()) ? (current.address() + "/0") //FIXME internal representation used : KBookmark::nextAddress(current.address()); } static bool lessAddress(const QString& first, const QString& second) { QString a = first; QString b = second; if(a == b) return false; QString error(QStringLiteral("ERROR")); if(a == error) return false; if(b == error) return true; a += '/'; b += '/'; uint aLast = 0; uint bLast = 0; uint aEnd = a.length(); uint bEnd = b.length(); // Each iteration checks one "/"-delimeted part of the address // "" is treated correctly while(true) { // Invariant: a[0 ... aLast] == b[0 ... bLast] if(aLast + 1 == aEnd) //The last position was the last slash return true; // That means a is shorter than b if(bLast +1 == bEnd) return false; uint aNext = a.indexOf(QLatin1String("/"), aLast + 1); uint bNext = b.indexOf(QLatin1String("/"), bLast + 1); bool okay; uint aNum = a.midRef(aLast + 1, aNext - aLast - 1).toUInt(&okay); if(!okay) return false; uint bNum = b.midRef(bLast + 1, bNext - bLast - 1).toUInt(&okay); if(!okay) return true; if(aNum != bNum) return aNum < bNum; aLast = aNext; bLast = bNext; } } static bool lessBookmark(const KBookmark & first, const KBookmark & second) //FIXME Using internal represantation { return lessAddress(first.address(), second.address()); } KBookmark::List KEBApp::allBookmarks() const { KBookmark::List bookmarks; selectedBookmarksExpandedHelper(GlobalBookmarkManager::self()->root(), bookmarks); return bookmarks; } KBookmark::List KEBApp::selectedBookmarks() const { KBookmark::List bookmarks; const QModelIndexList & list = mBookmarkListView->selectionModel()->selectedIndexes(); if (!list.isEmpty()) { QModelIndexList::const_iterator it, end; end = list.constEnd(); for( it = list.constBegin(); it != end; ++it) { if((*it).column() != 0) continue; KBookmark bk = mBookmarkListView->bookmarkModel()->bookmarkForIndex(*it);; if(bk.address() != GlobalBookmarkManager::self()->root().address()) bookmarks.push_back( bk ); } - qSort(bookmarks.begin(), bookmarks.end(), lessBookmark); + std::sort(bookmarks.begin(), bookmarks.end(), lessBookmark); } else { bookmarks.push_back(firstSelected()); } return bookmarks; } KBookmark::List KEBApp::selectedBookmarksExpanded() const { KBookmark::List bookmarks = selectedBookmarks(); KBookmark::List result; KBookmark::List::const_iterator it, end; end = bookmarks.constEnd(); for(it = bookmarks.constBegin(); it != end; ++it) { selectedBookmarksExpandedHelper( *it, result ); } return result; } void KEBApp::selectedBookmarksExpandedHelper(const KBookmark& bk, KBookmark::List & bookmarks) const { //FIXME in which order parents should ideally be: parent then child // or child and then parents if(bk.isGroup()) { KBookmarkGroup parent = bk.toGroup(); KBookmark child = parent.first(); while(!child.isNull()) { selectedBookmarksExpandedHelper(child, bookmarks); child = parent.next(child); } } else { bookmarks.push_back( bk ); } } KEBApp::~KEBApp() { // Save again, just in case the user expanded/collapsed folders (#131127) GlobalBookmarkManager::self()->notifyManagers(); s_topLevel = nullptr; delete m_cmdHistory; delete m_actionsImpl; delete mBookmarkListView; delete GlobalBookmarkManager::self(); } KToggleAction* KEBApp::getToggleAction(const char *action) const { return static_cast(actionCollection()->action(action)); } void KEBApp::resetActions() { stateChanged(QStringLiteral("disablestuff")); stateChanged(QStringLiteral("normal")); if (!m_readOnly) stateChanged(QStringLiteral("notreadonly")); } void KEBApp::selectionChanged() { updateActions(); } void KEBApp::updateActions() { resetActions(); setActionsEnabled(getSelectionAbilities()); } void KEBApp::slotClipboardDataChanged() { // //qDebug() << "KEBApp::slotClipboardDataChanged"; if (!m_readOnly) { m_canPaste = KBookmark::List::canDecode( QApplication::clipboard()->mimeData()); updateActions(); } } /* -------------------------- */ void KEBApp::notifyCommandExecuted() { // //qDebug() << "KEBApp::notifyCommandExecuted()"; updateActions(); } /* -------------------------- */ void KEBApp::slotConfigureToolbars() { //PORT TO QT5 saveMainWindowSettings(KConfigGroup( KSharedConfig::openConfig(), "MainWindow") ); KEditToolBar dlg(actionCollection(), this); connect(&dlg, &KEditToolBar::newToolBarConfig, this, &KEBApp::slotNewToolbarConfig); dlg.exec(); } void KEBApp::slotNewToolbarConfig() { // called when OK or Apply is clicked createGUI(); applyMainWindowSettings(KConfigGroup(KSharedConfig::openConfig(), "MainWindow") ); } /* -------------------------- */