summaryrefslogtreecommitdiffstats
path: root/src/utilities/batch/imageinfojob.cpp
blob: 58660697788eab921bb3196de34a302b81469af9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 *
 * Date        : 2006-22-01
 * Description : digikamalbum TDEIO slave interface to get image 
 *               info from database.
 *
 * Copyright (C) 2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * This program 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 2, or (at your option)
 * any later version.
 * 
 * This program 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.
 * 
 * ============================================================ */

// TQt includes.

#include <tqstring.h>
#include <tqdatastream.h>

// KDE includes.

#include <tdeio/job.h>
#include <kurl.h>

// Local includes.

#include "ddebug.h"
#include "album.h"
#include "albummanager.h"
#include "albumsettings.h"
#include "imageinfojob.h"
#include "imageinfojob.moc"

namespace Digikam
{

class ImageInfoJobPriv
{
public:

    ImageInfoJobPriv()
    {
        job         = 0;

        AlbumSettings *settings = AlbumSettings::instance();
        imagefilter = settings->getImageFileFilter().lower() +
                      settings->getImageFileFilter().upper() +
                      settings->getRawFileFilter().lower()   +
                      settings->getRawFileFilter().upper();
    }

    TQString            imagefilter; 

    TDEIO::TransferJob  *job;
};

ImageInfoJob::ImageInfoJob()
{
    d = new ImageInfoJobPriv;
}

ImageInfoJob::~ImageInfoJob()
{
    delete d;
}

void ImageInfoJob::allItemsFromAlbum(Album *album)
{
    if (d->job)
    {
        d->job->kill();
        d->job = 0;
    }

    if (!album)
        return;
    
    TQByteArray  ba;
    TQDataStream ds(ba, IO_WriteOnly);
    ds << AlbumManager::instance()->getLibraryPath();
    ds << album->kurl();
    ds << d->imagefilter;
    ds << 0; // getting dimensions (not needed here)
    ds << 0; // recursive sub-album (not needed here)
    ds << 0; // recursive sub-tags (not needed here)

    // Protocol = digikamalbums -> tdeio_digikamalbums
    d->job = new TDEIO::TransferJob(album->kurl(), TDEIO::CMD_SPECIAL,
                                  ba, TQByteArray(), false);

    connect(d->job, TQ_SIGNAL(result(TDEIO::Job*)),
            this, TQ_SLOT(slotResult(TDEIO::Job*)));

    connect(d->job, TQ_SIGNAL(data(TDEIO::Job*, const TQByteArray&)),
            this, TQ_SLOT(slotData(TDEIO::Job*, const TQByteArray&)));
}

void ImageInfoJob::stop()
{
    if (d->job)
    {
        d->job->kill();
        d->job = 0;
    }
}

void ImageInfoJob::slotResult(TDEIO::Job* job)
{
    d->job = 0;

    if (job->error())
    {
        DWarning() << "Failed to list url: " << job->errorString() << endl;
        return;
    }

    emit signalCompleted();
}

void ImageInfoJob::slotData(TDEIO::Job*, const TQByteArray& data)
{
    if (data.isEmpty())
        return;

    TQ_LLONG       imageID;
    int           albumID;
    TQString       name;
    TQString       date;
    size_t        size;
    TQSize         dims;
    ImageInfoList itemsList;
    TQDataStream   ds(data, IO_ReadOnly);

    while (!ds.atEnd())
    {
        ds >> imageID;
        ds >> albumID;
        ds >> name;
        ds >> date;
        ds >> size;
        ds >> dims;

        ImageInfo* info = new ImageInfo(imageID, albumID, name,
                                        TQDateTime::fromString(date, TQt::ISODate),
                                        size, dims);

        itemsList.append(info);
    }

    emit signalItemsInfo(itemsList);
}

}  // namespace Digikam