2013-04-14 03:44:02 +00:00
|
|
|
/*
|
|
|
|
* mainwindow.cpp
|
|
|
|
*
|
|
|
|
* classes for the main UI window in Subsurface
|
|
|
|
*/
|
2013-04-07 22:20:43 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
2013-04-13 13:17:59 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
2013-04-09 08:35:44 +00:00
|
|
|
#include <QtDebug>
|
2013-04-18 07:59:32 +00:00
|
|
|
#include <QDateTime>
|
2013-04-07 22:20:43 +00:00
|
|
|
|
2013-04-12 07:24:07 +00:00
|
|
|
#include "divelistview.h"
|
2013-04-22 23:00:27 +00:00
|
|
|
#include "starwidget.h"
|
2013-04-12 07:24:07 +00:00
|
|
|
|
2013-04-13 13:17:59 +00:00
|
|
|
#include "glib.h"
|
|
|
|
#include "../dive.h"
|
|
|
|
#include "../divelist.h"
|
|
|
|
#include "../pref.h"
|
|
|
|
|
|
|
|
|
2013-04-22 01:12:36 +00:00
|
|
|
MainWindow::MainWindow() : ui(new Ui::MainWindow()),
|
|
|
|
model(new DiveTripModel(this))
|
2013-04-07 22:20:43 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2013-04-22 01:12:36 +00:00
|
|
|
ui->ListWidget->setModel(model);
|
2013-04-24 22:57:50 +00:00
|
|
|
setWindowIcon(QIcon(":subsurface-icon"));
|
2013-04-22 23:00:27 +00:00
|
|
|
// Just to test the star widgets, can be safely removed.
|
2013-04-24 22:57:10 +00:00
|
|
|
|
2013-04-07 22:20:43 +00:00
|
|
|
}
|
|
|
|
|
2013-04-09 08:35:44 +00:00
|
|
|
void MainWindow::on_actionNew_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionNew");
|
2013-04-09 08:35:44 +00:00
|
|
|
}
|
2013-04-09 16:26:23 +00:00
|
|
|
|
|
|
|
void MainWindow::on_actionOpen_triggered()
|
|
|
|
{
|
2013-04-14 13:44:29 +00:00
|
|
|
QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter());
|
2013-04-18 07:59:32 +00:00
|
|
|
if (filename.isEmpty()) {
|
2013-04-13 13:17:59 +00:00
|
|
|
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();
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionSave_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionSave");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionSaveAs_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionSaveAs");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
void MainWindow::on_actionClose_triggered()
|
|
|
|
{
|
2013-04-13 13:17:59 +00:00
|
|
|
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);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionImport_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionImport");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionExportUDDF_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionExportUDDF");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionPrint_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionPrint");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionPreferences_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionPreferences");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionQuit_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionQuit");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionDownloadDC_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionDownloadDC");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionDownloadWeb_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionDownloadWeb");}
|
2013-04-09 16:26:23 +00:00
|
|
|
|
|
|
|
void MainWindow::on_actionEditDeviceNames_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionEditDeviceNames");}
|
2013-04-09 16:26:23 +00:00
|
|
|
|
|
|
|
void MainWindow::on_actionAddDive_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionAddDive");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionRenumber_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionRenumber");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionAutoGroup_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionAutoGroup");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionToggleZoom_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionToggleZoom");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionYearlyStatistics_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionYearlyStatistics");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionViewList_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionViewList");
|
2013-04-10 07:07:02 +00:00
|
|
|
|
|
|
|
ui->InfoWidget->setVisible(false);
|
|
|
|
ui->ListWidget->setVisible(true);
|
|
|
|
ui->ProfileWidget->setVisible(false);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionViewProfile_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionViewProfile");
|
2013-04-10 07:07:02 +00:00
|
|
|
|
|
|
|
ui->InfoWidget->setVisible(false);
|
|
|
|
ui->ListWidget->setVisible(false);
|
|
|
|
ui->ProfileWidget->setVisible(true);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionViewInfo_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionViewInfo");
|
2013-04-10 07:07:02 +00:00
|
|
|
|
|
|
|
ui->InfoWidget->setVisible(true);
|
|
|
|
ui->ListWidget->setVisible(false);
|
|
|
|
ui->ProfileWidget->setVisible(false);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionViewAll_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionViewAll");
|
2013-04-10 07:07:02 +00:00
|
|
|
|
|
|
|
ui->InfoWidget->setVisible(true);
|
|
|
|
ui->ListWidget->setVisible(true);
|
|
|
|
ui->ProfileWidget->setVisible(true);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionPreviousDC_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionPreviousDC");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionNextDC_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionNextDC");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionSelectEvents_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionSelectEvents");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionInputPlan_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionInputPlan");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionAboutSubsurface_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionAboutSubsurface");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionUserManual_triggered()
|
|
|
|
{
|
2013-04-10 06:27:38 +00:00
|
|
|
qDebug("actionUserManual");
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
2013-04-13 13:17:59 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2013-04-14 13:44:29 +00:00
|
|
|
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);
|
2013-04-13 13:17:59 +00:00
|
|
|
|
2013-04-18 07:59:32 +00:00
|
|
|
if (QMessageBox::question(this, tr("Save Changes?"), message) == QMessageBox::Ok) {
|
2013-04-13 13:17:59 +00:00
|
|
|
// WARNING: Port.
|
|
|
|
// file_save(NULL,NULL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|