2 * Copyright © 2022 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"
25 #include "helpers/UserAgentHelper.h"
27 // Qt toolkit headers.
28 #include <QInputDialog>
29 #include <QMessageBox>
30 #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 domain settings dialog UI.
47 Ui::DomainSettingsDialog domainSettingsDialogUi;
50 domainSettingsDialogUi.setupUi(this);
52 // Get handles for the widgets.
53 domainsListViewPointer = domainSettingsDialogUi.domainsListView;
54 domainSettingsWidgetPointer = domainSettingsDialogUi.domainSettingsWidget;
55 domainNameLineEditPointer = domainSettingsDialogUi.domainNameLineEdit;
56 javaScriptWidgetPointer = domainSettingsDialogUi.javaScriptWidget;
57 javaScriptComboBoxPointer = domainSettingsDialogUi.javaScriptComboBox;
58 javaScriptLabelPointer = domainSettingsDialogUi.javaScriptLabel;
59 localStorageWidgetPointer = domainSettingsDialogUi.localStorageWidget;
60 localStorageComboBoxPointer = domainSettingsDialogUi.localStorageComboBox;
61 localStorageLabelPointer = domainSettingsDialogUi.localStorageLabel;
62 domStorageWidgetPointer = domainSettingsDialogUi.domStorageWidget;
63 domStorageComboBoxPointer = domainSettingsDialogUi.domStorageComboBox;
64 domStorageLabelPointer = domainSettingsDialogUi.domStorageLabel;
65 userAgentWidgetPointer = domainSettingsDialogUi.userAgentWidget;
66 userAgentComboBoxPointer = domainSettingsDialogUi.userAgentComboBox;
67 userAgentLabelPointer = domainSettingsDialogUi.userAgentLabel;
68 zoomFactorWidgetPointer = domainSettingsDialogUi.zoomFactorWidget;
69 zoomFactorComboBoxPointer = domainSettingsDialogUi.zoomFactorComboBox;
70 customZoomFactorSpinBoxPointer = domainSettingsDialogUi.customZoomFactorSpinBox;
71 QPushButton *addDomainButtonPointer = domainSettingsDialogUi.addDomainButton;
72 deleteDomainButtonPointer = domainSettingsDialogUi.deleteDomainButton;
73 QDialogButtonBox *dialogButtonBoxPointer = domainSettingsDialogUi.dialogButtonBox;
74 applyButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::StandardButton::Apply);
75 resetButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::StandardButton::Reset);
77 // Create a table model.
78 domainsTableModelPointer = new QSqlTableModel(nullptr, QSqlDatabase::database(DomainsDatabase::CONNECTION_NAME));
80 // Set the table for the model.
81 domainsTableModelPointer->setTable(DomainsDatabase::DOMAINS_TABLE);
83 // Set the edit strategy to be manual.
84 domainsTableModelPointer->setEditStrategy(QSqlTableModel::EditStrategy::OnManualSubmit);
86 // Sort the output alphabetically.
87 domainsTableModelPointer->setSort(1, Qt::SortOrder::AscendingOrder);
89 // Set the model for the list view.
90 domainsListViewPointer->setModel(domainsTableModelPointer);
92 // Set the visible column to be the domain name.
93 domainsListViewPointer->setModelColumn(1);
95 // Get the domains selection model pointer.
96 domainsSelectionModelPointer = domainsListViewPointer->selectionModel();
98 // Disable editing of the list view.
99 domainsListViewPointer->setEditTriggers(QAbstractItemView::NoEditTriggers);
101 // Read the data from the database and apply it to the table model.
102 domainsTableModelPointer->select();
104 // Get the default palette.
105 defaultPalette = javaScriptWidgetPointer->palette();
107 // Populate the highlighted palette.
108 highlightedPalette = defaultPalette;
110 // Get the default highlight color.
111 QColor highlightColor = defaultPalette.color(QPalette::Highlight);
113 // Set the highlight color to be partially transparent.
114 highlightColor.setAlpha(64);
116 // Set highlighted background color.
117 highlightedPalette.setColor(QPalette::Window, highlightColor);
119 // Setup the dialog according to the start type.
122 case SHOW_ALL_DOMAINS:
124 // Select the first entry in the list view.
125 domainsListViewPointer->setCurrentIndex(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME)));
127 // Populate the domain settings.
128 domainSelected(domainsSelectionModelPointer->currentIndex());
135 // Add the new domain.
136 addDomain(domainName);
143 // Find the index for the new domain. `1` returns the first match.
144 QModelIndexList newDomainIndex = domainsTableModelPointer->match(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME)),
145 Qt::DisplayRole, domainName, 1, Qt::MatchWrap);
147 // Move to the new domain.
148 domainsListViewPointer->setCurrentIndex(newDomainIndex[0]);
150 // Populate the domain settings.
151 domainSelected(domainsSelectionModelPointer->currentIndex());
157 // Handle clicks on the domains.
158 connect(domainsListViewPointer, SIGNAL(activated(QModelIndex)), this, SLOT(domainSelected(QModelIndex)));
160 // Process changes to the domain settings.
161 connect(domainNameLineEditPointer, SIGNAL(textEdited(QString)), this, SLOT(domainNameChanged(QString)));
162 connect(javaScriptComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(javaScriptChanged(int)));
163 connect(localStorageComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(localStorageChanged(int)));
164 connect(domStorageComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(domStorageChanged(int)));
165 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(QString)), this, SLOT(userAgentChanged(QString)));
166 connect(zoomFactorComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(zoomFactorComboBoxChanged(int)));
167 connect(customZoomFactorSpinBoxPointer, SIGNAL(valueChanged(double)), this, SLOT(customZoomFactorChanged(double)));
169 // Connect the buttons.
170 connect(addDomainButtonPointer, SIGNAL(clicked()), this, SLOT(showAddMessageBox()));
171 connect(deleteDomainButtonPointer, SIGNAL(clicked()), this, SLOT(showDeleteMessageBox()));
172 connect(resetButtonPointer, SIGNAL(clicked()), this, SLOT(reset()));
173 connect(dialogButtonBoxPointer, SIGNAL(accepted()), this, SLOT(ok()));
174 connect(applyButtonPointer, SIGNAL(clicked()), this, SLOT(apply()));
175 connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(cancel()));
181 void DomainSettingsDialog::addDomain(const QString &domainName) const
183 // Create a new domain record.
184 QSqlRecord newDomainRecord = QSqlDatabase::database(DomainsDatabase::CONNECTION_NAME).record(DomainsDatabase::DOMAINS_TABLE);
186 // Set the values for the new domain.
187 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME), domainName);
188 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::JAVASCRIPT), DomainsDatabase::SYSTEM_DEFAULT);
189 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOM_STORAGE), DomainsDatabase::SYSTEM_DEFAULT);
190 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::USER_AGENT), UserAgentHelper::SYSTEM_DEFAULT_DATABASE);
191 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::ZOOM_FACTOR), DomainsDatabase::SYSTEM_DEFAULT);
192 newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::CUSTOM_ZOOM_FACTOR), 1.0);
194 // Insert the new domain. `-1` appends it to the end.
195 domainsTableModelPointer->insertRecord(-1, newDomainRecord);
197 // Submit all pending changes.
198 domainsTableModelPointer->submitAll();
200 // Find the index for the new domain. `-1` allows for multiple entries to be returned.
201 QModelIndexList newDomainIndex = domainsTableModelPointer->match(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME)),
202 Qt::DisplayRole, domainName, -1, Qt::MatchWrap);
204 // Move to the new domain. If there are multiple domains with the same name, the new one should be the last in the list.
205 domainsListViewPointer->setCurrentIndex(newDomainIndex[newDomainIndex.size() - 1]);
207 // Populate the domain settings.
208 domainSelected(domainsSelectionModelPointer->currentIndex());
214 void DomainSettingsDialog::apply() const
216 // Get the current index.
217 QModelIndex currentIndex = domainsListViewPointer->currentIndex();
219 // Get the ID of the current index row.
220 QVariant currentId = currentIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::_ID)).data();
222 // Submit all pending changes.
223 domainsTableModelPointer->submitAll();
225 // Find the new index for the selected id. The `1` keeps searching after the first match.
226 QModelIndexList newIndexList = domainsTableModelPointer->match(currentIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::_ID)), Qt::DisplayRole, currentId,
229 // Select the new index.
230 domainsListViewPointer->setCurrentIndex(newIndexList[0].siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME)));
235 // Emit the domain settings updated signal.
236 emit domainSettingsUpdated();
239 void DomainSettingsDialog::cancel()
241 // Revert all pending changes.
242 domainsTableModelPointer->revertAll();
248 void DomainSettingsDialog::customZoomFactorChanged(const double &newValue) const
250 // Update the domains table model.
251 domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::CUSTOM_ZOOM_FACTOR)), newValue);
257 void DomainSettingsDialog::domStorageChanged(const int &newIndex) const
259 // Update the domains table model.
260 domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOM_STORAGE)), newIndex);
262 // Populate the DOM storage label.
263 populateDomStorageLabel();
269 void DomainSettingsDialog::domainNameChanged(const QString &updatedDomainName) const
271 // Update the domains table model.
272 domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex(), updatedDomainName);
278 void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const
280 // Populate the domain name line edit pointer.
281 domainNameLineEditPointer->setText(modelIndex.data().toString());
283 // Populate the JavaScript combo box.
284 javaScriptComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::JAVASCRIPT)).data().toInt());
286 // Populate the local storage combo box.
287 localStorageComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::LOCAL_STORAGE)).data().toInt());
289 // Populate the DOM storage combo box.
290 domStorageComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOM_STORAGE)).data().toInt());
292 // Get the user agent string.
293 QString userAgent = modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::USER_AGENT)).data().toString();
295 // Get the user agent index.
296 int userAgentIndex = UserAgentHelper::getDomainSettingsUserAgentIndex(userAgent);
298 // Set the user agent combo box index.
299 userAgentComboBoxPointer->setCurrentIndex(userAgentIndex);
301 // Set the custom user agent if specified.
302 if (userAgentIndex == -1) userAgentComboBoxPointer->setCurrentText(userAgent);
304 // Get the zoom factor combo box index.
305 int zoomFactorComboBoxIndex = modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::ZOOM_FACTOR)).data().toInt();
307 // Populate the zoom factor combo box.
308 zoomFactorComboBoxPointer->setCurrentIndex(zoomFactorComboBoxIndex);
310 // Populate the custom zoom factor spin box according to the zoom factor combo box.
311 if (zoomFactorComboBoxIndex == 0) // System default zoom factor is selected.
313 // Display the default zoom factor.
314 customZoomFactorSpinBoxPointer->setValue(Settings::zoomFactor());
316 else // Custom zoom factor is selected.
318 // Display the custom zoom factor from the domain settings.
319 customZoomFactorSpinBoxPointer->setValue(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::CUSTOM_ZOOM_FACTOR)).data().toDouble());
322 // Set the initial status of the custom zoom factor spin box.
323 customZoomFactorSpinBoxPointer->setEnabled(zoomFactorComboBoxIndex);
325 // Populate the labels.
326 populateJavaScriptLabel();
327 populateLocalStorageLabel();
328 populateDomStorageLabel();
329 populateUserAgentLabel(userAgentComboBoxPointer->currentText());
335 void DomainSettingsDialog::javaScriptChanged(const int &newIndex) const
337 // Update the domains table model.
338 domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::JAVASCRIPT)), newIndex);
340 // Populate the JavaScript label.
341 populateJavaScriptLabel();
347 void DomainSettingsDialog::localStorageChanged(const int &newIndex) const
349 // Update the domains table model.
350 domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::LOCAL_STORAGE)), newIndex);
352 // Poplate the local storage label.
353 populateLocalStorageLabel();
359 void DomainSettingsDialog::ok()
361 // Submit all pending changes.
362 domainsTableModelPointer->submitAll();
364 // Emit the domain settings updated signal.
365 domainSettingsUpdated();
371 void DomainSettingsDialog::populateDomStorageLabel() const
373 // Populate the label according to the currently selected index.
374 switch (domStorageComboBoxPointer->currentIndex())
376 case (DomainsDatabase::SYSTEM_DEFAULT):
378 // Set the text according to the system default.
379 if (Settings::domStorageEnabled())
380 domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label.", "DOM storage enabled"));
382 domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label.", "DOM storage disabled"));
384 // Reset the palette.
385 domStorageWidgetPointer->setPalette(defaultPalette);
390 case (DomainsDatabase::DISABLED):
392 // Set the disabled text in bold.
393 domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The <b> tags should be retained.", "<b>DOM storage disabled</b>"));
396 domStorageWidgetPointer->setPalette(highlightedPalette);
401 case (DomainsDatabase::ENABLED):
403 // Set the enabled text in bold.
404 domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The <b> tags should be retained.", "<b>DOM storage enabled</b>"));
407 domStorageWidgetPointer->setPalette(highlightedPalette);
414 void DomainSettingsDialog::populateJavaScriptLabel() const
416 // Populate the label according to the currently selected index.
417 switch (javaScriptComboBoxPointer->currentIndex())
419 case (DomainsDatabase::SYSTEM_DEFAULT):
421 // Set the text according to the system default.
422 if (Settings::javaScriptEnabled())
423 javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label.", "JavaScript enabled"));
425 javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label.", "JavaScript disabled"));
427 // Reset the palette.
428 javaScriptWidgetPointer->setPalette(defaultPalette);
433 case (DomainsDatabase::DISABLED):
435 // Set the disabled text in bold.
436 javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The <b> tags should be retained.", "<b>JavaScript disabled</b>"));
439 javaScriptWidgetPointer->setPalette(highlightedPalette);
444 case (DomainsDatabase::ENABLED):
446 // Set the enabled text in bold.
447 javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The <b> tags should be retained.", "<b>JavaScript enabled</b>"));
450 javaScriptWidgetPointer->setPalette(highlightedPalette);
457 void DomainSettingsDialog::populateLocalStorageLabel() const
459 // Populate the label according to the currently selected index.
460 switch (localStorageComboBoxPointer->currentIndex())
462 case (DomainsDatabase::SYSTEM_DEFAULT):
464 // Set the text according to the system default.
465 if (Settings::localStorageEnabled())
466 localStorageLabelPointer->setText(i18nc("Domain settings local storage label.", "Local storage enabled"));
468 localStorageLabelPointer->setText(i18nc("Domain settings local storage label.", "Local storage disabled"));
470 // Reset the palette.
471 localStorageWidgetPointer->setPalette(defaultPalette);
476 case (DomainsDatabase::DISABLED):
478 // Set the disabled text in bold.
479 localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The <b> tags should be retained.", "<b>Local storage disabled</b>"));
482 localStorageWidgetPointer->setPalette(highlightedPalette);
487 case (DomainsDatabase::ENABLED):
489 // Set the enabled text in bold.
490 localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The <b> tabs should be retained.", "<b>Local storage enabled</b>"));
493 localStorageWidgetPointer->setPalette(highlightedPalette);
501 void DomainSettingsDialog::populateUserAgentLabel(const QString &userAgentName) const
503 // Populate the label according to the type.
504 if (userAgentName == UserAgentHelper::SYSTEM_DEFAULT_TRANSLATED)
506 // Display the system default user agent name.
507 userAgentLabelPointer->setText(UserAgentHelper::getTranslatedUserAgentNameFromDatabaseName(Settings::userAgent()));
509 // Reset the palette.
510 userAgentWidgetPointer->setPalette(defaultPalette);
514 // Display the user agent name in bold.
515 userAgentLabelPointer->setText("<strong>" + userAgentName + "</strong>");
518 userAgentWidgetPointer->setPalette(highlightedPalette);
522 void DomainSettingsDialog::reset() const
524 // Cancel all pending changes.
525 domainsTableModelPointer->revertAll();
527 // Repopulate the domain settings.
528 domainSelected(domainsListViewPointer->currentIndex());
534 void DomainSettingsDialog::showAddMessageBox()
536 // Create an OK flag.
539 // Display a dialog to request the new domain name from the user.
540 QString newDomainName = QInputDialog::getText(this, i18nc("Add domain dialog title", "Add Domain"),
541 i18nc("Add domain message. The \n\n are newline codes that should be retained",
542 "Add a new domain. Doing so will also save any pending changes that have been made to other domains.\n\n"
543 "*. may be prepended to a domain to include all subdomains (eg. *.stoutner.com)."),
544 QLineEdit::Normal, QString(), &okClicked);
546 // Add the new domain if the user clicked OK.
547 if (okClicked) addDomain(newDomainName);
550 void DomainSettingsDialog::showDeleteMessageBox() const
552 // Instantiate a delete dialog message box.
553 QMessageBox deleteDialogMessageBox;
556 deleteDialogMessageBox.setIcon(QMessageBox::Warning);
558 // Set the window title.
559 deleteDialogMessageBox.setWindowTitle(i18nc("Delete domain dialog title", "Delete Domain"));
562 deleteDialogMessageBox.setText(i18nc("Delete domain dialog main message", "Delete the current domain?"));
564 // Set the informative text.
565 deleteDialogMessageBox.setInformativeText(i18nc("Delete domain dialog secondary message", "Doing so will also save any pending changes that have been made to other domains."));
567 // Set the standard buttons.
568 deleteDialogMessageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
570 // Set the default button.
571 deleteDialogMessageBox.setDefaultButton(QMessageBox::No);
573 // Display the dialog and capture the return value.
574 int returnValue = deleteDialogMessageBox.exec();
576 // Delete the domain if instructed.
577 if (returnValue == QMessageBox::Yes)
579 // Get the current index.
580 QModelIndex currentIndex = domainsListViewPointer->currentIndex();
582 // Delete the current row.
583 domainsTableModelPointer->removeRow(domainsSelectionModelPointer->currentIndex().row());
585 // Submit all pending changes.
586 domainsTableModelPointer->submitAll();
588 // Select the row next to the deleted item if one exists.
589 if (domainsTableModelPointer->rowCount() > 0)
591 // Check the row of the deleted item.
592 if (currentIndex.row() == 0) // The first row was deleted.
594 // Reselect the current index.
595 domainsListViewPointer->setCurrentIndex(currentIndex);
597 else // A subsequent row was deleted.
599 // Select the crow above the deleted itemm.
600 domainsListViewPointer->setCurrentIndex(currentIndex.siblingAtRow(currentIndex.row() - 1));
603 // Populate the domain settings.
604 domainSelected(domainsListViewPointer->currentIndex());
612 void DomainSettingsDialog::updateUi() const
614 // Update the delete button status.
615 deleteDomainButtonPointer->setEnabled(domainsSelectionModelPointer->hasSelection());
617 // Update the reset button status.
618 resetButtonPointer->setEnabled(domainsTableModelPointer->isDirty());
620 // Update the apply button status.
621 applyButtonPointer->setEnabled(domainsTableModelPointer->isDirty());
623 // Display the domain settings if there is at least one domain.
624 domainSettingsWidgetPointer->setVisible(domainsTableModelPointer->rowCount() > 0);
627 void DomainSettingsDialog::userAgentChanged(const QString &updatedUserAgent) const
629 // Update the domains table model.
630 domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::USER_AGENT)),
631 UserAgentHelper::getDatabaseUserAgentNameFromTranslatedName(updatedUserAgent));
633 // Populate the user agent label.
634 populateUserAgentLabel(updatedUserAgent);
640 void DomainSettingsDialog::zoomFactorComboBoxChanged(const int &newIndex) const
642 // Get the current model index.
643 QModelIndex modelIndex = domainsSelectionModelPointer->currentIndex();
645 // Update the domains table model.
646 domainsTableModelPointer->setData(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::ZOOM_FACTOR)), newIndex);
648 // Populate the custom zoom factor spin box according to the zoom factor combo box.
649 if (newIndex == 0) // System default zoom factor is selected.
651 // Display the default zoom factor.
652 customZoomFactorSpinBoxPointer->setValue(Settings::zoomFactor());
654 // Reset the palette.
655 zoomFactorWidgetPointer->setPalette(defaultPalette);
657 else // Custom zoom factor is selected.
659 // Display the custom zoom factor from the domain settings.
660 customZoomFactorSpinBoxPointer->setValue(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::CUSTOM_ZOOM_FACTOR)).data().toDouble());
663 zoomFactorWidgetPointer->setPalette(highlightedPalette);
666 // Update the status of the custom zoom factor spin box.
667 customZoomFactorSpinBoxPointer->setEnabled(newIndex);