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

0001 /*
0002     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef _K3B_CORE_H_
0007 #define _K3B_CORE_H_
0008 
0009 #include "k3b_export.h"
0010 #include "config-k3b.h"
0011 
0012 #include <KSharedConfig>
0013 
0014 #include <QObject>
0015 #include <QList>
0016 
0017 #define LIBK3B_VERSION K3B_VERSION_STRING
0018 
0019 #define k3bcore K3b::Core::k3bCore()
0020 
0021 
0022 class KConfig;
0023 
0024 namespace K3b {
0025 
0026     class ExternalBinManager;
0027     class Version;
0028     class Job;
0029     class BurnJob;
0030     class GlobalSettings;
0031     class PluginManager;
0032     class MediaCache;
0033 
0034     namespace Device {
0035         class DeviceManager;
0036         class Device;
0037     }
0038 
0039     /**
0040      * The K3b core takes care of the managers.
0041      * This has been separated from Application to
0042      * make creating a Part easy.
0043      * This is the heart of the K3b system. Every plugin may use this
0044      * to get the information it needs.
0045      */
0046     class LIBK3B_EXPORT Core : public QObject
0047     {
0048         Q_OBJECT
0049 
0050     public:
0051         /**
0052          * Although Core is a singleton it's constructor is not private to make inheritance
0053          * possible. Just make sure to only create one instance.
0054          */
0055         explicit Core( QObject* parent = 0 );
0056         ~Core() override;
0057 
0058         QList<Job*> runningJobs() const;
0059 
0060         /**
0061          * Equals to !runningJobs().isEmpty()
0062          */
0063         bool jobsRunning() const;
0064 
0065         /**
0066          * The default implementation calls add four initXXX() methods,
0067          * scans for devices, applications, and reads the global settings.
0068          */
0069         virtual void init();
0070 
0071         virtual void readSettings( KSharedConfig::Ptr c );
0072 
0073         virtual void saveSettings( KSharedConfig::Ptr c );
0074 
0075         MediaCache* mediaCache() const;
0076 
0077         Device::DeviceManager* deviceManager() const;
0078 
0079         /**
0080          * Returns the external bin manager from Core.
0081          *
0082          * By default Core only adds the default programs:
0083          * cdrecord, cdrdao, growisofs, mkisofs, dvd+rw-format, readcd
0084          *
0085          * If you need other programs you have to add them manually like this:
0086          * <pre>externalBinManager()->addProgram( new NormalizeProgram() );</pre>
0087          */
0088         ExternalBinManager* externalBinManager() const;
0089         PluginManager* pluginManager() const;
0090 
0091         /**
0092          * Global settings used throughout libk3b. Change the settings directly in the
0093          * GlobalSettings object. They will be saved by Core::saveSettings
0094          */
0095         GlobalSettings* globalSettings() const;
0096 
0097         /**
0098          * returns the version of the library as defined by LIBK3B_VERSION
0099          */
0100         Version version() const;
0101 
0102         /**
0103          * Used by the writing jobs to block a device.
0104          * This makes sure no device is used twice within libk3b
0105          *
0106          * When using this method in a job be aware that reimplementations might
0107          * open dialogs and resulting in a blocking call.
0108          *
0109          * This method calls internalBlockDevice() to do the actual work.
0110          */
0111         bool blockDevice( Device::Device* );
0112         void unblockDevice( Device::Device* );
0113 
0114         /**
0115          * \return \p true if \p dev has been blocked via blockDevice.
0116          */
0117         bool deviceBlocked( Device::Device* dev ) const;
0118 
0119         static Core* k3bCore() { return s_k3bCore; }
0120 
0121     Q_SIGNALS:
0122         /**
0123          * Emitted once a new job has been started. This includes burn jobs.
0124          */
0125         void jobStarted( K3b::Job* );
0126         void burnJobStarted( K3b::BurnJob* );
0127         void jobFinished( K3b::Job* );
0128         void burnJobFinished( K3b::BurnJob* );
0129 
0130     public Q_SLOTS:
0131         /**
0132          * Every running job registers itself with the core.
0133          * For now this is only used to determine if some job
0134          * is running.
0135          */
0136         void registerJob( K3b::Job* job );
0137         void unregisterJob( K3b::Job* job );
0138 
0139     protected:
0140         /**
0141          * Reimplement this to add additional checks.
0142          *
0143          * This method is thread safe. blockDevice makes sure
0144          * it is only executed in the GUI thread.
0145          */
0146         virtual bool internalBlockDevice( Device::Device* );
0147         virtual void internalUnblockDevice( Device::Device* );
0148 
0149         virtual Device::DeviceManager* createDeviceManager() const;
0150 
0151         void customEvent( QEvent* e ) override;
0152 
0153     private:
0154         class Private;
0155         Private* d;
0156 
0157         static Core* s_k3bCore;
0158     };
0159 }
0160 
0161 #endif