~ubuntu-branches/ubuntu/intrepid/digikam/intrepid

« back to all changes in this revision

Viewing changes to digikam/kioslave/digikamalbums.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-07-17 20:25:39 UTC
  • mfrom: (1.2.15 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080717202539-6n7dtirbkoo7qvhd
Tags: 2:0.9.4-1
* New upstream release
  - digiKam 0.9.4 Release Plan (KDE3) ~ 13 July 08 (Closes: #490144)
* DEB_CONFIGURE_EXTRA_FLAGS := --without-included-sqlite3
* Debhelper compatibility level V7
* Install pixmaps in debian/*.install
* Add debian/digikam.lintian-overrides

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
 
73
73
// LibKDcraw includes.
74
74
 
75
 
#include <libkdcraw/rawfiles.h>
 
75
#include <libkdcraw/dcrawbinary.h>
76
76
 
77
77
// Local includes.
78
78
 
125
125
 
126
126
void kio_digikamalbums::special(const QByteArray& data)
127
127
{
 
128
    bool folders = (metaData("folders") == "yes");
 
129
 
128
130
    QString libraryPath;
129
131
    KURL    kurl;
130
132
    QString url;
146
148
        ds >> scan;
147
149
 
148
150
    libraryPath = QDir::cleanDirPath(libraryPath);
149
 
    
 
151
 
150
152
    if (m_libraryPath != libraryPath)
151
153
    {
152
154
        m_libraryPath = libraryPath;
155
157
    }
156
158
 
157
159
    url = kurl.path();
158
 
    
 
160
 
159
161
    if (scan)
160
162
    {
161
163
        scanAlbum(url);
162
164
        finished();
163
165
        return;
164
166
    }
165
 
    
 
167
 
166
168
    QValueList<QRegExp> regex = makeFilterList(filter);
167
 
    
168
 
    QStringList albumvalues;
169
 
    if (recurseAlbums)
 
169
    QByteArray ba;
 
170
 
 
171
    if (folders)       // Special mode to stats all album items
170
172
    {
171
 
        // Search for albums and sub-albums:
172
 
        // For this, get the path with a trailing "/".
173
 
        // Otherwise albums on the same level like "Paris", "Paris 2006",
174
 
        // would be found in addition to "Paris/*".
175
 
        urlWithTrailingSlash = kurl.path(1);
176
 
 
177
 
        m_sqlDB.execSql(QString("SELECT DISTINCT id, url FROM Albums WHERE  url='%1' OR url LIKE '\%%2\%';")
178
 
                        .arg(escapeString(url)).arg(escapeString(urlWithTrailingSlash)), &albumvalues);
 
173
        QMap<int, int> albumsStatMap;
 
174
        QStringList    values;
 
175
        int            albumID;
 
176
 
 
177
        m_sqlDB.execSql(QString("SELECT dirid, Images.name FROM Images "
 
178
                                "WHERE Images.dirid IN (SELECT DISTINCT id FROM Albums)"), &values);
 
179
 
 
180
        for ( QStringList::iterator it = values.begin(); it != values.end(); )
 
181
        {
 
182
            albumID = (*it).toInt();
 
183
            ++it;
 
184
 
 
185
            if ( matchFilterList( regex, *it ) )
 
186
            {
 
187
                QMap<int, int>::iterator it2 = albumsStatMap.find(albumID);
 
188
                if ( it2 == albumsStatMap.end() )
 
189
                    albumsStatMap.insert(albumID, 1);
 
190
                else
 
191
                    albumsStatMap.replace(albumID, it2.data() + 1);
 
192
            }
 
193
 
 
194
            ++it;
 
195
        }
 
196
 
 
197
        QDataStream os(ba, IO_WriteOnly);
 
198
        os << albumsStatMap;
179
199
    }
180
200
    else
181
201
    {
182
 
        // Search for albums 
183
 
 
184
 
        m_sqlDB.execSql(QString("SELECT DISTINCT id, url FROM Albums WHERE url='%1';")
185
 
                        .arg(escapeString(url)), &albumvalues);
186
 
    }
187
 
 
188
 
    QByteArray  ba;
189
 
    QDataStream* os = new QDataStream(ba, IO_WriteOnly);
190
 
 
191
 
    QString base;  
192
 
    Q_LLONG id;
193
 
    QString name;
194
 
    QString date;
195
 
    QSize   dims;
196
 
 
197
 
    struct stat stbuf;
198
 
    
199
 
    QStringList values;
200
 
    QString albumurl;
201
 
    int albumid;
202
 
 
203
 
    // Loop over all albums:
204
 
    int count = 0 ;
205
 
    for (QStringList::iterator albumit = albumvalues.begin(); albumit != albumvalues.end();)
206
 
    {
207
 
        albumid = (*albumit).toLongLong();
208
 
        ++albumit;
209
 
        albumurl = *albumit;
210
 
        ++albumit;
211
 
 
212
 
        base = libraryPath + albumurl + '/';
213
 
 
214
 
        values.clear();
215
 
        m_sqlDB.execSql(QString("SELECT id, name, datetime FROM Images "
216
 
                                "WHERE dirid = %1;")
217
 
                        .arg(albumid), &values);
218
 
 
219
 
        // Loop over all images in each album (specified by its albumid).
220
 
        for (QStringList::iterator it = values.begin(); it != values.end();)
221
 
        {
222
 
            id   = (*it).toLongLong();
223
 
            ++it;
224
 
            name = *it;
225
 
            ++it;
226
 
            date = *it;
227
 
            ++it;
228
 
 
229
 
            if (!matchFilterList(regex, name))
230
 
              continue;
231
 
 
232
 
            if (::stat(QFile::encodeName(base + name), &stbuf) != 0)
233
 
              continue;
234
 
 
235
 
            dims = QSize();
236
 
            if (getDimensions)
 
202
        QStringList albumvalues;
 
203
        if (recurseAlbums)
 
204
        {
 
205
            // Search for albums and sub-albums:
 
206
            // For this, get the path with a trailing "/".
 
207
            // Otherwise albums on the same level like "Paris", "Paris 2006",
 
208
            // would be found in addition to "Paris/*".
 
209
            urlWithTrailingSlash = kurl.path(1);
 
210
    
 
211
            m_sqlDB.execSql(QString("SELECT DISTINCT id, url FROM Albums WHERE  url='%1' OR url LIKE '%2\%';")
 
212
                            .arg(escapeString(url)).arg(escapeString(urlWithTrailingSlash)), &albumvalues);
 
213
        }
 
214
        else
 
215
        {
 
216
            // Search for albums 
 
217
    
 
218
            m_sqlDB.execSql(QString("SELECT DISTINCT id, url FROM Albums WHERE url='%1';")
 
219
                            .arg(escapeString(url)), &albumvalues);
 
220
        }
 
221
    
 
222
        QDataStream* os = new QDataStream(ba, IO_WriteOnly);
 
223
    
 
224
        QString base;  
 
225
        Q_LLONG id;
 
226
        QString name;
 
227
        QString date;
 
228
        QSize   dims;
 
229
    
 
230
        struct stat stbuf;
 
231
        
 
232
        QStringList values;
 
233
        QString albumurl;
 
234
        int albumid;
 
235
    
 
236
        // Loop over all albums:
 
237
        int count = 0 ;
 
238
        for (QStringList::iterator albumit = albumvalues.begin(); albumit != albumvalues.end();)
 
239
        {
 
240
            albumid = (*albumit).toLongLong();
 
241
            ++albumit;
 
242
            albumurl = *albumit;
 
243
            ++albumit;
 
244
    
 
245
            base = libraryPath + albumurl + '/';
 
246
    
 
247
            values.clear();
 
248
            m_sqlDB.execSql(QString("SELECT id, name, datetime FROM Images "
 
249
                                    "WHERE dirid = %1;")
 
250
                            .arg(albumid), &values);
 
251
    
 
252
            // Loop over all images in each album (specified by its albumid).
 
253
            for (QStringList::iterator it = values.begin(); it != values.end();)
237
254
            {
238
 
                QFileInfo fileInfo(base + name);
239
 
                QString rawFilesExt(raw_file_extentions);
240
 
                QString ext = fileInfo.extension(false).upper();
241
 
 
242
 
                if (!ext.isEmpty() && rawFilesExt.upper().contains(ext))
 
255
                id   = (*it).toLongLong();
 
256
                ++it;
 
257
                name = *it;
 
258
                ++it;
 
259
                date = *it;
 
260
                ++it;
 
261
    
 
262
                if (!matchFilterList(regex, name))
 
263
                continue;
 
264
    
 
265
                if (::stat(QFile::encodeName(base + name), &stbuf) != 0)
 
266
                continue;
 
267
    
 
268
                dims = QSize();
 
269
                if (getDimensions)
243
270
                {
244
 
                    Digikam::DMetadata metaData(base + name);
245
 
                    dims = metaData.getImageDimensions();
 
271
                    QFileInfo fileInfo(base + name);
 
272
                    QString rawFilesExt(KDcrawIface::DcrawBinary::instance()->rawFiles());
 
273
                    QString ext = fileInfo.extension(false).upper();
 
274
    
 
275
                    if (!ext.isEmpty() && rawFilesExt.upper().contains(ext))
 
276
                    {
 
277
                        Digikam::DMetadata metaData(base + name);
 
278
                        dims = metaData.getImageDimensions();
 
279
                    }
 
280
                    else
 
281
                    {
 
282
                        KFileMetaInfo metaInfo(base + name);
 
283
                        if (metaInfo.isValid())
 
284
                        {
 
285
                            if (metaInfo.containsGroup("Jpeg EXIF Data"))
 
286
                            {
 
287
                                dims = metaInfo.group("Jpeg EXIF Data").
 
288
                                item("Dimensions").value().toSize();
 
289
                            }
 
290
                            else if (metaInfo.containsGroup("General"))
 
291
                            {
 
292
                                dims = metaInfo.group("General").
 
293
                                item("Dimensions").value().toSize();
 
294
                            }
 
295
                            else if (metaInfo.containsGroup("Technical"))
 
296
                            {
 
297
                                dims = metaInfo.group("Technical").
 
298
                                item("Dimensions").value().toSize();
 
299
                            }                         
 
300
                        }                    
 
301
                    }
246
302
                }
247
 
                else
 
303
    
 
304
                *os << id;
 
305
                *os << albumid;
 
306
                *os << name;
 
307
                *os << date;
 
308
                *os << static_cast<size_t>(stbuf.st_size);
 
309
                *os << dims;
 
310
    
 
311
                count++;
 
312
    
 
313
                // Send images in batches of 200.
 
314
                if (count > 200)
248
315
                {
249
 
                    KFileMetaInfo metaInfo(base + name);
250
 
                    if (metaInfo.isValid())
251
 
                    {
252
 
                        if (metaInfo.containsGroup("Jpeg EXIF Data"))
253
 
                        {
254
 
                            dims = metaInfo.group("Jpeg EXIF Data").
255
 
                              item("Dimensions").value().toSize();
256
 
                        }
257
 
                        else if (metaInfo.containsGroup("General"))
258
 
                        {
259
 
                            dims = metaInfo.group("General").
260
 
                              item("Dimensions").value().toSize();
261
 
                        }
262
 
                        else if (metaInfo.containsGroup("Technical"))
263
 
                        {
264
 
                            dims = metaInfo.group("Technical").
265
 
                              item("Dimensions").value().toSize();
266
 
                        }                         
267
 
                    }                    
 
316
                    delete os;
 
317
                    os = 0;
 
318
    
 
319
                    SlaveBase::data(ba);
 
320
                    ba.resize(0);
 
321
    
 
322
                    count = 0;
 
323
                    os = new QDataStream(ba, IO_WriteOnly);
268
324
                }
269
325
            }
270
 
 
271
 
            *os << id;
272
 
            *os << albumid;
273
 
            *os << name;
274
 
            *os << date;
275
 
            *os << static_cast<size_t>(stbuf.st_size);
276
 
            *os << dims;
277
 
 
278
326
            count++;
279
 
 
280
 
            // Send images in batches of 200.
281
 
            if (count > 200)
282
 
            {
283
 
                delete os;
284
 
                os = 0;
285
 
 
286
 
                SlaveBase::data(ba);
287
 
                ba.resize(0);
288
 
 
289
 
                count = 0;
290
 
                os = new QDataStream(ba, IO_WriteOnly);
291
 
            }
292
327
        }
293
 
        count++;
294
328
    }
295
329
 
296
330
    SlaveBase::data(ba);