From d39801863307ba3c1e443c10ae0335003b0f00dc Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Wed, 2 Jan 2019 00:32:36 +0100 Subject: [PATCH] Fix macos build --- src/CMakeLists.txt | 4 +- src/core/mac_delegate.h | 8 +-- src/core/mac_startup.h | 4 +- src/core/mac_startup.mm | 18 ++--- src/device/devicemanager.cpp | 4 +- ...{macdevicelister.h => macosdevicelister.h} | 12 ++-- ...acdevicelister.mm => macosdevicelister.mm} | 67 ++++++++++--------- .../globalshortcutbackend-macos.h | 6 +- .../globalshortcutbackend-macos.mm | 6 +- 9 files changed, 65 insertions(+), 64 deletions(-) rename src/device/{macdevicelister.h => macosdevicelister.h} (89%) rename src/device/{macdevicelister.mm => macosdevicelister.mm} (92%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 332b19de..47f1c209 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -850,9 +850,9 @@ optional_source(APPLE if (APPLE) optional_source(HAVE_LIBMTP SOURCES - device/macdevicelister.mm + device/macosdevicelister.mm HEADERS - device/macdevicelister.h + device/macosdevicelister.h ) endif() diff --git a/src/core/mac_delegate.h b/src/core/mac_delegate.h index 0ca0b2a0..fe0c62fe 100644 --- a/src/core/mac_delegate.h +++ b/src/core/mac_delegate.h @@ -1,7 +1,7 @@ #import #include "config.h" -#include "globalshortcuts/macglobalshortcutbackend.h" +#include "globalshortcuts/globalshortcutbackend-macos.h" class PlatformInterface; @class SPMediaKeyTap; @@ -9,7 +9,7 @@ class PlatformInterface; @interface AppDelegate : NSObject { PlatformInterface* application_handler_; NSMenu* dock_menu_; - MacGlobalShortcutBackend* shortcut_handler_; + GlobalShortcutBackendMacOS* shortcut_handler_; SPMediaKeyTap* key_tap_; } @@ -27,7 +27,7 @@ class PlatformInterface; shouldPresentNotification: (id)notification; - (void) setDockMenu: (NSMenu*)menu; -- (MacGlobalShortcutBackend*) shortcut_handler; -- (void) setShortcutHandler: (MacGlobalShortcutBackend*)backend; +- (GlobalShortcutBackendMacOS*) shortcut_handler; +- (void) setShortcutHandler: (GlobalShortcutBackendMacOS*)backend; - (void) mediaKeyTap: (SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event; @end diff --git a/src/core/mac_startup.h b/src/core/mac_startup.h index 77da0625..7605b901 100644 --- a/src/core/mac_startup.h +++ b/src/core/mac_startup.h @@ -9,7 +9,7 @@ class QObject; class QWidget; -class MacGlobalShortcutBackend; +class GlobalShortcutBackendMacOS; class PlatformInterface { public: @@ -23,7 +23,7 @@ class PlatformInterface { namespace mac { void MacMain(); -void SetShortcutHandler(MacGlobalShortcutBackend *handler); +void SetShortcutHandler(GlobalShortcutBackendMacOS *handler); void SetApplicationHandler(PlatformInterface *handler); void CheckForUpdates(); diff --git a/src/core/mac_startup.mm b/src/core/mac_startup.mm index 5303a8dd..8cd3c3e6 100644 --- a/src/core/mac_startup.mm +++ b/src/core/mac_startup.mm @@ -51,7 +51,7 @@ #include "core/logging.h" #include "core/scoped_nsautorelease_pool.h" #include "globalshortcuts/globalshortcuts.h" -#include "globalshortcuts/macglobalshortcutbackend.h" +#include "globalshortcuts/globalshortcutbackend-macos.h" #ifdef HAVE_SPARKLE # import @@ -80,11 +80,11 @@ QDebug operator<<(QDebug dbg, NSObject* object) { PlatformInterface* application_handler_; AppDelegate* delegate_; // shortcut_handler_ only used to temporarily save it AppDelegate does all the heavy-shortcut-lifting - MacGlobalShortcutBackend* shortcut_handler_; + GlobalShortcutBackendMacOS* shortcut_handler_; } -- (MacGlobalShortcutBackend*)shortcut_handler; -- (void)SetShortcutHandler:(MacGlobalShortcutBackend*)handler; +- (GlobalShortcutBackendMacOS*)shortcut_handler; +- (void)SetShortcutHandler:(GlobalShortcutBackendMacOS*)handler; - (PlatformInterface*)application_handler; - (void)SetApplicationHandler:(PlatformInterface*)handler; @@ -147,11 +147,11 @@ static BreakpadRef InitBreakpad() { return dock_menu_; } -- (void)setShortcutHandler:(MacGlobalShortcutBackend*)backend { +- (void)setShortcutHandler:(GlobalShortcutBackendMacOS*)backend { shortcut_handler_ = backend; } -- (MacGlobalShortcutBackend*)shortcut_handler { +- (GlobalShortcutBackendMacOS*)shortcut_handler { return shortcut_handler_; } @@ -227,12 +227,12 @@ static BreakpadRef InitBreakpad() { return self; } -- (MacGlobalShortcutBackend*)shortcut_handler { +- (GlobalShortcutBackendMacOS*)shortcut_handler { // should be the same as delegate_'s shortcut handler return shortcut_handler_; } -- (void)SetShortcutHandler:(MacGlobalShortcutBackend*)handler { +- (void)SetShortcutHandler:(GlobalShortcutBackendMacOS*)handler { shortcut_handler_ = handler; if (delegate_) [delegate_ setShortcutHandler:handler]; } @@ -277,7 +277,7 @@ void MacMain() { #endif } -void SetShortcutHandler(MacGlobalShortcutBackend* handler) { +void SetShortcutHandler(GlobalShortcutBackendMacOS* handler) { [NSApp SetShortcutHandler:handler]; } diff --git a/src/device/devicemanager.cpp b/src/device/devicemanager.cpp index a6c9ed7f..0d64f416 100644 --- a/src/device/devicemanager.cpp +++ b/src/device/devicemanager.cpp @@ -81,7 +81,7 @@ # include "ilister.h" #endif #if defined(Q_OS_MACOS) and defined(HAVE_LIBMTP) -# include "macdevicelister.h" +# include "macosdevicelister.h" #endif #ifdef HAVE_LIBGPOD # include "gpoddevice.h" @@ -129,7 +129,7 @@ DeviceManager::DeviceManager(Application *app, QObject *parent) AddLister(new GioLister); #endif #if defined(Q_OS_MACOS) and defined(HAVE_LIBMTP) - AddLister(new MacDeviceLister); + AddLister(new MacOsDeviceLister); #endif AddDeviceClass(); diff --git a/src/device/macdevicelister.h b/src/device/macosdevicelister.h similarity index 89% rename from src/device/macdevicelister.h rename to src/device/macosdevicelister.h index a0aa5c63..7ad709e4 100644 --- a/src/device/macdevicelister.h +++ b/src/device/macosdevicelister.h @@ -18,11 +18,11 @@ #include "devicelister.h" -class MacDeviceLister : public DeviceLister { +class MacOsDeviceLister : public DeviceLister { Q_OBJECT public: - MacDeviceLister(); - ~MacDeviceLister(); + MacOsDeviceLister(); + ~MacOsDeviceLister(); virtual QStringList DeviceUniqueIDs(); virtual QVariantList DeviceIcons(const QString &id); @@ -57,7 +57,7 @@ class MacDeviceLister : public DeviceLister { virtual void ShutDown(); private: - virtual void Init(); + virtual bool Init(); static void DiskAddedCallback(DADiskRef disk, void* context); static void DiskRemovedCallback(DADiskRef disk, void* context); @@ -86,8 +86,8 @@ class MacDeviceLister : public DeviceLister { static QSet sMTPDeviceList; }; -uint qHash(const MacDeviceLister::MTPDevice& device); -inline bool operator==(const MacDeviceLister::MTPDevice& a, const MacDeviceLister::MTPDevice& b) { +uint qHash(const MacOsDeviceLister::MTPDevice& device); +inline bool operator==(const MacOsDeviceLister::MTPDevice& a, const MacOsDeviceLister::MTPDevice& b) { return (a.vendor_id == b.vendor_id) && (a.product_id == b.product_id); } diff --git a/src/device/macdevicelister.mm b/src/device/macosdevicelister.mm similarity index 92% rename from src/device/macdevicelister.mm rename to src/device/macosdevicelister.mm index fee65a75..9939ece6 100644 --- a/src/device/macdevicelister.mm +++ b/src/device/macosdevicelister.mm @@ -38,7 +38,7 @@ #include #include "config.h" -#include "macdevicelister.h" +#include "macosdevicelister.h" #include "mtpconnection.h" #include "core/logging.h" #include "core/scoped_cftyperef.h" @@ -98,17 +98,17 @@ class ScopedIOObject { // Libgphoto2 MTP detection code: // http://www.sfr-fresh.com/unix/privat/libgphoto2-2.4.10.1.tar.gz:a/libgphoto2-2.4.10.1/libgphoto2_port/usb/check-mtp-device.c -QSet MacDeviceLister::sMTPDeviceList; +QSet MacOsDeviceLister::sMTPDeviceList; -uint qHash(const MacDeviceLister::MTPDevice& d) { +uint qHash(const MacOsDeviceLister::MTPDevice& d) { return qHash(d.vendor_id) ^ qHash(d.product_id); } -MacDeviceLister::MacDeviceLister() {} +MacOsDeviceLister::MacOsDeviceLister() {} -MacDeviceLister::~MacDeviceLister() { CFRelease(loop_session_); } +MacOsDeviceLister::~MacOsDeviceLister() { CFRelease(loop_session_); } -void MacDeviceLister::Init() { +bool MacOsDeviceLister::Init() { ScopedNSAutoreleasePool pool; // Populate MTP Device list. @@ -187,9 +187,10 @@ void MacDeviceLister::Init() { CFRunLoopAddSource(run_loop_, io_source, kCFRunLoopDefaultMode); CFRunLoopRun(); + return true; } -void MacDeviceLister::ShutDown() { CFRunLoopStop(run_loop_); } +void MacOsDeviceLister::ShutDown() { CFRunLoopStop(run_loop_); } // IOKit helpers. namespace { @@ -311,7 +312,7 @@ QString FindDeviceProperty(const QString& bsd_name, CFStringRef property) { } } -quint64 MacDeviceLister::GetFreeSpace(const QUrl& url) { +quint64 MacOsDeviceLister::GetFreeSpace(const QUrl& url) { QMutexLocker l(&libmtp_mutex_); MtpConnection connection(url); if (!connection.is_valid()) { @@ -327,7 +328,7 @@ quint64 MacDeviceLister::GetFreeSpace(const QUrl& url) { return free_bytes; } -quint64 MacDeviceLister::GetCapacity(const QUrl& url) { +quint64 MacOsDeviceLister::GetCapacity(const QUrl& url) { QMutexLocker l(&libmtp_mutex_); MtpConnection connection(url); if (!connection.is_valid()) { @@ -343,8 +344,8 @@ quint64 MacDeviceLister::GetCapacity(const QUrl& url) { return capacity_bytes; } -void MacDeviceLister::DiskAddedCallback(DADiskRef disk, void* context) { - MacDeviceLister* me = reinterpret_cast(context); +void MacOsDeviceLister::DiskAddedCallback(DADiskRef disk, void* context) { + MacOsDeviceLister* me = reinterpret_cast(context); scoped_nsobject properties((NSDictionary*)DADiskCopyDescription(disk)); @@ -386,8 +387,8 @@ void MacDeviceLister::DiskAddedCallback(DADiskRef disk, void* context) { } } -void MacDeviceLister::DiskRemovedCallback(DADiskRef disk, void* context) { - MacDeviceLister* me = reinterpret_cast(context); +void MacOsDeviceLister::DiskRemovedCallback(DADiskRef disk, void* context) { + MacOsDeviceLister* me = reinterpret_cast(context); // We cannot access the USB tree when the disk is removed but we still get // the BSD disk name. @@ -448,8 +449,8 @@ int GetBusNumber(io_object_t o) { return -1; } -void MacDeviceLister::USBDeviceAddedCallback(void* refcon, io_iterator_t it) { - MacDeviceLister* me = reinterpret_cast(refcon); +void MacOsDeviceLister::USBDeviceAddedCallback(void* refcon, io_iterator_t it) { + MacOsDeviceLister* me = reinterpret_cast(refcon); io_object_t object; while ((object = IOIteratorNext(it))) { @@ -585,8 +586,8 @@ void MacDeviceLister::USBDeviceAddedCallback(void* refcon, io_iterator_t it) { } } -void MacDeviceLister::USBDeviceRemovedCallback(void* refcon, io_iterator_t it) { - MacDeviceLister* me = reinterpret_cast(refcon); +void MacOsDeviceLister::USBDeviceRemovedCallback(void* refcon, io_iterator_t it) { + MacOsDeviceLister* me = reinterpret_cast(refcon); io_object_t object; while ((object = IOIteratorNext(it))) { ScopedCFTypeRef class_name(IOObjectCopyClass(object)); @@ -611,7 +612,7 @@ void MacDeviceLister::USBDeviceRemovedCallback(void* refcon, io_iterator_t it) { } } -void MacDeviceLister::RemovedMTPDevice(const QString& serial) { +void MacOsDeviceLister::RemovedMTPDevice(const QString& serial) { int count = mtp_devices_.remove(serial); if (count) { qLog(Debug) << "MTP device removed:" << serial; @@ -619,7 +620,7 @@ void MacDeviceLister::RemovedMTPDevice(const QString& serial) { } } -void MacDeviceLister::FoundMTPDevice(const MTPDevice& device, const QString& serial) { +void MacOsDeviceLister::FoundMTPDevice(const MTPDevice& device, const QString& serial) { qLog(Debug) << "New MTP device detected!" << device.bus << device.address; mtp_devices_[serial] = device; QList urls = MakeDeviceUrls(serial); @@ -631,11 +632,11 @@ void MacDeviceLister::FoundMTPDevice(const MTPDevice& device, const QString& ser bool IsMTPSerial(const QString& serial) { return serial.startsWith("MTP"); } -bool MacDeviceLister::IsCDDevice(const QString& serial) const { +bool MacOsDeviceLister::IsCDDevice(const QString& serial) const { return cd_devices_.contains(serial); } -QString MacDeviceLister::MakeFriendlyName(const QString& serial) { +QString MacOsDeviceLister::MakeFriendlyName(const QString& serial) { if (IsMTPSerial(serial)) { const MTPDevice& device = mtp_devices_[serial]; if (device.vendor.isEmpty()) { @@ -668,7 +669,7 @@ QString MacDeviceLister::MakeFriendlyName(const QString& serial) { return vendor + " " + product; } -QList MacDeviceLister::MakeDeviceUrls(const QString& serial) { +QList MacOsDeviceLister::MakeDeviceUrls(const QString& serial) { if (IsMTPSerial(serial)) { const MTPDevice& device = mtp_devices_[serial]; QString str; @@ -701,11 +702,11 @@ QList MacDeviceLister::MakeDeviceUrls(const QString& serial) { return QList() << ret; } -QStringList MacDeviceLister::DeviceUniqueIDs() { +QStringList MacOsDeviceLister::DeviceUniqueIDs() { return current_devices_.keys() + mtp_devices_.keys(); } -QVariantList MacDeviceLister::DeviceIcons(const QString& serial) { +QVariantList MacOsDeviceLister::DeviceIcons(const QString& serial) { if (IsMTPSerial(serial)) { return QVariantList(); } @@ -735,21 +736,21 @@ QVariantList MacDeviceLister::DeviceIcons(const QString& serial) { return ret; } -QString MacDeviceLister::DeviceManufacturer(const QString& serial) { +QString MacOsDeviceLister::DeviceManufacturer(const QString& serial) { if (IsMTPSerial(serial)) { return mtp_devices_[serial].vendor; } return FindDeviceProperty(current_devices_[serial], CFSTR(kUSBVendorString)); } -QString MacDeviceLister::DeviceModel(const QString& serial) { +QString MacOsDeviceLister::DeviceModel(const QString& serial) { if (IsMTPSerial(serial)) { return mtp_devices_[serial].product; } return FindDeviceProperty(current_devices_[serial], CFSTR(kUSBProductString)); } -quint64 MacDeviceLister::DeviceCapacity(const QString& serial) { +quint64 MacOsDeviceLister::DeviceCapacity(const QString& serial) { if (IsMTPSerial(serial)) { QList urls = MakeDeviceUrls(serial); return mtp_devices_[serial].capacity; @@ -769,7 +770,7 @@ quint64 MacDeviceLister::DeviceCapacity(const QString& serial) { return ret; } -quint64 MacDeviceLister::DeviceFreeSpace(const QString& serial) { +quint64 MacOsDeviceLister::DeviceFreeSpace(const QString& serial) { if (IsMTPSerial(serial)) { QList urls = MakeDeviceUrls(serial); return mtp_devices_[serial].free_space; @@ -789,13 +790,13 @@ quint64 MacDeviceLister::DeviceFreeSpace(const QString& serial) { return 0; } -QVariantMap MacDeviceLister::DeviceHardwareInfo(const QString& serial){return QVariantMap();} +QVariantMap MacOsDeviceLister::DeviceHardwareInfo(const QString& serial){return QVariantMap();} -bool MacDeviceLister::AskForScan(const QString& serial) const { +bool MacOsDeviceLister::AskForScan(const QString& serial) const { return !IsCDDevice(serial); } -void MacDeviceLister::UnmountDevice(const QString& serial) { +void MacOsDeviceLister::UnmountDevice(const QString& serial) { if (IsMTPSerial(serial)) return; QString bsd_name = current_devices_[serial]; @@ -804,7 +805,7 @@ void MacDeviceLister::UnmountDevice(const QString& serial) { DADiskUnmount(disk, kDADiskUnmountOptionDefault, &DiskUnmountCallback, this); } -void MacDeviceLister::DiskUnmountCallback(DADiskRef disk, DADissenterRef dissenter, void* context) { +void MacOsDeviceLister::DiskUnmountCallback(DADiskRef disk, DADissenterRef dissenter, void* context) { if (dissenter) { qLog(Warning) << "Another app blocked the unmount"; } @@ -813,7 +814,7 @@ void MacDeviceLister::DiskUnmountCallback(DADiskRef disk, DADissenterRef dissent } } -void MacDeviceLister::UpdateDeviceFreeSpace(const QString& serial) { +void MacOsDeviceLister::UpdateDeviceFreeSpace(const QString& serial) { if (IsMTPSerial(serial)) { if (mtp_devices_.contains(serial)) { QList urls = MakeDeviceUrls(serial); diff --git a/src/globalshortcuts/globalshortcutbackend-macos.h b/src/globalshortcuts/globalshortcutbackend-macos.h index 9e718550..defcd1fa 100644 --- a/src/globalshortcuts/globalshortcutbackend-macos.h +++ b/src/globalshortcuts/globalshortcutbackend-macos.h @@ -36,7 +36,7 @@ class GlobalShortcut; -class GlobalShortcutBackendPrivateMacOS; +class GlobalShortcutBackendMacOSPrivate; class GlobalShortcutBackendMacOS : public GlobalShortcutBackend { Q_OBJECT @@ -59,8 +59,8 @@ class GlobalShortcutBackendMacOS : public GlobalShortcutBackend { QMap shortcuts_; - friend class GlobalShortcutBackendPrivateMacOS; - std::unique_ptr p_; + friend class GlobalShortcutBackendMacOSPrivate; + std::unique_ptr p_; }; #endif // GLOBALSHORTCUTBACKEND_MACOS_H diff --git a/src/globalshortcuts/globalshortcutbackend-macos.mm b/src/globalshortcuts/globalshortcutbackend-macos.mm index 67f72f56..6176c5b8 100644 --- a/src/globalshortcuts/globalshortcutbackend-macos.mm +++ b/src/globalshortcuts/globalshortcutbackend-macos.mm @@ -44,9 +44,9 @@ #import "core/mac_utilities.h" #import "core/SBSystemPreferences.h" -class GlobalShortcutBackendPrivate_MacOS : boost::noncopyable { +class GlobalShortcutBackendMacOSPrivate : boost::noncopyable { public: - explicit GlobalShortcutBackendPrivate_MacOS(GlobalShortcutBackendMacOS* backend) + explicit GlobalShortcutBackendMacOSPrivate(GlobalShortcutBackendMacOS* backend) : global_monitor_(nil), local_monitor_(nil), backend_(backend) {} bool Register() { @@ -80,7 +80,7 @@ class GlobalShortcutBackendPrivate_MacOS : boost::noncopyable { GlobalShortcutBackendMacOS::GlobalShortcutBackendMacOS(GlobalShortcuts* parent) : GlobalShortcutBackend(parent), - p_(new GlobalShortcutBackendPrivate_MacOS(this)) {} + p_(new GlobalShortcutBackendMacOSPrivate(this)) {} GlobalShortcutBackendMacOS::~GlobalShortcutBackendMacOS() {}