diff --git a/src/backend/corebackend.h b/src/backend/corebackend.h index 6a61b34..386d67f 100644 --- a/src/backend/corebackend.h +++ b/src/backend/corebackend.h @@ -1,179 +1,179 @@ /************************************************************************* * 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 .* *************************************************************************/ #if !defined(KPMCORE_COREBACKEND_H) #define KPMCORE_COREBACKEND_H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" #include #include #include class CoreBackendManager; class CoreBackendDevice; -class CoreBackendPrivate; +struct CoreBackendPrivate; class Device; class PartitionTable; class QString; /** * Interface class for backend plugins. * @author Volker Lanz */ class LIBKPMCORE_EXPORT CoreBackend : public QObject { Q_OBJECT Q_DISABLE_COPY(CoreBackend) friend class CoreBackendManager; protected: CoreBackend(); virtual ~CoreBackend(); Q_SIGNALS: /** * Emitted to inform about progress of any kind. * @param i the progress in percent (from 0 to 100) */ void progress(int i); /** * Emitted to inform about scan progress. * @param deviceNode the device being scanned just now (e.g. "/dev/sda") * @param i the progress in percent (from 0 to 100) */ void scanProgress(const QString& deviceNode, int i); public: /** * Return the plugin's unique Id from JSON metadata * @return the plugin's unique Id from JSON metadata */ QString id(); /** * Return the plugin's version from JSON metadata * @return the plugin's version from JSON metadata */ QString version(); /** * Initialize the plugin's FileSystem support */ virtual void initFSSupport() = 0; /** * Scan for devices in the system. * @param excludeReadOnly when true, devices that are read-only * according to the kernel are left out of the list. * When false (the default) all devices, writable or * not, including CD ROM devices, are returned. * @return a QList of pointers to Device instances. The caller is responsible * for deleting these objects. * @note A Device object is a description of the device, not * an object to operate on. See openDevice(). */ virtual QList scanDevices(bool excludeReadOnly = false) = 0; /** * Scan a single device in the system. * @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda1) * @return FileSystem type of the device on deviceNode */ virtual FileSystem::Type detectFileSystem(const QString& deviceNode) = 0; /** * Read a file system label * @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda1) * @return FileSystem label on deviceNode */ virtual QString readLabel(const QString& deviceNode) const = 0; /** * Read a file system UUID * @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda1) * @return FileSystem UUID on deviceNode */ virtual QString readUUID(const QString& deviceNode) const = 0; /** * Scan a single device in the system. * @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda) * @return a pointer to a Device instance. The caller is responsible for deleting * this object. */ virtual Device* scanDevice(const QString& deviceNode) = 0; /** * Open a device for reading. * @param deviceNode The path of the device that is to be opened (e.g. /dev/sda) * @return a pointer to a CoreBackendDevice or nullptr if the open failed. */ virtual std::unique_ptr openDevice(const Device& d) = 0; /** * Open a device in exclusive mode for writing. * @param deviceNode The path of the device that is to be opened (e.g. /dev/sda) * @return a pointer to a CoreBackendDevice or nullptr if the open failed. */ virtual std::unique_ptr openDeviceExclusive(const Device& d) = 0; /** * Close a CoreBackendDevice that has previously been opened. * @param core_device Pointer to the CoreBackendDevice to be closed. Must not be nullptr. * @return true if closing the CoreBackendDevice succeeded, otherwise false. */ virtual bool closeDevice(std::unique_ptr coreDevice) = 0; /** * Emit progress. * @param i the progress in percent (from 0 to 100) * This is used to emit a progress() signal from somewhere deep inside the plugin * backend code if that is ever necessary. */ virtual void emitProgress(int i); /** * Emit scan progress. * @param deviceNode the path to the device just being scanned (e.g. /dev/sda) * @param i the progress in percent (from 0 to 100) * This is used to emit a scanProgress() signal from the backend device scanning * code. */ virtual void emitScanProgress(const QString& deviceNode, int i); protected: static void setPartitionTableForDevice(Device& d, PartitionTable* p); static void setPartitionTableMaxPrimaries(PartitionTable& p, qint32 max_primaries); private: void setId(const QString& id); void setVersion(const QString& version); private: std::unique_ptr d; }; #endif diff --git a/src/gui/partwidget.cpp b/src/gui/partwidget.cpp index d728c23..57ebf23 100644 --- a/src/gui/partwidget.cpp +++ b/src/gui/partwidget.cpp @@ -1,152 +1,152 @@ /************************************************************************* * Copyright (C) 2008, 2010 by Volker Lanz * * * * 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/partwidget.h" #include "core/partition.h" #include "fs/filesystem.h" #include "util/capacity.h" -#include -#include #include #include +#include +#include /** Creates a new PartWidget @param parent pointer to the parent widget @param p pointer to the Partition this widget will show. must not be nullptr. */ PartWidget::PartWidget(QWidget* parent, Partition* p) : PartWidgetBase(parent), m_Partition(nullptr), m_Active(false) { setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); init(p); m_fileSystemColorCode = FileSystem::defaultColorCode; } void PartWidget::init(Partition* p) { m_Partition = p; if (partition()) setToolTip(partition()->deviceNode() + QStringLiteral("\n") + partition()->fileSystem().name() + QStringLiteral(" ") + QString(Capacity::formatByteSize(partition()->capacity()))); else setToolTip(QString()); updateChildren(); } /** Updates the widget's children */ void PartWidget::updateChildren() { if (partition()) { for (const auto &w : childWidgets()) { w->setVisible(false); w->deleteLater(); w->setParent(nullptr); } for (const auto &child : partition()->children()) { QWidget* w = new PartWidget(this, child); w->setVisible(true); } positionChildren(this, partition()->children(), childWidgets()); } } void PartWidget::setFileSystemColorCode(const std::vector& colorCode) { m_fileSystemColorCode = colorCode; repaint(); } void PartWidget::resizeEvent(QResizeEvent*) { if (partition()) positionChildren(this, partition()->children(), childWidgets()); } QColor PartWidget::activeColor(const QColor& col) const { return isActive() ? col.darker(190) : col; } void PartWidget::paintEvent(QPaintEvent*) { if (partition() == nullptr) return; const int usedPercentage = static_cast(partition()->used() * 100 / partition()->capacity()); const int w = width() * usedPercentage / 100; QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing); if (partition()->roles().has(PartitionRole::Extended)) { drawGradient(&painter, activeColor( m_fileSystemColorCode[ static_cast(partition()->fileSystem().type()) ]), QRect(0, 0, width(), height())); return; } const QColor base = activeColor(m_fileSystemColorCode[ static_cast(partition()->fileSystem().type()) ]); if (!partition()->roles().has(PartitionRole::Unallocated)) { const QColor dark = base.darker(105); const QColor light = base.lighter(120); // draw free space background drawGradient(&painter, light, QRect(0, 0, width(), height()), isActive()); // draw used space in front of that drawGradient(&painter, dark, QRect(0, 0, w, height() - 1)); } else drawGradient(&painter, base, QRect(0, 0, width(), height()), isActive()); // draw name and size QString text = partition()->deviceNode().remove(QStringLiteral("/dev/")) + QStringLiteral("\n") + QString(Capacity::formatByteSize(partition()->capacity())); const QRect textRect(0, 0, width() - 1, height() - 1); const QRect boundingRect = painter.boundingRect(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text); if (boundingRect.x() > PartWidgetBase::borderWidth() && boundingRect.y() > PartWidgetBase::borderHeight()) { if (isActive()) painter.setPen(QColor(255, 255, 255)); painter.drawText(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text); } } void PartWidget::drawGradient(QPainter* painter, const QColor& color, const QRect& rect, bool active) const { if (rect.width() < 8) return; QStyleOptionButton option; option.initFrom(this); option.rect = rect; option.palette.setColor(QPalette::Button, color); option.palette.setColor(QPalette::Window, color); option.state |= QStyle::State_Raised; if (!active) option.state &= ~QStyle::State_MouseOver; else option.state |= QStyle::State_MouseOver; style()->drawControl(QStyle::CE_PushButtonBevel, &option, painter, this); } diff --git a/src/util/helpers.cpp b/src/util/helpers.cpp index 6f1e3fb..6f2cfc9 100644 --- a/src/util/helpers.cpp +++ b/src/util/helpers.cpp @@ -1,73 +1,73 @@ /************************************************************************* * Copyright (C) 2008, 2009, 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/helpers.h" #include "util/externalcommand.h" #include "util/globallog.h" #include "ops/operation.h" #include #include void registerMetaTypes() { qRegisterMetaType("Operation*"); qRegisterMetaType("Log::Level"); } bool caseInsensitiveLessThan(const QString& s1, const QString& s2) { return s1.toLower() < s2.toLower(); } bool isMounted(const QString& deviceNode) { ExternalCommand cmd(QStringLiteral("lsblk"), { QStringLiteral("--noheadings"), QStringLiteral("--nodeps"), QStringLiteral("--output"), QStringLiteral("mountpoint"), deviceNode }); if (cmd.run(-1) && cmd.exitCode() == 0) { return !cmd.output().trimmed().isEmpty(); } return false; } KAboutData aboutKPMcore() { KAboutData aboutData( QStringLiteral("kpmcore"), xi18nc("@title", "KPMcore"), QStringLiteral(VERSION), xi18nc("@title", "Library for managing partitions"), - KAboutLicense::GPL_V3, xi18nc("@info:credit", "© 2008-2017 KPMcore developers" ) ); + KAboutLicense::GPL_V3, xi18nc("@info:credit", "© 2008-2018 KPMcore developers" ) ); aboutData.setOrganizationDomain(QByteArray("kde.org")); aboutData.setProductName(QByteArray("kpmcore")); aboutData.setHomepage(QStringLiteral("https://commits.kde.org/kpmcore")); 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.addCredit(xi18nc("@info:credit", "Adriaan de Groot"), i18nc("@info:credit", "Calamares maintainer"), QStringLiteral("groot@kde.org")); aboutData.addCredit(xi18nc("@info:credit", "Caio Carvalho"), i18nc("@info:credit", "Improved SMART support"), QStringLiteral("caiojcarvalho@gmail.com")); return aboutData; }