Skip to content
Snippets Groups Projects
Commit 8d6b7672 authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Start PartitionPage

parent afa1d9dc
No related branches found
No related tags found
No related merge requests found
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 )
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <DeviceModel.h>
// CalaPM
#include <core/device.h>
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 );
}
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef DEVICEMODEL_H
#define DEVICEMODEL_H
#include <QAbstractListModel>
#include <QList>
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 */
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <PartitionModel.h>
// CalaPM
#include <core/device.h>
#include <core/partition.h>
#include <core/partitiontable.h>
#include <fs/filesystem.h>
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 );
}
}
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef PARTITIONMODEL_H
#define PARTITIONMODEL_H
#include <QAbstractListModel>
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 */
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "PartitionPage.h"
// Local
#include <DeviceModel.h>
#include <PartitionModel.h>
#include <ui_PartitionPage.h>
// CalaPM
#include <CalaPM.h>
#include <backend/corebackend.h>
#include <backend/corebackendmanager.h>
// Qt
#include <QDebug>
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()
{
}
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef PARTITIONPAGE_H
#define PARTITIONPAGE_H
#include "viewpages/AbstractPage.h"
#include <QScopedPointer>
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
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PartitionPage</class>
<widget class="QWidget" name="PartitionPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>568</width>
<height>304</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>[Disk preview goes here]</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QListView" name="partitionListView"/>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="createButton">
<property name="text">
<string>Create</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteButton">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" rowspan="3">
<widget class="QListView" name="deviceListView">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "PartitionViewPlugin.h"
PartitionViewPlugin::PartitionViewPlugin( QObject* parent )
: Calamares::ViewPlugin( parent )
{
}
QString
PartitionViewPlugin::prettyName()
{
return tr( "Welcome" );
}
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef PARTITIONPAGEPLUGIN_H
#define PARTITIONPAGEPLUGIN_H
#include <QObject>
#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
#include <PartitionPage.h>
#include <QApplication>
int
main( int argc, char* argv[] )
{
QApplication app( argc, argv );
PartitionPage page;
page.show();
return app.exec();
}
# 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"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment