From 197df9c2568a7047a42f36dfb5e1be9269447fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Thu, 12 Dec 2019 18:40:39 -0300 Subject: [PATCH] [wgem] allow internal URLs installation option --- bauh/api/abstract/view.py | 16 ++++++++++++++++ bauh/gems/web/controller.py | 11 ++++++----- bauh/gems/web/resources/locale/en | 2 ++ bauh/gems/web/resources/locale/pt | 2 ++ bauh/view/qt/components.py | 28 +++++++++++++++++++++++++++- bauh/view/qt/confirmation.py | 6 ++++-- 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/bauh/api/abstract/view.py b/bauh/api/abstract/view.py index e1eacfd2..406bf537 100644 --- a/bauh/api/abstract/view.py +++ b/bauh/api/abstract/view.py @@ -97,3 +97,19 @@ class TextComponent(ViewComponent): def __init__(self, html: str, id_: str = None): super(TextComponent, self).__init__(id_=id_) self.value = html + + +class TextInputComponent(ViewComponent): + + def __init__(self, label: str, value: str = '', placeholder: str = None, tooltip: str = None, id_: str = None): + super(TextInputComponent, self).__init__(id_=id_) + self.label = label + self.value = value + self.tooltip = tooltip + self.placeholder = placeholder + + def get_value(self) -> str: + if self.value is not None: + return self.value.strip() + else: + return '' diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index 8efb1d99..558e84b2 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -16,7 +16,7 @@ from bauh.api.abstract.disk import DiskCacheLoader from bauh.api.abstract.handler import ProcessWatcher from bauh.api.abstract.model import SoftwarePackage, PackageAction, PackageSuggestion, PackageUpdate, PackageHistory from bauh.api.abstract.view import MessageType, MultipleSelectComponent, InputOption, SingleSelectComponent, \ - SelectViewType + SelectViewType, TextInputComponent from bauh.commons.html import bold from bauh.commons.system import ProcessHandler, get_dir_size, get_human_size_str from bauh.gems.web import INSTALLED_PATH, nativefier, DESKTOP_ENTRY_PATH_PATTERN @@ -179,6 +179,7 @@ class WebApplicationManager(SoftwareManager): op_max = InputOption(label=self.i18n['web.install.option.max.label'], value="--maximize", tooltip=self.i18n['web.install.option.max.tip']) op_fs = InputOption(label=self.i18n['web.install.option.fullscreen.label'], value="--full-screen", tooltip=self.i18n['web.install.option.fullscreen.tip']) op_nframe = InputOption(label=self.i18n['web.install.option.noframe.label'], value="--hide-window-frame", tooltip=self.i18n['web.install.option.noframe.tip']) + op_allow_urls = InputOption(label=self.i18n['web.install.option.allow_urls.label'], value='--internal-urls=.*', tooltip=self.i18n['web.install.option.allow_urls.tip']) op_ncache = InputOption(label=self.i18n['web.install.option.nocache.label'], value="--clear-cache", tooltip=self.i18n['web.install.option.nocache.tip']) op_insecure = InputOption(label=self.i18n['web.install.option.insecure.label'], value="--insecure", tooltip=self.i18n['web.install.option.insecure.tip']) op_igcert = InputOption(label=self.i18n['web.install.option.ignore_certificate.label'], value="--ignore-certificate", tooltip=self.i18n['web.install.option.ignore_certificate.tip']) @@ -187,10 +188,9 @@ class WebApplicationManager(SoftwareManager): tray_op_default = InputOption(label=self.i18n['web.install.option.tray.default.label'], value='--tray', tooltip=self.i18n['web.install.option.tray.default.tip']) tray_op_min = InputOption(label=self.i18n['web.install.option.tray.min.label'], value='--tray=start-in-tray', tooltip=self.i18n['web.install.option.tray.min.tip']) - check_options = MultipleSelectComponent(options=[op_single, op_max, op_fs, op_nframe, op_ncache, op_insecure, op_igcert], default_options={op_single}, label='') + check_options = MultipleSelectComponent(options=[op_single, op_allow_urls, op_max, op_fs, op_nframe, op_ncache, op_insecure, op_igcert], default_options={op_single}, label='') input_tray = SingleSelectComponent(type_=SelectViewType.COMBO, options=[tray_op_off, tray_op_default, tray_op_min], label=self.i18n['web.install.option.tray.label']) - # input_internal_urls = TextInput() res = watcher.request_confirmation(title=self.i18n['web.install.options_dialog.title'], body=self.i18n['web.install.options_dialog.body'].format(bold(bt_continue)), components=[check_options, input_tray], @@ -203,8 +203,9 @@ class WebApplicationManager(SoftwareManager): if check_options.values: selected.extend(check_options.get_selected_values()) - if input_tray.value: - selected.append(input_tray.get_selected_value()) + tray_mode = input_tray.get_selected_value() + if tray_mode is not None and tray_mode != 0: + selected.append(tray_mode) return res, selected diff --git a/bauh/gems/web/resources/locale/en b/bauh/gems/web/resources/locale/en index 0c0bebbf..146c5766 100644 --- a/bauh/gems/web/resources/locale/en +++ b/bauh/gems/web/resources/locale/en @@ -25,6 +25,8 @@ web.install.option.insecure.label=Allow insecure content web.install.option.insecure.tip=It allows the execution of insecure content within the application web.install.option.ignore_certificate.label=Ignore certificate errors web.install.option.ignore_certificate.tip=Certificate related errors will be ignored by the app +web.install.option.allow_urls.label=Allow internal URLs +web.install.option.allow_urls.tip=It allows the application to internally open addresses / URLs outside its domain. e.g: outlook.live.com would be able to open account.microsoft.com web.install.option.tray.label=Tray mode web.install.option.tray.off.label=Off web.install.option.tray.off.tip=Off diff --git a/bauh/gems/web/resources/locale/pt b/bauh/gems/web/resources/locale/pt index 4214dcc3..e00ee9de 100644 --- a/bauh/gems/web/resources/locale/pt +++ b/bauh/gems/web/resources/locale/pt @@ -25,6 +25,8 @@ web.install.option.insecure.label=Permitir conteúdo não confiável web.install.option.insecure.tip=Permite a execução de conteúdo não confiável dentro do aplicativo web.install.option.ignore_certificate.label=Ignorar erros de certificado web.install.option.ignore_certificate.tip=Erros associados a certificados serão ignorados pelo aplicativo +web.install.option.allow_urls.label=Permitir URLs internas +web.install.option.allow_urls.tip=Permite que o aplicativo abra internamente endereços / URLs fora do seu domínio. Exemplo: outlook.live.com conseguiria abrir account.microsoft.com web.install.option.tray.label=Modo bandeja web.install.option.tray.off.label=Desligado web.install.option.tray.off.tip=Desligado diff --git a/bauh/view/qt/components.py b/bauh/view/qt/components.py index 1e2d242b..9b8c921c 100644 --- a/bauh/view/qt/components.py +++ b/bauh/view/qt/components.py @@ -3,7 +3,8 @@ from PyQt5.QtGui import QIcon, QPixmap from PyQt5.QtWidgets import QRadioButton, QGroupBox, QCheckBox, QComboBox, QGridLayout, QWidget, \ QLabel, QSizePolicy, QLineEdit, QToolButton, QHBoxLayout -from bauh.api.abstract.view import SingleSelectComponent, InputOption, MultipleSelectComponent, SelectViewType +from bauh.api.abstract.view import SingleSelectComponent, InputOption, MultipleSelectComponent, SelectViewType, \ + TextInputComponent from bauh.view.util import resource @@ -114,6 +115,31 @@ class ComboSelectQt(QGroupBox): self.layout().addWidget(QLabel(model.label + ' :'), 0, 0) self.layout().addWidget(ComboBoxQt(model), 0, 1) + +class TextInputQt(QGroupBox): + + def __init__(self, model: TextInputComponent): + super(TextInputQt, self).__init__() + self.model = model + self.setLayout(QGridLayout()) + self.setStyleSheet('QGridLayout {margin-left: 0} QLabel { font-weight: bold}') + self.layout().addWidget(QLabel(model.label + ' :'), 0, 0) + + self.text_input = QLineEdit() + + if model.placeholder: + self.text_input.setPlaceholderText(model.placeholder) + + if model.tooltip: + self.text_input.setToolTip(model.tooltip) + + self.text_input.textChanged.connect(self._update_model) + + self.layout().addWidget(self.text_input, 0, 1) + + def _update_model(self, text: str): + self.model.value = text + # class ComboSelectQt(QGroupBox): # # def __init__(self, model: SingleSelectComponent): diff --git a/bauh/view/qt/confirmation.py b/bauh/view/qt/confirmation.py index 11b2f501..654a6d84 100644 --- a/bauh/view/qt/confirmation.py +++ b/bauh/view/qt/confirmation.py @@ -3,9 +3,9 @@ from typing import List from PyQt5.QtCore import QSize from PyQt5.QtWidgets import QMessageBox, QVBoxLayout, QLabel, QWidget, QScrollArea, QFrame -from bauh.api.abstract.view import ViewComponent, SingleSelectComponent, MultipleSelectComponent +from bauh.api.abstract.view import ViewComponent, SingleSelectComponent, MultipleSelectComponent, TextInputComponent from bauh.view.qt import css -from bauh.view.qt.components import MultipleSelectQt, new_single_select +from bauh.view.qt.components import MultipleSelectQt, new_single_select, TextInputQt from bauh.view.util.translation import I18n @@ -43,6 +43,8 @@ class ConfirmationDialog(QMessageBox): inst = new_single_select(comp) elif isinstance(comp, MultipleSelectComponent): inst = MultipleSelectQt(comp, None) + elif isinstance(comp, TextInputComponent): + inst = TextInputQt(comp) else: raise Exception("Cannot render instances of " + comp.__class__.__name__)