Q_INVOKABLE bool UserModel::isUserConnected(const int &id)
{
- if (!_users.isEmpty()) {
- return _users[id]->isConnected();
- } else {
+ if (_users.isEmpty())
return false;
- }
+ return _users[id]->isConnected();
}
Q_INVOKABLE QImage UserModel::currentUserAvatar()
{
- if (_users.count() >= 1) {
+ if (!_users.isEmpty()) {
return _users[_currentUserId]->avatar();
} else {
QImage image(128, 128, QImage::Format_ARGB32);
QImage UserModel::avatarById(const int &id)
{
+ if (_users.isEmpty())
+ return {};
+
return _users[id]->avatar(true);
}
Q_INVOKABLE QString UserModel::currentUserServer()
{
- if (_users.count() >= 1) {
- return _users[_currentUserId]->server();
- } else {
- return QString("");
- }
+ if (_users.isEmpty())
+ return {};
+
+ return _users[_currentUserId]->server();
}
Q_INVOKABLE bool UserModel::currentServerHasTalk()
{
- if (_users.count() >= 1) {
- return _users[_currentUserId]->serverHasTalk();
- } else {
+ if (_users.isEmpty())
return false;
- }
+
+ return _users[_currentUserId]->serverHasTalk();
}
void UserModel::addUser(AccountStatePtr &user, const bool &isCurrent)
Q_INVOKABLE void UserModel::openCurrentAccountLocalFolder()
{
+ if (_users.isEmpty())
+ return;
+
_users[_currentUserId]->openLocalFolder();
}
Q_INVOKABLE void UserModel::openCurrentAccountTalk()
{
+ if (_users.isEmpty())
+ return;
+
QString url = _users[_currentUserId]->server(false) + "/apps/spreed";
if (!(url.contains("http://") || url.contains("https://"))) {
url = "https://" + _users[_currentUserId]->server(false) + "/apps/spreed";
Q_INVOKABLE void UserModel::openCurrentAccountServer()
{
// Don't open this URL when the QML appMenu pops up on click (see Window.qml)
- if(appList().count() > 0)
+ if (appList().count() > 0)
+ return;
+ if (_users.isEmpty())
return;
QString url = _users[_currentUserId]->server(false);
Q_INVOKABLE void UserModel::switchCurrentUser(const int &id)
{
+ if (_users.isEmpty())
+ return;
+
_users[_currentUserId]->setCurrentUser(false);
_users[id]->setCurrentUser(true);
_currentUserId = id;
Q_INVOKABLE void UserModel::login(const int &id)
{
+ if (_users.isEmpty())
+ return;
+
_users[id]->login();
emit refreshCurrentUserGui();
}
Q_INVOKABLE void UserModel::logout(const int &id)
{
+ if (_users.isEmpty())
+ return;
+
_users[id]->logout();
emit refreshCurrentUserGui();
}
Q_INVOKABLE void UserModel::removeAccount(const int &id)
{
+ if (_users.isEmpty())
+ return;
+
QMessageBox messageBox(QMessageBox::Question,
tr("Confirm Account Removal"),
tr("<p>Do you really want to remove the connection to the account <i>%1</i>?</p>"
ActivityListModel *UserModel::currentActivityModel()
{
+ if (_users.isEmpty())
+ return nullptr;
+
return _users[currentUserIndex()]->getActivityModel();
}
bool UserModel::currentUserHasActivities()
{
+ if (_users.isEmpty())
+ return false;
+
return _users[currentUserIndex()]->hasActivities();
}
bool UserModel::currentUserHasLocalFolder()
{
+ if (_users.isEmpty())
+ return false;
+
return _users[currentUserIndex()]->getFolder() != nullptr;
}
void UserModel::fetchCurrentActivityModel()
{
- _users[currentUserId()]->slotRefresh();
+ if (!_users.isEmpty())
+ _users[currentUserId()]->slotRefresh();
}
AccountAppList UserModel::appList() const
{
- if (_users.count() > 0) {
- return _users[_currentUserId]->appList();
- } else {
+ if (_users.isEmpty())
return AccountAppList();
- }
+
+ return _users[_currentUserId]->appList();
}
User *UserModel::currentUser() const
{
+ if (_users.isEmpty())
+ return nullptr;
+
return _users[currentUserId()];
}
endRemoveRows();
}
- if(UserModel::instance()->appList().count() > 0) {
- foreach(AccountApp *app, UserModel::instance()->appList()) {
+ if (UserModel::instance()->appList().count() > 0) {
+ foreach (AccountApp *app, UserModel::instance()->appList()) {
// Filter out Talk because we have a dedicated button for it
- if(app->id() == QLatin1String("spreed"))
+ if (app->id() == QLatin1String("spreed"))
continue;
beginInsertRows(QModelIndex(), rowCount(), rowCount());