#include <QMessageBox>
#include <QPushButton>
-DomainSettingsDialog::DomainSettingsDialog(QWidget *parent) : QDialog(parent)
+// Define the public static int constants.
+const int DomainSettingsDialog::SHOW_ALL_DOMAINS = 0;
+const int DomainSettingsDialog::ADD_DOMAIN = 1;
+const int DomainSettingsDialog::EDIT_DOMAIN = 2;
+
+DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString &domainName) : QDialog(nullptr)
{
// Instantiate the domain settings view UI.
Ui::DomainSettingsDialog domainSettingsDialogUi;
// Read the data from the database and apply it to the table model.
domainsTableModelPointer->select();
- // Select the first entry in the list view.
- domainsListViewPointer->setCurrentIndex(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME)));
+ // Setup the dialog according to the start type.
+ switch (startType)
+ {
+ case SHOW_ALL_DOMAINS:
+ {
+ // Select the first entry in the list view.
+ domainsListViewPointer->setCurrentIndex(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME)));
- // Populate the domain settings.
- domainSelected(domainsListViewPointer->selectionModel()->currentIndex());
+ // Populate the domain settings.
+ domainSelected(domainsListViewPointer->selectionModel()->currentIndex());
+
+ break;
+ }
+
+ case ADD_DOMAIN:
+ {
+ // Add the new domain.
+ addDomain(domainName);
+
+ break;
+ }
+
+ case EDIT_DOMAIN:
+ {
+ // Find the index for the new domain. `1` returns the first match.
+ QModelIndexList newDomainIndex = domainsTableModelPointer->match(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME)),
+ Qt::DisplayRole, domainName, 1, Qt::MatchWrap);
+
+ // Move to the new domain.
+ domainsListViewPointer->setCurrentIndex(newDomainIndex[0]);
+
+ // Populate the domain settings.
+ domainSelected(domainsListViewPointer->selectionModel()->currentIndex());
+ }
+ }
// Handle clicks on the domains.
connect(domainsListViewPointer, SIGNAL(activated(QModelIndex)), this, SLOT(domainSelected(QModelIndex)));
updateUi();
}
+void DomainSettingsDialog::addDomain(const QString &domainName) const
+{
+ // Create a new domain record.
+ QSqlRecord newDomainRecord = QSqlDatabase::database(DomainsDatabaseHelper::CONNECTION_NAME).record(DomainsDatabaseHelper::DOMAINS_TABLE);
+
+ // Set the values for the new domain.
+ newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME), domainName);
+ newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT), DomainsDatabaseHelper::SYSTEM_DEFAULT);
+ newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::LOCAL_STORAGE), DomainsDatabaseHelper::SYSTEM_DEFAULT);
+ newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT), UserAgentHelper::SYSTEM_DEFAULT_DATABASE);
+ newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::ZOOM_FACTOR), DomainsDatabaseHelper::SYSTEM_DEFAULT);
+ newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR), 1.0);
+
+ // Insert the new domain. `-1` appends it to the end.
+ domainsTableModelPointer->insertRecord(-1, newDomainRecord);
+
+ // Submit all pending changes.
+ domainsTableModelPointer->submitAll();
+
+ // Find the index for the new domain. `-1` allows for multiple entries to be returned.
+ QModelIndexList newDomainIndex = domainsTableModelPointer->match(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME)),
+ Qt::DisplayRole, domainName, -1, Qt::MatchWrap);
+
+ // Move to the new domain. If there are multiple domains with the same name, the new one should be the last in the list.
+ domainsListViewPointer->setCurrentIndex(newDomainIndex[newDomainIndex.size() - 1]);
+
+ // Populate the domain settings.
+ domainSelected(domainsListViewPointer->selectionModel()->currentIndex());
+
+ // Update the UI.
+ updateUi();
+}
+
+
void DomainSettingsDialog::apply() const
{
// Get the current index.
QLineEdit::Normal, QString(), &okClicked);
// Add the new domain if the user clicked OK.
- if (okClicked)
- {
- // Create a new domain record.
- QSqlRecord newDomainRecord = QSqlDatabase::database(DomainsDatabaseHelper::CONNECTION_NAME).record(DomainsDatabaseHelper::DOMAINS_TABLE);
-
- // Set the values for the new domain.
- newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME), newDomainName);
- newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT), DomainsDatabaseHelper::SYSTEM_DEFAULT);
- newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::LOCAL_STORAGE), DomainsDatabaseHelper::SYSTEM_DEFAULT);
- newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT), UserAgentHelper::SYSTEM_DEFAULT_DATABASE);
- newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::ZOOM_FACTOR), DomainsDatabaseHelper::SYSTEM_DEFAULT);
- newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR), 1.0);
-
- // Insert the new domain. `-1` appends it to the end.
- domainsTableModelPointer->insertRecord(-1, newDomainRecord);
-
- // Submit all pending changes.
- domainsTableModelPointer->submitAll();
-
- // Find the index for the new domain. `-1` allows for multiple entries to be returned.
- QModelIndexList newDomainIndex = domainsTableModelPointer->match(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME)),
- Qt::DisplayRole, newDomainName, -1, Qt::MatchWrap);
-
- // Move to the new domain. If there are multiple domains with the same name, the new one should be the last in the list.
- domainsListViewPointer->setCurrentIndex(newDomainIndex[newDomainIndex.size() - 1]);
-
- // Populate the domain settings.
- domainSelected(domainsListViewPointer->selectionModel()->currentIndex());
-
- // Update the UI.
- updateUi();
- }
+ if (okClicked) addDomain(newDomainName);
}
void DomainSettingsDialog::showDeleteMessageBox() const
public:
// The primary constructor.
- explicit DomainSettingsDialog(QWidget *parent = nullptr);
+ explicit DomainSettingsDialog(const int &startType = SHOW_ALL_DOMAINS, const QString &domainName = QStringLiteral(""));
+
+ // The public static int constants.
+ static const int SHOW_ALL_DOMAINS;
+ static const int ADD_DOMAIN;
+ static const int EDIT_DOMAIN;
signals:
void domainSettingsUpdated() const;
QComboBox *zoomFactorComboBoxPointer;
// The private functions.
+ void addDomain(const QString &domainName) const;
void populateJavaScriptLabel() const;
void populateLocalStorageLabel() const;
void populateUserAgentLabel(const QString &userAgentName) const;
webEngineViewPointer->setZoomFactor(currentZoomFactor);
// Apply the domain settings palette to the URL line edit.
- emit updateDomainSettingsIndicator(true);
+ emit updateDomainSettingsIndicator(true, domainRecord.field(DomainsDatabaseHelper::DOMAIN_NAME).value().toString());
}
else // The hostname does not have domain settings.
{
webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
// Apply the no domain settings palette to the URL line edit.
- emit updateDomainSettingsIndicator(false);
+ emit updateDomainSettingsIndicator(false, QStringLiteral(""));
}
// Emit the update actions signals.
void BrowserView::updateUrl(const QUrl &url) const
{
// Update the URL line edit.
- emit updateUrlLineEdit(url.toString());
+ emit updateUrlLineEdit(url);
// Update the status of the forward and back buttons.
emit updateBackAction(webEngineHistoryPointer->canGoBack());
void linkHovered(const QString &linkUrl) const;
void showProgressBar(const int &progress) const;
void updateBackAction(const bool &isEnabled) const;
- void updateDomainSettingsIndicator(const bool status) const;
+ void updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain) const;
void updateForwardAction(const bool &isEnabled) const;
void updateJavaScriptAction(const bool &isEnabled) const;
void updateLocalStorageAction(const bool &isEnabled) const;
void updateSearchEngineActions(const QString &searchEngine) const;
- void updateUrlLineEdit(const QString &newUrl) const;
+ void updateUrlLineEdit(const QUrl &newUrl) const;
void updateUserAgentActions(const QString &userAgent) const;
void updateZoomFactorAction(const double &zoomFactor) const;
searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-yahoo")));
searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
- domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("network-server-symbolic")));
+ domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure")));
// Update the on-the-fly menus.
connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString)), this, SLOT(updateUserAgentActions(QString)));
// Create a URL line edit.
urlLineEditPointer = new KLineEdit();
+ // Add an edit or add domain settings action to the URL line edit.
+ QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure"), QLineEdit::TrailingPosition);
+
+ // Add or edit the current domain settings.
+ connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings()));
+
// Populate the URL toolbar.
urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
// Update the URL line edit on page loads.
- connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QString)), this, SLOT(updateUrlLineEdit(QString)));
+ connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
// Get a handle for the status bar.
QStatusBar *statusBarPointer = statusBar();
domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
// Update the applied palette.
- connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool)), this, SLOT(updateDomainSettingsIndicator(bool)));
+ connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool, QString)), this, SLOT(updateDomainSettingsIndicator(bool, QString)));
// Load the initial website.
browserViewPointer->loadInitialWebsite();
}
+void BrowserWindow::addOrEditDomainSettings() const
+{
+ // Remove the focus from the URL line edit.
+ urlLineEditPointer->clearFocus();
+
+ // Create the domain settings dialog pointer.
+ DomainSettingsDialog *domainSettingsDialogPointer;
+
+ // Run the commands according to the current domain settings status.
+ if (currentDomainSettingsDomain == "") // Domain settings are not currently applied.
+ {
+ // Instruct the domain settings dialog to add a new domain.
+ domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
+ }
+ else // Domain settings are currently applied.
+ {
+ // Instruct the domain settings dialog to edit the current domain.
+ domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsDomain);
+ }
+
+ // Set the dialog window title.
+ domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
+
+ // Set the modality.
+ domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
+
+ // Show the dialog.
+ domainSettingsDialogPointer->show();
+
+ // Reload the tabs when domain settings are updated.
+ connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
+}
+
void BrowserWindow::back() const
{
// Remove the focus from the URL line edit.
// Remove the focus from the URL line edit.
urlLineEditPointer->clearFocus();
- // Instantiate the domain settings window.
+ // Instantiate the domain settings dialog.
DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
// Set the dialog window title.
browserViewPointer->toggleLocalStorage();
}
-void BrowserWindow::updateDomainSettingsIndicator(const bool &status) const
+void BrowserWindow::updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain)
{
// Set the domain palette according to the status.
if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
else urlLineEditPointer->setPalette(noDomainSettingsPalette);
+
+ // Store the domain.
+ currentDomainSettingsDomain = domainSettingsDomain;
}
void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const
searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
}
-void BrowserWindow::updateUrlLineEdit(const QString &newUrl) const
+void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
{
// Update the URL line edit if it does not have focus.
if (!urlLineEditPointer->hasFocus())
{
// Update the URL line edit.
- urlLineEditPointer->setText(newUrl);
+ urlLineEditPointer->setText(newUrl.toString());
}
+
+ // Store the current URL.
+ currentUrl = newUrl;
}
void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
private Q_SLOTS:
// The private slots.
+ void addOrEditDomainSettings() const;
void back() const;
void fileNew() const;
void forward() const;
void showProgressBar(const int &progress) const;
void toggleJavaScript() const;
void toggleLocalStorage() const;
- void updateDomainSettingsIndicator(const bool &status) const;
+ void updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain);
void updateJavaScriptAction(const bool &isEnabled) const;
void updateLocalStorageAction(const bool &isEnabled) const;
void updateSearchEngineActions(const QString &searchEngine) const;
void updateUserAgentActions(const QString &userAgent) const;
void updateZoomFactorAction(const double &zoomFactor);
void updateSearchEngineLabel(const QString &searchEngineString) const;
- void updateUrlLineEdit(const QString &newUrl) const;
+ void updateUrlLineEdit(const QUrl &newUrl);
void updateUserAgentLabel(const QString &userAgentDatabaseName) const;
private:
// The private variables.
BrowserView *browserViewPointer;
KConfigDialog *configDialogPointer;
+ QString currentDomainSettingsDomain;
+ QUrl currentUrl;
+ double currentZoomFactor;
QAction *domainSettingsActionPointer;
QPalette domainSettingsPalette;
- double currentZoomFactor;
QAction *javaScriptActionPointer;
QAction *localStorageActionPointer;
QPalette noDomainSettingsPalette;