Fill in some missing functionality. Rename some variables and rearrange

a few things.

svn path=/trunk/; revision=44641
This commit is contained in:
Gerald Combs 2012-08-23 17:29:05 +00:00
parent 7cd408ebf4
commit a04d6e4690
4 changed files with 172 additions and 191 deletions

View File

@ -43,18 +43,18 @@
#include "ui/main_statusbar.h"
#include "ui/recent.h"
#include "ui/recent_utils.h"
#include "ui/ui_util.h"
#include <QTreeWidget>
#include <QTabWidget>
#include <QTextEdit>
static gboolean enable_color;
#include <QScrollBar>
// If we ever add the ability to open multiple capture files we might be
// able to use something like QMap<capture_file *, PacketList *> to match
// capture files against packet lists and models.
static PacketList *cur_packet_list = NULL;
static PacketList *gbl_cur_packet_list = NULL;
guint
new_packet_list_append(column_info *cinfo, frame_data *fdata, packet_info *pinfo)
@ -62,7 +62,7 @@ new_packet_list_append(column_info *cinfo, frame_data *fdata, packet_info *pinfo
Q_UNUSED(cinfo);
Q_UNUSED(pinfo);
if (!cur_packet_list)
if (!gbl_cur_packet_list)
return 0;
/* fdata should be filled with the stuff we need
@ -70,7 +70,7 @@ new_packet_list_append(column_info *cinfo, frame_data *fdata, packet_info *pinfo
*/
guint visible_pos;
visible_pos = cur_packet_list->packetListModel()->appendPacket(fdata);
visible_pos = gbl_cur_packet_list->packetListModel()->appendPacket(fdata);
return visible_pos;
}
@ -94,19 +94,19 @@ g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: new_packet_list_resize_column %d", col);
void
new_packet_list_select_first_row(void)
{
if (!cur_packet_list)
if (!gbl_cur_packet_list)
return;
cur_packet_list->goFirstPacket();
cur_packet_list->setFocus();
gbl_cur_packet_list->goFirstPacket();
gbl_cur_packet_list->setFocus();
}
void
new_packet_list_select_last_row(void)
{
if (!cur_packet_list)
if (!gbl_cur_packet_list)
return;
cur_packet_list->goLastPacket();
cur_packet_list->setFocus();
gbl_cur_packet_list->goLastPacket();
gbl_cur_packet_list->setFocus();
}
/*
@ -117,9 +117,9 @@ new_packet_list_select_last_row(void)
gboolean
new_packet_list_select_row_from_data(frame_data *fdata_needle)
{
int row = cur_packet_list->packetListModel()->visibleIndexOf(fdata_needle);
int row = gbl_cur_packet_list->packetListModel()->visibleIndexOf(fdata_needle);
if (row >= 0) {
cur_packet_list->setCurrentIndex(cur_packet_list->packetListModel()->index(row,0));
gbl_cur_packet_list->setCurrentIndex(gbl_cur_packet_list->packetListModel()->index(row,0));
return TRUE;
}
@ -129,114 +129,88 @@ new_packet_list_select_row_from_data(frame_data *fdata_needle)
gboolean
new_packet_list_check_end(void)
{
gboolean at_end = FALSE;
// GtkAdjustment *adj;
g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: new_packet_list_check_end");
// adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(packetlist->view));
// g_return_val_if_fail(adj != NULL, FALSE);
//#if GTK_CHECK_VERSION(2,14,0)
// if (gtk_adjustment_get_value(adj) >= gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj)) {
//#else
// if (adj->value >= adj->upper - adj->page_size) {
//#endif
// at_end = TRUE;
// }
//#ifdef HAVE_LIBPCAP
//#if GTK_CHECK_VERSION(2,14,0)
// if (gtk_adjustment_get_value(adj) > 0 && at_end != last_at_end && at_end != auto_scroll_live) {
//#else
// if (adj->value > 0 && at_end != last_at_end && at_end != auto_scroll_live) {
//#endif
// menu_auto_scroll_live_changed(at_end);
// }
//#endif
// last_at_end = at_end;
return at_end;
if (gbl_cur_packet_list) {
QScrollBar *sb = gbl_cur_packet_list->verticalScrollBar();
if (sb && sb->isVisible() && sb->value() == sb->maximum()) {
return TRUE;
}
}
return FALSE;
}
void
new_packet_list_clear(void)
{
g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: new_packet_list_clear");
cur_packet_list->clear();
if (gbl_cur_packet_list) {
gbl_cur_packet_list->clear();
}
}
void
new_packet_list_enable_color(gboolean enable)
{
enable_color = enable;
g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: new_packet_list_enable_color: %d", enable);
// gtk_widget_queue_draw (packetlist->view);
if (gbl_cur_packet_list && gbl_cur_packet_list->packetListModel()) {
gbl_cur_packet_list->packetListModel()->setColorEnabled(enable);
gbl_cur_packet_list->update();
}
}
void
new_packet_list_freeze(void)
{
g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: new_packet_list_freeze");
// /* So we don't lose the model by the time we want to thaw it */
// g_object_ref(packetlist);
// /* Detach view from model */
// gtk_tree_view_set_model(GTK_TREE_VIEW(packetlist->view), NULL);
if (gbl_cur_packet_list) {
gbl_cur_packet_list->setUpdatesEnabled(false);
}
}
void
new_packet_list_thaw(void)
{
g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: new_packet_list_thaw");
// /* Apply model */
// gtk_tree_view_set_model( GTK_TREE_VIEW(packetlist->view), GTK_TREE_MODEL(packetlist));
if (gbl_cur_packet_list) {
gbl_cur_packet_list->setUpdatesEnabled(true);
}
// /* Remove extra reference added by new_packet_list_freeze() */
// g_object_unref(packetlist);
packets_bar_update();
packets_bar_update();
}
void
new_packet_list_recreate_visible_rows(void)
{
cur_packet_list->packetListModel()->recreateVisibleRows();
if (gbl_cur_packet_list && gbl_cur_packet_list->packetListModel()) {
gbl_cur_packet_list->packetListModel()->recreateVisibleRows();
}
}
frame_data *
new_packet_list_get_row_data(gint row)
{
if (!cur_packet_list)
return NULL;
return cur_packet_list->packetListModel()->getRowFdata(row);
if (gbl_cur_packet_list && gbl_cur_packet_list->packetListModel()) {
return gbl_cur_packet_list->packetListModel()->getRowFdata(row);
}
return NULL;
}
void
new_packet_list_moveto_end(void)
{
if (cur_packet_list)
cur_packet_list->goLastPacket();
if (gbl_cur_packet_list)
gbl_cur_packet_list->goLastPacket();
}
/* Redraw the packet list *and* currently-selected detail */
void
new_packet_list_queue_draw(void)
{
// GtkTreeSelection *selection;
// GtkTreeIter iter;
// gint row;
if (gbl_cur_packet_list)
gbl_cur_packet_list->updateAll();
}
g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: new_packet_list_queue_draw");
// gtk_widget_queue_draw (packetlist->view);
void
new_packet_list_recent_write_all(FILE *rf) {
if (!gbl_cur_packet_list)
return;
// selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(packetlist->view));
// if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
// return;
// row = row_number_from_iter(&iter);
// cf_select_packet(&cfile, row);
cf_select_packet(&cfile, 1);
gbl_cur_packet_list->writeRecent(rf);
}
#define MIN_COL_WIDTH_STR "...."
@ -252,9 +226,11 @@ PacketList::PacketList(QWidget *parent) :
packet_list_model_ = new PacketListModel(this, &cfile);
setModel(packet_list_model_);
packet_list_model_->setColorEnabled(true); // We don't yet fetch color settings.
// packet_list_model_->setColorEnabled(recent.packet_list_colorize);
g_assert(cur_packet_list == NULL);
cur_packet_list = this;
g_assert(gbl_cur_packet_list == NULL);
gbl_cur_packet_list = this;
proto_tree_ = NULL;
byte_view_tab_ = NULL;
@ -328,6 +304,15 @@ void PacketList::selectionChanged (const QItemSelection & selected, const QItemS
}
}
// Redraw the packet list and detail
void PacketList::updateAll() {
update();
if (selectedIndexes().length() > 0) {
cf_select_packet(&cfile, selectedIndexes()[0].row());
}
}
void PacketList::clear() {
// packet_history_clear();
packetListModel()->clear();
@ -338,17 +323,10 @@ void PacketList::clear() {
delete byte_view_tab_->currentWidget();
}
// /* XXX is this correct in all cases?
// * Reset the sort column, use packetlist as model in case the list is frozen.
// */
cur_packet_list->sortByColumn(0, Qt::AscendingOrder);
}
extern "C" void new_packet_list_recent_write_all(FILE *rf) {
if (!cur_packet_list)
return;
cur_packet_list->writeRecent(rf);
/* XXX is this correct in all cases?
* Reset the sort column, use packetlist as model in case the list is frozen.
*/
gbl_cur_packet_list->sortByColumn(0, Qt::AscendingOrder);
}
void PacketList::writeRecent(FILE *rf) {
@ -381,8 +359,6 @@ void PacketList::writeRecent(FILE *rf) {
}
#include <QDebug>
void PacketList::goNextPacket(void) {
setCurrentIndex(moveCursor(MoveDown, Qt::NoModifier));
}

View File

@ -40,6 +40,7 @@ public:
PacketListModel *packetListModel() const;
void setProtoTree(ProtoTree *proto_tree);
void setByteViewTab(ByteViewTab *byteViewTab);
void updateAll();
void clear();
void writeRecent(FILE *rf);

View File

@ -44,89 +44,15 @@ PacketListModel::PacketListModel(QObject *parent, capture_file *cfPtr) :
cf = cfPtr;
}
gint PacketListModel::appendPacket(frame_data *fdata)
{
PacketListRecord *record = new PacketListRecord(fdata);
gint pos = visibleRows.count() + 1;
physicalRows << record;
if (fdata->flags.passed_dfilter || fdata->flags.ref_time) {
beginInsertRows(QModelIndex(), pos, pos);
visibleRows << record;
endInsertRows();
} else {
pos = -1;
}
return pos;
}
frame_data *PacketListModel::getRowFdata(int row) {
if (row >= visibleRows.count())
return NULL;
PacketListRecord *record = visibleRows[row];
if (!record)
return NULL;
return record->getFdata();
}
QVariant PacketListModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && section < cf->cinfo.num_cols) {
switch (role) {
case Qt::DisplayRole:
return cf->cinfo.col_title[section];
default:
break;
}
}
return QVariant();
}
guint PacketListModel::recreateVisibleRows()
{
int pos = visibleRows.count() + 1;
PacketListRecord *record;
beginResetModel();
visibleRows.clear();
endResetModel();
beginInsertRows(QModelIndex(), pos, pos);
foreach (record, physicalRows) {
if (record->getFdata()->flags.passed_dfilter || record->getFdata()->flags.ref_time) {
visibleRows << record;
}
}
endInsertRows();
return visibleRows.count();
}
int PacketListModel::visibleIndexOf(frame_data *fdata) const
{
int row = 0;
foreach (PacketListRecord *record, visibleRows) {
if (record->getFdata() == fdata) {
return row;
}
row++;
}
return -1;
}
// Packet list records have no children (for now, at least).
QModelIndex PacketListModel::index(int row, int column, const QModelIndex &parent)
const
{
Q_UNUSED(parent);
if (row >= visibleRows.count() || row < 0 || column >= cf->cinfo.num_cols)
if (row >= visible_rows_.count() || row < 0 || column >= cf->cinfo.num_cols)
return QModelIndex();
PacketListRecord *record = visibleRows[row];
PacketListRecord *record = visible_rows_[row];
return createIndex(row, column, record);
}
@ -138,12 +64,41 @@ QModelIndex PacketListModel::parent(const QModelIndex &index) const
return QModelIndex();
}
guint PacketListModel::recreateVisibleRows()
{
int pos = visible_rows_.count() + 1;
PacketListRecord *record;
beginResetModel();
visible_rows_.clear();
endResetModel();
beginInsertRows(QModelIndex(), pos, pos);
foreach (record, physical_rows_) {
if (record->getFdata()->flags.passed_dfilter || record->getFdata()->flags.ref_time) {
visible_rows_ << record;
}
}
endInsertRows();
return visible_rows_.count();
}
void PacketListModel::setColorEnabled(bool enable_color) {
enable_color_ = enable_color;
}
void PacketListModel::clear() {
beginResetModel();
physical_rows_.clear();
visible_rows_.clear();
endResetModel();
}
int PacketListModel::rowCount(const QModelIndex &parent) const
{
if (parent.column() >= cf->cinfo.num_cols)
return 0;
return visibleRows.count();
return visible_rows_.count();
}
int PacketListModel::columnCount(const QModelIndex &parent) const
@ -213,7 +168,6 @@ QVariant PacketListModel::data(const QModelIndex &index, int role) const
union wtap_pseudo_header pseudo_header; /* Packet pseudo_header */
guint8 pd[WTAP_MAX_PACKET_SIZE]; /* Packet data */
gboolean dissect_columns = TRUE; // XXX - Currently only a placeholder
gboolean dissect_color = TRUE; // XXX - Currently only a placeholder
if (dissect_columns)
cinfo = &cf->cinfo;
@ -241,28 +195,28 @@ QVariant PacketListModel::data(const QModelIndex &index, int role) const
// }
// record->columnized = TRUE;
}
if (dissect_color) {
if (enable_color_) {
fdata->color_filter = NULL;
// record->colorized = TRUE;
}
return QVariant(); /* error reading the frame */
}
create_proto_tree = (color_filters_used() && dissect_color) ||
create_proto_tree = (color_filters_used() && enable_color_) ||
(have_custom_cols(cinfo) && dissect_columns);
epan_dissect_init(&edt,
create_proto_tree,
FALSE /* proto_tree_visible */);
if (dissect_color)
if (enable_color_)
color_filters_prime_edt(&edt);
if (dissect_columns)
col_custom_prime_edt(&edt, cinfo);
epan_dissect_run(&edt, &pseudo_header, pd, fdata, cinfo);
if (dissect_color)
if (enable_color_)
fdata->color_filter = color_filters_colorize_packet(&edt);
if (dissect_columns) {
@ -279,7 +233,7 @@ QVariant PacketListModel::data(const QModelIndex &index, int role) const
// if (dissect_columns)
// record->columnized = TRUE;
// if (dissect_color)
// if (enable_color_)
// record->colorized = TRUE;
epan_dissect_cleanup(&edt);
@ -287,9 +241,56 @@ QVariant PacketListModel::data(const QModelIndex &index, int role) const
return record->data(col_num, cinfo);
}
void PacketListModel::clear() {
beginResetModel();
physicalRows.clear();
visibleRows.clear();
endResetModel();
QVariant PacketListModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && section < cf->cinfo.num_cols) {
switch (role) {
case Qt::DisplayRole:
return cf->cinfo.col_title[section];
default:
break;
}
}
return QVariant();
}
gint PacketListModel::appendPacket(frame_data *fdata)
{
PacketListRecord *record = new PacketListRecord(fdata);
gint pos = visible_rows_.count() + 1;
physical_rows_ << record;
if (fdata->flags.passed_dfilter || fdata->flags.ref_time) {
beginInsertRows(QModelIndex(), pos, pos);
visible_rows_ << record;
endInsertRows();
} else {
pos = -1;
}
return pos;
}
frame_data *PacketListModel::getRowFdata(int row) {
if (row >= visible_rows_.count())
return NULL;
PacketListRecord *record = visible_rows_[row];
if (!record)
return NULL;
return record->getFdata();
}
int PacketListModel::visibleIndexOf(frame_data *fdata) const
{
int row = 0;
foreach (PacketListRecord *record, visible_rows_) {
if (record->getFdata() == fdata) {
return row;
}
row++;
}
return -1;
}

View File

@ -48,17 +48,18 @@ public:
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
guint recreateVisibleRows();
void setColorEnabled(bool enable_color);
void clear();
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
gint appendPacket(frame_data *fdata);
frame_data *getRowFdata(int row);
void clear();
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
guint recreateVisibleRows();
int visibleIndexOf(frame_data *fdata) const;
@ -68,11 +69,13 @@ public slots:
private:
capture_file *cf;
QList<QString> colNames;
QVector<PacketListRecord *> visibleRows;
QVector<PacketListRecord *> physicalRows;
QFont plFont;
int headerHeight;
QList<QString> col_names_;
QVector<PacketListRecord *> visible_rows_;
QVector<PacketListRecord *> physical_rows_;
QFont pl_font_;
int header_height_;
bool enable_color_;
};
#endif // PACKET_LIST_MODEL_H