Isis 3.0 Programmer Reference
Back | Home
Environment.cpp
1 #include "Environment.h"
2 
3 #include <iostream>
4 #include <stdlib.h>
5 
6 #include <QString>
7 #include <QStringList>
8 #include <QCoreApplication>
9 
10 #ifndef __APPLE__
11 #include <QtDBus>
12 #endif
13 
14 #include "IException.h"
15 #include "IString.h"
16 #include "TextFile.h"
17 
22  static void QStartup() {
23  // Set the Qt plugin directory
24  QStringList pluginPaths;
25 
27  QCoreApplication *core = QCoreApplication::instance();
28  if ( !core ) {
29  std::cout << "**** Qt Plugin Path is not set because no instance of QCoreApplication ****\n";
30  }
31  else {
32  Isis::IString thirdPartyPluginPath = root + "/3rdParty/plugins";
33  pluginPaths << thirdPartyPluginPath.ToQt();
34  core->setLibraryPaths(pluginPaths);
35  }
36 
37  return;
38  }
39 
40 // Add this to ensure Qt is set up properly
41 Q_COREAPP_STARTUP_FUNCTION(QStartup);
42 
43 namespace Isis {
44 
45 
47 
48  Environment::Environment() {
49 
50 #if 0
51  // Set the Qt plugin directory
52  QStringList pluginPaths;
53 
54  IString root = getEnvironmentValue("ISISROOT", "");
55  std::cout << "ISISROOT=" << root << "\n";
56 
57  if (root != "") {
58 
59  QCoreApplication *core = QCoreApplication::instance();
60  if ( !core ) {
61  std::cout << "QCoreApplication doesn't exist yet!\n";
62  }
63  IString thirdPartyPluginPath = root + "/3rdParty/plugins";
64  pluginPaths << thirdPartyPluginPath.ToQt();
65  std::cout << "PluginPaths=" << pluginPaths.join(";") << "\n";
66  QCoreApplication::setLibraryPaths(pluginPaths);
67  }
68 #endif
69 
70 #ifndef __APPLE__
71  // We need to force the correct QDBus library to be loaded... to do that, just
72  // use a symbol in it's library. This only applies to linux and fixes #1228.
73 
74  // Long explanation:
75  // When we run GUI apps, the system (and Qt) work together to figure out
76  // which runtime libraries are necessary on-the-fly. When QApplication is
77  // instantiated, it goes into QtGui's style code. The styles ignore our plugin
78  // path setting (above) on all OS's. So Qt GUI grabs a style from the OS's styles,
79  // which is a shared library in the kde area. These styles require a version (any version)
80  // of QtDBus loaded. If QtDBus is not yet loaded, then the style library will grab it.
81  // However, on Ubuntu 12.04, the style library grabs the system (OS) QDBus library. QDBus
82  // detects that you've already loaded Isis' QtCore, so the library versions mismatch, and
83  // it crashes. The problem becomes more interesting because sometimes it picks up the system
84  // QDBus, and sometimes it picks up Isis' QDBus, and I have no good reason why we pick up
85  // one versus another; currently, installed apps pick up the system and locally built apps
86  // pick up Isis' (even when the executables are made to be identical). The end result is no
87  // installed GUI applications will run and our automated tests fail to catch it. This solution
88  // bypasses the entire issue by forcing QDBus to be loaded long before any styles are loaded,
89  // so the style plugins do not need to go and get their own QDBus library.
90  //
91  // The root cause is that Ubuntu's run time loader is failing to respect
92  // our executable's rpaths when loading a style library. However, when we link against the
93  // QBus library directly, we get the right one.
94  QDBusArgument();
95 #endif
96  }
97 
98 
103  return getEnvironmentValue("USER", "Unknown");
104  }
105 
106 
111  return getEnvironmentValue("HOST", "Unknown");
112  }
113 
114 
122  QString Environment::getEnvironmentValue(QString variable,
123  QString defaultValue) {
124 
125  QString value = defaultValue;
126 
127  char *envValue = getenv(variable.toLatin1().data());
128  if (envValue)
129  value = envValue;
130 
131  return value;
132  }
133 
134 
139  TextFile versionFile("$ISISROOT/version");
140  QString line1, line2, line3, line4;
141  versionFile.GetLine(line1);
142  versionFile.GetLine(line2);
143  versionFile.GetLine(line3);
144  versionFile.GetLine(line4);
145 
146  QRegExp validPartOfLine("[^ #]*");
147  if (validPartOfLine.indexIn(line1) != -1) {
148  line1 = validPartOfLine.cap();
149  }
150  else {
151  IString msg = "$ISISROOT/version line 1, no valid text found";
153  }
154 
155  if (validPartOfLine.indexIn(line2) != -1) {
156  line2 = validPartOfLine.cap();
157  }
158  else {
159  IString msg = "$ISISROOT/version line 2, no valid text found";
161  }
162 
163  if (validPartOfLine.indexIn(line4) != -1) {
164  line4 = validPartOfLine.cap();
165  }
166  else {
167  IString msg = "$ISISROOT/version line 4, no valid text found";
169  }
170 
171  return line1 + " " + line4 + " | " + line2;
172  }
173 
174 
175 }
QString ToQt() const
Retuns the object string as a QString.
Definition: IString.cpp:884
static QString getEnvironmentValue(QString, QString)
static Environment automaticEnvironmentSetup
Construct an environment in static space to initialize some global Isis 3 environment options...
Definition: Environment.h:71
static QString userName()
the user name.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:154
static QString hostName()
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
bool GetLine(QString &line, const bool skipComments=true)
Gets next line from file.
Definition: TextFile.cpp:427
static QString isisVersion()
Provides access to sequential ASCII stream I/O.
Definition: TextFile.h:54
Isis exception class.
Definition: IException.h:99
Adds specific functionality to C++ strings.
Definition: IString.h:179

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:17:49