[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [rekonq/frameworks] src: Reimplement singleton mode the KF5 way
From: Andrea Diamantini <adjam7 () gmail ! com>
Date: 2014-07-12 17:39:07
Message-ID: E1X61GN-0000Ef-FC () scm ! kde ! org
[Download RAW message or body]
Git commit d9eadcd0e8d8b54a57ef3134a0d761858fc655dd by Andrea Diamantini.
Committed on 12/07/2014 at 17:38.
Pushed by adjam into branch 'frameworks'.
Reimplement singleton mode the KF5 way
I need yet a trick to resume rekonq calls
after first launch
M +45 -55 src/application.cpp
M +3 -1 src/application.h
M +37 -23 src/main.cpp
http://commits.kde.org/rekonq/d9eadcd0e8d8b54a57ef3134a0d761858fc655dd
diff --git a/src/application.cpp b/src/application.cpp
index ef7e6a9..efe8cb9 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -87,8 +87,6 @@ Application::Application(int &argc, char **argv)
updateConfiguration();
setWindowIcon(QIcon::fromTheme(QL1S("rekonq")));
-
- newInstance();
}
@@ -115,57 +113,44 @@ Application::~Application()
}
-int Application::newInstance()
+int Application::webAppInstance(const QStringList &args)
{
- QStringList args = arguments();
-
- // not that easy, indeed
- // We have to consider 3 variables here:
- // 1) Is first load?
- // 2) Are there arguments?
- // 3) Is rekonq recovering from crash?
- // so, we have 8 possible cases...
- static bool isFirstLoad = true;
- bool areThereArguments = (args.count() > 1);
- bool hasToBeRecoveredFromCrash = (ReKonfig::recoverOnCrash() > 0);
- // note that hasToBeRecoveredFromCrash is always true if it is not the first \
load
- // !isFirstLoad -> hasToBeRecoveredFromCrash
+ qDebug() << "WEBAPP MODE...";
- qDebug() << "is first load? " << isFirstLoad;
- qDebug() << "are there arguments? " << areThereArguments;
- qDebug() << "is rekonq crashed? " << hasToBeRecoveredFromCrash;
+ if (args.count() == 0)
+ {
+ KMessageBox::error(0, i18n("Cannot launch webapp mode without an URL to \
load"), i18n("Error") ); + return 1;
+ }
- bool incognito = false; // FIXMEargs->isSet("incognito");
- bool webapp = false; // FIXME args->isSet("webapp");
+ if (args.count() > 1)
+ {
+ KMessageBox::error(0, i18n("Cannot load more than one URL in webapp mode"), \
i18n("Error") ); + return 1;
+ }
- if (webapp)
+ QUrl u = QUrl(args.at(0));
+ if (!u.isLocalFile() || !QFile::exists(u.toLocalFile()))
{
- qDebug() << "WEBAPP MODE...";
- if (!areThereArguments)
- {
- KMessageBox::error(0, i18n("Error"), i18n("Cannot launch webapp mode \
without an URL to load"));
- return 1;
- }
+ u = UrlResolver::urlFromTextTyped(args.at(0));
+ }
+ qDebug() << "URL: " << u;
- if (args.count() > 1)
- {
- KMessageBox::error(0, i18n("Error"), i18n("Cannot load more than one URL \
in webapp mode"));
- return 1;
- }
+ loadUrl(u, Rekonq::WebApp);
- QUrl u = QUrl(args.at(0));
- if (!u.isLocalFile() || !QFile::exists(u.toLocalFile()))
- {
- u = UrlResolver::urlFromTextTyped(args.at(0));
- }
- qDebug() << "URL: " << u;
+// KStartupInfo::appStarted();
+// isFirstLoad = false;
+ return 0;
+}
- loadUrl(u, Rekonq::WebApp);
- KStartupInfo::appStarted();
- isFirstLoad = false;
- return 0;
- }
+int Application::windowInstance(const QStringList &args, bool incognito)
+{
+ // FIXME: what about this? How can we know this is the first load or not?
+ bool isFirstLoad = true;
+
+ bool areThereArguments = (args.count() > 0);
+ bool hasToBeRecoveredFromCrash = (ReKonfig::recoverOnCrash() > 0);
if (areThereArguments)
{
@@ -173,7 +158,7 @@ int Application::newInstance()
// prepare URLS to load
QList<QUrl> urlList;
- for (int i = 1; i < args.count(); ++i)
+ for (int i = 0; i < args.count(); ++i)
{
const QUrl u = QUrl(args.at(i));
@@ -351,8 +336,8 @@ int Application::newInstance()
saveConfiguration();
}
- KStartupInfo::appStarted();
- isFirstLoad = false;
+// KStartupInfo::appStarted();
+// isFirstLoad = false;
return 0;
}
@@ -533,23 +518,28 @@ void Application::loadUrl(const QUrl& url, const \
Rekonq::OpenType& type) {
w = newWindow(true, true);
newType = Rekonq::CurrentTab;
+ w->loadUrl(url, newType);
+ return;
}
- else if (newType == Rekonq::NewWindow || (newType == Rekonq::NewTab || newType \
== Rekonq::NewFocusedTab)) +
+
+ if (newType == Rekonq::NewWindow)
{
w = newWindow();
newType = Rekonq::CurrentTab;
+ w->loadUrl(url, newType);
+ return;
}
- else
+
+ w = rekonqWindow();
+ if (!w)
{
- w = rekonqWindow();
- if (!w)
- {
- w = newWindow();
- newType = Rekonq::CurrentTab;
- }
+ w = newWindow();
+ newType = Rekonq::CurrentTab;
}
w->loadUrl(url, newType);
+ return;
}
diff --git a/src/application.h b/src/application.h
index f68be5e..7ccd60d 100644
--- a/src/application.h
+++ b/src/application.h
@@ -63,9 +63,11 @@ public:
Application(int &argc, char **argv);
~Application();
- int newInstance();
static Application *instance();
+ int webAppInstance(const QStringList &);
+ int windowInstance(const QStringList &, bool);
+
RekonqWindow *rekonqWindow();
RekonqWindowList rekonqWindowList();
diff --git a/src/main.cpp b/src/main.cpp
index 7473941..7592f7a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -43,6 +43,8 @@
// Qt Includes
#include <QCommandLineParser>
+#include <QCommandLineOption>
+
#include <QUrl>
@@ -181,7 +183,12 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
QL1S("pino@kde.org"));
KAboutData::setApplicationData(about);
- KDBusService* service = new KDBusService(KDBusService::Unique, &app);
+
+
+// -----------------------------------------------------------------------------------------------------------------
+
+ // register the app to dbus and set it as a singleton
+ KDBusService service(KDBusService::Unique);
// -----------------------------------------------------------------------------------------------------------------
@@ -191,29 +198,36 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
parser.setApplicationDescription(about.shortDescription());
parser.addHelpOption();
parser.addVersionOption();
-
-// // Initialize command line args
-// KCmdLineArgs::init(argc, argv, &about);
-//
-// // Define the command line options using KCmdLineOptions
-// KCmdLineOptions options;
-//
-// // adding options
-// options.add("incognito" , i18n("Open in incognito mode"));
-// options.add("webapp" , i18n("Open URL as web app (in a simple window)"));
-// options.add("+[URL]" , i18n("Location to open"));
-//
-// // Register the supported options
-// KCmdLineArgs::addCmdLineOptions(options);
-
-
-// #if defined(Q_WS_X11)
-// // On X11, the raster engine gives better performance than native.
-// QApplication::setGraphicsSystem(QL1S("raster"));
-// #endif
-//
-// KCmdLineArgs::setCwd(QDir::currentPath().toUtf8());
+ parser.addPositionalArgument(QL1S("URL"), i18n("Location to open"));
+
+ QCommandLineOption incognitoOption(QL1S("incognito"), i18n("Open in incognito \
mode")); + parser.addOption(incognitoOption);
+
+ QCommandLineOption webappOption(QL1S("webapp"), i18n("Open URL as web app (in a \
simple window)")); + parser.addOption(webappOption);
+
+
+ parser.process(app);
+
+ bool incognito = parser.isSet(incognitoOption);
+ qDebug() << "INCOGNITO: " << incognito;
+
+ bool webapp = parser.isSet(webappOption);
+ qDebug() << "WEBAPP: " << webapp;
+
+ const QStringList args = parser.positionalArguments();
+ qDebug() << "URLS: " << args;
+
+
+ if (webapp)
+ {
+ app.webAppInstance(args);
+ }
+ else
+ {
+ app.windowInstance(args, incognito);
+ }
// FIXME
// if (app.isSessionRestored())
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic