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
|
#include "settingsdialog.h"
#include "settings.h"
#include "globals.h"
#include <QGroupBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QVariant>
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent)
{
QVBoxLayout *settingsLayout = new QVBoxLayout();
QGroupBox *groupBox = new QGroupBox(tr("Direct Connections"), this);
QVBoxLayout *directc2cLayout = new QVBoxLayout();
rbDisableDirectConns = new QRadioButton(tr("Disable direct connections"), this);
rbEnableOutgoingConns = new QRadioButton(tr("Enable only outgoing direct connections"), this);
rbEnableIncomingConns = new QRadioButton(tr("Enable incoming direct connections"), this);
rbEnableIncomingConns->setChecked(true);
QLabel *lbAddr = new QLabel(tr("Public address for incoming connections"), this);
addr = new QLineEdit(tr("0.0.0.0"), this);
publicPort = new QSpinBox(this);
localPort = new QSpinBox(this);
publicPort->setRange(1, 65535);
localPort->setRange(1, 65535);
publicPort->setValue(2298);
localPort->setValue(2298);
directc2cLayout->addWidget(rbDisableDirectConns);
directc2cLayout->addWidget(rbEnableOutgoingConns);
directc2cLayout->addWidget(rbEnableIncomingConns);
directc2cLayout->addWidget(lbAddr);
directc2cLayout->addWidget(addr);
directc2cLayout->addWidget(publicPort);
directc2cLayout->addWidget(localPort);
directc2cLayout->addStretch(1);
groupBox->setLayout(directc2cLayout);
settingsLayout->addWidget(groupBox);
QHBoxLayout *buttonsLayout = new QHBoxLayout;
btOk = new QPushButton(tr("&OK"), this);
btCancel = new QPushButton(tr("Cancel"), this);
buttonsLayout->addStretch(1);
buttonsLayout->addWidget(btOk);
buttonsLayout->addWidget(btCancel);
settingsLayout->addLayout(buttonsLayout);
setLayout(settingsLayout);
connect(btOk, SIGNAL(clicked()), this, SLOT(OK()));
connect(btCancel, SIGNAL(clicked()), this, SLOT(Cancel()));
loadSettings();
setWindowTitle(tr("Pica Pica Messenger Settings"));
}
void SettingsDialog::OK()
{
storeSettings();
done(1);
}
void SettingsDialog::Cancel()
{
done(0);
}
void SettingsDialog::loadSettings()
{
Settings st(config_dbname);
//Direct c2c connections
int c2c_state;
c2c_state = st.loadValue("direct_c2c.state", 1).toInt();
switch (c2c_state)
{
case 0:
rbDisableDirectConns->setChecked(true);
break;
case 1:
rbEnableOutgoingConns->setChecked(true);
break;
case 2:
rbEnableIncomingConns->setChecked(true);
break;
default:
break;
}
addr->setText(st.loadValue("direct_c2c.public_addr", "0.0.0.0").toString());
publicPort->setValue(st.loadValue("direct_c2c.public_port", 2298).toInt());
localPort->setValue(st.loadValue("direct_c2c.local_port", 2298).toInt());
}
void SettingsDialog::storeSettings()
{
Settings st(config_dbname);
//Direct c2c connections
int c2c_state;
if (rbDisableDirectConns->isChecked())
c2c_state = 0;
else if (rbEnableOutgoingConns->isChecked())
c2c_state = 1;
else if (rbEnableIncomingConns->isChecked())
c2c_state = 2;
st.storeValue("direct_c2c.state", QString::number(c2c_state));
st.storeValue("direct_c2c.public_addr", addr->text());
st.storeValue("direct_c2c.public_port", QString::number(publicPort->value()));
st.storeValue("direct_c2c.local_port", QString::number(localPort->value()));
}
|