ImportCommand* ImportCommand::performImport(KBookmarkModel* model, const QString &type, QWidget *top) { ImportCommand *importer = ImportCommand::importerFactory(model, type); Q_ASSERT(importer); QString mydirname = importer->requestFilename(); if (mydirname.isEmpty()) { delete importer; return 0; } int answer = KMessageBox::questionYesNoCancel( top, i18n("Import as a new subfolder or replace all the current bookmarks?"), i18nc("@title:window", "%1 Import", importer->visibleName()), KGuiItem(i18n("As New Folder")), KGuiItem(i18n("Replace"))); if (answer == KMessageBox::Cancel) { delete importer; return 0; } importer->import(mydirname, answer == KMessageBox::Yes); return importer; }
extern "C" KDE_EXPORT int kdemain(int argc, char **argv) { KLocale::setMainCatalogue("konqueror"); KAboutData aboutData("keditbookmarks", I18N_NOOP("Bookmark Editor"), VERSION, I18N_NOOP("Konqueror Bookmarks Editor"), KAboutData::License_GPL, I18N_NOOP("(c) 2000 - 2003, KDE developers")); aboutData.addAuthor("David Faure", I18N_NOOP("Initial author"), "*****@*****.**"); aboutData.addAuthor("Alexander Kellett", I18N_NOOP("Author"), "*****@*****.**"); KCmdLineArgs::init(argc, argv, &aboutData); KApplication::addCmdLineOptions(); KCmdLineArgs::addCmdLineOptions(options); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); bool isGui = !(args->isSet("exportmoz") || args->isSet("exportns") || args->isSet("exporthtml") || args->isSet("exportie") || args->isSet("exportopera") || args->isSet("importmoz") || args->isSet("importns") || args->isSet("importie") || args->isSet("importopera")); bool browser = args->isSet("browser"); KApplication::disableAutoDcopRegistration(); KApplication app(isGui, isGui); bool gotArg = (args->count() == 1); QString filename = gotArg ? QString::fromLatin1(args->arg(0)) : locateLocal("data", QString::fromLatin1("konqueror/bookmarks.xml")); if(!isGui) { CurrentMgr::self()->createManager(filename); CurrentMgr::ExportType exportType = CurrentMgr::MozillaExport; // uumm.. can i just set it to -1 ? int got = 0; const char *arg, *arg2 = 0, *importType = 0; if(arg = "exportmoz", args->isSet(arg)) { exportType = CurrentMgr::MozillaExport; arg2 = arg; got++; } if(arg = "exportns", args->isSet(arg)) { exportType = CurrentMgr::NetscapeExport; arg2 = arg; got++; } if(arg = "exporthtml", args->isSet(arg)) { exportType = CurrentMgr::HTMLExport; arg2 = arg; got++; } if(arg = "exportie", args->isSet(arg)) { exportType = CurrentMgr::IEExport; arg2 = arg; got++; } if(arg = "exportopera", args->isSet(arg)) { exportType = CurrentMgr::OperaExport; arg2 = arg; got++; } if(arg = "importmoz", args->isSet(arg)) { importType = "Moz"; arg2 = arg; got++; } if(arg = "importns", args->isSet(arg)) { importType = "NS"; arg2 = arg; got++; } if(arg = "importie", args->isSet(arg)) { importType = "IE"; arg2 = arg; got++; } if(arg = "importopera", args->isSet(arg)) { importType = "Opera"; arg2 = arg; got++; } if(!importType && arg2) { Q_ASSERT(arg2); // TODO - maybe an xbel export??? if(got > 1) // got == 0 isn't possible as !isGui is dependant on "export.*" KCmdLineArgs::usage(I18N_NOOP("You may only specify a single --export option.")); QString path = QString::fromLocal8Bit(args->getOption(arg2)); CurrentMgr::self()->doExport(exportType, path); } else if(importType) { if(got > 1) // got == 0 isn't possible as !isGui is dependant on "import.*" KCmdLineArgs::usage(I18N_NOOP("You may only specify a single --import option.")); QString path = QString::fromLocal8Bit(args->getOption(arg2)); ImportCommand *importer = ImportCommand::importerFactory(importType); importer->import(path, true); importer->execute(); CurrentMgr::self()->managerSave(); CurrentMgr::self()->notifyManagers(); } return 0; // error flag on exit?, 1? } QString address = args->isSet("address") ? QString::fromLocal8Bit(args->getOption("address")) : QString("/0"); QString caption = args->isSet("customcaption") ? QString::fromLocal8Bit(args->getOption("customcaption")) : QString::null; args->clear(); bool readonly = false; // passed by ref if(askUser(app, (gotArg ? filename : QString::null), readonly)) { KEBApp *toplevel = new KEBApp(filename, readonly, address, browser, caption); toplevel->show(); app.setMainWidget(toplevel); return app.exec(); } return 0; }