From 93feb7fbf408ccc9178832d5f21c3806cb2a9f16 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 13 Apr 2016 15:46:41 +0300 Subject: Add support for different groups of update servers reading from servers list. --- src/gui/models/updatelistmodel.h | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'src/gui/models') diff --git a/src/gui/models/updatelistmodel.h b/src/gui/models/updatelistmodel.h index 67fffc34e..0f1104200 100644 --- a/src/gui/models/updatelistmodel.h +++ b/src/gui/models/updatelistmodel.h @@ -25,17 +25,25 @@ #include "gui/models/listmodel.h" -#include "net/logindata.h" +#include "net/hostsgroup.h" + +#include "utils/stringvector.h" #include "localconsts.h" class UpdateListModel final : public ListModel { public: - explicit UpdateListModel(LoginData *const data) : + explicit UpdateListModel(ServerInfo *const server) : ListModel(), - mLoginData(data) + mNames(), + mServer(server) { + FOR_EACH(std::vector::const_iterator, it, server->updateHosts) + { + const HostsGroup &group = *it; + mNames.push_back(group.name); + } } A_DELETE_COPY(UpdateListModel) @@ -45,20 +53,31 @@ class UpdateListModel final : public ListModel int getNumberOfElements() override final { - if (!mLoginData) - return 0; - return CAST_S32(mLoginData->updateHosts.size()); + return CAST_S32(mNames.size()); } std::string getElementAt(int i) override final { - if (!mLoginData || i >= getNumberOfElements() || i < 0) + if (i >= getNumberOfElements() || i < 0) return "???"; - return mLoginData->updateHosts[i]; + return mNames[i]; + } + + HostsGroup &getSelectedGroup(const unsigned int sel) + { + if (sel >= mServer->updateHosts.size()) + return mServer->updateHosts[0]; + mServer->updateHosts[sel]; + } + + bool empty() const + { + return mNames.empty(); } protected: - LoginData *mLoginData; + StringVect mNames; + ServerInfo *mServer; }; #endif // GUI_MODELS_UPDATELISTMODEL_H -- cgit v1.2.3-60-g2f50