Added code to remember the last directory for open/save streams. Also to remember the StreamConfigDialog geometry and protocol data tab

This commit is contained in:
Srivats P. 2011-03-21 22:25:34 +05:30
parent b3f2e0483f
commit 497a0be276
3 changed files with 23 additions and 10 deletions

View File

@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "streamconfigdialog.h"
#include "streamlistdelegate.h"
#include <QFileInfo>
#include <QInputDialog>
#include <QItemSelectionModel>
#include <QMessageBox>
@ -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;
}

View File

@ -30,7 +30,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#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();
}

View File

@ -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();