Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display the NC assistant in the main Window #6637

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/gui/tray/Window.qml
Original file line number Diff line number Diff line change
Expand Up @@ -621,21 +621,18 @@ ApplicationWindow {
}

HeaderButton {
id: trayWindowTalkButton

visible: UserModel.currentUser && UserModel.currentUser.serverHasTalk
icon.source: "image://svgimage-custom-color/talk-app.svg" + "/" + Style.currentUserHeaderTextColor
icon.color: Style.currentUserHeaderTextColor
onClicked: UserModel.openCurrentAccountTalk()
id: trayWindowFeaturedAppButton
visible: UserModel.currentUser.isFeaturedAppEnabled
icon.source: UserModel.currentUser.featuredAppIcon + "/" + Style.currentUserHeaderTextColor
camilasan marked this conversation as resolved.
Show resolved Hide resolved
onClicked: UserModel.openCurrentAccountFeaturedApp()

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

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

}

HeaderButton {
Expand Down
65 changes: 49 additions & 16 deletions src/gui/tray/usermodel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "notificationhandler.h"

Check notice on line 1 in src/gui/tray/usermodel.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/tray/usermodel.cpp

File src/gui/tray/usermodel.cpp does not conform to Custom style guidelines. (lines 1046, 1396)
#include "usermodel.h"

#include "accountmanager.h"
Expand Down Expand Up @@ -470,7 +470,7 @@

void User::slotRebuildNavigationAppList()
{
emit serverHasTalkChanged();
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 @@ -1036,7 +1036,23 @@
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 All @@ -1046,7 +1062,12 @@
return _account->account()->capabilities().hasActivities();
}

bool User::isNcAssistantEnabled() const

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

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1065: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 1070 in src/gui/tray/usermodel.cpp

View workflow job for this annotation

GitHub Actions / build

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

use a trailing return type for this function
{
return _account->account()->headerColor();
}
Expand Down Expand Up @@ -1329,19 +1350,6 @@
_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 @@ -1364,7 +1372,31 @@
_users[_currentUserId]->openFolderLocallyOrInBrowser(fullRemotePath);
}

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()) {
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());
}
}


void UserModel::setCurrentUserId(const int id)

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

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1399: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 +1662,11 @@

if (UserModel::instance()->appList().count() > 0) {
const auto talkApp = UserModel::instance()->currentUser()->talkApp();
foreach (AccountApp *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())
if (talkApp && app->id() == talkApp->id() && !UserModel::instance()->currentUser()->isNcAssistantEnabled()) {
camilasan marked this conversation as resolved.
Show resolved Hide resolved
mgallien marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

beginInsertRows(QModelIndex(), rowCount(), rowCount());
_apps << app;
Expand Down
15 changes: 11 additions & 4 deletions src/gui/tray/usermodel.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef USERMODEL_H
#define USERMODEL_H

#include <QAbstractListModel>

Check failure on line 4 in src/gui/tray/usermodel.h

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.h:4:10 [clang-diagnostic-error]

'QAbstractListModel' file not found
#include <QImage>
#include <QDateTime>
#include <QStringList>
Expand Down Expand Up @@ -56,7 +56,9 @@
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 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 @@ -79,10 +81,13 @@
[[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;
[[nodiscard]] bool isNcAssistantEnabled() const;
[[nodiscard]] QColor accentColor() const;
[[nodiscard]] QColor headerColor() const;
[[nodiscard]] QColor headerTextColor() const;
Expand All @@ -103,7 +108,7 @@
signals:
void nameChanged();
void hasLocalFolderChanged();
void serverHasTalkChanged();
void featuredAppChanged();
void avatarChanged();
void accountStateChanged();
void statusChanged();
Expand Down Expand Up @@ -168,6 +173,8 @@

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

[[nodiscard]] bool serverHasTalk() const;

AccountStatePtr _account;
bool _isCurrentUser;
ActivityListModel *_activityModel;
Expand Down Expand Up @@ -248,9 +255,9 @@
public slots:
void fetchCurrentActivityModel();
void openCurrentAccountLocalFolder();
void openCurrentAccountTalk();
void openCurrentAccountServer();
void openCurrentAccountFolderFromTrayInfo(const QString &fullRemotePath);
void openCurrentAccountFeaturedApp();
void setCurrentUserId(const int id);
void login(const int id);
void logout(const int id);
Expand Down
21 changes: 20 additions & 1 deletion src/libsync/capabilities.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/libsync/capabilities.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/libsync/capabilities.cpp

File src/libsync/capabilities.cpp does not conform to Custom style guidelines. (lines 282, 283, 288)
* Copyright (C) by Roeland Jago Douma <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -17,7 +17,7 @@
#include <QVariantMap>
#include <QLoggingCategory>
#include <QUrl>

#include <QVersionNumber>
#include <QDebug>

namespace OCC {
Expand Down Expand Up @@ -277,6 +277,25 @@
return userStatusMap.value("supports_emoji", false).toBool();
}

bool Capabilities::ncAssistantEnabled() const
{
if (_capabilities.contains("assistant")
&& _capabilities["assistant"].toMap()["enabled"].toBool()) {

const auto minimumVersion = QVersionNumber(1, 0, 9);
const auto versionString = _capabilities["assistant"].toMap()["version"].toString();

if (const auto currentVersion = QVersionNumber::fromString(versionString);
QVersionNumber::compare(currentVersion, minimumVersion) >= 0) {
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 @@ -16,7 +16,7 @@
#ifndef CAPABILITIES_H
#define CAPABILITIES_H

#include "owncloudlib.h"

Check failure on line 19 in src/libsync/capabilities.h

View workflow job for this annotation

GitHub Actions / build

src/libsync/capabilities.h:19:10 [clang-diagnostic-error]

'owncloudlib.h' file not found

#include <QVariantMap>
#include <QStringList>
Expand Down Expand Up @@ -69,6 +69,7 @@
[[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.
Loading