diff --git a/README.md b/README.md index 9686330..91d8f8b 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,16 @@ ## 功能介绍 -由论坛大佬 chanforever 的插件修改得来,在 dde-dock 添加插件实现快速切换显卡的操作。 - -原贴地址:[切换显卡插件](https://bbs.deepin.org/forum.php?mod=viewthread&tid=197280) +原贴地址:[切换显卡插件](https://bbs.deepin.org/zh/post/197280) github 原项目地址:[mywhat/DDESwitchCard](https://github.com/mywhat/DDESwitchCard/) +
+ +由论坛大佬 chanforever 的插件修改得来,在 dde-dock 添加插件实现快速切换显卡的操作。 + +
+ 修改了整个代码结构,优化函数调用逻辑,取消了外部储存配置文件,避免被修改而影响插件显示。 自动检测是否安装 NVIDIA 显卡驱动,避免切换后因为没有驱动导致无法进入图形界面。 @@ -34,13 +38,9 @@ qtcreator(推荐使用 Qt Creator 直接打开 CMakeLists.txt 编译运行) cmake, gcc, g++ -libqt5core5a - -libqt5gui5 - -libqt5widgets5 +qt5-default -libqt5dbus5 +qttools5-dev libdtkcore-dev @@ -48,6 +48,7 @@ libdtkwidget-dev dde-dock-dev +
mesa-utils(运行时依赖) @@ -73,22 +74,24 @@ libnotify4(运行时依赖) ## 感谢 -linuxdeepin 官方的 dde-dock 项目仓库 https://github.com/linuxdeepin/dde-dock +linuxdeepin 官方的 [dde-dock](https://github.com/linuxdeepin/dde-dock) 项目仓库 + +linuxdeepin 官方的 [dde-file-manager](https://github.com/linuxdeepin/dde-file-manager) 项目仓库 -linuxdeepin 官方的 dde-file-manager 项目仓库 https://github.com/linuxdeepin/dde-file-manager +GitHub 开源项目 [dde-appknitter](https://github.com/Dziban-dev/dde-appknitter) 的脚本翻译方式 -GitHub 开源项目 dde-appknitter 的脚本翻译方式 https://github.com/Dziban-dev/dde-appknitter +Github 开源项目 [dde-store](https://github.com/dekzi/dde-store) 的系统通知发送方式 -Github 开源项目 dde-store 的系统通知发送方式 https://github.com/dekzi/dde-store +GitHub 大佬 [xmuli](https://github.com/xmuli) 的 [Qt 项目(Cmake)设置国际化支持](https://ifmet.cn/posts/9644ed82/) 方法 -论坛大佬 chanforever 的插件 https://bbs.deepin.org/forum.php?mod=viewthread&tid=197280 +论坛大佬 chanforever 的 [DDESwitchCard](https://github.com/mywhat/DDESwitchCard) 插件 https://bbs.deepin.org/zh/post/197280 -论坛大佬 jfy_99 的显卡切换脚本 https://bbs.deepin.org/forum.php?mod=viewthread&tid=192750 +论坛大佬 jfy_99 的显卡切换脚本 https://bbs.deepin.org/zh/post/192750 -论坛大佬 risez 的 nvidia-prime 方案 https://bbs.deepin.org/forum.php?mod=viewthread&tid=191741 +论坛大佬 risez 的 nvidia-prime 方案 https://bbs.deepin.org/zh/post/191741 -论坛大佬 q77190858 的 dde-dock系统监控小插件 https://bbs.deepin.org/forum.php?mod=viewthread&tid=179425 +论坛大佬 q77190858 的 [dde-sys-monitor-plugin](https://github.com/q77190858/dde-sys-monitor-plugin) 插件 https://bbs.deepin.org/zh/post/179425 -论坛大佬 shenmo,lenke,mmlmonkey,xuey 等提供的修改建议 https://bbs.deepin.org/forum.php?mod=viewthread&tid=197367 +论坛大佬 shenmo,lenke,mmlmonkey,xuey 等提供的修改建议 https://bbs.deepin.org/zh/post/197367 -码云组织 开源应用 提供的 UOS 打包规范和方法 https://gitee.com/deepin-opensource +码云组织 [开源应用](https://gitee.com/deepin-opensource) 提供的 UOS 打包规范和方法 diff --git a/deb_uos/DEBIAN/control b/deb_uos/DEBIAN/control index 952d956..579fce7 100644 --- a/deb_uos/DEBIAN/control +++ b/deb_uos/DEBIAN/control @@ -1,5 +1,5 @@ Package: dde-dock-graphics-plugin -Version: 1.8.2spark0 +Version: 1.8.3 Maintainer: zty199 Section: utils Source: https://github.com/mywhat/DDESwitchCard diff --git a/deb_uos/opt/apps/dde-dock-graphics-plugin/info b/deb_uos/opt/apps/dde-dock-graphics-plugin/info index bfb3547..16e1625 100644 --- a/deb_uos/opt/apps/dde-dock-graphics-plugin/info +++ b/deb_uos/opt/apps/dde-dock-graphics-plugin/info @@ -1,7 +1,7 @@ { "appid": "dde-dock-graphics-plugin", "name": "SwitchGraphicsCardPlugin", - "version": "1.8.2spark0", + "version": "1.8.3", "arch": ["amd64"], "permissions": { "autostart": false, diff --git a/scripts/Initialize.sh b/scripts/Initialize.sh index 5b03921..b9a4621 100755 --- a/scripts/Initialize.sh +++ b/scripts/Initialize.sh @@ -63,6 +63,7 @@ Section "Screen" SubSection "Display" Depth 24 EndSubSection + Option "Coolbits" "28" EndSection' | sudo tee /etc/X11/xorg.conf.bak > /dev/null # 生成 nvidia-graphics-drivers.conf | Generate nvidia-graphics-drivers.conf diff --git a/scripts/Intel.sh b/scripts/Intel.sh index 8cd9ba3..73a810b 100755 --- a/scripts/Intel.sh +++ b/scripts/Intel.sh @@ -15,16 +15,13 @@ readonly TEXT1_zh="未检测到 NVIDIA 显卡驱动,建议安装 NVIDIA 闭源 readonly TEXT1_en="NVIDIA X driver not detected, suggest installing nvidia-driver first" readonly TEXT2_zh="已经是 Intel 显卡了" readonly TEXT2_en="Intel graphics is already in use" -readonly TIP1_zh="即将切换显卡并注销登录,请及时保存您的工作进度" -readonly TIP1_en="Preparing to switch graphics card and logout, please save your work in progress in time" -readonly TIP2_zh="正在刷新内核参数,请稍后..." -readonly TIP2_en="Updating initramfs, please wait..." +readonly TIP_zh="即将切换显卡并注销登录,请及时保存您的工作进度" +readonly TIP_en="Preparing to switch graphics card and logout, please save your work in progress in time" eval "TITLE=\$TITLE_${LANG}" eval "TEXT1=\$TEXT1_${LANG}" eval "TEXT2=\$TEXT2_${LANG}" -eval "TIP1=\$TIP1_${LANG}" -eval "TIP2=\$TIP2_${LANG}" +eval "TIP=\$TIP_${LANG}" # 判断 NVIDIA 闭源驱动 是否安装 | Judge whether nvidia-driver is installed lshw -c video | grep "driver=nvidia" > /dev/null @@ -47,7 +44,7 @@ then fi # 提示文本 | Tip -echo $TIP1 +echo $TIP # 初始化 nvidia-prime 相关配置文件 | Initialize sh /opt/apps/dde-dock-graphics-plugin/files/bin/Initialize.sh @@ -62,9 +59,6 @@ sudo sed -i 's$Screen 0 "Screen0" 0 0$Screen 0 "IGPU" 0 0$g' /etc/X1 # 移除 nvidia-graphics-drivers.conf | Remove nvidia-graphics-drivers.conf sudo mv /etc/modprobe.d/nvidia-graphics-driver.conf /etc/modprobe.d/nvidia-graphics-driver.conf.bak -echo $TIP2 -notify-send -t 5000 -a dde-dock-graphics-plugin -i deepin-graphics-driver-manager "$TIP2" -sudo update-initramfs -u # 恢复 lightdm.conf | Restore lightdm.conf sudo sed -i 's$display-setup-script=/etc/lightdm/display_setup.sh$#display-setup-script=$g' /etc/lightdm/lightdm.conf diff --git a/scripts/NVIDIA.sh b/scripts/NVIDIA.sh index a351cfe..760a38e 100755 --- a/scripts/NVIDIA.sh +++ b/scripts/NVIDIA.sh @@ -15,16 +15,13 @@ readonly TEXT1_zh="未检测到 NVIDIA 显卡驱动,建议安装 NVIDIA 闭源 readonly TEXT1_en="NVIDIA X driver not detected, suggest installing nvidia-driver first" readonly TEXT2_zh="已经是 NVIDIA 显卡了" readonly TEXT2_en="NVIDIA graphics is already in use" -readonly TIP1_zh="即将切换显卡并注销登录,请及时保存您的工作进度" -readonly TIP1_en="Preparing to switch graphics card and logout, please save your work in progress in time" -readonly TIP2_zh="正在刷新内核参数,请稍后..." -readonly TIP2_en="Updating initramfs, please wait..." +readonly TIP_zh="即将切换显卡并注销登录,请及时保存您的工作进度" +readonly TIP_en="Preparing to switch graphics card and logout, please save your work in progress in time" eval "TITLE=\$TITLE_${LANG}" eval "TEXT1=\$TEXT1_${LANG}" eval "TEXT2=\$TEXT2_${LANG}" -eval "TIP1=\$TIP1_${LANG}" -eval "TIP2=\$TIP2_${LANG}" +eval "TIP=\$TIP_${LANG}" # 判断 NVIDIA 闭源驱动 是否安装 | Judge whether nvidia-driver is installed lshw -c video | grep "driver=nvidia" > /dev/null @@ -47,7 +44,7 @@ then fi # 提示文本 | Tip -echo $TIP1 +echo $TIP # 初始化 NVIDIA 相关配置文件 | Initialize sh /opt/apps/dde-dock-graphics-plugin/files/bin/Initialize.sh @@ -63,9 +60,6 @@ sudo sed -i 's$\n Option "AllowNVIDIAGPUScreens"$$g' /etc/X11/xorg.co # 启用 nvidia-graphics-drivers.conf | Enable nvidia-graphics-drivers.conf sudo mv /etc/modprobe.d/nvidia-graphics-driver.conf.bak /etc/modprobe.d/nvidia-graphics-driver.conf -echo $TIP2 -notify-send -t 5000 -a dde-dock-graphics-plugin -i deepin-graphics-driver-manager "$TIP2" -sudo update-initramfs -u # 修改 lightdm.conf | Modify lightdm.conf sudo sed -i 's$#display-setup-script=$display-setup-script=/etc/lightdm/display_setup.sh$g' /etc/lightdm/lightdm.conf diff --git a/scripts/prime-run.sh b/scripts/prime-run.sh index 5d693fd..518ed75 100755 --- a/scripts/prime-run.sh +++ b/scripts/prime-run.sh @@ -1,10 +1,10 @@ #!/bin/sh -file=$1 +FILE=$1 -if [ "${file##*.}"x = "desktop"x ] +if [ "${FILE##*.}"x = "desktop"x ] then - __NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia $(cat $file | grep "Exec=" | sed "s/^Exec=//" | sed "s/%.//" | sed "s/^\"//g" | sed "s/\" *$//g" | head -n 1) + __NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia $(cat $FILE | grep "Exec=" | sed "s/^Exec=//" | sed "s/%.//" | sed "s/^\"//g" | sed "s/\" *$//g" | head -n 1) else - __NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia $file + __NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia $FILE fi diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 88dee5b..690c8fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,6 +36,13 @@ file(GLOB_RECURSE SRCS "*.h" "*.cpp") # <库名>_LIBRARIES 有哪些库文件(Qt5Widgets_LIBRARIES) find_package(Qt5Widgets REQUIRED) find_package(Qt5DBus REQUIRED) +find_package(Qt5LinguistTools REQUIRED) + +# .ts 翻译文件 +set(TS_FILES ${CMAKE_SOURCE_DIR}/translations/zh_CN.ts) +# 生成 .qm 翻译文件 +qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) +qt5_add_translation(QM_FILES ${TS_FILES}) find_package(DtkCore REQUIRED) find_package(DtkWidget REQUIRED) @@ -73,7 +80,7 @@ add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN") # SHARED 表示生成的库应该是动态库, # 变量 ${PLUGIN_NAME} 和 ${SRCS} 都是前面处理好的, # 另外 qrc 资源文件也应该追加在后面以编译进目标中。 -add_library(${PLUGIN_NAME} SHARED ${SRCS} switch-graphics-card.qrc) +add_library(${PLUGIN_NAME} SHARED ${SRCS} ${TS_FILES} switch-graphics-card.qrc) # 设置目标的生成位置,这里表示生成在执行 make 的目录, # 另外还有很多可用于设置的属性,可查阅 cmake 文档。 @@ -85,6 +92,7 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ./) target_include_directories(${PLUGIN_NAME} PUBLIC ${Qt5Widgets_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} + ${Qt5LinguistTools_INCLUDE_DIRS} ${DtkCore_INCLUDE_DIRS} ${DtkWidget_INCLUDE_DIRS} ${DdeDockInterface_INCLUDE_DIRS} @@ -96,13 +104,14 @@ target_include_directories(${PLUGIN_NAME} PUBLIC target_link_libraries(${PLUGIN_NAME} PRIVATE ${Qt5Widgets_LIBRARIES} ${Qt5DBus_LIBRARIES} + ${Qt5LinguistTools_LIBRARIES} ${DtkCore_LIBRARIES} ${DtkWidget_LIBRARIES} ${DdeDockInterface_LIBRARIES} ) # 设置安装路径的前缀(默认为"/usr/local") -#set(CMAKE_INSTALL_PREFIX "/usr") +# set(CMAKE_INSTALL_PREFIX "/usr") # 设置执行 make install 时哪个目标应该被 install 到哪个位置 -#install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins) +# install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins) diff --git a/src/ddeUtil.h b/src/ddeUtil.h index 6d94577..bac696b 100644 --- a/src/ddeUtil.h +++ b/src/ddeUtil.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #endif diff --git a/src/switch-graphics-card-plugin.cpp b/src/switch-graphics-card-plugin.cpp index 2ad4b32..4395087 100644 --- a/src/switch-graphics-card-plugin.cpp +++ b/src/switch-graphics-card-plugin.cpp @@ -6,22 +6,11 @@ SwitchGraphicsCardPlugin::SwitchGraphicsCardPlugin(QObject *parent) : QObject(parent) - , m_tipsWidget(new Dock::TipsWidget) - , m_appletWidget(new SwitchGraphicsCardAppletWidget) , process(new QProcess) , m_pluginLoaded(false) + , ts(new QTranslator) { - // 设置 tipsWidget 中的信息 - m_tipsWidget->setVisible(false); - m_tipsWidget->setAccessibleName("Switch Graphics Card"); - if(m_appletWidget->getLocale() == "zh") - { - m_tipsWidget->setText("当前显卡:" + m_appletWidget->getCardName()); - } - else - { - m_tipsWidget->setText("Current: " + m_appletWidget->getCardName()); - } + updateTranslator(); } const QString SwitchGraphicsCardPlugin::pluginName() const @@ -31,14 +20,7 @@ const QString SwitchGraphicsCardPlugin::pluginName() const const QString SwitchGraphicsCardPlugin::pluginDisplayName() const { - if(m_appletWidget->getLocale() == "zh") - { - return QString("显卡切换"); - } - else - { - return QString("Switch Graphics Card"); - } + return QString(tr("Switch Graphics Card")); } void SwitchGraphicsCardPlugin::init(PluginProxyInterface *proxyInter) @@ -107,40 +89,19 @@ const QString SwitchGraphicsCardPlugin::itemContextMenu(const QString &itemKey) QMap graphicsRefresh; graphicsRefresh["itemId"] = "graphics-refresh"; - if(m_appletWidget->getLocale() == "zh") - { - graphicsRefresh["itemText"] = "刷新"; - } - else - { - graphicsRefresh["itemText"] = "Refresh"; - } + graphicsRefresh["itemText"] = tr("Refresh"); graphicsRefresh["isActive"] = true; items.push_back(graphicsRefresh); QMap displaySettings; displaySettings["itemId"] = "display-settings"; - if(m_appletWidget->getLocale() == "zh") - { - displaySettings["itemText"] = "显示器设置"; - } - else - { - displaySettings["itemText"] = "Display Settings"; - } + displaySettings["itemText"] = tr("Display Settings"); displaySettings["isActive"] = true; items.push_back(displaySettings); QMap nvidiaSettings; nvidiaSettings["itemId"] = "nvidia-settings"; - if(m_appletWidget->getLocale() == "zh") - { - nvidiaSettings["itemText"] = "NVIDIA 显卡设置"; - } - else - { - nvidiaSettings["itemText"] = "Run nvidia-settings"; - } + nvidiaSettings["itemText"] = tr("Run nvidia-settings"); nvidiaSettings["isActive"] = true; items.push_back(nvidiaSettings); @@ -161,9 +122,8 @@ void SwitchGraphicsCardPlugin::invokedMenuItem(const QString &itemKey, const QSt // 根据上面接口设置的 id 执行不同的操作 if(menuId == "graphics-refresh") { - // 刷新显卡信息和系统语言环境 + // 刷新显卡信息 m_appletWidget->setCardName(); - m_appletWidget->setLocale(); m_appletWidget->refreshButton(); m_pluginWidget->getInfo(m_appletWidget); } @@ -225,10 +185,17 @@ void SwitchGraphicsCardPlugin::loadPlugin() m_pluginLoaded = true; m_pluginWidget = new SwitchGraphicsCardWidget; + m_tipsWidget = new Dock::TipsWidget; + m_appletWidget = new SwitchGraphicsCardAppletWidget; - // 初始化显卡信息和系统语言环境 + // 初始化显卡信息 m_pluginWidget->getInfo(m_appletWidget); + // 初始化 tipsWidget 信息 + m_tipsWidget->setVisible(false); + m_tipsWidget->setAccessibleName("Switch Graphics Card"); + m_tipsWidget->setText(tr("Current: ") + m_appletWidget->getCardName()); + m_proxyInter->itemAdded(this, pluginName()); displayModeChanged(displayMode()); } @@ -249,3 +216,12 @@ void SwitchGraphicsCardPlugin::refreshPluginItemsVisible() m_proxyInter->itemAdded(this, pluginName()); } } + +void SwitchGraphicsCardPlugin::updateTranslator() +{ + if(QLocale::system().name().split("_").at(0) == "zh") + { + ts->load("zh_CN.qm", ":/translations/translations"); + QCoreApplication::installTranslator(ts); + } +} diff --git a/src/switch-graphics-card-plugin.h b/src/switch-graphics-card-plugin.h index d066cf8..30f924d 100644 --- a/src/switch-graphics-card-plugin.h +++ b/src/switch-graphics-card-plugin.h @@ -3,10 +3,10 @@ #include "ddeUtil.h" #include -#include "tipswidget.h" #include "switchgraphicscardwidget.h" #include "switchgraphicscardappletwidget.h" +#include "tipswidget.h" class SwitchGraphicsCardPlugin : public QObject, PluginsItemInterface { @@ -58,9 +58,11 @@ class SwitchGraphicsCardPlugin : public QObject, PluginsItemInterface QProcess *process; bool m_pluginLoaded; + QTranslator *ts; void loadPlugin(); void refreshPluginItemsVisible(); + void updateTranslator(); }; diff --git a/src/switch-graphics-card.qrc b/src/switch-graphics-card.qrc index 218e1a9..410f25a 100644 --- a/src/switch-graphics-card.qrc +++ b/src/switch-graphics-card.qrc @@ -5,4 +5,7 @@ icons/NVIDIA_light.svg icons/Intel_dark.svg + + translations/zh_CN.qm + diff --git a/src/switchgraphicscardappletwidget.cpp b/src/switchgraphicscardappletwidget.cpp index 7e9bf36..73a691b 100644 --- a/src/switchgraphicscardappletwidget.cpp +++ b/src/switchgraphicscardappletwidget.cpp @@ -19,7 +19,6 @@ SwitchGraphicsCardAppletWidget::SwitchGraphicsCardAppletWidget(QWidget *parent) btn_nvidia->move(1, 30); setCardName(); - setLocale(); refreshButton(); connect(btn_intel, &QPushButton::clicked, this, &SwitchGraphicsCardAppletWidget::switchIntel); @@ -29,7 +28,7 @@ SwitchGraphicsCardAppletWidget::SwitchGraphicsCardAppletWidget(QWidget *parent) void SwitchGraphicsCardAppletWidget::setCardName() { // 获取当前显卡信息 - process->start("/opt/apps/dde-dock-graphics-plugin/files/bin/CheckGraphics.sh", QStringList()); + process->start("sh", QStringList() << "/opt/apps/dde-dock-graphics-plugin/files/bin/CheckGraphics.sh"); process->waitForFinished(); m_cardName = process->readAllStandardOutput(); process->close(); @@ -41,43 +40,15 @@ QString SwitchGraphicsCardAppletWidget::getCardName() return this->m_cardName; } -void SwitchGraphicsCardAppletWidget::setLocale() -{ - // 获取系统语言环境 - m_locale = QLocale::system().name().split("_").at(0); -} - -QString SwitchGraphicsCardAppletWidget::getLocale() -{ - return this->m_locale; -} - void SwitchGraphicsCardAppletWidget::switchIntel() { if(this->m_cardName == "Intel") { - if(this->m_locale == "zh") - { - // 使用 notify-send 向通知中心发送系统通知 - Dtk::Core::DUtil::DNotifySender("已经是 Intel 显卡").appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").timeOut(2000).call(); - } - else - { - Dtk::Core::DUtil::DNotifySender("Intel graphics is already in use").appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").timeOut(2000).call(); - } + Dtk::Core::DUtil::DNotifySender(tr("Intel graphics is already in use")).appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").timeOut(2000).call(); return; } - if(this->m_locale == "zh") - { - Dtk::Core::DUtil::DNotifySender("即将切换显卡并注销登录,请及时保存您的工作进度").appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").timeOut(3000).call(); - Dtk::Core::DUtil::DNotifySender("正在刷新内核参数,请稍后...").appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").call(); - } - else - { - Dtk::Core::DUtil::DNotifySender("Preparing to switch graphics card and logout, please save your work in progress in time").appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").timeOut(3000).call(); - Dtk::Core::DUtil::DNotifySender("Updating initramfs, please wait...").appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").call(); - } + Dtk::Core::DUtil::DNotifySender(tr("Preparing to switch graphics card and logout, please save your work in progress in time")).appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").call(); // 非阻塞调用外部脚本,不需要等待结束 process->start("pkexec", QStringList() << "/opt/apps/dde-dock-graphics-plugin/files/bin/Intel.sh"); @@ -87,41 +58,17 @@ void SwitchGraphicsCardAppletWidget::switchNVIDIA() { if(this->m_cardName == "NVIDIA") { - if(this->m_locale == "zh") - { - Dtk::Core::DUtil::DNotifySender("已经是 NVIDIA 显卡").appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").timeOut(2000).call(); - } - else - { - Dtk::Core::DUtil::DNotifySender("NVIDIA graphics is already in use").appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").timeOut(2000).call(); - } + Dtk::Core::DUtil::DNotifySender(tr("NVIDIA graphics is already in use")).appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").timeOut(2000).call(); return; } - if(this->m_locale == "zh") - { - Dtk::Core::DUtil::DNotifySender("即将切换显卡并注销登录,请及时保存您的工作进度").appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").timeOut(3000).call(); - Dtk::Core::DUtil::DNotifySender("正在刷新内核参数,请稍后...").appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").call(); - } - else - { - Dtk::Core::DUtil::DNotifySender("Preparing to switch graphics card and logout, please save your work in progress in time").appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").timeOut(3000).call(); - Dtk::Core::DUtil::DNotifySender("Updating initramfs, please wait...").appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").call(); - } + Dtk::Core::DUtil::DNotifySender(tr("Preparing to switch graphics card and logout, please save your work in progress in time")).appIcon("deepin-graphics-driver-manager").appName("dde-dock-graphics-plugin").call(); process->start("pkexec", QStringList() << "/opt/apps/dde-dock-graphics-plugin/files/bin/NVIDIA.sh"); } void SwitchGraphicsCardAppletWidget::refreshButton() { - if(this->m_locale == "zh") - { - btn_intel->setText("切换 Intel 显卡"); - btn_nvidia->setText("切换 NVIDIA 显卡"); - } - else - { - btn_intel->setText("Intel Graphics"); - btn_nvidia->setText("NVIDIA Graphics"); - } + btn_intel->setText(tr("Intel Graphics")); + btn_nvidia->setText(tr("NVIDIA Graphics")); } diff --git a/src/switchgraphicscardappletwidget.h b/src/switchgraphicscardappletwidget.h index 9600a08..920e1b3 100644 --- a/src/switchgraphicscardappletwidget.h +++ b/src/switchgraphicscardappletwidget.h @@ -12,8 +12,6 @@ class SwitchGraphicsCardAppletWidget : public QWidget void setCardName(); QString getCardName(); - void setLocale(); - QString getLocale(); void refreshButton(); private: diff --git a/src/tipswidget.cpp b/src/tipswidget.cpp index c5e77a1..13738af 100644 --- a/src/tipswidget.cpp +++ b/src/tipswidget.cpp @@ -80,7 +80,7 @@ void TipsWidget::paintEvent(QPaintEvent *event) } for(QString text : m_textList) { - painter.drawText(QRect(0, y, m_width, fontHeight), text, option); + painter.drawText(QRect(10, y, m_width, fontHeight), text, option); y += fontHeight; } } @@ -96,7 +96,7 @@ bool TipsWidget::event(QEvent *event) { if(!m_text.trimmed().isEmpty()) { - setFixedSize(fontMetrics().horizontalAdvance(m_text) + 6, fontMetrics().height()); + setFixedSize(fontMetrics().horizontalAdvance(m_text) + 20, fontMetrics().height()); update(); } } @@ -108,7 +108,7 @@ bool TipsWidget::event(QEvent *event) setFixedHeight(fontMetrics().height() * m_textList.size()); for(QString text : m_textList) { - int fontLength = fontMetrics().horizontalAdvance(text) + 6; + int fontLength = fontMetrics().horizontalAdvance(text) + 20; maxLength = qMax(maxLength,fontLength); } m_width = maxLength; diff --git a/src/tipswidget.h b/src/tipswidget.h index e0545b4..b9a5f4a 100644 --- a/src/tipswidget.h +++ b/src/tipswidget.h @@ -13,10 +13,11 @@ class TipsWidget : public QFrame SingleLine, MultiLine }; + public: explicit TipsWidget(QWidget *parent = nullptr); - const QString& text(){return m_text;} + const QString& text() { return m_text; } const QStringList &textList() { return m_textList; } void setText(const QString &text); void setTextList(const QStringList &textList); diff --git a/src/translations/translate_generation.sh b/src/translations/translate_generation.sh new file mode 100755 index 0000000..3d033e7 --- /dev/null +++ b/src/translations/translate_generation.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# this file is used to auto-generate .qm file from .ts file. +# author: shibowen at linuxdeepin.com + +ts_list=(`ls ./*.ts`) + +for ts in "${ts_list[@]}" +do + printf "\nprocess ${ts}\n" + lrelease "${ts}" +done diff --git a/src/translations/zh_CN.qm b/src/translations/zh_CN.qm new file mode 100644 index 0000000..d84ff35 Binary files /dev/null and b/src/translations/zh_CN.qm differ diff --git a/src/translations/zh_CN.ts b/src/translations/zh_CN.ts new file mode 100644 index 0000000..866a396 --- /dev/null +++ b/src/translations/zh_CN.ts @@ -0,0 +1,61 @@ + + + + + SwitchGraphicsCardAppletWidget + + + Intel graphics is already in use + 已经是 Intel 显卡 + + + + + Preparing to switch graphics card and logout, please save your work in progress in time + 即将切换显卡并注销登录,请及时保存您的工作进度 + + + + NVIDIA graphics is already in use + 已经是 NVIDIA 显卡 + + + + Intel Graphics + 切换 Intel 显卡 + + + + NVIDIA Graphics + 切换 NVIDIA 显卡 + + + + SwitchGraphicsCardPlugin + + + Current: + 当前显卡: + + + + Switch Graphics Card + 显卡切换 + + + + Refresh + 刷新 + + + + Display Settings + 显示器设置 + + + + Run nvidia-settings + NVIDIA 显卡设置 + + +