[officechooser] initial commit
This commit is contained in:
parent
92d256ae06
commit
5cabeee80d
30
src/modules/officechooser/CMakeLists.txt
Normal file
30
src/modules/officechooser/CMakeLists.txt
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
find_package( Qt5 COMPONENTS Core Gui Widgets REQUIRED )
|
||||||
|
|
||||||
|
calamares_add_plugin( officechooser
|
||||||
|
TYPE viewmodule
|
||||||
|
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||||
|
SOURCES
|
||||||
|
PackageChooserPage.cpp
|
||||||
|
PackageChooserViewStep.cpp
|
||||||
|
PackageModel.cpp
|
||||||
|
RESOURCES
|
||||||
|
packagechooser.qrc
|
||||||
|
UI
|
||||||
|
page_package.ui
|
||||||
|
LINK_PRIVATE_LIBRARIES
|
||||||
|
calamaresui
|
||||||
|
SHARED_LIB
|
||||||
|
)
|
||||||
|
|
||||||
|
if( ECM_FOUND AND BUILD_TESTING )
|
||||||
|
ecm_add_test(
|
||||||
|
Tests.cpp
|
||||||
|
TEST_NAME
|
||||||
|
packagechooosertest
|
||||||
|
LINK_LIBRARIES
|
||||||
|
${CALAMARES_LIBRARIES}
|
||||||
|
Qt5::Core
|
||||||
|
Qt5::Test
|
||||||
|
)
|
||||||
|
calamares_automoc( packagechooosertest)
|
||||||
|
endif()
|
101
src/modules/officechooser/PackageChooserPage.cpp
Normal file
101
src/modules/officechooser/PackageChooserPage.cpp
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
* Copyright 2019, Philip Müller <philm@manjaro.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 "PackageChooserPage.h"
|
||||||
|
|
||||||
|
#include "ui_page_package.h"
|
||||||
|
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/Retranslator.h"
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
PackageChooserPage::PackageChooserPage( PackageChooserMode mode, QWidget* parent )
|
||||||
|
: QWidget( parent )
|
||||||
|
, ui( new Ui::PackageChooserPage )
|
||||||
|
, m_introduction( QString(),
|
||||||
|
QString(),
|
||||||
|
tr( "Office Selection" ),
|
||||||
|
tr( "Please pick a office suite from the list. The selected product will be installed." ) )
|
||||||
|
{
|
||||||
|
m_introduction.screenshot = QPixmap( QStringLiteral( ":/images/choose-office.jpg" ) );
|
||||||
|
cDebug() << m_introduction.screenshot;
|
||||||
|
|
||||||
|
ui->setupUi( this );
|
||||||
|
CALAMARES_RETRANSLATE( updateLabels(); )
|
||||||
|
|
||||||
|
switch ( mode )
|
||||||
|
{
|
||||||
|
case PackageChooserMode::Optional:
|
||||||
|
case PackageChooserMode::Exclusive:
|
||||||
|
ui->products->setSelectionMode( QAbstractItemView::SingleSelection );
|
||||||
|
case PackageChooserMode::Multiple:
|
||||||
|
case PackageChooserMode::RequiredMultiple:
|
||||||
|
ui->products->setSelectionMode( QAbstractItemView::ExtendedSelection );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageChooserPage::currentChanged( const QModelIndex& index )
|
||||||
|
{
|
||||||
|
if ( !index.isValid() || !ui->products->selectionModel()->hasSelection() )
|
||||||
|
{
|
||||||
|
ui->productName->setText( m_introduction.name );
|
||||||
|
ui->productScreenshot->setPixmap( m_introduction.screenshot );
|
||||||
|
ui->productDescription->setText( m_introduction.description );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto* model = ui->products->model();
|
||||||
|
|
||||||
|
ui->productName->setText( model->data( index, PackageListModel::NameRole ).toString() );
|
||||||
|
ui->productScreenshot->setPixmap( model->data( index, PackageListModel::ScreenshotRole ).value< QPixmap >() );
|
||||||
|
ui->productDescription->setText( model->data( index, PackageListModel::DescriptionRole ).toString() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageChooserPage::updateLabels()
|
||||||
|
{
|
||||||
|
if ( ui && ui->products && ui->products->selectionModel() )
|
||||||
|
{
|
||||||
|
currentChanged( ui->products->selectionModel()->currentIndex() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentChanged( QModelIndex() );
|
||||||
|
}
|
||||||
|
emit selectionChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageChooserPage::setModel( QAbstractItemModel* model )
|
||||||
|
{
|
||||||
|
ui->products->setModel( model );
|
||||||
|
connect( ui->products->selectionModel(),
|
||||||
|
&QItemSelectionModel::selectionChanged,
|
||||||
|
this,
|
||||||
|
&PackageChooserPage::updateLabels );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PackageChooserPage::hasSelection() const
|
||||||
|
{
|
||||||
|
return ui && ui->products && ui->products->selectionModel() && ui->products->selectionModel()->hasSelection();
|
||||||
|
}
|
54
src/modules/officechooser/PackageChooserPage.h
Normal file
54
src/modules/officechooser/PackageChooserPage.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@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 PACKAGECHOOSERPAGE_H
|
||||||
|
#define PACKAGECHOOSERPAGE_H
|
||||||
|
|
||||||
|
#include "PackageModel.h"
|
||||||
|
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class PackageChooserPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
class PackageChooserPage : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit PackageChooserPage( PackageChooserMode mode, QWidget* parent = nullptr );
|
||||||
|
|
||||||
|
void setModel( QAbstractItemModel* model );
|
||||||
|
|
||||||
|
bool hasSelection() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void currentChanged( const QModelIndex& index );
|
||||||
|
void updateLabels();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void selectionChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::PackageChooserPage* ui;
|
||||||
|
PackageItem m_introduction;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PACKAGECHOOSERPAGE_H
|
181
src/modules/officechooser/PackageChooserViewStep.cpp
Normal file
181
src/modules/officechooser/PackageChooserViewStep.cpp
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
* Copyright 2019, Philip Müller <philm@manjaro.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 "PackageChooserViewStep.h"
|
||||||
|
|
||||||
|
#include "PackageChooserPage.h"
|
||||||
|
#include "PackageModel.h"
|
||||||
|
|
||||||
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
|
||||||
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/Variant.h"
|
||||||
|
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <QVariantMap>
|
||||||
|
|
||||||
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( PackageChooserViewStepFactory, registerPlugin< PackageChooserViewStep >(); )
|
||||||
|
|
||||||
|
PackageChooserViewStep::PackageChooserViewStep( QObject* parent )
|
||||||
|
: Calamares::ViewStep( parent )
|
||||||
|
, m_widget( nullptr )
|
||||||
|
, m_model( nullptr )
|
||||||
|
, m_mode( PackageChooserMode::Exclusive )
|
||||||
|
{
|
||||||
|
emit nextStatusChanged( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PackageChooserViewStep::~PackageChooserViewStep()
|
||||||
|
{
|
||||||
|
if ( m_widget && m_widget->parent() == nullptr )
|
||||||
|
{
|
||||||
|
m_widget->deleteLater();
|
||||||
|
}
|
||||||
|
delete m_model;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString
|
||||||
|
PackageChooserViewStep::prettyName() const
|
||||||
|
{
|
||||||
|
return tr( "Office Suite" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QWidget*
|
||||||
|
PackageChooserViewStep::widget()
|
||||||
|
{
|
||||||
|
if ( !m_widget )
|
||||||
|
{
|
||||||
|
m_widget = new PackageChooserPage( m_mode, nullptr );
|
||||||
|
connect( m_widget, &PackageChooserPage::selectionChanged, [=]() {
|
||||||
|
emit nextStatusChanged( this->isNextEnabled() );
|
||||||
|
} );
|
||||||
|
|
||||||
|
if ( m_model )
|
||||||
|
{
|
||||||
|
hookupModel();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cWarning() << "PackageChooser Widget created before model.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m_widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
PackageChooserViewStep::isNextEnabled() const
|
||||||
|
{
|
||||||
|
if ( !m_model )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !m_widget )
|
||||||
|
{
|
||||||
|
// No way to have changed anything
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ( m_mode )
|
||||||
|
{
|
||||||
|
case PackageChooserMode::Optional:
|
||||||
|
case PackageChooserMode::Multiple:
|
||||||
|
// zero or one OR zero or more
|
||||||
|
return true;
|
||||||
|
case PackageChooserMode::Exclusive:
|
||||||
|
case PackageChooserMode::RequiredMultiple:
|
||||||
|
// exactly one OR one or more
|
||||||
|
return m_widget->hasSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
NOTREACHED return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
PackageChooserViewStep::isBackEnabled() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
PackageChooserViewStep::isAtBeginning() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
PackageChooserViewStep::isAtEnd() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageChooserViewStep::onLeave()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Calamares::JobList
|
||||||
|
PackageChooserViewStep::jobs() const
|
||||||
|
{
|
||||||
|
Calamares::JobList l;
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
|
{
|
||||||
|
// TODO: use the configurationMap
|
||||||
|
|
||||||
|
if ( !m_model )
|
||||||
|
{
|
||||||
|
|
||||||
|
m_model = new PackageListModel( nullptr );
|
||||||
|
m_model->addPackage( PackageItem { "libreoffice-still", "libreoffice-still", "LibreOffice", "LibreOffice is a powerful and free office suite, used by millions of people around the world.", ":/images/LibreOffice.jpg" } );
|
||||||
|
m_model->addPackage(
|
||||||
|
PackageItem { "freeoffice", "freeoffice", "FreeOffice", "FreeOffice is a complete Office suite with a word processor, a spreadsheet application and a presentation program – all compatible with their counterparts in Microsoft Office.", ":/images/FreeOffice.jpg" } );
|
||||||
|
|
||||||
|
|
||||||
|
if ( m_widget )
|
||||||
|
{
|
||||||
|
hookupModel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageChooserViewStep::hookupModel()
|
||||||
|
{
|
||||||
|
if ( !m_model || !m_widget )
|
||||||
|
{
|
||||||
|
cError() << "Can't hook up model until widget and model both exist.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_widget->setModel( m_model );
|
||||||
|
}
|
69
src/modules/officechooser/PackageChooserViewStep.h
Normal file
69
src/modules/officechooser/PackageChooserViewStep.h
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@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 PACKAGECHOOSERVIEWSTEP_H
|
||||||
|
#define PACKAGECHOOSERVIEWSTEP_H
|
||||||
|
|
||||||
|
#include "PluginDllMacro.h"
|
||||||
|
#include "utils/PluginFactory.h"
|
||||||
|
#include "viewpages/ViewStep.h"
|
||||||
|
|
||||||
|
#include "PackageModel.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUrl>
|
||||||
|
#include <QVariantMap>
|
||||||
|
|
||||||
|
class PackageChooserPage;
|
||||||
|
class PackageListModel;
|
||||||
|
|
||||||
|
class PLUGINDLLEXPORT PackageChooserViewStep : public Calamares::ViewStep
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit PackageChooserViewStep( QObject* parent = nullptr );
|
||||||
|
virtual ~PackageChooserViewStep() override;
|
||||||
|
|
||||||
|
QString prettyName() const override;
|
||||||
|
|
||||||
|
QWidget* widget() override;
|
||||||
|
|
||||||
|
bool isNextEnabled() const override;
|
||||||
|
bool isBackEnabled() const override;
|
||||||
|
|
||||||
|
bool isAtBeginning() const override;
|
||||||
|
bool isAtEnd() const override;
|
||||||
|
|
||||||
|
void onLeave() override;
|
||||||
|
|
||||||
|
Calamares::JobList jobs() const override;
|
||||||
|
|
||||||
|
void setConfigurationMap( const QVariantMap& configurationMap ) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void hookupModel();
|
||||||
|
|
||||||
|
PackageChooserPage* m_widget;
|
||||||
|
PackageListModel* m_model;
|
||||||
|
PackageChooserMode m_mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
CALAMARES_PLUGIN_FACTORY_DECLARATION( PackageChooserViewStepFactory )
|
||||||
|
|
||||||
|
#endif // PACKAGECHOOSERVIEWSTEP_H
|
113
src/modules/officechooser/PackageModel.cpp
Normal file
113
src/modules/officechooser/PackageModel.cpp
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@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 "PackageModel.h"
|
||||||
|
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
PackageItem
|
||||||
|
PackageItem::fromAppStream( const QString& filename )
|
||||||
|
{
|
||||||
|
// TODO: implement this
|
||||||
|
return PackageItem {};
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageItem::PackageItem() {}
|
||||||
|
|
||||||
|
PackageItem::PackageItem( const QString& a_id,
|
||||||
|
const QString& a_package,
|
||||||
|
const QString& a_name,
|
||||||
|
const QString& a_description )
|
||||||
|
: id( a_id )
|
||||||
|
, package( a_package )
|
||||||
|
, name( a_name )
|
||||||
|
, description( a_description )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageItem::PackageItem( const QString& a_id,
|
||||||
|
const QString& a_package,
|
||||||
|
const QString& a_name,
|
||||||
|
const QString& a_description,
|
||||||
|
const QString& screenshotPath )
|
||||||
|
: id( a_id )
|
||||||
|
, package( a_package )
|
||||||
|
, name( a_name )
|
||||||
|
, description( a_description )
|
||||||
|
, screenshot( screenshotPath )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PackageListModel::PackageListModel( QObject* parent )
|
||||||
|
: QAbstractListModel( parent )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageListModel::PackageListModel( PackageList&& items, QObject* parent )
|
||||||
|
: QAbstractListModel( parent )
|
||||||
|
, m_packages( std::move( items ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageListModel::~PackageListModel() {}
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageListModel::addPackage( PackageItem&& p )
|
||||||
|
{
|
||||||
|
int c = m_packages.count();
|
||||||
|
beginInsertRows( QModelIndex(), c, c );
|
||||||
|
m_packages.append( p );
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
PackageListModel::rowCount( const QModelIndex& index ) const
|
||||||
|
{
|
||||||
|
// For lists, valid indexes have zero children; only the root index has them
|
||||||
|
return index.isValid() ? 0 : m_packages.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
PackageListModel::data( const QModelIndex& index, int role ) const
|
||||||
|
{
|
||||||
|
if ( !index.isValid() )
|
||||||
|
{
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
int row = index.row();
|
||||||
|
if ( row >= m_packages.count() || row < 0 )
|
||||||
|
{
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( role == Qt::DisplayRole /* Also PackageNameRole */ )
|
||||||
|
{
|
||||||
|
return m_packages[ row ].name;
|
||||||
|
}
|
||||||
|
else if ( role == DescriptionRole )
|
||||||
|
{
|
||||||
|
return m_packages[ row ].description;
|
||||||
|
}
|
||||||
|
else if ( role == ScreenshotRole )
|
||||||
|
{
|
||||||
|
return m_packages[ row ].screenshot;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
90
src/modules/officechooser/PackageModel.h
Normal file
90
src/modules/officechooser/PackageModel.h
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@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 PACKAGEMODEL_H
|
||||||
|
#define PACKAGEMODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
enum class PackageChooserMode
|
||||||
|
{
|
||||||
|
Optional, // zero or one
|
||||||
|
Exclusive, // exactly one
|
||||||
|
Multiple, // zero or more
|
||||||
|
RequiredMultiple // one or more
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PackageItem
|
||||||
|
{
|
||||||
|
QString id;
|
||||||
|
// TODO: may need more than one
|
||||||
|
QString package;
|
||||||
|
// TODO: name and description are localized
|
||||||
|
QString name;
|
||||||
|
QString description;
|
||||||
|
// TODO: may be more than one
|
||||||
|
QPixmap screenshot;
|
||||||
|
|
||||||
|
/// @brief Create blank PackageItem
|
||||||
|
PackageItem();
|
||||||
|
/** @brief Creates a PackageItem from given strings
|
||||||
|
*
|
||||||
|
* This constructor sets all the text members,
|
||||||
|
* but leaves the screenshot blank. Set that separately.
|
||||||
|
*/
|
||||||
|
PackageItem( const QString& id, const QString& package, const QString& name, const QString& description );
|
||||||
|
|
||||||
|
PackageItem( const QString& id,
|
||||||
|
const QString& package,
|
||||||
|
const QString& name,
|
||||||
|
const QString& description,
|
||||||
|
const QString& screenshotPath );
|
||||||
|
|
||||||
|
// TODO: implement this
|
||||||
|
PackageItem fromAppStream( const QString& filename );
|
||||||
|
};
|
||||||
|
|
||||||
|
using PackageList = QVector< PackageItem >;
|
||||||
|
|
||||||
|
class PackageListModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PackageListModel( PackageList&& items, QObject* parent );
|
||||||
|
PackageListModel( QObject* parent );
|
||||||
|
virtual ~PackageListModel();
|
||||||
|
|
||||||
|
void addPackage( PackageItem&& p );
|
||||||
|
|
||||||
|
int rowCount( const QModelIndex& index ) const override;
|
||||||
|
QVariant data( const QModelIndex& index, int role ) const override;
|
||||||
|
|
||||||
|
enum Roles : int
|
||||||
|
{
|
||||||
|
NameRole = Qt::DisplayRole,
|
||||||
|
DescriptionRole = Qt::UserRole,
|
||||||
|
ScreenshotRole
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
PackageList m_packages;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
38
src/modules/officechooser/Tests.cpp
Normal file
38
src/modules/officechooser/Tests.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@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 "Tests.h"
|
||||||
|
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
|
QTEST_GUILESS_MAIN( PackageChooserTests )
|
||||||
|
|
||||||
|
PackageChooserTests::PackageChooserTests() {}
|
||||||
|
|
||||||
|
PackageChooserTests::~PackageChooserTests() {}
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageChooserTests::initTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageChooserTests::testBogus()
|
||||||
|
{
|
||||||
|
QVERIFY( true );
|
||||||
|
}
|
36
src/modules/officechooser/Tests.h
Normal file
36
src/modules/officechooser/Tests.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@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 PACKAGECHOOSERTESTS_H
|
||||||
|
#define PACKAGECHOOSERTESTS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class PackageChooserTests : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
PackageChooserTests();
|
||||||
|
~PackageChooserTests() override;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void initTestCase();
|
||||||
|
void testBogus();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
BIN
src/modules/officechooser/images/FreeOffice.jpg
Normal file
BIN
src/modules/officechooser/images/FreeOffice.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
BIN
src/modules/officechooser/images/LibreOffice.jpg
Normal file
BIN
src/modules/officechooser/images/LibreOffice.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 46 KiB |
BIN
src/modules/officechooser/images/choose-office.jpg
Normal file
BIN
src/modules/officechooser/images/choose-office.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
7
src/modules/officechooser/packagechooser.qrc
Normal file
7
src/modules/officechooser/packagechooser.qrc
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>images/choose-office.jpg</file>
|
||||||
|
<file>images/LibreOffice.jpg</file>
|
||||||
|
<file>images/FreeOffice.jpg</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
66
src/modules/officechooser/page_package.ui
Normal file
66
src/modules/officechooser/page_package.ui
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>PackageChooserPage</class>
|
||||||
|
<widget class="QWidget" name="PackageChooserPage">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>500</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>1</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,2">
|
||||||
|
<item>
|
||||||
|
<widget class="QListView" name="products">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>1</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,3,1">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="productName">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="productScreenshot">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="productDescription">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user