From 7721c57e5e1093a3d8597b6b6f30c97d2aa3d8a5 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Wed, 11 Sep 2013 23:43:17 +0200 Subject: Split OneSixVersion into parts. --- logic/OneSixVersion.cpp | 112 +++--------------------------------------------- 1 file changed, 5 insertions(+), 107 deletions(-) (limited to 'logic/OneSixVersion.cpp') diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 56e272e2..7ffe9a94 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -1,111 +1,9 @@ #include "OneSixVersion.h" +#include "OneSixLibrary.h" -RuleAction RuleAction_fromString(QString name) +QList > OneSixVersion::getActiveNormalLibs() { - if(name == "allow") - return Allow; - if(name == "disallow") - return Disallow; - return Defer; -} - -OpSys OpSys_fromString(QString name) -{ - if(name == "linux") - return Os_Linux; - if(name == "windows") - return Os_Windows; - if(name == "osx") - return Os_OSX; - return Os_Other; -} - -void Library::finalize() -{ - QStringList parts = m_name.split ( ':' ); - QString relative = parts[0]; - relative.replace ( '.','/' ); - relative += '/' + parts[1] + '/' + parts[2] + '/' + parts[1] + '-' + parts[2]; - if ( !m_is_native ) - relative += ".jar"; - else - { - if ( m_native_suffixes.contains ( currentSystem ) ) - { - relative += "-" + m_native_suffixes[currentSystem] + ".jar"; - } - else - { - // really, bad. - relative += ".jar"; - } - } - m_storage_path = relative; - m_download_path = m_base_url + relative; - - if ( m_rules.empty() ) - { - m_is_active = true; - } - else - { - RuleAction result = Disallow; - for ( auto rule: m_rules ) - { - RuleAction temp = rule->apply ( this ); - if ( temp != Defer ) - result = temp; - } - m_is_active = ( result == Allow ); - } - if ( m_is_native ) - { - m_is_active = m_is_active && m_native_suffixes.contains ( currentSystem ); - } -} - -void Library::setName ( QString name ) -{ - m_name = name; -} -void Library::setBaseUrl ( QString base_url ) -{ - m_base_url = base_url; -} -void Library::setIsNative() -{ - m_is_native = true; -} -void Library::addNative ( OpSys os, QString suffix ) -{ - m_is_native = true; - m_native_suffixes[os] = suffix; -} -void Library::setRules ( QList< QSharedPointer< Rule > > rules ) -{ - m_rules = rules; -} -bool Library::isActive() -{ - return m_is_active; -} -bool Library::isNative() -{ - return m_is_native; -} -QString Library::downloadPath() -{ - return m_download_path; -} -QString Library::storagePath() -{ - return m_storage_path; -} - - -QList > OneSixVersion::getActiveNormalLibs() -{ - QList > output; + QList > output; for ( auto lib: libraries ) { if (lib->isActive() && !lib->isNative()) @@ -116,9 +14,9 @@ QList > OneSixVersion::getActiveNormalLibs() return output; } -QList > OneSixVersion::getActiveNativeLibs() +QList > OneSixVersion::getActiveNativeLibs() { - QList > output; + QList > output; for ( auto lib: libraries ) { if (lib->isActive() && lib->isNative()) -- cgit From d38b90530b3ba3a49c4eb072eb344ae2b0836913 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 16 Sep 2013 00:54:39 +0200 Subject: Forge version list implementation. Needs integration and testing. --- logic/OneSixVersion.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'logic/OneSixVersion.cpp') diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 7ffe9a94..dc1b5d6f 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -28,3 +28,74 @@ QList > OneSixVersion::getActiveNativeLibs() } +QVariant OneSixVersion::data(const QModelIndex& index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + int row = index.row(); + int column = index.column(); + + if(row < 0 || row >= libraries.size()) + return QVariant(); + + if(role == Qt::DisplayRole) + { + switch(column) + { + case 0: + return libraries[row]->name(); + case 1: + return libraries[row]->type(); + case 2: + return libraries[row]->version(); + default: + return QVariant(); + } + } + return QVariant(); +} + +Qt::ItemFlags OneSixVersion::flags(const QModelIndex& index) const +{ + if(!index.isValid()) + return Qt::NoItemFlags; + int row = index.row(); + if(libraries[row]->isActive()) + { + return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemNeverHasChildren; + } + else + { + return Qt::ItemNeverHasChildren; + } + //return QAbstractListModel::flags(index); +} + + +QVariant OneSixVersion::headerData ( int section, Qt::Orientation orientation, int role ) const +{ + if (role != Qt::DisplayRole || orientation != Qt::Horizontal) + return QVariant(); + switch (section) + { + case 0: + return QString("Name"); + case 1: + return QString("Type"); + case 2: + return QString("Version"); + default: + return QString(); + } +} + +int OneSixVersion::rowCount(const QModelIndex& parent) const +{ + return libraries.size(); +} + +int OneSixVersion::columnCount(const QModelIndex& parent) const +{ + return 3; +} -- cgit