From c3735720ddfe785c1a906386cb5e43a8feb45376 Mon Sep 17 00:00:00 2001
From: Paolo Capriotti
Date: Sun, 4 Nov 2007 01:09:58 +0100
Subject: [PATCH] Added "Save as..." action.
---
src/mainwindow.cpp | 28 ++++++++++++++++++++--------
src/mainwindow.h | 2 ++
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 627e0a1..c65c0da 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -167,6 +167,7 @@ void MainWindow::setupActions() {
KStandardAction::openNew(this, SLOT(newGame()), actionCollection());
KStandardAction::open(this, SLOT(loadGame()), actionCollection());
KStandardAction::save(this, SLOT(saveGame()), actionCollection());
+ KStandardAction::saveAs(this, SLOT(saveGameAs()), actionCollection());
KStandardAction::quit(this, SLOT(quit()), actionCollection());
KStandardAction::preferences(this, SLOT(preferences()), actionCollection());
@@ -465,24 +466,35 @@ void MainWindow::loadGame() {
void MainWindow::saveGame() {
if (m_url.isEmpty())
- m_url = KFileDialog::getOpenUrl(KUrl(), "*.pgn", this, i18n("Save PGN file"));
+ saveGameAs();
+ else
+ m_url = saveGame(m_url);
+}
- if (m_url.isEmpty())
- return;
+void MainWindow::saveGameAs() {
+ m_url = saveGame(KFileDialog::getOpenUrl(KUrl(), "*.pgn", this, i18n("Save PGN file")));
+}
+
+KUrl MainWindow::saveGame(const KUrl& url) {
+ if (url.isEmpty())
+ return KUrl();
- if (!m_url.isLocalFile()) {
+ if (!url.isLocalFile()) {
// save in a temporary file
KTemporaryFile tmp_file;
tmp_file.open();
saveFile(tmp_file);
- if (!KIO::NetAccess::upload(tmp_file.fileName(), m_url, this))
- m_url = KUrl();
+ if (!KIO::NetAccess::upload(tmp_file.fileName(), url, this))
+ return KUrl();
}
else {
- QFile file(m_url.path());
- file.open(QIODevice::WriteOnly);
+ QFile file(url.path());
+ if (!file.open(QIODevice::WriteOnly))
+ return KUrl();
saveFile(file);
}
+
+ return url;
}
void MainWindow::saveFile(QFile& file) {
diff --git a/src/mainwindow.h b/src/mainwindow.h
index ff160fb..227d62a 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -77,6 +77,7 @@ Q_OBJECT
bool openFile(const QString&);
void saveFile(QFile&);
+ KUrl saveGame(const KUrl& url);
void readSettings();
void writeSettings();
@@ -120,6 +121,7 @@ public Q_SLOTS:
bool newGame(const QString& var, AbstractPosition::Ptr, bool);
void loadGame();
void saveGame();
+ void saveGameAs();
void quit();
void flipView();
void toggleConsole();
--
2.11.4.GIT