summaryrefslogtreecommitdiffstats
path: root/qt-ui/mainwindow.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-04-13 10:17:59 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-04-13 14:08:16 -0700
commit92397a2bad3d1a2bc261dee67d230e3caa13b8d8 (patch)
tree32d54729f32bd6b2f1be2eacf27717dd3bede5a0 /qt-ui/mainwindow.cpp
parent76f71b4ca07dbef1069aec3db1138c199927b1bb (diff)
downloadsubsurface-92397a2bad3d1a2bc261dee67d230e3caa13b8d8.tar.gz
Started the real code on the Qt Interface.
1 - Open File already open files, it tries to not break the Gtk version, but some methods on the GTK version still need to be called inside Qt because the code is too tight-coupled. 2 - Close file already close files, same comments for the open file dialog applies here. 3 - The code for adding new cylinders in the cylinder dialog is done, already works and it's integrated with the system. There's a need to implement the edit and delete now, but it will be easyer since I'm starting to not get lost on the code. 4 - Some functions that were used to convert unities have been moved to convert.h ( can be changed later, put there because it's easyer to find something that converts in a convert.h =p ) because they were static functions that operated in the GTK version but I need those functions in the Qt version too. [Dirk Hohndel: lots and lots of whitespace and coding style changes] Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/mainwindow.cpp')
-rw-r--r--qt-ui/mainwindow.cpp107
1 files changed, 105 insertions, 2 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 03f6b6ca6..fdc823d9c 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -2,11 +2,19 @@
#include "ui_mainwindow.h"
#include <QVBoxLayout>
+#include <QFileDialog>
+#include <QMessageBox>
#include <QtDebug>
#include "divelistview.h"
#include "divetripmodel.h"
+#include "glib.h"
+#include "../dive.h"
+#include "../divelist.h"
+#include "../pref.h"
+
+
MainWindow::MainWindow() : ui(new Ui::MainWindow())
{
ui->setupUi(this);
@@ -45,7 +53,31 @@ void MainWindow::on_actionNew_triggered()
void MainWindow::on_actionOpen_triggered()
{
- qDebug("actionOpen");
+ QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter());
+ if (filename.isEmpty()){
+ return;
+ }
+
+ // Needed to convert to char*
+ QByteArray fileNamePtr = filename.toLocal8Bit();
+
+ on_actionClose_triggered();
+
+ GError *error = NULL;
+ parse_file(fileNamePtr.data(), &error);
+ set_filename(fileNamePtr.data(), TRUE);
+
+ if (error != NULL)
+ {
+ QMessageBox::warning(this, "Error", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+
+ //WARNING: Port This method to Qt
+ report_dives(FALSE, FALSE);
+
+ ui->InfoWidget->reload();
}
void MainWindow::on_actionSave_triggered()
@@ -59,7 +91,37 @@ void MainWindow::on_actionSaveAs_triggered()
}
void MainWindow::on_actionClose_triggered()
{
- qDebug("actionClose");
+ if (unsaved_changes() && (askSaveChanges() == FALSE))
+ {
+ return;
+ }
+
+ /* free the dives and trips */
+ while (dive_table.nr)
+ {
+ delete_single_dive(0);
+ }
+ mark_divelist_changed(FALSE);
+
+ /* clear the selection and the statistics */
+ selected_dive = 0;
+
+ //WARNING: Port this to Qt.
+ //process_selected_dives();
+
+ ui->InfoWidget->clearStats();
+ ui->InfoWidget->clearInfo();
+ ui->InfoWidget->clearEquipment();
+
+ clear_events();
+ show_dive_stats(NULL);
+
+ /* redraw the screen */
+ //WARNING: Port this to Qt.
+ dive_list_update_dives();
+
+ // WARNING? Port this to Qt.
+ show_dive_info(NULL);
}
void MainWindow::on_actionImport_triggered()
@@ -190,3 +252,44 @@ void MainWindow::on_actionUserManual_triggered()
{
qDebug("actionUserManual");
}
+
+QString MainWindow::filter()
+{
+ QString f;
+ f += "ALL ( *.xml *.XML *.uddf *.udcf *.UDFC *.jlb *.JLB ";
+#ifdef LIBZIP
+ f += "*.sde *.SDE *.dld *.DLD ";
+#endif
+#ifdef SQLITE3
+ f += "*.db";
+#endif
+ f += ");;";
+
+ f += "XML (*.xml *.XML);;";
+ f += "UDDF (*.uddf);;";
+ f += "UDCF (*.udcf *.UDCF);;";
+ f += "JLB (*.jlb *.JLB);;";
+
+#ifdef LIBZIP
+ f += "SDE (*.sde *.SDE);;";
+ f += "DLD (*.dld *.DLD);;";
+#endif
+#ifdef SQLITE3
+ f += "DB (*.db)";
+#endif
+
+ return f;
+}
+
+bool MainWindow::askSaveChanges()
+{
+ QString message = ! existing_filename ? tr("You have unsaved changes\nWould you like to save those before closing the datafile?")
+ : tr("You have unsaved changes to file: %1 \nWould you like to save those before closing the datafile?").arg(existing_filename);
+
+ if (QMessageBox::question(this, tr("Save Changes?"), message) == QMessageBox::Ok){
+ // WARNING: Port.
+ // file_save(NULL,NULL);
+ return true;
+ }
+ return false;
+}