• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KIO

  • kio
  • kio
metainfojob.cpp
Go to the documentation of this file.
1// -*- c++ -*-
2// vim: ts=4 sw=4 et
3/* This file is part of the KDE libraries
4 Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org>
5
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.
9
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.
14
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.
19 */
20
21#include "metainfojob.h"
22
23#include <kfileitem.h>
24#include <kdebug.h>
25#include <kfilemetainfo.h>
26#include <kservicetypetrader.h>
27
28#include <QtCore/QTimer>
29
30#include "jobuidelegate.h"
31#include "job_p.h"
32
33using namespace KIO;
34
35class KIO::MetaInfoJobPrivate: public KIO::JobPrivate
36{
37public:
38 KFileItemList items; // all the items we got
39 int currentItem;
40 bool succeeded; // if the current item is ok
41
42 Q_DECLARE_PUBLIC(MetaInfoJob)
43};
44
45MetaInfoJob::MetaInfoJob(const KFileItemList& items, KFileMetaInfo::WhatFlags,
46 int, int, const QStringList&, const QStringList&)
47 : KIO::Job(*new MetaInfoJobPrivate)
48{
49 Q_D(MetaInfoJob);
50 d->succeeded = false;
51 d->items = items;
52 d->currentItem = 0;
53
54 if (d->items.isEmpty())
55 {
56 kDebug(7007) << "nothing to do for the MetaInfoJob\n";
57 emitResult();
58 return;
59 }
60
61 kDebug(7007) << "starting MetaInfoJob\n";
62
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()));
66}
67
68MetaInfoJob::~MetaInfoJob()
69{
70}
71
72void MetaInfoJob::start()
73{
74 getMetaInfo();
75}
76
77void MetaInfoJob::removeItem(const KFileItem& item)
78{
79 Q_D(MetaInfoJob);
80 if (d->items.at( d->currentItem ) == item)
81 {
82 KJob* job = subjobs().first();
83 job->kill();
84 removeSubjob( job );
85 determineNextFile();
86 }
87
88 d->items.removeAll(item);
89}
90
91void MetaInfoJob::determineNextFile()
92{
93 Q_D(MetaInfoJob);
94 if (d->currentItem >= d->items.count() - 1)
95 {
96 kDebug(7007) << "finished MetaInfoJob\n";
97 emitResult();
98 return;
99 }
100
101 ++d->currentItem;
102 d->succeeded = false;
103
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())
107 {
108// kDebug(7007) << "Is already valid *************************\n";
109 emit gotMetaInfo(item);
110 determineNextFile();
111 return;
112 }
113
114 getMetaInfo();
115}
116
117void MetaInfoJob::slotResult( KJob *job )
118{
119 removeSubjob(job);
120 Q_ASSERT(!hasSubjobs()); // We should have only one job at a time ...
121
122 determineNextFile();
123}
124
125void MetaInfoJob::getMetaInfo()
126{
127 Q_D(MetaInfoJob);
128 KFileItem item = d->items.at( d->currentItem );
129 Q_ASSERT(!item.isNull());
130
131 KUrl URL;
132 URL.setProtocol("metainfo");
133 URL.setPath(item.url().path());
134
135 KIO::TransferJob* job = KIO::get(URL, NoReload, HideProgressInfo);
136 addSubjob(job);
137
138 connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
139 this, SLOT(slotMetaInfo(KIO::Job*,QByteArray)));
140
141 job->addMetaData("mimeType", item.mimetype());
142}
143
144
145void MetaInfoJob::slotMetaInfo(KIO::Job*, const QByteArray &data)
146{
147 Q_D(MetaInfoJob);
148 KFileMetaInfo info;
149 QDataStream s(data);
150
151 s >> info;
152
153 KFileItem item = d->items.at( d->currentItem );
154 item.setMetaInfo(info);
155 emit gotMetaInfo(item);
156 d->succeeded = true;
157}
158
159KIO_EXPORT MetaInfoJob *KIO::fileMetaInfo( const KFileItemList& items)
160{
161 return new MetaInfoJob(items);
162}
163
164KIO_EXPORT MetaInfoJob *KIO::fileMetaInfo( const KUrl::List &items)
165{
166 KFileItemList fileItems;
167 foreach (const KUrl& url, items) {
168 fileItems.append(KFileItem(KFileItem::Unknown, KFileItem::Unknown, url,
169 true));
170 }
171 MetaInfoJob *job = new MetaInfoJob(fileItems);
172 job->setUiDelegate(new JobUiDelegate());
173 return job;
174}
175
176#include "metainfojob.moc"
KCompositeJob::subjobs
const QList< KJob * > & subjobs() const
KCompositeJob::hasSubjobs
bool hasSubjobs()
KFileItemList
List of KFileItems, which adds a few helper methods to QList<KFileItem>.
Definition: kfileitem.h:675
KFileItem
A KFileItem is a generic class to handle a file, local or remote.
Definition: kfileitem.h:46
KFileItem::metaInfo
KFileMetaInfo metaInfo(bool autoget=true, int what=KFileMetaInfo::ContentInfo|KFileMetaInfo::TechnicalInfo) const
Returns the metainfo of this item.
Definition: kfileitem.cpp:1449
KFileItem::setMetaInfo
void setMetaInfo(const KFileMetaInfo &info) const
Sets the metainfo of this item to info.
Definition: kfileitem.cpp:1441
KFileItem::mimetype
QString mimetype() const
Returns the mimetype of the file item.
Definition: kfileitem.cpp:770
KFileItem::isNull
bool isNull() const
Return true if default-constructed.
Definition: kfileitem.cpp:1714
KFileItem::url
KUrl url() const
Returns the url of the file.
Definition: kfileitem.cpp:1543
KFileItem::Unknown
@ Unknown
Definition: kfileitem.h:48
KFileMetaInfo
KFileMetaInfo provides metadata extracted from a file or other resource.
Definition: kfilemetainfo.h:56
KFileMetaInfo::isValid
bool isValid() const
Definition: kfilemetainfo.cpp:372
KIO::JobPrivate
Definition: job_p.h:40
KIO::JobUiDelegate
A UI delegate tuned to be used with KIO Jobs.
Definition: jobuidelegate.h:40
KIO::Job
The base class for all jobs.
Definition: jobclasses.h:94
KIO::Job::removeSubjob
virtual bool removeSubjob(KJob *job)
Mark a sub job as being done.
Definition: job.cpp:118
KIO::Job::addSubjob
virtual bool addSubjob(KJob *job)
Add a job that has to be finished before a result is emitted.
Definition: job.cpp:95
KIO::Job::addMetaData
void addMetaData(const QString &key, const QString &value)
Add key/value pair to the meta data that is sent to the slave.
Definition: job.cpp:264
KIO::MetaInfoJob
MetaInfoJob is a KIO Job to retrieve meta information from files.
Definition: metainfojob.h:36
KIO::MetaInfoJob::gotMetaInfo
void gotMetaInfo(const KFileItem &item)
KIO::MetaInfoJob::getMetaInfo
void getMetaInfo()
Definition: metainfojob.cpp:125
KIO::MetaInfoJob::~MetaInfoJob
virtual ~MetaInfoJob()
Definition: metainfojob.cpp:68
KIO::MetaInfoJob::MetaInfoJob
MetaInfoJob(const KFileItemList &items, KFileMetaInfo::WhatFlags w=KFileMetaInfo::Everything, int iocost=3, int cpucost=6, const QStringList &requiredfields=QStringList(), const QStringList &requestedfields=QStringList())
Creates a new MetaInfoJob.
Definition: metainfojob.cpp:45
KIO::MetaInfoJob::slotResult
virtual void slotResult(KJob *job)
Definition: metainfojob.cpp:117
KIO::MetaInfoJob::removeItem
void removeItem(const KFileItem &item)
Removes an item from metainfo extraction.
Definition: metainfojob.cpp:77
KIO::TransferJob
The transfer job pumps data into and/or out of a Slave.
Definition: jobclasses.h:555
KJob
KJob::emitResult
void emitResult()
KJob::kill
bool kill(KillVerbosity verbosity=Quietly)
KJob::setUiDelegate
void setUiDelegate(KJobUiDelegate *delegate)
KUrl::List
KUrl
KUrl::path
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const
KUrl::setProtocol
void setProtocol(const QString &proto)
KUrl::setPath
void setPath(const QString &path)
kDebug
#define kDebug
job_p.h
jobuidelegate.h
kdebug.h
kfileitem.h
kfilemetainfo.h
kservicetypetrader.h
metainfojob.h
KIO
A namespace for KIO globals.
Definition: kbookmarkmenu.h:55
KIO::get
TransferJob * get(const KUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
Get (a.k.a.
Definition: job.cpp:1369
KIO::NoReload
@ NoReload
Definition: job.h:29
KIO::fileMetaInfo
MetaInfoJob * fileMetaInfo(const KFileItemList &items)
Retrieves meta information for the given items.
Definition: metainfojob.cpp:159
KIO::HideProgressInfo
@ HideProgressInfo
Hide progress information dialog, i.e.
Definition: jobclasses.h:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal