MSWSP: add parse_CNatLanguageRestriction()
[wireshark-wip.git] / ui / qt / file_set_dialog.cpp
blob837837f7df11d01835f68def1bb36dc72dd1ab2c
1 /* fileset_dialog.cpp
3 * $Id$
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
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.
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.
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.
24 #include "config.h"
26 #include <glib.h>
28 #include "file.h"
29 #include "fileset.h"
31 #include "ui/help_url.h"
33 #include <wsutil/str_util.h>
35 #include "file_set_dialog.h"
36 #include "ui_file_set_dialog.h"
37 #include "wireshark_application.h"
39 #include <QDialogButtonBox>
40 #include <QPushButton>
41 #include <QDateTime>
42 #include <QFontMetrics>
43 #include <QFont>
44 #include <QUrl>
46 Q_DECLARE_METATYPE(fileset_entry *)
48 /* this file is a part of the current file set, add it to the dialog */
49 void
50 fileset_dlg_add_file(fileset_entry *entry, void *window) {
51 FileSetDialog *fs_dlg = static_cast<FileSetDialog *>(window);
53 if (fs_dlg) fs_dlg->addFile(entry);
56 FileSetDialog::FileSetDialog(QWidget *parent) :
57 QDialog(parent),
58 fs_ui_(new Ui::FileSetDialog),
59 close_button_(NULL)
61 fs_ui_->setupUi(this);
63 fs_ui_->fileSetTree->headerItem();
65 close_button_ = fs_ui_->buttonBox->button(QDialogButtonBox::Close);
66 addFile();
69 FileSetDialog::~FileSetDialog()
71 delete fs_ui_;
74 /* a new capture file was opened, browse the dir and look for files matching the given file set */
75 void FileSetDialog::fileOpened(const capture_file *cf) {
76 if (!cf) return;
77 fs_ui_->fileSetTree->clear();
78 fileset_add_dir(cf->filename, this);
81 /* the capture file was closed */
82 void FileSetDialog::fileClosed() {
83 fileset_delete();
84 fs_ui_->fileSetTree->clear();
87 #include <QDebug>
88 void FileSetDialog::addFile(fileset_entry *entry) {
89 QString created;
90 QString modified;
91 QString dir_name;
92 QString elided_dir_name;
93 QTreeWidgetItem *entry_item;
94 gchar *size_str;
96 if (!entry) {
97 setWindowTitle(tr("Wireshark: No files in Set"));
98 fs_ui_->directoryLabel->setText(tr("No capture loaded"));
99 fs_ui_->directoryLabel->setEnabled(false);
100 return;
103 created = nameToDate(entry->name);
104 if(created.length() < 1) {
105 /* if this file doesn't follow the file set pattern, */
106 /* use the creation time of that file */
107 /* http://en.wikipedia.org/wiki/ISO_8601 */
108 created = QDateTime::fromTime_t(entry->ctime).toLocalTime().toString("yyyy-MM-dd HH:mm:ss");
111 modified = QDateTime::fromTime_t(entry->mtime).toLocalTime().toString("yyyy-MM-dd HH:mm:ss");
113 size_str = format_size(entry->size, format_size_unit_bytes|format_size_prefix_si);
115 entry_item = new QTreeWidgetItem(fs_ui_->fileSetTree);
116 entry_item->setToolTip(0, QString(tr("Open this capture file")));
117 entry_item->setData(0, Qt::UserRole, qVariantFromValue(entry));
119 entry_item->setText(0, entry->name);
120 entry_item->setText(1, created);
121 entry_item->setText(2, modified);
122 entry_item->setText(3, size_str);
123 g_free(size_str);
124 // Not perfect but better than nothing.
125 entry_item->setTextAlignment(3, Qt::AlignRight);
127 setWindowTitle(QString(tr("Wireshark: %1 File%2 in Set"))
128 .arg(fs_ui_->fileSetTree->topLevelItemCount())
129 .arg(plurality(fs_ui_->fileSetTree->topLevelItemCount(), "", "s")));
131 dir_name = fileset_get_dirname();
132 fs_ui_->directoryLabel->setText(dir_name);
133 fs_ui_->directoryLabel->setUrl(QUrl::fromLocalFile(dir_name).toString());
134 fs_ui_->directoryLabel->setEnabled(true);
136 if(entry->current) {
137 fs_ui_->fileSetTree->setCurrentItem(entry_item);
140 if (close_button_)
141 close_button_->setEnabled(true);
143 fs_ui_->fileSetTree->addTopLevelItem(entry_item);
144 for (int i = 0; i < fs_ui_->fileSetTree->columnCount(); i++)
145 fs_ui_->fileSetTree->resizeColumnToContents(i);
146 fs_ui_->fileSetTree->setFocus();
149 QString FileSetDialog::nameToDate(const char *name) {
150 QString dn;
152 if (!fileset_filename_match_pattern(name))
153 return NULL;
155 dn = name;
156 dn.remove(QRegExp(".*_"));
157 dn.truncate(14);
158 dn.insert(4, '-');
159 dn.insert(7, '-');
160 dn.insert(10, ' ');
161 dn.insert(13, ':');
162 dn.insert(16, ':');
163 return dn;
166 void FileSetDialog::on_buttonBox_helpRequested()
168 wsApp->helpTopicAction(HELP_FILESET_DIALOG);
171 void FileSetDialog::on_fileSetTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
173 Q_UNUSED(previous);
175 fileset_entry *entry;
177 if (!current)
178 return;
180 entry = current->data(0, Qt::UserRole).value<fileset_entry *>();
182 if (!entry || entry->current)
183 return;
185 QString new_cf_path = entry->fullname;
187 if (new_cf_path.length() > 0)
188 emit fileSetOpenCaptureFile(new_cf_path);
192 * Editor modelines
194 * Local Variables:
195 * c-basic-offset: 4
196 * tab-width: 8
197 * indent-tabs-mode: nil
198 * End:
200 * ex: set shiftwidth=4 tabstop=8 expandtab:
201 * :indentSize=4:tabSize=8:noTabs=true: