#include "config.h"
#include "tray/UserModel.h"
+#include <QDesktopServices>
#include <QGuiApplication>
#include <QQmlComponent>
#include <QQmlEngine>
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
_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();
}
{
}
-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)
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 {
}
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 {
return (trayScreen->geometry().height() - trayScreen->availableGeometry().height()) + 6;
}
}
-
-
} // namespace OCC
Q_INVOKABLE void showWindow();
private slots:
- void slotChangeActivityModel(const AccountStatePtr account);
+ void slotChangeActivityModel();
private:
- AccountStatePtr _currentAccount;
QQmlEngine *_trayEngine;
QQmlComponent *_trayComponent;
QQmlContext *_trayContext;
QHash<int, QByteArray> roles;
roles[PathRole] = "path";
roles[MessageRole] = "message";
+ roles[ActionRole] = "type";
+ roles[ActionIconRole] = "icon";
+ roles[ActionTextRole] = "subject";
+ roles[ObjectTypeRole] = "objectType";
return roles;
}
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()) {
}
}
}
- return QVariant();
+ return QString();
case ActionsLinksRole:{
QList<QVariant> customList;
foreach (ActivityLink customItem, a._links) {
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){
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;
return _account->hasTalk();
}
+bool User::hasActivities() const
+{
+ return _account->account()->capabilities().hasActivities();
+}
+
bool User::isCurrentUser() const
{
return _isCurrentUser;
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));
return _users[currentUserIndex()].getActivityModel();
}
+bool UserModel::currentUserHasActivities()
+{
+ return _users[currentUserIndex()].hasActivities();
+}
+
/*-------------------------------------------------------------------------------------*/
ImageProvider::ImageProvider()
QString name() const;
QString server(bool shortened = true) const;
bool serverHasTalk() const;
+ bool hasActivities() const;
QImage avatar() const;
QString id() const;
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);
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
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