- // Load the URL, adding standard protocol sections if needed. TODO. Replace this with logic that prefers HTTPS.
- webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser));
+ // Decide if the text is more likely to be a URL or a search.
+ if (urlFromUser.contains(".")) // The text is likely a URL.
+ {
+ // Check if the URL does not start with a valid protocol.
+ if (!urlFromUser.startsWith("http") && !urlFromUser.startsWith("file://"))
+ {
+ // Add `https://` to the beginning of the URL.
+ urlFromUser = "https://" + urlFromUser;
+ }
+
+ // Load the URL.
+ webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser));
+ }
+ else // The text is likely a search.
+ {
+ // Load the search.
+ webEngineViewPointer->setUrl(QUrl::fromUserInput(SearchEngineHelper::getSearchUrl(Settings::searchEngine()) + urlFromUser));
+ }