diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt new file mode 100644 index 000000000..69e6c62da --- /dev/null +++ b/src/modules/partition/CMakeLists.txt @@ -0,0 +1,42 @@ +add_definitions( -DCALAMARES ) + +include_directories( ${PROJECT_BINARY_DIR}/src/calamares ) +calamares_add_plugin( partition + TYPE viewmodule + EXPORT_MACRO PLUGINDLLEXPORT_PRO + CONFIG_FILE module.conf + SOURCES + DeviceModel.cpp + PartitionModel.cpp + PartitionPage.cpp + PartitionViewPlugin.cpp + UI + PartitionPage.ui + LINK_LIBRARIES + calapm + ${CALAMARES_LIBRARIES} + calamares_bin + SHARED_LIB +) + +# Temporary, until views are integrated +set( partview_SRCS + DeviceModel.cpp + PartitionModel.cpp + PartitionPage.cpp + ${calamares_SOURCE_DIR}/viewpages/AbstractPage.cpp + main.cpp +) +qt5_wrap_ui( partview_SRCS PartitionPage.ui ) + +include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) + +add_executable( partview ${partview_SRCS} ) +target_link_libraries( partview + calapm + ${CALAMARES_LIBRARIES} + Qt5::Widgets + Qt5::Gui + Qt5::Core +) +set_target_properties( partview PROPERTIES AUTOMOC TRUE ) diff --git a/src/modules/partition/DeviceModel.cpp b/src/modules/partition/DeviceModel.cpp new file mode 100644 index 000000000..ed57e1047 --- /dev/null +++ b/src/modules/partition/DeviceModel.cpp @@ -0,0 +1,78 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ +#include + +// CalaPM +#include + +DeviceModel::DeviceModel( QObject* parent ) + : QAbstractListModel( parent ) +{ +} + +void +DeviceModel::init( const QList< Device* >& devices ) +{ + beginResetModel(); + m_devices = devices; + endResetModel(); +} + +int +DeviceModel::rowCount( const QModelIndex& parent ) const +{ + return parent.isValid() ? 0 : m_devices.count(); +} + +QVariant +DeviceModel::data( const QModelIndex& index, int role ) const +{ + int row = index.row(); + if ( row < 0 || row >= m_devices.count() ) + { + return QVariant(); + } + + Device* device = m_devices.at( row ); + + switch ( role ) + { + case Qt::DisplayRole: + if ( device->name().isEmpty() ) + { + return device->deviceNode(); + } + else + { + return device->name() + " " + device->deviceNode(); + } + default: + return QVariant(); + } +} + +Device* +DeviceModel::deviceForIndex( const QModelIndex& index ) const +{ + int row = index.row(); + if ( row < 0 || row >= m_devices.count() ) + { + return nullptr; + } + return m_devices.at( row ); +} diff --git a/src/modules/partition/DeviceModel.h b/src/modules/partition/DeviceModel.h new file mode 100644 index 000000000..51fce7c5d --- /dev/null +++ b/src/modules/partition/DeviceModel.h @@ -0,0 +1,41 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ +#ifndef DEVICEMODEL_H +#define DEVICEMODEL_H + +#include +#include + +class Device; + +class DeviceModel : public QAbstractListModel +{ +public: + DeviceModel( QObject* parent = 0 ); + void init( const QList< Device* >& devices ); + + int rowCount( const QModelIndex& parent = QModelIndex() ) const Q_DECL_OVERRIDE; + QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const Q_DECL_OVERRIDE; + + Device* deviceForIndex( const QModelIndex& index ) const; + +private: + QList< Device* > m_devices; +}; + +#endif /* DEVICEMODEL_H */ diff --git a/src/modules/partition/PartitionModel.cpp b/src/modules/partition/PartitionModel.cpp new file mode 100644 index 000000000..2b75ba124 --- /dev/null +++ b/src/modules/partition/PartitionModel.cpp @@ -0,0 +1,82 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ +#include + +// CalaPM +#include +#include +#include +#include + +PartitionModel::PartitionModel( QObject* parent ) + : QAbstractListModel( parent ) +{ +} + +void +PartitionModel::init( Device* device ) +{ + beginResetModel(); + m_device = device; + m_partitionList.clear(); + if ( device ) + { + fillPartitionList( m_device->partitionTable() ); + } + endResetModel(); +} + +int +PartitionModel::rowCount( const QModelIndex& parent ) const +{ + return parent.isValid() ? 0 : m_partitionList.count(); +} + +QVariant +PartitionModel::data( const QModelIndex& index, int role ) const +{ + int row = index.row(); + if ( row < 0 || row >= m_partitionList.count() ) + { + return QVariant(); + } + + Partition* partition = m_partitionList.at( row ); + + switch ( role ) + { + case Qt::DisplayRole: + if ( partition->partitionPath().isEmpty() ) + { + return tr( "Free Space" ); + } + return partition->partitionPath() + " " + partition->fileSystem().name() + " " + partition->mountPoint(); + default: + return QVariant(); + } +} + +void +PartitionModel::fillPartitionList( PartitionNode* parent ) +{ + for ( auto partition : parent->children() ) + { + m_partitionList << partition; + fillPartitionList( partition ); + } +} diff --git a/src/modules/partition/PartitionModel.h b/src/modules/partition/PartitionModel.h new file mode 100644 index 000000000..a9bd3e403 --- /dev/null +++ b/src/modules/partition/PartitionModel.h @@ -0,0 +1,43 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ +#ifndef PARTITIONMODEL_H +#define PARTITIONMODEL_H + +#include + +class Device; +class Partition; +class PartitionNode; + +class PartitionModel : public QAbstractListModel +{ +public: + PartitionModel( QObject* parent = 0 ); + void init( Device* device ); + + int rowCount( const QModelIndex& parent = QModelIndex() ) const Q_DECL_OVERRIDE; + QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const Q_DECL_OVERRIDE; + +private: + Device* m_device; + QList< Partition* > m_partitionList; + + void fillPartitionList( PartitionNode* parent ); +}; + +#endif /* PARTITIONMODEL_H */ diff --git a/src/modules/partition/PartitionPage.cpp b/src/modules/partition/PartitionPage.cpp new file mode 100644 index 000000000..61fd54ebc --- /dev/null +++ b/src/modules/partition/PartitionPage.cpp @@ -0,0 +1,61 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#include "PartitionPage.h" + +// Local +#include +#include +#include + +// CalaPM +#include +#include +#include + +// Qt +#include + +PartitionPage::PartitionPage( QWidget* parent ) + : Calamares::AbstractPage( parent ) + , m_ui( new Ui_PartitionPage ) + , m_deviceModel( new DeviceModel( this ) ) + , m_partitionModel( new PartitionModel( this ) ) +{ + // FIXME: Should be done at startup + if ( !CalaPM::init() ) + { + qFatal( "Failed to init CalaPM" ); + } + m_backend = CoreBackendManager::self()->backend(); + m_ui->setupUi( this ); + m_ui->deviceListView->setModel( m_deviceModel ); + m_ui->partitionListView->setModel( m_partitionModel ); + + m_deviceModel->init( m_backend->scanDevices() ); + + connect( m_ui->deviceListView, &QListView::clicked, [ this ]( const QModelIndex & index ) + { + Device* device = m_deviceModel->deviceForIndex( index ); + m_partitionModel->init( device ); + } ); +} + +PartitionPage::~PartitionPage() +{ +} diff --git a/src/modules/partition/PartitionPage.h b/src/modules/partition/PartitionPage.h new file mode 100644 index 000000000..24f4d00c5 --- /dev/null +++ b/src/modules/partition/PartitionPage.h @@ -0,0 +1,50 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#ifndef PARTITIONPAGE_H +#define PARTITIONPAGE_H + +#include "viewpages/AbstractPage.h" + +#include + +class CoreBackend; +class Ui_PartitionPage; + +class DeviceModel; +class PartitionModel; + +class PartitionPage : public Calamares::AbstractPage +{ + Q_OBJECT +public: + explicit PartitionPage( QWidget* parent = 0 ); + ~PartitionPage(); + +Q_SIGNALS: + +public Q_SLOTS: + +private: + QScopedPointer< Ui_PartitionPage > m_ui; + DeviceModel* m_deviceModel; + PartitionModel* m_partitionModel; + CoreBackend* m_backend; +}; + +#endif // PARTITIONPAGE_H diff --git a/src/modules/partition/PartitionPage.ui b/src/modules/partition/PartitionPage.ui new file mode 100644 index 000000000..cc5b34fea --- /dev/null +++ b/src/modules/partition/PartitionPage.ui @@ -0,0 +1,79 @@ + + + PartitionPage + + + + 0 + 0 + 568 + 304 + + + + Form + + + + + + [Disk preview goes here] + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Create + + + + + + + Edit + + + + + + + Delete + + + + + + + + + + 0 + 0 + + + + + + + + + diff --git a/src/modules/partition/PartitionViewPlugin.cpp b/src/modules/partition/PartitionViewPlugin.cpp new file mode 100644 index 000000000..69f54d9d8 --- /dev/null +++ b/src/modules/partition/PartitionViewPlugin.cpp @@ -0,0 +1,32 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#include "PartitionViewPlugin.h" + + +PartitionViewPlugin::PartitionViewPlugin( QObject* parent ) + : Calamares::ViewPlugin( parent ) +{ +} + + +QString +PartitionViewPlugin::prettyName() +{ + return tr( "Welcome" ); +} diff --git a/src/modules/partition/PartitionViewPlugin.h b/src/modules/partition/PartitionViewPlugin.h new file mode 100644 index 000000000..fe7b2d892 --- /dev/null +++ b/src/modules/partition/PartitionViewPlugin.h @@ -0,0 +1,40 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#ifndef PARTITIONPAGEPLUGIN_H +#define PARTITIONPAGEPLUGIN_H + +#include + +#include "viewpages/ViewPlugin.h" +#include "PluginDllMacro.h" + +class PLUGINDLLEXPORT PartitionViewPlugin : public Calamares::ViewPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA( IID "calamares.ViewPlugin/1.0" ) + //FILE "module.json" ) + Q_INTERFACES( Calamares::ViewPlugin ) + +public: + explicit PartitionViewPlugin( QObject* parent = 0 ); + + QString prettyName() override; +}; + +#endif // PARTITIONPAGEPLUGIN_H diff --git a/src/modules/partition/main.cpp b/src/modules/partition/main.cpp new file mode 100644 index 000000000..c3390fc1c --- /dev/null +++ b/src/modules/partition/main.cpp @@ -0,0 +1,12 @@ +#include + +#include + +int +main( int argc, char* argv[] ) +{ + QApplication app( argc, argv ); + PartitionPage page; + page.show(); + return app.exec(); +} diff --git a/src/modules/partition/module.conf b/src/modules/partition/module.conf new file mode 100644 index 000000000..2c8dd6c6f --- /dev/null +++ b/src/modules/partition/module.conf @@ -0,0 +1,10 @@ +# Module metadata file for dummy plugin +# Syntax is YAML 1.2 +--- +type: "view" #core or view +name: "partition" #the module name. must be unique and same as the parent directory +interface: "qtplugin" #can be: qtplugin, python, process, ... +requires: [] #list of module names that must also be loaded. only applies to + #binary plugins! these are actual link-time dependencies, not + #conceptual dependencies for the setup procedure +load: "libcalamares_viewmodule_partition.so"