Skip to content

Commit bd594c8

Browse files
committed
Merge branch 'issue7814' of github.com:mike0609king/desktop into issue7814
Signed-off-by: Mike Mengjie Huang <[email protected]>
2 parents 6e76865 + 1937693 commit bd594c8

File tree

2 files changed

+51
-42
lines changed

2 files changed

+51
-42
lines changed

src/gui/tray/unifiedsearchresultslistmodel.cpp

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -324,48 +324,48 @@ bool UnifiedSearchResultsListModel::isSearchInProgress() const
324324
return !_searchJobConnections.isEmpty();
325325
}
326326

327-
void UnifiedSearchResultsListModel::resultClicked(
328-
const QString &providerId, const QUrl &resourceUrl, const QString &subline, const QString &title
329-
) const
327+
328+
void UnifiedSearchResultsListModel::resultClicked(const QString &providerId,
329+
const QUrl &resourceUrl,
330+
const QString &subline,
331+
const QString &title) const
330332
{
331-
if (_accountState == nullptr || _accountState->account() == nullptr || !providerId.contains(QStringLiteral("file"), Qt::CaseInsensitive)) {
332-
qCInfo(lcUnifiedSearch) << "immediately returning from resultClicked";
333-
return;
334-
}
335-
336-
const QUrlQuery urlQuery{resourceUrl};
337-
QString dir = urlQuery.queryItemValue(QStringLiteral("dir"), QUrl::ComponentFormattingOption::FullyDecoded);
338-
QString fileName = urlQuery.queryItemValue(QStringLiteral("scrollto"), QUrl::ComponentFormattingOption::FullyDecoded);
339-
340-
QString relativePath;
341-
// server version above 20
342-
if (dir.isEmpty() && fileName.isEmpty() && !title.isEmpty()) {
343-
if (!subline.isEmpty()) {
344-
dir = subline;
345-
dir.remove(0,3);
346-
fileName = QLatin1Char('/') + title;
347-
}
348-
else {
349-
dir = title;
350-
}
351-
relativePath = dir + fileName;
352-
}
353-
// server version 20
354-
else {
355-
relativePath = dir + QLatin1Char('/') + fileName;
356-
}
333+
const QUrlQuery urlQuery{resourceUrl};
334+
auto dir = urlQuery.queryItemValue(QStringLiteral("dir"), QUrl::ComponentFormattingOption::FullyDecoded);
335+
auto fileName = urlQuery.queryItemValue(QStringLiteral("scrollto"), QUrl::ComponentFormattingOption::FullyDecoded);
357336

358-
qCInfo(lcUnifiedSearch) << "relativePath: " << relativePath;
359-
const QStringList localFiles = FolderMan::instance()->findFileInLocalFolders(relativePath, _accountState->account());
337+
if (providerId.contains(QStringLiteral("file"), Qt::CaseInsensitive)){
338+
if (!_accountState || !_accountState->account()) {
339+
return;
340+
}
360341

361-
if (!localFiles.isEmpty()) {
362-
qCInfo(lcUnifiedSearch) << "Opening requested file or folder locally:" << localFiles.constFirst();
363-
QDesktopServices::openUrl(QUrl::fromLocalFile(localFiles.constFirst()));
364-
}
365-
else {
366-
qCInfo(lcUnifiedSearch) << "Opening requested file or folder in webbrowser: " << localFiles.constFirst();
367-
Utility::openBrowser(resourceUrl);
342+
// server version above 20
343+
if (dir.isEmpty() && fileName.isEmpty()) {
344+
// file is direct child of syncfolder
345+
if (subline.isEmpty()) {
346+
dir = title;
347+
} else {
348+
dir = subline.split(' ', Qt::SkipEmptyParts).last();
349+
fileName = QLatin1Char('/') + title;
350+
}
351+
} else if (dir.length() > 1) {
352+
// server version 20
353+
fileName.prepend(QLatin1Char('/'));
354+
}
355+
const auto relativePath = dir + fileName;
356+
357+
const auto localFiles = FolderMan::instance()->findFileInLocalFolders(relativePath, _accountState->account());
358+
if (!localFiles.isEmpty()) {
359+
qCInfo(lcUnifiedSearch) << "Opening file: " << localFiles.constFirst();
360+
const auto fileOpenedLocally = QDesktopServices::openUrl(QUrl::fromLocalFile(localFiles.constFirst()));
361+
if (fileOpenedLocally) {
362+
return;
363+
} else {
364+
qCWarning(lcUnifiedSearch) << "Warning: QDesktopServices::openUrl unexpectedly failed to open the file. Opening resourceUrl in web browser is attempted next.";
365+
}
366+
}
368367
}
368+
Utility::openBrowser(resourceUrl);
369369
}
370370

371371
void UnifiedSearchResultsListModel::fetchMoreTriggerClicked(const QString &providerId)

test/testunifiedsearchlistmodel.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,12 @@ FakeSearchResultsStorage *FakeSearchResultsStorage::_instance = nullptr;
274274

275275
}
276276

277-
class TestUnifiedSearchListmodel : public QObject
277+
class TestUnifiedSearchListModel : public QObject
278278
{
279279
Q_OBJECT
280280

281281
public:
282-
TestUnifiedSearchListmodel() = default;
282+
TestUnifiedSearchListModel() = default;
283283

284284
QScopedPointer<FakeQNAM> fakeQnam;
285285
OCC::AccountPtr account;
@@ -578,10 +578,19 @@ private slots:
578578
const auto providerId =
579579
model->data(model->index(i), OCC::UnifiedSearchResultsListModel::DataRole::ProviderIdRole)
580580
.toString();
581+
582+
const auto subline =
583+
model->data(model->index(i), OCC::UnifiedSearchResultsListModel::DataRole::SublineRole)
584+
.toString();
585+
586+
const auto title =
587+
model->data(model->index(i), OCC::UnifiedSearchResultsListModel::DataRole::TitleRole)
588+
.toString();
589+
581590
urlForClickedResult = model->data(model->index(i), OCC::UnifiedSearchResultsListModel::DataRole::ResourceUrlRole).toString();
582591

583592
if (!providerId.isEmpty() && !urlForClickedResult.isEmpty()) {
584-
model->resultClicked(providerId, QUrl(urlForClickedResult), "dummyStringNeedToFix", "dummyStringNeedToFix");
593+
model->resultClicked(providerId, QUrl(urlForClickedResult), subline, title);
585594
break;
586595
}
587596
}
@@ -632,5 +641,5 @@ private slots:
632641
}
633642
};
634643

635-
QTEST_MAIN(TestUnifiedSearchListmodel)
644+
QTEST_MAIN(TestUnifiedSearchListModel)
636645
#include "testunifiedsearchlistmodel.moc"

0 commit comments

Comments
 (0)