drumstick 2.0.0
networksettingsdialog.cpp
Go to the documentation of this file.
1/*
2 Virtual Piano test using the MIDI Sequencer C++ library
3 Copyright (C) 2006-2020, Pedro Lopez-Cabanillas <plcl@users.sf.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU 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 This program 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include <QDialogButtonBox>
20#include <QNetworkInterface>
21#include <QPushButton>
22
24#include "ui_networksettingsdialog.h"
26
31
32namespace drumstick { namespace widgets {
33
34const QString NetworkSettingsDialog::QSTR_ADDRESS_IPV4 = QStringLiteral("225.0.0.37");
35const QString NetworkSettingsDialog::QSTR_ADDRESS_IPV6 = QStringLiteral("ff12::37");
36
37NetworkSettingsDialog::NetworkSettingsDialog(QWidget *parent) :
38 QDialog(parent),
39 ui(new Ui::NetworkSettingsDialog)
40{
41 ui->setupUi(this);
42 connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::pressed,
43 this, &NetworkSettingsDialog::restoreDefaults);
44 connect(ui->checkIPv6, &QCheckBox::toggled, this, &NetworkSettingsDialog::toggledIPv6);
45}
46
47NetworkSettingsDialog::~NetworkSettingsDialog()
48{
49 delete ui;
50}
51
52void NetworkSettingsDialog::accept()
53{
54 writeSettings();
55 QDialog::accept();
56}
57
58void NetworkSettingsDialog::showEvent(QShowEvent *event)
59{
60 readSettings();
61 event->accept();
62}
63
64void NetworkSettingsDialog::readSettings()
65{
66 SettingsFactory settings;
67 settings->beginGroup("Network");
68 QString ifaceName = settings->value("interface", QString()).toString();
69 bool ipv6 = settings->value("ipv6", false).toBool();
70 QString address = settings->value("address", ipv6 ? QSTR_ADDRESS_IPV6 : QSTR_ADDRESS_IPV4).toString();
71 settings->endGroup();
72
73 ui->txtAddress->setText(address);
74 ui->checkIPv6->setChecked(ipv6);
75 ui->comboInterface->addItem(tr("Any"), "");
76 foreach( const QNetworkInterface& iface, QNetworkInterface::allInterfaces() ) {
77 if ( iface.isValid() &&
78 iface.flags().testFlag(QNetworkInterface::CanMulticast) &&
79 iface.flags().testFlag(QNetworkInterface::IsUp) &&
80 iface.flags().testFlag(QNetworkInterface::IsRunning) &&
81 !iface.flags().testFlag(QNetworkInterface::IsLoopBack) ) {
82 QString name = iface.name();
83 QString text = iface.humanReadableName();
84 ui->comboInterface->addItem(text, name);
85 if (name == ifaceName) {
86 ui->comboInterface->setCurrentText(text);
87 }
88 }
89 }
90}
91
92void NetworkSettingsDialog::writeSettings()
93{
94 SettingsFactory settings;
95 QString networkAddr = ui->txtAddress->text();
96 QString networkIface = ui->comboInterface->currentData().toString();
97 bool ipv6 = ui->checkIPv6->isChecked();
98
99 settings->beginGroup("Network");
100 settings->setValue("address", networkAddr);
101 settings->setValue("interface", networkIface);
102 settings->setValue("ipv6", ipv6);
103 settings->endGroup();
104 settings->sync();
105}
106
107void NetworkSettingsDialog::restoreDefaults()
108{
109 ui->checkIPv6->setChecked(false);
110 ui->txtAddress->setText(QSTR_ADDRESS_IPV4);
111 ui->comboInterface->setCurrentText(tr("Any"));
112}
113
114void NetworkSettingsDialog::toggledIPv6(bool checked)
115{
116 ui->txtAddress->setText(checked ? QSTR_ADDRESS_IPV6 : QSTR_ADDRESS_IPV4);
117}
118
119} // namespace widgets
120} // namespace drumstick
Drumstick Widgets library MIDI related widgets and functions.
Drumstick common.
Declaration of the Network configuration dialog.
SettingsFactory class declaration.