Starting to get rid of Q_UNUSED declarations for unused function parameters.
[metze/wireshark/wip.git] / ui / qt / remote_capture_dialog.cpp
1 /* remote_capture_dialog.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 // XXX This shouldn't exist. These controls should be in ManageInterfacesDialog instead.
23
24 #include "config.h"
25 #ifdef HAVE_PCAP_REMOTE
26 #include <glib.h>
27 #include "qt_ui_utils.h"
28 #include "ui/capture_globals.h"
29 #include "remote_capture_dialog.h"
30 #include <ui_remote_capture_dialog.h>
31 #include "capture_opts.h"
32 #include "caputils/capture-pcap-util.h"
33 #include "ui/capture_ui_utils.h"
34 #include "epan/prefs.h"
35 #include "epan/to_str.h"
36 #include "ui/ui_util.h"
37 #include "ui/recent.h"
38
39 #include <QMessageBox>
40
41 static guint num_selected = 0;
42
43 RemoteCaptureDialog::RemoteCaptureDialog(QWidget *parent) :
44     QDialog(parent),
45     ui(new Ui::RemoteCaptureDialog)
46 {
47     ui->setupUi(this);
48
49     fillComboBox();
50     connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(apply_remote()));
51     connect(this, SIGNAL(remoteAdded(GList *, remote_options*)), parent, SIGNAL(remoteAdded(GList *, remote_options*)));
52     connect(ui->hostCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(hostChanged(QString)));
53 }
54
55 RemoteCaptureDialog::~RemoteCaptureDialog()
56 {
57     delete ui;
58 }
59
60 void RemoteCaptureDialog::hostChanged(QString host)
61 {
62     if (!host.compare(tr("Clear list"))) {
63         free_remote_host_list();
64         ui->hostCombo->clear();
65     } else {
66         struct remote_host *rh = recent_get_remote_host(host.toUtf8().constData());
67         if (rh) {
68             ui->portText->setText(QString(rh->remote_port));
69             if (rh->auth_type == CAPTURE_AUTH_NULL) {
70                 ui->nullAuth->setChecked(true);
71             } else {
72                 ui->pwAuth->setChecked(true);
73             }
74         }
75     }
76
77 }
78
79 static void fillBox(gpointer key, gpointer, gpointer)
80 {
81     QComboBox *cb = (QComboBox *)user_data;
82     cb->addItem(QString((gchar*)key));
83 }
84
85 void RemoteCaptureDialog::fillComboBox()
86 {
87     GHashTable *ht = get_remote_host_list();
88     ui->hostCombo->addItem(QString(""));
89     if (g_hash_table_size(ht) > 0) {
90         g_hash_table_foreach(ht, fillBox, ui->hostCombo);
91         ui->hostCombo->insertSeparator(g_hash_table_size(ht)+1);
92         ui->hostCombo->addItem(QString(tr("Clear list")));
93     }
94 }
95
96 void RemoteCaptureDialog::apply_remote()
97 {
98     int err;
99     gchar *err_str;
100     remote_options global_remote_opts;
101
102     QString host = ui->hostCombo->currentText();
103     global_remote_opts.src_type = CAPTURE_IFREMOTE;
104     global_remote_opts.remote_host_opts.remote_host = qstring_strdup(host);
105     QString port = ui->portText->text();
106     global_remote_opts.remote_host_opts.remote_port = qstring_strdup(port);
107     if (ui->pwAuth->isChecked()) {
108         global_remote_opts.remote_host_opts.auth_type = CAPTURE_AUTH_PWD;
109     } else {
110         global_remote_opts.remote_host_opts.auth_type = CAPTURE_AUTH_NULL;
111     }
112     QString user = ui->userText->text();
113     global_remote_opts.remote_host_opts.auth_username = qstring_strdup(user);
114     QString pw = ui->pwText->text();
115     global_remote_opts.remote_host_opts.auth_password = qstring_strdup(pw);
116     GList *rlist = get_remote_interface_list(global_remote_opts.remote_host_opts.remote_host,
117                                               global_remote_opts.remote_host_opts.remote_port,
118                                               global_remote_opts.remote_host_opts.auth_type,
119                                               global_remote_opts.remote_host_opts.auth_username,
120                                               global_remote_opts.remote_host_opts.auth_password,
121                                               &err, &err_str);
122     if (rlist == NULL &&
123         (err == CANT_GET_INTERFACE_LIST || err == DONT_HAVE_PCAP)) {
124         QMessageBox::warning(this, tr("Error"),
125                              (err == CANT_GET_INTERFACE_LIST?tr("No remote interfaces found."):tr("PCAP not found")));
126         return;
127     }
128     if (ui->hostCombo->count() == 0) {
129         ui->hostCombo->addItem("");
130         ui->hostCombo->addItem(host);
131         ui->hostCombo->insertSeparator(2);
132         ui->hostCombo->addItem(QString(tr("Clear list")));
133     } else {
134         ui->hostCombo->insertItem(0, host);
135     }
136     struct remote_host *rh = recent_get_remote_host(host.toUtf8().constData());
137     if (!rh) {
138         rh = (struct remote_host *)g_malloc (sizeof (*rh));
139         rh->r_host = qstring_strdup(host);
140         rh->remote_port = qstring_strdup(port);
141         rh->auth_type = global_remote_opts.remote_host_opts.auth_type;
142         rh->auth_password = g_strdup("");
143         rh->auth_username = g_strdup("");
144         recent_add_remote_host(global_remote_opts.remote_host_opts.remote_host, rh);
145     }
146     emit remoteAdded(rlist, &global_remote_opts);
147 }
148
149 void RemoteCaptureDialog::on_pwAuth_toggled(bool checked)
150 {
151     if (checked) {
152         ui->userLabel->setEnabled(true);
153         ui->userText->setEnabled(true);
154         ui->pwLabel->setEnabled(true);
155         ui->pwText->setEnabled(true);
156     }
157 }
158
159 void RemoteCaptureDialog::on_nullAuth_toggled(bool checked)
160 {
161     if (checked) {
162         ui->userLabel->setEnabled(false);
163         ui->userText->setEnabled(false);
164         ui->pwLabel->setEnabled(false);
165         ui->pwText->setEnabled(false);
166     }
167 }
168 #endif /* HAVE_PCAP_REMOTE */
169
170 /*
171  * Editor modelines
172  *
173  * Local Variables:
174  * c-basic-offset: 4
175  * tab-width: 8
176  * indent-tabs-mode: nil
177  * End:
178  *
179  * ex: set shiftwidth=4 tabstop=8 expandtab:
180  * :indentSize=4:tabSize=8:noTabs=true:
181  */