aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/interface_tree.cpp
blob: b8866fe47d66563b1ec0fbc5748c9cf0a84987fc (plain)
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
/* interface_tree.cpp
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#include "interface_tree.h"

#include "config.h"

#ifdef HAVE_LIBPCAP
#include "capture.h"
#include "capture-pcap-util.h"
#include "capture_opts.h"
#include "capture_ui_utils.h"
#endif

#include <QLabel>
#include <QHeaderView>

InterfaceTree::InterfaceTree(QWidget *parent) :
    QTreeWidget(parent)
{
    GList *if_list;
    QTreeWidgetItem *ti;
    int err;
    gchar *err_str = NULL;

    header()->setVisible(false);
    setRootIsDecorated(false);
    setUniformRowHeights(true);
    setAccessibleName(tr("Welcome screen list"));

    setStyleSheet(
            "QTreeWidget {"
            "  border: 0;"
            "}"
            );

    if_list = capture_interface_list(&err, &err_str);
    g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: move if_list_comparator_alph out of ui/gtk/");
//    if_list = g_list_sort(if_list, if_list_comparator_alph);

    if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
        ti = new QTreeWidgetItem();
        QLabel *label = new QLabel(QString(tr("<h3>No interfaces found</h3>%1")).arg(QString().fromUtf8(err_str)));
        label->setWordWrap(true);

        setDisabled(true);
        addTopLevelItem(ti);
        setItemWidget(ti, 0, label);
        return;
    } else if (err_str) {
        g_free(err_str);
    }

    // XXX Do we need to check for this? capture_interface_list returns an error if the length is 0.
    if (g_list_length(if_list) > 0) {
        if_info_t *if_info;
        GList *curr;
        setDisabled(false);

        for (curr = g_list_first(if_list); curr; curr = g_list_next(curr)) {
            if_info = (if_info_t *) curr->data;
            /* Continue if capture device is hidden */
//            if (prefs_is_capture_device_hidden(if_info->name)) {
//                continue;
//            }

            ti = new QTreeWidgetItem();
            ti->setText(0, QString().fromUtf8(if_info->description ? if_info->description : if_info->name));
            addTopLevelItem(ti);
        }
    }
    free_interface_list(if_list);
}