qt: add missing initializers (CID 1325722)
[metze/wireshark/wip.git] / ui / qt / capture_preferences_frame.cpp
1 /* capture_preferences_frame.cpp
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include "config.h"
23
24 #include <glib.h>
25
26 #ifdef HAVE_LIBPCAP
27 #include "ui/capture_globals.h"
28 #endif
29
30 #include "capture_preferences_frame.h"
31 #include <ui_capture_preferences_frame.h>
32 #include "wireshark_application.h"
33
34 #include <QSpacerItem>
35
36 #include "ui/capture_ui_utils.h"
37 #include "ui/ui_util.h"
38
39 #include <cstdio>
40 #include <epan/prefs-int.h>
41
42 CapturePreferencesFrame::CapturePreferencesFrame(QWidget *parent) :
43     QFrame(parent),
44     ui(new Ui::CapturePreferencesFrame)
45 {
46     ui->setupUi(this);
47
48     pref_device_ = prefFromPrefPtr(&prefs.capture_device);
49     pref_prom_mode_ = prefFromPrefPtr(&prefs.capture_prom_mode);
50     pref_pcap_ng_ = prefFromPrefPtr(&prefs.capture_pcap_ng);
51     pref_real_time_ = prefFromPrefPtr(&prefs.capture_real_time);
52     pref_auto_scroll_ = prefFromPrefPtr(&prefs.capture_auto_scroll);
53     pref_show_info_ = prefFromPrefPtr(&prefs.capture_show_info);
54
55     // Setting the left margin via a style sheet clobbers its
56     // appearance.
57     int margin = style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
58     QRect geom = ui->defaultInterfaceSpacer->geometry();
59     geom.setWidth(margin);
60     ui->defaultInterfaceSpacer->setGeometry(geom);
61 }
62
63 CapturePreferencesFrame::~CapturePreferencesFrame()
64 {
65     delete ui;
66 }
67
68 void CapturePreferencesFrame::showEvent(QShowEvent *)
69 {
70     updateWidgets();
71 }
72
73 void CapturePreferencesFrame::updateWidgets()
74 {
75 #ifdef HAVE_LIBPCAP
76     interface_t device;
77     QString default_device_string;
78
79     if (pref_device_->stashed_val.string) {
80         default_device_string = pref_device_->stashed_val.string;
81     }
82     ui->defaultInterfaceComboBox->clear();
83     if (global_capture_opts.all_ifaces->len == 0) {
84         /*
85          * No interfaces - try refreshing the local interfaces, to
86          * see whether any have showed up (or privileges have changed
87          * to allow us to access them).
88          */
89         wsApp->refreshLocalInterfaces();
90     }
91     for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
92         device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
93
94         /* Continue if capture device is hidden */
95         if (device.hidden) {
96             continue;
97         }
98         ui->defaultInterfaceComboBox->addItem(QString((const char *)device.display_name));
99     }
100
101     if (!default_device_string.isEmpty()) {
102         ui->defaultInterfaceComboBox->setEditText(default_device_string);
103     } else {
104         ui->defaultInterfaceComboBox->clearEditText();
105     }
106
107     ui->capturePromModeCheckBox->setChecked(pref_prom_mode_->stashed_val.boolval);
108     ui->capturePcapNgCheckBox->setChecked(pref_pcap_ng_->stashed_val.boolval);
109     ui->captureRealTimeCheckBox->setChecked(pref_real_time_->stashed_val.boolval);
110     ui->captureAutoScrollCheckBox->setChecked(pref_auto_scroll_->stashed_val.boolval);
111     ui->captureShowInfoCheckBox->setChecked(pref_show_info_->stashed_val.boolval);
112 #endif // HAVE_LIBPCAP
113 }
114
115 void CapturePreferencesFrame::on_defaultInterfaceComboBox_editTextChanged(const QString &new_iface)
116 {
117     g_free((void *)pref_device_->stashed_val.string);
118     pref_device_->stashed_val.string = g_strdup(new_iface.toUtf8().constData());
119 }
120
121 void CapturePreferencesFrame::on_capturePromModeCheckBox_toggled(bool checked)
122 {
123     pref_prom_mode_->stashed_val.boolval = checked;
124 }
125
126 void CapturePreferencesFrame::on_capturePcapNgCheckBox_toggled(bool checked)
127 {
128     pref_pcap_ng_->stashed_val.boolval = checked;
129 }
130
131 void CapturePreferencesFrame::on_captureRealTimeCheckBox_toggled(bool checked)
132 {
133     pref_real_time_->stashed_val.boolval = checked;
134 }
135
136 void CapturePreferencesFrame::on_captureAutoScrollCheckBox_toggled(bool checked)
137 {
138     pref_auto_scroll_->stashed_val.boolval = checked;
139 }
140
141 void CapturePreferencesFrame::on_captureShowInfoCheckBox_toggled(bool checked)
142 {
143     pref_show_info_->stashed_val.boolval = checked;
144 }
145
146 /*
147  * Editor modelines
148  *
149  * Local Variables:
150  * c-basic-offset: 4
151  * tab-width: 8
152  * indent-tabs-mode: nil
153  * End:
154  *
155  * ex: set shiftwidth=4 tabstop=8 expandtab:
156  * :indentSize=4:tabSize=8:noTabs=true:
157  */