1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2 * (c)LGPL2+
3 *
4 * LXQt - a lightweight, Qt based, desktop toolset
5 * https://lxqt.org
6 *
7 * Copyright: 2011 Razor team
8 * Authors:
9 * Maciej Płaza <plaza.maciej@gmail.com>
10 *
11 * This program or library is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20
21 * You should have received a copy of the GNU Lesser General
22 * Public License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 USA
25 *
26 * END_COMMON_COPYRIGHT_HEADER */
27
28
29 #include "lxqtnetworkmonitorconfiguration.h"
30 #include "ui_lxqtnetworkmonitorconfiguration.h"
31
32 extern "C" {
33 #include <statgrab.h>
34 }
35
36 #ifdef __sg_public
37 // since libstatgrab 0.90 this macro is defined, so we use it for version check
38 #define STATGRAB_NEWER_THAN_0_90 1
39 #endif
40
LXQtNetworkMonitorConfiguration(PluginSettings * settings,QWidget * parent)41 LXQtNetworkMonitorConfiguration::LXQtNetworkMonitorConfiguration(PluginSettings *settings, QWidget *parent) :
42 LXQtPanelPluginConfigDialog(settings, parent),
43 ui(new Ui::LXQtNetworkMonitorConfiguration)
44 {
45 setAttribute(Qt::WA_DeleteOnClose);
46 setObjectName(QStringLiteral("NetworkMonitorConfigurationWindow"));
47 ui->setupUi(this);
48
49 connect(ui->buttons, &QDialogButtonBox::clicked, this, &LXQtNetworkMonitorConfiguration::dialogButtonsAction);
50 connect(ui->iconCB, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &LXQtNetworkMonitorConfiguration::saveSettings);
51 connect(ui->interfaceCB, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &LXQtNetworkMonitorConfiguration::saveSettings);
52
53 loadSettings();
54 }
55
~LXQtNetworkMonitorConfiguration()56 LXQtNetworkMonitorConfiguration::~LXQtNetworkMonitorConfiguration()
57 {
58 delete ui;
59 }
60
saveSettings()61 void LXQtNetworkMonitorConfiguration::saveSettings()
62 {
63 settings().setValue(QStringLiteral("icon"), ui->iconCB->currentIndex());
64 settings().setValue(QStringLiteral("interface"), ui->interfaceCB->currentText());
65 }
66
loadSettings()67 void LXQtNetworkMonitorConfiguration::loadSettings()
68 {
69 ui->iconCB->setCurrentIndex(settings().value(QStringLiteral("icon"), 1).toInt());
70
71 int count;
72 #ifdef STATGRAB_NEWER_THAN_0_90
73 size_t ret_count;
74 sg_network_iface_stats* stats = sg_get_network_iface_stats(&ret_count);
75 count = (int)ret_count;
76 #else
77 sg_network_iface_stats* stats = sg_get_network_iface_stats(&count);
78 #endif
79 for (int ix = 0; ix < count; ix++)
80 ui->interfaceCB->addItem(QLatin1String(stats[ix].interface_name));
81
82 QString interface = settings().value(QStringLiteral("interface")).toString();
83 ui->interfaceCB->setCurrentIndex(qMax(qMin(0, count - 1), ui->interfaceCB->findText(interface)));
84 }
85