summaryrefslogtreecommitdiff
path: root/src/ui/prefdialog.cpp
blob: c9248d7bd9294de3798f39bd3621425e8535c261 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
// SPDX-License-Identifier: GPL-2.0-or-later

#include <QCloseEvent>
#include <QComboBox>
#include <QFileDialog>

#include "fqterm_config.h"
#include "fqterm_path.h"
#include "fqterm_trace.h"

#include "prefdialog.h"
#include "soundconf.h"

namespace FQTerm {

/*
 *  Constructs a prefDialog which is a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'.
 *
 *  The dialog will by default be modeless, unless you set 'modal' to
 *  TRUE to construct a modal dialog.
 */
prefDialog::prefDialog(FQTermConfig * config, QWidget *parent, Qt::WindowFlags fl)
    : QDialog(parent, fl),
      soundButtonGroup_(this),
      verticalSettingButtonGroup_(this),
      config_(config){
  ui_.setupUi(this);
  fileDialog_ = new FQTermFileDialog(config_);
  soundButtonGroup_.addButton(ui_.noneRadioButton, 0);
  soundButtonGroup_.addButton(ui_.beepRadioButton, 1);
  soundButtonGroup_.addButton(ui_.fileRadioButton, 2);
  verticalSettingButtonGroup_.addButton(ui_.topRadioButton, 0);
  verticalSettingButtonGroup_.addButton(ui_.middleRadioButton, 1);
  verticalSettingButtonGroup_.addButton(ui_.bottomRadioButton, 2);

  connectSlots();

  loadSetting();

}

/*
 *  Destroys the object and frees any allocated resources
 */
prefDialog::~prefDialog() {
  // no need to delete child widgets, Qt does it all for us
  delete fileDialog_;
}

void prefDialog::connectSlots() {
  FQ_VERIFY(connect(ui_.okPushButton, SIGNAL(clicked()), this, SLOT(onOK())));
  FQ_VERIFY(connect(ui_.cancelPushButton, SIGNAL(clicked()), this, SLOT(onCancel())));
  FQ_VERIFY(connect(ui_.selectsoundPushButton, SIGNAL(clicked()), this, SLOT(onSound())));
  FQ_VERIFY(connect(ui_.choosehttpPushButton, SIGNAL(clicked()), this, SLOT(onHttp())));
  //FQ_VERIFY(connect(ButtonGroup1 , SIGNAL(clicked(int)), this, SLOT(onBeep(int)) ));
  FQ_VERIFY(connect(ui_.browsePushButton, SIGNAL(clicked()), this, SLOT(onBrowse())));
  FQ_VERIFY(connect(ui_.imagePushButton, SIGNAL(clicked()), this, SLOT(onImage())));
  FQ_VERIFY(connect(ui_.poolPushButton, SIGNAL(clicked()), this, SLOT(onPool())));
  FQ_VERIFY(connect(ui_.styleSheetPushButton, SIGNAL(clicked()), this, SLOT(onStyleSheet())));
  FQ_VERIFY(connect(ui_.editorPushButton, SIGNAL(clicked()), this, SLOT(onEditor())));
}

void prefDialog::loadSetting() {

  QString strTmp;

  strTmp = config_->getItemValue("preference", "displayoffset");
  ui_.displayOffsetSlider->setSliderPosition(strTmp.toInt());

  strTmp = config_->getItemValue("preference", "xim");
  ui_.ximComboBox->setCurrentIndex(strTmp.toInt());

  strTmp = config_->getItemValue("preference", "wordwrap");
  ui_.wordLineEdit3->setText(strTmp);

  strTmp = config_->getItemValue("preference", "smartww");
  ui_.smartCheckBox->setChecked(strTmp != "0");

  strTmp = config_->getItemValue("preference", "wheel");
  ui_.wheelCheckBox->setChecked(strTmp != "0");

  strTmp = config_->getItemValue("preference", "url");
  ui_.urlCheckBox->setChecked(strTmp != "0");

  strTmp = config_->getItemValue("preference", "logmsg");
  ui_.saveCheckBox->setChecked(strTmp != "0");

  strTmp = config_->getItemValue("preference", "blinktab");
  ui_.blinkCheckBox->setChecked(strTmp != "0");

  strTmp = config_->getItemValue("preference", "warn");
  ui_.warnCheckBox->setChecked(strTmp != "0");

  strTmp = config_->getItemValue("preference", "beep");
  qobject_cast<QRadioButton *>(soundButtonGroup_.button(strTmp.toInt()))->setChecked(true);

  strTmp = config_->getItemValue("preference", "vsetting");
  qobject_cast<QRadioButton *>(verticalSettingButtonGroup_.button(strTmp.toInt()))->setChecked(true);

  strTmp = config_->getItemValue("preference", "enq");
  ui_.enqCheckBox->setChecked(strTmp != "0");

  //ButtonGroup1->find(strTmp.toInt()))->setChecked(true);

  // 	if(strTmp.toInt()!=2)
  // 	{
  // 		wavefileLineEdit->setEnabled(false);
  // 		selectsoundPushButton->setEnabled(false);
  // 	}

  strTmp = config_->getItemValue("preference", "wavefile");
  ui_.wavefileLineEdit->setText(strTmp);

  strTmp = config_->getItemValue("preference", "antialias");
  ui_.aacheckBox->setChecked(strTmp != "0");


  strTmp = config_->getItemValue("preference", "tray");
  ui_.trayCheckBox->setChecked(strTmp != "0");

  strTmp = config_->getItemValue("preference", "clearpool");
  ui_.clearCheckBox->setChecked(strTmp == "1");

  strTmp = config_->getItemValue("preference", "pool");
  if (strTmp.isEmpty()) {
    strTmp = getPath(USER_CONFIG) + "pool/";
  }
  ui_.poolLineEdit->setText(strTmp);

  strTmp = config_->getItemValue("preference", "http");
  ui_.httpLineEdit->setText(strTmp);

  strTmp = config_->getItemValue("preference", "zmodem");
  if (strTmp.isEmpty()) {
    strTmp = getPath(USER_CONFIG) + "zmodem/";
  }
  ui_.zmodemLineEdit->setText(strTmp);

  strTmp = config_->getItemValue("preference", "image");
  ui_.imageLineEdit->setText(strTmp);

  strTmp = config_->getItemValue("preference", "qssfile");
  ui_.styleSheetLineEdit->setText(strTmp);

  strTmp = config_->getItemValue("preference", "editor");
  ui_.editorLineEdit->setText(strTmp);

  strTmp = config_->getItemValue("preference", "editorarg");
  ui_.editorArgLineEdit->setText(strTmp);

  strTmp = config_->getItemValue("preference", "asciienhance");
  ui_.asciiEnhanceCheckBox->setChecked(strTmp == "1");
}

void prefDialog::saveSetting() {

  QString strTmp;

  strTmp.setNum(ui_.displayOffsetSlider->sliderPosition());
  config_->setItemValue("preference", "displayoffset", strTmp);

  strTmp.setNum(ui_.ximComboBox->currentIndex());
  config_->setItemValue("preference", "xim", strTmp);


  config_->setItemValue("preference", "wordwrap", ui_.wordLineEdit3->text());

  strTmp.setNum(ui_.smartCheckBox->isChecked() ? 1 : 0);
  config_->setItemValue("preference", "smartww", strTmp);

  strTmp.setNum(ui_.wheelCheckBox->isChecked() ? 1 : 0);
  config_->setItemValue("preference", "wheel", strTmp);

  strTmp.setNum(ui_.urlCheckBox->isChecked() ? 1 : 0);
  config_->setItemValue("preference", "url", strTmp);

  strTmp.setNum(ui_.saveCheckBox->isChecked() ? 1 : 0);
  config_->setItemValue("preference", "logmsg", strTmp);

  strTmp.setNum(ui_.blinkCheckBox->isChecked() ? 1 : 0);
  config_->setItemValue("preference", "blinktab", strTmp);

  strTmp.setNum(ui_.warnCheckBox->isChecked() ? 1 : 0);
  config_->setItemValue("preference", "warn", strTmp);

  strTmp.setNum(ui_.aacheckBox->isChecked() ? 1 : 0);
  config_->setItemValue("preference", "antialias", strTmp);

  strTmp.setNum(ui_.trayCheckBox->isChecked() ? 1 : 0);
  config_->setItemValue("preference", "tray", strTmp);

  strTmp.setNum(ui_.enqCheckBox->isChecked() ? 1 : 0);
  config_->setItemValue("preference", "enq", strTmp);

  strTmp.setNum(soundButtonGroup_.checkedId());
  config_->setItemValue("preference", "beep", strTmp);

  strTmp.setNum(verticalSettingButtonGroup_.checkedId());
  config_->setItemValue("preference", "vsetting", strTmp);

  if (strTmp == "2") {
    config_->setItemValue("preference", "wavefile", ui_.wavefileLineEdit->text());
  }

  strTmp.setNum(ui_.clearCheckBox->isChecked() ? 1 : 0);
  config_->setItemValue("preference", "clearpool", strTmp);

  strTmp.setNum(ui_.asciiEnhanceCheckBox->isChecked() ? 1 : 0);
  config_->setItemValue("preference", "asciienhance", strTmp);

  strTmp = ui_.poolLineEdit->text();
  if (strTmp.isEmpty()) {
    strTmp = getPath(USER_CONFIG) + "pool/";
  }
  config_->setItemValue("preference", "pool", strTmp);

  strTmp = ui_.zmodemLineEdit->text();
  if (strTmp.isEmpty()) {
    strTmp = getPath(USER_CONFIG) + "zmodem/";
  }
  config_->setItemValue("preference", "zmodem", strTmp);
  config_->setItemValue("preference", "http", ui_.httpLineEdit->text());
  config_->setItemValue("preference", "image", ui_.imageLineEdit->text());

  config_->setItemValue("preference", "qssfile", ui_.styleSheetLineEdit->text().trimmed());

  config_->setItemValue("preference", "editor", ui_.editorLineEdit->text());
  config_->setItemValue("preference", "editorarg", ui_.editorArgLineEdit->text());
  
  config_->save(getPath(USER_CONFIG) + "fqterm.cfg");
}

void prefDialog::closeEvent(QCloseEvent*) {
  reject();
}

void prefDialog::onOK() {
  saveSetting();
  done(1);
}

void prefDialog::onCancel() {
  done(0);
}

void prefDialog::onSound() {
  soundConf soundconf(config_, this);
  if (soundconf.exec() == 1) {
    loadSetting();
  }

}

void prefDialog::onHttp() {
  QString http = fileDialog_->getOpenName("Choose a WWW browser", "*");
  if (!http.isEmpty()) {
    ui_.httpLineEdit->setText(http);
  }

}

// void prefDialog::onBeep( int id )
// {
// 	if(id==2)
// 	{
// 		ui.wavefileLineEdit->setEnabled(true);
// 		ui.selectsoundPushButton->setEnabled(true);
// 	}
// 	else if(id==0 || id==1 )
// 	{
// 		ui.wavefileLineEdit->setEnabled(false);
// 		ui.selectsoundPushButton->setEnabled(false);
// 	}
// }

void prefDialog::onBrowse() {
  QString dir = fileDialog_->getExistingDirectory("Choose a directory", ui_.zmodemLineEdit->text());
  if (!dir.isEmpty()) {
    ui_.zmodemLineEdit->setText(dir);
  }
}

void prefDialog::onImage() {
  QString image = fileDialog_->getOpenName("Choose an Image Viewer", "*");
  if (!image.isEmpty()) {
    ui_.imageLineEdit->setText(image);
  }
}

void prefDialog::onPool() {
  QString pool = fileDialog_->getExistingDirectory("Choose a directory", ui_.poolLineEdit->text());
  if (!pool.isEmpty()) {
    ui_.poolLineEdit->setText(pool);
  }
}

void prefDialog::onStyleSheet()
{
  QString qssFile = fileDialog_->getOpenName("Choose a QSS File", "Qt Style Sheets (*.qss *.QSS)");
  if (!qssFile.isEmpty()) {
    ui_.styleSheetLineEdit->setText(qssFile);
  }
}

void prefDialog::onEditor() {
  QString editor = fileDialog_->getOpenName("Choose a directory", ui_.editorLineEdit->text());
  if (!editor.isEmpty()) {
    ui_.editorLineEdit->setText(editor);
  }
}
}  // namespace FQTerm

#include "prefdialog.moc"