@@ -324,48 +324,48 @@ bool UnifiedSearchResultsListModel::isSearchInProgress() const
324
324
return !_searchJobConnections.isEmpty ();
325
325
}
326
326
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
330
332
{
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);
357
336
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
+ }
360
341
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
+ }
368
367
}
368
+ Utility::openBrowser (resourceUrl);
369
369
}
370
370
371
371
void UnifiedSearchResultsListModel::fetchMoreTriggerClicked (const QString &providerId)
0 commit comments