removed some windows and apple cruft

This commit is contained in:
Ivailo Monev 2014-11-17 00:52:07 +00:00
parent e0b7d38f81
commit e60c979750
89 changed files with 121 additions and 9495 deletions

View file

@ -16,10 +16,6 @@ set (KDE_VERSION_STRING "${KDE_VERSION}")
set (KDE_DISTRIBUTION_TEXT "compiled sources" CACHE STRING "Indicate the distribution in bug reports" )
# win32: give kde home in debug mode a different name as the release home dir because the settings and caches are different
if (WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
set (_KDE_DEFAULT_HOME_POSTFIX "-debug" CACHE STRING "default KDE home directory postfix" )
endif (WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
set (KDE_DEFAULT_HOME ".kde${_KDE_DEFAULT_HOME_POSTFIX}" CACHE STRING "The default KDE home directory" )
# this must be before FindKDE4Internal in order to preset the result of the visibility test, so that it will be skipped
@ -81,17 +77,10 @@ set_package_properties(ZLIB PROPERTIES DESCRIPTION "Support for gzip compressed
)
find_package(Strigi 0.6.3)
if (WIN32)
set (STRIGI_TYPE "OPTIONAL")
set (STRIGI_EXTRA_TEXT "")
else (WIN32)
set (STRIGI_TYPE "REQUIRED")
set (STRIGI_EXTRA_TEXT "Required by some critical kioslaves")
endif (WIN32)
set_package_properties(Strigi PROPERTIES DESCRIPTION "Desktop indexing and search support"
URL "http://strigi.sourceforge.net"
TYPE ${STRIGI_TYPE}
PURPOSE ${STRIGI_EXTRA_TEXT}
TYPE REQUIRED
PURPOSE "Required by some critical kioslaves"
)
find_package(LibAttica 0.4.2)
@ -176,9 +165,7 @@ endif(QCA2_FOUND)
set(KDE4_KJS_INCLUDES ${CMAKE_SOURCE_DIR}/kjs
${CMAKE_BINARY_DIR}/kjs)
if(NOT WINCE)
set(KDE4_KDECORE_INCLUDES ${KDE4_KJS_INCLUDES} )
endif(NOT WINCE)
set(KDE4_KDECORE_INCLUDES ${KDE4_KJS_INCLUDES} )
# kdecore depends on Qt (need only headers from kjs)
set(KDE4_KDECORE_INCLUDES ${KDE4_KDECORE_INCLUDES}
@ -237,18 +224,11 @@ set(KDE4_KPTY_INCLUDES ${CMAKE_SOURCE_DIR}/kpty ${KDE4_KIO_INCLUDES} )
set(KDE4_KPARTS_INCLUDES ${CMAKE_SOURCE_DIR}/kparts
${KDE4_KIO_INCLUDES})
if(NOT WINCE)
set(KDE4_KHTML_INCLUDES ${CMAKE_SOURCE_DIR}/khtml)
endif(NOT WINCE)
set(KDE4_KHTML_INCLUDES ${CMAKE_SOURCE_DIR}/khtml)
################# configure checks and create the configured files #################
if(WINCE)
set(STATIC_LIBRARY ON)
add_definitions(-DSTATIC_INSTALL_PATH=L\\\"/programme/kde\\\")
endif(WINCE)
if(STATIC_LIBRARY)
set(LIBRARY_TYPE STATIC)
add_definitions(-DKDELIBS_STATIC_LIBS)
@ -257,7 +237,6 @@ else(STATIC_LIBRARY)
set(LIBRARY_TYPE SHARED)
endif(STATIC_LIBRARY)
if(NOT WIN32)
# ACL stuff (used in kio/ and kioslaves/)
macro_optional_find_package(ACL)
set_package_properties(ACL PROPERTIES DESCRIPTION "Support for manipulating access control lists"
@ -267,7 +246,6 @@ set_package_properties(ACL PROPERTIES DESCRIPTION "Support for manipulating acce
)
macro_bool_to_01(ACL_FOUND HAVE_LIBACL HAVE_POSIX_ACL)
endif()
configure_file(config-acl.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-acl.h )
include(ConfigureChecks.cmake)
@ -288,22 +266,16 @@ check_library_exists(socket connect "" HAVE_SOCKET_LIBRARY)
add_subdirectory( cmake )
add_subdirectory( kdecore )
add_subdirectory( kdeui )
if (UNIX)
add_subdirectory( kpty )
add_subdirectory( kdesu )
endif (UNIX)
if(NOT WINCE)
add_subdirectory( kpty )
add_subdirectory( kdesu )
add_subdirectory( kjs )
add_subdirectory( kjsembed )
endif(NOT WINCE)
add_subdirectory( kio )
add_subdirectory( solid )
add_subdirectory( kded )
add_subdirectory( kfile )
add_subdirectory( kconf_update )
if(NOT WINCE)
add_subdirectory( kdoctools )
endif(NOT WINCE)
add_subdirectory( kioslave )
add_subdirectory( knewstuff )
add_subdirectory( kparts )
@ -313,23 +285,17 @@ add_subdirectory( mimetypes )
add_subdirectory( kinit )
add_subdirectory( threadweaver )
add_subdirectory( sonnet )
if(NOT WINCE)
add_subdirectory( khtml )
endif(NOT WINCE)
add_subdirectory( interfaces )
#if ( NOT CMAKE_CROSSCOMPILING AND QT_QTDESIGNER_FOUND )
add_subdirectory( kdewidgets )
#endif ( NOT CMAKE_CROSSCOMPILING AND QT_QTDESIGNER_FOUND )
add_subdirectory( knotify )
if(NOT WINCE)
add_subdirectory( kimgio )
endif(NOT WINCE)
add_subdirectory( dnssd )
add_subdirectory( kross )
add_subdirectory( security )
if(NOT WINCE)
add_subdirectory( plasma )
endif(NOT WINCE)
add_subdirectory( kunitconversion )
add_subdirectory( kdewebkit )
add_subdirectory( includes )

View file

@ -6,14 +6,12 @@ include_directories(${ZLIB_INCLUDE_DIR})
set(kmultipart_PART_SRCS kmultipart.cpp ${CMAKE_SOURCE_DIR}/kio/httpfilter/httpfilter.cc )
kde4_add_plugin(kmultipart WITH_PREFIX ${kmultipart_PART_SRCS})
target_link_libraries(kmultipart ${KDE4_KPARTS_LIBS} ${ZLIB_LIBRARY})
install(TARGETS kmultipart DESTINATION ${PLUGIN_INSTALL_DIR} )
########### install files ###############
install( FILES kmultipart.desktop DESTINATION ${SERVICES_INSTALL_DIR} )

View file

@ -3,10 +3,6 @@ add_subdirectory( ifaces )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
include_directories( ${QT_QTDBUS_INCLUDE_DIR} )
if(WIN32)
include_directories( ${KDEWIN_INCLUDES} )
endif(WIN32)
configure_file(solid_export.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/solid_export.h)
include (CheckCXXSourceCompiles)
@ -47,20 +43,12 @@ configure_file(config-processor.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-proce
file(MAKE_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/backends/fakehw
${CMAKE_CURRENT_BINARY_DIR}/backends/udev
${CMAKE_CURRENT_BINARY_DIR}/backends/wmi
${CMAKE_CURRENT_BINARY_DIR}/backends/win
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${KDE4_C_FLAGS}") # enable -fvisibility=hidden for C sources
if(WIN32)
set(solid_LIB_SRCS networking_win.cpp)
else()
set(solid_LIB_SRCS networking.cpp)
endif()
set(solid_LIB_SRCS
${solid_LIB_SRCS}
networking.cpp
solidnamespace.cpp
managerbase.cpp
device.cpp
@ -146,34 +134,30 @@ set(solid_LIB_SRCS
backends/shared/cpufeatures.cpp
)
if(NOT APPLE)
macro_optional_find_package( HUpnp )
macro_optional_find_package( HUpnp )
set(HUPNP_ENABLED FALSE CACHE BOOL "explicitly enable the compilation of the hupnp backend")
if (HUPNP_ENABLED AND HUPNP_FOUND AND ((HUPNP_VERSION_MAJOR EQUAL 0 AND HUPNP_VERSION_MINOR EQUAL 9) OR (HUPNP_VERSION_MAJOR EQUAL 1)))
include_directories( ${HUPNP_INCLUDE_DIR} )
message(STATUS "Building Solid UPnP backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/upnp/upnpdevice.cpp
backends/upnp/upnpdevicemanager.cpp
backends/upnp/upnpdeviceinterface.cpp
backends/upnp/upnpmediaserver.cpp
backends/upnp/upnpinternetgateway.cpp
backends/upnp/upnpcontrolpoint.cpp
)
else ()
if(NOT HUPNP_ENABLED)
message(STATUS "To have UPnP support, explicitly enable HUPNP_ENABLED in the cmake cache")
endif(NOT HUPNP_ENABLED)
set(HUPNP_FOUND false)
endif ()
macro_log_feature( HUPNP_FOUND "HUPnP" "UPnP support for Solid" "http://www.herqq.org" FALSE "" "Allows Solid to provide information about UPnP devices on the network" )
endif(NOT APPLE)
if(NOT WIN32 AND NOT APPLE)
# message(STATUS "Building Solid KUPnP backend." )
# set(solid_LIB_SRCS ${solid_LIB_SRCS}
set(HUPNP_ENABLED FALSE CACHE BOOL "explicitly enable the compilation of the hupnp backend")
if (HUPNP_ENABLED AND HUPNP_FOUND AND ((HUPNP_VERSION_MAJOR EQUAL 0 AND HUPNP_VERSION_MINOR EQUAL 9) OR (HUPNP_VERSION_MAJOR EQUAL 1)))
include_directories( ${HUPNP_INCLUDE_DIR} )
message(STATUS "Building Solid UPnP backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/upnp/upnpdevice.cpp
backends/upnp/upnpdevicemanager.cpp
backends/upnp/upnpdeviceinterface.cpp
backends/upnp/upnpmediaserver.cpp
backends/upnp/upnpinternetgateway.cpp
backends/upnp/upnpcontrolpoint.cpp
)
else ()
if(NOT HUPNP_ENABLED)
message(STATUS "To have UPnP support, explicitly enable HUPNP_ENABLED in the cmake cache")
endif(NOT HUPNP_ENABLED)
set(HUPNP_FOUND false)
endif ()
macro_log_feature( HUPNP_FOUND "HUPnP" "UPnP support for Solid" "http://www.herqq.org" FALSE "" "Allows Solid to provide information about UPnP devices on the network" )
# message(STATUS "Building Solid KUPnP backend." )
# set(solid_LIB_SRCS ${solid_LIB_SRCS}
# backends/kupnp/cagibidbuscodec.cpp
# backends/kupnp/cagibidevice.cpp
# backends/kupnp/kupnpstorageaccess.cpp
@ -185,207 +169,121 @@ if(NOT WIN32 AND NOT APPLE)
# backends/kupnp/kupnpdevice.cpp
# backends/kupnp/kupnprootdevice.cpp
# backends/kupnp/kupnpmanager.cpp
# )
# )
macro_optional_find_package( UDev )
set_package_properties(UDev PROPERTIES DESCRIPTION "UDev support for Solid"
URL "http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html"
TYPE OPTIONAL
PURPOSE "Allows Solid to use UDev to provide information about devices on Linux"
)
configure_file( config-solid.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-solid.h )
macro_optional_find_package( UDev )
set_package_properties(UDev PROPERTIES DESCRIPTION "UDev support for Solid"
URL "http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html"
TYPE OPTIONAL
PURPOSE "Allows Solid to use UDev to provide information about devices on Linux"
)
configure_file( config-solid.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-solid.h )
if ( UDEV_FOUND )
message(STATUS "Building Solid UDev backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/udev/utils.cpp
backends/udev/udevdevice.cpp
backends/udev/udevmanager.cpp
backends/udev/udevdeviceinterface.cpp
backends/udev/udevgenericinterface.cpp
backends/udev/cpuinfo.cpp
backends/udev/udevprocessor.cpp
backends/udev/udevcamera.cpp
backends/udev/udevvideo.cpp
backends/udev/udevaudiointerface.cpp
backends/udev/udevnetworkinterface.cpp
backends/udev/udevserialinterface.cpp
backends/udev/udevaudiointerface_p.cpp
backends/udev/udevportablemediaplayer.cpp
backends/udev/udevdvbinterface.cpp
backends/udev/udevblock.cpp
backends/udev/udevbutton.cpp
backends/shared/udevqtclient.cpp
backends/shared/udevqtdevice.cpp
)
set(UDEV_DETAILED_OUTPUT OFF CACHE BOOL "provide extended output regarding udev events")
if(UDEV_DETAILED_OUTPUT)
add_definitions(-DUDEV_DETAILED_OUTPUT)
endif(UDEV_DETAILED_OUTPUT)
# check for media-player-info (runtime-only optional dependency)
set(XDG_DATA_DIRS_ENV $ENV{XDG_DATA_DIRS}) # if(ENV{..}) does not work for me
if(XDG_DATA_DIRS_ENV)
find_path(MEDIAPLAYERINFO_PATH sony_psp.mpi
PATHS ENV XDG_DATA_DIRS
PATH_SUFFIXES "media-player-info" NO_DEFAULT_PATH
)
else(XDG_DATA_DIRS_ENV)
set(XDG_DATA_DIRS "/usr/share")
message(STATUS "Warning: environment variable XDG_DATA_DIRS not set, falling back to ${XDG_DATA_DIRS}")
find_path(MEDIAPLAYERINFO_PATH sony_psp.mpi
PATHS "${XDG_DATA_DIRS}"
PATH_SUFFIXES "media-player-info" NO_DEFAULT_PATH
)
endif(XDG_DATA_DIRS_ENV)
if ( UDEV_FOUND )
message(STATUS "Building Solid UDev backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/udev/utils.cpp
backends/udev/udevdevice.cpp
backends/udev/udevmanager.cpp
backends/udev/udevdeviceinterface.cpp
backends/udev/udevgenericinterface.cpp
backends/udev/cpuinfo.cpp
backends/udev/udevprocessor.cpp
backends/udev/udevcamera.cpp
backends/udev/udevvideo.cpp
backends/udev/udevaudiointerface.cpp
backends/udev/udevnetworkinterface.cpp
backends/udev/udevserialinterface.cpp
backends/udev/udevaudiointerface_p.cpp
backends/udev/udevportablemediaplayer.cpp
backends/udev/udevdvbinterface.cpp
backends/udev/udevblock.cpp
backends/udev/udevbutton.cpp
backends/shared/udevqtclient.cpp
backends/shared/udevqtdevice.cpp
)
set(UDEV_DETAILED_OUTPUT OFF CACHE BOOL "provide extended output regarding udev events")
if(UDEV_DETAILED_OUTPUT)
add_definitions(-DUDEV_DETAILED_OUTPUT)
endif(UDEV_DETAILED_OUTPUT)
# check for media-player-info (runtime-only optional dependency)
set(XDG_DATA_DIRS_ENV $ENV{XDG_DATA_DIRS}) # if(ENV{..}) does not work for me
if(XDG_DATA_DIRS_ENV)
find_path(MEDIAPLAYERINFO_PATH sony_psp.mpi
PATHS ENV XDG_DATA_DIRS
PATH_SUFFIXES "media-player-info" NO_DEFAULT_PATH
)
else(XDG_DATA_DIRS_ENV)
set(XDG_DATA_DIRS "/usr/share")
message(STATUS "Warning: environment variable XDG_DATA_DIRS not set, falling back to ${XDG_DATA_DIRS}")
find_path(MEDIAPLAYERINFO_PATH sony_psp.mpi
PATHS "${XDG_DATA_DIRS}"
PATH_SUFFIXES "media-player-info" NO_DEFAULT_PATH
)
endif(XDG_DATA_DIRS_ENV)
add_feature_info("media-player-info" MEDIAPLAYERINFO_PATH
"Enables identification and querying of portable media players.
add_feature_info("media-player-info" MEDIAPLAYERINFO_PATH
"Enables identification and querying of portable media players.
Runtime-only dependency of the udev solid backend.
Support for m-p-i is included even if not found during build"
)
endif( UDEV_FOUND )
endif( UDEV_FOUND )
message(STATUS "Building Solid UPower backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
message(STATUS "Building Solid UPower backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/upower/upowermanager.cpp
backends/upower/upowerdevice.cpp
backends/upower/upowerbattery.cpp
backends/upower/upoweracadapter.cpp
backends/upower/upowerdeviceinterface.cpp
backends/upower/upowergenericinterface.cpp
)
)
# FIXME: this should work on more Unix systems
if (CMAKE_SYSTEM_NAME MATCHES Linux)
# FIXME: this should work on more Unix systems
if ( WITH_SOLID_UDISKS2 )
message(STATUS "Building Solid UDisks2 backend." )
add_definitions(-DWITH_SOLID_UDISKS2)
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/udisks2/udisksmanager.cpp
backends/udisks2/udisksdevice.cpp
backends/udisks2/udisksdevicebackend.cpp
backends/udisks2/udisksblock.cpp
backends/udisks2/udisksstoragevolume.cpp
backends/udisks2/udisksdeviceinterface.cpp
backends/udisks2/udisksopticaldisc.cpp
backends/udisks2/udisksopticaldrive.cpp
backends/udisks2/udisksstoragedrive.cpp
backends/udisks2/udisksstorageaccess.cpp
backends/udisks2/udisksgenericinterface.cpp
backends/udisks2/dbus/manager.cpp
)
else ( WITH_SOLID_UDISKS2 )
message(STATUS "Building Solid UDisks backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/udisks/udisksmanager.cpp
backends/udisks/udisksdevice.cpp
backends/udisks/udisksblock.cpp
backends/udisks/udisksstoragevolume.cpp
backends/udisks/udisksdeviceinterface.cpp
backends/udisks/udisksopticaldisc.cpp
backends/udisks/udisksopticaldrive.cpp
backends/udisks/udisksstoragedrive.cpp
backends/udisks/udisksstorageaccess.cpp
backends/udisks/udisksgenericinterface.cpp
)
endif ( WITH_SOLID_UDISKS2 )
if ( WITH_SOLID_UDISKS2 )
message(STATUS "Building Solid UDisks2 backend." )
add_definitions(-DWITH_SOLID_UDISKS2)
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/udisks2/udisksmanager.cpp
backends/udisks2/udisksdevice.cpp
backends/udisks2/udisksdevicebackend.cpp
backends/udisks2/udisksblock.cpp
backends/udisks2/udisksstoragevolume.cpp
backends/udisks2/udisksdeviceinterface.cpp
backends/udisks2/udisksopticaldisc.cpp
backends/udisks2/udisksopticaldrive.cpp
backends/udisks2/udisksstoragedrive.cpp
backends/udisks2/udisksstorageaccess.cpp
backends/udisks2/udisksgenericinterface.cpp
backends/udisks2/dbus/manager.cpp
)
else ( WITH_SOLID_UDISKS2 )
message(STATUS "Building Solid UDisks backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/udisks/udisksmanager.cpp
backends/udisks/udisksdevice.cpp
backends/udisks/udisksblock.cpp
backends/udisks/udisksstoragevolume.cpp
backends/udisks/udisksdeviceinterface.cpp
backends/udisks/udisksopticaldisc.cpp
backends/udisks/udisksopticaldrive.cpp
backends/udisks/udisksstoragedrive.cpp
backends/udisks/udisksstorageaccess.cpp
backends/udisks/udisksgenericinterface.cpp
)
endif ( WITH_SOLID_UDISKS2 )
endif (CMAKE_SYSTEM_NAME MATCHES Linux)
message(STATUS "Building Solid fstab backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
message(STATUS "Building Solid fstab backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/fstab/fstabmanager.cpp
backends/fstab/fstabdevice.cpp
backends/fstab/fstabnetworkshare.cpp
backends/fstab/fstabstorageaccess.cpp
backends/fstab/fstabhandling.cpp
backends/fstab/fstabwatcher.cpp
)
endif(NOT WIN32 AND NOT APPLE)
if(APPLE)
find_package(IOKit REQUIRED)
message(STATUS "-- Building Solid IOKit backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/iokit/iokitmanager.cpp
backends/iokit/iokitdevice.cpp
backends/iokit/cfhelper.cpp
backends/iokit/iokitdeviceinterface.cpp
backends/iokit/iokitgenericinterface.cpp
backends/iokit/iokitprocessor.cpp
backends/iokit/iokitnetworkinterface.cpp
backends/iokit/iokitserialinterface.cpp
backends/iokit/iokitbattery.cpp
)
endif(APPLE)
if(WIN32)
if(WITH_SOLID_WMI)
include(CheckIncludeFileCXX)
check_include_file_cxx(wbemidl.h HAVE_WBEM)
FIND_LIBRARY(WBEM_LIBRARIES NAMES wbemuuid wbemuuidd)
if(HAVE_WBEM AND WBEM_LIBRARIES)
set(HAVE_WBEM True)
message(STATUS "Found wbemuuid library: ${WBEM_LIBRARIES}")
else(HAVE_WBEM AND WBEM_LIBRARIES)
set(HAVE_WBEM False)
set(WITH_SOLID_WMI False)
endif(HAVE_WBEM AND WBEM_LIBRARIES)
endif(WITH_SOLID_WMI)
if(WITH_SOLID_WMI)
add_definitions(-DWITH_SOLID_WMI)
message(STATUS "-- Building Solid WMI backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/wmi/wmiacadapter.cpp
backends/wmi/wmiaudiointerface.cpp
backends/wmi/wmibattery.cpp
backends/wmi/wmiblock.cpp
backends/wmi/wmibutton.cpp
backends/wmi/wmicamera.cpp
backends/wmi/wmicdrom.cpp
backends/wmi/wmideviceinterface.cpp
backends/wmi/wmidvbinterface.cpp
backends/wmi/wmigenericinterface.cpp
backends/wmi/wmidevice.cpp
backends/wmi/wmimanager.cpp
backends/wmi/wminetworkinterface.cpp
backends/wmi/wmiopticaldisc.cpp
backends/wmi/wmiportablemediaplayer.cpp
backends/wmi/wmiprocessor.cpp
backends/wmi/wmiquery.cpp
backends/wmi/wmistorageaccess.cpp
backends/wmi/wmistorage.cpp
backends/wmi/wmivideo.cpp
backends/wmi/wmivolume.cpp
)
else(WITH_SOLID_WMI)
message(STATUS "-- Building Solid Windows backend." )
set(solid_LIB_SRCS ${solid_LIB_SRCS}
backends/win/winblock.cpp
backends/win/winopticaldrive.cpp
backends/win/wininterface.cpp
backends/win/wingenericinterface.cpp
backends/win/windevice.cpp
backends/win/windevicemanager.cpp
backends/win/winopticaldisc.cpp
backends/win/winprocessor.cpp
#backends/win/wmiportablemediaplayer.cpp
backends/win/winstorageaccess.cpp
backends/win/winstoragedrive.cpp
backends/win/winstoragevolume.cpp
backends/win/winbattery.cpp
backends/win/winacadapter.cpp
)
endif(WITH_SOLID_WMI)
endif(WIN32)
)
set_source_files_properties( org.freedesktop.PowerManagement.xml
org.freedesktop.PowerManagement.Inhibit.xml
@ -401,19 +299,6 @@ qt4_add_dbus_interface(solid_LIB_SRCS org.kde.Solid.Networking.Client.xml
set(solid_OPTIONAL_LIBS)
if(WIN32)
set(solid_OPTIONAL_LIBS ${solid_OPTIONAL_LIBS} ${KDEWIN_LIBRARY} ${QT_QTNETWORK_LIBRARY})
if(WITH_SOLID_WMI)
set(solid_OPTIONAL_LIBS ${solid_OPTIONAL_LIBS} ${WBEM_LIBRARIES})
else()
set(solid_OPTIONAL_LIBS ${solid_OPTIONAL_LIBS} setupapi)
endif()
endif()
if(APPLE)
set(solid_OPTIONAL_LIBS ${IOKIT_LIBRARY})
endif(APPLE)
kde4_add_library(solid ${LIBRARY_TYPE} ${solid_LIB_SRCS})
if ( HUPNP_FOUND )
@ -427,10 +312,6 @@ endif ( UDEV_FOUND )
target_link_libraries(solid ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTGUI_LIBRARY} ${solid_OPTIONAL_LIBS} )
target_link_libraries(solid LINK_INTERFACE_LIBRARIES ${QT_CORE_LIBRARY} )
if (WINCE)
target_link_libraries(solid ${WCECOMPAT_LIBRARIES})
endif(WINCE)
set_target_properties(solid PROPERTIES
VERSION ${GENERIC_LIB_VERSION}
SOVERSION ${GENERIC_LIB_SOVERSION}
@ -448,9 +329,6 @@ kde4_add_library(solid_static STATIC ${solid_LIB_SRCS})
target_link_libraries(solid_static ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTGUI_LIBRARY} ${solid_OPTIONAL_LIBS})
if(WIN32)
set_target_properties(solid_static PROPERTIES COMPILE_FLAGS -DSOLID_EXPORT=)
endif(WIN32)
########### install files ###############
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/solid_export.h solidnamespace.h device.h

View file

@ -1,171 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include <QtCore/qvarlengtharray.h>
#include <QtCore/qstring.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qvariant.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qdebug.h>
#include <CoreFoundation/CoreFoundation.h>
/* helper classes to convert from CF types to Qt */
static QString q_toString(const CFStringRef &str)
{
CFIndex length = CFStringGetLength(str);
QVarLengthArray<UniChar> buffer(length);
CFRange range = { 0, length };
CFStringGetCharacters(str, range, buffer.data());
return QString(reinterpret_cast<const QChar *>(buffer.data()), length);
}
template <typename T>
static inline T convertCFNumber(const CFNumberRef &num, CFNumberType type)
{
T n;
CFNumberGetValue(num, type, &n);
return n;
}
static QVariant q_toVariant(const CFTypeRef &obj)
{
const CFTypeID typeId = CFGetTypeID(obj);
if (typeId == CFStringGetTypeID())
return QVariant(q_toString(static_cast<const CFStringRef>(obj)));
if (typeId == CFNumberGetTypeID()) {
const CFNumberRef num = static_cast<const CFNumberRef>(obj);
const CFNumberType type = CFNumberGetType(num);
switch (type) {
case kCFNumberSInt8Type:
return qVariantFromValue(convertCFNumber<char>(num, type));
case kCFNumberSInt16Type:
return qVariantFromValue(convertCFNumber<qint16>(num, type));
case kCFNumberSInt32Type:
return qVariantFromValue(convertCFNumber<qint32>(num, type));
case kCFNumberSInt64Type:
return qVariantFromValue(convertCFNumber<qint64>(num, type));
case kCFNumberCharType:
return qVariantFromValue(convertCFNumber<uchar>(num, type));
case kCFNumberShortType:
return qVariantFromValue(convertCFNumber<short>(num, type));
case kCFNumberIntType:
return qVariantFromValue(convertCFNumber<int>(num, type));
case kCFNumberLongType:
return qVariantFromValue(convertCFNumber<long>(num, type));
case kCFNumberLongLongType:
return qVariantFromValue(convertCFNumber<long long>(num, type));
case kCFNumberFloatType:
return qVariantFromValue(convertCFNumber<float>(num, type));
case kCFNumberDoubleType:
return qVariantFromValue(convertCFNumber<double>(num, type));
default:
if (CFNumberIsFloatType(num))
return qVariantFromValue(convertCFNumber<double>(num, kCFNumberDoubleType));
return qVariantFromValue(convertCFNumber<quint64>(num, kCFNumberLongLongType));
}
}
if (typeId == CFDateGetTypeID()) {
QDateTime dt;
dt.setTime_t(uint(kCFAbsoluteTimeIntervalSince1970));
return dt.addSecs(int(CFDateGetAbsoluteTime(static_cast<const CFDateRef>(obj))));
}
if (typeId == CFDataGetTypeID()) {
const CFDataRef cfdata = static_cast<const CFDataRef>(obj);
return QByteArray(reinterpret_cast<const char *>(CFDataGetBytePtr(cfdata)),
CFDataGetLength(cfdata));
}
if (typeId == CFBooleanGetTypeID())
return QVariant(bool(CFBooleanGetValue(static_cast<const CFBooleanRef>(obj))));
if (typeId == CFArrayGetTypeID()) {
const CFArrayRef cfarray = static_cast<const CFArrayRef>(obj);
QList<QVariant> list;
CFIndex size = CFArrayGetCount(cfarray);
bool metNonString = false;
for (CFIndex i = 0; i < size; ++i) {
QVariant value = q_toVariant(CFArrayGetValueAtIndex(cfarray, i));
if (value.type() != QVariant::String)
metNonString = true;
list << value;
}
if (metNonString)
return list;
else
return QVariant(list).toStringList();
}
if (typeId == CFDictionaryGetTypeID()) {
const CFDictionaryRef cfdict = static_cast<const CFDictionaryRef>(obj);
const CFTypeID arrayTypeId = CFArrayGetTypeID();
int size = int(CFDictionaryGetCount(cfdict));
QVarLengthArray<CFPropertyListRef> keys(size);
QVarLengthArray<CFPropertyListRef> values(size);
CFDictionaryGetKeysAndValues(cfdict, keys.data(), values.data());
QMultiMap<QString, QVariant> map;
for (int i = 0; i < size; ++i) {
QString key = q_toString(static_cast<const CFStringRef>(keys[i]));
if (CFGetTypeID(values[i]) == arrayTypeId) {
const CFArrayRef cfarray = static_cast<const CFArrayRef>(values[i]);
CFIndex arraySize = CFArrayGetCount(cfarray);
for (CFIndex j = arraySize - 1; j >= 0; --j)
map.insert(key, q_toVariant(CFArrayGetValueAtIndex(cfarray, j)));
} else {
map.insert(key, q_toVariant(values[i]));
}
}
return map;
}
return QVariant();
}
QMap<QString, QVariant> q_toVariantMap (const CFMutableDictionaryRef &dict)
{
Q_ASSERT(dict);
QMap<QString, QVariant> result;
const int count = CFDictionaryGetCount(dict);
QVarLengthArray<void *> keys(count);
QVarLengthArray<void *> values(count);
CFDictionaryGetKeysAndValues(dict,
const_cast<const void **>(keys.data()),
const_cast<const void **>(values.data()));
for (int i = 0; i < count; ++i) {
const QString key = q_toString((CFStringRef)keys[i]);
const QVariant value = q_toVariant((CFTypeRef)values[i]);
result[key] = value;
}
return result;
}

View file

@ -1,88 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "iokitbattery.h"
#include "iokitdevice.h"
#include <QtCore/qdebug.h>
// TODO - emit the signals
using namespace Solid::Backends::IOKit;
Battery::Battery(IOKitDevice *device)
: DeviceInterface(device)
{
}
Battery::~Battery()
{
}
bool Battery::isPlugged() const
{
return m_device->property(QLatin1String("ExternalConnected")).toBool();
}
Solid::Battery::BatteryType Battery::type() const
{
// TODO - how to figure that one out?
return Solid::Battery::UnknownBattery;
}
int Battery::chargePercent() const
{
if (m_device->property(QLatin1String("FullyCharged")).toBool())
return 100;
int maxCapacity = m_device->property(QLatin1String("MaxCapacity")).toInt();
if (maxCapacity == 0)
return 0; // prevent divide by 0
return m_device->property(QLatin1String("CurrentCapacity")).toInt() / maxCapacity;
}
int Battery::capacity() const
{
// TODO
return 100;
}
bool Battery::isRechargeable() const
{
return m_device->property(QLatin1String("DesignCycleCount")).toInt() > 1;
}
bool Battery::isPowerSupply() const
{
// TODO
return true;
}
Solid::Battery::ChargeState Battery::chargeState() const
{
if (m_device->property(QLatin1String("IsCharging")).toBool())
return Solid::Battery::Charging;
if (m_device->property(QLatin1String("FullyCharged")).toBool())
return Solid::Battery::NoCharge;
return Solid::Battery::Discharging;
}
#include "backends/iokit/iokitbattery.moc"

View file

@ -1,66 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_IOKIT_BATTERY_H
#define SOLID_BACKENDS_IOKIT_BATTERY_H
#include <solid/ifaces/battery.h>
#include "iokitdeviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace IOKit
{
class IOKitDevice;
class Battery : public DeviceInterface, virtual public Solid::Ifaces::Battery
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Battery)
public:
Battery(IOKitDevice *device);
virtual ~Battery();
bool isPlugged() const;
Solid::Battery::BatteryType type() const;
int chargePercent() const;
int capacity() const;
bool isRechargeable() const;
bool isPowerSupply() const;
Solid::Battery::ChargeState chargeState() const;
Q_SIGNALS:
void chargePercentChanged(int value, const QString &udi);
void capacityChanged(int value, const QString &udi);
void chargeStateChanged(int newState, const QString &udi);
void plugStateChanged(bool newState, const QString &udi);
void powerSupplyStateChanged(bool newState, const QString &udi);
};
}
}
}
#endif // SOLID_BACKENDS_IOKIT_BATTERY_H

View file

@ -1,246 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "iokitdevice.h"
#include "iokitgenericinterface.h"
#include "iokitprocessor.h"
#include "iokitbattery.h"
#include "iokitnetworkinterface.h"
#include "iokitserialinterface.h"
#include <QtCore/qdebug.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/usb/IOUSBLib.h>
#include <IOKit/network/IOEthernetInterface.h>
#include <CoreFoundation/CoreFoundation.h>
// from cfhelper.cpp
extern QMap<QString, QVariant> q_toVariantMap(const CFMutableDictionaryRef &dict);
namespace Solid { namespace Backends { namespace IOKit {
// returns a solid type from an entry and its properties
static Solid::DeviceInterface::Type typeFromEntry(const io_registry_entry_t &entry,
const QMap<QString, QVariant> &properties)
{
if (IOObjectConformsTo(entry, kIOEthernetInterfaceClass))
return Solid::DeviceInterface::NetworkInterface;
if (IOObjectConformsTo(entry, "AppleACPICPU"))
return Solid::DeviceInterface::Processor;
if (IOObjectConformsTo(entry, "IOSerialBSDClient"))
return Solid::DeviceInterface::SerialInterface;
if (IOObjectConformsTo(entry, "AppleSmartBattery"))
return Solid::DeviceInterface::Battery;
return Solid::DeviceInterface::Unknown;
}
// gets all properties from an entry into a QMap
static QMap<QString, QVariant> getProperties(const io_registry_entry_t &entry)
{
CFMutableDictionaryRef propertyDict = 0;
if (IORegistryEntryCreateCFProperties(entry, &propertyDict, kCFAllocatorDefault, kNilOptions) != KERN_SUCCESS) {
return QMap<QString, QVariant>();
}
QMap<QString, QVariant> result = q_toVariantMap(propertyDict);
CFRelease(propertyDict);
return result;
}
// gets the parent's Udi from an entry
static QString getParentDeviceUdi(const io_registry_entry_t &entry)
{
io_registry_entry_t parent = 0;
kern_return_t ret = IORegistryEntryGetParentEntry(entry, kIOServicePlane, &parent);
if (ret != KERN_SUCCESS) {
// don't release parent here - docs say only on success
return QString();
}
QString result;
io_string_t pathName;
ret = IORegistryEntryGetPath(parent, kIOServicePlane, pathName);
if (ret == KERN_SUCCESS)
result = QString::fromUtf8(pathName);
// now we can release the parent
IOObjectRelease(parent);
return result;
}
class IOKitDevicePrivate
{
public:
inline IOKitDevicePrivate()
: type(Solid::DeviceInterface::Unknown)
{}
void init(const QString &udiString, const io_registry_entry_t & entry);
QString udi;
QString parentUdi;
QMap<QString, QVariant> properties;
Solid::DeviceInterface::Type type;
};
void IOKitDevicePrivate::init(const QString &udiString, const io_registry_entry_t &entry)
{
Q_ASSERT(entry != MACH_PORT_NULL);
udi = udiString;
properties = getProperties(entry);
io_name_t className;
IOObjectGetClass(entry, className);
properties["className"] = QString::fromUtf8(className);
parentUdi = getParentDeviceUdi(entry);
type = typeFromEntry(entry, properties);
IOObjectRelease(entry);
}
IOKitDevice::IOKitDevice(const QString &udi, const io_registry_entry_t &entry)
: d(new IOKitDevicePrivate)
{
d->init(udi, entry);
}
IOKitDevice::IOKitDevice(const QString &udi)
: d(new IOKitDevicePrivate)
{
io_registry_entry_t entry = IORegistryEntryFromPath(
kIOMasterPortDefault,
udi.toLocal8Bit().constData());
if (entry == MACH_PORT_NULL) {
qDebug() << Q_FUNC_INFO << "Tried to create Device from invalid UDI" << udi;
return;
}
d->init(udi, entry);
}
IOKitDevice::~IOKitDevice()
{
delete d;
}
QString IOKitDevice::udi() const
{
return d->udi;
}
QString IOKitDevice::parentUdi() const
{
return d->parentUdi;
}
QString IOKitDevice::vendor() const
{
return QString(); // TODO
}
QString IOKitDevice::product() const
{
return QString(); // TODO
}
QString IOKitDevice::icon() const
{
return QString(); // TODO
}
QStringList IOKitDevice::emblems() const
{
return QStringList(); // TODO
}
QString IOKitDevice::description() const
{
return product(); // TODO
}
QVariant IOKitDevice::property(const QString &key) const
{
return d->properties.value(key);
}
QMap<QString, QVariant> IOKitDevice::allProperties() const
{
return d->properties;
}
bool IOKitDevice::propertyExists(const QString &key) const
{
return d->properties.contains(key);
}
bool IOKitDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &type) const
{
return (type == Solid::DeviceInterface::GenericInterface
|| type == d->type);
}
QObject *IOKitDevice::createDeviceInterface(const Solid::DeviceInterface::Type &type)
{
QObject *iface = 0;
switch (type)
{
case Solid::DeviceInterface::GenericInterface:
iface = new GenericInterface(this);
break;
case Solid::DeviceInterface::Processor:
if (d->type == Solid::DeviceInterface::Processor)
iface = new Processor(this);
break;
case Solid::DeviceInterface::NetworkInterface:
if (d->type == Solid::DeviceInterface::NetworkInterface)
iface = new NetworkInterface(this);
break;
case Solid::DeviceInterface::SerialInterface:
if (d->type == Solid::DeviceInterface::SerialInterface)
iface = new SerialInterface(this);
break;
case Solid::DeviceInterface::Battery:
if (d->type == Solid::DeviceInterface::Battery)
iface = new Battery(this);
break;
// the rest is TODO
}
return iface;
}
} } } // namespaces

View file

@ -1,75 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_IOKIT_IOKITDEVICE_H
#define SOLID_BACKENDS_IOKIT_IOKITDEVICE_H
#include <solid/ifaces/device.h>
#include <IOKit/IOKitLib.h>
namespace Solid
{
namespace Backends
{
namespace IOKit
{
class IOKitDevicePrivate;
class IOKitManager;
class IOKitDevice : public Solid::Ifaces::Device
{
Q_OBJECT
public:
IOKitDevice(const QString &udi);
virtual ~IOKitDevice();
virtual QString udi() const;
virtual QString parentUdi() const;
virtual QString vendor() const;
virtual QString product() const;
virtual QString icon() const;
virtual QStringList emblems() const;
virtual QString description() const;
virtual QVariant property(const QString &key) const;
virtual QMap<QString, QVariant> allProperties() const;
virtual bool propertyExists(const QString &key) const;
virtual bool queryDeviceInterface(const Solid::DeviceInterface::Type &type) const;
virtual QObject *createDeviceInterface(const Solid::DeviceInterface::Type &type);
Q_SIGNALS:
void propertyChanged(const QMap<QString,int> &changes);
void conditionRaised(const QString &condition, const QString &reason);
private:
friend class IOKitManager;
IOKitDevice(const QString &udi, const io_registry_entry_t &entry);
IOKitDevicePrivate * const d;
};
}
}
}
#endif // SOLID_BACKENDS_IOKIT_IOKITDEVICE_H

View file

@ -1,34 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "iokitdeviceinterface.h"
using namespace Solid::Backends::IOKit;
DeviceInterface::DeviceInterface(IOKitDevice *device)
: QObject(device), m_device(device)
{
}
DeviceInterface::~DeviceInterface()
{
}
#include "backends/iokit/iokitdeviceinterface.moc"

View file

@ -1,51 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_IOKIT_DEVICEINTERFACE_H
#define SOLID_BACKENDS_IOKIT_DEVICEINTERFACE_H
#include <solid/ifaces/deviceinterface.h>
#include "iokitdevice.h"
#include <QtCore/QObject>
#include <QtCore/QStringList>
namespace Solid
{
namespace Backends
{
namespace IOKit
{
class DeviceInterface : public QObject, virtual public Solid::Ifaces::DeviceInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::DeviceInterface)
public:
DeviceInterface(IOKitDevice *device);
virtual ~DeviceInterface();
protected:
IOKitDevice *m_device;
};
}
}
}
#endif // SOLID_BACKENDS_IOKIT_DEVICEINTERFACE_H

View file

@ -1,52 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "iokitgenericinterface.h"
#include "iokitdevice.h"
using namespace Solid::Backends::IOKit;
GenericInterface::GenericInterface(IOKitDevice *device)
: DeviceInterface(device)
{
}
GenericInterface::~GenericInterface()
{
}
QVariant GenericInterface::property(const QString &key) const
{
return m_device->property(key);
}
QMap<QString, QVariant> GenericInterface::allProperties() const
{
return m_device->allProperties();
}
bool GenericInterface::propertyExists(const QString &key) const
{
return m_device->propertyExists(key);
}
#include "backends/iokit/iokitgenericinterface.moc"

View file

@ -1,57 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_IOKIT_GENERICINTERFACE_H
#define SOLID_BACKENDS_IOKIT_GENERICINTERFACE_H
#include <solid/ifaces/genericinterface.h>
#include <solid/genericinterface.h>
#include "iokitdeviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace IOKit
{
class IOKitDevice;
class GenericInterface : public DeviceInterface, virtual public Solid::Ifaces::GenericInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::GenericInterface)
public:
GenericInterface(IOKitDevice *device);
virtual ~GenericInterface();
virtual QVariant property(const QString &key) const;
virtual QMap<QString, QVariant> allProperties() const;
virtual bool propertyExists(const QString &key) const;
Q_SIGNALS:
void propertyChanged(const QMap<QString,int> &changes);
void conditionRaised(const QString &condition, const QString &reason);
};
}
}
}
#endif // SOLID_BACKENDS_IOKIT_GENERICINTERFACE_H

View file

@ -1,245 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "iokitmanager.h"
#include "iokitdevice.h"
#include <QtCore/qdebug.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/usb/IOUSBLib.h>
#include <IOKit/network/IOEthernetInterface.h>
#include <CoreFoundation/CoreFoundation.h>
namespace Solid { namespace Backends { namespace IOKit {
class IOKitManagerPrivate
{
public:
inline IOKitManagerPrivate()
: port(0), source(0)
{}
IONotificationPortRef port;
CFRunLoopSourceRef source;
static const char *typeToName(Solid::DeviceInterface::Type type);
static QStringList devicesFromRegistry(io_iterator_t it);
QSet<Solid::DeviceInterface::Type> supportedInterfaces;
};
// gets all registry pathes from an iterator
QStringList IOKitManagerPrivate::devicesFromRegistry(io_iterator_t it)
{
QStringList result;
io_object_t obj;
io_string_t pathName;
while ((obj = IOIteratorNext(it))) {
kern_return_t ret = IORegistryEntryGetPath(obj, kIOServicePlane, pathName);
if (ret != KERN_SUCCESS) {
qWarning() << Q_FUNC_INFO << "IORegistryEntryGetPath failed";
continue;
}
result += QString::fromUtf8(pathName);
ret = IOObjectRelease(obj);
if (ret != KERN_SUCCESS) {
// very unlikely to happen - keep it a qDebug just in case.
// compiler will nuke this code in release builds.
qDebug() << Q_FUNC_INFO << "Unable to release object reference";
}
}
IOObjectRelease(it);
return result;
}
const char *IOKitManagerPrivate::typeToName(Solid::DeviceInterface::Type type)
{
switch (type) {
case Solid::DeviceInterface::Unknown:
return 0;
case Solid::DeviceInterface::NetworkInterface:
return kIOEthernetInterfaceClass;
case Solid::DeviceInterface::Processor:
return "AppleACPICPU";
case Solid::DeviceInterface::SerialInterface:
return "IOSerialBSDClient";
case Solid::DeviceInterface::Battery:
return "AppleSmartBattery";
//Solid::DeviceInterface::GenericInterface:
//Solid::DeviceInterface::Block:
//Solid::DeviceInterface::StorageAccess:
//Solid::DeviceInterface::StorageDrive:
//Solid::DeviceInterface::OpticalDrive:
//Solid::DeviceInterface::StorageVolume:
//Solid::DeviceInterface::OpticalDisc:
//Solid::DeviceInterface::Camera:
//Solid::DeviceInterface::PortableMediaPlayer:
//Solid::DeviceInterface::NetworkInterface:
//Solid::DeviceInterface::AcAdapter:
//Solid::DeviceInterface::Button:
//Solid::DeviceInterface::AudioInterface:
//Solid::DeviceInterface::DvbInterface:
//Solid::DeviceInterface::Video:
}
return 0;
}
IOKitManager::IOKitManager(QObject *parent)
: Solid::Ifaces::DeviceManager(parent), d(new IOKitManagerPrivate)
{
d->port = IONotificationPortCreate(kIOMasterPortDefault);
if (!d->port) {
qWarning() << Q_FUNC_INFO << "Unable to create notification port";
return;
}
d->source = IONotificationPortGetRunLoopSource(d->port);
if (!d->source) {
qWarning() << Q_FUNC_INFO << "Unable to create notification source";
return;
}
CFRunLoopAddSource(CFRunLoopGetCurrent(), d->source, kCFRunLoopDefaultMode);
d->supportedInterfaces << Solid::DeviceInterface::GenericInterface
<< Solid::DeviceInterface::Processor
<< Solid::DeviceInterface::Block
<< Solid::DeviceInterface::StorageAccess
<< Solid::DeviceInterface::StorageDrive
<< Solid::DeviceInterface::OpticalDrive
<< Solid::DeviceInterface::StorageVolume
<< Solid::DeviceInterface::OpticalDisc
<< Solid::DeviceInterface::Camera
<< Solid::DeviceInterface::PortableMediaPlayer
<< Solid::DeviceInterface::NetworkInterface
<< Solid::DeviceInterface::AcAdapter
<< Solid::DeviceInterface::Battery
<< Solid::DeviceInterface::Button
<< Solid::DeviceInterface::AudioInterface
<< Solid::DeviceInterface::DvbInterface
<< Solid::DeviceInterface::Video
<< Solid::DeviceInterface::SerialInterface
<< Solid::DeviceInterface::SmartCardReader;
}
IOKitManager::~IOKitManager()
{
if (d->source)
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), d->source, kCFRunLoopDefaultMode);
if (d->port)
IONotificationPortDestroy(d->port);
delete d;
}
QString IOKitManager::udiPrefix() const
{
return QString(); //FIXME: We should probably use a prefix there... has to be tested on Mac
}
QSet<Solid::DeviceInterface::Type> IOKitManager::supportedInterfaces() const
{
return d->supportedInterfaces;
}
QStringList IOKitManager::allDevices()
{
// use an IORegistry Iterator to iterate over all devices in the service plane
io_iterator_t it;
kern_return_t ret = IORegistryCreateIterator(
kIOMasterPortDefault,
kIOServicePlane,
kIORegistryIterateRecursively,
&it);
if (ret != KERN_SUCCESS) {
qWarning() << Q_FUNC_INFO << "unable to create iterator";
return QStringList();
}
return IOKitManagerPrivate::devicesFromRegistry(it);
}
QStringList IOKitManager::devicesFromQuery(const QString &parentUdi,
Solid::DeviceInterface::Type type)
{
QStringList result;
if (type == Solid::DeviceInterface::Unknown) {
// match all device interfaces
result = allDevices();
} else {
const char *deviceClassName = IOKitManagerPrivate::typeToName(type);
if (!deviceClassName)
return QStringList();
CFMutableDictionaryRef matchingDict = IOServiceMatching(deviceClassName);
if (!matchingDict)
return QStringList();
io_iterator_t it = 0;
// note - IOServiceGetMatchingServices dereferences the dict
kern_return_t ret = IOServiceGetMatchingServices(
kIOMasterPortDefault,
matchingDict,
&it);
result = IOKitManagerPrivate::devicesFromRegistry(it);
}
// if the parentUdi is an empty string, return all matches
if (parentUdi.isEmpty())
return result;
// return only matches that start with the parent's UDI
QStringList filtered;
foreach (const QString &udi, result) {
if (udi.startsWith(parentUdi))
filtered += udi;
}
return filtered;
}
QObject *IOKitManager::createDevice(const QString &udi)
{
io_registry_entry_t entry = IORegistryEntryFromPath(
kIOMasterPortDefault,
udi.toLocal8Bit().constData());
// we have to do IOObjectConformsTo - comparing the class names is not good enough
//if (IOObjectConformsTo(entry, kIOEthernetInterfaceClass)) {
//}
if (entry == MACH_PORT_NULL)
return 0;
return new IOKitDevice(udi, entry);
}
}}} // namespaces

View file

@ -1,62 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_IOKIT_IOKITMANAGER_H
#define SOLID_BACKENDS_IOKIT_IOKITMANAGER_H
#include <solid/ifaces/devicemanager.h>
#include <solid/deviceinterface.h>
#include <QtCore/QVariant>
#include <QtCore/QStringList>
namespace Solid
{
namespace Backends
{
namespace IOKit
{
class IOKitManagerPrivate;
class IOKitManager : public Solid::Ifaces::DeviceManager
{
Q_OBJECT
public:
IOKitManager(QObject *parent);
virtual ~IOKitManager();
virtual QString udiPrefix() const ;
virtual QSet<Solid::DeviceInterface::Type> supportedInterfaces() const;
virtual QStringList allDevices();
virtual QStringList devicesFromQuery(const QString &parentUdi,
Solid::DeviceInterface::Type type);
virtual QObject *createDevice(const QString &udi);
private:
IOKitManagerPrivate *d;
};
}
}
}
#endif // SOLID_BACKENDS_IOKIT_IOKITMANAGER_H

View file

@ -1,87 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "iokitnetworkinterface.h"
#include "iokitdevice.h"
#include <QtCore/qstringlist.h>
#include <QtCore/qdebug.h>
using namespace Solid::Backends::IOKit;
NetworkInterface::NetworkInterface(IOKitDevice *device)
: DeviceInterface(device)
{
}
NetworkInterface::~NetworkInterface()
{
}
QString NetworkInterface::ifaceName() const
{
return m_device->property(QLatin1String("BSD Name")).toString();
}
bool NetworkInterface::isWireless() const
{
return m_device->propertyExists(QLatin1String("IO80211HardwareVersion"));
}
QString NetworkInterface::hwAddress() const
{
// TODO - how to get the hw address? Return a string representation of the MAC addr for now
const QByteArray ba = IOKitDevice(m_device->parentUdi()).property(QLatin1String("IOMACAddress")).toByteArray();
qDebug() << ba.length();
if (ba.length() != 6)
return QString();
QString result;
for (int i = 0; i < 6; ++i) {
// produce a hex number, 2 digits width, 0-padded followed by a colon
result += QString::fromLatin1("%1:").arg(uchar(ba.at(i)), 2, 16, QLatin1Char('0'));
}
// remove tailing colon
result.chop(1);
return result;
}
qulonglong NetworkInterface::macAddress() const
{
// IOMacAddress property returns the mac address encoded in 6 bytes
const QByteArray ba = IOKitDevice(m_device->parentUdi()).property(QLatin1String("IOMACAddress")).toByteArray();
if (ba.length() != 6)
return 0;
// need to bit-shift instead of memcpy because of alignment and endianess
qulonglong result;
result = qulonglong((uchar)ba.at(0)) << 40;
result += qulonglong((uchar)ba.at(1)) << 32;
result += qulonglong((uchar)ba.at(2)) << 24;
result += qulonglong((uchar)ba.at(3)) << 16;
result += qulonglong((uchar)ba.at(4)) << 8;
result += (uchar)ba.at(5);
return result;
}
#include "backends/iokit/iokitnetworkinterface.moc"

View file

@ -1,53 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_IOKIT_IOKITNETWORKINTERFACE_H
#define SOLID_BACKENDS_IOKIT_IOKITNETWORKINTERFACE_H
#include <solid/ifaces/networkinterface.h>
#include "iokitdeviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace IOKit
{
class IOKitDevice;
class NetworkInterface : public DeviceInterface, virtual public Solid::Ifaces::NetworkInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::NetworkInterface)
public:
NetworkInterface(IOKitDevice *device);
virtual ~NetworkInterface();
virtual QString ifaceName() const;
virtual bool isWireless() const;
virtual QString hwAddress() const;
virtual qulonglong macAddress() const;
};
}
}
}
#endif // SOLID_BACKENDS_IOKIT_IOKITNETWORKINTERFACE_H

View file

@ -1,59 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "iokitprocessor.h"
#include "iokitdevice.h"
#include <QtCore/qdebug.h>
using namespace Solid::Backends::IOKit;
Processor::Processor(IOKitDevice *device)
: DeviceInterface(device)
{
//IOKitDevice parent(device->parentUdi());
}
Processor::~Processor()
{
}
int Processor::number() const
{
return m_device->property(QLatin1String("IOCPUNumber")).toInt();
}
int Processor::maxSpeed() const
{
return 0; // TODO
}
bool Processor::canChangeFrequency() const
{
return false; // TODO
}
Solid::Processor::InstructionSets Processor::instructionSets() const
{
return 0; // TODO
}
#include "backends/iokit/iokitprocessor.moc"

View file

@ -1,53 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_IOKIT_PROCESSOR_H
#define SOLID_BACKENDS_IOKIT_PROCESSOR_H
#include <solid/ifaces/processor.h>
#include "iokitdeviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace IOKit
{
class IOKitDevice;
class Processor : public DeviceInterface, virtual public Solid::Ifaces::Processor
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Processor)
public:
Processor(IOKitDevice *device);
virtual ~Processor();
virtual int number() const;
virtual int maxSpeed() const;
virtual bool canChangeFrequency() const;
virtual Solid::Processor::InstructionSets instructionSets() const;
};
}
}
}
#endif // SOLID_BACKENDS_IOKIT_PROCESSOR_H

View file

@ -1,55 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "iokitserialinterface.h"
#include "iokitdevice.h"
#include <QtCore/qdebug.h>
using namespace Solid::Backends::IOKit;
SerialInterface::SerialInterface(IOKitDevice *device)
: DeviceInterface(device)
{
}
SerialInterface::~SerialInterface()
{
}
QVariant SerialInterface::driverHandle() const
{
return m_device->property(QLatin1String("IODialinDevice"));
}
Solid::SerialInterface::SerialType SerialInterface::serialType() const
{
return Solid::SerialInterface::Unknown;
}
int SerialInterface::port() const
{
return -1; // TODO
}
#include "backends/iokit/iokitserialinterface.moc"

View file

@ -1,52 +0,0 @@
/*
Copyright 2009 Harald Fernengel <harry@kdevelop.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_IOKIT_SERIALINTERFACE_H
#define SOLID_BACKENDS_IOKIT_SERIALINTERFACE_H
#include <solid/ifaces/serialinterface.h>
#include "iokitdeviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace IOKit
{
class IOKitDevice;
class SerialInterface : public DeviceInterface, virtual public Solid::Ifaces::SerialInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::SerialInterface)
public:
SerialInterface(IOKitDevice *device);
virtual ~SerialInterface();
QVariant driverHandle() const;
Solid::SerialInterface::SerialType serialType() const;
int port() const;
};
}
}
}
#endif // SOLID_BACKENDS_IOKIT_PROCESSOR_H

View file

@ -1,58 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "winacadapter.h"
using namespace Solid::Backends::Win;
WinAcadapter::WinAcadapter(WinDevice *device) :
WinInterface(device)
{
powerChanged();
connect(WinDeviceManager::instance(),SIGNAL(powerChanged()),this,SLOT(powerChanged()));
}
bool WinAcadapter::isPlugged() const
{
return m_pluggedIn;
}
QSet<QString> WinAcadapter::getUdis()
{
QSet<QString> out;
out << QLatin1String("/org/kde/solid/win/power/acadapter");
return out;
}
void WinAcadapter::powerChanged()
{
bool old_pluggedIn = m_pluggedIn;
SYSTEM_POWER_STATUS status;
ZeroMemory(&status,sizeof(SYSTEM_POWER_STATUS));
GetSystemPowerStatus(&status);
m_pluggedIn = status.ACLineStatus == 1;
if(m_pluggedIn != old_pluggedIn)
{
emit plugStateChanged(m_pluggedIn,m_device->udi());
}
}
#include "winacadapter.moc"

View file

@ -1,58 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINACADAPTER_H
#define WINACADAPTER_H
#include <solid/ifaces/acadapter.h>
#include "wininterface.h"
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinAcadapter : public WinInterface, virtual public Solid::Ifaces::AcAdapter
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::AcAdapter)
public:
WinAcadapter(WinDevice *device);
virtual bool isPlugged() const;
static QSet<QString> getUdis();
signals:
void plugStateChanged(bool newState, const QString &udi);
private slots:
void powerChanged();
private:
bool m_pluggedIn;
};
}
}
}
#endif // WINACADAPTER_H

View file

@ -1,231 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "winbattery.h"
#include <setupapi.h>
#include <batclass.h>
#include <devguid.h>
using namespace Solid::Backends::Win;
QMap<QString,WinBattery::Battery> WinBattery::m_udiToGDI = QMap<QString,WinBattery::Battery>();
WinBattery::WinBattery(WinDevice *device) :
WinInterface(device),
m_state(Solid::Battery::NoCharge)
{
powerChanged();
connect(WinDeviceManager::instance(),SIGNAL(powerChanged()),this,SLOT(powerChanged()));
}
bool WinBattery::isPlugged() const
{
return m_pluggedIn;
}
Solid::Battery::BatteryType WinBattery::type() const
{
return m_type;
}
int WinBattery::chargePercent() const
{
return m_charge;
}
int WinBattery::capacity() const
{
return m_capacity;
}
bool WinBattery::isRechargeable() const
{
return m_rechargabel;
}
bool WinBattery::isPowerSupply() const
{
return m_isPowerSupply;
}
Solid::Battery::ChargeState WinBattery::chargeState() const
{
return m_state;
}
QSet<QString> WinBattery::getUdis()
{
QSet<QString> udis;
HDEVINFO hdev =
SetupDiGetClassDevs(&GUID_DEVCLASS_BATTERY,
0,
0,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (INVALID_HANDLE_VALUE != hdev)
{
// Limit search to 100 batteries max
for (int idev = 0; idev < 100; idev++)
{
SP_DEVICE_INTERFACE_DATA did;
ZeroMemory(&did,sizeof(did));
did.cbSize = sizeof(did);
if (SetupDiEnumDeviceInterfaces(hdev,
0,
&GUID_DEVCLASS_BATTERY,
idev,
&did))
{
DWORD cbRequired = 0;
SetupDiGetDeviceInterfaceDetailW(hdev,
&did,
0,
0,
&cbRequired,
0);
if (ERROR_INSUFFICIENT_BUFFER == GetLastError())
{
char *buffer = new char[cbRequired];
SP_DEVICE_INTERFACE_DETAIL_DATA *pdidd = (SP_DEVICE_INTERFACE_DETAIL_DATA*)buffer;
ZeroMemory(pdidd,cbRequired);
pdidd->cbSize = sizeof(*pdidd);
if (SetupDiGetDeviceInterfaceDetail(hdev,
&did,
pdidd,
cbRequired,
&cbRequired,
0))
{
QString path = QString::fromWCharArray(pdidd->DevicePath);
ulong tag = WinDeviceManager::getDeviceInfo<ulong>(path,IOCTL_BATTERY_QUERY_TAG);
QString udi = QLatin1String("/org/kde/solid/win/power.battery/battery#") + QString::number(tag);
udis << udi;
m_udiToGDI[udi] = Battery(path,tag);
}
delete [] buffer;
}
}
}
SetupDiDestroyDeviceInfoList(hdev);
}
return udis;
}
const WinBattery::Battery WinBattery::batteryInfoFromUdi(const QString &udi)
{
return m_udiToGDI[udi];
}
void WinBattery::powerChanged()
{
const int old_charge = m_charge;
const int old_capacity = m_capacity;
const Solid::Battery::ChargeState old_state = m_state;
const bool old_pluggedIn = m_pluggedIn;
const bool old_isPowerSupply = m_isPowerSupply;
BATTERY_WAIT_STATUS batteryStatusQuery;
ZeroMemory(&batteryStatusQuery,sizeof(batteryStatusQuery));
Battery b = m_udiToGDI[m_device->udi()];
batteryStatusQuery.BatteryTag = b.second;
BATTERY_STATUS status = WinDeviceManager::getDeviceInfo<BATTERY_STATUS,BATTERY_WAIT_STATUS>(b.first,IOCTL_BATTERY_QUERY_STATUS,&batteryStatusQuery);
BATTERY_QUERY_INFORMATION batteryInformationQuery;
ZeroMemory(&batteryInformationQuery,sizeof(batteryInformationQuery));
batteryInformationQuery.BatteryTag = b.second;
batteryInformationQuery.InformationLevel = BatteryInformation;
BATTERY_INFORMATION info = WinDeviceManager::getDeviceInfo<BATTERY_INFORMATION,BATTERY_QUERY_INFORMATION>(b.first,IOCTL_BATTERY_QUERY_INFORMATION,&batteryInformationQuery);
m_pluggedIn = status.PowerState & BATTERY_POWER_ON_LINE;
m_isPowerSupply = true;//TODO: is there a wy to implement this
if(info.FullChargedCapacity!=0)
{
m_charge = (float)status.Capacity/info.FullChargedCapacity*100.0;
}
if(info.DesignedCapacity != 0)
{
m_capacity = (float)info.FullChargedCapacity/info.DesignedCapacity*100.0;
}
if(status.PowerState == 0)
{
m_state = Solid::Battery::NoCharge;
}
else if(status.PowerState & BATTERY_CHARGING)
{
m_state = Solid::Battery::Charging;
}
else if(status.PowerState & BATTERY_DISCHARGING)
{
m_state = Solid::Battery::Discharging;
}
// else if(info.PowerState & 0x00000008)//critical
// {
// }
if(info.Capabilities & BATTERY_SYSTEM_BATTERY)
{
m_type = Solid::Battery::PrimaryBattery;
}
else{
m_type = Solid::Battery::UnknownBattery;
}
m_rechargabel = info.Technology == 1;
if(m_charge != old_charge)
{
emit chargePercentChanged(m_charge,m_device->udi());
}
if(m_capacity != old_capacity)
{
emit capacityChanged(m_capacity,m_device->udi());
}
if(old_state != m_state)
{
emit chargeStateChanged(m_state,m_device->udi());
}
if(old_pluggedIn != m_pluggedIn)
{
emit plugStateChanged(m_pluggedIn,m_device->udi());
}
if(old_isPowerSupply != m_isPowerSupply)
{
emit powerSupplyStateChanged(m_isPowerSupply,m_device->udi());
}
}
#include "winbattery.moc"

View file

@ -1,88 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINBATTERY_H
#define WINBATTERY_H
#include <solid/ifaces/battery.h>
#include "wininterface.h"
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinBattery : public WinInterface, virtual public Solid::Ifaces::Battery
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Battery)
public:
typedef QPair<QString,ulong> Battery;
WinBattery(WinDevice *device);
virtual bool isPlugged() const;
virtual Solid::Battery::BatteryType type() const;
virtual int chargePercent() const;
virtual int capacity() const;
virtual bool isRechargeable() const;
virtual bool isPowerSupply() const;
virtual Solid::Battery::ChargeState chargeState() const;
static QSet<QString> getUdis();
static const Battery batteryInfoFromUdi(const QString &udi);
signals:
void chargePercentChanged(int value, const QString &udi) ;
void capacityChanged(int value, const QString &udi);
void chargeStateChanged(int newState, const QString &udi);
void plugStateChanged(bool newState, const QString &udi);
void powerSupplyStateChanged(bool newState, const QString &udi);
private slots:
void powerChanged();
private:
static QMap<QString,Battery> m_udiToGDI;
bool m_pluggedIn;
Solid::Battery::BatteryType m_type;
int m_charge;
int m_capacity;
bool m_rechargabel;
bool m_isPowerSupply;
Solid::Battery::ChargeState m_state;
};
}
}
}
#endif // WINBATTERY_H

View file

@ -1,218 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "winblock.h"
#include <QSettings>
#include <QDebug>
using namespace Solid::Backends::Win;
#include <ntddcdrm.h>
#include <ntddmmc.h>
QMap<QString,QString> WinBlock::m_driveLetters = QMap<QString,QString>();
QMap<QString,QSet<QString> > WinBlock::m_driveUDIS = QMap<QString,QSet<QString> >();
QMap<QString,QString> WinBlock::m_virtualDrives = QMap<QString,QString>();
WinBlock::WinBlock(WinDevice *device):
WinInterface(device),
m_major(-1),
m_minor(-1)
{
if(m_device->type() == Solid::DeviceInterface::StorageVolume)
{
STORAGE_DEVICE_NUMBER info = WinDeviceManager::getDeviceInfo<STORAGE_DEVICE_NUMBER>(driveLetterFromUdi(m_device->udi()),IOCTL_STORAGE_GET_DEVICE_NUMBER);
m_major = info.DeviceNumber;
m_minor = info.PartitionNumber;
}
else if(m_device->type() == Solid::DeviceInterface::StorageDrive ||
m_device->type() == Solid::DeviceInterface::OpticalDrive ||
m_device->type() == Solid::DeviceInterface::OpticalDisc)
{
m_major = m_device->udi().mid(m_device->udi().length()-1).toInt();
}
else
{
qFatal("Not implemented device type %i",m_device->type());
}
}
WinBlock::~WinBlock()
{
}
int WinBlock::deviceMajor() const
{
Q_ASSERT(m_major != -1);
return m_major;
}
int WinBlock::deviceMinor() const
{
return m_minor;
}
QString WinBlock::device() const
{
return driveLetterFromUdi(m_device->udi());
}
QStringList WinBlock::drivesFromMask(const DWORD unitmask)
{
QStringList result;
DWORD localUnitmask(unitmask);
for (int i = 0; i <= 25; ++i)
{
if (0x01 == (localUnitmask & 0x1))
{
result<<QString("%1:").arg((char)(i+'A'));
}
localUnitmask >>= 1;
}
return result;
}
QSet<QString> WinBlock::getUdis()
{
return updateUdiFromBitMask(GetLogicalDrives());
}
QString WinBlock::driveLetterFromUdi(const QString &udi)
{
if(!m_driveLetters.contains(udi))
qWarning()<<udi<<"is not connected to a drive";
return m_driveLetters[udi];
}
QString WinBlock::udiFromDriveLetter(const QString &drive)
{
QString out;
for(QMap<QString,QString>::const_iterator it = m_driveLetters.begin();it != m_driveLetters.end();++it)
{
if(it.value() == drive)
{
out = it.key();
break;
}
}
return out;
}
QString WinBlock::resolveVirtualDrive(const QString &drive)
{
return m_virtualDrives[drive];
}
QSet<QString> WinBlock::updateUdiFromBitMask(const DWORD unitmask)
{
QStringList drives = drivesFromMask(unitmask);
QSet<QString> list;
wchar_t driveWCHAR[MAX_PATH];
wchar_t bufferOut[MAX_PATH];
QString dosPath;
foreach(const QString &drive,drives)
{
QSet<QString> udis;
driveWCHAR[drive.toWCharArray(driveWCHAR)] = 0;
if(GetDriveType(driveWCHAR) == DRIVE_REMOTE)//network drive
{
QSettings settings(QLatin1String("HKEY_CURRENT_USER\\Network\\") + drive.at(0),QSettings::NativeFormat);
QString path = settings.value("RemotePath").toString();
if(!path.isEmpty())
{
QString key = QLatin1String("/org/kde/solid/win/volume.virtual/") + drive.at(0);
m_virtualDrives[key] = path;
udis << key;
}
}
else
{
QueryDosDeviceW(driveWCHAR,bufferOut,MAX_PATH);
dosPath = QString::fromWCharArray(bufferOut);
if(dosPath.startsWith("\\??\\"))//subst junction
{
dosPath = dosPath.mid(4);
QString key = QLatin1String("/org/kde/solid/win/volume.virtual/") + drive.at(0);
m_virtualDrives[key] = dosPath;
udis << key;
}
else
{
STORAGE_DEVICE_NUMBER info = WinDeviceManager::getDeviceInfo<STORAGE_DEVICE_NUMBER>(drive,IOCTL_STORAGE_GET_DEVICE_NUMBER);
switch(info.DeviceType)
{
case FILE_DEVICE_DISK:
{
udis << QString("/org/kde/solid/win/volume/disk#%1,partition#%2").arg(info.DeviceNumber).arg(info.PartitionNumber);
udis << QString("/org/kde/solid/win/storage/disk#%1").arg(info.DeviceNumber);
}
break;
case FILE_DEVICE_CD_ROM:
case FILE_DEVICE_DVD:
{
udis << QString("/org/kde/solid/win/storage.cdrom/disk#%1").arg(info.DeviceNumber);
DISK_GEOMETRY_EX out = WinDeviceManager::getDeviceInfo<DISK_GEOMETRY_EX>(drive,IOCTL_DISK_GET_DRIVE_GEOMETRY_EX);
if(out.DiskSize.QuadPart != 0)
{
udis << QString("/org/kde/solid/win/volume.cdrom/disk#%1").arg(info.DeviceNumber);
}
}
break;
default:
qDebug() << "unknown device" << drive << info.DeviceType << info.DeviceNumber << info.PartitionNumber;
}
}
}
m_driveUDIS[drive] = udis;
foreach(const QString&s,udis)
{
m_driveLetters[s] = drive;
}
list += udis;
}
return list;
}
QSet<QString> WinBlock::getFromBitMask(const DWORD unitmask)
{
QSet<QString> list;
QStringList drives = drivesFromMask(unitmask);
foreach(const QString &drive,drives)
{
if(m_driveUDIS.contains(drive))
{
list += m_driveUDIS[drive];
}
else
{
//we have to update the cache
return updateUdiFromBitMask(unitmask);
}
}
return list;
}
#include "winblock.moc"

View file

@ -1,70 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINBLOCK_H
#define WINBLOCK_H
#include <solid/ifaces/block.h>
#include "wininterface.h"
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinBlock : public WinInterface, virtual public Solid::Ifaces::Block
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Block)
public:
WinBlock(WinDevice *device);
~WinBlock();
virtual int deviceMajor() const;
virtual int deviceMinor() const;
virtual QString device() const;
static QSet<QString> getUdis();
static QString driveLetterFromUdi(const QString &udi);
static QString udiFromDriveLetter(const QString &drive);
static QString resolveVirtualDrive(const QString &drive);
static QSet<QString> updateUdiFromBitMask(const DWORD unitmask);
static QSet<QString> getFromBitMask(const DWORD unitmask);
private:
static QMap<QString,QString> m_driveLetters;
static QMap<QString,QSet<QString> > m_driveUDIS;
static QMap<QString,QString> m_virtualDrives;
int m_major;
int m_minor;
static QStringList drivesFromMask(const DWORD unitmask);
};
}
}
}
#endif // WINBLOCK_H

View file

@ -1,433 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "windevice.h"
#include <solid/deviceinterface.h>
#include "wingenericinterface.h"
#include "winstoragevolume.h"
#include "winblock.h"
#include "winstorageaccess.h"
#include "winstoragedrive.h"
#include "winopticaldrive.h"
#include "winopticaldisc.h"
#include "windevice.h"
#include "winprocessor.h"
#include "winbattery.h"
#include "winacadapter.h"
#include <batclass.h>
#if defined(__MINGW32__) && !defined(IOCTL_STORAGE_QUERY_PROPERTY)
#include <winioctl_backport.h>
#endif
using namespace Solid::Backends::Win;
WinDevice::WinDevice(const QString &udi) :
Device(),
m_udi(udi),
m_type(Solid::DeviceInterface::Unknown)
{
/*
/org/kde/solid/win/volume/disk #%1, partition #%2
/org/kde/solid/win/storage.cdrom/disk #%0
*/
QStringList data = udi.split("/");
QString parentName = data[6].split(",")[0].trimmed();
QString type = data[5];
if(type == "storage")
m_type = Solid::DeviceInterface::StorageDrive;
else if(type == "volume")
m_type = Solid::DeviceInterface::StorageVolume;
else if (type == "storage.cdrom")
m_type = Solid::DeviceInterface::OpticalDrive;
else if (type == "volume.cdrom")
m_type = Solid::DeviceInterface::OpticalDisc;
else if (type == "cpu")
m_type = Solid::DeviceInterface::Processor;
else if (type == "power.battery")
m_type = Solid::DeviceInterface::Battery;
else if(type == "power")
m_type = Solid::DeviceInterface::AcAdapter;
else if(type == "volume.virtual")
{
m_type = Solid::DeviceInterface::StorageAccess;
}
switch(m_type)
{
case Solid::DeviceInterface::StorageVolume:
{
m_parentUdi = QLatin1String("/org/kde/solid/win/storage/") + parentName;
}
break;
case Solid::DeviceInterface::OpticalDisc:
{
m_parentUdi = QLatin1String("/org/kde/solid/win/storage.cdrom/") + parentName;
}
break;
case Solid::DeviceInterface::StorageAccess:
{
m_parentUdi = WinBlock::udiFromDriveLetter( WinBlock::resolveVirtualDrive(udi).mid(0,2));
if(m_parentUdi.isEmpty())
{
m_parentUdi = QLatin1String("/org/kde/solid/win/")+ type;
}
}
break;
default:
m_parentUdi = QLatin1String("/org/kde/solid/win/")+ type;
}
switch(m_type)
{
case Solid::DeviceInterface::Processor:
initCpuDevice();
break;
case Solid::DeviceInterface::Battery:
initBatteryDevice();
break;
case Solid::DeviceInterface::AcAdapter:
m_description = QObject::tr("A/C Adapter");
break;
default:
if(queryDeviceInterface(Solid::DeviceInterface::StorageAccess) || queryDeviceInterface(Solid::DeviceInterface::StorageDrive))
{
initStorageDevice();
}
else
{
qWarning()<<"Unknown device"<<udi;
}
}
}
void WinDevice::initStorageDevice()
{
QString dev;
switch(m_type)
{
case Solid::DeviceInterface::StorageAccess:
dev = WinBlock::driveLetterFromUdi(udi());
m_product = QString("Virtual drive %1").arg(dev);
m_description = QString("%1 (%2)").arg(dev, WinBlock::resolveVirtualDrive(udi()));
return;
case Solid::DeviceInterface::OpticalDrive:
dev = WinBlock::driveLetterFromUdi(udi());
break;
case Solid::DeviceInterface::StorageDrive:
dev = QString("PhysicalDrive%1").arg(WinBlock(this).deviceMajor());
break;
default:
dev = WinBlock::driveLetterFromUdi(udi());
m_description = QString("%1 (%2)").arg(dev, WinStorageVolume(this).label());
}
STORAGE_PROPERTY_QUERY query;
ZeroMemory(&query,sizeof(STORAGE_PROPERTY_QUERY));
query.PropertyId = StorageDeviceProperty;
query.QueryType = PropertyStandardQuery;
char buff[1024];
WinDeviceManager::getDeviceInfo<char,STORAGE_PROPERTY_QUERY>(dev,IOCTL_STORAGE_QUERY_PROPERTY,buff,1024,&query);
STORAGE_DEVICE_DESCRIPTOR *info = ((STORAGE_DEVICE_DESCRIPTOR*)buff);
if(info->VendorIdOffset != 0)
{
m_vendor = QString((char*)buff+ info->VendorIdOffset).trimmed();
if(info->ProductIdOffset != 0)
{
m_product = QString((char*)buff+ info->ProductIdOffset).trimmed();
}
}
else if(info->ProductIdOffset != 0)//fallback doesnt work for all devices
{
QStringList tmp = QString((char*)buff+ info->ProductIdOffset).trimmed().split(" ");
m_vendor = tmp.takeFirst();
m_product = tmp.join(" ");
}
}
void WinDevice::initBatteryDevice()
{
WinBattery::Battery battery = WinBattery::batteryInfoFromUdi(m_udi);
BATTERY_QUERY_INFORMATION query;
ZeroMemory(&query,sizeof(query));
query.BatteryTag = battery.second;
size_t size = 1024;
wchar_t buff[1024];
query.InformationLevel = BatteryDeviceName;
WinDeviceManager::getDeviceInfo<wchar_t,BATTERY_QUERY_INFORMATION>(battery.first,IOCTL_BATTERY_QUERY_INFORMATION,buff,size,&query);
m_product = QString::fromWCharArray(buff);
query.InformationLevel = BatteryManufactureName;
WinDeviceManager::getDeviceInfo<wchar_t,BATTERY_QUERY_INFORMATION>(battery.first,IOCTL_BATTERY_QUERY_INFORMATION,buff,size,&query);
m_vendor = QString::fromWCharArray(buff);
query.InformationLevel = BatteryInformation;
BATTERY_INFORMATION info = WinDeviceManager::getDeviceInfo<BATTERY_INFORMATION,BATTERY_QUERY_INFORMATION>(battery.first,IOCTL_BATTERY_QUERY_INFORMATION,&query);
if(info.Chemistry != 0)
{
QString tech = QString::fromUtf8((const char*)info.Chemistry,4);
m_description = QObject::tr("%1 Battery", "%1 is battery technology").arg(batteryTechnology(tech.toUpper()));
}
}
void WinDevice::initCpuDevice()
{
WinProcessor cpu(this);
WinProcessor::ProcessorInfo info = WinProcessor::updateCache()[cpu.number()];
m_vendor = info.vendor;
m_product = info.produuct;
m_description = info.name;
}
QString WinDevice::udi() const
{
return m_udi;
}
QString WinDevice::parentUdi() const
{
return m_parentUdi;
}
QString WinDevice::vendor() const
{
return m_vendor;
}
QString WinDevice::product() const
{
return m_product;
}
QString WinDevice::description() const
{
return m_description.isEmpty()?m_product:m_description;
}
QString WinDevice::icon() const
{
if (parentUdi().isEmpty()) {
return QLatin1String("computer");
}
QString icon;
switch(type()){
case Solid::DeviceInterface::OpticalDrive:
icon = QLatin1String("drive-optical");
break;
case Solid::DeviceInterface::OpticalDisc:
{
WinOpticalDisc disk(const_cast<WinDevice*>(this));
if(disk.availableContent() & Solid::OpticalDisc::Audio)
{
icon = QLatin1String("media-optical-audio");
}
else
{
icon = QLatin1String("drive-optical");
}
break;
}
case Solid::DeviceInterface::StorageDrive:
case Solid::DeviceInterface::StorageVolume:
{
WinStorageDrive storage(const_cast<WinDevice*>(this));
if(storage.bus() == Solid::StorageDrive::Usb)
icon = QLatin1String("drive-removable-media-usb-pendrive");
else
icon = QLatin1String("drive-harddisk");
}
break;
case Solid::DeviceInterface::Processor:
icon = QLatin1String("cpu");
break;
case Solid::DeviceInterface::Battery:
icon = QLatin1String("battery");
break;
case Solid::DeviceInterface::AcAdapter:
icon = QLatin1String("preferences-system-power-management");
break;
case Solid::DeviceInterface::StorageAccess:
icon = QLatin1String("drive-harddisk");
break;
default:
break;
}
return icon;
}
QStringList WinDevice::emblems() const
{
QStringList icons;
switch(type()){
case Solid::DeviceInterface::StorageAccess:
icons << QLatin1String("emblem-symbolic-link");
break;
default:
break;
}
return icons;
}
bool WinDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &queryType) const
{
if (queryType == Solid::DeviceInterface::GenericInterface) {
return true;
}
QList<Solid::DeviceInterface::Type> interfaceList;
interfaceList << type();
switch (type())
{
case Solid::DeviceInterface::GenericInterface:
break;
case Solid::DeviceInterface::Block:
break;
case Solid::DeviceInterface::StorageAccess:
break;
case Solid::DeviceInterface::StorageDrive:
break;
case Solid::DeviceInterface::OpticalDrive:
interfaceList << Solid::DeviceInterface::Block << Solid::DeviceInterface::StorageDrive;
break;
case Solid::DeviceInterface::StorageVolume:
interfaceList << Solid::DeviceInterface::Block << Solid::DeviceInterface::StorageAccess;
break;
case Solid::DeviceInterface::OpticalDisc:
interfaceList << Solid::DeviceInterface::Block << Solid::DeviceInterface::StorageVolume << Solid::DeviceInterface::StorageAccess;
break;
case Solid::DeviceInterface::PortableMediaPlayer:
break;
case Solid::DeviceInterface::Unknown:
case Solid::DeviceInterface::Last:
default:
break;
}
if (interfaceList.size() == 0)
qWarning() << "no interface found for type" << type();
return interfaceList.contains(queryType);
}
QObject *WinDevice::createDeviceInterface(const Solid::DeviceInterface::Type &type)
{
if (!queryDeviceInterface(type)) {
return 0;
}
WinInterface *iface = 0;
switch (type)
{
case Solid::DeviceInterface::GenericInterface:
iface = new WinGenericInterface(this);
break;
case Solid::DeviceInterface::Block:
iface = new WinBlock(this);
break;
case Solid::DeviceInterface::Processor:
iface = new WinProcessor(this);
break;
case Solid::DeviceInterface::StorageAccess:
iface = new WinStorageAccess(this);
break;
case Solid::DeviceInterface::StorageDrive:
iface = new WinStorageDrive(this);
break;
case Solid::DeviceInterface::OpticalDrive:
iface = new WinOpticalDrive(this);
break;
case Solid::DeviceInterface::StorageVolume:
iface = new WinStorageVolume(this);
break;
case Solid::DeviceInterface::OpticalDisc:
iface = new WinOpticalDisc(this);
break;
// case Solid::DeviceInterface::PortableMediaPlayer:
// iface = new PortableMediaPlayer(this);
// break;
case Solid::DeviceInterface::Battery:
iface = new WinBattery(this);
break;
case Solid::DeviceInterface::AcAdapter:
iface = new WinAcadapter(this);
break;
case Solid::DeviceInterface::Unknown:
case Solid::DeviceInterface::Last:
break;
default:
break;
}
return iface;
}
Solid::DeviceInterface::Type WinDevice::type() const
{
return m_type;
}
QString WinDevice::batteryTechnology(QString tec) const
{
//based on upowerdevice.cpp
if(tec == "LION" || tec == "LI-I")
{
return QObject::tr("Lithium Ion", "battery technology");
}
else if(tec == "PBAC")
{
return QObject::tr("Lead Acid", "battery technology");
}
else if(tec == "NICD")
{
return QObject::tr("Nickel Cadmium", "battery technology");
}
else if(tec == "NIMH")
{
return QObject::tr("Nickel Metal Hydride", "battery technology");
}
else if(tec == "NIZN")
{
return QObject::tr("Nickel Zinc", "battery technology");
}
else
{
qDebug()<<tec<< QObject::tr("Unknown", "battery technology");
return QObject::tr("Unknown", "battery technology");
}
}
#include "windevice.moc"

View file

@ -1,78 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINDEVICE_H
#define WINDEVICE_H
#include <solid/ifaces/device.h>
#include "windevicemanager.h"
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinDevice : public Solid::Ifaces::Device
{
Q_OBJECT
public:
WinDevice(const QString &udi);
virtual QString udi() const;
virtual QString parentUdi() const;
virtual QString vendor() const;
virtual QString product() const;
virtual QString icon() const;
virtual QStringList emblems() const;
virtual QString description() const;
virtual bool queryDeviceInterface(const Solid::DeviceInterface::Type &type) const;
virtual QObject *createDeviceInterface(const Solid::DeviceInterface::Type &type);
Solid::DeviceInterface::Type type() const;
private:
QString m_udi;
QString m_parentUdi;
QString m_vendor;
QString m_product;
QString m_description;
Solid::DeviceInterface::Type m_type;
void initStorageDevice();
void initBatteryDevice();
void initCpuDevice();
QString batteryTechnology(QString tech) const;
};
}
}
}
#endif // WINDEVICE_H

View file

@ -1,250 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include <solid/deviceinterface.h>
#include "windevicemanager.h"
#include "windevice.h"
#include "winprocessor.h"
#include "winblock.h"
#include "winbattery.h"
#include "winacadapter.h"
#include <dbt.h>
#include <QDebug>
#include <QTimer>
#include <QTime>
#include <QApplication>
using namespace Solid::Backends::Win;
WinDeviceManager *WinDeviceManager::m_instance = NULL;
WinDeviceManager::WinDeviceManager(QObject *parent)
:DeviceManager(parent)
{
if(m_instance)
qFatal("There are multiple WinDeviceManager instances");
m_instance = this;
m_supportedInterfaces << Solid::DeviceInterface::GenericInterface
// << Solid::DeviceInterface::Block
<< Solid::DeviceInterface::StorageAccess
<< Solid::DeviceInterface::StorageDrive
<< Solid::DeviceInterface::OpticalDrive
<< Solid::DeviceInterface::StorageVolume
<< Solid::DeviceInterface::OpticalDisc
<< Solid::DeviceInterface::Processor
<< Solid::DeviceInterface::Battery
<< Solid::DeviceInterface::AcAdapter;
updateDeviceList();
wchar_t title[] = L"KDEWinDeviceManager";
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = WinDeviceManager::WndProc;
wcex.hInstance = (HINSTANCE)::GetModuleHandle(NULL);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wcex.lpszClassName = title;
if(RegisterClassEx(&wcex) ==0)
{
qWarning() << "Failed to initialize KDEWinDeviceManager we will be unable to detect device changes";
return;
}
m_windowID = CreateWindow(title, title, WS_ICONIC, 0, 0,
CW_USEDEFAULT, 0, NULL, NULL, wcex.hInstance, NULL);
if(m_windowID == NULL)
{
qWarning() << "Failed to initialize KDEWinDeviceManager we will be unable to detect device changes";
return;
}
ShowWindow(m_windowID, SW_HIDE);
}
WinDeviceManager::~WinDeviceManager()
{
PostMessage(m_windowID, WM_CLOSE, 0, 0);
m_instance = NULL;
}
QString WinDeviceManager::udiPrefix() const
{
return QString();
}
QSet<Solid::DeviceInterface::Type> Solid::Backends::Win::WinDeviceManager::supportedInterfaces() const
{
return m_supportedInterfaces;
}
QStringList WinDeviceManager::allDevices()
{
return m_devicesList;
}
QStringList WinDeviceManager::devicesFromQuery(const QString &parentUdi, Solid::DeviceInterface::Type type)
{
QStringList list;
if (!parentUdi.isEmpty())
{
foreach(const QString &udi,allDevices()){
WinDevice device(udi);
if(device.type() == type && device.parentUdi() == parentUdi ){
list << udi;
}
}
} else if (type!=Solid::DeviceInterface::Unknown) {
foreach(const QString &udi,allDevices()){
WinDevice device(udi);
if(device.queryDeviceInterface(type)){
list << udi;
}
}
} else {
list << allDevices();
}
return list;
}
QObject *Solid::Backends::Win::WinDeviceManager::createDevice(const QString &udi)
{
if (allDevices().contains(udi)) {
return new WinDevice(udi);
} else {
return 0;
}
}
const WinDeviceManager *WinDeviceManager::instance()
{
return m_instance;
}
void WinDeviceManager::updateDeviceList()
{
QSet<QString> devices = WinProcessor::getUdis();
devices += WinBlock::getUdis();
devices += WinBattery::getUdis();
devices += WinAcadapter::getUdis();
m_devices = devices;
m_devicesList = m_devices.toList();
qSort(m_devicesList);
}
LRESULT WinDeviceManager::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//some parts of the code are based on http://www.codeproject.com/Articles/119168/Hardware-Change-Detection
switch(message)
{
case WM_DEVICECHANGE:
{
if ((wParam == DBT_DEVICEARRIVAL) || (wParam == DBT_DEVICEREMOVECOMPLETE))
{
DEV_BROADCAST_HDR* header = reinterpret_cast<DEV_BROADCAST_HDR*>(lParam);
if (header->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
DEV_BROADCAST_VOLUME* devNot = reinterpret_cast<DEV_BROADCAST_VOLUME*>(lParam);
switch(wParam)
{
case DBT_DEVICEREMOVECOMPLETE:
{
QSet<QString> udis = WinBlock::getFromBitMask(devNot->dbcv_unitmask);
m_instance->promoteRemovedDevice(udis);
}
break;
case DBT_DEVICEARRIVAL:
{
QSet<QString> udis = WinBlock::updateUdiFromBitMask(devNot->dbcv_unitmask);
m_instance->promoteAddedDevice(udis);
}
break;
}
break;
}
}
}
break;
case WM_POWERBROADCAST:
{
m_instance->promotePowerChange();
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
void WinDeviceManager::promoteAddedDevice(const QSet<QString> &udi)
{
QSet<QString> tmp = udi - m_devices;//dont report devices that are already known(cd drive)
m_devices += tmp;
m_devicesList = m_devices.toList();
qSort(m_devicesList);
foreach(const QString &s,tmp)
{
emit deviceAdded(s);
}
}
void WinDeviceManager::promoteRemovedDevice(const QSet<QString> &udi)
{
m_devices -= udi;
m_devicesList = m_devices.toList();
qSort(m_devicesList);
foreach(const QString &s,udi)
{
emit deviceRemoved(s);
}
}
void WinDeviceManager::promotePowerChange()
{
emit powerChanged();
}
#include <windevicemanager.moc>

View file

@ -1,191 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINDEVICEMANAGER_H
#define WINDEVICEMANAGER_H
#include <solid/ifaces/devicemanager.h>
#include <QSet>
#include <QDebug>
#include <windows.h>
#include <winioctl.h>
inline QString qGetLastError(ulong errorNummber = GetLastError())
{
LPVOID error = NULL;
size_t len = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
errorNummber,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR) &error ,
0, NULL );
QString out = QString::fromWCharArray((wchar_t*)error,len).trimmed().append(" %1").arg(errorNummber);
LocalFree(error);
return out;
}
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinDeviceManager : public Solid::Ifaces::DeviceManager
{
Q_OBJECT
public:
WinDeviceManager(QObject *parent=0);
~WinDeviceManager();
virtual QString udiPrefix() const;
virtual QSet<Solid::DeviceInterface::Type> supportedInterfaces() const;
virtual QStringList allDevices();
virtual QStringList devicesFromQuery(const QString &parentUdi,
Solid::DeviceInterface::Type type = Solid::DeviceInterface::Unknown);
virtual QObject *createDevice(const QString &udi);
static const WinDeviceManager *instance();
template< class INFO>
static INFO getDeviceInfo(const QString &devName, int code)
{
return getDeviceInfo<INFO,void*>(devName,code);
}
template< class INFO, class QUERY>
static INFO getDeviceInfo(const QString &devName, int code, QUERY *query = NULL)
{
INFO info;
ZeroMemory(&info,sizeof(INFO));
getDeviceInfoPrivate(devName,code,&info,sizeof(INFO),query);
return info;
}
template<class BUFFER_TYPE,class QUERY>
static void getDeviceInfo(const QString &devName, int code, BUFFER_TYPE *out, size_t outSize, QUERY *query = NULL)
{
ZeroMemory(out,sizeof(BUFFER_TYPE)*outSize);
getDeviceInfoPrivate(devName,code,out,outSize,query);
}
static void deviceAction(const QString &devName, int code)
{
getDeviceInfoPrivate<void,void*>(devName,code,NULL,0,NULL);
}
signals:
void powerChanged();
private slots:
void updateDeviceList();
private:
static WinDeviceManager *m_instance;
HWND m_windowID;
QSet<QString> m_devices;
QStringList m_devicesList;
QSet<Solid::DeviceInterface::Type> m_supportedInterfaces;
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void promoteAddedDevice(const QSet<QString> &udi);
void promoteRemovedDevice(const QSet<QString> &udi);
void promotePowerChange();
template< class INFO, class QUERY>
static void getDeviceInfoPrivate(const QString &devName, int code,INFO *info,size_t size, QUERY *query = NULL)
{
Q_ASSERT(!devName.isNull());
wchar_t deviceNameBuffer[MAX_PATH];
QString dev = devName;
if(!dev.startsWith("\\"))
{
dev = QLatin1String("\\\\?\\") + dev;
}
deviceNameBuffer[dev.toWCharArray(deviceNameBuffer)] = 0;
DWORD bytesReturned = 0;
ulong err = NO_ERROR;
HANDLE handle = ::CreateFileW(deviceNameBuffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL , OPEN_EXISTING , 0, NULL);
if(handle == INVALID_HANDLE_VALUE)
{
err = GetLastError();
if(err == ERROR_ACCESS_DENIED)
{
//we would need admin rights for GENERIC_READ on systenm drives and volumes
handle = ::CreateFileW(deviceNameBuffer, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL , OPEN_EXISTING , 0, NULL);
err = GetLastError();
}
if(handle == INVALID_HANDLE_VALUE)
{
qWarning() << "Invalid Handle" << dev << "reason:" << qGetLastError(err) << " this should not happen.";
return;
}
}
if(::DeviceIoControl(handle, code, query, sizeof(QUERY), info, size, &bytesReturned, NULL))
{
::CloseHandle(handle);
return;
}
if(handle == INVALID_HANDLE_VALUE)
{
qWarning() <<" Invalid Handle" << devName << "reason:" << qGetLastError() << " is probaply a subst path or more seriously there is bug!";
return;
}
err = GetLastError();
if(err == ERROR_NOT_READY)
{
//the drive is a cd drive with no disk
::CloseHandle(handle);
return;
}
#if 0
::CloseHandle(handle);
qFatal("Failed to query %s reason: %s", qPrintable(dev), qPrintable(qGetLastError(err)));
#else
qWarning() << "Failed to query" << dev << "reason:" << qGetLastError(err);
#endif
::CloseHandle(handle);
}
};
}
}
}
#endif // WINDEVICEMANAGER_H

View file

@ -1,52 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wingenericinterface.h"
using namespace Solid::Backends::Win;
WinGenericInterface::WinGenericInterface(WinDevice *device)
:WinInterface(device)
{
}
QVariant WinGenericInterface::property(const QString &key) const
{
Q_UNUSED(key)
qFatal("Not implemented");
return QVariant();
}
QMap<QString, QVariant> Solid::Backends::Win::WinGenericInterface::allProperties() const
{
qFatal("Not implemented");
return QMap<QString, QVariant>();
}
bool WinGenericInterface::propertyExists(const QString &key) const
{
Q_UNUSED(key)
qFatal("Not implemented");
return true;
}
#include "wingenericinterface.moc"

View file

@ -1,55 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINGENERICINTERFACE_H
#define WINGENERICINTERFACE_H
#include <solid/ifaces/genericinterface.h>
#include "wininterface.h"
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinGenericInterface : public WinInterface,virtual public Solid::Ifaces::GenericInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::GenericInterface)
public:
WinGenericInterface(WinDevice *device);
virtual QVariant property(const QString &key) const;
virtual QMap<QString, QVariant> allProperties() const;
virtual bool propertyExists(const QString &key) const;
signals:
void propertyChanged(const QMap<QString,int> &changes);
void conditionRaised(const QString &condition, const QString &reason);
};
}
}
}
#endif // WINGENERICINTERFACE_H

View file

@ -1,42 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wininterface.h"
using namespace Solid::Backends::Win;
WinInterface::WinInterface(WinDevice *device)
:QObject(device)
,m_device(device)
{
}
WinInterface::~WinInterface()
{
}
#include "wininterface.moc"

View file

@ -1,53 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WININTERFACE_H
#define WININTERFACE_H
#include <solid/ifaces/deviceinterface.h>
#include "windevice.h"
#include <QDebug>
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinInterface : public QObject, virtual public Solid::Ifaces::DeviceInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::DeviceInterface)
public:
WinInterface(WinDevice *device);
virtual ~WinInterface();
protected:
WinDevice *m_device;
};
}
}
}
#endif // WININTERFACE_H

View file

@ -1,115 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "winopticaldisc.h"
#include "winopticaldrive.h"
#include <ntddcdrm.h>
#include <ntddmmc.h>
using namespace Solid::Backends::Win;
WinOpticalDisc::WinOpticalDisc(WinDevice *device) :
WinStorageVolume(device),
m_discType(Solid::OpticalDisc::UnknownDiscType),
m_isRewritable(false)
{
//TODO: blueray etc
QMap<ulong,MediaProfiles> profiles = MediaProfiles::profiles(WinBlock::driveLetterFromUdi(m_device->udi()));
if(profiles[ProfileCdRecordable].active)
{
m_discType = Solid::OpticalDisc::CdRecordable;
}else if(profiles[ProfileCdRewritable].active)
{
m_discType = Solid::OpticalDisc::CdRewritable;
m_isRewritable = true;
}
else if(profiles[ProfileCdrom].active)
{
m_discType = Solid::OpticalDisc::CdRom;
}
else if(profiles[ProfileDvdRecordable].active)
{
m_discType = Solid::OpticalDisc::DvdRecordable;
}
else if(profiles[ProfileDvdRewritable].active)
{
m_discType = Solid::OpticalDisc::DvdRewritable;
m_isRewritable = true;
}
else if(profiles[ProfileDvdRom].active)
{
m_discType = Solid::OpticalDisc::DvdRom;
}
else
{
m_discType = Solid::OpticalDisc::UnknownDiscType;
}
}
WinOpticalDisc::~WinOpticalDisc()
{
}
Solid::OpticalDisc::ContentTypes WinOpticalDisc::availableContent() const
{
return Solid::OpticalDisc::NoContent;
}
Solid::OpticalDisc::DiscType WinOpticalDisc::discType() const
{
return m_discType;
}
bool WinOpticalDisc::isAppendable() const
{
return false;
}
bool WinOpticalDisc::isBlank() const
{
wchar_t dLetter[MAX_PATH];
int dLetterSize = WinBlock::driveLetterFromUdi(m_device->udi()).toWCharArray(dLetter);
dLetter[dLetterSize] = (wchar_t)'\\';
dLetter[dLetterSize+1] = 0;
ULARGE_INTEGER sizeTotal;
ULARGE_INTEGER sizeFree;
if(GetDiskFreeSpaceEx(dLetter,&sizeFree,&sizeTotal,NULL))
{
return sizeFree.QuadPart>0 && sizeTotal.QuadPart == 0;
}
//FIXME: the call will fail on a blank cd, and inf there is no cd, but if we got a disc type we could guess that it is a blank cd
return m_discType != Solid::OpticalDisc::UnknownDiscType ;
}
bool WinOpticalDisc::isRewritable() const
{
return m_isRewritable;
}
qulonglong WinOpticalDisc::capacity() const
{
return size();
}
#include "winopticaldisc.moc"

View file

@ -1,68 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINOPTICALDISC_H
#define WINOPTICALDISC_H
#include <solid/ifaces/opticaldisc.h>
#include "winstoragevolume.h"
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinOpticalDisc : public WinStorageVolume, virtual public Solid::Ifaces::OpticalDisc
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::OpticalDisc)
public:
WinOpticalDisc(WinDevice *device);
virtual ~WinOpticalDisc();
virtual Solid::OpticalDisc::ContentTypes availableContent() const;
virtual Solid::OpticalDisc::DiscType discType() const;
virtual bool isAppendable() const;
virtual bool isBlank() const;
virtual bool isRewritable() const;
virtual qulonglong capacity() const;
private:
Solid::OpticalDisc::DiscType m_discType;
bool m_isRewritable;
bool m_isBlank;
bool m_isAppendable;
};
}
}
}
#endif // WINOPTICALDISC_H

View file

@ -1,166 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "winopticaldrive.h"
#include <ntddcdrm.h>
#include <ntddmmc.h>
using namespace Solid::Backends::Win;
WinOpticalDrive::WinOpticalDrive(WinDevice *device) :
WinStorageDrive(device)
{
QMap<ulong,MediaProfiles> profiles = MediaProfiles::profiles(WinBlock::driveLetterFromUdi(m_device->udi()));
foreach(const MediaProfiles p,profiles.values())
{
m_supportedTypes |= p.type;
}
}
WinOpticalDrive::~WinOpticalDrive()
{
}
Solid::OpticalDrive::MediumTypes WinOpticalDrive::supportedMedia() const
{
return m_supportedTypes;
}
bool WinOpticalDrive::eject()
{
WinDeviceManager::deviceAction(WinBlock::driveLetterFromUdi(m_device->udi()),IOCTL_STORAGE_EJECT_MEDIA);
return true;
}
QList<int> WinOpticalDrive::writeSpeeds() const
{
return QList<int>();
}
int WinOpticalDrive::writeSpeed() const
{
return 0;
}
int WinOpticalDrive::readSpeed() const
{
return 0;
}
MediaProfiles::MediaProfiles() :
profile(0),
type(0),
active(false)
{
}
MediaProfiles::MediaProfiles(ulong profile, Solid::OpticalDrive::MediumTypes type, QString name):
profile(profile),
type(type),
name(name),
active(false)
{
}
MediaProfiles::MediaProfiles(FEATURE_DATA_PROFILE_LIST_EX *feature) :
profile(0),
type(0),
active(false)
{
ulong val = (feature->ProfileNumber[0] << 8 | feature->ProfileNumber[1] << 0);
MediaProfiles p = MediaProfiles::getProfile(val);
if(!p.isNull())
{
profile = p.profile;
type = p.type;
name = p.name;
active = feature->Current;
}
}
bool MediaProfiles::isNull()
{
return name.isNull();
}
QMap<ulong,MediaProfiles> MediaProfiles::profiles(const QString &drive)
{
//thx to http://www.adras.com/Determine-optical-drive-type-and-capabilities.t6826-144-1.html
QMap<ulong,MediaProfiles> out;
size_t buffSize = 1024;
char buffer[1024];
GET_CONFIGURATION_IOCTL_INPUT input;
ZeroMemory(&input,sizeof(GET_CONFIGURATION_IOCTL_INPUT));
input.Feature = FeatureProfileList;
input.RequestType = SCSI_GET_CONFIGURATION_REQUEST_TYPE_ALL;
WinDeviceManager::getDeviceInfo<char,GET_CONFIGURATION_IOCTL_INPUT>(drive,IOCTL_CDROM_GET_CONFIGURATION,buffer,buffSize,&input);
GET_CONFIGURATION_HEADER *info = (GET_CONFIGURATION_HEADER*)buffer;
FEATURE_DATA_PROFILE_LIST* profile = (FEATURE_DATA_PROFILE_LIST*)info->Data;
FEATURE_DATA_PROFILE_LIST_EX* feature = profile->Profiles;
for(int i = 0;i<profile->Header.AdditionalLength/4;++feature,++i)
{
MediaProfiles p = MediaProfiles(feature);
if(!p.isNull())
{
out.insert(p.profile,p);
}
}
return out;
}
const MediaProfiles MediaProfiles::getProfile(ulong val)
{
#define AddProfile(profile,type) profiles.insert(profile,MediaProfiles(profile,type,#profile))
static QMap<ulong,MediaProfiles> profiles;
if(profiles.isEmpty())
{
AddProfile(ProfileCdrom,0);
AddProfile(ProfileCdRecordable,Solid::OpticalDrive::Cdr);
AddProfile(ProfileCdRewritable,Solid::OpticalDrive::Cdrw);
AddProfile(ProfileDvdRom,Solid::OpticalDrive::Dvd);
AddProfile(ProfileDvdRecordable,Solid::OpticalDrive::Dvdr);
AddProfile(ProfileDvdRewritable,Solid::OpticalDrive::Dvdrw);
AddProfile(ProfileDvdRam,Solid::OpticalDrive::Dvdram);
AddProfile(ProfileDvdPlusR,Solid::OpticalDrive::Dvdplusr);
AddProfile(ProfileDvdPlusRW,Solid::OpticalDrive::Dvdplusrw);
AddProfile(ProfileDvdPlusRDualLayer,Solid::OpticalDrive::Dvdplusdl);
AddProfile(ProfileDvdPlusRWDualLayer,Solid::OpticalDrive::Dvdplusdlrw);
AddProfile(ProfileBDRom,Solid::OpticalDrive::Bd);
AddProfile(ProfileBDRRandomWritable,Solid::OpticalDrive::Bdr);
AddProfile(ProfileBDRSequentialWritable,Solid::OpticalDrive::Bdr);
AddProfile(ProfileBDRewritable,Solid::OpticalDrive::Bdre);
AddProfile(ProfileHDDVDRom,Solid::OpticalDrive::HdDvd);
AddProfile(ProfileHDDVDRecordable,Solid::OpticalDrive::HdDvdr);
AddProfile(ProfileHDDVDRewritable,Solid::OpticalDrive::HdDvdrw);
}
return profiles[val];
}
#include "winopticaldrive.moc"

View file

@ -1,88 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINOPTICALDRIVE_H
#define WINOPTICALDRIVE_H
#include <solid/ifaces/opticaldrive.h>
#include "winstoragedrive.h"
struct _FEATURE_DATA_PROFILE_LIST_EX;
typedef _FEATURE_DATA_PROFILE_LIST_EX FEATURE_DATA_PROFILE_LIST_EX;
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinOpticalDrive : public WinStorageDrive, virtual public Solid::Ifaces::OpticalDrive
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::OpticalDrive)
public:
WinOpticalDrive(WinDevice *device);
virtual ~WinOpticalDrive();
virtual Solid::OpticalDrive::MediumTypes supportedMedia() const;
virtual int readSpeed() const;
virtual int writeSpeed() const;
virtual QList<int> writeSpeeds() const;
virtual bool eject();
signals:
void ejectPressed(const QString &udi);
void ejectDone(Solid::ErrorType error, QVariant errorData, const QString &udi);
private:
Solid::OpticalDrive::MediumTypes m_supportedTypes;
};
class MediaProfiles//TODO: cleanup
{
public:
MediaProfiles();
ulong profile;
Solid::OpticalDrive::MediumTypes type;
QString name;
bool active;
static QMap<ulong, MediaProfiles> profiles(const QString &drive);
private:
MediaProfiles(ulong profile,Solid::OpticalDrive::MediumTypes type,QString name = "");
MediaProfiles(FEATURE_DATA_PROFILE_LIST_EX* feature);
bool isNull();
static const MediaProfiles getProfile(ulong id);
};
}
}
}
#endif // WINOPTICALDRIVE_H

View file

@ -1,144 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "winprocessor.h"
#include <solid/backends/shared/cpufeatures.h>
#include <QSettings>
using namespace Solid::Backends::Win;
typedef BOOL (WINAPI *GLPI_fn)(SYSTEM_LOGICAL_PROCESSOR_INFORMATION* Buffer, DWORD* ReturnLength);
GLPI_fn pGetLogicalProcessorInformation = (GLPI_fn)GetProcAddress(LoadLibraryA("kernel32.dll"), "GetLogicalProcessorInformation");
WinProcessor::WinProcessor(WinDevice *device):
WinInterface(device)
{
m_number = m_device->udi().mid(m_device->udi().length()-1).toInt();
}
WinProcessor::~WinProcessor()
{
}
int WinProcessor::number() const
{
return m_number;
}
int WinProcessor::maxSpeed() const
{
return updateCache()[m_number].speed;
}
bool WinProcessor::canChangeFrequency() const
{
//TODO:implement
return false;
}
Solid::Processor::InstructionSets WinProcessor::instructionSets() const
{
static Solid::Processor::InstructionSets set = Solid::Backends::Shared::cpuFeatures();
return set;
}
QSet<QString> WinProcessor::getUdis()
{
static QSet<QString> out;
if(out.isEmpty())
{
foreach(const ProcessorInfo &info,updateCache())
{
out << QString("/org/kde/solid/win/cpu/device#%1,cpu#%2").arg(info.id).arg(info.lgicalId);
}
}
return out;
}
DWORD WinProcessor::countSetBits(ULONG_PTR bitMask)
{
DWORD LSHIFT = sizeof(ULONG_PTR)*8 - 1;
DWORD bitSetCount = 0;
ULONG_PTR bitTest = (ULONG_PTR)1 << LSHIFT;
DWORD i;
for (i = 0; i <= LSHIFT; ++i)
{
bitSetCount += ((bitMask & bitTest)?1:0);
bitTest/=2;
}
return bitSetCount;
}
const QMap<int,WinProcessor::ProcessorInfo> &WinProcessor::updateCache()
{
static QMap<int,ProcessorInfo> p;
if(p.isEmpty())
{
DWORD size = 0;
pGetLogicalProcessorInformation(NULL,&size);
char *buff = new char[size];
SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION*)buff;
pGetLogicalProcessorInformation(info,&size);
size /= sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
uint processorCoreCount = 0;
uint logicalProcessorCount = 0;
for(uint i=0;i< size;++i)
{
if (info[i].Relationship == RelationProcessorCore)
{
// A hyperthreaded core supplies more than one logical processor.
uint old = logicalProcessorCount;
logicalProcessorCount += countSetBits(info[i].ProcessorMask);
for(;old<logicalProcessorCount;++old)
{
QSettings settings(QLatin1String("HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\") + QString::number(old), QSettings::NativeFormat);
ProcessorInfo proc;
proc.id = processorCoreCount;
proc.lgicalId = old;
proc.speed = settings.value("~MHz").toInt();
proc.vendor = settings.value("VendorIdentifier").toString().trimmed();
proc.name = settings.value("ProcessorNameString").toString().trimmed();
proc.produuct = settings.value("Identifier").toString().trimmed();
p[old] = proc;
}
processorCoreCount++;
}
}
delete [] buff;
}
return p;
}
#include "winprocessor.moc"

View file

@ -1,76 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINPROCESSOR_H
#define WINPROCESSOR_H
#include <solid/ifaces/processor.h>
#include "wininterface.h"
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinProcessor :public WinInterface, public Solid::Ifaces::Processor
{
friend class WinDevice;
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Processor)
public:
WinProcessor(WinDevice *device);
~WinProcessor();
virtual int number() const;
virtual int maxSpeed() const;
virtual bool canChangeFrequency() const;
virtual Solid::Processor::InstructionSets instructionSets() const;
static QSet<QString> getUdis();
private:
int m_number;
class ProcessorInfo
{
public:
int lgicalId;
int id;
int speed;
QString vendor;
QString name;
QString produuct;
};
static DWORD countSetBits(ULONG_PTR bitMask);
static const QMap<int, WinProcessor::ProcessorInfo> &updateCache();
};
}
}
}
#endif // WINPROCESSOR_H

View file

@ -1,69 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "winstorageaccess.h"
#include "winblock.h"
#include "winstoragedrive.h"
using namespace Solid::Backends::Win;
WinStorageAccess::WinStorageAccess(WinDevice *device) :
WinInterface(device)
{
}
WinStorageAccess::~WinStorageAccess()
{
}
bool WinStorageAccess::isAccessible() const
{
return true;
}
QString WinStorageAccess::filePath() const
{
return WinBlock::driveLetterFromUdi(m_device->udi()).append("/");
}
bool WinStorageAccess::isIgnored() const
{
return false;
}
bool WinStorageAccess::setup()
{
return true;
}
bool WinStorageAccess::teardown()
{
//only allow eject if we are an usb stick
//else we get "The request could not be performed because of an I/O device error. 1117"
if(m_device->queryDeviceInterface(Solid::DeviceInterface::StorageVolume) && WinStorageDrive(m_device).driveType() == Solid::StorageDrive::MemoryStick)
{
WinDeviceManager::deviceAction(WinBlock::driveLetterFromUdi(m_device->udi()),IOCTL_STORAGE_EJECT_MEDIA);
}
return true;
}
#include "winstorageaccess.moc"

View file

@ -1,70 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINSTORAGEACCESS_H
#define WINSTORAGEACCESS_H
#include <solid/ifaces/storageaccess.h>
#include "windevice.h"
#include "wininterface.h"
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinStorageAccess : public WinInterface, public virtual Solid::Ifaces::StorageAccess
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::StorageAccess)
public:
WinStorageAccess(WinDevice *device);
~WinStorageAccess();
virtual bool isAccessible() const;
virtual QString filePath() const;
virtual bool isIgnored() const;
virtual bool setup();
virtual bool teardown();
signals:
void accessibilityChanged(bool accessible, const QString &udi);
void setupDone(Solid::ErrorType error, QVariant resultData, const QString &udi);
void teardownDone(Solid::ErrorType error, QVariant resultData, const QString &udi);
void setupRequested(const QString &udi);
void teardownRequested(const QString &udi);
};
}
}
}
#endif // WINSTORAGEACCESS_H

View file

@ -1,114 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "winstoragedrive.h"
#include <windows.h>
#include <winioctl.h>
#if defined(__MINGW32__) && !defined(IOCTL_STORAGE_QUERY_PROPERTY)
#include <winioctl_backport.h>
#endif
using namespace Solid::Backends::Win;
WinStorageDrive::WinStorageDrive(WinDevice *device):
WinBlock(device)
{
updateCache();
}
WinStorageDrive::~WinStorageDrive()
{
}
Solid::StorageDrive::Bus WinStorageDrive::bus() const
{
return m_bus;
}
Solid::StorageDrive::DriveType WinStorageDrive::driveType() const
{
if(m_device->type() == Solid::DeviceInterface::OpticalDrive)
return Solid::StorageDrive::CdromDrive;
if(bus() == Solid::StorageDrive::Usb)
return Solid::StorageDrive::MemoryStick;
return Solid::StorageDrive::HardDisk;
}
bool WinStorageDrive::isRemovable() const
{
return m_isRemovable;
}
bool WinStorageDrive::isHotpluggable() const
{
return m_isHotplugges;
}
qulonglong WinStorageDrive::size() const
{
return m_size;
}
void WinStorageDrive::updateCache()
{
STORAGE_PROPERTY_QUERY storageProperty;
storageProperty.PropertyId = StorageAdapterProperty;
storageProperty.QueryType = PropertyStandardQuery;
QString dev;
if(m_device->type() == Solid::DeviceInterface::OpticalDrive)
{
dev = WinBlock::driveLetterFromUdi(m_device->udi());
}
else
{
dev = QLatin1String("PhysicalDrive") + QString::number(deviceMajor());
}
STORAGE_ADAPTER_DESCRIPTOR busInfo = WinDeviceManager::getDeviceInfo<STORAGE_ADAPTER_DESCRIPTOR>(dev,IOCTL_STORAGE_QUERY_PROPERTY,&storageProperty);
switch(busInfo.BusType)
{
case BusTypeUsb:
m_bus = Solid::StorageDrive::Usb;
break;
case BusType1394:
m_bus = Solid::StorageDrive::Ieee1394;
break;
case BusTypeScsi:
m_bus = Solid::StorageDrive::Scsi;
break;
case BusTypeAta:
default:
m_bus = Solid::StorageDrive::Ide;
}
DISK_GEOMETRY sizeInfo = WinDeviceManager::getDeviceInfo<DISK_GEOMETRY>(dev,IOCTL_DISK_GET_DRIVE_GEOMETRY);
m_size = sizeInfo.Cylinders.QuadPart * sizeInfo.TracksPerCylinder * sizeInfo.SectorsPerTrack * sizeInfo.BytesPerSector;
STORAGE_HOTPLUG_INFO plugInfo = WinDeviceManager::getDeviceInfo<STORAGE_HOTPLUG_INFO>(dev,IOCTL_STORAGE_GET_HOTPLUG_INFO);
m_isHotplugges = plugInfo.DeviceHotplug;
m_isRemovable = plugInfo.MediaRemovable;
}
#include "winstoragedrive.moc"

View file

@ -1,66 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINSTORAGEDRIVE_H
#define WINSTORAGEDRIVE_H
#include <solid/ifaces/storagedrive.h>
#include "windevice.h"
#include "winblock.h"
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinStorageDrive : public WinBlock , public virtual Solid::Ifaces::StorageDrive
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::StorageDrive)
public:
WinStorageDrive(WinDevice *device);
~WinStorageDrive();
virtual Solid::StorageDrive::Bus bus() const;
virtual Solid::StorageDrive::DriveType driveType() const;
virtual bool isRemovable() const;
virtual bool isHotpluggable() const;
virtual qulonglong size() const;
private:
void updateCache();
Solid::StorageDrive::Bus m_bus;
qulonglong m_size;
bool m_isHotplugges;
bool m_isRemovable;
};
}
}
}
#endif // WINSTORAGEDRIVE_H

View file

@ -1,108 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "winstoragevolume.h"
#include "windevicemanager.h"
#include <windows.h>
#include <iostream>
using namespace Solid::Backends::Win;
WinStorageVolume::WinStorageVolume(WinDevice *device)
: WinBlock(device),
m_size(0)
{
updateCache();
}
WinStorageVolume::~WinStorageVolume()
{
}
bool WinStorageVolume::isIgnored() const
{
return WinBlock::driveLetterFromUdi(m_device->udi()).isNull();
}
Solid::StorageVolume::UsageType WinStorageVolume::usage() const
{
return Solid::StorageVolume::FileSystem;//TODO:???
}
void WinStorageVolume::updateCache()
{
wchar_t label[MAX_PATH];
wchar_t fs[MAX_PATH];
DWORD serial;
DWORD flags;
//TODO:get correct name
wchar_t dLetter[MAX_PATH];
int dLetterSize = WinBlock::driveLetterFromUdi(m_device->udi()).toWCharArray(dLetter);
dLetter[dLetterSize] = (wchar_t)'\\';
dLetter[dLetterSize+1] = 0;
if(GetVolumeInformation(dLetter,label,MAX_PATH,&serial,NULL,&flags,fs,MAX_PATH))
{
m_label = QString::fromWCharArray(label);
m_fs = QString::fromWCharArray(fs);
m_uuid = QString::number(serial,16);
}
ULARGE_INTEGER size;
if(GetDiskFreeSpaceEx(dLetter,NULL,&size,NULL))
{
m_size = size.QuadPart;
}
}
QString WinStorageVolume::fsType() const
{
return m_fs;
}
QString WinStorageVolume::label() const
{
return m_label;
}
QString WinStorageVolume::uuid() const
{
return m_uuid;
}
qulonglong WinStorageVolume::size() const
{
return m_size;
}
QString WinStorageVolume::encryptedContainerUdi() const
{
return QString();
}
#include "winstoragevolume.moc"

View file

@ -1,68 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINSTORAGEVOLUME_H
#define WINSTORAGEVOLUME_H
#include <solid/ifaces/storagevolume.h>
#include "wininterface.h"
#include "winblock.h"
namespace Solid
{
namespace Backends
{
namespace Win
{
class WinStorageVolume : public WinBlock, public virtual Solid::Ifaces::StorageVolume
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::StorageVolume)
public:
WinStorageVolume(WinDevice *device);
~WinStorageVolume();
virtual bool isIgnored() const;
virtual Solid::StorageVolume::UsageType usage() const;
virtual QString fsType() const;
virtual QString label() const;
virtual QString uuid() const;
virtual qulonglong size() const;
virtual QString encryptedContainerUdi() const;
private:
QString m_fs;
QString m_label;
QString m_uuid;
qulonglong m_size;
void updateCache();
};
}
}
}
#endif // WINVOLUME_H

View file

@ -1,46 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmiacadapter.h"
using namespace Solid::Backends::Wmi;
AcAdapter::AcAdapter(WmiDevice *device)
: DeviceInterface(device)
{
// connect(device, SIGNAL(propertyChanged(QMap<QString,int>)),
// this, SLOT(slotPropertyChanged(QMap<QString,int>)));
}
AcAdapter::~AcAdapter()
{
}
bool AcAdapter::isPlugged() const
{
return m_device->property("BatteryStatus").toUInt() == 2;
}
void AcAdapter::slotPropertyChanged(const QMap<QString,int> &changes)
{
}
#include "backends/wmi/wmiacadapter.moc"

View file

@ -1,54 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_ACADAPTER_H
#define SOLID_BACKENDS_WMI_ACADAPTER_H
#include <solid/ifaces/acadapter.h>
#include "wmideviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class AcAdapter : public DeviceInterface, virtual public Solid::Ifaces::AcAdapter
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::AcAdapter)
public:
AcAdapter(WmiDevice *device);
virtual ~AcAdapter();
virtual bool isPlugged() const;
Q_SIGNALS:
void plugStateChanged(bool newState, const QString &udi);
private Q_SLOTS:
void slotPropertyChanged(const QMap<QString,int> &changes);
};
}
}
}
#endif // SOLID_BACKENDS_WMI_ACADAPTER_H

View file

@ -1,204 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmiaudiointerface.h"
#include "wmidevice.h"
using namespace Solid::Backends::Wmi;
AudioInterface::AudioInterface(WmiDevice *device)
: DeviceInterface(device),
m_soundcardType(Solid::AudioInterface::InternalSoundcard),
m_soundcardTypeValid(false)
{
}
AudioInterface::~AudioInterface()
{
}
Solid::AudioInterface::AudioDriver AudioInterface::driver() const
{
QString capacity = m_device->property("info.category").toString();
if (capacity == "alsa")
{
return Solid::AudioInterface::Alsa;
}
else if (capacity == "oss")
{
return Solid::AudioInterface::OpenSoundSystem;
}
else
{
return Solid::AudioInterface::UnknownAudioDriver;
}
}
QVariant AudioInterface::driverHandle() const
{
Solid::AudioInterface::AudioDriver d = driver();
if (d == Solid::AudioInterface::Alsa)
{
QVariant card_id = m_device->property("alsa.card");
QVariant dev_id = m_device->property("alsa.device");
QVariant subdev_id;
//TODO alsa.subdevice
return QList<QVariant>() << card_id << dev_id << subdev_id;
}
else if (d == Solid::AudioInterface::OpenSoundSystem)
{
return m_device->property("oss.device_file");
}
else
{
return QVariant();
}
}
QString AudioInterface::name() const
{
Solid::AudioInterface::AudioDriver d = driver();
if (d == Solid::AudioInterface::Alsa)
{
QVariant card_id = m_device->property("alsa.card_id");
if (card_id.isValid())
{
return card_id.toString().trimmed() + QLatin1String(" (") + m_device->property("alsa.device_id").toString().trimmed() + ')';
}
return m_device->property("alsa.device_id").toString();
}
else if (d == Solid::AudioInterface::OpenSoundSystem)
{
QVariant card_id = m_device->property("oss.card_id");
if (card_id.isValid())
{
return card_id.toString().trimmed() + QLatin1String(" (") + m_device->property("oss.device_id").toString().trimmed() + ')';
}
return m_device->property("oss.device_id").toString();
}
else
{
return QString();
}
}
Solid::AudioInterface::AudioInterfaceTypes AudioInterface::deviceType() const
{
Solid::AudioInterface::AudioDriver d = driver();
if (d == Solid::AudioInterface::Alsa)
{
QString type = m_device->property("alsa.type").toString();
if (type == "control")
{
return Solid::AudioInterface::AudioControl;
}
else if (type == "capture")
{
return Solid::AudioInterface::AudioInput;
}
else if (type == "playback")
{
return Solid::AudioInterface::AudioOutput;
}
else
{
return Solid::AudioInterface::UnknownAudioInterfaceType;
}
}
else if (d == Solid::AudioInterface::OpenSoundSystem)
{
QString type = m_device->property("oss.type").toString();
if (type == "mixer")
{
return Solid::AudioInterface::AudioControl;
}
else if (type == "pcm")
{
return Solid::AudioInterface::AudioInput|Solid::AudioInterface::AudioOutput;
}
else
{
return Solid::AudioInterface::UnknownAudioInterfaceType;
}
}
else
{
return Solid::AudioInterface::UnknownAudioInterfaceType;
}
}
Solid::AudioInterface::SoundcardType AudioInterface::soundcardType() const
{
if (m_soundcardTypeValid)
{
return m_soundcardType;
}
if (! m_device->parentUdi().isEmpty())
{
WmiDevice parentDevice(m_device->parentUdi());
QString productName = parentDevice.product();
QString deviceName = name();
if (productName.contains("headset", Qt::CaseInsensitive) ||
productName.contains("headphone", Qt::CaseInsensitive) ||
deviceName.contains("headset", Qt::CaseInsensitive) ||
deviceName.contains("headphone", Qt::CaseInsensitive))
{
m_soundcardType = Solid::AudioInterface::Headset;
}
else if (productName.contains("modem", Qt::CaseInsensitive) ||
deviceName.contains("modem", Qt::CaseInsensitive))
{
m_soundcardType = Solid::AudioInterface::Modem;
}
else
{
QString busName = parentDevice.property("info.subsystem").toString();
QString driverName = parentDevice.property("info.linux.driver").toString();
if (busName == "ieee1394")
{
m_soundcardType = Solid::AudioInterface::FirewireSoundcard;
}
else if (busName == "usb" || busName == "usb_device" || driverName.contains("usb", Qt::CaseInsensitive))
{
m_soundcardType = Solid::AudioInterface::UsbSoundcard;
}
else
{
m_soundcardType = Solid::AudioInterface::InternalSoundcard;
}
}
m_soundcardTypeValid = true;
}
return m_soundcardType;
}
#include "backends/wmi/wmiaudiointerface.moc"

View file

@ -1,59 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_WMIAUDIOINTERFACE_H
#define SOLID_BACKENDS_WMI_WMIAUDIOINTERFACE_H
#include <solid/ifaces/audiointerface.h>
#include "wmideviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class WmiDevice;
class AudioInterface : public DeviceInterface, virtual public Solid::Ifaces::AudioInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::AudioInterface)
public:
AudioInterface(WmiDevice *device);
virtual ~AudioInterface();
virtual Solid::AudioInterface::AudioDriver driver() const;
virtual QVariant driverHandle() const;
virtual QString name() const;
virtual Solid::AudioInterface::AudioInterfaceTypes deviceType() const;
virtual Solid::AudioInterface::SoundcardType soundcardType() const;
private:
mutable Solid::AudioInterface::SoundcardType m_soundcardType;
mutable bool m_soundcardTypeValid;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_WMIAUDIOINTERFACE_H

View file

@ -1,135 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmibattery.h"
using namespace Solid::Backends::Wmi;
Battery::Battery(WmiDevice *device)
: DeviceInterface(device)
{
// connect(device, SIGNAL(propertyChanged(QMap<QString,int>)),
// this, SLOT(slotPropertyChanged(QMap<QString,int>)));
}
Battery::~Battery()
{
}
bool Battery::isPlugged() const
{
return true;
}
Solid::Battery::BatteryType Battery::type() const
{
//as far as i know peripheral bateries are not listed
return Solid::Battery::PrimaryBattery;
}
int Battery::chargePercent() const
{
return m_device->property("EstimatedChargeRemaining").toInt();
}
bool Battery::isRechargeable() const
{
return true;
}
Solid::Battery::ChargeState Battery::chargeState() const
{
ushort status = m_device->property("BatteryStatus").toInt();
bool charging = status == 2 || status >= 6 && status <=8;//2 = The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging , but windows mostlikly wont tell anything else then 2 or 1
bool discharging = status == 1 || status >=3 && status <=5 || status == 11;
if (!charging && !discharging)
{
return Solid::Battery::NoCharge;
}
else if (charging)
{
return Solid::Battery::Charging;
}
else
{
return Solid::Battery::Discharging;
}
}
QString Battery::batteryTechnology() const
{
const ushort tech = m_device->property("Chemistry").toUInt();
switch (tech)
{
case 3:
return QObject::tr("Lead Acid", "battery technology");
case 4:
return QObject::tr("Nickel Cadmium", "battery technology");
case 5:
return QObject::tr("Nickel Metal Hydride", "battery technology");
case 6:
return QObject::tr("Lithium Ion", "battery technology");
case 8:
return QObject::tr("Lithium Polymer", "battery technology");
default:
return QObject::tr("Unknown", "battery technology");
}
}
bool Battery::isPowerSupply() const
{
return chargeState() == Solid::Battery::Charging;
}
int Battery::capacity() const
{
const unsigned int fullChargeCapacity = m_device->property("FullChargeCapacity").toUInt();
const unsigned int designCapacity = m_device->property("DesignCapacity").toUInt();
if ( designCapacity == 0 )
{
return 0;
}
return ( (int) (100.0 * fullChargeCapacity / designCapacity) );
}
void Battery::slotPropertyChanged(const QMap<QString,int> &changes)
{
// if (changes.contains("battery.charge_level.percentage"))
// {
// emit chargePercentChanged(chargePercent(), m_device->udi());
// }
// else if (changes.contains("battery.rechargeable.is_charging")
// || changes.contains("battery.rechargeable.is_discharging"))
// {
// emit chargeStateChanged(chargeState(), m_device->udi());
// }
// else if ( changes.contains( "battery.present" ) )
// {
// emit plugStateChanged(isPlugged(), m_device->udi());
// }
}
#include "backends/wmi/wmibattery.moc"

View file

@ -1,70 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_BATTERY_H
#define SOLID_BACKENDS_WMI_BATTERY_H
#include <solid/ifaces/battery.h>
#include "wmideviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class Battery : public DeviceInterface, virtual public Solid::Ifaces::Battery
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Battery)
public:
Battery(WmiDevice *device);
virtual ~Battery();
virtual bool isPlugged() const;
virtual Solid::Battery::BatteryType type() const;
virtual int chargePercent() const;
virtual bool isRechargeable() const;
virtual Solid::Battery::ChargeState chargeState() const;
QString batteryTechnology() const;
virtual bool isPowerSupply() const;
virtual int capacity() const;
Q_SIGNALS:
void chargePercentChanged(int value, const QString &udi);
void chargeStateChanged(int newState, const QString &udi);
void plugStateChanged(bool newState, const QString &udi);
void capacityChanged(int value, const QString &udi);
void powerSupplyStateChanged(bool newState, const QString &udi);
private Q_SLOTS:
void slotPropertyChanged(const QMap<QString,int> &changes);
};
}
}
}
#endif // SOLID_BACKENDS_WMI_BATTERY_H

View file

@ -1,65 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmiblock.h"
#include "wmidevice.h"
using namespace Solid::Backends::Wmi;
Block::Block(WmiDevice *device)
: DeviceInterface(device)
{
}
Block::~Block()
{
}
int Block::deviceMajor() const
{
return 0;
}
int Block::deviceMinor() const
{
return 0;
}
QString Block::device() const
{
QString drive;
switch(m_device->type()){
case Solid::DeviceInterface::StorageVolume:
{
drive = WmiDevice::win32LogicalDiskByDiskPartitionID(m_device->property("DeviceID").toString()).getProperty("DeviceID").toString();
}
break;
case Solid::DeviceInterface::OpticalDrive:
case Solid::DeviceInterface::OpticalDisc:
drive = m_device->property("Drive").toString();
break;
}
return drive;
}
#include "backends/wmi/wmiblock.moc"

View file

@ -1,50 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_BLOCK_H
#define SOLID_BACKENDS_WMI_BLOCK_H
#include <solid/ifaces/block.h>
#include "wmideviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class Block : public DeviceInterface, virtual public Solid::Ifaces::Block
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Block)
public:
Block(WmiDevice *device);
virtual ~Block();
virtual int deviceMajor() const;
virtual int deviceMinor() const;
virtual QString device() const;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_BLOCK_H

View file

@ -1,77 +0,0 @@
/*
Copyright 2006 Davide Bettio <davide.bettio@kdemail.net>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmibutton.h"
using namespace Solid::Backends::Wmi;
Button::Button(WmiDevice *device)
: DeviceInterface(device)
{
connect(device, SIGNAL(conditionRaised(QString,QString)),
this, SLOT(slotConditionRaised(QString,QString)));
}
Button::~Button()
{
}
Solid::Button::ButtonType Button::type() const
{
QString buttontype = m_device->property("button.type").toString();
if (buttontype=="lid")
{
return Solid::Button::LidButton;
}
else if (buttontype=="power")
{
return Solid::Button::PowerButton;
}
else if (buttontype=="sleep")
{
return Solid::Button::SleepButton;
}
else
{
return Solid::Button::UnknownButtonType;
}
}
bool Button::hasState() const
{
return m_device->property("button.has_state").toBool();
}
bool Button::stateValue() const
{
return m_device->property("button.state.value").toBool();
}
void Button::slotConditionRaised(const QString &name, const QString &/*reason */)
{
if (name == "ButtonPressed")
{
emit pressed(type(), m_device->udi());
}
}
#include "backends/wmi/wmibutton.moc"

View file

@ -1,58 +0,0 @@
/*
Copyright 2006 Davide Bettio <davide.bettio@kdemail.net>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_BUTTON_H
#define SOLID_BACKENDS_WMI_BUTTON_H
#include <solid/ifaces/button.h>
#include "wmideviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class WmiDevice;
class Button : public DeviceInterface, virtual public Solid::Ifaces::Button
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Button)
public:
Button(WmiDevice *device);
virtual ~Button();
virtual Solid::Button::ButtonType type() const;
virtual bool hasState() const;
virtual bool stateValue() const;
Q_SIGNALS:
void pressed(Solid::Button::ButtonType type, const QString &udi);
private Q_SLOTS:
void slotConditionRaised(const QString &condition, const QString &reason);
};
}
}
}
#endif // SOLID_BACKENDS_WMI_BUTTON_H

View file

@ -1,74 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmicamera.h"
using namespace Solid::Backends::Wmi;
Camera::Camera(WmiDevice *device)
: DeviceInterface(device)
{
}
Camera::~Camera()
{
}
QStringList Camera::supportedProtocols() const
{
QStringList protocols;
QString method = m_device->property("camera.access_method").toString();
protocols << method;
return protocols;
}
QStringList Camera::supportedDrivers(QString /*protocol*/) const
{
QStringList res;
if (m_device->property("camera.libgphoto2.support").toBool()) {
res << "gphoto";
}
return res;
}
QVariant Solid::Backends::Wmi::Camera::driverHandle(const QString &driver) const
{
if (driver=="gphoto"
&& m_device->property("info.subsystem").toString()=="usb") {
QVariantList list;
list << "usb"
<< m_device->property("usb.vendor_id")
<< m_device->property("usb.product_id");
return list;
}
return QVariant();
}
#include "backends/wmi/wmicamera.moc"

View file

@ -1,50 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_CAMERA_H
#define SOLID_BACKENDS_WMI_CAMERA_H
#include <solid/ifaces/camera.h>
#include "wmideviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class Camera : public DeviceInterface, virtual public Solid::Ifaces::Camera
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Camera)
public:
Camera(WmiDevice *device);
virtual ~Camera();
virtual QStringList supportedProtocols() const;
virtual QStringList supportedDrivers(QString protocol = QString()) const;
virtual QVariant driverHandle(const QString &driver) const;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_CAMERA_H

View file

@ -1,157 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmicdrom.h"
#include <QtCore/QStringList>
using namespace Solid::Backends::Wmi;
Cdrom::Cdrom(WmiDevice *device)
: Storage(device), m_ejectInProgress(false)
{
connect(device, SIGNAL(conditionRaised(QString,QString)),
this, SLOT(slotCondition(QString,QString)));
}
Cdrom::~Cdrom()
{
}
Solid::OpticalDrive::MediumTypes Cdrom::supportedMedia() const
{
Solid::OpticalDrive::MediumTypes supported;
QString type = m_device->property("MediaType").toString();
if (type == "CdRomOnly" || type == "CD-ROM")
{
supported |= Solid::OpticalDrive::Cdr;
}
else if (type == "CdRomWrite")
{
supported |= Solid::OpticalDrive::Cdr|Solid::OpticalDrive::Cdrw;
}
else if (type == "DVDRomOnly")
{
supported |= Solid::OpticalDrive::Dvd;
}
else if (type == "DVDRomWrite" || type == "DVD Writer")
{
supported |= Solid::OpticalDrive::Dvd|Solid::OpticalDrive::Dvdr|Solid::OpticalDrive::Dvdrw;
}
return supported;
}
int Cdrom::readSpeed() const
{
return m_device->property("TransferRate").toInt();
}
int Cdrom::writeSpeed() const
{
return m_device->property("TransferRate").toInt();
}
QList<int> Cdrom::writeSpeeds() const
{
QList<int> speeds;
return speeds;
}
void Cdrom::slotCondition(const QString &name, const QString &/*reason */)
{
if (name == "EjectPressed")
{
emit ejectPressed(m_device->udi());
}
}
bool Cdrom::eject()
{
if (m_ejectInProgress) {
return false;
}
m_ejectInProgress = true;
return callWmiDriveEject();
}
bool Cdrom::callWmiDriveEject()
{
// QString udi = m_device->udi();
// QString interface = "org.freedesktop.Wmi.Device.Storage";
// HACK: Eject doesn't work on cdrom drives when there's a mounted disc,
// let's try to workaround this by calling a child volume...
// if (m_device->property("storage.removable.media_available").toBool()) {
// QDBusInterface manager("org.freedesktop.Wmi",
// "/org/freedesktop/Wmi/Manager",
// "org.freedesktop.Wmi.Manager",
// QDBusConnection::systemBus());
// QDBusReply<QStringList> reply = manager.call("FindDeviceStringMatch", "info.parent", udi);
// if (reply.isValid())
// {
// QStringList udis = reply;
// if (!udis.isEmpty()) {
// udi = udis[0];
// interface = "org.freedesktop.Wmi.Device.Volume";
// }
// }
// }
// QDBusConnection c = QDBusConnection::systemBus();
// QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.Wmi", udi,
// interface, "Eject");
// msg << QStringList();
// return c.callWithCallback(msg, this,
// SLOT(slotDBusReply(QDBusMessage)),
// SLOT(slotDBusError(QDBusError)));
return false;
}
void Solid::Backends::Wmi::Cdrom::slotProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
Q_UNUSED(exitStatus);
if (m_ejectInProgress) {
m_ejectInProgress = false;
if (exitCode==0) {
emit ejectDone(Solid::NoError, QVariant(), m_device->udi());
} else {
emit ejectDone(Solid::UnauthorizedOperation,
m_process->readAllStandardError(),
m_device->udi());
}
}
delete m_process;
}
#include "backends/wmi/wmicdrom.moc"

View file

@ -1,69 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_CDROM_H
#define SOLID_BACKENDS_WMI_CDROM_H
#include <solid/ifaces/opticaldrive.h>
#include "wmistorage.h"
#include <QtCore/QProcess>
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class Cdrom : public Storage, virtual public Solid::Ifaces::OpticalDrive
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::OpticalDrive)
public:
Cdrom(WmiDevice *device);
virtual ~Cdrom();
virtual Solid::OpticalDrive::MediumTypes supportedMedia() const;
virtual int readSpeed() const;
virtual int writeSpeed() const;
virtual QList<int> writeSpeeds() const;
virtual bool eject();
Q_SIGNALS:
void ejectPressed(const QString &udi);
void ejectDone(Solid::ErrorType error, QVariant errorData, const QString &udi);
private Q_SLOTS:
void slotCondition(const QString &name, const QString &reason);
void slotProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
private:
bool callWmiDriveEject();
bool m_ejectInProgress;
QProcess *m_process;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_CDROM_H

View file

@ -1,701 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2005-2007 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmidevice.h"
#include <solid/genericinterface.h>
#include "wmiquery.h"
#include "wmimanager.h"
#include "wmideviceinterface.h"
#include "wmigenericinterface.h"
#include "wmiprocessor.h"
#include "wmiblock.h"
#include "wmistorageaccess.h"
#include "wmistorage.h"
#include "wmicdrom.h"
#include "wmivolume.h"
#include "wmiopticaldisc.h"
#include "wmicamera.h"
#include "wmiportablemediaplayer.h"
#include "wminetworkinterface.h"
#include "wmiacadapter.h"
#include "wmibattery.h"
#include "wmibutton.h"
#include "wmiaudiointerface.h"
#include "wmidvbinterface.h"
#include "wmivideo.h"
#include <QtCore/QDebug>
using namespace Solid::Backends::Wmi;
class Solid::Backends::Wmi::WmiDevicePrivate
{
public:
WmiDevicePrivate(const QString &_udi)
: parent(0)
, m_udi(_udi)
, m_wmiTable()
, m_wmiProperty()
, m_wmiValue()
{
}
~WmiDevicePrivate()
{
}
void discoverType()
{
if (!convertUDItoWMI(m_udi,m_wmiTable,m_wmiProperty,m_wmiValue,m_type))
return;
interfaceList<<getInterfaces(m_type);
}
const QString udi() const { return m_udi; }
WmiQuery::Item sendQuery()
{
if(m_item.isNull()){
QString query("SELECT * FROM " + m_wmiTable + " WHERE " + m_wmiProperty + "='" + m_wmiValue + "'");
WmiQuery::ItemList items = WmiQuery::instance().sendQuery(query);
Q_ASSERT(items.length() == 1);
if(items.length() != 1)
qDebug()<<"WmiDevicePrivate::sendQuery() failed";
m_item = items[0];
}
return m_item;
}
static bool convertUDItoWMI(const QString &udi, QString &wmiTable, QString &wmiProperty, QString &wmiValue,Solid::DeviceInterface::Type &type)
{
QString _udi = udi;
QStringList x = _udi.remove("/org/kde/solid/wmi/").split('/');
if (x.size() != 2 || x[1].isEmpty()) {
qDebug() << "invalid udi detected" << udi;
return false;
}
type = DeviceInterface::fromString(x[0]);
wmiProperty = getPropertyNameForUDI(type);
wmiValue = x[1];
wmiTable = getWMITable(type);
// qDebug()<<"wmi"<< type <<wmiTable <<wmiProperty <<wmiValue;
return true;
}
static bool exists(const QString &udi)
{
QString wmiTable;
QString wmiProperty;
QString wmiValue;
Solid::DeviceInterface::Type solidDevice;
if (!convertUDItoWMI(udi, wmiTable, wmiProperty, wmiValue,solidDevice))
return false;
QString query("SELECT * FROM " + wmiTable + " WHERE " + wmiProperty + "='" + wmiValue + "'");
WmiQuery::ItemList list = WmiQuery::instance().sendQuery(query);
if(list.size() > 0)
return true;
qWarning()<<"Device UDI:"<<udi<<"doesnt exist";
// qDebug()<<query;
return false;
}
static QString generateUDI(const QString &key, const QString &property)
{
return QString("/org/kde/solid/wmi/%1/%2").arg(key).arg(property);
}
static QList<Solid::DeviceInterface::Type> getInterfaces(const Solid::DeviceInterface::Type &type)
{
QList<Solid::DeviceInterface::Type> interfaceList;
interfaceList<<type;
switch (type)
{
case Solid::DeviceInterface::GenericInterface:
break;
case Solid::DeviceInterface::Processor:
break;
case Solid::DeviceInterface::Block:
break;
case Solid::DeviceInterface::StorageAccess:
break;
case Solid::DeviceInterface::StorageDrive:
break;
case Solid::DeviceInterface::OpticalDrive:
interfaceList <<Solid::DeviceInterface::Block<<Solid::DeviceInterface::StorageDrive;
break;
case Solid::DeviceInterface::StorageVolume:
interfaceList <<Solid::DeviceInterface::Block<<Solid::DeviceInterface::StorageAccess;
break;
case Solid::DeviceInterface::OpticalDisc:
interfaceList <<Solid::DeviceInterface::Block<<Solid::DeviceInterface::StorageVolume;
break;
case Solid::DeviceInterface::Camera:
break;
case Solid::DeviceInterface::PortableMediaPlayer:
break;
case Solid::DeviceInterface::NetworkInterface:
break;
case Solid::DeviceInterface::AcAdapter:
break;
case Solid::DeviceInterface::Battery:
break;
case Solid::DeviceInterface::Button:
break;
case Solid::DeviceInterface::AudioInterface:
break;
case Solid::DeviceInterface::DvbInterface:
break;
case Solid::DeviceInterface::Video:
break;
case Solid::DeviceInterface::Unknown:
case Solid::DeviceInterface::Last:
default:
break;
}
if (interfaceList.size() == 0)
qWarning() << "no interface found for type" << type;
return interfaceList;
}
static QString getUDIKey(const Solid::DeviceInterface::Type &type)
{
QStringList list = DeviceInterface::toStringList(type);
QString value = list.size() > 0 ? list[0] : QString();
return value;
}
static QString getWMITable(const Solid::DeviceInterface::Type &type)
{
QString wmiTable;
switch (type)
{
case Solid::DeviceInterface::GenericInterface:
break;
case Solid::DeviceInterface::Processor:
wmiTable = "Win32_Processor";
break;
case Solid::DeviceInterface::Block:
break;
case Solid::DeviceInterface::StorageAccess:
wmiTable = "Win32_DiskPartition";
break;
case Solid::DeviceInterface::StorageDrive:
wmiTable = "Win32_DiskDrive";
break;
case Solid::DeviceInterface::OpticalDrive:
wmiTable = "Win32_CDROMDrive";
break;
case Solid::DeviceInterface::StorageVolume:
wmiTable = "Win32_DiskPartition";
break;
case Solid::DeviceInterface::OpticalDisc:
wmiTable = "Win32_CDROMDrive";
break;
case Solid::DeviceInterface::Camera:
break;
case Solid::DeviceInterface::PortableMediaPlayer:
break;
case Solid::DeviceInterface::NetworkInterface:
break;
case Solid::DeviceInterface::AcAdapter:
case Solid::DeviceInterface::Battery:
wmiTable = "Win32_Battery";
break;
case Solid::DeviceInterface::Button:
break;
case Solid::DeviceInterface::AudioInterface:
break;
case Solid::DeviceInterface::DvbInterface:
break;
case Solid::DeviceInterface::Video:
break;
case Solid::DeviceInterface::Unknown:
case Solid::DeviceInterface::Last:
default:
wmiTable = "unknown";
break;
}
return wmiTable;
}
static QString getIgnorePattern(const Solid::DeviceInterface::Type &type)
{
QString propertyName;
switch(type){
case Solid::DeviceInterface::OpticalDisc:
propertyName = " WHERE MediaLoaded=TRUE";
break;
}
return propertyName;
}
static QString getPropertyNameForUDI(const Solid::DeviceInterface::Type &type)
{
QString propertyName;
switch(type){
case Solid::DeviceInterface::OpticalDrive:
case Solid::DeviceInterface::OpticalDisc:
propertyName = "Drive";
break;
case Solid::DeviceInterface::StorageDrive:
propertyName = "Index";
break;
default:
propertyName = "DeviceID";
}
return propertyName;
}
static QStringList generateUDIList(const Solid::DeviceInterface::Type &type)
{
QStringList result;
WmiQuery::ItemList list = WmiQuery::instance().sendQuery( "SELECT * FROM " + getWMITable(type) + getIgnorePattern(type));
foreach(const WmiQuery::Item& item, list) {
QString propertyName = getPropertyNameForUDI(type);
QString property = item.getProperty(propertyName).toString();
result << generateUDI(getUDIKey(type),property.toLower());
}
return result;
}
WmiDevice *parent;
static int m_instanceCount;
QString m_parent_uid;
QString m_udi;
QString m_wmiTable;
QString m_wmiProperty;
QString m_wmiValue;
Solid::DeviceInterface::Type m_type;
WmiQuery::Item m_item;
QList<Solid::DeviceInterface::Type> interfaceList;
};
Q_DECLARE_METATYPE(ChangeDescription)
Q_DECLARE_METATYPE(QList<ChangeDescription>)
WmiDevice::WmiDevice(const QString &udi)
: Device(), d(new WmiDevicePrivate(udi))
{
d->discoverType();
foreach (Solid::DeviceInterface::Type type, d->interfaceList)
{
createDeviceInterface(type);
}
}
WmiDevice::~WmiDevice()
{
//delete d->parent;
delete d;
}
QStringList WmiDevice::generateUDIList(const Solid::DeviceInterface::Type &type)
{
return WmiDevicePrivate::generateUDIList(type);
}
bool WmiDevice::exists(const QString &udi)
{
return WmiDevicePrivate::exists(udi);
}
bool WmiDevice::isValid() const
{
// does not work
//return sendQuery( "SELECT * FROM Win32_SystemDevices WHERE PartComponent='\\\\\\\\BEAST\root\cimv2:Win32_Processor.DeviceID=\"CPU0\"'" ).count() == 1;
return true;
}
QString WmiDevice::udi() const
{
return d->udi();
}
QString WmiDevice::parentUdi() const
{
if(!d->m_parent_uid.isEmpty())
return d->m_parent_uid;
QString result;
const QString value = udi().split("/").last();
switch(d->m_type){
case Solid::DeviceInterface::StorageVolume:
case Solid::DeviceInterface::StorageAccess:
result = "/org/kde/solid/wmi/storage/"+property("DiskIndex").toString();
break;
case Solid::DeviceInterface::OpticalDisc:
result = "/org/kde/solid/wmi/storage.cdrom/"+property("Drive").toString().toLower();
break;
}
if(result.isEmpty() && !value.isEmpty()){
result = udi();
result = result.remove("/"+value);
}
d->m_parent_uid = result;
return d->m_parent_uid;
}
QString WmiDevice::vendor() const
{
QString propertyName;
switch(type()){
case Solid::DeviceInterface::Processor:
propertyName = "Manufacturer";
break;
case Solid::DeviceInterface::OpticalDrive:
case Solid::DeviceInterface::OpticalDisc:
propertyName = "Caption";
break;
case Solid::DeviceInterface::Battery:
propertyName = "DeviceID";
break;
case Solid::DeviceInterface::StorageAccess:
case Solid::DeviceInterface::StorageVolume:
{
WmiDevice parent(parentUdi());
return parent.vendor();
}
break;
case Solid::DeviceInterface::StorageDrive:
propertyName = "Model";
break;
default:
propertyName = "DeviceID";//TODO:
}
return property(propertyName).toString();
}
QString WmiDevice::product() const
{
QString propertyName;
switch(type()){
case Solid::DeviceInterface::Processor:
propertyName = "Name";
break;
case Solid::DeviceInterface::StorageAccess:
case Solid::DeviceInterface::StorageVolume:
{
WmiQuery::Item item = win32LogicalDiskByDiskPartitionID(property("DeviceID").toString());
return item.getProperty("VolumeName").toString();
}
break;
case Solid::DeviceInterface::AcAdapter:
return description();
default:
propertyName = "Caption";
}
return property(propertyName).toString();
}
QString WmiDevice::icon() const
{
QString propertyName;
switch(type()){
case Solid::DeviceInterface::Processor:
propertyName = "cpu";
break;
case Solid::DeviceInterface::OpticalDisc:
{
WmiDevice dev(udi());
OpticalDisc disk(&dev);
if(disk.availableContent() | Solid::OpticalDisc::Audio)//no other are recognized yet
propertyName = "media-optical-audio";
else
propertyName = "drive-optical";
break;
}
case Solid::DeviceInterface::Battery:
propertyName = "battery";
break;
case Solid::DeviceInterface::StorageAccess:
case Solid::DeviceInterface::StorageVolume:
{
WmiDevice parent(parentUdi());
Storage storage(&parent);
if(storage.bus() == Solid::StorageDrive::Usb)
propertyName = "drive-removable-media-usb-pendrive";
else
propertyName = "drive-harddisk";
}
break;
}
return propertyName;
}
QStringList WmiDevice::emblems() const
{
return QStringList(); // TODO
}
QString WmiDevice::description() const
{
switch(type()){
case Solid::DeviceInterface::OpticalDisc:
return property("VolumeName").toString();
case Solid::DeviceInterface::AcAdapter:
return QObject::tr("A/C Adapter");
case Solid::DeviceInterface::Battery:
{
WmiDevice dev(udi());
Battery bat(&dev);
return QObject::tr("%1 Battery", "%1 is battery technology").arg(bat.batteryTechnology());
}
default:
return product();
}
}
QVariant WmiDevice::property(const QString &key) const
{
WmiQuery::Item item = d->sendQuery();
QVariant result = item.getProperty(key);
// qDebug()<<"property"<<key<<result;
return result;
}
const Solid::DeviceInterface::Type WmiDevice::type() const{
return d->m_type;
}
/**
* @brief WmiDevice::win32DiskPartitionByDeviceIndex
* @param deviceID something like "\\.\PHYSICALDRIVE0"
* @return
*/
WmiQuery::Item WmiDevice::win32DiskPartitionByDeviceIndex(const QString &deviceID){
WmiQuery::Item result;
QString id = deviceID;
QString query("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='"+ id +"'} WHERE AssocClass = Win32_DiskDriveToDiskPartition");
WmiQuery::ItemList items = WmiQuery::instance().sendQuery(query);
if(items.length()>0){
result = items[0];
}
return result;
}
/**
* @brief WmiDevice::win32DiskDriveByDiskPartitionID
* @param deviceID something like "disk #1, partition #0"
* @return
*/
WmiQuery::Item WmiDevice::win32DiskDriveByDiskPartitionID(const QString &deviceID){
WmiQuery::Item result;
QString id = deviceID;
QString query("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='"+ id +"'} WHERE AssocClass = Win32_DiskDriveToDiskPartition");
WmiQuery::ItemList items = WmiQuery::instance().sendQuery(query);
if(items.length()>0){
result = items[0];
}
return result;
}
/**
* @brief WmiDevice::win32LogicalDiskByDiskPartitionID
* @param deviceID something like "disk #1, partition #0"
* @return
*/
WmiQuery::Item WmiDevice::win32LogicalDiskByDiskPartitionID(const QString &deviceID){
WmiQuery::Item result;
QString id = deviceID;
QString query("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" + id + "'} WHERE AssocClass = Win32_LogicalDiskToPartition");
WmiQuery::ItemList items = WmiQuery::instance().sendQuery(query);
if(items.length()>0){
result = items[0];
}
return result;
}
/**
* @brief WmiDevice::win32DiskPartitionByDriveLetter
* @param driveLetter something lik "D:"
* @return
*/
WmiQuery::Item WmiDevice::win32DiskPartitionByDriveLetter(const QString &driveLetter){
WmiQuery::Item result;
QString id = driveLetter;
QString query("ASSOCIATORS OF {Win32_LogicalDisk.DeviceID='" + id + "'} WHERE AssocClass = Win32_LogicalDiskToPartition");
WmiQuery::ItemList items = WmiQuery::instance().sendQuery(query);
if(items.length()>0){
result = items[0];
}
return result;
}
/**
* @brief WmiDevice::win32LogicalDiskByDriveLetter
* @param driveLetter something lik "D:"
* @return
*/
WmiQuery::Item WmiDevice::win32LogicalDiskByDriveLetter(const QString &driveLetter){
WmiQuery::Item result;
QString id = driveLetter;
QString query("SELECT * FROM Win32_LogicalDisk WHERE DeviceID='"+id+"'");
WmiQuery::ItemList items = WmiQuery::instance().sendQuery(query);
if(items.length()>0){
result = items[0];
}
return result;
}
QMap<QString, QVariant> WmiDevice::allProperties() const
{
WmiQuery::Item item = d->sendQuery();
return item.getAllProperties();
}
bool WmiDevice::propertyExists(const QString &key) const
{
WmiQuery::Item item = d->sendQuery();
const bool isEmpty = item.getProperty( key ).isValid();
return isEmpty;
}
bool WmiDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &type) const
{
// Special cases not matching with WMI capabilities
if (type==Solid::DeviceInterface::GenericInterface) {
return true;
}
return d->interfaceList.contains(type);
}
QObject *WmiDevice::createDeviceInterface(const Solid::DeviceInterface::Type &type)
{
if (!queryDeviceInterface(type)) {
return 0;
}
DeviceInterface *iface = 0;
switch (type)
{
case Solid::DeviceInterface::GenericInterface:
iface = new GenericInterface(this);
break;
case Solid::DeviceInterface::Processor:
iface = new Processor(this);
break;
case Solid::DeviceInterface::Block:
iface = new Block(this);
break;
case Solid::DeviceInterface::StorageAccess:
iface = new StorageAccess(this);
break;
case Solid::DeviceInterface::StorageDrive:
iface = new Storage(this);
break;
case Solid::DeviceInterface::OpticalDrive:
iface = new Cdrom(this);
break;
case Solid::DeviceInterface::StorageVolume:
iface = new Volume(this);
break;
case Solid::DeviceInterface::OpticalDisc:
iface = new OpticalDisc(this);
break;
case Solid::DeviceInterface::Camera:
iface = new Camera(this);
break;
case Solid::DeviceInterface::PortableMediaPlayer:
iface = new PortableMediaPlayer(this);
break;
case Solid::DeviceInterface::NetworkInterface:
iface = new NetworkInterface(this);
break;
case Solid::DeviceInterface::AcAdapter:
iface = new AcAdapter(this);
break;
case Solid::DeviceInterface::Battery:
iface = new Battery(this);
break;
case Solid::DeviceInterface::Button:
iface = new Button(this);
break;
case Solid::DeviceInterface::AudioInterface:
iface = new AudioInterface(this);
break;
case Solid::DeviceInterface::DvbInterface:
iface = new DvbInterface(this);
break;
case Solid::DeviceInterface::Video:
iface = new Video(this);
break;
case Solid::DeviceInterface::Unknown:
case Solid::DeviceInterface::Last:
break;
}
return iface;
}
void WmiDevice::slotPropertyModified(int /*count */, const QList<ChangeDescription> &changes)
{
QMap<QString,int> result;
foreach (const ChangeDescription &change, changes)
{
QString key = change.key;
bool added = change.added;
bool removed = change.removed;
Solid::GenericInterface::PropertyChange type = Solid::GenericInterface::PropertyModified;
if (added)
{
type = Solid::GenericInterface::PropertyAdded;
}
else if (removed)
{
type = Solid::GenericInterface::PropertyRemoved;
}
result[key] = type;
}
emit propertyChanged(result);
}
void WmiDevice::slotCondition(const QString &condition, const QString &reason)
{
emit conditionRaised(condition, reason);
}
#include "backends/wmi/wmidevice.moc"

View file

@ -1,101 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2005,2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_WMIDEVICE_H
#define SOLID_BACKENDS_WMI_WMIDEVICE_H
#include <solid/ifaces/device.h>
#include "wmiquery.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class WmiManager;
class WmiDevicePrivate;
struct ChangeDescription
{
QString key;
bool added;
bool removed;
};
class WmiDevice : public Solid::Ifaces::Device
{
Q_OBJECT
public:
WmiDevice(const QString &udi);
virtual ~WmiDevice();
virtual QString udi() const;
virtual QString parentUdi() const;
virtual QString vendor() const;
virtual QString product() const;
virtual QString icon() const;
virtual QStringList emblems() const;
virtual QString description() const;
virtual bool isValid() const;
virtual QVariant property(const QString &key) const;
virtual QMap<QString, QVariant> allProperties() const;
virtual bool propertyExists(const QString &key) const;
virtual bool queryDeviceInterface(const Solid::DeviceInterface::Type &type) const;
virtual QObject *createDeviceInterface(const Solid::DeviceInterface::Type &type);
static QStringList generateUDIList(const Solid::DeviceInterface::Type &type);
static bool exists(const QString &udi);
const Solid::DeviceInterface::Type type() const;
//TODO:rename the folowing methodes...
static WmiQuery::Item win32LogicalDiskByDiskPartitionID(const QString &deviceID);
static WmiQuery::Item win32DiskDriveByDiskPartitionID(const QString &deviceID);
static WmiQuery::Item win32DiskPartitionByDeviceIndex(const QString &deviceID);
static WmiQuery::Item win32DiskPartitionByDriveLetter(const QString &driveLetter);
static WmiQuery::Item win32LogicalDiskByDriveLetter(const QString &driveLetter);
Q_SIGNALS:
void propertyChanged(const QMap<QString,int> &changes);
void conditionRaised(const QString &condition, const QString &reason);
private Q_SLOTS:
void slotPropertyModified(int count, const QList<ChangeDescription> &changes);
void slotCondition(const QString &condition, const QString &reason);
private:
WmiDevicePrivate *d;
friend class WmiDevicePrivate;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_WMIDEVICE_H

View file

@ -1,34 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmideviceinterface.h"
using namespace Solid::Backends::Wmi;
DeviceInterface::DeviceInterface(WmiDevice *device)
: QObject(device), m_device(device)
{
}
DeviceInterface::~DeviceInterface()
{
}
#include "backends/wmi/wmideviceinterface.moc"

View file

@ -1,163 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_DEVICEINTERFACE_H
#define SOLID_BACKENDS_WMI_DEVICEINTERFACE_H
#include <solid/ifaces/deviceinterface.h>
#include "wmidevice.h"
#include <QtCore/QObject>
#include <QtCore/QStringList>
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class DeviceInterface : public QObject, virtual public Solid::Ifaces::DeviceInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::DeviceInterface)
public:
DeviceInterface(WmiDevice *device);
virtual ~DeviceInterface();
protected:
WmiDevice *m_device;
public:
inline static QStringList toStringList(Solid::DeviceInterface::Type type)
{
QStringList list;
switch(type)
{
case Solid::DeviceInterface::GenericInterface:
// Doesn't exist with WMI
break;
case Solid::DeviceInterface::Processor:
list << "processor";
break;
case Solid::DeviceInterface::Block:
list << "block";
break;
case Solid::DeviceInterface::StorageAccess:
// Doesn't exist with WMI, but let's assume volume always cover this type
list << "volume";
break;
case Solid::DeviceInterface::StorageDrive:
list << "storage";
break;
case Solid::DeviceInterface::OpticalDrive:
list << "storage.cdrom";
break;
case Solid::DeviceInterface::StorageVolume:
list << "volume";
break;
case Solid::DeviceInterface::OpticalDisc:
list << "volume.disc";
break;
case Solid::DeviceInterface::Camera:
list << "camera";
break;
case Solid::DeviceInterface::PortableMediaPlayer:
list << "portable_audio_player";
break;
case Solid::DeviceInterface::NetworkInterface:
list << "net";
break;
case Solid::DeviceInterface::AcAdapter:
list << "ac_adapter";
break;
case Solid::DeviceInterface::Battery:
list << "battery";
break;
case Solid::DeviceInterface::Button:
list << "button";
break;
case Solid::DeviceInterface::AudioInterface:
list << "alsa" << "oss";
break;
case Solid::DeviceInterface::DvbInterface:
list << "dvb";
break;
case Solid::DeviceInterface::Video:
list << "video4linux";
break;
case Solid::DeviceInterface::InternetGateway:
list << "internet_gateway";
break;
case Solid::DeviceInterface::NetworkShare:
list << "networkshare";
break;
case Solid::DeviceInterface::Unknown:
break;
case Solid::DeviceInterface::Last:
break;
}
return list;
}
inline static Solid::DeviceInterface::Type fromString(const QString &capability)
{
if (capability == "processor")
return Solid::DeviceInterface::Processor;
else if (capability == "block")
return Solid::DeviceInterface::Block;
else if (capability == "storage")
return Solid::DeviceInterface::StorageDrive;
else if (capability == "storage.cdrom")
return Solid::DeviceInterface::OpticalDrive;
else if (capability == "volume")
return Solid::DeviceInterface::StorageVolume;
else if (capability == "volume.disc")
return Solid::DeviceInterface::OpticalDisc;
else if (capability == "camera")
return Solid::DeviceInterface::Camera;
else if (capability == "portable_audio_player")
return Solid::DeviceInterface::PortableMediaPlayer;
else if (capability == "net")
return Solid::DeviceInterface::NetworkInterface;
else if (capability == "ac_adapter")
return Solid::DeviceInterface::AcAdapter;
else if (capability == "battery")
return Solid::DeviceInterface::Battery;
else if (capability == "button")
return Solid::DeviceInterface::Button;
else if (capability == "alsa" || capability == "oss")
return Solid::DeviceInterface::AudioInterface;
else if (capability == "dvb")
return Solid::DeviceInterface::DvbInterface;
else if (capability == "video4linux")
return Solid::DeviceInterface::Video;
else if (capability == "networkshare")
return Solid::DeviceInterface::NetworkShare;
else
return Solid::DeviceInterface::Unknown;
}
};
}
}
}
#endif // SOLID_BACKENDS_WMI_DEVICEINTERFACE_H

View file

@ -1,134 +0,0 @@
/*
Copyright 2007 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmidvbinterface.h"
#include "wmidevice.h"
using namespace Solid::Backends::Wmi;
DvbInterface::DvbInterface(WmiDevice *device)
: DeviceInterface(device)
{
}
DvbInterface::~DvbInterface()
{
}
QString DvbInterface::device() const
{
return m_device->property("dvb.device").toString();
}
int DvbInterface::deviceAdapter() const
{
QString string = device();
int pos = string.lastIndexOf('/');
if (pos < 0)
return -1;
string = string.left(pos);
pos = string.lastIndexOf('/');
if (pos < 0)
return -1;
string = string.mid(pos + 1);
if (!string.startsWith(QLatin1String("adapter")))
return -1;
string = string.mid(7);
bool ok;
int adapter = string.toInt(&ok, 10);
if (ok)
return adapter;
else
return -1;
}
Solid::DvbInterface::DeviceType DvbInterface::deviceType() const
{
Solid::DvbInterface::DeviceType type;
int index;
if (parseTypeIndex(&type, &index))
return type;
else
return Solid::DvbInterface::DvbUnknown;
}
int DvbInterface::deviceIndex() const
{
Solid::DvbInterface::DeviceType type;
int index;
if (parseTypeIndex(&type, &index))
return index;
else
return -1;
}
bool DvbInterface::parseTypeIndex(Solid::DvbInterface::DeviceType *type, int *index) const
{
QString string = device();
int pos = string.lastIndexOf('/');
if (pos < 0)
return false;
string = string.mid(pos + 1);
if (string.startsWith(QLatin1String("audio"))) {
*type = Solid::DvbInterface::DvbAudio;
string = string.mid(5);
} else if (string.startsWith(QLatin1String("ca"))) {
*type = Solid::DvbInterface::DvbCa;
string = string.mid(2);
} else if (string.startsWith(QLatin1String("demux"))) {
*type = Solid::DvbInterface::DvbDemux;
string = string.mid(5);
} else if (string.startsWith(QLatin1String("dvr"))) {
*type = Solid::DvbInterface::DvbDvr;
string = string.mid(3);
} else if (string.startsWith(QLatin1String("frontend"))) {
*type = Solid::DvbInterface::DvbFrontend;
string = string.mid(8);
} else if (string.startsWith(QLatin1String("net"))) {
*type = Solid::DvbInterface::DvbNet;
string = string.mid(3);
} else if (string.startsWith(QLatin1String("osd"))) {
*type = Solid::DvbInterface::DvbOsd;
string = string.mid(3);
} else if (string.startsWith(QLatin1String("sec"))) {
*type = Solid::DvbInterface::DvbSec;
string = string.mid(3);
} else if (string.startsWith(QLatin1String("video"))) {
*type = Solid::DvbInterface::DvbVideo;
string = string.mid(5);
} else
return false;
bool ok;
*index = string.toInt(&ok, 10);
return ok;
}
#include "backends/wmi/wmidvbinterface.moc"

View file

@ -1,54 +0,0 @@
/*
Copyright 2007 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_WMIDVBINTERFACE_H
#define SOLID_BACKENDS_WMI_WMIDVBINTERFACE_H
#include <solid/ifaces/dvbinterface.h>
#include "wmideviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class DvbInterface : public DeviceInterface, virtual public Solid::Ifaces::DvbInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::DvbInterface)
public:
DvbInterface(WmiDevice *device);
virtual ~DvbInterface();
virtual QString device() const;
virtual int deviceAdapter() const;
virtual Solid::DvbInterface::DeviceType deviceType() const;
virtual int deviceIndex() const;
private:
bool parseTypeIndex(Solid::DvbInterface::DeviceType *type, int *index) const;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_WMIDVBINTERFACE_H

View file

@ -1,56 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmigenericinterface.h"
#include "wmidevice.h"
using namespace Solid::Backends::Wmi;
GenericInterface::GenericInterface(WmiDevice *device)
: DeviceInterface(device)
{
connect(device, SIGNAL(propertyChanged(QMap<QString,int>)),
this, SIGNAL(propertyChanged(QMap<QString,int>)));
connect(device, SIGNAL(conditionRaised(QString,QString)),
this, SIGNAL(conditionRaised(QString,QString)));
}
GenericInterface::~GenericInterface()
{
}
QVariant GenericInterface::property(const QString &key) const
{
return m_device->property(key);
}
QMap<QString, QVariant> GenericInterface::allProperties() const
{
return m_device->allProperties();
}
bool GenericInterface::propertyExists(const QString &key) const
{
return m_device->propertyExists(key);
}
#include "backends/wmi/wmigenericinterface.moc"

View file

@ -1,57 +0,0 @@
/*
Copyright 2007 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_GENERICINTERFACE_H
#define SOLID_BACKENDS_WMI_GENERICINTERFACE_H
#include <solid/ifaces/genericinterface.h>
#include <solid/genericinterface.h>
#include "wmideviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class WmiDevice;
class GenericInterface : public DeviceInterface, virtual public Solid::Ifaces::GenericInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::GenericInterface)
public:
GenericInterface(WmiDevice *device);
virtual ~GenericInterface();
virtual QVariant property(const QString &key) const;
virtual QMap<QString, QVariant> allProperties() const;
virtual bool propertyExists(const QString &key) const;
Q_SIGNALS:
void propertyChanged(const QMap<QString,int> &changes);
void conditionRaised(const QString &condition, const QString &reason);
};
}
}
}
#endif // SOLID_BACKENDS_WMI_GENERICINTERFACE_H

View file

@ -1,271 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2005,2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmimanager.h"
#include <QtCore/QDebug>
#include "wmidevice.h"
#include "wmideviceinterface.h"
#include "wmiquery.h"
using namespace Solid::Backends::Wmi;
class Solid::Backends::Wmi::WmiManagerPrivate
{
public:
WmiManagerPrivate(WmiManager *parent)
:m_parent(parent)
{
supportedInterfaces << Solid::DeviceInterface::GenericInterface
<< Solid::DeviceInterface::Processor
// << Solid::DeviceInterface::Block
<< Solid::DeviceInterface::StorageAccess
<< Solid::DeviceInterface::StorageDrive
<< Solid::DeviceInterface::OpticalDrive
<< Solid::DeviceInterface::StorageVolume
<< Solid::DeviceInterface::OpticalDisc
// << Solid::DeviceInterface::Camera
// << Solid::DeviceInterface::PortableMediaPlayer
// << Solid::DeviceInterface::NetworkInterface
<< Solid::DeviceInterface::AcAdapter
<< Solid::DeviceInterface::Battery
// << Solid::DeviceInterface::Button
// << Solid::DeviceInterface::AudioInterface
// << Solid::DeviceInterface::DvbInterface
// << Solid::DeviceInterface::Video
// << Solid::DeviceInterface::SerialInterface
// << Solid::DeviceInterface::SmartCardReader
;
update();
}
~WmiManagerPrivate()
{
}
void update(){
init();
}
void init(){
if(m_deviceCache.isEmpty())
{
foreach(const Solid::DeviceInterface::Type &dev, supportedInterfaces){
updateDeviceCache(dev);
}
}
}
void updateDeviceCache(const Solid::DeviceInterface::Type & type){
QSet<QString> devSet = m_parent->findDeviceByDeviceInterface(type).toSet();
if(m_deviceCache.contains(type)){
QSet<QString> added = devSet - m_deviceCache[type];
foreach(const QString & s,added){
m_parent->slotDeviceAdded(s);
}
QSet<QString> removed = m_deviceCache[type] - devSet;
foreach(const QString & s,removed){
m_parent->slotDeviceRemoved(s);
}
}
m_deviceCache[type] = devSet;
}
WmiQuery::ItemList sendQuery( const QString &wql )
{
return WmiQuery::instance().sendQuery( wql );
}
WmiManager *m_parent;
QSet<Solid::DeviceInterface::Type> supportedInterfaces;
QMap<Solid::DeviceInterface::Type,QSet<QString> > m_deviceCache;
};
WmiManager::WmiManager(QObject *parent)
: DeviceManager(parent)
{
d = new WmiManagerPrivate(this);
QList<Solid::DeviceInterface::Type> types;
types<<Solid::DeviceInterface::StorageDrive<<Solid::DeviceInterface::StorageVolume;
//partition added
WmiQuery::instance().addDeviceListeners(new WmiManager::WmiEventSink(this,"SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE TargetInstance ISA 'Win32_DiskPartition'",types));
//partition removed
WmiQuery::instance().addDeviceListeners(new WmiManager::WmiEventSink(this,"SELECT * FROM __InstanceDeletionEvent WITHIN 10 WHERE TargetInstance ISA 'Win32_DiskPartition'",types));
types.clear();
types<<Solid::DeviceInterface::OpticalDisc;
//MediaLoaded=True/False change
WmiQuery::instance().addDeviceListeners(new WmiManager::WmiEventSink(this,"SELECT * from __InstanceModificationEvent WITHIN 10 WHERE TargetInstance ISA 'Win32_CDromDrive'",types));
}
WmiManager::~WmiManager()
{
delete d;
}
QString WmiManager::udiPrefix() const
{
return QString(); //FIXME: We should probably use a prefix there... has to be tested on Windows
}
QSet<Solid::DeviceInterface::Type> WmiManager::supportedInterfaces() const
{
return d->supportedInterfaces;
}
QStringList WmiManager::allDevices()
{
QStringList list;
foreach(const Solid::DeviceInterface::Type &type,d->supportedInterfaces){
list<<d->m_deviceCache[type].toList();
}
return list;
}
bool WmiManager::deviceExists(const QString &udi)
{
return WmiDevice::exists(udi);
}
QStringList WmiManager::devicesFromQuery(const QString &parentUdi,
Solid::DeviceInterface::Type type)
{
QStringList result;
if (!parentUdi.isEmpty())
{
foreach(const QString &udi,allDevices()){
WmiDevice device(udi);
if(device.type() == type && device.parentUdi() == parentUdi ){
result<<udi;
}
}
} else if (type!=Solid::DeviceInterface::Unknown) {
result<<findDeviceByDeviceInterface(type);
} else {
result<<allDevices();
}
return result;
}
QObject *WmiManager::createDevice(const QString &udi)
{
if (deviceExists(udi)) {
return new WmiDevice(udi);
} else {
return 0;
}
}
QStringList WmiManager::findDeviceStringMatch(const QString &key, const QString &value)
{
qDebug() << "has to be implemented" << key << value;
QStringList result;
// qDebug() << result;
return result;
}
QStringList WmiManager::findDeviceByDeviceInterface(Solid::DeviceInterface::Type type)
{
return WmiDevice::generateUDIList(type);
}
void WmiManager::slotDeviceAdded(const QString &udi)
{
qDebug()<<"Device added"<<udi;
emit deviceAdded(udi);
}
void WmiManager::slotDeviceRemoved(const QString &udi)
{
qDebug()<<"Device removed"<<udi;
emit deviceRemoved(udi);
}
WmiManager::WmiEventSink::WmiEventSink(WmiManager* parent, const QString &query, const QList<Solid::DeviceInterface::Type> &types):
m_parent(parent),
m_query(query),
m_types(types),
m_count(0)
{}
WmiManager::WmiEventSink::~WmiEventSink()
{}
ulong STDMETHODCALLTYPE WmiManager::WmiEventSink::AddRef()
{
return InterlockedIncrement(&m_count);
}
ulong STDMETHODCALLTYPE WmiManager::WmiEventSink::Release()
{
long lRef = InterlockedDecrement(&m_count);
if(lRef == 0)
delete this;
return lRef;
}
HRESULT STDMETHODCALLTYPE WmiManager::WmiEventSink::QueryInterface(REFIID riid, void** ppv)
{
if (riid == IID_IUnknown || riid == IID_IWbemObjectSink)
{
*ppv = (IWbemObjectSink *) this;
AddRef();
return WBEM_S_NO_ERROR;
}
else return E_NOINTERFACE;
}
HRESULT STDMETHODCALLTYPE WmiManager::WmiEventSink::Indicate(long lObjectCount,IWbemClassObject **apObjArray)
{
foreach(const Solid::DeviceInterface::Type &type,m_types){
m_parent->d->updateDeviceCache(type);
}
return WBEM_S_NO_ERROR;
}
HRESULT STDMETHODCALLTYPE WmiManager::WmiEventSink::SetStatus(long lFlags,HRESULT hResult,BSTR strParam,IWbemClassObject *pObjParam)
{
return WBEM_S_NO_ERROR;
}
const QString& WmiManager::WmiEventSink::query() const {
return m_query;
}
#include "backends/wmi/wmimanager.moc"

View file

@ -1,102 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2005,2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_WMIMANAGER_H
#define SOLID_BACKENDS_WMI_WMIMANAGER_H
#include <solid/ifaces/devicemanager.h>
#include <solid/deviceinterface.h>
#include <QtCore/QVariant>
#include <QtCore/QStringList>
#include <Wbemidl.h>
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class WmiManagerPrivate;
class WmiManager : public Solid::Ifaces::DeviceManager
{
Q_OBJECT
public:
class WmiEventSink : public IWbemObjectSink
{
public:
WmiEventSink(class WmiManager* parent,const QString &query,const QList<Solid::DeviceInterface::Type> &types);
~WmiEventSink();
virtual ulong STDMETHODCALLTYPE AddRef();
virtual ulong STDMETHODCALLTYPE Release();
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv);
virtual HRESULT STDMETHODCALLTYPE Indicate(long lObjectCount,IWbemClassObject **apObjArray);
virtual HRESULT STDMETHODCALLTYPE SetStatus(long lFlags,HRESULT hResult,BSTR strParam,IWbemClassObject *pObjParam);
const QString& query() const;
private:
WmiManager *m_parent;
QString m_query;
QList<Solid::DeviceInterface::Type> m_types;
long m_count;
};
WmiManager(QObject *parent=0);
virtual ~WmiManager();
virtual QString udiPrefix() const ;
virtual QSet<Solid::DeviceInterface::Type> supportedInterfaces() const;
virtual QStringList allDevices();
virtual bool deviceExists(const QString &udi);
virtual QStringList devicesFromQuery(const QString &parentUdi,
Solid::DeviceInterface::Type type);
virtual QObject *createDevice(const QString &udi);
private Q_SLOTS:
void slotDeviceAdded(const QString &udi);
void slotDeviceRemoved(const QString &udi);
private:
QStringList findDeviceStringMatch(const QString &key, const QString &value);
QStringList findDeviceByDeviceInterface(Solid::DeviceInterface::Type type);
WmiManagerPrivate *d;
friend class WmiManagerPrivate;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_WMIMANAGER_H

View file

@ -1,69 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wminetworkinterface.h"
#include "wmidevice.h"
#include <QtCore/QStringList>
using namespace Solid::Backends::Wmi;
NetworkInterface::NetworkInterface(WmiDevice *device)
: DeviceInterface(device)
{
}
NetworkInterface::~NetworkInterface()
{
}
QString NetworkInterface::ifaceName() const
{
return m_device->property("net.interface").toString();
}
bool NetworkInterface::isWireless() const
{
QStringList capabilities = m_device->property("info.capabilities").toStringList();
return capabilities.contains("net.80211");
}
QString NetworkInterface::hwAddress() const
{
return m_device->property("net.address").toString();
}
qulonglong NetworkInterface::macAddress() const
{
if (m_device->propertyExists("net.80211.mac_address"))
{
return m_device->property("net.80211.mac_address").toULongLong();
}
else
{
return m_device->property("net.80203.mac_address").toULongLong();
}
}
#include "backends/wmi/wminetworkinterface.moc"

View file

@ -1,53 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_WMINETWORKINTERFACE_H
#define SOLID_BACKENDS_WMI_WMINETWORKINTERFACE_H
#include <solid/ifaces/networkinterface.h>
#include "wmideviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class WmiDevice;
class NetworkInterface : public DeviceInterface, virtual public Solid::Ifaces::NetworkInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::NetworkInterface)
public:
NetworkInterface(WmiDevice *device);
virtual ~NetworkInterface();
virtual QString ifaceName() const;
virtual bool isWireless() const;
virtual QString hwAddress() const;
virtual qulonglong macAddress() const;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_WMINETWORKINTERFACE_H

View file

@ -1,113 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmiopticaldisc.h"
#include <QDir>
using namespace Solid::Backends::Wmi;
OpticalDisc::OpticalDisc(WmiDevice *device)
: Volume(device)
{
m_logicalDisk = WmiDevice::win32LogicalDiskByDriveLetter(m_device->property("Drive").toString());
}
OpticalDisc::~OpticalDisc()
{
}
Solid::OpticalDisc::ContentTypes OpticalDisc::availableContent() const
{
Solid::OpticalDisc::ContentTypes content;
QDir dir(m_device->property("Drive").toString());
QStringList files = dir.entryList();
if(files.length()>0)
if(files[0].endsWith(".cda"))
content |= Solid::OpticalDisc::Audio;
return content;
}
Solid::OpticalDisc::DiscType OpticalDisc::discType() const
{
QString type = m_logicalDisk.getProperty("FileSystem").toString();
if (type == "CDFS")
{
return Solid::OpticalDisc::CdRom;
}
// else if (type == "CdRomWrite")
// {
// return Solid::OpticalDisc::CdRecordable;
// }
else if (type == "UDF")
{
return Solid::OpticalDisc::DvdRom;
}
// else if (type == "DVDRomWrite")
// {
// return Solid::OpticalDisc::DvdRecordable;
// }
else
{
qDebug()<<"Solid::OpticalDisc::DiscType OpticalDisc::discType(): Unknown Type"<<type;
return Solid::OpticalDisc::UnknownDiscType;
}
}
bool OpticalDisc::isAppendable() const
{
return false;
}
bool OpticalDisc::isBlank() const
{
ushort val = m_device->property("FileSystemFlagsEx").toUInt();
if(val == 0)
return true;
return false;
}
bool OpticalDisc::isRewritable() const
{
//TODO:
return capacity()>0 && isWriteable();
}
qulonglong OpticalDisc::capacity() const
{
return m_device->property("Size").toULongLong();
}
bool OpticalDisc::isWriteable() const
{
ushort val = m_device->property("FileSystemFlagsEx").toUInt();
if(val == 0)
return true;
return !val & 0x80001;//read only
}
#include "backends/wmi/wmiopticaldisc.moc"

View file

@ -1,57 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_OPTICALDISC_H
#define SOLID_BACKENDS_WMI_OPTICALDISC_H
#include <solid/ifaces/opticaldisc.h>
#include "wmivolume.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class OpticalDisc : public Volume, virtual public Solid::Ifaces::OpticalDisc
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::OpticalDisc)
public:
OpticalDisc(WmiDevice *device);
virtual ~OpticalDisc();
virtual Solid::OpticalDisc::ContentTypes availableContent() const;
virtual Solid::OpticalDisc::DiscType discType() const;
virtual bool isAppendable() const;
virtual bool isBlank() const;
virtual bool isRewritable() const;
virtual qulonglong capacity() const;
private:
bool isWriteable() const;
WmiQuery::Item m_logicalDisk;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_OPTICALDISC_H

View file

@ -1,68 +0,0 @@
/*
Copyright 2006 Davide Bettio <davide.bettio@kdemail.net>
Copyright 2007 Jeff Mitchell <kde-dev@emailgoeshere.com>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmiportablemediaplayer.h"
using namespace Solid::Backends::Wmi;
PortableMediaPlayer::PortableMediaPlayer(WmiDevice *device)
: DeviceInterface(device)
{
}
PortableMediaPlayer::~PortableMediaPlayer()
{
}
QStringList PortableMediaPlayer::supportedProtocols() const
{
return m_device->property("portable_audio_player.access_method.protocols").toStringList();
}
QStringList PortableMediaPlayer::supportedDrivers(QString protocol) const
{
QStringList drivers = m_device->property("portable_audio_player.access_method.drivers").toStringList();
if(protocol.isNull())
return drivers;
QStringList returnedDrivers;
QString temp;
for(int i = 0; i < drivers.size(); i++)
{
temp = drivers.at(i);
if(m_device->property("portable_audio_player." + temp + ".protocol") == protocol)
returnedDrivers << temp;
}
return returnedDrivers;
}
QVariant Solid::Backends::Wmi::PortableMediaPlayer::driverHandle(const QString &driver) const
{
if (driver=="mtp") {
return m_device->property("usb.serial");
}
// TODO: Fill in the blank for other drivers
return QVariant();
}
#include "backends/wmi/wmiportablemediaplayer.moc"

View file

@ -1,55 +0,0 @@
/*
Copyright 2006 Davide Bettio <davide.bettio@kdemail.net>
Copyright 2007 Jeff Mitchell <kde-dev@emailgoeshere.com>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_PORTABLEMEDIAPLAYER_H
#define SOLID_BACKENDS_WMI_PORTABLEMEDIAPLAYER_H
#include <solid/ifaces/portablemediaplayer.h>
#include "wmideviceinterface.h"
#include <QtCore/QStringList>
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class WmiDevice;
class PortableMediaPlayer : public DeviceInterface, virtual public Solid::Ifaces::PortableMediaPlayer
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::PortableMediaPlayer)
public:
PortableMediaPlayer(WmiDevice *device);
virtual ~PortableMediaPlayer();
virtual QStringList supportedProtocols() const;
virtual QStringList supportedDrivers(QString protocol = QString()) const;
virtual QVariant driverHandle(const QString &driver) const;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_PORTABLEMEDIAPLAYER_H

View file

@ -1,64 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmiprocessor.h"
#include "wmidevice.h"
#include "../shared/cpufeatures.h"
using namespace Solid::Backends::Wmi;
Processor::Processor(WmiDevice *device)
: DeviceInterface(device)
{
}
Processor::~Processor()
{
}
int Processor::number() const
{
return m_device->property("NumberOfCores").toInt();
}
int Processor::maxSpeed() const
{
return m_device->property("MaxClockSpeed").toInt();
}
bool Processor::canChangeFrequency() const
{
// dummy for now, need some changes in WMI!
return false;
}
Solid::Processor::InstructionSets Processor::instructionSets() const
{
static Solid::Processor::InstructionSets cpuextensions = Solid::Backends::Shared::cpuFeatures();
return cpuextensions;
}
#include "backends/wmi/wmiprocessor.moc"

View file

@ -1,53 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_PROCESSOR_H
#define SOLID_BACKENDS_WMI_PROCESSOR_H
#include <solid/ifaces/processor.h>
#include "wmideviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class WmiDevice;
class Processor : public DeviceInterface, virtual public Solid::Ifaces::Processor
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Processor)
public:
Processor(WmiDevice *device);
virtual ~Processor();
virtual int number() const;
virtual int maxSpeed() const;
virtual bool canChangeFrequency() const;
virtual Solid::Processor::InstructionSets instructionSets() const;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_PROCESSOR_H

View file

@ -1,390 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2008 Jeff Mitchell <mitchell@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
//#define _WIN32_DCOM
//#include <comdef.h>
#define INSIDE_WMIQUERY
#include "wmiquery.h"
#include "wmimanager.h"
#ifdef _DEBUG
# pragma comment(lib, "comsuppwd.lib")
#else
# pragma comment(lib, "comsuppw.lib")
#endif
# pragma comment(lib, "wbemuuid.lib")
#include <iostream>
#include <Wbemidl.h>
#include <Oaidl.h>
# pragma comment(lib, "wbemuuid.lib")
#include <QtCore/QDebug>
#include <QtCore/QVariant>
#include <QtCore/QList>
#include <QtCore/QStringList>
#include <QtCore/QCoreApplication>
//needed for mingw
inline OLECHAR* SysAllocString(const QString &s){
const OLECHAR *olename = reinterpret_cast<const OLECHAR *>(s.utf16());
return ::SysAllocString(olename);
}
using namespace Solid::Backends::Wmi;
QString bstrToQString(BSTR bstr)
{
QString str((QChar*)bstr,::SysStringLen(bstr));
return str;
}
QVariant WmiQuery::Item::msVariantToQVariant(VARIANT msVariant, CIMTYPE variantType)
{
QVariant returnVariant(QVariant::Invalid);
if(msVariant.vt == VT_NULL){
return QVariant(QVariant::String);
}
switch(variantType) {
case CIM_STRING:
case CIM_CHAR16:
case CIM_UINT64://bug I get a wrong value from ullVal
{
QString str = bstrToQString(msVariant.bstrVal);
QVariant vs(str);
returnVariant = vs;
}
break;
case CIM_BOOLEAN:
{
QVariant vb(msVariant.boolVal);
returnVariant = vb;
}
break;
case CIM_UINT8:
{
QVariant vb(msVariant.uintVal);
returnVariant = vb;
}
break;
case CIM_UINT16:
{
QVariant vb(msVariant.uintVal);
returnVariant = vb;
}
break;
case CIM_UINT32:
{
QVariant vb(msVariant.uintVal);
returnVariant = vb;
}
break;
// case CIM_UINT64:
// {
// QVariant vb(msVariant.ullVal);
//// wprintf(L"ulonglong %d %I64u\r\n",variantType, msVariant.ullVal); // 32-bit on x86, 64-bit on x64
// returnVariant = vb;
// }
// break;
// default:
// qDebug()<<"Unsupported variant"<<variantType;
};
VariantClear(&msVariant);
return returnVariant;
}
/**
When a WmiQuery instance is created as a static global
object a deadlock problem occurs in pLoc->ConnectServer.
Please DO NOT USE the following or similar statement in
the global space or a class.
static WmiQuery instance;
*/
QVariant WmiQuery::Item::getProperty(BSTR bstrProp) const
{
QVariant result;
if(m_p == NULL)
return result;
VARIANT vtProp;
CIMTYPE variantType;
HRESULT hr = m_p->Get(bstrProp, 0, &vtProp, &variantType, 0);
if (SUCCEEDED(hr)) {
result = msVariantToQVariant(vtProp,variantType);
}else{
QString className = getProperty(L"__CLASS").toString();
QString qprop = bstrToQString(bstrProp);
qFatal("\r\n--------------------------------------------------------------\r\n"
"Error: Property: %s not found in %s\r\n"
"--------------------------------------------------------------\r\n",qPrintable(qprop),qPrintable(className));
}
return result;
}
QVariant WmiQuery::Item::getProperty(const QString &property) const
{
QVariant result;
BSTR bstrProp;
bstrProp = ::SysAllocString(property);
result = getProperty(bstrProp);
::SysFreeString(bstrProp);
return result;
}
QVariantMap WmiQuery::Item::getAllProperties()
{
if(m_properies.isEmpty()){
SAFEARRAY *psaNames;
HRESULT hr = m_p->GetNames(NULL, WBEM_FLAG_ALWAYS | WBEM_FLAG_NONSYSTEM_ONLY,NULL,&psaNames);
if (SUCCEEDED(hr)) {
long lLower, lUpper;
SafeArrayGetLBound( psaNames, 1, &lLower );
SafeArrayGetUBound( psaNames, 1, &lUpper );
for(long i=lLower;i<lUpper;++i){
BSTR pName = { 0 };
hr = SafeArrayGetElement( psaNames, &i, &pName );
QVariant vr = getProperty(pName);
if(vr.isValid()){
QString key = bstrToQString(pName);
m_properies[key] = getProperty(pName);
}
}
}else{
qWarning()<<"Querying all failed";
}
SafeArrayDestroy( psaNames);
}
return m_properies;
}
WmiQuery::Item::Item()
:m_p(NULL)
{
}
WmiQuery::Item::Item(IWbemClassObject *p) : m_p(p)
{
if(m_p != NULL)
m_p->AddRef();
}
WmiQuery::Item::Item(const Item& other) : m_p(other.m_p)
{
if(m_p != NULL)
m_p->AddRef();
}
WmiQuery::Item& WmiQuery::Item::operator=(const Item& other)
{
if(m_p != NULL){
m_p->Release();
m_p = NULL;
}
if(other.m_p != NULL){
m_p = other.m_p;
m_p->AddRef();
}
return *this;
}
WmiQuery::Item::~Item()
{
if(m_p != NULL &&
!(qApp->closingDown() || WmiQuery::instance().m_bNeedUninit))//this means we are in a QApplication, so qt already called CoUninitialize and all COM references are all ready freed
m_p->Release();
}
IWbemClassObject* WmiQuery::Item::data() const
{
if(m_p != NULL)
m_p->AddRef();
return m_p;
}
bool WmiQuery::Item::isNull() const
{
return m_p == NULL;
}
WmiQuery::WmiQuery()
: m_failed(false)
, pLoc(0)
, pSvc(0)
{
HRESULT hres;
hres = CoInitializeEx(0,COINIT_MULTITHREADED);
if( FAILED(hres) && hres != S_FALSE && hres != RPC_E_CHANGED_MODE )
{
qCritical() << "Failed to initialize COM library. Error code = 0x" << hex << quint32(hres) << endl;
m_failed = true;
}
m_bNeedUninit = ( hres != S_FALSE && hres != RPC_E_CHANGED_MODE );
if( !m_failed )
{
hres = CoInitializeSecurity( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL );
// RPC_E_TOO_LATE --> security already initialized
if( FAILED(hres) && hres != RPC_E_TOO_LATE )
{
qCritical() << "Failed to initialize security. " << "Error code = " << hres << endl;
if ( m_bNeedUninit )
CoUninitialize();
m_failed = true;
}
}
if( !m_failed )
{
hres = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc );
if (FAILED(hres))
{
qCritical() << "Failed to create IWbemLocator object. " << "Error code = " << hres << endl;
if ( m_bNeedUninit )
CoUninitialize();
m_failed = true;
}
}
if( !m_failed )
{
hres = pLoc->ConnectServer( L"ROOT\\CIMV2", NULL, NULL, 0, NULL, 0, 0, &pSvc );
if( FAILED(hres) )
{
qCritical() << "Could not connect. Error code = " << hres << endl;
pLoc->Release();
if ( m_bNeedUninit )
CoUninitialize();
m_failed = true;
}
// else
// qDebug() << "Connected to ROOT\\CIMV2 WMI namespace" << endl;
}
if( !m_failed )
{
hres = CoSetProxyBlanket( pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
if( FAILED(hres) )
{
qCritical() << "Could not set proxy blanket. Error code = " << hres << endl;
pSvc->Release();
pLoc->Release();
if ( m_bNeedUninit )
CoUninitialize();
m_failed = true;
}
}
}
WmiQuery::~WmiQuery()
{
if( m_failed )
return; // already cleaned up properly
if( pSvc )
pSvc->Release();
if( pLoc )
pLoc->Release();
if( m_bNeedUninit )
CoUninitialize();
}
void WmiQuery::addDeviceListeners(WmiManager::WmiEventSink *sink){
if(m_failed)
return;
BSTR bstrQuery;
bstrQuery = ::SysAllocString(sink->query());
HRESULT hr = pSvc->ExecNotificationQueryAsync(L"WQL",bstrQuery,0, NULL,sink);
::SysFreeString(bstrQuery);
if(FAILED(hr)){
qWarning()<<"WmiQuery::addDeviceListeners "<<sink->query()<<" failed!";
}
}
WmiQuery::ItemList WmiQuery::sendQuery( const QString &wql )
{
// qDebug()<<"WmiQuery::ItemList WmiQuery::sendQuery"<<wql;
ItemList retList;
if (!pSvc)
{
m_failed = true;
return retList;
}
HRESULT hres;
IEnumWbemClassObject* pEnumerator = NULL;
BSTR bstrQuery;
bstrQuery = ::SysAllocString(wql);
hres = pSvc->ExecQuery( L"WQL",bstrQuery ,
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
::SysFreeString(bstrQuery);
if( FAILED(hres) )
{
qDebug() << "Query with string \"" << wql << "\" failed. Error code = " << hres << endl;
}
else
{
ULONG uReturn = 0;
while( pEnumerator )
{
IWbemClassObject *pclsObj;
hres = pEnumerator->Next( WBEM_INFINITE, 1, &pclsObj, &uReturn );
if( !uReturn )
break;
// pclsObj will be released on destruction of Item
retList.append( Item( pclsObj ) );
pclsObj->Release();
}
if( pEnumerator )
pEnumerator->Release();
else
qDebug() << "failed to release enumerator!";
}
// if(retList.size()== 0)
// qDebug()<<"querying"<<wql<<"returned empty list";
// else
// qDebug()<<"Feteched"<<retList.size()<<"items";
return retList;
}
bool WmiQuery::isLegit() const
{
return !m_failed;
}
WmiQuery &WmiQuery::instance()
{
static WmiQuery *query = 0;
if (!query)
query = new WmiQuery;
return *query;
}

View file

@ -1,92 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2008 Jeff Mitchell <mitchell@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_WMIQUERY_H
#define SOLID_BACKENDS_WMI_WMIQUERY_H
#include <QtCore/QDebug>
#include <QtCore/QVariant>
#include <QtCore/QList>
#include <QtCore/QAtomicInt>
#include <QtCore/QSharedPointer>
#include <solid/solid_export.h>
#include <windows.h>
#include <rpc.h>
#include <comdef.h>
#include <Wbemidl.h>
#include <WTypes.h>
#include "wmimanager.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class WmiQuery
{
public:
class Item {
public:
Item();
Item(IWbemClassObject *p);
Item(const Item& other);
Item& operator=(const Item& other);
~Item();
IWbemClassObject* data() const;
bool isNull() const;
QVariant getProperty(const QString &property) const;
QVariantMap getAllProperties();
private:
static QVariant msVariantToQVariant(VARIANT msVariant, CIMTYPE variantType);
QVariant getProperty(BSTR property) const;
// QSharedPointer alone doesn't help because we need to call Release()
IWbemClassObject* m_p;
QVariantMap m_properies;
};
typedef QList<Item> ItemList;
WmiQuery();
~WmiQuery();
ItemList sendQuery( const QString &wql );
void addDeviceListeners(WmiManager::WmiEventSink *sink);
bool isLegit() const;
static WmiQuery &instance();
private:
bool m_failed;
bool m_bNeedUninit;
IWbemLocator *pLoc;
IWbemServices *pSvc;
};
}
}
}
#endif

View file

@ -1,112 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmistorage.h"
#include "wmiquery.h"
using namespace Solid::Backends::Wmi;
Storage::Storage(WmiDevice *device)
: Block(device)
{
if(m_device->type() == Solid::DeviceInterface::StorageDrive)
{
WmiQuery::Item item = WmiDevice::win32DiskPartitionByDeviceIndex(m_device->property("DeviceID").toString());
QString id = item.getProperty("DeviceID").toString();
m_logicalDisk = WmiDevice::win32LogicalDiskByDiskPartitionID(id);
}else if(m_device->type() == Solid::DeviceInterface::OpticalDrive)
{
QString id = m_device->property("Drive").toString();
m_logicalDisk = WmiDevice::win32LogicalDiskByDriveLetter(id);
}
}
Storage::~Storage()
{
}
Solid::StorageDrive::Bus Storage::bus() const
{
if(m_device->type() == Solid::DeviceInterface::OpticalDrive)
return Solid::StorageDrive::Platform;
QString bus = m_device->property("InterfaceType").toString().toLower();
if (bus=="ide")
{
return Solid::StorageDrive::Ide;
}
else if (bus=="usb")
{
return Solid::StorageDrive::Usb;
}
else if (bus=="1394")
{
return Solid::StorageDrive::Ieee1394;
}
else if (bus=="scsi")
{
return Solid::StorageDrive::Scsi;
}
// else if (bus=="sata")//not availible http://msdn.microsoft.com/en-us/library/windows/desktop/aa394132(v=vs.85).aspx
// {
// return Solid::StorageDrive::Sata;
// }
else
{
return Solid::StorageDrive::Platform;
}
}
Solid::StorageDrive::DriveType Storage::driveType() const
{
ushort type = m_logicalDisk.getProperty("DriveType").toUInt();
switch(type){
case 2:
return Solid::StorageDrive::MemoryStick;
case 3:
return Solid::StorageDrive::HardDisk;
case 5:
return Solid::StorageDrive::CdromDrive;
default:
return Solid::StorageDrive::HardDisk;
}
}
bool Storage::isRemovable() const
{
return driveType() != Solid::StorageDrive::HardDisk;
}
bool Storage::isHotpluggable() const
{
return bus() == Solid::StorageDrive::Usb;
}
qulonglong Storage::size() const
{
return m_device->property("Size").toULongLong();
}
#include "backends/wmi/wmistorage.moc"

View file

@ -1,57 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_STORAGE_H
#define SOLID_BACKENDS_WMI_STORAGE_H
#include <solid/ifaces/storagedrive.h>
#include "wmiblock.h"
#include "wmiquery.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class Storage : public Block, virtual public Solid::Ifaces::StorageDrive
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::StorageDrive)
public:
Storage(WmiDevice *device);
virtual ~Storage();
virtual Solid::StorageDrive::Bus bus() const;
virtual Solid::StorageDrive::DriveType driveType() const;
virtual bool isRemovable() const;
virtual bool isHotpluggable() const;
virtual qulonglong size() const;
private:
WmiQuery::Item m_logicalDisk;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_STORAGE_H

View file

@ -1,208 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmistorageaccess.h"
#include <QtCore/QDebug>
#include <QtGui/QApplication>
#include <QtGui/QWidget>
#include <unistd.h>
using namespace Solid::Backends::Wmi;
StorageAccess::StorageAccess(WmiDevice *device)
: DeviceInterface(device), m_setupInProgress(false), m_teardownInProgress(false),
m_passphraseRequested(false)
{
connect(device, SIGNAL(propertyChanged(QMap<QString,int>)),
this, SLOT(slotPropertyChanged(QMap<QString,int>)));
// qDebug()<<"StorageAccess"<<m_device->type();
m_logicalDisk = WmiDevice::win32LogicalDiskByDiskPartitionID(m_device->property("DeviceID").toString());
}
StorageAccess::~StorageAccess()
{
}
bool StorageAccess::isAccessible() const
{
return !m_logicalDisk.isNull();
}
QString StorageAccess::filePath() const
{
QString path = m_logicalDisk.getProperty("DeviceID").toString();
if(!path.isNull())
path.append("\\");
return path;
}
bool Solid::Backends::Wmi::StorageAccess::isIgnored() const
{
return m_logicalDisk.isNull();
}
bool StorageAccess::setup()
{
if (m_teardownInProgress || m_setupInProgress) {
return false;
}
m_setupInProgress = true;
// if (m_device->property("info.interfaces").toStringList().contains("org.freedesktop.Wmi.Device.Volume.Crypto")) {
// return requestPassphrase();
// } else if (FstabHandling::isInFstab(m_device->property("block.device").toString())) {
// return callSystemMount();
// } else {
// return callWmiVolumeMount();
// }
return false;
}
bool StorageAccess::teardown()
{
if (m_teardownInProgress || m_setupInProgress) {
return false;
}
m_teardownInProgress = true;
// if (m_device->property("info.interfaces").toStringList().contains("org.freedesktop.Wmi.Device.Volume.Crypto")) {
// return callCryptoTeardown();
// } else if (FstabHandling::isInFstab(m_device->property("block.device").toString())) {
// return callSystemUnmount();
// } else {
// return callWmiVolumeUnmount();
// }
return false;
}
void StorageAccess::slotPropertyChanged(const QMap<QString,int> &changes)
{
if (changes.contains("volume.is_mounted"))
{
emit accessibilityChanged(isAccessible(), m_device->udi());
}
}
void Solid::Backends::Wmi::StorageAccess::slotProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
/*
Q_UNUSED(exitStatus);
if (m_setupInProgress) {
m_setupInProgress = false;
if (exitCode==0) {
emit setupDone(Solid::NoError, QVariant(), m_device->udi());
} else {
emit setupDone(Solid::UnauthorizedOperation,
m_process->readAllStandardError(),
m_device->udi());
}
} else if (m_teardownInProgress) {
m_teardownInProgress = false;
if (exitCode==0) {
emit teardownDone(Solid::NoError, QVariant(), m_device->udi());
} else {
emit teardownDone(Solid::UnauthorizedOperation,
m_process->readAllStandardError(),
m_device->udi());
}
}
delete m_process;
*/
}
QString generateReturnObjectPath()
{
static int number = 1;
return "/org/kde/solid/WmiStorageAccess_"+QString::number(number++);
}
bool StorageAccess::callWmiVolumeMount()
{
// QDBusConnection c = QDBusConnection::systemBus();
// QString udi = m_device->udi();
// QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.Wmi", udi,
// "org.freedesktop.Wmi.Device.Volume",
// "Mount");
// QStringList options;
// QStringList wmiOptions = m_device->property("volume.mount.valid_options").toStringList();
// if (wmiOptions.contains("uid=")) {
// options << "uid="+QString::number(::getuid());
// }
// msg << "" << "" << options;
// return c.callWithCallback(msg, this,
// SLOT(slotDBusReply(QDBusMessage)),
// SLOT(slotDBusError(QDBusError)));
return false;
}
bool StorageAccess::callWmiVolumeUnmount()
{
// QDBusConnection c = QDBusConnection::systemBus();
// QString udi = m_device->udi();
// QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.Wmi", udi,
// "org.freedesktop.Wmi.Device.Volume",
// "Unmount");
// msg << QStringList();
// return c.callWithCallback(msg, this,
// SLOT(slotDBusReply(QDBusMessage)),
// SLOT(slotDBusError(QDBusError)));
return false;
}
bool Solid::Backends::Wmi::StorageAccess::callSystemMount()
{
/*
const QString device = m_device->property("block.device").toString();
m_process = FstabHandling::callSystemCommand("mount", device,
this, SLOT(slotProcessFinished(int,QProcess::ExitStatus)));
return m_process!=0;
*/
return 0;
}
bool Solid::Backends::Wmi::StorageAccess::callSystemUnmount()
{
/*
const QString device = m_device->property("block.device").toString();
m_process = FstabHandling::callSystemCommand("umount", device,
this, SLOT(slotProcessFinished(int,QProcess::ExitStatus)));
return m_process!=0;
*/
return 0;
}
#include "backends/wmi/wmistorageaccess.moc"

View file

@ -1,81 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_STORAGEACCESS_H
#define SOLID_BACKENDS_WMI_STORAGEACCESS_H
#include <solid/ifaces/storageaccess.h>
#include "wmideviceinterface.h"
#include <QtCore/QProcess>
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class StorageAccess : public DeviceInterface, virtual public Solid::Ifaces::StorageAccess
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::StorageAccess)
public:
StorageAccess(WmiDevice *device);
virtual ~StorageAccess();
virtual bool isAccessible() const;
virtual QString filePath() const;
virtual bool isIgnored() const;
virtual bool setup();
virtual bool teardown();
Q_SIGNALS:
void accessibilityChanged(bool accessible, const QString &udi);
void setupDone(Solid::ErrorType error, QVariant errorData, const QString &udi);
void teardownDone(Solid::ErrorType error, QVariant errorData, const QString &udi);
void setupRequested(const QString &udi);
void teardownRequested(const QString &udi);
private Q_SLOTS:
void slotPropertyChanged(const QMap<QString,int> &changes);
void slotProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
private:
bool callWmiVolumeMount();
bool callWmiVolumeUnmount();
bool callSystemMount();
bool callSystemUnmount();
private:
bool m_setupInProgress;
bool m_teardownInProgress;
bool m_passphraseRequested;
QString m_lastReturnObject;
QProcess *m_process;
WmiQuery::Item m_logicalDisk;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_STORAGEACCESS_H

View file

@ -1,62 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
Copyright 2007 Will Stephenson <wstephenson@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmivideo.h"
using namespace Solid::Backends::Wmi;
Video::Video(WmiDevice *device)
: DeviceInterface(device)
{
}
Video::~Video()
{
}
QStringList Video::supportedProtocols() const
{
QStringList protocols;
protocols << QString( "video4linux" );
return protocols;
}
QStringList Video::supportedDrivers(QString protocol) const
{
// if there is a difference between v4l and v4l2
QStringList drivers;
drivers << QString( "video4linux" );
return drivers;
}
QVariant Solid::Backends::Wmi::Video::driverHandle(const QString &driver) const
{
if (driver=="video4linux") {
return m_device->property("video4linux.device");
}
// TODO: Fill in the blank for other drivers
return QVariant();
}
#include "backends/wmi/wmivideo.moc"

View file

@ -1,50 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
Copyright 2007 Will Stephenson <wstephenson@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_VIDEO_H
#define SOLID_BACKENDS_WMI_VIDEO_H
#include <solid/ifaces/video.h>
#include "wmideviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class Video : public DeviceInterface, virtual public Solid::Ifaces::Video
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Video)
public:
Video(WmiDevice *device);
virtual ~Video();
virtual QStringList supportedProtocols() const;
virtual QStringList supportedDrivers(QString protocol = QString()) const;
virtual QVariant driverHandle(const QString &driver) const;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_VIDEO_H

View file

@ -1,79 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "wmivolume.h"
using namespace Solid::Backends::Wmi;
Volume::Volume(WmiDevice *device)
: Block(device)
{
if(m_device->type() == Solid::DeviceInterface::StorageVolume)
{
m_logicalDisk = WmiDevice::win32LogicalDiskByDiskPartitionID(m_device->property("DeviceID").toString());
}else if(m_device->type() == Solid::DeviceInterface::OpticalDisc)
{
m_logicalDisk = WmiDevice::win32LogicalDiskByDriveLetter(m_device->property("Drive").toString());
}
}
Volume::~Volume()
{
}
bool Volume::isIgnored() const
{
return m_logicalDisk.isNull();
}
Solid::StorageVolume::UsageType Volume::usage() const
{
return Solid::StorageVolume::FileSystem;//TODO:???
}
QString Volume::fsType() const
{
return m_logicalDisk.getProperty("FileSystem").toString();
}
QString Volume::label() const
{
return m_logicalDisk.getProperty("VolumeName").toString();
}
QString Volume::uuid() const
{
return m_logicalDisk.getProperty("VolumeSerialNumber").toString();
}
qulonglong Volume::size() const
{
return m_device->property("Size").toULongLong();
}
QString Solid::Backends::Wmi::Volume::encryptedContainerUdi() const
{
return this->uuid();
}
#include "backends/wmi/wmivolume.moc"

View file

@ -1,58 +0,0 @@
/*
Copyright 2012 Patrick von Reth <vonreth@kde.org>
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_WMI_VOLUME_H
#define SOLID_BACKENDS_WMI_VOLUME_H
#include <solid/ifaces/storagevolume.h>
#include "wmiblock.h"
namespace Solid
{
namespace Backends
{
namespace Wmi
{
class Volume : public Block, virtual public Solid::Ifaces::StorageVolume
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::StorageVolume)
public:
Volume(WmiDevice *device);
virtual ~Volume();
virtual bool isIgnored() const;
virtual Solid::StorageVolume::UsageType usage() const;
virtual QString fsType() const;
virtual QString label() const;
virtual QString uuid() const;
virtual qulonglong size() const;
virtual QString encryptedContainerUdi() const;
private:
WmiQuery::Item m_logicalDisk;
};
}
}
}
#endif // SOLID_BACKENDS_WMI_VOLUME_H

View file

@ -1,119 +0,0 @@
/*
Copyright 2013 Patrick von Reth <vonreth@kde.org>
Copyright 2006-2007 Will Stephenson <wstephenson@kde.org>
Copyright 2006-2007 Kevin Ottens <ervin@kde.org>
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 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
//#include <KDebug>
#include "networking.h"
#include "networking_p.h"
#include "soliddefs_p.h"
#include "org_kde_solid_networking_client.h"
SOLID_GLOBAL_STATIC(Solid::NetworkingPrivate, globalNetworkManager)
Solid::NetworkingPrivate::NetworkingPrivate()
: netStatus(Solid::Networking::Unknown),
connectPolicy(Solid::Networking::Managed),
disconnectPolicy(Solid::Networking::Managed),
m_manager(new QNetworkConfigurationManager())
{
initialize();
}
Solid::NetworkingPrivate::~NetworkingPrivate()
{
m_manager->deleteLater();
}
Solid::Networking::Notifier::Notifier()
{
}
void Solid::NetworkingPrivate::initialize()
{
netStatus = m_manager->isOnline()?Solid::Networking::Connected:Solid::Networking::Unconnected;
connect(m_manager,SIGNAL(onlineStateChanged(bool)),this,SLOT(serviceStatusChanged(bool)));
}
uint Solid::NetworkingPrivate::status() const
{
return netStatus;
}
/*=========================================================================*/
Solid::Networking::Status Solid::Networking::status()
{
return static_cast<Solid::Networking::Status>( globalNetworkManager->status() );
}
Solid::Networking::Notifier *Solid::Networking::notifier()
{
return globalNetworkManager;
}
void Solid::NetworkingPrivate::serviceStatusChanged( bool status )
{
// kDebug( 921 ) ;
netStatus = status?Solid::Networking::Connected:Solid::Networking::Unconnected;
switch ( netStatus ) {
case Solid::Networking::Unknown:
break;
case Solid::Networking::Unconnected:
emit globalNetworkManager->shouldDisconnect();
break;
case Solid::Networking::Connected:
emit globalNetworkManager->shouldConnect();
break;
default:
break;
// kDebug( 921 ) << "Unrecognised status code!";
}
emit globalNetworkManager->statusChanged( netStatus );
}
Solid::Networking::ManagementPolicy Solid::Networking::connectPolicy()
{
return globalNetworkManager->connectPolicy;
}
void Solid::Networking::setConnectPolicy( Solid::Networking::ManagementPolicy policy )
{
globalNetworkManager->connectPolicy = policy;
}
Solid::Networking::ManagementPolicy Solid::Networking::disconnectPolicy()
{
return globalNetworkManager->disconnectPolicy;
}
void Solid::Networking::setDisconnectPolicy( Solid::Networking::ManagementPolicy policy )
{
globalNetworkManager->disconnectPolicy = policy;
}
#include "networking_p.moc"
#include "networking.moc"