Internal cleanup filebrowser threading; see issue #599

This commit is contained in:
Oliver Duis
2011-03-27 22:19:20 +02:00
parent 46183e33b3
commit 630da7d550
4 changed files with 126 additions and 3 deletions

View File

@@ -239,6 +239,12 @@ void FileBrowser::addEntry_ (FileBrowserEntry* entry) {
entry->resize (getCurrentThumbSize());
// find place in abc order
{
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
std::vector<ThumbBrowserEntryBase*>::iterator i = fd.begin();
while (i!=fd.end() && *entry < *((FileBrowserEntry*)*i))
i++;
@@ -246,10 +252,15 @@ void FileBrowser::addEntry_ (FileBrowserEntry* entry) {
fd.insert (i, entry);
initEntry (entry);
}
redraw ();
}
FileBrowserEntry* FileBrowser::delEntry (const Glib::ustring& fname) {
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
for (std::vector<ThumbBrowserEntryBase*>::iterator i=fd.begin(); i!=fd.end(); i++)
if ((*i)->filename==fname) {
@@ -270,6 +281,10 @@ FileBrowserEntry* FileBrowser::delEntry (const Glib::ustring& fname) {
}
FileBrowserEntry* FileBrowser::findEntry (const Glib::ustring& fname) {
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
for (std::vector<ThumbBrowserEntryBase*>::iterator i=fd.begin(); i!=fd.end(); i++)
if ((*i)->filename==fname)
@@ -288,12 +303,19 @@ void FileBrowser::close () {
fbih->destroyed = false;
fbih->pending = 0;
{
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
for (int i=0; i<fd.size(); i++)
{
delete fd[i];
}
fd.clear ();
selected.clear ();
}
notifySelectionListener ();
lastClicked = NULL;
}
@@ -332,12 +354,19 @@ void FileBrowser::menuItemActivated (Gtk::MenuItem* m) {
tbl->renameRequested (mselected);
else if (m==selall) {
lastClicked = NULL;
{
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
selected.clear ();
for (int i=0; i<fd.size(); i++)
if (checkFilter (fd[i])) {
fd[i]->selected = true;
selected.push_back (fd[i]);
}
}
queue_draw ();
notifySelectionListener ();
}
@@ -569,6 +598,12 @@ void FileBrowser::applyFilter (const BrowserFilter& filter) {
// remove items not complying the filter from the selection
bool selchanged = false;
numFiltered=0;
{
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
for (int i=0; i<fd.size(); i++)
if(checkFilter (fd[i]))
numFiltered++;
@@ -580,6 +615,8 @@ void FileBrowser::applyFilter (const BrowserFilter& filter) {
lastClicked = NULL;
selchanged = true;
}
}
if (selchanged)
notifySelectionListener ();
redraw ();
@@ -682,6 +719,10 @@ void FileBrowser::buttonPressed (LWButton* button, int actionCode, void* actionD
}
void FileBrowser::openNextImage () {
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
if (fd.size()>0) {
for (int i=fd.size()-1; i>=0; i--)
@@ -701,6 +742,10 @@ void FileBrowser::openNextImage () {
}
void FileBrowser::openPrevImage () {
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
if (fd.size()>0) {
for (int i=0; i<fd.size(); i++)

View File

@@ -54,6 +54,10 @@ ThumbBrowserBase::ThumbBrowserBase ()
}
void ThumbBrowserBase::scrollChanged () {
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
for (int i=0; i<fd.size(); i++)
fd[i]->setOffset ((int)(hscroll.get_value()), (int)(vscroll.get_value()));
@@ -133,6 +137,10 @@ void ThumbBrowserBase::configScrollBars () {
}
void ThumbBrowserBase::arrangeFiles () {
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
int N = fd.size ();
// apply filter
@@ -249,6 +257,10 @@ void ThumbBrowserBase::Internal::on_realize()
}
bool ThumbBrowserBase::Internal::on_query_tooltip (int x, int y, bool keyboard_tooltip, const Glib::RefPtr<Gtk::Tooltip>& tooltip) {
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(parent->entryMutex);
#endif
Glib::ustring ttip = "";
for (int i=0; i<parent->fd.size(); i++)
@@ -307,6 +319,12 @@ bool ThumbBrowserBase::Internal::on_button_press_event (GdkEventButton* event) {
void ThumbBrowserBase::buttonPressed (int x, int y, int button, GdkEventType type, int state, int clx, int cly, int clw, int clh) {
ThumbBrowserEntryBase* fileDescr = NULL;
bool handled = false;
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
for (int i=0; i<fd.size(); i++)
if (fd[i]->drawable) {
if (fd[i]->inside (x, y) && fd[i]->insideWindow (clx, cly, clw, clh))
@@ -409,6 +427,11 @@ bool ThumbBrowserBase::Internal::on_expose_event(GdkEventExpose* event) {
Glib::RefPtr<Gdk::Window> window = get_window();
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(parent->entryMutex);
#endif
int w = get_width();
int h = get_height();
@@ -430,6 +453,11 @@ bool ThumbBrowserBase::Internal::on_expose_event(GdkEventExpose* event) {
bool ThumbBrowserBase::Internal::on_button_release_event (GdkEventButton* event) {
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(parent->entryMutex);
#endif
int w = get_width();
int h = get_height();
@@ -440,6 +468,10 @@ bool ThumbBrowserBase::Internal::on_button_release_event (GdkEventButton* event)
}
bool ThumbBrowserBase::Internal::on_motion_notify_event (GdkEventMotion* event) {
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(parent->entryMutex);
#endif
int w = get_width();
int h = get_height();
@@ -483,8 +515,15 @@ void ThumbBrowserBase::zoomChanged (bool zoomIn) {
previewHeight = newHeight;
if (inTabMode) options.thumbSizeTab = newHeight; else options.thumbSize = newHeight;
for (int i=0; i<fd.size(); i++)
fd[i]->resize (previewHeight);
{
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
for (int i=0; i<fd.size(); i++) fd[i]->resize (previewHeight);
}
redraw ();
#ifdef _WIN32
gdk_window_process_updates (get_window()->gobj(), true);
@@ -494,6 +533,11 @@ void ThumbBrowserBase::zoomChanged (bool zoomIn) {
int ThumbBrowserBase::getCurrentThumbSize() { return inTabMode ? options.thumbSizeTab : options.thumbSize; }
void ThumbBrowserBase::refreshThumbImages () {
{
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
for (int i=0; i<fd.size(); i++){
previewHeight = getCurrentThumbSize();
@@ -501,11 +545,17 @@ void ThumbBrowserBase::refreshThumbImages () {
/* called if necessary by resize()
fd[i]->refreshThumbnailImage (); TODO: This might cause crashes on some installations */
}
}
redraw ();
}
void ThumbBrowserBase::refreshQuickThumbImages () {
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
for (int i=0; i<fd.size(); ++i){
fd[i]->refreshQuickThumbnailImage ();
}
@@ -514,8 +564,16 @@ void ThumbBrowserBase::refreshQuickThumbImages () {
void ThumbBrowserBase::refreshEditedState (const std::set<Glib::ustring>& efiles) {
editedFiles = efiles;
{
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
for (int i=0; i<fd.size(); i++)
fd[i]->framed = editedFiles.find (fd[i]->filename)!=editedFiles.end();
}
queue_draw ();
}
@@ -530,6 +588,11 @@ void ThumbBrowserBase::enableTabMode(bool enable) {
arrangement = inTabMode ? ThumbBrowserBase::TB_Horizontal : ThumbBrowserBase::TB_Vertical;
if (options.thumbSizeTab!=options.thumbSize) {
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
for (int i=0; i<fd.size(); i++)
fd[i]->resize (getCurrentThumbSize());
}
@@ -568,7 +631,15 @@ void ThumbBrowserBase::setScrollPosition (double h, double v) {
// needed for auto-height in single tab
int ThumbBrowserBase::getEffectiveHeight() {
int h=0;
{
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(entryMutex);
#endif
if (fd.size()>0) h=fd[0]->getEffectiveHeight();
}
return h;
}

View File

@@ -75,6 +75,8 @@ class ThumbBrowserBase : public Gtk::VBox {
int eventTime;
Glib::Mutex entryMutex; // Locks access to following vectors
std::vector<ThumbBrowserEntryBase*> fd;
std::vector<ThumbBrowserEntryBase*> selected;
ThumbBrowserEntryBase* lastClicked;

View File

@@ -276,8 +276,13 @@ void Thumbnail::decreaseRef ()
}
void Thumbnail::getThumbnailSize (int &w, int &h) {
// TODO: Check for Linux
#ifdef WIN32
Glib::Mutex::Lock lock(mutex);
#endif
w=0;
if (tpp) w = tpp->getImageWidth (getProcParams(), h); // this might return 0 if image was just building
if (!initial_ && tpp) w = tpp->getImageWidth (getProcParams(), h); // this might return 0 if image was just building
if (w==0) w = tw * h / th;
}