BookmarkHandler::BookmarkHandler(KActionCollection* collection, KMenu* menu, bool toplevel, QObject* parent) : QObject(parent), KBookmarkOwner(), _menu(menu), _toplevel(toplevel), _activeView(0) { setObjectName(QLatin1String("BookmarkHandler")); _file = KStandardDirs::locate("data", "konsole/bookmarks.xml"); if (_file.isEmpty()) _file = KStandardDirs::locateLocal("data", "konsole/bookmarks.xml"); KBookmarkManager* manager = KBookmarkManager::managerForFile(_file, "konsole"); manager->setUpdate(true); if (toplevel) _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, collection); else _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, 0); }
KFileBookmarkHandler::KFileBookmarkHandler( KFileDialog *dialog ) : QObject( dialog, "KFileBookmarkHandler" ), KBookmarkOwner(), m_dialog( dialog ) { m_menu = new KPopupMenu( dialog, "bookmark menu" ); QString file = locate( "data", "kfile/bookmarks.xml" ); if ( file.isEmpty() ) file = locateLocal( "data", "kfile/bookmarks.xml" ); KBookmarkManager *manager = KBookmarkManager::managerForFile( file, false); // import old bookmarks if ( !KStandardDirs::exists( file ) ) { QString oldFile = locate( "data", "kfile/bookmarks.html" ); if ( !oldFile.isEmpty() ) importOldBookmarks( oldFile, manager ); } manager->setUpdate( true ); manager->setShowNSBookmarks( false ); m_bookmarkMenu = new KBookmarkMenu( manager, this, m_menu, dialog->actionCollection(), true ); }
BookmarkHandler::BookmarkHandler(KActionCollection* collection, QMenu* menu, bool toplevel, QObject* parent) : QObject(parent), KBookmarkOwner(), _menu(menu), _toplevel(toplevel), _activeView(0) { setObjectName(QLatin1String("BookmarkHandler")); _file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konsole/bookmarks.xml")); if (_file.isEmpty()) { _file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/konsole"); QDir().mkpath(_file); _file += QStringLiteral("/bookmarks.xml"); } KBookmarkManager* manager = KBookmarkManager::managerForFile(_file, "konsole"); manager->setUpdate(true); if (toplevel) _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, collection); else _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, 0); }
bool BookmarkXXPort::exportContacts( const KABC::AddresseeList &list, const QString& ) { QString fileName = locateLocal( "data", "kabc/bookmarks.xml" ); KBookmarkManager *mgr = KBookmarkManager::managerForFile( fileName ); KBookmarkDomBuilder *builder = new KBookmarkDomBuilder( mgr->root(), mgr ); builder->connectImporter( this ); KABC::AddresseeList::ConstIterator it; emit newFolder( i18n( "AddressBook" ), false, "" ); for ( it = list.begin(); it != list.end(); ++it ) { if ( !(*it).url().isEmpty() ) { QString name = (*it).givenName() + " " + (*it).familyName(); emit newBookmark( name, (*it).url().url().latin1(), QString( "" ) ); } } emit endFolder(); delete builder; mgr->save(); KBookmarkMenu::DynMenuInfo menu; menu.name = i18n( "Addressbook Bookmarks" ); menu.location = fileName; menu.type = "xbel"; menu.show = true; KBookmarkMenu::setDynamicBookmarks( "kabc", menu ); return true; }
void XBELImportCommand::doExecute(const KBookmarkGroup &/*bkGroup*/) { // check if already open first??? KBookmarkManager *pManager = KBookmarkManager::managerForFile(m_fileName, QString()); QDomDocument doc = GlobalBookmarkManager::self()->mgr()->internalDocument(); // get the xbel QDomNode subDoc = pManager->internalDocument().namedItem("xbel").cloneNode(); if (subDoc.isProcessingInstruction()) subDoc = subDoc.nextSibling(); if (subDoc.isDocumentType()) subDoc = subDoc.nextSibling(); if (subDoc.nodeName() != "xbel") return; if (!folder().isEmpty()) { // transform into folder subDoc.toElement().setTagName("folder"); // clear attributes QStringList tags; for (int i = 0; i < subDoc.attributes().count(); i++) tags << subDoc.attributes().item(i).toAttr().name(); for (QStringList::const_iterator it = tags.constBegin(); it != tags.constEnd(); ++it) subDoc.attributes().removeNamedItem((*it)); subDoc.toElement().setAttribute("icon", m_icon); // give the folder a name QDomElement textElem = doc.createElement("title"); subDoc.insertBefore(textElem, subDoc.firstChild()); textElem.appendChild(doc.createTextNode(folder())); } // import and add it QDomNode node = doc.importNode(subDoc, true); if (!folder().isEmpty()) { GlobalBookmarkManager::self()->root().internalElement().appendChild(node); m_group = KBookmarkGroup(node.toElement()).address(); } else { QDomElement root = GlobalBookmarkManager::self()->root().internalElement(); QList<QDomElement> childList; QDomNode n = subDoc.firstChild().toElement(); while (!n.isNull()) { QDomElement e = n.toElement(); if (!e.isNull()) childList.append(e); n = n.nextSibling(); } QList<QDomElement>::Iterator it = childList.begin(); QList<QDomElement>::Iterator end = childList.end(); for (; it!= end ; ++it) root.appendChild((*it)); } }
void BookmarksContextMenu::addNullActions() { KBookmarkManager *mngr = manager(); if (mngr->toolbar().hasParent()) { addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::UNSET_TOOLBAR_FOLDER)); } addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::BOOKMARK_PAGE)); addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::NEW_FOLDER)); addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::NEW_SEPARATOR)); }
KBookmarkHandler::KBookmarkHandler( KDirOperator *parent, KPopupMenu* rootmenu ) : QObject( parent, "KBookmarkHandler" ) , KBookmarkOwner() { const QString file = Amarok::saveLocation() + "fileBrowserBookmarks.xml"; KBookmarkManager *manager = KBookmarkManager::managerForFile( file, false ); manager->setUpdate( true ); manager->setShowNSBookmarks( false ); new KBookmarkMenu( manager, this, rootmenu, 0, true ); }
void BookmarksListBox::dropEvent( QDropEvent *event ) { KURL::List urls; if (KURLDrag::decode(event, urls) && !urls.isEmpty()) { KBookmarkManager* manager = DolphinSettings::instance().bookmarkManager(); KBookmarkGroup root = manager->root(); KURL::List::iterator it; for(it=urls.begin(); it!=urls.end(); ++it) { root.addBookmark(manager, (*it).fileName(), (*it), "", false); } manager->emitChanged(root); } }
void KonqPopupMenuPrivate::slotPopupAddToBookmark() { KBookmarkGroup root; if (m_popupItemProperties.urlList().count() == 1) { const QUrl url = m_popupItemProperties.urlList().first(); const QString title = m_urlTitle.isEmpty() ? url.toDisplayString() : m_urlTitle; KBookmarkDialog dlg(m_bookmarkManager, m_parentWidget); dlg.addBookmark(title, url, QString()); } else { root = m_bookmarkManager->root(); Q_FOREACH (const QUrl &url, m_popupItemProperties.urlList()) { root.addBookmark(url.toDisplayString(), url, QString()); } m_bookmarkManager->emitChanged(root); } }
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; }
KateBookmarkHandler::KateBookmarkHandler( KateFileBrowser *parent, KMenu* kpopupmenu ) : QObject( parent ), KBookmarkOwner(), mParent( parent ), m_menu( kpopupmenu ) { setObjectName( "KateBookmarkHandler" ); if (!m_menu) m_menu = new KMenu( parent); QString file = KStandardDirs::locate( "data", "kate/fsbookmarks.xml" ); if ( file.isEmpty() ) file = KStandardDirs::locateLocal( "data", "kate/fsbookmarks.xml" ); KBookmarkManager *manager = KBookmarkManager::managerForFile( file, "kate" ); manager->setUpdate( true ); m_bookmarkMenu = new KBookmarkMenu( manager, this, m_menu, parent->actionCollection() ); }
KateBookmarkHandler::KateBookmarkHandler( KateFileBrowser *parent, QMenu* kpopupmenu ) : QObject( parent ), KBookmarkOwner(), mParent( parent ), m_menu( kpopupmenu ) { setObjectName( QStringLiteral ("KateBookmarkHandler") ); if (!m_menu) m_menu = new QMenu( parent); QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kate/fsbookmarks.xml")); if ( file.isEmpty() ) file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kate/fsbookmarks.xml"); KBookmarkManager *manager = KBookmarkManager::managerForFile( file, QStringLiteral("kate") ); manager->setUpdate( true ); m_bookmarkMenu = new KBookmarkMenu( manager, this, m_menu, parent->actionCollection() ); }
void BookmarksSettingsPage::applySettings() { // delete all bookmarks KBookmarkManager* manager = DolphinSettings::instance().bookmarkManager(); KBookmarkGroup root = manager->root(); KBookmark bookmark = root.first(); while (!bookmark.isNull()) { root.deleteBookmark(bookmark); bookmark = root.first(); } // add all items as bookmarks QListViewItem* item = m_listView->firstChild(); while (item != 0) { root.addBookmark(manager, item->text(NameIdx), KURL(item->text(URLIdx)), item->text(IconIdx)); // hidden column item = item->itemBelow(); } manager->emitChanged(root); }
void DolphinContextMenu::openViewportContextMenu() { // Parts of the following code have been taken // from the class KonqOperations located in // libqonq/konq_operations.h of Konqueror. // (Copyright (C) 2000 David Faure <*****@*****.**>) assert(m_fileInfo == 0); const int propertiesID = 100; const int bookmarkID = 101; KPopupMenu* popup = new KPopupMenu(m_dolphinView); Dolphin& dolphin = Dolphin::mainWin(); // setup 'Create New' menu KPopupMenu* createNewMenu = new KPopupMenu(); KAction* createFolderAction = dolphin.actionCollection()->action("create_folder"); if (createFolderAction != 0) { createFolderAction->plug(createNewMenu); } createNewMenu->insertSeparator(); KAction* action = 0; QPtrListIterator<KAction> fileGrouptIt(dolphin.fileGroupActions()); while ((action = fileGrouptIt.current()) != 0) { action->plug(createNewMenu); ++fileGrouptIt; } // TODO: not used yet. See documentation of Dolphin::linkGroupActions() // and Dolphin::linkToDeviceActions() in the header file for details. // //createNewMenu->insertSeparator(); // //QPtrListIterator<KAction> linkGroupIt(dolphin.linkGroupActions()); //while ((action = linkGroupIt.current()) != 0) { // action->plug(createNewMenu); // ++linkGroupIt; //} // //KPopupMenu* linkToDeviceMenu = new KPopupMenu(); //QPtrListIterator<KAction> linkToDeviceIt(dolphin.linkToDeviceActions()); //while ((action = linkToDeviceIt.current()) != 0) { // action->plug(linkToDeviceMenu); // ++linkToDeviceIt; //} // //createNewMenu->insertItem(i18n("Link to Device"), linkToDeviceMenu); const KURL& url = dolphin.activeView()->url(); if (url.protocol() == "trash") { popup->insertItem(i18n("Empty Deleted Items Folder"), emptyID); } else { popup->insertItem(SmallIcon("filenew"), i18n("Create New"), createNewMenu); } popup->insertSeparator(); KAction* pasteAction = dolphin.actionCollection()->action(KStdAction::stdName(KStdAction::Paste)); pasteAction->plug(popup); // setup 'View Mode' menu KPopupMenu* viewModeMenu = new KPopupMenu(); KAction* iconsMode = dolphin.actionCollection()->action("icons"); iconsMode->plug(viewModeMenu); KAction* detailsMode = dolphin.actionCollection()->action("details"); detailsMode->plug(viewModeMenu); KAction* previewsMode = dolphin.actionCollection()->action("previews"); previewsMode->plug(viewModeMenu); popup->insertItem(i18n("View Mode"), viewModeMenu); popup->insertSeparator(); popup->insertItem(i18n("Bookmark this folder"), bookmarkID); popup->insertSeparator(); popup->insertItem(i18n("Properties..."), propertiesID); int id = popup->exec(m_pos); if (id == emptyID) { KonqOperations::emptyTrash(); } else if (id == propertiesID) { new KPropertiesDialog(dolphin.activeView()->url()); } else if (id == bookmarkID) { const KURL& url = dolphin.activeView()->url(); KBookmark bookmark = EditBookmarkDialog::getBookmark(i18n("Add folder as bookmark"), url.filename(), url, "bookmark"); if (!bookmark.isNull()) { KBookmarkManager* manager = DolphinSettings::instance().bookmarkManager(); KBookmarkGroup root = manager->root(); root.addBookmark(manager, bookmark); manager->emitChanged(root); } } popup->deleteLater(); }
void BookmarksSidebarPage::slotContextMenuRequested(QListBoxItem* item, const QPoint& pos) { const int insertID = 1; const int editID = 2; const int deleteID = 3; const int addID = 4; QPopupMenu* popup = new QPopupMenu(); if (item == 0) { popup->insertItem(SmallIcon("filenew"), i18n("Add Bookmark..."), addID); } else { popup->insertItem(SmallIcon("filenew"), i18n("Insert Bookmark..."), insertID); popup->insertItem(SmallIcon("edit"), i18n("Edit..."), editID); popup->insertItem(SmallIcon("editdelete"), i18n("Delete"), deleteID); } KBookmarkManager* manager = DolphinSettings::instance().bookmarkManager(); KBookmarkGroup root = manager->root(); const int index = m_bookmarksList->index(m_bookmarksList->selectedItem()); const int result = popup->exec(pos); switch (result) { case insertID: { KBookmark newBookmark = EditBookmarkDialog::getBookmark(i18n("Insert Bookmark"), i18n("New bookmark"), KURL(), "bookmark"); if (!newBookmark.isNull()) { root.addBookmark(manager, newBookmark); if (index > 0) { KBookmark prevBookmark = DolphinSettings::instance().bookmark(index - 1); root.moveItem(newBookmark, prevBookmark); } else { // insert bookmark at first position (is a little bit tricky as KBookmarkGroup // only allows to move items after existing items) KBookmark firstBookmark = root.first(); root.moveItem(newBookmark, firstBookmark); root.moveItem(firstBookmark, newBookmark); } manager->emitChanged(root); } break; } case editID: { KBookmark oldBookmark = DolphinSettings::instance().bookmark(index); KBookmark newBookmark = EditBookmarkDialog::getBookmark(i18n("Edit Bookmark"), oldBookmark.text(), oldBookmark.url(), oldBookmark.icon()); if (!newBookmark.isNull()) { root.addBookmark(manager, newBookmark); root.moveItem(newBookmark, oldBookmark); root.deleteBookmark(oldBookmark); manager->emitChanged(root); } break; } case deleteID: { KBookmark bookmark = DolphinSettings::instance().bookmark(index); root.deleteBookmark(bookmark); manager->emitChanged(root); break; } case addID: { KBookmark bookmark = EditBookmarkDialog::getBookmark(i18n("Add Bookmark"), "New bookmark", KURL(), "bookmark"); if (!bookmark.isNull()) { root.addBookmark(manager, bookmark); manager->emitChanged(root); } } default: break; } delete popup; popup = 0; DolphinView* view = Dolphin::mainWin().activeView(); adjustSelection(view->url()); }
void DolphinContextMenu::openItemContextMenu() { // Parts of the following code have been taken // from the class KonqOperations located in // libqonq/konq_operations.h of Konqueror. // (Copyright (C) 2000 David Faure <*****@*****.**>) assert(m_fileInfo != 0); KPopupMenu* popup = new KPopupMenu(m_dolphinView); Dolphin& dolphin = Dolphin::mainWin(); const KURL::List urls = m_dolphinView->selectedURLs(); const KURL& url = dolphin.activeView()->url(); if (url.protocol() == "trash") { popup->insertItem(i18n("&Restore"), restoreID); } // insert 'Cut', 'Copy' and 'Paste' const KStdAction::StdAction actionNames[] = { KStdAction::Cut, KStdAction::Copy, KStdAction::Paste }; const int count = sizeof(actionNames) / sizeof(KStdAction::StdAction); for (int i = 0; i < count; ++i) { KAction* action = dolphin.actionCollection()->action(KStdAction::stdName(actionNames[i])); if (action != 0) { action->plug(popup); } } popup->insertSeparator(); // insert 'Rename' KAction* renameAction = dolphin.actionCollection()->action("rename"); renameAction->plug(popup); // insert 'Move to Trash' for local URLs, otherwise insert 'Delete' if (url.isLocalFile()) { KAction* moveToTrashAction = dolphin.actionCollection()->action("move_to_trash"); moveToTrashAction->plug(popup); } else { KAction* deleteAction = dolphin.actionCollection()->action("delete"); deleteAction->plug(popup); } // insert 'Bookmark this folder...' entry // urls is a list of selected items, so insert boolmark menu if // urls contains only one item, i.e. no multiple selection made if (m_fileInfo->isDir() && (urls.count() == 1)) { popup->insertItem(i18n("Bookmark this folder"), bookmarkID); } popup->insertSeparator(); // Insert 'Open With...' sub menu QValueVector<KService::Ptr> openWithVector; const int openWithID = insertOpenWithItems(popup, openWithVector); // Insert 'Actions' sub menu QValueVector<KDEDesktopMimeType::Service> actionsVector; insertActionItems(popup, actionsVector); // insert 'Properties...' entry popup->insertSeparator(); KAction* propertiesAction = dolphin.actionCollection()->action("properties"); propertiesAction->plug(popup); int id = popup->exec(m_pos); if (id == restoreID ) { KonqOperations::restoreTrashedItems(urls); } else if (id == bookmarkID) { const KURL selectedURL(m_fileInfo->url()); KBookmark bookmark = EditBookmarkDialog::getBookmark(i18n("Add folder as bookmark"), selectedURL.filename(), selectedURL, "bookmark"); if (!bookmark.isNull()) { KBookmarkManager* manager = DolphinSettings::instance().bookmarkManager(); KBookmarkGroup root = manager->root(); root.addBookmark(manager, bookmark); manager->emitChanged(root); } } else if (id >= actionsIDStart) { // one of the 'Actions' items has been selected KDEDesktopMimeType::executeService(urls, actionsVector[id - actionsIDStart]); } else if (id >= openWithIDStart) { // one of the 'Open With' items has been selected if (id == openWithID) { // the item 'Other...' has been selected KRun::displayOpenWithDialog(urls); } else { KService::Ptr servicePtr = openWithVector[id - openWithIDStart]; KRun::run(*servicePtr, urls); } } openWithVector.clear(); actionsVector.clear(); popup->deleteLater(); }
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(""); } } }