rawTherapee/rtgui/thumbnail.h
Niklas Haas 2101b846c3
Implement file sorting in thumbnail view (#6449)
* 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>
2023-01-02 21:27:12 +01:00

168 lines
6.7 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 <memory>
#include <string>
#include <glibmm/ustring.h>
#include <glibmm/datetime.h>
#include "cacheimagedata.h"
#include "threadutils.h"
#include "thumbnaillistener.h"
namespace rtengine
{
class Thumbnail;
namespace procparams
{
class ProcParams;
}
}
class CacheManager;
struct ParamsEdited;
class Thumbnail
{
MyMutex mutex;
Glib::ustring fname; // file name corresponding to the thumbnail
CacheImageData cfs; // cache entry corresponding to the thumbnail
CacheManager* cachemgr; // parent
int ref; // variable for reference counting
int enqueueNumber; // the number of instances in the batch queue corresponding to this thumbnail
// if the thumbnail is in processed mode, this class holds its data:
rtengine::Thumbnail* tpp;
int tw, th; // dimensions of timgdata (it stores tpp->width and tpp->height in processed mode for simplicity)
float imgRatio; // hack to avoid rounding error
// double scale; // portion of the sizes of the processed thumbnail image and the full scale image
const std::unique_ptr<rtengine::procparams::ProcParams> pparams;
bool pparamsValid;
bool imageLoading;
// these are the data of the result image of the last getthumbnailimage call (for caching purposes)
unsigned char* lastImg; // pointer to the processed and scaled base ImageIO image
int lastW; // non rotated width of the cached ImageIO image
int lastH; // non rotated height of the cached ImageIO image
double lastScale; // scale of the cached ImageIO image
// exif & date/time strings
Glib::ustring exifString;
Glib::ustring dateTimeString;
Glib::DateTime dateTime;
bool initial_;
// vector of listeners
std::vector<ThumbnailListener*> listeners;
void _loadThumbnail (bool firstTrial = true);
void _saveThumbnail ();
void _generateThumbnailImage ();
int infoFromImage (const Glib::ustring& fname, std::unique_ptr<rtengine::RawMetaDataLocation> rml = nullptr);
void generateExifDateTimeStrings ();
Glib::ustring getCacheFileName (const Glib::ustring& subdir, const Glib::ustring& fext) const;
public:
Thumbnail (CacheManager* cm, const Glib::ustring& fname, CacheImageData* cf);
Thumbnail (CacheManager* cm, const Glib::ustring& fname, const std::string& md5);
~Thumbnail ();
bool hasProcParams () const;
const rtengine::procparams::ProcParams& getProcParams ();
const rtengine::procparams::ProcParams& getProcParamsU (); // Unprotected version
// Use this to create params on demand for update ; if flaggingMode=true, the procparams is created for a file being flagged (inTrash, rank, colorLabel)
rtengine::procparams::ProcParams* createProcParamsForUpdate (bool returnParams, bool force, bool flaggingMode = false);
void setProcParams (const rtengine::procparams::ProcParams& pp, ParamsEdited* pe = nullptr, int whoChangedIt = -1, bool updateCacheNow = true, bool resetToDefault = false);
void clearProcParams (int whoClearedIt = -1);
void loadProcParams ();
void notifylisterners_procParamsChanged(int whoChangedIt);
bool isQuick() const;
bool isPParamsValid() const;
bool isRecentlySaved () const;
void imageDeveloped ();
void imageEnqueued ();
void imageRemovedFromQueue ();
bool isEnqueued () const;
bool isPixelShift () const;
bool isHDR () const;
// unsigned char* getThumbnailImage (int &w, int &h, int fixwh=1); // fixwh = 0: fix w and calculate h, =1: fix h and calculate w
rtengine::IImage8* processThumbImage (const rtengine::procparams::ProcParams& pparams, int h, double& scale);
rtengine::IImage8* upgradeThumbImage (const rtengine::procparams::ProcParams& pparams, int h, double& scale);
void getThumbnailSize (int &w, int &h, const rtengine::procparams::ProcParams *pparams = nullptr);
void getFinalSize (const rtengine::procparams::ProcParams& pparams, int& w, int& h);
void getOriginalSize (int& w, int& h) const;
const Glib::ustring& getExifString () const;
const Glib::ustring& getDateTimeString () const;
const Glib::DateTime& getDateTime () const;
void getCamWB (double& temp, double& green) const;
void getAutoWB (double& temp, double& green, double equal, double tempBias);
void getSpotWB (int x, int y, int rect, double& temp, double& green);
void applyAutoExp (rtengine::procparams::ProcParams& pparams);
ThFileType getType () const;
Glib::ustring getFileName () const
{
return fname;
}
void setFileName (const Glib::ustring &fn);
bool isSupported () const;
const CacheImageData* getCacheImageData() const;
std::string getMD5 () const;
int getRank () const;
void setRank (int rank);
int getColorLabel () const;
void setColorLabel (int colorlabel);
int getStage () const;
void setStage (bool stage);
void addThumbnailListener (ThumbnailListener* tnl);
void removeThumbnailListener (ThumbnailListener* tnl);
void increaseRef ();
void decreaseRef ();
void updateCache (bool updatePParams = true, bool updateCacheImageData = true);
void saveThumbnail ();
bool openDefaultViewer(int destination);
bool imageLoad(bool loading);
};