]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/windows/BrowserWindow.cpp
Make the spell check language names checkable. https://redmine.stoutner.com/issues/958
[PrivacyBrowserPC.git] / src / windows / BrowserWindow.cpp
index a0a7a97346211e0a52f59b026b1fceb307834f6b..fcca8e8f70351ef7c91b544ee524861b72ff9b1f 100644 (file)
@@ -59,9 +59,8 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     KActionCollection *actionCollectionPointer = this->actionCollection();
 
     // Add the standard actions.
-    KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
     KStandardAction::print(tabWidgetPointer, SLOT(print()), actionCollectionPointer);
-    KStandardAction::printPreview(tabWidgetPointer, SLOT(printPreview()), actionCollectionPointer);
+    QAction *printPreviewActionPointer = KStandardAction::printPreview(tabWidgetPointer, SLOT(printPreview()), actionCollectionPointer);
     KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
     KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer);
     fullScreenActionPointer = KStandardAction::fullScreen(this, SLOT(toggleFullScreen()), this, actionCollectionPointer);
@@ -74,6 +73,8 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     findPreviousActionPointer = KStandardAction::findPrev(this, SLOT(findPrevious()), actionCollectionPointer);
 
     // Add the custom actions.
+    QAction *newTabActionPointer = actionCollectionPointer->addAction(QLatin1String("new_tab"));
+    QAction *newWindowActionPointer = actionCollectionPointer->addAction(QLatin1String("new_window"));
     userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_privacy_browser"));
     userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_webengine_default"));
     userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_firefox_linux"));
@@ -147,6 +148,8 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     UserAgentHelper *userAgentHelperPointer = new UserAgentHelper();
 
     // Set the action text.
+    newTabActionPointer->setText(i18nc("New tab action", "New Tab"));
+    newWindowActionPointer->setText(i18nc("New window action", "New Window"));
     userAgentPrivacyBrowserActionPointer->setText(userAgentHelperPointer->PRIVACY_BROWSER_TRANSLATED);
     userAgentWebEngineDefaultActionPointer->setText(userAgentHelperPointer->WEB_ENGINE_DEFAULT_TRANSLATED);
     userAgentFirefoxLinuxActionPointer->setText(userAgentHelperPointer->FIREFOX_LINUX_TRANSLATED);
@@ -170,6 +173,8 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     hideFindTextActionPointer->setText(i18nc("Hide Find Text action", "Hide Find Text"));
 
     // Set the action icons.
+    newTabActionPointer->setIcon(QIcon::fromTheme(QLatin1String("tab-new")));
+    newWindowActionPointer->setIcon(QIcon::fromTheme(QLatin1String("window-new")));
     userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
     userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties")));
     userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QLatin1String("firefox-esr")));
@@ -193,6 +198,61 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     findCaseSensitiveActionPointer->setIcon(QIcon::fromTheme(QLatin1String("format-text-lowercase")));
     hideFindTextActionPointer->setIcon(QIcon::fromTheme(QLatin1String("window-close-symbolic")));
 
+    // Create the key sequences.
+    QKeySequence ctrlTKeySequence = QKeySequence(i18nc("The open new tab key sequence.", "Ctrl+T"));
+    QKeySequence ctrlNKeySequence = QKeySequence(i18nc("The open new window key sequence.", "Ctrl+N"));
+    QKeySequence ctrlShiftPKeySequence = QKeySequence(i18nc("The print preview key sequence.", "Ctrl+Shift+P"));
+    QKeySequence ctrlAltPKeySequence = QKeySequence(i18nc("The Privacy Browser user agent key sequence.", "Ctrl+Alt+P"));
+    QKeySequence ctrlAltWKeySequence = QKeySequence(i18nc("The WebEngine Default user agent key sequence.", "Ctrl+Alt+W"));
+    QKeySequence ctrlAltFKeySequence = QKeySequence(i18nc("The Firefox on Linux user agent key sequence.", "Ctrl+Alt+F"));
+    QKeySequence ctrlAltCKeySequence = QKeySequence(i18nc("The Chromium on Linux user agent key sequence.", "Ctrl+Alt+C"));
+    QKeySequence ctrlAltShiftFKeySequence = QKeySequence(i18nc("The Firefox on Windows user agent key sequence.", "Ctrl+Alt+Shift+F"));
+    QKeySequence ctrlAltShiftCKeySequence = QKeySequence(i18nc("The Chrome on Windows user agent key sequence.", "Ctrl+Alt+Shift+C"));
+    QKeySequence ctrlAltEKeySequence = QKeySequence(i18nc("The Edge on Windows user agent key sequence.", "Ctrl+Alt+E"));
+    QKeySequence ctrlAltSKeySequence = QKeySequence(i18nc("The Safari on macOS user agent key sequence.", "Ctrl+Alt+S"));
+    QKeySequence altShiftCKeySequence = QKeySequence(i18nc("The custom user agent key sequence.", "Alt+Shift+C"));
+    QKeySequence ctrlAltZKeySequence = QKeySequence(i18nc("The zoom factor key sequence.", "Ctrl+Alt+Z"));
+    QKeySequence ctrlShiftMKeySequence = QKeySequence(i18nc("The Mojeek search engine key sequence.", "Ctrl+Shift+M"));
+    QKeySequence ctrlShiftOKeySequence = QKeySequence(i18nc("The Monocles search engine key sequence.", "Ctrl+Shift+O"));
+    QKeySequence ctrlShiftEKeySequence = QKeySequence(i18nc("The MetaGer search engine key sequence.", "Ctrl+Shift+E"));
+    QKeySequence ctrlShiftGKeySequence = QKeySequence(i18nc("The Google search engine key sequence.", "Ctrl+Shift+G"));
+    QKeySequence ctrlShiftBKeySequence = QKeySequence(i18nc("The Bing search engine key sequence.", "Ctrl+Shift+B"));
+    QKeySequence ctrlShiftYKeySequence = QKeySequence(i18nc("The Yahoo search engine key sequence.", "Ctrl+Shift+Y"));
+    QKeySequence ctrlShiftCKeySequence = QKeySequence(i18nc("The custom search engine key sequence.", "Ctrl+Shift+C"));
+    QKeySequence ctrlDKeySequence = QKeySequence(i18nc("The domain settings key sequence.", "Ctrl+D"));
+    QKeySequence ctrlSemicolonKeySequence = QKeySequence(i18nc("The cookies dialog key sequence.", "Ctrl+;"));
+
+    // Set the action key sequences.
+    actionCollectionPointer->setDefaultShortcut(newTabActionPointer, ctrlTKeySequence);
+    actionCollectionPointer->setDefaultShortcut(newWindowActionPointer, ctrlNKeySequence);
+    actionCollectionPointer->setDefaultShortcut(printPreviewActionPointer, ctrlShiftPKeySequence);
+    actionCollectionPointer->setDefaultShortcut(userAgentPrivacyBrowserActionPointer, ctrlAltPKeySequence);
+    actionCollectionPointer->setDefaultShortcut(userAgentWebEngineDefaultActionPointer, ctrlAltWKeySequence);
+    actionCollectionPointer->setDefaultShortcut(userAgentFirefoxLinuxActionPointer, ctrlAltFKeySequence);
+    actionCollectionPointer->setDefaultShortcut(userAgentChromiumLinuxActionPointer, ctrlAltCKeySequence);
+    actionCollectionPointer->setDefaultShortcut(userAgentFirefoxWindowsActionPointer, ctrlAltShiftFKeySequence);
+    actionCollectionPointer->setDefaultShortcut(userAgentChromeWindowsActionPointer, ctrlAltShiftCKeySequence);
+    actionCollectionPointer->setDefaultShortcut(userAgentEdgeWindowsActionPointer, ctrlAltEKeySequence);
+    actionCollectionPointer->setDefaultShortcut(userAgentSafariMacosActionPointer, ctrlAltSKeySequence);
+    actionCollectionPointer->setDefaultShortcut(userAgentCustomActionPointer, altShiftCKeySequence);
+    actionCollectionPointer->setDefaultShortcut(zoomFactorActionPointer, ctrlAltZKeySequence);
+    actionCollectionPointer->setDefaultShortcut(searchEngineMojeekActionPointer, ctrlShiftMKeySequence);
+    actionCollectionPointer->setDefaultShortcut(searchEngineMonoclesActionPointer, ctrlShiftOKeySequence);
+    actionCollectionPointer->setDefaultShortcut(searchEngineMetagerActionPointer, ctrlShiftEKeySequence);
+    actionCollectionPointer->setDefaultShortcut(searchEngineGoogleActionPointer, ctrlShiftGKeySequence);
+    actionCollectionPointer->setDefaultShortcut(searchEngineBingActionPointer, ctrlShiftBKeySequence);
+    actionCollectionPointer->setDefaultShortcut(searchEngineYahooActionPointer, ctrlShiftYKeySequence);
+    actionCollectionPointer->setDefaultShortcut(searchEngineCustomActionPointer, ctrlShiftCKeySequence);
+    actionCollectionPointer->setDefaultShortcut(domainSettingsActionPointer, ctrlDKeySequence);
+    actionCollectionPointer->setDefaultShortcut(cookiesActionPointer, ctrlSemicolonKeySequence);
+
+    // Execute the actions.
+    connect(newTabActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(addTab()));
+    connect(newWindowActionPointer, SIGNAL(triggered()), this, SLOT(newWindow()));
+    connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
+    connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(showCookiesDialog()));
+    connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(showDomainSettingsDialog()));
+
     // Update the on-the-fly menus.
     connect(tabWidgetPointer, SIGNAL(updateUserAgentActions(QString, bool)), this, SLOT(updateUserAgentActions(QString, bool)));
     connect(tabWidgetPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
@@ -205,11 +265,6 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     // Process cookie changes.
     connect(tabWidgetPointer, SIGNAL(updateCookiesAction(int)), this, SLOT(updateCookiesAction(int)));
 
-    // Display dialogs.
-    connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
-    connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(showCookiesDialog()));
-    connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(showDomainSettingsDialog()));
-
     // Connect the URL toolbar actions.
     connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
     connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
@@ -353,12 +408,10 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     connect(tabWidgetPointer, SIGNAL(fullScreenRequested(bool)), this, SLOT(fullScreenRequested(bool)));
 
     // Create keyboard shortcuts.
-    QShortcut *ctrlTShortcutPointer = new QShortcut(QKeySequence(i18nc("The open new tab shortcut.", "Ctrl+t")), this);
     QShortcut *f11ShortcutPointer = new QShortcut(QKeySequence(i18nc("The toggle full screen shortcut.", "F11")), this);
     QShortcut *escapeShortcutPointer = new QShortcut(QKeySequence::Cancel, this);
 
-    // Connect the keyboard shortcuts to the actions.
-    connect(ctrlTShortcutPointer, SIGNAL(activated()), tabWidgetPointer, SLOT(addTab()));
+    // Connect the keyboard shortcuts.
     connect(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger()));
     connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape()));
 
@@ -436,7 +489,7 @@ void BrowserWindow::escape() const
     }
     else if (!findTextLineEditPointer->text().isEmpty())  // Find text is populated.
     {
-        // Clear the text in the line edit.
+        // Clear the find text line edit.
         findTextLineEditPointer->clear();
 
         // Clear the search in the WebEngine.
@@ -449,12 +502,6 @@ void BrowserWindow::escape() const
     }
 }
 
-void BrowserWindow::fileNew() const
-{
-    // Display a new instance of Privacy Browser.
-    (new BrowserWindow)->show();
-}
-
 void BrowserWindow::findNext() const
 {
     // Get the find string.
@@ -566,6 +613,12 @@ void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
     tabWidgetPointer->loadUrlFromLineEdit(url);
 }
 
+void BrowserWindow::newWindow() const
+{
+    // Display a new instance of Privacy Browser.
+    (new BrowserWindow)->show();
+}
+
 void BrowserWindow::refresh() const
 {
     // Remove the focus from the URL line edit.
@@ -710,20 +763,23 @@ void BrowserWindow::showSettingsDialog()
     // Add each dictionary to the spell check list widget.
     foreach(QString dictionaryString, dictionariesStringList)
     {
-        // Create a new list widget item pointer named after the dictionary string.
-        QListWidgetItem *listWidgetItemPointer = new QListWidgetItem(dictionaryString, spellCheckListWidgetPointer);
+        // Create a new list widget item pointer.
+        QListWidgetItem *listWidgetItemPointer = new QListWidgetItem();
 
-        // Set the list widget item pointer to be checkable.
-        listWidgetItemPointer->setFlags(listWidgetItemPointer->flags() | Qt::ItemIsUserCheckable);
+        // Create a dictionary check box widget with the name of the dictionary string.
+        QCheckBox *dictionaryCheckBoxWidget = new QCheckBox(dictionaryString);
 
         // Check the language if it is currently enabled.
         if (enabledSpellCheckLanguagesList.contains(dictionaryString))
-            listWidgetItemPointer->setCheckState(Qt::Checked);
+            dictionaryCheckBoxWidget->setCheckState(Qt::Checked);
         else
-            listWidgetItemPointer->setCheckState(Qt::Unchecked);
+            dictionaryCheckBoxWidget->setCheckState(Qt::Unchecked);
 
-        // Add the list widget item to the widget.
+        // Add the list widget item to the spell check list widget.
         spellCheckListWidgetPointer->addItem(listWidgetItemPointer);
+
+        // Set the list widget item check box widget.
+        spellCheckListWidgetPointer->setItemWidget(listWidgetItemPointer, dictionaryCheckBoxWidget);
     }
 
     // Get a handle for the KConfig skeleton.
@@ -770,9 +826,21 @@ void BrowserWindow::showSettingsDialog()
             // Get the language item.
             QListWidgetItem *languageItemPointer = spellCheckListWidgetPointer->item(i);
 
+            // Get the language check box.
+            QCheckBox *languageCheckBoxPointer = qobject_cast<QCheckBox*>(spellCheckListWidgetPointer->itemWidget(languageItemPointer));
+
             // Add the item to the enabled languages if it is checked.
-            if (languageItemPointer->checkState() == Qt::Checked)
-                newSpellCheckLanguages.append(languageItemPointer->text());
+            if (languageCheckBoxPointer->checkState() == Qt::Checked)
+            {
+                // Get the text.
+                QString languageString = languageCheckBoxPointer->text();
+
+                // Remove all instances of `&`, which may have been added automatically when creating the check box text.
+                languageString.remove(QChar('&'));
+
+                // Add the language string to the list.
+                newSpellCheckLanguages.append(languageString);
+            }
         }
 
         // Update the spell check languages.