mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-30 10:55:37 -04:00
[packagechooser] Start implementation of AppData loading
- Doing a manual read of the XML, since existing appdata libraries don't seem to have a convenient entry for what I need. - Expand tests to loading AppData (currently, they fail).
This commit is contained in:
parent
8329d7d7dc
commit
beb5896fa2
5 changed files with 101 additions and 10 deletions
|
@ -21,6 +21,11 @@
|
|||
#include "utils/Logger.h"
|
||||
#include "utils/Variant.h"
|
||||
|
||||
#ifdef HAVE_XML
|
||||
#include <QDomDocument>
|
||||
#include <QFile>
|
||||
#endif
|
||||
|
||||
const NamedEnumTable< PackageChooserMode >&
|
||||
roleNames()
|
||||
{
|
||||
|
@ -41,13 +46,6 @@ roleNames()
|
|||
return names;
|
||||
}
|
||||
|
||||
PackageItem
|
||||
PackageItem::fromAppStream( const QString& filename )
|
||||
{
|
||||
// TODO: implement this
|
||||
return PackageItem {};
|
||||
}
|
||||
|
||||
PackageItem::PackageItem() {}
|
||||
|
||||
PackageItem::PackageItem( const QString& a_id,
|
||||
|
@ -99,6 +97,56 @@ PackageItem::PackageItem::PackageItem( const QVariantMap& item_map )
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_XML
|
||||
QDomDocument
|
||||
loadAppData( const QString& fileName )
|
||||
{
|
||||
QFile file( fileName );
|
||||
if ( !file.open( QIODevice::ReadOnly ) )
|
||||
{
|
||||
return QDomDocument();
|
||||
}
|
||||
QDomDocument doc( "AppData" );
|
||||
if ( !doc.setContent( &file ) )
|
||||
{
|
||||
file.close();
|
||||
return QDomDocument();
|
||||
}
|
||||
file.close();
|
||||
return doc;
|
||||
}
|
||||
|
||||
QString
|
||||
getChildText( const QDomNode& n, const QString& tagName )
|
||||
{
|
||||
QDomElement e = n.firstChildElement( tagName );
|
||||
return e.isNull() ? QString() : e.text();
|
||||
}
|
||||
#endif
|
||||
|
||||
PackageItem
|
||||
PackageItem::fromAppData( const QString& fileName )
|
||||
{
|
||||
#ifdef HAVE_XML
|
||||
QDomDocument doc = loadAppData( fileName );
|
||||
if ( doc.isNull() )
|
||||
{
|
||||
return PackageItem();
|
||||
}
|
||||
|
||||
QDomElement componentNode = doc.documentElement();
|
||||
if ( !componentNode.isNull() && componentNode.tagName() == "component" )
|
||||
{
|
||||
QString id = getChildText( componentNode, "id" );
|
||||
cDebug() << "Got AppData id" << id;
|
||||
}
|
||||
|
||||
return PackageItem();
|
||||
#else
|
||||
return PackageItem();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PackageListModel::PackageListModel( QObject* parent )
|
||||
: QAbstractListModel( parent )
|
||||
|
@ -117,7 +165,7 @@ void
|
|||
PackageListModel::addPackage( PackageItem&& p )
|
||||
{
|
||||
// Only add valid packages
|
||||
if ( !p.name.isEmpty() )
|
||||
if ( p.isValid() )
|
||||
{
|
||||
int c = m_packages.count();
|
||||
beginInsertRows( QModelIndex(), c, c );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue