Get rid of windirmonitor

This commit is contained in:
heckflosse 2018-12-02 20:29:11 +01:00
parent 35f37e55a7
commit 61c84b9ee7
7 changed files with 4 additions and 242 deletions

View File

@ -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}

View File

@ -246,16 +246,6 @@ int updateVolumesUI (void* br)
return 1;
}
void DirBrowser::winDirChanged ()
{
const auto func = [](gpointer data) -> gboolean {
static_cast<DirBrowser*>(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<WinDirMonitor> monitor = Glib::RefPtr<WinDirMonitor>(new WinDirMonitor (iter->get_value (dtColumns.dirname), this));
iter->set_value (dtColumns.monitor, monitor);
#else
Glib::RefPtr<Gio::FileMonitor> 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)

View File

@ -21,16 +21,13 @@
#include <gtkmm.h>
#include <giomm.h>
#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<void, const Glib::ustring&, const Glib::ustring&> DirSelectionSignal;
@ -45,11 +42,7 @@ private:
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > icon1;
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > icon2;
Gtk::TreeModelColumn<Glib::ustring> dirname;
#ifdef WIN32
Gtk::TreeModelColumn<Glib::RefPtr<WinDirMonitor> > monitor;
#else
Gtk::TreeModelColumn<Glib::RefPtr<Gio::FileMonitor> > 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

View File

@ -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<FileCatalog*>(data)->reparseDirectory();
return FALSE;
};
idle_register.add(func, this);
}
#else
void FileCatalog::on_dir_changed (const Glib::RefPtr<Gio::File>& file, const Glib::RefPtr<Gio::File>& other_file, Gio::FileMonitorEvent event_type, bool internal)
{
@ -1777,8 +1744,6 @@ void FileCatalog::on_dir_changed (const Glib::RefPtr<Gio::File>& file, const Gli
}
}
#endif
void FileCatalog::checkAndAddFile (Glib::RefPtr<Gio::File> file)
{

View File

@ -19,9 +19,6 @@
#ifndef _FILECATALOG_
#define _FILECATALOG_
#ifdef WIN32
#include "windirmonitor.h"
#endif
#include "filebrowser.h"
#include "exiffiltersettings.h"
#include <giomm.h>
@ -48,9 +45,6 @@ class FileCatalog : public Gtk::VBox,
public FilterPanelListener,
public FileBrowserListener,
public ExportPanelListener
#ifdef WIN32
, public WinDirChangeListener
#endif
{
public:
typedef sigc::slot<void, const Glib::ustring&> DirSelectionSlot;
@ -142,11 +136,7 @@ private:
std::set<Glib::ustring> editedFiles;
guint modifierKey; // any modifiers held when rank button was pressed
#ifndef _WIN32
Glib::RefPtr<Gio::FileMonitor> 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<Gio::File>& file, const Glib::RefPtr<Gio::File>& other_file, Gio::FileMonitorEvent event_type, bool internal);
#else
void winDirChanged ();
#endif
};

View File

@ -1,109 +0,0 @@
/*
* This file is part of RawTherapee.
*
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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);
}
}

View File

@ -1,57 +0,0 @@
/*
* This file is part of RawTherapee.
*
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _WINDIRMONITOR_
#define _WINDIRMONITOR_
#include <glibmm.h>
#include <windows.h>
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