File indexing completed on 2024-05-19 05:01:19
0001 /* 0002 This file is part of the KDE project. 0003 0004 SPDX-FileCopyrightText: 2020 Stefano Crocco <posta@stefanocrocco.it> 0005 0006 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0007 */ 0008 0009 #include "webenginecustomizecacheablefieldsdlg.h" 0010 0011 #include <QDialogButtonBox> 0012 #include <QStandardItem> 0013 #include <QCheckBox> 0014 0015 #include "ui_webenginecustomizecacheablefieldsdlg.h" 0016 #include "webfieldsdataview.h" 0017 0018 using WebForm = WebEngineWallet::WebForm; 0019 using WebFormList = WebEngineWallet::WebFormList; 0020 using WebField = WebEngineWallet::WebForm::WebField; 0021 using WebFieldType = WebEngineWallet::WebForm::WebFieldType; 0022 0023 WebEngineCustomizeCacheableFieldsDlg::WebEngineCustomizeCacheableFieldsDlg(const WebEngineWallet::WebFormList &forms, const OldCustomizationData &oldCustomization, QWidget* parent): 0024 QDialog(parent), m_model(new WebFieldsDataModel(true, this)), 0025 m_ui(new Ui::WebEngineCustomizeCacheableFieldsDlg) 0026 { 0027 m_ui->setupUi(this); 0028 connect(m_ui->showPasswords, &QCheckBox::toggled, m_ui->fields, &WebFieldsDataView::togglePasswords); 0029 connect(m_ui->showDetails, &QCheckBox::toggled, m_ui->fields, &WebFieldsDataView::toggleDetails); 0030 m_model->setForms(forms); 0031 addChecksToPreviouslyChosenItems(forms, oldCustomization); 0032 m_ui->fields->setModel(m_model); 0033 m_ui->fields->horizontalHeader()->setStretchLastSection(true); 0034 m_ui->fields->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); 0035 m_ui->fields->toggleDetails(m_ui->showDetails->isChecked()); 0036 } 0037 0038 WebFormList WebEngineCustomizeCacheableFieldsDlg::selectedFields() const 0039 { 0040 return m_model->checkedFields(); 0041 } 0042 0043 bool WebEngineCustomizeCacheableFieldsDlg::immediatelyCacheData() const 0044 { 0045 return m_ui->immediatelyCacheData->isChecked(); 0046 } 0047 0048 void WebEngineCustomizeCacheableFieldsDlg::addChecksToPreviouslyChosenItems(const WebEngineWallet::WebFormList &forms, const OldCustomizationData &data) 0049 { 0050 bool autoCheck = data.isEmpty(); 0051 int row = 0; 0052 for (int i = 0; i < forms.length(); ++i) { 0053 const WebForm &form = forms.at(i); 0054 QStringList oldCustomInThisForm = data.value(form.name); 0055 for (int j = 0; j < form.fields.length(); ++j) { 0056 WebField field = form.fields.at(j); 0057 QStandardItem *chosen = m_model->item(row, WebFieldsDataModel::ChosenCol); 0058 bool checked = false; 0059 if (autoCheck) { 0060 checked = !field.value.isEmpty() && !field.readOnly && !field.disabled && field.autocompleteAllowed; 0061 } else { 0062 checked = oldCustomInThisForm.contains(field.name); 0063 } 0064 chosen->setCheckState(checked ? Qt::Checked : Qt::Unchecked); 0065 ++row; 0066 } 0067 } 0068 }