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.
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>
42 #include <QFontMetrics>
46 Q_DECLARE_METATYPE(fileset_entry
*)
48 /* this file is a part of the current file set, add it to the dialog */
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
) :
58 fs_ui_(new Ui::FileSetDialog
),
61 fs_ui_
->setupUi(this);
63 fs_ui_
->fileSetTree
->headerItem();
65 close_button_
= fs_ui_
->buttonBox
->button(QDialogButtonBox::Close
);
69 FileSetDialog::~FileSetDialog()
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
) {
77 fs_ui_
->fileSetTree
->clear();
78 fileset_add_dir(cf
->filename
, this);
81 /* the capture file was closed */
82 void FileSetDialog::fileClosed() {
84 fs_ui_
->fileSetTree
->clear();
88 void FileSetDialog::addFile(fileset_entry
*entry
) {
92 QString elided_dir_name
;
93 QTreeWidgetItem
*entry_item
;
97 setWindowTitle(tr("Wireshark: No files in Set"));
98 fs_ui_
->directoryLabel
->setText(tr("No capture loaded"));
99 fs_ui_
->directoryLabel
->setEnabled(false);
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
);
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);
137 fs_ui_
->fileSetTree
->setCurrentItem(entry_item
);
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
) {
152 if (!fileset_filename_match_pattern(name
))
156 dn
.remove(QRegExp(".*_"));
166 void FileSetDialog::on_buttonBox_helpRequested()
168 wsApp
->helpTopicAction(HELP_FILESET_DIALOG
);
171 void FileSetDialog::on_fileSetTree_currentItemChanged(QTreeWidgetItem
*current
, QTreeWidgetItem
*previous
)
175 fileset_entry
*entry
;
180 entry
= current
->data(0, Qt::UserRole
).value
<fileset_entry
*>();
182 if (!entry
|| entry
->current
)
185 QString new_cf_path
= entry
->fullname
;
187 if (new_cf_path
.length() > 0)
188 emit
fileSetOpenCaptureFile(new_cf_path
);
197 * indent-tabs-mode: nil
200 * ex: set shiftwidth=4 tabstop=8 expandtab:
201 * :indentSize=4:tabSize=8:noTabs=true: