From e0641df727810c223eee501c85824c13362663fd Mon Sep 17 00:00:00 2001 From: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Date: Fri, 3 Jan 2020 16:15:15 +0100 Subject: [PATCH] First real activity connection Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> --- src/gui/systray.cpp | 37 ++++++++++++++---------------- src/gui/systray.h | 3 +-- src/gui/tray/ActivityListModel.cpp | 31 +++++++++++++++++++------ src/gui/tray/UserModel.cpp | 12 +++++++++- src/gui/tray/UserModel.h | 2 ++ src/gui/tray/Window.qml | 18 +++++++++++++-- 6 files changed, 71 insertions(+), 32 deletions(-) diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index c5f1d1723..aaf35a10b 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -18,6 +18,7 @@ #include "config.h" #include "tray/UserModel.h" +#include #include #include #include @@ -36,8 +37,7 @@ namespace OCC { Systray::Systray() // TODO: make singleton, provide ::instance() - : _currentAccount(nullptr) - , _trayComponent(nullptr) + : _trayComponent(nullptr) , _trayContext(nullptr) { // Create QML tray engine, build component, set C++ backend context used in window.qml @@ -46,17 +46,17 @@ Systray::Systray() // TODO: make singleton, provide ::instance() _trayEngine->addImageProvider("avatars", new ImageProvider); _trayEngine->rootContext()->setContextProperty("userModelBackend", UserModel::instance()); _trayEngine->rootContext()->setContextProperty("systrayBackend", this); + _trayComponent = new QQmlComponent(_trayEngine, QUrl(QStringLiteral("qrc:/qml/src/gui/tray/Window.qml"))); _trayContext = _trayEngine->contextForObject(_trayComponent->create()); - // TODO: hack to pass the icon to QML - //ctxt->setContextProperty("theme", QLatin1String("colored")); - //ctxt->setContextProperty("filename", "state-offline"); - if (!AccountManager::instance()->accounts().isEmpty()) { - slotChangeActivityModel(AccountManager::instance()->accounts().first()); + slotChangeActivityModel(); } + connect(UserModel::instance(), &UserModel::newUserSelected, + this, &Systray::slotChangeActivityModel); + hideWindow(); } @@ -64,11 +64,10 @@ Systray::~Systray() { } -void Systray::slotChangeActivityModel(const AccountStatePtr account) +void Systray::slotChangeActivityModel() { - _currentAccount = account; - emit currentUserChanged(); _trayEngine->rootContext()->setContextProperty("activityModel", UserModel::instance()->currentActivityModel()); + emit currentUserChanged(); } void Systray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint) @@ -109,10 +108,10 @@ int Systray::calcTrayWindowX() int trayIconTopCenterX = (this->geometry().topRight() - ((this->geometry().topRight() - this->geometry().topLeft()) * 0.5)).x(); int trayIconTopCenterY = (this->geometry().topRight() - ((this->geometry().topRight() - this->geometry().topLeft()) * 0.5)).y(); - if ( (trayScreen->geometry().width() - trayIconTopCenterX) < (trayScreen->geometry().width() * 0.5) ) { + if ((trayScreen->geometry().width() - trayIconTopCenterX) < (trayScreen->geometry().width() * 0.5)) { // tray icon is on right side of the screen - if ( ((trayScreen->geometry().width() - trayIconTopCenterX) < trayScreen->geometry().height() - trayIconTopCenterY) - && ((trayScreen->geometry().width() - trayIconTopCenterX) < trayIconTopCenterY) ) { + if (((trayScreen->geometry().width() - trayIconTopCenterX) < trayScreen->geometry().height() - trayIconTopCenterY) + && ((trayScreen->geometry().width() - trayIconTopCenterX) < trayIconTopCenterY)) { // taskbar is on the right return trayScreen->availableSize().width() - 400 - 6; } else { @@ -132,20 +131,20 @@ int Systray::calcTrayWindowX() } int Systray::calcTrayWindowY() { -#if QT_VERSION >= QT_VERSION_CHECK(5,10,0) +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) QScreen *trayScreen = QGuiApplication::screenAt(this->geometry().topRight()); #else QScreen *trayScreen = QGuiApplication::primaryScreen(); #endif - + // get coordinates from top center point of tray icon int trayIconTopCenterX = (this->geometry().topRight() - ((this->geometry().topRight() - this->geometry().topLeft()) * 0.5)).x(); int trayIconTopCenterY = (this->geometry().topRight() - ((this->geometry().topRight() - this->geometry().topLeft()) * 0.5)).y(); - if ( (trayScreen->geometry().height() - trayIconTopCenterY) < (trayScreen->geometry().height() * 0.5) ) { + if ((trayScreen->geometry().height() - trayIconTopCenterY) < (trayScreen->geometry().height() * 0.5)) { // tray icon is on bottom side of the screen - if ( ((trayScreen->geometry().height() - trayIconTopCenterY) < trayScreen->geometry().width() - trayIconTopCenterX ) - && ((trayScreen->geometry().height() - trayIconTopCenterY) < trayIconTopCenterX) ) { + if (((trayScreen->geometry().height() - trayIconTopCenterY) < trayScreen->geometry().width() - trayIconTopCenterX) + && ((trayScreen->geometry().height() - trayIconTopCenterY) < trayIconTopCenterX)) { // taskbar is on the bottom return trayScreen->availableSize().height() - 500 - 6; } else { @@ -161,6 +160,4 @@ int Systray::calcTrayWindowY() return (trayScreen->geometry().height() - trayScreen->availableGeometry().height()) + 6; } } - - } // namespace OCC diff --git a/src/gui/systray.h b/src/gui/systray.h index 50c277186..bb02eecef 100644 --- a/src/gui/systray.h +++ b/src/gui/systray.h @@ -58,10 +58,9 @@ signals: Q_INVOKABLE void showWindow(); private slots: - void slotChangeActivityModel(const AccountStatePtr account); + void slotChangeActivityModel(); private: - AccountStatePtr _currentAccount; QQmlEngine *_trayEngine; QQmlComponent *_trayComponent; QQmlContext *_trayContext; diff --git a/src/gui/tray/ActivityListModel.cpp b/src/gui/tray/ActivityListModel.cpp index 48ec7d018..3c8b50839 100644 --- a/src/gui/tray/ActivityListModel.cpp +++ b/src/gui/tray/ActivityListModel.cpp @@ -45,6 +45,10 @@ QHash ActivityListModel::roleNames() const QHash roles; roles[PathRole] = "path"; roles[MessageRole] = "message"; + roles[ActionRole] = "type"; + roles[ActionIconRole] = "icon"; + roles[ActionTextRole] = "subject"; + roles[ObjectTypeRole] = "objectType"; return roles; } @@ -73,7 +77,8 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const if(folder) relPath.prepend(folder->remotePath()); list = FolderMan::instance()->findFileInLocalFolders(relPath, ast->account()); if (list.count() > 0) { - return QVariant(list.at(0)); + QString path = "file:///" + QString(list.at(0)); + return QUrl(path); } // File does not exist anymore? Let's try to open its path if(QFileInfo(relPath).exists()) { @@ -83,7 +88,7 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const } } } - return QVariant(); + return QString(); case ActionsLinksRole:{ QList customList; foreach (ActivityLink customItem, a._links) { @@ -96,13 +101,13 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const case ActionIconRole:{ ActionIcon actionIcon; if(a._type == Activity::NotificationType){ - /*QIcon cachedIcon = ServerNotificationHandler::iconCache.value(a._id); + QIcon cachedIcon; if(!cachedIcon.isNull()) { actionIcon.iconType = ActivityIconType::iconUseCached; actionIcon.cachedIcon = cachedIcon; } else { actionIcon.iconType = ActivityIconType::iconBell; - }*/ + } } else if(a._type == Activity::SyncResultType){ actionIcon.iconType = ActivityIconType::iconStateError; } else if(a._type == Activity::SyncFileItemType){ @@ -131,13 +136,25 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const case ObjectTypeRole: return a._objectType; case ActionRole:{ - QVariant type; - type.setValue(a._type); - return type; + switch (a._type) { + case Activity::ActivityType: + return "Activity"; + case Activity::NotificationType: + return "Notification"; + case Activity::SyncFileItemType: + return "File"; + case Activity::SyncResultType: + return "Sync"; + default: + return QVariant(); + } } case ActionTextRole: return a._subject; case MessageRole: + if (a._message.isEmpty()) { + return QString("No description available."); + } return a._message; case LinkRole: return a._link; diff --git a/src/gui/tray/UserModel.cpp b/src/gui/tray/UserModel.cpp index b7c6d5fc7..e7103a65a 100644 --- a/src/gui/tray/UserModel.cpp +++ b/src/gui/tray/UserModel.cpp @@ -86,6 +86,11 @@ bool User::serverHasTalk() const return _account->hasTalk(); } +bool User::hasActivities() const +{ + return _account->account()->capabilities().hasActivities(); +} + bool User::isCurrentUser() const { return _isCurrentUser; @@ -195,7 +200,7 @@ Q_INVOKABLE void UserModel::openCurrentAccountTalk() Q_INVOKABLE void UserModel::openCurrentAccountServer() { QString url = _users[_currentUserId].server(false); - if (! (url.contains("http://") || url.contains("https://")) ) { + if (!(url.contains("http://") || url.contains("https://"))) { url = "https://" + _users[_currentUserId].server(false); } QDesktopServices::openUrl(QUrl(url)); @@ -251,6 +256,11 @@ ActivityListModel *UserModel::currentActivityModel() return _users[currentUserIndex()].getActivityModel(); } +bool UserModel::currentUserHasActivities() +{ + return _users[currentUserIndex()].hasActivities(); +} + /*-------------------------------------------------------------------------------------*/ ImageProvider::ImageProvider() diff --git a/src/gui/tray/UserModel.h b/src/gui/tray/UserModel.h index 4b5008ead..d68c2bc9b 100644 --- a/src/gui/tray/UserModel.h +++ b/src/gui/tray/UserModel.h @@ -28,6 +28,7 @@ public: QString name() const; QString server(bool shortened = true) const; bool serverHasTalk() const; + bool hasActivities() const; QImage avatar() const; QString id() const; @@ -61,6 +62,7 @@ public: Q_INVOKABLE bool isCurrentUserConnected(); Q_INVOKABLE QString currentUserName(); Q_INVOKABLE QString currentUserServer(); + Q_INVOKABLE bool currentUserHasActivities(); Q_INVOKABLE bool currentServerHasTalk(); Q_INVOKABLE void switchCurrentUser(const int &id); diff --git a/src/gui/tray/Window.qml b/src/gui/tray/Window.qml index 37e8658e0..23a6f5feb 100644 --- a/src/gui/tray/Window.qml +++ b/src/gui/tray/Window.qml @@ -393,17 +393,22 @@ Window { sourceSize.width: 48 } Column { + id: activityTextColumn Layout.leftMargin: 6 spacing: 4 Layout.alignment: Qt.AlignLeft Text { id: activityTextTitle - text: path + text: subject + width: 220 + elide: Text.ElideRight font.pointSize: 9 } Text { id: activityTextInfo - text: message + text: path + width: 220 + elide: Text.ElideRight font.pointSize: 8 } } @@ -412,19 +417,28 @@ Window { Layout.fillWidth: true } Button { + id: activityButton1 Layout.preferredWidth: activityItem.height Layout.preferredHeight: activityItem.height Layout.alignment: Qt.AlignRight flat: true + hoverEnabled: false + visible: (path === "") ? false : true display: AbstractButton.IconOnly icon.source: "qrc:///client/resources/files.svg" icon.color: "transparent" + + onClicked: + { + Qt.openUrlExternally(path) + } } Button { Layout.preferredWidth: activityItem.height Layout.preferredHeight: activityItem.height Layout.alignment: Qt.AlignRight flat: true + hoverEnabled: false display: AbstractButton.IconOnly icon.source: "qrc:///client/resources/public.svg" icon.color: "transparent" -- 2.30.2