[vlmc-devel] commit: Workspace: Check if there' s a current workspace before coying files in it. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Mon Jun 28 21:57:19 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Mon Jun 28 21:40:41 2010 +0200| [dcfdb53e01dc56176666fbab87a9bba9ae0b2f74] | committer: Hugo Beauzée-Luyssen 

Workspace: Check if there's a current workspace before coying files in it.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=dcfdb53e01dc56176666fbab87a9bba9ae0b2f74
---

 src/CMakeLists.txt                |    2 +
 src/Gui/library/MediaCellView.cpp |    8 +++++-
 src/Project/Workspace.cpp         |    8 +++++-
 src/Project/Workspace.h           |   10 ++++---
 src/Tools/ErrorHandler.cpp        |   49 +++++++++++++++++++++++++++++++++++++
 src/Tools/ErrorHandler.h          |   40 ++++++++++++++++++++++++++++++
 6 files changed, 111 insertions(+), 6 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 02a0592..08fa60d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -25,6 +25,7 @@ SET(VLMC_SRCS
     Renderer/GenericRenderer.cpp
     Renderer/WorkflowFileRenderer.cpp
     Renderer/WorkflowRenderer.cpp
+    Tools/ErrorHandler.cpp
     Tools/Pool.hpp
     Tools/QSingleton.hpp
     Tools/Singleton.hpp
@@ -67,6 +68,7 @@ SET (VLMC_HDRS
     Renderer/GenericRenderer.h
     Renderer/WorkflowFileRenderer.h
     Renderer/WorkflowRenderer.h
+    Tools/ErrorHandler.h
     Tools/VlmcDebug.h
     Workflow/AudioClipWorkflow.h 
     Workflow/ClipWorkflow.h
diff --git a/src/Gui/library/MediaCellView.cpp b/src/Gui/library/MediaCellView.cpp
index b624b08..8d499be 100644
--- a/src/Gui/library/MediaCellView.cpp
+++ b/src/Gui/library/MediaCellView.cpp
@@ -280,5 +280,11 @@ MediaCellView::contextMenuEvent( QContextMenuEvent *event )
     if ( selectedAction == NULL )
         return ;
     if ( copyInWorkspace == selectedAction )
-        Workspace::getInstance()->copyToWorkspace( m_clip->getMedia() );
+    {
+        if ( Workspace::getInstance()->copyToWorkspace( m_clip->getMedia() ) == false )
+        {
+            QMessageBox::warning( NULL, tr( "Can't copy to workspace" ),
+                                  tr( "Can't copy this media to workspace: %1" ).arg( Workspace::getInstance()->lastError() ) );
+        }
+    }
 }
diff --git a/src/Project/Workspace.cpp b/src/Project/Workspace.cpp
index 1444036..d7c1043 100644
--- a/src/Project/Workspace.cpp
+++ b/src/Project/Workspace.cpp
@@ -46,9 +46,14 @@ Workspace::~Workspace()
     delete m_mediasToCopyMutex;
 }
 
-void
+bool
 Workspace::copyToWorkspace( Media *media )
 {
+    if ( VLMC_PROJECT_GET_STRING("general/Workspace").length() == 0 )
+    {
+        setError( "There is no current workspace. Please create a project first.");
+        return false;
+    }
     QMutexLocker    lock( m_mediasToCopyMutex );
 
     if ( m_copyInProgress == true )
@@ -64,6 +69,7 @@ Workspace::copyToWorkspace( Media *media )
             startCopyWorker( media );
         }
     }
+    return true;
 }
 
 void
diff --git a/src/Project/Workspace.h b/src/Project/Workspace.h
index 1d7694e..d3532f7 100644
--- a/src/Project/Workspace.h
+++ b/src/Project/Workspace.h
@@ -23,18 +23,20 @@
 #ifndef WORKSPACE_H
 #define WORKSPACE_H
 
-#include <QObject>
+#include "Singleton.hpp"
+
+#include "ErrorHandler.h"
 
 #include <QMutex>
+#include <QObject>
 #include <QQueue>
 
-#include "Singleton.hpp"
 class   Clip;
 class   Media;
 
 class   QFileInfo;
 
-class Workspace : public QObject, public Singleton<Workspace>
+class Workspace : public QObject, public Singleton<Workspace>, public ErrorHandler
 {
     Q_OBJECT
 
@@ -46,7 +48,7 @@ class Workspace : public QObject, public Singleton<Workspace>
         static bool                 isInProjectDir( const Media *media );
         static QString              pathInProjectDir( const Media* media );
 
-        void                        copyToWorkspace( Media* media );
+        bool                        copyToWorkspace( Media* media );
         void                        copyAllToWorkspace();
     private:
         Workspace();
diff --git a/src/Tools/ErrorHandler.cpp b/src/Tools/ErrorHandler.cpp
new file mode 100644
index 0000000..9574d27
--- /dev/null
+++ b/src/Tools/ErrorHandler.cpp
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ * ErrorHandler.cpp: Manage errors.
+ *****************************************************************************
+ * Copyright (C) 2008-2010 VideoLAN
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "ErrorHandler.h"
+
+QString
+ErrorHandler::lastError()
+{
+    QString ret = m_lastError;
+    resetError();
+    return ret;
+}
+
+bool
+ErrorHandler::isInErrorState() const
+{
+    return m_lastError.size() > 0;
+}
+
+void
+ErrorHandler::resetError()
+{
+    m_lastError.clear();
+}
+
+void
+ErrorHandler::setError( const QString &error )
+{
+    m_lastError = error;
+}
diff --git a/src/Tools/ErrorHandler.h b/src/Tools/ErrorHandler.h
new file mode 100644
index 0000000..953ce89
--- /dev/null
+++ b/src/Tools/ErrorHandler.h
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * ErrorHandler.h: Manage errors.
+ *****************************************************************************
+ * Copyright (C) 2008-2010 VideoLAN
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef ERRORHANDLER_H
+#define ERRORHANDLER_H
+
+#include <QString>
+
+class ErrorHandler
+{
+    public:
+        QString         lastError();
+        bool            isInErrorState() const;
+        void            resetError();
+    protected:
+        void            setError( const QString& error );
+    private:
+        QString     m_lastError;
+};
+
+#endif // ERRORHANDLER_H



More information about the Vlmc-devel mailing list