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 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 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() ); } }
QList<KBookmark> BookmarkManager::find(const QString &text) { QList<KBookmark> list; KBookmarkGroup root = rootGroup(); if (!root.isNull()) for (KBookmark bookmark = root.first(); !bookmark.isNull(); bookmark = root.next(bookmark)) find(&list, bookmark, text); return list; }
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 KBookmarkMenu::fillBookmarks() { KBookmarkGroup parentBookmark = m_pManager->findByAddress(m_parentAddress).toGroup(); Q_ASSERT(!parentBookmark.isNull()); if (m_bIsRoot && !parentBookmark.first().isNull()) { // at least one bookmark m_parentMenu->addSeparator(); } for (KBookmark bm = parentBookmark.first(); !bm.isNull(); bm = parentBookmark.next(bm)) { m_parentMenu->addAction(actionForBookmark(bm)); } }
void BookmarksSidebarPage::updateBookmarks() { m_bookmarksList->clear(); KIconLoader iconLoader; KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root(); KBookmark bookmark = root.first(); while (!bookmark.isNull()) { m_bookmarksList->insertItem( BookmarkItem::fromKbookmark(bookmark, iconLoader) ); bookmark = root.next(bookmark); } connectToActiveView(); }
bool ClearFaviconsAction::action() { QDir favIconDir(KGlobal::dirs()->saveLocation( "cache", QLatin1String( "favicons/" ) )); QStringList saveTheseFavicons; KBookmarkManager* konqiBookmarkMgr; konqiBookmarkMgr = KBookmarkManager::managerForFile(KStandardDirs::locateLocal("data", QLatin1String("konqueror/bookmarks.xml")), QLatin1String( "konqueror" )); kDebug() << "saving the favicons that are in konqueror bookmarks" ; kDebug() << "opened konqueror bookmarks at " << konqiBookmarkMgr->path() ; // get the entire slew of bookmarks KBookmarkGroup konqiBookmarks = konqiBookmarkMgr->root(); // walk through the bookmarks, if they have a favicon we should keep it KBookmark bookmark = konqiBookmarks.first(); while (!bookmark.isNull()) { if ((bookmark.icon()).startsWith(QLatin1String("favicons/"))) { // pick out the name, throw .png on the end, and store the filename QRegExp regex(QLatin1String( "favicons/(.*)" )); regex.indexIn(bookmark.icon(), 0); kDebug() << "will save " << (regex.cap(1) + QLatin1String( ".png" )) ; saveTheseFavicons << (regex.cap(1) + QLatin1String( ".png" )); } bookmark = konqiBookmarks.next(bookmark); } favIconDir.setFilter( QDir::Files ); const QStringList entries = favIconDir.entryList(); // erase all files in favicon directory... for( QStringList::const_iterator it = entries.begin() ; it != entries.end() ; ++it) { // ...if we're not supposed to save them, of course if (!saveTheseFavicons.contains(*it)) { kDebug() << "removing " << *it ; if(!favIconDir.remove(*it)) { errMsg = i18n("A favicon could not be removed."); return false; } } } return true; }
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 BookmarksSidebarPage::adjustSelection(const KURL& url) { // TODO (remarked in dolphin/TODO): the following code is quite equal // to BookmarkSelector::updateSelection(). KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root(); KBookmark bookmark = root.first(); int maxLength = 0; int selectedIndex = -1; // Search the bookmark which is equal to the URL or at least is a parent URL. // If there are more than one possible parent URL candidates, choose the bookmark // which covers the bigger range of the URL. int i = 0; while (!bookmark.isNull()) { const KURL bookmarkURL = bookmark.url(); if (bookmarkURL.isParentOf(url)) { const int length = bookmarkURL.prettyURL().length(); if (length > maxLength) { selectedIndex = i; maxLength = length; } } bookmark = root.next(bookmark); ++i; } const bool block = m_bookmarksList->signalsBlocked(); m_bookmarksList->blockSignals(true); if (selectedIndex < 0) { // no bookmark matches, hence deactivate any selection const int currentIndex = m_bookmarksList->index(m_bookmarksList->selectedItem()); m_bookmarksList->setSelected(currentIndex, false); } else { // select the bookmark which is part of the current URL m_bookmarksList->setSelected(selectedIndex, true); } m_bookmarksList->blockSignals(block); }
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 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 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 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 ); } }
// 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; }
BookmarksSettingsPage::BookmarksSettingsPage(QWidget*parent) : SettingsPageBase(parent), m_addButton(0), m_removeButton(0), m_moveUpButton(0), m_moveDownButton(0) { QVBoxLayout* topLayout = new QVBoxLayout(parent, 2, KDialog::spacingHint()); const int spacing = KDialog::spacingHint(); QHBox* hBox = new QHBox(parent); hBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); hBox->setSpacing(spacing); hBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored); m_listView = new KListView(hBox); m_listView->addColumn(i18n("Icon")); m_listView->addColumn(i18n("Name")); m_listView->addColumn(i18n("Location")); m_listView->setResizeMode(QListView::LastColumn); m_listView->setColumnAlignment(0, Qt::AlignHCenter); m_listView->setAllColumnsShowFocus(true); m_listView->setSorting(-1); connect(m_listView, SIGNAL(selectionChanged()), this, SLOT(updateButtons())); connect(m_listView, SIGNAL(pressed(QListViewItem*)), this, SLOT(slotBookmarkPressed(QListViewItem*))); connect(m_listView, SIGNAL(doubleClicked(QListViewItem*, const QPoint&, int)), this, SLOT(slotBookmarkDoubleClicked(QListViewItem*, const QPoint&, int))); QVBox* buttonBox = new QVBox(hBox); buttonBox->setSpacing(spacing); const QSizePolicy buttonSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); m_addButton = new KPushButton(i18n("Add..."), buttonBox); connect(m_addButton, SIGNAL(clicked()), this, SLOT(slotAddButtonClicked())); m_addButton->setSizePolicy(buttonSizePolicy); m_editButton = new KPushButton(i18n("Edit..."), buttonBox); connect(m_editButton, SIGNAL(clicked()), this, SLOT(slotEditButtonClicked())); m_editButton->setSizePolicy(buttonSizePolicy); m_removeButton = new KPushButton(i18n("Remove"), buttonBox); connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveButtonClicked())); m_removeButton->setSizePolicy(buttonSizePolicy); m_moveUpButton = new KPushButton(i18n("Move Up"), buttonBox); connect(m_moveUpButton, SIGNAL(clicked()), this, SLOT(slotMoveUpButtonClicked())); m_moveUpButton->setSizePolicy(buttonSizePolicy); m_moveDownButton = new KPushButton(i18n("Move Down"), buttonBox); connect(m_moveDownButton, SIGNAL(clicked()), this, SLOT(slotMoveDownButtonClicked())); m_moveDownButton->setSizePolicy(buttonSizePolicy); // Add a dummy widget with no restriction regarding a vertical resizing. // This assures that the spacing between the buttons is not increased. new QWidget(buttonBox); topLayout->addWidget(hBox); // insert all editable bookmarks. KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root(); KBookmark bookmark = root.first(); QListViewItem* prev = 0; while (!bookmark.isNull()) { QListViewItem* item = new QListViewItem(m_listView); item->setPixmap(PixmapIdx, SmallIcon(bookmark.icon())); item->setText(NameIdx, bookmark.text()); item->setText(URLIdx, bookmark.url().prettyURL()); // add hidden column to be able to retrieve the icon name again item->setText(IconIdx, bookmark.icon()); m_listView->insertItem(item); if (prev != 0) { item->moveItem(prev); } prev = item; bookmark = root.next(bookmark); } m_listView->setSelected(m_listView->firstChild(), true); updateButtons(); }
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(""); } } }