File indexing completed on 2024-04-28 04:49:43

0001 /*
0002     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef K3BDOC_H
0007 #define K3BDOC_H
0008 
0009 #include "config-k3b.h"
0010 #include "k3bglobals.h"
0011 
0012 #include "k3b_export.h"
0013 
0014 #include <KIO/Global>
0015 #include <QObject>
0016 #include <QString>
0017 #include <QUrl>
0018 
0019 class QDomElement;
0020 namespace K3b {
0021     class BurnJob;
0022     class JobHandler;
0023     class Msf;
0024 
0025     namespace Device {
0026         class Device;
0027     }
0028 
0029     /**
0030      * Doc is the base document class.
0031      * It handles some general settings.
0032      */
0033     class LIBK3B_EXPORT Doc : public QObject
0034     {
0035         Q_OBJECT
0036 
0037     public:
0038         explicit Doc( QObject* = 0 );
0039         ~Doc() override;
0040 
0041         enum Type {
0042             AudioProject = 0x1,
0043             DataProject = 0x2,
0044             MixedProject = 0x4,
0045             VcdProject = 0x8,
0046             MovixProject = 0x10,
0047             VideoDvdProject = 0x20
0048         };
0049 
0050         virtual Type type() const = 0;
0051 
0052         /**
0053          * \return A string representation of the document type.
0054          */
0055         virtual QString typeString() const = 0;
0056 
0057         /**
0058          * \return A name for the project which might for example be used as a suggestion for a file name
0059          *         when saving. The default implementation extracts a name from the URL.
0060          */
0061         virtual QString name() const;
0062 
0063         /**
0064          * The media types that are supported by this project type.
0065          * The default implementation returns all writable media types.
0066          * This should NOT take into account settings like the writing mode
0067          * or anything that can be changed in the burn dialog.
0068          */
0069         virtual Device::MediaTypes supportedMediaTypes() const;
0070 
0071         /**
0072          * returns the view widget set with setView() or null if none has been set.
0073          */
0074         QWidget* view() const { return m_view; }
0075 
0076         /**
0077          * Just for convenience to make an easy mapping from doc to GUI possible.
0078          */
0079         void setView( QWidget* v ) { m_view = v; }
0080 
0081         /**
0082          * sets the modified flag for the document after a modifying action on the view connected to the document.
0083          */
0084         virtual void setModified( bool m = true );
0085 
0086         /**
0087          * returns if the document is modified or not. Use this to determine
0088          * if your document needs saving by the user on closing.
0089          */
0090         virtual bool isModified() const { return m_modified; }
0091 
0092         /**
0093          * Subclasses should call this when reimplementing.
0094          * Sets some defaults.
0095          * FIXME: this method is completely useless. Just do it all in the constructor
0096          */
0097         virtual bool newDocument();
0098 
0099         /**
0100          * Clear project, i.e. remove all data that has ben added
0101          */
0102         virtual void clear() = 0;
0103 
0104         /**
0105          * Load a project from an xml stream.
0106          *
0107          * This is used to load/save k3b projects.
0108          */
0109         virtual bool loadDocumentData( QDomElement* root ) = 0;
0110 
0111         /**
0112          * Save a project to an xml stream.
0113          *
0114          * This is used to load/save k3b projects.
0115          */
0116         virtual bool saveDocumentData( QDomElement* docElem ) = 0;
0117 
0118         /** returns the QUrl of the document */
0119         const QUrl& URL() const;
0120         /** sets the URL of the document */
0121         virtual void setURL( const QUrl& url );
0122 
0123         WritingMode writingMode() const { return m_writingMode; }
0124         bool dummy() const { return m_dummy; }
0125         bool onTheFly() const { return m_onTheFly; }
0126         bool removeImages() const { return m_removeImages; }
0127         bool onlyCreateImages() const { return m_onlyCreateImages; }
0128         int copies() const { return m_copies; }
0129         int speed() const { return m_speed; }
0130         Device::Device* burner() const { return m_burner; }
0131 
0132         /**
0133          * \return the size that will actually be burnt to the medium.
0134          * This only differs from size() for multisession projects.
0135          */
0136         virtual KIO::filesize_t burningSize() const;
0137         virtual KIO::filesize_t size() const = 0;
0138         virtual Msf length() const = 0;
0139 
0140         // FIXME: rename this to something like imagePath
0141         const QString& tempDir() const { return m_tempDir; }
0142 
0143         virtual int numOfTracks() const { return 1; }
0144 
0145         /**
0146          * Create a new BurnJob to burn this project. It is not mandatory to use this
0147          * method. You may also just create the BurnJob you need manually. It is just
0148          * easier this way since you don't need to distinguish between the different
0149          * project types.
0150          */
0151         virtual BurnJob* newBurnJob( JobHandler*, QObject* parent = 0 ) = 0;
0152 
0153         WritingApp writingApp() const { return m_writingApp; }
0154         void setWritingApp( WritingApp a ) { m_writingApp = a; }
0155 
0156         /**
0157          * @return true if the document has successfully been saved to a file
0158          */
0159         bool isSaved() const { return m_saved; }
0160 
0161         /**
0162          * Used for session management. Use with care.
0163          */
0164         void setSaved( bool s ) { m_saved = s; }
0165 
0166     Q_SIGNALS:
0167         void changed();
0168         void changed( K3b::Doc* );
0169 
0170     public Q_SLOTS:
0171         void setDummy( bool d );
0172         void setWritingMode( WritingMode m ) { m_writingMode = m; }
0173         void setOnTheFly( bool b ) { m_onTheFly = b; }
0174         void setSpeed( int speed );
0175         void setBurner( Device::Device* dev );
0176         void setTempDir( const QString& dir ) { m_tempDir = dir; }
0177         void setRemoveImages( bool b ) { m_removeImages = b; }
0178         void setOnlyCreateImages( bool b ) { m_onlyCreateImages = b; }
0179         void setCopies( int c ) { m_copies = c; }
0180 
0181         /**
0182          * the default implementation just calls addUrls with
0183          * list containing the url
0184          */
0185         virtual void addUrl( const QUrl& url );
0186         virtual void addUrls( const QList<QUrl>& urls ) = 0;
0187 
0188     protected:
0189         bool saveGeneralDocumentData( QDomElement* );
0190 
0191         bool readGeneralDocumentData( const QDomElement& );
0192 
0193     private Q_SLOTS:
0194         void slotChanged();
0195 
0196     private:
0197         /** the modified flag of the current document */
0198         bool m_modified;
0199         QUrl doc_url;
0200 
0201         QWidget* m_view;
0202 
0203         QString m_tempDir;
0204         Device::Device* m_burner;
0205         bool m_dummy;
0206         bool m_onTheFly;
0207         bool m_removeImages;
0208         bool m_onlyCreateImages;
0209         int  m_speed;
0210 
0211         /** see k3bglobals.h */
0212         WritingApp m_writingApp;
0213 
0214         WritingMode m_writingMode;
0215 
0216         int m_copies;
0217 
0218         bool m_saved;
0219     };
0220 }
0221 
0222 #endif // K3BDOC_H