blob: e57bb0d0886d2b200b4aa5f0ab01b7b225f25704 [file] [log] [blame] [raw]
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
is_modified = false;
set_current_file(0);
}
MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::load(const QString &filename) {
}
bool MainWindow::save_file(const QString &filename) {
// TODO: copy current file to new file, and make changes to this new file by calling save_file
}
void MainWindow::open_file() {
if(!maybe_save()) return;
QString filename = QFileDialog::getOpenFileName(this, NULL, NULL, NULL, NULL, QFileDialog::DontUseNativeDialog);
if(!filename.isEmpty()) load(filename);
}
bool MainWindow::save_file() {
//if(is_untitled) return save_file_as(); // We don't want create a new file this time...
// TODO: reading the config, may pop a message box
//return save_file(current_file); // Don't use this function, because that is too large when we saving changes to current pe file
// TODO: saving changes to current file
}
bool MainWindow::save_file_as() {
QString filename = QFileDialog::getSaveFileName(this, tr("Save As"), current_file, NULL, NULL, QFileDialog::DontUseNativeDialog);
if(filename.isEmpty()) return false;
return save_file(filename);
}
void MainWindow::modified() {
setWindowModified(true);
is_modified = true;
}
bool MainWindow::maybe_save() {
if(is_modified) {
QMessageBox::StandardButton r = QMessageBox::warning(this, 0,
tr("The table has been modified.\nDo you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
if(r == QMessageBox::Save) return save_file();
if(r == QMessageBox::Cancel) return false;
}
return true;
}
QString MainWindow::stripped_name(const QString &filename) {
return QFileInfo(filename).fileName();
}
void MainWindow::set_current_file(const QString &filename) {
static int seq_number = 1;
is_untitled = filename.isEmpty();
if(is_untitled) {
current_file = tr("untitled-%1").arg(seq_number++);
} else {
current_file = QFileInfo(filename).canonicalFilePath();
}
is_modified = false;
setWindowModified(false);
setWindowTitle(tr("%1[*] - %2").arg(stripped_name(current_file)).arg(tr("PE Header Editor")));
setWindowModified(false);
}