From 497a0be27645ecae80f1afea19e60471cad2ee7a Mon Sep 17 00:00:00 2001 From: "Srivats P." Date: Mon, 21 Mar 2011 22:25:34 +0530 Subject: [PATCH] Added code to remember the last directory for open/save streams. Also to remember the StreamConfigDialog geometry and protocol data tab --- client/portswindow.cpp | 9 +++++++-- client/streamconfigdialog.cpp | 18 ++++++++++++------ client/streamconfigdialog.h | 6 ++++-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/client/portswindow.cpp b/client/portswindow.cpp index 1a7fdb5..837fb89 100644 --- a/client/portswindow.cpp +++ b/client/portswindow.cpp @@ -23,6 +23,7 @@ along with this program. If not, see #include "streamconfigdialog.h" #include "streamlistdelegate.h" +#include #include #include #include @@ -452,6 +453,7 @@ void PortsWindow::on_actionOpen_Streams_triggered() qDebug("Open Streams Action"); QModelIndex current = tvPortList->selectionModel()->currentIndex(); + static QString dirName; QString fileName; QString errorStr; bool append = true; @@ -459,7 +461,7 @@ void PortsWindow::on_actionOpen_Streams_triggered() Q_ASSERT(plm->isPort(current)); - fileName = QFileDialog::getOpenFileName(this, tr("Open Streams"), "D:/srivatsp/projects/ostinato/testfiles/pcaps"); + fileName = QFileDialog::getOpenFileName(this, tr("Open Streams"), dirName); if (fileName.isEmpty()) goto _exit; @@ -501,6 +503,7 @@ void PortsWindow::on_actionOpen_Streams_triggered() msgBox.exec(); } + dirName = QFileInfo(fileName).absolutePath(); _exit: return; @@ -511,7 +514,7 @@ void PortsWindow::on_actionSave_Streams_triggered() qDebug("Save Streams Action"); QModelIndex current = tvPortList->selectionModel()->currentIndex(); - QString fileName; + static QString fileName; QStringList fileTypes = AbstractFileFormat::supportedFileTypes(); QString fileType; QString errorStr; @@ -553,6 +556,8 @@ _retry: QMessageBox::critical(this, qApp->applicationName(), errorStr); else if (!errorStr.isEmpty()) QMessageBox::warning(this, qApp->applicationName(), errorStr); + + fileName = QFileInfo(fileName).absolutePath(); _exit: return; } diff --git a/client/streamconfigdialog.cpp b/client/streamconfigdialog.cpp index 981fabc..ad81cbf 100644 --- a/client/streamconfigdialog.cpp +++ b/client/streamconfigdialog.cpp @@ -30,7 +30,9 @@ along with this program. If not, see #include "../common/protocolmanager.h" extern ProtocolManager *OstProtocolManager; +QRect StreamConfigDialog::lastGeometry; int StreamConfigDialog::lastTopLevelTabIndex = 0; +int StreamConfigDialog::lastProtocolDataIndex = 0; StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex, QWidget *parent) : QDialog (parent), mPort(port) @@ -164,7 +166,10 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex, //! \todo Support Continuous Mode rbModeContinuous->setDisabled(true); - // Finally, restore the saved last selected tab for the various tab widgets + // Finally, restore the saved last geometry and selected tab for the + // various tab widgets + if (!lastGeometry.isNull()) + setGeometry(lastGeometry); twTopLevel->setCurrentIndex(lastTopLevelTabIndex); } @@ -532,13 +537,9 @@ void StreamConfigDialog::on_twTopLevel_currentChanged(int index) // Protocol Data case 1: { - QWidget *selWidget; - // Hide the ToolBox before modifying it - else we have a crash !!! tbProtocolData->hide(); - selWidget = tbProtocolData->currentWidget(); - // Remove all existing protocol widgets while (tbProtocolData->count() > 0) { @@ -555,7 +556,8 @@ void StreamConfigDialog::on_twTopLevel_currentChanged(int index) tbProtocolData->addItem(p->configWidget(), p->name()); } - tbProtocolData->setCurrentWidget(selWidget); + if (lastProtocolDataIndex < tbProtocolData->count()) + tbProtocolData->setCurrentIndex(lastProtocolDataIndex); tbProtocolData->show(); break; @@ -572,6 +574,8 @@ void StreamConfigDialog::on_twTopLevel_currentChanged(int index) default: break; } + + lastProtocolDataIndex = tbProtocolData->currentIndex(); } void StreamConfigDialog::update_NumPacketsAndNumBursts() @@ -998,7 +1002,9 @@ void StreamConfigDialog::on_pbOk_clicked() qDebug("stream stored"); + lastGeometry = geometry(); lastTopLevelTabIndex = twTopLevel->currentIndex(); + lastProtocolDataIndex = tbProtocolData->currentIndex(); accept(); } diff --git a/client/streamconfigdialog.h b/client/streamconfigdialog.h index bb91ce7..8321eba 100644 --- a/client/streamconfigdialog.h +++ b/client/streamconfigdialog.h @@ -84,8 +84,10 @@ private: // The following static variables are used to track the "selected" tab // for the various tab widgets so that it can be restored when the dialog - // is opened the next time - static int lastTopLevelTabIndex; + // is opened the next time. We also track the last Dialog geometry. + static QRect lastGeometry; + static int lastTopLevelTabIndex; + static int lastProtocolDataIndex; void setupUiExtra(); void LoadCurrentStream();