summaryrefslogtreecommitdiffstats
path: root/qt-ui/mainwindow.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-19 15:25:47 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-19 15:29:54 -0700
commit25b8092c0300a223321fc5a537d913fb14c91243 (patch)
treec24c9f6cf94447e3c8b0a5659bebb58114700daf /qt-ui/mainwindow.cpp
parentaf2354c1f310ee2982ef2541668d23b09f786874 (diff)
downloadsubsurface-25b8092c0300a223321fc5a537d913fb14c91243.tar.gz
Implenent file_save and file_save_as
This allows us to do the right thing at exit (and also connects to more of the menu actions to actually do something). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/mainwindow.cpp')
-rw-r--r--qt-ui/mainwindow.cpp49
1 files changed, 45 insertions, 4 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 3ee8dc29a..70023aeee 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -97,12 +97,12 @@ void MainWindow::on_actionOpen_triggered()
void MainWindow::on_actionSave_triggered()
{
- qDebug("actionSave");
+ file_save();
}
void MainWindow::on_actionSaveAs_triggered()
{
- qDebug("actionSaveAs");
+ file_save_as();
}
void MainWindow::on_actionClose_triggered()
{
@@ -295,8 +295,7 @@ bool MainWindow::askSaveChanges()
response = QMessageBox::question(this, tr("Save Changes?"), message,
QMessageBox::Save | QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Save);
if (response == QMessageBox::Save) {
- // WARNING: Port.
- // file_save(NULL,NULL);
+ file_save();
return true;
} else if (response == QMessageBox::Ok) {
return true;
@@ -492,3 +491,45 @@ MainTab* MainWindow::information()
{
return ui->InfoWidget;
}
+
+void MainWindow::file_save_as(void)
+{
+ QString filename;
+ const char *default_filename;
+
+ if (existing_filename)
+ default_filename = existing_filename;
+ else
+ default_filename = prefs.default_filename;
+ filename = QFileDialog::getSaveFileName(this, tr("Save File as"), default_filename,
+ tr("Subsurface XML files (*.ssrf *.xml *.XML)"));
+ if (!filename.isNull() && !filename.isEmpty()) {
+ save_dives(filename.toUtf8().data());
+ set_filename(filename.toUtf8().data(), TRUE);
+ mark_divelist_changed(FALSE);
+ }
+}
+
+void MainWindow::file_save(void)
+{
+ const char *current_default;
+
+ if (!existing_filename)
+ return file_save_as();
+
+ current_default = prefs.default_filename;
+ if (strcmp(existing_filename, current_default) == 0) {
+ /* if we are using the default filename the directory
+ * that we are creating the file in may not exist */
+ char *current_def_dir;
+ struct stat sb;
+
+ current_def_dir = g_path_get_dirname(existing_filename);
+ if (stat(current_def_dir, &sb) != 0) {
+ g_mkdir(current_def_dir, S_IRWXU);
+ }
+ free(current_def_dir);
+ }
+ save_dives(existing_filename);
+ mark_divelist_changed(FALSE);
+}