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

tdeio/tdeio

  • tdeio
  • tdeio
tdefilemetainfo.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (C) 2001-2002 Rolf Magnus <ramagnus@kde.org>
4 * Copyright (C) 2001-2002 Carsten Pfeiffer <pfeiffer@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 <assert.h>
24
25#include <tqshared.h>
26#include <tqdict.h>
27
28#include <ktrader.h>
29#include <kstaticdeleter.h>
30#include <tdeparts/componentfactory.h>
31#include <kuserprofile.h>
32#include <kdebug.h>
33#include <kmimetype.h>
34#include <kdatastream.h> // needed for serialization of bool
35#include <tdelocale.h>
36#include <tdeio/global.h>
37
38#include "tdefilemetainfo.h"
39
40// shared data of a KFileMetaInfoItem
41class KFileMetaInfoItem::Data : public TQShared
42{
43public:
44 Data( const KFileMimeTypeInfo::ItemInfo* mti, const TQString& _key,
45 const TQVariant& _value )
46 : TQShared(),
47 mimeTypeInfo( mti ),
48 key( _key ),
49 value( _value ),
50 dirty( false ),
51 added( false ),
52 removed( false )
53 {}
54
55 // we use this one for the streaming operators
56 Data() : mimeTypeInfo( 0L )
57 {}
58
59 ~Data()
60 {
61 if ( this == null ) // only the null item owns its mimeTypeInfo
62 delete mimeTypeInfo;
63 }
64
65 const KFileMimeTypeInfo::ItemInfo* mimeTypeInfo;
66 // mimeTypeInfo has the key, too, but only for non-variable ones
67 TQString key;
68 TQVariant value;
69 bool dirty :1;
70 bool added :1;
71 bool removed :1;
72
73 static Data* null;
74 static Data* makeNull();
75};
76
77//this is our null data
78KFileMetaInfoItem::Data* KFileMetaInfoItem::Data::null = 0L;
79static KStaticDeleter<KFileMetaInfoItem::Data> sd_KFileMetaInfoItemData;
80
81KFileMetaInfoItem::Data* KFileMetaInfoItem::Data::makeNull()
82{
83 if (!null)
84 {
85 // We deliberately do not reset "null" after it has been destroyed!
86 // Otherwise we will run into problems later in ~KFileMetaInfoItem
87 // where the d-pointer is compared against null.
88
89 KFileMimeTypeInfo::ItemInfo* info = new KFileMimeTypeInfo::ItemInfo();
90 null = new Data(info, TQString::null, TQVariant());
91 sd_KFileMetaInfoItemData.setObject( null );
92 }
93 return null;
94}
95
96KFileMetaInfoItem::KFileMetaInfoItem( const KFileMimeTypeInfo::ItemInfo* mti,
97 const TQString& key, const TQVariant& value )
98 : d( new Data( mti, key, value ) )
99{
100}
101
102KFileMetaInfoItem::KFileMetaInfoItem( const KFileMetaInfoItem& item )
103{
104 // operator= does everything that's necessary
105 d = Data::makeNull();
106 *this = item;
107}
108
109KFileMetaInfoItem::KFileMetaInfoItem()
110{
111 d = Data::makeNull();
112}
113
114KFileMetaInfoItem::~KFileMetaInfoItem()
115{
116 deref();
117}
118
119const KFileMetaInfoItem& KFileMetaInfoItem::operator=
120 (const KFileMetaInfoItem & item )
121{
122 if (d != item.d)
123 {
124 // first deref the old one
125 deref();
126 d = item.d;
127 // and now ref the new one
128 ref();
129 }
130
131 return *this;
132}
133
134bool KFileMetaInfoItem::setValue( const TQVariant& value )
135{
136 // We don't call makeNull here since it isn't necassery, see deref()
137 if ( d == Data::null ) return false;
138
139 if ( ! (d->mimeTypeInfo->attributes() & KFileMimeTypeInfo::Modifiable ) ||
140 ! (value.canCast(d->mimeTypeInfo->type())))
141 {
142 kdDebug(7033) << "setting the value of " << key() << "failed\n";
143 return false;
144 }
145
146// kdDebug(7033) << key() << ".setValue()\n";
147
148 if ( d->value == value )
149 return true;
150
151 d->dirty = true;
152 d->value = value;
153 // If we don't cast (and test for canCast in the above if), TQVariant is
154 // very picky about types (e.g. TQString vs. TQCString or int vs. uint)
155 d->value.cast(d->mimeTypeInfo->type());
156
157 return true;
158}
159
160bool KFileMetaInfoItem::isRemoved() const
161{
162 return d->removed;
163}
164
165TQString KFileMetaInfoItem::key() const
166{
167 return d->key;
168}
169
170TQString KFileMetaInfoItem::translatedKey() const
171{
172 // are we a variable key?
173 if (d->mimeTypeInfo->key().isNull())
174 {
175 // then try if we have luck with i18n()
176 return i18n(d->key.utf8());
177 }
178
179 return d->mimeTypeInfo->translatedKey();
180}
181
182const TQVariant& KFileMetaInfoItem::value() const
183{
184 return d->value;
185}
186
187TQString KFileMetaInfoItem::string( bool mangle ) const
188{
189 return d->mimeTypeInfo->string(d->value, mangle);
190}
191
192TQVariant::Type KFileMetaInfoItem::type() const
193{
194 return d->mimeTypeInfo->type();
195}
196
197uint KFileMetaInfoItem::unit() const
198{
199 return d->mimeTypeInfo->unit();
200}
201
202bool KFileMetaInfoItem::isModified() const
203{
204 return d->dirty;
205}
206
207TQString KFileMetaInfoItem::prefix() const
208{
209 return d->mimeTypeInfo->prefix();
210}
211
212TQString KFileMetaInfoItem::suffix() const
213{
214 return d->mimeTypeInfo->suffix();
215}
216
217uint KFileMetaInfoItem::hint() const
218{
219 return d->mimeTypeInfo->hint();
220}
221
222uint KFileMetaInfoItem::attributes() const
223{
224 return d->mimeTypeInfo->attributes();
225}
226
227bool KFileMetaInfoItem::isEditable() const
228{
229 return d->mimeTypeInfo->attributes() & KFileMimeTypeInfo::Modifiable;
230}
231
232bool KFileMetaInfoItem::isValid() const
233{
234 // We don't call makeNull here since it isn't necassery:
235 // If d is equal to null it means that null is initialized already.
236 // null is 0L when it hasn't been initialized and d is never 0L.
237 return d != Data::null;
238}
239
240void KFileMetaInfoItem::setAdded()
241{
242 d->added = true;
243}
244
245void KFileMetaInfoItem::setRemoved()
246{
247 d->removed = true;
248}
249
250void KFileMetaInfoItem::ref()
251{
252 if (d != Data::null) d->ref();
253}
254
255void KFileMetaInfoItem::deref()
256{
257 // We don't call makeNull here since it isn't necassery:
258 // If d is equal to null it means that null is initialized already.
259 // null is 0L when it hasn't been initialized and d is never 0L.
260 if ((d != Data::null) && d->deref())
261 {
262// kdDebug(7033) << "item " << d->key
263// << " is finally deleted\n";
264 delete d;
265 d = 0;
266 }
267}
268
271
272// shared data of a KFileMetaInfo
273class KFileMetaInfo::Data : public TQShared
274{
275public:
276 Data(const KURL& _url, uint _what)
277 : TQShared(),
278 url(_url),
279 what(_what),
280 mimeTypeInfo( 0L )
281 {}
282
283 // wee use this one for the streaming operators
284 Data() {};
285
286 KURL url;
287 uint what;
288 TQMap<TQString, KFileMetaInfoGroup> groups;
289 const KFileMimeTypeInfo* mimeTypeInfo;
290 TQStringList removedGroups;
291
292 static Data* null;
293 static Data* makeNull();
294
295};
296
297KFileMetaInfo::KFileMetaInfo( const TQString& path, const TQString& mimeType,
298 uint what )
299{
300 KURL u;
301
302 u.setPath(path);
303 init(u, mimeType, what);
304}
305
306KFileMetaInfo::KFileMetaInfo( const KURL& url, const TQString& mimeType,
307 uint what )
308{
309 init(url, mimeType, what);
310}
311
312void KFileMetaInfo::init( const KURL& url, const TQString& mimeType,
313 uint what )
314{
315 d = new Data( url, what );
316
317 TQString mT;
318 if (mimeType.isEmpty())
319 mT = KMimeType::findByURL(url)->name();
320 else
321 mT = mimeType;
322
323 // let's "share our property"
324 KFileMetaInfo item(*this);
325
326 //kdDebug() << k_funcinfo << mT << " " << url << endl;
327
328 d->mimeTypeInfo = KFileMetaInfoProvider::self()->mimeTypeInfo( mT, url.protocol() );
329 if ( d->mimeTypeInfo )
330 {
331 //kdDebug(7033) << "Found mimetype info for " << mT /* or protocol*/ << endl;
332 KFilePlugin *p = plugin();
333 Q_ASSERT( p );
334 if ( p && !p->readInfo( item, what) )
335 {
336 deref();
337 d = Data::makeNull();
338 }
339 }
340 else
341 {
342// kdDebug(7033) << "No mimetype info for " << mimeType << endl;
343 deref();
344 d = Data::makeNull();
345 }
346}
347
348KFileMetaInfo::KFileMetaInfo( const KFileMetaInfo& original )
349{
350 // operator= does everything that's necessary
351 d = Data::makeNull();
352 *this = original;
353}
354
355KFileMetaInfo::KFileMetaInfo()
356{
357 d = Data::makeNull();
358}
359
360KFileMetaInfo::~KFileMetaInfo()
361{
362 deref();
363}
364
365TQStringList KFileMetaInfo::supportedGroups() const
366{
367 assert(isValid());
368 return d->mimeTypeInfo->supportedGroups();
369}
370
371TQStringList KFileMetaInfo::supportedKeys() const
372{
373 assert(isValid());
374 return d->mimeTypeInfo->supportedKeys();
375}
376
377TQStringList KFileMetaInfo::groups() const
378{
379 TQStringList list;
380 TQMapConstIterator<TQString, KFileMetaInfoGroup> it = d->groups.begin();
381 for ( ; it != d->groups.end(); ++it )
382 list += (*it).name();
383
384 return list;
385}
386
387TQStringList KFileMetaInfo::editableGroups() const
388{
389 TQStringList list;
390 TQStringList supported = supportedGroups();
391 TQStringList::ConstIterator it = supported.begin();
392 for ( ; it != supported.end(); ++it ) {
393 const KFileMimeTypeInfo::GroupInfo * groupInfo = d->mimeTypeInfo->groupInfo( *it );
394 if ( groupInfo && groupInfo->attributes() &
395 (KFileMimeTypeInfo::Addable | KFileMimeTypeInfo::Removable) )
396 list.append( *it );
397 }
398
399 return list;
400}
401
402TQStringList KFileMetaInfo::preferredGroups() const
403{
404 assert(isValid());
405 TQStringList list = groups();
406 TQStringList newlist;
407 TQStringList preferred = d->mimeTypeInfo->preferredGroups();
408 TQStringList::Iterator pref;
409
410 // move all keys from the preferred groups that are in our list to a new list
411 for ( pref = preferred.begin(); pref != preferred.end(); ++pref )
412 {
413 TQStringList::Iterator group = list.find(*pref);
414 if ( group != list.end() )
415 {
416 newlist.append( *group );
417 list.remove(group);
418 }
419 }
420
421 // now the old list only contains the non-preferred items, so we
422 // add the remaining ones to newlist
423 newlist += list;
424
425 return newlist;
426}
427
428TQStringList KFileMetaInfo::preferredKeys() const
429{
430 TQStringList newlist;
431
432 TQStringList list = preferredGroups();
433 for (TQStringList::Iterator git = list.begin(); git != list.end(); ++git)
434 {
435 newlist += d->groups[*git].preferredKeys();
436 }
437
438 return newlist;
439}
440
441KFileMetaInfoGroup KFileMetaInfo::group(const TQString& key) const
442{
443 TQMapIterator<TQString,KFileMetaInfoGroup> it = d->groups.find( key );
444 if ( it != d->groups.end() )
445 return it.data();
446 else
447 return KFileMetaInfoGroup();
448}
449
450bool KFileMetaInfo::addGroup( const TQString& name )
451{
452 assert(isValid());
453 if ( d->mimeTypeInfo->supportedGroups().contains(name) &&
454 ! d->groups.contains(name) )
455 {
456 KFileMetaInfoGroup group( name, d->mimeTypeInfo );
457
458 // add all the items that can't be added by the user later
459 const KFileMimeTypeInfo::GroupInfo* ginfo = d->mimeTypeInfo->groupInfo(name);
460 Q_ASSERT(ginfo);
461 if (!ginfo) return false;
462
463 TQStringList keys = ginfo->supportedKeys();
464 for (TQStringList::Iterator it = keys.begin(); it != keys.end(); ++it)
465 {
466 const KFileMimeTypeInfo::ItemInfo* iteminfo = ginfo->itemInfo(*it);
467 Q_ASSERT(ginfo);
468 if (!iteminfo) return false;
469
470 if ( !(iteminfo->attributes() & KFileMimeTypeInfo::Addable) &&
471 (iteminfo->attributes() & KFileMimeTypeInfo::Modifiable))
472 {
473 // append it now or never
474 group.appendItem(iteminfo->key(), TQVariant());
475 }
476
477 }
478
479 d->groups.insert(name, group);
480 group.setAdded();
481 return true;
482 }
483
484 return false;
485}
486
487bool KFileMetaInfo::removeGroup( const TQString& name )
488{
489 TQMapIterator<TQString, KFileMetaInfoGroup> it = d->groups.find(name);
490 if ( (it==d->groups.end()) ||
491 !((*it).attributes() & KFileMimeTypeInfo::Removable))
492 return false;
493
494 d->groups.remove(it);
495 d->removedGroups.append(name);
496 return true;
497}
498
499TQStringList KFileMetaInfo::removedGroups()
500{
501 return d->removedGroups;
502}
503
504const KFileMetaInfo& KFileMetaInfo::operator= (const KFileMetaInfo& info )
505{
506 if (d != info.d)
507 {
508 deref();
509 // first deref the old one
510 d = info.d;
511 // and now ref the new one
512 ref();
513 }
514 return *this;
515}
516
517bool KFileMetaInfo::isValid() const
518{
519 // We don't call makeNull here since it isn't necassery, see deref()
520 return d != Data::null;
521}
522
523bool KFileMetaInfo::isEmpty() const
524{
525 for (TQMapIterator<TQString, KFileMetaInfoGroup> it = d->groups.begin();
526 it!=d->groups.end(); ++it)
527 if (!(*it).isEmpty())
528 return false;
529 return true;
530}
531
532bool KFileMetaInfo::applyChanges()
533{
534 return applyChanges( path() );
535}
536
537bool KFileMetaInfo::applyChanges( const TQString& path )
538{
539 bool doit = false;
540
541// kdDebug(7033) << "KFileMetaInfo::applyChanges()\n";
542
543 // look up if we need to write to the file
544 TQMapConstIterator<TQString, KFileMetaInfoGroup> it;
545 for (it = d->groups.begin(); it!=d->groups.end() && !doit; ++it)
546 {
547 if ( (*it).isModified() )
548 doit = true;
549
550 else
551 {
552 TQStringList keys = it.data().keys();
553 for (TQStringList::Iterator it2 = keys.begin(); it2!=keys.end(); ++it2)
554 {
555 if ( (*it)[*it2].isModified() )
556 {
557 doit = true;
558 break;
559 }
560 }
561 }
562 }
563
564 if (!doit)
565 {
566 kdDebug(7033) << "Don't need to write, nothing changed\n";
567 return true;
568 }
569
570 KFilePlugin* p = plugin();
571 if (!p) return false;
572
573// kdDebug(7033) << "Ok, trying to write the info\n";
574
575 KURL savedURL = url();
576 d->url = KURL();
577 d->url.setPath( path );
578
579 bool ret = p->writeInfo(*this);
580
581 d->url = savedURL;
582 return ret;
583}
584
585KFilePlugin * KFileMetaInfo::plugin() const
586{
587 assert(isValid());
588 KFileMetaInfoProvider* prov = KFileMetaInfoProvider::self();
589 return prov->plugin( d->mimeTypeInfo->mimeType(), d->url.protocol() );
590}
591
592TQString KFileMetaInfo::mimeType() const
593{
594 assert(isValid());
595 return d->mimeTypeInfo->mimeType();
596}
597
598bool KFileMetaInfo::contains(const TQString& key) const
599{
600 TQStringList glist = groups();
601 for (TQStringList::Iterator it = glist.begin(); it != glist.end(); ++it)
602 {
603 KFileMetaInfoGroup g = d->groups[*it];
604 if (g.contains(key)) return true;
605 }
606 return false;
607}
608
609bool KFileMetaInfo::containsGroup(const TQString& key) const
610{
611 return groups().contains(key);
612}
613
614KFileMetaInfoItem KFileMetaInfo::item( const TQString& key) const
615{
616 TQStringList groups = preferredGroups();
617 for (TQStringList::Iterator it = groups.begin(); it != groups.end(); ++it)
618 {
619 KFileMetaInfoItem i = d->groups[*it][key];
620 if (i.isValid()) return i;
621 }
622 return KFileMetaInfoItem();
623}
624
625KFileMetaInfoItem KFileMetaInfo::item(const KFileMetaInfoItem::Hint hint) const
626{
627 TQStringList groups = preferredGroups();
628 TQStringList::ConstIterator it;
629 for (it = groups.begin(); it != groups.end(); ++it)
630 {
631 KFileMetaInfoItem i = d->groups[*it].item(hint);
632 if (i.isValid()) return i;
633 }
634 return KFileMetaInfoItem();
635}
636
637KFileMetaInfoItem KFileMetaInfo::saveItem( const TQString& key,
638 const TQString& preferredGroup,
639 bool createGroup )
640{
641 assert(isValid());
642 // try the preferred groups first
643 if ( !preferredGroup.isEmpty() ) {
644 TQMapIterator<TQString,KFileMetaInfoGroup> it =
645 d->groups.find( preferredGroup );
646
647 // try to create the preferred group, if necessary
648 if ( it == d->groups.end() && createGroup ) {
649 const KFileMimeTypeInfo::GroupInfo *groupInfo =
650 d->mimeTypeInfo->groupInfo( preferredGroup );
651 if ( groupInfo && groupInfo->supportedKeys().contains( key ) ) {
652 if ( addGroup( preferredGroup ) )
653 it = d->groups.find( preferredGroup );
654 }
655 }
656
657 if ( it != d->groups.end() ) {
658 KFileMetaInfoItem item = it.data().addItem( key );
659 if ( item.isValid() )
660 return item;
661 }
662 }
663
664 TQStringList groups = preferredGroups();
665
666 KFileMetaInfoItem item;
667
668 TQStringList::ConstIterator groupIt = groups.begin();
669 for ( ; groupIt != groups.end(); ++groupIt )
670 {
671 TQMapIterator<TQString,KFileMetaInfoGroup> it = d->groups.find( *groupIt );
672 if ( it != d->groups.end() )
673 {
674 KFileMetaInfoGroup group = it.data();
675 item = findEditableItem( group, key );
676 if ( item.isValid() )
677 return item;
678 }
679 else // not existant -- try to create the group
680 {
681 const KFileMimeTypeInfo::GroupInfo *groupInfo =
682 d->mimeTypeInfo->groupInfo( *groupIt );
683 if ( groupInfo && groupInfo->supportedKeys().contains( key ) )
684 {
685 if ( addGroup( *groupIt ) )
686 {
687 KFileMetaInfoGroup group = d->groups[*groupIt];
688 KFileMetaInfoItem item = group.addItem( key );
689 if ( item.isValid() )
690 return item;
691// else ### add when removeGroup() is implemented :)
692// removeGroup( *groupIt ); // couldn't add item -> remove
693 }
694 }
695 }
696 }
697
698 // finally check for variable items
699
700 return item;
701}
702
703KFileMetaInfoItem KFileMetaInfo::findEditableItem( KFileMetaInfoGroup& group,
704 const TQString& key )
705{
706 assert(isValid());
707 KFileMetaInfoItem item = group.addItem( key );
708 if ( item.isValid() && item.isEditable() )
709 return item;
710
711 if ( (d->mimeTypeInfo->groupInfo( group.name() )->attributes() & KFileMimeTypeInfo::Addable) )
712 return item;
713
714 return KFileMetaInfoItem();
715}
716
717KFileMetaInfoGroup KFileMetaInfo::appendGroup(const TQString& name)
718{
719 assert(isValid());
720 if ( d->mimeTypeInfo->supportedGroups().contains(name) &&
721 ! d->groups.contains(name) )
722 {
723 KFileMetaInfoGroup group( name, d->mimeTypeInfo );
724 d->groups.insert(name, group);
725 return group;
726 }
727
728 else {
729 kdWarning(7033) << "Someone's trying to add a KFileMetaInfoGroup which is not supported or already existing: " << name << endl;
730 return KFileMetaInfoGroup();
731 }
732}
733
734TQString KFileMetaInfo::path() const
735{
736 return d->url.isLocalFile() ? d->url.path() : TQString::null;
737}
738
739KURL KFileMetaInfo::url() const
740{
741 return d->url;
742}
743
744void KFileMetaInfo::ref()
745{
746 if (d != Data::null) d->ref();
747
748}
749
750void KFileMetaInfo::deref()
751{
752 // We don't call makeNull here since it isn't necassery:
753 // If d is equal to null it means that null is initialized already.
754 // null is 0L when it hasn't been initialized and d is never 0L.
755 if ((d != Data::null) && d->deref())
756 {
757// kdDebug(7033) << "metainfo object for " << d->url.path << " is finally deleted\n";
758 delete d;
759 d = 0;
760 }
761
762}
763
764
765KFileMetaInfo::Data* KFileMetaInfo::Data::null = 0L;
766static KStaticDeleter<KFileMetaInfo::Data> sd_KFileMetaInfoData;
767
768KFileMetaInfo::Data* KFileMetaInfo::Data::makeNull()
769{
770 if (!null)
771 // We deliberately do not reset "null" after it has been destroyed!
772 // Otherwise we will run into problems later in ~KFileMetaInfoItem
773 // where the d-pointer is compared against null.
774 null = sd_KFileMetaInfoData.setObject( new KFileMetaInfo::Data(KURL(), 0) );
775 return null;
776}
777
780
781KFilePlugin::KFilePlugin( TQObject *parent, const char *name,
782 const TQStringList& /*args*/)
783 : TQObject( parent, name )
784{
785// kdDebug(7033) << "loaded a plugin for " << name << endl;
786}
787
788KFilePlugin::~KFilePlugin()
789{
790// kdDebug(7033) << "unloaded a plugin for " << name() << endl;
791}
792
793KFileMimeTypeInfo * KFilePlugin::addMimeTypeInfo( const TQString& mimeType )
794{
795 return KFileMetaInfoProvider::self()->addMimeTypeInfo( mimeType );
796}
797
798void KFilePlugin::virtual_hook( int, void* )
799{ /*BASE::virtual_hook( id, data );*/ }
800
801
802KFileMimeTypeInfo::GroupInfo* KFilePlugin::addGroupInfo(KFileMimeTypeInfo* info,
803 const TQString& key, const TQString& translatedKey) const
804{
805 return info->addGroupInfo(key, translatedKey);
806}
807
808void KFilePlugin::setAttributes(KFileMimeTypeInfo::GroupInfo* gi, uint attr) const
809{
810 gi->m_attr = attr;
811}
812
813void KFilePlugin::addVariableInfo(KFileMimeTypeInfo::GroupInfo* gi,
814 TQVariant::Type type, uint attr) const
815{
816 gi->addVariableInfo(type, attr);
817}
818
819KFileMimeTypeInfo::ItemInfo* KFilePlugin::addItemInfo(KFileMimeTypeInfo::GroupInfo* gi,
820 const TQString& key,
821 const TQString& translatedKey,
822 TQVariant::Type type)
823{
824 return gi->addItemInfo(key, translatedKey, type);
825}
826
827void KFilePlugin::setAttributes(KFileMimeTypeInfo::ItemInfo* item, uint attr)
828{
829 item->m_attr = attr;
830}
831
832void KFilePlugin::setHint(KFileMimeTypeInfo::ItemInfo* item, uint hint)
833{
834 item->m_hint = hint;
835}
836
837void KFilePlugin::setUnit(KFileMimeTypeInfo::ItemInfo* item, uint unit)
838{
839 item->m_unit = unit;
840 // set prefix and suffix
841 switch (unit)
842 {
843 case KFileMimeTypeInfo::Seconds:
844 item->m_suffix = i18n("s"); break;
845
846 case KFileMimeTypeInfo::MilliSeconds:
847 item->m_suffix = i18n("ms"); break;
848
849 case KFileMimeTypeInfo::BitsPerSecond:
850 item->m_suffix = i18n("bps"); break;
851
852 case KFileMimeTypeInfo::Pixels:
853 item->m_suffix = i18n("pixels"); break;
854
855 case KFileMimeTypeInfo::Inches:
856 item->m_suffix = i18n("in"); break;
857
858 case KFileMimeTypeInfo::Centimeters:
859 item->m_suffix = i18n("cm"); break;
860
861 case KFileMimeTypeInfo::Bytes:
862 item->m_suffix = i18n("B"); break;
863
864 case KFileMimeTypeInfo::KiloBytes:
865 item->m_suffix = i18n("KB"); break;
866
867 case KFileMimeTypeInfo::FramesPerSecond:
868 item->m_suffix = i18n("fps"); break;
869
870 case KFileMimeTypeInfo::DotsPerInch:
871 item->m_suffix = i18n("dpi"); break;
872
873 case KFileMimeTypeInfo::BitsPerPixel:
874 item->m_suffix = i18n("bpp"); break;
875
876 case KFileMimeTypeInfo::Hertz:
877 item->m_suffix = i18n("Hz"); break;
878
879 case KFileMimeTypeInfo::Millimeters:
880 item->m_suffix = i18n("mm");
881 }
882}
883
884void KFilePlugin::setPrefix(KFileMimeTypeInfo::ItemInfo* item, const TQString& prefix)
885{
886 item->m_prefix = prefix;
887}
888
889void KFilePlugin::setSuffix(KFileMimeTypeInfo::ItemInfo* item, const TQString& suffix)
890{
891 item->m_suffix = suffix;
892}
893
894KFileMetaInfoGroup KFilePlugin::appendGroup(KFileMetaInfo& info, const TQString& key)
895{
896 return info.appendGroup(key);
897}
898
899void KFilePlugin::appendItem(KFileMetaInfoGroup& group, const TQString& key, TQVariant value)
900{
901 group.appendItem(key, value);
902}
903
906
907
908KFileMetaInfoProvider * KFileMetaInfoProvider::s_self;
909static KStaticDeleter<KFileMetaInfoProvider> sd;
910
911KFileMetaInfoProvider * KFileMetaInfoProvider::self()
912{
913 if ( !s_self )
914 s_self = sd.setObject( s_self, new KFileMetaInfoProvider() );
915
916 return s_self;
917}
918
919KFileMetaInfoProvider::KFileMetaInfoProvider()
920{
921 m_plugins.setAutoDelete( true );
922}
923
924KFileMetaInfoProvider::~KFileMetaInfoProvider()
925{
926 m_plugins.clear();
927 sd.setObject( 0 );
928}
929
930KFilePlugin* KFileMetaInfoProvider::loadPlugin( const TQString& mimeType, const TQString& protocol )
931{
932 //kdDebug() << "loadPlugin: mimeType=" << mimeType << " protocol=" << protocol << endl;
933 // Currently the idea is: either the mimetype is set or the protocol, but not both.
934 // We need PNG fileinfo, and trash: fileinfo, but not "PNG in the trash".
935 TQString queryMimeType, query;
936 if ( !mimeType.isEmpty() ) {
937 query = "(not exist [X-TDE-Protocol])";
938 queryMimeType = mimeType;
939 } else {
940 query = TQString::fromLatin1( "[X-TDE-Protocol] == '%1'" ).arg(protocol);
941 // querying for a protocol: we have no mimetype, so we need to use KFilePlugin as one
942 queryMimeType = "KFilePlugin";
943 // hopefully using KFilePlugin as genericMimeType too isn't a problem
944 }
945 const TDETrader::OfferList offers = TDETrader::self()->query( queryMimeType, "KFilePlugin", query, TQString::null );
946 if ( offers.isEmpty() )
947 return 0;
948 KService::Ptr service = *(offers.begin());
949 Q_ASSERT( service && service->isValid() );
950 if ( !service || !service->isValid() )
951 return 0;
952
953 KFilePlugin* plugin = KParts::ComponentFactory::createInstanceFromService<KFilePlugin>
954 ( service, this, mimeType.local8Bit() );
955 if (!plugin)
956 kdWarning(7033) << "error loading the plugin from " << service->desktopEntryPath() << endl;
957
958 return plugin;
959}
960
961KFilePlugin* KFileMetaInfoProvider::loadAndRegisterPlugin( const TQString& mimeType, const TQString& protocol )
962{
963 Q_ASSERT( m_pendingMimetypeInfos.isEmpty() );
964 m_pendingMimetypeInfos.clear();
965
966 KFilePlugin* plugin = loadPlugin( mimeType, protocol );
967 if ( !plugin ) {
968 // No plugin found. Remember that, to save time.
969 m_plugins.insert( protocol.isEmpty() ? mimeType : protocol, new CachedPluginInfo );
970 return 0;
971 }
972
973 if ( !protocol.isEmpty() ) {
974 // Protocol-metainfo: only one entry
975 Q_ASSERT( m_pendingMimetypeInfos.count() == 1 );
976 KFileMimeTypeInfo* info = m_pendingMimetypeInfos[ protocol ];
977 Q_ASSERT( info );
978 m_plugins.insert( protocol, new CachedPluginInfo( plugin, info, true ) );
979 } else {
980 // Mimetype-metainfo: the plugin can register itself for multiple mimetypes, remember them all
981 bool first = true;
982 TQDictIterator<KFileMimeTypeInfo> it( m_pendingMimetypeInfos );
983 for( ; it.current(); ++it ) {
984 KFileMimeTypeInfo* info = it.current();
985 m_plugins.insert( it.currentKey(), new CachedPluginInfo( plugin, info, first ) );
986 first = false;
987 }
988 // Hopefully the above includes the mimetype we asked for!
989 if ( m_pendingMimetypeInfos.find( mimeType ) == 0 )
990 kdWarning(7033) << plugin->className() << " was created for " << mimeType << " but doesn't call addMimeTypeInfo for it!" << endl;
991 }
992 m_pendingMimetypeInfos.clear();
993 return plugin;
994}
995
996KFilePlugin * KFileMetaInfoProvider::plugin(const TQString& mimeType)
997{
998 return plugin( mimeType, TQString::null );
999}
1000
1001KFilePlugin * KFileMetaInfoProvider::plugin(const TQString& mimeType, const TQString& protocol)
1002{
1003 //kdDebug(7033) << "plugin() : looking for plugin for protocol=" << protocol << " mimeType=" << mimeType << endl;
1004
1005 if ( !protocol.isEmpty() ) {
1006 CachedPluginInfo *cache = m_plugins.find( protocol );
1007 if ( cache && cache->plugin ) {
1008 return cache->plugin;
1009 }
1010 if ( !cache ) {
1011 KFilePlugin* plugin = loadAndRegisterPlugin( TQString::null, protocol );
1012 if ( plugin )
1013 return plugin;
1014 }
1015 }
1016
1017 CachedPluginInfo *cache = m_plugins.find( mimeType );
1018 if ( cache ) {
1019 return cache->plugin;
1020 }
1021
1022 KFilePlugin* plugin = loadAndRegisterPlugin( mimeType, TQString::null );
1023
1024#if 0
1025 kdDebug(7033) << "currently loaded plugins:\n";
1026
1027 TQDictIterator<CachedPluginInfo> it( m_plugins );
1028 for( ; it.current(); ++it ) {
1029 CachedPluginInfo* cache = it.current();
1030 kdDebug(7033)
1031 << it.currentKey() // mimetype or protocol
1032 << " : " << (cache->plugin ? cache->plugin->className() : "(no plugin)") << endl; // plugin
1033 // TODO print cache->mimeTypeInfo
1034 }
1035#endif
1036
1037 return plugin;
1038}
1039
1040TQStringList KFileMetaInfoProvider::preferredKeys( const TQString& mimeType ) const
1041{
1042 KService::Ptr service =
1043 KServiceTypeProfile::preferredService( mimeType, "KFilePlugin");
1044
1045 if ( !service || !service->isValid() )
1046 {
1047// kdDebug(7033) << "no valid service found\n";
1048 return TQStringList();
1049 }
1050 return service->property("PreferredItems").toStringList();
1051}
1052
1053TQStringList KFileMetaInfoProvider::preferredGroups( const TQString& mimeType ) const
1054{
1055 KService::Ptr service =
1056 KServiceTypeProfile::preferredService( mimeType, "KFilePlugin");
1057
1058 if ( !service || !service->isValid() )
1059 {
1060// kdDebug(7033) << "no valid service found\n";
1061 return TQStringList();
1062 }
1063 return service->property("PreferredGroups").toStringList();
1064}
1065
1066const KFileMimeTypeInfo * KFileMetaInfoProvider::mimeTypeInfo( const TQString& mimeType )
1067{
1068 return mimeTypeInfo( mimeType, TQString::null );
1069}
1070
1071const KFileMimeTypeInfo * KFileMetaInfoProvider::mimeTypeInfo( const TQString& mimeType, const TQString& protocol )
1072{
1073 //kdDebug(7033) << "mimeTypeInfo() : looking for plugin for protocol=" << protocol << " mimeType=" << mimeType << endl;
1074 if ( !protocol.isEmpty() ) {
1075 CachedPluginInfo *cache = m_plugins.find( protocol );
1076 if ( cache && cache->mimeTypeInfo ) {
1077 return cache->mimeTypeInfo;
1078 }
1079
1080 if ( !cache ) {
1081 loadAndRegisterPlugin( TQString::null, protocol );
1082 cache = m_plugins.find( protocol );
1083 if ( cache && cache->mimeTypeInfo ) {
1084 return cache->mimeTypeInfo;
1085 }
1086 }
1087 }
1088
1089 CachedPluginInfo *cache = m_plugins.find( mimeType );
1090 if ( cache ) {
1091 return cache->mimeTypeInfo;
1092 }
1093
1094 loadAndRegisterPlugin( mimeType, TQString::null );
1095 cache = m_plugins.find( mimeType );
1096 if ( cache ) {
1097 return cache->mimeTypeInfo;
1098 }
1099 return 0;
1100}
1101
1102KFileMimeTypeInfo * KFileMetaInfoProvider::addMimeTypeInfo(
1103 const TQString& mimeType )
1104{
1105
1106 KFileMimeTypeInfo *info = m_pendingMimetypeInfos.find( mimeType );
1107 Q_ASSERT( !info );
1108 if ( !info )
1109 {
1110 info = new KFileMimeTypeInfo( mimeType );
1111 m_pendingMimetypeInfos.insert( mimeType, info );
1112 }
1113
1114 info->m_preferredKeys = preferredKeys( mimeType );
1115 info->m_preferredGroups = preferredGroups( mimeType );
1116
1117 return info;
1118}
1119
1120TQStringList KFileMetaInfoProvider::supportedMimeTypes() const
1121{
1122 TQStringList allMimeTypes;
1123 TQString tdefilePlugin = "KFilePlugin";
1124
1125 TDETrader::OfferList offers = TDETrader::self()->query( "KFilePlugin" );
1126 TDETrader::OfferListIterator it = offers.begin();
1127 for ( ; it != offers.end(); ++it )
1128 {
1129 const TQStringList mimeTypes = (*it)->serviceTypes();
1130 TQStringList::ConstIterator it2 = mimeTypes.begin();
1131 for ( ; it2 != mimeTypes.end(); ++it2 )
1132 if ( allMimeTypes.find( *it2 ) == allMimeTypes.end() &&
1133 *it2 != tdefilePlugin ) // also in serviceTypes()
1134 allMimeTypes.append( *it2 );
1135 }
1136
1137 return allMimeTypes;
1138}
1139
1144
1145
1146// shared data of a KFileMetaInfoGroup
1147class KFileMetaInfoGroup::Data : public TQShared
1148{
1149public:
1150 Data(const TQString& _name)
1151 : TQShared(),
1152 name(_name),
1153 mimeTypeInfo(0L),
1154 dirty( false ),
1155 added( false )
1156 {}
1157
1158 // we use this one for the streaming operators
1159 Data() : mimeTypeInfo(0L) {}
1160 ~Data() {
1161 if ( this == null )
1162 delete mimeTypeInfo;
1163 };
1164
1165 TQString name;
1166 TQMap<TQString, KFileMetaInfoItem> items;
1167 const KFileMimeTypeInfo* mimeTypeInfo;
1168 TQStringList removedItems;
1169 bool dirty :1;
1170 bool added :1;
1171
1172 static Data* null;
1173 static Data* makeNull();
1174
1175};
1176
1177KFileMetaInfoGroup::KFileMetaInfoGroup( const TQString& name,
1178 const KFileMimeTypeInfo* info )
1179 : d(new Data( name ) )
1180{
1181 d->mimeTypeInfo = info;
1182}
1183
1184KFileMetaInfoGroup::KFileMetaInfoGroup( const KFileMetaInfoGroup& original )
1185{
1186 // operator= does everything that's necessary
1187 d = Data::makeNull();
1188 *this = original;
1189}
1190
1191KFileMetaInfoGroup::KFileMetaInfoGroup()
1192{
1193 d = Data::makeNull();
1194}
1195
1196KFileMetaInfoGroup::~KFileMetaInfoGroup()
1197{
1198 deref();
1199}
1200
1201const KFileMetaInfoGroup& KFileMetaInfoGroup::operator= (const KFileMetaInfoGroup& info )
1202{
1203 if (d != info.d)
1204 {
1205 deref();
1206 // first deref the old one
1207 d = info.d;
1208 // and now ref the new one
1209 ref();
1210 }
1211 return *this;
1212}
1213
1214bool KFileMetaInfoGroup::isValid() const
1215{
1216 // We don't call makeNull here since it isn't necassery, see deref()
1217 return d != Data::null;
1218}
1219
1220bool KFileMetaInfoGroup::isEmpty() const
1221{
1222 return d->items.isEmpty();
1223}
1224
1225TQStringList KFileMetaInfoGroup::preferredKeys() const
1226{
1227 assert(isValid());
1228 TQStringList list = keys();
1229 TQStringList newlist;
1230 TQStringList preferredKeys = d->mimeTypeInfo->preferredKeys();
1231 TQStringList::Iterator pref;
1232 TQStringList::Iterator begin = preferredKeys.begin();
1233 TQStringList::Iterator end = preferredKeys.end();
1234
1235 // move all keys from the preferred keys that are in our list to a new list
1236 for ( pref = begin; pref!=end; ++pref )
1237 {
1238 TQStringList::Iterator item = list.find(*pref);
1239 if ( item != list.end() )
1240 {
1241 newlist.append( *item );
1242 list.remove(item);
1243 }
1244 }
1245
1246 // now the old list only contains the non-preferred items, so we
1247 // add the remaining ones to newlist
1248 newlist += list;
1249
1250 return newlist;
1251}
1252
1253TQStringList KFileMetaInfoGroup::keys() const
1254{
1255 if (d == Data::makeNull())
1256 kdWarning(7033) << "attempt to get the keys of "
1257 "an invalid metainfo group";
1258
1259 TQStringList list;
1260
1261 // make a TQStringList with all available keys
1262 TQMapConstIterator<TQString, KFileMetaInfoItem> it;
1263 for (it = d->items.begin(); it!=d->items.end(); ++it)
1264 {
1265 list.append(it.data().key());
1266// kdDebug(7033) << "Item " << it.data().key() << endl;
1267 }
1268 return list;
1269}
1270
1271TQString KFileMetaInfoGroup::translatedName() const
1272{
1273 assert(isValid());
1274 return d->mimeTypeInfo->groupInfo(d->name)->translatedName();
1275}
1276
1277TQStringList KFileMetaInfoGroup::supportedKeys() const
1278{
1279 assert(isValid());
1280 return d->mimeTypeInfo->groupInfo(d->name)->supportedKeys();
1281}
1282
1283bool KFileMetaInfoGroup::supportsVariableKeys() const
1284{
1285 assert(isValid());
1286 return d->mimeTypeInfo->groupInfo(d->name)->supportsVariableKeys();
1287}
1288
1289bool KFileMetaInfoGroup::contains( const TQString& key ) const
1290{
1291 return d->items.contains(key);
1292}
1293
1294KFileMetaInfoItem KFileMetaInfoGroup::item( const TQString& key) const
1295{
1296 TQMapIterator<TQString,KFileMetaInfoItem> it = d->items.find( key );
1297 if ( it != d->items.end() )
1298 return it.data();
1299
1300 return KFileMetaInfoItem();
1301}
1302
1303KFileMetaInfoItem KFileMetaInfoGroup::item(uint hint) const
1304{
1305 TQMapIterator<TQString, KFileMetaInfoItem> it;
1306
1307 for (it = d->items.begin(); it!=d->items.end(); ++it)
1308 if (it.data().hint() == hint)
1309 return it.data();
1310
1311 return KFileMetaInfoItem();
1312}
1313
1314TQString KFileMetaInfoGroup::name() const
1315{
1316 return d->name;
1317}
1318
1319uint KFileMetaInfoGroup::attributes() const
1320{
1321 assert(isValid());
1322 return d->mimeTypeInfo->groupInfo(d->name)->attributes();
1323}
1324
1325void KFileMetaInfoGroup::setAdded()
1326{
1327 d->added = true;
1328}
1329
1330bool KFileMetaInfoGroup::isModified() const
1331{
1332 return d->dirty;
1333}
1334
1335void KFileMetaInfoGroup::ref()
1336{
1337 if (d != Data::null) d->ref();
1338
1339}
1340
1341void KFileMetaInfoGroup::deref()
1342{
1343 // We don't call makeNull here since it isn't necassery:
1344 // If d is equal to null it means that null is initialized already.
1345 // null is 0L when it hasn't been initialized and d is never 0L.
1346 if ((d != Data::null) && d->deref())
1347 {
1348// kdDebug(7033) << "metainfo group " << d->name
1349// << " is finally deleted\n";
1350 delete d;
1351 d = 0;
1352 }
1353
1354}
1355
1356KFileMetaInfoItem KFileMetaInfoGroup::addItem( const TQString& key )
1357{
1358 assert(isValid());
1359 TQMapIterator<TQString,KFileMetaInfoItem> it = d->items.find( key );
1360 if ( it != d->items.end() )
1361 return it.data();
1362
1363 const KFileMimeTypeInfo::GroupInfo* ginfo = d->mimeTypeInfo->groupInfo(d->name);
1364
1365 if ( !ginfo ) {
1366 Q_ASSERT( ginfo );
1367 return KFileMetaInfoItem();
1368 }
1369
1370 const KFileMimeTypeInfo::ItemInfo* info = ginfo->itemInfo(key);
1371
1372 if ( !info ) {
1373 Q_ASSERT( info );
1374 return KFileMetaInfoItem();
1375 }
1376
1377 KFileMetaInfoItem item;
1378
1379 if (info->isVariableItem())
1380 item = KFileMetaInfoItem(ginfo->variableItemInfo(), key, TQVariant());
1381 else
1382 item = KFileMetaInfoItem(info, key, TQVariant());
1383
1384 d->items.insert(key, item);
1385 item.setAdded(); // mark as added
1386 d->dirty = true; // mark ourself as dirty, too
1387 return item;
1388}
1389
1390bool KFileMetaInfoGroup::removeItem( const TQString& key )
1391{
1392 if (!isValid())
1393 {
1394 kdDebug(7033) << "trying to remove an item from an invalid group\n";
1395 return false;
1396 }
1397
1398 TQMapIterator<TQString, KFileMetaInfoItem> it = d->items.find(key);
1399 if ( it==d->items.end() )
1400 {
1401 kdDebug(7033) << "trying to remove the non existant item " << key << "\n";
1402 return false;
1403 }
1404
1405 if (!((*it).attributes() & KFileMimeTypeInfo::Removable))
1406 {
1407 kdDebug(7033) << "trying to remove a non removable item\n";
1408 return false;
1409 }
1410
1411 (*it).setRemoved();
1412 d->items.remove(it);
1413 d->removedItems.append(key);
1414 d->dirty = true;
1415 return true;
1416}
1417
1418TQStringList KFileMetaInfoGroup::removedItems()
1419{
1420 return d->removedItems;
1421}
1422
1423KFileMetaInfoItem KFileMetaInfoGroup::appendItem(const TQString& key,
1424 const TQVariant& value)
1425{
1426 //KDE4 enforce (value.type() == d->mimeTypeInfo->type())
1427 assert(isValid());
1428 const KFileMimeTypeInfo::GroupInfo* ginfo = d->mimeTypeInfo->groupInfo(d->name);
1429 if ( !ginfo ) {
1430 kdWarning() << "Trying to append a Metadata item for a non-existant group:" << d->name << endl;
1431 return KFileMetaInfoItem();
1432 }
1433 const KFileMimeTypeInfo::ItemInfo* info = ginfo->itemInfo(key);
1434 if ( !info ) {
1435 kdWarning() << "Trying to append a Metadata item for an unknown key (no ItemInfo): " << key << endl;
1436 return KFileMetaInfoItem();
1437 }
1438
1439 KFileMetaInfoItem item;
1440
1441 if (info->key().isNull())
1442 item = KFileMetaInfoItem(ginfo->variableItemInfo(), key, value);
1443 else
1444 item = KFileMetaInfoItem(info, key, value);
1445
1446 kdDebug(7033) << "KFileMetaInfogroup inserting a " << key << endl;
1447
1448 d->items.insert(key, item);
1449 return item;
1450}
1451
1452KFileMetaInfoGroup::Data* KFileMetaInfoGroup::Data::null = 0L;
1453static KStaticDeleter<KFileMetaInfoGroup::Data> sd_KFileMetaInfoGroupData;
1454
1455KFileMetaInfoGroup::Data* KFileMetaInfoGroup::Data::makeNull()
1456{
1457 if (!null)
1458 {
1459 // We deliberately do not reset "null" after it has been destroyed!
1460 // Otherwise we will run into problems later in ~KFileMetaInfoItem
1461 // where the d-pointer is compared against null.
1462 null = new Data(TQString::null);
1463 null->mimeTypeInfo = new KFileMimeTypeInfo();
1464 sd_KFileMetaInfoGroupData.setObject( null );
1465 }
1466 return null;
1467}
1468
1469
1472
1473KFileMimeTypeInfo::KFileMimeTypeInfo( const TQString& mimeType )
1474 : m_mimeType( mimeType )
1475{
1476 m_groups.setAutoDelete( true );
1477}
1478
1479KFileMimeTypeInfo::~KFileMimeTypeInfo()
1480{
1481}
1482
1483const KFileMimeTypeInfo::GroupInfo * KFileMimeTypeInfo::groupInfo( const TQString& group ) const
1484{
1485 return m_groups.find( group );
1486}
1487
1488KFileMimeTypeInfo::GroupInfo * KFileMimeTypeInfo::addGroupInfo(
1489 const TQString& name, const TQString& translatedName )
1490{
1491 GroupInfo* group = new GroupInfo( name, translatedName );
1492 m_groups.insert(name, group);
1493 return group;
1494}
1495
1496TQStringList KFileMimeTypeInfo::supportedGroups() const
1497{
1498 TQStringList list;
1499 TQDictIterator<GroupInfo> it( m_groups );
1500 for ( ; it.current(); ++it )
1501 list.append( it.current()->name() );
1502
1503 return list;
1504}
1505
1506TQStringList KFileMimeTypeInfo::translatedGroups() const
1507{
1508 TQStringList list;
1509 TQDictIterator<GroupInfo> it( m_groups );
1510 for ( ; it.current(); ++it )
1511 list.append( it.current()->translatedName() );
1512
1513 return list;
1514}
1515
1516TQStringList KFileMimeTypeInfo::supportedKeys() const
1517{
1518 // not really efficient, but not those are not large lists, probably.
1519 // maybe cache the result?
1520 TQStringList keys;
1521 TQStringList::ConstIterator lit;
1522 TQDictIterator<GroupInfo> it( m_groups );
1523 for ( ; it.current(); ++it ) { // need to nuke dupes
1524 TQStringList list = it.current()->supportedKeys();
1525 for ( lit = list.begin(); lit != list.end(); ++lit ) {
1526 if ( keys.find( *lit ) == keys.end() )
1527 keys.append( *lit );
1528 }
1529 }
1530
1531 return keys;
1532}
1533
1534TQValidator * KFileMimeTypeInfo::createValidator(const TQString& group,
1535 const TQString& key,
1536 TQObject *parent,
1537 const char *name) const
1538{
1539 KFilePlugin* plugin = KFileMetaInfoProvider::self()->plugin(m_mimeType);
1540 if (plugin) return plugin->createValidator(mimeType(), group, key,
1541 parent, name);
1542 return 0;
1543}
1544
1545
1548
1549KFileMimeTypeInfo::GroupInfo::GroupInfo( const TQString& name,
1550 const TQString& translatedName )
1551 : m_name( name ),
1552 m_translatedName( translatedName ),
1553 m_attr( 0 ),
1554 m_variableItemInfo( 0 )
1555
1556{
1557 m_itemDict.setAutoDelete( true );
1558}
1559
1560KFileMimeTypeInfo::GroupInfo::~GroupInfo()
1561{
1562 delete m_variableItemInfo;
1563}
1564
1565const KFileMimeTypeInfo::ItemInfo * KFileMimeTypeInfo::GroupInfo::itemInfo( const TQString& key ) const
1566{
1567 ItemInfo* item = m_itemDict.find( key );
1568
1569 // if we the item isn't found and variable keys are supported, we need to
1570 // return the default variable key iteminfo.
1571 if (!item && m_variableItemInfo)
1572 {
1573 return m_variableItemInfo;
1574 }
1575 return item;
1576}
1577
1578KFileMimeTypeInfo::ItemInfo* KFileMimeTypeInfo::GroupInfo::addItemInfo(
1579 const TQString& key, const TQString& translatedKey,
1580 TQVariant::Type type)
1581{
1582// kdDebug(7034) << key << "(" << translatedKey << ") -> " << TQVariant::typeToName(type) << endl;
1583
1584 ItemInfo* item = new ItemInfo(key, translatedKey, type);
1585 m_supportedKeys.append(key);
1586 m_itemDict.insert(key, item);
1587 return item;
1588}
1589
1590
1591void KFileMimeTypeInfo::GroupInfo::addVariableInfo( TQVariant::Type type,
1592 uint attr )
1593{
1594 // just make sure that it's not already there
1595 delete m_variableItemInfo;
1596 m_variableItemInfo = new ItemInfo(TQString::null, TQString::null, type);
1597 m_variableItemInfo->m_attr = attr;
1598}
1599
1602
1603TQString KFileMimeTypeInfo::ItemInfo::string(const TQVariant& value, bool mangle) const
1604{
1605 TQString s;
1606
1607 switch (value.type())
1608 {
1609 case TQVariant::Invalid :
1610 return "---";
1611
1612 case TQVariant::Bool :
1613 s = value.toBool() ? i18n("Yes") : i18n("No");
1614 break;
1615
1616 case TQVariant::Int :
1617 if (unit() == KFileMimeTypeInfo::Seconds)
1618 {
1619 int seconds = value.toInt() % 60;
1620 int minutes = value.toInt() / 60 % 60;
1621 int hours = value.toInt() / 3600;
1622 s = hours ? TQString().sprintf("%d:%02d:%02d",hours, minutes, seconds)
1623 : TQString().sprintf("%02d:%02d", minutes, seconds);
1624 return s; // no suffix wanted
1625 }
1626 else if (unit() == KFileMimeTypeInfo::Bytes)
1627 {
1628 // convertSize already adds the correct suffix
1629 return TDEIO::convertSize(value.toInt());
1630 }
1631 else if (unit() == KFileMimeTypeInfo::KiloBytes)
1632 {
1633 // convertSizeFromKB already adds the correct suffix
1634 return TDEIO::convertSizeFromKB(value.toInt());
1635 }
1636 else
1637 s = TDEGlobal::locale()->formatNumber( value.toInt() , 0);
1638 break;
1639
1640 case TQVariant::LongLong :
1641 s = TDEGlobal::locale()->formatNumber( value.toLongLong(), 0 );
1642 break;
1643
1644 case TQVariant::ULongLong :
1645 if ( unit() == KFileMimeTypeInfo::Bytes )
1646 return TDEIO::convertSize( value.toULongLong() );
1647 else if ( unit() == KFileMimeTypeInfo::KiloBytes )
1648 return TDEIO::convertSizeFromKB( value.toULongLong() );
1649 else
1650 s = TDEGlobal::locale()->formatNumber( value.toULongLong(), 0 );
1651 break;
1652
1653 case TQVariant::UInt :
1654 s = TDEGlobal::locale()->formatNumber( value.toUInt() , 0);
1655 break;
1656
1657 case TQVariant::Double :
1658 s = TDEGlobal::locale()->formatNumber( value.toDouble(), 3);
1659 break;
1660
1661 case TQVariant::Date :
1662 s = TDEGlobal::locale()->formatDate( value.toDate(), true );
1663 break;
1664
1665 case TQVariant::Time :
1666 s = TDEGlobal::locale()->formatTime( value.toTime(), true );
1667 break;
1668
1669 case TQVariant::DateTime :
1670 s = TDEGlobal::locale()->formatDateTime( value.toDateTime(),
1671 true, true );
1672 break;
1673
1674 case TQVariant::Size :
1675 s = TQString("%1 x %2").arg(value.toSize().width())
1676 .arg(value.toSize().height());
1677 break;
1678
1679 case TQVariant::Point :
1680 s = TQString("%1/%2").arg(value.toSize().width())
1681 .arg(value.toSize().height());
1682 break;
1683
1684 default:
1685 s = value.toString();
1686 }
1687
1688 if (mangle && !s.isNull())
1689 {
1690 s.prepend(prefix());
1691 s.append(" " + suffix());
1692 }
1693 return s;
1694}
1695
1696
1699
1700
1701
1702// stream operators
1703
1704/* serialization of a KFileMetaInfoItem:
1705 first a bool that says if the items is valid, and if yes,
1706 all the elements of the Data
1707*/
1708TDEIO_EXPORT TQDataStream& operator <<(TQDataStream& s, const KFileMetaInfoItem& item )
1709{
1710
1711 KFileMetaInfoItem::Data* d = item.d;
1712
1713 // if the object is invalid, put only a char in the stream
1714 bool isValid = item.isValid();
1715 s << isValid;
1716 // ### what do about mimetypeInfo ?
1717 if (isValid)
1718 s << d->key
1719 << d->value
1720 << d->dirty
1721 << d->added
1722 << d->removed;
1723
1724 return s;
1725}
1726
1727
1728TDEIO_EXPORT TQDataStream& operator >>(TQDataStream& s, KFileMetaInfoItem& item )
1729{
1730 bool isValid;
1731 s >> isValid;
1732
1733 if (!isValid)
1734 {
1735 item = KFileMetaInfoItem();
1736 return s;
1737 }
1738
1739 // we need a new object for our data
1740 item.deref();
1741 item.d = new KFileMetaInfoItem::Data();
1742
1743 // ### what do about mimetypeInfo ?
1744 bool dirty, added, removed;
1745 s >> item.d->key
1746 >> item.d->value
1747 >> dirty
1748 >> added
1749 >> removed;
1750 item.d->dirty = dirty;
1751 item.d->added = added;
1752 item.d->removed = removed;
1753
1754 return s;
1755}
1756
1757
1758// serialization of a KFileMetaInfoGroup
1759// we serialize the name of the mimetype here instead of the mimetype info
1760// on the other side, we can simply use this to ask the provider for the info
1761TDEIO_EXPORT TQDataStream& operator <<(TQDataStream& s, const KFileMetaInfoGroup& group )
1762{
1763 KFileMetaInfoGroup::Data* d = group.d;
1764
1765 // if the object is invalid, put only a byte in the stream
1766 bool isValid = group.isValid();
1767
1768 s << isValid;
1769 if (isValid)
1770 {
1771 s << d->name
1772 << d->items
1773 << d->mimeTypeInfo->mimeType();
1774 }
1775 return s;
1776}
1777
1778TDEIO_EXPORT TQDataStream& operator >>(TQDataStream& s, KFileMetaInfoGroup& group )
1779{
1780 TQString mimeType;
1781 bool isValid;
1782 s >> isValid;
1783
1784 // if it's invalid, there is not much to do
1785 if (!isValid)
1786 {
1787 group = KFileMetaInfoGroup();
1788 return s;
1789 }
1790
1791 // we need a new object for our data
1792 group.deref();
1793 group.d = new KFileMetaInfoGroup::Data();
1794
1795 s >> group.d->name
1796 >> group.d->items
1797 >> mimeType;
1798
1799 group.d->mimeTypeInfo = KFileMetaInfoProvider::self()->mimeTypeInfo(mimeType);
1800
1801 // we need to set the item info for the items here
1802 TQMapIterator<TQString, KFileMetaInfoItem> it = group.d->items.begin();
1803 for ( ; it != group.d->items.end(); ++it)
1804 {
1805 (*it).d->mimeTypeInfo = group.d->mimeTypeInfo->groupInfo(group.d->name)
1806 ->itemInfo((*it).key());
1807 }
1808
1809 return s;
1810}
1811
1812// serialization of a KFileMetaInfo object
1813// we serialize the name of the mimetype here instead of the mimetype info
1814// on the other side, we can simply use this to ask the provider for the info
1815TDEIO_EXPORT TQDataStream& operator <<(TQDataStream& s, const KFileMetaInfo& info )
1816{
1817 KFileMetaInfo::Data* d = info.d;
1818
1819 // if the object is invalid, put only a byte that tells this
1820 bool isValid = info.isValid();
1821
1822 s << isValid;
1823 if (isValid)
1824 {
1825 s << d->url
1826 << d->what
1827 << d->groups
1828 << d->mimeTypeInfo->mimeType();
1829 }
1830 return s;
1831}
1832
1833TDEIO_EXPORT TQDataStream& operator >>(TQDataStream& s, KFileMetaInfo& info )
1834{
1835 TQString mimeType;
1836 bool isValid;
1837 s >> isValid;
1838
1839 // if it's invalid, there is not much to do
1840 if (!isValid)
1841 {
1842 info = KFileMetaInfo();
1843 return s;
1844 }
1845
1846 // we need a new object for our data
1847 info.deref();
1848 info.d = new KFileMetaInfo::Data();
1849
1850 s >> info.d->url
1851 >> info.d->what
1852 >> info.d->groups
1853 >> mimeType;
1854 info.d->mimeTypeInfo = KFileMetaInfoProvider::self()->mimeTypeInfo(mimeType);
1855
1856 return s;
1857}
1858
1859#include "tdefilemetainfo.moc"
KFileMetaInfoGroup
A group of meta information items about a file.
Definition: tdefilemetainfo.h:685
KFileMetaInfoGroup::removeItem
bool removeItem(const TQString &key)
Remove this item from the meta info of the file.
Definition: tdefilemetainfo.cpp:1390
KFileMetaInfoGroup::isEmpty
bool isEmpty() const
Returns false if the object contains data, true if it's empty.
Definition: tdefilemetainfo.cpp:1220
KFileMetaInfoGroup::item
KFileMetaInfoItem item(const TQString &key) const
This method searches for the specified item.
Definition: tdefilemetainfo.cpp:1294
KFileMetaInfoGroup::removedItems
TQStringList removedItems()
Returns a list of all removed items.
Definition: tdefilemetainfo.cpp:1418
KFileMetaInfoGroup::name
TQString name() const
The name of this group.
Definition: tdefilemetainfo.cpp:1314
KFileMetaInfoGroup::value
const TQVariant value(const TQString &key) const
Convenience function.
Definition: tdefilemetainfo.h:784
KFileMetaInfoGroup::supportedKeys
TQStringList supportedKeys() const
Use this method to get a list of keys in the specified group that the plugin knows about.
Definition: tdefilemetainfo.cpp:1277
KFileMetaInfoGroup::operator=
const KFileMetaInfoGroup & operator=(const KFileMetaInfoGroup &info)
The assignment operator, so you can do:
Definition: tdefilemetainfo.cpp:1201
KFileMetaInfoGroup::keys
TQStringList keys() const
Returns a list of all keys.
Definition: tdefilemetainfo.cpp:1253
KFileMetaInfoGroup::isValid
bool isValid() const
Returns true if the item is valid, i.e.
Definition: tdefilemetainfo.cpp:1214
KFileMetaInfoGroup::supportsVariableKeys
bool supportsVariableKeys() const
Returns true if this group supports adding or removing arbitrary keys, false if not.
Definition: tdefilemetainfo.cpp:1283
KFileMetaInfoGroup::translatedName
TQString translatedName() const
The translated name of this group.
Definition: tdefilemetainfo.cpp:1271
KFileMetaInfoGroup::attributes
uint attributes() const
Returns the attributes of this item.
Definition: tdefilemetainfo.cpp:1319
KFileMetaInfoGroup::addItem
KFileMetaInfoItem addItem(const TQString &key)
Add an item to the info.
Definition: tdefilemetainfo.cpp:1356
KFileMetaInfoGroup::isModified
bool isModified() const
Returns true if an item as added or removed from the group.
Definition: tdefilemetainfo.cpp:1330
KFileMetaInfoGroup::contains
bool contains(const TQString &key) const
Checks whether an item with the given key exists.
Definition: tdefilemetainfo.cpp:1289
KFileMetaInfoGroup::preferredKeys
TQStringList preferredKeys() const
Returns a list of all keys in preference order.
Definition: tdefilemetainfo.cpp:1225
KFileMetaInfoGroup::KFileMetaInfoGroup
KFileMetaInfoGroup()
Default constructor.
Definition: tdefilemetainfo.cpp:1191
KFileMetaInfoItem
A meta information item about a file.
Definition: tdefilemetainfo.h:497
KFileMetaInfoItem::key
TQString key() const
Returns the key of the item.
Definition: tdefilemetainfo.cpp:165
KFileMetaInfoItem::translatedKey
TQString translatedKey() const
Returns a translation of the key for displaying to the user.
Definition: tdefilemetainfo.cpp:170
KFileMetaInfoItem::isEditable
bool isEditable() const
You can query if the application can edit the item and write it back to the file with this method.
Definition: tdefilemetainfo.cpp:227
KFileMetaInfoItem::isValid
bool isValid() const
Return true if the item is valid, i.e.
Definition: tdefilemetainfo.cpp:232
KFileMetaInfoItem::prefix
TQString prefix() const
This method returns a translated prefix to be displayed before the value.
Definition: tdefilemetainfo.cpp:207
KFileMetaInfoItem::isRemoved
bool isRemoved() const
If you remove an item, it is only marked for removal for the file.
Definition: tdefilemetainfo.cpp:160
KFileMetaInfoItem::isModified
bool isModified() const
If you change an item, it is marked as "dirty".
Definition: tdefilemetainfo.cpp:202
KFileMetaInfoItem::type
TQVariant::Type type() const
Return the type of the item.
Definition: tdefilemetainfo.cpp:192
KFileMetaInfoItem::unit
uint unit() const
Returns the unit for this item.
Definition: tdefilemetainfo.cpp:197
KFileMetaInfoItem::value
const TQVariant & value() const
Returns the value of the item.
Definition: tdefilemetainfo.cpp:182
KFileMetaInfoItem::KFileMetaInfoItem
KFileMetaInfoItem()
Default constructor.
Definition: tdefilemetainfo.cpp:109
KFileMetaInfoItem::hint
uint hint() const
Returns the hint for this item.
Definition: tdefilemetainfo.cpp:217
KFileMetaInfoItem::suffix
TQString suffix() const
This method returns a translated suffix to be displayed after the value.
Definition: tdefilemetainfo.cpp:212
KFileMetaInfoItem::attributes
uint attributes() const
Returns the attributes for this item.
Definition: tdefilemetainfo.cpp:222
KFileMetaInfoItem::setValue
bool setValue(const TQVariant &value)
Changes the value of the item.
Definition: tdefilemetainfo.cpp:134
KFileMetaInfoItem::string
TQString string(bool mangle=true) const
Returns a string containing the value, if possible.
Definition: tdefilemetainfo.cpp:187
KFileMetaInfo
Meta Information about a file.
Definition: tdefilemetainfo.h:927
KFileMetaInfo::containsGroup
bool containsGroup(const TQString &key) const
Checks whether a group with the given key exists.
Definition: tdefilemetainfo.cpp:609
KFileMetaInfo::editableGroups
TQStringList editableGroups() const
Returns the list of groups that you can add or remove from the file.
Definition: tdefilemetainfo.cpp:387
KFileMetaInfo::contains
bool contains(const TQString &key) const
Checks whether an item with the given key exists.
Definition: tdefilemetainfo.cpp:598
KFileMetaInfo::preferredKeys
TQStringList preferredKeys() const
Returns a list of all preferred keys.
Definition: tdefilemetainfo.cpp:428
KFileMetaInfo::isValid
bool isValid() const
Returns true if the item is valid, i.e.
Definition: tdefilemetainfo.cpp:517
KFileMetaInfo::removeGroup
bool removeGroup(const TQString &name)
Remove the specified group.
Definition: tdefilemetainfo.cpp:487
KFileMetaInfo::applyChanges
bool applyChanges()
This method writes all pending changes of the meta info back to the file.
Definition: tdefilemetainfo.cpp:532
KFileMetaInfo::item
KFileMetaInfoItem item(const TQString &key) const
Returns the KFileMetaInfoItem with the given key.
Definition: tdefilemetainfo.cpp:614
KFileMetaInfo::removedGroups
TQStringList removedGroups()
Returns a list of removed groups.
Definition: tdefilemetainfo.cpp:499
KFileMetaInfo::preferredGroups
TQStringList preferredGroups() const
Returns a list of the preferred groups.
Definition: tdefilemetainfo.cpp:402
KFileMetaInfo::supportedKeys
TQStringList supportedKeys() const
Returns a list of supported keys.
Definition: tdefilemetainfo.cpp:371
KFileMetaInfo::KFileMetaInfo
KFileMetaInfo()
Default constructor.
Definition: tdefilemetainfo.cpp:355
KFileMetaInfo::supportedGroups
TQStringList supportedGroups() const
Returns a list of all supported groups.
Definition: tdefilemetainfo.cpp:365
KFileMetaInfo::mimeType
TQString mimeType() const
Returns the mime type of file.
Definition: tdefilemetainfo.cpp:592
KFileMetaInfo::group
KFileMetaInfoGroup group(const TQString &key) const
Returns the KFileMetaInfoGroup with the given key.
Definition: tdefilemetainfo.cpp:441
KFileMetaInfo::operator=
const KFileMetaInfo & operator=(const KFileMetaInfo &info)
The assignment operator, so you can do e.g.
Definition: tdefilemetainfo.cpp:504
KFileMetaInfo::saveItem
KFileMetaInfoItem saveItem(const TQString &key, const TQString &preferredGroup=TQString::null, bool createGroup=true)
Saves the item with the given key.
Definition: tdefilemetainfo.cpp:637
KFileMetaInfo::groups
TQStringList groups() const
Returns a list of all groups.
Definition: tdefilemetainfo.cpp:377
KFileMetaInfo::path
TQString path() const
Returns the path of file - or TQString::null if file is non-local.
Definition: tdefilemetainfo.cpp:734
KFileMetaInfo::plugin
KFilePlugin * plugin() const
Definition: tdefilemetainfo.cpp:585
KFileMetaInfo::addGroup
bool addGroup(const TQString &name)
Try to add the specified group.
Definition: tdefilemetainfo.cpp:450
KFileMetaInfo::url
KURL url() const
Returns the url of file.
Definition: tdefilemetainfo.cpp:739
KFileMetaInfo::isEmpty
bool isEmpty() const
Returns false if the object contains data, true if it's empty.
Definition: tdefilemetainfo.cpp:523
KFileMimeTypeInfo::GroupInfo
Information about a meta information group.
Definition: tdefilemetainfo.h:139
KFileMimeTypeInfo::GroupInfo::variableItemInfo
const ItemInfo * variableItemInfo() const
If the group supports variable keys, you can query their item info with this method.
Definition: tdefilemetainfo.h:217
KFileMimeTypeInfo::GroupInfo::supportedKeys
TQStringList supportedKeys() const
Use this method to get a list of keys in the specified group that the plugin knows about.
Definition: tdefilemetainfo.h:154
KFileMimeTypeInfo::GroupInfo::attributes
uint attributes() const
Get the attributes of this group (see Attributes)
Definition: tdefilemetainfo.h:196
KFileMimeTypeInfo::GroupInfo::itemInfo
const ItemInfo * itemInfo(const TQString &key) const
A group object can contain several item objects (of which you can get the names with supportedKeys() ...
Definition: tdefilemetainfo.cpp:1565
KFileMimeTypeInfo::ItemInfo
This is the class for one item of a KFileMimeTypeInfo.
Definition: tdefilemetainfo.h:251
KFileMimeTypeInfo::ItemInfo::string
TQString string(const TQVariant &value, bool mangle=true) const
Returns a string for the specified value, if possible.
Definition: tdefilemetainfo.cpp:1603
KFileMimeTypeInfo::ItemInfo::attributes
uint attributes() const
Return the attributes of the item.
Definition: tdefilemetainfo.h:341
KFileMimeTypeInfo::ItemInfo::key
const TQString & key() const
Returns the name of the item.
Definition: tdefilemetainfo.h:296
KFileMimeTypeInfo::ItemInfo::isVariableItem
bool isVariableItem() const
Is this item the variable item?
Definition: tdefilemetainfo.h:319
KFileMimeTypeInfo
Represents the capabilities of a KFilePlugin for a given mimetype.
Definition: tdefilemetainfo.h:51
KFileMimeTypeInfo::groupInfo
const GroupInfo * groupInfo(const TQString &group) const
Get the group info for a specific group.
Definition: tdefilemetainfo.cpp:1483
KFileMimeTypeInfo::Removable
@ Removable
It can be removed.
Definition: tdefilemetainfo.h:67
KFileMimeTypeInfo::Modifiable
@ Modifiable
The value can be edited (no meaning for a group)
Definition: tdefilemetainfo.h:68
KFileMimeTypeInfo::Addable
@ Addable
The item or group can be added by a user.
Definition: tdefilemetainfo.h:66
KFileMimeTypeInfo::translatedGroups
TQStringList translatedGroups() const
Same as the above function, but returns the strings to display to the user.
Definition: tdefilemetainfo.cpp:1506
KFileMimeTypeInfo::Seconds
@ Seconds
The item represents a time in seconds.
Definition: tdefilemetainfo.h:113
KFileMimeTypeInfo::Pixels
@ Pixels
For image dimensions and similar.
Definition: tdefilemetainfo.h:116
KFileMimeTypeInfo::Inches
@ Inches
Sizes.
Definition: tdefilemetainfo.h:117
KFileMimeTypeInfo::FramesPerSecond
@ FramesPerSecond
A frame rate.
Definition: tdefilemetainfo.h:120
KFileMimeTypeInfo::DotsPerInch
@ DotsPerInch
Resolution in DPI.
Definition: tdefilemetainfo.h:121
KFileMimeTypeInfo::BitsPerSecond
@ BitsPerSecond
A bit rate.
Definition: tdefilemetainfo.h:115
KFileMimeTypeInfo::Bytes
@ Bytes
Some data/file size in bytes.
Definition: tdefilemetainfo.h:119
KFileMimeTypeInfo::Millimeters
@ Millimeters
Sizes.
Definition: tdefilemetainfo.h:125
KFileMimeTypeInfo::KiloBytes
@ KiloBytes
Some data/file size in kilobytes.
Definition: tdefilemetainfo.h:124
KFileMimeTypeInfo::Centimeters
@ Centimeters
Sizes.
Definition: tdefilemetainfo.h:118
KFileMimeTypeInfo::Hertz
@ Hertz
Sample rates and similar.
Definition: tdefilemetainfo.h:123
KFileMimeTypeInfo::MilliSeconds
@ MilliSeconds
The item represents a time in milliseconds.
Definition: tdefilemetainfo.h:114
KFileMimeTypeInfo::BitsPerPixel
@ BitsPerPixel
A bit depth.
Definition: tdefilemetainfo.h:122
KFileMimeTypeInfo::mimeType
TQString mimeType() const
Returns the mimetype to which this info belongs.
Definition: tdefilemetainfo.h:435
KFileMimeTypeInfo::supportedKeys
TQStringList supportedKeys() const
Return a list of all supported keys without looking for a specific group.
Definition: tdefilemetainfo.cpp:1516
KFileMimeTypeInfo::supportedGroups
TQStringList supportedGroups() const
Returns the list of all groups that the plugin for this mimetype supports.
Definition: tdefilemetainfo.cpp:1496
KFileMimeTypeInfo::Hint
Hint
This enum is mainly for items that have a special meaning for some applications.
Definition: tdefilemetainfo.h:89
KFileMimeTypeInfo::createValidator
TQValidator * createValidator(const TQString &group, const TQString &key, TQObject *parent=0, const char *name=0) const
Creates a validator for this item.
Definition: tdefilemetainfo.cpp:1534
KFilePlugin
Base class for a meta information plugin.
Definition: tdefilemetainfo.h:1395
KFilePlugin::addGroupInfo
KFileMimeTypeInfo::GroupInfo * addGroupInfo(KFileMimeTypeInfo *info, const TQString &key, const TQString &translatedKey) const
Creates a meta information group for KFileMimeTypeInfo object returned by addMimeTypeInfo().
Definition: tdefilemetainfo.cpp:802
KFilePlugin::addItemInfo
KFileMimeTypeInfo::ItemInfo * addItemInfo(KFileMimeTypeInfo::GroupInfo *gi, const TQString &key, const TQString &translatedKey, TQVariant::Type type)
Adds a meta information item to a GroupInfo object as returned by addGroupInfo().
Definition: tdefilemetainfo.cpp:819
KFilePlugin::setPrefix
void setPrefix(KFileMimeTypeInfo::ItemInfo *item, const TQString &prefix)
Sets a prefix string which is displayed before the item's value.
Definition: tdefilemetainfo.cpp:884
KFilePlugin::virtual_hook
virtual void virtual_hook(int id, void *data)
Helper method to allow binary compatible extensions when needing "new virtual methods".
Definition: tdefilemetainfo.cpp:798
KFilePlugin::addMimeTypeInfo
KFileMimeTypeInfo * addMimeTypeInfo(const TQString &mimeType)
Call this from within your constructor to tell the KFile framework what mimetypes your plugin support...
Definition: tdefilemetainfo.cpp:793
KFilePlugin::setUnit
void setUnit(KFileMimeTypeInfo::ItemInfo *item, uint unit)
Sets the unit used in the meta information item.
Definition: tdefilemetainfo.cpp:837
KFilePlugin::~KFilePlugin
virtual ~KFilePlugin()
Destructor.
Definition: tdefilemetainfo.cpp:788
KFilePlugin::writeInfo
virtual bool writeInfo(const KFileMetaInfo &info) const
Similar to the readInfo() but for writing the info back to the file.
Definition: tdefilemetainfo.h:1442
KFilePlugin::appendItem
void appendItem(KFileMetaInfoGroup &group, const TQString &key, TQVariant value)
Call this method from within readInfo() to fill the meta information item identified by key with a va...
Definition: tdefilemetainfo.cpp:899
KFilePlugin::setAttributes
void setAttributes(KFileMimeTypeInfo::GroupInfo *gi, uint attr) const
Sets attributes of the GroupInfo object returned by addGroupInfo().
Definition: tdefilemetainfo.cpp:808
KFilePlugin::setHint
void setHint(KFileMimeTypeInfo::ItemInfo *item, uint hint)
Defines the meaning of the meta information item.
Definition: tdefilemetainfo.cpp:832
KFilePlugin::appendGroup
KFileMetaInfoGroup appendGroup(KFileMetaInfo &info, const TQString &key)
Call this method from within readInfo() to indicate that you wish to fill meta information items of t...
Definition: tdefilemetainfo.cpp:894
KFilePlugin::KFilePlugin
KFilePlugin(TQObject *parent, const char *name, const TQStringList &args)
Creates a new KFilePlugin instance.
Definition: tdefilemetainfo.cpp:781
KFilePlugin::setSuffix
void setSuffix(KFileMimeTypeInfo::ItemInfo *item, const TQString &suffix)
Sets a suffix string which is displayed before the item's value.
Definition: tdefilemetainfo.cpp:889
KFilePlugin::readInfo
virtual bool readInfo(KFileMetaInfo &info, uint what=KFileMetaInfo::Fastest)=0
Read the info from the file in this method and insert it into the provided KFileMetaInfo object.
KFilePlugin::createValidator
virtual TQValidator * createValidator(const TQString &mimeType, const TQString &group, const TQString &key, TQObject *parent, const char *name) const
This method should create an appropriate validator for the specified item if it's editable or return ...
Definition: tdefilemetainfo.h:1462
KMimeType::findByURL
static Ptr findByURL(const KURL &_url, mode_t _mode=0, bool _is_local_file=false, bool _fast_mode=false)
Finds a KMimeType with the given _url.
Definition: kmimetype.cpp:165
KServiceTypeProfile::preferredService
static KService::Ptr preferredService(const TQString &serviceType, const TQString &genericServiceType)
Returns the preferred service for _serviceType and _genericServiceType ("Application",...
Definition: kuserprofile.cpp:303
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
TDETrader::self
static TDETrader * self()
This is a static pointer to a TDETrader instance.
Definition: ktrader.cpp:90
TDETrader::OfferList
TQValueList< KService::Ptr > OfferList
A list of services.
Definition: ktrader.h:92
TDEIO::convertSizeFromKB
TDEIO_EXPORT TQString convertSizeFromKB(TDEIO::filesize_t kbSize)
Converts size from kilo-bytes to the string representation.
Definition: global.cpp:91
TDEIO::convertSize
TDEIO_EXPORT TQString convertSize(TDEIO::filesize_t size)
Converts size from bytes to the string representation.
Definition: global.cpp:53

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.4
This website is maintained by Timothy Pearson.