summaryrefslogtreecommitdiffstats
path: root/logic/OneSixVersion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'logic/OneSixVersion.cpp')
-rw-r--r--logic/OneSixVersion.cpp173
1 files changed, 71 insertions, 102 deletions
diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp
index 56e272e2..dc1b5d6f 100644
--- a/logic/OneSixVersion.cpp
+++ b/logic/OneSixVersion.cpp
@@ -1,132 +1,101 @@
#include "OneSixVersion.h"
+#include "OneSixLibrary.h"
-RuleAction RuleAction_fromString(QString name)
+QList<QSharedPointer<OneSixLibrary> > OneSixVersion::getActiveNormalLibs()
{
- if(name == "allow")
- return Allow;
- if(name == "disallow")
- return Disallow;
- return Defer;
+ QList<QSharedPointer<OneSixLibrary> > output;
+ for ( auto lib: libraries )
+ {
+ if (lib->isActive() && !lib->isNative())
+ {
+ output.append(lib);
+ }
+ }
+ return output;
}
-OpSys OpSys_fromString(QString name)
+QList<QSharedPointer<OneSixLibrary> > OneSixVersion::getActiveNativeLibs()
{
- if(name == "linux")
- return Os_Linux;
- if(name == "windows")
- return Os_Windows;
- if(name == "osx")
- return Os_OSX;
- return Os_Other;
+ QList<QSharedPointer<OneSixLibrary> > output;
+ for ( auto lib: libraries )
+ {
+ if (lib->isActive() && lib->isNative())
+ {
+ output.append(lib);
+ }
+ }
+ return output;
}
-void Library::finalize()
+
+QVariant OneSixVersion::data(const QModelIndex& index, int role) const
{
- 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(!index.isValid())
+ return QVariant();
+
+ int row = index.row();
+ int column = index.column();
+
+ if(row < 0 || row >= libraries.size())
+ return QVariant();
+
+ if(role == Qt::DisplayRole)
{
- if ( m_native_suffixes.contains ( currentSystem ) )
- {
- relative += "-" + m_native_suffixes[currentSystem] + ".jar";
- }
- else
+ switch(column)
{
- // really, bad.
- relative += ".jar";
+ case 0:
+ return libraries[row]->name();
+ case 1:
+ return libraries[row]->type();
+ case 2:
+ return libraries[row]->version();
+ default:
+ return QVariant();
}
}
- m_storage_path = relative;
- m_download_path = m_base_url + relative;
+ return QVariant();
+}
- if ( m_rules.empty() )
+Qt::ItemFlags OneSixVersion::flags(const QModelIndex& index) const
+{
+ if(!index.isValid())
+ return Qt::NoItemFlags;
+ int row = index.row();
+ if(libraries[row]->isActive())
{
- m_is_active = true;
+ return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemNeverHasChildren;
}
else
{
- RuleAction result = Disallow;
- for ( auto rule: m_rules )
- {
- RuleAction temp = rule->apply ( this );
- if ( temp != Defer )
- result = temp;
- }
- m_is_active = ( result == Allow );
+ return Qt::ItemNeverHasChildren;
}
- 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;
+ //return QAbstractListModel::flags(index);
}
-QList<QSharedPointer<Library> > OneSixVersion::getActiveNormalLibs()
+QVariant OneSixVersion::headerData ( int section, Qt::Orientation orientation, int role ) const
{
- QList<QSharedPointer<Library> > output;
- for ( auto lib: libraries )
+ if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
+ return QVariant();
+ switch (section)
{
- if (lib->isActive() && !lib->isNative())
- {
- output.append(lib);
- }
+ case 0:
+ return QString("Name");
+ case 1:
+ return QString("Type");
+ case 2:
+ return QString("Version");
+ default:
+ return QString();
}
- return output;
}
-QList<QSharedPointer<Library> > OneSixVersion::getActiveNativeLibs()
+int OneSixVersion::rowCount(const QModelIndex& parent) const
{
- QList<QSharedPointer<Library> > output;
- for ( auto lib: libraries )
- {
- if (lib->isActive() && lib->isNative())
- {
- output.append(lib);
- }
- }
- return output;
+ return libraries.size();
}
-
+int OneSixVersion::columnCount(const QModelIndex& parent) const
+{
+ return 3;
+}