diff --git a/src/config/advancedpagewidget.cpp b/src/config/advancedpagewidget.cpp index 14d43bd..5002d0e 100644 --- a/src/config/advancedpagewidget.cpp +++ b/src/config/advancedpagewidget.cpp @@ -1,95 +1,98 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * Copyright (C) 2018 by Caio Carvalho * * * * 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. * * * * 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, see .* *************************************************************************/ #include "config/advancedpagewidget.h" #include #include #include #include #include #include #include AdvancedPageWidget::AdvancedPageWidget(QWidget* parent) : QWidget(parent) { setupUi(this); setupDialog(); - raidConfigFilePath->clear(); - raidConfigFilePath->insert(SoftwareRAID::raidConfigurationFilePath()); - connect(selectRaidFileButton, &QPushButton::clicked, this, &AdvancedPageWidget::searchForRaidConfigFile); } QString AdvancedPageWidget::backend() const { const auto backends = CoreBackendManager::self()->list(); for (const auto &backend : backends) if (backend.name() == comboBackend().currentText()) return backend.pluginId(); return QString(); } void AdvancedPageWidget::setBackend(const QString& name) { const auto backends = CoreBackendManager::self()->list(); for (const auto &backend : backends) if (backend.pluginId() == name) comboBackend().setCurrentIndex(comboBackend().findText(backend.name())); } void AdvancedPageWidget::setupDialog() { const auto backends = CoreBackendManager::self()->list(); for (const auto &backend : backends) comboBackend().addItem(backend.name()); setBackend(Config::backend()); + setRaidConfigurationFile(Config::raidConfigurationFilePath()); } QString AdvancedPageWidget::raidConfigurationFile() const { return raidConfigFilePath->text(); } +void AdvancedPageWidget::setRaidConfigurationFile(const QString &file) +{ + raidConfigFilePath->insert(file); +} + void AdvancedPageWidget::searchForRaidConfigFile() { QPointer dialog = new QFileDialog(this, QStringLiteral("Select Software RAID configuration file"), QStringLiteral("/")); dialog->setFileMode(QFileDialog::FileMode::ExistingFile); dialog->setNameFilter(QStringLiteral("Configuration files (*.conf)")); auto updateConfig = [this](const QString& file){ if (!file.isEmpty()) { raidConfigFilePath->clear(); raidConfigFilePath->insert(file); } }; connect(dialog, &QFileDialog::fileSelected, updateConfig); dialog->exec(); } diff --git a/src/config/advancedpagewidget.h b/src/config/advancedpagewidget.h index 9acbb78..333818b 100644 --- a/src/config/advancedpagewidget.h +++ b/src/config/advancedpagewidget.h @@ -1,59 +1,60 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * Copyright (C) 2018 by Caio Carvalho * * * * 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. * * * * 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, see .* *************************************************************************/ #if !defined(ADVANCEDPAGEWIDGET_H) #define ADVANCEDPAGEWIDGET_H #include "ui_configurepageadvanced.h" #include #include class QString; class QComboBox; class AdvancedPageWidget : public QWidget, public Ui::ConfigurePageAdvanced { public: AdvancedPageWidget(QWidget* parent); public: QComboBox& comboBackend() { return *m_ComboBackend; } const QComboBox& comboBackend() const { return *m_ComboBackend; } QString backend() const; void setBackend(const QString& name); QString raidConfigurationFile() const; + void setRaidConfigurationFile(const QString& file); protected Q_SLOTS: void searchForRaidConfigFile(); private: void setupDialog(); }; #endif diff --git a/src/config/configureoptionsdialog.cpp b/src/config/configureoptionsdialog.cpp index 2c339db..ee5f1b4 100644 --- a/src/config/configureoptionsdialog.cpp +++ b/src/config/configureoptionsdialog.cpp @@ -1,166 +1,174 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * 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. * * * * 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, see .* *************************************************************************/ #include "config/configureoptionsdialog.h" #include "config/generalpagewidget.h" #include "config/filesystemcolorspagewidget.h" #include "config/advancedpagewidget.h" #include #include #include #include #include #include "util/guihelpers.h" #include "ui_configurepagefilesystemcolors.h" #include #include #include #include #include #include #include ConfigureOptionsDialog::ConfigureOptionsDialog(QWidget* parent, const OperationStack& ostack, const QString& name) : KConfigDialog(parent, name, Config::self()), m_GeneralPageWidget(new GeneralPageWidget(this)), m_FileSystemColorsPageWidget(new FileSystemColorsPageWidget(this)), m_AdvancedPageWidget(new AdvancedPageWidget(this)), m_OperationStack(ostack) { setFaceType(List); KPageWidgetItem* item = nullptr; item = addPage(&generalPageWidget(), xi18nc("@title:tab general application settings", "General"), QString(), i18n("General Settings")); item->setIcon(QIcon::fromTheme(QStringLiteral("partitionmanager")).pixmap(IconSize(KIconLoader::Desktop))); connect(&generalPageWidget().comboDefaultFileSystem(), qOverload(&QComboBox::activated), this, &ConfigureOptionsDialog::onComboDefaultFileSystemActivated); connect(generalPageWidget().radioButton, &QRadioButton::toggled, this, &ConfigureOptionsDialog::onShredSourceActivated); item = addPage(&fileSystemColorsPageWidget(), xi18nc("@title:tab", "File System Colors"), QString(), i18n("File System Color Settings")); item->setIcon(QIcon::fromTheme(QStringLiteral("format-fill-color")).pixmap(IconSize(KIconLoader::Desktop))); item = addPage(&advancedPageWidget(), xi18nc("@title:tab advanced application settings", "Advanced"), QString(), i18n("Advanced Settings")); item->setIcon(QIcon::fromTheme(QStringLiteral("configure")).pixmap(IconSize(KIconLoader::Desktop))); connect(&advancedPageWidget().comboBackend(), qOverload(&QComboBox::activated), this, &ConfigureOptionsDialog::onComboDefaultFileSystemActivated); KConfigGroup kcg(KSharedConfig::openConfig(), "configureOptionsDialogs"); restoreGeometry(kcg.readEntry("Geometry", QByteArray())); } /** Destroys a ConfigureOptionsDialog instance */ ConfigureOptionsDialog::~ConfigureOptionsDialog() { KConfigGroup kcg(KSharedConfig::openConfig(), "configureOptionsDialog"); kcg.writeEntry("Geometry", saveGeometry()); } void ConfigureOptionsDialog::updateSettings() { KConfigDialog::updateSettings(); bool changed = false; if (generalPageWidget().defaultFileSystem() != static_cast(Config::defaultFileSystem())) { Config::setDefaultFileSystem(static_cast(generalPageWidget().defaultFileSystem())); changed = true; } if (generalPageWidget().radioButton->isChecked() != (Config::shredSource() == Config::EnumShredSource::random)) { qDebug() << "updateSettings: " << generalPageWidget().kcfg_shredSource->checkedId(); Config::setShredSource(generalPageWidget().kcfg_shredSource->checkedId()); changed = true; } if (advancedPageWidget().backend() != Config::backend()) { Config::setBackend(advancedPageWidget().backend()); changed = true; } - if (advancedPageWidget().raidConfigurationFile() != SoftwareRAID::raidConfigurationFilePath()) + if (advancedPageWidget().raidConfigurationFile() != Config::raidConfigurationFilePath()) { SoftwareRAID::setRaidConfigurationFilePath(advancedPageWidget().raidConfigurationFile()); + Config::setRaidConfigurationFilePath(advancedPageWidget().raidConfigurationFile()); + changed = true; + } if (changed) emit KConfigDialog::settingsChanged(i18n("General Settings")); } bool ConfigureOptionsDialog::hasChanged() { bool result = KConfigDialog::hasChanged(); KConfigSkeletonItem* kcItem = Config::self()->findItem(QStringLiteral("defaultFileSystem")); result = result || !kcItem->isEqual(static_cast(generalPageWidget().defaultFileSystem())); result = result || (generalPageWidget().kcfg_shredSource->checkedId() != Config::shredSource()); if (advancedPageWidget().isVisible()) { kcItem = Config::self()->findItem(QStringLiteral("backend")); result = result || !kcItem->isEqual(advancedPageWidget().backend()); + + kcItem = Config::self()->findItem(QStringLiteral("raidConfigurationFilePath")); + result = result || !kcItem->isEqual(advancedPageWidget().raidConfigurationFile()); } return result; } bool ConfigureOptionsDialog::isDefault() { bool result = KConfigDialog::isDefault(); if (result) { const bool useDefaults = Config::self()->useDefaults(true); result = !hasChanged(); Config::self()->useDefaults(useDefaults); } return result; } void ConfigureOptionsDialog::updateWidgetsDefault() { bool useDefaults = Config::self()->useDefaults(true); generalPageWidget().setDefaultFileSystem(GuiHelpers::defaultFileSystem()); generalPageWidget().radioButton->setChecked(true); - if (advancedPageWidget().isVisible()) + if (advancedPageWidget().isVisible()) { advancedPageWidget().setBackend(CoreBackendManager::defaultBackendName()); + advancedPageWidget().setRaidConfigurationFile(SoftwareRAID::getDefaultRaidConfigFile()); + } Config::self()->useDefaults(useDefaults); } void ConfigureOptionsDialog::onComboBackendActivated(int) { Q_ASSERT(advancedPageWidget().isVisible()); if (operationStack().size() == 0 || KMessageBox::warningContinueCancel(this, xi18nc("@info", "Do you really want to change the backend?" "This will also rescan devices and thus clear the list of pending operations."), xi18nc("@title:window", "Really Change Backend?"), KGuiItem(xi18nc("@action:button", "Change the Backend"), QStringLiteral("arrow-right")), KGuiItem(xi18nc("@action:button", "Do Not Change the Backend"), QStringLiteral("dialog-cancel")), QStringLiteral("reallyChangeBackend")) == KMessageBox::Continue) { settingsChangedSlot(); } else advancedPageWidget().setBackend(CoreBackendManager::defaultBackendName()); } diff --git a/src/main.cpp b/src/main.cpp index 578cef5..fe9c847 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,85 +1,87 @@ /************************************************************************* * Copyright (C) 2008,2011 by Volker Lanz * * Copyright (C) 2014-2018 by Andrius Štikonas * * * * 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. * * * * 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, see .* *************************************************************************/ #include "gui/mainwindow.h" #include #include #include #include "util/guihelpers.h" #include #include #include #include #include #include #include #include int Q_DECL_IMPORT main(int argc, char* argv[]) { QApplication app(argc, argv); KLocalizedString::setApplicationDomain("partitionmanager"); KAboutData aboutData ( QStringLiteral("partitionmanager"), xi18nc("@title", "KDE Partition Manager"), QStringLiteral(VERSION), xi18nc("@title", "Manage your disks, partitions and file systems"), KAboutLicense::GPL_V3, xi18nc("@info:credit", "© 2008-2013 Volker Lanz\n© 2012-2018 Andrius Štikonas")); aboutData.setOrganizationDomain(QByteArray("kde.org")); aboutData.setProductName(QByteArray("partitionmanager")); aboutData.addAuthor(xi18nc("@info:credit", "Volker Lanz"), xi18nc("@info:credit", "Former maintainer")); aboutData.addAuthor(xi18nc("@info:credit", "Andrius Štikonas"), xi18nc("@info:credit", "Maintainer"), QStringLiteral("andrius@stikonas.eu")); aboutData.addCredit(xi18nc("@info:credit", "Teo Mrnjavac"), i18nc("@info:credit", "Former Calamares maintainer"), QStringLiteral("teo@kde.org")); aboutData.addCredit(xi18nc("@info:credit", "Chantara Tith"), i18nc("@info:credit", "LVM support"), QStringLiteral("tith.chantara@gmail.com")); aboutData.addCredit(xi18nc("@info:credit", "Pali Rohár"), i18nc("@info:credit", "UDF support"), QStringLiteral("pali.rohar@gmail.com")); aboutData.setHomepage(QStringLiteral("https://www.kde.org/applications/system/kdepartitionmanager")); aboutData.addCredit(i18n("Hugo Pereira Da Costa"), xi18nc("@info:credit", "Partition Widget Design"), QStringLiteral("hugo@oxygen-icons.org")); KAboutData::setApplicationData(aboutData); app.setAttribute(Qt::AA_UseHighDpiPixmaps, true); KCrash::initialize(); QCommandLineParser parser; aboutData.setupCommandLine(&parser); // FIXME parser.addPositionalArgument(QStringLiteral("device"), xi18nc("@info:shell", "Device(s) to manage"), QStringLiteral("[device...]")); parser.process(app); aboutData.processCommandLine(&parser); KDBusService service(KDBusService::Unique); registerMetaTypes(); Config::instance(QStringLiteral("partitionmanagerrc")); if (!loadBackend()) return 0; + loadRaidConfiguration(); + MainWindow* mainWindow = new MainWindow(); Q_UNUSED(mainWindow) return app.exec(); } diff --git a/src/partitionmanager.kcfg b/src/partitionmanager.kcfg index 1cf4e26..2fdb5d1 100644 --- a/src/partitionmanager.kcfg +++ b/src/partitionmanager.kcfg @@ -1,158 +1,161 @@ fs/filesystem.h util/capacity.h true 0 2048 false true Unknown Extended Ext2 Ext3 Ext4 LinuxSwap Fat16 Fat32 Ntfs ReiserFS Reiser4 Xfs Jfs Hfs HfsPlus Ufs Unformatted Btrfs Hpfs Luks Ocfs2 Zfs Exfat Nilfs2 Lvm2_PV F2fs Udf Iso9660 Luks2 Fat12 LinuxRaidMember 220,205,175 187,249,207 102,121,150 122,145,180 143,170,210 155,155,130 204,179,215 229,201,240 244,214,255 216,220,135 251,255,157 200,255,254 137,200,198 210,136,142 240,165,171 151,220,134 220,205,175 173,205,255 176,155,185 170,30,77 96,140,85 33,137,108 250,230,255 242,155,104 160,210,180 255,170,0 170,120,255 177,82,69 223,39,104 204,179,255 255,100,100 true static_cast<int>(FileSystem::Type::Ext4) Capacity::Byte Capacity::KiB Capacity::MiB Capacity::GiB Capacity::TiB Capacity::PiB Capacity::EiB Capacity::MiB random + + /etc/mdadm.conf + diff --git a/src/util/guihelpers.cpp b/src/util/guihelpers.cpp index 49a537a..141b913 100644 --- a/src/util/guihelpers.cpp +++ b/src/util/guihelpers.cpp @@ -1,130 +1,137 @@ /************************************************************************* * Copyright (C) 2008-2010 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * 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. * * * * 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, see .* *************************************************************************/ #include "util/guihelpers.h" #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include + QIcon createFileSystemColor(FileSystem::Type type, quint32 size) { QPixmap pixmap(size, size); QPainter painter(&pixmap); painter.setPen(QColor(0, 0, 0)); painter.setBrush(Config::fileSystemColorCode(static_cast(type))); painter.drawRect(QRect(0, 0, pixmap.width() - 1, pixmap.height() - 1)); painter.end(); return QIcon(pixmap); } bool loadBackend() { if (CoreBackendManager::self()->load(Config::backend()) == false) { if (CoreBackendManager::self()->load(CoreBackendManager::defaultBackendName())) { if (!Config::firstRun()) KMessageBox::sorry(nullptr, xi18nc("@info", "The configured backend plugin \"%1\" could not be loaded." "Loading the default backend plugin \"%2\" instead.", Config::backend(), CoreBackendManager::defaultBackendName()), xi18nc("@title:window", "Error: Could Not Load Backend Plugin")); Config::setBackend(CoreBackendManager::defaultBackendName()); } else { KMessageBox::error(nullptr, xi18nc("@info", "Neither the configured (\"%1\") nor the default (\"%2\") backend " "plugin could be loaded.Please check your installation.", Config::backend(), CoreBackendManager::defaultBackendName()), xi18nc("@title:window", "Error: Could Not Load Backend Plugin")); return false; } } return true; } +void loadRaidConfiguration() +{ + SoftwareRAID::setRaidConfigurationFilePath(Config::raidConfigurationFilePath()); +} + Capacity::Unit preferredUnit() { return static_cast(Config::preferredUnit()); } void showColumnsContextMenu(const QPoint& p, QTreeWidget& tree) { QMenu headerMenu(xi18nc("@title:menu", "Columns")); QHeaderView* header = tree.header(); for (qint32 i = 0; i < tree.model()->columnCount(); i++) { const int idx = header->logicalIndex(i); const QString text = tree.model()->headerData(idx, Qt::Horizontal).toString(); QAction* action = headerMenu.addAction(text); action->setCheckable(true); action->setChecked(!header->isSectionHidden(idx)); action->setData(idx); action->setEnabled(idx > 0); } QAction* action = headerMenu.exec(tree.header()->mapToGlobal(p)); if (action != nullptr) { const bool hidden = !action->isChecked(); tree.setColumnHidden(action->data().toInt(), hidden); if (!hidden) tree.resizeColumnToContents(action->data().toInt()); } } namespace GuiHelpers { FileSystem::Type defaultFileSystem() { return static_cast(Config::defaultFileSystem()); } std::vector fileSystemColorCodesFromSettings() { std::vector cc; cc.resize(Config::EnumFileSystem::type::COUNT); for (int i = 0; i < Config::EnumFileSystem::type::COUNT; ++i) { cc[i] = Config::fileSystemColorCode(i); } return cc; } } diff --git a/src/util/guihelpers.h b/src/util/guihelpers.h index 5313045..989b85f 100644 --- a/src/util/guihelpers.h +++ b/src/util/guihelpers.h @@ -1,42 +1,43 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * 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. * * * * 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, see .* *************************************************************************/ #ifndef GUIHELPERS_H #define GUIHELPERS_H #include #include #include class QIcon; class QPoint; class QString; class QTreeWidget; bool loadBackend(); +void loadRaidConfiguration(); QIcon createFileSystemColor(FileSystem::Type type, quint32 size); Capacity::Unit preferredUnit(); void showColumnsContextMenu(const QPoint& p, QTreeWidget& tree); namespace GuiHelpers { FileSystem::Type defaultFileSystem(); std::vector fileSystemColorCodesFromSettings(); } #endif