[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kate] /: QtSingleApplication is used on Windows & Mac per default
From: Christoph Cullmann <cullmann () kde ! org>
Date: 2016-06-18 8:27:18
Message-ID: E1bEBb4-0001DH-V5 () code ! kde ! org
[Download RAW message or body]
Git commit aeb6855f94c97bf088025a4764c162be4d6b4461 by Christoph Cullmann.
Committed on 18/06/2016 at 08:23.
Pushed by cullmann into branch 'master'.
QtSingleApplication is used on Windows & Mac per default
file passing to running instance should work now, using QJson to pass data instead of \
homebrewed format still no other things work and e.g. extra arguments like encoding \
are not passed on but better than no instance reuse as ATM
M +4 -6 addons/CMakeLists.txt
M +2 -4 kate/CMakeLists.txt
M +25 -19 kate/kateapp.cpp
M +3 -4 kate/kateapp.h
M +1 -1 kate/katetabbar.h
M +86 -46 kate/main.cpp
http://commits.kde.org/kate/aeb6855f94c97bf088025a4764c162be4d6b4461
diff --git a/addons/CMakeLists.txt b/addons/CMakeLists.txt
index d26d67e..c0b8f26 100644
--- a/addons/CMakeLists.txt
+++ b/addons/CMakeLists.txt
@@ -23,10 +23,8 @@ ecm_optional_add_subdirectory (kate-ctags)
# backtrace
ecm_optional_add_subdirectory (backtracebrowser)
-# file browser, atm guarded until we have a check for KIOWidgets
-if (NOT WIN32)
- ecm_optional_add_subdirectory (filebrowser)
-endif()
+# file browser
+ecm_optional_add_subdirectory (filebrowser)
# xml completion
ecm_optional_add_subdirectory (xmltools)
@@ -73,8 +71,8 @@ if(KF5NewStuff_FOUND)
ecm_optional_add_subdirectory (snippets)
endif()
-if(KF5Service_FOUND)
- # terminal tool view
+# terminal tool view
+if(KF5Service_FOUND AND NOT WIN32)
ecm_optional_add_subdirectory (konsole)
endif()
diff --git a/kate/CMakeLists.txt b/kate/CMakeLists.txt
index 74b2f78..b7e3c37 100644
--- a/kate/CMakeLists.txt
+++ b/kate/CMakeLists.txt
@@ -13,9 +13,6 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/qtsingleapplication
)
-option(USE_QT_SINGLE_APP "Use QtSingleApplication for single application in stead of \
DBus" OFF)
-
-
# collect the needed source files
set (KATE_LIBRARY_SRCS
kateappadaptor.cpp
@@ -94,7 +91,8 @@ set (KATE_APP_SRCS
main.cpp
)
-if (USE_QT_SINGLE_APP)
+# use single application instead of dbus on mac + windows
+if (APPLE OR WIN32)
set(singleapp_SRCS
qtsingleapplication/qtlocalpeer.cpp
qtsingleapplication/qtsingleapplication.cpp
diff --git a/kate/kateapp.cpp b/kate/kateapp.cpp
index 5c84e33..cea0a27 100644
--- a/kate/kateapp.cpp
+++ b/kate/kateapp.cpp
@@ -409,35 +409,41 @@ bool KateApp::eventFilter(QObject *obj, QEvent *event)
}
return true;
}
-
+
/**
* else: pass over to default implementation
*/
return QObject::eventFilter(obj, event);
}
-#ifdef USE_QT_SINGLE_APP
-void KateApp::remoteMessageReceived(const QString &message, QObject *socket)
+void KateApp::remoteMessageReceived(const QString &message, QObject *)
{
- //qDebug() << message;
- QStringList urlInfos = message.split(QLatin1Char(';'), QString::SkipEmptyParts);
- Q_FOREACH(QString urlInfo, urlInfos) {
- QStringList info = urlInfo.split(QStringLiteral("||"));
- //qDebug() << urlInfo << info;
- if (info.size() != 3) {
- continue;
- }
- QUrl url = QUrl::fromUserInput(info[0]);
- bool ok;
- int line = info[1].toInt(&ok);
- int column = info[2].toInt();
+ /**
+ * try to parse message, ignore if no object
+ */
+ const QJsonDocument jsonMessage = QJsonDocument::fromJson(message.toUtf8());
+ if (!jsonMessage.isObject())
+ return;
+ /**
+ * open all passed urls
+ */
+ const QJsonArray urls = \
jsonMessage.object().value(QLatin1String("urls")).toArray(); + \
Q_FOREACH(QJsonValue urlObject, urls) { + /**
+ * get url meta data
+ */
+ const QUrl url = \
urlObject.toObject().value(QLatin1String("url")).toVariant().toUrl(); + const \
int line = urlObject.toObject().value(QLatin1String("line")).toVariant().toInt(); + \
const int column = urlObject.toObject().value(QLatin1String("column")).toVariant().toInt();
+
+ /**
+ * open file + set line/column if requested
+ */
openUrl(url, QString(), false);
- if (ok) {
+ if (line >= 0 && column >= 0) {
setCursor(line, column);
}
+
}
}
-#endif
-
-
diff --git a/kate/kateapp.h b/kate/kateapp.h
index 8cc96ba..692614e 100644
--- a/kate/kateapp.h
+++ b/kate/kateapp.h
@@ -311,15 +311,14 @@ public Q_SLOTS:
return true;
}
-#ifdef USE_QT_SINGLE_APP
/**
- * A message is received from an external instance
+ * A message is received from an external instance, if we use \
QtSingleApplication + *
* \p message is a serialized message (at the moment just the file list \
separated by ';')
* \p socket is the QLocalSocket used for the communication
*/
void remoteMessageReceived(const QString &message, QObject *socket);
-#endif
-
+
protected:
/**
* Event filter for QApplication to handle mac os like file open
diff --git a/kate/katetabbar.h b/kate/katetabbar.h
index 2e5f5cb..3744de1 100644
--- a/kate/katetabbar.h
+++ b/kate/katetabbar.h
@@ -229,7 +229,7 @@ protected:
void paintEvent(QPaintEvent *event) override;
//! Request context menu
- void contextMenuEvent(QContextMenuEvent *ev);
+ void contextMenuEvent(QContextMenuEvent *ev) override;
//! Cycle through tabs
void wheelEvent(QWheelEvent * event) override;
diff --git a/kate/main.cpp b/kate/main.cpp
index e07b970..fd3cff5 100644
--- a/kate/main.cpp
+++ b/kate/main.cpp
@@ -212,12 +212,42 @@ int main(int argc, char **argv)
*/
aboutData.processCommandLine(&parser);
+ /**
+ * remember the urls we shall open
+ */
+ const QStringList urls = parser.positionalArguments();
-#ifndef USE_QT_SINGLE_APP
/**
- * use dbus, if available
+ * compute if we shall start a new instance or reuse
+ * an old one
+ * this will later be updated once more after detecting some
+ * things about already running kate's, like their sessions
+ */
+ bool force_new = parser.isSet(startNewInstanceOption);
+ if (!force_new) {
+ if (!(
+ parser.isSet(startSessionOption) ||
+ parser.isSet(startNewInstanceOption) ||
+ parser.isSet(usePidOption) ||
+ parser.isSet(useEncodingOption) ||
+ parser.isSet(gotoLineOption) ||
+ parser.isSet(gotoColumnOption) ||
+ parser.isSet(readStdInOption)
+ ) && (urls.isEmpty())) {
+ force_new = true;
+ }
+ }
+
+ /**
+ * only block, if files to open there....
+ */
+ const bool needToBlock = parser.isSet(startBlockingOption) && !urls.isEmpty();
+
+ /**
+ * use dbus, if available for linux and co.
* allows for resuse of running Kate instances
*/
+#ifndef USE_QT_SINGLE_APP
if (QDBusConnectionInterface * const sessionBusInterface = \
QDBusConnection::sessionBus().interface()) { /**
* try to get the current running kate instances
@@ -233,24 +263,6 @@ int main(int argc, char **argv)
}
QString serviceName;
- const QStringList urls = parser.positionalArguments();
-
- bool force_new = parser.isSet(startNewInstanceOption);
-
- if (!force_new) {
- if (!(
- parser.isSet(startSessionOption) ||
- parser.isSet(startNewInstanceOption) ||
- parser.isSet(usePidOption) ||
- parser.isSet(useEncodingOption) ||
- parser.isSet(gotoLineOption) ||
- parser.isSet(gotoColumnOption) ||
- parser.isSet(readStdInOption)
- ) && (urls.isEmpty())) {
- force_new = true;
- }
- }
-
QString start_session;
bool session_already_opened = false;
@@ -344,9 +356,6 @@ int main(int argc, char **argv)
bool tempfileSet = parser.isSet(tempfileOption);
- // only block, if files to open there....
- bool needToBlock = parser.isSet(startBlockingOption) && !urls.isEmpty();
-
QStringList tokens;
// open given files...
@@ -457,26 +466,56 @@ int main(int argc, char **argv)
return needToBlock ? app.exec() : 0;
}
}
- #else // USE_QT_SINGLE_APP
-
- if (!parser.isSet(startNewInstanceOption)) {
- QString urlsSerialized;
- const QStringList urls = parser.positionalArguments();
- foreach(const QString & url, urls) {
- UrlInfo info(url);
- //qDebug() << info.url.toString()<< info.cursor.line() << \
info.cursor.column();
- urlsSerialized += QStringLiteral("%1||%2||%3;")
- .arg(info.url.toString())
- .arg(info.cursor.line())
- .arg(info.cursor.column());
- }
- if (app.sendMessage(urlsSerialized)) {
- //qDebug() << "kate is already running";
- return 0;
+
+ /**
+ * for mac & windows: use QtSingleApplication
+ */
+#else
+ /**
+ * only try to reuse existing kate instances if not already forbidden by \
arguments + */
+ if (!force_new) {
+ /**
+ * any instance running we can use?
+ * later we could do here pid checks and stuff
+ */
+ bool instanceFound = app.isRunning();
+
+ /**
+ * if instance was found, send over all urls to be opened
+ */
+ if (instanceFound) {
+ /**
+ * tell single application to block if needed
+ */
+ app.setBlock(needToBlock);
+
+ /**
+ * construct one big message with all urls to open
+ * later we will add additional data to this
+ */
+ QVariantMap message;
+ QVariantList messageUrls;
+ foreach(const QString & url, urls) {
+ /**
+ * get url info and pack them into the message as extra element in \
urls list + */
+ UrlInfo info(url);
+ QVariantMap urlMessagePart;
+ urlMessagePart[QLatin1String("url")] = info.url;
+ urlMessagePart[QLatin1String("line")] = info.cursor.line();
+ urlMessagePart[QLatin1String("column")] = info.cursor.column();
+ messageUrls.append(urlMessagePart);
+ }
+ message[QLatin1String("urls")] = messageUrls;
+
+ /**
+ * try to send message, return success
+ */
+ return !app.sendMessage(QString::fromUtf8(QJsonDocument::fromVariant(QVariant(message)).toJson()));
}
}
-
- #endif // USE_QT_SINGLE_APP
+#endif // USE_QT_SINGLE_APP
/**
* if we arrive here, we need to start a new kate instance!
@@ -498,20 +537,21 @@ int main(int argc, char **argv)
return 0;
}
- #ifndef USE_QT_SINGLE_APP
+#ifndef USE_QT_SINGLE_APP
/**
* finally register this kate instance for dbus, don't die if no dbus is around!
*/
const KDBusService dbusService(KDBusService::Multiple | \
KDBusService::NoExitOnFailure);
-
- #else
-
+#else
+ /**
+ * else: connect the single application notifications
+ */
QObject::connect(&app, &SharedTools::QtSingleApplication::messageReceived,
&kateApp, &KateApp::remoteMessageReceived);
QObject::connect(&app, SIGNAL(messageReceived(QString,QObject*)),
&app, SLOT(activateWindow()));
- #endif
+#endif
/**
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic