| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kfilemetainfo.h

    00001 /*
    00002  *  This file is part of the KDE libraries
    00003  *  Copyright (C) 2001-2002 Rolf Magnus <ramagnus@kde.org>
    00004  *  Copyright (C) 2001-2002 Carsten Pfeiffer <pfeiffer@kde.org>
    00005  *
    00006  *  This library is free software; you can redistribute it and/or
    00007  *  modify it under the terms of the GNU Library General Public
    00008  *  License as published by the Free Software Foundation version 2.0.
    00009  *
    00010  *  This library is distributed in the hope that it will be useful,
    00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  *  Library General Public License for more details.
    00014  *
    00015  *  You should have received a copy of the GNU Library General Public License
    00016  *  along with this library; see the file COPYING.LIB.  If not, write to
    00017  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018  *  Boston, MA 02111-1307, USA.
    00019  *
    00020  *  $Id: kfilemetainfo.h,v 1.47.2.3 2003/01/29 18:21:58 mcamen Exp $
    00021  */
    00022 #ifndef KILEMETAINFO_H
    00023 #define KILEMETAINFO_H
    00024
    00025 /* Hack for HPUX: Namespace pollution
    00026    m_unit is a define in <sys/sysmacros.h> */
    00027 #define m_unit outouftheway_m_unit
    00028
    00029 #include <qdict.h>
    00030 #include <qvariant.h>
    00031 #include <qobject.h>
    00032 #include <qstring.h>
    00033
    00034 #undef m_unit
    00035
    00036 class QValidator;
    00037 class KFilePlugin;
    00038 class KFileMetaInfoGroup;
    00039
    00047 class KFileMimeTypeInfo
    00048 {
    00049     // the plugin needs to be a friend because it puts the data into the object,
    00050     // and it should be the only one allowed to do this.
    00051     friend class KFilePlugin;
    00052     friend class KFileMetaInfoProvider;
    00053
    00054 public:
    00055     KFileMimeTypeInfo() {}
    00056
    00077     enum Attributes
    00078     {
    00079         Addable     =  1,
    00080         Removable   =  2,
    00081         Modifiable  =  4,
    00082         Cummulative =  8,
    00083         Averaged    = 16,
    00084         MultiLine   = 32,
    00085         SqueezeText = 64
    00086     };
    00087
    00104     enum Hint {
    00105         NoHint      = 0,
    00106         Name        = 1,
    00107         Author      = 2,
    00108         Description = 3,
    00109         Width       = 4,
    00110         Height      = 5,
    00111         Size        = 6,
    00112         Bitrate     = 7,
    00113         Length      = 8,
    00114         Hidden      = 9,
    00115         Thumbnail   = 10
    00116     };
    00117
    00139     enum Unit {
    00140         NoUnit          = 0,
    00141         Seconds         = 1,
    00142         MilliSeconds    = 2,
    00143         BitsPerSecond   = 3,
    00144         Pixels          = 4,
    00145         Inches          = 5,
    00146         Centimeters     = 6,
    00147         Bytes           = 7,
    00148         FramesPerSecond = 8,
    00149         DotsPerInch     = 9,
    00150         BitsPerPixel    = 10,
    00151         Hertz           = 11,
    00152         KiloBytes       = 12
    00153     };
    00154
    00155
    00156     class ItemInfo;
    00157
    00163     class GroupInfo
    00164     {
    00165
    00166     friend class KFilePlugin;
    00167     friend class KFileMimeTypeInfo;
    00168     public:
    00179         QStringList supportedKeys() const
    00180         {
    00181             return m_supportedKeys;
    00182         }
    00183
    00190         const QString& name() const
    00191         {
    00192             return m_name;
    00193         }
    00194
    00202         const QString& translatedName() const
    00203         {
    00204             return m_translatedName;
    00205         }
    00206
    00214         const ItemInfo * itemInfo( const QString& key ) const;
    00215
    00221         uint attributes() const
    00222         {
    00223             return m_attr;
    00224         }
    00225
    00230         bool supportsVariableKeys() const
    00231         {
    00232             return m_variableItemInfo;
    00233         }
    00234
    00242         const ItemInfo* variableItemInfo( ) const
    00243         {
    00244             return m_variableItemInfo;
    00245         }
    00246
    00247     private:
    00249         GroupInfo( const QString& name, const QString& translatedName);
    00250
    00252         KFileMimeTypeInfo::ItemInfo* addItemInfo( const QString& key,
    00253                                                   const QString& translatedKey,
    00254                                                   QVariant::Type type);
    00255
    00257         void addVariableInfo( QVariant::Type type, uint attr );
    00258
    00259         QString         m_name;
    00260         QString         m_translatedName;
    00261         QStringList     m_supportedKeys;
    00262         uint            m_attr;
    00263         ItemInfo*       m_variableItemInfo;
    00264         QDict<ItemInfo> m_itemDict;
    00265
    00266     };
    00267
    00273     class ItemInfo
    00274     {
    00275     friend class KFilePlugin;
    00276     friend class GroupInfo;
    00277     public:
    00279         ItemInfo() {}     // ### should be private?
    00280
    00288         const QString& prefix() const
    00289         {
    00290             return m_prefix;
    00291         }
    00292
    00299         const QString& suffix() const
    00300         {
    00301             return m_suffix;
    00302         }
    00303
    00310         QVariant::Type type() const
    00311         {
    00312             return m_type;
    00313         }
    00314
    00318         const QString& key() const
    00319         {
    00320             return m_key;
    00321         }
    00322
    00332         QString string( const QVariant& value, bool mangle = true ) const;
    00333
    00339         bool isVariableItem() const
    00340         {
    00341             // every valid item is supposed to have a non-null key
    00342             return key().isNull();
    00343         }
    00344
    00350         const QString& translatedKey() const
    00351         {
    00352             return m_translatedKey;
    00353         }
    00354
    00359         uint attributes() const
    00360         {
    00361             return m_attr;
    00362         }
    00363
    00368         uint hint() const
    00369         {
    00370             return m_hint;
    00371         }
    00372
    00377         uint unit() const
    00378         {
    00379             return m_unit;
    00380         }
    00381
    00382     private:
    00384         ItemInfo(const QString& key, const QString& translatedKey,
    00385                  QVariant::Type type)
    00386             : m_key(key), m_translatedKey(translatedKey),
    00387               m_type(type),
    00388               m_attr(0), m_unit(NoUnit), m_hint(NoHint),
    00389               m_prefix(QString::null), m_suffix(QString::null)
    00390         {}
    00391
    00392         QString           m_key;
    00393         QString           m_translatedKey;
    00394         QVariant::Type    m_type;
    00395         uint              m_attr;
    00396         uint              m_unit;
    00397         uint              m_hint;
    00398         QString           m_prefix;
    00399         QString           m_suffix;
    00400     };
    00401
    00402     // ### could it be made private? Would this be BC?
    00403     ~KFileMimeTypeInfo();
    00404
    00409     QValidator * createValidator(const QString& group, const QString& key,
    00410                                  QObject *parent = 0, const char *name = 0) const;
    00411
    00418     QStringList supportedGroups() const;
    00419
    00426     QStringList translatedGroups() const;
    00427
    00434     QStringList preferredGroups() const
    00435     {
    00436         return m_preferredGroups;
    00437     }
    00438
    00442     QString mimeType()  const {return m_mimeType;}
    00443
    00449     const GroupInfo * groupInfo( const QString& group ) const;
    00450
    00451     // always returning stringlists which the user has to iterate and use them
    00452     // to look up the real items sounds strange to me. I think we should add
    00453     // our own iterators some time (somewhere in the future ;)
    00454
    00461     QStringList supportedKeys() const;
    00462
    00468     QStringList preferredKeys() const
    00469     {
    00470         return m_preferredKeys;
    00471     }
    00472
    00473     // ### shouldn't this be private? BC?
    00474     GroupInfo * addGroupInfo( const QString& name,
    00475                               const QString& translatedName);
    00476
    00477     QString         m_translatedName;
    00478     QStringList     m_supportedKeys;
    00479     uint            m_attr;
    00480     //        bool            m_supportsVariableKeys : 1;
    00481     QDict<ItemInfo> m_itemDict;
    00482
    00483 // ### this should be made private instead, but this would be BIC
    00484 protected:
    00486     KFileMimeTypeInfo( const QString& mimeType );
    00487
    00488     QDict<GroupInfo> m_groups;
    00489     QString     m_mimeType;
    00490     QStringList m_preferredKeys;   // same as KFileMetaInfoProvider::preferredKeys()
    00491     QStringList m_preferredGroups; // same as KFileMetaInfoProvider::preferredKeys()
    00492 };
    00493
    00494
    00499 class KFileMetaInfoItem
    00500 {
    00501 public:
    00502     class Data;
    00503     typedef KFileMimeTypeInfo::Hint Hint;
    00504     typedef KFileMimeTypeInfo::Unit Unit;
    00505     typedef KFileMimeTypeInfo::Attributes Attributes;
    00506
    00512     // ### hmm, then it should be private
    00513     KFileMetaInfoItem( const KFileMimeTypeInfo::ItemInfo* mti,
    00514                        const QString& key, const QVariant& value);
    00515
    00519     KFileMetaInfoItem( const KFileMetaInfoItem & item );
    00520
    00530     const KFileMetaInfoItem& operator= (const KFileMetaInfoItem & item );
    00531
    00535     KFileMetaInfoItem();
    00536
    00537     ~KFileMetaInfoItem();
    00538
    00542     QString key() const;
    00543
    00548     QString translatedKey() const;
    00549
    00553     const QVariant& value() const;
    00554
    00561     QString string( bool mangle = true ) const;
    00562
    00566     bool setValue( const QVariant& value );
    00567
    00572     QVariant::Type type() const;
    00573
    00581     bool isEditable() const;
    00582
    00591     bool isRemoved() const;
    00592
    00601     bool isModified() const;
    00602
    00609     QString prefix() const;
    00610
    00617     QString suffix() const;
    00618
    00622     uint hint() const;
    00623
    00627     uint unit() const;
    00628
    00633     uint attributes() const;
    00634
    00641     bool isValid() const;
    00642
    00643     friend QDataStream& operator >>(QDataStream& s, KFileMetaInfoItem& );
    00644     friend QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& );
    00645     friend QDataStream& operator <<(QDataStream& s, const KFileMetaInfoItem& );
    00646     friend class KFileMetaInfoGroup;
    00647
    00648 protected:
    00649     void setAdded();
    00650     void setRemoved();
    00651
    00652     void ref();
    00653     void deref();
    00654
    00655     Data *d;
    00656 };
    00657
    00662 class KFileMetaInfoGroup
    00663 {
    00664   friend class KFilePlugin;
    00665   friend class KFileMetaInfo;
    00666   friend QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& );
    00667   friend QDataStream& operator <<(QDataStream& s, const KFileMetaInfoGroup& );
    00668
    00669 public:
    00670     class Data;
    00676     // ### hmm, then it should be private
    00677     KFileMetaInfoGroup( const QString& name, const KFileMimeTypeInfo* info );
    00678
    00682     KFileMetaInfoGroup( const KFileMetaInfoGroup& original );
    00683
    00693     const KFileMetaInfoGroup& operator= (const KFileMetaInfoGroup& info );
    00694
    00699      KFileMetaInfoGroup();
    00700
    00701     ~KFileMetaInfoGroup();
    00702
    00709     bool isValid() const;
    00710
    00715     bool isEmpty() const;
    00716
    00723     bool isModified() const;
    00724
    00729     KFileMetaInfoItem operator[]( const QString& key ) const
    00730     { return item( key ); }
    00731
    00737     KFileMetaInfoItem item( const QString& key ) const;
    00738
    00742     KFileMetaInfoItem item( uint hint ) const;
    00743
    00748     const QVariant value( const QString& key ) const
    00749     {
    00750         const KFileMetaInfoItem &i = item( key );
    00751         return i.value();
    00752     }
    00753
    00754
    00765     QStringList supportedKeys() const;
    00766
    00771     bool supportsVariableKeys() const;
    00772
    00776     bool contains( const QString& key ) const;
    00777
    00781     QStringList keys() const;
    00782
    00786     QStringList preferredKeys() const;
    00787
    00794     // ### do we really want to support that?
    00795     // let's not waste time on thinking about it. Let's just kick it for now
    00796     // and add it in 4.0 if needed ;)
    00797 //    const QMemArray<QVariant::Type>& types( const QString& key ) const;
    00798
    00804     KFileMetaInfoItem addItem( const QString& key );
    00805
    00812     bool removeItem(const QString& key);
    00813
    00814     QStringList removedItems();
    00815
    00816     QString name() const;
    00817
    00818     uint attributes() const;
    00819
    00820 protected:
    00821       void setAdded();
    00822       KFileMetaInfoItem appendItem( const QString& key, const QVariant& value);
    00823
    00824       Data* d;
    00825       void ref();
    00826       void deref();
    00827
    00828 };
    00829
    00830
    00833
    00834
    00853 class KFileMetaInfo
    00854 {
    00855 public:
    00856     typedef KFileMimeTypeInfo::Hint Hint;
    00857     typedef KFileMimeTypeInfo::Unit Unit;
    00858     typedef KFileMimeTypeInfo::Attributes Attributes;
    00859     class Data;
    00860
    00880     enum What
    00881     {
    00882       Fastest       = 0x1,
    00883       DontCare      = 0x2,
    00884       TechnicalInfo = 0x4,
    00885       ContentInfo   = 0x8,
    00886       ExtenedAttr   = 0x10,
    00887       Thumbnail     = 0x20,
    00888       Preferred     = 0x40,
    00889       Everything    = 0xffff // all bits 1 (this also makes sure the enum is
    00890                              // at least 16bit, so there is more space for
    00891                              // new values)
    00892
    00893     };
    00894
    00913     KFileMetaInfo( const QString& path,
    00914                    const QString& mimeType = QString::null,
    00915                    uint what = Fastest);
    00916
    00921     KFileMetaInfo();
    00922
    00926     KFileMetaInfo( const KFileMetaInfo& original);
    00927
    00928     ~KFileMetaInfo();
    00929
    00940     const KFileMetaInfo& operator= (const KFileMetaInfo& info );
    00941
    00942
    00946     QStringList groups() const;
    00947
    00948     QStringList supportedGroups() const;
    00949
    00950     QStringList preferredGroups() const;
    00951
    00952     QStringList preferredKeys() const;
    00953
    00954     QStringList supportedKeys() const;
    00955
    00959     QStringList editableGroups() const;
    00960
    00961     // I'd like to keep those for lookup without group, at least the hint
    00962     // version
    00963     KFileMetaInfoItem item(const QString& key) const;
    00964     KFileMetaInfoItem item(const KFileMetaInfoItem::Hint hint) const;
    00965     KFileMetaInfoItem saveItem( const QString& key,
    00966                                 const QString& preferredGroup = QString::null,
    00967                                 bool createGroup = true );
    00968
    00969     KFileMetaInfoGroup group(const QString& key) const;
    00970
    00971     KFileMetaInfoGroup operator[] (const QString& key) const
    00972     {
    00973         return group(key);
    00974     }
    00975
    00982     bool addGroup( const QString& name );
    00983
    00990     bool removeGroup( const QString& name );
    00991
    00992     QStringList removedGroups();
    00993
    01000     bool applyChanges();
    01001
    01005     bool contains( const QString& key ) const;
    01006
    01010     bool containsGroup( const QString& key ) const;
    01011
    01012     const QVariant value( const QString& key ) const
    01013     {
    01014         return item(key).value();
    01015     }
    01016
    01017
    01022     bool isValid() const;
    01023
    01028     bool isEmpty() const;
    01029
    01030     QString mimeType() const;
    01031
    01032     QString path() const;
    01033
    01034     friend QDataStream& operator >>(QDataStream& s, KFileMetaInfo& );
    01035     friend QDataStream& operator <<(QDataStream& s, const KFileMetaInfo& );
    01036     friend class KFilePlugin;
    01037
    01038 protected:
    01039     KFileMetaInfoGroup appendGroup(const QString& name);
    01040
    01045     KFilePlugin * const plugin() const;
    01046
    01047     void ref();
    01048     void deref();
    01049
    01050     Data* d;
    01051
    01052 private:
    01053     KFileMetaInfoItem findEditableItem( KFileMetaInfoGroup& group,
    01054                                         const QString& key );
    01055 };
    01056
    01059
    01060
    01078 class KFilePlugin : public QObject
    01079 {
    01080     Q_OBJECT
    01081
    01082 public:
    01083     KFilePlugin( QObject *parent, const char *name,
    01084                  const QStringList& args );
    01085
    01086     virtual ~KFilePlugin();
    01087
    01093     virtual bool readInfo( KFileMetaInfo& info,
    01094                            uint what = KFileMetaInfo::Fastest ) = 0;
    01095
    01100     virtual bool writeInfo( const KFileMetaInfo& /*info*/ ) const
    01101     {
    01102         return true;
    01103     }
    01104
    01113     virtual QValidator* createValidator( const QString& /* mimeType */,
    01114                                          const QString& /* group */,
    01115                                          const QString& /* key */,
    01116                                          QObject* /*parent*/,
    01117                                          const char* /*name*/) const
    01118     {
    01119         return 0;
    01120     }
    01121
    01122 protected:
    01123
    01124     KFileMimeTypeInfo::GroupInfo*  addGroupInfo(KFileMimeTypeInfo* info,
    01125                       const QString& key, const QString& translatedKey) const;
    01126     void setAttributes(KFileMimeTypeInfo::GroupInfo* gi, uint attr) const;
    01127     void addVariableInfo(KFileMimeTypeInfo::GroupInfo* gi, QVariant::Type type,
    01128                          uint attr) const;
    01129     KFileMimeTypeInfo::ItemInfo* addItemInfo(KFileMimeTypeInfo::GroupInfo* gi,
    01130                                              const QString& key,
    01131                                              const QString& translatedKey,
    01132                                              QVariant::Type type);
    01133     void setAttributes(KFileMimeTypeInfo::ItemInfo* item, uint attr);
    01134     void setHint(KFileMimeTypeInfo::ItemInfo* item, uint hint);
    01135     void setUnit(KFileMimeTypeInfo::ItemInfo* item, uint unit);
    01136     void setPrefix(KFileMimeTypeInfo::ItemInfo* item, const QString& prefix);
    01137     void setSuffix(KFileMimeTypeInfo::ItemInfo* item, const QString& suffix);
    01138     KFileMetaInfoGroup appendGroup(KFileMetaInfo& info, const QString& key);
    01139     void appendItem(KFileMetaInfoGroup& group, const QString& key, QVariant value);
    01140
    01144     // ### do we need this, if it only calls the provider?
    01145     // IMHO the Plugin shouldn't call its provider.
    01146     KFileMimeTypeInfo * addMimeTypeInfo( const QString& mimeType );
    01147
    01148     QStringList m_preferredKeys;
    01149     QStringList m_preferredGroups;
    01150
    01151 protected:
    01152     virtual void virtual_hook( int id, void* data );
    01153 private:
    01154     class KFilePluginPrivate;
    01155     KFilePluginPrivate *d;
    01156 };
    01157
    01160
    01161
    01168 class KFileMetaInfoProvider: QObject
    01169 {
    01170     friend class KFilePlugin;
    01171
    01172   Q_OBJECT
    01173 public:
    01174     virtual ~KFileMetaInfoProvider();
    01175
    01176     static KFileMetaInfoProvider * self();
    01177
    01182     KFilePlugin * plugin( const QString& mimeType );
    01183
    01184     const KFileMimeTypeInfo * mimeTypeInfo( const QString& mimeType );
    01185
    01186     QStringList preferredKeys( const QString& mimeType ) const;
    01187     QStringList preferredGroups( const QString& mimeType ) const;
    01188
    01190     QStringList supportedMimeTypes() const;
    01191
    01192 protected:
    01193     KFileMetaInfoProvider();
    01194
    01195     QDict<KFilePlugin> m_plugins;
    01196     QDict<KFileMimeTypeInfo> m_mimeTypeDict;
    01197
    01198 private:
    01199     static KFileMetaInfoProvider * s_self;
    01200
    01201     KFileMimeTypeInfo * addMimeTypeInfo( const QString& mimeType );
    01202
    01203     class KFileMetaInfoProviderPrivate;
    01204     KFileMetaInfoProviderPrivate *d;
    01205
    01206 };
    01207
    01208 QDataStream& operator <<(QDataStream& s, const KFileMetaInfoItem& );
    01209 QDataStream& operator >>(QDataStream& s, KFileMetaInfoItem& );
    01210
    01211 QDataStream& operator <<(QDataStream& s, const KFileMetaInfoGroup& );
    01212 QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& );
    01213
    01214 QDataStream& operator <<(QDataStream& s, const KFileMetaInfo& );
    01215 QDataStream& operator >>(QDataStream& s, KFileMetaInfo& );
    01216
    01217
    01218 #endif // KILEMETAINFO_H

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:13:32 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001