summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2014-08-09 11:27:12 (GMT)
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-08-09 11:27:12 (GMT)
commitc7e003d7bce9980de51856527de227c439200379 (patch)
tree2314fbc5a6fc3dc98379c0e4206adb88cb820e37
parent7a9036ec2bc83196297537182c24b6640b2ffdec (diff)
Port to QCommandLineParser
-rw-r--r--core/bookmarkmanager.cpp2
-rw-r--r--core/fileprinter.cpp2
-rw-r--r--shell/main.cpp76
-rw-r--r--shell/shell.cpp11
-rw-r--r--shell/shell.h6
5 files changed, 51 insertions, 46 deletions
diff --git a/core/bookmarkmanager.cpp b/core/bookmarkmanager.cpp
index 52db81e..47d668d 100644
--- a/core/bookmarkmanager.cpp
+++ b/core/bookmarkmanager.cpp
@@ -160,7 +160,7 @@ QUrl BookmarkManager::Private::currentUrl() const
QString BookmarkManager::Private::currentTitle() const
{
-#pragma("KF5 porting: check if QUrl usage is right")
+#pragma message("KF5 porting: check if QUrl usage is right")
return url.isLocalFile() ? url.toLocalFile() : url.prettyUrl();
}
diff --git a/core/fileprinter.cpp b/core/fileprinter.cpp
index dd41075..456f9ac 100644
--- a/core/fileprinter.cpp
+++ b/core/fileprinter.cpp
@@ -100,7 +100,7 @@ int FilePrinter::doPrintFiles( QPrinter &printer, QStringList fileList, FileDele
kDebug(OkularDebug) << "Executing" << exe << "with arguments" << argList;
ret = KProcess::execute( exe, argList );
-#pragma("KF5: Fix PostScript printing")
+#pragma message("KF5: Fix PostScript printing")
// } else if ( inputFileInfo.suffix() == "pdf" && printer.outputFormat() == QPrinter::PostScriptFormat && pdf2psAvailable() ) {
// exe = "pdf2ps";
// argList << fileList[0] << printer.outputFileName();
diff --git a/shell/main.cpp b/shell/main.cpp
index 61e2113..5cb2d77 100644
--- a/shell/main.cpp
+++ b/shell/main.cpp
@@ -13,18 +13,25 @@
***************************************************************************/
#include "shell.h"
-#include <kapplication.h>
-#include <kcmdlineargs.h>
+
+
#include <klocale.h>
#include <QtDBus/qdbusinterface.h>
#include <QTextStream>
#include <kwindowsystem.h>
+#include <QApplication>
+#include <KAboutData>
+#include <KLocalizedString>
+#include <QCommandLineParser>
+#include <QCommandLineOption>
#include "aboutdata.h"
#include "shellutils.h"
-static bool attachUniqueInstance(KCmdLineArgs* args)
+#include <kapplication.h>
+
+static bool attachUniqueInstance(QCommandLineParser* args)
{
- if (!args->isSet("unique") || args->count() != 1)
+ if (!args->isSet("unique") || args->positionalArguments().count() != 1)
return false;
QDBusInterface iface("org.kde.okular", "/okular", "org.kde.okular");
@@ -35,9 +42,9 @@ static bool attachUniqueInstance(KCmdLineArgs* args)
if (args->isSet("print"))
iface.call("enableStartWithPrint");
if (args->isSet("page"))
- iface.call("openDocument", ShellUtils::urlFromArg(args->arg(0), ShellUtils::qfileExistFunc(), args->getOption("page")).url());
+ iface.call("openDocument", ShellUtils::urlFromArg(args->positionalArguments().at(0), ShellUtils::qfileExistFunc(), args->value("page")).url());
else
- iface.call("openDocument", ShellUtils::urlFromArg(args->arg(0), ShellUtils::qfileExistFunc()).url());
+ iface.call("openDocument", ShellUtils::urlFromArg(args->positionalArguments().at(0), ShellUtils::qfileExistFunc()).url());
if (args->isSet("raise")) {
iface2.call("tryRaise");
}
@@ -46,9 +53,9 @@ static bool attachUniqueInstance(KCmdLineArgs* args)
}
// Ask an existing non-unique instance to open new tabs
-static bool attachExistingInstance( KCmdLineArgs* args )
+static bool attachExistingInstance( QCommandLineParser* args )
{
- if ( args->count() < 1 )
+ if ( args->positionalArguments().count() < 1 )
return false;
const QStringList services = QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
@@ -67,7 +74,7 @@ static bool attachExistingInstance( KCmdLineArgs* args )
bestService.reset( new QDBusInterface(service, "/okularshell", "org.kde.okular") );
// Find a window that can handle our documents
- const QDBusReply<bool> reply = bestService->call( "canOpenDocs", args->count(), desktop );
+ const QDBusReply<bool> reply = bestService->call( "canOpenDocs", args->positionalArguments().count(), desktop );
if( reply.isValid() && reply.value() )
break;
@@ -78,10 +85,8 @@ static bool attachExistingInstance( KCmdLineArgs* args )
if ( !bestService )
return false;
- for( int i = 0; i < args->count(); ++i )
+ foreach ( QString arg, args->positionalArguments() )
{
- QString arg = args->arg( i );
-
// Copy stdin to temporary file which can be opened by the existing
// window. The temp file is automatically deleted after it has been
// opened. Not sure if this behavior is safe on all platforms.
@@ -104,10 +109,6 @@ static bool attachExistingInstance( KCmdLineArgs* args )
arg = tempFile->fileName();
}
- else
- {
- arg = args->url( i ).url();
- }
// Returns false if it can't fit another document
const QDBusReply<bool> reply = bestService->call( "openDocument", arg );
@@ -124,18 +125,22 @@ int main(int argc, char** argv)
{
KAboutData about = okularAboutData( "okular", I18N_NOOP( "Okular" ) );
- KCmdLineArgs::init(argc, argv, &about);
-
- KCmdLineOptions options;
- options.add("p");
- options.add("page <number>", ki18n("Page of the document to be shown"));
- options.add("presentation", ki18n("Start the document in presentation mode"));
- options.add("print", ki18n("Start with print dialog"));
- options.add("unique", ki18n("\"Unique instance\" control"));
- options.add("noraise", ki18n("Not raise window"));
- options.add("+[URL]", ki18n("Document to open. Specify '-' to read from stdin."));
- KCmdLineArgs::addCmdLineOptions( options );
- KApplication app;
+ QApplication app(argc, argv);
+ QCommandLineParser parser;
+ KAboutData::setApplicationData(aboutData);
+ parser.addVersionOption();
+ parser.addHelpOption();
+ //PORTING SCRIPT: adapt aboutdata variable if necessary
+ aboutData.setupCommandLine(&parser);
+ parser.process(app);
+ aboutData.processCommandLine(&parser);
+
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("p") << QLatin1String("page"), i18n("Page of the document to be shown"), QLatin1String("number")));
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("presentation"), i18n("Start the document in presentation mode")));
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("print"), i18n("Start with print dialog")));
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("unique"), i18n("\"Unique instance\" control")));
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("noraise"), i18n("Not raise window")));
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("+[URL]"), i18n("Document to open. Specify '-' to read from stdin.")));
// see if we are starting with session management
if (app.isSessionRestored())
@@ -143,16 +148,15 @@ int main(int argc, char** argv)
RESTORE(Shell);
} else {
// no session.. just start up normally
- KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
// try to attach to existing session, unique or not
- if (attachUniqueInstance(args) || attachExistingInstance(args))
+ if (attachUniqueInstance(&parser) || attachExistingInstance(&parser))
{
- args->clear();
+
return 0;
}
- if (args->isSet( "unique" ) && args->count() > 1)
+ if (parser.isSet( "unique" ) && parser.positionalArguments().count() > 1)
{
QTextStream stream(stderr);
stream << i18n( "Error: Can't open more than one document with the --unique switch" ) << endl;
@@ -160,15 +164,15 @@ int main(int argc, char** argv)
}
else
{
- Shell* shell = new Shell( args );
+ Shell* shell = new Shell( &parser );
shell->show();
- for ( int i = 0; i < args->count(); )
+ for ( int i = 0; i < parser.positionalArguments().count(); )
{
- if ( shell->openDocument( args->arg(i)) )
+ if ( shell->openDocument( parser.positionalArguments().at(i)) )
++i;
else
{
- shell = new Shell( args );
+ shell = new Shell( &parser );
shell->show();
}
}
diff --git a/shell/shell.cpp b/shell/shell.cpp
index d6ed51d..929aa21 100644
--- a/shell/shell.cpp
+++ b/shell/shell.cpp
@@ -63,7 +63,7 @@
static const char *shouldShowMenuBarComingFromFullScreen = "shouldShowMenuBarComingFromFullScreen";
static const char *shouldShowToolBarComingFromFullScreen = "shouldShowToolBarComingFromFullScreen";
-Shell::Shell(KCmdLineArgs* args, int argIndex)
+Shell::Shell(QCommandLineParser *args, int argIndex)
: KParts::MainWindow(), m_args(args), m_menuBarWasShown(true), m_toolBarWasShown(true)
#ifdef KActivities_FOUND
, m_activityResource(0)
@@ -71,8 +71,9 @@ Shell::Shell(KCmdLineArgs* args, int argIndex)
{
if (m_args && argIndex != -1)
{
- m_openUrl = ShellUtils::urlFromArg(m_args->arg(argIndex),
- ShellUtils::qfileExistFunc(), m_args->getOption("page"));
+ Q_ASSERT(m_args->positionalArguments().count() > argIndex);
+ m_openUrl = ShellUtils::urlFromArg(m_args->positionalArguments().at(argIndex),
+ ShellUtils::qfileExistFunc(), m_args->value("page"));
}
init();
}
@@ -129,7 +130,7 @@ void Shell::init()
readSettings();
m_unique = false;
- if (m_args && m_args->isSet("unique") && m_args->count() <= 1)
+ if (m_args && m_args->isSet("unique") && m_args->positionalArguments().count() <= 1)
{
m_unique = QDBusConnection::sessionBus().registerService("org.kde.okular");
if (!m_unique)
@@ -172,7 +173,7 @@ Shell::~Shell()
}
}
if ( m_args )
- m_args->clear();
+ m_args->clearPositionalArguments();
}
// Open a new document if we have space for it
diff --git a/shell/shell.h b/shell/shell.h
index 9761f4b..7139bfe 100644
--- a/shell/shell.h
+++ b/shell/shell.h
@@ -24,7 +24,7 @@
#include <QtDBus/QtDBus>
-class KCmdLineArgs;
+class QCommandLineParser;
class KRecentFilesAction;
class KToggleAction;
class KTabWidget;
@@ -54,7 +54,7 @@ public:
/**
* Constructor
*/
- explicit Shell(KCmdLineArgs* args = 0, int argIndex = -1);
+ explicit Shell(QCommandLineParser* args = 0, int argIndex = -1);
/**
* Default Destructor
@@ -128,7 +128,7 @@ private:
int findTabIndex( QObject* sender );
private:
- KCmdLineArgs* m_args;
+ QCommandLineParser* m_args;
KPluginFactory* m_partFactory;
KRecentFilesAction* m_recent;
QStringList m_fileformats;