"Fossies" - the Fresh Open Source Software Archive

Member "digikam-6.3.0/core/libs/database/item/lister/itemlister_falbum.cpp" (4 Sep 2019, 6205 Bytes) of package /linux/misc/digikam-6.3.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "itemlister_falbum.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 6.2.0_vs_6.3.0.

    1 /* ============================================================
    2  *
    3  * This file is a part of digiKam project
    4  * https://www.digikam.org
    5  *
    6  * Date        : 2007-03-20
    7  * Description : Listing information from database - FAlbum helpers.
    8  *
    9  * Copyright (C) 2007-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
   10  * Copyright (C) 2007-2019 by Gilles Caulier <caulier dot gilles at gmail dot com>
   11  * Copyright (C) 2015      by Mohamed_Anwer  <m_dot_anwer at gmx dot com>
   12  * Copyright (C) 2018      by Mario Frank    <mario dot frank at uni minus potsdam dot de>
   13  *
   14  * This program is free software; you can redistribute it
   15  * and/or modify it under the terms of the GNU General
   16  * Public License as published by the Free Software Foundation;
   17  * either version 2, or (at your option)
   18  * any later version.
   19  *
   20  * This program is distributed in the hope that it will be useful,
   21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   23  * GNU General Public License for more details.
   24  *
   25  * ============================================================ */
   26 
   27 #include "itemlister_p.h"
   28 
   29 namespace Digikam
   30 {
   31 
   32 void ItemLister::listFaces(ItemListerReceiver* const receiver, int personId)
   33 {
   34     QList<qlonglong> list;
   35     QList<QVariant>  values;
   36 
   37     {
   38         CoreDbAccess access;
   39         access.backend()->execSql(QString::fromUtf8("SELECT Images.id "
   40                                           " FROM Images "
   41                                           "       LEFT JOIN ImageInformation ON Images.id=ImageInformation.imageid "
   42                                           "       INNER JOIN Albums ON Albums.id=") +
   43                                           QString::number(personId) +
   44                                           QString::fromUtf8(" WHERE Images.status=1 "
   45                                           " ORDER BY Albums.id;"),
   46                                   &values);
   47     }
   48 
   49     QListIterator<QVariant> it(values);
   50 
   51     while (it.hasNext())
   52     {
   53         TagsCache* const cache = TagsCache::instance();
   54 
   55         ItemTagPair pair(list.last(), cache->tagForPath(QLatin1String("/People/Unknown")));
   56         QList<QString> nameList = pair.values(QLatin1String("face"));
   57 
   58         // push the image into the list every time a face with the name is found in the image
   59         int count = nameList.count(cache->tagName(personId));
   60 
   61         for (int i = 0 ; i < count ; ++i)
   62         {
   63             list += it.next().toLongLong();
   64         }
   65     }
   66 
   67     listFromIdList(receiver, list);
   68 }
   69 
   70 void ItemLister::listFromIdList(ItemListerReceiver* const receiver,
   71                                 const QList<qlonglong>& imageIds)
   72 {
   73     QList<QVariant> values;
   74     QString         errMsg;
   75     bool            executionSuccess = true;
   76 
   77     {
   78 /*
   79         // Unfortunately, we need to convert to QVariant
   80         QList<QVariant> variantIdList;
   81 
   82         foreach (const qlonglong& id, imageIds)
   83         {
   84             variantIdList << id;
   85         }
   86 
   87         CoreDbAccess access;
   88         QSqlQuery query = access.backend()->prepareQuery(QString::fromUtf8(
   89                     "SELECT DISTINCT Images.id, Images.name, Images.album, "
   90                     "       ImageInformation.rating, ImageInformation.creationDate, "
   91                     "       Images.modificationDate, Images.fileSize, "
   92                     "       ImageInformation.width, ImageInformation.height "
   93                     " FROM Images "
   94                     "       LEFT JOIN ImageInformation ON Images.id=ImageInformation.imageid "
   95                     " WHERE Images.id = ?;"));
   96 
   97         query.addBindValue(variantIdList);
   98         executionSuccess = query.execBatch
   99 */
  100         CoreDbAccess access;
  101         DbEngineSqlQuery query = access.backend()->prepareQuery(QString::fromUtf8(
  102                              "SELECT DISTINCT Images.id, Images.name, Images.album, "
  103                              "       Albums.albumRoot, "
  104                              "       ImageInformation.rating, Images.category, "
  105                              "       ImageInformation.format, ImageInformation.creationDate, "
  106                              "       Images.modificationDate, Images.fileSize, "
  107                              "       ImageInformation.width, ImageInformation.height "
  108                              " FROM Images "
  109                              "       LEFT JOIN ImageInformation ON Images.id=ImageInformation.imageid "
  110                              "       LEFT JOIN Albums ON Albums.id=Images.album "
  111                              " WHERE Images.status=1 AND Images.id = ?;"));
  112 
  113         foreach (const qlonglong& id, imageIds)
  114         {
  115             query.bindValue(0, id);
  116             executionSuccess = access.backend()->exec(query);
  117 
  118             if (!executionSuccess)
  119             {
  120                 errMsg = access.backend()->lastError();
  121                 break;
  122             }
  123 
  124             // append results to list
  125             values << access.backend()->readToList(query);
  126         }
  127     }
  128 
  129     if (!executionSuccess)
  130     {
  131         receiver->error(errMsg);
  132         return;
  133     }
  134 
  135     int width, height;
  136 
  137     for (QList<QVariant>::const_iterator it = values.constBegin() ; it != values.constEnd() ;)
  138     {
  139         ItemListerRecord record;
  140 
  141         record.imageID           = (*it).toLongLong();
  142         ++it;
  143         record.name              = (*it).toString();
  144         ++it;
  145         record.albumID           = (*it).toInt();
  146         ++it;
  147         record.albumRootID       = (*it).toInt();
  148         ++it;
  149         record.rating            = (*it).toInt();
  150         ++it;
  151         record.category          = (DatabaseItem::Category)(*it).toInt();
  152         ++it;
  153         record.format            = (*it).toString();
  154         ++it;
  155         record.creationDate      = (*it).toDateTime();
  156         ++it;
  157         record.modificationDate  = (*it).toDateTime();
  158         ++it;
  159         record.fileSize          = d->toInt32BitSafe(it);
  160         ++it;
  161         width                    = (*it).toInt();
  162         ++it;
  163         height                   = (*it).toInt();
  164         ++it;
  165 
  166         record.imageSize         = QSize(width, height);
  167 
  168         receiver->receive(record);
  169     }
  170 }
  171 
  172 } // namespace Digikam