diff --git a/TODO b/TODO index c0cc999..35a7aeb 100644 --- a/TODO +++ b/TODO @@ -20,7 +20,8 @@ Plans and ideas for 1.1: * offer a) no alignment of partition boundaries at all or b) legacy cylinder alignment or c) sector based alignment (the name is misleading, though) -* align partitions while changing size and position in the size dialog base +* don't hardcode any support for libparted-related stuff like shrinking fat16 + in the file system classes. =============================================================================== diff --git a/src/backend/corebackend.cpp b/src/backend/corebackend.cpp index 5fec6dc..c96d395 100644 --- a/src/backend/corebackend.cpp +++ b/src/backend/corebackend.cpp @@ -24,11 +24,8 @@ #include "util/globallog.h" -#include -#include #include #include -#include #include @@ -52,29 +49,6 @@ CoreBackend::~CoreBackend() delete d; } -CoreBackend* CoreBackend::self() -{ - static CoreBackend* instance = NULL; - - if (instance == NULL) - { - KPluginLoader loader(Config::backend()); - - KPluginFactory* factory = loader.factory(); - - if (factory != NULL) - { - instance = factory->create(NULL); - instance->setAboutData(factory->componentData().aboutData()); - kDebug() << "Loaded backend plugin: " << instance->about().programName() << ", " << instance->about().version(); - } - else - kWarning() << "Could not load instance plugin for core backend: " << loader.errorString(); - } - - return instance; -} - void CoreBackend::emitProgress(int i) { emit progress(i); diff --git a/src/backend/corebackend.h b/src/backend/corebackend.h index b222131..34a5ed7 100644 --- a/src/backend/corebackend.h +++ b/src/backend/corebackend.h @@ -26,6 +26,7 @@ #include #include +class CoreBackendManager; class CoreBackendDevice; class Device; class PartitionTable; @@ -39,6 +40,8 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT CoreBackend : public QObject Q_OBJECT Q_DISABLE_COPY(CoreBackend) + friend class CoreBackendManager; + protected: CoreBackend(); virtual ~CoreBackend(); @@ -48,7 +51,6 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT CoreBackend : public QObject void scanProgress(const QString&,int); public: - static CoreBackend* self(); virtual const KAboutData& about() const { return *m_AboutData; } virtual QList scanDevices() = 0; diff --git a/src/backend/corebackendmanager.cpp b/src/backend/corebackendmanager.cpp new file mode 100644 index 0000000..a4ac5d6 --- /dev/null +++ b/src/backend/corebackendmanager.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (C) 2010 by Volker Lanz +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +CoreBackendManager::CoreBackendManager() : + m_Backend(NULL) +{ +} + +CoreBackendManager* CoreBackendManager::self() +{ + static CoreBackendManager* instance = NULL; + + if (instance == NULL) + instance = new CoreBackendManager; + + return instance; +} + +KService::List CoreBackendManager::list() const +{ + return KServiceTypeTrader::self()->query("PartitionManager/Plugin", "[X-KDE-PluginInfo-Category] == 'BackendPlugin'"); +} + +bool CoreBackendManager::load(const QString& name) +{ + if (backend()) + unload(); + + KPluginLoader loader(name); + + KPluginFactory* factory = loader.factory(); + + if (factory != NULL) + { + m_Backend = factory->create(NULL); + backend()->setAboutData(factory->componentData().aboutData()); + kDebug() << "Loaded backend plugin: " << backend()->about().programName() << ", " << backend()->about().version(); + return true; + } + + kWarning() << "Could not load plugin for core backend " << name << ": " << loader.errorString(); + return false; +} + +void CoreBackendManager::unload() +{ + delete m_Backend; + m_Backend = NULL; +} diff --git a/src/backend/corebackendmanager.h b/src/backend/corebackendmanager.h new file mode 100644 index 0000000..d8017d7 --- /dev/null +++ b/src/backend/corebackendmanager.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2010 by Volker Lanz + +class QString; +class QStringList; +class CoreBackend; + +class LIBPARTITIONMANAGERPRIVATE_EXPORT CoreBackendManager +{ + private: + CoreBackendManager(); + + public: + static CoreBackendManager* self(); + static QString defaultBackendName() { return "pmlibpartedbackendplugin"; } + + KService::List list() const; + bool load(const QString& name); + void unload(); + CoreBackend* backend() { return m_Backend; } + + private: + CoreBackend* m_Backend; +}; + +#endif diff --git a/src/config.kcfg b/src/config.kcfg index 0a5dd53..cb6cc45 100644 --- a/src/config.kcfg +++ b/src/config.kcfg @@ -80,7 +80,7 @@ - pluginpmlibparted + pmlibpartedbackendplugin FileSystem::Ext3 diff --git a/src/core/copysourcedevice.cpp b/src/core/copysourcedevice.cpp index ada8021..b0fae2e 100644 --- a/src/core/copysourcedevice.cpp +++ b/src/core/copysourcedevice.cpp @@ -20,6 +20,7 @@ #include "core/copysourcedevice.h" #include "backend/corebackend.h" +#include "backend/corebackendmanager.h" #include "backend/corebackenddevice.h" #include "core/copytarget.h" @@ -53,7 +54,7 @@ CopySourceDevice::~CopySourceDevice() */ bool CopySourceDevice::open() { - m_BackendDevice = CoreBackend::self()->openDeviceExclusive(device().deviceNode()); + m_BackendDevice = CoreBackendManager::self()->backend()->openDeviceExclusive(device().deviceNode()); return m_BackendDevice != NULL; } diff --git a/src/core/copytargetdevice.cpp b/src/core/copytargetdevice.cpp index e06fb95..e14955d 100644 --- a/src/core/copytargetdevice.cpp +++ b/src/core/copytargetdevice.cpp @@ -20,6 +20,7 @@ #include "core/copytargetdevice.h" #include "backend/corebackend.h" +#include "backend/corebackendmanager.h" #include "backend/corebackenddevice.h" #include "core/device.h" @@ -50,7 +51,7 @@ CopyTargetDevice::~CopyTargetDevice() */ bool CopyTargetDevice::open() { - m_BackendDevice = CoreBackend::self()->openDeviceExclusive(device().deviceNode()); + m_BackendDevice = CoreBackendManager::self()->backend()->openDeviceExclusive(device().deviceNode()); return m_BackendDevice != NULL; } diff --git a/src/core/devicescanner.cpp b/src/core/devicescanner.cpp index 146f5ca..f30713a 100644 --- a/src/core/devicescanner.cpp +++ b/src/core/devicescanner.cpp @@ -20,6 +20,7 @@ #include "core/devicescanner.h" #include "backend/corebackend.h" +#include "backend/corebackendmanager.h" #include "core/operationstack.h" #include "core/device.h" @@ -34,7 +35,12 @@ DeviceScanner::DeviceScanner(QObject* parent, OperationStack& ostack) : QThread(parent), m_OperationStack(ostack) { - connect(CoreBackend::self(), SIGNAL(scanProgress(QString,int)), SIGNAL(progress(QString,int))); + setupConnections(); +} + +void DeviceScanner::setupConnections() +{ + connect(CoreBackendManager::self()->backend(), SIGNAL(scanProgress(QString,int)), SIGNAL(progress(QString,int))); } void DeviceScanner::clear() @@ -54,7 +60,7 @@ void DeviceScanner::scan() clear(); - QList deviceList = CoreBackend::self()->scanDevices(); + QList deviceList = CoreBackendManager::self()->backend()->scanDevices(); foreach(Device* d, deviceList) operationStack().addDevice(d); diff --git a/src/core/devicescanner.h b/src/core/devicescanner.h index 30b7342..26e6621 100644 --- a/src/core/devicescanner.h +++ b/src/core/devicescanner.h @@ -40,6 +40,7 @@ class DeviceScanner : public QThread public: void clear(); /**< clear Devices and the OperationStack */ void scan(); /**< do the actual scanning; blocks if called directly */ + void setupConnections(); signals: void progress(const QString& device_node, int progress); diff --git a/src/gui/configureoptionsdialog.cpp b/src/gui/configureoptionsdialog.cpp index 9636e75..b24d05f 100644 --- a/src/gui/configureoptionsdialog.cpp +++ b/src/gui/configureoptionsdialog.cpp @@ -19,6 +19,8 @@ #include "gui/configureoptionsdialog.h" +#include "backend/corebackendmanager.h" + #include "fs/filesystem.h" #include "fs/filesystemfactory.h" @@ -28,6 +30,7 @@ #include "ui_configurepagefilesystemcolors.h" #include +#include #include @@ -37,8 +40,11 @@ class GeneralPageWidget : public QWidget, public Ui::ConfigurePageGeneral GeneralPageWidget(QWidget* parent) : QWidget(parent) { setupUi(this); setupDialog(); } public: - QComboBox& comboDefaultFileSystem() { return *m_ComboDefaultFileSystem; } - const QComboBox& comboDefaultFileSystem() const { return *m_ComboDefaultFileSystem; } + KComboBox& comboDefaultFileSystem() { return *m_ComboDefaultFileSystem; } + const KComboBox& comboDefaultFileSystem() const { return *m_ComboDefaultFileSystem; } + + KComboBox& comboBackend() { return *m_ComboBackend; } + const KComboBox& comboBackend() const { return *m_ComboBackend; } FileSystem::Type defaultFileSystem() const { @@ -50,6 +56,26 @@ class GeneralPageWidget : public QWidget, public Ui::ConfigurePageGeneral comboDefaultFileSystem().setCurrentIndex(comboDefaultFileSystem().findText(FileSystem::nameForType(t))); } + QString backend() const + { + KService::List services = CoreBackendManager::self()->list(); + + foreach(KService::Ptr p, services) + if (p->name() == comboBackend().currentText()) + return p->library(); + + return QString(); + } + + void setBackend(const QString& name) + { + KService::List services = CoreBackendManager::self()->list(); + + foreach(KService::Ptr p, services) + if (p->library() == name) + comboBackend().setCurrentIndex(comboBackend().findText(p->name())); + } + private: void setupDialog() { @@ -64,6 +90,12 @@ class GeneralPageWidget : public QWidget, public Ui::ConfigurePageGeneral comboDefaultFileSystem().addItem(createFileSystemColor(FileSystem::typeForName(fsName), 8), fsName); setDefaultFileSystem(FileSystem::defaultFileSystem()); + + KService::List services = CoreBackendManager::self()->list(); + foreach(KService::Ptr p, services) + comboBackend().addItem(p->name()); + + setBackend(Config::backend()); } }; @@ -86,6 +118,8 @@ ConfigureOptionsDialog::ConfigureOptionsDialog(QWidget* parent, const QString& n item->setIcon(KIcon(DesktopIcon("configure"))); connect(&generalPageWidget().comboDefaultFileSystem(), SIGNAL(activated(int)), SLOT(onComboDefaultFileSystemActivated(int))); + connect(&generalPageWidget().comboBackend(), SIGNAL(activated(int)), SLOT(onComboBackendActivated(int))); + item = addPage(&fileSystemColorsPageWidget(), i18nc("@title:tab", "File System Colors"), QString(), i18n("File System Color Settings")); item->setIcon(KIcon(DesktopIcon("format-fill-color"))); @@ -101,22 +135,47 @@ ConfigureOptionsDialog::~ConfigureOptionsDialog() void ConfigureOptionsDialog::updateSettings() { - Config::setDefaultFileSystem(generalPageWidget().defaultFileSystem()); + KConfigDialog::updateSettings(); + + bool changed = false; + + if (generalPageWidget().defaultFileSystem() != Config::defaultFileSystem()) + { + Config::setDefaultFileSystem(generalPageWidget().defaultFileSystem()); + changed = true; + } + + if (generalPageWidget().backend() != Config::backend()) + { + Config::setBackend(generalPageWidget().backend()); + changed = true; + } + + if (changed) + emit KConfigDialog::settingsChanged(i18n("General Settings")); +} + +bool ConfigureOptionsDialog::hasChanged() +{ + bool result = KConfigDialog::hasChanged(); + + KConfigSkeletonItem* kcItem = Config::self()->findItem("defaultFileSystem"); + result = result || !kcItem->isEqual(generalPageWidget().defaultFileSystem()); + + kcItem = Config::self()->findItem("backend"); + result = result || !kcItem->isEqual(generalPageWidget().backend()); + + return result; } bool ConfigureOptionsDialog::isDefault() { - bool result = !hasChanged(); + bool result = KConfigDialog::isDefault(); if (result) { const bool useDefaults = Config::self()->useDefaults(true); - KConfigSkeletonItem* kcItem = Config::self()->findItem("defaultFileSystem"); - if (kcItem != NULL) - result = kcItem->isEqual(generalPageWidget().defaultFileSystem()); - else - kWarning() << "the kcitem for defaultFileSytstem is gone."; - + result = !hasChanged(); Config::self()->useDefaults(useDefaults); } @@ -127,6 +186,6 @@ void ConfigureOptionsDialog::updateWidgetsDefault() { bool useDefaults = Config::self()->useDefaults(true); generalPageWidget().setDefaultFileSystem(FileSystem::defaultFileSystem()); + generalPageWidget().setBackend(CoreBackendManager::defaultBackendName()); Config::self()->useDefaults(useDefaults); } - diff --git a/src/gui/configureoptionsdialog.h b/src/gui/configureoptionsdialog.h index 493fb64..61b32e2 100644 --- a/src/gui/configureoptionsdialog.h +++ b/src/gui/configureoptionsdialog.h @@ -38,8 +38,10 @@ class ConfigureOptionsDialog : public KConfigDialog protected slots: virtual void updateSettings(); virtual void updateWidgetsDefault(); + virtual bool hasChanged(); virtual bool isDefault(); void onComboDefaultFileSystemActivated(int) { settingsChangedSlot(); } + void onComboBackendActivated(int) { settingsChangedSlot(); } protected: GeneralPageWidget& generalPageWidget() { Q_ASSERT(m_GeneralPageWidget); return *m_GeneralPageWidget; } diff --git a/src/gui/configurepagegeneral.ui b/src/gui/configurepagegeneral.ui index 7457685..4e3dd80 100644 --- a/src/gui/configurepagegeneral.ui +++ b/src/gui/configurepagegeneral.ui @@ -7,7 +7,7 @@ 0 0 459 - 633 + 389 @@ -32,7 +32,7 @@ - Allow Applying Operations Without Administrator Privileges + Allow applying operations without administrator privileges @@ -54,7 +54,7 @@ - Use Cylinder Based MS-Dos Partition Alignment (Windows XP compatible) + Use cylinder based MS-Dos partition alignment (Windows XP compatible) true @@ -67,7 +67,7 @@ true - Partition Sector Alignment: + Partition sector alignment: kcfg_sectorAlignment @@ -108,7 +108,7 @@ - Hide Messages Below: + Hide messages below: kcfg_minLogLevel @@ -116,7 +116,7 @@ - + Debug @@ -157,21 +157,56 @@ - Default File System: + Default file system: - kcfg_minLogLevel + m_ComboDefaultFileSystem - + + + + + + + + + + 0 + 1 + + + + Backend + + + + + + Active backend: + + + m_ComboBackend + + + + + + + + KComboBox + QComboBox +
kcombobox.h
+
+
diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 9d629db..9b5f567 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -26,6 +26,9 @@ #include "gui/configureoptionsdialog.h" #include "gui/devicepropsdialog.h" +#include "backend/corebackendmanager.h" +#include "backend/corebackend.h" + #include "core/device.h" #include "core/partition.h" @@ -42,6 +45,8 @@ #include "fs/filesystem.h" #include "fs/filesystemfactory.h" +#include "util/helpers.h" + #include #include #include @@ -903,8 +908,23 @@ void MainWindow::onFileSystemSupport() dlg.exec(); } -void MainWindow::onSettingsChanged(const QString&) +void MainWindow::onSettingsChanged() { + if (CoreBackendManager::self()->backend()->about().appName() != Config::backend()) + { + CoreBackendManager::self()->unload(); + // FIXME: if loadBackend() fails to load the configured backend and loads the default + // one instead it also sets the default backend in the config; the config dialog will + // overwrite that again, however, after we're done here. + if (loadBackend()) + { + deviceScanner().setupConnections(); + scanDevices(); + } + else + close(); + } + enableActions(); pmWidget().updatePartitions(); } @@ -916,7 +936,11 @@ void MainWindow::onConfigureOptions() QPointer dlg = new ConfigureOptionsDialog(this, "Settings"); - connect(dlg, SIGNAL(settingsChanged(const QString&)), SLOT(onSettingsChanged(const QString&))); + // FIXME: we'd normally use settingsChanged(), according to the kde api docs. however, this + // is emitted each time the user changes any of our own settings (backend, default file system), without + // applying or clicking ok. so the below is the workaround for that. + connect(dlg, SIGNAL(applyClicked()), SLOT(onSettingsChanged())); + connect(dlg, SIGNAL(okClicked()), SLOT(onSettingsChanged())); dlg->show(); } @@ -943,4 +967,3 @@ void MainWindow::onPropertiesDevice(const QString&) delete dlg; } } - diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 52469b6..9413a2c 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -159,7 +159,7 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT MainWindow : public KXmlGuiWindow, publi void onClearAllOperations(); void onConfigureOptions(); - void onSettingsChanged(const QString&); + void onSettingsChanged(); void onFileSystemSupport(); diff --git a/src/jobs/createpartitionjob.cpp b/src/jobs/createpartitionjob.cpp index 478edd4..e585cf7 100644 --- a/src/jobs/createpartitionjob.cpp +++ b/src/jobs/createpartitionjob.cpp @@ -20,6 +20,7 @@ #include "jobs/createpartitionjob.h" #include "backend/corebackend.h" +#include "backend/corebackendmanager.h" #include "backend/corebackenddevice.h" #include "backend/corebackendpartitiontable.h" @@ -49,7 +50,7 @@ bool CreatePartitionJob::run(Report& parent) Report* report = jobStarted(parent); - CoreBackendDevice* backendDevice = CoreBackend::self()->openDevice(device().deviceNode()); + CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(device().deviceNode()); if (backendDevice) { diff --git a/src/jobs/createpartitiontablejob.cpp b/src/jobs/createpartitiontablejob.cpp index a068865..4c1c450 100644 --- a/src/jobs/createpartitiontablejob.cpp +++ b/src/jobs/createpartitiontablejob.cpp @@ -19,6 +19,7 @@ #include "jobs/createpartitiontablejob.h" +#include "backend/corebackendmanager.h" #include "backend/corebackenddevice.h" #include "backend/corebackend.h" @@ -44,7 +45,7 @@ bool CreatePartitionTableJob::run(Report& parent) Report* report = jobStarted(parent); - CoreBackendDevice* backendDevice = CoreBackend::self()->openDevice(device().deviceNode()); + CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(device().deviceNode()); if (backendDevice != NULL) { diff --git a/src/jobs/deletefilesystemjob.cpp b/src/jobs/deletefilesystemjob.cpp index 22135dc..339edf8 100644 --- a/src/jobs/deletefilesystemjob.cpp +++ b/src/jobs/deletefilesystemjob.cpp @@ -20,6 +20,7 @@ #include "jobs/deletefilesystemjob.h" #include "backend/corebackend.h" +#include "backend/corebackendmanager.h" #include "backend/corebackenddevice.h" #include "backend/corebackendpartitiontable.h" @@ -60,7 +61,7 @@ bool DeleteFileSystemJob::run(Report& parent) rval = true; else { - CoreBackendDevice* backendDevice = CoreBackend::self()->openDevice(device().deviceNode()); + CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(device().deviceNode()); if (backendDevice) { diff --git a/src/jobs/deletepartitionjob.cpp b/src/jobs/deletepartitionjob.cpp index b8497ae..bc7b6de 100644 --- a/src/jobs/deletepartitionjob.cpp +++ b/src/jobs/deletepartitionjob.cpp @@ -20,6 +20,7 @@ #include "jobs/deletepartitionjob.h" #include "backend/corebackend.h" +#include "backend/corebackendmanager.h" #include "backend/corebackenddevice.h" #include "backend/corebackendpartitiontable.h" @@ -56,7 +57,7 @@ bool DeletePartitionJob::run(Report& parent) Report* report = jobStarted(parent); - CoreBackendDevice* backendDevice = CoreBackend::self()->openDevice(device().deviceNode()); + CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(device().deviceNode()); if (backendDevice) { diff --git a/src/jobs/resizefilesystemjob.cpp b/src/jobs/resizefilesystemjob.cpp index dcb7804..c32245b 100644 --- a/src/jobs/resizefilesystemjob.cpp +++ b/src/jobs/resizefilesystemjob.cpp @@ -23,6 +23,7 @@ #include "core/device.h" #include "backend/corebackend.h" +#include "backend/corebackendmanager.h" #include "backend/corebackenddevice.h" #include "backend/corebackendpartitiontable.h" @@ -115,7 +116,7 @@ bool ResizeFileSystemJob::resizeFileSystemInternal(Report& report) { bool rval = false; - CoreBackendDevice* backendDevice = CoreBackend::self()->openDevice(device().deviceNode()); + CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(device().deviceNode()); if (backendDevice) { @@ -123,9 +124,9 @@ bool ResizeFileSystemJob::resizeFileSystemInternal(Report& report) if (backendPartitionTable) { - connect(CoreBackend::self(), SIGNAL(progress(int)), this, SIGNAL(progress(int))); + connect(CoreBackendManager::self()->backend(), SIGNAL(progress(int)), this, SIGNAL(progress(int))); rval = backendPartitionTable->resizeFileSystem(report, partition(), newLength()); - disconnect(CoreBackend::self(), SIGNAL(progress(int)), this, SIGNAL(progress(int))); + disconnect(CoreBackendManager::self()->backend(), SIGNAL(progress(int)), this, SIGNAL(progress(int))); if (rval) { diff --git a/src/jobs/restorefilesystemjob.cpp b/src/jobs/restorefilesystemjob.cpp index a1c4996..b8fb557 100644 --- a/src/jobs/restorefilesystemjob.cpp +++ b/src/jobs/restorefilesystemjob.cpp @@ -20,6 +20,7 @@ #include "jobs/restorefilesystemjob.h" #include "backend/corebackend.h" +#include "backend/corebackendmanager.h" #include "backend/corebackenddevice.h" #include "backend/corebackendpartitiontable.h" @@ -83,7 +84,7 @@ bool RestoreFileSystemJob::run(Report& parent) // create a new file system for what was restored with the length of the image file const qint64 newLastSector = targetPartition().firstSector() + copySource.length() - 1; - CoreBackendDevice* backendDevice = CoreBackend::self()->openDevice(targetDevice().deviceNode()); + CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(targetDevice().deviceNode()); FileSystem::Type t = FileSystem::Unknown; diff --git a/src/jobs/setpartflagsjob.cpp b/src/jobs/setpartflagsjob.cpp index 983238e..5518aba 100644 --- a/src/jobs/setpartflagsjob.cpp +++ b/src/jobs/setpartflagsjob.cpp @@ -20,6 +20,7 @@ #include "jobs/setpartflagsjob.h" #include "backend/corebackend.h" +#include "backend/corebackendmanager.h" #include "backend/corebackenddevice.h" #include "backend/corebackendpartition.h" #include "backend/corebackendpartitiontable.h" @@ -57,7 +58,7 @@ bool SetPartFlagsJob::run(Report& parent) Report* report = jobStarted(parent); - CoreBackendDevice* backendDevice = CoreBackend::self()->openDevice(device().deviceNode()); + CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(device().deviceNode()); if (backendDevice) { diff --git a/src/jobs/setpartgeometryjob.cpp b/src/jobs/setpartgeometryjob.cpp index 733406a..a24f804 100644 --- a/src/jobs/setpartgeometryjob.cpp +++ b/src/jobs/setpartgeometryjob.cpp @@ -20,6 +20,7 @@ #include "jobs/setpartgeometryjob.h" #include "backend/corebackend.h" +#include "backend/corebackendmanager.h" #include "backend/corebackenddevice.h" #include "backend/corebackendpartitiontable.h" @@ -55,7 +56,7 @@ bool SetPartGeometryJob::run(Report& parent) Report* report = jobStarted(parent); - CoreBackendDevice* backendDevice = CoreBackend::self()->openDevice(device().deviceNode()); + CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(device().deviceNode()); if (backendDevice) { diff --git a/src/main.cpp b/src/main.cpp index bd5d02d..62f3651 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,12 +20,14 @@ #include "gui/mainwindow.h" #include "backend/corebackend.h" +#include "backend/corebackendmanager.h" #include "util/helpers.h" #include #include #include +#include #include @@ -47,11 +49,8 @@ int main(int argc, char* argv[]) Config::instance("partitionmanagerrc"); - if (CoreBackend::self() == NULL) - { - KMessageBox::error(NULL, i18nc("@info", "The core backend plugin could not be loaded. Please check your installation."), i18nc("@title:window", "Fatal Error: Could Not Load Backend Plugin")); + if (!loadBackend()) return 0; - } MainWindow* mainWindow = new MainWindow(); mainWindow->show(); diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index d10547e..36c2283 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -17,5 +17,8 @@ ############################################ +install(FILES pmcorebackendplugin.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR}) + add_subdirectory(libparted) add_subdirectory(dummy) + diff --git a/src/plugins/dummy/CMakeLists.txt b/src/plugins/dummy/CMakeLists.txt index 4ab648c..b58b25b 100644 --- a/src/plugins/dummy/CMakeLists.txt +++ b/src/plugins/dummy/CMakeLists.txt @@ -15,12 +15,12 @@ # Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -file (GLOB pluginpmdummy_SRCS *.cpp) +file (GLOB pmdummybackendplugin_SRCS *.cpp) -kde4_add_library(pluginpmdummy SHARED ${pluginpmdummy_SRCS}) +kde4_add_plugin(pmdummybackendplugin ${pmdummybackendplugin_SRCS}) -target_link_libraries(pluginpmdummy partitionmanagerprivate ${KDE4_KDECORE_LIBS} ${KDE4_KIO_LIBS} ${LIBPARTED_LIBS} ${BLKID_LIBRARIES} ${KDE4_SOLID_LIBS}) +target_link_libraries(pmdummybackendplugin partitionmanagerprivate ${KDE4_KDECORE_LIBS} ${KDE4_KIO_LIBS} ${LIBPARTED_LIBS} ${BLKID_LIBRARIES} ${KDE4_SOLID_LIBS}) -set_target_properties(pluginpmdummy PROPERTIES PREFIX "") +install(TARGETS pmdummybackendplugin DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES pmdummybackendplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR}) -install(TARGETS pluginpmdummy DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/src/plugins/dummy/dummybackend.cpp b/src/plugins/dummy/dummybackend.cpp index cedf847..82390bf 100644 --- a/src/plugins/dummy/dummybackend.cpp +++ b/src/plugins/dummy/dummybackend.cpp @@ -42,7 +42,7 @@ K_PLUGIN_FACTORY(DummyBackendFactory, registerPlugin(); ) static KAboutData createPluginAboutData() { KAboutData about( - "dummypmplugin", + "pmdummybackendplugin", NULL, ki18nc("@title", "Dummy Backend Plugin"), QString(VERSION).toUtf8(), diff --git a/src/plugins/dummy/pmdummybackendplugin.desktop b/src/plugins/dummy/pmdummybackendplugin.desktop new file mode 100644 index 0000000..2492cbd --- /dev/null +++ b/src/plugins/dummy/pmdummybackendplugin.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=KDE Partition Manager Dummy Backend +Comment=A KDE Partition Manager dummy backend for testing purposes. +Type=Service +ServiceTypes=PartitionManager/Plugin +Icon=preferences-plugin + +X-KDE-PluginInfo-Name=pmdummybackendplugin +X-KDE-PluginInfo-Author=Volker Lanz +X-KDE-PluginInfo-Email=vl@fidra.de +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-Category=BackendPlugin +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-PluginInfo-Version=1 +X-KDE-PluginInfo-Website=http://www.partitionmanager.org diff --git a/src/plugins/libparted/CMakeLists.txt b/src/plugins/libparted/CMakeLists.txt index 7202b6c..14a0765 100644 --- a/src/plugins/libparted/CMakeLists.txt +++ b/src/plugins/libparted/CMakeLists.txt @@ -15,12 +15,11 @@ # Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -file (GLOB pluginpmlibparted_SRCS *.cpp) +file (GLOB pmlibpartedbackendplugin_SRCS *.cpp) -kde4_add_library(pluginpmlibparted SHARED ${pluginpmlibparted_SRCS}) +kde4_add_plugin(pmlibpartedbackendplugin ${pmlibpartedbackendplugin_SRCS}) -target_link_libraries(pluginpmlibparted partitionmanagerprivate ${KDE4_KDECORE_LIBS} ${KDE4_KIO_LIBS} ${LIBPARTED_LIBS} ${BLKID_LIBRARIES} ${KDE4_SOLID_LIBS}) +target_link_libraries(pmlibpartedbackendplugin partitionmanagerprivate ${KDE4_KDECORE_LIBS} ${KDE4_KIO_LIBS} ${LIBPARTED_LIBS} ${BLKID_LIBRARIES} ${KDE4_SOLID_LIBS}) -set_target_properties(pluginpmlibparted PROPERTIES PREFIX "") - -install(TARGETS pluginpmlibparted DESTINATION ${PLUGIN_INSTALL_DIR}) +install(TARGETS pmlibpartedbackendplugin DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES pmlibpartedbackendplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index 95adf4d..d0e77d3 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -56,7 +56,7 @@ K_PLUGIN_FACTORY(LibPartedBackendFactory, registerPlugin(); ) static KAboutData createPluginAboutData() { KAboutData about( - "libpartedpmplugin", + "pmlibpartedbackendplugin", NULL, ki18nc("@title", "LibParted Backend Plugin"), QString("%1, libparted version: %2").arg(VERSION).arg(ped_get_version()).toUtf8(), @@ -425,7 +425,7 @@ QList LibPartedBackend::scanDevices() const Solid::Block* solidBlock = solidDevice.as(); - Device* d = CoreBackend::self()->scanDevice(solidBlock->device()); + Device* d = scanDevice(solidBlock->device()); if (d != NULL) { diff --git a/src/plugins/libparted/libpartedpartitiontable.cpp b/src/plugins/libparted/libpartedpartitiontable.cpp index 0b48cbd..3960bca 100644 --- a/src/plugins/libparted/libpartedpartitiontable.cpp +++ b/src/plugins/libparted/libpartedpartitiontable.cpp @@ -21,6 +21,9 @@ #include "plugins/libparted/libpartedpartition.h" #include "plugins/libparted/libpartedbackend.h" +#include "backend/corebackend.h" +#include "backend/corebackendmanager.h" + #include "core/partition.h" #include "core/device.h" @@ -291,7 +294,7 @@ bool LibPartedPartitionTable::clobberFileSystem(Report& report, const Partition& static void pedTimerHandler(PedTimer* pedTimer, void*) { - CoreBackend::self()->emitProgress(pedTimer->frac * 100); + CoreBackendManager::self()->backend()->emitProgress(pedTimer->frac * 100); } bool LibPartedPartitionTable::resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) diff --git a/src/plugins/libparted/pmlibpartedbackendplugin.desktop b/src/plugins/libparted/pmlibpartedbackendplugin.desktop new file mode 100644 index 0000000..652b261 --- /dev/null +++ b/src/plugins/libparted/pmlibpartedbackendplugin.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=KDE Partition Manager LibParted Backend +Comment=The LibParted backend for KDE Partition Manager +Type=Service +ServiceTypes=PartitionManager/Plugin +Icon=preferences-plugin + +X-KDE-PluginInfo-Name=pmlibpartedbackendplugin +X-KDE-PluginInfo-Author=Volker Lanz +X-KDE-PluginInfo-Email=vl@fidra.de +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-Category=BackendPlugin +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-PluginInfo-Version=1 +X-KDE-PluginInfo-Website=http://www.partitionmanager.org diff --git a/src/plugins/pmcorebackendplugin.desktop b/src/plugins/pmcorebackendplugin.desktop new file mode 100644 index 0000000..4d1a20b --- /dev/null +++ b/src/plugins/pmcorebackendplugin.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Type=ServiceType +X-KDE-ServiceType=PartitionManager/Plugin +Name=KDE Partition Manager Plugin + diff --git a/src/util/helpers.cpp b/src/util/helpers.cpp index c084cd1..3971dc0 100644 --- a/src/util/helpers.cpp +++ b/src/util/helpers.cpp @@ -20,6 +20,8 @@ #include "util/helpers.h" #include "util/globallog.h" +#include "backend/corebackendmanager.h" + #include "ops/operation.h" #include @@ -179,3 +181,29 @@ void showColumnsContextMenu(const QPoint& p, QTreeWidget& tree) } } +bool loadBackend() +{ + if (CoreBackendManager::self()->load(Config::backend()) == false) + { + if (CoreBackendManager::self()->load(CoreBackendManager::defaultBackendName())) + { + KMessageBox::sorry(NULL, + i18nc("@info", "The configured backend plugin \"%1\" could not be loaded." + "Loading the default backend plugin \"%2\" instead.", + Config::backend(), CoreBackendManager::defaultBackendName()), + i18nc("@title:window", "Error: Could Not Load Backend Plugin")); + Config::setBackend(CoreBackendManager::defaultBackendName()); + } + else + { + KMessageBox::error(NULL, + i18nc("@info", "Neither the configured (\"%1\") nor the default (\"%2\") backend " + "plugin could be loaded.Please check your installation.", + Config::backend(), CoreBackendManager::defaultBackendName()), + i18nc("@title:window", "Error: Could Not Load Backend Plugin")); + return false; + } + } + + return true; +} diff --git a/src/util/helpers.h b/src/util/helpers.h index 51229c9..cd568ac 100644 --- a/src/util/helpers.h +++ b/src/util/helpers.h @@ -43,4 +43,6 @@ LIBPARTITIONMANAGERPRIVATE_EXPORT QIcon createFileSystemColor(FileSystem::Type t LIBPARTITIONMANAGERPRIVATE_EXPORT void showColumnsContextMenu(const QPoint& p, QTreeWidget& tree); +LIBPARTITIONMANAGERPRIVATE_EXPORT bool loadBackend(); + #endif diff --git a/src/util/report.cpp b/src/util/report.cpp index 529c829..c753263 100644 --- a/src/util/report.cpp +++ b/src/util/report.cpp @@ -20,6 +20,7 @@ #include "util/report.h" #include "backend/corebackend.h" +#include "backend/corebackendmanager.h" #include @@ -98,7 +99,7 @@ QString Report::htmlHeader() s += "\n"; s += tableLine(i18n("Date:"), KGlobal::locale()->formatDateTime(KDateTime::currentLocalDateTime())); s += tableLine(i18n("Program version:"), KGlobal::mainComponent().aboutData()->version()); - s += tableLine(i18n("Backend:"), QString("%1 (%2)").arg(CoreBackend::self()->about().programName()).arg(CoreBackend::self()->about().version())); + s += tableLine(i18n("Backend:"), QString("%1 (%2)").arg(CoreBackendManager::self()->backend()->about().programName()).arg(CoreBackendManager::self()->backend()->about().version())); s += tableLine(i18n("KDE version:"), KDE_VERSION_STRING); s += tableLine(i18n("Machine:"), unameString); s += tableLine(i18n("User ID:"), QString::number(geteuid()));