Isis 3 Programmer Reference
Environment.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "Environment.h"
8
9#include <iostream>
10#include <stdlib.h>
11
12#include <QString>
13#include <QStringList>
14#include <QCoreApplication>
15
16#include "IException.h"
17#include "IString.h"
18#include "TextFile.h"
19
24 static void QStartup() {
25 // Set the Qt plugin directory
26 QStringList pluginPaths;
27
29 QCoreApplication *core = QCoreApplication::instance();
30 if ( !core ) {
31 std::cout << "**** Qt Plugin Path is not set because no instance of QCoreApplication ****\n";
32 }
33
34 return;
35 }
36
37// Add this to ensure Qt is set up properly
38Q_COREAPP_STARTUP_FUNCTION(QStartup);
39
40namespace Isis {
41
42
44
45 Environment::Environment() {
46
47#if 0
48 // Set the Qt plugin directory
49 QStringList pluginPaths;
50
51 IString root = getEnvironmentValue("ISISROOT", "");
52 std::cout << "ISISROOT=" << root << "\n";
53
54 if (root != "") {
55
56 QCoreApplication *core = QCoreApplication::instance();
57 if ( !core ) {
58 std::cout << "QCoreApplication doesn't exist yet!\n";
59 }
60 IString thirdPartyPluginPath = root + "/3rdParty/plugins";
61 pluginPaths << thirdPartyPluginPath.ToQt();
62 std::cout << "PluginPaths=" << pluginPaths.join(";") << "\n";
63 QCoreApplication::setLibraryPaths(pluginPaths);
64 }
65#endif
66 }
67
68
73 return getEnvironmentValue("USER", "Unknown");
74 }
75
76
81 return getEnvironmentValue("HOST", "Unknown");
82 }
83
84
92 QString Environment::getEnvironmentValue(QString variable,
93 QString defaultValue) {
94
95 QString value = defaultValue;
96
97 char *envValue = getenv(variable.toLatin1().data());
98 if (envValue)
99 value = envValue;
100
101 return value;
102 }
103
104
109 TextFile versionFile("$ISISROOT/version");
110 QString line1, line2, line3, line4;
111 versionFile.GetLine(line1);
112 versionFile.GetLine(line2);
113 versionFile.GetLine(line3);
114 versionFile.GetLine(line4);
115
116 QRegExp validPartOfLine("[^ #]*");
117 if (validPartOfLine.indexIn(line1) != -1) {
118 line1 = validPartOfLine.cap();
119 }
120 else {
121 IString msg = "$ISISROOT/version line 1, no valid text found";
122 throw IException(IException::Programmer, msg, _FILEINFO_);
123 }
124
125 if (validPartOfLine.indexIn(line2) != -1) {
126 line2 = validPartOfLine.cap();
127 }
128 else {
129 IString msg = "$ISISROOT/version line 2, no valid text found";
130 throw IException(IException::Programmer, msg, _FILEINFO_);
131 }
132
133 if (validPartOfLine.indexIn(line4) != -1) {
134 line4 = validPartOfLine.cap();
135 }
136 else {
137 IString msg = "$ISISROOT/version line 4, no valid text found";
138 throw IException(IException::Programmer, msg, _FILEINFO_);
139 }
140
141 return line1 + " " + line4 + " | " + line2;
142 }
143
144
145}
static QString isisVersion()
static QString hostName()
static QString userName()
@Returns the user name.
static Environment automaticEnvironmentSetup
Construct an environment in static space to initialize some global Isis environment options.
Definition Environment.h:55
static QString getEnvironmentValue(QString, QString)
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Adds specific functionality to C++ strings.
Definition IString.h:165
Provides access to sequential ASCII stream I/O.
Definition TextFile.h:38
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16