Merge lp:~zeller-benjamin/qtcreator-plugin-ubuntu/displayvar into lp:qtcreator-plugin-ubuntu

Proposed by Benjamin Zeller on 2016-08-29
Status: Merged
Approved by: Benjamin Zeller on 2016-08-29
Approved revision: 471
Merged at revision: 468
Proposed branch: lp:~zeller-benjamin/qtcreator-plugin-ubuntu/displayvar
Merge into: lp:qtcreator-plugin-ubuntu
Diff against target: 59 lines (+35/-0)
1 file modified
src/ubuntu/device/container/ubuntulocalrunconfiguration.cpp (+35/-0)
To merge this branch: bzr merge lp:~zeller-benjamin/qtcreator-plugin-ubuntu/displayvar
Reviewer Review Type Date Requested Status
Zoltan Balogh (community) 2016-08-29 Approve on 2016-08-29
Review via email: mp+304246@code.launchpad.net

Commit message

Use DISPLAY env var to detect and check the local X connection

Description of the change

Use DISPLAY env var to detect and check the local X connection

To post a comment you must log in.
Zoltan Balogh (bzoltan) wrote :

Correct

review: Approve
472. By Benjamin Zeller on 2016-08-29

-

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ubuntu/device/container/ubuntulocalrunconfiguration.cpp'
2--- src/ubuntu/device/container/ubuntulocalrunconfiguration.cpp 2016-08-18 07:15:14 +0000
3+++ src/ubuntu/device/container/ubuntulocalrunconfiguration.cpp 2016-08-29 15:46:34 +0000
4@@ -40,6 +40,10 @@
5 #include <qmakeprojectmanager/qmakeprojectmanagerconstants.h>
6 #include <qmljs/parser/qmldirparser_p.h>
7 #include <qmljs/parser/qmlerror.h>
8+#include <coreplugin/icore.h>
9+
10+#include <QRegularExpression>
11+#include <QMessageBox>
12
13 using namespace Ubuntu::Internal;
14
15@@ -55,6 +59,13 @@
16 Utils::Environment UbuntuLocalEnvironmentAspect::baseEnvironment() const
17 {
18 Utils::Environment env = RemoteLinuxEnvironmentAspect::baseEnvironment();
19+ Utils::Environment lEnv = Utils::Environment::systemEnvironment();
20+
21+ //forward the currently used DISPLAY for the current session
22+ const QString displayKey(QStringLiteral("DISPLAY"));
23+ if (lEnv.hasKey(displayKey))
24+ env.set(displayKey, lEnv.value(displayKey));
25+
26 if (const UbuntuLocalRunConfiguration *rc = qobject_cast<const UbuntuLocalRunConfiguration *>(runConfiguration()))
27 rc->addToBaseEnvironment(env);
28 return env;
29@@ -146,6 +157,30 @@
30
31 bool UbuntuLocalRunConfiguration::aboutToStart(QString *errorMessage)
32 {
33+ int displayNr = 0;
34+ QString d = QString::fromLocal8Bit(qgetenv("DISPLAY"));
35+ if(!d.isEmpty()) {
36+ QRegularExpression exp(":([0-9]+)");
37+ auto match = exp.match(d);
38+ if (match.hasMatch()) {
39+ bool isInt = false;
40+ int capturedVal = match.captured(1).toInt(&isInt);
41+ if (isInt) {
42+ displayNr = capturedVal;
43+ }
44+ }
45+ }
46+
47+ if (!QFile::exists(QString::fromLatin1("/tmp/.X11-unix/X%1").arg(displayNr))) {
48+ QMessageBox msgBox(Core::ICore::mainWindow());
49+ msgBox.setWindowTitle(qApp->applicationName());
50+ msgBox.setTextFormat(Qt::RichText); //make the link clickable
51+ msgBox.setText(tr("The X11 socket in /tmp/.X11-unix is missing, the application will most likely not run.<br/><br/>"
52+ "%1")
53+ .arg("<a href=\"http://askubuntu.com/questions/818264/ubuntu-sdk-ide-qxcbconnection-could-not-connect-to-display\">More Info on AskUbuntu.</a>"));
54+ msgBox.exec();
55+ }
56+
57 if(target()->project()->id() != Constants::UBUNTUPROJECT_ID) {
58 QString idString = id().toString();
59 if(idString.startsWith(QLatin1String(Constants::UBUNTUPROJECT_RUNCONTROL_APP_ID))) {

Subscribers

People subscribed via source and target branches