Skip to content

Commit

Permalink
Display the Nextcloud assistant icon in the main window.
Browse files Browse the repository at this point in the history
- If NC assistant is enabled in the server, display the icon
to open it instead of Talk. Talk is then displayed in the
list with the other apps.
- The direct link is only available in the assistant app >= 1.0.9.

Signed-off-by: Camila Ayres <[email protected]>
  • Loading branch information
camilasan committed Apr 25, 2024
1 parent 7e801d6 commit d5ffd28
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/gui/tray/Window.qml
Original file line number Diff line number Diff line change
Expand Up @@ -637,21 +637,20 @@ ApplicationWindow {
}

HeaderButton {
id: trayWindowTalkButton
id: trayWindowFeaturedAppButton

visible: UserModel.currentUser.serverHasTalk
icon.source: "qrc:///client/theme/white/talk-app.svg"
visible: UserModel.currentUser.isNcAssistantEnabled || UserModel.currentUser.serverHasTalk
icon.source: UserModel.currentUser.isNcAssistantEnabled? "qrc:///client/theme/white/nc-assistant-app.svg" : "qrc:///client/theme/white/talk-app.svg"
icon.color: Style.currentUserHeaderTextColor
onClicked: UserModel.openCurrentAccountTalk()
onClicked: UserModel.currentUser.isNcAssistantEnabled? UserModel.openCurrentAccountNcAssistant() : UserModel.openCurrentAccountTalk()

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

Layout.alignment: Qt.AlignRight
Layout.preferredWidth: Style.trayWindowHeaderHeight
Layout.preferredHeight: Style.trayWindowHeaderHeight

}

HeaderButton {
Expand Down
25 changes: 23 additions & 2 deletions src/gui/tray/usermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ void User::slotRefreshNotifications()
void User::slotRebuildNavigationAppList()
{
emit serverHasTalkChanged();
emit ncAssistantAvailabityChanged();

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

View workflow job for this annotation

GitHub Actions / build

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

use a trailing return type for this function
// Rebuild App list
UserAppsModel::instance()->buildAppList();
}
Expand Down Expand Up @@ -1046,6 +1047,11 @@ bool User::hasActivities() const
return _account->account()->capabilities().hasActivities();
}

bool User::isNcAssistantEnabled() 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:12 [modernize-use-trailing-return-type]

use a trailing return type for this function
{
return _account->account()->capabilities().ncAssistantEnabled();
}

QColor User::headerColor() 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:14 [modernize-use-trailing-return-type]

use a trailing return type for this function
{
return _account->account()->headerColor();
Expand Down Expand Up @@ -1364,6 +1370,20 @@ void UserModel::openCurrentAccountFolderFromTrayInfo(const QString &fullRemotePa
_users[_currentUserId]->openFolderLocallyOrInBrowser(fullRemotePath);
}

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

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

View workflow job for this annotation

GitHub Actions / build

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

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

if (currentUser()->isNcAssistantEnabled()) {

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

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1379:5 [bugprone-branch-clone]

if with identical then and else branches
QDesktopServices::openUrl(QUrl(_users[_currentUserId]->server(false).append("/apps/assistant/")));
} else {
qCWarning(lcActivity) << "The Nextcloud Assistant app is not enabled on" << currentUser()->server();
}
}


void UserModel::setCurrentUserId(const int id)

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

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1387:44 [readability-identifier-length]

parameter name 'id' is too short, expected at least 3 characters
{
Q_ASSERT(id < _users.size());
Expand Down Expand Up @@ -1630,10 +1650,11 @@ void UserAppsModel::buildAppList()

if (UserModel::instance()->appList().count() > 0) {
const auto talkApp = UserModel::instance()->currentUser()->talkApp();
foreach (AccountApp *app, UserModel::instance()->appList()) {
for (auto &app : UserModel::instance()->appList()) {
// Filter out Talk because we have a dedicated button for it
if (talkApp && app->id() == talkApp->id())
if (talkApp && app->id() == talkApp->id() && !UserModel::instance()->currentUser()->isNcAssistantEnabled()) {
continue;
}

beginInsertRows(QModelIndex(), rowCount(), rowCount());
_apps << app;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/tray/usermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class User : public QObject
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(QString avatar READ avatarUrl NOTIFY avatarChanged)
Q_PROPERTY(bool isConnected READ isConnected NOTIFY accountStateChanged)
Q_PROPERTY(UnifiedSearchResultsListModel* unifiedSearchResultsListModel READ getUnifiedSearchResultsListModel CONSTANT)
Expand All @@ -83,6 +84,7 @@ class User : public QObject
[[nodiscard]] bool serverHasUserStatus() const;
[[nodiscard]] AccountApp *talkApp() const;
[[nodiscard]] bool hasActivities() const;
[[nodiscard]] bool isNcAssistantEnabled() const;
[[nodiscard]] QColor accentColor() const;
[[nodiscard]] QColor headerColor() const;
[[nodiscard]] QColor headerTextColor() const;
Expand Down Expand Up @@ -113,6 +115,7 @@ 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 @@ -251,6 +254,7 @@ public slots:
void openCurrentAccountTalk();
void openCurrentAccountServer();
void openCurrentAccountFolderFromTrayInfo(const QString &fullRemotePath);
void openCurrentAccountNcAssistant();
void setCurrentUserId(const int id);
void login(const int id);
void logout(const int id);
Expand Down
17 changes: 17 additions & 0 deletions src/libsync/capabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,23 @@ bool Capabilities::userStatusSupportsEmoji() const
return userStatusMap.value("supports_emoji", false).toBool();
}

bool Capabilities::ncAssistantEnabled() const
{
if (_capabilities.contains("assistant")
&& _capabilities["assistant"].toMap()["enabled"].toBool()) {
const auto version = _capabilities["assistant"].toMap()["version"].toByteArray().split('.');
if (version.at(0).toInt() >= 1
&& version.at(1).toInt() >= 0
&& version.at(2).toInt() >= 9) {
return true;
}

qCInfo(lcServerCapabilities) << "The NC Assistant app only provides a direct link starting at 1.0.9.";
}

return false;
}

QColor Capabilities::serverColor() const
{
const auto themingMap = serverThemingMap();
Expand Down
1 change: 1 addition & 0 deletions src/libsync/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class OWNCLOUDSYNC_EXPORT Capabilities
[[nodiscard]] bool filesLockTypeAvailable() const;
[[nodiscard]] bool userStatus() const;
[[nodiscard]] bool userStatusSupportsEmoji() const;
[[nodiscard]] bool ncAssistantEnabled() const;
[[nodiscard]] QColor serverColor() const;
[[nodiscard]] QColor serverTextColor() const;

Expand Down
1 change: 1 addition & 0 deletions theme.qrc.in
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
<file>theme/white/folder.svg</file>
<file>theme/white/more-apps.svg</file>
<file>theme/white/talk-app.svg</file>
<file>theme/white/nc-assistant-app.svg</file>
<file>theme/white/caret-down.svg</file>
<file>theme/black/caret-down.svg</file>
<file>theme/white/user.svg</file>
Expand Down
3 changes: 3 additions & 0 deletions theme/white/nc-assistant-app.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d5ffd28

Please sign in to comment.