Project.h 5.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*****************************************************************************
 * Project.h: Handles all core project components
 *****************************************************************************
 * Copyright (C) 2008-2014 VideoLAN
 *
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
 *
 * 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 PROJECT_H
#define PROJECT_H

#include "config.h"

#include <QObject>

30
#include "ILoadSave.h"
31 32 33 34 35 36 37 38
#include "Tools/Singleton.hpp"

class QDomDocument;
class QFile;
class QString;
class QUndoStack;
class QXmlStreamWriter;

39
class AutomaticBackup;
40
class IProjectUiCb;
41 42 43 44
class Library;
class MainWorkflow;
class ProjectManager;
class Settings;
45
class WorkflowRenderer;
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

class Project : public QObject, public Singleton<Project>
{
    Q_OBJECT
    public:
        static const QString            unNamedProject;
        static const QString            backupSuffix;

    public:
        // Main entry point for loading a project
        static bool     load( const QString& fileName );
        static bool     create(const QString& projectName, const QString& projectPath );
        static bool     isProjectLoaded();
        void            save();
        void            saveAs();
        bool            loadEmergencyBackup();
        void            emergencyBackup();
63
        bool            registerLoadSave( ILoadSave* loadSave );
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

    private:
        Q_DISABLE_COPY( Project );
        Project();
        ~Project();

        /**
         *  @brief      Check for a project backup file, and load the appropriate file,
         *              according to the user input.
         *  @param fileName     The path of the project file to load. This is expected to be
         *                      an absolute file path.
         *  if an outdated project backup is found, the used is asked if she wants to delete
         *  it.
         */
        bool                loadProject( const QString& fileName );
        /**
         * @brief connectComponents     Connects project specific components' signals & slots
         */
        void                connectComponents();
        /**
         * @brief checkBackupFile   Check for potential backup files and handle them
         * @param projectFile       The project file being opened
         * @return                  A path to a backup project if any. projectFile otherwise.
         */
        QString             checkBackupFile( const QString& projectFile );
        void                initSettings();
        QString             name();
        bool                closeProject();
        void                saveProject( const QString& filename );
        void                newProject( const QString& projectName, const QString &workspacePath );


    private slots:
        void                cleanChanged( bool val );
        void                libraryCleanChanged( bool val );
        void                projectNameChanged( const QVariant& projectName );
        void                autoSaveRequired();

    signals:
        /**
         *  This signal is emitted when :
         *      - The project name has changed
         *      - The clean state has changed
         *      - The revision (if activated) has changed
         */
        void                projectUpdated( const QString& projectName );

        /**
         *  \brief      Used to signal that the project has been saved.
         *
         *  Right now, it is only used by the undo stack to flag the current state as clean.
         */
        void                projectSaved();

        /**
          * @brief cleanStateChanged    Emited when the clean state changes.
          *
          * This state is a combination of both library & undoStack clean states.
          */
        void                cleanStateChanged( bool value );

        /**
         * @brief projectLoaded Emited when a project is loaded (which also include a project
         *                      being created)
         * @param projectName   The project name
         * @param projectPath   The path to the project file
         */
        void                projectLoaded( const QString& projectName, const QString& projectPath );

    private:
        QFile*              m_projectFile;
        QString             m_projectName;
        bool                m_isClean;
        bool                m_libraryCleanState;
        IProjectUiCb*       m_projectManagerUi;
139
        QList<ILoadSave*>   m_loadSave;
140 141 142 143 144 145 146

    ///////////////////////////////////
    // Dependent components part below:
    public:
        Library*            library();
        QUndoStack*         undoStack();
        Settings*           settings();
147 148
        MainWorkflow*       workflow();
        WorkflowRenderer*   workflowRenderer();
149 150 151 152 153 154

    private:
        Library*            m_library;
        MainWorkflow*       m_workflow;
        QUndoStack*         m_undoStack;
        Settings*           m_settings;
155
        WorkflowRenderer*   m_workflowRenderer;
156 157 158 159 160

    friend class Singleton<Project>;
};

#endif // PROJECT_H