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

tdeio/tdeio

  • tdeio
  • tdeio
metainfojob.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation version 2.0.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 
18  $Id$
19 */
20 
21 #include <kdatastream.h> // Do not remove, needed for correct bool serialization
22 #include <tdefileitem.h>
23 #include <kdebug.h>
24 #include <tdefilemetainfo.h>
25 #include <tdeio/kservice.h>
26 #include <tdeparts/componentfactory.h>
27 
28 #include <tqtimer.h>
29 
30 #include "metainfojob.moc"
31 
32 using namespace TDEIO;
33 
34 struct TDEIO::MetaInfoJobPrivate
35 {
36  KFileItemList items; // all the items we got
37  KFileItemListIterator* currentItem; // argh! No default constructor
38  bool deleteItems; // Delete the KFileItems when done?
39  bool succeeded; // if the current item is ok
40 };
41 
42 MetaInfoJob::MetaInfoJob(const KFileItemList &items, bool deleteItems)
43  : TDEIO::Job(false /* no GUI */)
44 {
45  d = new MetaInfoJobPrivate;
46  d->deleteItems = deleteItems;
47  d->succeeded = false;
48  d->items = items;
49  d->currentItem = new KFileItemListIterator(d->items);
50 
51  d->items.setAutoDelete(deleteItems);
52 
53  if (d->currentItem->isEmpty())
54  {
55  kdDebug(7007) << "nothing to do for the MetaInfoJob\n";
56  emitResult();
57  return;
58  }
59 
60  kdDebug(7007) << "starting MetaInfoJob\n";
61 
62  // Return to event loop first, determineNextFile() might delete this;
63  // (no idea what that means, it comes from previewjob)
64  TQTimer::singleShot(0, this, TQT_SLOT(start()));
65 }
66 
67 MetaInfoJob::~MetaInfoJob()
68 {
69  delete d->currentItem;
70  delete d;
71 }
72 
73 void MetaInfoJob::start()
74 {
75  getMetaInfo();
76 }
77 
78 void MetaInfoJob::removeItem(const KFileItem* item)
79 {
80  if (d->currentItem->current() == item)
81  {
82  subjobs.first()->kill();
83  subjobs.removeFirst();
84  determineNextFile();
85  }
86 
87  d->items.remove(d->items.find(item));
88 }
89 
90 void MetaInfoJob::determineNextFile()
91 {
92  if (d->currentItem->atLast())
93  {
94  kdDebug(7007) << "finished MetaInfoJob\n";
95  emitResult();
96  return;
97  }
98 
99  ++(*d->currentItem);
100  d->succeeded = false;
101 
102  // does the file item already have the needed info? Then shortcut
103  if (d->currentItem->current()->metaInfo(false).isValid())
104  {
105 // kdDebug(7007) << "Is already valid *************************\n";
106  emit gotMetaInfo(d->currentItem->current());
107  determineNextFile();
108  return;
109  }
110 
111  getMetaInfo();
112 }
113 
114 void MetaInfoJob::slotResult( TDEIO::Job *job )
115 {
116  subjobs.remove(job);
117  Q_ASSERT(subjobs.isEmpty()); // We should have only one job at a time ...
118 
119  determineNextFile();
120 }
121 
122 void MetaInfoJob::getMetaInfo()
123 {
124  Q_ASSERT(!d->currentItem->isEmpty());
125 
126  KURL URL;
127  URL.setProtocol("metainfo");
128  URL.setPath(d->currentItem->current()->url().path());
129 
130  TDEIO::TransferJob* job = TDEIO::get(URL, false, false);
131  addSubjob(job);
132 
133  connect(job, TQT_SIGNAL(data(TDEIO::Job *, const TQByteArray &)),
134  this, TQT_SLOT(slotMetaInfo(TDEIO::Job *, const TQByteArray &)));
135 
136  job->addMetaData("mimeType", d->currentItem->current()->mimetype());
137 }
138 
139 
140 void MetaInfoJob::slotMetaInfo(TDEIO::Job*, const TQByteArray &data)
141 {
142  KFileMetaInfo info;
143  TQDataStream s(data, IO_ReadOnly);
144 
145  s >> info;
146 
147  d->currentItem->current()->setMetaInfo(info);
148  emit gotMetaInfo(d->currentItem->current());
149  d->succeeded = true;
150 }
151 
152 TQStringList MetaInfoJob::availablePlugins()
153 {
154  TQStringList result;
155  TDETrader::OfferList plugins = TDETrader::self()->query("KFilePlugin");
156  for (TDETrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it)
157  result.append((*it)->desktopEntryName());
158  return result;
159 }
160 
161 TQStringList MetaInfoJob::supportedMimeTypes()
162 {
163  TQStringList result;
164  TDETrader::OfferList plugins = TDETrader::self()->query("KFilePlugin");
165  for (TDETrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it)
166  result += (*it)->property("MimeTypes").toStringList();
167  return result;
168 }
169 
170 TDEIO_EXPORT MetaInfoJob *TDEIO::fileMetaInfo( const KFileItemList &items)
171 {
172  return new MetaInfoJob(items, false);
173 }
174 
175 TDEIO_EXPORT MetaInfoJob *TDEIO::fileMetaInfo( const KURL::List &items)
176 {
177  KFileItemList fileItems;
178  for (KURL::List::ConstIterator it = items.begin(); it != items.end(); ++it)
179  fileItems.append(new KFileItem(KFileItem::Unknown, KFileItem::Unknown, *it, true));
180  return new MetaInfoJob(fileItems, true);
181 }
182 
TDEIO::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
TDETrader::self
static TDETrader * self()
This is a static pointer to a TDETrader instance.
Definition: ktrader.cpp:90
TDEIO::MetaInfoJob::removeItem
void removeItem(const KFileItem *item)
Removes an item from metainfo extraction.
Definition: metainfojob.cpp:78
TDEIO::fileMetaInfo
TDEIO_EXPORT MetaInfoJob * fileMetaInfo(const KFileItemList &items)
Retrieves meta information for the given items.
Definition: metainfojob.cpp:170
TDEIO
A namespace for TDEIO globals.
Definition: authinfo.h:29
TDEIO::MetaInfoJob::MetaInfoJob
MetaInfoJob(const KFileItemList &items, bool deleteItems=false)
Creates a new MetaInfoJob.
Definition: metainfojob.cpp:42
TDEIO::Job
The base class for all jobs.
Definition: jobclasses.h:67
TDEIO::MetaInfoJob::supportedMimeTypes
static TQStringList supportedMimeTypes()
Returns a list of all supported MIME types.
Definition: metainfojob.cpp:161
TDETrader::query
virtual OfferList query(const TQString &servicetype, const TQString &constraint=TQString::null, const TQString &preferences=TQString::null) const
The main function in the TDETrader class.
Definition: ktrader.cpp:106
KFileMetaInfo
Meta Information about a file.
Definition: tdefilemetainfo.h:926
TDEIO::MetaInfoJob::gotMetaInfo
void gotMetaInfo(const KFileItem *item)
Emitted when the meta info for item has been successfully retrieved.
TDEIO::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
TDEIO::get
TDEIO_EXPORT TransferJob * get(const KURL &url, bool reload=false, bool showProgressInfo=true)
Get (a.k.a.
Definition: job.cpp:1255
TDEIO::MetaInfoJob
MetaInfoJob is a TDEIO Job to retrieve meta information from files.
Definition: metainfojob.h:33
TDEIO::Job::result
void result(TDEIO::Job *job)
Emitted when the job is finished, in any case (completed, canceled, failed...).
TDETrader::OfferList
TQValueList< KService::Ptr > OfferList
A list of services.
Definition: ktrader.h:92
TDEIO::MetaInfoJob::availablePlugins
static TQStringList availablePlugins()
Returns a list of all available metainfo plugins.
Definition: metainfojob.cpp:152
TDEIO::TransferJob
The transfer job pumps data into and/or out of a Slave.
Definition: jobclasses.h:874
TDEIO::Job::emitResult
void emitResult()
Utility function to emit the result signal, and suicide this job.
Definition: job.cpp:228
KFileItem
A KFileItem is a generic class to handle a file, local or remote.
Definition: tdefileitem.h:41

tdeio/tdeio

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

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.8.8
This website is maintained by Timothy Pearson.