[Digikam-devel] extragear/graphics/digikam/libs/database
Marcel Wiesweg
marcel.wiesweg at gmx.de
Wed Aug 15 19:47:24 BST 2007
SVN commit 700513 by mwiesweg:
Move filtering by name from listing to scanning.
Previously, all files were taken in the database, and only after listing from the db,
files were filtered by the file suffixes.
With this change, as discussed on the devel list quite some time ago,
files are filtered by suffix before they are taken up in the database,
and filtering after listing is not necessary.
This accommodates better to the view that all entries in the db are part of the collection,
and it solves some bugs when SQL features are used to get statistics from db.
TODO:
The situation in the config dialog needs to be cleared. At least there must be a big fat
warning if users try to remove "*.jpg" and the like, as they would lose their tags.
Second, after a change, a rescan is needed.
We should anyway think about the format list, when raw formats are added, old users may not see them.
There could be a "use default values" check - and only with this unchecked, the formats would be configurable.
CCMAIL: digikam-devel at kde.org
M +24 -1 collectionscanner.cpp
M +15 -1 collectionscanner.h
M +30 -44 imagelister.cpp
M +16 -17 imagelister.h
--- trunk/extragear/graphics/digikam/libs/database/collectionscanner.cpp #700512:700513
@@ -57,6 +57,29 @@
// ------------------- CollectionScanner code -------------------------
+void CollectionScanner::setNameFilters(QString filter)
+{
+ QStringList filterList;
+
+ QChar sep( ';' );
+ int i = filter.indexOf( sep );
+ if ( i == -1 && filter.indexOf( ' ') != -1 )
+ sep = QChar( ' ' );
+
+ QStringList sepList = filter.split(sep, QString::SkipEmptyParts);
+ foreach (QString f, sepList)
+ {
+ filterList << f.trimmed();
+ }
+ setNameFilters(filterList);
+}
+
+void CollectionScanner::setNameFilters(QStringList filters)
+{
+ m_nameFilters = filters;
+}
+
+
void CollectionScanner::scanForStaleAlbums()
{
QStringList albumRootPaths = CollectionManager::instance()->allAvailableAlbumRootPaths();
@@ -251,7 +274,7 @@
filesFoundInDB << *it;
}
- const QFileInfoList list = dir.entryInfoList();
+ const QFileInfoList list = dir.entryInfoList(m_nameFilters, QDir::AllDirs | QDir::Files /*not CaseSensitive*/);
QFileInfoList::const_iterator fi;
for (fi = list.constBegin(); fi != list.constEnd(); ++fi)
--- trunk/extragear/graphics/digikam/libs/database/collectionscanner.h #700512:700513
@@ -47,6 +47,19 @@
public:
/**
+ * Sets a filter for the file formats which shall be included in the collection.
+ * The string is a list of name wildcards (understanding * and ?),
+ * separated by ';' characters.
+ * Example: "*.jpg;*.png"
+ */
+ void setNameFilters(QString filters);
+ /**
+ * Sets a filter for the file formats which shall be included in the collection.
+ * Each name filter in the list is a wildcard (globbing)
+ * filter that understands * and ? wildcards (see QDir::setNameFilters)
+ */
+ void setNameFilters(QStringList filters);
+ /**
* Carries out a full scan (for new albums + new pictures,
* stale albums, stale pictures) on the given path.
* @param filePath a folder somewhere in the collection
@@ -162,7 +175,8 @@
int countItemsInFolder(const QString& directory);
QList< QPair<QString,int> > m_filesToBeDeleted;
- QList<AlbumShortInfo> m_foldersToBeDeleted;
+ QList<AlbumShortInfo> m_foldersToBeDeleted;
+ QStringList m_nameFilters;
};
} // namespace Digikam
--- trunk/extragear/graphics/digikam/libs/database/imagelister.cpp #700512:700513
@@ -56,7 +56,6 @@
#include "databaseaccess.h"
#include "databasebackend.h"
#include "dmetadata.h"
-#include "namefilter.h"
#include "imagelister.h"
namespace Digikam
@@ -88,18 +87,27 @@
return ds;
}
-KIO::TransferJob *ImageLister::startListJob(const DatabaseUrl &url, const QString &filter,
- int getDimension, int extraValue)
+KIO::TransferJob *ImageLister::startListJob(const DatabaseUrl &url, int extraValue)
{
QByteArray ba;
QDataStream ds(&ba, QIODevice::WriteOnly);
ds << url;
+ if (extraValue != -1)
+ ds << extraValue;
+
+ return new KIO::SpecialJob(url, ba);
+}
+
+KIO::TransferJob *ImageLister::startScanJob(const DatabaseUrl &url, const QString &filter, int extraValue)
+{
+ QByteArray ba;
+ QDataStream ds(&ba, QIODevice::WriteOnly);
+ ds << url;
ds << filter;
- ds << getDimension;
if (extraValue != -1)
ds << extraValue;
- return new KIO::SpecialJob(url,ba);
+ return new KIO::SpecialJob(url, ba);
}
QSize ImageLister::retrieveDimension(const QString &filePath)
@@ -132,28 +140,26 @@
}
-void ImageLister::list(ImageListerReceiver *receiver, const DatabaseUrl &url,
- const QString &filter, bool getDimension)
+void ImageLister::list(ImageListerReceiver *receiver, const DatabaseUrl &url)
{
if (url.isAlbumUrl())
{
QString albumRoot = url.albumRootPath();
QString album = url.album();
- listAlbum(receiver, albumRoot, album, filter, getDimension);
+ listAlbum(receiver, albumRoot, album);
}
else if (url.isTagUrl())
{
- listTag(receiver, url.tagId(), filter, getDimension);
+ listTag(receiver, url.tagId());
}
else if (url.isDateUrl())
{
- listMonth(receiver, url.date(), filter, getDimension);
+ listMonth(receiver, url.date());
}
}
void ImageLister::listAlbum(ImageListerReceiver *receiver,
- const QString &albumRoot, const QString &album,
- const QString &filter, bool getDimension)
+ const QString &albumRoot, const QString &album)
{
int albumid;
@@ -165,12 +171,11 @@
return;
}
- listAlbum(receiver, albumRoot, album, albumid, filter, getDimension);
+ listAlbum(receiver, albumRoot, album, albumid);
}
void ImageLister::listAlbum(ImageListerReceiver *receiver,
- const QString &albumRoot, const QString &album, int albumid,
- const QString &filter, bool getDimensions)
+ const QString &albumRoot, const QString &album, int albumid)
{
QString base = albumRoot + album;
@@ -191,7 +196,6 @@
*/
}
- NameFilter nameFilter(filter);
struct stat stbuf;
for (QList<QVariant>::iterator it = values.begin(); it != values.end();)
{
@@ -207,24 +211,20 @@
record.albumName = album;
record.albumRoot = albumRoot;
- if (!nameFilter.matches(record.name))
- continue;
-
QString filePath = base + '/' + record.name;
if (::stat(QFile::encodeName(filePath), &stbuf) != 0)
continue;
record.size = static_cast<size_t>(stbuf.st_size);
- if (getDimensions)
- record.dims = retrieveDimension(filePath);
+ //if (getDimensions)
+ // record.dims = retrieveDimension(filePath);
receiver->receive(record);
}
}
-void ImageLister::listTag(ImageListerReceiver *receiver,
- int tagId, const QString &filter, bool getDimensions)
+void ImageLister::listTag(ImageListerReceiver *receiver, int tagId)
{
QString albumRoot = DatabaseAccess::albumRoot();
@@ -243,7 +243,6 @@
tagId, tagId, &values );
}
- NameFilter nameFilter(filter);
struct stat stbuf;
for (QList<QVariant>::iterator it = values.begin(); it != values.end();)
{
@@ -261,24 +260,20 @@
record.albumRoot = albumRoot;
- if (!nameFilter.matches(record.name))
- continue;
-
QString path = albumRoot + record.albumName + '/' + record.name;
if (::stat(QFile::encodeName(path), &stbuf) != 0)
continue;
record.size = static_cast<size_t>(stbuf.st_size);
- if (getDimensions)
- record.dims = retrieveDimension(path);
+ //if (getDimensions)
+ // record.dims = retrieveDimension(path);
receiver->receive(record);
}
}
-void ImageLister::listMonth(ImageListerReceiver *receiver,
- const QDate &date, const QString &filter, bool getDimensions)
+void ImageLister::listMonth(ImageListerReceiver *receiver, const QDate &date)
{
QString albumRoot = DatabaseAccess::albumRoot();
@@ -301,7 +296,6 @@
&values);
}
- NameFilter nameFilter(filter);
struct stat stbuf;
for (QList<QVariant>::iterator it = values.begin(); it != values.end();)
{
@@ -319,17 +313,14 @@
record.albumRoot = albumRoot;
- if (!nameFilter.matches(record.name))
- continue;
-
QString path = albumRoot + record.albumName + '/' + record.name;
if (::stat(QFile::encodeName(path), &stbuf) != 0)
continue;
record.size = static_cast<size_t>(stbuf.st_size);
- if (getDimensions)
- record.dims = retrieveDimension(path);
+ //if (getDimensions)
+ // record.dims = retrieveDimension(path);
receiver->receive(record);
}
@@ -338,7 +329,6 @@
void ImageLister::listSearch(ImageListerReceiver *receiver,
const QString &sqlConditionalExpression,
const QList<QVariant> &boundValues,
- const QString &filter, bool getDimensions,
bool getSize, int limit)
{
QString albumRoot = DatabaseAccess::albumRoot();
@@ -378,7 +368,6 @@
return;
}
- NameFilter nameFilter(filter);
struct stat stbuf;
for (QList<QVariant>::iterator it = values.begin(); it != values.end();)
{
@@ -396,9 +385,6 @@
record.albumRoot = albumRoot;
- if (!nameFilter.matches(record.name))
- continue;
-
QString path = albumRoot + record.albumName + '/' + record.name;
if (getSize)
@@ -412,8 +398,8 @@
record.size = 0;
}
- if (getDimensions)
- record.dims = retrieveDimension(path);
+ //if (getDimensions)
+ // record.dims = retrieveDimension(path);
receiver->receive(record);
}
--- trunk/extragear/graphics/digikam/libs/database/imagelister.h #700512:700513
@@ -53,21 +53,23 @@
/**
* Create a TransferJob for the "special" method of one of the database ioslaves,
* referenced by the URL.
- * Three or four parameters will be sent to the "special" method:
- * KUrl, QString, int (, int).
* @param extraValue If -1, nothing is sent. If it takes another value,
- * this value will be sent as a fourth parameter.
+ * this value will be sent as a second parameter.
*/
- static KIO::TransferJob *startListJob(const DatabaseUrl &url, const QString &filter,
- int getDimension, int extraValue = -1);
+ static KIO::TransferJob *startListJob(const DatabaseUrl &url, int extraValue = -1);
+ /**
+ * Create a TransferJob for the scanning part of the "special" method of the albums ioslave,
+ * referenced by the URL. Filter and extraValue will be added to the job data.
+ */
+ static KIO::TransferJob *startScanJob(const DatabaseUrl &url, const QString &filter, int extraValue);
+
/**
* Convenience method for Album, Tag and Date URLs, _not_ for Search URLs.
*/
void list(ImageListerReceiver *receiver,
- const DatabaseUrl &url,
- const QString &filter, bool getDimension);
+ const DatabaseUrl &url);
/**
* List images in the Album (physical album) specified by albumRoot, album (and albumid).
@@ -76,31 +78,28 @@
* @param getDimension retrieve dimension - slow!. If false, dimension will be QSize()
*/
void listAlbum(ImageListerReceiver *receiver,
- const QString &albumRoot, const QString &album,
- const QString &filter, bool getDimensions);
+ const QString &albumRoot, const QString &album);
void listAlbum(ImageListerReceiver *receiver,
- const QString &albumRoot, const QString &album, int albumid,
- const QString &filter, bool getDimensions);
+ const QString &albumRoot, const QString &album, int albumid);
/**
* List the images which have assigned the tag specified by tagId
*/
- void listTag(ImageListerReceiver *receiver,
- int tagId, const QString &filter, bool getDimensions);
+ void listTag(ImageListerReceiver *receiver, int tagId);
/**
* List those images whose date lies in the month specified by the date
*/
- void listMonth(ImageListerReceiver *receiver,
- const QDate &date, const QString &filter, bool getDimensions);
+ void listMonth(ImageListerReceiver *receiver, const QDate &date);
/**
* Execute the search specified by a SQL expression
+ * @param sqlConditionalExpression SQL code for the WHERE part of the query
+ * @param boundValues SQL bound values used in the sql conditional expression
* @param getSize stat the file size. If false, size will be 0
* @param limit limit the count of the result set. If limit = 0, then no limit is set.
*/
void listSearch(ImageListerReceiver *receiver,
- const QString &sqlQuery,
+ const QString &sqlConditionalExpression,
const QList<QVariant> &boundValues,
- const QString &filter, bool getDimensions,
bool getSize = true, int limit = 0);
/**
More information about the Digikam-devel
mailing list