tuchulcha  0.10.1
Graphical Workflow Configuration Editor
OptionsDialog.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011 Jens-Malte Gottfried
2 
3  This file is part of Tuchulcha.
4 
5  Tuchulcha is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Tuchulcha is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with Tuchulcha. If not, see <http://www.gnu.org/licenses/>.
17 */
25 #include "OptionsDialog.h"
26 #include "ui_OptionsDialog.h"
27 
28 #include <QSettings>
29 #include <QDir>
30 #include <QMessageBox>
31 #include <QTableWidgetItem>
32 #include <QVariant>
33 #include <QCoreApplication>
34 
35 OptionsDialog::OptionsDialog(QWidget* pp, Qt::WindowFlags f) :
36  QDialog(pp,f)
37 {
38  _ui = new Ui::OptionsDialog;
39  _ui->setupUi(this);
40 #ifdef USE_ASSISTANT
41  _ui->bBox->setStandardButtons(
42  _ui->bBox->standardButtons() | QDialogButtonBox::Help);
43 #endif
44  QSettings settings;
45  if (settings.allKeys().isEmpty()) {
46  // use default values if settings environment empty
47  restore();
48  apply();
49  }
50  else {
51  refresh();
52  }
53 }
54 
55 OptionsDialog::~OptionsDialog() {
56  delete _ui;
57 }
58 
59 void OptionsDialog::setTab(int tab) {
60  if (tab >= 0 && tab < _ui->tabOptions->count()) {
61  _ui->tabOptions->setCurrentIndex(tab);
62  }
63 }
64 
66  // set up dialog content
67  QSettings settings;
68  _ui->eGlobPath->setText(
69  settings.value("globalPluginPath").toStringList().join("; "));
70  _ui->ePrivPath->setText(
71  settings.value("privatePluginPath").toStringList().join("; "));
72  _ui->ePrivPathD->setText(
73  settings.value("privatePluginPathD").toStringList().join("; "));
74  _ui->checkDebug->setChecked(
75  settings.value("suffixedPlugins", false).toBool());
76  _ui->checkSplash->setChecked(
77  settings.value("splashScreen",true).toBool());
78  _ui->checkPathPopup->setChecked(
79  settings.value("pathDialogPopup", false).toBool());
80  _ui->checkDelay->setChecked(
81  settings.value("delayExecution",false).toBool());
82  _ui->checkReload->setChecked(
83  settings.value("reloadOnStartup",false).toBool());
84  _ui->comboCheckLevel->setCurrentIndex(
85  settings.value("versionCheckLevel",2).toInt());
86  _setExcludes(settings.value("excludeList").toStringList());
87  _ui->bButtonStyle->setCurrentIndex(
88  settings.value("toolButtonStyle",Qt::ToolButtonFollowStyle).toInt());
89  _ui->checkRelativePaths->setChecked(
90  settings.value("relativePaths",true).toBool());
91 }
92 
94  QSettings settings;
95  settings.setValue("globalPluginPath",_ui->eGlobPath->text()
96  .split(QRegExp("\\s*;\\s*"),QString::SkipEmptyParts));
97  settings.setValue("privatePluginPath",_ui->ePrivPath->text()
98  .split(QRegExp("\\s*;\\s*"),QString::SkipEmptyParts));
99  settings.setValue("privatePluginPathD",_ui->ePrivPathD->text()
100  .split(QRegExp("\\s*;\\s*"),QString::SkipEmptyParts));
101  settings.setValue("suffixedPlugins",_ui->checkDebug->isChecked());
102  settings.setValue("splashScreen",_ui->checkSplash->isChecked());
103  settings.setValue("delayExecution", _ui->checkDelay->isChecked());
104  settings.setValue("reloadOnStartup",_ui->checkReload->isChecked());
105  settings.setValue("pathDialogPopup",_ui->checkPathPopup->isChecked());
106  settings.setValue("versionCheckLevel",_ui->comboCheckLevel->currentIndex());
107  settings.setValue("excludeList",_getExcludes());
108  settings.setValue("toolButtonStyle",_ui->bButtonStyle->currentIndex());
109  settings.setValue("relativePaths",_ui->checkRelativePaths->isChecked());
110  if (check()) {
111  refresh();
112  }
113 }
114 
116  QSettings defaults(":/config/default.ini",QSettings::IniFormat);
117 #ifdef UNIX
118  // standard install path on linux systems
119  QString globalPath = "/usr/lib/charon-plugins";
120 #else
121  // Assume global plugin dir to be the same directory
122  // where the tuchulcha.exe is located
123  QString globalPath = QCoreApplication::applicationDirPath();
124 #endif
125  _ui->checkSplash->setChecked(true);
126  _ui->eGlobPath->setText(globalPath);
127  _ui->ePrivPath->setText(QString());
128  _ui->ePrivPathD->setText(QString());
129  _ui->checkRelease->setChecked(true);
130  _ui->checkDelay->setChecked(false);
131  _ui->checkReload->setChecked(false);
132  _ui->checkPathPopup->setChecked(false);
133  _ui->comboCheckLevel->setCurrentIndex(2);
134  _setExcludes(defaults.value("excludeList").toStringList());
135  _ui->bButtonStyle->setCurrentIndex(Qt::ToolButtonFollowStyle);
136  _ui->checkRelativePaths->setChecked(true);
137 }
138 
139 void OptionsDialog::on_bBox_clicked(QAbstractButton* button) {
140  switch (_ui->bBox->buttonRole(button)) {
141  case QDialogButtonBox::ResetRole:
142  restore();
143  break;
144  case QDialogButtonBox::ApplyRole:
145  case QDialogButtonBox::AcceptRole:
146  apply();
147  break;
148  default:
149  break;
150  }
151 }
152 
154  QString page;
155  switch (_ui->tabOptions->currentIndex()) {
156  case 0:
157  page="#options-config";
158  break;
159  case 1:
160  page="#options-paths";
161  break;
162  case 2:
163  page="#options-excludes";
164  break;
165  case 3:
166  page="#options-appearance";
167  break;
168  default:
169  break;
170  }
171  emit helpRequested(
172  QString("tuchulcha-options.html%1").arg(page));
173 }
174 
175 void OptionsDialog::_setExcludes(QStringList list) const {
176  _ui->tableExclude->clear();
177  _ui->tableExclude->setRowCount(list.size()+1);
178  for (int i = 0; i < list.size(); i++) {
179  _ui->tableExclude->setItem(i,0,new QTableWidgetItem(list[i]));
180  }
181  _ui->tableExclude->setItem(list.size(),0,new QTableWidgetItem());
182 }
183 
184 QStringList OptionsDialog::_getExcludes() const {
185  QStringList res;
186  for (int i=0; i < _ui->tableExclude->rowCount(); i++) {
187  QTableWidgetItem* it = _ui->tableExclude->item(i,0);
188  if (it) {
189  res << it->data(Qt::DisplayRole).toString().trimmed();
190  }
191  }
192  res.removeAll(QString(""));
193  res.removeAll(QString::null);
194  return res;
195 }
196 
197 void OptionsDialog::on_tableExclude_itemChanged(QTableWidgetItem* item) const {
198  QTableWidget* tab = _ui->tableExclude;
199  int row = item->row();
200  int rowc = tab->rowCount();
201  if (item->data(Qt::DisplayRole).toString().isEmpty()) {
202  if (row < rowc-1) {
203  tab->removeRow(row);
204  }
205  }
206  else {
207  if (row >= rowc-1) {
208  tab->insertRow(rowc);
209  }
210  }
211 }
212 
214  QSettings settings;
215  if (settings.allKeys().isEmpty()) {
216  // first start (or config deleted)
217  return true;
218  }
219  bool errors = false;
220 
221  // make sure, that the exclude list is populated
222  // with default entries if unset
223  QSettings defaults(":/config/default.ini",QSettings::IniFormat);
224  if(!settings.contains("excludeList")) {
225  settings.setValue("excludeList",defaults.value("excludeList"));
226  }
227 
228  // check current path values
229  QStringList pVars, allPaths;
230  pVars<<"globalPluginPath"<<"privatePluginPath"<<"privatePluginPathD";
231 
232  foreach (const QString& pVar, pVars) {
233  QStringList paths = settings.value(pVar).toStringList();
234  QStringListIterator pIter(paths);
235  while (pIter.hasNext()) {
236  const QString& p = pIter.next();
237  if(!QDir(p).exists()) {
238  errors = true;
239  if (QMessageBox::question(
240  0,tr("path not found"),
241  tr("path <tt>%1</tt> has not been found.</br>"
242  "Remove it from <em>%2</em>?").arg(p).arg(pVar),
243  QMessageBox::Yes,QMessageBox::No) ==
244  QMessageBox::Yes) {
245  paths.removeAll(p);
246  }
247  }
248  }
249  settings.setValue(pVar,paths);
250  allPaths << paths;
251  }
252  if (allPaths.isEmpty()) {
253  return true; // something went wrong if all paths vanished
254  }
255 
256  return errors;
257 }
Ui::OptionsDialog * _ui
designer gui
Definition: OptionsDialog.h:78
void on_bBox_clicked(QAbstractButton *button)
handle button click events
void _setExcludes(QStringList list) const
set exclude list
void apply()
apply new settings values
bool charon_core_DLL_PUBLIC exists(const std::string &file)
void on_bBox_helpRequested()
handle help request
void setTab(int tab=-1)
set shown tab
OptionsDialog(QWidget *parent=0, Qt::WindowFlags f=0)
constructor
Declaration of class OptionsDialog.
void on_tableExclude_itemChanged(QTableWidgetItem *item) const
handle exclude list changes
void helpRequested(QString)
request help on specified page
QStringList _getExcludes() const
get exclude list
void restore()
restore default values
void refresh()
refresh from saved settings
static bool check()
Configures plugin paths.