* Use mtime as fallback timestamp for files without EXIF data As suggested in #6449, with date-based sorting it can be useful to have at least *some* sort of time-relevant information for EXIF-less files, to prevent them from falling back to getting sorted alphabetically all the time. This commit simply defaults the file timestamp to the file's mtime as returned by g_stat. For annoying reasons, it doesn't suffice to merely forward the timestamp to the FileData structs - we also need to keep track of it inside FilesData to cover the case of a file with 0 frames in it. * Add DateTime to Thumbnail Putting it here facilitate easier sorting without having to re-construct the DateTime on every comparison. To simplify things moving forwards, use the Glib::DateTime struct right away. This struct also contains timezone information, but we don't currently care about timezone - so just use the local timezone as the best approximation. (Nothing currently depends on getting the timezone right, anyway) In addition to the above, this commit also changes the logic to allow generating datetime strings even for files with missing EXIF (which makes sense as a result of the previous commit allowing the use of mtime instead). * Implement file sorting in thumbnail view For simplicity, I decided to only implement the attributes that I could verily easily reach from the existing metadata exported by Thumbnail. Ideally, I would also like to be able to sort by "last modified" but I'm not sure of the best way to reach this from this place in the code. It's worth pointing out that, with the current implementation, the list will not dynamically re-sort itself until you re-select the sorting method - even if you make changes to the files that would otherwise affect the sorting (e.g. changing the rank while sorting by rank). One might even call this a feature, not a bug, since it prevents thumbnails from moving around while you're trying to re-label them. You can always re-select "sort by ..." from the context menu to force a re-sort. Fixes #3317 Co-authored-by: Thanatomanic <6567747+Thanatomanic@users.noreply.github.com>
262 lines
7.3 KiB
C++
262 lines
7.3 KiB
C++
/*
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
*/
|
|
#pragma once
|
|
|
|
#include <set>
|
|
|
|
#include <gtkmm.h>
|
|
|
|
#include "guiutils.h"
|
|
#include "options.h"
|
|
|
|
/*
|
|
* Class handling the list of ThumbBrowserEntry objects and their position in it's allocated space
|
|
*/
|
|
|
|
class Inspector;
|
|
class ThumbBrowserEntryBase;
|
|
|
|
class ThumbBrowserBase :
|
|
public Gtk::Grid
|
|
{
|
|
|
|
class Internal :
|
|
public Gtk::DrawingArea
|
|
{
|
|
//Cairo::RefPtr<Cairo::Context> cc;
|
|
int ofsX, ofsY;
|
|
ThumbBrowserBase* parent;
|
|
bool dirty;
|
|
|
|
// caching some very often used values
|
|
Glib::RefPtr<Gtk::StyleContext> style;
|
|
Gdk::RGBA textn;
|
|
Gdk::RGBA texts;
|
|
Gdk::RGBA bgn;
|
|
Gdk::RGBA bgs;
|
|
|
|
public:
|
|
Internal ();
|
|
void setParent (ThumbBrowserBase* p);
|
|
void on_realize() override;
|
|
void on_style_updated() override;
|
|
bool on_configure_event(GdkEventConfigure *configure_event) override;
|
|
bool on_draw(const ::Cairo::RefPtr< Cairo::Context> &cr) override;
|
|
|
|
Gtk::SizeRequestMode get_request_mode_vfunc () const override;
|
|
void get_preferred_height_vfunc (int &minimum_height, int &natural_height) const final;
|
|
void get_preferred_width_vfunc (int &minimum_width, int &natural_width) const final;
|
|
void get_preferred_height_for_width_vfunc (int width, int &minimum_height, int &natural_height) const final;
|
|
void get_preferred_width_for_height_vfunc (int height, int &minimum_width, int &natural_width) const final;
|
|
|
|
bool on_button_press_event (GdkEventButton* event) override;
|
|
bool on_button_release_event (GdkEventButton* event) override;
|
|
bool on_motion_notify_event (GdkEventMotion* event) override;
|
|
bool on_scroll_event (GdkEventScroll* event) override;
|
|
bool on_key_press_event (GdkEventKey* event) override;
|
|
bool on_query_tooltip (int x, int y, bool keyboard_tooltip, const Glib::RefPtr<Gtk::Tooltip>& tooltip);
|
|
void setPosition (int x, int y);
|
|
|
|
Glib::RefPtr<Gtk::StyleContext> getStyle() {
|
|
return style;
|
|
}
|
|
Gdk::RGBA getNormalTextColor() {
|
|
return textn;
|
|
}
|
|
Gdk::RGBA getSelectedTextColor() {
|
|
return texts;
|
|
}
|
|
Gdk::RGBA getNormalBgColor() {
|
|
return bgn;
|
|
}
|
|
Gdk::RGBA getSelectedBgColor() {
|
|
return bgs;
|
|
}
|
|
|
|
void setDirty ()
|
|
{
|
|
dirty = true;
|
|
}
|
|
bool isDirty ()
|
|
{
|
|
return dirty;
|
|
}
|
|
};
|
|
|
|
public:
|
|
|
|
enum eLocation {
|
|
THLOC_BATCHQUEUE,
|
|
THLOC_FILEBROWSER,
|
|
THLOC_EDITOR
|
|
} location;
|
|
|
|
protected:
|
|
virtual int getMaxThumbnailHeight() const
|
|
{
|
|
return options.maxThumbnailHeight; // Differs between batch and file
|
|
}
|
|
virtual void saveThumbnailHeight (int height) = 0;
|
|
virtual int getThumbnailHeight () = 0;
|
|
|
|
Internal internal;
|
|
Gtk::Scrollbar hscroll;
|
|
Gtk::Scrollbar vscroll;
|
|
|
|
int inW, inH;
|
|
|
|
Inspector *inspector;
|
|
bool isInspectorActive;
|
|
|
|
|
|
void resizeThumbnailArea (int w, int h);
|
|
void internalAreaResized (Gtk::Allocation& req);
|
|
void buttonPressed (int x, int y, int button, GdkEventType type, int state, int clx, int cly, int clw, int clh);
|
|
|
|
public:
|
|
|
|
void setInspector(Inspector* inspector)
|
|
{
|
|
this->inspector = inspector;
|
|
}
|
|
Inspector* getInspector()
|
|
{
|
|
return inspector;
|
|
}
|
|
void disableInspector();
|
|
void enableInspector();
|
|
enum Arrangement {TB_Horizontal, TB_Vertical};
|
|
void configScrollBars ();
|
|
void scrollChanged ();
|
|
void scroll (int direction, double deltaX=0.0, double deltaY=0.0);
|
|
void scrollPage (int direction);
|
|
|
|
private:
|
|
void selectSingle (ThumbBrowserEntryBase* clicked);
|
|
void selectRange (ThumbBrowserEntryBase* clicked, bool additional);
|
|
void selectSet (ThumbBrowserEntryBase* clicked);
|
|
|
|
public:
|
|
void selectPrev (int distance, bool enlarge);
|
|
void selectNext (int distance, bool enlarge);
|
|
void selectFirst (bool enlarge);
|
|
void selectLast (bool enlarge);
|
|
|
|
virtual bool isInTabMode()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
eLocation getLocation()
|
|
{
|
|
return location;
|
|
}
|
|
|
|
protected:
|
|
|
|
int eventTime;
|
|
|
|
MyRWMutex entryRW; // Locks access to following 'fd' AND 'selected'
|
|
std::vector<ThumbBrowserEntryBase*> fd;
|
|
std::vector<ThumbBrowserEntryBase*> selected;
|
|
ThumbBrowserEntryBase* lastClicked;
|
|
ThumbBrowserEntryBase* anchor;
|
|
|
|
int previewHeight;
|
|
int numOfCols;
|
|
int lastRowHeight;
|
|
|
|
Arrangement arrangement;
|
|
|
|
std::set<Glib::ustring> editedFiles;
|
|
|
|
void arrangeFiles (ThumbBrowserEntryBase* entry = nullptr);
|
|
void zoomChanged (bool zoomIn);
|
|
|
|
public:
|
|
|
|
ThumbBrowserBase ();
|
|
|
|
void zoomIn ()
|
|
{
|
|
zoomChanged (true);
|
|
}
|
|
void zoomOut ()
|
|
{
|
|
zoomChanged (false);
|
|
}
|
|
int getEffectiveHeight ();
|
|
|
|
const std::vector<ThumbBrowserEntryBase*>& getEntries ()
|
|
{
|
|
return fd;
|
|
}
|
|
void on_style_updated () override;
|
|
void resort (); // re-apply sort method
|
|
void redraw (ThumbBrowserEntryBase* entry = nullptr); // arrange files and draw area
|
|
void refreshThumbImages (); // refresh thumbnail sizes, re-generate thumbnail images, arrange and draw
|
|
void refreshQuickThumbImages (); // refresh thumbnail sizes, re-generate thumbnail images, arrange and draw
|
|
void refreshEditedState (const std::set<Glib::ustring>& efiles);
|
|
|
|
void insertEntry (ThumbBrowserEntryBase* entry);
|
|
|
|
void getScrollPosition (double& h, double& v);
|
|
void setScrollPosition (double h, double v);
|
|
|
|
void setArrangement (Arrangement a);
|
|
void enableTabMode(bool enable); // set both thumb sizes and arrangements
|
|
|
|
virtual bool checkFilter (ThumbBrowserEntryBase* entry) const
|
|
{
|
|
return true;
|
|
}
|
|
virtual void rightClicked () = 0;
|
|
virtual void doubleClicked (ThumbBrowserEntryBase* entry) {}
|
|
virtual bool keyPressed (GdkEventKey* event)
|
|
{
|
|
return true;
|
|
}
|
|
virtual void selectionChanged () {}
|
|
|
|
virtual void redrawNeeded (ThumbBrowserEntryBase* entry);
|
|
virtual void thumbRearrangementNeeded () {}
|
|
|
|
Gtk::Widget* getDrawingArea ()
|
|
{
|
|
return &internal;
|
|
}
|
|
|
|
Glib::RefPtr<Gtk::StyleContext> getStyle() {
|
|
return internal.getStyle();
|
|
}
|
|
Gdk::RGBA getNormalTextColor() {
|
|
return internal.getNormalTextColor();
|
|
}
|
|
Gdk::RGBA getSelectedTextColor() {
|
|
return internal.getSelectedTextColor();
|
|
}
|
|
Gdk::RGBA getNormalBgColor() {
|
|
return internal.getNormalBgColor();
|
|
}
|
|
Gdk::RGBA getSelectedBgColor() {
|
|
return internal.getSelectedBgColor();
|
|
}
|
|
|
|
};
|