Files
2026-08-30 19:13:43 +08:00

130 lines
4.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Copyright (C) 2024–present Loren Eteval & contributors <loren.eteval@proton.me>
#
# This file is part of Furious.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Provide widgets for GUI customize proxy bypass."""
from __future__ import annotations
from Furious.Frozenlib import *
from Furious.Qt import *
from Furious.Qt import gettext as _
from PySide6 import QtCore
from PySide6.QtWidgets import *
import logging
__all__ = ['ProxyBypassDialog']
logger = logging.getLogger(__name__)
class ProxyBypassDialog(AppQDialog):
"""Present the GUI customize proxy bypass dialog."""
DEFAULT_DIALOG_SIZE = QtCore.QSize(656, 125)
def __init__(self, *args, **kwargs):
"""Initialize the proxy bypass settings dialog."""
super().__init__(*args, **kwargs)
self.setWindowTitle(_('Customize System Proxy Bypass Address'))
self.setWindowModality(QtCore.Qt.WindowModality.WindowModal)
self.proxyBypassText = AppQLabel(
_('Enter system proxy bypass address (separated by semicolons):')
)
self.proxyBypassEdit = AppQLineEdit()
settings = AppSettings.get('CustomProxyBypass')
if isinstance(settings, str):
self.proxyBypassEdit.setText(settings)
else:
self.proxyBypassEdit.setText(PROXY_SERVER_BYPASS)
self.dialogBtns = AppQDialogButtonBox(QtCore.Qt.Orientation.Horizontal)
self.dialogBtns.addButton(_('OK'), AppQDialogButtonBox.ButtonRole.AcceptRole)
self.dialogBtns.addButton(
_('Cancel'), AppQDialogButtonBox.ButtonRole.RejectRole
)
connectWeakly(self.dialogBtns.accepted, self, 'accept')
connectWeakly(self.dialogBtns.rejected, self, 'reject')
self.resetBtn = AppQPushButton(_('Reset'))
connectWeakly(
self.resetBtn.clicked,
self,
'handleResetButtonClicked',
)
self.hboxLayout = QHBoxLayout()
self.hboxLayout.addWidget(self.resetBtn)
self.hboxLayout.addWidget(self.dialogBtns)
layout = QFormLayout()
layout.addRow(self.proxyBypassText)
layout.addRow(self.proxyBypassEdit)
layout.addRow(self.hboxLayout)
layout.setFormAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.setLayout(layout)
connectWeakly(self.finished, self, 'handleResultCode')
def handleResultCode(self, code):
"""Handle result code."""
if code == PySide6Legacy.enumValueWrapper(AppQDialog.DialogCode.Accepted):
oldValue = AppSettings.get('CustomProxyBypass')
newValue = self.proxyBypassEdit.text()
def writeNewSettings(value):
"""Handle write new settings for the GUI customize proxy bypass dialog."""
logger.info(f'setting custom proxy bypass address to \'{value}\'')
AppSettings.set('CustomProxyBypass', value)
showMBoxNewChangesNextTime()
if not isinstance(oldValue, str):
if newValue == PROXY_SERVER_BYPASS:
return
else:
writeNewSettings(newValue)
else:
if oldValue != newValue:
writeNewSettings(newValue)
else:
try:
settings = AppSettings.get('CustomProxyBypass')
if settings is not None:
self.proxyBypassEdit.setText(str(settings))
else:
self.proxyBypassEdit.setText(PROXY_SERVER_BYPASS)
except Exception as ex:
# Any non-exit exceptions
logger.error(f'error restoring proxy bypass address: {ex}')
@QtCore.Slot()
def handleResetButtonClicked(self):
"""Handle reset button clicked."""
self.proxyBypassEdit.setText(PROXY_SERVER_BYPASS)