Import Upstream version 3.20.0.5

This commit is contained in:
luzhiping 2022-07-15 13:43:17 +08:00
commit e3ceb13042
73 changed files with 15318 additions and 0 deletions

12
AUTHORS Normal file
View File

@ -0,0 +1,12 @@
Upstream Authors:
LXQT team: https://lxqt.org
Razor team: http://razor-qt.org
kylin team: https://www.ukui.com
Copyright:
Copyright (c) 2010-2012 Razor team
Copyright (c) 2012-2017 iLXQT team
Copyright (c) 2019 Tianjin KYLIN Information Technology Co., Ltd. *
License: LGPL-2.1+
The full text of the licenses can be found in the 'COPYING' file.

1
CHANGELOG Normal file
View File

@ -0,0 +1 @@
Use 'git log' for a detailed list of changes.

99
CMakeLists.txt Normal file
View File

@ -0,0 +1,99 @@
cmake_minimum_required(VERSION 3.1.0)
project(kylin-device-daemon)
#,gcc,c++11
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-g -std=c++11 ${CMAKE_CXX_FLAGS}")
message(STATUS "optional:-std=c++11")
endif(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()
find_package(Qt5 COMPONENTS Widgets Network LinguistTools REQUIRED)
find_package(Qt5DBus REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(KF5WindowSystem REQUIRED)
pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0 udisks2)
pkg_check_modules(QGS REQUIRED gsettings-qt)
FILE(GLOB TS_FILES ${CMAKE_SOURCE_DIR}/translation/*.ts)
FILE(GLOB SRC_FILES ${CMAKE_SOURCE_DIR}/src/kylin-device-daemon.qrc
${CMAKE_SOURCE_DIR}/src/main.cpp
${CMAKE_SOURCE_DIR}/src/mainwindow.cpp
${CMAKE_SOURCE_DIR}/src/qclickwidget.cpp
${CMAKE_SOURCE_DIR}/src/qclickwidget.h
${CMAKE_SOURCE_DIR}/src/UnionVariable.cpp
${CMAKE_SOURCE_DIR}/src/UnionVariable.h
${CMAKE_SOURCE_DIR}/src/ejectInterface.cpp
${CMAKE_SOURCE_DIR}/src/ejectInterface.h
${CMAKE_SOURCE_DIR}/src/clickLabel.h
${CMAKE_SOURCE_DIR}/src/device-operation.h
${CMAKE_SOURCE_DIR}/src/device-operation.cpp
${CMAKE_SOURCE_DIR}/src/clickLabel.cpp
${CMAKE_SOURCE_DIR}/src/device-manager.h
${CMAKE_SOURCE_DIR}/src/device-manager.cpp
${CMAKE_SOURCE_DIR}/src/repair-dialog-box.h
${CMAKE_SOURCE_DIR}/src/repair-dialog-box.cpp
${CMAKE_SOURCE_DIR}/src/MainController.h
${CMAKE_SOURCE_DIR}/src/MainController.cpp
${CMAKE_SOURCE_DIR}/src/MacroFile.h
${CMAKE_SOURCE_DIR}/src/interactivedialog.cpp
${CMAKE_SOURCE_DIR}/src/interactivedialog.h
${CMAKE_SOURCE_DIR}/src/gpartedinterface.cpp
${CMAKE_SOURCE_DIR}/src/gpartedinterface.h
${CMAKE_SOURCE_DIR}/src/mainwindow.ui
${CMAKE_SOURCE_DIR}/src/mainwindow.h
${CMAKE_SOURCE_DIR}/src/fdapplication.cpp
${CMAKE_SOURCE_DIR}/src/fdapplication.h
${CMAKE_SOURCE_DIR}/src/fdframe.cpp
${CMAKE_SOURCE_DIR}/src/fdframe.h
${CMAKE_SOURCE_DIR}/src/flashdiskdata.cpp
${CMAKE_SOURCE_DIR}/src/flashdiskdata.h
${CMAKE_SOURCE_DIR}/src/fdclickwidget.cpp
${CMAKE_SOURCE_DIR}/src/fdclickwidget.h
${CMAKE_SOURCE_DIR}/src/QtSingleApplication/qtsingleapplication.h
${CMAKE_SOURCE_DIR}/src/QtSingleApplication/qtsingleapplication.cpp
${CMAKE_SOURCE_DIR}/src/QtSingleApplication/qtlocalpeer.h
${CMAKE_SOURCE_DIR}/src/QtSingleApplication/qtlocalpeer.cpp
${CMAKE_SOURCE_DIR}/src/datacdrom.h
${CMAKE_SOURCE_DIR}/src/datacdrom.cpp)
QT5_CREATE_TRANSLATION(QM_FILES ${PROJECT_SOURCE_DIR} ${TS_FILES})
include_directories(${GLIB2_INCLUDE_DIRS})
include_directories(${QGS_INCLUDE_DIRS})
add_executable(kylin-device-daemon ${QM_FILES} ${SRC_FILES})
add_executable(test-repair-dialog
${CMAKE_SOURCE_DIR}/src/device-manager.h
${CMAKE_SOURCE_DIR}/src/device-manager.cpp
${CMAKE_SOURCE_DIR}/src/repair-dialog-box.h
${CMAKE_SOURCE_DIR}/src/repair-dialog-box.cpp
${CMAKE_SOURCE_DIR}/src/device-operation.h
${CMAKE_SOURCE_DIR}/src/device-operation.cpp
${CMAKE_SOURCE_DIR}/src/test-repair-dialog.cpp
)
target_link_libraries(test-repair-dialog Qt5::Widgets Qt5::DBus ${GLIB2_LIBRARIES} ${QGS_LIBRARIES} KF5::WindowSystem)
add_definitions(-DQT_NO_KEYWORDS)
add_definitions(-DQT_MESSAGELOGCONTEXT)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::DBus Qt5::Network ${GLIB2_LIBRARIES} ${QGS_LIBRARIES} KF5::WindowSystem -lukui-log4qt)
install(TARGETS kylin-device-daemon DESTINATION bin)
install(FILES ${CMAKE_SOURCE_DIR}/data/kylin-device-daemon.lock DESTINATION "/usr/share/ukui/ukui-panel" COMPONENT Runtime)
install(FILES ${CMAKE_SOURCE_DIR}/data/org.kylin.kylin-device-daemon-pkexec.policy DESTINATION "/usr/share/polkit-1/actions/" COMPONENT Runtime)
install(FILES ${CMAKE_SOURCE_DIR}/data/kylin-device-daemon-pkexec.sh DESTINATION "/usr/bin/" COMPONENT Runtime PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
install(FILES ${CMAKE_SOURCE_DIR}/data/kylin-device-daemon.desktop DESTINATION "/etc/xdg/autostart/" COMPONENT Runtime)
install(FILES ${CMAKE_SOURCE_DIR}/src/kylin-device-daemon.qrc ${CMAKE_BINARY_DIR}/kylin-device-daemon_zh_CN.qm ${CMAKE_BINARY_DIR}/kylin-device-daemon_bo_CN.qm ${CMAKE_BINARY_DIR}/kylin-device-daemon_tr.qm DESTINATION "/usr/share/kylin-device-daemon/" COMPONENT Runtime)
install(FILES ${CMAKE_SOURCE_DIR}/data/org.kylin-device-daemon.autoload.gschema.xml DESTINATION "/usr/share/glib-2.0/schemas" COMPONENT Runtime)

418
CMakeLists.txt.user Normal file
View File

@ -0,0 +1,418 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.11.0, 2022-06-23T10:39:49. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{6c026b56-752d-4365-bbdb-c829a30fbcdd}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="int">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">桌面</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">桌面</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{9c849945-79b4-46b9-b0ce-d0243754f3e0}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<valuelist type="QVariantList" key="CMake.Configuration">
<value type="QString">CMAKE_BUILD_TYPE:STRING=Debug</value>
<value type="QString">CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}</value>
<value type="QString">CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}</value>
<value type="QString">CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}</value>
<value type="QString">QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}</value>
</valuelist>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/kylin/桌面/tmp/ukui3.1-git/build-kylin-device-daemon-unknown-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<valuelist type="QVariantList" key="CMake.Configuration">
<value type="QString">CMAKE_BUILD_TYPE:STRING=Release</value>
<value type="QString">CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}</value>
<value type="QString">CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}</value>
<value type="QString">CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}</value>
<value type="QString">QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}</value>
</valuelist>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/kylin/桌面/tmp/ukui3.1-git/build-kylin-device-daemon-unknown-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<valuelist type="QVariantList" key="CMake.Configuration">
<value type="QString">CMAKE_BUILD_TYPE:STRING=RelWithDebInfo</value>
<value type="QString">CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}</value>
<value type="QString">CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}</value>
<value type="QString">CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}</value>
<value type="QString">QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}</value>
</valuelist>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/kylin/桌面/tmp/ukui3.1-git/build-kylin-device-daemon-unknown-RelWithDebInfo</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release with Debug Information</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.3">
<valuelist type="QVariantList" key="CMake.Configuration">
<value type="QString">CMAKE_BUILD_TYPE:STRING=MinSizeRel</value>
<value type="QString">CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}</value>
<value type="QString">CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}</value>
<value type="QString">CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}</value>
<value type="QString">QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}</value>
</valuelist>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/kylin/桌面/tmp/ukui3.1-git/build-kylin-device-daemon-unknown-MinSizeRel</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Minimum Size Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">4</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="QString" key="Analyzer.Perf.CallgraphMode">dwarf</value>
<valuelist type="QVariantList" key="Analyzer.Perf.Events">
<value type="QString">cpu-cycles</value>
</valuelist>
<valuelist type="QVariantList" key="Analyzer.Perf.ExtraArguments"/>
<value type="int" key="Analyzer.Perf.Frequency">250</value>
<valuelist type="QVariantList" key="Analyzer.Perf.RecordArguments">
<value type="QString">-e</value>
<value type="QString">cpu-cycles</value>
<value type="QString">--call-graph</value>
<value type="QString">dwarf,4096</value>
<value type="QString">-F</value>
<value type="QString">250</value>
</valuelist>
<value type="QString" key="Analyzer.Perf.SampleMode">-F</value>
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Perf.StackSize">4096</value>
<value type="bool" key="Analyzer.QmlProfiler.AggregateTraces">false</value>
<value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
<value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value>
<value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
<value type="QString" key="Analyzer.Valgrind.KCachegrindExecutable">kcachegrind</value>
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">0</value>
<value type="int">1</value>
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
<value type="int">11</value>
<value type="int">12</value>
<value type="int">13</value>
<value type="int">14</value>
</valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">kylin-device-daemon</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeRunConfiguration.kylin-device-daemon</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">kylin-device-daemon</value>
<value type="QString" key="RunConfiguration.Arguments"></value>
<value type="bool" key="RunConfiguration.Arguments.multi">false</value>
<value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/home/kylin/桌面/tmp/ukui3.1-git/build-kylin-device-daemon-unknown-Debug</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.1">
<value type="QString" key="Analyzer.Perf.CallgraphMode">dwarf</value>
<valuelist type="QVariantList" key="Analyzer.Perf.Events">
<value type="QString">cpu-cycles</value>
</valuelist>
<valuelist type="QVariantList" key="Analyzer.Perf.ExtraArguments"/>
<value type="int" key="Analyzer.Perf.Frequency">250</value>
<valuelist type="QVariantList" key="Analyzer.Perf.RecordArguments">
<value type="QString">-e</value>
<value type="QString">cpu-cycles</value>
<value type="QString">--call-graph</value>
<value type="QString">dwarf,4096</value>
<value type="QString">-F</value>
<value type="QString">250</value>
</valuelist>
<value type="QString" key="Analyzer.Perf.SampleMode">-F</value>
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Perf.StackSize">4096</value>
<value type="bool" key="Analyzer.QmlProfiler.AggregateTraces">false</value>
<value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
<value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value>
<value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
<value type="QString" key="Analyzer.Valgrind.KCachegrindExecutable">kcachegrind</value>
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">0</value>
<value type="int">1</value>
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
<value type="int">11</value>
<value type="int">12</value>
<value type="int">13</value>
<value type="int">14</value>
</valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">test-repair-dialog</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeRunConfiguration.test-repair-dialog</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">test-repair-dialog</value>
<value type="QString" key="RunConfiguration.Arguments"></value>
<value type="bool" key="RunConfiguration.Arguments.multi">false</value>
<value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/home/kylin/桌面/tmp/ukui3.1-git/build-kylin-device-daemon-unknown-Debug</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">2</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="int">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">22</value>
</data>
<data>
<variable>Version</variable>
<value type="int">22</value>
</data>
</qtcreator>

458
COPYING Normal file
View File

@ -0,0 +1,458 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS

0
INSTALL Normal file
View File

6
NEWS Normal file
View File

@ -0,0 +1,6 @@
### ukui-panel 2.0.0
* fork from lxqt-panel
### ukui-panel 1.0.0
* Initial release.

0
README.md Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

27
data/drive-removable-media.svg Executable file
View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="图层_2_1_" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
y="0px" viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;}
</style>
<g id="U盘">
<g id="_16">
<g>
<path class="st0" d="M10,1v2H5V1H10 M11,0H4v4h7V0L11,0z"/>
</g>
<g>
<path class="st0" d="M12,14c0,0.6-0.4,1-1,1H4c-0.6,0-1-0.4-1-1V5c0-0.6,0.4-1,1-1h7c0.6,0,1,0.4,1,1V14z M4,3C2.9,3,2,3.9,2,5v9
c0,1.1,0.9,2,2,2h7c1.1,0,2-0.9,2-2V5c0-1.1-0.9-2-2-2H4z"/>
</g>
<path class="st0" d="M4,5.5v8C4,13.8,4.2,14,4.5,14h6c0.3,0,0.5-0.2,0.5-0.5v-8C11,5.2,10.8,5,10.5,5h-6C4.2,5,4,5.2,4,5.5z
M10.1,8.4H9.8V9c0,0.2-0.1,0.5-0.3,0.7C9.2,9.9,9,10.1,8.7,10.2c-0.2,0.1-0.8,0.3-0.8,0.3c-0.1,0.1-0.1,0.1-0.1,0.2v0.8v0.6
c0.3,0.1,0.5,0.4,0.5,0.7l0,0c0,0.4-0.4,0.7-0.8,0.7l0,0c-0.4,0-0.8-0.3-0.8-0.7c0-0.3,0.3-0.6,0.6-0.7v-0.7c0-0.1,0-0.2-0.1-0.2
l-1.7-0.8c-0.2-0.1-0.3-0.3-0.3-0.6V9.2C5,9.1,4.8,8.9,4.8,8.7l0,0c0-0.3,0.3-0.6,0.7-0.6l0,0c0.3,0,0.6,0.3,0.6,0.6
c0,0.2-0.2,0.5-0.4,0.5v0.5c0,0.1,0,0.2,0.1,0.2c0.1,0.1,1.4,0.5,1.4,0.5V6.7H6.7l0.9-1.3l0.9,1.3H7.8v3.2c0,0,0.7-0.3,0.9-0.3
c0.2-0.1,0.5-0.3,0.5-0.7V8.4H8.9V7.2h1.2C10.1,7.2,10.1,8.4,10.1,8.4z"/>
<rect id="rect3767" x="6" y="2" class="st0" width="1" height="1"/>
<rect id="rect3769" x="8" y="2" class="st0" width="1" height="1"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,199 @@
#!/bin/bash
function parseopts()
{
local opt= optarg= i= shortopts=$1
local -a longopts=() unused_argv=()
shift
while [[ $1 && $1 != '--' ]]; do
longopts+=("$1")
shift
done
shift
longoptmatch() {
local o longmatch=()
for o in "${longopts[@]}"; do
if [[ ${o%:} = "$1" ]]; then
longmatch=("$o")
break
fi
[[ ${o%:} = "$1"* ]] && longmatch+=("$o")
done
case ${#longmatch[*]} in
1)
opt=${longmatch%:}
if [[ $longmatch = *: ]]; then
return 1
else
return 0
fi ;;
0)
return 255 ;;
*)
return 254 ;;
esac
}
while (( $# )); do
case $1 in
--) # explicit end of options
shift
break
;;
-[!-]*) # short option
for (( i = 1; i < ${#1}; i++ )); do
opt=${1:i:1}
# option doesn't exist
if [[ $shortopts != *$opt* ]]; then
OPTRET=(--)
return 1
fi
OPTRET+=("-$opt")
# option requires optarg
if [[ $shortopts = *$opt:* ]]; then
if (( i < ${#1} - 1 )); then
OPTRET+=("${1:i+1}")
break
elif (( i == ${#1} - 1 )) && [[ "$2" ]]; then
OPTRET+=("$2")
shift
break
# parse failure
else
OPTRET=(--)
return 1
fi
fi
done
;;
--?*=*|--?*) # long option
IFS='=' read -r opt optarg <<< "${1#--}"
longoptmatch "$opt"
case $? in
0)
if [[ $optarg ]]; then
OPTRET=(--)
return 1
else
OPTRET+=("--$opt")
fi
;;
1)
if [[ $optarg ]]; then
OPTRET+=("--$opt" "$optarg")
elif [[ "$2" ]]; then
OPTRET+=("--$opt" "$2" )
shift
else
printf "%s: 配置选项 '--%s' 需要参数!\n" "${0##*/}" "$opt"
OPTRET=(--)
return 1
fi
;;
254)
OPTRET=(--)
return 1
;;
255)
# parse failure
printf "%s: 未定义的配置选项 '%s'\n" "${0##*/}" "--$opt"
OPTRET=(--)
return 1
;;
esac
;;
*) # non-option arg encountered, add it as a parameter
unused_argv+=("$1")
;;
esac
shift
done
# add end-of-opt terminator and any leftover positional parameters
OPTRET+=('--' "${unused_argv[@]}" "$@")
unset longoptmatch
return 0
}
function cleanup()
{
exit ${1:-$?}
}
function usage()
{
cat <<EOF
使用: ${0##*/} [配置选项]
配置选项:
-m, --mount <设备名> 将设备挂载到指定位置
-p, --point <挂载点> 将设备挂载到指定位置
-h, --help 显示此帮助信息并退出
EOF
}
function mount_udf_cdrom()
{
if [[ "x$1" != "x" && "x$2" != "x" ]]; then
[[ ! -d "$2" ]] && mkdir -p "$2"
mount -o nouser "$1" "$2"
fi
}
### main
trap 'cleanup 130' INT
trap 'cleanup 143' TERM
if [ "$#" -lt 1 ]; then
usage
cleanup 1
fi
device=""
mountPoint=""
_opt_short='d:p:h'
_opt_long=('device:' 'point:' 'help')
parseopts "$_opt_short" "${_opt_long[@]}" -- "$@" || exit 1
set -- "${OPTRET[@]}"
unset _opt_short _opt_long OPTRET
while :; do
case $1 in
-d|--device)
shift
# 挂载设备
device="$1"
;;
-p|--point)
shift
# 挂载位置
mountPoint="$1"
;;
-h|--help)
usage
cleanup 0
;;
--)
shift
break 2
;;
esac
shift
done
if [[ "x${device}" != "x" && "x${mountPoint}" != "x" ]];
then
mount_udf_cdrom "${device}" "${mountPoint}"
fi

View File

@ -0,0 +1,12 @@
[Desktop Entry]
Name=kylin device daemon
Name[zh_CN]=麒麟设备管理后台
Comment=kylin device daemon
Comment[zh_CN]=麒麟设备管理后台
Exec=kylin-device-daemon
Terminal=false
Type=Application
Icon=panel
X-UKUI-AutoRestart=true
OnlyShowIn=UKUI
NoDisplay=true

View File

View File

@ -0,0 +1 @@
<svg id="播放" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><defs><style>.cls-1{fill:#fff;}</style></defs><title>画板 1</title><g id="_16" data-name=" 16"><rect class="cls-1" y="13" width="16" height="1"/><path class="cls-1" d="M8,2.7,14,11H2L8,2.7M8,1,0,12H16L8,1Z"/></g></svg>

After

Width:  |  Height:  |  Size: 292 B

View File

@ -0,0 +1,9 @@
<schemalist gettext-domain="kylin-device-daemon">
<schema id="org.kylin.device-daemon.autoload" path="/org/kylin/device-daemon/autoload/">
<key type="b" name="ifautoload">
<default>true</default>
<summary>auto load udisk</summary>
<description>Control if auto load udisk</description>
</key>
</schema>
</schemalist>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<vendor>kylin-device-daemon-pkexec</vendor>
<vendor_url></vendor_url>
<action id="org.freedesktop.pkexec.kylin_device_daemon_pkexec">
<description>kylin-device-daemon-pkexec</description>
<description xml:lang="zh_CN">kylin-device-daemon-pkexec</description>
<message>Authentication</message>
<message xml:lang="zh_CN">kylin-device-daemon-pkexec</message>
<icon_name>system-file-manager</icon_name>
<defaults>
<allow_any>yes</allow_any>
<allow_inactive>yes</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/kylin-device-daemon-pkexec.sh</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
</action>
</policyconfig>

17
man/kylin-device-daemon.1 Normal file
View File

@ -0,0 +1,17 @@
.TH ukui "1" "2020-01-01" "UKUI 0.10.0" "UKUI Desktop Environment"
.SH NAME
kylin-device-daemon \- The Daemon Application for the UKUI Desktop Environment
.SH SYNOPSIS
.B kylin-device-daemon
.br
.SH DESCRIPTION
This is daemon for ukui-panel
.SH BEHAVIOR
kylin-device-daemon daemon can detect whether there is external storage medium mounted
Click to open the content of the storage medium
.P
kylin-device-daemon can according to the detected signal to determine whether to display in the tray bar
.SH "REPORTING BUGS"
Report bugs to https://github.com/ukui/ukui-panel/issues
.SH "SEE ALSO"

54
src/MacroFile.h Normal file
View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef _MACROFILE_H_
#define _MACROFILE_H_
typedef enum {downPosition = 0,upPosition,leftPosition,rightPosition}Suit;
#define SERVICE_NAME_SIZE 64
#define DistanceToPanel 2
#define SmallPanelSize 46
#define UKUI_FLASH_DISK_PATH "/"
#define UKUI_FLASH_DISK_SERVICE "com.ukuiflashdisk.hotel"
#define UKUI_FLASH_DISK_INTERFACE "com.flshdisk.hotel"
#define NORMALDEVICE 0
#define DATADEVICE 1
#define OCCUPYDEVICE 2
#define GPARTEDINTERFACE 3
#define DISTANCEPADDING 6
#define DISTANCEMEND 2
#define FLASHDISKITEM_TITLE_HEIGHT 15
#define FLASHDISKITEM_CONTENT_HEIGHT 45
#define FLASHDISKITEM_HEIGHT 112
#define NEWINFO_DELAYSHOW_TIME 1500
/**
* QT主题
*/
#define THEME_QT_SCHEMA "org.ukui.style"
//opacity setting
#define THEME_QT_TRANS "org.ukui.control-center.personalise"
#define FONT_SIZE "system-font-size"
#define MODE_QT_KEY "style-name"
#define AUTOLOAD "org.kylin.device-daemon.autoload"
#define IFAUTOLOAD "ifautoload"
#define IFDISTINCT_DEVICON 1
#endif //_MACROFILE_H_

45
src/MainController.cpp Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "MainController.h"
#include <KWindowEffects>
//#include "stdlib.h"
MainController* MainController::mSelf = 0; //static variable
MainController* MainController::self() //static function //complete the singleton object
{
if (!mSelf)
{
mSelf = new MainController;
}
return mSelf;
}
MainController::MainController()
{
}
MainController::~MainController()
{
}
int MainController::init() //init select
{
m_DiskWindow = new MainWindow; //main process singleton object
connect(this, &MainController::notifyWnd, m_DiskWindow, &MainWindow::onNotifyWnd);
return 0;
}

50
src/MainController.h Normal file
View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef _MAINCONTROL_H_
#define _MAINCONTROL_H_
#include <QObject>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusAbstractAdaptor>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusReply>
#include <QtDBus/QDBusConnectionInterface>
#include "mainwindow.h"
#include "MacroFile.h"
class MainController : public QObject
{
Q_OBJECT
public:
static MainController* self();
virtual ~MainController();
int init();
private:
explicit MainController();
public:
Q_SIGNALS:
void notifyWnd(QObject* obj, QEvent *event);
private:
static MainController *mSelf;
MainWindow *m_DiskWindow;
};
#endif //_MAINCONTROL_H_

View File

@ -0,0 +1 @@
#include "qtlockedfile.h"

View File

@ -0,0 +1 @@
#include "qtsingleapplication.h"

View File

@ -0,0 +1,213 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Solutions component.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtlocalpeer.h"
#include <QCoreApplication>
#include <QDataStream>
#include <QTime>
#if defined(Q_OS_WIN)
#include <QLibrary>
#include <qt_windows.h>
typedef BOOL(WINAPI*PProcessIdToSessionId)(DWORD,DWORD*);
static PProcessIdToSessionId pProcessIdToSessionId = 0;
#endif
#if defined(Q_OS_UNIX)
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#endif
namespace QtLP_Private {
#include "qtlockedfile.cpp"
#if defined(Q_OS_WIN)
#include "qtlockedfile_win.cpp"
#else
#include "qtlockedfile_unix.cpp"
#endif
}
const char* QtLocalPeer::ack = "ack";
QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId)
: QObject(parent), id(appId)
{
QString prefix = id;
if (id.isEmpty()) {
id = QCoreApplication::applicationFilePath();
#if defined(Q_OS_WIN)
id = id.toLower();
#endif
prefix = id.section(QLatin1Char('/'), -1);
}
prefix.remove(QRegExp("[^a-zA-Z]"));
prefix.truncate(6);
QByteArray idc = id.toUtf8();
quint16 idNum = qChecksum(idc.constData(), idc.size());
socketName = QLatin1String("qtsingleapp-") + prefix
+ QLatin1Char('-') + QString::number(idNum, 16);
#if defined(Q_OS_WIN)
if (!pProcessIdToSessionId) {
QLibrary lib("kernel32");
pProcessIdToSessionId = (PProcessIdToSessionId)lib.resolve("ProcessIdToSessionId");
}
if (pProcessIdToSessionId) {
DWORD sessionId = 0;
pProcessIdToSessionId(GetCurrentProcessId(), &sessionId);
socketName += QLatin1Char('-') + QString::number(sessionId, 16);
}
#else
socketName += QLatin1Char('-') + QString::number(::getuid(), 16);
#endif
server = new QLocalServer(this);
QString lockName = QDir(QDir::tempPath()).absolutePath()
+ QLatin1Char('/') + socketName
+ QLatin1String("-lockfile");
lockFile.setFileName(lockName);
lockFile.open(QIODevice::ReadWrite);
}
bool QtLocalPeer::isClient()
{
if (lockFile.isLocked())
return false;
if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false))
return true;
bool res = server->listen(socketName);
#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0))
// ### Workaround
if (!res && server->serverError() == QAbstractSocket::AddressInUseError) {
QFile::remove(QDir::cleanPath(QDir::tempPath())+QLatin1Char('/')+socketName);
res = server->listen(socketName);
}
#endif
if (!res)
qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString()));
QObject::connect(server, SIGNAL(newConnection()), SLOT(receiveConnection()));
return false;
}
bool QtLocalPeer::sendMessage(const QString &message, int timeout)
{
if (!isClient())
return false;
QLocalSocket socket;
bool connOk = false;
for(int i = 0; i < 2; i++) {
// Try twice, in case the other instance is just starting up
socket.connectToServer(socketName);
connOk = socket.waitForConnected(timeout/2);
if (connOk || i)
break;
int ms = 250;
#if defined(Q_OS_WIN)
Sleep(DWORD(ms));
#else
struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
nanosleep(&ts, NULL);
#endif
}
if (!connOk)
return false;
QByteArray uMsg(message.toUtf8());
QDataStream ds(&socket);
ds.writeBytes(uMsg.constData(), uMsg.size());
bool res = socket.waitForBytesWritten(timeout);
if (res) {
res &= socket.waitForReadyRead(timeout); // wait for ack
if (res)
res &= (socket.read(qstrlen(ack)) == ack);
}
return res;
}
void QtLocalPeer::receiveConnection()
{
QLocalSocket* socket = server->nextPendingConnection();
if (!socket)
return;
while (true) {
if (socket->state() == QLocalSocket::UnconnectedState) {
qWarning("QtLocalPeer: Peer disconnected");
delete socket;
return;
}
if (socket->bytesAvailable() >= qint64(sizeof(quint32)))
break;
socket->waitForReadyRead();
}
QDataStream ds(socket);
QByteArray uMsg;
quint32 remaining;
ds >> remaining;
uMsg.resize(remaining);
int got = 0;
char* uMsgBuf = uMsg.data();
do {
got = ds.readRawData(uMsgBuf, remaining);
remaining -= got;
uMsgBuf += got;
} while (remaining && got >= 0 && socket->waitForReadyRead(2000));
if (got < 0) {
qWarning("QtLocalPeer: Message reception failed %s", socket->errorString().toLatin1().constData());
delete socket;
return;
}
QString message(QString::fromUtf8(uMsg));
socket->write(ack, qstrlen(ack));
socket->waitForBytesWritten(1000);
socket->waitForDisconnected(1000); // make sure client reads ack
delete socket;
Q_EMIT messageReceived(message); //### (might take a long time to return)
}

View File

@ -0,0 +1,77 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Solutions component.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QTLOCALPEER_H
#define QTLOCALPEER_H
#include <QLocalServer>
#include <QLocalSocket>
#include <QDir>
#include "qtlockedfile.h"
class QtLocalPeer : public QObject
{
Q_OBJECT
public:
QtLocalPeer(QObject *parent = 0, const QString &appId = QString());
bool isClient();
bool sendMessage(const QString &message, int timeout);
QString applicationId() const
{ return id; }
Q_SIGNALS:
void messageReceived(const QString &message);
protected Q_SLOTS:
void receiveConnection();
protected:
QString id;
QString socketName;
QLocalServer* server;
QtLP_Private::QtLockedFile lockFile;
private:
static const char* ack;
};
#endif // QTLOCALPEER_H

View File

@ -0,0 +1,193 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Solutions component.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtlockedfile.h"
/*!
\class QtLockedFile
\brief The QtLockedFile class extends QFile with advisory locking
functions.
A file may be locked in read or write mode. Multiple instances of
\e QtLockedFile, created in multiple processes running on the same
machine, may have a file locked in read mode. Exactly one instance
may have it locked in write mode. A read and a write lock cannot
exist simultaneously on the same file.
The file locks are advisory. This means that nothing prevents
another process from manipulating a locked file using QFile or
file system functions offered by the OS. Serialization is only
guaranteed if all processes that access the file use
QLockedFile. Also, while holding a lock on a file, a process
must not open the same file again (through any API), or locks
can be unexpectedly lost.
The lock provided by an instance of \e QtLockedFile is released
whenever the program terminates. This is true even when the
program crashes and no destructors are called.
*/
/*! \enum QtLockedFile::LockMode
This enum describes the available lock modes.
\value ReadLock A read lock.
\value WriteLock A write lock.
\value NoLock Neither a read lock nor a write lock.
*/
/*!
Constructs an unlocked \e QtLockedFile object. This constructor
behaves in the same way as \e QFile::QFile().
\sa QFile::QFile()
*/
QtLockedFile::QtLockedFile()
: QFile()
{
#ifdef Q_OS_WIN
wmutex = 0;
rmutex = 0;
#endif
m_lock_mode = NoLock;
}
/*!
Constructs an unlocked QtLockedFile object with file \a name. This
constructor behaves in the same way as \e QFile::QFile(const
QString&).
\sa QFile::QFile()
*/
QtLockedFile::QtLockedFile(const QString &name)
: QFile(name)
{
#ifdef Q_OS_WIN
wmutex = 0;
rmutex = 0;
#endif
m_lock_mode = NoLock;
}
/*!
Opens the file in OpenMode \a mode.
This is identical to QFile::open(), with the one exception that the
Truncate mode flag is disallowed. Truncation would conflict with the
advisory file locking, since the file would be modified before the
write lock is obtained. If truncation is required, use resize(0)
after obtaining the write lock.
Returns true if successful; otherwise false.
\sa QFile::open(), QFile::resize()
*/
bool QtLockedFile::open(OpenMode mode)
{
if (mode & QIODevice::Truncate) {
qWarning("QtLockedFile::open(): Truncate mode not allowed.");
return false;
}
return QFile::open(mode);
}
/*!
Returns \e true if this object has a in read or write lock;
otherwise returns \e false.
\sa lockMode()
*/
bool QtLockedFile::isLocked() const
{
return m_lock_mode != NoLock;
}
/*!
Returns the type of lock currently held by this object, or \e
QtLockedFile::NoLock.
\sa isLocked()
*/
QtLockedFile::LockMode QtLockedFile::lockMode() const
{
return m_lock_mode;
}
/*!
\fn bool QtLockedFile::lock(LockMode mode, bool block = true)
Obtains a lock of type \a mode. The file must be opened before it
can be locked.
If \a block is true, this function will block until the lock is
aquired. If \a block is false, this function returns \e false
immediately if the lock cannot be aquired.
If this object already has a lock of type \a mode, this function
returns \e true immediately. If this object has a lock of a
different type than \a mode, the lock is first released and then a
new lock is obtained.
This function returns \e true if, after it executes, the file is
locked by this object, and \e false otherwise.
\sa unlock(), isLocked(), lockMode()
*/
/*!
\fn bool QtLockedFile::unlock()
Releases a lock.
If the object has no lock, this function returns immediately.
This function returns \e true if, after it executes, the file is
not locked by this object, and \e false otherwise.
\sa lock(), isLocked(), lockMode()
*/
/*!
\fn QtLockedFile::~QtLockedFile()
Destroys the \e QtLockedFile object. If any locks were held, they
are released.
*/

View File

@ -0,0 +1,97 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Solutions component.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QTLOCKEDFILE_H
#define QTLOCKEDFILE_H
#include <QFile>
#ifdef Q_OS_WIN
#include <QVector>
#endif
#if defined(Q_OS_WIN)
# if !defined(QT_QTLOCKEDFILE_EXPORT) && !defined(QT_QTLOCKEDFILE_IMPORT)
# define QT_QTLOCKEDFILE_EXPORT
# elif defined(QT_QTLOCKEDFILE_IMPORT)
# if defined(QT_QTLOCKEDFILE_EXPORT)
# undef QT_QTLOCKEDFILE_EXPORT
# endif
# define QT_QTLOCKEDFILE_EXPORT __declspec(dllimport)
# elif defined(QT_QTLOCKEDFILE_EXPORT)
# undef QT_QTLOCKEDFILE_EXPORT
# define QT_QTLOCKEDFILE_EXPORT __declspec(dllexport)
# endif
#else
# define QT_QTLOCKEDFILE_EXPORT
#endif
namespace QtLP_Private {
class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile
{
public:
enum LockMode { NoLock = 0, ReadLock, WriteLock };
QtLockedFile();
QtLockedFile(const QString &name);
~QtLockedFile();
bool open(OpenMode mode);
bool lock(LockMode mode, bool block = true);
bool unlock();
bool isLocked() const;
LockMode lockMode() const;
private:
#ifdef Q_OS_WIN
Qt::HANDLE wmutex;
Qt::HANDLE rmutex;
QVector<Qt::HANDLE> rmutexes;
QString mutexname;
Qt::HANDLE getMutexHandle(int idx, bool doCreate);
bool waitMutex(Qt::HANDLE mutex, bool doBlock);
#endif
LockMode m_lock_mode;
};
}
#endif

View File

@ -0,0 +1,115 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Solutions component.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include "qtlockedfile.h"
bool QtLockedFile::lock(LockMode mode, bool block)
{
if (!isOpen()) {
qWarning("QtLockedFile::lock(): file is not opened");
return false;
}
if (mode == NoLock)
return unlock();
if (mode == m_lock_mode)
return true;
if (m_lock_mode != NoLock)
unlock();
struct flock fl;
fl.l_whence = SEEK_SET;
fl.l_start = 0;
fl.l_len = 0;
fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK;
int cmd = block ? F_SETLKW : F_SETLK;
int ret = fcntl(handle(), cmd, &fl);
if (ret == -1) {
if (errno != EINTR && errno != EAGAIN)
qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno));
return false;
}
m_lock_mode = mode;
return true;
}
bool QtLockedFile::unlock()
{
if (!isOpen()) {
qWarning("QtLockedFile::unlock(): file is not opened");
return false;
}
if (!isLocked())
return true;
struct flock fl;
fl.l_whence = SEEK_SET;
fl.l_start = 0;
fl.l_len = 0;
fl.l_type = F_UNLCK;
int ret = fcntl(handle(), F_SETLKW, &fl);
if (ret == -1) {
qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno));
return false;
}
m_lock_mode = NoLock;
return true;
}
QtLockedFile::~QtLockedFile()
{
if (isOpen())
unlock();
}

View File

@ -0,0 +1,211 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Solutions component.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtlockedfile.h"
#include <qt_windows.h>
#include <QFileInfo>
#define MUTEX_PREFIX "QtLockedFile mutex "
// Maximum number of concurrent read locks. Must not be greater than MAXIMUM_WAIT_OBJECTS
#define MAX_READERS MAXIMUM_WAIT_OBJECTS
#if QT_VERSION >= 0x050000
#define QT_WA(unicode, ansi) unicode
#endif
Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate)
{
if (mutexname.isEmpty()) {
QFileInfo fi(*this);
mutexname = QString::fromLatin1(MUTEX_PREFIX)
+ fi.absoluteFilePath().toLower();
}
QString mname(mutexname);
if (idx >= 0)
mname += QString::number(idx);
Qt::HANDLE mutex;
if (doCreate) {
QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); },
{ mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } );
if (!mutex) {
qErrnoWarning("QtLockedFile::lock(): CreateMutex failed");
return 0;
}
}
else {
QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); },
{ mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } );
if (!mutex) {
if (GetLastError() != ERROR_FILE_NOT_FOUND)
qErrnoWarning("QtLockedFile::lock(): OpenMutex failed");
return 0;
}
}
return mutex;
}
bool QtLockedFile::waitMutex(Qt::HANDLE mutex, bool doBlock)
{
Q_ASSERT(mutex);
DWORD res = WaitForSingleObject(mutex, doBlock ? INFINITE : 0);
switch (res) {
case WAIT_OBJECT_0:
case WAIT_ABANDONED:
return true;
break;
case WAIT_TIMEOUT:
break;
default:
qErrnoWarning("QtLockedFile::lock(): WaitForSingleObject failed");
}
return false;
}
bool QtLockedFile::lock(LockMode mode, bool block)
{
if (!isOpen()) {
qWarning("QtLockedFile::lock(): file is not opened");
return false;
}
if (mode == NoLock)
return unlock();
if (mode == m_lock_mode)
return true;
if (m_lock_mode != NoLock)
unlock();
if (!wmutex && !(wmutex = getMutexHandle(-1, true)))
return false;
if (!waitMutex(wmutex, block))
return false;
if (mode == ReadLock) {
int idx = 0;
for (; idx < MAX_READERS; idx++) {
rmutex = getMutexHandle(idx, false);
if (!rmutex || waitMutex(rmutex, false))
break;
CloseHandle(rmutex);
}
bool ok = true;
if (idx >= MAX_READERS) {
qWarning("QtLockedFile::lock(): too many readers");
rmutex = 0;
ok = false;
}
else if (!rmutex) {
rmutex = getMutexHandle(idx, true);
if (!rmutex || !waitMutex(rmutex, false))
ok = false;
}
if (!ok && rmutex) {
CloseHandle(rmutex);
rmutex = 0;
}
ReleaseMutex(wmutex);
if (!ok)
return false;
}
else {
Q_ASSERT(rmutexes.isEmpty());
for (int i = 0; i < MAX_READERS; i++) {
Qt::HANDLE mutex = getMutexHandle(i, false);
if (mutex)
rmutexes.append(mutex);
}
if (rmutexes.size()) {
DWORD res = WaitForMultipleObjects(rmutexes.size(), rmutexes.constData(),
TRUE, block ? INFINITE : 0);
if (res != WAIT_OBJECT_0 && res != WAIT_ABANDONED) {
if (res != WAIT_TIMEOUT)
qErrnoWarning("QtLockedFile::lock(): WaitForMultipleObjects failed");
m_lock_mode = WriteLock; // trick unlock() to clean up - semiyucky
unlock();
return false;
}
}
}
m_lock_mode = mode;
return true;
}
bool QtLockedFile::unlock()
{
if (!isOpen()) {
qWarning("QtLockedFile::unlock(): file is not opened");
return false;
}
if (!isLocked())
return true;
if (m_lock_mode == ReadLock) {
ReleaseMutex(rmutex);
CloseHandle(rmutex);
rmutex = 0;
}
else {
foreach(Qt::HANDLE mutex, rmutexes) {
ReleaseMutex(mutex);
CloseHandle(mutex);
}
rmutexes.clear();
ReleaseMutex(wmutex);
}
m_lock_mode = QtLockedFile::NoLock;
return true;
}
QtLockedFile::~QtLockedFile()
{
if (isOpen())
unlock();
if (wmutex)
CloseHandle(wmutex);
}

View File

@ -0,0 +1,348 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Solutions component.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtsingleapplication.h"
#include "qtlocalpeer.h"
#include <QWidget>
/*!
\class QtSingleApplication qtsingleapplication.h
\brief The QtSingleApplication class provides an API to detect and
communicate with running instances of an application.
This class allows you to create applications where only one
instance should be running at a time. I.e., if the user tries to
launch another instance, the already running instance will be
activated instead. Another usecase is a client-server system,
where the first started instance will assume the role of server,
and the later instances will act as clients of that server.
By default, the full path of the executable file is used to
determine whether two processes are instances of the same
application. You can also provide an explicit identifier string
that will be compared instead.
The application should create the QtSingleApplication object early
in the startup phase, and call isRunning() to find out if another
instance of this application is already running. If isRunning()
returns false, it means that no other instance is running, and
this instance has assumed the role as the running instance. In
this case, the application should continue with the initialization
of the application user interface before entering the event loop
with exec(), as normal.
The messageReceived() signal will be emitted when the running
application receives messages from another instance of the same
application. When a message is received it might be helpful to the
user to raise the application so that it becomes visible. To
facilitate this, QtSingleApplication provides the
setActivationWindow() function and the activateWindow() slot.
If isRunning() returns true, another instance is already
running. It may be alerted to the fact that another instance has
started by using the sendMessage() function. Also data such as
startup parameters (e.g. the name of the file the user wanted this
new instance to open) can be passed to the running instance with
this function. Then, the application should terminate (or enter
client mode).
If isRunning() returns true, but sendMessage() fails, that is an
indication that the running instance is frozen.
Here's an example that shows how to convert an existing
application to use QtSingleApplication. It is very simple and does
not make use of all QtSingleApplication's functionality (see the
examples for that).
\code
// Original
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MyMainWidget mmw;
mmw.show();
return app.exec();
}
// Single instance
int main(int argc, char **argv)
{
QtSingleApplication app(argc, argv);
if (app.isRunning())
return !app.sendMessage(someDataString);
MyMainWidget mmw;
app.setActivationWindow(&mmw);
mmw.show();
return app.exec();
}
\endcode
Once this QtSingleApplication instance is destroyed (normally when
the process exits or crashes), when the user next attempts to run the
application this instance will not, of course, be encountered. The
next instance to call isRunning() or sendMessage() will assume the
role as the new running instance.
For console (non-GUI) applications, QtSingleCoreApplication may be
used instead of this class, to avoid the dependency on the QtGui
library.
\sa QtSingleCoreApplication
*/
void QtSingleApplication::sysInit(const QString &appId)
{
actWin = 0;
peer = new QtLocalPeer(this, appId);
connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
}
/*!
Creates a QtSingleApplication object. The application identifier
will be QCoreApplication::applicationFilePath(). \a argc, \a
argv, and \a GUIenabled are passed on to the QAppliation constructor.
If you are creating a console application (i.e. setting \a
GUIenabled to false), you may consider using
QtSingleCoreApplication instead.
*/
QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled)
: QApplication(argc, argv, GUIenabled)
{
sysInit();
}
/*!
Creates a QtSingleApplication object with the application
identifier \a appId. \a argc and \a argv are passed on to the
QAppliation constructor.
*/
QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv)
: QApplication(argc, argv)
{
sysInit(appId);
}
#if QT_VERSION < 0x050000
/*!
Creates a QtSingleApplication object. The application identifier
will be QCoreApplication::applicationFilePath(). \a argc, \a
argv, and \a type are passed on to the QAppliation constructor.
*/
QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type)
: QApplication(argc, argv, type)
{
sysInit();
}
# if defined(Q_WS_X11)
/*!
Special constructor for X11, ref. the documentation of
QApplication's corresponding constructor. The application identifier
will be QCoreApplication::applicationFilePath(). \a dpy, \a visual,
and \a cmap are passed on to the QApplication constructor.
*/
QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap)
: QApplication(dpy, visual, cmap)
{
sysInit();
}
/*!
Special constructor for X11, ref. the documentation of
QApplication's corresponding constructor. The application identifier
will be QCoreApplication::applicationFilePath(). \a dpy, \a argc, \a
argv, \a visual, and \a cmap are passed on to the QApplication
constructor.
*/
QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap)
: QApplication(dpy, argc, argv, visual, cmap)
{
sysInit();
}
/*!
Special constructor for X11, ref. the documentation of
QApplication's corresponding constructor. The application identifier
will be \a appId. \a dpy, \a argc, \a
argv, \a visual, and \a cmap are passed on to the QApplication
constructor.
*/
QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap)
: QApplication(dpy, argc, argv, visual, cmap)
{
sysInit(appId);
}
# endif // Q_WS_X11
#endif // QT_VERSION < 0x050000
/*!
Returns true if another instance of this application is running;
otherwise false.
This function does not find instances of this application that are
being run by a different user (on Windows: that are running in
another session).
\sa sendMessage()
*/
bool QtSingleApplication::isRunning()
{
return peer->isClient();
}
/*!
Tries to send the text \a message to the currently running
instance. The QtSingleApplication object in the running instance
will emit the messageReceived() signal when it receives the
message.
This function returns true if the message has been sent to, and
processed by, the current instance. If there is no instance
currently running, or if the running instance fails to process the
message within \a timeout milliseconds, this function return false.
\sa isRunning(), messageReceived()
*/
bool QtSingleApplication::sendMessage(const QString &message, int timeout)
{
return peer->sendMessage(message, timeout);
}
/*!
Returns the application identifier. Two processes with the same
identifier will be regarded as instances of the same application.
*/
QString QtSingleApplication::id() const
{
return peer->applicationId();
}
/*!
Sets the activation window of this application to \a aw. The
activation window is the widget that will be activated by
activateWindow(). This is typically the application's main window.
If \a activateOnMessage is true (the default), the window will be
activated automatically every time a message is received, just prior
to the messageReceived() signal being emitted.
\sa activateWindow(), messageReceived()
*/
void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage)
{
actWin = aw;
if (activateOnMessage)
connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow()));
else
disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow()));
}
/*!
Returns the applications activation window if one has been set by
calling setActivationWindow(), otherwise returns 0.
\sa setActivationWindow()
*/
QWidget* QtSingleApplication::activationWindow() const
{
return actWin;
}
/*!
De-minimizes, raises, and activates this application's activation window.
This function does nothing if no activation window has been set.
This is a convenience function to show the user that this
application instance has been activated when he has tried to start
another instance.
This function should typically be called in response to the
messageReceived() signal. By default, that will happen
automatically, if an activation window has been set.
\sa setActivationWindow(), messageReceived(), initialize()
*/
void QtSingleApplication::activateWindow()
{
if (actWin) {
actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
actWin->raise();
actWin->showNormal();
actWin->activateWindow();
}
}
/*!
\fn void QtSingleApplication::messageReceived(const QString& message)
This signal is emitted when the current instance receives a \a
message from another instance of this application.
\sa sendMessage(), setActivationWindow(), activateWindow()
*/
/*!
\fn void QtSingleApplication::initialize(bool dummy = true)
\obsolete
*/

View File

@ -0,0 +1,105 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Solutions component.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QTSINGLEAPPLICATION_H
#define QTSINGLEAPPLICATION_H
#include <QApplication>
class QtLocalPeer;
#if defined(Q_OS_WIN)
# if !defined(QT_QTSINGLEAPPLICATION_EXPORT) && !defined(QT_QTSINGLEAPPLICATION_IMPORT)
# define QT_QTSINGLEAPPLICATION_EXPORT
# elif defined(QT_QTSINGLEAPPLICATION_IMPORT)
# if defined(QT_QTSINGLEAPPLICATION_EXPORT)
# undef QT_QTSINGLEAPPLICATION_EXPORT
# endif
# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllimport)
# elif defined(QT_QTSINGLEAPPLICATION_EXPORT)
# undef QT_QTSINGLEAPPLICATION_EXPORT
# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllexport)
# endif
#else
# define QT_QTSINGLEAPPLICATION_EXPORT
#endif
class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication
{
Q_OBJECT
public:
QtSingleApplication(int &argc, char **argv, bool GUIenabled = true);
QtSingleApplication(const QString &id, int &argc, char **argv);
#if QT_VERSION < 0x050000
QtSingleApplication(int &argc, char **argv, Type type);
# if defined(Q_WS_X11)
QtSingleApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0);
QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0);
QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0);
# endif // Q_WS_X11
#endif // QT_VERSION < 0x050000
bool isRunning();
QString id() const;
void setActivationWindow(QWidget* aw, bool activateOnMessage = true);
QWidget* activationWindow() const;
// Obsolete:
void initialize(bool dummy = true)
{ isRunning(); Q_UNUSED(dummy) }
public Q_SLOTS:
bool sendMessage(const QString &message, int timeout = 5000);
void activateWindow();
Q_SIGNALS:
void messageReceived(const QString &message);
private:
void sysInit(const QString &appId = QString());
QtLocalPeer *peer;
QWidget *actWin;
};
#endif // QTSINGLEAPPLICATION_H

View File

@ -0,0 +1,16 @@
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
QT *= network
greaterThan(QT_MAJOR_VERSION, 4): QT *= widgets
qtsingleapplication-uselib:!qtsingleapplication-buildlib {
LIBS += -L$$QTSINGLEAPPLICATION_LIBDIR -l$$QTSINGLEAPPLICATION_LIBNAME
} else {
SOURCES += $$PWD/qtsingleapplication.cpp $$PWD/qtlocalpeer.cpp
HEADERS += $$PWD/qtsingleapplication.h $$PWD/qtlocalpeer.h
}
win32 {
contains(TEMPLATE, lib):contains(CONFIG, shared):DEFINES += QT_QTSINGLEAPPLICATION_EXPORT
else:qtsingleapplication-uselib:DEFINES += QT_QTSINGLEAPPLICATION_IMPORT
}

View File

@ -0,0 +1,149 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Solutions component.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtsinglecoreapplication.h"
#include "qtlocalpeer.h"
/*!
\class QtSingleCoreApplication qtsinglecoreapplication.h
\brief A variant of the QtSingleApplication class for non-GUI applications.
This class is a variant of QtSingleApplication suited for use in
console (non-GUI) applications. It is an extension of
QCoreApplication (instead of QApplication). It does not require
the QtGui library.
The API and usage is identical to QtSingleApplication, except that
functions relating to the "activation window" are not present, for
obvious reasons. Please refer to the QtSingleApplication
documentation for explanation of the usage.
A QtSingleCoreApplication instance can communicate to a
QtSingleApplication instance if they share the same application
id. Hence, this class can be used to create a light-weight
command-line tool that sends commands to a GUI application.
\sa QtSingleApplication
*/
/*!
Creates a QtSingleCoreApplication object. The application identifier
will be QCoreApplication::applicationFilePath(). \a argc and \a
argv are passed on to the QCoreAppliation constructor.
*/
QtSingleCoreApplication::QtSingleCoreApplication(int &argc, char **argv)
: QCoreApplication(argc, argv)
{
peer = new QtLocalPeer(this);
connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
}
/*!
Creates a QtSingleCoreApplication object with the application
identifier \a appId. \a argc and \a argv are passed on to the
QCoreAppliation constructor.
*/
QtSingleCoreApplication::QtSingleCoreApplication(const QString &appId, int &argc, char **argv)
: QCoreApplication(argc, argv)
{
peer = new QtLocalPeer(this, appId);
connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
}
/*!
Returns true if another instance of this application is running;
otherwise false.
This function does not find instances of this application that are
being run by a different user (on Windows: that are running in
another session).
\sa sendMessage()
*/
bool QtSingleCoreApplication::isRunning()
{
return peer->isClient();
}
/*!
Tries to send the text \a message to the currently running
instance. The QtSingleCoreApplication object in the running instance
will emit the messageReceived() signal when it receives the
message.
This function returns true if the message has been sent to, and
processed by, the current instance. If there is no instance
currently running, or if the running instance fails to process the
message within \a timeout milliseconds, this function return false.
\sa isRunning(), messageReceived()
*/
bool QtSingleCoreApplication::sendMessage(const QString &message, int timeout)
{
return peer->sendMessage(message, timeout);
}
/*!
Returns the application identifier. Two processes with the same
identifier will be regarded as instances of the same application.
*/
QString QtSingleCoreApplication::id() const
{
return peer->applicationId();
}
/*!
\fn void QtSingleCoreApplication::messageReceived(const QString& message)
This signal is emitted when the current instance receives a \a
message from another instance of this application.
\sa sendMessage()
*/

View File

@ -0,0 +1,71 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Solutions component.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QTSINGLECOREAPPLICATION_H
#define QTSINGLECOREAPPLICATION_H
#include <QCoreApplication>
class QtLocalPeer;
class QtSingleCoreApplication : public QCoreApplication
{
Q_OBJECT
public:
QtSingleCoreApplication(int &argc, char **argv);
QtSingleCoreApplication(const QString &id, int &argc, char **argv);
bool isRunning();
QString id() const;
public Q_SLOTS:
bool sendMessage(const QString &message, int timeout = 5000);
Q_SIGNALS:
void messageReceived(const QString &message);
private:
QtLocalPeer* peer;
};
#endif // QTSINGLECOREAPPLICATION_H

View File

@ -0,0 +1,16 @@
QT += network
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
HEADERS += $$PWD/qtsinglecoreapplication.h \
$$PWD/qtlocalpeer.h
SOURCES += $$PWD/qtsinglecoreapplication.cpp \
$$PWD/qtlocalpeer.cpp
win32:contains(TEMPLATE, lib):contains(CONFIG, shared) {
DEFINES += QT_QTSINGLECOREAPPLICATION_EXPORT=__declspec(dllexport)
}

200
src/UnionVariable.cpp Normal file
View File

@ -0,0 +1,200 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "UnionVariable.h"
#include <QDir>
#include <QFileInfoList>
#include <QDebug>
#include <syslog.h>
#include <wait.h>
static QList<GMount *> gmountList;
QList<GMount *> *findGMountList()
{
return &gmountList;
}
static QList<GVolume *> gtelevolumeList;
QList<GVolume *> *findTeleGVolumeList()
{
return &gtelevolumeList;
}
static QList<GVolume *> gvolumeList;
QList<GVolume *> *findGVolumeList()
{
return &gvolumeList;
}
static QList<GDrive *> gdriveList;
QList<GDrive *> *findGDriveList()
{
return &gdriveList;
}
static QList<GMount *> gtelemountList;
QList<GMount *> *findTeleGMountList()
{
return &gtelemountList;
}
QString getElidedText(QFont font, QString str, int MaxWidth)
{
if (str.isEmpty())
{
return "";
}
QFontMetrics fontWidth(font);
//计算字符串宽度
//calculat the width of the string
int width = fontWidth.width(str);
//当字符串宽度大于最大宽度时进行转换
//Convert when string width is greater than maximum width
if (width >= MaxWidth)
{
//右部显示省略号
//show by ellipsis in right
str = fontWidth.elidedText(str, Qt::ElideRight, MaxWidth);
}
//返回处理后的字符串
//return the string that is been handled
return str;
}
/**
* @brief
* 使 glib
*/
void handleVolumeLabelForFat32Me(QString &volumeName,const QString &unixDeviceName)
{
if (unixDeviceName.isNull() || unixDeviceName.isEmpty()) {
return;
}
GVolumeMonitor *vm = g_volume_monitor_get();
GList *volumes = g_volume_monitor_get_volumes(vm);
GList *l = volumes;
while (l) {
GVolume *volume = static_cast<GVolume *>(l->data);
g_autofree char *volume_unix_dev = g_volume_get_identifier(volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
if (unixDeviceName == volume_unix_dev) {
g_autofree char *volume_name = g_volume_get_name(volume);
volumeName = volume_name;
break;
}
l = l->next;
}
g_list_free_full(volumes, g_object_unref);
g_object_unref(vm);
return;
QFileInfoList diskList;
QFileInfo diskLabel;
QDir diskDir;
QString partitionName,linkTarget;
QString tmpName,finalName;
int i;
diskDir.setPath("/dev/disk/by-label");
if(!diskDir.exists()) //this means: volume has no name.
return; // or there no mobile devices.
diskList = diskDir.entryInfoList(); //all file from dir.
/* eg: unixDeviceName == "/dev/sdb4"
* partitionName == "sdb4"
*/
partitionName = unixDeviceName.mid(unixDeviceName.lastIndexOf('/')+1);
for(i = 0; i < diskList.size(); ++i){
diskLabel = diskList.at(i);
linkTarget = diskLabel.symLinkTarget();
if(linkTarget.contains(partitionName))
break;
linkTarget.clear();
}
if(!linkTarget.isEmpty())
tmpName = diskLabel.fileName();//可能带有乱码的名字
if(!tmpName.isEmpty()){
if(tmpName == volumeName) //ntfs、exfat格式或者非纯中文名的fat32设备,这个设备的名字不需要转码
return;
else {
finalName = transcodeForGbkCode(tmpName.toLocal8Bit(), volumeName);
if(!finalName.isEmpty())
volumeName = finalName;
}
}
}
QString transcodeForGbkCode(QByteArray gbkName, QString &volumeName)
{
int i;
QByteArray dest,tmp;
QString name;
int len = gbkName.size();
for(i = 0x0; i < len; ++i){
if(92 == gbkName.at(i)){
if(4 == tmp.size())
dest.append(QByteArray::fromHex(tmp));
else{
if(tmp.size() > 4){
dest.append(QByteArray::fromHex(tmp.left(4)));
dest.append(tmp.mid(4));
}else
dest.append(tmp);
}
tmp.clear();
tmp.append(gbkName.at(i));
continue;
}else if(tmp.size() > 0){
tmp.append(gbkName.at(i));
continue;
}else
dest.append(gbkName.at(i));
}
if(4 == tmp.size())
dest.append(QByteArray::fromHex(tmp));
else{
if(tmp.size() > 4){
dest.append(QByteArray::fromHex(tmp.left(4)));
dest.append(tmp.mid(4));
}else
dest.append(tmp);
}
/*
* gio的api获取的卷名和/dev/disk/by-label先的名字不一致
* /dev/disk/label下的卷名含有转义字符
* (2020-08-22)/dev/disk/by-label
* :"数据光盘\x282020-08-22\x29",
*
*/
name = QString(dest);
if (name == volumeName){
return name;
}
name = QTextCodec::codecForName("GBK")->toUnicode(dest);
return name;
}

36
src/UnionVariable.h Normal file
View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef UNIONVARIABLE_H
#define UNIONVARIABLE_H
#include <QList>
#include <gio/gio.h>
#include <QString>
#include <QFont>
#include <QFontMetrics>
#include <QTextCodec>
#include <syslog.h>
QList<GMount *> *findGMountList();
QList<GMount *> *findTeleGMountList();
QList<GVolume *> *findGVolumeList();
QList<GVolume *> *findTeleGVolumeList();
QList<GDrive *> *findGDriveList();
QString getElidedText(QFont font, QString str, int MaxWidth);
QString transcodeForGbkCode(QByteArray gbkName, QString &volumeName);
void handleVolumeLabelForFat32Me(QString &volumeName,const QString &unixDevcieName);
//int m_system(char *cmd);
#endif

40
src/clickLabel.cpp Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "clickLabel.h"
ClickLabel::ClickLabel(QWidget *parent)
{
}
ClickLabel::~ClickLabel()
{
}
void ClickLabel::mousePressEvent(QMouseEvent *event){
if (event->button() == Qt::LeftButton)
Q_EMIT clicked();
QLabel::mousePressEvent(event);
}
//void ClickLabel::paintEvent(QPaintEvent *event){
//// Q_UNUSED(event)
//// QStyleOption opt;
//// opt.init(this);
//// QPainter p(this);
//// style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
//}

42
src/clickLabel.h Normal file
View File

@ -0,0 +1,42 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef CLICKLABEL_H
#define CLICKLABEL_H
#include <QLabel>
#include <QMouseEvent>
#include <QPainter>
#include <QStyleOption>
class ClickLabel : public QLabel
{
Q_OBJECT
public:
explicit ClickLabel(QWidget *parent = 0);
~ClickLabel();
protected:
void mousePressEvent(QMouseEvent * event);
//virtual void paintEvent(QPaintEvent * event);
Q_SIGNALS:
void clicked();
};
#endif // CLICKLABEL_H

603
src/datacdrom.cpp Normal file
View File

@ -0,0 +1,603 @@
/*
* Peony-Qt's Library
*
* Copyright (C) 2020, KylinSoft Co., Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library. If not, see <https://www.gnu.org/licenses/>.
*
* Authors: renpeijia <renpeijia@kylinos.cn>
*
*/
#include "datacdrom.h"
#include <unistd.h>
#include <fcntl.h>
#include <scsi/sg.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <mntent.h>
#include <QThread>
#include <QCoreApplication>
#include <QFileInfo>
#include <QDebug>
DataCDROM::DataCDROM(QString &blockName, QObject *parent) : QObject(parent)
{
m_oBlockName = blockName;
m_iHandle = -1;
m_oMediumType.clear();
m_u32MediumRSupport = 0;
m_u32MediumWSupport = 0;
m_u32TrackNumber = 0;
m_u64UsedCapacity = 0;
m_u64FreeCapacity = 0;
m_u64Capacity = 0;
}
DataCDROM::~DataCDROM()
{
}
void DataCDROM::getCDROMInfo()
{
int ret = 0;
// 0. open device.
if (!open()) {
qWarning()<<"open cdrom device failed";
return;
}
// 1. load support mediu types.
ret = checkRWSupport();
if (ret < 0) {
qWarning()<<"check support type failed";
close();
return;
}
// 2. check have medium or not.
ret = checkMediumType();
if (ret < 0) {
qWarning()<<"check medium type failed";
close();
return;
}
//3、get track num
ret = cdRomGetTrackNum();
if (ret < 0) {
qWarning()<<"get cdrom track num failed";
close();
return;
}
//4、get capacity
cdRomCapacity();
//5、close device
close();
return;
}
bool DataCDROM::open()
{
if (-1 != m_iHandle) {
return true;
}
m_iHandle = ::open(m_oBlockName.toUtf8().constData(), O_NONBLOCK | O_RDONLY);
if (m_iHandle < 0) {
qWarning()<<QString("Open block device %1 faied.").arg(m_oBlockName);
return false;
}
return true;
}
void DataCDROM::close()
{
if (-1 != m_iHandle) {
::close(m_iHandle);
}
m_iHandle = -1;
}
bool DataCDROM::execSCSI(const unsigned char *cdb, const int cdbLength,
unsigned char *result, const int resultLength)
{
sg_io_hdr_t sgio;
if (!open()) {
return false;
}
if (!cdb || !result || resultLength < 1) {
return false;
}
memset(&sgio, 0, sizeof(sg_io_hdr_t));
sgio.interface_id = 'S';
sgio.dxfer_direction = SG_DXFER_FROM_DEV;
sgio.flags = SG_FLAG_LUN_INHIBIT;
sgio.cmdp = (unsigned char *)cdb;
sgio.cmd_len = cdbLength;
sgio.dxferp = result;
sgio.dxfer_len = resultLength;
if (0 != ioctl(m_iHandle, SG_IO, &sgio)) {
qWarning("Do SCSI CDB cmd failed.");
return false;
}
return true;
}
int DataCDROM::checkRWSupport()
{
unsigned short len = 0;
unsigned char cdb[12] = { 0x46, // get configuraion
0x00,
0x00,
0x00, // fearture low
0x00, // reserved
0x00, // reserved
0x00, // reserved
0x00, // allocation length high
0x0C,
0 };
unsigned char result[65536] = {0};
// get header length first.
if (!execSCSI(cdb, 12, result, 12)) {
qWarning()<<"scsi get header length failed.";
return -1;
}
if (!(result[8] == cdb[2] && result[9] == cdb[3])) {
qWarning()<<"scsi check header info failed";
return -1;
}
len = (result[0] << 24) | (result[1] << 16) | (result[2] << 8) | result[3];
cdb[7] = ((len & 0xFF00) >> 8);
cdb[8] = (len & 0x00FF);
// get real result.
if (!execSCSI(cdb, 12, result, len)) {
qWarning()<<"scsi get medium read type support";
return -1;
}
len = result[11];
// loop result, adjust support read medium type.
for (int i = 0; i < len; ++i) {
switch ((result[i + 12] << 8) | result[i + 13]) {
case 0x0008: // CD-ROM
m_u32MediumRSupport |= MEDIUM_CD_ROM;
break;
case 0x0009: // CD-R
m_u32MediumRSupport |= MEDIUM_CD_R;
break;
case 0x000A: // CD-RW
m_u32MediumRSupport |= MEDIUM_CD_RW;
break;
// 000B - 000F reserved.
case 0x0010: // DVD-ROM
m_u32MediumRSupport |= MEDIUM_DVD_ROM;
break;
case 0x0011: // DVD-R
m_u32MediumRSupport |= MEDIUM_DVD_R;
break;
case 0x0012: // DVD-RAM
m_u32MediumRSupport |= MEDIUM_DVD_RAM;
break;
// define in MMC-5
case 0x0013: // DVD-RW
m_u32MediumRSupport |= MEDIUM_DVD_RW_OVERWRITE;
break;
case 0x0014:
m_u32MediumRSupport |= MEDIUM_DVD_RW_SEQ;
break;
case 0x0015:
m_u32MediumRSupport |= MEDIUM_DVD_R_DL_SEQ;
break;
case 0x0016:
m_u32MediumRSupport |= MEDIUM_DVD_R_DL_JUMP;
break;
case 0x001A: // DVD+RW
m_u32MediumRSupport |= MEDIUM_DVD_PLUS_RW;
break;
case 0x001B: //DVD+R
m_u32MediumRSupport |= MEDIUM_DVD_PLUS_R;
break;
case 0x002B:
m_u32MediumRSupport |= MEDIUM_DVD_PLUS_R_DL;
break;
case 0x0002:
// qDebug()<< "Removable CDROM.";
break;
default:
// qDebug()<<"Unkown medium type" << ((result[i + 12] << 8) | result[i + 13]);
break;
}
}
// load write suppport
// CD TAO
cdb[2] = 0x00;
cdb[3] = 0x2D;
cdb[7] = 0x00;
cdb[8] = 0x10;
if (!execSCSI(cdb, 12, result, 16)) {
qWarning()<<"scsi get cd tao write support failed.";
return -1;
}
if (result[8] == cdb[2] && result[9] == cdb[3]) {
m_u32MediumWSupport |= MEDIUM_CD_R;
if (result[12] & 0x02) {
m_u32MediumWSupport |= MEDIUM_CD_RW;
}
}
//CD SAO
cdb[2] = 0x00;
cdb[3] = 0x2E;
cdb[7] = 0x00;
cdb[8] = 0x10;
if (!execSCSI(cdb, 12, result, 16)) {
qWarning()<<"scsi get cd sao write medium support failed";
return -1;
}
if (result[8] == cdb[2] && result[9] == cdb[3]){
m_u32MediumWSupport |= MEDIUM_CD_R;
if (result[12] & 0x02) {
m_u32MediumWSupport |= MEDIUM_CD_RW;
}
}
//DVD
cdb[2] = 0x00;
cdb[3] = 0x1F;
cdb[7] = 0x00;
cdb[8] = 0x10;
if (!execSCSI(cdb, 12, result, 16)) {
qWarning()<<"scsi get DVD-ROM read medium support failed";
return -1;
}
if (result[8] == cdb[2] && result[9] == cdb[3]) {
m_u32MediumRSupport |= MEDIUM_DVD_ROM;
//qDebug("%1 sure support read mode : DVD-ROM");
}
//DVD+RW
cdb[2] = 0x00; cdb[3] = 0x2A; cdb[7] = 0x00; cdb[8] = 0x10;
if (!execSCSI(cdb, 12, result, 16)) {
qWarning()<<"scsi get DVD+RW write medium support failed";
return -1;
}
if (result[8] == cdb[2] && result[9] == cdb[3]){
if (result[12] & 0x01) {
m_u32MediumWSupport |= MEDIUM_DVD_PLUS_RW;
} else {
m_u32MediumWSupport |= MEDIUM_DVD_ROM;
}
}
//DVD+R
cdb[2] = 0x00; cdb[3] = 0x2B; cdb[7] = 0x00; cdb[8] = 0x10;
if (!execSCSI(cdb, 12, result, 16)) {
qWarning()<<"scsi get DVD+R RW medium support failed";
return -1;
}
if (result[8] == cdb[2] && result[9] == cdb[3]) {
m_u32MediumRSupport |= MEDIUM_DVD_PLUS_R;
if (result[12] & 0x01) {
m_u32MediumWSupport |= MEDIUM_DVD_PLUS_R;
}
}
//DVD-R / DVD-RW
cdb[2] = 0x00;
cdb[3] = 0x2F;
cdb[7] = 0x00;
cdb[8] = 0x10;
if (!execSCSI(cdb, 12, result, 16)) {
qWarning()<<"scsi get DVD-R/DVD-RW RW medium type support failed";
return -1;
}
if (result[8] == cdb[2] && result[9] == cdb[3]) {
m_u32MediumRSupport |= MEDIUM_DVD_R;
//qDebug("it sure support read mode : DVD-R");
m_u32MediumWSupport |= MEDIUM_DVD_R;
//qDebug("it support write mode : DVD-R");
m_u32MediumRSupport |= MEDIUM_DVD_RW;
//qDebug("it sure support read mode : DVD-RW");
if (result[12] & 0x02) {
m_u32MediumWSupport |= MEDIUM_DVD_RW;
//qDebug("%1 support write mode : DVD-RW");
}
}
if (m_u32MediumRSupport & ((MEDIUM_DVD_RW_OVERWRITE | MEDIUM_DVD_RW_SEQ))) {
m_u32MediumRSupport |= MEDIUM_DVD_RW;
}
qDebug()<<"m_u32MediumRSupport"<<m_u32MediumRSupport
<<"m_u32MediumWSupport"<<m_u32MediumWSupport;
return 0;
}
int DataCDROM::checkMediumType()
{
unsigned short profile = 0;
unsigned int len = 0;
unsigned char cdb[12] = {0x46, // operation code
0x01, // RT : 0x10b
0x00, // fearture high
0x00, // fearture low
0x00, // reserved
0x00, // reserved
0x00, // reserved
0x00, // allocation length high
0x0C, // allocation length low
0};
unsigned char result[65536] = {0};
m_oMediumType.clear();
if (!execSCSI(cdb, 12, result, 12)) {
qWarning()<<"scsi get medium type failed";
return -1;
}
if (!(result[8] == cdb[2] && result[9] == cdb[3])) {
qWarning()<<"scsi check medium type result failed";
return -1;
}
profile = (result[6] << 8) | result[7];
switch (profile) {
case 0x0008: // CD-ROM
if (m_u32MediumRSupport & MEDIUM_CD_ROM) {
m_oMediumType = "CD-ROM";
break;
}
qWarning("CDROM cannot support to read CD-ROM medium");
break;
case 0x0009: //CD-R
if (m_u32MediumRSupport & MEDIUM_CD_R) {
m_oMediumType = "CD-R";
break;
}
qWarning("CDROM cannot support to read CD-R medium");
break;
case 0x000A: // CD-RW
if (m_u32MediumRSupport & MEDIUM_CD_RW) {
m_oMediumType = "CD-RW";
break;
}
qWarning("CDROM cannot support to read CD-RW medium");
break;
case 0x0010: // DVD-ROM
if (m_u32MediumRSupport & MEDIUM_DVD_ROM) {
m_oMediumType = "DVD-ROM";
break;
}
qWarning("CDROM cannot support to read DVD-ROM medium");
break;
case 0x0011: // DVD-R
if (m_u32MediumRSupport & MEDIUM_DVD_R) {
m_oMediumType = "DVD-R";
break;
}
qWarning("CDROM cannot support to read DVD-R medium");
break;
case 0x0012: // DVD-RAM
if (m_u32MediumRSupport & MEDIUM_DVD_RAM) {
m_oMediumType = "DVD-RAM";
break;
}
qWarning("CDROM cannot support to read DVD-RAM medium");
break;
case 0x0013: // DVD-RW
if (m_u32MediumRSupport & MEDIUM_DVD_RW_OVERWRITE) {
m_oMediumType = "DVD-RW";
break;
}
qWarning("CDROM cannot support to read DVD-RW(OVERWRITE) medium");
break;
case 0x0014: // DVD-RW
if (m_u32MediumRSupport & MEDIUM_DVD_RW_SEQ) {
m_oMediumType = "DVD-RW";
break;
}
qWarning("CDROM cannot support to read DVD-RW medium");
break;
case 0x001A: // DVD+RW
if (m_u32MediumRSupport & MEDIUM_DVD_PLUS_RW) {
m_oMediumType = "DVD+RW";
break;
}
qWarning("CDROM cannot support to read DVD+RW medium");
break;
case 0x001B: // DVD+R
if (m_u32MediumRSupport & MEDIUM_DVD_PLUS_R) {
m_oMediumType = "DVD+R";
break;
}
qWarning("CDROM cannot support to read DVD+R medium");
break;
default:
qWarning()<<"the type" << profile << "undefined";
return -1;
}
qDebug()<<"the medium type "<< m_oMediumType;
return 0;
}
int DataCDROM::cdRomGetTrackNum()
{
unsigned short len = 0;
unsigned char cdb[10] = { 0x51,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x20,
0 };
unsigned char result[32] = { 0 };
if (!execSCSI(cdb, 10, result, 32)) {
qWarning()<<"scsi get cd rom track num failed.";
return -1;
}
len = (result[0] << 8) | result[1];
if ((len - 32) % 8) {
qWarning()<<"scsi get wrong reply from cdrom";
return -1; // len is 32 + 8 * n
}
#if 0
switch (result[2] & 0x03)
{
case 0x00: // empty
m_u8Status = MEDIUM_EMPTY;
//qDebug()<<"empty mediun.";
break;
case 0x01: // incomplete
m_u8Status = MEDIUM_INCOMPLETE;
//qDebug("incomplete mediun.");
break;
case 0x02:
m_u8Status = MEDIUM_FINALIZED;
//qDebug("finalized mediun.");
break;
case 0x03:
m_u8Status = MEDIUM_OTHER;
break;
default:
break;
}
#endif
m_u32TrackNumber = (((result[11] << 8) & 0xFF00) | result[6]);
return 0;
}
/*
*dvd+rw-mediainfo的实现代码scsi获取DVD+RW/DVD-RW的
*
*/
void DataCDROM::DVDRWCapacity()
{
int index = 0;
QProcess process;
QStringList deviceName;
deviceName<<m_oBlockName;
process.start("dvd+rw-mediainfo", deviceName);
process.waitForFinished(10000);
QString result = process.readAllStandardOutput();
QStringList dvdInfo = result.split("\n");
for (index = dvdInfo.size() - 1; index > 0; --index){
if (dvdInfo.at(index).startsWith("READ FORMAT CAPACITIES:")) {
QStringList formatCapacity = dvdInfo.takeAt(index + 1).split("=");
qWarning()<<"format capacity is"<<formatCapacity.last();
if (m_oMediumType.contains("DVD+RW")) {
m_u64Capacity = formatCapacity.last().toULong();
}
}
if (dvdInfo.at(index).startsWith("READ CAPACITY:")) {
QStringList readCapacity = dvdInfo.takeAt(index).split("=");
qWarning()<<"DVD RW read capacity is "<<readCapacity.last();
}
if (dvdInfo.at(index).startsWith("READ DVD STRUCTURE")) {
QStringList dvdStruct = dvdInfo.takeAt(index + 2).split("=");
qWarning()<<"DVD RW struct capacity is"<<dvdStruct.last();
if (m_oMediumType.contains("DVD-RW")) {
m_u64Capacity += dvdStruct.last().toULong();
}
}
}
return;
}
void DataCDROM::cdRomCapacity()
{
unsigned char cdb[10] = { 0x52,
0x01,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x28,
0 };
unsigned char result[40] = { 0 }; // 256 + 12
// qWarning()<<"medium type"<<m_oMediumType;
if (!m_oMediumType.isEmpty()
&& (m_oMediumType.contains("DVD+RW") || m_oMediumType.contains("DVD-RW")))
{
DVDRWCapacity();
qWarning()<<"DVD+RW/DVD-RW get capacity";
return;
}
cdb[2] = (m_u32TrackNumber >> 24);
cdb[3] = (m_u32TrackNumber >> 16);
cdb[4] = (m_u32TrackNumber >> 8);
cdb[5] = m_u32TrackNumber;
if (!execSCSI(cdb, 10, result, 40)) {
qWarning()<<"scsi get cd rom capacity failed.";
return;
}
m_u64UsedCapacity = ((result[8] << 24) | (result[9] << 16) | (result[10] << 8) | result[11]);
m_u64UsedCapacity *= 2048;
m_u64FreeCapacity = ((result[16] << 24) | (result[17] << 16) | (result[18] << 8) | result[19]);
m_u64FreeCapacity *= 2048;
m_u64Capacity = m_u64UsedCapacity + m_u64FreeCapacity;
qDebug()<<"total capacity:"<<m_u64Capacity
<< "used capacity:"<<m_u64UsedCapacity
<< "free capacity:"<<m_u64FreeCapacity;
return;
}

114
src/datacdrom.h Normal file
View File

@ -0,0 +1,114 @@
/*
* Peony-Qt's Library
*
* Copyright (C) 2020, KylinSoft Co., Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library. If not, see <https://www.gnu.org/licenses/>.
*
* Authors: renpeijia <renpeijia@kylinos.cn>
*
*/
#ifndef DATACDROM_H
#define DATACDROM_H
#include <QObject>
#include <QIcon>
#include <QProcess>
enum MEDIUM_TYPE
{
MEDIUM_UNKOWN = 0x0000,
MEDIUM_CD_ROM = 0x0001,
MEDIUM_CD_R = 0x0002,
MEDIUM_CD_RW = 0x0004,
MEDIUM_DVD_ROM = 0x0008,
MEDIUM_DVD_R = 0x0010,
MEDIUM_DVD_RAM = 0x0020,
MEDIUM_DVD_R_DL_SEQ = 0x0040,
MEDIUM_DVD_R_DL_JUMP = 0x0080,
MEDIUM_DVD_PLUS_RW = 0x0100,
MEDIUM_DVD_PLUS_R = 0x0101,
MEDIUM_DVD_PLUS_RW_DL = 0x0102,
MEDIUM_DVD_PLUS_R_DL = 0x0104,
MEDIUM_DVD_RW_OVERWRITE = 0x0108,
MEDIUM_DVD_RW_SEQ = 0x0110,
MEDIUM_CD_RW_S0 = 0x0120, // in MMC-5 CD-RW has 8 subtypes.
MEDIUM_CD_RW_S1 = 0x0140,
MEDIUM_CD_RW_S2 = 0x0180,
MEDIUM_CD_RW_S3 = 0x0200,
MEDIUM_CD_RW_S4 = 0x0201,
MEDIUM_CD_RW_S5 = 0x0202,
MEDIUM_CD_RW_S6 = 0x0204,
MEDIUM_CD_RW_S7 = 0x0208,
MEDIUM_DVD_RW = 0x0210
};
enum MEDIUM_STATUS
{
MEDIUM_EMPTY = 0,
MEDIUM_INCOMPLETE,
MEDIUM_FINALIZED,
MEDIUM_OTHER
};
enum BURN_MODE
{
BURN_CD_TAO = 0x01,
BURN_CD_SAO = 0x02,
BURN_CD_DAO = 0x04 // close session/track when TAO over.
};
class DataCDROM : public QObject
{
Q_OBJECT
public:
explicit DataCDROM(QString &blockName, QObject *parent = nullptr);
~DataCDROM();
public:
void getCDROMInfo();
unsigned long getCDROMCapacity() {
return m_u64Capacity;
}
unsigned long getCDROMUsedCapacity() {
return m_u64UsedCapacity;
}
private:
bool open();
void close();
bool execSCSI(const unsigned char *, const int, unsigned char *, const int);
int checkRWSupport();
int checkMediumType();
int cdRomGetTrackNum();
void DVDRWCapacity();
void cdRomCapacity();
private:
int m_iHandle;
unsigned int m_u32MediumRSupport;
unsigned int m_u32MediumWSupport;
QString m_oBlockName;
QString m_oMediumType;
unsigned int m_u32TrackNumber;
unsigned long m_u64UsedCapacity;
unsigned long m_u64FreeCapacity;
unsigned long m_u64Capacity;
};
#endif // DATACDROM_H

69
src/device-manager.cpp Normal file
View File

@ -0,0 +1,69 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Ding Jing dingjing@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "device-manager.h"
DeviceManager* DeviceManager::gInstance = new DeviceManager;
const DeviceManager* DeviceManager::getInstance()
{
return gInstance;
}
DeviceManager::DeviceManager(QObject *parent) : QObject(parent)
{
mGvolumeMonitor = g_volume_monitor_get();
g_signal_connect(mGvolumeMonitor, "drive-connected", G_CALLBACK(drive_connected_callback), this);
g_signal_connect(mGvolumeMonitor, "drive-disconnected", G_CALLBACK(drive_disconnected_callback), this);
}
DeviceManager::~DeviceManager()
{
if (mGvolumeMonitor) g_object_unref(mGvolumeMonitor);
}
void DeviceManager::drive_connected_callback(GVolumeMonitor *monitor, GDrive *drive, gpointer pThis)
{
g_return_if_fail(drive);
g_return_if_fail(pThis);
DeviceManager* dm = static_cast<DeviceManager*>(pThis);
Q_UNUSED(dm);
Q_UNUSED(monitor);
}
void DeviceManager::drive_disconnected_callback(GVolumeMonitor* monitor, GDrive* drive, gpointer pThis)
{
g_return_if_fail(drive);
g_return_if_fail(pThis);
#if 0
DeviceManager* dm = static_cast<DeviceManager*>(pThis);
g_autofree gchar* devName = g_drive_get_identifier(drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE);
if (nullptr != devName) {
Q_EMIT dm->driveDisconnected(devName);
}
#endif
Q_UNUSED(monitor);
}

52
src/device-manager.h Normal file
View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Ding Jing dingjing@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef DEVICEMANAGER_H
#define DEVICEMANAGER_H
#include <gio/gio.h>
#include <QMap>
#include <QObject>
class DeviceManager : public QObject
{
Q_OBJECT
public:
static const DeviceManager* getInstance();
private:
explicit DeviceManager(QObject* parent = nullptr);
~DeviceManager();
static void drive_connected_callback(GVolumeMonitor* monitor, GDrive* drive, gpointer pThis);
static void drive_disconnected_callback(GVolumeMonitor* monitor, GDrive* drive, gpointer pThis);
Q_SIGNALS:
void driveDisconnected(QString drive);
private:
static DeviceManager* gInstance;
GVolumeMonitor* mGvolumeMonitor = nullptr;
QMap<gpointer, QString> mDevice;
};
#endif // DEVICEMANAGER_H

326
src/device-operation.cpp Normal file
View File

@ -0,0 +1,326 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Ding Jing dingjing@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "device-operation.h"
#include <sys/stat.h>
static void formatCB (GObject* sourceObject, GAsyncResult* res, gpointer udata);
static void repairCB (GObject* sourceObject, GAsyncResult* res, gpointer udata);
DeviceOperation::DeviceOperation(GDrive *drive, QObject *parent) : QObject(parent)
{
g_return_if_fail(drive);
g_autofree char* devName = g_drive_get_identifier(drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE);
g_return_if_fail(devName);
g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL);
g_return_if_fail(client);
g_autoptr(UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName);
g_return_if_fail(udiskObj);
mDiskBlock = udisks_object_get_block(udiskObj);
mDiskManager = udisks_object_get_manager(udiskObj);
mDiskFilesystem = udisks_object_get_filesystem(udiskObj);
}
DeviceOperation::DeviceOperation(GVolume* volume, QObject *parent) : QObject(parent)
{
g_return_if_fail(volume);
g_autofree char* devName = g_volume_get_identifier(volume, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE);
g_return_if_fail(devName);
g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL);
g_return_if_fail(client);
g_autoptr(UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName);
g_return_if_fail(udiskObj);
mDiskBlock = udisks_object_get_block(udiskObj);
mDiskManager = udisks_object_get_manager(udiskObj);
mDiskFilesystem = udisks_object_get_filesystem(udiskObj);
}
DeviceOperation::~DeviceOperation()
{
g_clear_object(&mDiskBlock);
g_clear_object(&mDiskManager);
g_clear_object(&mDiskFilesystem);
}
bool DeviceOperation::repairFilesystem(GDrive *drive)
{
gboolean ret = FALSE;
g_return_val_if_fail(drive, ret);
g_autofree char* devName = g_drive_get_identifier (drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE);
g_return_val_if_fail(devName, ret);
g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL);
g_return_val_if_fail(client, ret);
g_autoptr (UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName);
g_return_val_if_fail(udiskObj, ret);
g_autoptr (UDisksFilesystem) diskFilesystem = udisks_object_get_filesystem(udiskObj);
GVariantBuilder optionsBuilder;
g_variant_builder_init(&optionsBuilder, G_VARIANT_TYPE_VARDICT);
udisks_filesystem_call_repair_sync(diskFilesystem, g_variant_builder_end(&optionsBuilder), &ret, nullptr, nullptr);
return ret;
}
bool DeviceOperation::repairFilesystem(GVolume *volume)
{
gboolean ret = FALSE;
g_return_val_if_fail(volume, ret);
g_autofree char* devName = g_volume_get_identifier (volume, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE);
g_return_val_if_fail(devName, ret);
g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL);
g_return_val_if_fail(client, ret);
g_autoptr (UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName);
g_return_val_if_fail(udiskObj, ret);
g_autoptr (UDisksFilesystem) diskFilesystem = udisks_object_get_filesystem(udiskObj);
GVariantBuilder optionsBuilder;
g_variant_builder_init(&optionsBuilder, G_VARIANT_TYPE_VARDICT);
udisks_filesystem_call_repair_sync(diskFilesystem, g_variant_builder_end(&optionsBuilder), &ret, nullptr, nullptr);
return ret;
}
gint64 DeviceOperation::getDriveSize(GDrive *drive)
{
gint64 ret = 0;
g_return_val_if_fail(drive, ret);
g_autofree char* devName = g_drive_get_identifier (drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE);
g_return_val_if_fail(devName, ret);
g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL);
g_return_val_if_fail(client, ret);
g_autoptr (UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName);
g_return_val_if_fail(udiskObj, ret);
g_autoptr (UDisksBlock) diskBlock = udisks_object_get_block (udiskObj);
return udisks_block_get_size(diskBlock);
}
gchar *DeviceOperation::getDriveLabel(GDrive *drive)
{
gchar* ret = NULL;
g_return_val_if_fail(drive, ret);
g_autofree char* devName = g_drive_get_identifier (drive, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE);
g_return_val_if_fail(devName, ret);
ret = g_strdup (devName);
g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL);
g_return_val_if_fail(client, ret);
g_autoptr (UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName);
g_return_val_if_fail(udiskObj, ret);
g_autoptr (UDisksBlock) diskBlock = udisks_object_get_block (udiskObj);
g_return_val_if_fail(udiskObj, ret);
// cannot free
const gchar* label = udisks_block_get_id_label (diskBlock);
if (label && 0 != g_strcmp0 (label, "") && 0 != g_strcmp0 (label, " ")) { if (ret) g_free(ret); ret = g_strdup (label);};
return ret;
}
gchar *DeviceOperation::getDriveLabel(GVolume *volume)
{
gchar* ret = NULL;
g_return_val_if_fail(volume, ret);
g_autofree char* devName = g_volume_get_identifier (volume, G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE);
g_return_val_if_fail(devName, ret);
ret = g_strdup (devName);
g_autoptr(UDisksClient) client = udisks_client_new_sync(NULL, NULL);
g_return_val_if_fail(client, ret);
g_autoptr (UDisksObject) udiskObj = getObjectFromBlockDevice(client, devName);
g_return_val_if_fail(udiskObj, ret);
g_autoptr (UDisksBlock) diskBlock = udisks_object_get_block (udiskObj);
g_return_val_if_fail(udiskObj, ret);
// cannot free
const gchar* label = udisks_block_get_id_label (diskBlock);
if (label && 0 != g_strcmp0 (label, "") && 0 != g_strcmp0 (label, " ")) { if (ret) g_free(ret); ret = g_strdup (label);};
return ret;
}
void DeviceOperation::udiskFormat(QString type, QString labelName)
{
if (!mDiskBlock) {
Q_EMIT formatFinished(false);
return;
}
GVariantBuilder optionsBuilder;
g_variant_builder_init(&optionsBuilder, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add (&optionsBuilder, "{sv}", "label", g_variant_new_string (labelName.toUtf8().constData()));
g_variant_builder_add (&optionsBuilder, "{sv}", "take-ownership", g_variant_new_boolean (TRUE));
g_variant_builder_add (&optionsBuilder, "{sv}", "update-partition-type", g_variant_new_boolean (TRUE));
// g_cancellable_reset(&mFormatCancel);
udisks_block_call_format(mDiskBlock, type.toLower().toUtf8().constData(), g_variant_builder_end(&optionsBuilder), nullptr /*&mFormatCancel*/, GAsyncReadyCallback(formatCB), this);
}
void DeviceOperation::udiskRepair()
{
if (!mDiskFilesystem) {
Q_EMIT repairFinished(false);
return;
}
GVariantBuilder optionsBuilder;
g_variant_builder_init(&optionsBuilder, G_VARIANT_TYPE_VARDICT);
// g_cancellable_reset(&mRepairCancel);
udisks_filesystem_call_repair(mDiskFilesystem, g_variant_builder_end(&optionsBuilder), nullptr /*&mRepairCancel*/, GAsyncReadyCallback(repairCB), this);
}
void DeviceOperation::udiskFormatCancel()
{
// if (g_cancellable_is_cancelled(&mFormatCancel)) {
// g_cancellable_cancel(&mFormatCancel);
// }
}
void DeviceOperation::udiskRepairCancel()
{
// if (g_cancellable_is_cancelled(&mRepairCancel)) {
// g_cancellable_cancel(&mRepairCancel);
// }
}
QString DeviceOperation::udiskSize()
{
g_return_val_if_fail(mDiskBlock, tr("unknown"));
guint64 size = udisks_block_get_size(mDiskBlock);
g_autofree char* str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS);
return str;
}
QString DeviceOperation::udiskUUID()
{
g_return_val_if_fail(mDiskBlock, tr("unknown"));
const char* str = udisks_block_get_id_uuid(mDiskBlock);
return str;
}
QString DeviceOperation::udiskLabel()
{
g_return_val_if_fail(mDiskBlock, tr("unknown"));
const char* str = udisks_block_get_id_label(mDiskBlock);
return str;
}
UDisksObject* DeviceOperation::getObjectFromBlockDevice(UDisksClient* client, const gchar* bdevice)
{
struct stat statbuf;
UDisksObject* object = NULL;
UDisksObject* cryptoBackingObject = NULL;
g_autofree const gchar* cryptoBackingDevice = NULL;
g_return_val_if_fail(stat(bdevice, &statbuf) == 0, object);
// cannot free
UDisksBlock* block = udisks_client_get_block_for_dev (client, statbuf.st_rdev);
g_return_val_if_fail(block != NULL, object);
object = UDISKS_OBJECT (g_dbus_interface_dup_object (G_DBUS_INTERFACE (block)));
cryptoBackingDevice = udisks_block_get_crypto_backing_device ((udisks_object_peek_block (object)));
cryptoBackingObject = udisks_client_get_object (client, cryptoBackingDevice);
if (cryptoBackingObject != NULL) {
g_object_unref (object);
object = cryptoBackingObject;
}
return object;
}
static void formatCB (GObject* sourceObject, GAsyncResult* res, gpointer udata)
{
bool ret = true;
GError* error = NULL;
DeviceOperation* pThis = static_cast<DeviceOperation*>(udata);
if (!udisks_block_call_format_finish (UDISKS_BLOCK(sourceObject), res, &error)) {
if (NULL != error && NULL != strstr(error->message, "wipefs:")) {
g_clear_error(&error);
}
ret = false;
}
Q_EMIT pThis->formatFinished(ret);
}
static void repairCB (GObject* sourceObject, GAsyncResult* res, gpointer udata)
{
GError* error = NULL;
gboolean outRet = FALSE;
DeviceOperation* pThis = static_cast<DeviceOperation*>(udata);
if (!udisks_filesystem_call_repair_finish(UDISKS_FILESYSTEM(sourceObject), &outRet, res, &error)) {
g_clear_error(&error);
}
Q_EMIT pThis->repairFinished(outRet);
}

73
src/device-operation.h Normal file
View File

@ -0,0 +1,73 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Ding Jing dingjing@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef DEVICEOPERATION_H
#define DEVICEOPERATION_H
#include <QObject>
#include <gio/gio.h>
#include <udisks/udisks.h>
class DeviceOperation : public QObject
{
Q_OBJECT
public:
explicit DeviceOperation(GDrive* drive, QObject *parent = nullptr);
explicit DeviceOperation(GVolume* volume, QObject *parent = nullptr);
~DeviceOperation();
static bool repairFilesystem(GDrive* drive);
static bool repairFilesystem(GVolume* volume);
static gint64 getDriveSize(GDrive* drive);
static gchar* getDriveLabel(GDrive* drive);
static gchar* getDriveLabel(GVolume* volume);
public Q_SLOTS:
void udiskFormat(QString type, QString labelName);
void udiskRepair();
void udiskFormatCancel();
void udiskRepairCancel();
QString udiskSize();
QString udiskUUID();
QString udiskLabel();
private:
static UDisksObject* getObjectFromBlockDevice(UDisksClient *client, const gchar *bdevice);
Q_SIGNALS:
void repairFinished(bool);
void formatFinished(bool);
private:
UDisksBlock* mDiskBlock = NULL;
UDisksManager* mDiskManager = NULL;
UDisksFilesystem* mDiskFilesystem = NULL;
GCancellable mRepairCancel;
GCancellable mFormatCancel;
};
#endif // DEVICEOPERATION_H

284
src/ejectInterface.cpp Normal file
View File

@ -0,0 +1,284 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "ejectInterface.h"
#include <qgsettings.h>
#include <KWindowEffects>
#include "flashdiskdata.h"
ejectInterface::ejectInterface(QWidget *parent,QString mount_name,int deviceType,QString strDevId) : QWidget(parent),eject_image_label(nullptr),show_text_label(nullptr),
mount_name_label(nullptr)
{
initFontSetting();
getFontSize();
//interface layout
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
EjectScreen = qApp->primaryScreen();
eject_image_label = new QLabel(this);
eject_image_label->setFixedSize(24,24);
//QPixmap pixmap("kylin-media-removable-symbolic");
QString strNoraml = "";
QString strIcon = FlashDiskData::getInstance()->getVolumeIcon(strDevId);
eject_image_icon = QIcon::fromTheme(strIcon);
strNoraml = mount_name;
if (eject_image_icon.isNull()) {
eject_image_icon = QIcon::fromTheme("kylin-media-removable-symbolic");
}
QPixmap pixmap = eject_image_icon.pixmap(QSize(24, 24));
eject_image_label->setPixmap(pixmap);
//add it to show the eject button
show_text_label = new QLabel(this);
show_text_label->setFixedSize(192, 36);
show_text_label->setFont(QFont("Noto Sans CJK SC",fontSize));
show_text_label->setAlignment(Qt::AlignHCenter);
QString normalShow = getElidedText(show_text_label->font(),strNoraml,192);
//add the text of the eject interface
show_text_label->setText(normalShow);
if (strNoraml != normalShow) {
show_text_label->setToolTip(strNoraml);
}
ejectinterface_h_BoxLayout = new QHBoxLayout();
ejectinterface_h_BoxLayout->setContentsMargins(0,0,0,0);
ejectinterface_h_BoxLayout->setSpacing(8);
ejectinterface_h_BoxLayout->addWidget(eject_image_label,0,Qt::AlignLeft|Qt::AlignTop);
ejectinterface_h_BoxLayout->addWidget(show_text_label,0,Qt::AlignHCenter|Qt::AlignTop);
QHBoxLayout *ejectTipLayout = new QHBoxLayout();
ejectTipLayout->setContentsMargins(0,0,0,0);
ejectTipLayout->setSpacing(0);
QLabel *ejectTip = new QLabel();
ejectTip->setText(tr("Storage device can be safely unplugged"));
ejectTip->setAlignment(Qt::AlignHCenter|Qt::AlignTop);
ejectTip->setWordWrap(true);
ejectTipLayout->addWidget(ejectTip,0,Qt::AlignHCenter|Qt::AlignTop);
main_V_BoxLayput = new QVBoxLayout;
main_V_BoxLayput->setContentsMargins(8,8,8,8);
main_V_BoxLayput->setSpacing(0);
main_V_BoxLayput->addLayout(ejectinterface_h_BoxLayout);
main_V_BoxLayput->addLayout(ejectTipLayout);
main_V_BoxLayput->addStretch();
QString strTipShow = getElidedText(ejectTip->font(),ejectTip->text(),224);
if (strTipShow != ejectTip->text()) {
this->setFixedSize(240,120);
} else {
this->setFixedSize(240,90);
}
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
this->setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明
this->setAttribute(Qt::WA_DeleteOnClose); //设置窗口关闭时自动销毁
this->setLayout(main_V_BoxLayput);
//set the main signal-slot function to complete the eject interface to let it disappear automatically
interfaceHideTime = new QTimer(this);
interfaceHideTime->setTimerType(Qt::PreciseTimer);
connect(interfaceHideTime, SIGNAL(timeout()), this, SLOT(on_interface_hide()));
interfaceHideTime->start(1000);
moveEjectInterfaceRight();
initTransparentState();
this->getTransparentData();
}
ejectInterface::~ejectInterface()
{
if (m_transparency_gsettings) {
delete m_transparency_gsettings;
m_transparency_gsettings = nullptr;
}
if (fontSettings) {
delete fontSettings;
fontSettings = nullptr;
}
}
//If the fillet does not take effect
void ejectInterface::paintEvent(QPaintEvent *event)
{
QPainterPath path;
auto rect = this->rect();
rect.adjust(1, 1, -1, -1);
path.addRoundedRect(rect, 6, 6);
setProperty("blurRegion", QRegion(path.toFillPolygon().toPolygon()));
QStyleOption opt;
opt.init(this);
QPainter p(this);
QRect rectReal = this->rect();
p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
p.setBrush(opt.palette.color(QPalette::Base));
p.setOpacity(m_transparency);
p.setPen(Qt::NoPen);
p.drawRoundedRect(rectReal, 6, 6);
QWidget::paintEvent(event);
KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon()));
}
//slot function to hide eject interface
void ejectInterface::on_interface_hide()
{
this->hide();
this->deleteLater();
}
//set the location of the eject interface
void ejectInterface::moveEjectInterfaceRight()
{
// if(EjectScreen->availableGeometry().x() == EjectScreen->availableGeometry().y() && EjectScreen->availableSize().height() < EjectScreen->size().height())
// {
// qDebug()<<"the position of panel is down";
// this->move(EjectScreen->availableGeometry().x() + EjectScreen->size().width() -
// this->width() - DistanceToPanel,EjectScreen->availableGeometry().y() +
// EjectScreen->availableSize().height() - this->height() - DistanceToPanel);
// }
// if(EjectScreen->availableGeometry().x() < EjectScreen->availableGeometry().y() && EjectScreen->availableSize().height() < EjectScreen->size().height())
// {
// qDebug()<<"this position of panel is up";
// this->move(EjectScreen->availableGeometry().x() + EjectScreen->size().width() -
// this->width() - DistanceToPanel,EjectScreen->availableGeometry().y());
// }
// if(EjectScreen->availableGeometry().x() > EjectScreen->availableGeometry().y() && EjectScreen->availableSize().width() < EjectScreen->size().width())
// {
// qDebug()<<"this position of panel is left";
// this->move(EjectScreen->availableGeometry().x() + DistanceToPanel,EjectScreen->availableGeometry().y()
// + EjectScreen->availableSize().height() - this->height());
// }
// if(EjectScreen->availableGeometry().x() == EjectScreen->availableGeometry().y() && EjectScreen->availableSize().width() < EjectScreen->size().width())
// {
// qDebug()<<"this position of panel is right";
// this->move(EjectScreen->availableGeometry().x() + EjectScreen->availableSize().width() -
// DistanceToPanel - this->width(),EjectScreen->availableGeometry().y() +
// EjectScreen->availableSize().height() - (this->height())*(DistanceToPanel - 1));
// }
//show the ejectinterface by primaryscreen()
int position=0;
int panelSize=0;
if(QGSettings::isSchemaInstalled(QString("org.ukui.panel.settings").toLocal8Bit()))
{
QGSettings* gsetting=new QGSettings(QString("org.ukui.panel.settings").toLocal8Bit());
if(gsetting->keys().contains(QString("panelposition")))
position=gsetting->get("panelposition").toInt();
else
position=0;
if(gsetting->keys().contains(QString("panelsize")))
panelSize=gsetting->get("panelsize").toInt();
else
panelSize=SmallPanelSize;
}
else
{
position=0;
panelSize=SmallPanelSize;
}
int x=QApplication::primaryScreen()->geometry().x();
int y=QApplication::primaryScreen()->geometry().y();
if(position==0)
this->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-this->width(),y+QApplication::primaryScreen()->geometry().height()-panelSize-this->height(),this->width(),this->height()));
else if(position==1)
this->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-this->width(),y+panelSize,this->width(),this->height())); // Style::minw,Style::minh the width and the height of the interface which you want to show
else if(position==2)
this->setGeometry(QRect(x+panelSize,y + QApplication::primaryScreen()->geometry().height() - this->height(),this->width(),this->height()));
else
this->setGeometry(QRect(x+QApplication::primaryScreen()->geometry().width()-panelSize-this->width(),y + QApplication::primaryScreen()->geometry().height() - this->height(),this->width(),this->height()));
}
int ejectInterface::getPanelPosition(QString str)
{
QDBusInterface interface( "com.ukui.panel.desktop",
"/",
"com.ukui.panel.desktop",
QDBusConnection::sessionBus() );
QDBusReply<int> reply = interface.call("GetPanelPosition", str);
return reply;
}
/*
use the dbus to get the height of the panel
*/
int ejectInterface::getPanelHeight(QString str)
{
QDBusInterface interface( "com.ukui.panel.desktop",
"/",
"com.ukui.panel.desktop",
QDBusConnection::sessionBus() );
QDBusReply<int> reply = interface.call("GetPanelSize", str);
return reply;
}
void ejectInterface::initTransparentState()
{
const QByteArray idtrans(THEME_QT_TRANS);
if(QGSettings::isSchemaInstalled(idtrans))
{
m_transparency_gsettings = new QGSettings(idtrans);
}
}
void ejectInterface::getTransparentData()
{
if (!m_transparency_gsettings)
{
m_transparency = 0.95;
return;
}
QStringList keys = m_transparency_gsettings->keys();
if (keys.contains("transparency"))
{
m_transparency = m_transparency_gsettings->get("transparency").toDouble();
}
}
void ejectInterface::initFontSetting()
{
const QByteArray id(THEME_QT_SCHEMA);
if(QGSettings::isSchemaInstalled(id))
{
fontSettings = new QGSettings(id);
}
}
void ejectInterface::getFontSize()
{
if (!fontSettings)
{
fontSize = 11;
return;
}
QStringList keys = fontSettings->keys();
if (keys.contains("systemFont") || keys.contains("systemFontSize"))
{
fontSize = fontSettings->get("system-font").toInt();
}
}

89
src/ejectInterface.h Normal file
View File

@ -0,0 +1,89 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef EJECTINTERFACE_H
#define EJECTINTERFACE_H
#include <QWidget>
#include <QtWidgets>
#include <QLabel>
#include <QBoxLayout>
#include <QIcon>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QStyle>
#include <QStyleOption>
#include <QPainter>
#include <QPainterPath>
#include <QTimer>
#include <QApplication>
#include <QScreen>
#include <QDebug>
#include <QPushButton>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusObjectPath>
#include <QDBusReply>
#include <qgsettings.h>
#include "MacroFile.h"
#include "UnionVariable.h"
QT_BEGIN_NAMESPACE
namespace Ui { class ejectInterface; }
QT_END_NAMESPACE
class ejectInterface : public QWidget
{
Q_OBJECT
public:
ejectInterface(QWidget *parent,QString name,int typeDevice,QString strDevId);
~ejectInterface();
int getPanelPosition(QString str);
int getPanelHeight(QString str);
void initTransparentState();
void getTransparentData();
void initFontSetting();
void getFontSize();
private:
QLabel *eject_image_label;
QIcon eject_image_icon;
QLabel *show_text_label;
QLabel *mount_name_label;
QHBoxLayout *ejectinterface_h_BoxLayout;
QHBoxLayout *mountname_h_BoxLayout;
QVBoxLayout *main_V_BoxLayput;
QTimer *interfaceHideTime;
QScreen *EjectScreen;
double m_transparency;
int fontSize;
QGSettings *m_transparency_gsettings = nullptr;
QGSettings *fontSettings = nullptr;
private Q_SLOTS:
void on_interface_hide();
protected:
void paintEvent(QPaintEvent *event);
private:
void moveEjectInterfaceRight();
};
#endif

45
src/fdapplication.cpp Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Yang Min yangmin@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "fdapplication.h"
FDApplication::FDApplication(int &argc, char **argv)
: QtSingleApplication(argc, argv)
{
}
FDApplication::FDApplication(const QString &id, int &argc, char **argv)
: QtSingleApplication(id, argc, argv)
{
}
FDApplication::~FDApplication()
{
}
bool FDApplication::notify(QObject* obj, QEvent *event)
{
Q_EMIT notifyWnd(obj, event);
return QtSingleApplication::notify(obj, event);
}

44
src/fdapplication.h Normal file
View File

@ -0,0 +1,44 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Yang Min yangmin@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __FDAPPLICATION_H__
#define __FDAPPLICATION_H__
#include "QtSingleApplication/qtsingleapplication.h"
#include <QApplication>
#include <QDebug>
class FDApplication : public QtSingleApplication
{
Q_OBJECT
public:
FDApplication(int &argc, char **argv);
FDApplication(const QString &id, int &argc, char **argv);
virtual ~FDApplication();
bool notify(QObject* obj, QEvent *event);
Q_SIGNALS:
void notifyWnd(QObject* obj, QEvent *event);
};
#endif // __FDAPPLICATION_H__

552
src/fdclickwidget.cpp Normal file
View File

@ -0,0 +1,552 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Yang Min yangmin@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "fdclickwidget.h"
#include "MacroFile.h"
#include <KWindowEffects>
#include <QFontMetrics>
#include "flashdiskdata.h"
#include "UnionVariable.h"
#include <QDebug>
FDClickWidget::FDClickWidget(FDFrame *parent,
unsigned diskNo,
QString strDriveId,
QString strVolumeId,
QString strMountId,
QString driveName,
QString volumeName,
quint64 capacityDis,
QString strMountUri)
: m_frame(parent),
m_uDiskNo(diskNo),
m_driveName(driveName),
m_volumeName(volumeName),
m_capacityDis(capacityDis),
m_mountUri(strMountUri),
m_driveId(strDriveId),
m_volumeId(strVolumeId),
m_mountId(strMountId)
{
//union layout
/*
* it's the to set the title interface,we get the drive name and add picture of a u disk
*/
const QByteArray id(THEME_QT_SCHEMA);
if(QGSettings::isSchemaInstalled(id))
{
fontSettings = new QGSettings(id);
}
const QByteArray idd(THEME_QT_SCHEMA);
if(QGSettings::isSchemaInstalled(idd))
{
qtSettings = new QGSettings(idd);
}
initFontSize();
initThemeMode();
m_hideTime = new QTimer(this);
QHBoxLayout *drivename_H_BoxLayout = new QHBoxLayout();
if (m_uDiskNo <= 1) {
image_show_label = new QLabel(this);
image_show_label->setFocusPolicy(Qt::NoFocus);
image_show_label->installEventFilter(this);
//to get theme picture for label
#if IFDISTINCT_DEVICON
// QString strDevId = m_driveId.isEmpty()?m_volumeId:m_driveId;
// QString strIcon = FlashDiskData::getInstance()->getVolumeIcon(strDevId);
// imgIcon = QIcon::fromTheme(strIcon);
imgIcon = QIcon::fromTheme("drive-removable-media-usb-symbolic");
if (imgIcon.isNull()) {
imgIcon = QIcon::fromTheme("media-removable-symbolic");
}
#else
imgIcon = QIcon::fromTheme("media-removable-symbolic");
#endif
QPixmap pixmap = imgIcon.pixmap(QSize(18, 18));
image_show_label->setPixmap(pixmap);
image_show_label->setProperty("useIconHighlightEffect", 0x2);
image_show_label->setFixedSize(30,30);
image_show_label->move(26,27);
m_driveName_label = new QLabel(this);
m_driveName_label->setFont(QFont("Noto Sans CJK SC",fontSize));
QString DriveName = getElidedText(m_driveName_label->font(), m_driveName, 180);
m_driveName_label->setText(DriveName);
if (DriveName != m_driveName) {
m_driveName_label->setToolTip(m_driveName);
}
m_driveName_label->setStyleSheet("QLabel{color: palette(Text);}");
m_driveName_label->setFixedSize(180,20);
m_driveName_label->setObjectName("driveNameLabel");
m_eject_button = new ClickLabel(this);
m_eject_button->setProperty("useIconHighlightEffect", 0x2);
m_eject_button->setProperty("useButtonPalette", true);
//m_eject_button->setFlat(true); //this property set that when the mouse is hovering in the icon the icon will move up a litte
m_eject_button->move(m_eject_button->x()+320,m_eject_button->y()+10);
m_eject_button->installEventFilter(this);
//m_eject_button->setPixmap(QIcon::fromTheme("media-eject-symbolic").pixmap(16,16)); //setIcon(QIcon::fromTheme("media-eject-symbolic"));
m_eject_button->setFixedSize(60,100);
m_eject_button->setParent(this);
m_eject_button->setToolTip(tr("Eject"));
m_eject_button->show();
connect(m_eject_button,SIGNAL(clicked()),SLOT(switchWidgetClicked())); // this signal-slot function is to emit a signal which
//is to trigger a slot in mainwindow
drivename_H_BoxLayout->setContentsMargins(0,0,0,0);
drivename_H_BoxLayout->addSpacing(45);
//drivename_H_BoxLayout->addWidget(image_show_label);
drivename_H_BoxLayout->addWidget(m_driveName_label);
drivename_H_BoxLayout->addStretch();
}
disWidgetNumOne = new QWidget(this);
disWidgetNumOne->setFixedSize(288,20);
//disWidgetNumOne->setStyleSheet("border:1px solid red;");//for test
m_nameDis1_label = new ClickLabel(disWidgetNumOne);
m_nameDis1_label->setFont(QFont("Microsoft YaHei",fontSize-2));
m_nameDis1_label->setFixedSize(200,20);
handleVolumeLabelForFat32Me(m_volumeName, m_volumeId);
QString VolumeName = getElidedText(m_nameDis1_label->font(), m_volumeName, 120); //超出一定宽度后显示省略号
m_nameDis1_label->adjustSize(); //根据内容自动调整控件大小
m_nameDis1_label->setText("- "+VolumeName+":");
if (m_volumeName != VolumeName) {
m_nameDis1_label->setToolTip(m_volumeName);
}
m_capacityDis1_label = new QLabel();
QString str_capacityDis1 = size_human(m_capacityDis); //将容量转换为XXGB形式
m_capacityDis1_label->setFont(QFont("Microsoft YaHei",fontSize-2));
m_capacityDis1_label->setText("("+str_capacityDis1+")");
//m_capacityDis1_label->setObjectName("capacityLabel");
//卷名标签的横向布局
QHBoxLayout *onevolume_h_BoxLayout = new QHBoxLayout();
onevolume_h_BoxLayout->setSpacing(0);
onevolume_h_BoxLayout->addSpacing(50);
onevolume_h_BoxLayout->setMargin(0); //使得widget上的label得以居中显示
onevolume_h_BoxLayout->addWidget(m_nameDis1_label);
//onevolume_h_BoxLayout->addWidget(m_capacityDis1_label);
onevolume_h_BoxLayout->addSpacing(20);
onevolume_h_BoxLayout->addStretch();
disWidgetNumOne->setObjectName("OriginObjectOnly");
disWidgetNumOne->setLayout(onevolume_h_BoxLayout);
disWidgetNumOne->installEventFilter(this);
//设置主页面布局
main_V_BoxLayout = new QVBoxLayout(this);
if(m_uDiskNo <= 1){
main_V_BoxLayout->setContentsMargins(15, 0, 6, 20);
main_V_BoxLayout->setSpacing(0);
main_V_BoxLayout->addSpacing(20);
main_V_BoxLayout->addLayout(drivename_H_BoxLayout);
}
main_V_BoxLayout->setContentsMargins(15, 0, 6, 20);
main_V_BoxLayout->addSpacing(0);
main_V_BoxLayout->addWidget(disWidgetNumOne);
main_V_BoxLayout->addSpacing(0);
this->setLayout(main_V_BoxLayout);
if (m_mountUri.isEmpty()) {
m_capacityDis1_label->setText(tr("Unmounted"));
}
if (m_uDiskNo <= 1) {
this->setFixedSize(388,100);
} else {
this->setFixedSize(200,20);
}
this->setAttribute(Qt::WA_TranslucentBackground, true); //设置顶层面板背景透明
// check capacity lable width
m_strCapacityDis = m_capacityDis1_label->text(); //获取qlabel中的字符串
qDebug()<<"----添加主窗口控件-卷名为"<<VolumeName;
m_nameDis1_label->setText("- "+VolumeName+":"+m_strCapacityDis);
// int nNameWidth = m_nameDis1_label->fontMetrics().boundingRect(m_nameDis1_label->text()).width();
// QString strCapacity = getElidedText(m_capacityDis1_label->font(), m_strCapacityDis, 210-nNameWidth);
// if (strCapacity != m_strCapacityDis) {
// m_capacityDis1_label->setText(strCapacity);
// m_capacityDis1_label->setToolTip(m_strCapacityDis);
// }
//this->setStyleSheet("border:1px solid red;");//for test
connect(this, &FDClickWidget::themeFontChange, this, &FDClickWidget::onThemeFontChange);
connect(m_hideTime, SIGNAL(timeout()), this,SLOT(on_hideinterface()));
//弹出按钮滑动效果
connect(this, &FDClickWidget::hoverEjectBotton, m_frame, &FDFrame::on_updateSize);
connect(this, &FDClickWidget::leaveEjectBotton, m_frame, &FDFrame::on_cursorLeave);
}
void FDClickWidget::initFontSize()
{
if (!fontSettings)
{
fontSize = 11;
return;
}
connect(fontSettings,&QGSettings::changed,[=](QString key)
{
if("systemFont" == key || "systemFontSize" == key)
{
fontSize = fontSettings->get(FONT_SIZE).toString().toFloat();
Q_EMIT themeFontChange(fontSize);
}
});
QStringList keys = fontSettings->keys();
if (keys.contains("systemFont") || keys.contains("systemFontSize"))
{
fontSize = fontSettings->get(FONT_SIZE).toInt();
}
}
void FDClickWidget::onThemeFontChange(qreal lfFontSize)
{
}
void FDClickWidget::on_hideinterface()
{
m_frame->hide();
}
void FDClickWidget::initThemeMode()
{
if(!qtSettings)
{
currentThemeMode = "ukui-white";
}
QStringList keys = qtSettings->keys();
if(keys.contains("styleName"))
{
currentThemeMode = qtSettings->get("style-name").toString();
}
}
FDClickWidget::~FDClickWidget()
{
if(chooseDialog)
delete chooseDialog;
if(gpartedface)
delete gpartedface;
if (fontSettings) {
delete fontSettings;
fontSettings = nullptr;
}
if (qtSettings) {
delete qtSettings;
qtSettings = nullptr;
}
}
void FDClickWidget::mousePressEvent(QMouseEvent *ev)
{
mousePos = QPoint(ev->x(), ev->y());
}
void FDClickWidget::mouseReleaseEvent(QMouseEvent *ev)
{
if(mousePos == QPoint(ev->x(), ev->y())) Q_EMIT clicked();
}
//click the first area to show the interface
void FDClickWidget::on_volume_clicked()
{
if (!m_mountUri.isEmpty()) {
qDebug()<<"----uri is "<<m_mountUri;
QString aaa = "peony "+m_mountUri;
QProcess::startDetached(aaa.toUtf8().data());
this->topLevelWidget()->hide();
}
}
void FDClickWidget::switchWidgetClicked()
{
EjectDeviceInfo eDeviceInfo;
eDeviceInfo.strDriveId = m_driveId;
eDeviceInfo.strDriveName = m_driveName;
eDeviceInfo.strVolumeId = m_volumeId;
eDeviceInfo.strVolumeName = m_volumeName;
eDeviceInfo.strMountId = m_mountId;
eDeviceInfo.strMountUri = m_mountUri;
m_frame->hide();
Q_EMIT clickedEject(eDeviceInfo);
}
QPixmap FDClickWidget::drawSymbolicColoredPixmap(const QPixmap &source)
{
if(currentThemeMode == "ukui-light" || currentThemeMode == "ukui-white")
{
QImage img = source.toImage();
for (int x = 0; x < img.width(); x++)
{
for (int y = 0; y < img.height(); y++)
{
auto color = img.pixelColor(x, y);
if (color.alpha() > 0)
{
color.setRed(0);
color.setGreen(0);
color.setBlue(0);
img.setPixelColor(x, y, color);
}
}
}
return QPixmap::fromImage(img);
}
else if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default" )
{
QImage img = source.toImage();
for (int x = 0; x < img.width(); x++)
{
for (int y = 0; y < img.height(); y++)
{
auto color = img.pixelColor(x, y);
if (color.alpha() > 0)
{
color.setRed(255);
color.setGreen(255);
color.setBlue(255);
img.setPixelColor(x, y, color);
}
}
}
return QPixmap::fromImage(img);
}
else
{
QImage img = source.toImage();
for (int x = 0; x < img.width(); x++)
{
for (int y = 0; y < img.height(); y++)
{
auto color = img.pixelColor(x, y);
if (color.alpha() > 0)
{
color.setRed(0);
color.setGreen(0);
color.setBlue(0);
img.setPixelColor(x, y, color);
}
}
}
return QPixmap::fromImage(img);
}
}
void FDClickWidget::ejectBottonAnim()
{
m_ejectAnimation = new QPropertyAnimation(m_eject_button,"geometry");
m_ejectAnimation->setDuration(500);
m_ejectAnimation->setStartValue(QRect(330,3, 50, 64));
m_ejectAnimation->setEndValue(QRect(310,3, 50, 64));
m_ejectAnimation->start();
}
void FDClickWidget::ejectBottonLeaveAnim()
{
m_ejectAnimation1 = new QPropertyAnimation(m_eject_button,"geometry");
m_ejectAnimation1->setDuration(500);
m_ejectAnimation1->setStartValue(QRect(310,3, 50, 64));
m_ejectAnimation1->setEndValue(QRect(330,3, 50, 64));
m_ejectAnimation1->start();
}
//to convert the capacity by another type
QString FDClickWidget::size_human(qlonglong capacity)
{
// float capacity = this->size();
if(capacity > 1)
{
int conversionNum = 0;
QStringList list;
list << "KB" << "MB" << "GB" << "TB";
QStringListIterator i(list);
QString unit("B");
qlonglong conversion = capacity;
while(conversion >= 1024.0 && i.hasNext())
{
unit = i.next();
conversion /= 1024.0;
conversionNum++;
}
qlonglong remain = capacity - conversion * qPow(1024,conversionNum);
double showRemain = 0.0;
if(conversionNum == 4) {
showRemain = (float)remain /1024/1024/1024/1024;
} else if(conversionNum == 3) {
showRemain = (float)remain /1024/1024/1024;
} else if(conversionNum == 2) {
showRemain = (float)remain /1024/1024;
} else if(conversionNum == 1) {
showRemain = (float)remain /1024;
}
double showValue = conversion + showRemain;
QString str2=QString::number(showValue,'f',1);
QString str_capacity=QString(" %1%2").arg(str2).arg(unit);
return str_capacity;
// return QString().setNum(capacity,'f',2)+" "+unit;
}
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
if(capacity == NULL)
{
QString str_capaticity = tr("the capacity is empty");
return str_capaticity;
}
#endif
if(capacity == 1)
{
QString str_capacity = tr("blank CD");
return str_capacity;
}
QString str_capacity = tr("other user device");
return str_capacity;
}
//set the style of the eject button and label when the mouse doing some different operations
bool FDClickWidget::eventFilter(QObject *obj, QEvent *event)
{
if(obj == m_eject_button)
{
if(event->type() == QEvent::MouseButtonPress)
{
if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default")
{
// m_eject_button->setIconSize(QSize(14,14));
// m_eject_button->setFixedSize(38,38);
}
else
{
// m_eject_button->setIconSize(QSize(14,14));
// m_eject_button->setFixedSize(38,38);
}
}
if(event->type() == QEvent::Enter)
{
Q_EMIT hoverEjectBotton();
//update();
ejectBottonAnim();
if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default")
{
// m_eject_button->setIconSize(QSize(16,16));
// m_eject_button->setFixedSize(40,40);
}
else
{
// m_eject_button->setIconSize(QSize(16,16));
// m_eject_button->setFixedSize(40,40);
}
}
if(event->type() == QEvent::Leave)
{
qDebug()<<"------leave";
Q_EMIT leaveEjectBotton();
ejectBottonLeaveAnim();
if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black")
{
// m_eject_button->setIconSize(QSize(16,16));
// m_eject_button->setFixedSize(40,40);
}
else
{
// m_eject_button->setIconSize(QSize(16,16));
// m_eject_button->setFixedSize(40,40);
}
}
}
if(obj == disWidgetNumOne)
{
if(event->type() == QEvent::Enter)
{
if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default"
|| currentThemeMode == "ukui")
{
// disWidgetNumOne->setStyleSheet(
// "QWidget#OriginObjectOnly{background:rgba(255,255,255,0.12);"
// "border-radius: 6px;}");
disWidgetNumOne->setStyleSheet("QLabel:hover{color:rgba(55,144,250,1);}");
}
else
{
// disWidgetNumOne->setStyleSheet(
// "QWidget#OriginObjectOnly{background:rgba(0,0,0,0.12);"
// "border-radius: 6px;}");
disWidgetNumOne->setStyleSheet("QLabel:hover{color:rgba(55,144,250,1);}");
}
}
if(event->type() == QEvent::Leave)
{
qDebug()<<"------------ClickWidget-leave----";
// disWidgetNumOne->setStyleSheet("");
// m_hideTime->start(2000);
}
if(event->type() == QEvent::Enter)
{
qDebug()<<"------------ClickWidget-Enter----";
// if (m_hideTime->isActive()) {
// m_hideTime->stop();
// }
}
if(event->type() == QEvent::MouseButtonPress)
{
on_volume_clicked();
}
}
return false;
}
void FDClickWidget::resizeEvent(QResizeEvent *event)
{
}
void FDClickWidget::paintEvent(QPaintEvent * event)
{
//绘制图标底圆
if(image_show_label != nullptr){
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
painter.setClipping(true); //
painter.setPen(Qt::transparent);
painter.setBrush(this->palette().color(QPalette::Button));
painter.drawEllipse((image_show_label->pos().x()-9),(image_show_label->pos().y()-3),36,36);
}
}

143
src/fdclickwidget.h Normal file
View File

@ -0,0 +1,143 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Yang Min yangmin@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __FDCLICKWIDGET_H__
#define __FDCLICKWIDGET_H__
#include <QWidget>
#include <QProcess>
#include <QDebug>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QStyle>
#include <QStyleOption>
#include <QPainter>
#include <QLabel>
#include <QBoxLayout>
#include <QPushButton>
#include <qgsettings.h>
#include <QPropertyAnimation>
#include <QTimer>
#include "ejectInterface.h"
#include "clickLabel.h"
#include "UnionVariable.h"
#include "interactivedialog.h"
#include "gpartedinterface.h"
#include "fdframe.h"
typedef struct _EjectDeviceInfo_s
{
void* pVoid = nullptr;
QString strDriveId = "";
QString strDriveName = "";
QString strVolumeId = "";
QString strVolumeName = "";
QString strMountId = "";
QString strMountUri = "";
unsigned uFlag = 0;
}EjectDeviceInfo;
class MainWindow;
class FDClickWidget : public QWidget
{
Q_OBJECT
public:
explicit FDClickWidget(FDFrame *parent = nullptr,
unsigned diskNo = 0,
QString strDriveId = "",
QString strVolumeId = "",
QString strMountId = "",
QString driveName = "",
QString volumeName = "",
quint64 capacityDis = 0,
QString strMountUri = "");
~FDClickWidget();
protected:
void mousePressEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev);
private:
QIcon imgIcon;
unsigned m_uDiskNo;
QString m_driveName;
QString m_volumeName;
quint64 m_capacityDis;
QString m_mountUri;
QString m_driveId;
QString m_volumeId;
QString m_mountId;
MainWindow *m_mainwindow;
QPoint mousePos;
QLabel *image_show_label = nullptr;
QLabel *m_driveName_label;
ClickLabel *m_nameDis1_label;
QLabel *m_capacityDis1_label;
QLabel *m_animLabel;
QTimer *m_hideTime;
QWidget *disWidgetNumOne;
QVBoxLayout *main_V_BoxLayout = nullptr;
QGSettings *fontSettings = nullptr;
QGSettings *qtSettings = nullptr;
int fontSize;
QString currentThemeMode;
QString m_strCapacityDis;
FDFrame *m_frame;
int m_width = 320;
QPropertyAnimation *m_ejectAnimation;
QPropertyAnimation *m_ejectAnimation1;
public:
ClickLabel *m_eject_button = nullptr;
interactiveDialog *chooseDialog = nullptr;
gpartedInterface *gpartedface = nullptr;
bool ifSucess = false;
Q_SIGNALS:
void clicked();
void clickedEject(EjectDeviceInfo eDeviceInfo);
void noDeviceSig();
void themeFontChange(qreal lfFontSize);
void hoverEjectBotton();
void leaveEjectBotton();
private Q_SLOTS:
void on_volume_clicked();
void switchWidgetClicked();
void onThemeFontChange(qreal lfFontSize);
void on_hideinterface();
private:
QString size_human(qlonglong capacity);
QPixmap drawSymbolicColoredPixmap(const QPixmap &source);
void ejectBottonAnim();
void ejectBottonLeaveAnim();
protected:
bool eventFilter(QObject *obj, QEvent *event);
void resizeEvent(QResizeEvent *event);
void paintEvent(QPaintEvent * event);
public:
void initFontSize();
void initThemeMode();
};
#endif // __FDCLICKWIDGET_H__

301
src/fdframe.cpp Normal file
View File

@ -0,0 +1,301 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Yang Min yangmin@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include <QPainter>
#include <QStyleOption>
#include <QDebug>
#include <QApplication>
#include <QScreen>
#include <QPainterPath>
#include <KWindowEffects>
#include <QGSettings>
#include <QPixmap>
#include <QGraphicsColorizeEffect>
#include "fdframe.h"
#define THEME_UKFD_TRANS "org.ukui.control-center.personalise"
#define IN_THEME_BLACKLIST 0
FDFrame::FDFrame(QWidget* parent) : QFrame(parent)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip);
setAttribute(Qt::WA_AlwaysShowToolTips);
setAttribute(Qt::WA_TranslucentBackground);
//setWindowOpacity(0.8);
initOpacityGSettings();
installEventFilter(this);
m_animLabel = new ClickLabel(this);
m_animLabel->move(0,0);
m_animLabel->setFixedSize(320,112);
m_animLabel->setAutoFillBackground(true);
//m_animLabel->setBackgroundRole(QPalette::Base);
setanimColor();
m_animLabel->palette().color(QPalette::Base);
m_animLabel->installEventFilter(this);
//m_animLabel->setPalette(QPalette::Base);
m_animLabel->setParent(this);
m_animLabel->show();
m_ejectLabel = new QLabel(this);
m_ejectLabel->setText(tr("eject"));
m_ejectLabel->setStyleSheet("QLabel{color: palette(Text);}");
m_ejectLabel->setParent(this);
m_ejectLabel->move(330,35);
m_ejectLabel->setFixedSize(40,40);
m_ejectLabel->hide();
m_ejectIcon = new QLabel(this);
m_ejectIcon->setProperty("useIconHighlightEffect", 0x2);
m_ejectIcon->setProperty("useButtonPalette", true);
QPixmap ejectpixmap =QIcon::fromTheme("media-eject-symbolic").pixmap(16,16);
m_ejectIcon->setPixmap(ejectpixmap);
m_ejectIcon->setStyleSheet("QLabel{color: rgba(140, 140, 140, 1);}");
m_ejectIcon->move(343,47);
m_ejectIcon->setFixedSize(16,16);
m_ejectIcon->show();
m_hideFrameTime = new QTimer(this);
connect(m_hideFrameTime, SIGNAL(timeout()), this,SLOT(on_hideframe()));
KWindowEffects::enableBlurBehind(winId(), true);
}
FDFrame::~FDFrame()
{
if (m_gsTransOpacity) {
delete m_gsTransOpacity;
m_gsTransOpacity = nullptr;
}
}
void FDFrame::initOpacityGSettings()
{
const QByteArray idtrans(THEME_UKFD_TRANS);
if(QGSettings::isSchemaInstalled(idtrans)) {
m_gsTransOpacity = new QGSettings(idtrans);
}
if (!m_gsTransOpacity) {
m_curTransOpacity = 1;
return;
}
connect(m_gsTransOpacity, &QGSettings::changed, this, [=](const QString &key) {
if (key == "transparency") {
QStringList keys = m_gsTransOpacity->keys();
if (keys.contains("transparency")) {
m_curTransOpacity = m_gsTransOpacity->get("transparency").toString().toDouble();
repaint();
}
}
});
QStringList keys = m_gsTransOpacity->keys();
if(keys.contains("transparency")) {
m_curTransOpacity = m_gsTransOpacity->get("transparency").toString().toDouble();
}
}
int FDFrame::readlabeltWidth()
{
return this->m_animLabel->width();
}
void FDFrame::setlabeltWidth(int width)
{
this->m_animLabel->setFixedWidth(width);
m_ejectIcon->move(width+23,47);
if(width == 288)
{
m_ejectIcon->setStyleSheet("QLabel{color: palette(Text);}");
m_ejectIcon->setProperty("useIconHighlightEffect", 0x2);
m_ejectLabel->show();
}else {
m_ejectIcon->setStyleSheet("QLabel{color: rgba(140, 140, 140, 1);}");
m_ejectLabel->hide();
}
}
void FDFrame::setanimColor()
{
#if !IN_THEME_BLACKLIST
QGSettings* gSettings = nullptr;
if (QGSettings::isSchemaInstalled("org.ukui.style")){
gSettings = new QGSettings("org.ukui.style");
}
if(gSettings != nullptr){
m_currentThemeMode = gSettings->get("styleName").toString();
connect(gSettings,&QGSettings::changed,this,[=](const QString &key) {
if((m_currentThemeMode != nullptr)&&(m_animLabel != nullptr)){
m_currentThemeMode = gSettings->get("styleName").toString();
if (("ukui-white" == m_currentThemeMode)||("ukui-light" == m_currentThemeMode)||("ukui-default" == m_currentThemeMode)){
m_animLabel->setStyleSheet("background-color:rgb(255,255,255); border-radius:12px; ");
}else {
m_animLabel->setStyleSheet("background-color:rgb(13,13,13); border-radius:12px;");
}
repaint();
}
});
}
style()->unpolish(this->m_animLabel);
if (("ukui-white" == m_currentThemeMode)||("ukui-light" == m_currentThemeMode)||("ukui-default" == m_currentThemeMode)){
m_animLabel->setStyleSheet("background-color:rgb(255,255,255); border-radius:12px; ");
}else {
m_animLabel->setStyleSheet("background-color:rgb(13,13,13); border-radius:12px;");
}
style()->polish(this->m_animLabel);
#else
m_animLabel->setStyleSheet("QLabel { background-color:rgb(13,13,13); border-radius:12px; }");
#endif
}
void FDFrame::paintEvent(QPaintEvent * event)
{
QPainterPath path;
QPainter painter(this);
painter.setOpacity(m_curTransOpacity);
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
painter.setClipping(true);
painter.setPen(Qt::transparent);
path.addRoundedRect(this->rect(), 12, 12);
path.setFillRule(Qt::WindingFill);
painter.setBrush(this->palette().color(QPalette::Base));
painter.setPen(Qt::transparent);
painter.drawPath(path);
#if !IN_THEME_BLACKLIST
//setanimColor();
#endif
QFrame::paintEvent(event);
}
bool FDFrame::eventFilter(QObject *obj, QEvent *event)
{
if(obj == m_animLabel)
{
if(event->type() == QEvent::MouseButtonPress)
{
qDebug()<<"-----MouseButtonPress------";
return true;
}
if(event->type() == QEvent::MouseButtonRelease)
{
qDebug()<<"-----MouseButtonRelease------";
return true;
}
if(event->type() == QEvent::Leave)
{
qDebug()<<"-----Leave------";
return true;
}
if(event->type() == QEvent::Enter)
{
qDebug()<<"-----Enter------";
if(("ukui-white" == m_currentThemeMode)||("ukui-light" == m_currentThemeMode)||("ukui-default" == m_currentThemeMode))
{
m_animLabel->setStyleSheet("background-color:rgb(240,240,240); border-radius:12px;");
}
else
{
m_animLabel->setStyleSheet("background-color:rgb(38,38,38); border-radius:12px;");
}
repaint();
return true;
}
}
if(event->type() == QEvent::Leave)
{
m_hideFrameTime->start(2000);
if(("ukui-white" == m_currentThemeMode)||("ukui-light" == m_currentThemeMode)||("ukui-default" == m_currentThemeMode))
{
m_animLabel->setStyleSheet("background-color:rgb(255,255,255); border-radius:12px;");
}
else
{
m_animLabel->setStyleSheet("background-color:rgb(18,18,18); border-radius:12px;");
}
repaint();
return true;
}
if(event->type() == QEvent::Enter)
{
if(("ukui-white" == m_currentThemeMode)||("ukui-light" == m_currentThemeMode)||("ukui-default" == m_currentThemeMode))
{
m_animLabel->setStyleSheet("background-color:rgb(240,240,240); border-radius:12px;");
}
else
{
m_animLabel->setStyleSheet("background-color:rgb(38,38,38); border-radius:12px;");
}
repaint();
if (m_hideFrameTime->isActive()) {
m_hideFrameTime->stop();
}
return true;
}
return false;
}
void FDFrame::on_updateSize()
{
QPropertyAnimation * m_enterAnimation = new QPropertyAnimation(this, "labeltWidth");
m_enterAnimation->setDuration(500);
m_enterAnimation->setStartValue(320);
m_enterAnimation->setEndValue(288);
m_enterAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
void FDFrame::on_cursorLeave()
{
QPropertyAnimation * m_leaveAnimation = new QPropertyAnimation(this, "labeltWidth");
m_leaveAnimation->setDuration(500);
m_leaveAnimation->setStartValue(288);
m_leaveAnimation->setEndValue(320);
m_leaveAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
void FDFrame::on_hideframe()
{
m_hideFrameTime->stop();
this->hide();
}

76
src/fdframe.h Normal file
View File

@ -0,0 +1,76 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Yang Min yangmin@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __FDFRAME_H__
#define __FDFRAME_H__
#include <QFrame>
#include <QPainterPath>
#include <QGSettings>
#include <QLabel>
#include <QPropertyAnimation>
#include <QTimer>
//#include <QPushButton>
#include "clickLabel.h"
class FDFrame : public QFrame
{
Q_OBJECT
Q_PROPERTY(int labeltWidth READ readlabeltWidth WRITE setlabeltWidth)
public:
explicit FDFrame(QWidget* parent);
virtual ~FDFrame();
void initOpacityGSettings();
protected:
public:
ClickLabel *m_animLabel;
int m_mainWindowHigh;
private:
// QGSettings
QGSettings *m_gsTransOpacity = nullptr;
qreal m_curTransOpacity = 1;
int m_hoverFlag = 0;
int m_width;
QLabel *m_ejectLabel;
QLabel *m_ejectIcon;
QPropertyAnimation *m_enterAnimation;
QPropertyAnimation *m_leaveAnimation;
QTimer *m_hideFrameTime;
QString m_currentThemeMode;
void paintEvent(QPaintEvent * event);
bool eventFilter(QObject *obj, QEvent *event);
int readlabeltWidth();
void setlabeltWidth(int width);
void setanimColor();
public Q_SLOTS:
void on_updateSize();
void on_cursorLeave();
void on_hideframe();
};
#endif

591
src/flashdiskdata.cpp Normal file
View File

@ -0,0 +1,591 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Yang Min yangmin@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include <QDebug>
#include <iostream>
#include <QDateTime>
using namespace std;
#include "flashdiskdata.h"
FlashDiskData* FlashDiskData::m_instance = nullptr;
QMutex FlashDiskData::m_mutex;
FlashDiskData::FlashDiskData()
{
m_devInfoWithDrive.clear();
m_devInfoWithVolume.clear();
m_devInfoWithMount.clear();
}
FlashDiskData::~FlashDiskData()
{
}
FlashDiskData *FlashDiskData::getInstance()
{
if (m_instance == nullptr)
{
QMutexLocker locker(&m_mutex);
if (m_instance == nullptr)
{
m_instance = new FlashDiskData();
}
}
return m_instance;
}
map<string, FDDriveInfo>& FlashDiskData::getDevInfoWithDrive()
{
return m_devInfoWithDrive;
}
map<string, FDVolumeInfo>& FlashDiskData::getDevInfoWithVolume()
{
return m_devInfoWithVolume;
}
map<string, FDMountInfo>& FlashDiskData::getDevInfoWithMount()
{
return m_devInfoWithMount;
}
int FlashDiskData::addDriveInfo(FDDriveInfo driveInfo)
{
if (driveInfo.strId.empty()) {
return -1;
}
map<string, FDVolumeInfo>::iterator itVolumeInfoNew = driveInfo.listVolumes.begin();
for (; itVolumeInfoNew != driveInfo.listVolumes.end(); itVolumeInfoNew++) {
if (!itVolumeInfoNew->second.strId.empty()) {
map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.find(itVolumeInfoNew->second.strId);
if (itVolumeInfo != m_devInfoWithVolume.end()) {
m_devInfoWithVolume.erase(itVolumeInfo);
}
}
}
m_devInfoWithDrive[driveInfo.strId] = driveInfo;
return 0;
}
int FlashDiskData::addVolumeInfoWithDrive(FDDriveInfo driveInfo, FDVolumeInfo volumeInfo)
{
if (driveInfo.strId.empty() || volumeInfo.strId.empty()) {
return -1;
}
volumeInfo.mountInfo.lluMountTick = QDateTime::currentDateTime().toMSecsSinceEpoch();
map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.find(volumeInfo.strId);
if (itVolumeInfo != m_devInfoWithVolume.end()) {
m_devInfoWithVolume.erase(itVolumeInfo);
}
map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.find(driveInfo.strId);
if (itDriveInfo != m_devInfoWithDrive.end()) {
itDriveInfo->second.listVolumes[volumeInfo.strId] = volumeInfo;
} else {
driveInfo.listVolumes.clear();
driveInfo.listVolumes[volumeInfo.strId] = volumeInfo;
m_devInfoWithDrive[driveInfo.strId] = driveInfo;
}
return 0;
}
int FlashDiskData::addMountInfoWithDrive(FDDriveInfo driveInfo, FDVolumeInfo volumeInfo, FDMountInfo mountInfo)
{
if (driveInfo.strId.empty() || mountInfo.strId.empty()) {
return -1;
}
mountInfo.lluMountTick = QDateTime::currentDateTime().toMSecsSinceEpoch();
map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.find(driveInfo.strId);
if (itDriveInfo != m_devInfoWithDrive.end()) {
volumeInfo.mountInfo = mountInfo;
if (volumeInfo.strId.empty()) {
itDriveInfo->second.listVolumes[mountInfo.strId] = volumeInfo;
} else {
itDriveInfo->second.listVolumes[volumeInfo.strId] = volumeInfo;
}
} else {
driveInfo.listVolumes.clear();
volumeInfo.mountInfo = mountInfo;
if (volumeInfo.strId.empty()) {
driveInfo.listVolumes[mountInfo.strId] = volumeInfo;
} else {
driveInfo.listVolumes[volumeInfo.strId] = volumeInfo;
}
m_devInfoWithDrive[driveInfo.strId] = driveInfo;
}
return 0;
}
int FlashDiskData::addVolumeInfo(FDVolumeInfo volumeInfo)
{
if (volumeInfo.strId.empty()) {
return -1;
}
volumeInfo.mountInfo.lluMountTick = QDateTime::currentDateTime().toMSecsSinceEpoch();
map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
if (itDriveInfo->second.listVolumes.find(volumeInfo.strId) != itDriveInfo->second.listVolumes.end()) {
itDriveInfo->second.listVolumes[volumeInfo.strId] = volumeInfo;
return 1;
}
}
if (!volumeInfo.mountInfo.strId.empty()) {
map<string, FDMountInfo>::iterator itMountInfo = m_devInfoWithMount.find(volumeInfo.mountInfo.strId);
if (itMountInfo != m_devInfoWithMount.end()) {
m_devInfoWithMount.erase(itMountInfo);
}
}
m_devInfoWithVolume[volumeInfo.strId] = volumeInfo;
return 0;
}
int FlashDiskData::addMountInfo(FDMountInfo mountInfo)
{
if (mountInfo.strId.empty()) {
return -1;
}
mountInfo.lluMountTick = QDateTime::currentDateTime().toMSecsSinceEpoch();
map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin();
for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) {
if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) {
return 1;
}
}
map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
itVolumeInfo = itDriveInfo->second.listVolumes.begin();
for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) {
if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) {
return 1;
}
}
}
m_devInfoWithMount[mountInfo.strId] = mountInfo;
return 0;
}
int FlashDiskData::removeDriveInfo(FDDriveInfo driveInfo)
{
if (driveInfo.strId.empty()) {
return -1;
}
if (m_devInfoWithDrive.find(driveInfo.strId) != m_devInfoWithDrive.end()) {
if (getAttachedVolumeCount(driveInfo.strId) > 0) {
//Q_EMIT notifyDeviceRemoved(QString::fromStdString(driveInfo.strId));
}
m_devInfoWithDrive.erase(driveInfo.strId);
return 0;
}
return 1;
}
int FlashDiskData::removeVolumeInfo(FDVolumeInfo volumeInfo)
{
if (volumeInfo.strId.empty()) {
return -1;
}
if (m_devInfoWithVolume.find(volumeInfo.strId) != m_devInfoWithVolume.end()) {
if (getAttachedVolumeCount(volumeInfo.strId) == 1) {
//Q_EMIT notifyDeviceRemoved(QString::fromStdString(volumeInfo.strId));
}
m_devInfoWithVolume.erase(volumeInfo.strId);
return 0;
} else {
map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
map<string, FDVolumeInfo>::iterator itVolumeInfo = itDriveInfo->second.listVolumes.find(volumeInfo.strId);
if (itVolumeInfo != itDriveInfo->second.listVolumes.end()) {
if (getAttachedVolumeCount(volumeInfo.strId) == 1) {
//Q_EMIT notifyDeviceRemoved(QString::fromStdString(volumeInfo.strId));
}
if (itVolumeInfo->second.mountInfo.strId.empty()) {
itDriveInfo->second.listVolumes.erase(volumeInfo.strId);
} else {
itVolumeInfo->second.strId = "";
}
return 0;
}
}
}
return 1;
}
int FlashDiskData::removeMountInfo(FDMountInfo mountInfo)
{
if (mountInfo.strId.empty()) {
return -1;
}
if (m_devInfoWithMount.find(mountInfo.strId) != m_devInfoWithMount.end()) {
m_devInfoWithMount.erase(mountInfo.strId);
return 0;
} else {
map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin();
for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) {
if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) {
#if 0
FDMountInfo mountTemp;
itVolumeInfo->second.mountInfo = mountTemp;
if (itVolumeInfo->second.strId.empty()) {
m_devInfoWithVolume.erase(itVolumeInfo);
}
#else
// if (getAttachedVolumeCount(itVolumeInfo->second.strId) == 1) {
// Q_EMIT notifyDeviceRemoved(QString::fromStdString(itVolumeInfo->second.strId));
// }
// m_devInfoWithVolume.erase(itVolumeInfo);
itVolumeInfo->second.mountInfo.strId = "";
#endif
return 0;
}
}
map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
itVolumeInfo = itDriveInfo->second.listVolumes.begin();
for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) {
if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) {
#if 0
FDMountInfo mountTemp;
itVolumeInfo->second.mountInfo = mountTemp;
if (itVolumeInfo->second.strId.empty()) {
itDriveInfo->second.listVolumes.erase(itVolumeInfo);
}
#else
// if (getAttachedVolumeCount(itVolumeInfo->second.strId) == 1) {
// Q_EMIT notifyDeviceRemoved(QString::fromStdString(itVolumeInfo->second.strId));
// }
// itDriveInfo->second.listVolumes.erase(itVolumeInfo);
itVolumeInfo->second.mountInfo.strId = "";
#endif
return 0;
}
}
}
}
return 1;
}
bool FlashDiskData::isMountInfoExist(FDMountInfo mountInfo)
{
if (mountInfo.strId.empty()) {
return false;
}
if (m_devInfoWithMount.find(mountInfo.strId) != m_devInfoWithMount.end()) {
return true;
}
map<string, FDDriveInfo>::iterator itDriveInfo;
map<string, FDVolumeInfo>::iterator itVolumeInfo;
itVolumeInfo = m_devInfoWithVolume.begin();
for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) {
if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) {
return true;
}
}
itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
itVolumeInfo = itDriveInfo->second.listVolumes.begin();
for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) {
if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) {
return true;
}
}
}
return false;
}
quint64 FlashDiskData::getMountTickDiff(FDMountInfo mountInfo)
{
quint64 curTick = QDateTime::currentDateTime().toMSecsSinceEpoch();
if (mountInfo.strId.empty()) {
return 0;
}
if (m_devInfoWithMount.find(mountInfo.strId) != m_devInfoWithMount.end()) {
return (curTick-m_devInfoWithMount[mountInfo.strId].lluMountTick);
}
map<string, FDDriveInfo>::iterator itDriveInfo;
map<string, FDVolumeInfo>::iterator itVolumeInfo;
itVolumeInfo = m_devInfoWithVolume.begin();
for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) {
if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) {
return (curTick-itVolumeInfo->second.mountInfo.lluMountTick);
}
}
itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
itVolumeInfo = itDriveInfo->second.listVolumes.begin();
for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) {
if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) {
return (curTick-itVolumeInfo->second.mountInfo.lluMountTick);
}
}
}
return 0;
}
bool FlashDiskData::getVolumeInfoByMount(FDMountInfo mountInfo, FDVolumeInfo& volumeInfo)
{
quint64 curTick = QDateTime::currentDateTime().toMSecsSinceEpoch();
if (mountInfo.strId.empty()) {
return false;
}
if (m_devInfoWithMount.find(mountInfo.strId) != m_devInfoWithMount.end()) {
return false;
}
map<string, FDDriveInfo>::iterator itDriveInfo;
map<string, FDVolumeInfo>::iterator itVolumeInfo;
itVolumeInfo = m_devInfoWithVolume.begin();
for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) {
if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) {
volumeInfo = itVolumeInfo->second;
return true;
}
}
itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
itVolumeInfo = itDriveInfo->second.listVolumes.begin();
for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) {
if (itVolumeInfo->second.mountInfo.strId == mountInfo.strId) {
volumeInfo = itVolumeInfo->second;
return true;
}
}
}
return false;
}
void FlashDiskData::resetAllNewState()
{
map<string, FDMountInfo>::iterator itMountInfo = m_devInfoWithMount.begin();
for (; itMountInfo != m_devInfoWithMount.end(); itMountInfo++) {
if (!itMountInfo->second.strId.empty()) {
itMountInfo->second.isNewInsert = false;
}
}
map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin();
for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) {
itVolumeInfo->second.isNewInsert = false;
if (!itVolumeInfo->second.mountInfo.strId.empty()) {
itVolumeInfo->second.mountInfo.isNewInsert = false;
}
}
map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
itVolumeInfo = itDriveInfo->second.listVolumes.begin();
for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) {
itVolumeInfo->second.isNewInsert = false;
if (!itVolumeInfo->second.mountInfo.strId.empty()) {
itVolumeInfo->second.mountInfo.isNewInsert = false;
}
}
}
}
unsigned FlashDiskData::getValidInfoCount()
{
unsigned uDriveCount = 0;
unsigned uVolumeCount = 0;
unsigned uMountCount = 0;
uMountCount = m_devInfoWithMount.size();
map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin();
for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) {
if (!itVolumeInfo->second.mountInfo.strId.empty()) {
uVolumeCount ++;
}
}
map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
itVolumeInfo = itDriveInfo->second.listVolumes.begin();
for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) {
if (!itVolumeInfo->second.mountInfo.strId.empty()) {
uDriveCount ++;
}
}
}
return uDriveCount + uVolumeCount + uMountCount;
}
unsigned FlashDiskData::getAttachedVolumeCount(string strId)
{
if (strId.empty()) {
return 0;
}
map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin();
for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) {
if (itVolumeInfo->second.strId == strId) {
return 1;
}
}
map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
if (itDriveInfo->second.strId == strId) {
return itDriveInfo->second.listVolumes.size();
} else {
itVolumeInfo = itDriveInfo->second.listVolumes.begin();
for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) {
if (itVolumeInfo->second.strId == strId) {
return itDriveInfo->second.listVolumes.size();
}
}
}
}
return 0;
}
static bool strEndsWith(string s, string sub) {
if (s.rfind(sub)==(s.length()-sub.length())) {
return true;
} else {
return false;
}
}
static bool strStartsWith(string s, string sub) {
if (s.rfind(sub)==(s.length()-sub.length())) {
return true;
} else {
return false;
}
}
QString FlashDiskData::getVolumeIcon(QString strVolumeId)
{
QString strVolumeIcon = "drive-removable-media-usb";
quint64 mountSize = 0;
map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin();
for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) {
if (itVolumeInfo->second.strId.find(strVolumeId.toStdString()) == 0) {
strVolumeIcon = QString::fromStdString(itVolumeInfo->second.strIconPath);
if (!itVolumeInfo->second.mountInfo.strId.empty()) {
mountSize = itVolumeInfo->second.mountInfo.lluTotalSize;
// if (!itVolumeInfo->second.mountInfo.strIconPath.empty()) {
// if (strEndsWith(itVolumeInfo->second.mountInfo.strIconPath, ".ico")) {
// strVolumeIcon = QString::fromStdString(itVolumeInfo->second.mountInfo.strIconPath);
// }
// }
}
break;
}
}
if (strVolumeIcon == "drive-removable-media-usb") {
map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
itVolumeInfo = itDriveInfo->second.listVolumes.begin();
for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) {
if (itVolumeInfo->second.strId.find(strVolumeId.toStdString()) == 0) {
strVolumeIcon = QString::fromStdString(itVolumeInfo->second.strIconPath);
if (!itVolumeInfo->second.mountInfo.strId.empty()) {
mountSize = itVolumeInfo->second.mountInfo.lluTotalSize;
// if (!itVolumeInfo->second.mountInfo.strIconPath.empty()) {
// if (strEndsWith(itVolumeInfo->second.mountInfo.strIconPath, ".ico")) {
// strVolumeIcon = QString::fromStdString(itVolumeInfo->second.mountInfo.strIconPath);
// }
// }
}
break;
}
}
}
}
if (strVolumeIcon != "drive-harddisk-usb") {
return strVolumeIcon;
}
if (mountSize/(1024 * 1024 *1024) > 128)
strVolumeIcon = "drive-harddisk-usb";
else
strVolumeIcon = "drive-removable-media-usb";
return strVolumeIcon;
}
void FlashDiskData::clearAllData()
{
}
void FlashDiskData::OutputInfos()
{
#if 0
unsigned uDriveCount = 0;
unsigned uVolumeCount = 0;
unsigned uMountCount = 0;
uMountCount = m_devInfoWithMount.size();
uVolumeCount = m_devInfoWithVolume.size();
map<string, FDDriveInfo>::iterator itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
uDriveCount += itDriveInfo->second.listVolumes.size();
}
qDebug()<<"info count:"<<uDriveCount<<"|"<<uVolumeCount<<"|"<<uMountCount;
qDebug()<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
map<string, FDMountInfo>::iterator itMountInfo = m_devInfoWithMount.begin();
for (; itMountInfo != m_devInfoWithMount.end(); itMountInfo++) {
if (!itMountInfo->second.strId.empty()) {
qDebug()<<"Mount:"<<QString::fromStdString(itMountInfo->second.strId)<<"|"
<<QString::fromStdString(itMountInfo->second.strName)<<"|"<<itMountInfo->second.isCanUnmount
<<"|"<<itMountInfo->second.isCanEject<<"|"<<QString::fromStdString(itMountInfo->second.strTooltip)<<"|"
<<QString::fromStdString(itMountInfo->second.strUri)<<"|"<<itMountInfo->second.isNativeDev
<<"|"<<itMountInfo->second.lluTotalSize<<"|"<<itMountInfo->second.isNewInsert<<"|"<<itMountInfo->second.lluMountTick
<<"|"<<itMountInfo->second.strIconPath.c_str();
}
}
qDebug()<<"--------------------------------------------------------";
map<string, FDVolumeInfo>::iterator itVolumeInfo = m_devInfoWithVolume.begin();
for (; itVolumeInfo != m_devInfoWithVolume.end(); itVolumeInfo++) {
qDebug()<<"Volume:"<<QString::fromStdString(itVolumeInfo->second.strId)<<"|"
<<QString::fromStdString(itVolumeInfo->second.strName)<<"|"<<itVolumeInfo->second.isCanMount
<<"|"<<itVolumeInfo->second.isShouldAutoMount<<"|"<<itVolumeInfo->second.isCanEject
<<"|"<<QString::fromStdString(itVolumeInfo->second.strDevName)<<"|"<<itVolumeInfo->second.isNewInsert
<<"|"<<itVolumeInfo->second.strIconPath.c_str();
if (!itVolumeInfo->second.mountInfo.strId.empty()) {
qDebug()<<"Mount:"<<QString::fromStdString(itVolumeInfo->second.mountInfo.strId)<<"|"
<<QString::fromStdString(itVolumeInfo->second.mountInfo.strName)<<"|"<<itVolumeInfo->second.mountInfo.isCanUnmount
<<"|"<<itVolumeInfo->second.mountInfo.isCanEject<<"|"<<QString::fromStdString(itVolumeInfo->second.mountInfo.strTooltip)<<"|"
<<QString::fromStdString(itVolumeInfo->second.mountInfo.strUri)<<"|"<<itVolumeInfo->second.mountInfo.isNativeDev
<<"|"<<itVolumeInfo->second.mountInfo.lluTotalSize<<"|"<<itVolumeInfo->second.mountInfo.isNewInsert<<"|"
<<itVolumeInfo->second.mountInfo.lluMountTick<<"|"<<itVolumeInfo->second.mountInfo.strIconPath.c_str();
}
}
qDebug()<<"--------------------------------------------------------";
itDriveInfo = m_devInfoWithDrive.begin();
for (; itDriveInfo != m_devInfoWithDrive.end(); itDriveInfo++) {
qDebug()<<"Drive:"<<QString::fromStdString(itDriveInfo->second.strId)<<"|"
<<QString::fromStdString(itDriveInfo->second.strName)<<"|"<<itDriveInfo->second.isCanEject
<<"|"<<itDriveInfo->second.isRemovable<<"|"<<itDriveInfo->second.isCanStart<<"|"<<itDriveInfo->second.isCanStop
<<"|"<<itDriveInfo->second.strIconPath.c_str();
itVolumeInfo = itDriveInfo->second.listVolumes.begin();
for (; itVolumeInfo != itDriveInfo->second.listVolumes.end(); itVolumeInfo++) {
qDebug()<<"Volume:"<<QString::fromStdString(itVolumeInfo->second.strId)<<"|"
<<QString::fromStdString(itVolumeInfo->second.strName)<<"|"<<itVolumeInfo->second.isCanMount
<<"|"<<itVolumeInfo->second.isShouldAutoMount<<"|"<<itVolumeInfo->second.isCanEject
<<"|"<<QString::fromStdString(itVolumeInfo->second.strDevName)<<"|"<<itVolumeInfo->second.isNewInsert
<<"|"<<itVolumeInfo->second.strIconPath.c_str();
if (!itVolumeInfo->second.mountInfo.strId.empty()) {
qDebug()<<"Mount:"<<QString::fromStdString(itVolumeInfo->second.mountInfo.strId)<<"|"
<<QString::fromStdString(itVolumeInfo->second.mountInfo.strName)<<"|"<<itVolumeInfo->second.mountInfo.isCanUnmount
<<"|"<<itVolumeInfo->second.mountInfo.isCanEject<<"|"<<QString::fromStdString(itVolumeInfo->second.mountInfo.strTooltip)<<"|"
<<QString::fromStdString(itVolumeInfo->second.mountInfo.strUri)<<"|"<<itVolumeInfo->second.mountInfo.isNativeDev
<<"|"<<itVolumeInfo->second.mountInfo.lluTotalSize<<"|"<<itVolumeInfo->second.mountInfo.isNewInsert<<"|"
<<itVolumeInfo->second.mountInfo.lluMountTick<<"|"<<itVolumeInfo->second.mountInfo.strIconPath.c_str();
}
}
}
qDebug()<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
#endif
}

117
src/flashdiskdata.h Normal file
View File

@ -0,0 +1,117 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Yang Min yangmin@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef __FLASHDISKDATA_H__
#define __FLASHDISKDATA_H__
#include <QList>
#include <gio/gio.h>
#include <QString>
#include <QFont>
#include <QFontMetrics>
#include <QTextCodec>
#include <QMutex>
#include <map>
#include <string>
using namespace std;
typedef struct FDMountInfo_s {
string strId = "";
string strName = "";
bool isCanUnmount = false;
bool isCanEject = false;
string strTooltip = "";
string strUri = "";
bool isNativeDev = false;
bool isNewInsert = false;
quint64 lluTotalSize = 0;
quint64 lluMountTick = 0;
string strIconPath = "";
}FDMountInfo;
typedef struct FDVolumeInfo_s {
string strId = "";
string strName = "";
string strDevName = "";
bool isCanMount = false;
bool isShouldAutoMount = false;
bool isCanEject = false;
bool isNewInsert = false;
FDMountInfo mountInfo;
string strIconPath = "";
}FDVolumeInfo;
Q_DECLARE_METATYPE(FDVolumeInfo);
typedef struct FDDriveInfo_s {
string strId = "";
string strName = "";
bool isCanEject = false;
bool isRemovable = false;
bool isCanStart = false;
bool isCanStop = false;
map<string, FDVolumeInfo> listVolumes;
string strIconPath = "";
}FDDriveInfo;
class FlashDiskData : public QObject
{
Q_OBJECT
public:
virtual ~FlashDiskData();
static FlashDiskData* getInstance();
map<string, FDDriveInfo>& getDevInfoWithDrive();
map<string, FDVolumeInfo>& getDevInfoWithVolume();
map<string, FDMountInfo>& getDevInfoWithMount();
int addDriveInfo(FDDriveInfo driveInfo);
int addVolumeInfoWithDrive(FDDriveInfo driveInfo, FDVolumeInfo volumeInfo);
int addMountInfoWithDrive(FDDriveInfo driveInfo, FDVolumeInfo volumeInfo, FDMountInfo mountInfo);
int addVolumeInfo(FDVolumeInfo volumeInfo);
int addMountInfo(FDMountInfo mountInfo);
int removeDriveInfo(FDDriveInfo driveInfo);
int removeVolumeInfo(FDVolumeInfo volumeInfo);
int removeMountInfo(FDMountInfo mountInfo);
unsigned getValidInfoCount();
void clearAllData();
bool isMountInfoExist(FDMountInfo mountInfo);
void resetAllNewState();
quint64 getMountTickDiff(FDMountInfo mountInfo);
bool getVolumeInfoByMount(FDMountInfo mountInfo, FDVolumeInfo& volumeInfo);
unsigned getAttachedVolumeCount(string strId);
QString getVolumeIcon(QString strVolumeId);
void OutputInfos();
Q_SIGNALS:
void notifyDeviceRemoved(QString strDevId);
private:
FlashDiskData();
static FlashDiskData *m_instance;
static QMutex m_mutex;
map<string, FDDriveInfo> m_devInfoWithDrive; //
map<string, FDVolumeInfo> m_devInfoWithVolume; // except with drive
map<string, FDMountInfo> m_devInfoWithMount; // except with volume
};
#endif // __FLASHDISKDATA_H__

134
src/gpartedinterface.cpp Normal file
View File

@ -0,0 +1,134 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "gpartedinterface.h"
#include <KWindowEffects>
gpartedInterface::gpartedInterface(QWidget *parent):QWidget(parent)
{
this->setFixedSize(300,86);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
this->setAttribute(Qt::WA_TranslucentBackground);
initWidgets();
moveChooseDialogRight();
initTransparentState();
getTransparentData();
}
void gpartedInterface::initTransparentState()
{
const QByteArray idtrans(THEME_QT_TRANS);
if(QGSettings::isSchemaInstalled(idtrans))
{
m_transparency_gsettings = new QGSettings(idtrans);
}
}
void gpartedInterface::getTransparentData()
{
if (!m_transparency_gsettings)
{
m_transparency = 0.95;
return;
}
QStringList keys = m_transparency_gsettings->keys();
if (keys.contains("transparency"))
{
m_transparency = m_transparency_gsettings->get("transparency").toDouble();
}
}
void gpartedInterface::initWidgets()
{
noticeLabel = new QLabel(this);
noticeLabel->setText(tr("gparted has started,can not eject"));
okButton = new QPushButton(tr("ok"));
notice_H_BoxLayout = new QHBoxLayout();
main_V_BoxLayout = new QVBoxLayout();
button_H_BoxLayout = new QHBoxLayout();
notice_H_BoxLayout->addWidget(noticeLabel);
button_H_BoxLayout->addWidget(okButton,1,Qt::AlignRight);
main_V_BoxLayout->addLayout(notice_H_BoxLayout);
main_V_BoxLayout->addLayout(button_H_BoxLayout);
this->setLayout(main_V_BoxLayout);
connect(okButton,SIGNAL(clicked()),this,SLOT(close()));
}
void gpartedInterface::moveChooseDialogRight()
{
int position=0;
int panelSize=0;
if(QGSettings::isSchemaInstalled(QString("org.ukui.panel.settings").toLocal8Bit()))
{
QGSettings* gsetting=new QGSettings(QString("org.ukui.panel.settings").toLocal8Bit());
if(gsetting->keys().contains(QString("panelposition")))
position=gsetting->get("panelposition").toInt();
else
position=0;
if(gsetting->keys().contains(QString("panelsize")))
panelSize=gsetting->get("panelsize").toInt();
else
panelSize=SmallPanelSize;
}
else
{
position=0;
panelSize=SmallPanelSize;
}
int x=QApplication::primaryScreen()->geometry().x();
int y=QApplication::primaryScreen()->geometry().y();
qDebug()<<"QApplication::primaryScreen()->geometry().x();"<<QApplication::primaryScreen()->geometry().x();
qDebug()<<"QApplication::primaryScreen()->geometry().y();"<<QApplication::primaryScreen()->geometry().y();
if(position==0)
this->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-this->width() - DISTANCEPADDING - DISTANCEMEND,y+QApplication::primaryScreen()->geometry().height()-panelSize-this->height() - DISTANCEPADDING,this->width(),this->height()));
else if(position==1)
this->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-this->width() - DISTANCEPADDING - DISTANCEMEND,y+panelSize + DISTANCEPADDING,this->width(),this->height())); // Style::minw,Style::minh the width and the height of the interface which you want to show
else if(position==2)
this->setGeometry(QRect(x+panelSize + DISTANCEPADDING,y + QApplication::primaryScreen()->geometry().height() - this->height() - DISTANCEPADDING,this->width(),this->height()));
else
this->setGeometry(QRect(x+QApplication::primaryScreen()->geometry().width()-panelSize-this->width() - DISTANCEPADDING,y + QApplication::primaryScreen()->geometry().height() - this->height() - DISTANCEPADDING,this->width(),this->height()));
}
gpartedInterface::~gpartedInterface()
{
}
void gpartedInterface::paintEvent(QPaintEvent *event)
{
QPainterPath path;
auto rect = this->rect();
rect.adjust(1, 1, -1, -1);
path.addRoundedRect(rect, 6, 6);
setProperty("blurRegion", QRegion(path.toFillPolygon().toPolygon()));
QStyleOption opt;
opt.init(this);
QPainter p(this);
QRect rectReal = this->rect();
p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
p.setBrush(opt.palette.color(QPalette::Base));
p.setOpacity(m_transparency);
p.setPen(Qt::NoPen);
p.drawRoundedRect(rectReal, 6, 6);
QWidget::paintEvent(event);
KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon()));
}

72
src/gpartedinterface.h Normal file
View File

@ -0,0 +1,72 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef GPARTEDINTERFACE_H
#define GPARTEDINTERFACE_H
#include "MacroFile.h"
#include <QWidget>
#include <QtWidgets>
#include <QLabel>
#include <QBoxLayout>
#include <QIcon>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QStyle>
#include <QStyleOption>
#include <QPainter>
#include <QPainterPath>
#include <QTimer>
#include <QApplication>
#include <QScreen>
#include <QDebug>
#include <QPushButton>
#include <QLabel>
#include <qgsettings.h>
QT_BEGIN_NAMESPACE
namespace Ui { class gpartedInterface; }
QT_END_NAMESPACE
class gpartedInterface: public QWidget
{
Q_OBJECT
public:
gpartedInterface(QWidget *parent);
~gpartedInterface();
private:
double m_transparency;
QGSettings *m_transparency_gsettings = nullptr;
QGSettings *gsetting = nullptr;
QPushButton *okButton;
QLabel *noticeLabel;
QHBoxLayout *notice_H_BoxLayout = nullptr;
QHBoxLayout *button_H_BoxLayout = nullptr;
QVBoxLayout *main_V_BoxLayout = nullptr;
private:
void initWidgets();
void moveChooseDialogRight();
void initTransparentState();
void getTransparentData();
protected:
void paintEvent(QPaintEvent *event);
};
#endif //GPARTEDINTERFAC_H

253
src/interactivedialog.cpp Normal file
View File

@ -0,0 +1,253 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "interactivedialog.h"
#include <KWindowEffects>
interactiveDialog::interactiveDialog(QString strDevId, QWidget *parent):QWidget(parent)
{
this->setFixedSize(300,86);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
QPainterPath path;
auto rect = this->rect();
rect.adjust(1, 1, -1, -1);
path.addRoundedRect(rect, 6, 6);
setProperty("blurRegion", QRegion(path.toFillPolygon().toPolygon()));
this->setAttribute(Qt::WA_TranslucentBackground);
initWidgets(strDevId);
connect(chooseBtnCancle,SIGNAL(clicked()),this,SLOT(close()));
connect(chooseBtnContinue,SIGNAL(clicked()),this,SLOT(convert()));
moveChooseDialogRight();
initTransparentState();
getTransparentData();
KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon()));
}
void interactiveDialog::initTransparentState()
{
const QByteArray idtrans(THEME_QT_TRANS);
if(QGSettings::isSchemaInstalled(idtrans))
{
m_transparency_gsettings = new QGSettings(idtrans);
}
}
void interactiveDialog::getTransparentData()
{
if (!m_transparency_gsettings)
{
m_transparency = 0.95;
return;
}
QStringList keys = m_transparency_gsettings->keys();
if (keys.contains("transparency"))
{
m_transparency = m_transparency_gsettings->get("transparency").toDouble();
}
}
void interactiveDialog::initWidgets(QString strDevId)
{
contentLable = new QLabel(this);
contentLable->setWordWrap(true);
updateContentLable(strDevId);
content_H_BoxLayout = new QHBoxLayout();
content_H_BoxLayout->addWidget(contentLable, 1, Qt::AlignCenter);
#ifdef UDISK_SUPPORT_FORCEEJECT
chooseBtnCancle = new QPushButton();
chooseBtnCancle->setText(tr("cancle"));
chooseBtnCancle->setFlat(true);
chooseBtnContinue = new QPushButton();
chooseBtnContinue->setText(tr("yes"));
chooseBtnContinue->setFlat(true);
chooseBtn_H_BoxLayout = new QHBoxLayout();
chooseBtn_H_BoxLayout->addSpacing(70);
chooseBtn_H_BoxLayout->addWidget(chooseBtnCancle);
chooseBtn_H_BoxLayout->addWidget(chooseBtnContinue);
chooseBtn_H_BoxLayout->setSpacing(0);
#else
chooseBtnCancle = new QPushButton();
chooseBtnCancle->setText(tr("yes"));
chooseBtnCancle->setFlat(true);
chooseBtnContinue = new QPushButton();
chooseBtnContinue->hide();
chooseBtn_H_BoxLayout = new QHBoxLayout();
chooseBtn_H_BoxLayout->addWidget(chooseBtnCancle, 1, Qt::AlignCenter);
chooseBtn_H_BoxLayout->addWidget(chooseBtnContinue);
chooseBtn_H_BoxLayout->setSpacing(0);
#endif
main_V_BoxLayout = new QVBoxLayout();
main_V_BoxLayout->addLayout(content_H_BoxLayout);
main_V_BoxLayout->addLayout(chooseBtn_H_BoxLayout);
this->setLayout(main_V_BoxLayout);
}
void interactiveDialog::updateContentLable(QString strDevId)
{
m_strDevId = strDevId;
#ifdef UDISK_SUPPORT_FORCEEJECT
if (m_strDevId.startsWith("/dev/sr")) {
contentLable->setText(tr("cdrom is occupying,do you want to eject it"));
} else if (m_strDevId.startsWith("/dev/mmcblk")) {
contentLable->setText(tr("sd is occupying,do you want to eject it"));
} else {
contentLable->setText(tr("usb is occupying,do you want to eject it"));
}
#else
if (m_strDevId.startsWith("/dev/sr")) {
contentLable->setText(tr("cdrom is occupying"));
} else if (m_strDevId.startsWith("/dev/mmcblk")) {
contentLable->setText(tr("sd is occupying"));
} else {
contentLable->setText(tr("usb is occupying"));
}
#endif
}
void interactiveDialog::convert()
{
Q_EMIT FORCESIG();
}
void interactiveDialog::moveChooseDialogRight()
{
int position=0;
int panelSize=0;
if(QGSettings::isSchemaInstalled(QString("org.ukui.panel.settings").toLocal8Bit()))
{
QGSettings* gsetting=new QGSettings(QString("org.ukui.panel.settings").toLocal8Bit());
if(gsetting->keys().contains(QString("panelposition")))
position=gsetting->get("panelposition").toInt();
else
position=0;
if(gsetting->keys().contains(QString("panelsize")))
panelSize=gsetting->get("panelsize").toInt();
else
panelSize=SmallPanelSize;
}
else
{
position=0;
panelSize=SmallPanelSize;
}
int x=QApplication::primaryScreen()->geometry().x();
int y=QApplication::primaryScreen()->geometry().y();
qDebug()<<"QApplication::primaryScreen()->geometry().x();"<<QApplication::primaryScreen()->geometry().x();
qDebug()<<"QApplication::primaryScreen()->geometry().y();"<<QApplication::primaryScreen()->geometry().y();
if(position==0)
this->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-this->width() - DISTANCEPADDING - DISTANCEMEND,y+QApplication::primaryScreen()->geometry().height()-panelSize-this->height() - DISTANCEPADDING,this->width(),this->height()));
else if(position==1)
this->setGeometry(QRect(x + QApplication::primaryScreen()->geometry().width()-this->width() - DISTANCEPADDING - DISTANCEMEND,y+panelSize + DISTANCEPADDING,this->width(),this->height())); // Style::minw,Style::minh the width and the height of the interface which you want to show
else if(position==2)
this->setGeometry(QRect(x+panelSize + DISTANCEPADDING,y + QApplication::primaryScreen()->geometry().height() - this->height() - DISTANCEPADDING,this->width(),this->height()));
else
this->setGeometry(QRect(x+QApplication::primaryScreen()->geometry().width()-panelSize-this->width() - DISTANCEPADDING,y + QApplication::primaryScreen()->geometry().height() - this->height() - DISTANCEPADDING,this->width(),this->height()));
}
interactiveDialog::~interactiveDialog()
{
if (m_transparency_gsettings) {
delete m_transparency_gsettings;
m_transparency_gsettings = nullptr;
}
if (gsetting) {
delete gsetting;
gsetting = nullptr;
}
}
void interactiveDialog::paintEvent(QPaintEvent *event)
{
// QStyleOption opt;
// opt.init(this);
// QPainter p(this);
// QRect rect = this->rect();
// p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
// p.setBrush(opt.palette.color(QPalette::Base));
//// p.setBrush(QColor(Qt::red));
//// p.setOpacity(m_transparency);
// p.setPen(Qt::NoPen);
// p.drawRoundedRect(rect, 6, 6);
// qDebug()<<__FUNCTION__;
// QStyleOption opt;
// opt.init(this);
// QPainter p(this);
// QRect rect = this->rect();
// p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
// p.setBrush(opt.palette.color(QPalette::Base));
// p.setOpacity(m_transparency);
// p.setPen(Qt::NoPen);
// p.drawRoundedRect(rect, 6, 6);
// QWidget::paintEvent(event);
// qDebug()<<__FUNCTION__;
// QStyleOption opt;
// opt.init(this);
// QPainter p(this);
// QRect rect = this->rect();
// p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
// p.setBrush(opt.palette.color(QPalette::Base));
// p.setOpacity(m_transparency);
// p.setPen(Qt::NoPen);
// p.drawRect(rect);
// QWidget::paintEvent(event);
// QStyleOption opt;
// opt.init(this);
// QPainter p(this);
// p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
// p.setBrush(opt.palette.color(QPalette::Base));
// p.setOpacity(m_transparency);
// QPainterPath path;
// auto rect = this->rect();
// path.addRoundedRect(rect, 12, 12);
// path.drawRoundedRect
// QRegion region(path.toFillPolygon().toPolygon());
//// this->setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明
// KWindowEffects::enableBlurBehind(this->winId(),true,region);
// QWidget::paintEvent(event);
QStyleOption opt;
opt.init(this);
QPainter p(this);
QRect rect = this->rect();
p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
p.setBrush(opt.palette.color(QPalette::Base));
p.setOpacity(m_transparency);
p.setPen(Qt::NoPen);
p.drawRoundedRect(rect, 6, 6);
QWidget::paintEvent(event);
}

82
src/interactivedialog.h Normal file
View File

@ -0,0 +1,82 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef INTERACTIVEDIALOG_H
#define INTERACTIVEDIALOG_H
#include "MacroFile.h"
#include <QWidget>
#include <QtWidgets>
#include <QLabel>
#include <QBoxLayout>
#include <QIcon>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QStyle>
#include <QStyleOption>
#include <QPainter>
#include <QPainterPath>
#include <QTimer>
#include <QApplication>
#include <QScreen>
#include <QDebug>
#include <QPushButton>
#include <qgsettings.h>
QT_BEGIN_NAMESPACE
namespace Ui { class interactiveDialog; }
QT_END_NAMESPACE
class interactiveDialog: public QWidget
{
Q_OBJECT
public:
interactiveDialog(QString strDevId, QWidget *parent);
~interactiveDialog();
void updateContentLable(QString strDevId);
private:
QPushButton *chooseBtnContinue = nullptr;
QPushButton *chooseBtnCancle = nullptr;
QLabel *contentLable = nullptr;
QHBoxLayout *content_H_BoxLayout = nullptr;
QHBoxLayout *chooseBtn_H_BoxLayout = nullptr;
QVBoxLayout *main_V_BoxLayout = nullptr;
double m_transparency;
int fontSize;
QGSettings *m_transparency_gsettings = nullptr;
QGSettings *gsetting = nullptr;
private:
void initWidgets(QString strDevId);
void moveChooseDialogRight();
void initTransparentState();
void getTransparentData();
protected:
void paintEvent(QPaintEvent *event);
public Q_SLOTS:
void convert();
Q_SIGNALS:
void FORCESIG();
private:
QString m_strDevId;
};
#endif

View File

@ -0,0 +1,8 @@
<RCC>
<qresource prefix="/">
<file>kylin-device-daemon.qss</file>
<file>../data/media-eject-symbolic.svg</file>
<file>../data/drive-removable-media.svg</file>
<file>../data/drive-removable-media-usb.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,48 @@
QWidget#lineWidget{
background-color: rgba(255,255,255,0.2);
width:276px;
height:1px;
}
/* QLabel about */
QLabel#driveNameLabel{
font-size:14px;
font-family:Noto Sans CJK SC;
font-weight:400;
color:rgba(255,255,255,1);
line-height:28px;
opacity:0.91;
}
QLabel#capacityLabel{
font-size:14px;
font-family:Microsoft YaHei;
font-weight:400;
color:rgba(255,255,255,0.35);
line-height:28px;
opacity:0.35;
}
/* QPushButton about */
QPushButton#Button::pressed{
background:rgba(255,0,0,1);
border-radius:4px;
width:38px;
height:38px;
}
QPushButton#Button::hover{
background:rgba(255,255,255,0.08);
border-radius:4px;
width:40px;
height:40px;
}
QPushButton#Button{
background:rgba(255,255,255,0);
border-radius:4px;
width:40px;
height:40px;
}

97
src/main.cpp Normal file
View File

@ -0,0 +1,97 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include <QApplication>
#include <QDebug>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <syslog.h>
#include <QDebug>
#include <QtDBus/QDBusConnection>
#include <QTranslator>
#include <QTextCodec>
#include <ukui-log4qt.h>
#include "UnionVariable.h"
#include "mainwindow.h"
#include "MainController.h"
#include "fdapplication.h"
int main(int argc, char *argv[])
{
initUkuiLog4qt("kylin-device-daemon");
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
QTextCodec *codec = QTextCodec::codecForName("utf8"); //Linux
QTextCodec::setCodecForLocale(codec);
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QString id = QString("kylin-device-daemon_%1_%2").arg(getuid()).arg(QLatin1String(getenv("DISPLAY")));
FDApplication a(id, argc, argv);
// Process does not exit implicitly
a.setQuitOnLastWindowClosed(false);
if (a.isRunning()) {
qInfo() << "kylin-device-daemon is running, now exit!";
return 1;
}
// load translation file
QString locale = QLocale::system().name();
QTranslator translator;
if (locale == "zh_CN") {
if (translator.load("/usr/share/kylin-device-daemon/kylin-device-daemon_zh_CN.qm")) {
qDebug() << "load success";
a.installTranslator(&translator);
} else {
qDebug() << "Load translations file" << locale << "failed!";
}
}
if (locale == "bo_CN") {
if (translator.load("/usr/share/kylin-device-daemon/kylin-device-daemon_bo_CN.qm")) {
qDebug() << "load success";
a.installTranslator(&translator);
} else {
qDebug() << "Load translations file" << locale << "failed!";
}
}
if (QApplication::desktop()->width() >= 2560) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
}
MainController *ctrl = MainController::self();
// single instance is running
if (ctrl->init() != 0) {
return 0;
}
QObject::connect(&a, &FDApplication::notifyWnd, ctrl, &MainController::notifyWnd);
a.exec();
delete ctrl;
return 0;
}

3470
src/mainwindow.cpp Executable file

File diff suppressed because it is too large Load Diff

248
src/mainwindow.h Executable file
View File

@ -0,0 +1,248 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtWidgets>
#include <QLabel>
#include <QPushButton>
#include <QSystemTrayIcon>
#include <QIcon>
#include <gio/gio.h>
#include <glib.h>
#include <QApplication>
#include <QEvent>
#include <qgsettings.h>
#include <QMap>
#include <vector>
using namespace std;
#include "qclickwidget.h"
#include "UnionVariable.h"
#include "ejectInterface.h"
#include "mainwindow.h"
#include "MacroFile.h"
#include "flashdiskdata.h"
#include "fdclickwidget.h"
#include "repair-dialog-box.h"
#define UDFAUTOMOUNT 0
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public:
QSystemTrayIcon *m_systray;
ejectInterface *m_eject = nullptr;
interactiveDialog *chooseDialog = nullptr;
bool m_ismountadd = false;
bool ifSucess;
int flagType;
int driveMountNum;
vector<string> m_vtDeviveId;
EjectDeviceInfo m_curEjectDeviceInfo;
void MainWindowShow(bool isUpdate = false);
void initTransparentState();
void initThemeMode();
void getTransparentData();
int getPanelPosition(QString str);
int getPanelHeight(QString str);
protected:
void hideEvent(QHideEvent event);
void resizeEvent(QResizeEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
void paintEvent(QPaintEvent *event);
private:
Ui::MainWindow *ui;
QVBoxLayout *vboxlayout;
QLabel *no_device_label;
QPushButton *eject_image_button;
char *UDiskPathDis1;
char *UDiskPathDis2;
char *UDiskPathDis3;
char *UDiskPathDis4;
quint64 totalDis1;
quint64 totalDis2;
quint64 totalDis3;
quint64 totalDis4;
QClickWidget *open_widget;
FDClickWidget *m_fdClickWidget;
int hign;
int VolumeNum;
QTimer *interfaceHideTime;
int num = 0;
QScreen *screen;
int triggerType = 0; //detective the type of MainWinow(insert USB disk or click systemtray icon)
double m_transparency;
QString currentThemeMode;
QGSettings *m_transparency_gsettings = nullptr;
QWidget *line = nullptr;
bool ifautoload;
bool insertorclick;
QGSettings * ifsettings = nullptr;
int telephoneNum;
QString tmpPath;
bool findPointMount;
int driveVolumeNum;
FlashDiskData* m_dataFlashDisk = nullptr;
bool m_bIsMouseInTraIcon = false;
bool m_bIsMouseInCentral = false;
qint64 m_nAppStartTimestamp = 0; // 进程启动时的时间戳
QString m_strSysRootDev;
FDFrame *centralWidgetList[6] = {0};
bool mIsrunning = false;
QMap<QString, RepairDialogBox*> mRepairDialog;
void initFlashDisk();
void initSlots();
void newarea(int No,
GDrive *Drive,
GVolume *Volume,
QString Drivename,
QString nameDis1,
QString nameDis2,
QString nameDis3,
QString nameDis4,
qlonglong capacityDis1,
qlonglong capacityDis2,
qlonglong capacityDis3,
qlonglong capacityDis4,
QString pathDis1,
QString pathDis2,
QString pathDis3,
QString pathDis4,
int linestatus);
void newarea(unsigned uDiskNo,
QString strDriveId,
QString strVolumeId,
QString strMountId,
QString driveName,
QString volumeName,
quint64 capacityDis,
QString strMountUri,
int linestatus);
void showMainWindow(int uVolumeNum,
int uDiskCount,
quint64 uVolumeSum,
QVBoxLayout *vboxLayout1,
QString strDriveId,
QString strVolumeId,
QString strMountId,
QString driveName,
QString volumeName,
quint64 capacityDis,
QString strMountUri);
void showFristWindow(quint64 uVolumeSum,
int uVolumeNum,
QString strDriveId,
QString strVolumeId,
QString strMountId,
QString driveName,
QString volumeName,
quint64 capacityDis,
QString strMountUri);
void moveBottomRight();
void moveBottomDirect(GDrive *drive);
void moveBottomNoBase();
QString size_human(qlonglong capacity);
void getDeviceInfo();
static void frobnitz_result_func_volume(GVolume *source_object,GAsyncResult *res,MainWindow *p_this);
static void frobnitz_result_func_mount(GMount *source_object,GAsyncResult *res,MainWindow *p_this);
//static void frobnitz_result_func_volume(GVolume *source_object,GAsyncResult *res,gpointer);
static void drive_connected_callback (GVolumeMonitor *monitor, GDrive *drive, MainWindow *p_this);
static void drive_disconnected_callback (GVolumeMonitor *monitor, GDrive *drive, MainWindow *p_this);
static void volume_added_callback (GVolumeMonitor *monitor, GVolume *volume, MainWindow *p_this);
static void volume_removed_callback (GVolumeMonitor *monitor, GVolume *volume, MainWindow *p_this);
static void mount_added_callback (GVolumeMonitor *monitor, GMount *mount, MainWindow *p_this);
static void mount_removed_callback (GVolumeMonitor *monitor, GMount *mount, MainWindow *p_this);
void ifgetPinitMount();
static void frobnitz_force_result_func(GDrive *source_object,GAsyncResult *res,MainWindow *p_this);
static void frobnitz_result_func(GDrive *source_object,GAsyncResult *res,MainWindow *p_this);
static void frobnitz_normal_result_volume_eject(GVolume *source_object,GAsyncResult *res,MainWindow *p_this);
static void frobnitz_force_result_unmount(GMount *source_object,GAsyncResult *res,MainWindow *p_this);
static void AsyncUnmount(QString strMountRoot,MainWindow *p_this);
void getSystemRootDev();
bool isSystemRootDev(QString strDev);
bool doRealEject(EjectDeviceInfo* peDeviceInfo, GMountUnmountFlags flag);
static GAsyncReadyCallback fileEjectMountableCB(GFile *file, GAsyncResult *res, EjectDeviceInfo *peDeviceInfo);
static void driveStopCb(GObject* object, GAsyncResult* res, EjectDeviceInfo *peDeviceInfo);
bool getDataCDRomCapacity(QString strDevId, quint64 &totalCapacity);
void getDriveIconsInfo(GDrive* drive, FDDriveInfo& driveInfo);
void getVolumeIconsInfo(GVolume* volume, FDVolumeInfo& volumeInfo);
void getMountIconsInfo(GMount* mount, FDMountInfo& mountInfo);
bool getDevInterface(QString strDev);
public Q_SLOTS:
void iconActivated(QSystemTrayIcon::ActivationReason reason);
void onConvertShowWindow(QString strDriveId, QString strMountUri);
void onConvertUpdateWindow(QString strDevName, unsigned uDevType);
void onMaininterfacehide();
void on_clickPanelToHideInterface();
void onRequestSendDesktopNotify(QString message, QString strIcon);
void onInsertAbnormalDiskNotify(QString message);
void onNotifyWnd(QObject* obj, QEvent *event);
void onClickedEject(EjectDeviceInfo eDeviceInfo);
void onRemountVolume(FDVolumeInfo volumeInfo);
void onCheckDriveValid(FDDriveInfo driveInfo);
bool onDeviceErrored(GDrive* drive);
void onMountVolume(GVolume*);
void onEjectVolumeForce(GVolume* v); // A fix pops up if the mount fails
void onNotifyDeviceRemoved(QString strDevId);
Q_SIGNALS:
void clicked();
void convertShowWindow(QString strDriveId, QString strMountUri);
void convertUpdateWindow(QString, unsigned);
void unloadMount();
void telephoneMount();
bool deviceError(GDrive*);
void mountVolume(GVolume*);
void ejectVolumeForce(GVolume*);
void remountVolume(FDVolumeInfo volumeInfo);
void checkDriveValid(FDDriveInfo driveInfo);
void notifyDeviceRemoved(QString strDevId);
};
#endif

21
src/mainwindow.ui Normal file
View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>370</width>
<height>232</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

979
src/qclickwidget.cpp Normal file
View File

@ -0,0 +1,979 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "qclickwidget.h"
#include <KWindowEffects>
#include <QtConcurrent/QtConcurrent>
void frobnitz_force_result_func(GDrive *source_object,GAsyncResult *res,QClickWidget *p_this)
{
auto env = qgetenv("QT_QPA_PLATFORMTHEME");
qDebug()<<"env"<<env;
gboolean success = FALSE;
GError *err = nullptr;
success = g_drive_eject_with_operation_finish (source_object, res, &err);
if (!err)
{
findGDriveList()->removeOne(source_object);
p_this->m_eject = new ejectInterface(p_this,g_drive_get_name(source_object),NORMALDEVICE,"");
p_this->m_eject->show();
}
else
{
int volumeNum = g_list_length(g_drive_get_volumes(source_object));
for(int eachVolume = 0 ; eachVolume < volumeNum ;eachVolume++)
{
p_this->flagType = 0;
if(g_mount_can_unmount(g_volume_get_mount((GVolume *)g_list_nth_data(g_drive_get_volumes(source_object),eachVolume))))
{
QtConcurrent::run([=](){
char *dataPath = g_file_get_path(g_mount_get_root(g_volume_get_mount((GVolume *)g_list_nth_data(g_drive_get_volumes(source_object),eachVolume))));
qDebug()<<"dataPath"<<dataPath;
QProcess p;
p.setProgram("pkexec");
p.setArguments(QStringList()<<"eject"<<QString(dataPath));
p.start();
p_this->ifSucess = p.waitForFinished();
});
}
}
}
}
void frobnitz_result_func(GDrive *source_object,GAsyncResult *res,QClickWidget *p_this)
{
gboolean success = FALSE;
GError *err = nullptr;
success = g_drive_eject_with_operation_finish (source_object, res, &err);
if (!err)
{
findGDriveList()->removeOne(source_object);
p_this->m_eject = new ejectInterface(p_this,g_drive_get_name(source_object),NORMALDEVICE,"");
p_this->m_eject->show();
}
else /*if(g_drive_can_stop(source_object) == true)*/
{
if (p_this->chooseDialog == nullptr)
{
p_this->chooseDialog = new interactiveDialog("", p_this);
}
// p_this->chooseDialog->raise();
p_this->chooseDialog->show();
p_this->chooseDialog->setFocus();
p_this->connect(p_this->chooseDialog,&interactiveDialog::FORCESIG,p_this,[=]()
{
g_drive_eject_with_operation(source_object,
G_MOUNT_UNMOUNT_FORCE,
NULL,
NULL,
GAsyncReadyCallback(frobnitz_force_result_func),
p_this
);
p_this->chooseDialog->close();
});
}
}
void frobnitz_force_result_tele(GVolume *source_object,GAsyncResult *res,QClickWidget *p_this)
{
gboolean success = FALSE;
GError *err = nullptr;
success = g_mount_unmount_with_operation_finish(g_volume_get_mount(source_object),res, &err);
if(!err)
{
qDebug()<<"unload successful";
findTeleGVolumeList()->removeOne(source_object);
findGVolumeList()->removeOne(source_object);
if(findTeleGVolumeList()->size() == 1)
{
if(findGVolumeList()->size() == 1)
{
Q_EMIT p_this->noDeviceSig();
}
}
}
}
QClickWidget::QClickWidget(QWidget *parent,
int num,
GDrive *Drive,
GVolume *Volume,
QString driveName,
QString nameDis1,
QString nameDis2,
QString nameDis3,
QString nameDis4,
qlonglong capacityDis1,
qlonglong capacityDis2,
qlonglong capacityDis3,
qlonglong capacityDis4,
QString pathDis1,
QString pathDis2,
QString pathDis3,
QString pathDis4)
: QWidget(parent),
m_Num(num),
m_Drive(Drive),
m_driveName(driveName),
m_nameDis1(nameDis1),
m_nameDis2(nameDis2),
m_nameDis3(nameDis3),
m_nameDis4(nameDis4),
m_capacityDis1(capacityDis1),
m_capacityDis2(capacityDis2),
m_capacityDis3(capacityDis3),
m_capacityDis4(capacityDis4),
m_pathDis1(pathDis1),
m_pathDis2(pathDis2),
m_pathDis3(pathDis3),
m_pathDis4(pathDis4)
{
//union layout
/*
* it's the to set the title interface,we get the drive name and add picture of a u disk
*/
const QByteArray id(THEME_QT_SCHEMA);
if(QGSettings::isSchemaInstalled(id))
{
fontSettings = new QGSettings(id);
}
const QByteArray idd(THEME_QT_SCHEMA);
if(QGSettings::isSchemaInstalled(idd))
{
qtSettings = new QGSettings(idd);
}
initFontSize();
initThemeMode();
QHBoxLayout *drivename_H_BoxLayout = new QHBoxLayout();
drivename_H_BoxLayout = new QHBoxLayout();
image_show_label = new QLabel(this);
image_show_label->setFocusPolicy(Qt::NoFocus);
image_show_label->installEventFilter(this);
//to get theme picture for label
imgIcon = QIcon::fromTheme("drive-removable-media-usb");
QPixmap pixmap = imgIcon.pixmap(QSize(25, 25));
image_show_label->setPixmap(pixmap);
image_show_label->setFixedSize(40,40);
m_driveName_label = new QLabel(this);
m_driveName_label->setFont(QFont("Noto Sans CJK SC",fontSize));
QString DriveName = getElidedText(m_driveName_label->font(), m_driveName, 180);
m_driveName_label->setText(DriveName);
m_driveName_label->setFixedSize(180,40);
m_driveName_label->setObjectName("driveNameLabel");
m_eject_button = new QPushButton(this);
m_eject_button->setFlat(true); //this property set that when the mouse is hovering in the icon the icon will move up a litte
m_eject_button->move(m_eject_button->x()+234,m_eject_button->y()+2);
//->setObjectName("Button");
m_eject_button->installEventFilter(this);
m_eject_button->setIcon(drawSymbolicColoredPixmap(QPixmap::fromImage(QIcon::fromTheme("media-eject-symbolic").pixmap(24,24).toImage())));
m_eject_button->setFixedSize(40,40);
m_eject_button->setToolTip(tr("弹出"));
drivename_H_BoxLayout->addSpacing(8);
drivename_H_BoxLayout->addWidget(image_show_label);
drivename_H_BoxLayout->addWidget(m_driveName_label);
drivename_H_BoxLayout->addStretch();
QVBoxLayout *main_V_BoxLayout = new QVBoxLayout(this);
main_V_BoxLayout->setContentsMargins(0,0,0,0);
connect(m_eject_button,SIGNAL(clicked()),SLOT(switchWidgetClicked())); // this signal-slot function is to emit a signal which
//is to trigger a slot in mainwindow
connect(m_eject_button, &QPushButton::clicked,this,[=]()
{
if(Drive != NULL)
{
g_drive_eject_with_operation(Drive,
G_MOUNT_UNMOUNT_NONE,
NULL,
NULL,
GAsyncReadyCallback(frobnitz_result_func),
this);
}
else
{
g_mount_unmount_with_operation(g_volume_get_mount(Volume),
G_MOUNT_UNMOUNT_NONE,
NULL,
NULL,
GAsyncReadyCallback(frobnitz_force_result_tele),
this);
}
});
//when the drive only has one vlolume
//we set the information and set all details of the U disk in main interface
if(m_Num == 1)
{
disWidgetNumOne = new QWidget(this);
QHBoxLayout *onevolume_h_BoxLayout = new QHBoxLayout();
m_nameDis1_label = new ClickLabel(disWidgetNumOne);
m_nameDis1_label->setFont(QFont("Microsoft YaHei",fontSize));
QString VolumeName = getElidedText(m_nameDis1_label->font(), m_nameDis1, 120);
m_nameDis1_label->adjustSize();
m_nameDis1_label->setText("- "+VolumeName+":");
m_capacityDis1_label = new QLabel(disWidgetNumOne);
QString str_capacityDis1 = size_human(m_capacityDis1);
// QString str_capacityDis1Show = getElidedText(m_capacityDis1_label->font(),str_capacityDis1,200);
m_capacityDis1_label->setFont(QFont("Microsoft YaHei",fontSize));
m_capacityDis1_label->setText("("+str_capacityDis1+")");
m_capacityDis1_label->setObjectName("capacityLabel");
onevolume_h_BoxLayout->setSpacing(0);
onevolume_h_BoxLayout->addSpacing(50);
onevolume_h_BoxLayout->setMargin(0); //使得widget上的label得以居中显示
onevolume_h_BoxLayout->addWidget(m_nameDis1_label);
onevolume_h_BoxLayout->addWidget(m_capacityDis1_label);
onevolume_h_BoxLayout->addSpacing(10);
onevolume_h_BoxLayout->addStretch();
disWidgetNumOne->setObjectName("OriginObjectOnly");
disWidgetNumOne->setLayout(onevolume_h_BoxLayout);
disWidgetNumOne->installEventFilter(this);
disWidgetNumOne->setFixedHeight(30);
main_V_BoxLayout->addLayout(drivename_H_BoxLayout);
if (m_pathDis1.isEmpty()) {
m_capacityDis1_label->setText(tr("Unmounted"));
}
main_V_BoxLayout->addWidget(disWidgetNumOne);
this->setLayout(main_V_BoxLayout);
this->setFixedSize(276,68);
}
//when the drive has two volumes
if(m_Num == 2)
{
QHBoxLayout *onevolume_h_BoxLayout = new QHBoxLayout();
m_nameDis1_label = new ClickLabel();
m_nameDis1_label->setFont(QFont("Microsoft YaHei",fontSize));
QString VolumeNameDis1 = getElidedText(m_nameDis1_label->font(), m_nameDis1, 120);
m_nameDis1_label->adjustSize();
m_nameDis1_label->setText("- "+VolumeNameDis1+":");
m_nameDis1_label->installEventFilter(this);
m_capacityDis1_label = new QLabel(this);
QString str_capacityDis1 = size_human(m_capacityDis1);
m_capacityDis1_label->setFont(QFont("Microsoft YaHei",fontSize));
m_capacityDis1_label->setText("("+str_capacityDis1+")");
m_capacityDis1_label->setObjectName("capacityLabel");
onevolume_h_BoxLayout->addSpacing(50);
onevolume_h_BoxLayout->setSpacing(0);
onevolume_h_BoxLayout->addWidget(m_nameDis1_label);
onevolume_h_BoxLayout->setMargin(0);
onevolume_h_BoxLayout->addWidget(m_capacityDis1_label);
onevolume_h_BoxLayout->addStretch();
disWidgetNumOne = new QWidget;
disWidgetNumOne->setFixedHeight(30);
disWidgetNumOne->setObjectName("OriginObjectOnly");
disWidgetNumOne->setLayout(onevolume_h_BoxLayout);
disWidgetNumOne->installEventFilter(this);
QHBoxLayout *twovolume_h_BoxLayout = new QHBoxLayout();
m_nameDis2_label = new ClickLabel(this);
m_nameDis2_label->setFont(QFont("Microsoft YaHei",fontSize));
QString VolumeNameDis2 = getElidedText(m_nameDis2_label->font(), m_nameDis2, 120);
m_nameDis2_label->setText("- "+VolumeNameDis2+":");
m_nameDis2_label->adjustSize();
m_nameDis2_label->installEventFilter(this);
m_capacityDis2_label = new QLabel(this);
QString str_capacityDis2 = size_human(m_capacityDis2);
m_capacityDis2_label->setText("("+str_capacityDis2+")");
m_capacityDis2_label->setFont(QFont("Microsoft YaHei",fontSize));
m_capacityDis2_label->setObjectName("capacityLabel");
twovolume_h_BoxLayout->addSpacing(50);
twovolume_h_BoxLayout->setSpacing(0);
twovolume_h_BoxLayout->addWidget(m_nameDis2_label);
twovolume_h_BoxLayout->setMargin(0);
twovolume_h_BoxLayout->addWidget(m_capacityDis2_label);
twovolume_h_BoxLayout->addStretch();
disWidgetNumTwo = new QWidget;
disWidgetNumTwo->setFixedHeight(30);
disWidgetNumTwo->setObjectName("OriginObjectOnly");
disWidgetNumTwo->setLayout(twovolume_h_BoxLayout);
disWidgetNumTwo->installEventFilter(this);
main_V_BoxLayout->setContentsMargins(0,0,0,0);
main_V_BoxLayout->addLayout(drivename_H_BoxLayout);
if(m_pathDis1 != "")
{
main_V_BoxLayout->addWidget(disWidgetNumOne);
}
if(m_pathDis2 != "")
{
main_V_BoxLayout->addWidget(disWidgetNumTwo);
}
main_V_BoxLayout->addStretch();
this->setLayout(main_V_BoxLayout);
this->setFixedSize(276,97);
}
//when the drive has three volumes
if(m_Num == 3)
{
QHBoxLayout *onevolume_h_BoxLayout = new QHBoxLayout();
m_nameDis1_label = new ClickLabel(this);
m_nameDis1_label->setFont(QFont("Microsoft YaHei",fontSize));
QString VolumeNameDis1 = getElidedText(m_nameDis1_label->font(), m_nameDis2, 120);
m_nameDis1_label->setText("- "+VolumeNameDis1+":");
m_nameDis1_label->adjustSize();
m_nameDis1_label->installEventFilter(this);
//m_nameDis1_label->setText("- "+m_nameDis1+":");
m_capacityDis1_label = new QLabel(this);
QString str_capacityDis1 = size_human(m_capacityDis1);
m_capacityDis1_label->setFont(QFont("Microsoft YaHei",fontSize));
m_capacityDis1_label->setText("("+str_capacityDis1+")");
m_capacityDis1_label->setObjectName("capacityLabel");
onevolume_h_BoxLayout->addSpacing(50);
onevolume_h_BoxLayout->setSpacing(0);
onevolume_h_BoxLayout->addWidget(m_nameDis1_label);
onevolume_h_BoxLayout->addWidget(m_capacityDis1_label);
onevolume_h_BoxLayout->addStretch();
onevolume_h_BoxLayout->setMargin(0);
disWidgetNumOne = new QWidget;
disWidgetNumOne->setFixedHeight(30);
disWidgetNumOne->setLayout(onevolume_h_BoxLayout);
disWidgetNumOne->setObjectName("OriginObjectOnly");
disWidgetNumOne->installEventFilter(this);
QHBoxLayout *twovolume_h_BoxLayout = new QHBoxLayout();
m_nameDis2_label = new ClickLabel(this);
m_nameDis2_label->setFont(QFont("Microsoft YaHei",fontSize));
QString VolumeNameDis2 = getElidedText(m_nameDis2_label->font(), m_nameDis2, 120);
m_nameDis2_label->setText("- "+VolumeNameDis2+":");
m_nameDis2_label->adjustSize();
m_nameDis2_label->installEventFilter(this);
m_capacityDis2_label = new QLabel(this);
QString str_capacityDis2 = size_human(m_capacityDis2);
m_capacityDis2_label->setText("("+str_capacityDis2+")");
m_capacityDis2_label->setFont(QFont("Microsoft YaHei",fontSize));
m_capacityDis2_label->setObjectName("capacityLabel");
twovolume_h_BoxLayout->addSpacing(50);
twovolume_h_BoxLayout->setSpacing(0);
twovolume_h_BoxLayout->addWidget(m_nameDis2_label);
twovolume_h_BoxLayout->addWidget(m_capacityDis2_label);
twovolume_h_BoxLayout->addStretch();
twovolume_h_BoxLayout->setMargin(0);
disWidgetNumTwo = new QWidget;
disWidgetNumTwo->setFixedHeight(30);
disWidgetNumTwo->setObjectName("OriginObjectOnly");
disWidgetNumTwo->setLayout(twovolume_h_BoxLayout);
disWidgetNumTwo->installEventFilter(this);
QHBoxLayout *threevolume_h_BoxLayout = new QHBoxLayout();
m_nameDis3_label = new ClickLabel(this);
m_nameDis3_label->setFont(QFont("Microsoft YaHei",fontSize));
QString VolumeNameDis3 = getElidedText(m_nameDis3_label->font(), m_nameDis3, 120);
m_nameDis3_label->setText("- "+VolumeNameDis3+":");
m_nameDis3_label->adjustSize();
m_nameDis3_label->installEventFilter(this);
m_capacityDis3_label = new QLabel(this);
QString str_capacityDis3 = size_human(m_capacityDis3);
m_capacityDis3_label->setText("("+str_capacityDis3+")");
m_capacityDis3_label->setFont(QFont("Microsoft YaHei",fontSize));
m_capacityDis3_label->setObjectName("capacityLabel");
threevolume_h_BoxLayout->addSpacing(50);
threevolume_h_BoxLayout->setSpacing(0);
threevolume_h_BoxLayout->addWidget(m_nameDis3_label);
threevolume_h_BoxLayout->addWidget(m_capacityDis3_label);
threevolume_h_BoxLayout->addStretch();
threevolume_h_BoxLayout->setMargin(0);
disWidgetNumThree = new QWidget;
disWidgetNumThree->setFixedHeight(30);
disWidgetNumThree->setObjectName("OriginObjectOnly");
disWidgetNumThree->setLayout(threevolume_h_BoxLayout);
disWidgetNumThree->installEventFilter(this);
main_V_BoxLayout->setContentsMargins(0,0,0,0);
main_V_BoxLayout->addLayout(drivename_H_BoxLayout);
if(m_pathDis1 != "")
{
main_V_BoxLayout->addWidget(disWidgetNumOne);
}
if(m_pathDis2 != "")
{
main_V_BoxLayout->addWidget(disWidgetNumTwo);
}
if(m_pathDis3 != "")
{
main_V_BoxLayout->addWidget(disWidgetNumThree);
}
this->setLayout(main_V_BoxLayout);
this->setFixedSize(276,136);
}
//when the drive has four volumes
if(m_Num == 4)
{
QHBoxLayout *onevolume_h_BoxLayout = new QHBoxLayout();
m_nameDis1_label = new ClickLabel(this);
m_nameDis1_label->setFont(QFont("Microsoft YaHei",fontSize));
QString VolumeNameDis1 = getElidedText(m_nameDis1_label->font(), m_nameDis1, 120);
m_nameDis1_label->setText("- "+VolumeNameDis1+":");
m_nameDis1_label->adjustSize();
m_nameDis1_label->installEventFilter(this);
//m_nameDis1_label->setText("- "+m_nameDis1+":");
m_capacityDis1_label = new QLabel(this);
QString str_capacityDis1 = size_human(m_capacityDis1);
m_capacityDis1_label->setText("("+str_capacityDis1+")");
m_capacityDis1_label->setFont(QFont("Microsoft YaHei",fontSize));
m_capacityDis1_label->setObjectName("capacityLabel");
onevolume_h_BoxLayout->addSpacing(50);
onevolume_h_BoxLayout->setSpacing(0);
onevolume_h_BoxLayout->addWidget(m_nameDis1_label);
onevolume_h_BoxLayout->addWidget(m_capacityDis1_label);
onevolume_h_BoxLayout->addStretch();
onevolume_h_BoxLayout->setMargin(0);
disWidgetNumOne = new QWidget;
disWidgetNumOne->setFixedHeight(30);
disWidgetNumOne->setObjectName("OriginObjectOnly");
disWidgetNumOne->setLayout(onevolume_h_BoxLayout);
disWidgetNumOne->installEventFilter(this);
QHBoxLayout *twovolume_h_BoxLayout = new QHBoxLayout();
m_nameDis2_label = new ClickLabel(this);
m_nameDis2_label->setFont(QFont("Microsoft YaHei",fontSize));
QString VolumeNameDis2 = getElidedText(m_nameDis2_label->font(), m_nameDis2, 120);
m_nameDis2_label->setText("- "+VolumeNameDis2+":");
m_nameDis2_label->installEventFilter(this);
m_nameDis2_label->adjustSize();
m_nameDis2_label->installEventFilter(this);
//m_nameDis2_label->setText("- "+m_nameDis2+":");
m_capacityDis2_label = new QLabel(this);
QString str_capacityDis2 = size_human(m_capacityDis2);
m_capacityDis2_label->setText("("+str_capacityDis2+")");
m_capacityDis2_label->setFont(QFont("Microsoft YaHei",fontSize));
m_capacityDis2_label->setObjectName("capacityLabel");
twovolume_h_BoxLayout->addSpacing(50);
twovolume_h_BoxLayout->setSpacing(0);
twovolume_h_BoxLayout->addWidget(m_nameDis2_label);
twovolume_h_BoxLayout->addWidget(m_capacityDis2_label);
twovolume_h_BoxLayout->addStretch();
twovolume_h_BoxLayout->setMargin(0);
disWidgetNumTwo = new QWidget;
disWidgetNumTwo->setFixedHeight(30);
disWidgetNumTwo->setObjectName("OriginObjectOnly");
disWidgetNumTwo->setLayout(twovolume_h_BoxLayout);
disWidgetNumTwo->installEventFilter(this);
QHBoxLayout *threevolume_h_BoxLayout = new QHBoxLayout();
m_nameDis3_label = new ClickLabel(this);
m_nameDis3_label->setFont(QFont("Microsoft YaHei",fontSize));
QString VolumeNameDis3 = getElidedText(m_nameDis3_label->font(), m_nameDis3, 120);
m_nameDis3_label->setText("- "+VolumeNameDis3+":");
m_nameDis3_label->installEventFilter(this);
m_capacityDis3_label = new QLabel(this);
QString str_capacityDis3 = size_human(m_capacityDis3);
m_capacityDis3_label->setText("("+str_capacityDis3+")");
m_capacityDis3_label->setFont(QFont("Microsoft YaHei",fontSize));
m_capacityDis3_label->setObjectName("capacityLabel");
threevolume_h_BoxLayout->addSpacing(50);
threevolume_h_BoxLayout->setSpacing(0);
threevolume_h_BoxLayout->addWidget(m_nameDis3_label);
threevolume_h_BoxLayout->addWidget(m_capacityDis3_label);
threevolume_h_BoxLayout->addStretch(0);
threevolume_h_BoxLayout->setMargin(0);
disWidgetNumThree = new QWidget;
disWidgetNumThree->setFixedHeight(30);
disWidgetNumThree->setObjectName("OriginObjectOnly");
disWidgetNumThree->setLayout(threevolume_h_BoxLayout);
disWidgetNumThree->installEventFilter(this);
QHBoxLayout *fourvolume_h_BoxLayout = new QHBoxLayout();
m_nameDis4_label = new ClickLabel(this);
m_nameDis4_label->setFont(QFont("Microsoft YaHei",fontSize));
QString VolumeNameDis4 = getElidedText(m_nameDis4_label->font(), m_nameDis4, 120);
m_nameDis4_label->setText("- "+VolumeNameDis4+":");
m_nameDis4_label->adjustSize();
m_nameDis4_label->installEventFilter(this);
//m_nameDis4_label->setText("- "+m_nameDis4+":");
m_capacityDis4_label = new QLabel(this);
QString str_capacityDis4 = size_human(m_capacityDis4);
m_capacityDis4_label->setText("("+str_capacityDis4+")");
m_capacityDis4_label->setFont(QFont("Microsoft YaHei",fontSize));
m_capacityDis4_label->setObjectName("capacityLabel");
fourvolume_h_BoxLayout->addSpacing(50);
fourvolume_h_BoxLayout->setSpacing(0);
fourvolume_h_BoxLayout->addWidget(m_nameDis4_label);
fourvolume_h_BoxLayout->addWidget(m_capacityDis4_label);
fourvolume_h_BoxLayout->addStretch();
fourvolume_h_BoxLayout->setMargin(0);
disWidgetNumFour = new QWidget;
disWidgetNumFour->setFixedHeight(30);
disWidgetNumFour->setObjectName("OriginObjectOnly");
disWidgetNumFour->setLayout(fourvolume_h_BoxLayout);
disWidgetNumFour->installEventFilter(this);
main_V_BoxLayout->setContentsMargins(0,0,0,0);
main_V_BoxLayout->addLayout(drivename_H_BoxLayout);
if(m_pathDis1 != "")
{
main_V_BoxLayout->addWidget(disWidgetNumOne);
}
if(m_pathDis2 != "")
{
main_V_BoxLayout->addWidget(disWidgetNumTwo);
}
if(m_pathDis3 != "")
{
main_V_BoxLayout->addWidget(disWidgetNumThree);
}
if(m_pathDis4 != "")
{
main_V_BoxLayout->addWidget(disWidgetNumFour);
}
this->setLayout(main_V_BoxLayout);
this->setFixedSize(276,165);
}
qDebug()<<"4444";
this->setAttribute(Qt::WA_TranslucentBackground, true);
qDebug()<<"qlcked overeend";
}
void QClickWidget::initFontSize()
{
if (!fontSettings)
{
fontSize = 11;
return;
}
QStringList keys = fontSettings->keys();
if (keys.contains("systemFont") || keys.contains("systemFontSize"))
{
fontSize = fontSettings->get("system-font").toInt();
}
}
void QClickWidget::initThemeMode()
{
if(!qtSettings)
{
currentThemeMode = "ukui-white";
}
QStringList keys = qtSettings->keys();
if(keys.contains("styleName"))
{
currentThemeMode = qtSettings->get("style-name").toString();
}
}
QClickWidget::~QClickWidget()
{
if(chooseDialog)
delete chooseDialog;
if(gpartedface)
delete gpartedface;
}
void QClickWidget::mouseClicked()
{
QProcess::startDetached("peony "+m_pathDis1);
this->topLevelWidget()->hide();
}
void QClickWidget::mousePressEvent(QMouseEvent *ev)
{
mousePos = QPoint(ev->x(), ev->y());
}
void QClickWidget::mouseReleaseEvent(QMouseEvent *ev)
{
if(mousePos == QPoint(ev->x(), ev->y())) Q_EMIT clicked();
}
//click the first area to show the interface
void QClickWidget::on_volume1_clicked()
{
if (!m_pathDis1.isEmpty()) {
QString aaa = "peony "+m_pathDis1;
QProcess::startDetached(aaa.toUtf8().data());
this->topLevelWidget()->hide();
}
}
//click the second area to show the interface
void QClickWidget::on_volume2_clicked()
{
if (!m_pathDis2.isEmpty()) {
QString aaa = "peony "+m_pathDis2;
QProcess::startDetached(aaa.toUtf8().data());
this->topLevelWidget()->hide();
}
}
//click the third area to show the interface
void QClickWidget::on_volume3_clicked()
{
if (!m_pathDis3.isEmpty()) {
QProcess::startDetached("peony "+m_pathDis3);
this->topLevelWidget()->hide();
}
}
//click the forth area to show the interface
void QClickWidget::on_volume4_clicked()
{
if (!m_pathDis4.isEmpty()) {
QProcess::startDetached("peony "+m_pathDis4);
this->topLevelWidget()->hide();
}
}
void QClickWidget::switchWidgetClicked()
{
Q_EMIT clickedConvert();
}
QPixmap QClickWidget::drawSymbolicColoredPixmap(const QPixmap &source)
{
if(currentThemeMode == "ukui-light" || currentThemeMode == "ukui-white")
{
QImage img = source.toImage();
for (int x = 0; x < img.width(); x++)
{
for (int y = 0; y < img.height(); y++)
{
auto color = img.pixelColor(x, y);
if (color.alpha() > 0)
{
color.setRed(0);
color.setGreen(0);
color.setBlue(0);
img.setPixelColor(x, y, color);
}
}
}
return QPixmap::fromImage(img);
}
else if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default" )
{
QImage img = source.toImage();
for (int x = 0; x < img.width(); x++)
{
for (int y = 0; y < img.height(); y++)
{
auto color = img.pixelColor(x, y);
if (color.alpha() > 0)
{
color.setRed(255);
color.setGreen(255);
color.setBlue(255);
img.setPixelColor(x, y, color);
}
}
}
return QPixmap::fromImage(img);
}
else
{
QImage img = source.toImage();
for (int x = 0; x < img.width(); x++)
{
for (int y = 0; y < img.height(); y++)
{
auto color = img.pixelColor(x, y);
if (color.alpha() > 0)
{
color.setRed(0);
color.setGreen(0);
color.setBlue(0);
img.setPixelColor(x, y, color);
}
}
}
return QPixmap::fromImage(img);
}
}
//to convert the capacity by another type
QString QClickWidget::size_human(qlonglong capacity)
{
// float capacity = this->size();
if(capacity != 0 && capacity != 1)
{
int conversionNum = 0;
QStringList list;
list << "KB" << "MB" << "GB" << "TB";
QStringListIterator i(list);
QString unit("bytes");
qlonglong conversion = capacity;
while(conversion >= 1000.0 && i.hasNext())
{
unit = i.next();
conversion /= 1000.0;
conversionNum++;
}
qlonglong remain = capacity - conversion * qPow(1000,conversionNum);
float showRemain;
if(conversionNum == 3)
{
showRemain = (float)remain /1000/1000/1000;
}
if(conversionNum == 2)
{
showRemain = (float)remain /1000/1000;
}
if(conversionNum == 1)
{
showRemain = (float)remain /1000;
}
double showValue = conversion + showRemain;
QString str2=QString::number(showValue,'f',1);
QString str_capacity=QString(" %1%2").arg(str2).arg(unit);
return str_capacity;
// return QString().setNum(capacity,'f',2)+" "+unit;
}
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
if(capacity == NULL)
{
QString str_capaticity = tr("the capacity is empty");
return str_capaticity;
}
#endif
if(capacity == 1)
{
QString str_capacity = tr("blank CD");
return str_capacity;
}
QString str_capacity = tr("other user device");
return str_capacity;
}
//set the style of the eject button and label when the mouse doing some different operations
bool QClickWidget::eventFilter(QObject *obj, QEvent *event)
{
if(obj == m_eject_button)
{
if(event->type() == QEvent::MouseButtonPress)
{
if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default")
{
m_eject_button->setIconSize(QSize(14,14));
m_eject_button->setFixedSize(38,38);
m_eject_button->setStyleSheet(
"background:rgba(255,255,255,0.08);"
"border-radius:4px;"
);
}
else
{
m_eject_button->setIconSize(QSize(14,14));
m_eject_button->setFixedSize(38,38);
m_eject_button->setStyleSheet(
"background:rgba(0,0,0,0.08);"
"border-radius:4px;"
);
}
}
if(event->type() == QEvent::Enter)
{
if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default")
{
m_eject_button->setIconSize(QSize(16,16));
m_eject_button->setFixedSize(40,40);
m_eject_button->setStyleSheet(
"background-color:rgba(255,255,255,0.91);"
"background:rgba(255,255,255,0.12);"
"border-radius:4px;");
}
else
{
m_eject_button->setIconSize(QSize(16,16));
m_eject_button->setFixedSize(40,40);
m_eject_button->setStyleSheet(
"background-color:rgba(0,0,0,0.91);"
"background:rgba(0,0,0,0.12);"
"border-radius:4px;");
}
}
if(event->type() == QEvent::Leave)
{
if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black")
{
m_eject_button->setIconSize(QSize(16,16));
m_eject_button->setFixedSize(40,40);
m_eject_button->setStyleSheet(
"background-color:rgba(255,255,255,0.75);"
"background-color:rgba(255,255,255,0.57);"
"background:rgba(255,255,255,0);"
"border-radius:4px;");
}
else
{
m_eject_button->setIconSize(QSize(16,16));
m_eject_button->setFixedSize(40,40);
m_eject_button->setStyleSheet(
"background-color:rgba(0,0,0,0.75);"
"background-color:rgba(0,0,0,0.57);"
"background:rgba(0,0,0,0);"
"border-radius:4px;");
}
}
}
if(obj == disWidgetNumOne)
{
if(event->type() == QEvent::Enter)
{
if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default")
{
disWidgetNumOne->setStyleSheet(
"QWidget#OriginObjectOnly{background:rgba(255,255,255,0.12);}");
}
else
{
disWidgetNumOne->setStyleSheet(
"QWidget#OriginObjectOnly{background:rgba(0,0,0,0.12);}");
}
}
if(event->type() == QEvent::Leave)
{
disWidgetNumOne->setStyleSheet("");
}
if(event->type() == QEvent::MouseButtonPress)
{
on_volume1_clicked();
}
}
if(obj == disWidgetNumTwo)
{
if(event->type() == QEvent::Enter )
{
if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default")
{
disWidgetNumTwo->setStyleSheet(
"QWidget#OriginObjectOnly{background:rgba(255,255,255,0.12);}");
}
else
{
disWidgetNumTwo->setStyleSheet(
"QWidget#OriginObjectOnly{background:rgba(0,0,0,0.12);}");
}
}
if(event->type() == QEvent::Leave)
{
disWidgetNumTwo->setStyleSheet("");
}
if(event->type() == QEvent::MouseButtonPress)
{
on_volume2_clicked();
}
}
if(obj == disWidgetNumThree)
{
if(event->type() == QEvent::Enter )
{
if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default")
{
disWidgetNumThree->setStyleSheet(
"QWidget#OriginObjectOnly{background:rgba(255,255,255,0.12);}");
}
else
{
disWidgetNumThree->setStyleSheet(
"QWidget#OriginObjectOnly{background:rgba(0,0,0,0.12);}");
}
}
if(event->type() == QEvent::Leave)
{
disWidgetNumThree->setStyleSheet("");
}
if(event->type() == QEvent::MouseButtonPress)
{
on_volume3_clicked();
}
}
if(obj == disWidgetNumFour)
{
if(event->type() == QEvent::Enter )
{
if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black" || currentThemeMode == "ukui-default")
{
disWidgetNumFour->setStyleSheet(
"QWidget#OriginObjectOnly{background:rgba(255,255,255,0.12);}");
}
else
{
disWidgetNumFour->setStyleSheet(
"QWidget#OriginObjectOnly{background:rgba(0,0,0,0.12);}");
}
}
if(event->type() == QEvent::Leave)
{
disWidgetNumFour->setStyleSheet("");
}
if(event->type() == QEvent::MouseButtonPress)
{
on_volume4_clicked();
}
}
return false;
}
void QClickWidget::resizeEvent(QResizeEvent *event)
{
}

141
src/qclickwidget.h Normal file
View File

@ -0,0 +1,141 @@
/*
* Copyright: 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program or library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef QCLICKWIDGET_H
#define QCLICKWIDGET_H
#include <QWidget>
#include <QProcess>
#include <QDebug>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QStyle>
#include <QStyleOption>
#include <QPainter>
#include <QLabel>
#include <QBoxLayout>
#include <QPushButton>
#include <qgsettings.h>
#include "ejectInterface.h"
#include "clickLabel.h"
#include "UnionVariable.h"
#include "interactivedialog.h"
#include "gpartedinterface.h"
class MainWindow;
class QClickWidget : public QWidget
{
Q_OBJECT
public:
explicit QClickWidget(QWidget *parent = nullptr,
int num = 0,
GDrive *Drive=NULL,
GVolume *Volume=NULL,
QString driveName=NULL,
QString nameDis1=NULL,
QString nameDis2 =NULL,
QString nameDis3 = NULL,
QString nameDis4 = NULL,
qlonglong capacityDis1=0,
qlonglong capacityDis2=0,
qlonglong capacityDis3=0,
qlonglong capacityDis4=0,
QString pathDis1=NULL,
QString pathDis2=NULL,
QString pathDis3=NULL,
QString pathDis4=NULL);
~QClickWidget();
public Q_SLOTS:
void mouseClicked();
protected:
void mousePressEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev);
//void paintEvent(QPaintEvent *);
private:
QIcon imgIcon;
QString m_driveName;
QString m_nameDis1;
QString m_nameDis2;
QString m_nameDis3;
QString m_nameDis4;
qlonglong m_capacityDis1;
qlonglong m_capacityDis2;
qlonglong m_capacityDis3;
qlonglong m_capacityDis4;
QString m_pathDis1;
QString m_pathDis2;
QString m_pathDis3;
QString m_pathDis4;
MainWindow *m_mainwindow;
QPoint mousePos;
int m_Num;
GDrive *m_Drive;
QLabel *image_show_label;
QLabel *m_driveName_label;
ClickLabel *m_nameDis1_label;
ClickLabel *m_nameDis2_label;
ClickLabel *m_nameDis3_label;
ClickLabel *m_nameDis4_label;
QLabel *m_capacityDis1_label;
QLabel *m_capacityDis2_label;
QLabel *m_capacityDis3_label;
QLabel *m_capacityDis4_label;
QWidget *disWidgetNumOne;
QWidget *disWidgetNumTwo;
QWidget *disWidgetNumThree;
QWidget *disWidgetNumFour;
QGSettings *fontSettings = nullptr;
QGSettings *qtSettings = nullptr;
int fontSize;
QString currentThemeMode;
public:
QPushButton *m_eject_button = nullptr;
ejectInterface *m_eject = nullptr;
interactiveDialog *chooseDialog = nullptr;
gpartedInterface *gpartedface = nullptr;
bool ifSucess;
int flagType;
Q_SIGNALS:
void clicked();
void clickedConvert();
void noDeviceSig();
private Q_SLOTS:
void on_volume1_clicked();
void on_volume2_clicked();
void on_volume3_clicked();
void on_volume4_clicked();
void switchWidgetClicked();
private:
QString size_human(qlonglong capacity);
QPixmap drawSymbolicColoredPixmap(const QPixmap &source);
protected:
bool eventFilter(QObject *obj, QEvent *event);
void resizeEvent(QResizeEvent *event);
public:
void initFontSize();
void initThemeMode();
};
#endif

1627
src/repair-dialog-box.cpp Normal file

File diff suppressed because it is too large Load Diff

216
src/repair-dialog-box.h Normal file
View File

@ -0,0 +1,216 @@
/*
* Copyright (C) 2021 KylinSoft Co., Ltd.
*
* Authors:
* Ding Jing dingjing@kylinos.cn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef REPAIRDIALOGBOX_H
#define REPAIRDIALOGBOX_H
#include <QDialog>
#include <QCheckBox>
#include <QComboBox>
#include <QProgressBar>
#include <QTimer>
#include <QThread>
#include <QLabel>
#include <QLineEdit>
#include <QWidget>
#include <QMessageBox>
#include <QProxyStyle>
#include <gio/gio.h>
#include "device-operation.h"
#include "flashdiskdata.h"
#include "MacroFile.h"
class QGSettings;
class QDBusConnection;
class RepairProgressBar;
class BaseDialogStyle : public QProxyStyle
{
Q_OBJECT
public:
static BaseDialogStyle* getStyle();
public:
void polish (QWidget* w) override;
void drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const override;
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const override;
void drawPrimitive(PrimitiveElement elem, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override;
void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const override;
private:
BaseDialogStyle ();
~BaseDialogStyle ();
private:
QPalette mPalette;
static BaseDialogStyle* gInstance;
};
class BaseDialog : public QDialog
{
Q_OBJECT
public:
explicit BaseDialog(QWidget *parent = nullptr);
QPalette getPalette();
QPalette getBlackPalette();
QPalette getWhitePalette();
void setTheme();
Q_SIGNALS:
void themeChanged ();
private:
QGSettings* mGSettings = nullptr;
};
class RepairDialogBox : public BaseDialog
{
Q_OBJECT
public:
explicit RepairDialogBox(GDrive* drive, QWidget *parent = nullptr);
explicit RepairDialogBox(GVolume* volume, QWidget *parent = nullptr);
QString getDeviceName ();
static bool mshowflag;
~RepairDialogBox();
public Q_SLOTS:
void onRemountDevice();
private:
void initUI();
void isRunning(bool running = false);
static void drive_disconnected_callback(GVolumeMonitor* monitor, GDrive* drive, RepairDialogBox* pThis);
Q_SIGNALS:
void repairOK (RepairDialogBox*);
void remountDevice(FDVolumeInfo volumeInfo);
private:
bool mRepair = false;
bool mFormat = false;
const int mFixWidth = 480;
const int mFixHeight = 240;
gulong mVMConnect = 0;
QPushButton* mRepairBtn = nullptr;
QPushButton* mFormatBtn = nullptr;
QString mDeviceName = nullptr;
GDrive* mDrive = nullptr;
GVolume* mVolume = nullptr;
};
class RepairProgressBar : public BaseDialog
{
Q_OBJECT
public:
explicit RepairProgressBar(GDrive* drive, QWidget* parent = nullptr);
explicit RepairProgressBar(GVolume* volume, QWidget* parent = nullptr);
~RepairProgressBar();
int exec() override;
void onStopRepair(bool);
void onStartRepair();
private:
void initUI ();
Q_SIGNALS:
void cancel();
void startRepair();
void remountDevice();
private:
int mProcess = 0;
const int mFixWidth = 480;
const int mFixHeight = 240;
QTimer* mTimer = nullptr;
QProgressBar* mProgress = nullptr;
QPushButton* mCancelBtn = nullptr;
QThread* mThread = nullptr;
DeviceOperation* mDeviceOperation = nullptr;
GDrive* mDrive = nullptr;
GVolume* mVolume = nullptr;
};
class FormateDialog : public BaseDialog
{
Q_OBJECT
public:
explicit FormateDialog(GDrive* drive, QWidget *parent = nullptr);
explicit FormateDialog(GVolume* drive, QWidget *parent = nullptr);
~FormateDialog();
int exec() override;
void onStopFormat(bool);
void onStartFormat();
private:
void initUI();
Q_SIGNALS:
void cancel();
void startFormat(QString type, QString labelName);
private:
const int mFixWidth = 480;
const int mFixHeight = 440;
QTimer* mTimer = nullptr;
QComboBox* mFSCombox = nullptr;
QProgressBar* mProgress = nullptr;
QPushButton* mCancelBtn = nullptr;
QPushButton* mFormatBtn = nullptr;
QCheckBox* mEraseCkbox = nullptr;
QLineEdit* mNameEdit = nullptr;
QComboBox* mRomSizeCombox = nullptr;
QThread* mThread = nullptr;
DeviceOperation* mDeviceOperation = nullptr;
GDrive* mDrive = nullptr;
GVolume* mVolume = nullptr;
};
// tip dialog
class MessageBox : public BaseDialog
{
Q_OBJECT
public:
MessageBox(QString title, QString text, QMessageBox::StandardButtons bt, QWidget* parent = nullptr);
Q_SIGNALS:
void format();
};
#endif // REPAIRDIALOGBOX_H

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "repair-dialog-box.h"
#include <QDebug>
#include <QApplication>
#include <QMessageBox>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
GDrive* test = nullptr;
RepairDialogBox box(test);
box.show();
// RepairProgressBar test(QObject::tr("正在进行磁盘修复..."));
// test.exec();
// FormateDialog test(nullptr);
// test.exec();
return app.exec();
}

69
src/ui_mainwindow.h Normal file
View File

@ -0,0 +1,69 @@
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, 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 <http://www.gnu.org/licenses/&gt;.
*
*/
/********************************************************************************
** Form generated from reading UI file 'mainwindow.ui'
**
** Created by: Qt User Interface Compiler version 5.12.5
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QWidget>
#include "fdframe.h"
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
FDFrame *centralWidget;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(400, 300);
centralWidget = new FDFrame(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
MainWindow->setCentralWidget(centralWidget);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H

View File

@ -0,0 +1,339 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="bo_CN">
<context>
<name>BaseDialog</name>
<message>
<source>Disk test</source>
<translation></translation>
</message>
</context>
<context>
<name>DeviceOperation</name>
<message>
<source>unknown</source>
<translation></translation>
</message>
</context>
<context>
<name>FDClickWidget</name>
<message>
<source>the capacity is empty</source>
<translation></translation>
</message>
<message>
<source>blank CD</source>
<translation></translation>
</message>
<message>
<source>other user device</source>
<translation></translation>
</message>
<message>
<source>another device</source>
<translation type="obsolete"></translation>
</message>
<message>
<source>Eject</source>
<translation></translation>
</message>
<message>
<source>Unmounted</source>
<translation></translation>
</message>
</context>
<context>
<name>FDFrame</name>
<message>
<source>eject</source>
<translation></translation>
</message>
</context>
<context>
<name>FormateDialog</name>
<message>
<source>Formatted successfully!</source>
<translation></translation>
</message>
<message>
<source>Formatting failed, please unplug the U disk and try again!</source>
<translation></translation>
</message>
<message>
<source>Format</source>
<translation></translation>
</message>
<message>
<source>Rom size:</source>
<translation>Rom </translation>
</message>
<message>
<source>Filesystem:</source>
<translation></translation>
</message>
<message>
<source>Disk name:</source>
<translation></translation>
</message>
<message>
<source>Completely erase(Time is longer, please confirm!)</source>
<translation> ( )</translation>
</message>
<message>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<source>Format disk</source>
<translation></translation>
</message>
<message>
<source>Formatting this volume will erase all data on it. Please back up all retained data before formatting. Do you want to continue?</source>
<translation> </translation>
</message>
<message>
<source>Disk test</source>
<translation type="obsolete">U盘检测</translation>
</message>
<message>
<source>Disk format</source>
<translation></translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
<source>usb management tool</source>
<translation>usb </translation>
</message>
<message>
<source>ukui-flash-disk</source>
<translation type="vanished">U盘管理工具</translation>
</message>
<message>
<source>kindly reminder</source>
<translation></translation>
</message>
<message>
<source>wrong reminder</source>
<translation></translation>
</message>
<message>
<source>Please do not pull out the USB flash disk when reading or writing</source>
<translation></translation>
</message>
<message>
<source>Please do not pull out the CDROM when reading or writing</source>
<translation>CDROMཕྱིར</translation>
</message>
<message>
<source>Please do not pull out the SD Card when reading or writing</source>
<translation>SD Cardམ</translation>
</message>
<message>
<source>There is a problem with this device</source>
<translation type="obsolete"></translation>
</message>
<message>
<source>telephone device</source>
<translation></translation>
</message>
<message>
<source>Removable storage device removed</source>
<translation type="vanished"></translation>
</message>
<message>
<source>Please do not pull out the storage device when reading or writing</source>
<translation></translation>
</message>
<message>
<source>Storage device removed</source>
<translation></translation>
</message>
<message>
<source>MainWindow</source>
<translation>MainWindow</translation>
</message>
<message>
<source>ukui flash disk</source>
<translation type="vanished">U盘管理工具</translation>
</message>
<message>
<source>kylin device daemon</source>
<translation></translation>
</message>
</context>
<context>
<name>MessageBox</name>
<message>
<source>OK</source>
<translation></translation>
</message>
<message>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<source>Format</source>
<translation></translation>
</message>
</context>
<context>
<name>QClickWidget</name>
<message>
<source>the capacity is empty</source>
<translation></translation>
</message>
<message>
<source>blank CD</source>
<translation></translation>
</message>
<message>
<source>other user device</source>
<translation></translation>
</message>
<message>
<source>another device</source>
<translation type="obsolete"></translation>
</message>
<message>
<source>Unmounted</source>
<translation></translation>
</message>
<message>
<source></source>
<translation></translation>
</message>
</context>
<context>
<name>RepairDialogBox</name>
<message>
<source>Disk test</source>
<translation></translation>
</message>
<message>
<source>&lt;h4&gt;The system could not recognize the disk contents&lt;/h4&gt;&lt;p&gt;Check that the disk and drive are properly connected, make sure the disk is not a read-only disk, and try again. For more information, search for help on read-only files and how to change read-only files.&lt;/p&gt;</source>
<translation type="vanished">&lt;h4&gt;U盘内容&lt;/h4&gt;&lt;p&gt;&lt;/p&gt;</translation>
</message>
<message>
<source>Format disk</source>
<translation></translation>
</message>
<message>
<source>Repair</source>
<translation></translation>
</message>
<message>
<source>&lt;h4&gt;The system could not recognize the disk contents&lt;/h4&gt;&lt;p&gt;Check that the disk/drive is properly connected,make sure the disk is not a read-only disk, and try again.For more information, search for help on read-only files andhow to change read-only files.&lt;/p&gt;</source>
<translation>&lt;h4&gt; &lt;/h4&gt;&lt;p&gt;&lt;p&gt; &lt;/p&gt;</translation>
</message>
<message>
<source>&lt;h4&gt;The system could not recognize the disk contents&lt;/h4&gt;&lt;p&gt;Check that the disk/drive &apos;%1&apos; is properly connected,make sure the disk is not a read-only disk, and try again.For more information, search for help on read-only files andhow to change read-only files.&lt;/p&gt;</source>
<translation>&lt;h4&gt; &lt;/h4&gt;&lt;p&gt;&lt;p&gt;&apos;%1&apos; &lt;/p&gt;</translation>
</message>
</context>
<context>
<name>RepairProgressBar</name>
<message>
<source>&lt;h3&gt;%1&lt;/h3&gt;</source>
<translation>&lt;h3&gt;%1&lt;/h3&gt;</translation>
</message>
<message>
<source>Attempting a disk repair...</source>
<translation></translation>
</message>
<message>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<source>Repair successfully!</source>
<translation></translation>
</message>
<message>
<source>The repair completed. If the USB flash disk is not mounted, please try formatting the device!</source>
<translation type="vanished"></translation>
</message>
<message>
<source>Disk test</source>
<translation type="obsolete">U盘检测</translation>
</message>
<message>
<source>Disk repair</source>
<translation></translation>
</message>
<message>
<source>Repair failed. If the USB flash disk is not mounted, please try formatting the device!</source>
<translation> </translation>
</message>
</context>
<context>
<name>ejectInterface</name>
<message>
<source>usb has been unplugged safely</source>
<translation type="vanished">U盘已安全拔出</translation>
</message>
<message>
<source>cdrom has been unplugged safely</source>
<translation type="vanished"></translation>
</message>
<message>
<source>sd has been unplugged safely</source>
<translation type="vanished">SD卡已安全拔出</translation>
</message>
<message>
<source>usb is occupying unejectable</source>
<translation type="vanished">U盘占用无法弹出</translation>
</message>
<message>
<source>Storage device can be safely unplugged</source>
<translation></translation>
</message>
</context>
<context>
<name>gpartedInterface</name>
<message>
<source>ok</source>
<translation></translation>
</message>
<message>
<source>gparted has started,can not eject</source>
<translation></translation>
</message>
</context>
<context>
<name>interactiveDialog</name>
<message>
<source>usb is occupying,do you want to eject it</source>
<translation>usbབཙན </translation>
</message>
<message>
<source>cdrom is occupying,do you want to eject it</source>
<translation>cdromབཙན </translation>
</message>
<message>
<source>sd is occupying,do you want to eject it</source>
<translation>sdནི </translation>
</message>
<message>
<source>cancle</source>
<translation></translation>
</message>
<message>
<source>yes</source>
<translation></translation>
</message>
<message>
<source>cdrom is occupying</source>
<translation>cdromནི</translation>
</message>
<message>
<source>sd is occupying</source>
<translation>sdནི</translation>
</message>
<message>
<source>usb is occupying</source>
<translation>usbབདག</translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,295 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="tr" sourcelanguage="tr">
<context>
<name>BaseDialog</name>
<message>
<source>Disk test</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DeviceOperation</name>
<message>
<source>unknown</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FDClickWidget</name>
<message>
<source>the capacity is empty</source>
<translation>Kapasite boş</translation>
</message>
<message>
<source>blank CD</source>
<translation type="unfinished">blank CD</translation>
</message>
<message>
<source>other user device</source>
<translation type="unfinished">other user device</translation>
</message>
<message>
<source>another device</source>
<translation type="obsolete">another device</translation>
</message>
<message>
<source>Eject</source>
<translation>Çıkar</translation>
</message>
<message>
<source>Unmounted</source>
<translation type="unfinished">Unmounted</translation>
</message>
</context>
<context>
<name>FDFrame</name>
<message>
<source>eject</source>
<translation type="unfinished">Çıkar</translation>
</message>
</context>
<context>
<name>FormateDialog</name>
<message>
<source>Formatted successfully!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Formatting failed, please unplug the U disk and try again!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Format</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Rom size:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Filesystem:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Disk name:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Completely erase(Time is longer, please confirm!)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Format disk</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Formatting this volume will erase all data on it. Please back up all retained data before formatting. Do you want to continue?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Disk format</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
<source>usb management tool</source>
<translation>Usb yönetim aracı</translation>
</message>
<message>
<source>kindly reminder</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>wrong reminder</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please do not pull out the CDROM when reading or writing</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please do not pull out the SD Card when reading or writing</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please do not pull out the USB flash disk when reading or writing</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>telephone device</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please do not pull out the storage device when reading or writing</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Storage device removed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>MainWindow</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>kylin device daemon</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MessageBox</name>
<message>
<source>OK</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Format</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QClickWidget</name>
<message>
<source>eject</source>
<translation type="vanished">Çıkar</translation>
</message>
<message>
<source>the capacity is empty</source>
<translation>Kapasite boş</translation>
</message>
<message>
<source>Unmounted</source>
<translation type="unfinished">Unmounted</translation>
</message>
<message>
<source>blank CD</source>
<translation type="unfinished">blank CD</translation>
</message>
<message>
<source>other user device</source>
<translation type="unfinished">other user device</translation>
</message>
<message>
<source></source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RepairDialogBox</name>
<message>
<source>Disk test</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Format disk</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Repair</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;h4&gt;The system could not recognize the disk contents&lt;/h4&gt;&lt;p&gt;Check that the disk/drive is properly connected,make sure the disk is not a read-only disk, and try again.For more information, search for help on read-only files andhow to change read-only files.&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;h4&gt;The system could not recognize the disk contents&lt;/h4&gt;&lt;p&gt;Check that the disk/drive &apos;%1&apos; is properly connected,make sure the disk is not a read-only disk, and try again.For more information, search for help on read-only files andhow to change read-only files.&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RepairProgressBar</name>
<message>
<source>&lt;h3&gt;%1&lt;/h3&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Attempting a disk repair...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Repair successfully!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Disk repair</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Repair failed. If the USB flash disk is not mounted, please try formatting the device!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ejectInterface</name>
<message>
<source>usb has been unplugged safely</source>
<translation type="vanished">USB güvenli bir şekilde çıkarıldı</translation>
</message>
<message>
<source>Storage device can be safely unplugged</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>gpartedInterface</name>
<message>
<source>gparted has started,can not eject</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>ok</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>interactiveDialog</name>
<message>
<source>cdrom is occupying,do you want to eject it</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sd is occupying,do you want to eject it</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>usb is occupying,do you want to eject it</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>cancle</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>yes</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>cdrom is occupying</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sd is occupying</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>usb is occupying</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,339 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>BaseDialog</name>
<message>
<source>Disk test</source>
<translation></translation>
</message>
</context>
<context>
<name>DeviceOperation</name>
<message>
<source>unknown</source>
<translation></translation>
</message>
</context>
<context>
<name>FDClickWidget</name>
<message>
<source>the capacity is empty</source>
<translation></translation>
</message>
<message>
<source>blank CD</source>
<translation></translation>
</message>
<message>
<source>other user device</source>
<translation></translation>
</message>
<message>
<source>another device</source>
<translation type="obsolete"></translation>
</message>
<message>
<source>Eject</source>
<translation></translation>
</message>
<message>
<source>Unmounted</source>
<translation></translation>
</message>
</context>
<context>
<name>FDFrame</name>
<message>
<source>eject</source>
<translation></translation>
</message>
</context>
<context>
<name>FormateDialog</name>
<message>
<source>Formatted successfully!</source>
<translation></translation>
</message>
<message>
<source>Formatting failed, please unplug the U disk and try again!</source>
<translation></translation>
</message>
<message>
<source>Format</source>
<translation></translation>
</message>
<message>
<source>Rom size:</source>
<translation></translation>
</message>
<message>
<source>Filesystem:</source>
<translation></translation>
</message>
<message>
<source>Disk name:</source>
<translation></translation>
</message>
<message>
<source>Completely erase(Time is longer, please confirm!)</source>
<translation></translation>
</message>
<message>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<source>Format disk</source>
<translation></translation>
</message>
<message>
<source>Formatting this volume will erase all data on it. Please back up all retained data before formatting. Do you want to continue?</source>
<translation></translation>
</message>
<message>
<source>Disk test</source>
<translation type="obsolete">U盘检测</translation>
</message>
<message>
<source>Disk format</source>
<translation></translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
<source>usb management tool</source>
<translation>U盘管理工具</translation>
</message>
<message>
<source>ukui-flash-disk</source>
<translation type="vanished">U盘管理工具</translation>
</message>
<message>
<source>kindly reminder</source>
<translation></translation>
</message>
<message>
<source>wrong reminder</source>
<translation></translation>
</message>
<message>
<source>Please do not pull out the USB flash disk when reading or writing</source>
<translation></translation>
</message>
<message>
<source>Please do not pull out the CDROM when reading or writing</source>
<translation></translation>
</message>
<message>
<source>Please do not pull out the SD Card when reading or writing</source>
<translation>SD卡读写时请不要直接拔出</translation>
</message>
<message>
<source>There is a problem with this device</source>
<translation type="obsolete"></translation>
</message>
<message>
<source>telephone device</source>
<translation></translation>
</message>
<message>
<source>Removable storage device removed</source>
<translation type="vanished"></translation>
</message>
<message>
<source>Please do not pull out the storage device when reading or writing</source>
<translation></translation>
</message>
<message>
<source>Storage device removed</source>
<translation></translation>
</message>
<message>
<source>MainWindow</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>ukui flash disk</source>
<translation type="vanished">U盘管理工具</translation>
</message>
<message>
<source>kylin device daemon</source>
<translation>U盘管理工具</translation>
</message>
</context>
<context>
<name>MessageBox</name>
<message>
<source>OK</source>
<translation></translation>
</message>
<message>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<source>Format</source>
<translation></translation>
</message>
</context>
<context>
<name>QClickWidget</name>
<message>
<source>the capacity is empty</source>
<translation></translation>
</message>
<message>
<source>blank CD</source>
<translation></translation>
</message>
<message>
<source>other user device</source>
<translation></translation>
</message>
<message>
<source>another device</source>
<translation type="obsolete"></translation>
</message>
<message>
<source>Unmounted</source>
<translation></translation>
</message>
<message>
<source></source>
<translation></translation>
</message>
</context>
<context>
<name>RepairDialogBox</name>
<message>
<source>Disk test</source>
<translation></translation>
</message>
<message>
<source>&lt;h4&gt;The system could not recognize the disk contents&lt;/h4&gt;&lt;p&gt;Check that the disk and drive are properly connected, make sure the disk is not a read-only disk, and try again. For more information, search for help on read-only files and how to change read-only files.&lt;/p&gt;</source>
<translation type="vanished">&lt;h4&gt;U盘内容&lt;/h4&gt;&lt;p&gt;&lt;/p&gt;</translation>
</message>
<message>
<source>Format disk</source>
<translation></translation>
</message>
<message>
<source>Repair</source>
<translation></translation>
</message>
<message>
<source>&lt;h4&gt;The system could not recognize the disk contents&lt;/h4&gt;&lt;p&gt;Check that the disk/drive is properly connected,make sure the disk is not a read-only disk, and try again.For more information, search for help on read-only files andhow to change read-only files.&lt;/p&gt;</source>
<translation>&lt;h4&gt;&lt;/h4&gt;&lt;p&gt;/&lt;/p&gt;</translation>
</message>
<message>
<source>&lt;h4&gt;The system could not recognize the disk contents&lt;/h4&gt;&lt;p&gt;Check that the disk/drive &apos;%1&apos; is properly connected,make sure the disk is not a read-only disk, and try again.For more information, search for help on read-only files andhow to change read-only files.&lt;/p&gt;</source>
<translation>&lt;h4&gt;&lt;/h4&gt;&lt;p&gt;/ &quot;%1&quot; &lt;/p&gt;</translation>
</message>
</context>
<context>
<name>RepairProgressBar</name>
<message>
<source>&lt;h3&gt;%1&lt;/h3&gt;</source>
<translation>&lt;h3&gt;%1&lt;/h3&gt;</translation>
</message>
<message>
<source>Attempting a disk repair...</source>
<translation>...</translation>
</message>
<message>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<source>Repair successfully!</source>
<translation></translation>
</message>
<message>
<source>The repair completed. If the USB flash disk is not mounted, please try formatting the device!</source>
<translation type="vanished"></translation>
</message>
<message>
<source>Disk test</source>
<translation type="obsolete">U盘检测</translation>
</message>
<message>
<source>Disk repair</source>
<translation></translation>
</message>
<message>
<source>Repair failed. If the USB flash disk is not mounted, please try formatting the device!</source>
<translation></translation>
</message>
</context>
<context>
<name>ejectInterface</name>
<message>
<source>usb has been unplugged safely</source>
<translation type="vanished">U盘已安全拔出</translation>
</message>
<message>
<source>cdrom has been unplugged safely</source>
<translation type="vanished"></translation>
</message>
<message>
<source>sd has been unplugged safely</source>
<translation type="vanished">SD卡已安全拔出</translation>
</message>
<message>
<source>usb is occupying unejectable</source>
<translation type="vanished">U盘占用无法弹出</translation>
</message>
<message>
<source>Storage device can be safely unplugged</source>
<translation></translation>
</message>
</context>
<context>
<name>gpartedInterface</name>
<message>
<source>ok</source>
<translation></translation>
</message>
<message>
<source>gparted has started,can not eject</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>interactiveDialog</name>
<message>
<source>usb is occupying,do you want to eject it</source>
<translation>U盘正在占用中</translation>
</message>
<message>
<source>cdrom is occupying,do you want to eject it</source>
<translation></translation>
</message>
<message>
<source>sd is occupying,do you want to eject it</source>
<translation>SD卡正在占用中</translation>
</message>
<message>
<source>cancle</source>
<translation></translation>
</message>
<message>
<source>yes</source>
<translation></translation>
</message>
<message>
<source>cdrom is occupying</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sd is occupying</source>
<translation type="unfinished">SD卡正在占用中</translation>
</message>
<message>
<source>usb is occupying</source>
<translation type="unfinished">U盘正在占用中</translation>
</message>
</context>
</TS>