- Added Preferences Dialog
- Wireshark path can be configured by user in the preferences - Support for portable mode for preferences (.ini in same location as the executable)
This commit is contained in:
parent
6d4be4272b
commit
1cfc771daa
BIN
client/icons/preferences.png
Normal file
BIN
client/icons/preferences.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 584 B |
@ -20,6 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QSettings>
|
||||
|
||||
QSettings *appSettings;
|
||||
|
||||
QMainWindow *mainWindow;
|
||||
|
||||
@ -28,9 +32,21 @@ int main(int argc, char* argv[])
|
||||
QApplication app(argc, argv);
|
||||
int exitCode;
|
||||
|
||||
/* (Portable Mode) If we have a .ini file in the same directory as the
|
||||
executable, we use that instead of the platform specific location
|
||||
and format for the settings */
|
||||
QString portableIni = QCoreApplication::applicationDirPath()
|
||||
+ "/ostinato.ini";
|
||||
if (QFile::exists(portableIni))
|
||||
appSettings = new QSettings(portableIni, QSettings::IniFormat);
|
||||
else
|
||||
appSettings = new QSettings("Ostinato", "Ostinato");
|
||||
|
||||
mainWindow = new MainWindow;
|
||||
mainWindow->show();
|
||||
exitCode = app.exec();
|
||||
delete mainWindow;
|
||||
delete appSettings;
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "portgrouplist.h"
|
||||
#include "portstatswindow.h"
|
||||
#include "portswindow.h"
|
||||
#include "preferences.h"
|
||||
#include "ui_about.h"
|
||||
|
||||
#include <QDockWidget>
|
||||
@ -74,6 +75,15 @@ MainWindow::~MainWindow()
|
||||
delete localServer_;
|
||||
}
|
||||
|
||||
void MainWindow::on_actionPreferences_triggered()
|
||||
{
|
||||
Preferences *preferences = new Preferences();
|
||||
|
||||
preferences->exec();
|
||||
|
||||
delete preferences;
|
||||
}
|
||||
|
||||
void MainWindow::on_actionHelpAbout_triggered()
|
||||
{
|
||||
QDialog *aboutDialog = new QDialog;
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
void on_actionPreferences_triggered();
|
||||
void on_actionHelpAbout_triggered();
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
<property name="title" >
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionPreferences" />
|
||||
<addaction name="actionFileExit" />
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuHelp" >
|
||||
@ -48,7 +49,17 @@
|
||||
<string>&About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPreferences" >
|
||||
<property name="icon" >
|
||||
<iconset resource="ostinato.qrc" >:/icons/preferences.png</iconset>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Preferences</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="ostinato.qrc" />
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -37,6 +37,8 @@ HEADERS += \
|
||||
portstatsfilterdialog.h \
|
||||
portstatswindow.h \
|
||||
portswindow.h \
|
||||
preferences.h \
|
||||
settings.h \
|
||||
streamconfigdialog.h \
|
||||
streamlistdelegate.h \
|
||||
streammodel.h
|
||||
@ -47,6 +49,7 @@ FORMS += \
|
||||
portstatsfilter.ui \
|
||||
portstatswindow.ui \
|
||||
portswindow.ui \
|
||||
preferences.ui \
|
||||
streamconfigdialog.ui
|
||||
|
||||
SOURCES += \
|
||||
@ -64,6 +67,7 @@ SOURCES += \
|
||||
portstatsfilterdialog.cpp \
|
||||
portstatswindow.cpp \
|
||||
portswindow.cpp \
|
||||
preferences.cpp \
|
||||
streamconfigdialog.cpp \
|
||||
streamlistdelegate.cpp \
|
||||
streammodel.cpp
|
||||
|
@ -24,6 +24,7 @@
|
||||
<file>icons/portstats_clear.png</file>
|
||||
<file>icons/portstats_clear_all.png</file>
|
||||
<file>icons/portstats_filter.png</file>
|
||||
<file>icons/preferences.png</file>
|
||||
<file>icons/sound_mute.png</file>
|
||||
<file>icons/sound_none.png</file>
|
||||
<file>icons/stream_add.png</file>
|
||||
|
@ -19,9 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "portgroup.h"
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCursor>
|
||||
#include <QMainWindow>
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QTemporaryFile>
|
||||
#include <QtGlobal>
|
||||
@ -661,20 +664,26 @@ void PortGroup::processViewCaptureAck(PbRpcController *controller)
|
||||
{
|
||||
QFile *capFile = static_cast<QFile*>(controller->binaryBlob());
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
QString viewer("C:/Program Files/Wireshark/wireshark.exe");
|
||||
#else
|
||||
QString viewer("/usr/bin/wireshark");
|
||||
#endif
|
||||
QString viewer = appSettings->value(kWiresharkPathKey,
|
||||
kWiresharkPathDefaultValue).toString();
|
||||
|
||||
qDebug("In %s", __FUNCTION__);
|
||||
|
||||
capFile->flush();
|
||||
capFile->close();
|
||||
|
||||
if (!QFile::exists(viewer))
|
||||
{
|
||||
QMessageBox::warning(NULL, "Can't find Wireshark",
|
||||
viewer + QString(" does not exist!\n\nPlease correct the path"
|
||||
" to Wireshark in the Preferences."));
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (!QProcess::startDetached(viewer, QStringList() << capFile->fileName()))
|
||||
qDebug("Failed starting Wireshark");
|
||||
|
||||
_exit:
|
||||
delete controller;
|
||||
}
|
||||
|
||||
|
56
client/preferences.cpp
Normal file
56
client/preferences.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (C) 2010 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "preferences.h"
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
Preferences::Preferences()
|
||||
{
|
||||
Q_ASSERT(appSettings);
|
||||
|
||||
setupUi(this);
|
||||
|
||||
wiresharkPathEdit->setText(appSettings->value(kWiresharkPathKey,
|
||||
kWiresharkPathDefaultValue).toString());
|
||||
}
|
||||
|
||||
Preferences::~Preferences()
|
||||
{
|
||||
}
|
||||
|
||||
void Preferences::accept()
|
||||
{
|
||||
appSettings->setValue(kWiresharkPathKey, wiresharkPathEdit->text());
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void Preferences::on_wiresharkPathButton_clicked()
|
||||
{
|
||||
QString path;
|
||||
|
||||
path = QFileDialog::getOpenFileName(0, "Locate Wireshark",
|
||||
wiresharkPathEdit->text());
|
||||
|
||||
if (!path.isEmpty())
|
||||
wiresharkPathEdit->setText(path);
|
||||
}
|
41
client/preferences.h
Normal file
41
client/preferences.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright (C) 2010 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _PREFERENCES_H
|
||||
#define _PREFERENCES_H
|
||||
|
||||
#include "ui_preferences.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class Preferences : public QDialog, public Ui::Preferences
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Preferences();
|
||||
~Preferences();
|
||||
|
||||
public slots:
|
||||
void accept();
|
||||
|
||||
private slots:
|
||||
void on_wiresharkPathButton_clicked();
|
||||
};
|
||||
|
||||
#endif
|
114
client/preferences.ui
Normal file
114
client/preferences.ui
Normal file
@ -0,0 +1,114 @@
|
||||
<ui version="4.0" >
|
||||
<class>Preferences</class>
|
||||
<widget class="QDialog" name="Preferences" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>164</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>Preferences</string>
|
||||
</property>
|
||||
<property name="windowIcon" >
|
||||
<iconset resource="ostinato.qrc" >:/icons/preferences.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<item>
|
||||
<widget class="QFrame" name="frame" >
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<item>
|
||||
<widget class="QLabel" name="label" >
|
||||
<property name="text" >
|
||||
<string>Wireshark Path</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="wiresharkPathEdit" />
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="wiresharkPathButton" >
|
||||
<property name="text" >
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons" >
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="ostinato.qrc" />
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Preferences</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Preferences</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
38
client/settings.h
Normal file
38
client/settings.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright (C) 2010 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _SETTINGS_H
|
||||
#define _SETTINGS_H
|
||||
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
|
||||
extern QSettings *appSettings;
|
||||
|
||||
const QString kWiresharkPathKey("WiresharkPath");
|
||||
#ifdef Q_OS_WIN32
|
||||
const QString kWiresharkPathDefaultValue(
|
||||
"C:/Program Files/Wireshark/wireshark.exe");
|
||||
#else
|
||||
const QString kWiresharkPathDefaultValue("/usr/bin/wireshark");
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user