Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
xcommandpreviewidget.cpp
Go to the documentation of this file.
1 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
2 // FGx FlightGear Launcher // xcommandpreview.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 
13 
14 #include "utilities/utilities.h"
15 
17  QWidget(parent)
18 {
19 
20  mainObject = mob;
21 
22  QVBoxLayout *mainLayout = new QVBoxLayout();
23 
24  setLayout(mainLayout);
25 
26 
27  txtPreviewOutput = new QPlainTextEdit();
28  mainLayout->addWidget(txtPreviewOutput);
29  txtPreviewOutput->setReadOnly(true);
30 
31 
32  QHBoxLayout *layoutButtons = new QHBoxLayout();
33  mainLayout->addLayout(layoutButtons);
34 
35 
36  //=============================================================
37  buttonGroup = new QButtonGroup(this);
38  buttonGroup->setExclusive(true);
39  connect(buttonGroup, SIGNAL(buttonClicked(int)) , this, SLOT(preview()));
40 
41  QRadioButton *radioString = new QRadioButton();
42  radioString->setText("Single line");
43  radioString->setProperty("value", "string");
44  layoutButtons->addWidget(radioString);
45  buttonGroup->addButton(radioString, 0);
46 
47  QRadioButton *radioLines = new QRadioButton();
48  radioLines->setText("Separate lines");
49  radioLines->setProperty("value", "lines");
50  layoutButtons->addWidget(radioLines);
51  buttonGroup->addButton(radioLines, 1);
52 
53  QRadioButton *radioShell = new QRadioButton();
54  radioShell->setText("Shell lines");
55  radioShell->setProperty("value", "shell");
56  layoutButtons->addWidget(radioShell);
57  buttonGroup->addButton(radioShell, 2);
58 
59 
60  //=============================================================
61  QPushButton *buttonCommandPreview = new QPushButton();
62  buttonCommandPreview->setText(tr("Preview"));
63  layoutButtons->addWidget(buttonCommandPreview);
64  connect(buttonCommandPreview, SIGNAL(clicked()), this, SLOT(preview()));
65 
66  QPushButton *buttonCommandHelp = new QPushButton();
67  buttonCommandHelp->setText(tr("Help"));
68  layoutButtons->addWidget(buttonCommandHelp);
69  connect(buttonCommandHelp, SIGNAL(clicked()), this, SLOT(on_command_help()));
70 
71  QPushButton* buttonCommandVersion = new QPushButton();
72  buttonCommandVersion->setText(tr("Version"));
73  layoutButtons->addWidget(buttonCommandVersion);
74  connect(buttonCommandVersion, SIGNAL(clicked()), this, SLOT(on_command_version()));
75 
76  layoutButtons->addStretch(20);
77 
78  buttonGroup->button(mainObject->settings->value("preview_type", "1").toInt())->setChecked(true);
79 
80 
81  // Connections
82  connect(mainObject->X, SIGNAL(updated(QStringList)), this, SLOT(preview()));
83 
84 }
85 
86 
87 
88 //=============================================================================================================//
89 //== Command Preview Handlers
90 //=============================================================================================================//
91 
92 
94  QProcess process;
95  QStringList args;
96  args << "-h" << "-v" << QString("--fg-root=").append(mainObject->X->fgroot());
97  process.start(mainObject->X->fgfs_path(), args, QIODevice::ReadOnly);
98  if(process.waitForStarted()){
99  process.waitForFinished(10000);
100  QString ok_result = process.readAllStandardOutput();
101  txtPreviewOutput->setPlainText(ok_result);
102  }
103 }
104 
106  QProcess process;
107  QStringList args;
108  args << "-h" << "--version" << QString("--fg-root=").append(mainObject->X->fgroot());
109  process.start(mainObject->X->fgfs_path(), args, QIODevice::ReadOnly);
110  if(process.waitForStarted()){
111  process.waitForFinished(10000);
112  QString ok_result = process.readAllStandardError();
113  outLog(process.readAllStandardError());
114  txtPreviewOutput->setPlainText(ok_result);
115  }
116 }
117 
118 
120  mainObject->settings->setValue("preview_type", buttonGroup->checkedId());
121  QString delim("");
122  QString type = buttonGroup->checkedButton()->property("value").toString();
123  if(type == "lines"){
124  delim.append("\n");
125  }else if(type == "shell"){
126  delim.append(" \\\n");
127  }else{
128  delim.append(" ");
129  }
130 
131  txtPreviewOutput->setPlainText(mainObject->X->get_fgfs_list().join(delim));
132 }
133 
XCommandPrevieWidget(MainObject *mob, QWidget *parent=0)
QPlainTextEdit * txtPreviewOutput
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
XSettingsModel * X
Definition: mainobject.h:86
QString fgfs_path()
Path to fgfs executable.
QStringList get_fgfs_list()
XSettings * settings
Definition: mainobject.h:85