GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4StartClient.cpp
Go to the documentation of this file.
1 // $Id: TGo4StartClient.cpp 2118 2018-06-28 14:30:37Z 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 f�r 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  setObjectName("Go4StartClient");
29 
30 #ifdef WIN32
31  // enable only exec and qtwindow in WIN32 mode
33  rsh_selected->setEnabled(false);
34  ssh_selected->setEnabled(false);
35 
37  xterm_selected->setEnabled(false);
38  konsole_selected->setEnabled(false);
39  go4sett->setClientNode("localhost");
40  LineEditClientNode->setEnabled(false);
41 #endif
42 
43  fSelectedFilter = -1;
44 
45  ClientShellGroup = new QButtonGroup(this);
46  ClientShellGroup->addButton(exec_selected, 0);
47  ClientShellGroup->addButton(rsh_selected, 1);
48  ClientShellGroup->addButton(ssh_selected, 2);
49  ClientShellGroup->button(go4sett->getClientShellMode())->setChecked(true);
50 
51  ClientTermGroup = new QButtonGroup(this);
52  ClientTermGroup->addButton(qt_selected, 1);
53  ClientTermGroup->addButton(xterm_selected, 2);
54  ClientTermGroup->addButton(konsole_selected, 3);
55  ClientTermGroup->button(go4sett->getClientTermMode())->setChecked(true);
56 
57  LineEditClientName->setText(go4sett->getClientName());
58  LineEditClientNode->setText(go4sett->getClientNode());
59  PortNumber->setValue(go4sett->getClientPort());
60  LineEditClientDir->setText(go4sett->getClientDir());
61  LineEditClientExec->setText(go4sett->getClientExec());
62  LineEditArgs->setText(go4sett->getClientArgs());
63 
64  if (LineEditClientDir->text().isEmpty())
65  LineEditClientDir->setText(QDir::currentPath());
66 
67  int mode = go4sett->getClientIsServer(); // 0 - client, 1 - server, 2 - http
68 
69 #ifdef WIN32
70  if (mode == 1) mode = 2;
71 
72  QModelIndex index = ServerModeCombo->model()->index(1, 0);
73  // This is the effective 'disable' flag
74  QVariant v(0);
75  // the magic
76  ServerModeCombo->model()->setData(index, v, Qt::UserRole - 1);
77 #else
78  qt_selected->setEnabled(mode!=1);
79 
80  if ((mode==1) && ClientTermGroup->checkedId()==1)
81  ClientTermGroup->button(2)->setChecked(true);
82 #endif
83 
84  ServerModeCombo->setCurrentIndex(mode);
85  PortNumber->setEnabled(mode == 2);
86 
87  ExeModeCombo->setCurrentIndex(mode==2 ? 1 : go4sett->getClientExeMode());
88 
89 
90 }
91 
93 {
94  LineEditClientExec->setText(go4sett->getClientExec(id));
95 }
96 
98 {
99  go4sett->setClientName(LineEditClientName->text());
100  go4sett->setClientNode(LineEditClientNode->text());
101  go4sett->setClientDir(LineEditClientDir->text());
102  go4sett->setClientExeMode(ExeModeCombo->currentIndex());
103  go4sett->setClientExec(LineEditClientExec->text());
104  go4sett->setClientArgs(LineEditArgs->text());
107  go4sett->setClientIsServer(ServerModeCombo->currentIndex());
108  go4sett->setClientConnectMode(ServerModeCombo->currentIndex()>0 ? ServerModeCombo->currentIndex() - 1 : 0);
109  go4sett->setClientPort(PortNumber->value());
110 }
111 
113 {
114  QFileDialog fd(this, "Select your working directory");
115  fd.setFileMode(QFileDialog::DirectoryOnly);
116 #if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
117  fd.setOption(QFileDialog::DontUseNativeDialog);
118 #endif
119  //< JAM also do not use native dialog here to be consistent with lib dialog, see below
120  QString dir = LineEditClientDir->text();
121  if (dir.isEmpty() || !QDir(dir).exists())
122  dir = QDir::currentPath();
123  fd.setDirectory(dir);
124 
125  if (fd.exec() != QDialog::Accepted ) return;
126 
127  QStringList flst = fd.selectedFiles();
128  if (flst.isEmpty()) return;
129 
130  LineEditClientDir->setText(flst[0]);
131 
132  QString fileName = LineEditClientExec->text();
133  if (fileName.length()==0) return;
134 
135  QString exeDirPath = QFileInfo(fileName).path();
136  if (exeDirPath.isEmpty() || ((exeDirPath == QString(".")) && (fileName[0]!='.'))) {
137  fileName = QFileInfo(QDir(flst[0]), fileName).filePath();
138  LineEditClientExec->setText(fileName);
139  }
140 }
141 
142 
144 {
145  const char* caption = 0;
146 
147 #ifdef WIN32
148  QString exe1_filter("User analysis (MainUserAnalysis.exe)");
149  QString exe2_filter("Any executable (*.exe)");
150  QString dll1_filter("User library (libGo4UserAnalysis.dll)");
151  QString dll2_filter("Any shared library (*.dll)");
152  QString any_filter("Any files (*.*)");
153 #else
154  QString exe1_filter("User analysis (MainUserAnalysis)");
155  QString exe2_filter("Any executable (*)");
156  QString dll1_filter("User library (libGo4UserAnalysis.so)");
157  QString dll2_filter("Any shared library (*.so)");
158  QString any_filter("Any files (*)");
159 #endif
160 
161  QStringList filters;
162  filters << exe1_filter << exe2_filter << dll1_filter << dll2_filter << any_filter;
163 
164  QFileDialog fd(this, caption);
165  fd.setFileMode(QFileDialog::ExistingFile);
166 #if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
167  fd.setOption(QFileDialog::DontUseNativeDialog);
168 #endif
169  //< JAM: native dialog may suppress the chosen filer when displayed and use always first entry in list!
170  fd.setNameFilters(filters);
171  int select_filer = fSelectedFilter;
172  if (select_filer<0)
173  select_filer= (ExeModeCombo->currentIndex()==0) ? 0 : 2;
174  switch (select_filer) {
175  case 0: fd.selectNameFilter(exe1_filter); break;
176  case 1: fd.selectNameFilter(exe2_filter); break;
177  case 2: fd.selectNameFilter(dll1_filter); break;
178  case 3: fd.selectNameFilter(dll2_filter); break;
179  default: fd.selectNameFilter(any_filter); break;
180  }
181 
182  QString filename = LineEditClientExec->text();
183  if (filename.length() > 0)
184  fd.selectFile(filename);
185 
186  if (fd.exec() != QDialog::Accepted) return;
187 
188  QStringList flst = fd.selectedFiles();
189  if (flst.isEmpty()) return;
190 
191  select_filer = 4;
192  if (fd.selectedNameFilter()==exe1_filter) select_filer = 0; else
193  if (fd.selectedNameFilter()==exe2_filter) select_filer = 1; else
194  if (fd.selectedNameFilter()==dll1_filter) select_filer = 2; else
195  if (fd.selectedNameFilter()==dll2_filter) select_filer = 3;
196  fSelectedFilter = select_filer;
197 
198  if ((select_filer==0) || (select_filer==1)) ExeModeCombo->setCurrentIndex(0); else
199  if ((select_filer==2) || (select_filer==3)) ExeModeCombo->setCurrentIndex(1);
200 
201  LineEditClientExec->setText(flst[0]);
202 }
203 
204 
206 {
207  bool windows = false;
208 
209 #ifdef WIN32
210  if (id==1) {
211  ServerModeCombo->setCurrentIndex(2);
212  id = 2;
213  }
214  windows = true;
215 #endif
216 
217  ExeModeCombo->setEnabled(id<2);
218  if (id==2) ExeModeCombo->setCurrentIndex(1);
219  bool isserver = (id>0);
220  qt_selected->setEnabled(id!=1);
221  PortNumber->setEnabled(id==2);
222  if (id==1) { // if Qt was selected, select Xterm
223  if (ClientTermGroup->checkedId()==1)
224  ClientTermGroup->button(2)->setChecked(true);
225  }
226  else { // if Xterm was selected, select Qt
227  if (ClientTermGroup->checkedId()==2)
228  ClientTermGroup->button(1)->setChecked(true);
229  }
230 }
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()