diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bea036..dc1b48a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH}) include(QtVersionOption) include(KDEInstallDirs) +include(KDEClangFormat) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(ECMDeprecationSettings) diff --git a/src/Config.h b/src/Config.h index cce9093..e229be4 100644 --- a/src/Config.h +++ b/src/Config.h @@ -65,4 +65,4 @@ struct KWalletConfig { constexpr static const auto ProxyPassword = "Krunner-QuickWebShortcuts-proxy_password"; }; #endif -#endif //QUICKWEBSHORTCUTS_CONFIG_H +#endif // QUICKWEBSHORTCUTS_CONFIG_H diff --git a/src/config/SearchEngineItem.cpp b/src/config/SearchEngineItem.cpp index 48f8a75..1efef58 100644 --- a/src/config/SearchEngineItem.cpp +++ b/src/config/SearchEngineItem.cpp @@ -1,9 +1,11 @@ +#include "SearchEngineItem.h" +#include #include #include -#include -#include "SearchEngineItem.h" -SearchEngineItem::SearchEngineItem(QWidget *parent) : QWidget(parent) { +SearchEngineItem::SearchEngineItem(QWidget *parent) + : QWidget(parent) +{ setupUi(this); connect(this->useRadioButton, &QRadioButton::clicked, this, &SearchEngineItem::changed); connect(this->useRadioButton, &QRadioButton::clicked, this, &SearchEngineItem::itemSelected); @@ -20,8 +22,10 @@ SearchEngineItem::SearchEngineItem(QWidget *parent) : QWidget(parent) { connect(this->urlLineEdit, &QLineEdit::textChanged, this, &SearchEngineItem::extractNameFromUrl); } -void SearchEngineItem::extractNameFromUrl() { - if (!this->nameLineEdit->text().isEmpty()) return; +void SearchEngineItem::extractNameFromUrl() +{ + if (!this->nameLineEdit->text().isEmpty()) + return; QRegularExpression exp(QStringLiteral(R"(^(?:https?://)(www\.)?([^/]+)\.(?:\.?[\w]{2,})+/?)")); if (this->urlLineEdit->text().contains(exp)) { const auto regexMatch = exp.match(this->urlLineEdit->text()); @@ -33,9 +37,9 @@ void SearchEngineItem::extractNameFromUrl() { } } -void SearchEngineItem::iconPicker() { - const QString iconPath = QFileDialog::getOpenFileName(this, tr("Select Icon"), "", - tr("Images (.*.jpg *.jpeg *.png *.ico *.svg *.svgz)")); +void SearchEngineItem::iconPicker() +{ + const QString iconPath = QFileDialog::getOpenFileName(this, tr("Select Icon"), "", tr("Images (.*.jpg *.jpeg *.png *.ico *.svg *.svgz)")); if (!iconPath.isEmpty()) { this->originalIcon = this->icon; this->icon = iconPath; diff --git a/src/config/SearchEngineItem.h b/src/config/SearchEngineItem.h index 8839e0e..3bb8326 100644 --- a/src/config/SearchEngineItem.h +++ b/src/config/SearchEngineItem.h @@ -5,8 +5,9 @@ #include -class SearchEngineItem : public QWidget, public Ui::SearchEngineItemUi { -Q_OBJECT +class SearchEngineItem : public QWidget, public Ui::SearchEngineItemUi +{ + Q_OBJECT public: QString originalName, originalURL, originalIcon, icon; @@ -18,7 +19,10 @@ Q_OBJECT public Q_SLOTS: void extractNameFromUrl(); - void edited() { this->isEdited = true; } + void edited() + { + this->isEdited = true; + } void iconPicker(); Q_SIGNALS: @@ -27,4 +31,4 @@ public Q_SLOTS: void deleteCurrentItem(); }; -#endif //QUICKWEBSHORTCUTS_SEARCHENGINEITEM_H +#endif // QUICKWEBSHORTCUTS_SEARCHENGINEITEM_H diff --git a/src/config/api_language_utility.h b/src/config/api_language_utility.h index 15fe569..56cda48 100644 --- a/src/config/api_language_utility.h +++ b/src/config/api_language_utility.h @@ -5,7 +5,8 @@ // Shorter syntax for macro #define s(str) QStringLiteral(str) -void setBingLanguages(QComboBox *box) { +void setBingLanguages(QComboBox *box) +{ box->clear(); box->addItem(s("ar-sa (Arabic)"), s("ar-sa")); box->addItem(s("da-dk (Danish)"), s("da-dk")); @@ -51,7 +52,8 @@ void setBingLanguages(QComboBox *box) { box->addItem(s("zh-tw (Traditional Chinese-Taiwan)"), s("zh-tw")); } -void setGoogleLanguages(QComboBox *box) { +void setGoogleLanguages(QComboBox *box) +{ box->clear(); // https://sites.google.com/site/tomihasa/google-language-codes box->addItem(s("Afrikaans"), s("af")); @@ -205,4 +207,4 @@ void setGoogleLanguages(QComboBox *box) { box->addItem(s("Zulu"), s("zu")); } -#endif //QUICKWEBSHORTCUTS_API_LANGUAGE_UTILITY_H +#endif // QUICKWEBSHORTCUTS_API_LANGUAGE_UTILITY_H diff --git a/src/config/quick_web_shortcuts_config.cpp b/src/config/quick_web_shortcuts_config.cpp index 403bbaa..a4f3859 100644 --- a/src/config/quick_web_shortcuts_config.cpp +++ b/src/config/quick_web_shortcuts_config.cpp @@ -1,28 +1,28 @@ #include "quick_web_shortcuts_config.h" #include "Config.h" -#include "searchengines/SearchEngines.h" #include "api_language_utility.h" -#include +#include "searchengines/SearchEngines.h" #include +#include #include -#include -#include #include +#include +#include #include K_PLUGIN_CLASS(QuickWebShortcutsConfig) -QuickWebShortcutsConfig::QuickWebShortcutsConfig(QWidget *parent, const QVariantList &args) : KCModule(parent, args) { +QuickWebShortcutsConfig::QuickWebShortcutsConfig(QWidget *parent, const QVariantList &args) + : KCModule(parent, args) +{ m_ui = new QuickWebShortcutsConfigForm(this); auto *layout = new QGridLayout(this); layout->addWidget(m_ui, 0, 0); initializeConfigFile(); - config = KSharedConfig::openConfig( - QDir::homePath() + QStringLiteral("/.config/krunnerplugins/quickwebshortcutsrunnerrc")) - ->group(Config::RootGroup); + config = KSharedConfig::openConfig(QDir::homePath() + QStringLiteral("/.config/krunnerplugins/quickwebshortcutsrunnerrc"))->group(Config::RootGroup); config.config()->reparseConfiguration(); // Initialize function pointers that require method overloading @@ -52,8 +52,7 @@ QuickWebShortcutsConfig::QuickWebShortcutsConfig(QWidget *parent, const QVariant connect(m_ui->bingRadioButton, &QCheckBox::clicked, this, changedSlotPointer); connect(m_ui->bingRadioButton, &QCheckBox::clicked, this, &QuickWebShortcutsConfig::validateSearchSuggestions); connect(m_ui->duckDuckGoRadioButton, &QCheckBox::clicked, this, changedSlotPointer); - connect(m_ui->duckDuckGoRadioButton, &QCheckBox::clicked, this, - &QuickWebShortcutsConfig::validateSearchSuggestions); + connect(m_ui->duckDuckGoRadioButton, &QCheckBox::clicked, this, &QuickWebShortcutsConfig::validateSearchSuggestions); connect(m_ui->disableRadioButton, &QCheckBox::clicked, this, changedSlotPointer); connect(m_ui->disableRadioButton, &QCheckBox::clicked, this, &QuickWebShortcutsConfig::validateSearchSuggestions); connect(m_ui->privateWindowCheckBox, &QCheckBox::clicked, this, changedSlotPointer); @@ -64,8 +63,7 @@ QuickWebShortcutsConfig::QuickWebShortcutsConfig(QWidget *parent, const QVariant // Signals/Slots that depend on the proxy feature to be enabled #ifndef NO_PROXY_INTEGRATION wallet = Wallet::openWallet(Wallet::LocalWallet(), 0, Wallet::Synchronous); - const auto validateProxyOptionsSlotPointer = - static_cast(&QuickWebShortcutsConfig::validateProxyOptions); + const auto validateProxyOptionsSlotPointer = static_cast(&QuickWebShortcutsConfig::validateProxyOptions); connect(m_ui->noProxyRadioButton, &QCheckBox::clicked, this, changedSlotPointer); connect(m_ui->httpProxyRadioButton, &QCheckBox::clicked, this, changedSlotPointer); connect(m_ui->socks5ProxyRadioButton, &QCheckBox::clicked, this, changedSlotPointer); @@ -81,13 +79,15 @@ QuickWebShortcutsConfig::QuickWebShortcutsConfig(QWidget *parent, const QVariant #endif } -QuickWebShortcutsConfig::~QuickWebShortcutsConfig() { +QuickWebShortcutsConfig::~QuickWebShortcutsConfig() +{ #ifndef NO_PROXY_INTEGRATION delete wallet; #endif } -void QuickWebShortcutsConfig::load() { +void QuickWebShortcutsConfig::load() +{ QString searchEngineName = config.readEntry(Config::SearchEngineName); if (searchEngineName.isEmpty()) { searchEngineName = QStringLiteral("Google"); @@ -120,9 +120,8 @@ void QuickWebShortcutsConfig::load() { // Fill ComboBox with existing web shortcuts QMap availableWebShortcuts; - const QStringList servicesDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, - QStringLiteral("kservices5/searchproviders/"), - QStandardPaths::LocateDirectory); + const QStringList servicesDirs = + QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kservices5/searchproviders/"), QStandardPaths::LocateDirectory); for (const QString &dirPath : servicesDirs) { QDir dir(dirPath); const auto files = dir.entryList({QStringLiteral("*.desktop")}, QDir::Files); @@ -132,25 +131,22 @@ void QuickWebShortcutsConfig::load() { availableWebShortcuts.insert(configGroup.readEntry("Name"), filePath); } } - for (const auto &mapEntry: availableWebShortcuts.toStdMap()) { + for (const auto &mapEntry : availableWebShortcuts.toStdMap()) { m_ui->webShortcutComboBox->addItem(mapEntry.first, mapEntry.second); } m_ui->useWebshortcutRadioButton->setChecked(!config.readEntry(Config::WebShortcut).isEmpty()); m_ui->webShortcutComboBox->setDisabled(config.readEntry(Config::WebShortcut).isEmpty()); - m_ui->webShortcutComboBox->setCurrentIndex( - m_ui->webShortcutComboBox->findData(config.readEntry(Config::WebShortcut), Qt::UserRole)); + m_ui->webShortcutComboBox->setCurrentIndex(m_ui->webShortcutComboBox->findData(config.readEntry(Config::WebShortcut), Qt::UserRole)); m_ui->showPrivateActionCheckBox->setChecked(config.readEntry(Config::PrivateWindowAction, true)); m_ui->showSearchEngineName->setChecked(config.readEntry(Config::ShowName, true)); m_ui->showSearchForCheckBox->setChecked(config.readEntry(Config::ShowSearchForNote, true)); m_ui->showPrivateNoteCheckBox->setChecked(config.readEntry(Config::PrivateWindowNote, true)); - m_ui->triggerCharacterComboBox->setCurrentText( - config.readEntry(Config::TriggerCharacter, Config::TriggerCharacterDefault)); + m_ui->triggerCharacterComboBox->setCurrentText(config.readEntry(Config::TriggerCharacter, Config::TriggerCharacterDefault)); showSearchForClicked(); // Search Suggestions settings - const QString searchSuggestionOption = config.readEntry(Config::SearchSuggestions, - Config::SearchSuggestionDisabled); + const QString searchSuggestionOption = config.readEntry(Config::SearchSuggestions, Config::SearchSuggestionDisabled); if (searchSuggestionOption == Config::SearchSuggestionGoogle) { m_ui->googleRadioButton->setChecked(true); } else if (searchSuggestionOption == Config::SearchSuggestionBing) { @@ -161,17 +157,13 @@ void QuickWebShortcutsConfig::load() { m_ui->disableRadioButton->setChecked(true); } m_ui->privateWindowCheckBox->setChecked(config.readEntry(Config::PrivateWindowSearchSuggestions, false)); - m_ui->minimumLetterCountSpinBox->setValue( - config.readEntry(Config::MinimumLetterCount, Config::MinimumLetterCountDefault)); - m_ui->maxSearchSuggestionsSpinBox->setValue( - config.readEntry(Config::MaxSuggestionResults, Config::MaxSuggestionResultsDefault)); + m_ui->minimumLetterCountSpinBox->setValue(config.readEntry(Config::MinimumLetterCount, Config::MinimumLetterCountDefault)); + m_ui->maxSearchSuggestionsSpinBox->setValue(config.readEntry(Config::MaxSuggestionResults, Config::MaxSuggestionResultsDefault)); setBingLanguages(m_ui->bingLocaleSelectComboBox); setGoogleLanguages(m_ui->googleLanguageComboBox); - m_ui->bingLocaleSelectComboBox->setCurrentIndex(m_ui->bingLocaleSelectComboBox->findData( - config.readEntry(Config::BingMarket, Config::BingMarketDefault))); - m_ui->googleLanguageComboBox->setCurrentIndex(m_ui->googleLanguageComboBox->findData( - config.readEntry(Config::GoogleLocale, Config::GoogleLocaleDefault))); + m_ui->bingLocaleSelectComboBox->setCurrentIndex(m_ui->bingLocaleSelectComboBox->findData(config.readEntry(Config::BingMarket, Config::BingMarketDefault))); + m_ui->googleLanguageComboBox->setCurrentIndex(m_ui->googleLanguageComboBox->findData(config.readEntry(Config::GoogleLocale, Config::GoogleLocaleDefault))); validateSearchSuggestions(); // Shows general warnings, hidden by default m_ui->topLabel->setHidden(true); @@ -179,9 +171,12 @@ void QuickWebShortcutsConfig::load() { #ifndef NO_PROXY_INTEGRATION // Proxy settings const QString proxy = config.readEntry(Config::Proxy); - if (proxy == Config::ProxyHTTP) m_ui->httpProxyRadioButton->setChecked(true); - else if (proxy == Config::ProxySocks5) m_ui->socks5ProxyRadioButton->setChecked(true); - else m_ui->noProxyRadioButton->setChecked(true); + if (proxy == Config::ProxyHTTP) + m_ui->httpProxyRadioButton->setChecked(true); + else if (proxy == Config::ProxySocks5) + m_ui->socks5ProxyRadioButton->setChecked(true); + else + m_ui->noProxyRadioButton->setChecked(true); readKWalletEntries(); validateProxyOptions(); @@ -203,12 +198,12 @@ void QuickWebShortcutsConfig::load() { Q_EMIT changed(false); // NOLINT(readability-misleading-indentation) } - -void QuickWebShortcutsConfig::save() { +void QuickWebShortcutsConfig::save() +{ // Remove old groups const int itemCount = m_ui->searchEnginesItemLayout->count(); const auto filteredGroups = config.groupList().filter(QRegularExpression(QStringLiteral("^SearchEngine-"))); - for (const auto &groupName: filteredGroups) { + for (const auto &groupName : filteredGroups) { config.group(groupName).deleteGroup(); } // Write items to config @@ -216,11 +211,14 @@ void QuickWebShortcutsConfig::save() { for (int i = 0; i < itemCount; ++i) { auto *item = reinterpret_cast(m_ui->searchEnginesItemLayout->itemAt(i)->widget()); const QString itemName = item->nameLineEdit->text(); - if (item->useRadioButton->isChecked()) selected = itemName; - if (item->isDefault && !item->isEdited) continue; + if (item->useRadioButton->isChecked()) + selected = itemName; + if (item->isDefault && !item->isEdited) + continue; const QString itemUrl = item->urlLineEdit->text(); - if (itemName.isEmpty() || itemUrl.isEmpty()) continue; + if (itemName.isEmpty() || itemUrl.isEmpty()) + continue; auto itemConfig = config.group(QStringLiteral("SearchEngine-") + itemName); itemConfig.writeEntry(SearchEngineConfig::Name, itemName); @@ -249,10 +247,8 @@ void QuickWebShortcutsConfig::save() { config.writeEntry(Config::PrivateWindowSearchSuggestions, m_ui->privateWindowCheckBox->isChecked()); config.writeEntry(Config::MinimumLetterCount, m_ui->minimumLetterCountSpinBox->value()); config.writeEntry(Config::MaxSuggestionResults, m_ui->maxSearchSuggestionsSpinBox->value()); - config.writeEntry(Config::BingMarket, m_ui->bingLocaleSelectComboBox->itemData( - m_ui->bingLocaleSelectComboBox->currentIndex())); - config.writeEntry(Config::GoogleLocale, m_ui->googleLanguageComboBox->itemData( - m_ui->googleLanguageComboBox->currentIndex())); + config.writeEntry(Config::BingMarket, m_ui->bingLocaleSelectComboBox->itemData(m_ui->bingLocaleSelectComboBox->currentIndex())); + config.writeEntry(Config::GoogleLocale, m_ui->googleLanguageComboBox->itemData(m_ui->googleLanguageComboBox->currentIndex())); QString webShortcut; if (m_ui->useWebshortcutRadioButton->isChecked()) { @@ -292,7 +288,8 @@ void QuickWebShortcutsConfig::save() { config.config()->sync(); } -void QuickWebShortcutsConfig::defaults() { +void QuickWebShortcutsConfig::defaults() +{ m_ui->historyQuick->setChecked(true); const int itemCount = m_ui->searchEnginesItemLayout->count(); for (int i = 0; i < itemCount; ++i) { @@ -309,7 +306,6 @@ void QuickWebShortcutsConfig::defaults() { item->useRadioButton->setChecked(false); continue; } - } m_ui->showPrivateActionCheckBox->setChecked(true); m_ui->useWebshortcutRadioButton->setChecked(false); @@ -331,14 +327,16 @@ void QuickWebShortcutsConfig::defaults() { Q_EMIT markAsChanged(); } -void QuickWebShortcutsConfig::addSearchEngine() { +void QuickWebShortcutsConfig::addSearchEngine() +{ auto *item = new SearchEngineItem(m_ui->groupBoxSearch); m_ui->searchEnginesItemLayout->insertWidget(0, item); item->iconPushButton->setIcon(QIcon::fromTheme(QStringLiteral("globe"))); connectSearchEngineSignals(item); } -void QuickWebShortcutsConfig::connectSearchEngineSignals(SearchEngineItem *item) { +void QuickWebShortcutsConfig::connectSearchEngineSignals(SearchEngineItem *item) +{ const auto changedSlotPointer = &QuickWebShortcutsConfig::markAsChanged; connect(item, &SearchEngineItem::changed, this, changedSlotPointer); connect(item, &SearchEngineItem::itemSelected, this, &QuickWebShortcutsConfig::itemSelected); @@ -347,13 +345,15 @@ void QuickWebShortcutsConfig::connectSearchEngineSignals(SearchEngineItem *item) connect(item, &SearchEngineItem::deleteCurrentItem, this, changedSlotPointer); } -void QuickWebShortcutsConfig::deleteCurrentItem() { +void QuickWebShortcutsConfig::deleteCurrentItem() +{ auto *item = reinterpret_cast(this->sender()); m_ui->searchEnginesItemLayout->removeWidget(item); item->deleteLater(); } -void QuickWebShortcutsConfig::validateSearchSuggestions() { +void QuickWebShortcutsConfig::validateSearchSuggestions() +{ const auto origin = reinterpret_cast(sender()); // If the current selection is clicked again it should still be selected if (origin != nullptr && !origin->isChecked()) { @@ -368,8 +368,8 @@ void QuickWebShortcutsConfig::validateSearchSuggestions() { m_ui->googleLanguageComboBox->setHidden(!m_ui->googleRadioButton->isChecked()); } - -void QuickWebShortcutsConfig::validateProxyOptions() { +void QuickWebShortcutsConfig::validateProxyOptions() +{ m_ui->proxyDataContainerWidget->setHidden(m_ui->noProxyRadioButton->isChecked()); } @@ -377,7 +377,8 @@ void QuickWebShortcutsConfig::validateProxyOptions() { * This method makes sure that exactly one search engine from the radio buttons * is selected. It is a bit messy but only for ui validation relevant */ -void QuickWebShortcutsConfig::itemSelected() { +void QuickWebShortcutsConfig::itemSelected() +{ if (this->sender()->objectName() == QLatin1String("useWebshortcutRadioButton")) { if (m_ui->useWebshortcutRadioButton->isChecked()) { for (int i = 0; i < m_ui->searchEnginesItemLayout->count(); ++i) { @@ -414,17 +415,21 @@ void QuickWebShortcutsConfig::itemSelected() { m_ui->webShortcutComboBox->setDisabled(true); } -void QuickWebShortcutsConfig::showSearchForClicked() { +void QuickWebShortcutsConfig::showSearchForClicked() +{ m_ui->showSearchEngineName->setDisabled(!m_ui->showSearchForCheckBox->isChecked()); } #ifndef NO_PROXY_INTEGRATION -void QuickWebShortcutsConfig::validateProxyConnection() { +void QuickWebShortcutsConfig::validateProxyConnection() +{ auto *manager = new QNetworkAccessManager(this); auto *proxy = new QNetworkProxy(); - if (m_ui->httpProxyRadioButton->isChecked()) proxy->setType(QNetworkProxy::HttpProxy); - else proxy->setType(QNetworkProxy::Socks5Proxy); + if (m_ui->httpProxyRadioButton->isChecked()) + proxy->setType(QNetworkProxy::HttpProxy); + else + proxy->setType(QNetworkProxy::Socks5Proxy); proxy->setHostName(m_ui->hostNameLineEdit->text()); proxy->setPort(m_ui->portLineEdit->text().toInt()); proxy->setUser(m_ui->usernameLineEdit->text()); @@ -433,8 +438,7 @@ void QuickWebShortcutsConfig::validateProxyConnection() { QNetworkRequest request(QUrl(QStringLiteral("https://ifconfig.me/ip"))); timeBeforeRequest = QTime::currentTime(); auto initialReply = manager->get(request); - connect(manager, &QNetworkAccessManager::finished, this, - &QuickWebShortcutsConfig::showProxyConnectionValidationResults); + connect(manager, &QNetworkAccessManager::finished, this, &QuickWebShortcutsConfig::showProxyConnectionValidationResults); m_ui->proxyTestResultLabel->setText(QStringLiteral("Making request...")); QTimer::singleShot(5000, initialReply, [initialReply]() { @@ -444,26 +448,25 @@ void QuickWebShortcutsConfig::validateProxyConnection() { }); } -void QuickWebShortcutsConfig::showProxyConnectionValidationResults(QNetworkReply *reply) { +void QuickWebShortcutsConfig::showProxyConnectionValidationResults(QNetworkReply *reply) +{ if (reply->error() == QNetworkReply::NoError) { const int msecDuration = timeBeforeRequest.msecsTo(QTime::currentTime()); - QString text = QStringLiteral("No Error!\nYour Ip address is: \n") + reply->readAll() + - QStringLiteral("\nThe request took:\n") - + QString::number(msecDuration) + QStringLiteral(" ms"); + QString text = QStringLiteral("No Error!\nYour Ip address is: \n") + reply->readAll() + QStringLiteral("\nThe request took:\n") + + QString::number(msecDuration) + QStringLiteral(" ms"); if (msecDuration >= 2000) text.append(QStringLiteral("\n Warning! A duration longer that 2000ms will result in a timeout!")); m_ui->proxyTestResultLabel->setText(text); } else { - m_ui->proxyTestResultLabel->setText( - QString(QMetaEnum::fromType().valueToKey(int(reply->error()))) + - ":\n" + - reply->errorString()); + m_ui->proxyTestResultLabel->setText(QString(QMetaEnum::fromType().valueToKey(int(reply->error()))) + ":\n" + + reply->errorString()); } delete reply; } -void QuickWebShortcutsConfig::readKWalletEntries() { +void QuickWebShortcutsConfig::readKWalletEntries() +{ if (KWallet::Wallet::isEnabled() && wallet && wallet->isOpen()) { QByteArray hostName; wallet->readEntry(KWalletConfig::ProxyHostname, hostName); @@ -484,7 +487,8 @@ void QuickWebShortcutsConfig::readKWalletEntries() { } } -void QuickWebShortcutsConfig::saveKWalletEntries() { +void QuickWebShortcutsConfig::saveKWalletEntries() +{ if (KWallet::Wallet::isEnabled() && wallet && wallet->isOpen()) { wallet->writeEntry(KWalletConfig::ProxyHostname, m_ui->hostNameLineEdit->text().toLocal8Bit()); wallet->writeEntry(KWalletConfig::ProxyPort, m_ui->portLineEdit->text().toLocal8Bit()); @@ -496,15 +500,22 @@ void QuickWebShortcutsConfig::saveKWalletEntries() { #else // For internal qt calls -void QuickWebShortcutsConfig::validateProxyConnection() {} +void QuickWebShortcutsConfig::validateProxyConnection() +{ +} -void QuickWebShortcutsConfig::showProxyConnectionValidationResults(QNetworkReply *) {} +void QuickWebShortcutsConfig::showProxyConnectionValidationResults(QNetworkReply *) +{ +} -void QuickWebShortcutsConfig::readKWalletEntries() {} +void QuickWebShortcutsConfig::readKWalletEntries() +{ +} -void QuickWebShortcutsConfig::saveKWalletEntries() {} +void QuickWebShortcutsConfig::saveKWalletEntries() +{ +} #endif - #include "quick_web_shortcuts_config.moc" diff --git a/src/config/quick_web_shortcuts_config.h b/src/config/quick_web_shortcuts_config.h index 3b67a52..479cd48 100644 --- a/src/config/quick_web_shortcuts_config.h +++ b/src/config/quick_web_shortcuts_config.h @@ -1,11 +1,11 @@ #ifndef QUICKWEBSHORTCUTSCONFIG_H #define QUICKWEBSHORTCUTSCONFIG_H +#include "SearchEngineItem.h" #include "ui_quick_web_shortcuts_config.h" #include #include #include -#include "SearchEngineItem.h" #ifndef NO_PROXY_INTEGRATION @@ -15,18 +15,21 @@ using KWallet::Wallet; #endif -class QuickWebShortcutsConfigForm : public QWidget, public Ui::QuickWebShortcutsConfigUi { -Q_OBJECT +class QuickWebShortcutsConfigForm : public QWidget, public Ui::QuickWebShortcutsConfigUi +{ + Q_OBJECT public: - explicit QuickWebShortcutsConfigForm(QWidget *parent) : QWidget(parent) { + explicit QuickWebShortcutsConfigForm(QWidget *parent) + : QWidget(parent) + { setupUi(this); } - }; -class QuickWebShortcutsConfig : public KCModule { -Q_OBJECT +class QuickWebShortcutsConfig : public KCModule +{ + Q_OBJECT public: explicit QuickWebShortcutsConfig(QWidget *parent = nullptr, const QVariantList &args = QVariantList()); @@ -52,7 +55,6 @@ public Q_SLOTS: void readKWalletEntries(); void saveKWalletEntries(); - private: QuickWebShortcutsConfigForm *m_ui; KConfigGroup config; diff --git a/src/quick_web_shortcuts.cpp b/src/quick_web_shortcuts.cpp index f08df31..56a34d3 100644 --- a/src/quick_web_shortcuts.cpp +++ b/src/quick_web_shortcuts.cpp @@ -1,26 +1,29 @@ #include "quick_web_shortcuts.h" +#include "Config.h" +#include "searchengines/SearchEngines.h" +#include "utilities.h" +#include +#include #include #include #include -#include -#include -#include "searchengines/SearchEngines.h" -#include "Config.h" -#include "utilities.h" #include -#include #include +#include QuickWebShortcuts::QuickWebShortcuts(QObject *parent, const KPluginMetaData &pluginMetaData, const QVariantList &args) - : KRunner::AbstractRunner(parent, pluginMetaData, args) { + : KRunner::AbstractRunner(parent, pluginMetaData, args) +{ } -QuickWebShortcuts::~QuickWebShortcuts() { +QuickWebShortcuts::~QuickWebShortcuts() +{ filterHistory(); delete requiredData.proxy; } -void QuickWebShortcuts::init() { +void QuickWebShortcuts::init() +{ initializeConfigFile(); // Add file watcher for config @@ -31,12 +34,12 @@ void QuickWebShortcuts::init() { reloadPluginConfiguration(); } -void QuickWebShortcuts::reloadPluginConfiguration(const QString &configFile) { +void QuickWebShortcuts::reloadPluginConfiguration(const QString &configFile) +{ // To detect invalid state if config is updated currentSearchEngine.url.clear(); - KConfigGroup configGroup = KSharedConfig::openConfig( - QDir::homePath() + QStringLiteral("/.config/krunnerplugins/") + Config::ConfigFile) - ->group(Config::RootGroup); + KConfigGroup configGroup = + KSharedConfig::openConfig(QDir::homePath() + QStringLiteral("/.config/krunnerplugins/") + Config::ConfigFile)->group(Config::RootGroup); // Force sync from file if (!configFile.isEmpty()) { configGroup.config()->reparseConfiguration(); @@ -55,7 +58,7 @@ void QuickWebShortcuts::reloadPluginConfiguration(const QString &configFile) { if (configGroup.readEntry(Config::WebShortcut).isEmpty()) { // Load search engines const QString searchEngineName = configGroup.readEntry(Config::SearchEngineName); - for (auto &engine:SearchEngines::getAllSearchEngines()) { + for (auto &engine : SearchEngines::getAllSearchEngines()) { if (engine.name == searchEngineName) { currentSearchEngine = engine; break; @@ -93,8 +96,7 @@ void QuickWebShortcuts::reloadPluginConfiguration(const QString &configFile) { // Display text for private browser option if (configGroup.readEntry(Config::PrivateWindowNote, true)) { - privateBrowserMode = privateBrowser.contains(QLatin1String("private")) ? - QStringLiteral(" in private window") : QStringLiteral(" in incognito mode"); + privateBrowserMode = privateBrowser.contains(QLatin1String("private")) ? QStringLiteral(" in private window") : QStringLiteral(" in incognito mode"); } else { privateBrowserMode = QString(); } @@ -106,10 +108,7 @@ void QuickWebShortcuts::reloadPluginConfiguration(const QString &configFile) { searchSuggestions = searchSuggestionChoice != Config::SearchSuggestionDisabled; privateWindowSearchSuggestions = searchSuggestions && configGroup.readEntry(Config::PrivateWindowSearchSuggestions, false); if (configGroup.readEntry(Config::PrivateWindowAction, true)) { - normalActions = {new QAction(QIcon::fromTheme(QStringLiteral("view-private")), - QStringLiteral("launch query in private/incognito window"), - this) - }; + normalActions = {new QAction(QIcon::fromTheme(QStringLiteral("view-private")), QStringLiteral("launch query in private/incognito window"), this)}; } else { normalActions.clear(); } @@ -151,8 +150,10 @@ void QuickWebShortcuts::reloadPluginConfiguration(const QString &configFile) { } } -void QuickWebShortcuts::filterHistory() { - if (cleanNone || (cleanQuick && !wasActive)) return; +void QuickWebShortcuts::filterHistory() +{ + if (cleanNone || (cleanQuick && !wasActive)) + return; QString history = generalKrunnerConfig.readEntry("history"); const int initialHistorySize = history.size(); QString filteredHistory; @@ -163,7 +164,8 @@ void QuickWebShortcuts::filterHistory() { if (cleanAll || cleanQuick) { // If cleanAll is true, filtered history has already been set => read value, clear it and write the final result const QString toFilter = cleanAll ? filteredHistory : history; - if (cleanAll) filteredHistory = ""; + if (cleanAll) + filteredHistory = ""; const QChar sep = ','; for (const auto &item : toFilter.split(sep, Qt::SkipEmptyParts)) { if (!item.startsWith(triggerCharacter)) { @@ -172,14 +174,16 @@ void QuickWebShortcuts::filterHistory() { } } // No changes have been made, exit function - if (filteredHistory.size() == initialHistorySize) return; + if (filteredHistory.size() == initialHistorySize) + return; // Write changes and make sure that the config gets synced generalKrunnerConfig.writeEntry("history", filteredHistory); generalKrunnerConfig.sync(); } -void QuickWebShortcuts::match(KRunner::RunnerContext &context) { +void QuickWebShortcuts::match(KRunner::RunnerContext &context) +{ wasActive = false; // Remove escape character @@ -221,7 +225,8 @@ void QuickWebShortcuts::match(KRunner::RunnerContext &context) { } } -void QuickWebShortcuts::run(const KRunner::RunnerContext &/*context*/, const KRunner::QueryMatch &match) { +void QuickWebShortcuts::run(const KRunner::RunnerContext & /*context*/, const KRunner::QueryMatch &match) +{ const QMap payload = match.data().toMap(); const QString url = payload.value(QStringLiteral("url")).toString(); QString launchCommand; @@ -235,8 +240,7 @@ void QuickWebShortcuts::run(const KRunner::RunnerContext &/*context*/, const KRu KNotification::event(KNotification::Error, QStringLiteral("Krunner-QuickWebShortcuts"), QStringLiteral("Error when parsing command browser arguments"), - QStringLiteral("globe") - ); + QStringLiteral("globe")); return; } launchCommand = arguments.takeAt(0); @@ -251,7 +255,8 @@ void QuickWebShortcuts::run(const KRunner::RunnerContext &/*context*/, const KRu wasActive = true; } -KRunner::QueryMatch QuickWebShortcuts::createMatch(const QString &text, const QMap &data, const bool useGlobe) { +KRunner::QueryMatch QuickWebShortcuts::createMatch(const QString &text, const QMap &data, const bool useGlobe) +{ KRunner::QueryMatch match(this); match.setIcon(useGlobe ? globeIcon : currentSearchEngine.qIcon); match.setText(text); @@ -261,9 +266,8 @@ KRunner::QueryMatch QuickWebShortcuts::createMatch(const QString &text, const QM return match; } - -void QuickWebShortcuts::searchSuggest(KRunner::RunnerContext &context, const QString &term, const QString &browser) { - +void QuickWebShortcuts::searchSuggest(KRunner::RunnerContext &context, const QString &term, const QString &browser) +{ if (searchSuggestionChoice == Config::SearchSuggestionBing) { QEventLoop loop; Bing bing(context, term, requiredData, bingMarket, browser); @@ -280,10 +284,10 @@ void QuickWebShortcuts::searchSuggest(KRunner::RunnerContext &context, const QSt connect(&duckDuckGo, &DuckDuckGo::finished, &loop, &QEventLoop::quit); loop.exec(); } - } -QList QuickWebShortcuts::actionsForMatch(const KRunner::QueryMatch &match) { +QList QuickWebShortcuts::actionsForMatch(const KRunner::QueryMatch &match) +{ if (match.data().toMap().contains(QStringLiteral("browser"))) { return privateActions; } diff --git a/src/quick_web_shortcuts.h b/src/quick_web_shortcuts.h index ebf1e0b..d9a5810 100644 --- a/src/quick_web_shortcuts.h +++ b/src/quick_web_shortcuts.h @@ -1,17 +1,18 @@ #ifndef QUICKWEBSHORTCUTS_H #define QUICKWEBSHORTCUTS_H +#include "searchengines/SearchEngine.h" +#include #include -#include -#include -#include #include -#include +#include #include -#include "searchengines/SearchEngine.h" +#include +#include -class QuickWebShortcuts : public KRunner::AbstractRunner { -Q_OBJECT +class QuickWebShortcuts : public KRunner::AbstractRunner +{ + Q_OBJECT private: // General variables diff --git a/src/searchengines/SearchEngine.h b/src/searchengines/SearchEngine.h index dc05f05..ec83fef 100644 --- a/src/searchengines/SearchEngine.h +++ b/src/searchengines/SearchEngine.h @@ -1,10 +1,11 @@ #ifndef QUICKWEBSHORTCUTS_SEARCHENGINE_H #define QUICKWEBSHORTCUTS_SEARCHENGINE_H -#include #include +#include -class SearchEngine { +class SearchEngine +{ public: QString name; QString url; @@ -17,5 +18,4 @@ class SearchEngine { bool isDefaultBased = false; }; - -#endif //QUICKWEBSHORTCUTS_SEARCHENGINE_H +#endif // QUICKWEBSHORTCUTS_SEARCHENGINE_H diff --git a/src/searchengines/SearchEngines.h b/src/searchengines/SearchEngines.h index 9f2bd50..224cfda 100644 --- a/src/searchengines/SearchEngines.h +++ b/src/searchengines/SearchEngines.h @@ -1,41 +1,40 @@ #ifndef QUICKWEBSHORTCUTS_SEARCHENGINES_H #define QUICKWEBSHORTCUTS_SEARCHENGINES_H - -#include -#include -#include +#include "SearchEngine.h" +#include #include +#include #include -#include -#include "SearchEngine.h" - -class SearchEngines { +#include +#include +class SearchEngines +{ public: - static QMap getDefaultSearchEngines() { + static QMap getDefaultSearchEngines() + { // Shorter macro #define s(str) QStringLiteral(str) return { - {s("Google"), s("https://www.google.com/search?q=")}, - {s("DuckDuckGo"), s("https://duckduckgo.com/?q=")}, - {s("Stackoverflow"), s("https://stackoverflow.com/search?q=")}, - {s("Bing"), s("https://www.bing.com/search?q=")}, - {s("Github"), s("https://github.com/search?q=")}, - {s("Youtube"), s("https://www.youtube.com/results?search_query=")}, + {s("Google"), s("https://www.google.com/search?q=")}, + {s("DuckDuckGo"), s("https://duckduckgo.com/?q=")}, + {s("Stackoverflow"), s("https://stackoverflow.com/search?q=")}, + {s("Bing"), s("https://www.bing.com/search?q=")}, + {s("Github"), s("https://github.com/search?q=")}, + {s("Youtube"), s("https://www.youtube.com/results?search_query=")}, }; } - - static QList getAllSearchEngines() { + static QList getAllSearchEngines() + { QList searchEngines; - const auto rootConfig = KSharedConfig::openConfig( - QDir::homePath() + QStringLiteral("/.config/krunnerplugins/") + Config::ConfigFile) - ->group(Config::RootGroup); + const auto rootConfig = + KSharedConfig::openConfig(QDir::homePath() + QStringLiteral("/.config/krunnerplugins/") + Config::ConfigFile)->group(Config::RootGroup); auto defaultEngines = getDefaultSearchEngines(); const auto fallbackIcon = QIcon::fromTheme(QStringLiteral("globe")); const auto filteredGroups = rootConfig.groupList().filter(QRegularExpression(QStringLiteral("^SearchEngine-"))); - for (const auto &groupName: filteredGroups) { + for (const auto &groupName : filteredGroups) { const auto config = rootConfig.group(groupName); SearchEngine engine; engine.name = config.readEntry(SearchEngineConfig::Name); @@ -67,8 +66,6 @@ class SearchEngines { } return searchEngines; } - - }; -#endif //QUICKWEBSHORTCUTS_SEARCHENGINES_H +#endif // QUICKWEBSHORTCUTS_SEARCHENGINES_H diff --git a/src/searchproviders/Bing.h b/src/searchproviders/Bing.h index e865e44..a2a2319 100644 --- a/src/searchproviders/Bing.h +++ b/src/searchproviders/Bing.h @@ -1,24 +1,23 @@ #ifndef QUICKWEBSHORTCUTS_BING_H #define QUICKWEBSHORTCUTS_BING_H - -#include +#include "RequiredData.h" +#include +#include +#include +#include #include -#include #include -#include +#include +#include #include -#include -#include -#include #include -#include "RequiredData.h" -//#define TEST_PROXY +// #define TEST_PROXY -class Bing: public QObject { - -Q_OBJECT +class Bing : public QObject +{ + Q_OBJECT private: QNetworkAccessManager *manager; @@ -30,16 +29,18 @@ Q_OBJECT QNetworkReply *reply; public: - Bing(KRunner::RunnerContext &context, QString query, RequiredData &data, QString market = "en-us", - QString browserLaunchCommand = "") - : context(context), query(std::move(query)), market(std::move(market)), - browserLaunchCommand(std::move(browserLaunchCommand)), data(data) { - + Bing(KRunner::RunnerContext &context, QString query, RequiredData &data, QString market = "en-us", QString browserLaunchCommand = "") + : context(context) + , query(std::move(query)) + , market(std::move(market)) + , browserLaunchCommand(std::move(browserLaunchCommand)) + , data(data) + { manager = new QNetworkAccessManager(this); if (data.proxy) { manager->setProxy(*this->data.proxy); } -#ifdef TEST_PROXY +#ifdef TEST_PROXY QNetworkRequest request(QUrl("https://ifconfig.me/ip")); m_manager->get(request); connect(manager, &QNetworkAccessManager::finished, this, &Bing::parseResponse); @@ -48,8 +49,8 @@ Q_OBJECT queryParameters.addQueryItem(QStringLiteral("query"), this->query); queryParameters.addQueryItem(QStringLiteral("market"), this->market); - QNetworkRequest request(QUrl(QStringLiteral("https://api.bing.com/osjson.aspx?") + - QUrl(queryParameters.query(QUrl::FullyEncoded).toUtf8()).toEncoded())); + QNetworkRequest request( + QUrl(QStringLiteral("https://api.bing.com/osjson.aspx?") + QUrl(queryParameters.query(QUrl::FullyEncoded).toUtf8()).toEncoded())); request.setSslConfiguration(QSslConfiguration::defaultConfiguration()); request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-www-form-urlencoded")); @@ -62,13 +63,15 @@ Q_OBJECT }); #endif } - virtual ~Bing() { + virtual ~Bing() + { delete reply; } public Q_SLOTS: - void parseResponse() { + void parseResponse() + { #ifdef TEST_PROXY qInfo() << reply->readAll(); Q_EMIT finished(); @@ -82,9 +85,9 @@ public Q_SLOTS: if (data.showNetworkErrors) { KNotification::event(KNotification::Error, QStringLiteral("Krunner-QuickWebShortcuts"), - QString(QMetaEnum::fromType().valueToKey(int(reply->error()))) + - QStringLiteral(":\n") + - reply->errorString(), QStringLiteral("globe")); + QString(QMetaEnum::fromType().valueToKey(int(reply->error()))) + QStringLiteral(":\n") + + reply->errorString(), + QStringLiteral("globe")); } } else if (context.isValid()) { const auto suggestionsObject = QJsonDocument::fromJson(reply->readAll()); @@ -102,7 +105,7 @@ public Q_SLOTS: KRunner::QueryMatch match(data.runner); match.setIcon(data.icon); match.setText(data.searchOptionTemplate.arg(suggestion)); - match.setRelevance((float) (19 - i) / 20); + match.setRelevance((float)(19 - i) / 20); QMap runData; QString url; @@ -112,7 +115,9 @@ public Q_SLOTS: url = data.searchEngine + QUrl::toPercentEncoding(suggestion); } runData.insert(QStringLiteral("url"), url); - if (!browserLaunchCommand.isEmpty()) { runData.insert(QStringLiteral("browser"), browserLaunchCommand); } + if (!browserLaunchCommand.isEmpty()) { + runData.insert(QStringLiteral("browser"), browserLaunchCommand); + } match.setData(runData); context.addMatch(match); } diff --git a/src/searchproviders/DuckDuckGo.h b/src/searchproviders/DuckDuckGo.h index c8867ef..cef903c 100644 --- a/src/searchproviders/DuckDuckGo.h +++ b/src/searchproviders/DuckDuckGo.h @@ -1,21 +1,20 @@ #ifndef QUICKWEBSHORTCUTS_DUCKDUCKGO_H #define QUICKWEBSHORTCUTS_DUCKDUCKGO_H - -#include -#include -#include -#include -#include -#include -#include -#include #include "RequiredData.h" +#include #include +#include +#include +#include +#include +#include +#include +#include -class DuckDuckGo : public QObject { - -Q_OBJECT +class DuckDuckGo : public QObject +{ + Q_OBJECT private: QNetworkAccessManager *manager; @@ -26,9 +25,12 @@ Q_OBJECT QNetworkReply *reply; public: - DuckDuckGo(KRunner::RunnerContext &context, QString query, RequiredData data, - QString browserLaunchCommand = "") : context(context), query(std::move(query)), - browserLaunchCommand(std::move(browserLaunchCommand)), data(std::move(data)) { + DuckDuckGo(KRunner::RunnerContext &context, QString query, RequiredData data, QString browserLaunchCommand = "") + : context(context) + , query(std::move(query)) + , browserLaunchCommand(std::move(browserLaunchCommand)) + , data(std::move(data)) + { manager = new QNetworkAccessManager(this); if (data.proxy) { manager->setProxy(*this->data.proxy); @@ -37,8 +39,8 @@ Q_OBJECT QUrlQuery queryParameters; queryParameters.addQueryItem(QStringLiteral("q"), this->query); - QNetworkRequest request(QUrl(QStringLiteral("https://lite.duckduckgo.com/lite/?") + - QUrl(queryParameters.query(QUrl::FullyEncoded).toUtf8()).toEncoded())); + QNetworkRequest request( + QUrl(QStringLiteral("https://lite.duckduckgo.com/lite/?") + QUrl(queryParameters.query(QUrl::FullyEncoded).toUtf8()).toEncoded())); request.setSslConfiguration(QSslConfiguration::defaultConfiguration()); request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-www-form-urlencoded")); request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader, @@ -52,13 +54,15 @@ Q_OBJECT }); } - virtual ~DuckDuckGo() { + virtual ~DuckDuckGo() + { delete reply; } public Q_SLOTS: - void parseResponse() { + void parseResponse() + { if (reply->error() == QNetworkReply::OperationCanceledError) { Q_EMIT finished(); return; @@ -67,9 +71,9 @@ public Q_SLOTS: if (data.showNetworkErrors) { KNotification::event(KNotification::Error, QStringLiteral("Krunner-QuickWebShortcuts"), - QString(QMetaEnum::fromType().valueToKey(int(reply->error()))) + - QStringLiteral(":\n") + - reply->errorString(), QStringLiteral("globe")); + QString(QMetaEnum::fromType().valueToKey(int(reply->error()))) + QStringLiteral(":\n") + + reply->errorString(), + QStringLiteral("globe")); } } else if (context.isValid()) { // Parse html content @@ -89,15 +93,13 @@ public Q_SLOTS: const QStringList ¤tList = urlList.at(i); KRunner::QueryMatch match(data.runner); match.setIcon(data.icon); - match.setText(QString(currentList.at(1)) - .remove(QLatin1String("http://")) - .remove(QLatin1String("https://")) - .remove(QLatin1String("www."))); - match.setRelevance((float) (19 - i) / 20); + match.setText(QString(currentList.at(1)).remove(QLatin1String("http://")).remove(QLatin1String("https://")).remove(QLatin1String("www."))); + match.setRelevance((float)(19 - i) / 20); QMap runData; runData.insert(QStringLiteral("url"), currentList.at(1)); - if (!browserLaunchCommand.isEmpty()) runData.insert(QStringLiteral("browser"), browserLaunchCommand); + if (!browserLaunchCommand.isEmpty()) + runData.insert(QStringLiteral("browser"), browserLaunchCommand); match.setData(runData); context.addMatch(match); } @@ -111,4 +113,4 @@ public Q_SLOTS: void finished(); }; -#endif //QUICKWEBSHORTCUTS_DUCKDUCKGO_H +#endif // QUICKWEBSHORTCUTS_DUCKDUCKGO_H diff --git a/src/searchproviders/Google.h b/src/searchproviders/Google.h index e99b2f3..4f0044d 100644 --- a/src/searchproviders/Google.h +++ b/src/searchproviders/Google.h @@ -1,19 +1,19 @@ #ifndef QUICKWEBSHORTCUTS_GOOGLE_H #define QUICKWEBSHORTCUTS_GOOGLE_H +#include +#include +#include #include #include #include -#include #include -#include -#include #include "RequiredData.h" -class Google : public QObject { - -Q_OBJECT +class Google : public QObject +{ + Q_OBJECT private: QNetworkAccessManager *manager; @@ -25,14 +25,13 @@ Q_OBJECT QNetworkReply *reply; public: - Google(KRunner::RunnerContext &context, - QString query, - RequiredData data, - QString language = "en", - QString browserLaunchCommand = "" - ) : context(context), query(std::move(query)), language(std::move(language)), - browserLaunchCommand(std::move(browserLaunchCommand)), data(std::move(data)) { - + Google(KRunner::RunnerContext &context, QString query, RequiredData data, QString language = "en", QString browserLaunchCommand = "") + : context(context) + , query(std::move(query)) + , language(std::move(language)) + , browserLaunchCommand(std::move(browserLaunchCommand)) + , data(std::move(data)) + { manager = new QNetworkAccessManager(this); if (data.proxy) { manager->setProxy(*this->data.proxy); @@ -43,8 +42,8 @@ Q_OBJECT queryParameters.addQueryItem(QStringLiteral("hl"), this->language); queryParameters.addQueryItem(QStringLiteral("output"), "toolbar"); - QNetworkRequest request(QUrl(QStringLiteral("https://clients1.google.com/complete/search?") + - QUrl(queryParameters.query(QUrl::FullyEncoded).toUtf8()).toEncoded())); + QNetworkRequest request( + QUrl(QStringLiteral("https://clients1.google.com/complete/search?") + QUrl(queryParameters.query(QUrl::FullyEncoded).toUtf8()).toEncoded())); request.setSslConfiguration(QSslConfiguration::defaultConfiguration()); request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-www-form-urlencoded")); @@ -56,13 +55,15 @@ Q_OBJECT }); } - virtual ~Google() { + virtual ~Google() + { delete reply; } public Q_SLOTS: - void parseResponse() { + void parseResponse() + { if (reply->error() == QNetworkReply::OperationCanceledError) { Q_EMIT finished(); return; @@ -71,9 +72,9 @@ public Q_SLOTS: if (data.showNetworkErrors) { KNotification::event(KNotification::Error, QStringLiteral("Krunner-QuickWebShortcuts"), - QString(QMetaEnum::fromType().valueToKey(int(reply->error()))) + - QStringLiteral(":\n") + - reply->errorString(), QStringLiteral("globe")); + QString(QMetaEnum::fromType().valueToKey(int(reply->error()))) + QStringLiteral(":\n") + + reply->errorString(), + QStringLiteral("globe")); } } else if (context.isValid()) { const QString xmlContent = reply->readAll(); @@ -85,10 +86,10 @@ public Q_SLOTS: while (reader.readNextStartElement()) { reader.readNext(); const QString suggestion = reader.attributes().value(QStringLiteral("data")).toString(); - if (suggestion != query) suggestions.append(suggestion); + if (suggestion != query) + suggestions.append(suggestion); reader.readElementText(); reader.skipCurrentElement(); - } } } @@ -98,7 +99,7 @@ public Q_SLOTS: KRunner::QueryMatch match(data.runner); match.setIcon(data.icon); match.setText(data.searchOptionTemplate.arg(suggestion)); - match.setRelevance((float) (19 - i) / 20); + match.setRelevance((float)(19 - i) / 20); QMap runData; QString url; @@ -114,7 +115,6 @@ public Q_SLOTS: match.setData(runData); context.addMatch(match); } - } Q_EMIT finished(); } @@ -124,4 +124,4 @@ public Q_SLOTS: void finished(); }; -#endif //QUICKWEBSHORTCUTS_GOOGLE_H +#endif // QUICKWEBSHORTCUTS_GOOGLE_H diff --git a/src/searchproviders/RequiredData.h b/src/searchproviders/RequiredData.h index 360dd90..afe9494 100644 --- a/src/searchproviders/RequiredData.h +++ b/src/searchproviders/RequiredData.h @@ -1,11 +1,12 @@ #ifndef QUICKWEBSHORTCUTS_REQUIREDDATA_H #define QUICKWEBSHORTCUTS_REQUIREDDATA_H -#include -#include #include +#include +#include -class RequiredData { +class RequiredData +{ public: QNetworkProxy *proxy = nullptr; KRunner::AbstractRunner *runner; @@ -17,4 +18,4 @@ class RequiredData { QString searchOptionTemplate; }; -#endif //QUICKWEBSHORTCUTS_REQUIREDDATA_H +#endif // QUICKWEBSHORTCUTS_REQUIREDDATA_H diff --git a/src/utilities.h b/src/utilities.h index b18aa7f..0cfb504 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -1,18 +1,21 @@ #ifndef QUICKWEBSHORTCUTS_UTILITIES_H #define QUICKWEBSHORTCUTS_UTILITIES_H +#include "Config.h" +#include "searchengines/SearchEngine.h" +#include +#include #include #include #include -#include -#include -#include "Config.h" -#include "searchengines/SearchEngine.h" -inline void initializeConfigFile() { +inline void initializeConfigFile() +{ const QString configFolder = QDir::homePath() + QStringLiteral("/.config/krunnerplugins/"); const QDir configDir(configFolder); - if (!configDir.exists()) { configDir.mkpath(configFolder); } + if (!configDir.exists()) { + configDir.mkpath(configFolder); + } // Create file QFile configFile(configFolder + Config::ConfigFile); if (!configFile.exists()) { @@ -21,20 +24,19 @@ inline void initializeConfigFile() { } } -inline QString loadPrivateBrowser() { +inline QString loadPrivateBrowser() +{ // Read entry for private browsing launch command QString privateBrowser; - QString browser = KSharedConfig::openConfig(QDir::homePath() + QStringLiteral("/.kde/share/config/kdeglobals")) - ->group("General").readEntry("BrowserApplication"); + QString browser = + KSharedConfig::openConfig(QDir::homePath() + QStringLiteral("/.kde/share/config/kdeglobals"))->group("General").readEntry("BrowserApplication"); if (browser.isEmpty()) { - browser = KSharedConfig::openConfig(QDir::homePath() + QStringLiteral("/./config/kdeglobals")) - ->group("General").readEntry("BrowserApplication"); + browser = KSharedConfig::openConfig(QDir::homePath() + QStringLiteral("/./config/kdeglobals"))->group("General").readEntry("BrowserApplication"); } if (!browser.isEmpty()) { const KSharedConfig::Ptr browserConfig = KSharedConfig::openConfig(QStringLiteral("/usr/share/applications/") + browser); - for (const auto &group: browserConfig->groupList()) { - if (group.contains(QStringLiteral("incognito"), Qt::CaseInsensitive) || - group.contains(QStringLiteral("private"), Qt::CaseInsensitive)) { + for (const auto &group : browserConfig->groupList()) { + if (group.contains(QStringLiteral("incognito"), Qt::CaseInsensitive) || group.contains(QStringLiteral("private"), Qt::CaseInsensitive)) { privateBrowser = browserConfig->group(group).readEntry("Exec"); } } @@ -42,7 +44,8 @@ inline QString loadPrivateBrowser() { return privateBrowser.isEmpty() ? QStringLiteral("firefox --private-window") : privateBrowser; } -inline SearchEngine getDefaultSearchEngine() { +inline SearchEngine getDefaultSearchEngine() +{ SearchEngine defaultEngine; defaultEngine.qIcon = QIcon::fromTheme(QStringLiteral("google")); defaultEngine.name = QStringLiteral("Google"); @@ -52,12 +55,13 @@ inline SearchEngine getDefaultSearchEngine() { #ifndef NO_PROXY_INTEGRATION -#include #include +#include using KWallet::Wallet; -inline QNetworkProxy *getProxyFromConfig(const QString &proxyChoice) { +inline QNetworkProxy *getProxyFromConfig(const QString &proxyChoice) +{ if (proxyChoice != Config::ProxyDisabled) { auto *wallet = Wallet::openWallet(Wallet::LocalWallet(), 0, Wallet::Synchronous); auto *proxy = new QNetworkProxy(); @@ -87,7 +91,8 @@ inline QNetworkProxy *getProxyFromConfig(const QString &proxyChoice) { if (!port.isEmpty() && !hostName.isEmpty()) { return proxy; } else { - KNotification::event(KNotification::Error, QStringLiteral("Krunner-QuickWebShortcuts"), + KNotification::event(KNotification::Error, + QStringLiteral("Krunner-QuickWebShortcuts"), QStringLiteral("The Proxy credentials require at least a Hostname and Port, proceeding without!"), QStringLiteral("globe")); } @@ -98,4 +103,4 @@ inline QNetworkProxy *getProxyFromConfig(const QString &proxyChoice) { } #endif -#endif //QUICKWEBSHORTCUTS_UTILITIES_H +#endif // QUICKWEBSHORTCUTS_UTILITIES_H