• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/kio
 

kio/kio

  • kio
  • kio
metainfojob.cpp
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  $Id$
21 */
22 
23 #include <kdatastream.h> // Do not remove, needed for correct bool serialization
24 #include <kfileitem.h>
25 #include <kdebug.h>
26 #include <kfilemetainfo.h>
27 #include <kio/kservice.h>
28 #include <kparts/componentfactory.h>
29 
30 #include <tqtimer.h>
31 
32 #include "metainfojob.moc"
33 
34 using namespace KIO;
35 
36 struct KIO::MetaInfoJobPrivate
37 {
38  KFileItemList items; // all the items we got
39  KFileItemListIterator* currentItem; // argh! No default constructor
40  bool deleteItems; // Delete the KFileItems when done?
41  bool succeeded; // if the current item is ok
42 };
43 
44 MetaInfoJob::MetaInfoJob(const KFileItemList &items, bool deleteItems)
45  : KIO::Job(false /* no GUI */)
46 {
47  d = new MetaInfoJobPrivate;
48  d->deleteItems = deleteItems;
49  d->succeeded = false;
50  d->items = items;
51  d->currentItem = new KFileItemListIterator(d->items);
52 
53  d->items.setAutoDelete(deleteItems);
54 
55  if (d->currentItem->isEmpty())
56  {
57  kdDebug(7007) << "nothing to do for the MetaInfoJob\n";
58  emitResult();
59  return;
60  }
61 
62  kdDebug(7007) << "starting MetaInfoJob\n";
63 
64  // Return to event loop first, determineNextFile() might delete this;
65  // (no idea what that means, it comes from previewjob)
66  TQTimer::singleShot(0, this, TQT_SLOT(start()));
67 }
68 
69 MetaInfoJob::~MetaInfoJob()
70 {
71  delete d->currentItem;
72  delete d;
73 }
74 
75 void MetaInfoJob::start()
76 {
77  getMetaInfo();
78 }
79 
80 void MetaInfoJob::removeItem(const KFileItem* item)
81 {
82  if (d->currentItem->current() == item)
83  {
84  subjobs.first()->kill();
85  subjobs.removeFirst();
86  determineNextFile();
87  }
88 
89  d->items.remove(d->items.find(item));
90 }
91 
92 void MetaInfoJob::determineNextFile()
93 {
94  if (d->currentItem->atLast())
95  {
96  kdDebug(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  if (d->currentItem->current()->metaInfo(false).isValid())
106  {
107 // kdDebug(7007) << "Is already valid *************************\n";
108  emit gotMetaInfo(d->currentItem->current());
109  determineNextFile();
110  return;
111  }
112 
113  getMetaInfo();
114 }
115 
116 void MetaInfoJob::slotResult( KIO::Job *job )
117 {
118  subjobs.remove(job);
119  Q_ASSERT(subjobs.isEmpty()); // We should have only one job at a time ...
120 
121  determineNextFile();
122 }
123 
124 void MetaInfoJob::getMetaInfo()
125 {
126  Q_ASSERT(!d->currentItem->isEmpty());
127 
128  KURL URL;
129  URL.setProtocol("metainfo");
130  URL.setPath(d->currentItem->current()->url().path());
131 
132  KIO::TransferJob* job = KIO::get(URL, false, false);
133  addSubjob(job);
134 
135  connect(job, TQT_SIGNAL(data(KIO::Job *, const TQByteArray &)),
136  this, TQT_SLOT(slotMetaInfo(KIO::Job *, const TQByteArray &)));
137 
138  job->addMetaData("mimeType", d->currentItem->current()->mimetype());
139 }
140 
141 
142 void MetaInfoJob::slotMetaInfo(KIO::Job*, const TQByteArray &data)
143 {
144  KFileMetaInfo info;
145  TQDataStream s(data, IO_ReadOnly);
146 
147  s >> info;
148 
149  d->currentItem->current()->setMetaInfo(info);
150  emit gotMetaInfo(d->currentItem->current());
151  d->succeeded = true;
152 }
153 
154 TQStringList MetaInfoJob::availablePlugins()
155 {
156  TQStringList result;
157  KTrader::OfferList plugins = KTrader::self()->query("KFilePlugin");
158  for (KTrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it)
159  result.append((*it)->desktopEntryName());
160  return result;
161 }
162 
163 TQStringList MetaInfoJob::supportedMimeTypes()
164 {
165  TQStringList result;
166  KTrader::OfferList plugins = KTrader::self()->query("KFilePlugin");
167  for (KTrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it)
168  result += (*it)->property("MimeTypes").toStringList();
169  return result;
170 }
171 
172 KIO_EXPORT MetaInfoJob *KIO::fileMetaInfo( const KFileItemList &items)
173 {
174  return new MetaInfoJob(items, false);
175 }
176 
177 KIO_EXPORT MetaInfoJob *KIO::fileMetaInfo( const KURL::List &items)
178 {
179  KFileItemList fileItems;
180  for (KURL::List::ConstIterator it = items.begin(); it != items.end(); ++it)
181  fileItems.append(new KFileItem(KFileItem::Unknown, KFileItem::Unknown, *it, true));
182  return new MetaInfoJob(fileItems, true);
183 }
184 
KIO::MetaInfoJob::MetaInfoJob
MetaInfoJob(const KFileItemList &items, bool deleteItems=false)
Creates a new MetaInfoJob.
Definition: metainfojob.cpp:44
KIO::MetaInfoJob::availablePlugins
static TQStringList availablePlugins()
Returns a list of all available metainfo plugins.
Definition: metainfojob.cpp:154
KIO
A namespace for KIO globals.
Definition: authinfo.h:29
KIO::MetaInfoJob::gotMetaInfo
void gotMetaInfo(const KFileItem *item)
Emitted when the meta info for item has been successfully retrieved.
KIO::fileMetaInfo
KIO_EXPORT MetaInfoJob * fileMetaInfo(const KFileItemList &items)
Retrieves meta information for the given items.
Definition: metainfojob.cpp:172
KIO::MetaInfoJob::supportedMimeTypes
static TQStringList supportedMimeTypes()
Returns a list of all supported MIME types.
Definition: metainfojob.cpp:163
KTrader::query
virtual OfferList query(const TQString &servicetype, const TQString &constraint=TQString::null, const TQString &preferences=TQString::null) const
The main function in the KTrader class.
Definition: ktrader.cpp:106
KIO::Job::addSubjob
virtual void addSubjob(Job *job, bool inheritMetaData=true)
Add a job that has to be finished before a result is emitted.
Definition: job.cpp:162
KFileMetaInfo
Meta Information about a file.
Definition: kfilemetainfo.h:926
KIO::Job::addMetaData
void addMetaData(const TQString &key, const TQString &value)
Add key/value pair to the meta data that is sent to the slave.
Definition: job.cpp:405
KIO::Job::emitResult
void emitResult()
Utility function to emit the result signal, and suicide this job.
Definition: job.cpp:228
KTrader::OfferList
TQValueList< KService::Ptr > OfferList
A list of services.
Definition: ktrader.h:92
KIO::MetaInfoJob::removeItem
void removeItem(const KFileItem *item)
Removes an item from metainfo extraction.
Definition: metainfojob.cpp:80
KTrader::self
static KTrader * self()
This is a static pointer to a KTrader instance.
Definition: ktrader.cpp:90
KIO::Job
The base class for all jobs.
Definition: jobclasses.h:68
KIO::TransferJob
The transfer job pumps data into and/or out of a Slave.
Definition: jobclasses.h:875
KIO::MetaInfoJob
MetaInfoJob is a KIO Job to retrieve meta information from files.
Definition: metainfojob.h:35
KIO::get
KIO_EXPORT TransferJob * get(const KURL &url, bool reload=false, bool showProgressInfo=true)
Get (a.k.a.
Definition: job.cpp:1220
KIO::Job::result
void result(KIO::Job *job)
Emitted when the job is finished, in any case (completed, canceled, failed...).
KFileItem
A KFileItem is a generic class to handle a file, local or remote.
Definition: kfileitem.h:41

kio/kio

Skip menu "kio/kio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kio/kio

Skip menu "kio/kio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kio by doxygen 1.8.13
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |