void KBookmarkDialog::accept() { if (d->mode == KBookmarkDialogPrivate::NewFolder) { KBookmarkGroup parent = d->parentBookmark(); if (d->title->text().isEmpty()) { d->title->setText(QStringLiteral("New Folder")); } d->bm = parent.createNewFolder(d->title->text()); d->bm.setDescription(d->comment->text()); d->mgr->emitChanged(parent); } else if (d->mode == KBookmarkDialogPrivate::NewBookmark) { KBookmarkGroup parent = d->parentBookmark(); if (d->title->text().isEmpty()) { d->title->setText(QStringLiteral("New Bookmark")); } d->bm = parent.addBookmark(d->title->text(), QUrl(d->url->text()), d->icon); d->bm.setDescription(d->comment->text()); d->mgr->emitChanged(parent); } else if (d->mode == KBookmarkDialogPrivate::NewMultipleBookmarks) { KBookmarkGroup parent = d->parentBookmark(); if (d->title->text().isEmpty()) { d->title->setText(QStringLiteral("New Folder")); } d->bm = parent.createNewFolder(d->title->text()); d->bm.setDescription(d->comment->text()); foreach (const KBookmarkOwner::FutureBookmark &fb, d->list) { d->bm.toGroup().addBookmark(fb.title(), fb.url(), fb.icon()); } d->mgr->emitChanged(parent); } else if (d->mode == KBookmarkDialogPrivate::EditBookmark) {
void KonqSidebarBookmarkModule::slotCreateFolder() { KonqSidebarBookmarkItem *bi = dynamic_cast<KonqSidebarBookmarkItem*>( tree()->selectedItem() ); KBookmarkGroup parentGroup; if (bi) { if (bi->bookmark().isGroup()) { parentGroup = bi->bookmark().toGroup(); } else { parentGroup = bi->bookmark().parentGroup(); } } else if(tree()->selectedItem() == m_topLevelItem) { parentGroup = s_bookmarkManager->root(); } else { return; } bool ok; const QString str = KInputDialog::getText(i18nc("@title:window", "Create New Bookmark Folder"), i18n("New folder:"), QString(), &ok, tree()); if (!ok) { return; } KBookmark bookmark = parentGroup.createNewFolder(str); if (bi && !(bi->bookmark().isGroup())) { parentGroup.moveBookmark(bookmark, bi->bookmark()); } s_bookmarkManager->emitChanged( parentGroup ); }
void CreateCommand::redo() { QString parentAddress = KBookmark::parentAddress(m_to); KBookmarkGroup parentGroup = m_model->bookmarkManager()->findByAddress(parentAddress).toGroup(); QString previousSibling = KBookmark::previousAddress(m_to); // kDebug() << "previousSibling=" << previousSibling; KBookmark prev = (previousSibling.isEmpty()) ? KBookmark(QDomElement()) : m_model->bookmarkManager()->findByAddress(previousSibling); KBookmark bk = KBookmark(QDomElement()); const int pos = KBookmark::positionInParent(m_to); m_model->beginInsert(parentGroup, pos, pos); if (m_separator) { bk = parentGroup.createNewSeparator(); } else if (m_group) { Q_ASSERT(!m_text.isEmpty()); bk = parentGroup.createNewFolder(m_text); bk.internalElement().setAttribute("folded", (m_open ? "no" : "yes")); if (!m_iconPath.isEmpty()) { bk.setIcon(m_iconPath); } } else if(!m_originalBookmark.isNull()) { QDomElement element = m_originalBookmark.internalElement().cloneNode().toElement(); bk = KBookmark(element); parentGroup.addBookmark(bk); } else { bk = parentGroup.addBookmark(m_text, m_url, m_iconPath); } // move to right position parentGroup.moveBookmark(bk, prev); if (!(text().isEmpty()) && !parentAddress.isEmpty() ) { // open the parent (useful if it was empty) - only for manual commands Q_ASSERT( parentGroup.internalElement().tagName() != "xbel" ); parentGroup.internalElement().setAttribute("folded", "no"); } Q_ASSERT(bk.address() == m_to); m_model->endInsert(); }
void KonqSidebarBookmarkModule::slotCreateFolder() { KonqSidebarBookmarkItem *bi = dynamic_cast<KonqSidebarBookmarkItem*>( tree()->selectedItem() ); KBookmarkGroup parentGroup; if (bi) { if (bi->bookmark().isGroup()) parentGroup = bi->bookmark().toGroup(); else parentGroup = bi->bookmark().parentGroup(); } else if(tree()->selectedItem() == m_topLevelItem) { parentGroup = KonqBookmarkManager::self()->root(); } else return; KBookmark bookmark = parentGroup.createNewFolder(KonqBookmarkManager::self()); if(bi && !(bi->bookmark().isGroup())) parentGroup.moveItem(bookmark, bi->bookmark()); KonqBookmarkManager::self()->emitChanged( parentGroup ); }