From 87016d353a48916f982780a762d42c1215314cda Mon Sep 17 00:00:00 2001 From: Adam Reichold Date: Sat, 5 Dec 2015 11:25:23 +0100 Subject: [PATCH 1/2] Replace the DirSelectionListener interface using a typedef'ed signal to increase simplicity and reduce boiler plate. --- rtgui/dirbrowser.cc | 8 ++------ rtgui/dirbrowser.h | 17 ++++++++++------- rtgui/dirselectionlistener.h | 32 -------------------------------- rtgui/filecatalog.h | 4 +--- rtgui/filepanel.cc | 9 +++++---- rtgui/placesbrowser.h | 5 ++--- rtgui/recentbrowser.h | 5 ++--- rtgui/toolpanelcoord.h | 4 +--- 8 files changed, 23 insertions(+), 61 deletions(-) delete mode 100644 rtgui/dirselectionlistener.h diff --git a/rtgui/dirbrowser.cc b/rtgui/dirbrowser.cc index 914b74ef5..b79bb2c0f 100644 --- a/rtgui/dirbrowser.cc +++ b/rtgui/dirbrowser.cc @@ -347,9 +347,7 @@ void DirBrowser::row_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewC Glib::ustring dname = dirTreeModel->get_iter (path)->get_value (dtColumns.dirname); if (safe_file_test (dname, Glib::FILE_TEST_IS_DIR)) - for (size_t i = 0; i < dllisteners.size(); i++) { - dllisteners[i]->dirSelected (dname); - } + dirSelectionSignal (dname, Glib::ustring()); } Gtk::TreePath DirBrowser::expandToDir (const Glib::ustring& absDirPath) @@ -439,9 +437,7 @@ void DirBrowser::open (const Glib::ustring& dirname, const Glib::ustring& fileNa absFilePath = Glib::build_filename (absDirPath, fileName); } - for (size_t i = 0; i < dllisteners.size(); i++) { - dllisteners[i]->dirSelected (absDirPath, absFilePath); - } + dirSelectionSignal (absDirPath, absFilePath); } void DirBrowser::file_changed (const Glib::RefPtr& file, const Glib::RefPtr& other_file, Gio::FileMonitorEvent event_type, const Gtk::TreeModel::iterator& iter, const Glib::ustring& dirName) diff --git a/rtgui/dirbrowser.h b/rtgui/dirbrowser.h index fcba64ce0..c60673d7b 100644 --- a/rtgui/dirbrowser.h +++ b/rtgui/dirbrowser.h @@ -24,7 +24,6 @@ #ifdef WIN32 #include "windirmonitor.h" #endif -#include "dirselectionlistener.h" #include "dirbrowserremoteinterface.h" class DirBrowser : public Gtk::VBox, public DirBrowserRemoteInterface @@ -32,6 +31,8 @@ class DirBrowser : public Gtk::VBox, public DirBrowserRemoteInterface , public WinDirChangeListener #endif { +public: + typedef sigc::signal DirSelectionSignal; private: @@ -67,7 +68,7 @@ private: Gtk::TreeView *dirtree; Gtk::ScrolledWindow *scrolledwindow4; - std::vector dllisteners; + DirSelectionSignal dirSelectionSignal; void fillRoot (); @@ -94,7 +95,6 @@ private: void addDir (const Gtk::TreeModel::iterator& iter, const Glib::ustring& dirname); Gtk::TreePath expandToDir (const Glib::ustring& dirName); void updateDir (const Gtk::TreeModel::iterator& iter); - void notifyListeners (); public: DirBrowser (); @@ -105,11 +105,14 @@ public: void row_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); void file_changed (const Glib::RefPtr& file, const Glib::RefPtr& other_file, Gio::FileMonitorEvent event_type, const Gtk::TreeModel::iterator& iter, const Glib::ustring& dirName); void open (const Glib::ustring& dirName, const Glib::ustring& fileName = ""); // goes to dir "dirName" and selects file "fileName" - void addDirSelectionListener (DirSelectionListener* l) - { - dllisteners.push_back (l); - } void selectDir (Glib::ustring dir); + + DirSelectionSignal dirSelected () const; }; +inline DirBrowser::DirSelectionSignal DirBrowser::dirSelected () const +{ + return dirSelectionSignal; +} + #endif diff --git a/rtgui/dirselectionlistener.h b/rtgui/dirselectionlistener.h deleted file mode 100644 index 3225487cb..000000000 --- a/rtgui/dirselectionlistener.h +++ /dev/null @@ -1,32 +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 _DIRSELECTIONLISTENER_ -#define _DIRSELECTIONLISTENER_ - -#include - -class DirSelectionListener -{ - -public: - virtual ~DirSelectionListener () {} - virtual void dirSelected (const Glib::ustring& dirname, const Glib::ustring& openfile = "") {} -}; - -#endif diff --git a/rtgui/filecatalog.h b/rtgui/filecatalog.h index b30ebb553..16d5460e1 100644 --- a/rtgui/filecatalog.h +++ b/rtgui/filecatalog.h @@ -23,7 +23,6 @@ #include "windirmonitor.h" #endif #include "dirbrowserremoteinterface.h" -#include "dirselectionlistener.h" #include "filebrowser.h" #include "exiffiltersettings.h" #include @@ -60,7 +59,6 @@ class FilePanel; * - monitoring the directory (for any change) */ class FileCatalog : public Gtk::VBox, - public DirSelectionListener, public PreviewLoaderListener, public FilterPanelListener, public FileBrowserListener, @@ -175,7 +173,7 @@ public: FileCatalog (CoarsePanel* cp, ToolBar* tb, FilePanel* filepanel); ~FileCatalog(); - void dirSelected (const Glib::ustring& dirname, const Glib::ustring& openfile = ""); + void dirSelected (const Glib::ustring& dirname, const Glib::ustring& openfile); void closeDir (); void refreshEditedState (const std::set& efiles); diff --git a/rtgui/filepanel.cc b/rtgui/filepanel.cc index 5be2ab0df..5a7d7ef78 100644 --- a/rtgui/filepanel.cc +++ b/rtgui/filepanel.cc @@ -61,10 +61,11 @@ FilePanel::FilePanel () : parent(NULL) placesBrowser->setDirBrowserRemoteInterface (dirBrowser); recentBrowser->setDirBrowserRemoteInterface (dirBrowser); - dirBrowser->addDirSelectionListener (fileCatalog); - dirBrowser->addDirSelectionListener (recentBrowser); - dirBrowser->addDirSelectionListener (placesBrowser); - dirBrowser->addDirSelectionListener (tpc); + DirBrowser::DirSelectionSignal dirSelected = dirBrowser->dirSelected (); + dirSelected.connect (sigc::mem_fun (fileCatalog, &FileCatalog::dirSelected)); + dirSelected.connect (sigc::mem_fun (recentBrowser, &RecentBrowser::dirSelected)); + dirSelected.connect (sigc::mem_fun (placesBrowser, &PlacesBrowser::dirSelected)); + dirSelected.connect (sigc::mem_fun (tpc, &BatchToolPanelCoordinator::dirSelected)); fileCatalog->setFileSelectionListener (this); fileCatalog->setDirBrowserRemoteInterface (dirBrowser); diff --git a/rtgui/placesbrowser.h b/rtgui/placesbrowser.h index e8c443345..b3746b74e 100644 --- a/rtgui/placesbrowser.h +++ b/rtgui/placesbrowser.h @@ -22,10 +22,9 @@ #include #include #include "dirbrowserremoteinterface.h" -#include "dirselectionlistener.h" #include "multilangmgr.h" -class PlacesBrowser : public Gtk::VBox, public DirSelectionListener +class PlacesBrowser : public Gtk::VBox { class PlacesColumns : public Gtk::TreeModel::ColumnRecord @@ -63,7 +62,7 @@ public: { listener = l; } - void dirSelected (const Glib::ustring& dirname, const Glib::ustring& openfile = ""); + void dirSelected (const Glib::ustring& dirname, const Glib::ustring& openfile); void refreshPlacesList (); void mountChanged (const Glib::RefPtr& m); diff --git a/rtgui/recentbrowser.h b/rtgui/recentbrowser.h index 511207fa4..c42fe4773 100644 --- a/rtgui/recentbrowser.h +++ b/rtgui/recentbrowser.h @@ -21,11 +21,10 @@ #include #include "dirbrowserremoteinterface.h" -#include "dirselectionlistener.h" #include "multilangmgr.h" #include "guiutils.h" -class RecentBrowser : public Gtk::VBox, public DirSelectionListener +class RecentBrowser : public Gtk::VBox { Gtk::ComboBoxText* recentDirs; @@ -42,7 +41,7 @@ public: } void selectionChanged (); - void dirSelected (const Glib::ustring& dirname, const Glib::ustring& openfile = ""); + void dirSelected (const Glib::ustring& dirname, const Glib::ustring& openfile); }; #endif diff --git a/rtgui/toolpanelcoord.h b/rtgui/toolpanelcoord.h index 44073344b..46285ce3e 100644 --- a/rtgui/toolpanelcoord.h +++ b/rtgui/toolpanelcoord.h @@ -57,7 +57,6 @@ #include "toolbar.h" #include "lensgeom.h" #include "lensgeomlistener.h" -#include "dirselectionlistener.h" #include "wavelet.h" #include "dirpyrequalizer.h" #include "hsvequalizer.h" @@ -93,7 +92,6 @@ class ToolPanelCoordinator : public ToolPanelListener, public SpotWBListener, public CropPanelListener, public ICMPanelListener, - public DirSelectionListener, public ImageAreaToolListener { @@ -236,7 +234,7 @@ public: void setDefaults (rtengine::procparams::ProcParams* defparams); // DirSelectionListener interface - void dirSelected (const Glib::ustring& dirname, const Glib::ustring& openfile = ""); + void dirSelected (const Glib::ustring& dirname, const Glib::ustring& openfile); // to support the GUI: CropGUIListener* getCropGUIListener (); // through the CropGUIListener the editor area can notify the "crop" ToolPanel when the crop selection changes From 4f68e370d47d8c0be27099ed93e80b320735f8cd Mon Sep 17 00:00:00 2001 From: Adam Reichold Date: Sat, 5 Dec 2015 11:45:15 +0100 Subject: [PATCH 2/2] Replace the DirBrowserRemoteInterface by slots to reduce coupling by using ad-hoc yet type-safe collaborations. --- rtgui/dirbrowser.h | 3 +-- rtgui/dirbrowserremoteinterface.h | 32 ------------------------------- rtgui/filecatalog.cc | 5 ++--- rtgui/filecatalog.h | 15 +++++++++------ rtgui/filepanel.cc | 6 +++--- rtgui/placesbrowser.cc | 6 +++--- rtgui/placesbrowser.h | 17 ++++++++++------ rtgui/recentbrowser.cc | 6 +++--- rtgui/recentbrowser.h | 16 ++++++++++------ 9 files changed, 42 insertions(+), 64 deletions(-) delete mode 100644 rtgui/dirbrowserremoteinterface.h diff --git a/rtgui/dirbrowser.h b/rtgui/dirbrowser.h index c60673d7b..850a9fa78 100644 --- a/rtgui/dirbrowser.h +++ b/rtgui/dirbrowser.h @@ -24,9 +24,8 @@ #ifdef WIN32 #include "windirmonitor.h" #endif -#include "dirbrowserremoteinterface.h" -class DirBrowser : public Gtk::VBox, public DirBrowserRemoteInterface +class DirBrowser : public Gtk::VBox #ifdef WIN32 , public WinDirChangeListener #endif diff --git a/rtgui/dirbrowserremoteinterface.h b/rtgui/dirbrowserremoteinterface.h deleted file mode 100644 index dda78bc47..000000000 --- a/rtgui/dirbrowserremoteinterface.h +++ /dev/null @@ -1,32 +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 _DIRBROWSERREMOTEINTERFACE_ -#define _DIRBROWSERREMOTEINTERFACE_ - -#include - -class DirBrowserRemoteInterface -{ - -public: - virtual void selectDir (Glib::ustring dir) {} -}; - -#endif - diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 915f0d84e..8b9f299d8 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -43,7 +43,6 @@ FileCatalog::FileCatalog (CoarsePanel* cp, ToolBar* tb, FilePanel* filepanel) : selectedDirectoryId(1), listener(NULL), fslistener(NULL), - dirlistener(NULL), hasValidCurrentEFS(false), filterPanel(NULL), previewsToLoad(0), @@ -2042,8 +2041,8 @@ void FileCatalog::buttonBrowsePathPressed () // handle shortcuts in the BrowsePath -- END // validate the path - if (safe_file_test(BrowsePathValue, Glib::FILE_TEST_IS_DIR) && dirlistener) { - dirlistener->selectDir (BrowsePathValue); + if (safe_file_test(BrowsePathValue, Glib::FILE_TEST_IS_DIR) && selectDir) { + selectDir (BrowsePathValue); } else // error, likely path not found: show red arrow { diff --git a/rtgui/filecatalog.h b/rtgui/filecatalog.h index 16d5460e1..b7ea1802f 100644 --- a/rtgui/filecatalog.h +++ b/rtgui/filecatalog.h @@ -22,7 +22,6 @@ #ifdef WIN32 #include "windirmonitor.h" #endif -#include "dirbrowserremoteinterface.h" #include "filebrowser.h" #include "exiffiltersettings.h" #include @@ -67,6 +66,8 @@ class FileCatalog : public Gtk::VBox, , public WinDirChangeListener #endif { +public: + typedef sigc::slot DirSelectionSlot; private: FilePanel* filepanel; @@ -82,7 +83,7 @@ private: FileSelectionListener* listener; FileSelectionChangeListener* fslistener; ImageAreaToolListener* iatlistener; - DirBrowserRemoteInterface* dirlistener; + DirSelectionSlot selectDir; Gtk::HBox* buttonBar; Gtk::HBox* hbToolBar1; @@ -242,10 +243,7 @@ public: { iatlistener = l; } - void setDirBrowserRemoteInterface (DirBrowserRemoteInterface* l) - { - dirlistener = l; - } + void setDirSelector (const DirSelectionSlot& selectDir); void setFilterPanel (FilterPanel* fpanel); void setExportPanel (ExportPanel* expanel); @@ -310,4 +308,9 @@ public: }; +inline void FileCatalog::setDirSelector (const FileCatalog::DirSelectionSlot& selectDir) +{ + this->selectDir = selectDir; +} + #endif diff --git a/rtgui/filepanel.cc b/rtgui/filepanel.cc index 5a7d7ef78..0069a6dbd 100644 --- a/rtgui/filepanel.cc +++ b/rtgui/filepanel.cc @@ -59,15 +59,15 @@ FilePanel::FilePanel () : parent(NULL) ribbonPane->set_size_request(50, 150); dirpaned->pack2 (*ribbonPane, true, true); - placesBrowser->setDirBrowserRemoteInterface (dirBrowser); - recentBrowser->setDirBrowserRemoteInterface (dirBrowser); DirBrowser::DirSelectionSignal dirSelected = dirBrowser->dirSelected (); dirSelected.connect (sigc::mem_fun (fileCatalog, &FileCatalog::dirSelected)); dirSelected.connect (sigc::mem_fun (recentBrowser, &RecentBrowser::dirSelected)); dirSelected.connect (sigc::mem_fun (placesBrowser, &PlacesBrowser::dirSelected)); dirSelected.connect (sigc::mem_fun (tpc, &BatchToolPanelCoordinator::dirSelected)); + fileCatalog->setDirSelector (sigc::mem_fun (dirBrowser, &DirBrowser::selectDir)); + placesBrowser->setDirSelector (sigc::mem_fun (dirBrowser, &DirBrowser::selectDir)); + recentBrowser->setDirSelector (sigc::mem_fun (dirBrowser, &DirBrowser::selectDir)); fileCatalog->setFileSelectionListener (this); - fileCatalog->setDirBrowserRemoteInterface (dirBrowser); rightBox = Gtk::manage ( new Gtk::HBox () ); rightBox->set_size_request(50, 100); diff --git a/rtgui/placesbrowser.cc b/rtgui/placesbrowser.cc index 6edb3b471..bb92fab0d 100644 --- a/rtgui/placesbrowser.cc +++ b/rtgui/placesbrowser.cc @@ -23,7 +23,7 @@ #include "guiutils.h" #include "rtimage.h" -PlacesBrowser::PlacesBrowser () : listener (NULL) +PlacesBrowser::PlacesBrowser () { scrollw = Gtk::manage (new Gtk::ScrolledWindow ()); @@ -286,8 +286,8 @@ void PlacesBrowser::selectionChanged () drives[i]->poll_for_media (); break; } - } else if (listener) { - listener->selectDir (iter->get_value (placesColumns.root)); + } else if (selectDir) { + selectDir (iter->get_value (placesColumns.root)); } } } diff --git a/rtgui/placesbrowser.h b/rtgui/placesbrowser.h index b3746b74e..b9d74648b 100644 --- a/rtgui/placesbrowser.h +++ b/rtgui/placesbrowser.h @@ -21,11 +21,14 @@ #include #include -#include "dirbrowserremoteinterface.h" #include "multilangmgr.h" class PlacesBrowser : public Gtk::VBox { +public: + typedef sigc::slot DirSelectionSlot; + +private: class PlacesColumns : public Gtk::TreeModel::ColumnRecord { @@ -49,7 +52,7 @@ class PlacesBrowser : public Gtk::VBox Gtk::TreeView* treeView; Glib::RefPtr placesModel; Glib::RefPtr vm; - DirBrowserRemoteInterface* listener; + DirSelectionSlot selectDir; Glib::ustring lastSelectedDir; Gtk::Button* add; Gtk::Button* del; @@ -58,10 +61,7 @@ public: PlacesBrowser (); - void setDirBrowserRemoteInterface (DirBrowserRemoteInterface* l) - { - listener = l; - } + void setDirSelector (const DirSelectionSlot& selectDir); void dirSelected (const Glib::ustring& dirname, const Glib::ustring& openfile); void refreshPlacesList (); @@ -74,6 +74,11 @@ public: void delPressed (); }; +inline void PlacesBrowser::setDirSelector (const PlacesBrowser::DirSelectionSlot& selectDir) +{ + this->selectDir = selectDir; +} + #endif diff --git a/rtgui/recentbrowser.cc b/rtgui/recentbrowser.cc index 80d56de4d..1d559a9cd 100644 --- a/rtgui/recentbrowser.cc +++ b/rtgui/recentbrowser.cc @@ -22,7 +22,7 @@ using namespace rtengine; -RecentBrowser::RecentBrowser () : listener (NULL) +RecentBrowser::RecentBrowser () { recentDirs = Gtk::manage (new MyComboBoxText ()); @@ -46,8 +46,8 @@ void RecentBrowser::selectionChanged () Glib::ustring sel = recentDirs->get_active_text (); - if (sel != "" && listener) { - listener->selectDir (sel); + if (!sel.empty() && selectDir) { + selectDir (sel); } } diff --git a/rtgui/recentbrowser.h b/rtgui/recentbrowser.h index c42fe4773..2d1e210f4 100644 --- a/rtgui/recentbrowser.h +++ b/rtgui/recentbrowser.h @@ -20,30 +20,34 @@ #define _RECENTBROWSER_ #include -#include "dirbrowserremoteinterface.h" #include "multilangmgr.h" #include "guiutils.h" class RecentBrowser : public Gtk::VBox { +public: + typedef sigc::slot DirSelectionSlot; +private: Gtk::ComboBoxText* recentDirs; sigc::connection conn; - DirBrowserRemoteInterface* listener; + DirSelectionSlot selectDir; public: RecentBrowser (); - void setDirBrowserRemoteInterface (DirBrowserRemoteInterface* l) - { - listener = l; - } + void setDirSelector (const DirSelectionSlot& selectDir); void selectionChanged (); void dirSelected (const Glib::ustring& dirname, const Glib::ustring& openfile); }; +inline void RecentBrowser::setDirSelector (const RecentBrowser::DirSelectionSlot& selectDir) +{ + this->selectDir = selectDir; +} + #endif