Normalize line endings in already existing files
This commit is contained in:
@@ -1,40 +1,40 @@
|
||||
#include "Account.hpp"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
Account::Account(ProviderId providerId)
|
||||
: providerId_(providerId)
|
||||
{
|
||||
static QString twitch("Twitch");
|
||||
|
||||
this->category_ = [&]() {
|
||||
switch (providerId)
|
||||
{
|
||||
case ProviderId::Twitch:
|
||||
return twitch;
|
||||
}
|
||||
return QString("Unknown ProviderId");
|
||||
}();
|
||||
}
|
||||
|
||||
const QString &Account::getCategory() const
|
||||
{
|
||||
return this->category_;
|
||||
}
|
||||
|
||||
ProviderId Account::getProviderId() const
|
||||
{
|
||||
return this->providerId_;
|
||||
}
|
||||
|
||||
bool Account::operator<(const Account &other) const
|
||||
{
|
||||
QString a = this->toString();
|
||||
QString b = other.toString();
|
||||
|
||||
return std::tie(this->category_, a) < std::tie(other.category_, b);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
#include "Account.hpp"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
Account::Account(ProviderId providerId)
|
||||
: providerId_(providerId)
|
||||
{
|
||||
static QString twitch("Twitch");
|
||||
|
||||
this->category_ = [&]() {
|
||||
switch (providerId)
|
||||
{
|
||||
case ProviderId::Twitch:
|
||||
return twitch;
|
||||
}
|
||||
return QString("Unknown ProviderId");
|
||||
}();
|
||||
}
|
||||
|
||||
const QString &Account::getCategory() const
|
||||
{
|
||||
return this->category_;
|
||||
}
|
||||
|
||||
ProviderId Account::getProviderId() const
|
||||
{
|
||||
return this->providerId_;
|
||||
}
|
||||
|
||||
bool Account::operator<(const Account &other) const
|
||||
{
|
||||
QString a = this->toString();
|
||||
QString b = other.toString();
|
||||
|
||||
return std::tie(this->category_, a) < std::tie(other.category_, b);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/ProviderId.hpp"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Account
|
||||
{
|
||||
public:
|
||||
Account(ProviderId providerId);
|
||||
virtual ~Account() = default;
|
||||
|
||||
virtual QString toString() const = 0;
|
||||
const QString &getCategory() const;
|
||||
ProviderId getProviderId() const;
|
||||
|
||||
bool operator<(const Account &other) const;
|
||||
|
||||
private:
|
||||
ProviderId providerId_;
|
||||
QString category_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include "common/ProviderId.hpp"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Account
|
||||
{
|
||||
public:
|
||||
Account(ProviderId providerId);
|
||||
virtual ~Account() = default;
|
||||
|
||||
virtual QString toString() const = 0;
|
||||
const QString &getCategory() const;
|
||||
ProviderId getProviderId() const;
|
||||
|
||||
bool operator<(const Account &other) const;
|
||||
|
||||
private:
|
||||
ProviderId providerId_;
|
||||
QString category_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
#include "AccountController.hpp"
|
||||
|
||||
#include "controllers/accounts/Account.hpp"
|
||||
#include "controllers/accounts/AccountModel.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
this->accounts_.itemRemoved.connect([this](const auto &args) {
|
||||
switch (args.item->getProviderId())
|
||||
{
|
||||
case ProviderId::Twitch:
|
||||
{
|
||||
if (args.caller != this)
|
||||
{
|
||||
auto accs = this->twitch.accounts.cloneVector();
|
||||
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::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
this->twitch.load();
|
||||
}
|
||||
|
||||
AccountModel *AccountController::createModel(QObject *parent)
|
||||
{
|
||||
AccountModel *model = new AccountModel(parent);
|
||||
|
||||
model->init(&this->accounts_);
|
||||
return model;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
#include "AccountController.hpp"
|
||||
|
||||
#include "controllers/accounts/Account.hpp"
|
||||
#include "controllers/accounts/AccountModel.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
this->accounts_.itemRemoved.connect([this](const auto &args) {
|
||||
switch (args.item->getProviderId())
|
||||
{
|
||||
case ProviderId::Twitch:
|
||||
{
|
||||
if (args.caller != this)
|
||||
{
|
||||
auto accs = this->twitch.accounts.cloneVector();
|
||||
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::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
this->twitch.load();
|
||||
}
|
||||
|
||||
AccountModel *AccountController::createModel(QObject *parent)
|
||||
{
|
||||
AccountModel *model = new AccountModel(parent);
|
||||
|
||||
model->init(&this->accounts_);
|
||||
return model;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
#include "providers/twitch/TwitchAccountManager.hpp"
|
||||
#include "util/SharedPtrElementLess.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Account;
|
||||
class Settings;
|
||||
class Paths;
|
||||
|
||||
class AccountModel;
|
||||
|
||||
class AccountController final : public Singleton
|
||||
{
|
||||
public:
|
||||
AccountController();
|
||||
|
||||
AccountModel *createModel(QObject *parent);
|
||||
|
||||
virtual void initialize(Settings &settings, Paths &paths) override;
|
||||
|
||||
TwitchAccountManager twitch;
|
||||
|
||||
private:
|
||||
SortedSignalVector<std::shared_ptr<Account>, SharedPtrElementLess<Account>>
|
||||
accounts_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
#include "providers/twitch/TwitchAccountManager.hpp"
|
||||
#include "util/SharedPtrElementLess.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Account;
|
||||
class Settings;
|
||||
class Paths;
|
||||
|
||||
class AccountModel;
|
||||
|
||||
class AccountController final : public Singleton
|
||||
{
|
||||
public:
|
||||
AccountController();
|
||||
|
||||
AccountModel *createModel(QObject *parent);
|
||||
|
||||
virtual void initialize(Settings &settings, Paths &paths) override;
|
||||
|
||||
TwitchAccountManager twitch;
|
||||
|
||||
private:
|
||||
SortedSignalVector<std::shared_ptr<Account>, SharedPtrElementLess<Account>>
|
||||
accounts_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
#include "AccountModel.hpp"
|
||||
|
||||
#include "controllers/accounts/Account.hpp"
|
||||
#include "util/StandardItemHelper.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
AccountModel::AccountModel(QObject *parent)
|
||||
: SignalVectorModel<std::shared_ptr<Account>>(1, parent)
|
||||
{
|
||||
}
|
||||
|
||||
// turn a vector item into a model row
|
||||
std::shared_ptr<Account> AccountModel::getItemFromRow(
|
||||
std::vector<QStandardItem *> &, const std::shared_ptr<Account> &original)
|
||||
{
|
||||
return original;
|
||||
}
|
||||
|
||||
// turns a row in the model into a vector item
|
||||
void AccountModel::getRowFromItem(const std::shared_ptr<Account> &item,
|
||||
std::vector<QStandardItem *> &row)
|
||||
{
|
||||
setStringItem(row[0], item->toString(), false);
|
||||
row[0]->setData(QFont("Segoe UI", 10), Qt::FontRole);
|
||||
}
|
||||
|
||||
int AccountModel::beforeInsert(const std::shared_ptr<Account> &item,
|
||||
std::vector<QStandardItem *> &row,
|
||||
int proposedIndex)
|
||||
{
|
||||
if (this->categoryCount_[item->getCategory()]++ == 0)
|
||||
{
|
||||
auto newRow = this->createRow();
|
||||
|
||||
setStringItem(newRow[0], item->getCategory(), false, false);
|
||||
newRow[0]->setData(QFont("Segoe UI Light", 16), Qt::FontRole);
|
||||
|
||||
this->insertCustomRow(std::move(newRow), proposedIndex);
|
||||
|
||||
return proposedIndex + 1;
|
||||
}
|
||||
|
||||
return proposedIndex;
|
||||
}
|
||||
|
||||
void AccountModel::afterRemoved(const std::shared_ptr<Account> &item,
|
||||
std::vector<QStandardItem *> &row, int index)
|
||||
{
|
||||
auto it = this->categoryCount_.find(item->getCategory());
|
||||
assert(it != this->categoryCount_.end());
|
||||
|
||||
if (it->second <= 1)
|
||||
{
|
||||
this->categoryCount_.erase(it);
|
||||
this->removeCustomRow(index - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second--;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
#include "AccountModel.hpp"
|
||||
|
||||
#include "controllers/accounts/Account.hpp"
|
||||
#include "util/StandardItemHelper.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
AccountModel::AccountModel(QObject *parent)
|
||||
: SignalVectorModel<std::shared_ptr<Account>>(1, parent)
|
||||
{
|
||||
}
|
||||
|
||||
// turn a vector item into a model row
|
||||
std::shared_ptr<Account> AccountModel::getItemFromRow(
|
||||
std::vector<QStandardItem *> &, const std::shared_ptr<Account> &original)
|
||||
{
|
||||
return original;
|
||||
}
|
||||
|
||||
// turns a row in the model into a vector item
|
||||
void AccountModel::getRowFromItem(const std::shared_ptr<Account> &item,
|
||||
std::vector<QStandardItem *> &row)
|
||||
{
|
||||
setStringItem(row[0], item->toString(), false);
|
||||
row[0]->setData(QFont("Segoe UI", 10), Qt::FontRole);
|
||||
}
|
||||
|
||||
int AccountModel::beforeInsert(const std::shared_ptr<Account> &item,
|
||||
std::vector<QStandardItem *> &row,
|
||||
int proposedIndex)
|
||||
{
|
||||
if (this->categoryCount_[item->getCategory()]++ == 0)
|
||||
{
|
||||
auto newRow = this->createRow();
|
||||
|
||||
setStringItem(newRow[0], item->getCategory(), false, false);
|
||||
newRow[0]->setData(QFont("Segoe UI Light", 16), Qt::FontRole);
|
||||
|
||||
this->insertCustomRow(std::move(newRow), proposedIndex);
|
||||
|
||||
return proposedIndex + 1;
|
||||
}
|
||||
|
||||
return proposedIndex;
|
||||
}
|
||||
|
||||
void AccountModel::afterRemoved(const std::shared_ptr<Account> &item,
|
||||
std::vector<QStandardItem *> &row, int index)
|
||||
{
|
||||
auto it = this->categoryCount_.find(item->getCategory());
|
||||
assert(it != this->categoryCount_.end());
|
||||
|
||||
if (it->second <= 1)
|
||||
{
|
||||
this->categoryCount_.erase(it);
|
||||
this->removeCustomRow(index - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second--;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/SignalVectorModel.hpp"
|
||||
#include "controllers/accounts/Account.hpp"
|
||||
#include "util/QStringHash.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Account;
|
||||
class AccountController;
|
||||
|
||||
class AccountModel : public SignalVectorModel<std::shared_ptr<Account>>
|
||||
{
|
||||
public:
|
||||
AccountModel(QObject *parent);
|
||||
|
||||
protected:
|
||||
// turn a vector item into a model row
|
||||
virtual std::shared_ptr<Account> getItemFromRow(
|
||||
std::vector<QStandardItem *> &row,
|
||||
const std::shared_ptr<Account> &original) override;
|
||||
|
||||
// turns a row in the model into a vector item
|
||||
virtual void getRowFromItem(const std::shared_ptr<Account> &item,
|
||||
std::vector<QStandardItem *> &row) override;
|
||||
|
||||
virtual int beforeInsert(const std::shared_ptr<Account> &item,
|
||||
std::vector<QStandardItem *> &row,
|
||||
int proposedIndex) override;
|
||||
|
||||
virtual void afterRemoved(const std::shared_ptr<Account> &item,
|
||||
std::vector<QStandardItem *> &row,
|
||||
int index) override;
|
||||
|
||||
friend class AccountController;
|
||||
|
||||
private:
|
||||
std::unordered_map<QString, int> categoryCount_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include "common/SignalVectorModel.hpp"
|
||||
#include "controllers/accounts/Account.hpp"
|
||||
#include "util/QStringHash.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Account;
|
||||
class AccountController;
|
||||
|
||||
class AccountModel : public SignalVectorModel<std::shared_ptr<Account>>
|
||||
{
|
||||
public:
|
||||
AccountModel(QObject *parent);
|
||||
|
||||
protected:
|
||||
// turn a vector item into a model row
|
||||
virtual std::shared_ptr<Account> getItemFromRow(
|
||||
std::vector<QStandardItem *> &row,
|
||||
const std::shared_ptr<Account> &original) override;
|
||||
|
||||
// turns a row in the model into a vector item
|
||||
virtual void getRowFromItem(const std::shared_ptr<Account> &item,
|
||||
std::vector<QStandardItem *> &row) override;
|
||||
|
||||
virtual int beforeInsert(const std::shared_ptr<Account> &item,
|
||||
std::vector<QStandardItem *> &row,
|
||||
int proposedIndex) override;
|
||||
|
||||
virtual void afterRemoved(const std::shared_ptr<Account> &item,
|
||||
std::vector<QStandardItem *> &row,
|
||||
int index) override;
|
||||
|
||||
friend class AccountController;
|
||||
|
||||
private:
|
||||
std::unordered_map<QString, int> categoryCount_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user