void KonqSidebarBookmarkModule::slotOpenTab() { KonqSidebarBookmarkItem *bi = dynamic_cast<KonqSidebarBookmarkItem*>( tree()->selectedItem() ); KBookmark bookmark; if (bi) { bookmark = bi->bookmark(); } else if(tree()->selectedItem() == m_topLevelItem) bookmark = KonqBookmarkManager::self()->root(); else return; DCOPRef ref(kapp->dcopClient()->appId(), tree()->topLevelWidget()->name()); if (bookmark.isGroup()) { KBookmarkGroup group = bookmark.toGroup(); bookmark = group.first(); while (!bookmark.isNull()) { if (!bookmark.isGroup() && !bookmark.isSeparator()) ref.call( "newTab(QString)", bookmark.url().url() ); bookmark = group.next(bookmark); } } else { ref.call( "newTab(QString)", bookmark.url().url() ); } }
void KonqSidebarBookmarkModule::slotOpenTab() { KonqSidebarBookmarkItem *bi = dynamic_cast<KonqSidebarBookmarkItem*>( tree()->selectedItem() ); KBookmark bookmark; if (bi) { bookmark = bi->bookmark(); } else if(tree()->selectedItem() == m_topLevelItem) bookmark = s_bookmarkManager->root(); else return; KParts::OpenUrlArguments args; args.setActionRequestedByUser(true); KParts::BrowserArguments browserArguments; browserArguments.setNewTab(true); if (bookmark.isGroup()) { KBookmarkGroup group = bookmark.toGroup(); bookmark = group.first(); while (!bookmark.isNull()) { if (!bookmark.isGroup() && !bookmark.isSeparator()) { emit tree()->createNewWindow(bookmark.url(), args, browserArguments); } bookmark = group.next(bookmark); } } else { emit tree()->createNewWindow(bookmark.url(), args, browserArguments); } }
void ActionsImpl::slotSort() { KEBApp::self()->bkInfo()->commitChanges(); KBookmark bk = KEBApp::self()->firstSelected(); Q_ASSERT(bk.isGroup()); SortCommand *cmd = new SortCommand(m_model, i18nc("(qtundo-format)", "Sort Alphabetically"), bk.address()); commandHistory()->addCommand(cmd); }
void ActionsImpl::slotSetAsToolbar() { KEBApp::self()->bkInfo()->commitChanges(); KBookmark bk = KEBApp::self()->firstSelected(); Q_ASSERT(bk.isGroup()); QUndoCommand *mcmd = CmdGen::setAsToolbar(m_model, bk); commandHistory()->addCommand(mcmd); }
void KonqSidebarBookmarkModule::slotProperties(KonqSidebarBookmarkItem *bi) { if (!bi) { bi = dynamic_cast<KonqSidebarBookmarkItem*>( tree()->selectedItem() ); if (!bi) return; } KBookmark bookmark = bi->bookmark(); QString folder = bookmark.isGroup() ? QString::null : bookmark.url().pathOrURL(); BookmarkEditDialog dlg( bookmark.fullText(), folder, 0, 0, i18n("Bookmark Properties") ); if ( dlg.exec() != KDialogBase::Accepted ) return; makeTextNodeMod(bookmark, "title", dlg.finalTitle()); if ( !dlg.finalUrl().isNull() ) { KURL u = KURL::fromPathOrURL(dlg.finalUrl()); bookmark.internalElement().setAttribute("href", u.url(0, 106)); } KBookmarkGroup parentBookmark = bookmark.parentGroup(); KonqBookmarkManager::self()->emitChanged( parentBookmark ); }
void BookmarkToolBar::startDrag() { KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(m_dragAction); if (action) { QMimeData *mimeData = new QMimeData; KBookmark bookmark = action->bookmark(); QByteArray address = bookmark.address().toLatin1(); mimeData->setData(BookmarkManager::bookmark_mime_type(), address); bookmark.populateMimeData(mimeData); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); if (bookmark.isGroup()) { drag->setPixmap(KIcon(bookmark.icon()).pixmap(24, 24)); } else { drag->setPixmap(IconManager::self()->iconForUrl(action->bookmark().url()).pixmap(24, 24)); } drag->start(Qt::MoveAction); connect(drag, SIGNAL(destroyed()), this, SLOT(dragDestroyed())); } }
void KonqSidebarBookmarkModule::slotDelete() { KonqSidebarBookmarkItem *bi = dynamic_cast<KonqSidebarBookmarkItem*>( tree()->selectedItem() ); if (!bi) return; KBookmark bookmark = bi->bookmark(); bool folder = bookmark.isGroup(); if (KMessageBox::warningYesNo( tree(), folder ? i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?").arg(bookmark.text()) : i18n("Are you sure you wish to remove the bookmark\n\"%1\"?").arg(bookmark.text()), folder ? i18n("Bookmark Folder Deletion") : i18n("Bookmark Deletion"), KGuiItem( i18n("&Delete"), "editdelete"), KStdGuiItem::cancel()) != KMessageBox::Yes ) return; KBookmarkGroup parentBookmark = bookmark.parentGroup(); parentBookmark.deleteBookmark( bookmark ); KonqBookmarkManager::self()->emitChanged( parentBookmark ); }
QList< BookmarkMatch > KDEBrowser::match(const QString& term, bool addEverything) { KBookmarkGroup bookmarkGroup = m_bookmarkManager->root(); QList< BookmarkMatch > matches; QStack<KBookmarkGroup> groups; KBookmark bookmark = bookmarkGroup.first(); while (!bookmark.isNull()) { // if (!context.isValid()) { // return; // } TODO: restore? if (bookmark.isSeparator()) { bookmark = bookmarkGroup.next(bookmark); continue; } if (bookmark.isGroup()) { // descend //kDebug (kdbg_code) << "descending into" << bookmark.text(); groups.push(bookmarkGroup); bookmarkGroup = bookmark.toGroup(); bookmark = bookmarkGroup.first(); while (bookmark.isNull() && !groups.isEmpty()) { // if (!context.isValid()) { // return; // } TODO: restore? bookmark = bookmarkGroup; bookmarkGroup = groups.pop(); bookmark = bookmarkGroup.next(bookmark); } continue; } BookmarkMatch bookmarkMatch(m_favicon, term, bookmark.text(), bookmark.url().url() ); bookmarkMatch.addTo(matches, addEverything); bookmark = bookmarkGroup.next(bookmark); while (bookmark.isNull() && !groups.isEmpty()) { // if (!context.isValid()) { // return; // } // TODO: restore? bookmark = bookmarkGroup; bookmarkGroup = groups.pop(); //kDebug(kdbg_code) << "ascending from" << bookmark.text() << "to" << bookmarkGroup.text(); bookmark = bookmarkGroup.next(bookmark); } } return matches; }
void KBookmarkBar::fillBookmarkBar(const KBookmarkGroup & parent) { if (parent.isNull()) return; for (KBookmark bm = parent.first(); !bm.isNull(); bm = parent.next(bm)) { // Filtered special cases if(d->m_filteredToolbar) { if(bm.isGroup() && !bm.showInToolbar() ) fillBookmarkBar(bm.toGroup()); if(!bm.showInToolbar()) continue; } if (!bm.isGroup()) { if ( bm.isSeparator() ) m_toolBar->addSeparator(); else { KAction *action = new KBookmarkAction( bm, m_pOwner, 0 ); m_toolBar->addAction(action); d->m_actions.append( action ); } } else { KBookmarkActionMenu *action = new KBookmarkActionMenu(bm, 0); action->setDelayed( false ); m_toolBar->addAction(action); d->m_actions.append( action ); KBookmarkMenu *menu = new KonqBookmarkMenu(m_pManager, m_pOwner, action, bm.address()); m_lstSubMenus.append( menu ); } } }
void KBookmarkDialogPrivate::fillGroup(QTreeWidgetItem *parentItem, const KBookmarkGroup &group, const KBookmarkGroup &selectGroup) { for (KBookmark bk = group.first(); !bk.isNull(); bk = group.next(bk)) { if (bk.isGroup()) { const KBookmarkGroup bkGroup = bk.toGroup(); QTreeWidgetItem* item = new KBookmarkTreeItem(parentItem, folderTree, bkGroup); if (selectGroup == bkGroup) { folderTree->setCurrentItem(item); } fillGroup(item, bkGroup, selectGroup); } } }
void ActionsImpl::slotRecursiveSort() { KEBApp::self()->bkInfo()->commitChanges(); KBookmark bk = KEBApp::self()->firstSelected(); Q_ASSERT(bk.isGroup()); KEBMacroCommand *mcmd = new KEBMacroCommand(i18nc("(qtundo-format)", "Recursive Sort")); KBookmarkGroupList lister(GlobalBookmarkManager::self()->mgr()); QList<KBookmark> bookmarks = lister.getList(bk.toGroup()); bookmarks << bk.toGroup(); for (QList<KBookmark>::ConstIterator it = bookmarks.constBegin(); it != bookmarks.constEnd(); ++it) { new SortCommand(m_model, "", (*it).address(), mcmd); } commandHistory()->addCommand(mcmd); }
void ActionsImpl::slotPaste() { KEBApp::self()->bkInfo()->commitChanges(); QString addr; KBookmark bk = KEBApp::self()->firstSelected(); if(bk.isGroup()) addr = bk.address() + "/0"; //FIXME internal else addr = bk.address(); QUndoCommand *mcmd = CmdGen::insertMimeSource( m_model, i18nc("(qtundo-format)", "Paste"), QApplication::clipboard()->mimeData(), addr); commandHistory()->addCommand(mcmd); }
void KonqSidebarBookmarkModule::slotCopyLocation() { KonqSidebarBookmarkItem *bi = dynamic_cast<KonqSidebarBookmarkItem*>( tree()->selectedItem() ); if (!bi) return; KBookmark bookmark = bi->bookmark(); if ( !bookmark.isGroup() ) { kapp->clipboard()->setData( KBookmarkDrag::newDrag(bookmark, 0), QClipboard::Selection ); kapp->clipboard()->setData( KBookmarkDrag::newDrag(bookmark, 0), QClipboard::Clipboard ); } }
void CmdHistory::slotCommandExecuted(KCommand *k) { KEBApp::self()->notifyCommandExecuted(); IKEBCommand * cmd = dynamic_cast<IKEBCommand *>(k); Q_ASSERT(cmd); KBookmark bk = CurrentMgr::bookmarkAt(cmd->affectedBookmarks()); Q_ASSERT(bk.isGroup()); CurrentMgr::self()->notifyManagers(bk.toGroup()); // sets currentItem to something sensible // if the currentItem was invalidated by executing // CreateCommand or DeleteManyCommand // otherwise does nothing // sensible is either a already selected item or cmd->currentAddress() ListView::self()->fixUpCurrent( cmd->currentAddress() ); }
void KonqSidebarBookmarkModule::slotDropped(KListView *, QDropEvent *e, QListViewItem *parent, QListViewItem *after) { if (!KBookmarkDrag::canDecode(e)) return; KBookmark afterBookmark; KonqSidebarBookmarkItem *afterItem = dynamic_cast<KonqSidebarBookmarkItem*>(after); if (afterItem) afterBookmark = afterItem->bookmark(); KBookmarkGroup parentGroup; // try to get the parent group... if (after) { parentGroup = afterBookmark.parentGroup(); } else if (parent) { if(KonqSidebarBookmarkItem *p = dynamic_cast<KonqSidebarBookmarkItem*>(parent)) { if (!p) return; KBookmark bm = p->bookmark(); if (bm.isGroup()) parentGroup = bm.toGroup(); else return; } else if(parent == m_topLevelItem) { parentGroup = KonqBookmarkManager::self()->root(); } } else { // it's most probably the root... parentGroup = KonqBookmarkManager::self()->root(); } QValueList<KBookmark> bookmarks = KBookmarkDrag::decode(e); // copy QValueList<KBookmark>::iterator it = bookmarks.begin(); for (;it != bookmarks.end(); ++it) { // insert new item. parentGroup.moveItem(*it, afterBookmark); } KonqBookmarkManager::self()->emitChanged( parentGroup ); }
void KonqSidebarBookmarkModule::slotDropped(K3ListView *, QDropEvent *e, Q3ListViewItem *parent, Q3ListViewItem *after) { if (!KBookmark::List::canDecode(e->mimeData())) return; KBookmark afterBookmark; KonqSidebarBookmarkItem *afterItem = dynamic_cast<KonqSidebarBookmarkItem*>(after); if (afterItem) afterBookmark = afterItem->bookmark(); KBookmarkGroup parentGroup; // try to get the parent group... if (after) { parentGroup = afterBookmark.parentGroup(); } else if (parent) { if(KonqSidebarBookmarkItem *p = dynamic_cast<KonqSidebarBookmarkItem*>(parent)) { if (!p) return; KBookmark bm = p->bookmark(); if (bm.isGroup()) parentGroup = bm.toGroup(); else return; } else if(parent == m_topLevelItem) { parentGroup = s_bookmarkManager->root(); } } else { // it's most probably the root... parentGroup = s_bookmarkManager->root(); } QDomDocument parentDocument; const KBookmark::List bookmarks = KBookmark::List::fromMimeData(e->mimeData(), parentDocument); // copy KBookmark::List::const_iterator it = bookmarks.constBegin(); for (;it != bookmarks.constEnd(); ++it) { // insert new item. parentGroup.moveBookmark(*it, afterBookmark); } s_bookmarkManager->emitChanged( parentGroup ); }
void BookmarkMenu::addOpenFolderInTabs() { KBookmarkGroup group = manager()->findByAddress(parentAddress()).toGroup(); if (!group.first().isNull()) { KBookmark bookmark = group.first(); while (bookmark.isGroup() || bookmark.isSeparator()) { bookmark = group.next(bookmark); } if (!bookmark.isNull()) { parentMenu()->addAction(rApp->bookmarkManager()->owner()->createAction(group, BookmarkOwner::OPEN_FOLDER)); } } }
void DeleteCommand::redo() { KBookmark bk = m_model->bookmarkManager()->findByAddress(m_from); Q_ASSERT(!bk.isNull()); if (m_contentOnly) { QDomElement groupRoot = bk.internalElement(); QDomNode n = groupRoot.firstChild(); while (!n.isNull()) { QDomElement e = n.toElement(); if (!e.isNull()) { // kDebug() << e.tagName(); } QDomNode next = n.nextSibling(); groupRoot.removeChild(n); n = next; } return; } // TODO - bug - unparsed xml is lost after undo, // we must store it all therefore //FIXME this removes the comments, that's bad! if (!m_cmd) { if (bk.isGroup()) { m_cmd = new CreateCommand(m_model, m_from, bk.fullText(), bk.icon(), bk.internalElement().attribute("folded") == "no"); m_subCmd = deleteAll(m_model, bk.toGroup()); m_subCmd->redo(); } else { m_cmd = (bk.isSeparator()) ? new CreateCommand(m_model, m_from) : new CreateCommand(m_model, m_from, bk.fullText(), bk.icon(), bk.url()); } } m_cmd->undo(); }
void BookmarksProtocol::echoFolder( const KBookmarkGroup &folder ) { if (sizeOfGroup(folder.toGroup(), true) > 1) { QString descriptionAsTitle = folder.description(); if (!descriptionAsTitle.isEmpty()) descriptionAsTitle.prepend(QLatin1String("\" title=\"")); if (folder.parentGroup() == tree) { if (config.readEntry("ShowBackgrounds", true)) echo("<ul style=\"background-image: url(/background/" + folder.icon() + ")\">"); else echo("<ul>"); echo ("<li class=\"title" + descriptionAsTitle + "\">" + folder.fullText() + "</li>"); } else { echo("<ul>"); echo ("<li class=\"title" + descriptionAsTitle + "\"><img src=\"/icon/" + folder.icon() + "\"/>" + folder.text() + "</li>"); } indent++; for (KBookmark bm = folder.first(); !bm.isNull(); bm = folder.next(bm)) { if (bm.isGroup()) echoFolder(bm.toGroup()); else if (bm.isSeparator()) echoSeparator(); else echoBookmark(bm); } indent--; echo("</ul>"); } }
void BookmarksContextMenu::addFolderActions() { KBookmarkGroup group = bookmark().toGroup(); if (bookmark().internalElement().attributeNode("toolbar").value() == "yes") { addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::UNSET_TOOLBAR_FOLDER)); } else { addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::SET_TOOLBAR_FOLDER)); } if (!group.first().isNull()) { KBookmark child = group.first(); while (child.isGroup() || child.isSeparator()) { child = group.next(child); } if (!child.isNull()) { addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::OPEN_FOLDER)); addSeparator(); } } addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::BOOKMARK_PAGE)); addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::NEW_FOLDER)); addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::NEW_SEPARATOR)); addSeparator(); addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::EDIT)); addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::DELETE)); }
void WebBrowser::fillGroup(BookmarkItem *parentItem, const KBookmarkGroup &group) { KBookmark it = group.first(); while (!it.isNull()) { BookmarkItem *bookmarkItem = new BookmarkItem(it); bookmarkItem->setEditable(false); if (it.isGroup()) { KBookmarkGroup grp = it.toGroup(); fillGroup( bookmarkItem, grp ); } if (parentItem) { parentItem->appendRow(bookmarkItem); } else { m_bookmarkModel->appendRow(bookmarkItem); } it = m_bookmarkManager->root().next(it); } }
void KonqSidebarBookmarkModule::fillGroup( KonqSidebarTreeItem * parentItem, KBookmarkGroup group ) { int n = 0; for ( KBookmark bk = group.first() ; !bk.isNull() ; bk = group.next(bk), ++n ) { KonqSidebarBookmarkItem * item = new KonqSidebarBookmarkItem( parentItem, m_topLevelItem, bk, n ); if ( bk.isGroup() ) { KBookmarkGroup grp = bk.toGroup(); fillGroup( item, grp ); QString address(grp.address()); if (m_folderOpenState.contains(address)) item->setOpen(m_folderOpenState[address]); else item->setOpen(false); } else if ( bk.isSeparator() ) item->setVisible( false ); else item->setExpandable( false ); } }
void BookmarksPanel::loadFoldedState(const QModelIndex &root) { QAbstractItemModel *model = panelTreeView()->model(); if (!model) return; int count = model->rowCount(root); QModelIndex index; for (int i = 0; i < count; ++i) { index = model->index(i, 0, root); if (index.isValid()) { KBookmark bm = bookmarkForIndex(index); if (bm.isGroup()) { panelTreeView()->setExpanded(index, bm.toGroup().isOpen()); loadFoldedState(index); } } } }
bool TestLinkItr::isApplicable(const KBookmark &bk) const { return !bk.isGroup() && !bk.isSeparator(); }
int main(int argc, char **argv) { const bool kdeRunning = kdeIsRunning(); KAboutData aboutData("kbookmarkmerger", I18N_NOOP("KBookmarkMerger"), "1.0", I18N_NOOP("Merges bookmarks installed by 3rd parties into the user's bookmarks"), KAboutData::License_BSD, I18N_NOOP("Copyright © 2005 Frerich Raabe")); aboutData.addAuthor("Frerich Raabe", I18N_NOOP("Original author"), "*****@*****.**"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions(cmdLineOptions); if(!kdeRunning) { KApplication::disableAutoDcopRegistration(); } KApplication app(false, false); app.disableSessionManagement(); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if(args->count() != 1) { kdError() << "No directory to scan for bookmarks specified." << endl; return 1; } KBookmarkManager *konqBookmarks = KBookmarkManager::userBookmarksManager(); QStringList mergedFiles; { KBookmarkGroup root = konqBookmarks->root(); for(KBookmark bm = root.first(); !bm.isNull(); bm = root.next(bm)) { if(bm.isGroup()) { continue; } QString mergedFrom = bm.metaDataItem("merged_from"); if(!mergedFrom.isNull()) { mergedFiles << mergedFrom; } } } bool didMergeBookmark = false; QString extraBookmarksDirName = QFile::decodeName(args->arg(0)); QDir extraBookmarksDir(extraBookmarksDirName, "*.xml"); if(!extraBookmarksDir.isReadable()) { kdError() << "Failed to read files in directory " << extraBookmarksDirName << endl; return 1; } for(unsigned int i = 0; i < extraBookmarksDir.count(); ++i) { const QString fileName = extraBookmarksDir[i]; if(mergedFiles.find(fileName) != mergedFiles.end()) { continue; } const QString absPath = extraBookmarksDir.filePath(fileName); KBookmarkManager *mgr = KBookmarkManager::managerForFile(absPath, false); KBookmarkGroup root = mgr->root(); for(KBookmark bm = root.first(); !bm.isNull(); bm = root.next(bm)) { if(bm.isGroup()) { continue; } bm.setMetaDataItem("merged_from", fileName); konqBookmarks->root().addBookmark(konqBookmarks, bm, false); didMergeBookmark = true; } } if(didMergeBookmark) { if(!konqBookmarks->save()) { kdError() << "Failed to write merged bookmarks." << endl; return 1; } if(kdeRunning) { konqBookmarks->notifyChanged(""); } } }
bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) { if (m_currentMenu && m_currentMenu->isVisible() && !m_currentMenu->rect().contains(m_currentMenu->mapFromGlobal(QCursor::pos()))) { // To switch root folders as in a menubar KBookmarkActionMenu* act = dynamic_cast<KBookmarkActionMenu *>(actionAt(mapFromGlobal(QCursor::pos()))); if (event->type() == QEvent::MouseMove && act && act->menu() != m_currentMenu) { m_currentMenu->hide(); QPoint pos = mapToGlobal(widgetForAction(act)->pos()); act->menu()->popup(QPoint(pos.x(), pos.y() + widgetForAction(act)->height())); } else if (event->type() == QEvent::MouseButtonPress && act) { m_currentMenu->hide(); } return QObject::eventFilter(watched, event); } switch (event->type()) { case QEvent::Show: { if (!m_filled) { BookmarkManager::self()->fillBookmarkBar(this); m_filled = true; } } break; case QEvent::ActionRemoved: { QActionEvent *actionEvent = static_cast<QActionEvent*>(event); if (actionEvent && actionEvent->action() != m_dropAction) { QWidget *widget = widgetForAction(actionEvent->action()); if (widget) { widget->removeEventFilter(this); } } } break; case QEvent::ParentChange: { QActionEvent *actionEvent = static_cast<QActionEvent*>(event); if (actionEvent && actionEvent->action() != m_dropAction) { QWidget *widget = widgetForAction(actionEvent->action()); if (widget) { widget->removeEventFilter(this); } } } break; case QEvent::DragEnter: { QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent*>(event); if (dragEvent->mimeData()->hasFormat(BookmarkManager::bookmark_mime_type()) || dragEvent->mimeData()->hasFormat("text/uri-list") || dragEvent->mimeData()->hasFormat("text/plain")) { QFrame* dropIndicatorWidget = new QFrame(this); dropIndicatorWidget->setFrameShape(QFrame::VLine); m_dropAction = insertWidget(actionAt(dragEvent->pos()), dropIndicatorWidget); dragEvent->accept(); } } break; case QEvent::DragLeave: { QDragLeaveEvent *dragEvent = static_cast<QDragLeaveEvent*>(event); if (m_checkedAction) { m_checkedAction->setCheckable(false); m_checkedAction->setChecked(false); } delete m_dropAction; m_dropAction = 0; dragEvent->accept(); } break; case QEvent::DragMove: { QDragMoveEvent *dragEvent = static_cast<QDragMoveEvent*>(event); if (dragEvent->mimeData()->hasFormat(BookmarkManager::bookmark_mime_type()) || dragEvent->mimeData()->hasFormat("text/uri-list") || dragEvent->mimeData()->hasFormat("text/plain")) { QAction *overAction = actionAt(dragEvent->pos()); KBookmarkActionInterface *overActionBK = dynamic_cast<KBookmarkActionInterface*>(overAction); QWidget *widgetAction = widgetForAction(overAction); if (overAction != m_dropAction && overActionBK && widgetAction && m_dropAction) { removeAction(m_dropAction); if (m_checkedAction) { m_checkedAction->setCheckable(false); m_checkedAction->setChecked(false); } if (!overActionBK->bookmark().isGroup()) { if ((dragEvent->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2)) { if (actions().count() > actions().indexOf(overAction) + 1) { insertAction(actions().at(actions().indexOf(overAction) + 1), m_dropAction); } else { addAction(m_dropAction); } } else { insertAction(overAction, m_dropAction); } } else { if ((dragEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() * 0.75)) { if (actions().count() > actions().indexOf(overAction) + 1) { insertAction(actions().at(actions().indexOf(overAction) + 1), m_dropAction); } else { addAction(m_dropAction); } } else if ((dragEvent->pos().x() - widgetAction->pos().x()) <= (widgetAction->width() * 0.25)) { insertAction(overAction, m_dropAction); } else { overAction->setCheckable(true); overAction->setChecked(true); m_checkedAction = overAction; } } dragEvent->accept(); } } } break; case QEvent::Drop: { QDropEvent *dropEvent = static_cast<QDropEvent*>(event); KBookmark bookmark; KBookmarkGroup root = BookmarkManager::self()->manager()->toolbar(); if (m_checkedAction) { m_checkedAction->setCheckable(false); m_checkedAction->setChecked(false); } if (dropEvent->mimeData()->hasFormat(BookmarkManager::bookmark_mime_type())) { QByteArray addresses = dropEvent->mimeData()->data(BookmarkManager::bookmark_mime_type()); bookmark = BookmarkManager::self()->findByAddress(QString::fromLatin1(addresses.data())); if (bookmark.isNull()) return false; } else if (dropEvent->mimeData()->hasFormat("text/uri-list")) { // DROP is URL QString url = dropEvent->mimeData()->urls().at(0).toString(); WebWindow *w = qobject_cast<WebWindow *>(parent()); QString title = url.contains(w->url().url()) ? w->title() : url; bookmark = root.addBookmark(title, url); } else if (dropEvent->mimeData()->hasFormat("text/plain")) { // DROP is TEXT QString url = dropEvent->mimeData()->text(); KUrl u(url); if (u.isValid()) { WebWindow *w = qobject_cast<WebWindow *>(parent()); QString title = url.contains(w->url().url()) ? w->title() : url; bookmark = root.addBookmark(title, url); } } else { return false; } QAction *destAction = actionAt(dropEvent->pos()); if (destAction && destAction == m_dropAction) { if (actions().indexOf(m_dropAction) > 0) { destAction = actions().at(actions().indexOf(m_dropAction) - 1); } else { destAction = actions().at(1); } } if (destAction) { KBookmarkActionInterface *destBookmarkAction = dynamic_cast<KBookmarkActionInterface *>(destAction); QWidget *widgetAction = widgetForAction(destAction); if (destBookmarkAction && !destBookmarkAction->bookmark().isNull() && widgetAction && bookmark.address() != destBookmarkAction->bookmark().address()) { KBookmark destBookmark = destBookmarkAction->bookmark(); if (!destBookmark.isGroup()) { if ((dropEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() / 2)) { root.moveBookmark(bookmark, destBookmark); } else { root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark)); } } else { if ((dropEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() * 0.75)) { root.moveBookmark(bookmark, destBookmark); } else if ((dropEvent->pos().x() - widgetAction->pos().x()) <= (widgetAction->width() * 0.25)) { root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark)); } else { destBookmark.toGroup().addBookmark(bookmark); } } BookmarkManager::self()->emitChanged(); } } else { root.deleteBookmark(bookmark); bookmark = root.addBookmark(bookmark); if (dropEvent->pos().x() < widgetForAction(actions().first())->pos().x()) { root.moveBookmark(bookmark, KBookmark()); } BookmarkManager::self()->emitChanged(); } dropEvent->accept(); } break; default: break; } QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); // These events need to be handled only for Bookmark actions and not the bar if (watched != this && mouseEvent) { switch (event->type()) { case QEvent::MouseButtonPress: // drag handling { QPoint pos = mapFromGlobal(QCursor::pos()); KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(actionAt(pos)); if (action && mouseEvent->button() != Qt::MiddleButton) { m_dragAction = actionAt(pos); m_startDragPos = pos; // The menu is displayed only when the mouse button is released if (action->bookmark().isGroup()) return true; } } break; case QEvent::MouseMove: { int distance = (mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength(); if (!m_currentMenu && distance >= QApplication::startDragDistance()) { startDrag(); } } break; case QEvent::MouseButtonRelease: { QPoint destPos = mapFromGlobal(QCursor::pos()); int distance = (destPos - m_startDragPos).manhattanLength(); KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(actionAt(destPos)); if (action) { if (action->bookmark().isGroup()) { if (mouseEvent->button() == Qt::MiddleButton) { BookmarkManager::self()->owner()->loadBookmarkFolder(action->bookmark()); } else if (distance < QApplication::startDragDistance()) { KBookmarkActionMenu *menu = dynamic_cast<KBookmarkActionMenu *>(actionAt(m_startDragPos)); QPoint actionPos = mapToGlobal(widgetForAction(menu)->pos()); menu->menu()->popup(QPoint(actionPos.x(), actionPos.y() + widgetForAction(menu)->height())); } } else { if (!action->bookmark().isNull() && !action->bookmark().isSeparator()) { if (mouseEvent->button() == Qt::MiddleButton) { BookmarkManager::self()->owner()->loadBookmarkInNewTab(action->bookmark()); } } } } } break; default: break; } } return QObject::eventFilter(watched, event); }
// SHUFFLE all these functions around, the order is just plain stupid void BookmarkInfoWidget::showBookmark(const KBookmark &bk) { // Fast exit if already shown, otherwise editing a title leads to a command after each keypress if (m_bk == bk) return; commitChanges(); m_bk = bk; if (m_bk.isNull()) { // all read only and blank m_title_le->setReadOnly(true); m_title_le->setText(QString()); m_url_le->setReadOnly(true); m_url_le->setText(QString()); m_comment_le->setReadOnly(true); m_comment_le->setText(QString()); m_visitdate_le->setReadOnly(true); m_visitdate_le->setText(QString()); m_credate_le->setReadOnly(true); m_credate_le->setText(QString()); m_visitcount_le->setReadOnly(true); m_visitcount_le->setText(QString()); return; } // read/write fields m_title_le->setReadOnly( (bk.isSeparator()|| !bk.hasParent() )? true : false); if (bk.fullText() != m_title_le->text()) m_title_le->setText(bk.fullText()); m_url_le->setReadOnly(bk.isGroup() || bk.isSeparator()); if (bk.isGroup()) { m_url_le->setText(QString()); } else { // Update the text if and only if the text represents a different URL to that // of the current bookmark - the old method, "m_url_le->text() != bk.url().pathOrUrl()", // created difficulties due to the ambiguity of converting URLs to text. (#172647) if (QUrl::fromUserInput(m_url_le->text()) != bk.url()) { const int cursorPosition = m_url_le->cursorPosition(); m_url_le->setText(bk.url().url(QUrl::PreferLocalFile)); m_url_le->setCursorPosition(cursorPosition); } } m_comment_le->setReadOnly((bk.isSeparator()|| !bk.hasParent()) ? true : false ); QString commentText = bk.description(); if (m_comment_le->text() != commentText) { const int cursorPosition = m_comment_le->cursorPosition(); m_comment_le->setText(commentText); m_comment_le->setCursorPosition(cursorPosition); } // readonly fields updateStatus(); }