Merge pull request #6637 from nextcloud/feature/nc-assistance

Display the NC assistant in the main Window
This commit is contained in:
Camila Ayres 2024-06-25 16:26:48 +02:00 committed by GitHub
commit 7db343b8a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 91 additions and 30 deletions

View file

@ -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
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 {

View file

@ -470,7 +470,7 @@ void User::slotRefreshNotifications()
void User::slotRebuildNavigationAppList()
{
emit serverHasTalkChanged();
emit featuredAppChanged();
// Rebuild App list
UserAppsModel::instance()->buildAppList();
}
@ -1036,6 +1036,22 @@ bool User::serverHasTalk() const
return talkApp() != nullptr;
}
bool User::isFeaturedAppEnabled() const
{
return isNcAssistantEnabled() || serverHasTalk();
}
QString User::featuredAppIcon() const
{
return isNcAssistantEnabled() ? "image://svgimage-custom-color/nc-assistant-app.svg"
: "image://svgimage-custom-color/talk-app.svg";
}
QString User::featuredAppAccessibleName() const
{
return isNcAssistantEnabled() ? tr("Open Nextcloud Assistant in browser") : tr("Open Nextcloud Talk in browser");
}
AccountApp *User::talkApp() const
{
return _account->findApp(QStringLiteral("spreed"));
@ -1046,6 +1062,11 @@ bool User::hasActivities() const
return _account->account()->capabilities().hasActivities();
}
bool User::isNcAssistantEnabled() const
{
return _account->account()->capabilities().ncAssistantEnabled();
}
QColor User::headerColor() const
{
return _account->account()->headerColor();
@ -1329,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())
@ -1364,6 +1372,30 @@ void UserModel::openCurrentAccountFolderFromTrayInfo(const QString &fullRemotePa
_users[_currentUserId]->openFolderLocallyOrInBrowser(fullRemotePath);
}
void UserModel::openCurrentAccountFeaturedApp()
{
if (!currentUser()) {
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)
{
Q_ASSERT(id < _users.size());
@ -1630,10 +1662,11 @@ void UserAppsModel::buildAppList()
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()) {
continue;
}
beginInsertRows(QModelIndex(), rowCount(), rowCount());
_apps << app;

View file

@ -56,7 +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 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)
@ -79,10 +81,13 @@ public:
[[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;
@ -103,7 +108,7 @@ public:
signals:
void nameChanged();
void hasLocalFolderChanged();
void serverHasTalkChanged();
void featuredAppChanged();
void avatarChanged();
void accountStateChanged();
void statusChanged();
@ -168,6 +173,8 @@ private:
void checkAndRemoveSeenActivities(const ActivityList &list, const int numTalkNotificationsReceived);
[[nodiscard]] bool serverHasTalk() const;
AccountStatePtr _account;
bool _isCurrentUser;
ActivityListModel *_activityModel;
@ -248,9 +255,9 @@ signals:
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);

View file

@ -17,7 +17,7 @@
#include <QVariantMap>
#include <QLoggingCategory>
#include <QUrl>
#include <QVersionNumber>
#include <QDebug>
namespace OCC {
@ -277,6 +277,25 @@ 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 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();

View file

@ -69,6 +69,7 @@ public:
[[nodiscard]] bool filesLockTypeAvailable() const;
[[nodiscard]] bool userStatus() const;
[[nodiscard]] bool userStatusSupportsEmoji() const;
[[nodiscard]] bool ncAssistantEnabled() const;
[[nodiscard]] QColor serverColor() const;
[[nodiscard]] QColor serverTextColor() const;

View file

@ -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>

View file

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#fff">
<path d="M19,1L17.74,3.75L15,5L17.74,6.26L19,9L20.25,6.26L23,5L20.25,3.75M9,4L6.5,9.5L1,12L6.5,14.5L9,20L11.5,14.5L17,12L11.5,9.5M19,15L17.74,17.74L15,19L17.74,20.25L19,23L20.25,20.25L23,19L20.25,17.74" />
</svg>

After

Width:  |  Height:  |  Size: 290 B