Skip to content

Commit

Permalink
Move the logic for handling the featured app qml to cpp.
Browse files Browse the repository at this point in the history
Signed-off-by: Camila Ayres <[email protected]>
  • Loading branch information
camilasan committed Jun 25, 2024
1 parent 3a0021b commit 4d897e4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
11 changes: 4 additions & 7 deletions src/gui/tray/Window.qml
Original file line number Diff line number Diff line change
Expand Up @@ -622,15 +622,12 @@ ApplicationWindow {

HeaderButton {
id: trayWindowFeaturedAppButton
visible: UserModel.currentUser.isNcAssistantEnabled || UserModel.currentUser.serverHasTalk
icon.source: UserModel.currentUser.isNcAssistantEnabled
? "image:///client/theme/white/nc-assistant-app.svg" + "/" + Style.currentUserHeaderTextColor
: "image:///client/theme/white/talk-app.svg" + "/" + Style.currentUserHeaderTextColor
icon.color: Style.currentUserHeaderTextColor
onClicked: UserModel.currentUser.isNcAssistantEnabled ? UserModel.openCurrentAccountNcAssistant() : UserModel.openCurrentAccountTalk()
visible: UserModel.currentUser.isFeaturedAppEnabled
icon.source: UserModel.currentUser.featuredAppIcon + "/" + Style.currentUserHeaderTextColor
onClicked: UserModel.openCurrentAccountFeaturedApp()

Accessible.role: Accessible.Button
Accessible.name: UserModel.currentUser.isNcAssistantEnabled ? qsTr("Open Nextcloud Assistant in browser") : qsTr("Open Nextcloud Talk in browser")
Accessible.name: UserModel.currentUser.featuredAppAccessibleName
Accessible.onPressAction: trayWindowFeaturedAppButton.clicked()

Layout.alignment: Qt.AlignRight
Expand Down
52 changes: 32 additions & 20 deletions src/gui/tray/usermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,7 @@ void User::slotRefreshNotifications()

void User::slotRebuildNavigationAppList()
{
emit serverHasTalkChanged();
emit ncAssistantAvailabityChanged();
emit featuredAppChanged();

Check warning on line 473 in src/gui/tray/usermodel.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:473:10 [modernize-use-trailing-return-type]

use a trailing return type for this function
// Rebuild App list
UserAppsModel::instance()->buildAppList();
}
Expand Down Expand Up @@ -1037,6 +1036,22 @@ bool User::serverHasTalk() const
return talkApp() != nullptr;
}

bool User::isFeaturedAppEnabled() const

Check warning on line 1039 in src/gui/tray/usermodel.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1039:12 [modernize-use-trailing-return-type]

use a trailing return type for this function
{
return isNcAssistantEnabled() || serverHasTalk();
}

QString User::featuredAppIcon() const

Check warning on line 1044 in src/gui/tray/usermodel.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1044:15 [modernize-use-trailing-return-type]

use a trailing return type for this function
{
return isNcAssistantEnabled() ? "image://svgimage-custom-color/nc-assistant-app.svg"
: "image://svgimage-custom-color/talk-app.svg";
}

QString User::featuredAppAccessibleName() const

Check warning on line 1050 in src/gui/tray/usermodel.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1050:15 [modernize-use-trailing-return-type]

use a trailing return type for this function
{
return isNcAssistantEnabled() ? tr("Open Nextcloud Assistant in browser") : tr("Open Nextcloud Talk in browser");
}

AccountApp *User::talkApp() const

Check warning on line 1055 in src/gui/tray/usermodel.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1055:19 [modernize-use-trailing-return-type]

use a trailing return type for this function
{
return _account->findApp(QStringLiteral("spreed"));
Expand Down Expand Up @@ -1335,19 +1350,6 @@ void UserModel::openCurrentAccountLocalFolder()
_users[_currentUserId]->openLocalFolder();
}

void UserModel::openCurrentAccountTalk()
{
if (!currentUser())
return;

const auto talkApp = currentUser()->talkApp();
if (talkApp) {
Utility::openBrowser(talkApp->url());
} else {
qCWarning(lcActivity) << "The Talk app is not enabled on" << currentUser()->server();
}
}

void UserModel::openCurrentAccountServer()
{
if (_currentUserId < 0 || _currentUserId >= _users.size())
Expand All @@ -1370,16 +1372,26 @@ void UserModel::openCurrentAccountFolderFromTrayInfo(const QString &fullRemotePa
_users[_currentUserId]->openFolderLocallyOrInBrowser(fullRemotePath);
}

void UserModel::openCurrentAccountNcAssistant()
void UserModel::openCurrentAccountFeaturedApp()
{
if (!currentUser()) {

Check warning on line 1377 in src/gui/tray/usermodel.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1377:10 [readability-implicit-bool-conversion]

implicit conversion 'OCC::User *' -> bool
return;
}

if (!currentUser()->isFeaturedAppEnabled()) {
qCWarning(lcActivity) << "There is no feature app enabled on" << currentUser()->server();
return;
}

if (currentUser()->isNcAssistantEnabled()) {
QDesktopServices::openUrl(QUrl(_users[_currentUserId]->server(false).append("/apps/assistant/")));
} else {
qCWarning(lcActivity) << "The Nextcloud Assistant app is not enabled on" << currentUser()->server();
auto serverUrl = currentUser()->server(false);
const auto assistanceUrl = serverUrl.append("/apps/assistant/");
QDesktopServices::openUrl(QUrl::fromUserInput(assistanceUrl));
return;
}

if (const auto talkApp = currentUser()->talkApp()) {
Utility::openBrowser(talkApp->url());
}
}

Expand Down Expand Up @@ -1650,7 +1662,7 @@ void UserAppsModel::buildAppList()

if (UserModel::instance()->appList().count() > 0) {
const auto talkApp = UserModel::instance()->currentUser()->talkApp();
for (auto &app : UserModel::instance()->appList()) {
for (const auto &app : UserModel::instance()->appList()) {
// Filter out Talk because we have a dedicated button for it
if (talkApp && app->id() == talkApp->id() && !UserModel::instance()->currentUser()->isNcAssistantEnabled()) {
continue;
Expand Down
17 changes: 10 additions & 7 deletions src/gui/tray/usermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ class User : public QObject
Q_PROPERTY(QString statusMessage READ statusMessage NOTIFY statusChanged)
Q_PROPERTY(bool desktopNotificationsAllowed READ isDesktopNotificationsAllowed NOTIFY desktopNotificationsAllowedChanged)
Q_PROPERTY(bool hasLocalFolder READ hasLocalFolder NOTIFY hasLocalFolderChanged)
Q_PROPERTY(bool serverHasTalk READ serverHasTalk NOTIFY serverHasTalkChanged)
Q_PROPERTY(bool isNcAssistantEnabled READ isNcAssistantEnabled NOTIFY ncAssistantAvailabityChanged)
Q_PROPERTY(bool isFeaturedAppEnabled READ isFeaturedAppEnabled NOTIFY featuredAppChanged)
Q_PROPERTY(QString featuredAppIcon READ featuredAppIcon NOTIFY featuredAppChanged)
Q_PROPERTY(QString featuredAppAccessibleName READ featuredAppAccessibleName NOTIFY featuredAppChanged)
Q_PROPERTY(QString avatar READ avatarUrl NOTIFY avatarChanged)
Q_PROPERTY(bool isConnected READ isConnected NOTIFY accountStateChanged)
Q_PROPERTY(UnifiedSearchResultsListModel* unifiedSearchResultsListModel READ getUnifiedSearchResultsListModel CONSTANT)
Expand All @@ -80,7 +81,9 @@ class User : public QObject
[[nodiscard]] QString name() const;
[[nodiscard]] QString server(bool shortened = true) const;
[[nodiscard]] bool hasLocalFolder() const;
[[nodiscard]] bool serverHasTalk() const;
[[nodiscard]] bool isFeaturedAppEnabled() const;
[[nodiscard]] QString featuredAppIcon() const;
[[nodiscard]] QString featuredAppAccessibleName() const;
[[nodiscard]] bool serverHasUserStatus() const;
[[nodiscard]] AccountApp *talkApp() const;
[[nodiscard]] bool hasActivities() const;
Expand All @@ -105,7 +108,7 @@ class User : public QObject
signals:
void nameChanged();
void hasLocalFolderChanged();
void serverHasTalkChanged();
void featuredAppChanged();
void avatarChanged();
void accountStateChanged();
void statusChanged();
Expand All @@ -115,7 +118,6 @@ class User : public QObject
void accentColorChanged();
void sendReplyMessage(const int activityIndex, const QString &conversationToken, const QString &message, const QString &replyTo);
void groupFoldersChanged();
void ncAssistantAvailabityChanged();

public slots:
void slotItemCompleted(const QString &folder, const OCC::SyncFileItemPtr &item);
Expand Down Expand Up @@ -171,6 +173,8 @@ private slots:

void checkAndRemoveSeenActivities(const ActivityList &list, const int numTalkNotificationsReceived);

[[nodiscard]] bool serverHasTalk() const;

AccountStatePtr _account;
bool _isCurrentUser;
ActivityListModel *_activityModel;
Expand Down Expand Up @@ -251,10 +255,9 @@ class UserModel : public QAbstractListModel
public slots:
void fetchCurrentActivityModel();
void openCurrentAccountLocalFolder();
void openCurrentAccountTalk();
void openCurrentAccountServer();
void openCurrentAccountFolderFromTrayInfo(const QString &fullRemotePath);
void openCurrentAccountNcAssistant();
void openCurrentAccountFeaturedApp();
void setCurrentUserId(const int id);
void login(const int id);
void logout(const int id);
Expand Down

0 comments on commit 4d897e4

Please sign in to comment.