-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingsdialog.cpp
More file actions
103 lines (82 loc) · 2.83 KB
/
Copy pathsettingsdialog.cpp
File metadata and controls
103 lines (82 loc) · 2.83 KB
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
#include <QTreeWidgetItem>
#include <QDebug>
#include <QPushButton>
#include "bitslinger.h"
#include "settings/proxysettingspage.h"
#include "settings/sslcasettingspage.h"
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
SettingsDialog::SettingsDialog(BitSlinger *slinger, QWidget *parent) :
QDialog(parent),
ui(new Ui::SettingsDialog),
m_slinger(slinger)
{
ui->setupUi(this);
createPages();
ui->splitter->setStretchFactor(0, 1);
ui->splitter->setStretchFactor(1, 6);
ui->pageTitle->setText(pages[0]->windowTitle());
ui->pageStack->setCurrentIndex(0);
pages[0]->aboutToShow();
ui->pageStack->setCurrentIndex(0);
connect(ui->treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
this, SLOT(pageChanged()));
connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
this, SLOT(apply()));
connect(ui->buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()),
this, SLOT(apply()));
connect(ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
this, SLOT(reset()));
connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()),
this, SLOT(defaults()));
}
SettingsDialog::~SettingsDialog()
{
delete ui;
}
void SettingsDialog::createPages()
{
ProxySettingsPage *proxySettings = new ProxySettingsPage();
connect(proxySettings, SIGNAL(saved()), m_slinger, SLOT(loadProxyConfig()));
addPage(proxySettings);
SslCaSettingsPage *sslCaSettings = new SslCaSettingsPage();
connect(sslCaSettings, SIGNAL(saved()), m_slinger, SLOT(loadCaConfig()));
addPage(sslCaSettings);
}
void SettingsDialog::addPage(SettingsPage *page)
{
qDebug() << "Adding page" << page->windowTitle();
pages.append(page);
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget);
item->setText(0, page->windowTitle());
ui->pageStack->addWidget(page);
}
void SettingsDialog::pageChanged()
{
int index = ui->treeWidget->currentIndex().row();
if (index < 0)
return;
int prev = ui->pageStack->currentIndex();
if (!pages[prev]->aboutToClose()) {
QTreeWidgetItem *item = ui->treeWidget->topLevelItem(prev);
item->setSelected(true);
qDebug() << "attempting to select" << item->text(0);
return;
}
qDebug() << "Changing to page" << index;
pages[index]->aboutToShow();
ui->pageTitle->setText(pages[index]->windowTitle());
ui->pageStack->setCurrentIndex(index);
}
void SettingsDialog::apply()
{
static_cast<SettingsPage *>(ui->pageStack->currentWidget())->save();
}
void SettingsDialog::defaults()
{
static_cast<SettingsPage *>(ui->pageStack->currentWidget())->defaults();
}
void SettingsDialog::reset()
{
static_cast<SettingsPage *>(ui->pageStack->currentWidget())->reset();
}