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

KIO

  • sources
  • kde-4.14
  • kdelibs
  • 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 
33 using namespace KIO;
34 
35 class KIO::MetaInfoJobPrivate: public KIO::JobPrivate
36 {
37 public:
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 
45 MetaInfoJob::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 
68 MetaInfoJob::~MetaInfoJob()
69 {
70 }
71 
72 void MetaInfoJob::start()
73 {
74  getMetaInfo();
75 }
76 
77 void 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 
91 void 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 
117 void 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 
125 void 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 
145 void 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 
159 KIO_EXPORT MetaInfoJob *KIO::fileMetaInfo( const KFileItemList& items)
160 {
161  return new MetaInfoJob(items);
162 }
163 
164 KIO_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"
KIO::MetaInfoJob::getMetaInfo
void getMetaInfo()
Definition: metainfojob.cpp:125
KFileMetaInfo::isValid
bool isValid() const
Definition: kfilemetainfo.cpp:372
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
kdebug.h
KCompositeJob::emitResult
void emitResult()
KCompositeJob::setUiDelegate
void setUiDelegate(KJobUiDelegate *delegate)
QByteArray
KIO::fileMetaInfo
MetaInfoJob * fileMetaInfo(const KFileItemList &items)
Retrieves meta information for the given items.
Definition: metainfojob.cpp:159
KFileItem::mimetype
QString mimetype() const
Returns the mimetype of the file item.
Definition: kfileitem.cpp:770
KIO::MetaInfoJob::slotResult
virtual void slotResult(KJob *job)
Definition: metainfojob.cpp:117
QDataStream
KFileItem::isNull
bool isNull() const
Return true if default-constructed.
Definition: kfileitem.cpp:1714
KIO::HideProgressInfo
Hide progress information dialog, i.e.
Definition: jobclasses.h:51
KIO::get
TransferJob * get(const KUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
Get (a.k.a.
Definition: job.cpp:1369
KFileItem::metaInfo
KFileMetaInfo metaInfo(bool autoget=true, int what=KFileMetaInfo::ContentInfo|KFileMetaInfo::TechnicalInfo) const
Returns the metainfo of this item.
Definition: kfileitem.cpp:1449
KIO::Job::removeSubjob
virtual bool removeSubjob(KJob *job)
Mark a sub job as being done.
Definition: job.cpp:118
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KUrl
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
KFileItem::Unknown
Definition: kfileitem.h:48
kservicetypetrader.h
KUrl::setProtocol
void setProtocol(const QString &proto)
QList::append
void append(const T &value)
KFileMetaInfo
KFileMetaInfo provides metadata extracted from a file or other resource.
Definition: kfilemetainfo.h:56
KIO::JobUiDelegate
A UI delegate tuned to be used with KIO Jobs.
Definition: jobuidelegate.h:39
KFileItemList
List of KFileItems, which adds a few helper methods to QList.
Definition: kfileitem.h:674
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
metainfojob.h
QList::first
T & first()
KUrl::path
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const
KIO::MetaInfoJob::removeItem
void removeItem(const KFileItem &item)
Removes an item from metainfo extraction.
Definition: metainfojob.cpp:77
QStringList
jobuidelegate.h
job_p.h
KUrl::List
kfilemetainfo.h
KIO::MetaInfoJob::gotMetaInfo
void gotMetaInfo(const KFileItem &item)
Emitted when the meta info for item has been successfully retrieved.
KIO::MetaInfoJob::~MetaInfoJob
virtual ~MetaInfoJob()
Definition: metainfojob.cpp:68
KIO::Job
The base class for all jobs.
Definition: jobclasses.h:94
KIO::NoReload
Definition: job.h:29
KCompositeJob::subjobs
const QList< KJob * > & subjobs() const
KCompositeJob::hasSubjobs
bool hasSubjobs()
KIO::TransferJob
The transfer job pumps data into and/or out of a Slave.
Definition: jobclasses.h:555
KIO::MetaInfoJob
MetaInfoJob is a KIO Job to retrieve meta information from files.
Definition: metainfojob.h:35
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KIO::JobPrivate
Definition: job_p.h:39
KFileItem::setMetaInfo
void setMetaInfo(const KFileMetaInfo &info) const
Sets the metainfo of this item to info.
Definition: kfileitem.cpp:1441
KJob
kfileitem.h
KFileItem::url
KUrl url() const
Returns the url of the file.
Definition: kfileitem.cpp:1543
KFileItem
A KFileItem is a generic class to handle a file, local or remote.
Definition: kfileitem.h:45
QTimer::singleShot
singleShot
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:53 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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