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 tr...


From: Remon Sijrier
Subject: [Traverso-commit] traverso/src core/Project.cpp core/Project.h tr...
Date: Tue, 03 Apr 2007 19:56:30 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Remon Sijrier <r_sijrier>       07/04/03 19:56:30

Modified files:
        src/core       : Project.cpp Project.h 
        src/traverso/dialogs/project: ProjectManagerDialog.cpp 

Log message:
        added logic to extract and save template to harddisk

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Project.cpp?cvsroot=traverso&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Project.h?cvsroot=traverso&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/dialogs/project/ProjectManagerDialog.cpp?cvsroot=traverso&r1=1.7&r2=1.8

Patches:
Index: core/Project.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Project.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- core/Project.cpp    3 Apr 2007 19:06:18 -0000       1.24
+++ core/Project.cpp    3 Apr 2007 19:56:30 -0000       1.25
@@ -194,6 +194,22 @@
        QFile data( fileName );
 
        if (data.open( QIODevice::WriteOnly ) ) {
+               get_state(doc);
+               QTextStream stream(&data);
+               doc.save(stream, 4);
+               data.close();
+               info().information( tr("Project %1 saved ").arg(title) );
+       } else {
+               info().critical( tr("Couldn't open Project properties file for 
writing! (%1)").arg(fileName) );
+               return -1;
+       }
+
+       return 1;
+}
+
+
+QDomNode Project::get_state(QDomDocument doc, bool istemplate)
+{
                QDomElement projectNode = doc.createElement("Project");
                QDomElement properties = doc.createElement("Properties");
 
@@ -204,7 +220,9 @@
                properties.setAttribute("rate", m_rate);
                properties.setAttribute("bitdepth", m_bitDepth);
                properties.setAttribute("projectfileversion", 
PROJECT_FILE_VERSION);
+       if (! istemplate) {
                properties.setAttribute("id", m_id);
+       }
                properties.setAttribute("importdir", m_importDir);
                
                projectNode.appendChild(properties);
@@ -212,30 +230,23 @@
                doc.appendChild(projectNode);
 
                // Get the AudioSources Node, and append
-               projectNode.appendChild(m_asmanager->get_state( doc ));
+       if (! istemplate) {
+               projectNode.appendChild(m_asmanager->get_state(doc));
+       }
 
                // Get all the Songs
                QDomNode songsNode = doc.createElement("Songs");
 
-               foreach(Song* song, m_songs)
-               songsNode.appendChild(song->get_state(doc));
+       foreach(Song* song, m_songs) {
+               songsNode.appendChild(song->get_state(doc, istemplate));
+       }
 
                projectNode.appendChild(songsNode);
 
-               QTextStream stream(&data);
-               doc.save(stream, 4);
-               data.close();
-
-               info().information( tr("Project %1 saved ").arg(title) );
-
-       } else {
-               info().critical( tr("Couldn't open Project properties file for 
writing! (%1)").arg(fileName) );
-               return -1;
-       }
-
-       return 1;
+       return projectNode;
 }
 
+
 void Project::set_title(const QString& pTitle)
 {
        title = pTitle;

Index: core/Project.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/Project.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- core/Project.h      3 Apr 2007 19:06:18 -0000       1.14
+++ core/Project.h      3 Apr 2007 19:56:30 -0000       1.15
@@ -24,7 +24,7 @@
 
 #include <QString>
 #include <QList>
-
+#include <QDomNode>
 #include "ContextItem.h"
 
 
@@ -57,6 +57,7 @@
        Song* get_current_song() const ;
        Song* get_song(qint64 id) const;
        int get_song_index(qint64 id) const;
+       QDomNode get_state(QDomDocument doc, bool istemplate=false);
 
 
        // Set functions

Index: traverso/dialogs/project/ProjectManagerDialog.cpp
===================================================================
RCS file: 
/sources/traverso/traverso/src/traverso/dialogs/project/ProjectManagerDialog.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- traverso/dialogs/project/ProjectManagerDialog.cpp   3 Apr 2007 19:05:38 
-0000       1.7
+++ traverso/dialogs/project/ProjectManagerDialog.cpp   3 Apr 2007 19:56:30 
-0000       1.8
@@ -23,9 +23,12 @@
 
 #include "libtraversocore.h"
 #include <QStringList>
-#include <QMessageBox>
-#include <QFileDialog>
+#include <QInputDialog>
 #include <QHeaderView>
+#include <QTextStream>
+#include <QFile>
+#include <QDir>
+#include <QMessageBox>
 #include <dialogs/project/NewSongDialog.h>
 #include <Interface.h>
 
@@ -88,8 +91,6 @@
                return;
        }
        
-       printf("update_song_list() \n");
-
        treeSongWidget->clear();
        foreach(Song* song, m_project->get_songs()) {
 
@@ -137,8 +138,6 @@
        
        QTreeWidgetItem* item = treeSongWidget->currentItem();
        
-       
-       
        if ( ! item) {
                return;
        }
@@ -213,13 +212,56 @@
 
 void ProjectManagerDialog::on_exportTemplateButton_clicked()
 {
-}
+       bool ok;
+       QString text = QInputDialog::getText(this, tr("Save Template"),
+                                            tr("Enter Template name"),
+                                            QLineEdit::Normal, "", &ok);
+       if (! ok || text.isEmpty()) {
+               return;
+       }
 
-//eof
+       QString fileName = QDir::homePath() + "/.traverso/ProjectTemplates/";
+       
+       QDir dir;
+       if (! dir.exists(fileName)) {
+               if (! dir.mkdir(fileName)) {
+                       info().critical( tr("Couldn't open file %1 for 
writing!").arg(fileName));
+                       return;
+               }
+       }
+       
+       fileName.append(text + ".tpt");
+       
+       QDomDocument doc(text);
+       
+       if (QFile::exists(fileName)) {
+               QMessageBox::StandardButton button = QMessageBox::question(this,
+                               tr("Traverso - Information"),
+                               tr("Template with name %1 allready exists!\n Do 
you want to overwrite it?").arg(fileName),
+                               QMessageBox::Yes | QMessageBox::No,
+                               QMessageBox::No);
+                               
+               if (button == QMessageBox::No) {
+                       return;
+               }
+       }
+       
+       QFile file(fileName);
+
+       if (file.open( QIODevice::WriteOnly ) ) {
+               m_project->get_state(doc, true);
+               QTextStream stream(&file);
+               doc.save(stream, 4);
+               file.close();
+               info().information(tr("Saved Project Template: %1").arg(text));
+       } else {
+               info().critical( tr("Couldn't open file %1 for 
writing!").arg(fileName));
+       }
+       
+}
 
 void ProjectManagerDialog::accept()
 {
-       printf("accept\n");
        if ( ! m_project ) {
                hide();
                return;
@@ -232,7 +274,6 @@
 
 void ProjectManagerDialog::reject()
 {
-       printf("reject\n");
        if ( ! m_project ) {
                hide();
                return;
@@ -242,3 +283,5 @@
        hide();
 }
 
+//eof
+




reply via email to

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