kfilemetainfo.h
/*
* This file is part of the KDE libraries
* Copyright (C) 2001-2002 Rolf Magnus <ramagnus@kde.org>
* Copyright (C) 2001-2002 Carsten Pfeiffer <pfeiffer@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation version 2.0.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KILEMETAINFO_H
#define KILEMETAINFO_H
/* Hack for HPUX: Namespace pollution
m_unit is a define in <sys/sysmacros.h> */
#define m_unit outouftheway_m_unit
#include <qdict.h>
#include <qvariant.h>
#include <qobject.h>
#include <qstring.h>
#include <kurl.h>
#undef m_unit
class QValidator;
class KFilePlugin;
class KFileMetaInfoGroup;
class KIO_EXPORT KFileMimeTypeInfo
{
// the plugin needs to be a friend because it puts the data into the object,
// and it should be the only one allowed to do this.
friend class KFilePlugin;
friend class KFileMetaInfoProvider;
public:
KFileMimeTypeInfo() {}
enum Attributes
{
Addable = 1,
Removable = 2,
Modifiable = 4,
Cumulative = 8,
Cummulative = Cumulative,
Averaged = 16,
MultiLine = 32,
SqueezeText = 64
};
enum Hint {
NoHint = 0,
Name = 1,
Author = 2,
Description = 3,
Width = 4,
Height = 5,
Size = 6,
Bitrate = 7,
Length = 8,
Hidden = 9,
Thumbnail = 10
};
enum Unit {
NoUnit = 0,
Seconds = 1,
MilliSeconds = 2,
BitsPerSecond = 3,
Pixels = 4,
Inches = 5,
Centimeters = 6,
Bytes = 7,
FramesPerSecond = 8,
DotsPerInch = 9,
BitsPerPixel = 10,
Hertz = 11,
KiloBytes = 12,
Millimeters = 13
};
class ItemInfo;
class KIO_EXPORT GroupInfo
{
friend class KFilePlugin;
friend class KFileMimeTypeInfo;
public:
QStringList supportedKeys() const
{
return m_supportedKeys;
}
const QString& name() const
{
return m_name;
}
const QString& translatedName() const
{
return m_translatedName;
}
const ItemInfo * itemInfo( const QString& key ) const;
uint attributes() const
{
return m_attr;
}
bool supportsVariableKeys() const
{
return m_variableItemInfo;
}
const ItemInfo* variableItemInfo( ) const
{
return m_variableItemInfo;
}
~GroupInfo();
private:
GroupInfo( const QString& name, const QString& translatedName);
KFileMimeTypeInfo::ItemInfo* addItemInfo( const QString& key,
const QString& translatedKey,
QVariant::Type type);
void addVariableInfo( QVariant::Type type, uint attr );
QString m_name;
QString m_translatedName;
QStringList m_supportedKeys;
uint m_attr;
ItemInfo* m_variableItemInfo;
QDict<ItemInfo> m_itemDict;
};
class KIO_EXPORT ItemInfo
{
friend class KFilePlugin;
friend class GroupInfo;
public:
ItemInfo() {} // ### should be private?
const QString& prefix() const
{
return m_prefix;
}
const QString& suffix() const
{
return m_suffix;
}
QVariant::Type type() const
{
return m_type;
}
const QString& key() const
{
return m_key;
}
QString string( const QVariant& value, bool mangle = true ) const;
bool isVariableItem() const
{
// every valid item is supposed to have a non-null key
return key().isNull();
}
const QString& translatedKey() const
{
return m_translatedKey;
}
uint attributes() const
{
return m_attr;
}
uint hint() const
{
return m_hint;
}
uint unit() const
{
return m_unit;
}
private:
ItemInfo(const QString& key, const QString& translatedKey,
QVariant::Type type)
: m_key(key), m_translatedKey(translatedKey),
m_type(type),
m_attr(0), m_unit(NoUnit), m_hint(NoHint),
m_prefix(QString::null), m_suffix(QString::null)
{}
QString m_key;
QString m_translatedKey;
QVariant::Type m_type;
uint m_attr;
uint m_unit;
uint m_hint;
QString m_prefix;
QString m_suffix;
};
// ### could it be made private? Would this be BC?
~KFileMimeTypeInfo();
QValidator * createValidator(const QString& group, const QString& key,
QObject *parent = 0, const char *name = 0) const;
QStringList supportedGroups() const;
QStringList translatedGroups() const;
QStringList preferredGroups() const
{
return m_preferredGroups;
}
QString mimeType() const {return m_mimeType;}
const GroupInfo * groupInfo( const QString& group ) const;
// always returning stringlists which the user has to iterate and use them
// to look up the real items sounds strange to me. I think we should add
// our own iterators some time (somewhere in the future ;)
QStringList supportedKeys() const;
QStringList preferredKeys() const
{
return m_preferredKeys;
}
// ### shouldn't this be private? BC?
GroupInfo * addGroupInfo( const QString& name,
const QString& translatedName);
QString m_translatedName;
QStringList m_supportedKeys;
uint m_attr;
// bool m_supportsVariableKeys : 1;
QDict<ItemInfo> m_itemDict;
// ### this should be made private instead, but this would be BIC
protected:
KFileMimeTypeInfo( const QString& mimeType );
QDict<GroupInfo> m_groups;
QString m_mimeType;
QStringList m_preferredKeys; // same as KFileMetaInfoProvider::preferredKeys()
QStringList m_preferredGroups; // same as KFileMetaInfoProvider::preferredKeys()
};
class KIO_EXPORT KFileMetaInfoItem
{
public:
class Data;
typedef KFileMimeTypeInfo::Hint Hint;
typedef KFileMimeTypeInfo::Unit Unit;
typedef KFileMimeTypeInfo::Attributes Attributes;
// ### hmm, then it should be private
KFileMetaInfoItem( const KFileMimeTypeInfo::ItemInfo* mti,
const QString& key, const QVariant& value);
KFileMetaInfoItem( const KFileMetaInfoItem & item );
const KFileMetaInfoItem& operator= (const KFileMetaInfoItem & item );
KFileMetaInfoItem();
~KFileMetaInfoItem();
QString key() const;
QString translatedKey() const;
const QVariant& value() const;
QString string( bool mangle = true ) const;
bool setValue( const QVariant& value );
QVariant::Type type() const;
bool isEditable() const;
bool isRemoved() const;
bool isModified() const;
QString prefix() const;
QString suffix() const;
uint hint() const;
uint unit() const;
uint attributes() const;
bool isValid() const;
KIO_EXPORT friend QDataStream& operator >>(QDataStream& s, KFileMetaInfoItem& );
KIO_EXPORT friend QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& );
KIO_EXPORT friend QDataStream& operator <<(QDataStream& s, const KFileMetaInfoItem& );
friend class KFileMetaInfoGroup;
protected:
void setAdded();
void setRemoved();
void ref();
void deref();
Data *d;
};
class KIO_EXPORT KFileMetaInfoGroup
{
friend class KFilePlugin;
friend class KFileMetaInfo;
KIO_EXPORT friend QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& );
KIO_EXPORT friend QDataStream& operator <<(QDataStream& s, const KFileMetaInfoGroup& );
public:
class Data;
// ### hmm, then it should be private
KFileMetaInfoGroup( const QString& name, const KFileMimeTypeInfo* info );
KFileMetaInfoGroup( const KFileMetaInfoGroup& original );
const KFileMetaInfoGroup& operator= (const KFileMetaInfoGroup& info );
KFileMetaInfoGroup();
~KFileMetaInfoGroup();
bool isValid() const;
bool isEmpty() const;
bool isModified() const;
KFileMetaInfoItem operator[]( const QString& key ) const
{ return item( key ); }
KFileMetaInfoItem item( const QString& key ) const;
KFileMetaInfoItem item( uint hint ) const;
const QVariant value( const QString& key ) const
{
const KFileMetaInfoItem &i = item( key );
return i.value();
}
QStringList supportedKeys() const;
bool supportsVariableKeys() const;
bool contains( const QString& key ) const;
QStringList keys() const;
QStringList preferredKeys() const;
// ### do we really want to support that?
// let's not waste time on thinking about it. Let's just kick it for now
// and add it in 4.0 if needed ;)
// const QMemArray<QVariant::Type>& types( const QString& key ) const;
KFileMetaInfoItem addItem( const QString& key );
bool removeItem(const QString& key);
QStringList removedItems();
QString name() const;
QString translatedName() const;
uint attributes() const;
protected:
void setAdded();
KFileMetaInfoItem appendItem( const QString& key, const QVariant& value);
Data* d;
void ref();
void deref();
};
class KIO_EXPORT KFileMetaInfo
{
public:
typedef KFileMimeTypeInfo::Hint Hint;
typedef KFileMimeTypeInfo::Unit Unit;
typedef KFileMimeTypeInfo::Attributes Attributes;
class Data;
enum What
{
Fastest = 0x1,
DontCare = 0x2,
TechnicalInfo = 0x4,
ContentInfo = 0x8,
ExtenedAttr = 0x10,
Thumbnail = 0x20,
Preferred = 0x40,
Everything = 0xffff
};
KFileMetaInfo( const QString& path,
const QString& mimeType = QString::null,
uint what = Fastest);
KFileMetaInfo( const KURL& url,
const QString& mimeType = QString::null,
uint what = Fastest);
KFileMetaInfo();
KFileMetaInfo( const KFileMetaInfo& original);
~KFileMetaInfo();
const KFileMetaInfo& operator= (const KFileMetaInfo& info );
QStringList groups() const;
QStringList supportedGroups() const;
QStringList preferredGroups() const;
QStringList preferredKeys() const;
QStringList supportedKeys() const;
QStringList editableGroups() const;
// I'd like to keep those for lookup without group, at least the hint
// version
KFileMetaInfoItem item(const QString& key) const;
KFileMetaInfoItem item(const KFileMetaInfoItem::Hint hint) const;
KFileMetaInfoItem saveItem( const QString& key,
const QString& preferredGroup = QString::null,
bool createGroup = true );
KFileMetaInfoGroup group(const QString& key) const;
KFileMetaInfoGroup operator[] (const QString& key) const
{
return group(key);
}
bool addGroup( const QString& name );
bool removeGroup( const QString& name );
QStringList removedGroups();
bool applyChanges();
bool applyChanges(const QString& path);
bool contains( const QString& key ) const;
bool containsGroup( const QString& key ) const;
const QVariant value( const QString& key ) const
{
return item(key).value();
}
bool isValid() const;
bool isEmpty() const;
QString mimeType() const;
QString path() const;
KURL url() const;
KIO_EXPORT friend QDataStream& operator >>(QDataStream& s, KFileMetaInfo& );
KIO_EXPORT friend QDataStream& operator <<(QDataStream& s, const KFileMetaInfo& );
friend class KFilePlugin;
protected:
KFileMetaInfoGroup appendGroup(const QString& name);
KFilePlugin * const plugin() const;
void ref();
void deref();
Data* d;
private:
KFileMetaInfoItem findEditableItem( KFileMetaInfoGroup& group,
const QString& key );
void init( const KURL& url,
const QString& mimeType = QString::null,
uint what = Fastest);
};
class KIO_EXPORT KFilePlugin : public QObject
{
Q_OBJECT
public:
KFilePlugin( QObject *parent, const char *name,
const QStringList& args );
virtual ~KFilePlugin();
virtual bool readInfo( KFileMetaInfo& info,
uint what = KFileMetaInfo::Fastest ) = 0;
virtual bool writeInfo( const KFileMetaInfo& info ) const
{
Q_UNUSED(info);
return true;
}
virtual QValidator* createValidator( const QString& mimeType,
const QString& group,
const QString& key,
QObject* parent,
const char* name) const
{
Q_UNUSED(mimeType); Q_UNUSED(group);Q_UNUSED(key);
Q_UNUSED(parent);Q_UNUSED(name);
return 0;
}
protected:
KFileMimeTypeInfo * addMimeTypeInfo( const QString& mimeType );
// ### do we need this, if it only calls the provider?
// IMHO the Plugin shouldn't call its provider.
// DF: yes we need this. A plugin can create more than one mimetypeinfo.
// What sucks though, is to let plugins do that in their ctor.
// Would be much simpler to have a virtual init method for that,
// so that the provider can set up stuff with the plugin pointer first!
KFileMimeTypeInfo::GroupInfo* addGroupInfo(KFileMimeTypeInfo* info,
const QString& key, const QString& translatedKey) const;
void setAttributes(KFileMimeTypeInfo::GroupInfo* gi, uint attr) const;
void addVariableInfo(KFileMimeTypeInfo::GroupInfo* gi, QVariant::Type type,
uint attr) const;
KFileMimeTypeInfo::ItemInfo* addItemInfo(KFileMimeTypeInfo::GroupInfo* gi,
const QString& key,
const QString& translatedKey,
QVariant::Type type);
void setAttributes(KFileMimeTypeInfo::ItemInfo* item, uint attr);
void setHint(KFileMimeTypeInfo::ItemInfo* item, uint hint);
void setUnit(KFileMimeTypeInfo::ItemInfo* item, uint unit);
void setPrefix(KFileMimeTypeInfo::ItemInfo* item, const QString& prefix);
void setSuffix(KFileMimeTypeInfo::ItemInfo* item, const QString& suffix);
KFileMetaInfoGroup appendGroup(KFileMetaInfo& info, const QString& key);
void appendItem(KFileMetaInfoGroup& group, const QString& key, QVariant value);
QStringList m_preferredKeys;
QStringList m_preferredGroups;
protected:
virtual void virtual_hook( int id, void* data );
private:
class KFilePluginPrivate;
KFilePluginPrivate *d;
};
class KIO_EXPORT KFileMetaInfoProvider: private QObject
{
friend class KFilePlugin;
Q_OBJECT
public:
virtual ~KFileMetaInfoProvider();
static KFileMetaInfoProvider * self();
KFilePlugin * plugin( const QString& mimeType ); // KDE4: merge with method below
KFilePlugin * plugin( const QString& mimeType, const QString& protocol );
const KFileMimeTypeInfo * mimeTypeInfo( const QString& mimeType ); // KDE4: merge with below
const KFileMimeTypeInfo * mimeTypeInfo( const QString& mimeType, const QString& protocol );
QStringList preferredKeys( const QString& mimeType ) const;
QStringList preferredGroups( const QString& mimeType ) const;
QStringList supportedMimeTypes() const;
protected: // ## should be private, right?
KFileMetaInfoProvider();
private:
// Data structure:
// Mimetype or Protocol -> { Plugin and MimeTypeInfo }
// The {} struct is CachedPluginInfo
struct CachedPluginInfo
{
CachedPluginInfo() : plugin( 0 ), mimeTypeInfo( 0 ), ownsPlugin( false ) {}
CachedPluginInfo( KFilePlugin* p, KFileMimeTypeInfo* i, bool owns )
: plugin( p ), mimeTypeInfo( i ), ownsPlugin( owns ) {}
// auto-delete behavior
~CachedPluginInfo() {
if ( ownsPlugin ) delete plugin;
delete mimeTypeInfo;
}
// If plugin and mimeTypeInfo are 0, means that no plugin is available.
KFilePlugin* plugin;
KFileMimeTypeInfo* mimeTypeInfo;
// The problem here is that plugin can be shared in multiple instances,
// so the memory management isn't easy. KDE4 solution: use KSharedPtr?
// For now we flag one copy of the KFilePlugin pointer as being "owned".
bool ownsPlugin;
};
// The key is either a mimetype or a protocol. Those things don't look the same
// so there's no need for two QDicts.
QDict<CachedPluginInfo> m_plugins;
// This data is aggregated during the creation of a plugin,
// before being moved to the appropriate CachedPluginInfo(s)
// At any other time than during the loading of a plugin, this dict is EMPTY.
// Same key as in m_plugins: mimetype or protocol
QDict<KFileMimeTypeInfo> m_pendingMimetypeInfos;
private:
static KFileMetaInfoProvider * s_self;
KFilePlugin* loadPlugin( const QString& mimeType, const QString& protocol );
KFilePlugin* loadAndRegisterPlugin( const QString& mimeType, const QString& protocol );
KFileMimeTypeInfo * addMimeTypeInfo( const QString& mimeType );
class KFileMetaInfoProviderPrivate;
KFileMetaInfoProviderPrivate *d;
};
KIO_EXPORT QDataStream& operator <<(QDataStream& s, const KFileMetaInfoItem& );
KIO_EXPORT QDataStream& operator >>(QDataStream& s, KFileMetaInfoItem& );
KIO_EXPORT QDataStream& operator <<(QDataStream& s, const KFileMetaInfoGroup& );
KIO_EXPORT QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& );
KIO_EXPORT QDataStream& operator <<(QDataStream& s, const KFileMetaInfo& );
KIO_EXPORT QDataStream& operator >>(QDataStream& s, KFileMetaInfo& );
#endif // KILEMETAINFO_H
KFileMetaInfo::value
const QVariant value(const QString &key) const
Returns the value with the given key.
Definition: kfilemetainfo.h:1183
KFileMimeTypeInfo::ItemInfo::hint
uint hint() const
Return the hints for the item.
Definition: kfilemetainfo.h:351
KFileMimeTypeInfo::GroupInfo
Information about a meta information group.
Definition: kfilemetainfo.h:138
KFileMetaInfoItem
A meta information item about a file.
Definition: kfilemetainfo.h:496
KFileMimeTypeInfo::Unit
Unit
This enum exists so that you can specify units for items, which you can usually use for integer items...
Definition: kfilemetainfo.h:111
KFileMimeTypeInfo::GroupInfo::name
const QString & name() const
Use this method to get the name of the group.
Definition: kfilemetainfo.h:165
KFileMimeTypeInfo::Hint
Hint
This enum is mainly for items that have a special meaning for some applications.
Definition: kfilemetainfo.h:89
KFileMimeTypeInfo::Attributes
Attributes
This enum is used to specify some attributes that an item can have, which fit neither in the Hint nor...
Definition: kfilemetainfo.h:64
KFileMetaInfo::Fastest
do the fastest possible read and omit all items that might need a significantly longer time than the ...
Definition: kfilemetainfo.h:940
KFileMetaInfoGroup
A group of meta information items about a file.
Definition: kfilemetainfo.h:684
KFileMimeTypeInfo::ItemInfo::attributes
uint attributes() const
Return the attributes of the item.
Definition: kfilemetainfo.h:341
KFileMimeTypeInfo::preferredGroups
QStringList preferredGroups() const
This returns the list of groups in the preferred order that's specified in the .desktop file...
Definition: kfilemetainfo.h:425
KFilePlugin::appendGroup
KFileMetaInfoGroup appendGroup(KFileMetaInfo &info, const QString &key)
Call this method from within readInfo() to indicate that you wish to fill meta information items of t...
Definition: kfilemetainfo.cpp:894
KFileMimeTypeInfo::GroupInfo::attributes
uint attributes() const
Get the attributes of this group (see Attributes)
Definition: kfilemetainfo.h:196
KFileMimeTypeInfo::GroupInfo::supportsVariableKeys
bool supportsVariableKeys() const
Definition: kfilemetainfo.h:205
KFileMimeTypeInfo::preferredKeys
QStringList preferredKeys() const
Return a list of all supported keys in preference order.
Definition: kfilemetainfo.h:463
KFilePlugin::writeInfo
virtual bool writeInfo(const KFileMetaInfo &info) const
Similar to the readInfo() but for writing the info back to the file.
Definition: kfilemetainfo.h:1442
KFileMetaInfoGroup::operator[]
KFileMetaInfoItem operator[](const QString &key) const
Operator for convenience.
Definition: kfilemetainfo.h:758
KFileMetaInfoGroup::value
const QVariant value(const QString &key) const
Convenience function.
Definition: kfilemetainfo.h:784
KFileMimeTypeInfo
Represents the capabilities of a KFilePlugin for a given mimetype.
Definition: kfilemetainfo.h:50
KFileMetaInfo
Meta Information about a file.
Definition: kfilemetainfo.h:926
KFileMimeTypeInfo::ItemInfo::type
QVariant::Type type() const
The items for a file are stored as a QVariant and this method can be used to get the data type of thi...
Definition: kfilemetainfo.h:287
KFilePlugin
Base class for a meta information plugin.
Definition: kfilemetainfo.h:1394
KFileMimeTypeInfo::GroupInfo::translatedName
const QString & translatedName() const
Use this method to get the string to display to the user as group name.
Definition: kfilemetainfo.h:177
KFileMimeTypeInfo::mimeType
QString mimeType() const
Returns the mimetype to which this info belongs.
Definition: kfilemetainfo.h:435
KFileMimeTypeInfo::ItemInfo::isVariableItem
bool isVariableItem() const
Is this item the variable item?
Definition: kfilemetainfo.h:319
KFileMetaInfo::What
What
This is used to specify what a KFileMetaInfo object should read, so you can specify if you want to re...
Definition: kfilemetainfo.h:938
KFileMimeTypeInfo::ItemInfo::translatedKey
const QString & translatedKey() const
Returns a translation of the key for displaying to the user.
Definition: kfilemetainfo.h:331
KFileMimeTypeInfo::GroupInfo::supportedKeys
QStringList supportedKeys() const
Use this method to get a list of keys in the specified group that the plugin knows about...
Definition: kfilemetainfo.h:154
KFileMimeTypeInfo::ItemInfo::prefix
const QString & prefix() const
This method returns a translated prefix to be displayed before the value.
Definition: kfilemetainfo.h:265
KFileMimeTypeInfo::ItemInfo::key
const QString & key() const
Returns the name of the item.
Definition: kfilemetainfo.h:296
KFilePlugin::createValidator
virtual QValidator * createValidator(const QString &mimeType, const QString &group, const QString &key, QObject *parent, const char *name) const
This method should create an appropriate validator for the specified item if it's editable or return ...
Definition: kfilemetainfo.h:1462
KFileMimeTypeInfo::GroupInfo::variableItemInfo
const ItemInfo * variableItemInfo() const
If the group supports variable keys, you can query their item info with this method.
Definition: kfilemetainfo.h:217
KFileMimeTypeInfo::ItemInfo
This is the class for one item of a KFileMimeTypeInfo.
Definition: kfilemetainfo.h:250
KFileMimeTypeInfo::ItemInfo::suffix
const QString & suffix() const
This method returns a translated suffix to be displayed after the value.
Definition: kfilemetainfo.h:276
KFileMetaInfoItem::value
const QVariant & value() const
Returns the value of the item.
Definition: kfilemetainfo.cpp:182
KFileMimeTypeInfo::ItemInfo::unit
uint unit() const
Return the unit of the item.
Definition: kfilemetainfo.h:361

KDE Home | KDE Accessibility Home | Description of Access Keys