Clean up obsolete source code

Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
Loren Eteval
2026-08-12 12:24:03 +08:00
parent 1820c1db26
commit 4d88940434
14 changed files with 45 additions and 468 deletions
-86
View File
@@ -1,86 +0,0 @@
# 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/>.
"""Implement tray actions for language."""
from __future__ import annotations
from Furious.Frozenlib import *
from Furious.Qt import *
from Furious.Qt import gettext as _
import logging
__all__ = ['LanguageAction']
logger = logging.getLogger(__name__)
# Handy stuff
SMART_CHOSEN_LANGUAGE = (
SYSTEM_LANGUAGE if SYSTEM_LANGUAGE in SUPPORTED_LANGUAGE else 'EN'
)
registerAppSettings(
'Language', validRange=SUPPORTED_LANGUAGE, default=SMART_CHOSEN_LANGUAGE
)
class LanguageChildAction(AppQAction):
"""Handle the language child action."""
def __init__(self, *args, **kwargs):
"""Initialize the LanguageChildAction."""
super().__init__(*args, **kwargs)
def triggeredCallback(self, checked):
"""Handle activation of the action."""
abbr = LANGUAGE_TO_ABBR[self.text()]
if AppSettings.get('Language') != abbr:
logger.info(f'set language to \'{self.text()}\'')
AppSettings.set('Language', abbr)
Mixins.QTranslatable.retranslateAll()
def retranslate(self):
# Nothing to do
"""Refresh translated text for the language child action."""
pass
class LanguageAction(AppQAction):
"""Handle the language action."""
def __init__(self, **kwargs):
"""Initialize the LanguageAction."""
super().__init__(
_('Language'),
icon=bootstrapIcon('globe2.svg'),
menu=AppQMenu(
*list(
LanguageChildAction(
# Language representation
text,
checkable=True,
checked=text == ABBR_TO_LANGUAGE[AppSettings.get('Language')],
)
for text in list(LANGUAGE_TO_ABBR.keys())
),
),
**kwargs,
)
-2
View File
@@ -29,7 +29,6 @@ from .Import import (
ImportQRCodeOnTheScreenAction,
ImportURIFromClipboardAction,
)
from .Language import LanguageAction
from .Routing import RoutingAction
__all__ = [
@@ -41,7 +40,6 @@ __all__ = [
'ImportJSONFromClipboardAction',
'ImportQRCodeOnTheScreenAction',
'ImportURIFromClipboardAction',
'LanguageAction',
'RoutingAction',
'ShowHomePageAction',
]
-6
View File
@@ -31,7 +31,6 @@ __all__ = [
'DEFAULT_HYSTERIA2_TUN_SETTINGS',
'buildHysteria2TUNConfig',
'getHysteria2TUNSettings',
'hasHysteria2TUNConfig',
'isHysteria2TUNEnabled',
'resolveHysteria2ServerAddresses',
'saveHysteria2TUNSettings',
@@ -258,8 +257,3 @@ def buildHysteria2TUNConfig(settings=None, serverAddresses=()) -> dict:
result['route'] = route
return result
def hasHysteria2TUNConfig(config) -> bool:
"""Return whether a Hysteria 2 configuration contains native TUN mode."""
return isinstance(config.get('tun'), dict)
-64
View File
@@ -1593,69 +1593,6 @@ class GuiVTransportItemAuthHysteria(GuiEditorItemTextInput):
self.setText('')
class GuiVTransportItemPasswordHysteria(GuiEditorItemTextInput):
"""Represent GUI v transport item password hysteria."""
def __init__(self, *args, **kwargs):
"""Initialize the GuiVTransportItemPasswordHysteria."""
super().__init__(*args, **kwargs)
def inputToFactory(self, config: ConfigFactory) -> bool:
"""Apply the current editor value to the configuration."""
streamSettings = ConfigXray.getProxyOutboundStream(config)
if not isinstance(streamSettings.get('finalmask'), dict):
streamSettings['finalmask'] = {}
finalmaskObject = streamSettings['finalmask']
if not isinstance(finalmaskObject.get('salamander'), dict):
finalmaskObject['salamander'] = {}
salamander = finalmaskObject['salamander']
try:
oldPassword = salamander.get('password', '')
except Exception:
# Any non-exit exceptions
oldPassword = ''
newPassword = self.text()
def setNewPassword():
"""Set new password."""
if newPassword == '':
finalmaskObject.pop('salamander', None)
else:
salamander['password'] = newPassword
if isinstance(oldPassword, str):
if newPassword != oldPassword:
setNewPassword()
return True
else:
return False
else:
setNewPassword()
return True
def factoryToInput(self, config: ConfigFactory):
"""Load the configuration value into the editor."""
try:
salamander = ConfigXray.getProxyOutboundStream(config)['finalmask'][
'salamander'
]
self.setText(salamander.get('password', ''))
except Exception:
# Any non-exit exceptions
self.setText('')
class GuiVTransportPageXXX(GuiEditorWidgetQWidget):
"""Represent GUI v transport page xxx."""
@@ -1882,7 +1819,6 @@ class GuiVTransportPageHysteria(GuiVTransportPageXXX):
GuiVTransportItemFinalMask(title='Finalmask', translatable=False),
GuiVTransportItemVersionHysteria(title='Version', translatable=False),
GuiVTransportItemAuthHysteria(title='Auth', translatable=False),
# GuiVTransportItemPasswordHysteria(title='Password', translatable=False),
]
@@ -6,6 +6,14 @@
# 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/>.
"""Apply persistent application preferences independently from their UI."""
+8
View File
@@ -6,6 +6,14 @@
# 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/>.
"""Expose presentation-independent application controllers."""
+5 -36
View File
@@ -6,8 +6,7 @@ TRANSLATION = {
"Furious.Qt.QtWidgets",
"Furious.Widget.ServerTableView",
"Furious.Widget.SubscriptionTableView",
"Furious.Window.SubscriptionPage",
"Furious.Window.SubscriptionWindow"
"Furious.Window.SubscriptionPage"
],
"RU": "Удалить",
"ZH": "删除",
@@ -228,7 +227,6 @@ TRANSLATION = {
"Furious.Window.NetworkTestDialog",
"Furious.Window.ProxyBypassDialog",
"Furious.Window.SubscriptionPage",
"Furious.Window.SubscriptionWindow",
"Furious.Window.TextEditorWindow"
],
"RU": "Отмена",
@@ -664,51 +662,24 @@ TRANSLATION = {
},
"Add Subscription": {
"source": [
"Furious.Window.SubscriptionPage",
"Furious.Window.SubscriptionWindow"
"Furious.Window.SubscriptionPage"
],
"RU": "Добавить подписку",
"ZH": "添加订阅",
"isReviewed": "True"
},
"Enter subscription remark:": {
"source": [
"Furious.Window.SubscriptionWindow"
],
"RU": "Введите примечание о подписке:",
"ZH": "输入订阅名称:",
"isReviewed": "True"
},
"Enter subscription URL:": {
"source": [
"Furious.Window.SubscriptionWindow"
],
"RU": "Введите URL-адрес подписки:",
"ZH": "输入订阅URL:",
"isReviewed": "True"
},
"Edit Subscription": {
"source": [
"Furious.Window.SubscriptionPage",
"Furious.Window.SubscriptionWindow"
"Furious.Window.SubscriptionPage"
],
"RU": "Редактировать подписку",
"ZH": "编辑订阅",
"isReviewed": "True"
},
"Subscription List": {
"source": [
"Furious.Window.SubscriptionWindow"
],
"RU": "Список подписок",
"ZH": "订阅列表",
"isReviewed": "True"
},
"Add": {
"source": [
"Furious.Backends.Xray.RoutingWindow",
"Furious.Window.SubscriptionPage",
"Furious.Window.SubscriptionWindow"
"Furious.Window.SubscriptionPage"
],
"RU": "Добавить",
"ZH": "添加",
@@ -953,7 +924,6 @@ TRANSLATION = {
},
"Language": {
"source": [
"Furious.Actions.Language",
"Furious.Window.SettingsPage"
],
"RU": "Язык",
@@ -1307,8 +1277,7 @@ TRANSLATION = {
"Furious.Window.IndentDialog",
"Furious.Window.NetworkTestDialog",
"Furious.Window.ProxyBypassDialog",
"Furious.Window.SubscriptionPage",
"Furious.Window.SubscriptionWindow"
"Furious.Window.SubscriptionPage"
],
"RU": "OK",
"ZH": "OK",
+8
View File
@@ -100,4 +100,12 @@ ABBR_TO_LANGUAGE = {value: key for key, value in LANGUAGE_TO_ABBR.items()}
SUPPORTED_LANGUAGE = list(LANGUAGE_TO_ABBR.values())
_SMART_CHOSEN_LANGUAGE = (
SYSTEM_LANGUAGE if SYSTEM_LANGUAGE in SUPPORTED_LANGUAGE else 'EN'
)
registerAppSettings(
'Language', validRange=SUPPORTED_LANGUAGE, default=_SMART_CHOSEN_LANGUAGE
)
installTranslation(TRANSLATION)
-63
View File
@@ -53,7 +53,6 @@ __all__ = [
'AppQPushButton',
'AppQSpinBox',
'AppQTableView',
'AppQTableWidget',
'AppQTabWidget',
'AppQToolBar',
'IconTextPushButton',
@@ -870,68 +869,6 @@ class AppQTableView(QTableView):
self.verticalHeader().setDefaultSectionSize(height)
class AppQTableWidget(QTableWidget):
"""Provide the app Qt table widget."""
def __init__(self, *args, **kwargs):
"""Initialize the AppQTableWidget."""
super().__init__(*args, **kwargs)
self.setWordWrap(False)
self.setAlternatingRowColors(True)
@property
def selectedIndex(self):
"""Return the selected index value."""
return sorted(list(set(index.row() for index in self.selectedIndexes())))
def activateItemByIndex(self, index, activate):
"""Activate item by index."""
if activate:
for column in range(self.columnCount()):
item = self.item(int(index), column)
if item is None:
# Do nothing
continue
font = item.font()
font.setBold(True)
item.setFont(font)
item.setForeground(QColor(AppHue.currentColor()))
else:
for column in range(self.columnCount()):
item = self.item(int(index), column)
if item is None:
# Do nothing
continue
font = item.font()
font.setBold(False)
item.setFont(font)
item.setForeground(QBrush())
def selectMultipleRows(self, indexes: list[int], clearCurrentSelection: bool):
"""Select multiple rows."""
if clearCurrentSelection:
self.selectionModel().clearSelection()
selection = self.selectionModel().selection()
for index in indexes:
selection.select(
self.model().index(index, 0),
self.model().index(index, self.columnCount() - 1),
)
self.selectionModel().select(
selection, QtCore.QItemSelectionModel.SelectionFlag.Select
)
class AppQTabWidget(Mixins.QTranslatable, QTabWidget):
"""Provide the app q tab widget."""
-2
View File
@@ -68,7 +68,6 @@ from .QtWidgets import (
AppQPushButton,
AppQSpinBox,
AppQTableView,
AppQTableWidget,
AppQTabWidget,
AppQToolBar,
IconTextPushButton,
@@ -123,7 +122,6 @@ __all__ = [
'AppQSpinBox',
'AppQTabWidget',
'AppQTableView',
'AppQTableWidget',
'AppQTextBrowser',
'AppQToolBar',
'AppStyleSheet',
+8
View File
@@ -6,6 +6,14 @@
# 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/>.
"""Bridge plugin UI capabilities into the host's page-based interface."""
+8
View File
@@ -6,6 +6,14 @@
# 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/>.
"""Present subscription definitions and synchronization as a dedicated page."""
-207
View File
@@ -1,207 +0,0 @@
# 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 the application window for user subs window."""
from __future__ import annotations
from Furious.Frozenlib import *
from Furious.Qt import *
from Furious.Qt import gettext as _
from Furious.Widget.SubscriptionTableView import *
from PySide6 import QtCore
from PySide6.QtWidgets import *
import uuid
import functools
__all__ = ['SubscriptionWindow']
# Migrate legacy settings
registerAppSettings('SubscriptionWidgetWindowSize')
registerAppSettings('UserSubsWindowGeometry')
registerAppSettings('UserSubsWindowState')
class AddSubsDialog(AppQDialog):
"""Present the add subs dialog."""
def __init__(self, *args, **kwargs):
"""Initialize the AddSubsDialog."""
super().__init__(*args, **kwargs)
self.setWindowTitle(_('Add Subscription'))
self.remarkText = AppQLabel(_('Enter subscription remark:'))
self.remarkEdit = QLineEdit()
self.webURLText = AppQLabel(_('Enter subscription URL:'))
self.webURLEdit = QLineEdit()
self.dialogBtns = AppQDialogButtonBox(QtCore.Qt.Orientation.Horizontal)
self.dialogBtns.addButton(_('OK'), AppQDialogButtonBox.ButtonRole.AcceptRole)
self.dialogBtns.addButton(
_('Cancel'), AppQDialogButtonBox.ButtonRole.RejectRole
)
self.dialogBtns.accepted.connect(self.accept)
self.dialogBtns.rejected.connect(self.reject)
layout = QFormLayout()
layout.addRow(self.remarkText)
layout.addRow(self.remarkEdit)
layout.addRow(self.webURLText)
layout.addRow(self.webURLEdit)
layout.addRow(self.dialogBtns)
layout.setFormAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.setLayout(layout)
def setWidthAndHeight(self):
"""Apply the default size for the add subs dialog."""
self.resize(456, 150)
def subsRemark(self):
"""Return the subs remark value used by the add subs dialog."""
return self.remarkEdit.text()
def subsWebURL(self):
"""Return the subs web URL value used by the add subs dialog."""
return self.webURLEdit.text()
class SubscriptionWindow(AppQMainWindow):
"""Present the user subs window."""
DEFAULT_WINDOW_SIZE = QtCore.QSize(1120, 600)
def __init__(self, *args, **kwargs):
"""Initialize the subscription window."""
callback = kwargs.pop('deleteUniqueCallback', None)
super().__init__(*args, **kwargs)
self.setWindowTitle(_('Edit Subscription'))
self.userSubsQTableWidget = SubscriptionTableView(
deleteUniqueCallback=callback, parent=self
)
self.userSubsTab = AppQTabWidget(self)
self.userSubsTab.addTab(self.userSubsQTableWidget, _('Subscription List'))
self.toolbar = AppQToolBar(
AppQAction(
_('Add'),
icon=bootstrapIcon('plus-lg.svg'),
callback=lambda: self.addSubs(),
),
AppQAction(
_('Delete'),
icon=bootstrapIcon('dash-lg.svg'),
callback=lambda: self.deleteSelectedItem(),
),
parent=self,
)
self.toolbar.setObjectName('UserSubsWindow_AppQToolBar')
self.addToolBar(self.toolbar)
self.fakeCentralWidget = QWidget()
self.fakeCentralWidgetLayout = QVBoxLayout(self.fakeCentralWidget)
self.fakeCentralWidgetLayout.addWidget(self.userSubsTab)
self.setCentralWidget(self.fakeCentralWidget)
def addSubs(self):
"""Add subs."""
def handleResultCode(_addSubsDialog, code):
"""Handle result code."""
if code == PySide6Legacy.enumValueWrapper(AppQDialog.DialogCode.Accepted):
remark = _addSubsDialog.subsRemark()
webURL = _addSubsDialog.subsWebURL()
if remark:
# Unique id. Used by display and deletion
unique = str(uuid.uuid4())
self.userSubsQTableWidget.appendNewItem(
unique=unique, remark=remark, webURL=webURL
)
else:
# Do nothing
pass
addSubsDialog = AddSubsDialog(parent=self)
addSubsDialog.setWindowModality(QtCore.Qt.WindowModality.WindowModal)
addSubsDialog.finished.connect(
functools.partial(handleResultCode, addSubsDialog)
)
# Show the MessageBox asynchronously
addSubsDialog.open()
def deleteSelectedItem(self):
"""Delete selected item."""
self.userSubsQTableWidget.deleteSelectedItem()
def keyPressEvent(self, event):
"""Handle a key press for the user subs window."""
if event.key() == QtCore.Qt.Key.Key_Delete:
self.deleteSelectedItem()
else:
super().keyPressEvent(event)
def setWidthAndHeight(self):
"""Apply the default size for the user subs window."""
if AppSettings.get('UserSubsWindowGeometry') is None:
# Migrate legacy settings
try:
windowSize = AppSettings.get('SubscriptionWidgetWindowSize').split(',')
width, height = tuple(int(size) for size in windowSize)
if (width, height) == (640, 480):
self.resize(SubscriptionWindow.DEFAULT_WINDOW_SIZE)
else:
self.resize(width, height)
except Exception:
# Any non-exit exceptions
self.resize(SubscriptionWindow.DEFAULT_WINDOW_SIZE)
else:
if PLATFORM == 'Darwin':
self.resize(SubscriptionWindow.DEFAULT_WINDOW_SIZE)
else:
try:
self.restoreGeometry(AppSettings.get('UserSubsWindowGeometry'))
except Exception:
# Any non-exit exceptions
self.resize(SubscriptionWindow.DEFAULT_WINDOW_SIZE)
try:
self.restoreState(AppSettings.get('UserSubsWindowState'))
except Exception:
# Any non-exit exceptions
pass
def cleanup(self):
"""Release resources owned by the user subs window."""
AppSettings.set('UserSubsWindowGeometry', self.saveGeometry())
AppSettings.set('UserSubsWindowState', self.saveState())
-2
View File
@@ -29,7 +29,6 @@ from .SubscriptionPage import SubscriptionPage
from .NetworkTestDialog import NetworkTestDialog
from .ProxyBypassDialog import ProxyBypassDialog
from .QRCodeWindow import QRCodeWindow
from .SubscriptionWindow import SubscriptionWindow
from .TextEditorWindow import TextEditorWindow
from .TunSettingsDialog import TunSettingsDialog
@@ -44,7 +43,6 @@ __all__ = [
'NetworkTestDialog',
'ProxyBypassDialog',
'QRCodeWindow',
'SubscriptionWindow',
'TextEditorWindow',
'TunSettingsDialog',
]