From 61c84b9ee746de9c99151de7b86814dba7d781ba Mon Sep 17 00:00:00 2001 From: heckflosse Date: Sun, 2 Dec 2018 20:29:11 +0100 Subject: [PATCH] Get rid of windirmonitor --- rtgui/CMakeLists.txt | 2 +- rtgui/dirbrowser.cc | 15 ------ rtgui/dirbrowser.h | 14 ++---- rtgui/filecatalog.cc | 35 ------------- rtgui/filecatalog.h | 14 ------ rtgui/windirmonitor.cc | 109 ----------------------------------------- rtgui/windirmonitor.h | 57 --------------------- 7 files changed, 4 insertions(+), 242 deletions(-) delete mode 100644 rtgui/windirmonitor.cc delete mode 100644 rtgui/windirmonitor.h diff --git a/rtgui/CMakeLists.txt b/rtgui/CMakeLists.txt index 434e8187e..6ea768a03 100644 --- a/rtgui/CMakeLists.txt +++ b/rtgui/CMakeLists.txt @@ -170,7 +170,7 @@ endif() if(WIN32) set(EXTRA_SRC_CLI myicon.rc) - set(EXTRA_SRC_NONCLI myicon.rc windirmonitor.cc) + set(EXTRA_SRC_NONCLI myicon.rc) set(EXTRA_LIB_RTGUI winmm) include_directories(${EXTRA_INCDIR} ${GIOMM_INCLUDE_DIRS} diff --git a/rtgui/dirbrowser.cc b/rtgui/dirbrowser.cc index 81ee85fed..e1acbad3e 100644 --- a/rtgui/dirbrowser.cc +++ b/rtgui/dirbrowser.cc @@ -246,16 +246,6 @@ int updateVolumesUI (void* br) return 1; } -void DirBrowser::winDirChanged () -{ - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->updateDirTreeRoot(); - - return FALSE; - }; - - idle_register.add(func, this); -} #endif void DirBrowser::fillRoot () @@ -333,14 +323,9 @@ void DirBrowser::row_expanded (const Gtk::TreeModel::iterator& iter, const Gtk:: expandSuccess = true; } -#ifdef WIN32 - Glib::RefPtr monitor = Glib::RefPtr(new WinDirMonitor (iter->get_value (dtColumns.dirname), this)); - iter->set_value (dtColumns.monitor, monitor); -#else Glib::RefPtr monitor = dir->monitor_directory (); iter->set_value (dtColumns.monitor, monitor); monitor->signal_changed().connect (sigc::bind(sigc::mem_fun(*this, &DirBrowser::file_changed), iter, dir->get_parse_name())); -#endif } void DirBrowser::updateDir (const Gtk::TreeModel::iterator& iter) diff --git a/rtgui/dirbrowser.h b/rtgui/dirbrowser.h index 9d004f5f9..15b6dd201 100644 --- a/rtgui/dirbrowser.h +++ b/rtgui/dirbrowser.h @@ -21,16 +21,13 @@ #include #include -#ifdef WIN32 -#include "windirmonitor.h" -#endif #include "guiutils.h" +#ifdef WIN32 +#include "windows.h" +#endif class DirBrowser : public Gtk::VBox -#ifdef WIN32 - , public WinDirChangeListener -#endif { public: typedef sigc::signal DirSelectionSignal; @@ -45,11 +42,7 @@ private: Gtk::TreeModelColumn > icon1; Gtk::TreeModelColumn > icon2; Gtk::TreeModelColumn dirname; -#ifdef WIN32 - Gtk::TreeModelColumn > monitor; -#else Gtk::TreeModelColumn > monitor; -#endif DirTreeColumns() { @@ -89,7 +82,6 @@ public: void updateVolumes (); void updateDirTree (const Gtk::TreeModel::iterator& iter); void updateDirTreeRoot (); - void winDirChanged () override; private: void addRoot (char letter); #endif diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 0b45d3e3d..305b3985e 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -459,9 +459,6 @@ FileCatalog::FileCatalog (CoarsePanel* cp, ToolBar* tb, FilePanel* filepanel) : } selectedDirectory = ""; -#ifdef WIN32 - wdMonitor = NULL; -#endif } FileCatalog::~FileCatalog() @@ -540,21 +537,10 @@ void FileCatalog::closeDir () exportPanel->set_sensitive (false); } -#ifndef WIN32 - if (dirMonitor) { dirMonitor->cancel (); } -#else - - if (wdMonitor) { - delete wdMonitor; - wdMonitor = NULL; - } - -#endif - // ignore old requests ++selectedDirectoryId; @@ -671,12 +657,8 @@ void FileCatalog::dirSelected (const Glib::ustring& dirname, const Glib::ustring filepanel->loadingThumbs(M("PROGRESSBAR_LOADINGTHUMBS"), 0); } -#ifdef WIN32 - wdMonitor = new WinDirMonitor (selectedDirectory, this); -#else dirMonitor = dir->monitor_directory (); dirMonitor->signal_changed().connect (sigc::bind(sigc::mem_fun(*this, &FileCatalog::on_dir_changed), false)); -#endif } catch (Glib::Exception& ex) { std::cout << ex.what(); } @@ -1748,21 +1730,6 @@ void FileCatalog::reparseDirectory () fileNameList = nfileNameList; } -#ifdef WIN32 - -void FileCatalog::winDirChanged () -{ - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->reparseDirectory(); - - return FALSE; - }; - - idle_register.add(func, this); -} - -#else - void FileCatalog::on_dir_changed (const Glib::RefPtr& file, const Glib::RefPtr& other_file, Gio::FileMonitorEvent event_type, bool internal) { @@ -1777,8 +1744,6 @@ void FileCatalog::on_dir_changed (const Glib::RefPtr& file, const Gli } } -#endif - void FileCatalog::checkAndAddFile (Glib::RefPtr file) { diff --git a/rtgui/filecatalog.h b/rtgui/filecatalog.h index 407535ba0..7e613a2b4 100644 --- a/rtgui/filecatalog.h +++ b/rtgui/filecatalog.h @@ -19,9 +19,6 @@ #ifndef _FILECATALOG_ #define _FILECATALOG_ -#ifdef WIN32 -#include "windirmonitor.h" -#endif #include "filebrowser.h" #include "exiffiltersettings.h" #include @@ -48,9 +45,6 @@ class FileCatalog : public Gtk::VBox, public FilterPanelListener, public FileBrowserListener, public ExportPanelListener -#ifdef WIN32 - , public WinDirChangeListener -#endif { public: typedef sigc::slot DirSelectionSlot; @@ -142,11 +136,7 @@ private: std::set editedFiles; guint modifierKey; // any modifiers held when rank button was pressed -#ifndef _WIN32 Glib::RefPtr dirMonitor; -#else - WinDirMonitor* wdMonitor; -#endif IdleRegister idle_register; @@ -288,11 +278,7 @@ public: void showToolBar(); void hideToolBar(); -#ifndef _WIN32 void on_dir_changed (const Glib::RefPtr& file, const Glib::RefPtr& other_file, Gio::FileMonitorEvent event_type, bool internal); -#else - void winDirChanged (); -#endif }; diff --git a/rtgui/windirmonitor.cc b/rtgui/windirmonitor.cc deleted file mode 100644 index 1888d9405..000000000 --- a/rtgui/windirmonitor.cc +++ /dev/null @@ -1,109 +0,0 @@ -/* - * This file is part of RawTherapee. - * - * Copyright (c) 2004-2010 Gabor Horvath - * - * RawTherapee 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. - * - * RawTherapee 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 RawTherapee. If not, see . - */ -#include "windirmonitor.h" -#include "options.h" - -static void CALLBACK current_directory_monitor_callback (DWORD error, DWORD nBytes, LPOVERLAPPED lpOverlapped) -{ - DWORD dwOffset = 0; - FILE_NOTIFY_INFORMATION* pInfo = NULL; - - WinDirMonitor::MonitorData* monData = (WinDirMonitor::MonitorData*)lpOverlapped; - - if (!nBytes) { - delete monData; - return; - } - - bool notify = false; - - // Analysis of the modifications. Let only parsed file extensions emit a notify, not PP3 changes - do { - // Get a pointer to the first change record... - pInfo = (FILE_NOTIFY_INFORMATION*) &monData->file_notify_buffer[dwOffset]; - - char fnameC[(MAX_PATH + 1) * 2] = {0}; - int strLen = WideCharToMultiByte(CP_UTF8, 0, pInfo->FileName, pInfo->FileNameLength / sizeof(WCHAR), fnameC, sizeof(fnameC), 0, 0); - fnameC[strLen] = 0; - Glib::ustring fname = fnameC; - - if (options.has_retained_extention(fname)) { - notify = true; - } - - // More than one change may happen at the same time. Load the next change and continue... - dwOffset += pInfo->NextEntryOffset; - } while (!notify && pInfo->NextEntryOffset != 0); - - // ReadDirectoryChangesW sometimes emits multiple events per change (one for each change type) - // To make sure it's not flooding update, this gets filtered. - DWORD curTick = GetTickCount(); - - if (notify && monData->listener && (curTick - monData->lastTimeUpdateTick) > 500) { - monData->lastTimeUpdateTick = curTick; - monData->listener->winDirChanged (); - } - - ReadDirectoryChangesW (monData->hDirectory, - monData->file_notify_buffer, - monData->buffer_allocated_bytes, - FALSE, - FILE_NOTIFY_CHANGE_FILE_NAME | - FILE_NOTIFY_CHANGE_DIR_NAME | - FILE_NOTIFY_CHANGE_LAST_WRITE, - &monData->buffer_filled_bytes, - &monData->overlapped, - current_directory_monitor_callback); -} - -WinDirMonitor::WinDirMonitor (Glib::ustring dirName, WinDirChangeListener* listener) : monData(NULL) -{ - wchar_t* wdirname = (wchar_t*)g_utf8_to_utf16 (dirName.c_str(), -1, NULL, NULL, NULL); - HANDLE hDirectory = CreateFileW (wdirname, FILE_LIST_DIRECTORY, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL); - g_free (wdirname); - - if (hDirectory != INVALID_HANDLE_VALUE) { - - monData = new MonitorData (); - monData->listener = listener; - monData->buffer_allocated_bytes = 32768; - monData->file_notify_buffer = new char [monData->buffer_allocated_bytes]; - monData->hDirectory = hDirectory; - monData->lastTimeUpdateTick = GetTickCount(); - - ReadDirectoryChangesW (monData->hDirectory, - monData->file_notify_buffer, - monData->buffer_allocated_bytes, - FALSE, - FILE_NOTIFY_CHANGE_FILE_NAME | - FILE_NOTIFY_CHANGE_DIR_NAME | - FILE_NOTIFY_CHANGE_LAST_WRITE, - &monData->buffer_filled_bytes, - &monData->overlapped, - current_directory_monitor_callback); - } -} - -WinDirMonitor::~WinDirMonitor () -{ - - if (monData && monData->hDirectory != INVALID_HANDLE_VALUE) { - CloseHandle (monData->hDirectory); - } -} diff --git a/rtgui/windirmonitor.h b/rtgui/windirmonitor.h deleted file mode 100644 index 8e18b7914..000000000 --- a/rtgui/windirmonitor.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of RawTherapee. - * - * Copyright (c) 2004-2010 Gabor Horvath - * - * RawTherapee 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. - * - * RawTherapee 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 RawTherapee. If not, see . - */ -#ifndef _WINDIRMONITOR_ -#define _WINDIRMONITOR_ - -#include -#include - -class WinDirChangeListener -{ -public: - virtual ~WinDirChangeListener() = default; - - virtual void winDirChanged() = 0; -}; - -class WinDirMonitor : public Glib::Object -{ - -public: - struct MonitorData { - OVERLAPPED overlapped; - DWORD buffer_allocated_bytes; - char *file_notify_buffer; - DWORD buffer_filled_bytes; - HANDLE hDirectory; - WinDirChangeListener* listener; - int bigyo; - DWORD lastTimeUpdateTick; // for filtering multiple updates events - }; - -private: - MonitorData* monData; - -public: - WinDirMonitor (Glib::ustring dirName, WinDirChangeListener* listener); - ~WinDirMonitor (); -}; - -#endif -