Changeset View
Changeset View
Standalone View
Standalone View
src/core/accountmanager.cpp
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 53 | connect(account, &RocketChatAccount::notification, this, [this, account](const Utils::NotificationInfo &info) { | |||
---|---|---|---|---|---|
58 | job->start(); | 58 | job->start(); | ||
59 | }); | 59 | }); | ||
60 | connect(account, &RocketChatAccount::updateNotification, this, &AccountManager::updateNotification); | 60 | connect(account, &RocketChatAccount::updateNotification, this, &AccountManager::updateNotification); | ||
61 | connect(account, &RocketChatAccount::logoutDone, this, &AccountManager::logoutAccountDone); | 61 | connect(account, &RocketChatAccount::logoutDone, this, &AccountManager::logoutAccountDone); | ||
62 | } | 62 | } | ||
63 | 63 | | |||
64 | void AccountManager::slotSwitchToAccountAndRoomName(const QString &accountName, const QString &roomName, const QString &channelType) | 64 | void AccountManager::slotSwitchToAccountAndRoomName(const QString &accountName, const QString &roomName, const QString &channelType) | ||
65 | { | 65 | { | ||
66 | setCurrentAccount(accountName); | 66 | setCurrentAccount(accountName, false /*showLastRoom*/); | ||
67 | QString linkRoom; | 67 | QString linkRoom; | ||
68 | if (channelType == QLatin1Char('c')) { | 68 | if (channelType == QLatin1Char('c')) { | ||
69 | linkRoom = QStringLiteral("ruqola:/room/%1").arg(roomName); | 69 | linkRoom = QStringLiteral("ruqola:/room/%1").arg(roomName); | ||
70 | } else { | 70 | } else { | ||
71 | linkRoom = QStringLiteral("ruqola:/user/%1").arg(roomName); | 71 | linkRoom = QStringLiteral("ruqola:/user/%1").arg(roomName); | ||
72 | } | 72 | } | ||
73 | Q_EMIT mCurrentAccount->raiseWindow(); | 73 | Q_EMIT mCurrentAccount->raiseWindow(); | ||
74 | Q_EMIT mCurrentAccount->openLinkRequested(linkRoom); | 74 | Q_EMIT mCurrentAccount->openLinkRequested(linkRoom); | ||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | 168 | { | |||
169 | RocketChatAccount *account = mRocketChatAccountModel->account(accountName); | 169 | RocketChatAccount *account = mRocketChatAccountModel->account(accountName); | ||
170 | if (account) { | 170 | if (account) { | ||
171 | mCurrentAccount = account; | 171 | mCurrentAccount = account; | ||
172 | } else { | 172 | } else { | ||
173 | qCWarning(RUQOLA_LOG) << "AccountName " << accountName << " is not found on system."; | 173 | qCWarning(RUQOLA_LOG) << "AccountName " << accountName << " is not found on system."; | ||
174 | } | 174 | } | ||
175 | } | 175 | } | ||
176 | 176 | | |||
177 | void AccountManager::setCurrentAccount(const QString &accountName) | 177 | void AccountManager::setCurrentAccount(const QString &accountName, bool showLastRoom) | ||
178 | { | 178 | { | ||
179 | RocketChatAccount *account = mRocketChatAccountModel->account(accountName); | 179 | RocketChatAccount *account = mRocketChatAccountModel->account(accountName); | ||
180 | if (account) { | 180 | if (account) { | ||
181 | if (mCurrentAccount != account) { | 181 | if (mCurrentAccount != account) { | ||
182 | QSettings settings; | 182 | QSettings settings; | ||
183 | settings.setValue(QStringLiteral("currentAccount"), accountName); | 183 | settings.setValue(QStringLiteral("currentAccount"), accountName); | ||
184 | settings.sync(); | 184 | settings.sync(); | ||
185 | mCurrentAccount = account; | 185 | mCurrentAccount = account; | ||
186 | Q_EMIT currentAccountChanged(); | 186 | Q_EMIT currentAccountChanged(showLastRoom); | ||
187 | } | 187 | } | ||
188 | } else { | 188 | } else { | ||
189 | qCWarning(RUQOLA_LOG) << "AccountName " << accountName << " is not found on system. Fallback to default one."; | 189 | qCWarning(RUQOLA_LOG) << "AccountName " << accountName << " is not found on system. Fallback to default one."; | ||
190 | } | 190 | } | ||
191 | } | 191 | } | ||
192 | 192 | | |||
193 | QString AccountManager::currentAccount() const | 193 | QString AccountManager::currentAccount() const | ||
194 | { | 194 | { | ||
195 | return mCurrentAccount ? mCurrentAccount->accountName() : QString(); | 195 | return mCurrentAccount ? mCurrentAccount->accountName() : QString(); | ||
196 | } | 196 | } | ||
197 | 197 | | |||
198 | void AccountManager::removeAccount(const QString &accountName) | 198 | void AccountManager::removeAccount(const QString &accountName) | ||
199 | { | 199 | { | ||
200 | mRocketChatAccountModel->removeAccount(accountName); | 200 | mRocketChatAccountModel->removeAccount(accountName); | ||
201 | if (mRocketChatAccountModel->accountNumber() > 0) { | 201 | if (mRocketChatAccountModel->accountNumber() > 0) { | ||
202 | mCurrentAccount = mRocketChatAccountModel->account(0); | 202 | mCurrentAccount = mRocketChatAccountModel->account(0); | ||
203 | } else { | 203 | } else { | ||
204 | //TODO create new dummy account ! | 204 | //TODO create new dummy account ! | ||
205 | } | 205 | } | ||
206 | Q_EMIT currentAccountChanged(); | 206 | Q_EMIT currentAccountChanged(false /*showLastRoom*/); | ||
207 | } | 207 | } | ||
208 | 208 | | |||
209 | RocketChatAccountModel *AccountManager::rocketChatAccountModel() const | 209 | RocketChatAccountModel *AccountManager::rocketChatAccountModel() const | ||
210 | { | 210 | { | ||
211 | return mRocketChatAccountModel; | 211 | return mRocketChatAccountModel; | ||
212 | } | 212 | } |