diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b1cb363db..59b173115 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -866,7 +866,6 @@ optional_source(APPLE core/scoped_nsautorelease_pool.mm core/mac_startup.mm core/macsystemtrayicon.mm - core/macfslistener.mm osd/osdmac.mm widgets/searchfield_mac.mm engine/macosdevicefinder.cpp @@ -875,7 +874,6 @@ optional_source(APPLE device/macosdevicelister.mm HEADERS core/macsystemtrayicon.h - core/macfslistener.h osd/osdmac.h globalshortcuts/globalshortcutsbackend-macos.h device/macosdevicelister.h diff --git a/src/core/filesystemwatcherinterface.cpp b/src/core/filesystemwatcherinterface.cpp index 699399879..03e5f06e6 100644 --- a/src/core/filesystemwatcherinterface.cpp +++ b/src/core/filesystemwatcherinterface.cpp @@ -25,22 +25,14 @@ #include "filesystemwatcherinterface.h" #include "qtfslistener.h" -#ifdef Q_OS_MACOS -# include "macfslistener.h" -#endif - FileSystemWatcherInterface::FileSystemWatcherInterface(QObject *parent) : QObject(parent) {} FileSystemWatcherInterface *FileSystemWatcherInterface::Create(QObject *parent) { -#ifdef Q_OS_MACOS - FileSystemWatcherInterface *ret = new MacFSListener(parent); -#else - FileSystemWatcherInterface *ret = new QtFSListener(parent); -#endif + FileSystemWatcherInterface *listener = new QtFSListener(parent); + listener->Init(); - ret->Init(); - return ret; + return listener; } diff --git a/src/core/macfslistener.h b/src/core/macfslistener.h deleted file mode 100644 index 66a36a7d8..000000000 --- a/src/core/macfslistener.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Strawberry Music Player - * This file was part of Clementine. - * Copyright 2012, David Sansome - * Copyright 2018-2021, Jonas Kvinge - * - * Strawberry 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. - * - * Strawberry 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 Strawberry. If not, see . - * - */ - -#ifndef MACFSLISTENER_H -#define MACFSLISTENER_H - -#include "config.h" - -#include - -#include -#include -#include - -#include "filesystemwatcherinterface.h" - -class QTimer; - -class MacFSListener : public FileSystemWatcherInterface { - Q_OBJECT - - public: - explicit MacFSListener(QObject *parent = nullptr); - void Init(); - void AddPath(const QString &path); - void RemovePath(const QString &path); - void Clear(); - - Q_SIGNALS: - void PathChanged(const QString &path); - - private Q_SLOTS: - void UpdateStream(); - - private: - void UpdateStreamAsync(); - - static void EventStreamCallback(ConstFSEventStreamRef stream, void *user_data, size_t num_events, void *event_paths, const FSEventStreamEventFlags event_flags[], const FSEventStreamEventId event_ids[]); - - CFRunLoopRef run_loop_; - FSEventStreamRef stream_; - - QSet paths_; - QTimer *update_timer_; -}; - -#endif // MACFSLISTENER_H diff --git a/src/core/macfslistener.mm b/src/core/macfslistener.mm deleted file mode 100644 index e90465a26..000000000 --- a/src/core/macfslistener.mm +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Strawberry Music Player - * This file was part of Clementine. - * Copyright 2010, David Sansome - * Copyright 2018-2021, Jonas Kvinge - * - * Strawberry 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. - * - * Strawberry 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 Strawberry. If not, see . - * - */ - -#include "macfslistener.h" - -#include "config.h" - -#include - -#include -#include -#include - -#include "core/logging.h" -#include "scoped_nsobject.h" - -using namespace Qt::Literals::StringLiterals; - -MacFSListener::MacFSListener(QObject *parent) - : FileSystemWatcherInterface(parent), - run_loop_(nullptr), - stream_(nullptr), - update_timer_(new QTimer(this)) { - - update_timer_->setSingleShot(true); - update_timer_->setInterval(2000); - QObject::connect(update_timer_, &QTimer::timeout, this, &MacFSListener::UpdateStream); - -} - -void MacFSListener::Init() { run_loop_ = CFRunLoopGetCurrent(); } - -void MacFSListener::EventStreamCallback(ConstFSEventStreamRef stream, void *user_data, size_t num_events, void *event_paths, const FSEventStreamEventFlags event_flags[], const FSEventStreamEventId event_ids[]) { - - Q_UNUSED(stream); - Q_UNUSED(event_flags); - Q_UNUSED(event_ids); - - MacFSListener *me = reinterpret_cast(user_data); - char **paths = reinterpret_cast(event_paths); - for (size_t i = 0; i < num_events; ++i) { - QString path = QString::fromUtf8(paths[i]); - qLog(Debug) << "Something changed at:" << path; - while (path.endsWith(u'/')) { - path.chop(1); - } - Q_EMIT me->PathChanged(path); - } - -} - -void MacFSListener::AddPath(const QString &path) { - - Q_ASSERT(run_loop_); - paths_.insert(path); - UpdateStreamAsync(); - -} - -void MacFSListener::RemovePath(const QString &path) { - - Q_ASSERT(run_loop_); - paths_.remove(path); - UpdateStreamAsync(); - -} - -void MacFSListener::Clear() { - - paths_.clear(); - UpdateStreamAsync(); - -} - -void MacFSListener::UpdateStreamAsync() { - update_timer_->start(); -} - -void MacFSListener::UpdateStream() { - - if (stream_) { - FSEventStreamStop(stream_); - FSEventStreamInvalidate(stream_); - FSEventStreamRelease(stream_); - stream_ = nullptr; - } - - if (paths_.empty()) { - return; - } - - scoped_nsobject array([ [NSMutableArray alloc] init]); - - for (const QString &path : paths_) { - scoped_nsobject string([ [NSString alloc] initWithUTF8String:path.toUtf8().constData()]); - [array addObject:string.get()]; - } - - FSEventStreamContext context; - memset(&context, 0, sizeof(context)); - context.info = this; - CFAbsoluteTime latency = 1.0; - - stream_ = FSEventStreamCreate(nullptr, &EventStreamCallback, &context, // Copied - reinterpret_cast(array.get()), - kFSEventStreamEventIdSinceNow, latency, - kFSEventStreamCreateFlagNone); - - FSEventStreamScheduleWithRunLoop(stream_, run_loop_, kCFRunLoopDefaultMode); - FSEventStreamStart(stream_); - -}