traverso-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Traverso-commit] traverso/src core/Project.cpp core/Project.h co...


From: Remon Sijrier
Subject: [Traverso-commit] traverso/src core/Project.cpp core/Project.h co...
Date: Sat, 06 Oct 2007 18:20:26 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Remon Sijrier <r_sijrier>       07/10/06 18:20:26

Modified files:
        src/core       : Project.cpp Project.h ProjectManager.cpp 
                         ProjectManager.h 
        src/traverso   : Interface.cpp Interface.h 

Log message:
        * present the user first with the reason why a project load didn't work 
before showing the Restore from backup dialog

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Project.cpp?cvsroot=traverso&r1=1.56&r2=1.57
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Project.h?cvsroot=traverso&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ProjectManager.cpp?cvsroot=traverso&r1=1.43&r2=1.44
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ProjectManager.h?cvsroot=traverso&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/Interface.cpp?cvsroot=traverso&r1=1.98&r2=1.99
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/Interface.h?cvsroot=traverso&r1=1.41&r2=1.42

Patches:
Index: core/Project.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Project.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -b -r1.56 -r1.57
--- core/Project.cpp    6 Oct 2007 14:17:58 -0000       1.56
+++ core/Project.cpp    6 Oct 2007 18:20:25 -0000       1.57
@@ -44,7 +44,7 @@
 #include <AddRemove.h>
 #include "FileHelpers.h"
 
-#define PROJECT_FILE_VERSION   2
+#define PROJECT_FILE_VERSION   3
 
 // Always put me below _all_ includes, this is needed
 // in case we run with memory leak detection enabled!
@@ -60,8 +60,8 @@
        engineer = "";
 
        m_useResampling = config().get_property("Conversion", 
"DynamicResampling", false).toBool();
-       rootDir = config().get_property("Project", "directory", 
"/directory/unknown/").toString() + "/" + m_title;
-       m_sourcesDir = rootDir + "/audiosources";
+       m_rootDir = config().get_property("Project", "directory", 
"/directory/unknown/").toString() + "/" + m_title;
+       m_sourcesDir = m_rootDir + "/audiosources";
        m_rate = audiodevice().get_sample_rate();
        m_bitDepth = audiodevice().get_bit_depth();
 
@@ -92,8 +92,8 @@
        PMESG("Creating new project %s  NumSongs=%d", QS_C(m_title), songcount);
 
        QDir dir;
-       if (dir.mkdir(rootDir) < 0) {
-               info().critical(tr("Cannot create dir %1").arg(rootDir));
+       if (dir.mkdir(m_rootDir) < 0) {
+               info().critical(tr("Cannot create dir %1").arg(m_rootDir));
                return -1;
        }
        
@@ -105,7 +105,7 @@
                return -1;
        }
        
-       if (create_projectfilebackup_dir() < 0) {
+       if (pm().create_projectfilebackup_dir(m_rootDir) < 0) {
                return -1;
        }
        
@@ -140,7 +140,7 @@
 int Project::create_peakfiles_dir()
 {
        QDir dir;
-       QString peaksDir = rootDir + "/peakfiles/";
+       QString peaksDir = m_rootDir + "/peakfiles/";
 
        if (dir.mkdir(peaksDir) < 0) {
                info().critical(tr("Cannot create dir %1").arg(peaksDir));
@@ -150,19 +150,6 @@
        return 1;
 }
 
-int Project::create_projectfilebackup_dir()
-{
-       QDir dir;
-       QString path = rootDir + "/projectfilebackup/";
-
-       if (dir.mkdir(path) < 0) {
-               info().critical(tr("Cannot create dir %1").arg(path));
-               return -1;
-       }
-       
-       return 1;
-}
-
 int Project::load(QString projectfile)
 {
        PENTER;
@@ -172,7 +159,7 @@
        QString filename;
        
        if (projectfile.isEmpty()) {
-               filename = rootDir + "/project.tpf";
+               filename = m_rootDir + "/project.tpf";
                file.setFileName(filename);
        } else {
                filename = projectfile;
@@ -180,29 +167,36 @@
        }
 
        if (!file.open(QIODevice::ReadOnly)) {
-               file.close();
-               info().critical(tr("Project %1: Cannot open project.tpf file! 
(Reason: %2)")
-                               .arg(m_title).arg(file.errorString()));
-               
+               m_errorString = tr("Project %1: Cannot open project.tpf file! 
(Reason: %2)").arg(m_title).arg(file.errorString());
+               info().critical(m_errorString);
                return -1;
        }
 
+       // Check if important directories still exist!
+       QDir dir;
+       if (!dir.exists(m_rootDir + "/peakfiles")) {
+               create_peakfiles_dir();
+       }
+       if (!dir.exists(m_rootDir + "/audiosources")) {
+               create_audiosources_dir();
+       }
+
+       
+       // Start setting and parsing the content of the xml file
        QString errorMsg;
        if (!doc.setContent(&file, &errorMsg)) {
-               info().critical(tr("Project %1: Failed to parse project.tpf 
file! (Reason: %2)")
-                               .arg(m_title).arg(errorMsg));
-               
+               m_errorString = tr("Project %1: Failed to parse project.tpf 
file! (Reason: %2)").arg(m_title).arg(errorMsg);
+               info().critical(m_errorString);
                return -1;
        }
        
-       file.close();
-
        QDomElement docElem = doc.documentElement();
        QDomNode propertiesNode = docElem.firstChildElement("Properties");
        QDomElement e = propertiesNode.toElement();
        
        if (e.attribute("projectfileversion", "-1").toInt() != 
PROJECT_FILE_VERSION) {
-               info().warning(tr("Project File Version does not match, unable 
to load Project!"));
+               m_errorString = tr("Project File Version does not match, unable 
to load Project!");
+               info().warning(m_errorString);
                return -1;
        }
 
@@ -261,7 +255,7 @@
 {
        PENTER;
        QDomDocument doc("Project");
-       QString fileName = rootDir + "/project.tpf";
+       QString fileName = m_rootDir + "/project.tpf";
        
        QFile data( fileName );
 
@@ -348,11 +342,11 @@
        
        QString newrootdir = config().get_property("Project", "directory", 
"/directory/unknown/").toString() + "/" + title;
        
-       QDir dir(rootDir);
+       QDir dir(m_rootDir);
        
        if ( ! dir.exists() ) {
                info().critical(tr("Project directory %1 no longer exists, did 
you rename it? " 
-                               "Shame on you! Please undo that, and come back 
later to rename your Project...").arg(rootDir));
+                               "Shame on you! Please undo that, and come back 
later to rename your Project...").arg(m_rootDir));
                return;
        }
        
@@ -360,7 +354,7 @@
        
        save();
        
-       if (pm().rename_project_dir(rootDir, newrootdir) < 0 ) {
+       if (pm().rename_project_dir(m_rootDir, newrootdir) < 0 ) {
                return;
        }
        
@@ -812,12 +806,12 @@
 
 QString Project::get_root_dir( ) const
 {
-       return rootDir;
+       return m_rootDir;
 }
 
 QString Project::get_audiosources_dir() const
 {
-       return rootDir + "/audiosources/";
+       return m_rootDir + "/audiosources/";
 }
 
 ResourcesManager * Project::get_audiosource_manager( ) const

Index: core/Project.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/Project.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- core/Project.h      6 Oct 2007 14:17:58 -0000       1.25
+++ core/Project.h      6 Oct 2007 18:20:25 -0000       1.26
@@ -61,6 +61,7 @@
        QString get_root_dir() const;
        QString get_audiosources_dir() const;
        QString get_import_dir() const;
+       QString get_error_string() const {return m_errorString;}
        QList<Song* > get_songs() const;
        Song* get_current_song() const ;
        Song* get_song(qint64 id) const;
@@ -109,7 +110,7 @@
        ExportThread*   m_exportThread;
 
        QString         m_title;
-       QString         rootDir;
+       QString         m_rootDir;
        QString         m_sourcesDir;
        QString         engineer;
        QString         m_description;
@@ -121,6 +122,7 @@
        QString         m_arranger;
        QString         m_songwriter;
        QString         m_message;
+       QString         m_errorString;
 
        int             m_rate;
        int             m_bitDepth;
@@ -135,7 +137,6 @@
        int create(int songcount, int numtracks);
        int create_audiosources_dir();
        int create_peakfiles_dir();
-       int create_projectfilebackup_dir();
        
        friend class ProjectManager;
 

Index: core/ProjectManager.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/ProjectManager.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- core/ProjectManager.cpp     6 Oct 2007 14:17:58 -0000       1.43
+++ core/ProjectManager.cpp     6 Oct 2007 18:20:25 -0000       1.44
@@ -200,7 +200,7 @@
        set_current_project(newProject);
 
        if (currentProject->load() < 0) {
-               emit projectLoadFailed(currentProject->get_title());
+               emit projectLoadFailed(currentProject->get_title(), 
currentProject->get_error_string());
                delete currentProject;
                currentProject = 0;
                set_current_project(0);
@@ -482,16 +482,22 @@
        QString project_dir = config().get_property("Project", "directory", 
"/directory/unknown").toString();
        QString project_path = project_dir + "/" + projectname;
        QString fileName = project_path + "/project.tpf";
+       QString backupdir = project_path + "/projectfilebackup";
+       
+       // Check if the projectfilebackup directory still exist
+       QDir dir;
+       if (!dir.exists(backupdir)) {
+               create_projectfilebackup_dir(project_path);
+       }
        
        QFile reader(fileName);
        if (!reader.open(QIODevice::ReadOnly)) {
-               //
-               reader.close();
+               info().warning(tr("Projectfile backup: The project file %1 
could not be opened for reading (Reason: 
%2)").arg(fileName).arg(reader.errorString()));
                return;
        }
        
        QDateTime time = QDateTime::currentDateTime();
-       QString writelocation = project_path + "/projectfilebackup/" + 
time.toString() + "__" + QString::number(time.toTime_t());
+       QString writelocation = backupdir + "/" + time.toString() + "__" + 
QString::number(time.toTime_t());
        QFile compressedWriter(writelocation);
        
        if (!compressedWriter.open( QIODevice::WriteOnly ) ) {
@@ -590,3 +596,16 @@
        return dateList;
 }
 
+int ProjectManager::create_projectfilebackup_dir(const QString& rootDir)
+{
+       QDir dir;
+       QString path = rootDir + "/projectfilebackup/";
+
+       if (dir.mkdir(path) < 0) {
+               info().critical(tr("Cannot create dir %1").arg(path));
+               return -1;
+       }
+       
+       return 1;
+}
+

Index: core/ProjectManager.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/ProjectManager.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- core/ProjectManager.h       6 Oct 2007 14:17:59 -0000       1.19
+++ core/ProjectManager.h       6 Oct 2007 18:20:26 -0000       1.20
@@ -52,6 +52,7 @@
        bool project_exists(const QString& title);
        bool exit_in_progress() const {return m_exitInProgress;}
 
+       int create_projectfilebackup_dir(const QString& rootDir);
        int remove_project(const QString& title);
        
        void scheduled_for_deletion(Song* song);
@@ -104,7 +105,7 @@
        void currentProjectDirChanged();
        void unsupportedProjectDirChangeDetected();
        void projectDirChangeDetected();
-       void projectLoadFailed(QString project);
+       void projectLoadFailed(QString,QString);
        
 private slots:
        void project_dir_rename_detected(const QString& dirname);

Index: traverso/Interface.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/Interface.cpp,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -b -r1.98 -r1.99
--- traverso/Interface.cpp      6 Oct 2007 14:17:59 -0000       1.98
+++ traverso/Interface.cpp      6 Oct 2007 18:20:26 -0000       1.99
@@ -190,7 +190,7 @@
        connect(&pm(), SIGNAL(projectLoaded(Project*)), this, 
SLOT(set_project(Project*)));
        connect(&pm(), SIGNAL(aboutToDelete(Song*)), this, 
SLOT(delete_songwidget(Song*)));
        connect(&pm(), SIGNAL(unsupportedProjectDirChangeDetected()), this, 
SLOT(project_dir_change_detected()));       
-       connect(&pm(), SIGNAL(projectLoadFailed(QString)), this, 
SLOT(show_restore_project_backup_dialog()));
+       connect(&pm(), SIGNAL(projectLoadFailed(QString,QString)), this, 
SLOT(project_load_failed(QString,QString)));
 
        cpointer().add_contextitem(this);
 
@@ -1063,3 +1063,14 @@
        show_restore_project_backup_dialog(project->get_title());
 }
 
+void Interface::project_load_failed(QString project, QString reason)
+{
+       QMessageBox::critical(  this, tr("Traverso - Project load failed"), 
+                               tr("The requested Project could not be loaded 
for the following reason:\n\n'%1'"
+                               "\n\nYou will now be given a list of available 
backups (if any) \n"
+                               "to restore the Project from.").arg(reason),
+                               QMessageBox::Ok);
+       
+       show_restore_project_backup_dialog(project);
+}
+

Index: traverso/Interface.h
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/Interface.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- traverso/Interface.h        6 Oct 2007 14:17:59 -0000       1.41
+++ traverso/Interface.h        6 Oct 2007 18:20:26 -0000       1.42
@@ -155,6 +155,7 @@
        void update_opengl();
        void import_audio();
        void show_restore_project_backup_dialog();
+       void project_load_failed(QString project, QString reason);
 
        Command* full_screen();
        Command* about_traverso();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]