Page MenuHomePhabricator

No OneTemporary

Size
16 KB
Referenced Files
None
Subscribers
None
diff --git a/trunk/dlgpreferences.cpp b/trunk/dlgpreferences.cpp
index 05ad703..085c310 100644
--- a/trunk/dlgpreferences.cpp
+++ b/trunk/dlgpreferences.cpp
@@ -1,122 +1,200 @@
#include "dlgpreferences.h"
#include "ui_dlgpreferences.h"
#include <QString>
#include <QStringList>
#include <QListIterator>
#include <QModelIndexList>
+#include <QFileDialog>
+#include <QMessageBox>
#include <QDebug>
+/*******************************************************************************
+ * Public
+ ******************************************************************************/
+
DlgPreferences::DlgPreferences(Settings *p_sets, QWidget *p_parent) :
QDialog(p_parent), ui(new Ui::DlgPreferences)
{
ui->setupUi(this);
this->p_settings=p_sets;
// Load current values
this->LoadPreferences();
}
DlgPreferences::~DlgPreferences() {
delete ui;
}
+/*******************************************************************************
+ * Private slots
+ ******************************************************************************/
+
void DlgPreferences::on_BtnCancel_clicked() {
this->reject();
}
void DlgPreferences::on_ListReportLocations_clicked(const QModelIndex &index) {
if(!index.isValid()) {
// No valid row selected, disable some buttons
this->ui->BtnEditReportLoc->setEnabled(false);
this->ui->BtnRemoveReportLoc->setEnabled(false);
this->ui->BtnMoveReportLocUp->setEnabled(false);
this->ui->BtnMoveReportLocDown->setEnabled(false);
return;
}
if(this->ui->ListReportLocations->count()==1) {
// Only one item left, disable up/down buttons
this->ui->BtnEditReportLoc->setEnabled(true);
this->ui->BtnRemoveReportLoc->setEnabled(true);
this->ui->BtnMoveReportLocUp->setEnabled(false);
this->ui->BtnMoveReportLocDown->setEnabled(false);
return;
}
if(index.row()==0) {
// First row selected, disable up button
this->ui->BtnEditReportLoc->setEnabled(true);
this->ui->BtnRemoveReportLoc->setEnabled(true);
this->ui->BtnMoveReportLocUp->setEnabled(false);
this->ui->BtnMoveReportLocDown->setEnabled(true);
return;
}
if(index.row()==(this->ui->ListReportLocations->count()-1)) {
// Last row selected, disable down button
this->ui->BtnEditReportLoc->setEnabled(true);
this->ui->BtnRemoveReportLoc->setEnabled(true);
this->ui->BtnMoveReportLocUp->setEnabled(true);
this->ui->BtnMoveReportLocDown->setEnabled(false);
return;
}
// Any other valid row selected, enable up/down buttons
this->ui->BtnEditReportLoc->setEnabled(true);
this->ui->BtnRemoveReportLoc->setEnabled(true);
this->ui->BtnMoveReportLocUp->setEnabled(true);
this->ui->BtnMoveReportLocDown->setEnabled(true);
}
-void DlgPreferences::LoadPreferences() {
-
- // Populate report location list
- QStringList report_dirs=this->p_settings->GetReportTemplateDirs();
- QListIterator<QString> it_report_dirs(report_dirs);
- if(!report_dirs.isEmpty()) {
- while(it_report_dirs.hasNext()) {
- this->ui->ListReportLocations->addItem(it_report_dirs.next());
- }
- this->ui->ListReportLocations->setCurrentRow(0);
- this->ui->BtnEditReportLoc->setEnabled(true);
- this->ui->BtnRemoveReportLoc->setEnabled(true);
- this->ui->BtnMoveReportLocDown->setEnabled(true);
- }
-}
-
void DlgPreferences::on_BtnAddReportLoc_clicked() {
- // TODO
+ QString new_loc=QFileDialog::getExistingDirectory(this,
+ tr("Select new report "
+ "directory"));
+ if(!new_loc.isEmpty()) {
+ this->ui->ListReportLocations->addItem(new_loc);
+ }
}
void DlgPreferences::on_BtnEditReportLoc_clicked() {
- // TODO
+ QModelIndex cur_item=this->ui->ListReportLocations->currentIndex();
+ if(!cur_item.isValid()) return;
+
+ // Get selected item
+ QListWidgetItem *p_item=this->ui->ListReportLocations->item(cur_item.row());
+
+ // Let user select new directory
+ QString new_loc=QFileDialog::getExistingDirectory(this,
+ tr("Edit report directory"),
+ p_item->text());
+ if(!new_loc.isEmpty()) {
+ p_item->setText(new_loc);
+ }
}
void DlgPreferences::on_BtnRemoveReportLoc_clicked() {
QModelIndex cur_item=this->ui->ListReportLocations->currentIndex();
if(!cur_item.isValid()) return;
QListWidgetItem *p_item=
this->ui->ListReportLocations->takeItem(cur_item.row());
delete p_item;
// Update buttons
this->on_ListReportLocations_clicked(
this->ui->ListReportLocations->currentIndex());
}
void DlgPreferences::on_BtnMoveReportLocUp_clicked() {
QModelIndex cur_item=this->ui->ListReportLocations->currentIndex();
if(!cur_item.isValid() || cur_item.row()==0) return;
- // TODO: takeItem/insertItem
+
+ // Move selected item up
+ QListWidgetItem *p_item=
+ this->ui->ListReportLocations->takeItem(cur_item.row());
+ this->ui->ListReportLocations->insertItem(cur_item.row()-1,p_item);
+
+ // Reselect moved item and update buttons
+ this->ui->ListReportLocations->setCurrentItem(p_item);
+ this->on_ListReportLocations_clicked(
+ this->ui->ListReportLocations->currentIndex());
}
void DlgPreferences::on_BtnMoveReportLocDown_clicked() {
- // TODO: takeItem/insertItem
+ QModelIndex cur_item=this->ui->ListReportLocations->currentIndex();
+ if(!cur_item.isValid() ||
+ cur_item.row()==(this->ui->ListReportLocations->count()-1))
+ {
+ return;
+ }
+
+ // Move selected item up
+ QListWidgetItem *p_item=
+ this->ui->ListReportLocations->takeItem(cur_item.row());
+ this->ui->ListReportLocations->insertItem(cur_item.row()+1,p_item);
+
+ // Reselect moved item and update buttons
+ this->ui->ListReportLocations->setCurrentItem(p_item);
+ this->on_ListReportLocations_clicked(
+ this->ui->ListReportLocations->currentIndex());
}
void DlgPreferences::on_BtnReset_clicked() {
- // TODO
+ if(QMessageBox::warning(this,
+ tr("Reset default settings"),
+ tr("Are you sure to reset all settings to their defaults?"),
+ QMessageBox::No,
+ QMessageBox::Yes)==QMessageBox::Yes)
+ {
+ this->p_settings->Reset();
+ }
+}
+
+void DlgPreferences::on_BtnOk_clicked() {
+ this->SavePreferences();
+ this->accept();
+}
+
+/*******************************************************************************
+ * Private
+ ******************************************************************************/
+
+void DlgPreferences::LoadPreferences() {
+
+ // Populate report location list
+ this->ui->ListReportLocations->clear();
+ QStringList report_dirs=this->p_settings->GetReportTemplateDirs();
+ QListIterator<QString> it_report_dirs(report_dirs);
+ if(!report_dirs.isEmpty()) {
+ while(it_report_dirs.hasNext()) {
+ this->ui->ListReportLocations->addItem(it_report_dirs.next());
+ }
+ this->ui->ListReportLocations->setCurrentRow(0);
+ this->ui->BtnEditReportLoc->setEnabled(true);
+ this->ui->BtnRemoveReportLoc->setEnabled(true);
+ this->ui->BtnMoveReportLocDown->setEnabled(true);
+ }
+}
+
+void DlgPreferences::SavePreferences() {
+
+ // Save report location list
+ QStringList report_dirs;
+ for(int i=0;i<this->ui->ListReportLocations->count();i++) {
+ report_dirs.append(this->ui->ListReportLocations->item(i)->text());
+ }
+ this->p_settings->SetReportTemplateDirs(report_dirs);
}
diff --git a/trunk/dlgpreferences.h b/trunk/dlgpreferences.h
index 93c5199..60c52eb 100644
--- a/trunk/dlgpreferences.h
+++ b/trunk/dlgpreferences.h
@@ -1,37 +1,40 @@
#ifndef DLGPREFERENCES_H
#define DLGPREFERENCES_H
#include <QDialog>
#include <QModelIndex>
#include "settings.h"
namespace Ui {
class DlgPreferences;
}
class DlgPreferences : public QDialog {
Q_OBJECT
public:
explicit DlgPreferences(Settings *p_sets, QWidget *p_parent=0);
~DlgPreferences();
private slots:
void on_BtnCancel_clicked();
void on_ListReportLocations_clicked(const QModelIndex &index);
void on_BtnAddReportLoc_clicked();
void on_BtnEditReportLoc_clicked();
void on_BtnRemoveReportLoc_clicked();
void on_BtnMoveReportLocUp_clicked();
void on_BtnMoveReportLocDown_clicked();
void on_BtnReset_clicked();
+ void on_BtnOk_clicked();
+
private:
Ui::DlgPreferences *ui;
Settings *p_settings;
void LoadPreferences();
+ void SavePreferences();
};
#endif // DLGPREFERENCES_H
diff --git a/trunk/settings.cpp b/trunk/settings.cpp
index 12dee0d..47245b0 100644
--- a/trunk/settings.cpp
+++ b/trunk/settings.cpp
@@ -1,122 +1,137 @@
/*******************************************************************************
* fred Copyright (c) 2011-2013 by Gillen Daniel <gillen.dan@pinguin.lu> *
* *
* Forensic Registry EDitor (fred) is a cross-platform M$ registry hive editor *
* with special feautures useful during forensic analysis. *
* *
* This program 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 "settings.h"
#include <QDir>
#ifndef FRED_REPORT_TEMPLATE_DIR
#ifndef __MINGW32__
#define SYSTEM_REPORT_TEMPLATE_DIR "/usr/share/fred/report_templates"
#else
#define SYSTEM_REPORT_TEMPLATE_DIR ".\\report_templates\\"
#endif
#endif
#define APP_ORGANIZATION "pinguin.lu"
#define APP_NAME "fred"
+/*******************************************************************************
+ * Public
+ ******************************************************************************/
+
Settings::Settings(QObject *p_parent) : QObject(p_parent) {
// Init vars
this->p_settings=NULL;
this->initialized=false;
this->user_settings_dir=QDir::homePath()
.append(QDir::separator()).append(".fred");
this->user_report_template_dir=QString(this->user_settings_dir)
.append(QDir::separator())
.append("report_templates");
// Make sure config dirs exist
if(!QDir(this->user_settings_dir).exists()) {
// User config dir does not exists, try to create it
if(!QDir().mkpath(this->user_settings_dir)) {
// TODO: Maybe warn user
return;
}
}
if(!QDir(this->user_report_template_dir).exists()) {
// Create config dir sub folder for report templates
if(!QDir().mkpath(this->user_report_template_dir)) {
// TODO: Maybe warn user
return;
}
}
// Create / open settings
#ifndef __MINGW32__
// On any Unix-like OS, settings should be saved in the .fred folder
this->p_settings=new QSettings(QString(this->user_settings_dir)
.append(QDir::separator())
.append("fred.conf"),
QSettings::NativeFormat,
this);
#else
// On Windows, it can be stored inside registry
this->p_settings=new QSettings(QSettings::NativeFormat,
QSettings::UserScope,
APP_ORGANIZATION,
APP_NAME,
this);
#endif
if(this->p_settings->status()!=QSettings::NoError ||
!this->p_settings->isWritable())
{
return;
}
this->initialized=true;
}
+void Settings::Reset() {
+
+}
+
+void Settings::SetReportTemplateDirs(QStringList &dirs) {
+ this->p_settings->setValue("ReportTemplateDirs",dirs);
+}
+
QStringList Settings::GetReportTemplateDirs() {
- return QStringList()<<SYSTEM_REPORT_TEMPLATE_DIR
- <<this->user_report_template_dir;
+ if(!this->initialized) return QStringList();
+ return this->p_settings->value("ReportTemplateDirs",
+ QStringList()<<SYSTEM_REPORT_TEMPLATE_DIR
+ <<this->user_report_template_dir
+ ).toStringList();
}
void Settings::SaveWindowGeometry(QString window_name, QByteArray geometry) {
if(!this->initialized) return;
this->p_settings->setValue(QString("WindowGeometry_%1").arg(window_name),
geometry);
}
QByteArray Settings::GetWindowGeometry(QString window_name) {
if(!this->initialized) return QByteArray();
return this->p_settings->value(QString("WindowGeometry_%1")
.arg(window_name)).toByteArray();
}
void Settings::AddRecentFile(QString file) {
// Get recent files
QStringList recent_files=this->GetRecentFiles();
if(recent_files.contains(file)) {
// File already exists in recent list. Simply move it to top
recent_files.move(recent_files.indexOf(file),0);
} else {
// We only save 5 files at max
if(recent_files.count()==5) recent_files.removeLast();
recent_files.prepend(file);
}
this->p_settings->setValue("RecentFiles",recent_files);
}
QStringList Settings::GetRecentFiles() {
return this->p_settings->value("RecentFiles").toStringList();
}
diff --git a/trunk/settings.h b/trunk/settings.h
index 732e88c..4d65a7a 100644
--- a/trunk/settings.h
+++ b/trunk/settings.h
@@ -1,54 +1,57 @@
/*******************************************************************************
* fred Copyright (c) 2011-2013 by Gillen Daniel <gillen.dan@pinguin.lu> *
* *
* Forensic Registry EDitor (fred) is a cross-platform M$ registry hive editor *
* with special feautures useful during forensic analysis. *
* *
* This program 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 <QObject>
#include <QSettings>
#include <QString>
#include <QStringList>
#include <QByteArray>
class Settings : public QObject {
Q_OBJECT
public:
explicit Settings(QObject *p_parent=0);
+ void Reset();
+
+ void SetReportTemplateDirs(QStringList &dirs);
QStringList GetReportTemplateDirs();
void SetSaveWindowGeometryStatus(bool save);
bool GetSaveWindowGeometryStatus();
void SaveWindowGeometry(QString window_name, QByteArray geometry);
QByteArray GetWindowGeometry(QString window_name);
void SetRecentFileDepth(int depth);
int GetRecentFileDepth();
void AddRecentFile(QString file);
QStringList GetRecentFiles();
private:
QSettings *p_settings;
bool initialized;
QString user_settings_dir;
QString user_report_template_dir;
};
#endif // SETTINGS_H

File Metadata

Mime Type
text/x-diff
Expires
Tue, Dec 24, 3:06 AM (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1176970
Default Alt Text
(16 KB)

Event Timeline