First real activity connection
authorDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Fri, 3 Jan 2020 15:15:15 +0000 (16:15 +0100)
committerDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Fri, 3 Jan 2020 15:15:15 +0000 (16:15 +0100)
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
src/gui/systray.cpp
src/gui/systray.h
src/gui/tray/ActivityListModel.cpp
src/gui/tray/UserModel.cpp
src/gui/tray/UserModel.h
src/gui/tray/Window.qml

index c5f1d1723cd574ceed175badfb3d19c7617a5685..aaf35a10b6e5546cfd5381c2c8cbc20c82a54808 100644 (file)
@@ -18,6 +18,7 @@
 #include "config.h"
 #include "tray/UserModel.h"
 
+#include <QDesktopServices>
 #include <QGuiApplication>
 #include <QQmlComponent>
 #include <QQmlEngine>
@@ -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
index 50c277186bc49a07c00dfbb4135a3fc167537790..bb02eecef447923276a2143c84faa3914d846a8d 100644 (file)
@@ -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;
index 48ec7d018f51f175177d73cce03237c85c3dfa0e..3c8b5083969069733f6fcd415d7bf607b839548a 100644 (file)
@@ -45,6 +45,10 @@ QHash<int, QByteArray> ActivityListModel::roleNames() const
     QHash<int, QByteArray> 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<QVariant> 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;
index b7c6d5fc711e57b3af3d369e42b2cefeaf3a43bd..e7103a65ad2197290771f262438bec08386070f9 100644 (file)
@@ -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()
index 4b5008ead19ae460885d40acfac722081d05b592..d68c2bc9bbc34db837dfc581f50df4a6c3434238 100644 (file)
@@ -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);
 
index 37e8658e01bbf525f6c02d67a5a4d83d7c9723f0..23a6f5febbb204057762a3b6f14ef713ac61b794 100644 (file)
@@ -393,17 +393,22 @@ Window {
                     sourceSize.width: 48\r
                 }\r
                 Column {\r
+                    id: activityTextColumn\r
                     Layout.leftMargin: 6\r
                     spacing: 4\r
                     Layout.alignment: Qt.AlignLeft\r
                     Text {\r
                         id: activityTextTitle\r
-                        text: path\r
+                        text: subject\r
+                        width: 220\r
+                        elide: Text.ElideRight\r
                         font.pointSize: 9\r
                     }\r
                     Text {\r
                         id: activityTextInfo\r
-                        text: message\r
+                        text: path\r
+                        width: 220\r
+                        elide: Text.ElideRight\r
                         font.pointSize: 8\r
                     }\r
                 }\r
@@ -412,19 +417,28 @@ Window {
                     Layout.fillWidth: true\r
                 }\r
                 Button {\r
+                    id: activityButton1\r
                     Layout.preferredWidth: activityItem.height\r
                     Layout.preferredHeight: activityItem.height\r
                     Layout.alignment: Qt.AlignRight\r
                     flat: true\r
+                    hoverEnabled: false\r
+                    visible: (path === "") ? false : true\r
                     display: AbstractButton.IconOnly\r
                     icon.source: "qrc:///client/resources/files.svg"\r
                     icon.color: "transparent"\r
+\r
+                    onClicked:\r
+                    {\r
+                         Qt.openUrlExternally(path)\r
+                    }\r
                 }\r
                 Button {\r
                     Layout.preferredWidth: activityItem.height\r
                     Layout.preferredHeight: activityItem.height\r
                     Layout.alignment: Qt.AlignRight\r
                     flat: true\r
+                    hoverEnabled: false\r
                     display: AbstractButton.IconOnly\r
                     icon.source: "qrc:///client/resources/public.svg"\r
                     icon.color: "transparent"\r