00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KILEMETAINFO_H
00021 #define KILEMETAINFO_H
00022
00023
00024
00025 #define m_unit outouftheway_m_unit
00026
00027 #include <qdict.h>
00028 #include <qvariant.h>
00029 #include <qobject.h>
00030 #include <qstring.h>
00031 #include <kurl.h>
00032
00033 #undef m_unit
00034
00035 class QValidator;
00036 class KFilePlugin;
00037 class KFileMetaInfoGroup;
00038
00050 class KIO_EXPORT KFileMimeTypeInfo
00051 {
00052
00053
00054 friend class KFilePlugin;
00055 friend class KFileMetaInfoProvider;
00056
00057 public:
00058 KFileMimeTypeInfo() {}
00059
00064 enum Attributes
00065 {
00066 Addable = 1,
00067 Removable = 2,
00068 Modifiable = 4,
00069 Cumulative = 8,
00072 Cummulative = Cumulative,
00073 Averaged = 16,
00075 MultiLine = 32,
00079 SqueezeText = 64
00083 };
00084
00089 enum Hint {
00090 NoHint = 0,
00091 Name = 1,
00092 Author = 2,
00093 Description = 3,
00094 Width = 4,
00095 Height = 5,
00096 Size = 6,
00097 Bitrate = 7,
00098 Length = 8,
00099 Hidden = 9,
00100 Thumbnail = 10
00101
00102 };
00103
00111 enum Unit {
00112 NoUnit = 0,
00113 Seconds = 1,
00114 MilliSeconds = 2,
00115 BitsPerSecond = 3,
00116 Pixels = 4,
00117 Inches = 5,
00118 Centimeters = 6,
00119 Bytes = 7,
00120 FramesPerSecond = 8,
00121 DotsPerInch = 9,
00122 BitsPerPixel = 10,
00123 Hertz = 11,
00124 KiloBytes = 12,
00125 Millimeters = 13
00126 };
00127
00128
00129 class ItemInfo;
00130
00138 class KIO_EXPORT GroupInfo
00139 {
00140
00141 friend class KFilePlugin;
00142 friend class KFileMimeTypeInfo;
00143 public:
00154 QStringList supportedKeys() const
00155 {
00156 return m_supportedKeys;
00157 }
00158
00165 const QString& name() const
00166 {
00167 return m_name;
00168 }
00169
00177 const QString& translatedName() const
00178 {
00179 return m_translatedName;
00180 }
00181
00189 const ItemInfo * itemInfo( const QString& key ) const;
00190
00196 uint attributes() const
00197 {
00198 return m_attr;
00199 }
00200
00205 bool supportsVariableKeys() const
00206 {
00207 return m_variableItemInfo;
00208 }
00209
00217 const ItemInfo* variableItemInfo( ) const
00218 {
00219 return m_variableItemInfo;
00220 }
00221
00223 ~GroupInfo();
00224 private:
00226 GroupInfo( const QString& name, const QString& translatedName);
00227
00229 KFileMimeTypeInfo::ItemInfo* addItemInfo( const QString& key,
00230 const QString& translatedKey,
00231 QVariant::Type type);
00232
00234 void addVariableInfo( QVariant::Type type, uint attr );
00235
00236 QString m_name;
00237 QString m_translatedName;
00238 QStringList m_supportedKeys;
00239 uint m_attr;
00240 ItemInfo* m_variableItemInfo;
00241 QDict<ItemInfo> m_itemDict;
00242
00243 };
00244
00250 class KIO_EXPORT ItemInfo
00251 {
00252 friend class KFilePlugin;
00253 friend class GroupInfo;
00254 public:
00256 ItemInfo() {}
00257
00265 const QString& prefix() const
00266 {
00267 return m_prefix;
00268 }
00269
00276 const QString& suffix() const
00277 {
00278 return m_suffix;
00279 }
00280
00287 QVariant::Type type() const
00288 {
00289 return m_type;
00290 }
00291
00296 const QString& key() const
00297 {
00298 return m_key;
00299 }
00300
00312 QString string( const QVariant& value, bool mangle = true ) const;
00313
00319 bool isVariableItem() const
00320 {
00321
00322 return key().isNull();
00323 }
00324
00331 const QString& translatedKey() const
00332 {
00333 return m_translatedKey;
00334 }
00335
00341 uint attributes() const
00342 {
00343 return m_attr;
00344 }
00345
00351 uint hint() const
00352 {
00353 return m_hint;
00354 }
00355
00361 uint unit() const
00362 {
00363 return m_unit;
00364 }
00365
00366 private:
00368 ItemInfo(const QString& key, const QString& translatedKey,
00369 QVariant::Type type)
00370 : m_key(key), m_translatedKey(translatedKey),
00371 m_type(type),
00372 m_attr(0), m_unit(NoUnit), m_hint(NoHint),
00373 m_prefix(QString::null), m_suffix(QString::null)
00374 {}
00375
00376 QString m_key;
00377 QString m_translatedKey;
00378 QVariant::Type m_type;
00379 uint m_attr;
00380 uint m_unit;
00381 uint m_hint;
00382 QString m_prefix;
00383 QString m_suffix;
00384 };
00385
00386
00387 ~KFileMimeTypeInfo();
00388
00400 QValidator * createValidator(const QString& group, const QString& key,
00401 QObject *parent = 0, const char *name = 0) const;
00402
00409 QStringList supportedGroups() const;
00410
00417 QStringList translatedGroups() const;
00418
00425 QStringList preferredGroups() const
00426 {
00427 return m_preferredGroups;
00428 }
00429
00435 QString mimeType() const {return m_mimeType;}
00436
00444 const GroupInfo * groupInfo( const QString& group ) const;
00445
00446
00447
00448
00449
00456 QStringList supportedKeys() const;
00457
00463 QStringList preferredKeys() const
00464 {
00465 return m_preferredKeys;
00466 }
00467
00468
00469 GroupInfo * addGroupInfo( const QString& name,
00470 const QString& translatedName);
00471
00472 QString m_translatedName;
00473 QStringList m_supportedKeys;
00474 uint m_attr;
00475
00476 QDict<ItemInfo> m_itemDict;
00477
00478
00479 protected:
00481 KFileMimeTypeInfo( const QString& mimeType );
00482
00483 QDict<GroupInfo> m_groups;
00484 QString m_mimeType;
00485 QStringList m_preferredKeys;
00486 QStringList m_preferredGroups;
00487 };
00488
00489
00496 class KIO_EXPORT KFileMetaInfoItem
00497 {
00498 public:
00499 class Data;
00500 typedef KFileMimeTypeInfo::Hint Hint;
00501 typedef KFileMimeTypeInfo::Unit Unit;
00502 typedef KFileMimeTypeInfo::Attributes Attributes;
00503
00509
00510 KFileMetaInfoItem( const KFileMimeTypeInfo::ItemInfo* mti,
00511 const QString& key, const QVariant& value);
00512
00516 KFileMetaInfoItem( const KFileMetaInfoItem & item );
00517
00527 const KFileMetaInfoItem& operator= (const KFileMetaInfoItem & item );
00528
00532 KFileMetaInfoItem();
00533
00534 ~KFileMetaInfoItem();
00535
00541 QString key() const;
00542
00549 QString translatedKey() const;
00550
00556 const QVariant& value() const;
00557
00566 QString string( bool mangle = true ) const;
00567
00574 bool setValue( const QVariant& value );
00575
00581 QVariant::Type type() const;
00582
00592 bool isEditable() const;
00593
00602 bool isRemoved() const;
00603
00612 bool isModified() const;
00613
00620 QString prefix() const;
00621
00628 QString suffix() const;
00629
00635 uint hint() const;
00636
00643 uint unit() const;
00644
00651 uint attributes() const;
00652
00661 bool isValid() const;
00662
00663 KIO_EXPORT friend QDataStream& operator >>(QDataStream& s, KFileMetaInfoItem& );
00664 KIO_EXPORT friend QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& );
00665 KIO_EXPORT friend QDataStream& operator <<(QDataStream& s, const KFileMetaInfoItem& );
00666 friend class KFileMetaInfoGroup;
00667
00668 protected:
00669 void setAdded();
00670 void setRemoved();
00671
00672 void ref();
00673 void deref();
00674
00675 Data *d;
00676 };
00677
00684 class KIO_EXPORT KFileMetaInfoGroup
00685 {
00686 friend class KFilePlugin;
00687 friend class KFileMetaInfo;
00688 KIO_EXPORT friend QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& );
00689 KIO_EXPORT friend QDataStream& operator <<(QDataStream& s, const KFileMetaInfoGroup& );
00690
00691 public:
00692 class Data;
00698
00699 KFileMetaInfoGroup( const QString& name, const KFileMimeTypeInfo* info );
00700
00704 KFileMetaInfoGroup( const KFileMetaInfoGroup& original );
00705
00715 const KFileMetaInfoGroup& operator= (const KFileMetaInfoGroup& info );
00716
00722 KFileMetaInfoGroup();
00723
00724 ~KFileMetaInfoGroup();
00725
00734 bool isValid() const;
00735
00742 bool isEmpty() const;
00743
00752 bool isModified() const;
00753
00758 KFileMetaInfoItem operator[]( const QString& key ) const
00759 { return item( key ); }
00760
00767 KFileMetaInfoItem item( const QString& key ) const;
00768
00775 KFileMetaInfoItem item( uint hint ) const;
00776
00784 const QVariant value( const QString& key ) const
00785 {
00786 const KFileMetaInfoItem &i = item( key );
00787 return i.value();
00788 }
00789
00800 QStringList supportedKeys() const;
00801
00808 bool supportsVariableKeys() const;
00809
00815 bool contains( const QString& key ) const;
00816
00822 QStringList keys() const;
00823
00829 QStringList preferredKeys() const;
00830
00837
00838
00839
00840
00841
00850 KFileMetaInfoItem addItem( const QString& key );
00851
00861 bool removeItem(const QString& key);
00862
00868 QStringList removedItems();
00869
00875 QString name() const;
00876
00884 QString translatedName() const;
00885
00891 uint attributes() const;
00892
00893 protected:
00894 void setAdded();
00895 KFileMetaInfoItem appendItem( const QString& key, const QVariant& value);
00896
00897 Data* d;
00898 void ref();
00899 void deref();
00900
00901 };
00902
00903
00906
00907
00926 class KIO_EXPORT KFileMetaInfo
00927 {
00928 public:
00929 typedef KFileMimeTypeInfo::Hint Hint;
00930 typedef KFileMimeTypeInfo::Unit Unit;
00931 typedef KFileMimeTypeInfo::Attributes Attributes;
00932 class Data;
00933
00938 enum What
00939 {
00940 Fastest = 0x1,
00943 DontCare = 0x2,
00944
00945 TechnicalInfo = 0x4,
00948 ContentInfo = 0x8,
00950 ExtenedAttr = 0x10,
00952 Thumbnail = 0x20,
00954 Preferred = 0x40,
00955 Everything = 0xffff
00956
00957 };
00958
00979 KFileMetaInfo( const QString& path,
00980 const QString& mimeType = QString::null,
00981 uint what = Fastest);
00982
00990 KFileMetaInfo( const KURL& url,
00991 const QString& mimeType = QString::null,
00992 uint what = Fastest);
00993
00998 KFileMetaInfo();
00999
01006 KFileMetaInfo( const KFileMetaInfo& original);
01007
01008 ~KFileMetaInfo();
01009
01020 const KFileMetaInfo& operator= (const KFileMetaInfo& info );
01021
01022
01028 QStringList groups() const;
01029
01035 QStringList supportedGroups() const;
01036
01042 QStringList preferredGroups() const;
01043
01049 QStringList preferredKeys() const;
01050
01056 QStringList supportedKeys() const;
01057
01063 QStringList editableGroups() const;
01064
01065
01066
01073 KFileMetaInfoItem item(const QString& key) const;
01080 KFileMetaInfoItem item(const KFileMetaInfoItem::Hint hint) const;
01081
01090 KFileMetaInfoItem saveItem( const QString& key,
01091 const QString& preferredGroup = QString::null,
01092 bool createGroup = true );
01093
01100 KFileMetaInfoGroup group(const QString& key) const;
01101
01108 KFileMetaInfoGroup operator[] (const QString& key) const
01109 {
01110 return group(key);
01111 }
01112
01123 bool addGroup( const QString& name );
01124
01134 bool removeGroup( const QString& name );
01135
01141 QStringList removedGroups();
01142
01150 bool applyChanges();
01151
01159 bool applyChanges(const QString& path);
01160
01167 bool contains( const QString& key ) const;
01168
01175 bool containsGroup( const QString& key ) const;
01176
01183 const QVariant value( const QString& key ) const
01184 {
01185 return item(key).value();
01186 }
01187
01188
01195 bool isValid() const;
01196
01203 bool isEmpty() const;
01204
01210 QString mimeType() const;
01211
01217 QString path() const;
01218
01224 KURL url() const;
01225
01226 KIO_EXPORT friend QDataStream& operator >>(QDataStream& s, KFileMetaInfo& );
01227 KIO_EXPORT friend QDataStream& operator <<(QDataStream& s, const KFileMetaInfo& );
01228 friend class KFilePlugin;
01229
01230 protected:
01231 KFileMetaInfoGroup appendGroup(const QString& name);
01232
01237 KFilePlugin * const plugin() const;
01238
01239 void ref();
01240 void deref();
01241
01242 Data* d;
01243
01244 private:
01245 KFileMetaInfoItem findEditableItem( KFileMetaInfoGroup& group,
01246 const QString& key );
01247
01248 void init( const KURL& url,
01249 const QString& mimeType = QString::null,
01250 uint what = Fastest);
01251 };
01252
01255
01256
01394 class KIO_EXPORT KFilePlugin : public QObject
01395 {
01396 Q_OBJECT
01397
01398 public:
01412 KFilePlugin( QObject *parent, const char *name,
01413 const QStringList& args );
01414
01418 virtual ~KFilePlugin();
01419
01432 virtual bool readInfo( KFileMetaInfo& info,
01433 uint what = KFileMetaInfo::Fastest ) = 0;
01434
01442 virtual bool writeInfo( const KFileMetaInfo& info ) const
01443 {
01444 Q_UNUSED(info);
01445 return true;
01446 }
01447
01462 virtual QValidator* createValidator( const QString& mimeType,
01463 const QString& group,
01464 const QString& key,
01465 QObject* parent,
01466 const char* name) const
01467 {
01468 Q_UNUSED(mimeType); Q_UNUSED(group);Q_UNUSED(key);
01469 Q_UNUSED(parent);Q_UNUSED(name);
01470 return 0;
01471 }
01472
01473 protected:
01474
01482 KFileMimeTypeInfo * addMimeTypeInfo( const QString& mimeType );
01483
01484
01485
01486
01487
01488
01489
01506 KFileMimeTypeInfo::GroupInfo* addGroupInfo(KFileMimeTypeInfo* info,
01507 const QString& key, const QString& translatedKey) const;
01508
01516 void setAttributes(KFileMimeTypeInfo::GroupInfo* gi, uint attr) const;
01517
01518 void addVariableInfo(KFileMimeTypeInfo::GroupInfo* gi, QVariant::Type type,
01519 uint attr) const;
01520
01535 KFileMimeTypeInfo::ItemInfo* addItemInfo(KFileMimeTypeInfo::GroupInfo* gi,
01536 const QString& key,
01537 const QString& translatedKey,
01538 QVariant::Type type);
01539
01549 void setAttributes(KFileMimeTypeInfo::ItemInfo* item, uint attr);
01550
01560 void setHint(KFileMimeTypeInfo::ItemInfo* item, uint hint);
01561
01572 void setUnit(KFileMimeTypeInfo::ItemInfo* item, uint unit);
01573
01582 void setPrefix(KFileMimeTypeInfo::ItemInfo* item, const QString& prefix);
01583
01592 void setSuffix(KFileMimeTypeInfo::ItemInfo* item, const QString& suffix);
01593
01605 KFileMetaInfoGroup appendGroup(KFileMetaInfo& info, const QString& key);
01606
01615 void appendItem(KFileMetaInfoGroup& group, const QString& key, QVariant value);
01616
01617 QStringList m_preferredKeys;
01618 QStringList m_preferredGroups;
01619
01620 protected:
01628 virtual void virtual_hook( int id, void* data );
01629 private:
01630 class KFilePluginPrivate;
01631 KFilePluginPrivate *d;
01632 };
01633
01636
01637
01646 class KIO_EXPORT KFileMetaInfoProvider: private QObject
01647 {
01648 friend class KFilePlugin;
01649
01650 Q_OBJECT
01651 public:
01652 virtual ~KFileMetaInfoProvider();
01653
01654 static KFileMetaInfoProvider * self();
01655
01660 KFilePlugin * plugin( const QString& mimeType );
01661
01667 KFilePlugin * plugin( const QString& mimeType, const QString& protocol );
01668
01669 const KFileMimeTypeInfo * mimeTypeInfo( const QString& mimeType );
01670 const KFileMimeTypeInfo * mimeTypeInfo( const QString& mimeType, const QString& protocol );
01671
01672 QStringList preferredKeys( const QString& mimeType ) const;
01673 QStringList preferredGroups( const QString& mimeType ) const;
01674
01676 QStringList supportedMimeTypes() const;
01677
01678 protected:
01679 KFileMetaInfoProvider();
01680
01681 private:
01682
01683
01684
01685
01686 struct CachedPluginInfo
01687 {
01688 CachedPluginInfo() : plugin( 0 ), mimeTypeInfo( 0 ), ownsPlugin( false ) {}
01689 CachedPluginInfo( KFilePlugin* p, KFileMimeTypeInfo* i, bool owns )
01690 : plugin( p ), mimeTypeInfo( i ), ownsPlugin( owns ) {}
01691
01692 ~CachedPluginInfo() {
01693 if ( ownsPlugin ) delete plugin;
01694 delete mimeTypeInfo;
01695 }
01696
01697
01698 KFilePlugin* plugin;
01699 KFileMimeTypeInfo* mimeTypeInfo;
01700
01701
01702
01703 bool ownsPlugin;
01704 };
01705
01706
01707
01708 QDict<CachedPluginInfo> m_plugins;
01709
01710
01711
01712
01713
01714 QDict<KFileMimeTypeInfo> m_pendingMimetypeInfos;
01715
01716 private:
01717 static KFileMetaInfoProvider * s_self;
01718
01719 KFilePlugin* loadPlugin( const QString& mimeType, const QString& protocol );
01720 KFilePlugin* loadAndRegisterPlugin( const QString& mimeType, const QString& protocol );
01721 KFileMimeTypeInfo * addMimeTypeInfo( const QString& mimeType );
01722
01723 class KFileMetaInfoProviderPrivate;
01724 KFileMetaInfoProviderPrivate *d;
01725
01726 };
01727
01728 KIO_EXPORT QDataStream& operator <<(QDataStream& s, const KFileMetaInfoItem& );
01729 KIO_EXPORT QDataStream& operator >>(QDataStream& s, KFileMetaInfoItem& );
01730
01731 KIO_EXPORT QDataStream& operator <<(QDataStream& s, const KFileMetaInfoGroup& );
01732 KIO_EXPORT QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& );
01733
01734 KIO_EXPORT QDataStream& operator <<(QDataStream& s, const KFileMetaInfo& );
01735 KIO_EXPORT QDataStream& operator >>(QDataStream& s, KFileMetaInfo& );
01736
01737
01738 #endif // KILEMETAINFO_H