To unittest the lilypond export I need to be able to create a RosegardenDocument without creating a RosegardenMainWindow.
There are a few uses of the MainWindow in Document, this patch removes the first one of them, by moving saveIfModified() to MainWindow. Does someone want to review it before I commit it? Do you prefer patches for review here or in https://sourceforge.net/p/rosegarden/patches/ ? (or should I just commit such things?) Let me know how you prefer me to work, I don't mind either way. -- David Faure, fa...@kde.org, http://www.davidfaure.fr Working on KDE Frameworks 5
commit 33b32d67fce7465c71da0eafecb883b2fa79ad40 Author: David Faure <fa...@kde.org> Date: Sat Nov 14 12:20:42 2015 +0100 Move saveIfModified from Document to MainWindow. It needs slotFileSaveAs from the MainWindow anyway, so it belongs there. This is a first step towards making it possible to create a Document without a MainWindow. diff --git a/src/document/RosegardenDocument.cpp b/src/document/RosegardenDocument.cpp index 0e65960..733125c 100644 --- a/src/document/RosegardenDocument.cpp +++ b/src/document/RosegardenDocument.cpp @@ -128,11 +128,7 @@ RosegardenDocument::RosegardenDocument(QWidget *parent, { checkSequencerTimer(); -//### FIX-qt4-removed: -// m_viewList.setAutoDelete(false); -// m_editViewList.setAutoDelete(false); - - connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()), + connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()), this, SLOT(slotDocumentModified())); connect(CommandHistory::getInstance(), SIGNAL(documentRestored()), @@ -219,6 +215,11 @@ const QString &RosegardenDocument::getAbsFilePath() const return m_absFilePath; } +void RosegardenDocument::deleteAutoSaveFile() +{ + QFile::remove(getAutoSaveFileName()); +} + const QString& RosegardenDocument::getTitle() const { return m_title; @@ -331,76 +332,6 @@ bool RosegardenDocument::isRegularDotRGFile() return getAbsFilePath().right(3).toLower() == ".rg"; } -bool RosegardenDocument::saveIfModified() -{ - RG_DEBUG << "RosegardenDocument::saveIfModified()" << endl; - bool completed = true; - - if (!isModified()) - return completed; - - - RosegardenMainWindow *win = (RosegardenMainWindow *)parent(); - - int wantSave = QMessageBox::warning( dynamic_cast<QWidget*>(win), tr("Rosegarden - Warning"), tr("<qt><p>The current file has been modified.</p><p>Do you want to save it?</p></qt>"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Cancel ); - - RG_DEBUG << "wantSave = " << wantSave << endl; - - switch (wantSave) { - - case QMessageBox::Yes: - - if (!isRegularDotRGFile()) { - - RG_DEBUG << "RosegardenDocument::saveIfModified() : new or imported file\n"; - completed = win->slotFileSaveAs(); - - } else { - - RG_DEBUG << "RosegardenDocument::saveIfModified() : regular file\n"; - QString errMsg; - completed = saveDocument(getAbsFilePath(), errMsg); - - if (!completed) { - if (!errMsg.isEmpty()) { - QMessageBox::critical( dynamic_cast<QWidget *>(parent()), tr("Rosegarden"), tr("Could not save document at %1\n(%2)").arg(getAbsFilePath()).arg(errMsg)); - } else { - QMessageBox::critical( dynamic_cast<QWidget *>(parent()), tr("Rosegarden"), tr("Could not save document at %1").arg( getAbsFilePath() )); - } - } - } - - break; - - case QMessageBox::No: - // delete the autosave file so it won't annoy - // the user when reloading the file. - QFile::remove - (getAutoSaveFileName()); - completed = true; - break; - - case QMessageBox::Cancel: - completed = false; - break; - - default: - completed = false; - break; - } - - if (completed) { - completed = deleteOrphanedAudioFiles(wantSave == QMessageBox::No); - if (completed) { - m_audioFileManager.resetRecentlyCreatedFiles(); - } - } - - if (completed) - setModified(false); - return completed; -} - bool RosegardenDocument::deleteOrphanedAudioFiles(bool documentWillNotBeSaved) { @@ -1455,7 +1386,7 @@ bool RosegardenDocument::saveDocumentActual(const QString& filename, emit documentModified(false); setModified(false); CommandHistory::getInstance()->documentSaved(); - } + } if (progress) { progress->close(); // is deleteOnClose progress = 0; diff --git a/src/document/RosegardenDocument.h b/src/document/RosegardenDocument.h index e03c2b6..bea001c 100644 --- a/src/document/RosegardenDocument.h +++ b/src/document/RosegardenDocument.h @@ -153,7 +153,7 @@ public: * returns if the document is modified or not. Use this to * determine if your document needs saving by the user on closing. */ - bool isModified() const { return m_modified; }; + bool isModified() const { return m_modified; } /** * clears the 'modified' status of the document (sets it back to false). @@ -162,12 +162,6 @@ public: void clearModifiedStatus(); /** - * "save modified" - asks the user for saving if the document is - * modified - */ - bool saveIfModified(); - - /** * get the autosave interval in seconds */ unsigned int getAutoSavePeriod() const; @@ -219,6 +213,11 @@ public: const QString &getAbsFilePath() const; /** + * removes the autosave file (e.g. after saving) + */ + void deleteAutoSaveFile(); + + /** * sets the filename of the document */ void setTitle(const QString &title); @@ -449,6 +448,8 @@ public: /// Verify that the audio path exists and can be written to. void checkAudioPath(Track *track); + bool deleteOrphanedAudioFiles(bool documentWillNotBeSaved); + public slots: /** * calls repaint() on all views connected to the document object @@ -521,7 +522,7 @@ signals: void docColoursChanged(); void devicesResyncd(); -protected: +private: /** * initializes the document generally */ @@ -580,9 +581,6 @@ protected: long totalNbOfEvents, long &count, QString extraAttributes = QString::null); - bool deleteOrphanedAudioFiles(bool documentWillNotBeSaved); - - /// Identifies a specific event within a specific segment. /** * A struct formed by a Segment pointer and an iterator into the same diff --git a/src/gui/application/RosegardenMainWindow.cpp b/src/gui/application/RosegardenMainWindow.cpp index fea3c8d..0bdbace 100644 --- a/src/gui/application/RosegardenMainWindow.cpp +++ b/src/gui/application/RosegardenMainWindow.cpp @@ -1851,7 +1851,7 @@ RosegardenMainWindow::queryClose() return false; // Let the user save any unsaved changes. - return m_doc->saveIfModified(); + return saveIfModified(); } void @@ -1875,7 +1875,7 @@ RosegardenMainWindow::slotFileNew() if (!m_doc->isModified()) { makeNew = true; // m_doc->closeDocument(); - } else if (m_doc->saveIfModified()) { + } else if (saveIfModified()) { makeNew = true; } @@ -1909,7 +1909,7 @@ RosegardenMainWindow::slotOpenDroppedURL(QString url) // track editor is erased too soon - it is the originator of the signal // this slot is connected to. - if (!m_doc->saveIfModified()) + if (!saveIfModified()) return ; openURL(QUrl(url)); @@ -1962,7 +1962,7 @@ RosegardenMainWindow::openURL(const QUrl& url) RG_DEBUG << "RosegardenMainWindow::openURL: target : " << target << endl; - if (!m_doc->saveIfModified()) + if (!saveIfModified()) return ; source.waitForData(); @@ -2026,7 +2026,7 @@ RosegardenMainWindow::slotFileOpen() settings.setValue("open_file", directory); settings.endGroup(); - if (m_doc && !m_doc->saveIfModified()) + if (m_doc && !saveIfModified()) return ; settings.beginGroup(GeneralOptionsConfigGroup); @@ -2092,7 +2092,7 @@ RosegardenMainWindow::slotFileOpenRecent() TmpStatusMsg msg(tr("Opening file..."), this); if (m_doc) { - if (!m_doc->saveIfModified()) { + if (!saveIfModified()) { return ; } } @@ -2318,7 +2318,7 @@ RosegardenMainWindow::slotFileClose() TmpStatusMsg msg(tr("Closing file..."), this); - if (m_doc->saveIfModified()) { + if (saveIfModified()) { setDocument(new RosegardenDocument(this, m_pluginManager)); } @@ -3901,7 +3901,7 @@ RosegardenMainWindow::slotRevertToSaved() void RosegardenMainWindow::slotImportProject() { - if (m_doc && !m_doc->saveIfModified()) + if (m_doc && !saveIfModified()) return ; QSettings settings; @@ -3953,7 +3953,7 @@ RosegardenMainWindow::importProject(QString filePath) void RosegardenMainWindow::slotImportMIDI() { - if (m_doc && !m_doc->saveIfModified()) + if (m_doc && !saveIfModified()) return ; QSettings settings; @@ -4111,7 +4111,7 @@ RosegardenMainWindow::fixTextEncodings(Composition *c) RosegardenDocument* RosegardenMainWindow::createDocumentFromMIDIFile(QString file) { - //if (!merge && !m_doc->saveIfModified()) return; + //if (!merge && !saveIfModified()) return; // Create new document (autoload is inherent) // @@ -4251,7 +4251,7 @@ RosegardenMainWindow::createDocumentFromMIDIFile(QString file) void RosegardenMainWindow::slotImportRG21() { - if (m_doc && !m_doc->saveIfModified()) + if (m_doc && !saveIfModified()) return ; QSettings settings; @@ -4373,7 +4373,7 @@ RosegardenMainWindow::createDocumentFromRG21File(QString file) void RosegardenMainWindow::slotImportHydrogen() { - if (m_doc && !m_doc->saveIfModified()) + if (m_doc && !saveIfModified()) return ; QSettings settings; @@ -4494,7 +4494,7 @@ RosegardenMainWindow::createDocumentFromHydrogenFile(QString file) void RosegardenMainWindow::slotImportMusicXML() { - if (m_doc && !m_doc->saveIfModified()) + if (m_doc && !saveIfModified()) return ; QSettings settings; @@ -8696,6 +8696,73 @@ RosegardenMainWindow::checkAudioPath() #endif } +bool RosegardenMainWindow::saveIfModified() +{ + RG_DEBUG << "saveIfModified()" << endl; + bool completed = true; + + if (!m_doc->isModified()) + return completed; + + int wantSave = QMessageBox::warning( this, tr("Rosegarden - Warning"), tr("<qt><p>The current file has been modified.</p><p>Do you want to save it?</p></qt>"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Cancel ); + + RG_DEBUG << "wantSave = " << wantSave << endl; + + switch (wantSave) { + + case QMessageBox::Yes: + + if (!m_doc->isRegularDotRGFile()) { + + RG_DEBUG << "saveIfModified() : new or imported file\n"; + completed = slotFileSaveAs(); + + } else { + + RG_DEBUG << "saveIfModified() : regular file\n"; + QString errMsg; + completed = m_doc->saveDocument(m_doc->getAbsFilePath(), errMsg); + + if (!completed) { + if (!errMsg.isEmpty()) { + QMessageBox::critical(this, tr("Rosegarden"), tr("Could not save document at %1\n(%2)").arg(m_doc->getAbsFilePath()).arg(errMsg)); + } else { + QMessageBox::critical(this, tr("Rosegarden"), tr("Could not save document at %1").arg(m_doc->getAbsFilePath())); + } + } + } + + break; + + case QMessageBox::No: + // delete the autosave file so it won't annoy + // the user when reloading the file. + m_doc->deleteAutoSaveFile(); + completed = true; + break; + + case QMessageBox::Cancel: + completed = false; + break; + + default: + completed = false; + break; + } + + if (completed) { + completed = m_doc->deleteOrphanedAudioFiles(wantSave == QMessageBox::No); + if (completed) { + m_doc->getAudioFileManager().resetRecentlyCreatedFiles(); + } + } + + if (completed) + m_doc->clearModifiedStatus(); + + return completed; +} + void RosegardenMainWindow::uiUpdateKludge() diff --git a/src/gui/application/RosegardenMainWindow.h b/src/gui/application/RosegardenMainWindow.h index 292d0e1..ce528ba 100644 --- a/src/gui/application/RosegardenMainWindow.h +++ b/src/gui/application/RosegardenMainWindow.h @@ -1637,6 +1637,12 @@ private: */ void checkAudioPath(); + /** + * "save modified" - asks the user for saving if the document is + * modified + */ + bool saveIfModified(); + //--------------- Data members --------------------------------- bool m_alwaysUseDefaultStudio;
------------------------------------------------------------------------------
_______________________________________________ Rosegarden-devel mailing list Rosegarden-devel@lists.sourceforge.net - use the link below to unsubscribe https://lists.sourceforge.net/lists/listinfo/rosegarden-devel