Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
metarwidget.cpp
Go to the documentation of this file.
1 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
2 // FGx FlightGear Launcher // metarwidget.cpp
3 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
4 // (c) 2010-2012
5 // Yves Sablonier, Pete Morgan
6 // Geoff McLane
7 // GNU GPLv2, see main.cpp and shipped licence.txt for further information
8 
9 
10 #include <QProcess>
11 #include <QVBoxLayout>
12 
13 #include "airports/metarwidget.h"
14 #include "utilities/utilities.h"
15 
17  QWidget(parent)
18 {
19 
20  mainObject = mob;
21 
22  setWindowIcon(QIcon(":/icon/metar"));
23  setWindowTitle("Metar Fetch");
24 
25  setMinimumWidth(600);
26 
27  QVBoxLayout *mainLayout = new QVBoxLayout();
28  setLayout(mainLayout);
29 
30  txtMetar = new QPlainTextEdit();
31  txtMetar->setStyleSheet("font-size: 9pt;");
32  mainLayout->addWidget(txtMetar);
33 
34 }
35 
36 //=================================================
37 //= load Metar
38 //===================================================
39 void MetarWidget::load_metar(QString apt)
40 {
41  QProcess process;
42  QStringList args;
43  QString results;
44  QString metarPath;
45  QString tmp;
46  QString error_result;
47  QDir d;
48  metarPath = "metar";
49  args << "-r" << "-v" << apt;
50 
51  // for environment output, deactivated
52  /*QStringList environment = QProcess::systemEnvironment();
53  for (int i=0; i < environment.count(); i++) {
54  outLog("Env: "+environment[i]);
55  }*/
56 
57 #ifdef Q_OS_MAC
58  metarPath = mainObject->X->fgfs_path();
59  metarPath.chop(4);
60  metarPath.append("metar");
61 #else
62  // it is hoped this would suit ALL ports
63  tmp = mainObject->X->fgfs_path();
64  tmp = util_getBasePath(tmp);
65  tmp.append("metar");
66 #ifdef Q_OS_WIN
67  tmp.append(".exe"); // add windows thing
68 #endif
69  if (QFile::exists(tmp))
70  metarPath = tmp;
71 #endif
72  txtMetar->setPlainText( QString("Loading..\n\nmetar %1").arg(apt) );
73  outLog("Running: ["+metarPath+" "+args.join(" ")+"]");
74  process.start(metarPath, args, QIODevice::ReadOnly);
75  if(process.waitForStarted()){
76  process.waitForFinished(3000);
77  results = process.readAllStandardOutput();
78  error_result = process.readAllStandardError();
79  tmp = results.simplified();
80  if (tmp.size() == 0) {
81  if (error_result.size() > 0) {
82  results = error_result;
83  } else {
84  results = "NO metar results found!";
85  }
86  }
87  txtMetar->setPlainText(results);
88  } else {
89  results = "ERROR: Running of metar FAILED";
90  }
91  outLog("Results: "+results);
92 }
93 
95 {
96  txtMetar->setPlainText( "" );
97 }
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
void load_metar(QString apt)
Definition: metarwidget.cpp:39
QPlainTextEdit * txtMetar
Definition: metarwidget.h:29
MetarWidget(MainObject *mob, QWidget *parent=0)
Definition: metarwidget.cpp:16
MainObject * mainObject
Definition: metarwidget.h:27
XSettingsModel * X
Definition: mainobject.h:86
QString fgfs_path()
Path to fgfs executable.
void clear_metar()
Definition: metarwidget.cpp:94