2015-11-02 00:23:22 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Roeland Jago Douma <roeland@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2015-11-02 00:23:22 +03:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sharee.h"
|
|
|
|
#include "ocsshareejob.h"
|
2023-02-24 16:06:29 +03:00
|
|
|
#include "theme.h"
|
2015-11-02 00:23:22 +03:00
|
|
|
|
2017-04-26 12:38:10 +03:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
2023-02-24 16:06:29 +03:00
|
|
|
namespace OCC
|
|
|
|
{
|
2017-12-28 22:33:10 +03:00
|
|
|
Q_LOGGING_CATEGORY(lcSharing, "nextcloud.gui.sharing", QtInfoMsg)
|
2017-05-09 15:24:11 +03:00
|
|
|
|
2023-02-24 16:06:29 +03:00
|
|
|
Sharee::Sharee(const QString &shareWith, const QString &displayName, const Type type, const QString &iconUrl)
|
2015-11-02 00:23:22 +03:00
|
|
|
: _shareWith(shareWith)
|
|
|
|
, _displayName(displayName)
|
|
|
|
, _type(type)
|
2023-02-24 16:06:29 +03:00
|
|
|
, _iconUrl(iconUrl)
|
2015-11-02 00:23:22 +03:00
|
|
|
{
|
2023-02-24 16:06:29 +03:00
|
|
|
if (!_iconUrl.isEmpty()) {
|
|
|
|
// make sure no color path is contained in the url
|
|
|
|
_iconUrl.replace(QStringLiteral("/black"), "");
|
|
|
|
_iconUrl.replace(QStringLiteral("/white"), "");
|
|
|
|
_iconColor = Theme::instance()->darkMode() ? QStringLiteral("white") : QStringLiteral("black");
|
|
|
|
}
|
|
|
|
updateIconUrl();
|
2015-11-02 00:23:22 +03:00
|
|
|
}
|
2015-11-05 00:00:35 +03:00
|
|
|
|
|
|
|
QString Sharee::format() const
|
|
|
|
{
|
|
|
|
QString formatted = _displayName;
|
|
|
|
|
|
|
|
if (_type == Type::Group) {
|
|
|
|
formatted += QLatin1String(" (group)");
|
2020-12-04 14:01:04 +03:00
|
|
|
} else if (_type == Type::Email) {
|
|
|
|
formatted += QLatin1String(" (email)");
|
2015-11-05 00:00:35 +03:00
|
|
|
} else if (_type == Type::Federated) {
|
|
|
|
formatted += QLatin1String(" (remote)");
|
2020-03-05 12:44:06 +03:00
|
|
|
} else if (_type == Type::Circle) {
|
|
|
|
formatted += QLatin1String(" (circle)");
|
2020-12-04 14:01:04 +03:00
|
|
|
} else if (_type == Type::Room) {
|
|
|
|
formatted += QLatin1String(" (conversation)");
|
2015-11-05 00:00:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return formatted;
|
|
|
|
}
|
|
|
|
|
2015-11-02 00:23:22 +03:00
|
|
|
QString Sharee::shareWith() const
|
|
|
|
{
|
|
|
|
return _shareWith;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Sharee::displayName() const
|
|
|
|
{
|
|
|
|
return _displayName;
|
|
|
|
}
|
|
|
|
|
2023-02-24 16:06:29 +03:00
|
|
|
void Sharee::setDisplayName(const QString &displayName)
|
|
|
|
{
|
|
|
|
if (displayName != _displayName) {
|
|
|
|
_displayName = displayName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sharee::setIconUrl(const QString &iconUrl)
|
|
|
|
{
|
|
|
|
if (iconUrl != _iconUrl) {
|
|
|
|
_iconUrl = iconUrl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sharee::setType(const Type &type)
|
|
|
|
{
|
|
|
|
if (type != _type) {
|
|
|
|
_type = type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sharee::setIsIconColourful(const bool isColourful)
|
|
|
|
{
|
|
|
|
if (_isIconColourful != isColourful) {
|
|
|
|
_isIconColourful = isColourful;
|
|
|
|
updateIconUrl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sharee::updateIconUrl()
|
|
|
|
{
|
|
|
|
if (_iconUrl.isEmpty() || !_isIconColourful) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto iconUrlColoured = _iconUrlColoured;
|
|
|
|
_iconColor = (!_isIconColourful || !Theme::instance()->darkMode()) ? QStringLiteral("black") : QStringLiteral("white");
|
|
|
|
_iconUrlColoured = QStringLiteral("image://svgimage-custom-color/") + _iconUrl + QStringLiteral("/") + _iconColor;
|
|
|
|
|
|
|
|
return iconUrlColoured != _iconUrlColoured;
|
|
|
|
}
|
|
|
|
|
2015-11-02 00:23:22 +03:00
|
|
|
Sharee::Type Sharee::type() const
|
|
|
|
{
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
|
2023-02-24 16:06:29 +03:00
|
|
|
QString Sharee::iconUrl() const
|
|
|
|
{
|
|
|
|
return _iconUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Sharee::iconUrlColoured() const
|
|
|
|
{
|
|
|
|
return _iconUrlColoured;
|
|
|
|
}
|
|
|
|
|
2015-11-02 00:23:22 +03:00
|
|
|
}
|