2025-10-29 22:20:21 +08:00
|
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
|
|
|
|
from loguru import logger
|
|
|
|
|
|
from PyQt6.QtCore import QSize
|
|
|
|
|
|
from PyQt6.QtGui import QColor, QIcon
|
|
|
|
|
|
from PyQt6.QtWidgets import QApplication, QWidget
|
|
|
|
|
|
from qfluentwidgets import NavigationAvatarWidget, NavigationItemPosition, SplashScreen
|
2025-11-02 19:17:20 +08:00
|
|
|
|
from qfluentwidgets import FluentIcon
|
2025-10-29 22:20:21 +08:00
|
|
|
|
|
|
|
|
|
|
from app.core import cfg, qconfig, userConfig, GetUserAvatarThread,lang,signalBus
|
|
|
|
|
|
from app.view.app_info_interface import AppInfoInterface
|
|
|
|
|
|
from app.view.ownFiled_interface import OwnFiledInterface
|
|
|
|
|
|
from app.view.setting_interface import SettingInterface
|
|
|
|
|
|
from app.view.storagespace_interface import StoragespaceInterface
|
|
|
|
|
|
from app.view.task_interface import TaskInterface
|
|
|
|
|
|
from app.view.widgets.custom_fluent_window import CustomFluentWindow
|
|
|
|
|
|
from app.view.widgets.preview_box import OptimizedPreviewBox, PreviewTextBox
|
|
|
|
|
|
from app.view.widgets.share_folder_messageBox import ShareFolderMessageBox
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MainWindow(CustomFluentWindow):
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
logger.info("开始初始化主窗口")
|
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
self.initWindow()
|
|
|
|
|
|
|
|
|
|
|
|
self.ownFiledInterface = OwnFiledInterface(self)
|
|
|
|
|
|
self.storagespaceInterface = StoragespaceInterface(self)
|
|
|
|
|
|
self.taskInterface = TaskInterface(self)
|
|
|
|
|
|
self.appInfoInterface = AppInfoInterface(self)
|
|
|
|
|
|
|
|
|
|
|
|
self.connectSignalToSlot()
|
|
|
|
|
|
|
|
|
|
|
|
self.initNavigation()
|
|
|
|
|
|
logger.info("主窗口初始化完成")
|
|
|
|
|
|
|
|
|
|
|
|
def connectSignalToSlot(self):
|
|
|
|
|
|
logger.debug("连接信号和槽")
|
|
|
|
|
|
signalBus.micaEnableChanged.connect(self.setMicaEffectEnabled)
|
|
|
|
|
|
# 预览信号连接
|
|
|
|
|
|
signalBus.imagePreviewSignal.connect(self.imagePreview)
|
|
|
|
|
|
signalBus.txtPreviewSignal.connect(self.txtPreview)
|
|
|
|
|
|
# 背景信号连接
|
|
|
|
|
|
signalBus.backgroundChanged.connect(self.updateBackground)
|
|
|
|
|
|
signalBus.opacityChanged.connect(self.updateBackground)
|
|
|
|
|
|
# 下载上传任务信号连接
|
|
|
|
|
|
signalBus.addUploadFileTask.connect(self.addUploadFileTask)
|
|
|
|
|
|
signalBus.addDownloadFileTask.connect(self.addDownloadFileTask)
|
|
|
|
|
|
|
|
|
|
|
|
signalBus.shareFolderViewSignal.connect(self.shareFolderView)
|
|
|
|
|
|
# 语言变更信号连接
|
|
|
|
|
|
signalBus.languageChanged.connect(self.updateNavigation)
|
|
|
|
|
|
|
|
|
|
|
|
def updateNavigation(self):
|
|
|
|
|
|
# 更新导航项文本
|
2025-11-01 20:39:53 +08:00
|
|
|
|
# 使用MSFluentWindow的方法更新导航项文本
|
|
|
|
|
|
self.navigationInterface.setItemText(self.ownFiledInterface.objectName(), lang("我的文件"))
|
2025-10-29 22:20:21 +08:00
|
|
|
|
self.navigationInterface.setItemText(
|
2025-11-01 20:39:53 +08:00
|
|
|
|
self.storagespaceInterface.objectName(), lang("存储配额")
|
2025-10-29 22:20:21 +08:00
|
|
|
|
)
|
2025-11-01 20:39:53 +08:00
|
|
|
|
self.navigationInterface.setItemText(self.taskInterface.objectName(), lang("任务管理"))
|
|
|
|
|
|
self.navigationInterface.setItemText(self.appInfoInterface.objectName(), lang("应用信息"))
|
2025-10-29 22:20:21 +08:00
|
|
|
|
|
|
|
|
|
|
def initNavigation(self):
|
|
|
|
|
|
logger.info("开始初始化导航界面")
|
2025-11-01 20:39:53 +08:00
|
|
|
|
|
|
|
|
|
|
# MSFluentWindow自带导航设置,不需要直接设置navigationInterface
|
|
|
|
|
|
# 注意:MSFluentWindow的addSubInterface方法支持selectedIcon参数
|
2025-10-29 22:20:21 +08:00
|
|
|
|
self.addSubInterface(
|
|
|
|
|
|
self.ownFiledInterface,
|
2025-11-02 19:17:20 +08:00
|
|
|
|
FluentIcon.FOLDER,
|
2025-10-29 22:20:21 +08:00
|
|
|
|
lang("我的文件"),
|
2025-11-01 20:39:53 +08:00
|
|
|
|
position=NavigationItemPosition.TOP,
|
2025-10-29 22:20:21 +08:00
|
|
|
|
)
|
|
|
|
|
|
self.addSubInterface(
|
|
|
|
|
|
self.storagespaceInterface,
|
2025-11-02 19:17:20 +08:00
|
|
|
|
FluentIcon.APPLICATION,
|
2025-10-29 22:20:21 +08:00
|
|
|
|
lang("存储配额"),
|
2025-11-01 20:39:53 +08:00
|
|
|
|
position=NavigationItemPosition.TOP,
|
2025-10-29 22:20:21 +08:00
|
|
|
|
)
|
|
|
|
|
|
self.addSubInterface(
|
|
|
|
|
|
self.taskInterface,
|
2025-11-02 19:17:20 +08:00
|
|
|
|
FluentIcon.PASTE,
|
2025-10-29 22:20:21 +08:00
|
|
|
|
lang("任务管理"),
|
2025-11-01 20:39:53 +08:00
|
|
|
|
position=NavigationItemPosition.TOP,
|
2025-10-29 22:20:21 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
self.addSubInterface(
|
|
|
|
|
|
self.appInfoInterface,
|
2025-11-02 19:17:20 +08:00
|
|
|
|
FluentIcon.INFO,
|
2025-10-29 22:20:21 +08:00
|
|
|
|
lang("应用信息"),
|
2025-11-01 20:39:53 +08:00
|
|
|
|
position=NavigationItemPosition.BOTTOM,
|
2025-10-29 22:20:21 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# 创建默认头像widget,先使用本地默认头像
|
|
|
|
|
|
self.avatarWidget = NavigationAvatarWidget(
|
|
|
|
|
|
userConfig.userName, ":app/images/logo.png"
|
|
|
|
|
|
)
|
2025-11-01 20:39:53 +08:00
|
|
|
|
|
|
|
|
|
|
# 使用MSFluentWindow的navigationInterface添加头像widget
|
|
|
|
|
|
# 直接使用原始图标而不是avatarWidget.avatar
|
|
|
|
|
|
self.navigationInterface.addItem(
|
2025-10-29 22:20:21 +08:00
|
|
|
|
routeKey="settingInterface",
|
2025-11-01 20:39:53 +08:00
|
|
|
|
icon=QIcon(":app/images/logo.png"),
|
|
|
|
|
|
text="", # 不显示文本,只显示头像
|
2025-10-29 22:20:21 +08:00
|
|
|
|
onClick=self.setPersonalInfoWidget,
|
2025-11-01 20:39:53 +08:00
|
|
|
|
selectable=False,
|
|
|
|
|
|
position=NavigationItemPosition.BOTTOM,
|
2025-10-29 22:20:21 +08:00
|
|
|
|
)
|
2025-11-01 20:39:53 +08:00
|
|
|
|
|
2025-10-29 22:20:21 +08:00
|
|
|
|
self.settingInterface = SettingInterface(self)
|
|
|
|
|
|
self.stackedWidget.addWidget(self.settingInterface)
|
|
|
|
|
|
|
|
|
|
|
|
self.splashScreen.finish()
|
|
|
|
|
|
logger.info("导航界面初始化完成")
|
|
|
|
|
|
|
|
|
|
|
|
self.avatarThread = GetUserAvatarThread("l")
|
|
|
|
|
|
self.avatarThread.avatarPixmap.connect(self.onAvatarDownloaded)
|
|
|
|
|
|
self.avatarThread.start()
|
|
|
|
|
|
|
|
|
|
|
|
def shareFolderView(self, _id):
|
|
|
|
|
|
w = ShareFolderMessageBox(_id, self)
|
|
|
|
|
|
if w.exec():
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
def addUploadFileTask(self, filePath):
|
|
|
|
|
|
logger.info(f"添加上传文件任务: {filePath}")
|
|
|
|
|
|
self.taskInterface.uploadScrollWidget.addUploadTask(filePath)
|
|
|
|
|
|
self.stackedWidget.setCurrentWidget(self.taskInterface)
|
|
|
|
|
|
self.navigationInterface.setCurrentItem("taskInterface")
|
|
|
|
|
|
self.taskInterface._changePivot("Upload")
|
|
|
|
|
|
|
|
|
|
|
|
def addDownloadFileTask(self, suffix, fileName, _id):
|
|
|
|
|
|
logger.info(f"添加下载文件任务: {fileName}")
|
|
|
|
|
|
self.taskInterface.downloadScrollWidget.addDownloadTask(suffix, fileName, _id)
|
|
|
|
|
|
self.stackedWidget.setCurrentWidget(self.taskInterface)
|
|
|
|
|
|
self.navigationInterface.setCurrentItem("taskInterface")
|
|
|
|
|
|
self.taskInterface._changePivot("Download")
|
|
|
|
|
|
|
|
|
|
|
|
def setPersonalInfoWidget(self):
|
2025-11-01 20:39:53 +08:00
|
|
|
|
# 使用MSFluentWindow的方式切换到设置界面
|
|
|
|
|
|
self.stackedWidget.setCurrentWidget(self.settingInterface)
|
|
|
|
|
|
# 由于设置项是通过addItem添加的非selectable项,不需要设置currentItem
|
2025-10-29 22:20:21 +08:00
|
|
|
|
|
|
|
|
|
|
def onAvatarDownloaded(self, pixmap):
|
|
|
|
|
|
userConfig.setUserAvatarPixmap(pixmap)
|
|
|
|
|
|
self.avatarWidget.setAvatar(pixmap)
|
|
|
|
|
|
self.settingInterface.updateAvatar(pixmap)
|
2025-11-01 20:39:53 +08:00
|
|
|
|
|
|
|
|
|
|
# 更新导航项中的头像图标
|
|
|
|
|
|
if hasattr(self, 'navigationInterface'):
|
|
|
|
|
|
# 创建临时QIcon
|
|
|
|
|
|
icon = QIcon()
|
|
|
|
|
|
icon.addPixmap(pixmap)
|
|
|
|
|
|
|
|
|
|
|
|
# 使用QFluentWidgets的正确API更新导航项图标
|
|
|
|
|
|
# 由于NavigationBar没有setItemIcon方法,我们重新创建导航项
|
|
|
|
|
|
# 先获取现有的设置项并移除
|
|
|
|
|
|
try:
|
|
|
|
|
|
# 移除现有的设置项
|
|
|
|
|
|
self.navigationInterface.removeItem("settingInterface")
|
|
|
|
|
|
# 重新添加设置项,使用新的头像图标
|
|
|
|
|
|
self.navigationInterface.addItem(
|
|
|
|
|
|
routeKey="settingInterface",
|
|
|
|
|
|
icon=icon,
|
|
|
|
|
|
text="", # 不显示文本,只显示头像
|
|
|
|
|
|
onClick=self.setPersonalInfoWidget,
|
|
|
|
|
|
selectable=False,
|
|
|
|
|
|
position=NavigationItemPosition.BOTTOM,
|
|
|
|
|
|
)
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"更新导航头像失败: {str(e)}")
|
2025-10-29 22:20:21 +08:00
|
|
|
|
|
|
|
|
|
|
def initWindow(self):
|
|
|
|
|
|
logger.info("开始初始化窗口设置")
|
|
|
|
|
|
self.resize(960, 780)
|
|
|
|
|
|
self.setMinimumWidth(760)
|
|
|
|
|
|
self.setWindowIcon(QIcon(":app/images/logo.png"))
|
|
|
|
|
|
self.setWindowTitle(lang("LeonPan"))
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug("已设置窗口基本属性")
|
|
|
|
|
|
|
|
|
|
|
|
self.setCustomBackgroundColor(QColor(240, 244, 249), QColor(32, 32, 32))
|
|
|
|
|
|
self.setMicaEffectEnabled(cfg.get(cfg.micaEnabled))
|
|
|
|
|
|
logger.debug("已设置窗口背景和Mica效果")
|
|
|
|
|
|
self.setBackgroundImage(
|
|
|
|
|
|
qconfig.get(cfg.customBackground), qconfig.get(cfg.customOpactity)
|
|
|
|
|
|
) # create splash screen
|
|
|
|
|
|
# 使用自定义的背景设置方法
|
|
|
|
|
|
# create splash screen
|
|
|
|
|
|
self.splashScreen = SplashScreen(self.windowIcon(), self)
|
|
|
|
|
|
self.splashScreen.setIconSize(QSize(106, 106))
|
|
|
|
|
|
self.splashScreen.raise_()
|
|
|
|
|
|
logger.debug("已创建并设置启动屏幕")
|
|
|
|
|
|
|
|
|
|
|
|
desktop = QApplication.primaryScreen().availableGeometry()
|
|
|
|
|
|
w, h = desktop.width(), desktop.height()
|
|
|
|
|
|
self.move(w // 2 - self.width() // 2, h // 2 - self.height() // 2)
|
|
|
|
|
|
logger.debug("已移动窗口到屏幕中心")
|
|
|
|
|
|
|
|
|
|
|
|
self.show()
|
|
|
|
|
|
QApplication.processEvents()
|
|
|
|
|
|
logger.info("窗口初始化完成并显示")
|
|
|
|
|
|
|
|
|
|
|
|
def resizeEvent(self, e):
|
|
|
|
|
|
super().resizeEvent(e)
|
|
|
|
|
|
if hasattr(self, "splashScreen"):
|
|
|
|
|
|
self.splashScreen.resize(self.size())
|
|
|
|
|
|
# 窗口大小改变时更新背景
|
|
|
|
|
|
|
|
|
|
|
|
def imagePreview(self, _id):
|
2025-11-01 20:14:35 +08:00
|
|
|
|
# 直接传递文件ID给OptimizedPreviewBox,让它内部使用getFileUrl获取临时URL
|
|
|
|
|
|
self.previewBox = OptimizedPreviewBox(self, fileId=_id)
|
2025-10-29 22:20:21 +08:00
|
|
|
|
if self.previewBox.exec():
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def txtPreview(self, _id):
|
2025-11-01 20:14:35 +08:00
|
|
|
|
# 直接使用fileUri,不再构建URL
|
|
|
|
|
|
# _id 应该是 cloudreve:// 格式的URI
|
|
|
|
|
|
self.previewBox = PreviewTextBox(self, "", _id)
|
2025-10-29 22:20:21 +08:00
|
|
|
|
if self.previewBox.exec():
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def updateBackground(self):
|
|
|
|
|
|
"""更新窗口背景"""
|
|
|
|
|
|
self.setBackgroundImage(
|
|
|
|
|
|
qconfig.get(cfg.customBackground), qconfig.get(cfg.customOpactity)
|
|
|
|
|
|
)
|