3 /* This file is part of the KDE libraries
4 Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation version 2.0.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "metainfojob.h"
23 #include <kfileitem.h>
25 #include <kfilemetainfo.h>
26 #include <kservicetypetrader.h>
28 #include <QtCore/QTimer>
30 #include "jobuidelegate.h"
35 class KIO::MetaInfoJobPrivate
: public KIO::JobPrivate
38 KFileItemList items
; // all the items we got
40 bool succeeded
; // if the current item is ok
42 Q_DECLARE_PUBLIC(MetaInfoJob
)
45 MetaInfoJob::MetaInfoJob(const KFileItemList
& items
, KFileMetaInfo::WhatFlags
,
46 int, int, const QStringList
&, const QStringList
&)
47 : KIO::Job(*new MetaInfoJobPrivate
)
54 if (d
->items
.isEmpty())
56 kDebug(7007) << "nothing to do for the MetaInfoJob\n";
61 kDebug(7007) << "starting MetaInfoJob\n";
63 // Return to event loop first, determineNextFile() might delete this;
64 // (no idea what that means, it comes from previewjob)
65 QTimer::singleShot(0, this, SLOT(start()));
68 MetaInfoJob::~MetaInfoJob()
72 void MetaInfoJob::start()
77 void MetaInfoJob::removeItem(const KFileItem
& item
)
80 if (d
->items
.at( d
->currentItem
) == item
)
82 KJob
* job
= subjobs().first();
88 d
->items
.removeAll(item
);
91 void MetaInfoJob::determineNextFile()
94 if (d
->currentItem
>= d
->items
.count() - 1)
96 kDebug(7007) << "finished MetaInfoJob\n";
102 d
->succeeded
= false;
104 // does the file item already have the needed info? Then shortcut
105 KFileItem item
= d
->items
.at( d
->currentItem
);
106 if (item
.metaInfo(false).isValid())
108 // kDebug(7007) << "Is already valid *************************\n";
109 emit
gotMetaInfo(item
);
117 void MetaInfoJob::slotResult( KJob
*job
)
120 Q_ASSERT(!hasSubjobs()); // We should have only one job at a time ...
125 void MetaInfoJob::getMetaInfo()
128 KFileItem item
= d
->items
.at( d
->currentItem
);
129 Q_ASSERT(!item
.isNull());
132 URL
.setProtocol("metainfo");
133 URL
.setPath(item
.url().path());
135 KIO::TransferJob
* job
= KIO::get(URL
, NoReload
, HideProgressInfo
);
138 connect(job
, SIGNAL(data(KIO::Job
*, const QByteArray
&)),
139 this, SLOT(slotMetaInfo(KIO::Job
*, const QByteArray
&)));
141 job
->addMetaData("mimeType", item
.mimetype());
145 void MetaInfoJob::slotMetaInfo(KIO::Job
*, const QByteArray
&data
)
153 KFileItem item
= d
->items
.at( d
->currentItem
);
154 item
.setMetaInfo(info
);
155 emit
gotMetaInfo(item
);
159 KIO_EXPORT MetaInfoJob
*KIO::fileMetaInfo( const KFileItemList
& items
)
161 return new MetaInfoJob(items
);
164 KIO_EXPORT MetaInfoJob
*KIO::fileMetaInfo( const KUrl::List
&items
)
166 KFileItemList fileItems
;
167 foreach (const KUrl
& url
, items
) {
168 fileItems
.append(KFileItem(KFileItem::Unknown
, KFileItem::Unknown
, url
,
171 MetaInfoJob
*job
= new MetaInfoJob(fileItems
);
172 job
->setUiDelegate(new JobUiDelegate());
176 #include "metainfojob.moc"