projectmanager.h 7.12 KB
Newer Older
Till Theato's avatar
Till Theato committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
Copyright (C) 2014  Till Theato <root@ttill.de>
This file is part of kdenlive. See www.kdenlive.org.

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 3 of the License, or
(at your option) any later version.
*/

#ifndef PROJECTMANAGER_H
#define PROJECTMANAGER_H

Nicolas Carion's avatar
Nicolas Carion committed
14 15 16
#include "kdenlivecore_export.h"
#include <KRecentFilesAction>
#include <QDir>
Till Theato's avatar
Till Theato committed
17
#include <QObject>
18
#include <QTime>
Nicolas Carion's avatar
Nicolas Carion committed
19 20
#include <QTimer>
#include <QUrl>
Laurent Montel's avatar
Laurent Montel committed
21
#include <QElapsedTimer>
Till Theato's avatar
Till Theato committed
22

23
#include "timeline2/model/timelineitemmodel.hpp"
Vincent Pinon's avatar
Vincent Pinon committed
24

25 26 27 28
#include <memory>
#include <unordered_map>
#include <unordered_set>

29 30
class KAutoSaveFile;
class KJob;
31
class KdenliveDoc;
32
class MarkerListModel;
33
class NotesPlugin;
34
class Project;
35
class QAction;
36
class QProgressDialog;
37
class QUrl;
38
class DocUndoStack;
Till Theato's avatar
Till Theato committed
39 40 41 42 43 44

/**
 * @class ProjectManager
 * @brief Takes care of interaction with projects.
 */

45
class /*KDENLIVECORE_EXPORT*/ ProjectManager : public QObject
Till Theato's avatar
Till Theato committed
46 47 48 49 50
{
    Q_OBJECT

public:
    /** @brief Sets up actions to interact for project interaction (undo, redo, open, save, ...) and creates an empty project. */
Laurent Montel's avatar
Laurent Montel committed
51
    explicit ProjectManager(QObject *parent = nullptr);
Nicolas Carion's avatar
Nicolas Carion committed
52
    ~ProjectManager() override;
Till Theato's avatar
Till Theato committed
53

Nicolas Carion's avatar
Nicolas Carion committed
54 55 56 57
    /** @brief Returns a pointer to the currently opened project. A project should always be open.
        The method is virtual to allow mocking
     */
    virtual KdenliveDoc *current();
Till Theato's avatar
Till Theato committed
58

59
    /** @brief Store command line args for later opening. */
60
    void init(const QUrl &projectUrl, const QString &clipList);
Till Theato's avatar
Till Theato committed
61

62
    void doOpenFile(const QUrl &url, KAutoSaveFile *stale);
63
    KRecentFilesAction *recentFilesAction();
64
    void prepareSave();
65 66
    /** @brief Disable all bin effects in current project */
    void disableBinEffects(bool disable);
67
    /** @brief Returns current project's xml scene */
Laurent Montel's avatar
Laurent Montel committed
68
    QString projectSceneList(const QString &outputFolder);
69 70
    /** @brief returns a default hd profile depending on timezone*/
    static QString getDefaultProjectFormat();
Laurent Montel's avatar
Laurent Montel committed
71
    void saveZone(const QStringList &info, const QDir &dir);
Laurent Montel's avatar
Laurent Montel committed
72
    /** @brief Move project data files to new url */
73
    void moveProjectData(const QString &src, const QString &dest);
74 75
    /** @brief Retrieve current project's notes */
    QString documentNotes() const;
76

77 78 79
    /** @brief Retrieve the current Guide Model
        The method is virtual to allow mocking
     */
80 81
    virtual std::shared_ptr<MarkerListModel> getGuideModel();

82 83 84 85 86
    /** @brief Return the current undo stack
        The method is virtual to allow mocking
    */
    virtual std::shared_ptr<DocUndoStack> undoStack();

87
    /** @brief This will create a backup file with fps appended to project name,
88
     *  and save the project with an updated profile info, then reopen it.
89
     */
Nicolas Carion's avatar
Nicolas Carion committed
90
    void saveWithUpdatedProfile(const QString &updatedProfile);
91

92 93 94 95 96 97 98 99
    /** @brief Get the number of tracks in this projec (video, audio).
     */
    QPair<int, int> tracksCount();

    /** @brief Add requested audio tracks number to projet.
     */
    void addAudioTracks(int tracksCount);

Till Theato's avatar
Till Theato committed
100
public slots:
101 102
    void newFile(QString profileName, bool showProjectSettings = true);
    void newFile(bool showProjectSettings = true);
Till Theato's avatar
Till Theato committed
103 104 105
    /** @brief Shows file open dialog. */
    void openFile();
    void openLastFile();
106 107
    /** @brief Load files / clips passed on the command line. */
    void slotLoadOnOpen();
Till Theato's avatar
Till Theato committed
108 109

    /** @brief Checks whether a URL is available to save to.
Nicolas Carion's avatar
Nicolas Carion committed
110
     * @return Whether the file was saved. */
Till Theato's avatar
Till Theato committed
111 112 113
    bool saveFile();

    /** @brief Shows a save file dialog for saving the project.
114
     * @param saveACopy Default is false. If true, the file title of the dialog is set to "Save Copy…"
Nicolas Carion's avatar
Nicolas Carion committed
115
     * @return Whether the file was saved. */
116
    bool saveFileAs(bool saveACopy = false);
117

Till Theato's avatar
Till Theato committed
118
    /** @brief Set properties to match outputFileName and save the document.
119
     * Creates an autosave version of the output file too (only if not in copymode), at
120 121
     * ~/.kde/data/stalefiles/kdenlive/ \n
     * that will be actually written in KdenliveDoc::slotAutoSave()
Nicolas Carion's avatar
Nicolas Carion committed
122
     * @param outputFileName The URL to save to / The document's URL.
123
     * @param saveACopy Default is false. If true, the file will be saved but isn’t opened afterwards. Besides no autosave version will be created
Nicolas Carion's avatar
Nicolas Carion committed
124
     * @return Whether we had success. */
125 126
    bool saveFileAs(const QString &outputFileName, bool saveACopy = false);

Till Theato's avatar
Till Theato committed
127
    /** @brief Close currently opened document. Returns false if something went wrong (cannot save modifications, ...). */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
128
    bool closeCurrentDocument(bool saveChanges = true, bool quit = false);
Till Theato's avatar
Till Theato committed
129 130

    /** @brief Prepares opening @param url.
Nicolas Carion's avatar
Nicolas Carion committed
131 132
     *
     * Checks if already open and whether backup exists */
133
    void openFile(const QUrl &url);
Laurent Montel's avatar
Laurent Montel committed
134

135 136
    /** @brief Start autosave timer */
    void slotStartAutoSave();
Till Theato's avatar
Till Theato committed
137

138
    /** @brief Update project and monitors profiles */
139
    void slotResetProfiles(bool reloadThumbs);
140

141 142 143
    /** @brief Rebuild consumers after a property change */
    void slotResetConsumers(bool fullReset);

144 145 146
    /** @brief Dis/enable all timeline effects */
    void slotDisableTimelineEffects(bool disable);

147 148
    /** @brief Un/Lock current timeline track */
    void slotSwitchTrackLock();
149
    void slotSwitchAllTrackLock();
150 151 152

    /** @brief Make current timeline track active/inactive*/
    void slotSwitchTrackActive();
153
    /** @brief Toogle the active/inactive state of all tracks*/
154
    void slotSwitchAllTrackActive();
155 156
    /** @brief Make all tracks active or inactive */
    void slotMakeAllTrackActive();
157

158 159
    /** @brief Un/Set current track as target */
    void slotSwitchTrackTarget();
160

161 162 163
    /** @brief Set the text for current project's notes */
    void setDocumentNotes(const QString &notes);

164 165
    /** @brief Project's duration changed, adjust monitor, etc. */
    void adjustProjectDuration();
166
    /** @brief Add an asset in timeline (effect, transition). */
Nicolas Carion's avatar
Nicolas Carion committed
167
    void activateAsset(const QVariantMap &effectData);
168 169
    /** @brief insert current timeline timecode in notes widget and focus widget to allow entering quick note */
    void slotAddProjectNote();
170

Till Theato's avatar
Till Theato committed
171 172
private slots:
    void slotRevert();
173
    /** @brief Open the project's backupdialog. */
174
    bool slotOpenBackup(const QUrl &url = QUrl());
175 176
    /** @brief Start autosaving the document. */
    void slotAutoSave();
177 178 179
    /** @brief Report progress of folder move operation. */
    void slotMoveProgress(KJob *, unsigned long progress);
    void slotMoveFinished(KJob *job);
Till Theato's avatar
Till Theato committed
180 181

signals:
182
    void docOpened(KdenliveDoc *document);
Nicolas Carion's avatar
Nicolas Carion committed
183
    //     void projectOpened(Project *project);
184 185

protected:
186
    bool updateTimeline(int pos = -1, int scrollPos = -1);
187

Till Theato's avatar
Till Theato committed
188
private:
189
    /** @brief checks if autoback files exists, recovers from it if user says yes, returns true if files were recovered. */
190
    bool checkForBackupFile(const QUrl &url, bool newFile = false);
Till Theato's avatar
Till Theato committed
191

Nicolas Carion's avatar
Nicolas Carion committed
192
    KdenliveDoc *m_project{nullptr};
193
    std::shared_ptr<TimelineItemModel> m_mainTimelineModel;
Laurent Montel's avatar
Laurent Montel committed
194
    QElapsedTimer m_lastSave;
195
    QTimer m_autoSaveTimer;
196 197
    QUrl m_startUrl;
    QString m_loadClipsOnOpen;
Laurent Montel's avatar
Laurent Montel committed
198
    QMap<QString, QString> m_replacementPattern;
Till Theato's avatar
Till Theato committed
199

200
    QAction *m_fileRevert;
201
    KRecentFilesAction *m_recentFilesAction;
202
    NotesPlugin *m_notesPlugin;
Nicolas Carion's avatar
Nicolas Carion committed
203
    QProgressDialog *m_progressDialog{nullptr};
204
    void saveRecentFiles();
Till Theato's avatar
Till Theato committed
205 206 207
};

#endif