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 WebBrowser::removeBookmarkMessageButtonPressed(const Plasma::MessageButton button) { if (button == Plasma::ButtonNo){ return; } const QModelIndexList list = m_bookmarkModel->match(m_bookmarkModel->index(0,0), BookmarkItem::UrlRole, m_url.prettyUrl()); if (!list.isEmpty()) { const QModelIndex &index = list.first(); BookmarkItem *item = dynamic_cast<BookmarkItem *>(m_bookmarkModel->itemFromIndex(index)); if (item) { KBookmark bookmark = item->bookmark(); bookmark.parentGroup().deleteBookmark(bookmark); m_bookmarkManager->save(); } if (item && item->parent()) { item->parent()->removeRow(index.row()); } else { m_bookmarkModel->removeRow(index.row()); } } m_addBookmark->setAction(m_addBookmarkAction); }
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 ); }
void CreateCommand::undo() { KBookmark bk = m_model->bookmarkManager()->findByAddress(m_to); Q_ASSERT(!bk.isNull() && !bk.parentGroup().isNull()); m_model->removeBookmark(bk); }
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 KonqSidebarBookmarkModule::slotMoved(QListViewItem *i, QListViewItem*, QListViewItem *after) { KonqSidebarBookmarkItem *item = dynamic_cast<KonqSidebarBookmarkItem*>( i ); if (!item) return; KBookmark bookmark = item->bookmark(); KBookmark afterBookmark; KonqSidebarBookmarkItem *afterItem = dynamic_cast<KonqSidebarBookmarkItem*>(after); if (afterItem) afterBookmark = afterItem->bookmark(); KBookmarkGroup oldParentGroup = bookmark.parentGroup(); KBookmarkGroup parentGroup; // try to get the parent group (assume that the QListViewItem has been reparented by KListView)... // if anything goes wrong, use the root. if (item->parent()) { bool error = false; KonqSidebarBookmarkItem *parent = dynamic_cast<KonqSidebarBookmarkItem*>( (item->parent()) ); if (!parent) { error = true; } else { if (parent->bookmark().isGroup()) parentGroup = parent->bookmark().toGroup(); else error = true; } if (error) parentGroup = KonqBookmarkManager::self()->root(); } else { // No parent! This means the user dropped it before the top level item // And KListView has moved the item there, we need to correct it tree()->moveItem(item, m_topLevelItem, 0L); parentGroup = KonqBookmarkManager::self()->root(); } // remove the old reference. oldParentGroup.deleteBookmark( bookmark ); // insert the new item. parentGroup.moveItem(bookmark, afterBookmark); // inform others about the changed groups. quite expensive, so do // our best to update them in only one emitChanged call. QString oldAddress = oldParentGroup.address(); QString newAddress = parentGroup.address(); if (oldAddress == newAddress) { KonqBookmarkManager::self()->emitChanged( parentGroup ); } else { int i = 0; while (true) { QChar c1 = oldAddress[i]; QChar c2 = newAddress[i]; if (c1 == QChar::null) { // oldParentGroup is probably parent of parentGroup. KonqBookmarkManager::self()->emitChanged( oldParentGroup ); break; } else if (c2 == QChar::null) { // parentGroup is probably parent of oldParentGroup. KonqBookmarkManager::self()->emitChanged( parentGroup ); break; } else { if (c1 == c2) { // step to the next character. ++i; } else { // ugh... need to update both groups separately. KonqBookmarkManager::self()->emitChanged( oldParentGroup ); KonqBookmarkManager::self()->emitChanged( parentGroup ); break; } } } } }
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); }