Merge pull request #207 from calamares/debugwindow
New debug window for Calamares testing, adaptation and deployment
This commit is contained in:
commit
a25c0cf490
@ -23,6 +23,9 @@
|
|||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
#include "utils/CalamaresStyle.h"
|
#include "utils/CalamaresStyle.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/DebugWindow.h"
|
||||||
|
#include "utils/Retranslator.h"
|
||||||
|
#include "Settings.h"
|
||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@ -33,6 +36,7 @@
|
|||||||
|
|
||||||
CalamaresWindow::CalamaresWindow( QWidget* parent )
|
CalamaresWindow::CalamaresWindow( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
|
, m_debugWindow( nullptr )
|
||||||
{
|
{
|
||||||
// Hide close button
|
// Hide close button
|
||||||
setWindowFlags( Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint );
|
setWindowFlags( Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint );
|
||||||
@ -83,6 +87,40 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
|
|||||||
ProgressTreeView* tv = new ProgressTreeView( sideBox );
|
ProgressTreeView* tv = new ProgressTreeView( sideBox );
|
||||||
sideLayout->addWidget( tv );
|
sideLayout->addWidget( tv );
|
||||||
tv->setFocusPolicy( Qt::NoFocus );
|
tv->setFocusPolicy( Qt::NoFocus );
|
||||||
|
|
||||||
|
if ( Calamares::Settings::instance()->debugMode() )
|
||||||
|
{
|
||||||
|
QPushButton* debugWindowBtn = new QPushButton;
|
||||||
|
CALAMARES_RETRANSLATE(
|
||||||
|
debugWindowBtn->setText( tr( "Show debug information" ) );
|
||||||
|
)
|
||||||
|
sideLayout->addWidget( debugWindowBtn );
|
||||||
|
debugWindowBtn->setFlat( true );
|
||||||
|
debugWindowBtn->setCheckable( true );
|
||||||
|
connect( debugWindowBtn, &QPushButton::clicked,
|
||||||
|
[ this, debugWindowBtn ]( bool checked )
|
||||||
|
{
|
||||||
|
if ( checked )
|
||||||
|
{
|
||||||
|
m_debugWindow = new Calamares::DebugWindow();
|
||||||
|
m_debugWindow->show();
|
||||||
|
connect( m_debugWindow, &Calamares::DebugWindow::closed,
|
||||||
|
[ this, debugWindowBtn ]
|
||||||
|
{
|
||||||
|
m_debugWindow->deleteLater();
|
||||||
|
debugWindowBtn->setChecked( false );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( m_debugWindow )
|
||||||
|
{
|
||||||
|
m_debugWindow->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
CalamaresUtils::unmarginLayout( sideLayout );
|
CalamaresUtils::unmarginLayout( sideLayout );
|
||||||
CalamaresUtils::unmarginLayout( mainLayout );
|
CalamaresUtils::unmarginLayout( mainLayout );
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -19,8 +19,14 @@
|
|||||||
#ifndef CALAMARESWINDOW_H
|
#ifndef CALAMARESWINDOW_H
|
||||||
#define CALAMARESWINDOW_H
|
#define CALAMARESWINDOW_H
|
||||||
|
|
||||||
|
#include <QPointer>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
namespace Calamares
|
||||||
|
{
|
||||||
|
class DebugWindow;
|
||||||
|
}
|
||||||
|
|
||||||
class CalamaresWindow : public QWidget
|
class CalamaresWindow : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -28,6 +34,8 @@ public:
|
|||||||
CalamaresWindow( QWidget* parent = nullptr );
|
CalamaresWindow( QWidget* parent = nullptr );
|
||||||
virtual ~CalamaresWindow() {}
|
virtual ~CalamaresWindow() {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPointer< Calamares::DebugWindow > m_debugWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //CALAMARESWINDOW_H
|
#endif //CALAMARESWINDOW_H
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -31,6 +31,7 @@ namespace bp = boost::python;
|
|||||||
namespace Calamares {
|
namespace Calamares {
|
||||||
|
|
||||||
GlobalStorage::GlobalStorage()
|
GlobalStorage::GlobalStorage()
|
||||||
|
: QObject( nullptr )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +54,7 @@ void
|
|||||||
GlobalStorage::insert( const QString& key, const QVariant& value )
|
GlobalStorage::insert( const QString& key, const QVariant& value )
|
||||||
{
|
{
|
||||||
m.insert( key, value );
|
m.insert( key, value );
|
||||||
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -67,6 +69,7 @@ int
|
|||||||
GlobalStorage::remove( const QString& key )
|
GlobalStorage::remove( const QString& key )
|
||||||
{
|
{
|
||||||
return m.remove( key );
|
return m.remove( key );
|
||||||
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -76,47 +79,63 @@ GlobalStorage::value( const QString& key ) const
|
|||||||
return m.value( key );
|
return m.value( key );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Calamares
|
||||||
|
|
||||||
#ifdef WITH_PYTHON
|
#ifdef WITH_PYTHON
|
||||||
|
|
||||||
bool
|
namespace CalamaresPython
|
||||||
GlobalStorage::python_contains( const std::string& key ) const
|
|
||||||
{
|
{
|
||||||
return contains( QString::fromStdString( key ) );
|
|
||||||
|
GlobalStoragePythonWrapper::GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs )
|
||||||
|
: m_gs( gs )
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool
|
||||||
|
GlobalStoragePythonWrapper::contains( const std::string& key ) const
|
||||||
|
{
|
||||||
|
return m_gs->contains( QString::fromStdString( key ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
GlobalStoragePythonWrapper::count() const
|
||||||
|
{
|
||||||
|
return m_gs->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalStorage::python_insert( const std::string& key,
|
GlobalStoragePythonWrapper::insert( const std::string& key,
|
||||||
const bp::object& value )
|
const bp::object& value )
|
||||||
{
|
{
|
||||||
insert( QString::fromStdString( key ),
|
m_gs->insert( QString::fromStdString( key ),
|
||||||
CalamaresPython::variantFromPyObject( value ) );
|
CalamaresPython::variantFromPyObject( value ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bp::list
|
bp::list
|
||||||
GlobalStorage::python_keys() const
|
GlobalStoragePythonWrapper::keys() const
|
||||||
{
|
{
|
||||||
bp::list pyList;
|
bp::list pyList;
|
||||||
foreach( const QString& key, keys() )
|
foreach( const QString& key, m_gs->keys() )
|
||||||
pyList.append( key.toStdString() );
|
pyList.append( key.toStdString() );
|
||||||
return pyList;
|
return pyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
GlobalStorage::python_remove( const std::string& key )
|
GlobalStoragePythonWrapper::remove( const std::string& key )
|
||||||
{
|
{
|
||||||
return remove( QString::fromStdString( key ) );
|
return m_gs->remove( QString::fromStdString( key ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bp::object
|
bp::object
|
||||||
GlobalStorage::python_value( const std::string& key ) const
|
GlobalStoragePythonWrapper::value( const std::string& key ) const
|
||||||
{
|
{
|
||||||
return CalamaresPython::variantToPyObject( value( QString::fromStdString( key ) ) );
|
return CalamaresPython::variantToPyObject( m_gs->value( QString::fromStdString( key ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // WITH_PYTHON
|
} // namespace CalamaresPython
|
||||||
|
|
||||||
} // namespace Calamares
|
#endif // WITH_PYTHON
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -40,8 +40,11 @@ class list;
|
|||||||
namespace Calamares
|
namespace Calamares
|
||||||
{
|
{
|
||||||
|
|
||||||
class GlobalStorage
|
class DebugWindow;
|
||||||
|
|
||||||
|
class GlobalStorage : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit GlobalStorage();
|
explicit GlobalStorage();
|
||||||
|
|
||||||
@ -54,17 +57,37 @@ public:
|
|||||||
int remove( const QString& key );
|
int remove( const QString& key );
|
||||||
QVariant value( const QString& key ) const;
|
QVariant value( const QString& key ) const;
|
||||||
|
|
||||||
#ifdef WITH_PYTHON
|
signals:
|
||||||
bool python_contains( const std::string& key ) const;
|
void changed();
|
||||||
void python_insert( const std::string& key, const boost::python::api::object& value );
|
|
||||||
boost::python::list python_keys() const;
|
|
||||||
int python_remove( const std::string& key );
|
|
||||||
boost::python::api::object python_value( const std::string& key ) const;
|
|
||||||
#endif
|
|
||||||
private:
|
private:
|
||||||
QVariantMap m;
|
QVariantMap m;
|
||||||
|
|
||||||
|
friend DebugWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
|
||||||
|
#ifdef WITH_PYTHON
|
||||||
|
namespace CalamaresPython
|
||||||
|
{
|
||||||
|
|
||||||
|
class GlobalStoragePythonWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs );
|
||||||
|
|
||||||
|
bool contains( const std::string& key ) const;
|
||||||
|
int count() const;
|
||||||
|
void insert( const std::string& key, const boost::python::api::object& value );
|
||||||
|
boost::python::list keys() const;
|
||||||
|
int remove( const std::string& key );
|
||||||
|
boost::python::api::object value( const std::string& key ) const;
|
||||||
|
private:
|
||||||
|
Calamares::GlobalStorage* m_gs;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace CalamaresPython
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // CALAMARES_GLOBALSTORAGE_H
|
#endif // CALAMARES_GLOBALSTORAGE_H
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -158,6 +158,7 @@ JobQueue::enqueue( const Calamares::job_ptr& job )
|
|||||||
{
|
{
|
||||||
Q_ASSERT( !m_thread->isRunning() );
|
Q_ASSERT( !m_thread->isRunning() );
|
||||||
m_jobs.append( job );
|
m_jobs.append( job );
|
||||||
|
emit queueChanged( m_jobs );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -166,6 +167,7 @@ JobQueue::enqueue( const QList< job_ptr >& jobs )
|
|||||||
{
|
{
|
||||||
Q_ASSERT( !m_thread->isRunning() );
|
Q_ASSERT( !m_thread->isRunning() );
|
||||||
m_jobs.append( jobs );
|
m_jobs.append( jobs );
|
||||||
|
emit queueChanged( m_jobs );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -46,6 +46,7 @@ public:
|
|||||||
void start();
|
void start();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void queueChanged( const QList< Calamares::job_ptr >& jobs );
|
||||||
void progress( qreal percent, const QString& prettyName );
|
void progress( qreal percent, const QString& prettyName );
|
||||||
void finished();
|
void finished();
|
||||||
void failed( const QString& message, const QString& details );
|
void failed( const QString& message, const QString& details );
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -79,13 +79,13 @@ BOOST_PYTHON_MODULE( libcalamares )
|
|||||||
"as a real number between 0 and 1."
|
"as a real number between 0 and 1."
|
||||||
);
|
);
|
||||||
|
|
||||||
bp::class_< Calamares::GlobalStorage >( "GlobalStorage", bp::init<>() )
|
bp::class_< CalamaresPython::GlobalStoragePythonWrapper >( "GlobalStorage", bp::init< Calamares::GlobalStorage* >() )
|
||||||
.def( "contains", &Calamares::GlobalStorage::python_contains )
|
.def( "contains", &CalamaresPython::GlobalStoragePythonWrapper::contains )
|
||||||
.def( "count", &Calamares::GlobalStorage::count )
|
.def( "count", &CalamaresPython::GlobalStoragePythonWrapper::count )
|
||||||
.def( "insert", &Calamares::GlobalStorage::python_insert )
|
.def( "insert", &CalamaresPython::GlobalStoragePythonWrapper::insert )
|
||||||
.def( "keys", &Calamares::GlobalStorage::python_keys )
|
.def( "keys", &CalamaresPython::GlobalStoragePythonWrapper::keys )
|
||||||
.def( "remove", &Calamares::GlobalStorage::python_remove )
|
.def( "remove", &CalamaresPython::GlobalStoragePythonWrapper::remove )
|
||||||
.def( "value", &Calamares::GlobalStorage::python_value );
|
.def( "value", &CalamaresPython::GlobalStoragePythonWrapper::value );
|
||||||
|
|
||||||
// libcalamares.utils submodule starts here
|
// libcalamares.utils submodule starts here
|
||||||
bp::object utilsModule( bp::handle<>( bp::borrowed( PyImport_AddModule( "libcalamares.utils" ) ) ) );
|
bp::object utilsModule( bp::handle<>( bp::borrowed( PyImport_AddModule( "libcalamares.utils" ) ) ) );
|
||||||
@ -271,7 +271,8 @@ PythonJob::exec()
|
|||||||
bp::dict calamaresNamespace = bp::extract< bp::dict >( calamaresModule.attr( "__dict__" ) );
|
bp::dict calamaresNamespace = bp::extract< bp::dict >( calamaresModule.attr( "__dict__" ) );
|
||||||
|
|
||||||
calamaresNamespace[ "job" ] = CalamaresPython::PythonJobInterface( this );
|
calamaresNamespace[ "job" ] = CalamaresPython::PythonJobInterface( this );
|
||||||
calamaresNamespace[ "globalstorage" ] = bp::ptr( JobQueue::instance()->globalStorage() );
|
calamaresNamespace[ "globalstorage" ] = CalamaresPython::GlobalStoragePythonWrapper(
|
||||||
|
JobQueue::instance()->globalStorage() );
|
||||||
|
|
||||||
bp::object execResult = bp::exec_file( scriptFI.absoluteFilePath().toLocal8Bit().data(),
|
bp::object execResult = bp::exec_file( scriptFI.absoluteFilePath().toLocal8Bit().data(),
|
||||||
scriptNamespace,
|
scriptNamespace,
|
||||||
|
@ -7,9 +7,13 @@ list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_SOURCES
|
|||||||
modulesystem/ViewModule.cpp
|
modulesystem/ViewModule.cpp
|
||||||
|
|
||||||
utils/CalamaresUtilsGui.cpp
|
utils/CalamaresUtilsGui.cpp
|
||||||
|
utils/DebugWindow.cpp
|
||||||
utils/ImageRegistry.cpp
|
utils/ImageRegistry.cpp
|
||||||
utils/YamlUtils.cpp
|
utils/YamlUtils.cpp
|
||||||
|
|
||||||
|
utils/qjsonmodel.cpp
|
||||||
|
utils/qjsonitem.cpp
|
||||||
|
|
||||||
viewpages/AbstractPage.cpp
|
viewpages/AbstractPage.cpp
|
||||||
viewpages/ViewStep.cpp
|
viewpages/ViewStep.cpp
|
||||||
|
|
||||||
@ -24,7 +28,7 @@ list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_UI
|
list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_UI
|
||||||
|
utils/DebugWindow.ui
|
||||||
)
|
)
|
||||||
|
|
||||||
if( WITH_PYTHON )
|
if( WITH_PYTHON )
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -213,6 +213,13 @@ Module::isLoaded() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantMap
|
||||||
|
Module::configurationMap()
|
||||||
|
{
|
||||||
|
return m_configurationMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Module::Module()
|
Module::Module()
|
||||||
: m_loaded( false )
|
: m_loaded( false )
|
||||||
{}
|
{}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -73,6 +73,8 @@ public:
|
|||||||
|
|
||||||
virtual QList< job_ptr > jobs() const = 0;
|
virtual QList< job_ptr > jobs() const = 0;
|
||||||
|
|
||||||
|
QVariantMap configurationMap();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Module();
|
explicit Module();
|
||||||
virtual void initFrom( const YAML::Node& node );
|
virtual void initFrom( const YAML::Node& node );
|
||||||
|
@ -32,11 +32,24 @@
|
|||||||
namespace Calamares
|
namespace Calamares
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
ModuleManager* ModuleManager::s_instance = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
ModuleManager*
|
||||||
|
ModuleManager::instance()
|
||||||
|
{
|
||||||
|
return s_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ModuleManager::ModuleManager( const QStringList& paths, QObject* parent )
|
ModuleManager::ModuleManager( const QStringList& paths, QObject* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_paths( paths )
|
, m_paths( paths )
|
||||||
, m_lastPhaseLoaded( Phase_NULL )
|
, m_lastPhaseLoaded( Phase_NULL )
|
||||||
{
|
{
|
||||||
|
Q_ASSERT( !s_instance );
|
||||||
|
s_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModuleManager::~ModuleManager()
|
ModuleManager::~ModuleManager()
|
||||||
|
@ -38,6 +38,8 @@ public:
|
|||||||
explicit ModuleManager( const QStringList& paths, QObject* parent = nullptr );
|
explicit ModuleManager( const QStringList& paths, QObject* parent = nullptr );
|
||||||
virtual ~ModuleManager();
|
virtual ~ModuleManager();
|
||||||
|
|
||||||
|
static ModuleManager* instance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init goes through the module search directories and gets a list of
|
* @brief init goes through the module search directories and gets a list of
|
||||||
* modules available for loading, along with their metadata.
|
* modules available for loading, along with their metadata.
|
||||||
@ -64,10 +66,10 @@ private:
|
|||||||
void checkDependencies();
|
void checkDependencies();
|
||||||
|
|
||||||
QMap< QString, Module* > m_availableModules;
|
QMap< QString, Module* > m_availableModules;
|
||||||
|
|
||||||
QStringList m_paths;
|
QStringList m_paths;
|
||||||
|
|
||||||
Phase m_lastPhaseLoaded;
|
Phase m_lastPhaseLoaded;
|
||||||
|
|
||||||
|
static ModuleManager* s_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
107
src/libcalamaresui/utils/DebugWindow.cpp
Normal file
107
src/libcalamaresui/utils/DebugWindow.cpp
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2015, Teo Mrnjavac <teo@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 "DebugWindow.h"
|
||||||
|
#include "utils/Retranslator.h"
|
||||||
|
#include "utils/qjsonmodel.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
#include "Job.h"
|
||||||
|
#include "GlobalStorage.h"
|
||||||
|
#include "modulesystem/ModuleManager.h"
|
||||||
|
#include "modulesystem/Module.h"
|
||||||
|
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QSplitter>
|
||||||
|
#include <QStringListModel>
|
||||||
|
#include <QTreeView>
|
||||||
|
|
||||||
|
namespace Calamares {
|
||||||
|
|
||||||
|
DebugWindow::DebugWindow()
|
||||||
|
: QWidget( nullptr )
|
||||||
|
{
|
||||||
|
setupUi( this );
|
||||||
|
|
||||||
|
// GlobalStorage page
|
||||||
|
QJsonModel* jsonModel = new QJsonModel( this );
|
||||||
|
|
||||||
|
globalStorageView->setModel( jsonModel );
|
||||||
|
GlobalStorage* gs = JobQueue::instance()->globalStorage();
|
||||||
|
|
||||||
|
connect( gs, &GlobalStorage::changed, [ = ]
|
||||||
|
{
|
||||||
|
jsonModel->loadJson( QJsonDocument::fromVariant( gs->m ).toJson() );
|
||||||
|
globalStorageView->expandAll();
|
||||||
|
} );
|
||||||
|
jsonModel->loadJson( QJsonDocument::fromVariant( gs->m ).toJson() );
|
||||||
|
globalStorageView->expandAll();
|
||||||
|
|
||||||
|
// JobQueue page
|
||||||
|
jobQueueText->setReadOnly( true );
|
||||||
|
connect( JobQueue::instance(), &JobQueue::queueChanged,
|
||||||
|
[ this ]( const QList< Calamares::job_ptr >& jobs )
|
||||||
|
{
|
||||||
|
QStringList text;
|
||||||
|
foreach( auto job, jobs )
|
||||||
|
{
|
||||||
|
text.append( job->prettyName() );
|
||||||
|
}
|
||||||
|
|
||||||
|
jobQueueText->setText( text.join( '\n' ) );
|
||||||
|
} );
|
||||||
|
|
||||||
|
// Modules page
|
||||||
|
QSplitter* splitter = new QSplitter( modulesTab );
|
||||||
|
modulesTab->layout()->addWidget( splitter );
|
||||||
|
splitter->addWidget( modulesListView );
|
||||||
|
splitter->addWidget( moduleConfigView );
|
||||||
|
|
||||||
|
QStringListModel* modulesModel = new QStringListModel( ModuleManager::instance()->availableModules() );
|
||||||
|
modulesListView->setModel( modulesModel );
|
||||||
|
modulesListView->setSelectionMode( QAbstractItemView::SingleSelection );
|
||||||
|
|
||||||
|
QJsonModel* moduleConfigModel = new QJsonModel( this );
|
||||||
|
moduleConfigView->setModel( moduleConfigModel );
|
||||||
|
|
||||||
|
connect( modulesListView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||||
|
[ this, moduleConfigModel ]
|
||||||
|
{
|
||||||
|
QString moduleName = modulesListView->currentIndex().data().toString();
|
||||||
|
Module* module = ModuleManager::instance()->module( moduleName );
|
||||||
|
if ( module )
|
||||||
|
{
|
||||||
|
moduleConfigModel->loadJson( QJsonDocument::fromVariant( module->configurationMap() ).toJson() );
|
||||||
|
moduleConfigView->expandAll();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
CALAMARES_RETRANSLATE(
|
||||||
|
retranslateUi( this );
|
||||||
|
setWindowTitle( tr( "Debug information" ) );
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DebugWindow::closeEvent( QCloseEvent* e )
|
||||||
|
{
|
||||||
|
Q_UNUSED( e )
|
||||||
|
emit closed();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Calamares
|
45
src/libcalamaresui/utils/DebugWindow.h
Normal file
45
src/libcalamaresui/utils/DebugWindow.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2015, Teo Mrnjavac <teo@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 CALAMARES_DEBUGWINDOW_H
|
||||||
|
#define CALAMARES_DEBUGWINDOW_H
|
||||||
|
|
||||||
|
#include "ui_DebugWindow.h"
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
namespace Calamares {
|
||||||
|
|
||||||
|
class DebugWindow : public QWidget, private Ui::DebugWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DebugWindow();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void closed();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void closeEvent( QCloseEvent* e ) override;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Calamares
|
||||||
|
#endif // CALAMARES_DEBUGWINDOW_H
|
61
src/libcalamaresui/utils/DebugWindow.ui
Normal file
61
src/libcalamaresui/utils/DebugWindow.ui
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Calamares::DebugWindow</class>
|
||||||
|
<widget class="QWidget" name="Calamares::DebugWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>632</width>
|
||||||
|
<height>497</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="globalStorageTab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>GlobalStorage</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeView" name="globalStorageView"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="jobQueueTab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>JobQueue</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QTextEdit" name="jobQueueText"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="modulesTab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Modules</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QListView" name="modulesListView"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeView" name="moduleConfigView"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
138
src/libcalamaresui/utils/qjsonitem.cpp
Normal file
138
src/libcalamaresui/utils/qjsonitem.cpp
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Originally from QJsonModel <https://github.com/dridk/QJsonmodel>
|
||||||
|
* Copyright 2015, Sacha Schutz <sacha@labsquare.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 "qjsonitem.h"
|
||||||
|
|
||||||
|
QJsonTreeItem::QJsonTreeItem(QJsonTreeItem *parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
mParent = parent;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonTreeItem::~QJsonTreeItem()
|
||||||
|
{
|
||||||
|
qDeleteAll(mChilds);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QJsonTreeItem::appendChild(QJsonTreeItem *item)
|
||||||
|
{
|
||||||
|
mChilds.append(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonTreeItem *QJsonTreeItem::child(int row)
|
||||||
|
{
|
||||||
|
return mChilds.value(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonTreeItem *QJsonTreeItem::parent()
|
||||||
|
{
|
||||||
|
return mParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
int QJsonTreeItem::childCount() const
|
||||||
|
{
|
||||||
|
return mChilds.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
int QJsonTreeItem::row() const
|
||||||
|
{
|
||||||
|
if (mParent)
|
||||||
|
return mParent->mChilds.indexOf(const_cast<QJsonTreeItem*>(this));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QJsonTreeItem::setKey(const QString &key)
|
||||||
|
{
|
||||||
|
mKey = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QJsonTreeItem::setValue(const QString &value)
|
||||||
|
{
|
||||||
|
mValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QJsonTreeItem::setType(const QJsonValue::Type &type)
|
||||||
|
{
|
||||||
|
mType = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QJsonTreeItem::key() const
|
||||||
|
{
|
||||||
|
return mKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QJsonTreeItem::value() const
|
||||||
|
{
|
||||||
|
return mValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonValue::Type QJsonTreeItem::type() const
|
||||||
|
{
|
||||||
|
return mType;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonTreeItem* QJsonTreeItem::load(const QJsonValue& value, QJsonTreeItem* parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
QJsonTreeItem * rootItem = new QJsonTreeItem(parent);
|
||||||
|
rootItem->setKey("root");
|
||||||
|
|
||||||
|
if ( value.isObject())
|
||||||
|
{
|
||||||
|
|
||||||
|
//Get all QJsonValue childs
|
||||||
|
foreach (QString key , value.toObject().keys()){
|
||||||
|
QJsonValue v = value.toObject().value(key);
|
||||||
|
QJsonTreeItem * child = load(v,rootItem);
|
||||||
|
child->setKey(key);
|
||||||
|
child->setType(v.type());
|
||||||
|
rootItem->appendChild(child);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ( value.isArray())
|
||||||
|
{
|
||||||
|
//Get all QJsonValue childs
|
||||||
|
int index = 0;
|
||||||
|
foreach (QJsonValue v , value.toArray()){
|
||||||
|
|
||||||
|
QJsonTreeItem * child = load(v,rootItem);
|
||||||
|
child->setKey(QString::number(index));
|
||||||
|
child->setType(v.type());
|
||||||
|
rootItem->appendChild(child);
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rootItem->setValue(value.toVariant().toString());
|
||||||
|
rootItem->setType(value.type());
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootItem;
|
||||||
|
}
|
||||||
|
|
60
src/libcalamaresui/utils/qjsonitem.h
Normal file
60
src/libcalamaresui/utils/qjsonitem.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Originally from QJsonModel <https://github.com/dridk/QJsonmodel>
|
||||||
|
* Copyright 2015, Sacha Schutz <sacha@labsquare.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 JSONITEM_H
|
||||||
|
#define JSONITEM_H
|
||||||
|
#include <QtCore>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
class QJsonTreeItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QJsonTreeItem(QJsonTreeItem * parent = 0);
|
||||||
|
~QJsonTreeItem();
|
||||||
|
void appendChild(QJsonTreeItem * item);
|
||||||
|
QJsonTreeItem *child(int row);
|
||||||
|
QJsonTreeItem *parent();
|
||||||
|
int childCount() const;
|
||||||
|
int row() const;
|
||||||
|
void setKey(const QString& key);
|
||||||
|
void setValue(const QString& value);
|
||||||
|
void setType(const QJsonValue::Type& type);
|
||||||
|
QString key() const;
|
||||||
|
QString value() const;
|
||||||
|
QJsonValue::Type type() const;
|
||||||
|
|
||||||
|
|
||||||
|
static QJsonTreeItem* load(const QJsonValue& value, QJsonTreeItem * parent = 0);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString mKey;
|
||||||
|
QString mValue;
|
||||||
|
QJsonValue::Type mType;
|
||||||
|
|
||||||
|
QList<QJsonTreeItem*> mChilds;
|
||||||
|
QJsonTreeItem * mParent;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // JSONITEM_H
|
172
src/libcalamaresui/utils/qjsonmodel.cpp
Normal file
172
src/libcalamaresui/utils/qjsonmodel.cpp
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Originally from QJsonModel <https://github.com/dridk/QJsonmodel>
|
||||||
|
* Copyright 2015, Sacha Schutz <sacha@labsquare.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 "qjsonmodel.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QFont>
|
||||||
|
|
||||||
|
QJsonModel::QJsonModel(QObject *parent) :
|
||||||
|
QAbstractItemModel(parent)
|
||||||
|
{
|
||||||
|
mRootItem = new QJsonTreeItem;
|
||||||
|
mHeaders.append("key");
|
||||||
|
mHeaders.append("value");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QJsonModel::load(const QString &fileName)
|
||||||
|
{
|
||||||
|
QFile file(fileName);
|
||||||
|
bool success = false;
|
||||||
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
|
success = load(&file);
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else success = false;
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QJsonModel::load(QIODevice *device)
|
||||||
|
{
|
||||||
|
return loadJson(device->readAll());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QJsonModel::loadJson(const QByteArray &json)
|
||||||
|
{
|
||||||
|
mDocument = QJsonDocument::fromJson(json);
|
||||||
|
|
||||||
|
if (!mDocument.isNull())
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
mRootItem = QJsonTreeItem::load(QJsonValue(mDocument.object()));
|
||||||
|
endResetModel();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariant QJsonModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!index.isValid())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
|
||||||
|
QJsonTreeItem *item = static_cast<QJsonTreeItem*>(index.internalPointer());
|
||||||
|
|
||||||
|
|
||||||
|
if ((role == Qt::DecorationRole) && (index.column() == 0)){
|
||||||
|
|
||||||
|
return mTypeIcons.value(item->type());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
|
||||||
|
if (index.column() == 0)
|
||||||
|
return QString("%1").arg(item->key());
|
||||||
|
|
||||||
|
if (index.column() == 1)
|
||||||
|
return QString("%1").arg(item->value());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant QJsonModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
{
|
||||||
|
if (role != Qt::DisplayRole)
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
if (orientation == Qt::Horizontal) {
|
||||||
|
|
||||||
|
return mHeaders.value(section);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex QJsonModel::index(int row, int column, const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
if (!hasIndex(row, column, parent))
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
|
QJsonTreeItem *parentItem;
|
||||||
|
|
||||||
|
if (!parent.isValid())
|
||||||
|
parentItem = mRootItem;
|
||||||
|
else
|
||||||
|
parentItem = static_cast<QJsonTreeItem*>(parent.internalPointer());
|
||||||
|
|
||||||
|
QJsonTreeItem *childItem = parentItem->child(row);
|
||||||
|
if (childItem)
|
||||||
|
return createIndex(row, column, childItem);
|
||||||
|
else
|
||||||
|
return QModelIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex QJsonModel::parent(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
|
QJsonTreeItem *childItem = static_cast<QJsonTreeItem*>(index.internalPointer());
|
||||||
|
QJsonTreeItem *parentItem = childItem->parent();
|
||||||
|
|
||||||
|
if (parentItem == mRootItem)
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
|
return createIndex(parentItem->row(), 0, parentItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
int QJsonModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
QJsonTreeItem *parentItem;
|
||||||
|
if (parent.column() > 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!parent.isValid())
|
||||||
|
parentItem = mRootItem;
|
||||||
|
else
|
||||||
|
parentItem = static_cast<QJsonTreeItem*>(parent.internalPointer());
|
||||||
|
|
||||||
|
return parentItem->childCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
int QJsonModel::columnCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QJsonModel::setIcon(const QJsonValue::Type &type, const QIcon &icon)
|
||||||
|
{
|
||||||
|
mTypeIcons.insert(type,icon);
|
||||||
|
}
|
56
src/libcalamaresui/utils/qjsonmodel.h
Normal file
56
src/libcalamaresui/utils/qjsonmodel.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Originally from QJsonModel <https://github.com/dridk/QJsonmodel>
|
||||||
|
* Copyright 2015, Sacha Schutz <sacha@labsquare.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 QJSONMODEL_H
|
||||||
|
#define QJSONMODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
#include "qjsonitem.h"
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QIcon>
|
||||||
|
class QJsonModel : public QAbstractItemModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit QJsonModel(QObject *parent = 0);
|
||||||
|
bool load(const QString& fileName);
|
||||||
|
bool load(QIODevice * device);
|
||||||
|
bool loadJson(const QByteArray& json);
|
||||||
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||||
|
QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
void setIcon(const QJsonValue::Type& type, const QIcon& icon);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
QJsonTreeItem * mRootItem;
|
||||||
|
QJsonDocument mDocument;
|
||||||
|
QStringList mHeaders;
|
||||||
|
QHash<QJsonValue::Type, QIcon> mTypeIcons;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QJSONMODEL_H
|
Loading…
Reference in New Issue
Block a user