Skip to content

Commit

Permalink
Fix review coments + changed which image provider to use for coloured…
Browse files Browse the repository at this point in the history
… SVG.

Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander committed Mar 3, 2023
1 parent 329bca1 commit 7aa7043
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 45 deletions.
11 changes: 3 additions & 8 deletions src/gui/filedetails/ShareeDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ ItemDelegate {

text: model.display

contentItem:
RowLayout {
Layout.fillWidth: true
contentItem: RowLayout {
height: visible ? implicitHeight : 0

visible: true

Loader {
id: shareeIconLoader

Expand All @@ -44,7 +40,8 @@ ItemDelegate {
sourceComponent: Image {
id: shareeIcon

Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
horizontalAlignment: Qt.AlignLeft
verticalAlignment: Qt.AlignVCenter

width: height
height: shareeLabel.height
Expand All @@ -57,8 +54,6 @@ ItemDelegate {
source: model.icon

sourceSize: Qt.size(shareeIcon.height * 1.0, shareeIcon.height * 1.0)

visible: true
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/gui/filedetails/ShareeSearchField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ TextField {
shareeListView.count > 0 ? suggestionsPopup.open() : suggestionsPopup.close();
}

function searchGlobally() {
shareeModel.searchGlobally();
}

placeholderText: qsTr("Search for users or groups…")
placeholderTextColor: placeholderColor
color: Style.ncTextColor
Expand Down Expand Up @@ -236,7 +232,7 @@ TextField {
function selectItem() {
if (model.type === Sharee.LookupServerSearch) {
shareeListView.currentIndex = -1
root.searchGlobally()
root.shareeModel.searchGlobally()
} else {
selectSharee()
}
Expand Down
29 changes: 8 additions & 21 deletions src/gui/filedetails/shareemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ShareeModel::ShareeModel(QObject *parent)
{
_searchRateLimitingTimer.setSingleShot(true);
_searchRateLimitingTimer.setInterval(500);
_searchGloballyPlaceholder.reset(new Sharee({}, tr("Search globally"), Sharee::LookupServerSearch, QStringLiteral(":/client/theme/magnifying-glass.svg")));
_searchGloballyPlaceholder.reset(new Sharee({}, tr("Search globally"), Sharee::LookupServerSearch, QStringLiteral("magnifying-glass.svg")));
_searchGloballyPlaceholder->setIsIconColourful(true);
connect(&_searchRateLimitingTimer, &QTimer::timeout, this, &ShareeModel::fetch);
connect(Theme::instance(), &Theme::darkModeChanged, this, &ShareeModel::slotDarkModeChanged);
Expand Down Expand Up @@ -271,14 +271,17 @@ void ShareeModel::shareesFetched(const QJsonDocument &reply)

void ShareeModel::insertSearchGloballyItem(const QVector<ShareePtr> &newShareesFetched)
{
const auto isAlreadyInserted = std::find_if(std::begin(_sharees), std::end(_sharees), [](const ShareePtr &sharee) {
const auto foundIt = std::find_if(std::begin(_sharees), std::end(_sharees), [](const ShareePtr &sharee) {
return sharee->type() == Sharee::LookupServerSearch || sharee->type() == Sharee::LookupServerSearchResults;
}) != std::end(_sharees);
});

if (!isAlreadyInserted) {
_sharees.push_back(_searchGloballyPlaceholder);
// remove it if it somehow appeared not at the end, to avoid writing complex proxy models for sorting
if (foundIt != std::end(_sharees) && (foundIt + 1) != std::end(_sharees)) {
_sharees.erase(foundIt);
}

_sharees.push_back(_searchGloballyPlaceholder);

if (lookupMode() == LookupMode::GlobalSearch) {
const auto displayName = newShareesFetched.isEmpty() ? tr("No results found") : tr("Global search results");
_searchGloballyPlaceholder->setDisplayName(displayName);
Expand All @@ -287,22 +290,6 @@ void ShareeModel::insertSearchGloballyItem(const QVector<ShareePtr> &newShareesF
_searchGloballyPlaceholder->setDisplayName(tr("Search globally"));
_searchGloballyPlaceholder->setType(Sharee::LookupServerSearch);
}

sortSharees();
}

void ShareeModel::sortSharees()
{
// sort _sharees such that lookup placeholder is always last
std::sort(std::begin(_sharees), std::end(_sharees), [](const auto &left, const auto &right) {
const auto isRightElementLookupPlaceholder = right->type() == Sharee::LookupServerSearch
|| right->type() == Sharee::LookupServerSearchResults;

const auto isLeftElementLookupPlaceholder = left->type() == Sharee::LookupServerSearch
|| left->type() == Sharee::LookupServerSearchResults;

return !isLeftElementLookupPlaceholder && isRightElementLookupPlaceholder;
});
}

ShareePtr ShareeModel::parseSharee(const QJsonObject &data) const
Expand Down
1 change: 0 additions & 1 deletion src/gui/filedetails/shareemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public slots:
private slots:
void shareesFetched(const QJsonDocument &reply);
void insertSearchGloballyItem(const QVector<ShareePtr> &newShareesFetched);
void sortSharees();
void filterSharees();
void slotDarkModeChanged();

Expand Down
2 changes: 0 additions & 2 deletions src/gui/filedetails/sharemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,8 +998,6 @@ void ShareModel::createNewUserGroupShareWithPassword(const ShareePtr &sharee, co
return;
}

emit startedCretingNewUserGroupShare();

_manager->createShare(_sharePath,
Share::ShareType(sharee->type()),
sharee->shareWith(),
Expand Down
1 change: 0 additions & 1 deletion src/gui/filedetails/sharemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class ShareModel : public QAbstractListModel
void passwordSetError(const QString &shareId, const int code, const QString &message);
void requestPasswordForLinkShare();
void requestPasswordForEmailSharee(const OCC::ShareePtr &sharee);
void startedCretingNewUserGroupShare() const;

void sharesChanged();

Expand Down
2 changes: 1 addition & 1 deletion src/gui/sharee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool Sharee::updateIconUrl()

const auto iconUrlColoured = _iconUrlColoured;
_iconColor = (!_isIconColourful || !Theme::instance()->darkMode()) ? QStringLiteral("black") : QStringLiteral("white");
_iconUrlColoured = QStringLiteral("image://tray-image-provider/") + _iconUrl + QStringLiteral("/") + _iconColor;
_iconUrlColoured = QStringLiteral("image://svgimage-custom-color/") + _iconUrl + QStringLiteral("/") + _iconColor;

return iconUrlColoured != _iconUrlColoured;
}
Expand Down
12 changes: 6 additions & 6 deletions src/gui/sharee.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class Sharee
explicit Sharee() = default;
explicit Sharee(const QString &shareWith, const QString &displayName, const Type type, const QString &iconUrl = {});

Q_REQUIRED_RESULT QString format() const;
Q_REQUIRED_RESULT QString shareWith() const;
Q_REQUIRED_RESULT QString displayName() const;
Q_REQUIRED_RESULT QString iconUrl() const;
Q_REQUIRED_RESULT QString iconUrlColoured() const;
Q_REQUIRED_RESULT Type type() const;
[[nodiscard]] QString format() const;
[[nodiscard]] QString shareWith() const;
[[nodiscard]] QString displayName() const;
[[nodiscard]] QString iconUrl() const;
[[nodiscard]] QString iconUrlColoured() const;
[[nodiscard]] Type type() const;
bool updateIconUrl();

void setDisplayName(const QString &displayName);
Expand Down

0 comments on commit 7aa7043

Please sign in to comment.