This commit is contained in:
fourtf
2018-06-26 13:24:55 +02:00
parent ec04f10895
commit c9722b9780
301 changed files with 0 additions and 0 deletions
@@ -0,0 +1,53 @@
#include "accountcontroller.hpp"
#include "controllers/accounts/accountmodel.hpp"
namespace chatterino {
namespace controllers {
namespace accounts {
AccountController::AccountController()
{
this->twitch.accounts.itemInserted.connect([this](const auto &args) {
this->accounts.insertItem(std::dynamic_pointer_cast<Account>(args.item));
});
this->twitch.accounts.itemRemoved.connect([this](const auto &args) {
if (args.caller != this) {
auto &accs = this->twitch.accounts.getVector();
auto it = std::find(accs.begin(), accs.end(), args.item);
assert(it != accs.end());
this->accounts.removeItem(it - accs.begin());
}
});
this->accounts.itemRemoved.connect([this](const auto &args) {
switch (args.item->getProviderId()) {
case ProviderId::Twitch: {
auto &accs = this->twitch.accounts.getVector();
auto it = std::find(accs.begin(), accs.end(), args.item);
assert(it != accs.end());
this->twitch.accounts.removeItem(it - accs.begin(), this);
} break;
}
});
}
void AccountController::load()
{
this->twitch.load();
}
AccountModel *AccountController::createModel(QObject *parent)
{
AccountModel *model = new AccountModel(parent);
model->init(&this->accounts);
return model;
}
} // namespace accounts
} // namespace controllers
} // namespace chatterino