GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4StartClient.cpp
Go to the documentation of this file.
1 // $Id: TGo4StartClient.cpp 3139 2021-03-30 12:32:42Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4StartClient.h"
15 
16 #include <QDir>
17 #include <QFileInfo>
18 #include <QFileDialog>
19 #include <QButtonGroup>
20 
21 #include "TGo4QSettings.h"
22 
24  : QDialog( parent )
25 {
26  setupUi(this);
27 
28  QObject::connect(ChooseDir, SIGNAL(clicked()), this, SLOT(SelectDir()));
29  QObject::connect(ChooseExc, SIGNAL(clicked()), this, SLOT(SelectProg()));
30  QObject::connect(ServerModeCombo, SIGNAL(activated(int)), this, SLOT(ServerModeCombo_activated(int)));
31  QObject::connect(ExeModeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(ExeMode_changed(int)));
32 
33  setObjectName("Go4StartClient");
34 
35 #ifdef WIN32
36  // enable only exec and qtwindow in WIN32 mode
38  rsh_selected->setEnabled(false);
39  ssh_selected->setEnabled(false);
40 
42  xterm_selected->setEnabled(false);
43  konsole_selected->setEnabled(false);
44  go4sett->setClientNode("localhost");
45  LineEditClientNode->setEnabled(false);
46 #endif
47 
48  fSelectedFilter = -1;
49 
50  ClientShellGroup = new QButtonGroup(this);
51  ClientShellGroup->addButton(exec_selected, 0);
52  ClientShellGroup->addButton(rsh_selected, 1);
53  ClientShellGroup->addButton(ssh_selected, 2);
54  ClientShellGroup->button(go4sett->getClientShellMode())->setChecked(true);
55 
56  ClientTermGroup = new QButtonGroup(this);
57  ClientTermGroup->addButton(qt_selected, 1);
58  ClientTermGroup->addButton(xterm_selected, 2);
59  ClientTermGroup->addButton(konsole_selected, 3);
60  ClientTermGroup->button(go4sett->getClientTermMode())->setChecked(true);
61 
62  LineEditClientName->setText(go4sett->getClientName());
63  LineEditClientNode->setText(go4sett->getClientNode());
64  PortNumber->setValue(go4sett->getClientPort());
65  LineEditClientDir->setText(go4sett->getClientDir());
66  LineEditClientExec->setText(go4sett->getClientExec());
67  LineEditArgs->setText(go4sett->getClientArgs());
68 
69  if (LineEditClientDir->text().isEmpty())
70  LineEditClientDir->setText(QDir::currentPath());
71 
72  int mode = go4sett->getClientIsServer(); // 0 - client, 1 - server, 2 - http
73 
74 #ifdef WIN32
75  if (mode == 1) mode = 2;
76 
77  QModelIndex index = ServerModeCombo->model()->index(1, 0);
78  // This is the effective 'disable' flag
79  QVariant v(0);
80  // the magic
81  ServerModeCombo->model()->setData(index, v, Qt::UserRole - 1);
82 #else
83  qt_selected->setEnabled(mode!=1);
84 
85  if ((mode==1) && ClientTermGroup->checkedId()==1)
86  ClientTermGroup->button(2)->setChecked(true);
87 #endif
88 
89  ServerModeCombo->setCurrentIndex(mode);
90  PortNumber->setEnabled(mode == 2);
91 
92  ExeModeCombo->setCurrentIndex(mode==2 ? 1 : go4sett->getClientExeMode());
93 }
94 
96 {
97  LineEditClientExec->setText(go4sett->getClientExec(id));
98 }
99 
101 {
102  go4sett->setClientName(LineEditClientName->text());
103  go4sett->setClientNode(LineEditClientNode->text());
104  go4sett->setClientDir(LineEditClientDir->text());
105  go4sett->setClientExeMode(ExeModeCombo->currentIndex());
106  go4sett->setClientExec(LineEditClientExec->text());
107  go4sett->setClientArgs(LineEditArgs->text());
110  go4sett->setClientIsServer(ServerModeCombo->currentIndex());
111  go4sett->setClientConnectMode(ServerModeCombo->currentIndex()>0 ? ServerModeCombo->currentIndex() - 1 : 0);
112  go4sett->setClientPort(PortNumber->value());
113 }
114 
116 {
117  QFileDialog fd(this, "Select your working directory");
118  fd.setOption(QFileDialog::ShowDirsOnly, true);
119  fd.setFileMode(QFileDialog::Directory);
120 
121 #if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
122  fd.setOption(QFileDialog::DontUseNativeDialog);
123 #endif
124  //< JAM also do not use native dialog here to be consistent with lib dialog, see below
125  QString dir = LineEditClientDir->text();
126  if (dir.isEmpty() || !QDir(dir).exists())
127  dir = QDir::currentPath();
128  fd.setDirectory(dir);
129 
130  if (fd.exec() != QDialog::Accepted ) return;
131 
132  QStringList flst = fd.selectedFiles();
133  if (flst.isEmpty()) return;
134 
135  LineEditClientDir->setText(flst[0]);
136 
137  QString fileName = LineEditClientExec->text();
138  if (fileName.length()==0) return;
139 
140  QString exeDirPath = QFileInfo(fileName).path();
141  if (exeDirPath.isEmpty() || ((exeDirPath == QString(".")) && (fileName[0]!='.'))) {
142  fileName = QFileInfo(QDir(flst[0]), fileName).filePath();
143  LineEditClientExec->setText(fileName);
144  }
145 }
146 
147 
149 {
150  const char* caption = 0;
151 
152 #ifdef WIN32
153  QString exe1_filter("User analysis (MainUserAnalysis.exe)");
154  QString exe2_filter("Any executable (*.exe)");
155  QString dll1_filter("User library (libGo4UserAnalysis.dll)");
156  QString dll2_filter("Any shared library (*.dll)");
157  QString any_filter("Any files (*.*)");
158 #else
159  QString exe1_filter("User analysis (MainUserAnalysis)");
160  QString exe2_filter("Any executable (*)");
161  QString dll1_filter("User library (libGo4UserAnalysis.so)");
162  QString dll2_filter("Any shared library (*.so)");
163  QString any_filter("Any files (*)");
164 #endif
165 
166  QStringList filters;
167  filters << exe1_filter << exe2_filter << dll1_filter << dll2_filter << any_filter;
168 
169  QFileDialog fd(this, caption);
170  fd.setFileMode(QFileDialog::ExistingFile);
171 #if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
172  fd.setOption(QFileDialog::DontUseNativeDialog);
173 #endif
174  //< JAM: native dialog may suppress the chosen filer when displayed and use always first entry in list!
175  fd.setNameFilters(filters);
176  int select_filer = fSelectedFilter;
177  if (select_filer<0)
178  select_filer= (ExeModeCombo->currentIndex()==0) ? 0 : 2;
179  switch (select_filer) {
180  case 0: fd.selectNameFilter(exe1_filter); break;
181  case 1: fd.selectNameFilter(exe2_filter); break;
182  case 2: fd.selectNameFilter(dll1_filter); break;
183  case 3: fd.selectNameFilter(dll2_filter); break;
184  default: fd.selectNameFilter(any_filter); break;
185  }
186 
187  QString filename = LineEditClientExec->text();
188  if (filename.length() > 0)
189  fd.selectFile(filename);
190 
191  if (fd.exec() != QDialog::Accepted) return;
192 
193  QStringList flst = fd.selectedFiles();
194  if (flst.isEmpty()) return;
195 
196  select_filer = 4;
197  if (fd.selectedNameFilter()==exe1_filter) select_filer = 0; else
198  if (fd.selectedNameFilter()==exe2_filter) select_filer = 1; else
199  if (fd.selectedNameFilter()==dll1_filter) select_filer = 2; else
200  if (fd.selectedNameFilter()==dll2_filter) select_filer = 3;
201  fSelectedFilter = select_filer;
202 
203  if ((select_filer==0) || (select_filer==1)) ExeModeCombo->setCurrentIndex(0); else
204  if ((select_filer==2) || (select_filer==3)) ExeModeCombo->setCurrentIndex(1);
205 
206  LineEditClientExec->setText(flst[0]);
207 }
208 
209 
211 {
212  bool windows = false;
213 
214 #ifdef WIN32
215  if (id==1) {
216  ServerModeCombo->setCurrentIndex(2);
217  id = 2;
218  }
219  windows = true;
220 #endif
221 
222  ExeModeCombo->setEnabled(id<2);
223  if (id==2) ExeModeCombo->setCurrentIndex(1);
224  bool isserver = (id>0);
225  qt_selected->setEnabled(id!=1);
226  PortNumber->setEnabled(id==2);
227  if (id==1) { // if Qt was selected, select Xterm
228  if (ClientTermGroup->checkedId()==1)
229  ClientTermGroup->button(2)->setChecked(true);
230  }
231  else { // if Xterm was selected, select Qt
232  if (ClientTermGroup->checkedId()==2)
233  ClientTermGroup->button(1)->setChecked(true);
234  }
235 }
QString getClientDir()
virtual void SelectDir()
int getClientShellMode()
void setClientExeMode(int mode)
void setClientArgs(const QString &)
void setClientDir(const QString &)
QString getClientName()
virtual void ServerModeCombo_activated(int)
QString getClientExec(int mode=-1)
void setClientName(const QString &)
void setClientTermMode(int)
void setClientShellMode(int)
TGo4StartClient(QWidget *parent=0)
void setClientPort(int)
void setClientIsServer(int kind)
QString getClientArgs()
QButtonGroup * ClientTermGroup
TGo4QSettings * go4sett
virtual void ExeMode_changed(int)
void setClientExec(const QString &)
void setClientNode(const QString &)
QButtonGroup * ClientShellGroup
void setClientConnectMode(int)
virtual void SelectProg()
QString getClientNode()