diff --git a/CMakeLists.txt b/CMakeLists.txt
index 50557f7..2ad1de9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,41 +1,40 @@
project(imagewriter)
set(PROJECT_VERSION "0.1")
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
set(QT_MIN_VERSION "5.4.0")
set(KF5_REQUIRED_VERSION "5.56.0")
find_package(ECM 1.1.0 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(ECMPackageConfigHelpers)
include(ECMOptionalAddSubdirectory)
include(ECMQtDeclareLoggingCategory)
option(ROSA_BRANDING "Build with ROSA branding" OFF)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
- find_package(PkgConfig REQUIRED)
- pkg_check_modules(LIBUDEV REQUIRED libudev)
+ find_package(UDev REQUIRED)
endif()
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Widgets)
find_package(KF5 ${KF5_REQUIRED_VERSION} REQUIRED COMPONENTS
I18n
CoreAddons
Auth
WidgetsAddons
IconThemes
)
KDE_ENABLE_EXCEPTIONS()
add_subdirectory(isoimagewriter)
add_subdirectory(images)
add_subdirectory(signing-keys)
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
diff --git a/isoimagewriter/CMakeLists.txt b/isoimagewriter/CMakeLists.txt
index 40eb45b..f1288de 100644
--- a/isoimagewriter/CMakeLists.txt
+++ b/isoimagewriter/CMakeLists.txt
@@ -1,92 +1,95 @@
set(GPGME_REQUIRED_VERSION "1.8.0")
find_package(Gpgmepp ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED)
find_package(QGpgme ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED)
#find_package(KF5 REQUIRED COMPONENTS QGpgme)
set(isoimagewriter_common_SRCS
platform_lin.cpp
common.cpp
)
ecm_qt_declare_logging_category(isoimagewriter_common_SRCS
HEADER isoimagewriter_debug.h
IDENTIFIER ISOIMAGEWRITER_LOG
CATEGORY_NAME org.kde.isoimagewriter
DEFAULT_SEVERITY Debug)
set(isoimagewriter_SRCS
${isoimagewriter_common_SRCS}
usbdevicemonitor.h
common.cpp
mainapplication.cpp
maindialog.cpp
externalprogressbar_lin.cpp
imagewriter.cpp
physicaldevice.cpp
main.cpp
verifyisoworker.cpp
verifyiso.cpp
verifyneoniso.cpp
verifykubuntuiso.cpp
verifynetrunneriso.cpp
verifyarchiso.cpp
)
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
message("Compiling isoimagewriter for Windaes")
set(isoimagewriter_SRCS
${isoimagewriter_SRCS}
platform_win.cpp
usbdevicemonitor_win.cpp
)
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
message("Compiling isoimagewriter for Linux")
set(isoimagewriter_SRCS
${isoimagewriter_SRCS}
platform_lin.cpp
usbdevicemonitor_lin.cpp
)
else()
message("Unsupported Platform " . ${CMAKE_SYSTEM_NAME})
endif()
ki18n_wrap_ui(isoimagewriter_SRCS maindialog.ui)
add_executable(isoimagewriter ${isoimagewriter_SRCS})
#add_executable(testy testy.cpp ${isoimagewriter_common_SRCS})
#target_link_libraries(testy Qt5::Widgets KF5::Auth)
if (ROSA_BRANDING)
target_compile_definitions(isoimagewriter PRIVATE -DROSA_BRANDING="1")
endif (ROSA_BRANDING)
target_compile_definitions(isoimagewriter PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}")
target_link_libraries(isoimagewriter
Qt5::Widgets
KF5::I18n
KF5::CoreAddons
KF5::AuthCore
QGpgme
- dl
KF5::WidgetsAddons
KF5::IconThemes
)
+if(CMAKE_SYSTEM_NAME STREQUAL Linux)
+ target_link_libraries(isoimagewriter udev)
+endif()
+
#target_link_libraries(testy
# Qt5::Widgets
# KF5::I18n
# KF5::CoreAddons
# dl
# QGpgme
# Gpgmepp
#)
install(TARGETS isoimagewriter ${INSTALL_TARGETS_DEFAULT_ARGS})
install(PROGRAMS org.kde.isoimagewriter.desktop DESTINATION ${XDG_APPS_INSTALL_DIR})
install(FILES org.kde.isoimagewriter.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR})
add_executable(isoimagewriter_helper common.cpp imagewriter_helper.cpp imagewriter.cpp physicaldevice.cpp)
target_link_libraries(isoimagewriter_helper Qt5::Widgets KF5::AuthCore KF5::I18n KF5::WidgetsAddons)
install(TARGETS isoimagewriter_helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR})
kauth_install_helper_files(isoimagewriter_helper org.kde.isoimagewriter root)
kauth_install_actions(org.kde.isoimagewriter isoimagewriter.actions)
diff --git a/isoimagewriter/usbdevicemonitor_lin.cpp b/isoimagewriter/usbdevicemonitor_lin.cpp
index b5b3069..90a3cf5 100644
--- a/isoimagewriter/usbdevicemonitor_lin.cpp
+++ b/isoimagewriter/usbdevicemonitor_lin.cpp
@@ -1,161 +1,135 @@
/*
* Copyright 2016 ROSA
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
////////////////////////////////////////////////////////////////////////////////
// Linux implementation of UsbDeviceMonitor
-#include "usbdevicemonitor_lin_p.h"
-
-#include
+#include
+#include "usbdevicemonitor_lin_p.h"
#include "usbdevicemonitor.h"
-// Declare required functions as weak so that they were not reported as missing at compile time.
-// In runtime it is required to ensure they are defined: we do it by checking that libudev is loaded.
-#pragma weak udev_device_unref
-#pragma weak udev_monitor_enable_receiving
-#pragma weak udev_monitor_filter_add_match_subsystem_devtype
-#pragma weak udev_monitor_get_fd
-#pragma weak udev_monitor_new_from_netlink
-#pragma weak udev_monitor_receive_device
-#pragma weak udev_monitor_unref
-#pragma weak udev_new
-#pragma weak udev_unref
-
// Private class implementation
UsbDeviceMonitorPrivate::UsbDeviceMonitorPrivate(QObject *parent) :
QObject(parent)
{
- //TODO replace this with QLibrary to deal with segfault if symbols/functions do not exist
- m_udevLib = dlopen("libudev.so.1", RTLD_NOW | RTLD_GLOBAL);
- if (m_udevLib == NULL)
- m_udevLib = dlopen("libudev.so.0", RTLD_NOW | RTLD_GLOBAL);
}
UsbDeviceMonitorPrivate::~UsbDeviceMonitorPrivate()
{
- if (m_udevLib != NULL)
- dlclose(m_udevLib);
}
// Processes udev socket notification
void UsbDeviceMonitorPrivate::processUdevNotification(int socket)
{
Q_UNUSED(socket);
- if (m_udevLib == NULL)
- return;
// Read the device information
// We don't really need it, but we have to empty the queue
struct udev_device* dev = udev_monitor_receive_device(m_udevMonitor);
if (dev)
{
udev_device_unref(dev);
emit q_ptr->deviceChanged();
}
}
// Main class implementation
UsbDeviceMonitor::UsbDeviceMonitor(QObject *parent) :
QObject(parent),
d_ptr(new UsbDeviceMonitorPrivate())
{
d_ptr->q_ptr = this;
d_ptr->m_udev = NULL;
d_ptr->m_udevMonitor = NULL;
d_ptr->m_udevNotifier = NULL;
}
UsbDeviceMonitor::~UsbDeviceMonitor()
{
cleanup();
delete d_ptr;
}
// Closes handles and frees resources
void UsbDeviceMonitor::cleanup()
{
- if (d_ptr->m_udevLib == NULL)
- return;
if (d_ptr->m_udevMonitor != NULL)
{
udev_monitor_unref(d_ptr->m_udevMonitor);
d_ptr->m_udevMonitor = NULL;
}
if (d_ptr->m_udev != NULL)
{
udev_unref(d_ptr->m_udev);
d_ptr->m_udev = NULL;
}
if (d_ptr->m_udevNotifier)
{
d_ptr->m_udevNotifier->setEnabled(false);
delete d_ptr->m_udevNotifier;
d_ptr->m_udevNotifier = NULL;
}
}
// Implements QAbstractNativeEventFilter interface for processing WM_DEVICECHANGE messages (Windows)
bool UsbDeviceMonitor::nativeEventFilter(const QByteArray& eventType, void* message, long* result)
{
Q_UNUSED(eventType);
Q_UNUSED(message);
Q_UNUSED(result);
return false;
}
bool UsbDeviceMonitor::startMonitoring()
{
- // In Linux we use udev monitor
- if (d_ptr->m_udevLib == NULL)
- return false;
try
{
d_ptr->m_udev = udev_new();
if (d_ptr->m_udev == NULL)
throw 1;
// Initialize monitoring
d_ptr->m_udevMonitor = udev_monitor_new_from_netlink(d_ptr->m_udev, "udev");
if (d_ptr->m_udevMonitor == NULL)
throw 1;
// Set filter to get notified only about block devices of type "disk"
if (udev_monitor_filter_add_match_subsystem_devtype(d_ptr->m_udevMonitor, "block", "disk") < 0)
throw 1;
// Start monitoring
if (udev_monitor_enable_receiving(d_ptr->m_udevMonitor) < 0)
throw 1;
// Get the socket file descriptor for QSocketNotifier
int fd = udev_monitor_get_fd(d_ptr->m_udevMonitor);
// Initialize QSocketNotifier for watching the socket
d_ptr->m_udevNotifier = new QSocketNotifier(fd, QSocketNotifier::Read);
connect(d_ptr->m_udevNotifier, &QSocketNotifier::activated, d_ptr, &UsbDeviceMonitorPrivate::processUdevNotification);
d_ptr->m_udevNotifier->setEnabled(true);
}
catch (...)
{
// Something went wrong, destroy everything and do without monitoring udev
cleanup();
return false;
}
return true;
}
diff --git a/isoimagewriter/usbdevicemonitor_lin_p.h b/isoimagewriter/usbdevicemonitor_lin_p.h
index 7ad876b..134d673 100644
--- a/isoimagewriter/usbdevicemonitor_lin_p.h
+++ b/isoimagewriter/usbdevicemonitor_lin_p.h
@@ -1,50 +1,48 @@
/*
* Copyright 2016 ROSA
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef USBDEVICEMONITOR_LIN_P_H
#define USBDEVICEMONITOR_LIN_P_H
#include
#include
// Class with platform-specific data
class UsbDeviceMonitor;
class UsbDeviceMonitorPrivate : public QObject
{
Q_OBJECT
public:
explicit UsbDeviceMonitorPrivate(QObject *parent = 0);
virtual ~UsbDeviceMonitorPrivate();
UsbDeviceMonitor* q_ptr;
- // Handle to dynamically loaded udev library
- void* m_udevLib;
// udev library context
struct udev* m_udev;
// udev device monitor handle
struct udev_monitor* m_udevMonitor;
// Watcher for udev monitor socket
QSocketNotifier* m_udevNotifier;
public slots:
// Processes udev socket notification
void processUdevNotification(int socket);
};
#endif // USBDEVICEMONITOR_LIN_P_H