Skip to content

Commit

Permalink
Set UnifiedSearchResultNothingFound visibility less messily
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
  • Loading branch information
claucambra authored and pull[bot] committed Nov 7, 2022
1 parent bb25a42 commit 5177344
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
23 changes: 3 additions & 20 deletions src/gui/tray/Window.qml
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ ApplicationWindow {

UnifiedSearchResultNothingFound {
id: unifiedSearchResultNothingFound
visible: false

anchors.top: trayWindowUnifiedSearchInputContainer.bottom
anchors.left: trayWindowMainItem.left
anchors.right: trayWindowMainItem.right
Expand All @@ -715,28 +715,11 @@ ApplicationWindow {
text: UserModel.currentUser.unifiedSearchResultsListModel.searchTerm

property bool isSearchRunning: UserModel.currentUser.unifiedSearchResultsListModel.isSearchInProgress
property bool waitingForSearchTermEditEnd: UserModel.currentUser.unifiedSearchResultsListModel.waitingForSearchTermEditEnd
property bool isSearchResultsEmpty: unifiedSearchResultsListView.count === 0
property bool nothingFound: text && isSearchResultsEmpty && !UserModel.currentUser.unifiedSearchResultsListModel.errorString

onIsSearchRunningChanged: {
if (unifiedSearchResultNothingFound.isSearchRunning) {
visible = false;
} else {
if (nothingFound) {
visible = true;
}
}
}

onTextChanged: {
visible = false;
}

onIsSearchResultsEmptyChanged: {
if (!unifiedSearchResultNothingFound.isSearchResultsEmpty) {
visible = false;
}
}
visible: !isSearchRunning && !waitingForSearchTermEditEnd && nothingFound
}

Loader {
Expand Down
13 changes: 13 additions & 0 deletions src/gui/tray/unifiedsearchresultslistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Q_LOGGING_CATEGORY(lcUnifiedSearch, "nextcloud.gui.unifiedsearch", QtInfoMsg)

UnifiedSearchResultsListModel::UnifiedSearchResultsListModel(AccountState *accountState, QObject *parent)
: QAbstractListModel(parent)
, _waitingForSearchTermEditEnd(false)
, _accountState(accountState)
{
}
Expand Down Expand Up @@ -280,6 +281,11 @@ QString UnifiedSearchResultsListModel::currentFetchMoreInProgressProviderId() co
return _currentFetchMoreInProgressProviderId;
}

bool UnifiedSearchResultsListModel::waitingForSearchTermEditEnd() const
{
return _waitingForSearchTermEditEnd;
}

void UnifiedSearchResultsListModel::setSearchTerm(const QString &term)
{
if (term == _searchTerm) {
Expand All @@ -303,13 +309,17 @@ void UnifiedSearchResultsListModel::setSearchTerm(const QString &term)

if (_unifiedSearchTextEditingFinishedTimer.isActive()) {
_unifiedSearchTextEditingFinishedTimer.stop();
_waitingForSearchTermEditEnd = false;
emit waitingForSearchTermEditEndChanged();
}

if (!_searchTerm.isEmpty()) {
_unifiedSearchTextEditingFinishedTimer.setInterval(searchTermEditingFinishedSearchStartDelay);
connect(&_unifiedSearchTextEditingFinishedTimer, &QTimer::timeout, this,
&UnifiedSearchResultsListModel::slotSearchTermEditingFinished);
_unifiedSearchTextEditingFinishedTimer.start();
_waitingForSearchTermEditEnd = true;
emit waitingForSearchTermEditEndChanged();
}

if (!_results.isEmpty()) {
Expand Down Expand Up @@ -367,6 +377,9 @@ void UnifiedSearchResultsListModel::fetchMoreTriggerClicked(const QString &provi

void UnifiedSearchResultsListModel::slotSearchTermEditingFinished()
{
_waitingForSearchTermEditEnd = false;
emit waitingForSearchTermEditEndChanged();

disconnect(&_unifiedSearchTextEditingFinishedTimer, &QTimer::timeout, this,
&UnifiedSearchResultsListModel::slotSearchTermEditingFinished);

Expand Down
4 changes: 4 additions & 0 deletions src/gui/tray/unifiedsearchresultslistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class UnifiedSearchResultsListModel : public QAbstractListModel
currentFetchMoreInProgressProviderIdChanged)
Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
Q_PROPERTY(QString searchTerm READ searchTerm WRITE setSearchTerm NOTIFY searchTermChanged)
Q_PROPERTY(bool waitingForSearchTermEditEnd READ waitingForSearchTermEditEnd NOTIFY waitingForSearchTermEditEndChanged)

struct UnifiedSearchProvider
{
Expand Down Expand Up @@ -77,6 +78,7 @@ class UnifiedSearchResultsListModel : public QAbstractListModel
QString currentFetchMoreInProgressProviderId() const;
QString searchTerm() const;
QString errorString() const;
bool waitingForSearchTermEditEnd() const;

Q_INVOKABLE void resultClicked(const QString &providerId, const QUrl &resourceUrl) const;
Q_INVOKABLE void fetchMoreTriggerClicked(const QString &providerId);
Expand Down Expand Up @@ -106,6 +108,7 @@ class UnifiedSearchResultsListModel : public QAbstractListModel
void isSearchInProgressChanged();
void errorStringChanged();
void searchTermChanged();
void waitingForSearchTermEditEndChanged();

public slots:
void setSearchTerm(const QString &term);
Expand All @@ -121,6 +124,7 @@ private slots:

QString _searchTerm;
QString _errorString;
bool _waitingForSearchTermEditEnd;

QString _currentFetchMoreInProgressProviderId;

Expand Down

0 comments on commit 5177344

Please sign in to comment.