mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-24 21:35:47 +03:00
More stuff regarding tray/UserModel.cpp
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
This commit is contained in:
parent
53abf5a316
commit
4478399282
7 changed files with 124 additions and 143 deletions
|
@ -108,7 +108,7 @@ set(client_SRCS
|
||||||
elidedlabel.cpp
|
elidedlabel.cpp
|
||||||
iconjob.cpp
|
iconjob.cpp
|
||||||
remotewipe.cpp
|
remotewipe.cpp
|
||||||
tray/menumodel.cpp
|
tray/UserModel.cpp
|
||||||
creds/credentialsfactory.cpp
|
creds/credentialsfactory.cpp
|
||||||
creds/httpcredentialsgui.cpp
|
creds/httpcredentialsgui.cpp
|
||||||
creds/oauth.cpp
|
creds/oauth.cpp
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include "systray.h"
|
#include "systray.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "tray/menumodel.h"
|
#include "tray/UserModel.h"
|
||||||
|
|
||||||
#include <QQmlComponent>
|
#include <QQmlComponent>
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
|
@ -55,7 +55,6 @@ Systray::Systray() // TODO: make singleton, provide ::instance()
|
||||||
slotChangeActivityModel(AccountManager::instance()->accounts().first());
|
slotChangeActivityModel(AccountManager::instance()->accounts().first());
|
||||||
}
|
}
|
||||||
|
|
||||||
//_trayContext->setContextProperty("serverTest", QVariant("Test"));
|
|
||||||
//connect(AccountManager::instance(), &AccountManager::accountAdded,
|
//connect(AccountManager::instance(), &AccountManager::accountAdded,
|
||||||
// this, &Systray::slotChangeActivityModel);
|
// this, &Systray::slotChangeActivityModel);
|
||||||
}
|
}
|
||||||
|
@ -64,46 +63,6 @@ Systray::~Systray()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_INVOKABLE int Systray::numAccounts() const
|
|
||||||
{
|
|
||||||
return AccountManager::instance()->accounts().size();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Lots of memory shifting here
|
|
||||||
// Probably OK because the avatar is not changing a trillion times per second
|
|
||||||
// But should consider moving to a generic ImageProvider helper class for img/QML-provision
|
|
||||||
Q_INVOKABLE QString Systray::currentAvatar() const
|
|
||||||
{
|
|
||||||
QByteArray bArray;
|
|
||||||
QBuffer buffer(&bArray);
|
|
||||||
buffer.open(QIODevice::WriteOnly);
|
|
||||||
AvatarJob::makeCircularAvatar(_currentAccount->account()->avatar()).save(&buffer, "PNG");
|
|
||||||
|
|
||||||
QString img("data:image/png;base64,");
|
|
||||||
img.append(QString::fromLatin1(bArray.toBase64().data()));
|
|
||||||
return img;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
void Systray::slotChangeActivityModel(const AccountStatePtr account)
|
||||||
{
|
{
|
||||||
_currentAccount = account;
|
_currentAccount = account;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
|
|
||||||
#include "accountmanager.h"
|
#include "accountmanager.h"
|
||||||
#include "tray/menumodel.h"
|
#include "tray/UserModel.h"
|
||||||
|
|
||||||
class QIcon;
|
class QIcon;
|
||||||
|
|
||||||
|
@ -48,11 +48,6 @@ public:
|
||||||
void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000);
|
void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000);
|
||||||
void setToolTip(const QString &tip);
|
void setToolTip(const QString &tip);
|
||||||
|
|
||||||
Q_INVOKABLE QString currentAvatar() const;
|
|
||||||
Q_INVOKABLE QString currentAccountServer() const;
|
|
||||||
Q_INVOKABLE QString currentAccountUser() const;
|
|
||||||
Q_INVOKABLE int numAccounts() const;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void currentUserChanged();
|
void currentUserChanged();
|
||||||
|
|
||||||
|
|
108
src/gui/tray/UserModel.cpp
Normal file
108
src/gui/tray/UserModel.cpp
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
#include "accountmanager.h"
|
||||||
|
#include "UserModel.h"
|
||||||
|
|
||||||
|
namespace OCC {
|
||||||
|
|
||||||
|
User::User(const AccountStatePtr &account)
|
||||||
|
: _account(account)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString User::name() const
|
||||||
|
{
|
||||||
|
return _account->account()->davDisplayName();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString User::server() const
|
||||||
|
{
|
||||||
|
QString serverUrl = _account->account()->url().toString();
|
||||||
|
serverUrl.replace(QLatin1String("https://"), QLatin1String(""));
|
||||||
|
serverUrl.replace(QLatin1String("http://"), QLatin1String(""));
|
||||||
|
return serverUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Lots of memory shifting here
|
||||||
|
// Probably OK because the avatar is not changing a trillion times per second
|
||||||
|
// But should consider moving to a generic ImageProvider helper class for img/QML-provision
|
||||||
|
QString User::avatar() const
|
||||||
|
{
|
||||||
|
QByteArray bArray;
|
||||||
|
QBuffer buffer(&bArray);
|
||||||
|
buffer.open(QIODevice::WriteOnly);
|
||||||
|
AvatarJob::makeCircularAvatar(_account->account()->avatar()).save(&buffer, "PNG");
|
||||||
|
|
||||||
|
QString img("data:image/png;base64,");
|
||||||
|
img.append(QString::fromLatin1(bArray.toBase64().data()));
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
UserModel::UserModel(QObject *parent)
|
||||||
|
: QAbstractListModel()
|
||||||
|
, _currentUser()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < AccountManager::instance()->accounts().size(); i++) {
|
||||||
|
addUser(User(AccountManager::instance()->accounts().at(i)));
|
||||||
|
}
|
||||||
|
_currentUser = &_users.first();
|
||||||
|
}
|
||||||
|
|
||||||
|
UserModel::~UserModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_INVOKABLE QString UserModel::currentUserAvatar()
|
||||||
|
{
|
||||||
|
return _currentUser->avatar();
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_INVOKABLE QString UserModel::currentUserName()
|
||||||
|
{
|
||||||
|
return _currentUser->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_INVOKABLE QString UserModel::currentUserServer()
|
||||||
|
{
|
||||||
|
return _currentUser->server();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserModel::addUser(const User &user)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||||
|
_users << user;
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
int UserModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent);
|
||||||
|
return _users.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant UserModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.row() < 0 || index.row() >= _users.count()) {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
const User &user = _users[index.row()];
|
||||||
|
if (role == NameRole) {
|
||||||
|
return user.name();
|
||||||
|
} else if (role == ServerRole) {
|
||||||
|
return user.server();
|
||||||
|
} else if (role == AvatarRole) {
|
||||||
|
return user.avatar();
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> UserModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NameRole] = "name";
|
||||||
|
roles[ServerRole] = "server";
|
||||||
|
roles[AvatarRole] = "avatar";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,21 +4,21 @@
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
#include "accountmanager.h"
|
||||||
|
|
||||||
namespace OCC {
|
namespace OCC {
|
||||||
|
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
User(const QString &name, const QString &server, const QString &avatar);
|
User(const AccountStatePtr &account);
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
QString server() const;
|
QString server() const;
|
||||||
QString avatar() const;
|
QString avatar() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString _name;
|
AccountStatePtr _account;
|
||||||
QString _server;
|
|
||||||
QString _avatar;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class UserModel : public QAbstractListModel
|
class UserModel : public QAbstractListModel
|
||||||
|
@ -35,6 +35,10 @@ public:
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
Q_INVOKABLE QString currentUserAvatar();
|
||||||
|
Q_INVOKABLE QString currentUserName();
|
||||||
|
Q_INVOKABLE QString currentUserServer();
|
||||||
|
|
||||||
enum UserRoles {
|
enum UserRoles {
|
||||||
NameRole = Qt::UserRole + 1,
|
NameRole = Qt::UserRole + 1,
|
||||||
ServerRole,
|
ServerRole,
|
||||||
|
@ -46,6 +50,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<User> _users;
|
QList<User> _users;
|
||||||
|
User *_currentUser;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,78 +0,0 @@
|
||||||
#include "accountmanager.h"
|
|
||||||
#include "menumodel.h"
|
|
||||||
|
|
||||||
namespace OCC {
|
|
||||||
|
|
||||||
User::User(const QString &name, const QString &server, const QString &avatar)
|
|
||||||
: _name(name)
|
|
||||||
, _server(server)
|
|
||||||
, _avatar(avatar)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QString User::name() const
|
|
||||||
{
|
|
||||||
return _name;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString User::server() const
|
|
||||||
{
|
|
||||||
return _server;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString User::avatar() const
|
|
||||||
{
|
|
||||||
return _avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
UserModel::UserModel(QObject *parent)
|
|
||||||
: QAbstractListModel()
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < AccountManager::instance()->accounts().size(); i++) {
|
|
||||||
addUser(User("test", "test", "test"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UserModel::~UserModel()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void UserModel::addUser(const User &user)
|
|
||||||
{
|
|
||||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
|
||||||
_users << user;
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
int UserModel::rowCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(parent);
|
|
||||||
return _users.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant UserModel::data(const QModelIndex &index, int role) const
|
|
||||||
{
|
|
||||||
if (index.row() < 0 || index.row() >= _users.count()) {
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
const User &user = _users[index.row()];
|
|
||||||
if (role == NameRole) {
|
|
||||||
return user.name();
|
|
||||||
} else if (role == ServerRole) {
|
|
||||||
return user.server();
|
|
||||||
} else if (role == AvatarRole) {
|
|
||||||
return user.avatar();
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
QHash<int, QByteArray> UserModel::roleNames() const
|
|
||||||
{
|
|
||||||
QHash<int, QByteArray> roles;
|
|
||||||
roles[NameRole] = "name";
|
|
||||||
roles[ServerRole] = "server";
|
|
||||||
roles[AvatarRole] = "avatar";
|
|
||||||
return roles;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -76,17 +76,9 @@ Window {
|
||||||
radius: 4
|
radius: 4
|
||||||
}
|
}
|
||||||
|
|
||||||
/*ListView {
|
|
||||||
model: systrayBackend
|
|
||||||
delegate: UserLine {
|
|
||||||
text: name
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
Instantiator {
|
Instantiator {
|
||||||
model: systrayBackend
|
model: systrayBackend
|
||||||
delegate: UserLine {
|
delegate: UserLine {}
|
||||||
}
|
|
||||||
onObjectAdded: accountMenu.insertItem(index, object)
|
onObjectAdded: accountMenu.insertItem(index, object)
|
||||||
onObjectRemoved: accountMenu.removeItem(object)
|
onObjectRemoved: accountMenu.removeItem(object)
|
||||||
}
|
}
|
||||||
|
@ -156,7 +148,7 @@ Window {
|
||||||
height: (trayWindowHeaderBackground.height - 12)
|
height: (trayWindowHeaderBackground.height - 12)
|
||||||
Layout.leftMargin: 6
|
Layout.leftMargin: 6
|
||||||
verticalAlignment: Qt.AlignCenter
|
verticalAlignment: Qt.AlignCenter
|
||||||
source: systrayBackend.currentAvatar()
|
source: systrayBackend.currentUserAvatar()
|
||||||
Layout.preferredHeight: (trayWindowHeaderBackground.height -12)
|
Layout.preferredHeight: (trayWindowHeaderBackground.height -12)
|
||||||
Layout.preferredWidth: (trayWindowHeaderBackground.height -12)
|
Layout.preferredWidth: (trayWindowHeaderBackground.height -12)
|
||||||
}
|
}
|
||||||
|
@ -168,14 +160,14 @@ Window {
|
||||||
Layout.leftMargin: 6
|
Layout.leftMargin: 6
|
||||||
Label {
|
Label {
|
||||||
id: currentAccountUser
|
id: currentAccountUser
|
||||||
text: systrayBackend.currentAccountUser()
|
text: systrayBackend.currentUserName()
|
||||||
color: "white"
|
color: "white"
|
||||||
font.pointSize: 9
|
font.pointSize: 9
|
||||||
font.bold: true
|
font.bold: true
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
id: currentAccountServer
|
id: currentAccountServer
|
||||||
text: systrayBackend.currentAccountServer()
|
text: systrayBackend.currentUserServer()
|
||||||
color: "white"
|
color: "white"
|
||||||
font.pointSize: 8
|
font.pointSize: 8
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue