Changeset View
Changeset View
Standalone View
Standalone View
src/core/model/rocketchataccountmodel.cpp
Show All 14 Lines | 1 | /* | |||
---|---|---|---|---|---|
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License | ||
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to | ||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "rocketchataccountmodel.h" | 21 | #include "rocketchataccountmodel.h" | ||
22 | #include "rocketchataccount.h" | 22 | #include "rocketchataccount.h" | ||
23 | #include "roommodel.h" | ||||
23 | #include "ruqolaserverconfig.h" | 24 | #include "ruqolaserverconfig.h" | ||
24 | #include "ruqola_debug.h" | 25 | #include "ruqola_debug.h" | ||
25 | 26 | | |||
27 | #include <QIcon> | ||||
28 | | ||||
26 | RocketChatAccountModel::RocketChatAccountModel(QObject *parent) | 29 | RocketChatAccountModel::RocketChatAccountModel(QObject *parent) | ||
27 | : QAbstractListModel(parent) | 30 | : QAbstractListModel(parent) | ||
28 | { | 31 | { | ||
29 | } | 32 | } | ||
30 | 33 | | |||
31 | RocketChatAccountModel::~RocketChatAccountModel() | 34 | RocketChatAccountModel::~RocketChatAccountModel() | ||
32 | { | 35 | { | ||
33 | qDeleteAll(mRocketChatAccount); | 36 | qDeleteAll(mRocketChatAccount); | ||
Show All 9 Lines | 40 | { | |||
43 | } | 46 | } | ||
44 | Q_EMIT accountNumberChanged(); | 47 | Q_EMIT accountNumberChanged(); | ||
45 | } | 48 | } | ||
46 | 49 | | |||
47 | void RocketChatAccountModel::setAccounts(const QVector<RocketChatAccount *> &accounts) | 50 | void RocketChatAccountModel::setAccounts(const QVector<RocketChatAccount *> &accounts) | ||
48 | { | 51 | { | ||
49 | if (rowCount() != 0) { | 52 | if (rowCount() != 0) { | ||
50 | beginRemoveRows(QModelIndex(), 0, mRocketChatAccount.count() - 1); | 53 | beginRemoveRows(QModelIndex(), 0, mRocketChatAccount.count() - 1); | ||
54 | for (auto acct: accounts) | ||||
55 | acct->roomModel()->disconnect(this); | ||||
51 | mRocketChatAccount.clear(); | 56 | mRocketChatAccount.clear(); | ||
52 | endRemoveRows(); | 57 | endRemoveRows(); | ||
53 | } | 58 | } | ||
54 | if (!accounts.isEmpty()) { | 59 | if (!accounts.isEmpty()) { | ||
55 | beginInsertRows(QModelIndex(), 0, accounts.count() - 1); | 60 | beginInsertRows(QModelIndex(), 0, accounts.count() - 1); | ||
56 | mRocketChatAccount = accounts; | 61 | mRocketChatAccount = accounts; | ||
62 | for (auto acct: accounts) | ||||
63 | { | ||||
64 | connect(acct->roomModel(), &RoomModel::needToUpdateNotification, this, [this, acct]{ | ||||
65 | const auto idx = index(mRocketChatAccount.indexOf(acct)); | ||||
66 | Q_EMIT dataChanged(idx, idx); | ||||
67 | }); | ||||
68 | } | ||||
57 | endInsertRows(); | 69 | endInsertRows(); | ||
58 | } | 70 | } | ||
59 | Q_EMIT accountNumberChanged(); | 71 | Q_EMIT accountNumberChanged(); | ||
60 | } | 72 | } | ||
61 | 73 | | |||
62 | RocketChatAccount *RocketChatAccountModel::account(const QString &accountName) const | 74 | RocketChatAccount *RocketChatAccountModel::account(const QString &accountName) const | ||
63 | { | 75 | { | ||
64 | if (mRocketChatAccount.isEmpty()) { | 76 | if (mRocketChatAccount.isEmpty()) { | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
108 | { | 120 | { | ||
109 | if (!index.isValid()) { | 121 | if (!index.isValid()) { | ||
110 | qCWarning(RUQOLA_LOG) << "ERROR: invalid index"; | 122 | qCWarning(RUQOLA_LOG) << "ERROR: invalid index"; | ||
111 | return {}; | 123 | return {}; | ||
112 | } | 124 | } | ||
113 | const int idx = index.row(); | 125 | const int idx = index.row(); | ||
114 | RocketChatAccount *account = mRocketChatAccount.at(idx); | 126 | RocketChatAccount *account = mRocketChatAccount.at(idx); | ||
115 | switch (role) { | 127 | switch (role) { | ||
128 | case Qt::DecorationRole: | ||||
129 | { | ||||
130 | bool hasAlert = false; | ||||
131 | int nbUnread = 0; | ||||
132 | account->roomModel()->getUnreadAlertFromAccount(hasAlert, nbUnread); | ||||
133 | if (hasAlert) | ||||
134 | return QIcon::fromTheme(QStringLiteral("flag-red")); | ||||
135 | if (nbUnread) | ||||
136 | return QIcon::fromTheme(QStringLiteral("flag-green")); | ||||
137 | return QIcon::fromTheme(QStringLiteral("flag-black")); | ||||
mwolff: this looks odd with dark color schemes - maybe no flag at all when nothing is there? | |||||
138 | } | ||||
116 | case Qt::DisplayRole: | 139 | case Qt::DisplayRole: | ||
117 | case Name: | 140 | case Name: | ||
118 | return account->accountName(); | 141 | return account->accountName(); | ||
119 | case SiteUrl: | 142 | case SiteUrl: | ||
120 | return account->ruqolaServerConfig()->siteUrl(); | 143 | return account->ruqolaServerConfig()->siteUrl(); | ||
121 | case UserName: | 144 | case UserName: | ||
122 | return account->userName(); | 145 | return account->userName(); | ||
146 | case Account: | ||||
147 | return QVariant::fromValue(account); | ||||
123 | } | 148 | } | ||
124 | //Add icon ??? | 149 | //Add icon ??? | ||
125 | return {}; | 150 | return {}; | ||
126 | } | 151 | } | ||
127 | 152 | | |||
128 | void RocketChatAccountModel::insertAccount(RocketChatAccount *account) | 153 | void RocketChatAccountModel::insertAccount(RocketChatAccount *account) | ||
129 | { | 154 | { | ||
130 | //Verify that we have it ? | 155 | //Verify that we have it ? | ||
Show All 32 Lines |
this looks odd with dark color schemes - maybe no flag at all when nothing is there?
personally I would even prefer no icons here at all and just use the same kind of (1) markers we have for channels to show the unreads and alert status?