Restructures and refactorings: New systray class, handling of current user selection, integration of user information in tray window header

This commit is contained in:
Dominique Fuchs 2019-12-02 22:45:14 +01:00
parent 08d4c56886
commit 478281d853
8 changed files with 66 additions and 15 deletions

View file

@ -32,7 +32,7 @@
</qresource>
<qresource prefix="/"/>
<qresource prefix="/qml">
<file>src/gui/systemtray.qml</file>
<file>src/gui/traywindow.qml</file>
<file>src/gui/tray/init.qml</file>
<file>src/gui/tray/window.qml</file>
</qresource>
</RCC>

View file

@ -20,6 +20,7 @@
#ifndef UTILITY_H
#define UTILITY_H
#include "ocsynclib.h"
#include <QString>
#include <QByteArray>
@ -29,6 +30,7 @@
#include <QMap>
#include <QUrl>
#include <QUrlQuery>
#include <QtQuick/QQuickImageProvider>
#include <functional>
#include <memory>

View file

@ -32,11 +32,11 @@ set(client_UI_SRCS
shareusergroupwidget.ui
shareuserline.ui
sslerrordialog.ui
systemtray.qml
traywindow.qml
addcertificatedialog.ui
proxyauthdialog.ui
mnemonicdialog.ui
tray/init.qml
tray/window.qml
wizard/owncloudadvancedsetuppage.ui
wizard/owncloudconnectionmethoddialog.ui
wizard/owncloudhttpcredspage.ui

View file

@ -81,6 +81,7 @@ ownCloudGui::ownCloudGui(Application *parent)
, _app(parent)
{
_tray = new Systray();
//qmlRegisterType<Systray>("nc.desktop.systray.backend", 1, 0, "Systray");
_tray->setParent(this);
// for the beginning, set the offline icon until the account was verified
_tray->setIcon(Theme::instance()->folderOfflineIcon(/*systray?*/ true, /*currently visible?*/ false));

View file

@ -14,6 +14,7 @@
#include "accountmanager.h"
#include "systray.h"
#include "../common/utility.h"
#include "theme.h"
#include "config.h"
@ -36,23 +37,63 @@ Systray::Systray() // TODO: make singleton, provide ::instance()
: _currentAccount(nullptr)
, _trayContext(nullptr)
{
_currentAccount = AccountManager::instance()->accounts().first();
// Create QML tray engine, build component, set C++ backend context used in window.qml
QQmlEngine *engine = new QQmlEngine;
QQmlComponent systray(engine, QUrl(QStringLiteral("qrc:/qml/src/gui/systemtray.qml")));
QQmlComponent systray(engine, QUrl(QStringLiteral("qrc:/qml/src/gui/tray/init.qml")));
_trayContext = engine->contextForObject(systray.create());
systray.engine()->rootContext()->setContextProperty("systrayBackend", this);
// 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());
}
//_trayContext->setContextProperty("serverTest", QVariant("Test"));
//connect(AccountManager::instance(), &AccountManager::accountAdded,
// this, &Systray::slotChangeActivityModel);
}
Systray::~Systray()
{
}
void Systray::slotChangeActivityModel()
Q_INVOKABLE QIcon Systray::currentAvatar() const
{
QImage userAvatarImg = _currentAccount->account()->avatar();
QIcon userAvatar(QPixmap::fromImage(userAvatarImg));
return userAvatar;
}
Q_INVOKABLE QString Systray::currentAccountServer() const
{
QString serverUrl = _currentAccount->account()->url().toString();
if (serverUrl.length() > 25) {
serverUrl.truncate(23);
serverUrl.append(QByteArray("..."));
}
return serverUrl;
}
Q_INVOKABLE QString Systray::currentAccountUser() const
{
QString userName = _currentAccount->account()->davDisplayName();
if (userName.length() > 19) {
userName.truncate(17);
userName.append(QByteArray("..."));
}
return userName;
}
void Systray::slotChangeActivityModel(const AccountStatePtr account)
{
_currentAccount = account;
emit currentUserChanged();
bool test;
}
void Systray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint)

View file

@ -46,9 +46,15 @@ public:
~Systray();
void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000);
void setToolTip(const QString &tip);
Q_INVOKABLE QIcon currentAvatar() const;
Q_INVOKABLE QString currentAccountServer() const;
Q_INVOKABLE QString currentAccountUser() const;
signals:
void currentUserChanged();
private slots:
void slotChangeActivityModel();
void slotChangeActivityModel(const AccountStatePtr account);
private:
AccountStatePtr _currentAccount;

View file

@ -11,7 +11,7 @@ SystemTrayIcon {
}
onActivated: {
var component = Qt.createComponent("qrc:/qml/src/gui/traywindow.qml")
var component = Qt.createComponent("qrc:/qml/src/gui/tray/window.qml")
var win = component.createObject()
win.show()
win.raise()

View file

@ -5,6 +5,7 @@ import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0
Window {
id: trayWindow
visible: true
width: 400
@ -135,7 +136,7 @@ Window {
height: (trayWindowHeaderBackground.height - 12)
Layout.leftMargin: 6
verticalAlignment: Qt.AlignCenter
//source: "file"
source: "image://avatars/current.png"
}
Column {
@ -144,15 +145,15 @@ Window {
Layout.alignment: Qt.AlignLeft
Layout.leftMargin: 6
Label {
id: syncStatusLabel
text: "Up to date"
id: currentAccountUser
text: systrayBackend.currentAccountUser()
color: "white"
font.pointSize: 9
font.bold: true
}
Label {
id: currentUserLabel
text: "cloud.nextcloud.com"
id: currentAccountServer
text: systrayBackend.currentAccountServer()
color: "white"
font.pointSize: 8
}