2 * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
6 * Privacy Browser PC is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser PC is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
20 // Application headers.
21 #include "DomainSettingsDialog.h"
23 #include "ui_DomainSettingsDialog.h"
24 #include "databases/DomainsDatabase.h"
26 // Qt toolkit headers.
27 #include <QInputDialog>
28 #include <QMessageBox>
29 #include <QPushButton>
32 // Define the public static int constants.
33 const int DomainSettingsDialog::SHOW_ALL_DOMAINS = 0;
34 const int DomainSettingsDialog::ADD_DOMAIN = 1;
35 const int DomainSettingsDialog::EDIT_DOMAIN = 2;
37 // Construct the class.
38 DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString &domainName) : QDialog(nullptr)
40 // Set the window title.
41 setWindowTitle(i18nc("The domain settings dialog window title", "Domain Settings"));
43 // Set the window modality.
44 setWindowModality(Qt::WindowModality::ApplicationModal);
46 // Instantiate the user agent helper.
47 userAgentHelperPointer = new UserAgentHelper();
49 // Instantiate the domain settings dialog UI.
50 Ui::DomainSettingsDialog domainSettingsDialogUi;
53 domainSettingsDialogUi.setupUi(this);
55 // Get handles for the widgets.
56 domainsListViewPointer = domainSettingsDialogUi.domainsListView;
57 domainSettingsWidgetPointer = domainSettingsDialogUi.domainSettingsWidget;
58 domainNameLineEditPointer = domainSettingsDialogUi.domainNameLineEdit;
59 javaScriptWidgetPointer = domainSettingsDialogUi.javaScriptWidget;
60 javaScriptComboBoxPointer = domainSettingsDialogUi.javaScriptComboBox;
61 javaScriptLabelPointer = domainSettingsDialogUi.javaScriptLabel;
62 localStorageWidgetPointer = domainSettingsDialogUi.localStorageWidget;
63 localStorageComboBoxPointer = domainSettingsDialogUi.localStorageComboBox;
64 localStorageLabelPointer = domainSettingsDialogUi.localStorageLabel;
65 domStorageWidgetPointer = domainSettingsDialogUi.domStorageWidget;
66 domStorageComboBoxPointer = domainSettingsDialogUi.domStorageComboBox;
67 domStorageLabelPointer = domainSettingsDialogUi.domStorageLabel;
68 userAgentWidgetPointer = domainSettingsDialogUi.userAgentWidget;
69 userAgentComboBoxPointer = domainSettingsDialogUi.userAgentComboBox;
70 userAgentLabelPointer = domainSettingsDialogUi.userAgentLabel;
71 zoomFactorWidgetPointer = domainSettingsDialogUi.zoomFactorWidget;
72 zoomFactorComboBoxPointer = domainSettingsDialogUi.zoomFactorComboBox;
73 customZoomFactorSpinBoxPointer = domainSettingsDialogUi.customZoomFactorSpinBox;
74 QPushButton *addDomainButtonPointer = domainSettingsDialogUi.addDomainButton;
75 deleteDomainButtonPointer = domainSettingsDialogUi.deleteDomainButton;
76 QDialogButtonBox *dialogButtonBoxPointer = domainSettingsDialogUi.dialogButtonBox;
77 applyButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::StandardButton::Apply);
78 resetButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::StandardButton::Reset);
80 // Create a table model.
81 domainsTableModelPointer = new QSqlTableModel(nullptr, QSqlDatabase::database(DomainsDatabase::CONNECTION_NAME));
83 // Set the table for the model.
84 domainsTableModelPointer->setTable(DomainsDatabase::DOMAINS_TABLE);
86 // Set the edit strategy to be manual.
87 domainsTableModelPointer->setEditStrategy(QSqlTableModel::EditStrategy::OnManualSubmit);
89 // Sort the output alphabetically.
90 domainsTableModelPointer->setSort(1, Qt::SortOrder::AscendingOrder);
92 // Set the model for the list view.
93 domainsListViewPointer->setModel(domainsTableModelPointer);
95 // Set the visible column to be the domain name.
96 domainsListViewPointer->setModelColumn(1);
98 // Get the domains selection model pointer.
99 domainsSelectionModelPointer = domainsListViewPointer->selectionModel();
101 // Disable editing of the list view.
102 domainsListViewPointer->setEditTriggers(QAbstractItemView::NoEditTriggers);
104 // Read the data from the database and apply it to the table model.
105 domainsTableModelPointer->select();
107 // Get the default palette.
108 defaultPalette = javaScriptWidgetPointer->palette();
110 // Populate the highlighted palette.
111 highlightedPalette = defaultPalette;
113 // Get the default highlight color.
114 QColor highlightColor = defaultPalette.color(QPalette::Highlight);
116 // Set the highlight color to be partially transparent.
117 highlightColor.setAlpha(64);
119 // Set highlighted background color.
120 highlightedPalette.setColor(QPalette::Window, highlightColor);
122 // Setup the dialog according to the start type.
125 case SHOW_ALL_DOMAINS:
127 // Select the first entry in the list view.
128 domainsListViewPointer->setCurrentIndex(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME)));
130 // Populate the domain settings.
131 domainSelected(domainsSelectionModelPointer->currentIndex());
138 // Add the new domain.
139 addDomain(domainName);
141 // Emit the domain settings updated signal after 100 milliseconds. This is necessary because the browser window takes time to process the connect command to receive the signal.
142 QTimer::singleShot(100, [this] () { emit domainSettingsUpdated();});
149 // Find the index for the new domain. `1` returns the first match.
150 QModelIndexList newDomainIndex = domainsTableModelPointer->match(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME)),
151 Qt::DisplayRole, domainName, 1, Qt::MatchWrap);
153 // Move to the new domain.
154 domainsListViewPointer->setCurrentIndex(newDomainIndex[0]);
156 // Populate the domain settings.
157 domainSelected(domainsSelectionModelPointer->currentIndex());
163 // Handle clicks on the domains.
164 connect(domainsListViewPointer, SIGNAL(activated(QModelIndex)), this, SLOT(domainSelected(QModelIndex)));
166 // Process changes to the domain settings.
167 connect(domainNameLineEditPointer, SIGNAL(textEdited(QString)), this, SLOT(domainNameChanged(QString)));
168 connect(javaScriptComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(javaScriptChanged(int)));
169 connect(localStorageComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(localStorageChanged(int)));
170 connect(domStorageComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(domStorageChanged(int)));
171 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(QString)), this, SLOT(userAgentChanged(QString)));
172 connect(zoomFactorComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(zoomFactorComboBoxChanged(int)));
173 connect(customZoomFactorSpinBoxPointer, SIGNAL(valueChanged(double)), this, SLOT(customZoomFactorChanged(double)));
175 // Connect the buttons.
176 connect(addDomainButtonPointer, SIGNAL(clicked()), this, SLOT(showAddMessageBox()));
177 connect(deleteDomainButtonPointer, SIGNAL(clicked()), this, SLOT(showDeleteMessageBox()));
178 connect(resetButtonPointer, SIGNAL(clicked()), this, SLOT(reset()));
179 connect(dialogButtonBoxPointer, SIGNAL(accepted()), this, SLOT(ok()));
180 connect(applyButtonPointer, SIGNAL(clicked()), this, SLOT(apply()));
181 connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(cancel()));
187 void DomainSettingsDialog::addDomain(const QString &domainName) const
189 // Create a new domain record.
190 QSqlRecord newDomainRecord = QSqlDatabase::database(DomainsDatabase::CONNECTION_NAME).record(DomainsDatabase::DOMAINS_TABLE);
192 // Set the values for the new domain.
193 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME), domainName);
194 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::JAVASCRIPT), DomainsDatabase::SYSTEM_DEFAULT);
195 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::LOCAL_STORAGE), DomainsDatabase::SYSTEM_DEFAULT);
196 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOM_STORAGE), DomainsDatabase::SYSTEM_DEFAULT);
197 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::USER_AGENT), UserAgentHelper::SYSTEM_DEFAULT_DATABASE);
198 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::ZOOM_FACTOR), DomainsDatabase::SYSTEM_DEFAULT);
199 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::CUSTOM_ZOOM_FACTOR), 1.0);
201 // Insert the new domain. `-1` appends it to the end.
202 domainsTableModelPointer->insertRecord(-1, newDomainRecord);
204 // Submit all pending changes.
205 domainsTableModelPointer->submitAll();
207 // Find the index for the new domain. `-1` allows for multiple entries to be returned.
208 QModelIndexList newDomainIndex = domainsTableModelPointer->match(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME)),
209 Qt::DisplayRole, domainName, -1, Qt::MatchWrap);
211 // Move to the new domain. If there are multiple domains with the same name, the new one should be the last in the list.
212 domainsListViewPointer->setCurrentIndex(newDomainIndex[newDomainIndex.size() - 1]);
214 // Populate the domain settings.
215 domainSelected(domainsSelectionModelPointer->currentIndex());
220 // Emit the domain settings updated signal.
221 emit domainSettingsUpdated();
224 void DomainSettingsDialog::apply() const
226 // Get the current index.
227 QModelIndex currentIndex = domainsListViewPointer->currentIndex();
229 // Get the ID of the current index row.
230 QVariant currentId = currentIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::ID)).data();
232 // Submit all pending changes.
233 domainsTableModelPointer->submitAll();
235 // Find the new index for the selected id. The `1` keeps searching after the first match.
236 QModelIndexList newIndexList = domainsTableModelPointer->match(currentIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::ID)), Qt::DisplayRole, currentId,
239 // Select the new index.
240 domainsListViewPointer->setCurrentIndex(newIndexList[0].siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME)));
245 // Emit the domain settings updated signal.
246 emit domainSettingsUpdated();
249 void DomainSettingsDialog::cancel()
251 // Revert all pending changes.
252 domainsTableModelPointer->revertAll();
258 void DomainSettingsDialog::customZoomFactorChanged(const double &newValue) const
260 // Update the domains table model.
261 domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::CUSTOM_ZOOM_FACTOR)), newValue);
267 void DomainSettingsDialog::domStorageChanged(const int &newIndex) const
269 // Update the domains table model.
270 domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOM_STORAGE)), newIndex);
272 // Populate the DOM storage label.
273 populateDomStorageLabel();
279 void DomainSettingsDialog::domainNameChanged(const QString &updatedDomainName) const
281 // Update the domains table model.
282 domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex(), updatedDomainName);
288 void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const
290 // Populate the domain name line edit pointer.
291 domainNameLineEditPointer->setText(modelIndex.data().toString());
293 // Populate the JavaScript combo box.
294 javaScriptComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::JAVASCRIPT)).data().toInt());
296 // Populate the local storage combo box.
297 localStorageComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::LOCAL_STORAGE)).data().toInt());
299 // Populate the DOM storage combo box.
300 domStorageComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOM_STORAGE)).data().toInt());
302 // Get the user agent string.
303 QString userAgent = modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::USER_AGENT)).data().toString();
305 // Get the user agent index.
306 int userAgentIndex = UserAgentHelper::getDomainSettingsUserAgentIndex(userAgent);
308 // Set the user agent combo box index.
309 userAgentComboBoxPointer->setCurrentIndex(userAgentIndex);
311 // Set the custom user agent if specified.
312 if (userAgentIndex == -1) userAgentComboBoxPointer->setCurrentText(userAgent);
314 // Get the zoom factor combo box index.
315 int zoomFactorComboBoxIndex = modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::ZOOM_FACTOR)).data().toInt();
317 // Populate the zoom factor combo box.
318 zoomFactorComboBoxPointer->setCurrentIndex(zoomFactorComboBoxIndex);
320 // Populate the custom zoom factor spin box according to the zoom factor combo box.
321 if (zoomFactorComboBoxIndex == 0) // System default zoom factor is selected.
323 // Display the default zoom factor.
324 customZoomFactorSpinBoxPointer->setValue(Settings::zoomFactor());
326 else // Custom zoom factor is selected.
328 // Display the custom zoom factor from the domain settings.
329 customZoomFactorSpinBoxPointer->setValue(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::CUSTOM_ZOOM_FACTOR)).data().toDouble());
332 // Set the initial status of the custom zoom factor spin box.
333 customZoomFactorSpinBoxPointer->setEnabled(zoomFactorComboBoxIndex);
335 // Populate the labels.
336 populateJavaScriptLabel();
337 populateLocalStorageLabel();
338 populateDomStorageLabel();
339 populateUserAgentLabel(userAgentComboBoxPointer->currentText());
345 void DomainSettingsDialog::javaScriptChanged(const int &newIndex) const
347 // Update the domains table model.
348 domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::JAVASCRIPT)), newIndex);
350 // Populate the JavaScript label.
351 populateJavaScriptLabel();
357 void DomainSettingsDialog::localStorageChanged(const int &newIndex) const
359 // Update the domains table model.
360 domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::LOCAL_STORAGE)), newIndex);
362 // Populate the local storage label.
363 populateLocalStorageLabel();
369 void DomainSettingsDialog::ok()
371 // Submit all pending changes.
372 domainsTableModelPointer->submitAll();
374 // Emit the domain settings updated signal.
375 emit domainSettingsUpdated();
381 void DomainSettingsDialog::populateDomStorageLabel() const
383 // Populate the label according to the currently selected index.
384 switch (domStorageComboBoxPointer->currentIndex())
386 case (DomainsDatabase::SYSTEM_DEFAULT):
388 // Set the text according to the system default.
389 if (Settings::domStorageEnabled())
390 domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label.", "DOM storage enabled"));
392 domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label.", "DOM storage disabled"));
394 // Reset the palette.
395 domStorageWidgetPointer->setPalette(defaultPalette);
400 case (DomainsDatabase::ENABLED):
402 // Set the enabled text in bold.
403 domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The <b> tags should be retained.", "<b>DOM storage enabled</b>"));
406 domStorageWidgetPointer->setPalette(highlightedPalette);
411 case (DomainsDatabase::DISABLED):
413 // Set the disabled text in bold.
414 domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The <b> tags should be retained.", "<b>DOM storage disabled</b>"));
417 domStorageWidgetPointer->setPalette(highlightedPalette);
424 void DomainSettingsDialog::populateJavaScriptLabel() const
426 // Populate the label according to the currently selected index.
427 switch (javaScriptComboBoxPointer->currentIndex())
429 case (DomainsDatabase::SYSTEM_DEFAULT):
431 // Set the text according to the system default.
432 if (Settings::javaScriptEnabled())
433 javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label.", "JavaScript enabled"));
435 javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label.", "JavaScript disabled"));
437 // Reset the palette.
438 javaScriptWidgetPointer->setPalette(defaultPalette);
443 case (DomainsDatabase::ENABLED):
445 // Set the enabled text in bold.
446 javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The <b> tags should be retained.", "<b>JavaScript enabled</b>"));
449 javaScriptWidgetPointer->setPalette(highlightedPalette);
454 case (DomainsDatabase::DISABLED):
456 // Set the disabled text in bold.
457 javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The <b> tags should be retained.", "<b>JavaScript disabled</b>"));
460 javaScriptWidgetPointer->setPalette(highlightedPalette);
467 void DomainSettingsDialog::populateLocalStorageLabel() const
469 // Populate the label according to the currently selected index.
470 switch (localStorageComboBoxPointer->currentIndex())
472 case (DomainsDatabase::SYSTEM_DEFAULT):
474 // Set the text according to the system default.
475 if (Settings::localStorageEnabled())
476 localStorageLabelPointer->setText(i18nc("Domain settings local storage label.", "Local storage enabled"));
478 localStorageLabelPointer->setText(i18nc("Domain settings local storage label.", "Local storage disabled"));
480 // Reset the palette.
481 localStorageWidgetPointer->setPalette(defaultPalette);
486 case (DomainsDatabase::ENABLED):
488 // Set the enabled text in bold.
489 localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The <b> tabs should be retained.", "<b>Local storage enabled</b>"));
492 localStorageWidgetPointer->setPalette(highlightedPalette);
497 case (DomainsDatabase::DISABLED):
499 // Set the disabled text in bold.
500 localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The <b> tags should be retained.", "<b>Local storage disabled</b>"));
503 localStorageWidgetPointer->setPalette(highlightedPalette);
511 void DomainSettingsDialog::populateUserAgentLabel(const QString &userAgentName) const
513 // Populate the label according to the type.
514 if (userAgentName == userAgentHelperPointer->SYSTEM_DEFAULT_TRANSLATED)
516 // Display the system default user agent name.
517 userAgentLabelPointer->setText(userAgentHelperPointer->getTranslatedUserAgentNameFromDatabaseName(Settings::userAgent()));
519 // Reset the palette.
520 userAgentWidgetPointer->setPalette(defaultPalette);
524 // Display the user agent name in bold.
525 userAgentLabelPointer->setText("<strong>" + userAgentName + "</strong>");
528 userAgentWidgetPointer->setPalette(highlightedPalette);
532 void DomainSettingsDialog::reset() const
534 // Cancel all pending changes.
535 domainsTableModelPointer->revertAll();
537 // Repopulate the domain settings.
538 domainSelected(domainsListViewPointer->currentIndex());
544 void DomainSettingsDialog::showAddMessageBox()
546 // Create an OK flag.
549 // Display a dialog to request the new domain name from the user.
550 QString newDomainName = QInputDialog::getText(this, i18nc("Add domain dialog title", "Add Domain"),
551 i18nc("Add domain message. The \n\n are newline codes that should be retained",
552 "Add a new domain. Doing so will also save any pending changes that have been made to other domains.\n\n"
553 "*. may be prepended to a domain to include all subdomains (eg. *.stoutner.com)."),
554 QLineEdit::Normal, QString(), &okClicked);
556 // Add the new domain if the user clicked OK.
557 if (okClicked) addDomain(newDomainName);
560 void DomainSettingsDialog::showDeleteMessageBox() const
562 // Instantiate a delete dialog message box.
563 QMessageBox deleteDialogMessageBox;
566 deleteDialogMessageBox.setIcon(QMessageBox::Warning);
568 // Set the window title.
569 deleteDialogMessageBox.setWindowTitle(i18nc("Delete domain dialog title", "Delete Domain"));
572 deleteDialogMessageBox.setText(i18nc("Delete domain dialog main message", "Delete the current domain?"));
574 // Set the informative text.
575 deleteDialogMessageBox.setInformativeText(i18nc("Delete domain dialog secondary message", "Doing so will also save any pending changes that have been made to other domains."));
577 // Set the standard buttons.
578 deleteDialogMessageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
580 // Set the default button.
581 deleteDialogMessageBox.setDefaultButton(QMessageBox::No);
583 // Display the dialog and capture the return value.
584 int returnValue = deleteDialogMessageBox.exec();
586 // Delete the domain if instructed.
587 if (returnValue == QMessageBox::Yes)
589 // Get the current index.
590 QModelIndex currentIndex = domainsListViewPointer->currentIndex();
592 // Delete the current row.
593 domainsTableModelPointer->removeRow(domainsSelectionModelPointer->currentIndex().row());
595 // Submit all pending changes.
596 domainsTableModelPointer->submitAll();
598 // Select the row next to the deleted item if one exists.
599 if (domainsTableModelPointer->rowCount() > 0)
601 // Check the row of the deleted item.
602 if (currentIndex.row() == 0) // The first row was deleted.
604 // Reselect the current index.
605 domainsListViewPointer->setCurrentIndex(currentIndex);
607 else // A subsequent row was deleted.
609 // Select the crow above the deleted itemm.
610 domainsListViewPointer->setCurrentIndex(currentIndex.siblingAtRow(currentIndex.row() - 1));
613 // Populate the domain settings.
614 domainSelected(domainsListViewPointer->currentIndex());
620 // Emit the domain settings updated signal.
621 emit domainSettingsUpdated();
625 void DomainSettingsDialog::updateUi() const
627 // Update the delete button status.
628 deleteDomainButtonPointer->setEnabled(domainsSelectionModelPointer->hasSelection());
630 // Update the reset button status.
631 resetButtonPointer->setEnabled(domainsTableModelPointer->isDirty());
633 // Update the apply button status.
634 applyButtonPointer->setEnabled(domainsTableModelPointer->isDirty());
636 // Display the domain settings if there is at least one domain.
637 domainSettingsWidgetPointer->setVisible(domainsTableModelPointer->rowCount() > 0);
640 void DomainSettingsDialog::userAgentChanged(const QString &updatedUserAgent) const
642 // Update the domains table model.
643 domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::USER_AGENT)),
644 userAgentHelperPointer->getDatabaseUserAgentNameFromTranslatedName(updatedUserAgent));
646 // Populate the user agent label.
647 populateUserAgentLabel(updatedUserAgent);
653 void DomainSettingsDialog::zoomFactorComboBoxChanged(const int &newIndex) const
655 // Get the current model index.
656 QModelIndex modelIndex = domainsSelectionModelPointer->currentIndex();
658 // Update the domains table model.
659 domainsTableModelPointer->setData(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::ZOOM_FACTOR)), newIndex);
661 // Populate the custom zoom factor spin box according to the zoom factor combo box.
662 if (newIndex == 0) // System default zoom factor is selected.
664 // Display the default zoom factor.
665 customZoomFactorSpinBoxPointer->setValue(Settings::zoomFactor());
667 // Reset the palette.
668 zoomFactorWidgetPointer->setPalette(defaultPalette);
670 else // Custom zoom factor is selected.
672 // Display the custom zoom factor from the domain settings.
673 customZoomFactorSpinBoxPointer->setValue(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::CUSTOM_ZOOM_FACTOR)).data().toDouble());
676 zoomFactorWidgetPointer->setPalette(highlightedPalette);
679 // Update the status of the custom zoom factor spin box.
680 customZoomFactorSpinBoxPointer->setEnabled(newIndex);