1e975d63a47294f2876d0d88b9efc3601a64511d
[metze/wireshark/wip.git] / ui / qt / about_dialog.cpp
1 /* about_dialog.cpp
2  *
3  * $Id$
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include "config.h"
25
26 #include "about_dialog.h"
27 #include "ui_about_dialog.h"
28
29 #include "wireshark_application.h"
30 #include <wsutil/filesystem.h>
31
32 #ifdef HAVE_LIBSMI
33 #include <epan/oids.h>
34 #endif
35 #ifdef HAVE_GEOIP
36 #include <epan/geoip_db.h>
37 #endif
38 #ifdef HAVE_LUA
39 #include <epan/wslua/init_wslua.h>
40 #endif
41
42 #include "../log.h"
43 #include "../version_info.h"
44 #include "../register.h"
45
46 #include "ui/text_import_scanner.h"
47 #include "ui/last_open_dir.h"
48 #include "ui/alert_box.h"
49 #include "ui/help_url.h"
50
51 #include "file.h"
52 #include "wsutil/file_util.h"
53 #include "wsutil/tempfile.h"
54 #include "wsutil/plugins.h"
55
56 #include <QtGui>
57 #include <QTextStream>
58
59 // To do:
60 // - Tweat and enhance ui...
61
62 void AboutDialog::about_folders_row(const char *name, const char *dir, const char *typ_file)
63 {
64     ui->tbFolders->setRowCount(ui->tbFolders->rowCount() + 1);
65
66     ui->tbFolders->setItem(ui->tbFolders->rowCount()-1, 0, new QTableWidgetItem(name));
67     ui->tbFolders->setItem(ui->tbFolders->rowCount()-1, 1, new QTableWidgetItem(dir));
68     ui->tbFolders->setItem(ui->tbFolders->rowCount()-1, 2, new QTableWidgetItem(typ_file));
69
70 }
71
72 static void plugins_add_description(const char *name, const char *version,
73                                     const char *types, const char *filename,
74                                     void *user_data )
75 {
76
77     QTableWidget *tbPlugins = (QTableWidget *)user_data;
78     tbPlugins->setRowCount(tbPlugins->rowCount() + 1);
79
80     tbPlugins->setItem(tbPlugins->rowCount()-1, 0, new QTableWidgetItem(name));
81     tbPlugins->setItem(tbPlugins->rowCount()-1, 1, new QTableWidgetItem(version));
82     tbPlugins->setItem(tbPlugins->rowCount()-1, 2, new QTableWidgetItem(types));
83     tbPlugins->setItem(tbPlugins->rowCount()-1, 3, new QTableWidgetItem(filename));
84 }
85
86
87 void AboutDialog::plugins_scan()
88 {
89 #ifdef HAVE_PLUGINS
90     plugins_get_descriptions(plugins_add_description, ui->tbPlugins);
91 #endif
92
93 #ifdef HAVE_LUA
94     wslua_plugins_get_descriptions(plugins_add_description, ui->tbPlugins);
95 #endif
96 }
97
98 AboutDialog::AboutDialog(QWidget *parent) :
99     QDialog(parent),
100     ui(new Ui::AboutDialog)
101 {
102     ui->setupUi(this);
103     QFile f_authors;
104     QFile f_license;
105     char *path = NULL;
106     const char *constpath;
107     gchar       *message;
108 #if defined (HAVE_LIBSMI) || defined (HAVE_GEOIP)
109     gint i;
110     gchar **resultArray;
111 #endif
112
113
114     /* Wireshark tab */
115
116     /* Construct the message string */
117     message = g_strdup_printf(
118         "Version " VERSION "%s\n"
119         "\n"
120         "%s"
121         "\n"
122         "%s"
123         "\n"
124         "%s"
125         "\n"
126         "Wireshark is Open Source Software released under the GNU General Public License.\n"
127         "\n"
128         "Check the man page and http://www.wireshark.org for more information.",
129         wireshark_svnversion, get_copyright_info(), comp_info_str->str,
130         runtime_info_str->str);
131
132     ui->label_wireshark->setTextInteractionFlags(Qt::TextSelectableByMouse);
133     ui->label_wireshark->setText(message);
134
135 /* Check if it is a dev release... (VERSION_MINOR is odd in dev release) */
136 #if VERSION_MINOR & 1
137         ui->label_logo->setPixmap( QPixmap( ":/about/wssplash_dev.png" ) );
138 #endif
139
140
141     /* Authors */
142
143     f_authors.setFileName(get_datafile_path("AUTHORS-SHORT"));
144     f_authors.open(QFile::ReadOnly | QFile::Text);
145     QTextStream ReadFile_authors(&f_authors);
146
147     ui->pte_Authors->insertPlainText(ReadFile_authors.readAll());
148     ui->pte_Authors->moveCursor(QTextCursor::Start);
149
150     /* Folders */
151
152     /* set column widths */
153
154 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
155     ui->tbFolders->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
156 #else
157     ui->tbFolders->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
158 #endif
159
160     ui->tbFolders->setRowCount(0);
161
162     /* "file open" */
163     about_folders_row("\"File\" dialogs", get_last_open_dir(), "capture files");
164
165     /* temp */
166     about_folders_row("Temp", g_get_tmp_dir(), "untitled capture files");
167
168     /* pers conf */
169     path = get_persconffile_path("", FALSE);
170     about_folders_row("Personal configuration", path, "\"dfilters\", \"preferences\", \"ethers\", ...");
171     g_free(path);
172
173     /* global conf */
174     constpath = get_datafile_dir();
175     if (constpath != NULL) {
176         about_folders_row("Global configuration", constpath, "\"dfilters\", \"preferences\", \"manuf\", ...");
177     }
178
179     /* system */
180     constpath = get_systemfile_dir();
181     about_folders_row("System", constpath, "\"ethers\", \"ipxnets\"");
182
183     /* program */
184     constpath = get_progfile_dir();
185     about_folders_row("Program", constpath, "program files");
186
187 #if defined(HAVE_PLUGINS) || defined(HAVE_LUA)
188     /* pers plugins */
189     path = get_plugins_pers_dir();
190     about_folders_row("Personal Plugins", path, "dissector plugins");
191     g_free(path);
192
193     /* global plugins */
194     about_folders_row("Global Plugins", get_plugin_dir(), "dissector plugins");
195 #endif
196
197 #ifdef HAVE_PYTHON
198     /* global python bindings */
199     about_folders_row("Python Bindings", get_wspython_dir(), "python bindings");
200 #endif
201
202 #ifdef HAVE_GEOIP
203     /* GeoIP */
204     path = geoip_db_get_paths();
205
206     resultArray = g_strsplit(path, G_SEARCHPATH_SEPARATOR_S, 10);
207
208     for(i = 0; resultArray[i]; i++)
209         about_folders_row("GeoIP path", g_strstrip(resultArray[i]), "GeoIP database search path");
210     g_strfreev(resultArray);
211     g_free(path);
212 #endif
213
214 #ifdef HAVE_LIBSMI
215     /* SMI MIBs/PIBs */
216     path = oid_get_default_mib_path();
217
218     resultArray = g_strsplit(path, G_SEARCHPATH_SEPARATOR_S, 10);
219
220     for(i = 0; resultArray[i]; i++)
221         about_folders_row("MIB/PIB path", g_strstrip(resultArray[i]), "SMI MIB/PIB search path");
222     g_strfreev(resultArray);
223     g_free(path);
224 #endif
225
226
227     /* Plugins */
228 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
229     ui->tbPlugins->horizontalHeader()->setResizeMode(3, QHeaderView::Stretch);
230 #else
231     ui->tbPlugins->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch);
232 #endif
233     plugins_scan();
234
235     /* License */
236
237 #if defined(_WIN32)
238     f_license.setFileName(get_datafile_path("COPYING.txt"));
239 #else
240     f_license.setFileName(get_datafile_path("COPYING"));
241 #endif
242
243     f_license.open(QFile::ReadOnly | QFile::Text);
244     QTextStream ReadFile_license(&f_license);
245
246     ui->pte_License->insertPlainText(ReadFile_license.readAll());
247     ui->pte_License->moveCursor(QTextCursor::Start);
248 }
249
250 AboutDialog::~AboutDialog()
251 {
252     delete ui;
253 }
254
255 /*
256  * Editor modelines
257  *
258  * Local Variables:
259  * c-basic-offset: 4
260  * tab-width: 8
261  * indent-tabs-mode: nil
262  * End:
263  *
264  * ex: set shiftwidth=4 tabstop=8 expandtab:
265  * :indentSize=4:tabSize=8:noTabs=true:
266  */