static inline QUrl urlForGroup(const KBookmark &group) { if ( group.url().isValid() ) return group.url(); else return QUrl::fromUserInput( group.fullText() ); }
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 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 HTMLExporter::visit(const KBookmark &bk) { // //qDebug() << "visit(" << bk.text() << ")"; if(bk.isSeparator()) { m_out << bk.fullText() << "<br>"<<endl; } else { if(m_showAddress) { m_out << bk.fullText() <<"<br>"<< endl; m_out << "<i><div style =\"margin-left: 1em\">" << bk.url().url().toUtf8() << "</div></i>"; } else { m_out << "<a href=\"" << bk.url().url().toUtf8() << "\">"; m_out << bk.fullText() << "</a><br>" << endl; } } }
void EditCommand::redo() { KBookmark bk = m_model->bookmarkManager()->findByAddress(mAddress); if(mCol==-2) { if (mOldValue.isEmpty()) mOldValue = bk.internalElement().attribute("toolbar"); bk.internalElement().setAttribute("toolbar", mNewValue); } else if(mCol==-1) { if (mOldValue.isEmpty()) mOldValue = bk.icon(); bk.setIcon(mNewValue); } else if(mCol==0) { if (mOldValue.isEmpty()) // only the first time, not when compressing changes in modify() mOldValue = bk.fullText(); kDebug() << "mOldValue=" << mOldValue; bk.setFullText(mNewValue); } else if(mCol==1) { if (mOldValue.isEmpty()) mOldValue = bk.url().prettyUrl(); const KUrl newUrl(mNewValue); if (!(newUrl.isEmpty() && !mNewValue.isEmpty())) // prevent emptied line if the currently entered url is invalid bk.setUrl(newUrl); } else if(mCol==2) { if (mOldValue.isEmpty()) mOldValue = bk.description(); bk.setDescription(mNewValue); } m_model->emitDataChanged(bk); }
// 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(); }
static inline KUrl urlForGroup(const KBookmark &group) { if ( group.url().isValid() ) return group.url(); else return KUrl( group.fullText() ); }
// TODO *** drop improvements *** // open submenus on drop interactions bool KBookmarkBar::eventFilter( QObject *, QEvent *e ) { if (d->m_filteredToolbar) return false; // todo: make this limit the actions if ( e->type() == QEvent::DragLeave ) { removeTempSep(); } else if ( e->type() == QEvent::Drop ) { removeTempSep(); QDropEvent *dev = static_cast<QDropEvent*>( e ); QDomDocument doc; QList<KBookmark> list = KBookmark::List::fromMimeData( dev->mimeData(), doc ); if ( list.isEmpty() ) return false; if (list.count() > 1) kWarning(7043) << "Sorry, currently you can only drop one address " "onto the bookmark bar!"; KBookmark toInsert = list.first(); KBookmarkGroup parentBookmark = getToolbar(); if(d->m_sepIndex == 0) { KBookmark newBookmark = parentBookmark.addBookmark(toInsert.fullText(), toInsert.url() ); parentBookmark.moveBookmark( newBookmark, KBookmark() ); m_pManager->emitChanged( parentBookmark ); return true; } else { KBookmark after = parentBookmark.first(); for(int i=0; i < d->m_sepIndex - 1 ; ++i) after = parentBookmark.next(after); KBookmark newBookmark = parentBookmark.addBookmark(toInsert.fullText(), toInsert.url() ); parentBookmark.moveBookmark( newBookmark, after ); m_pManager->emitChanged( parentBookmark ); return true; } } else if ( e->type() == QEvent::DragMove || e->type() == QEvent::DragEnter ) { QDragMoveEvent *dme = static_cast<QDragMoveEvent*>( e ); if (!KBookmark::List::canDecode( dme->mimeData() )) return false; //cache text, save positions (inserting the temporary widget changes the positions) if(e->type() == QEvent::DragEnter) { QDomDocument doc; const QList<KBookmark> list = KBookmark::List::fromMimeData( dme->mimeData(), doc ); if ( list.isEmpty() ) return false; d->tempLabel = list.first().url().pathOrUrl(); d->widgetPositions.clear(); for (int i = 0; i < m_toolBar->actions().count(); ++i) if (QWidget* button = m_toolBar->widgetForAction(m_toolBar->actions()[i])) { if(m_toolBar->orientation() == Qt::Horizontal) { if(QApplication::isLeftToRight()) { d->widgetPositions.push_back(button->geometry().right()); } else { d->widgetPositions.push_back(button->geometry().left()); } } else { d->widgetPositions.push_back(button->geometry().bottom()); } } } bool accept = handleToolbarDragMoveEvent(dme->pos(), d->m_actions, d->tempLabel); if (accept) { dme->accept(); return true; //Really? } } return false; }