* 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>
234 lines
6.3 KiB
C++
234 lines
6.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 <atomic>
|
|
#include <tuple>
|
|
#include <gtkmm.h>
|
|
|
|
#include "cursormanager.h"
|
|
#include "guiutils.h"
|
|
#include "lwbuttonset.h"
|
|
#include "threadutils.h"
|
|
#include "options.h"
|
|
#include "thumbnail.h"
|
|
|
|
#include "../rtengine/coord2d.h"
|
|
|
|
class Thumbnail;
|
|
class ThumbBrowserBase;
|
|
class ThumbBrowserEntryBase
|
|
{
|
|
|
|
public:
|
|
enum eWithFilename {
|
|
WFNAME_NONE,
|
|
WFNAME_REDUCED,
|
|
WFNAME_FULL
|
|
};
|
|
|
|
protected:
|
|
int fnlabw, fnlabh; // dimensions of the filename label
|
|
int dtlabw, dtlabh; // dimensions of the date/time label
|
|
int exlabw, exlabh; // dimensions of the exif label
|
|
int prew; // width of the thumbnail
|
|
int preh; // height of the thumbnail
|
|
int prex;
|
|
int prey;
|
|
|
|
int upperMargin;
|
|
int borderWidth;
|
|
int textGap;
|
|
int sideMargin;
|
|
int lowerMargin;
|
|
|
|
|
|
MyRWMutex lockRW; // Locks access to all image thumb changing actions
|
|
|
|
std::vector<guint8> preview; // holds the preview image. used in updateBackBuffer.
|
|
|
|
Glib::ustring dispname;
|
|
|
|
LWButtonSet* buttonSet;
|
|
|
|
int width; // minimal width
|
|
int height; // minimal height
|
|
// set by arrangeFiles() of thumbbrowser
|
|
int exp_width; // arranged width (backbuffer dimensions)
|
|
int exp_height; // arranged height
|
|
int startx; // x coord. in the widget
|
|
int starty; // y coord. in the widget
|
|
|
|
int ofsX, ofsY; // offset due to the scrolling of the parent
|
|
|
|
std::atomic<int> redrawRequests;
|
|
|
|
ThumbBrowserBase* parent;
|
|
ThumbBrowserEntryBase* original;
|
|
|
|
Glib::RefPtr<BackBuffer> backBuffer;
|
|
bool bbSelected, bbFramed;
|
|
guint8* bbPreview;
|
|
std::vector<Glib::RefPtr<Gdk::Pixbuf>> bbIcons;
|
|
std::vector<Glib::RefPtr<Gdk::Pixbuf>> bbSpecificityIcons;
|
|
CursorShape cursor_type;
|
|
|
|
void drawFrame (Cairo::RefPtr<Cairo::Context> cr, const Gdk::RGBA& bg, const Gdk::RGBA& fg);
|
|
void getTextSizes (int& w, int& h);
|
|
|
|
// called during updateBackBuffer for custom overlays
|
|
virtual void customBackBufferUpdate (Cairo::RefPtr<Cairo::Context> c) {}
|
|
|
|
private:
|
|
const std::string collate_name;
|
|
const std::string collate_exif;
|
|
|
|
public:
|
|
|
|
Thumbnail* thumbnail;
|
|
|
|
// thumbnail preview properties:
|
|
Glib::ustring filename;
|
|
Glib::ustring exifline;
|
|
Glib::ustring datetimeline;
|
|
|
|
// misc attributes
|
|
bool selected;
|
|
bool drawable;
|
|
bool filtered;
|
|
bool framed;
|
|
bool processing;
|
|
bool italicstyle;
|
|
bool edited;
|
|
bool recentlysaved;
|
|
bool updatepriority;
|
|
eWithFilename withFilename;
|
|
|
|
explicit ThumbBrowserEntryBase (const Glib::ustring& fname, Thumbnail *thm);
|
|
virtual ~ThumbBrowserEntryBase ();
|
|
|
|
void setParent (ThumbBrowserBase* l)
|
|
{
|
|
parent = l;
|
|
}
|
|
|
|
void updateBackBuffer ();
|
|
void resize (int h);
|
|
virtual void draw (Cairo::RefPtr<Cairo::Context> cc);
|
|
|
|
void addButtonSet (LWButtonSet* bs);
|
|
int getMinimalHeight () const
|
|
{
|
|
return height;
|
|
}
|
|
int getMinimalWidth () const
|
|
{
|
|
return width;
|
|
}
|
|
|
|
int getEffectiveWidth () const
|
|
{
|
|
return exp_width;
|
|
}
|
|
int getEffectiveHeight () const
|
|
{
|
|
return exp_height;
|
|
}
|
|
int getPreviewHeight () const
|
|
{
|
|
return preh;
|
|
}
|
|
int getStartX () const
|
|
{
|
|
return startx;
|
|
}
|
|
int getStartY () const
|
|
{
|
|
return starty;
|
|
}
|
|
int getX () const
|
|
{
|
|
return ofsX + startx;
|
|
}
|
|
int getY () const
|
|
{
|
|
return ofsY + starty;
|
|
}
|
|
|
|
bool inside (int x, int y) const;
|
|
rtengine::Coord2D getPosInImgSpace (int x, int y) const;
|
|
bool insideWindow (int x, int y, int w, int h) const;
|
|
void setPosition (int x, int y, int w, int h);
|
|
void setOffset (int x, int y);
|
|
|
|
bool compare (const ThumbBrowserEntryBase& other, Options::SortMethod method) const
|
|
{
|
|
int cmp = 0;
|
|
switch (method){
|
|
case Options::SORT_BY_NAME:
|
|
return collate_name < other.collate_name;
|
|
case Options::SORT_BY_DATE:
|
|
cmp = thumbnail->getDateTime().compare(other.thumbnail->getDateTime());
|
|
break;
|
|
case Options::SORT_BY_EXIF:
|
|
cmp = collate_exif.compare(other.collate_exif);
|
|
break;
|
|
case Options::SORT_BY_RANK:
|
|
cmp = thumbnail->getRank() - other.thumbnail->getRank();
|
|
break;
|
|
case Options::SORT_BY_LABEL:
|
|
cmp = thumbnail->getColorLabel() - other.thumbnail->getColorLabel();
|
|
break;
|
|
case Options::SORT_METHOD_COUNT: abort();
|
|
}
|
|
|
|
// Always fall back to sorting by name
|
|
if (!cmp)
|
|
cmp = collate_name.compare(other.collate_name);
|
|
|
|
return cmp < 0;
|
|
}
|
|
|
|
virtual void refreshThumbnailImage () = 0;
|
|
virtual void refreshQuickThumbnailImage () {}
|
|
virtual void calcThumbnailSize () = 0;
|
|
|
|
virtual void drawProgressBar (Glib::RefPtr<Gdk::Window> win, const Gdk::RGBA& foregr, const Gdk::RGBA& backgr, int x, int w, int y, int h) {}
|
|
|
|
virtual std::vector<Glib::RefPtr<Gdk::Pixbuf>> getIconsOnImageArea ();
|
|
virtual std::vector<Glib::RefPtr<Gdk::Pixbuf>> getSpecificityIconsOnImageArea ();
|
|
virtual void getIconSize (int& w, int& h) const = 0;
|
|
|
|
virtual bool motionNotify (int x, int y);
|
|
virtual bool pressNotify (int button, int type, int bstate, int x, int y);
|
|
virtual bool releaseNotify (int button, int type, int bstate, int x, int y);
|
|
virtual std::tuple<Glib::ustring, bool> getToolTip (int x, int y) const;
|
|
|
|
inline ThumbBrowserEntryBase* getOriginal() const
|
|
{
|
|
return original;
|
|
}
|
|
|
|
inline void setOriginal(ThumbBrowserEntryBase* original)
|
|
{
|
|
this->original = original;
|
|
}
|
|
|
|
};
|