Isis 3 Programmer Reference
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 #include "IException.h"
11 #include "IString.h"
12 #include "TextFile.h"
13 
18  static void QStartup() {
19  // Set the Qt plugin directory
20  QStringList pluginPaths;
21 
23  QCoreApplication *core = QCoreApplication::instance();
24  if ( !core ) {
25  std::cout << "**** Qt Plugin Path is not set because no instance of QCoreApplication ****\n";
26  }
27 
28  return;
29  }
30 
31 // Add this to ensure Qt is set up properly
32 Q_COREAPP_STARTUP_FUNCTION(QStartup);
33 
34 namespace Isis {
35 
36 
38 
39  Environment::Environment() {
40 
41 #if 0
42  // Set the Qt plugin directory
43  QStringList pluginPaths;
44 
45  IString root = getEnvironmentValue("ISISROOT", "");
46  std::cout << "ISISROOT=" << root << "\n";
47 
48  if (root != "") {
49 
50  QCoreApplication *core = QCoreApplication::instance();
51  if ( !core ) {
52  std::cout << "QCoreApplication doesn't exist yet!\n";
53  }
54  IString thirdPartyPluginPath = root + "/3rdParty/plugins";
55  pluginPaths << thirdPartyPluginPath.ToQt();
56  std::cout << "PluginPaths=" << pluginPaths.join(";") << "\n";
57  QCoreApplication::setLibraryPaths(pluginPaths);
58  }
59 #endif
60  }
61 
62 
67  return getEnvironmentValue("USER", "Unknown");
68  }
69 
70 
75  return getEnvironmentValue("HOST", "Unknown");
76  }
77 
78 
86  QString Environment::getEnvironmentValue(QString variable,
87  QString defaultValue) {
88 
89  QString value = defaultValue;
90 
91  char *envValue = getenv(variable.toLatin1().data());
92  if (envValue)
93  value = envValue;
94 
95  return value;
96  }
97 
98 
103  TextFile versionFile("$ISISROOT/version");
104  QString line1, line2, line3, line4;
105  versionFile.GetLine(line1);
106  versionFile.GetLine(line2);
107  versionFile.GetLine(line3);
108  versionFile.GetLine(line4);
109 
110  QRegExp validPartOfLine("[^ #]*");
111  if (validPartOfLine.indexIn(line1) != -1) {
112  line1 = validPartOfLine.cap();
113  }
114  else {
115  IString msg = "$ISISROOT/version line 1, no valid text found";
117  }
118 
119  if (validPartOfLine.indexIn(line2) != -1) {
120  line2 = validPartOfLine.cap();
121  }
122  else {
123  IString msg = "$ISISROOT/version line 2, no valid text found";
125  }
126 
127  if (validPartOfLine.indexIn(line4) != -1) {
128  line4 = validPartOfLine.cap();
129  }
130  else {
131  IString msg = "$ISISROOT/version line 4, no valid text found";
133  }
134 
135  return line1 + " " + line4 + " | " + line2;
136  }
137 
138 
139 }
static QString getEnvironmentValue(QString, QString)
Definition: Environment.cpp:86
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.
Definition: Environment.cpp:66
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
static QString hostName()
Definition: Environment.cpp:74
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
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:107
Adds specific functionality to C++ strings.
Definition: IString.h:181
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31