kfilemetainfo.cpp
/*
* 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.
*
* $Id: kfilemetainfo.cpp 585308 2006-09-16 23:00:15Z kling $
*/
#include <assert.h>
#include <qshared.h>
#include <qdict.h>
#include <ktrader.h>
#include <kstaticdeleter.h>
#include <kparts/componentfactory.h>
#include <kuserprofile.h>
#include <kdebug.h>
#include <kmimetype.h>
#include <kdatastream.h> // needed for serialization of bool
#include <klocale.h>
#include <kio/global.h>
#include "kfilemetainfo.h"
// shared data of a KFileMetaInfoItem
class KFileMetaInfoItem::Data : public QShared
{
public:
Data( const KFileMimeTypeInfo::ItemInfo* mti, const QString& _key,
const QVariant& _value )
: QShared(),
mimeTypeInfo( mti ),
key( _key ),
value( _value ),
dirty( false ),
added( false ),
removed( false )
{}
// we use this one for the streaming operators
Data() : mimeTypeInfo( 0L )
{}
~Data()
{
if ( this == null ) // only the null item owns its mimeTypeInfo
delete mimeTypeInfo;
}
const KFileMimeTypeInfo::ItemInfo* mimeTypeInfo;
// mimeTypeInfo has the key, too, but only for non-variable ones
QString key;
QVariant value;
bool dirty :1;
bool added :1;
bool removed :1;
static Data* null;
static Data* makeNull();
};
//this is our null data
KFileMetaInfoItem::Data* KFileMetaInfoItem::Data::null = 0L;
static KStaticDeleter<KFileMetaInfoItem::Data> sd_KFileMetaInfoItemData;
KFileMetaInfoItem::Data* KFileMetaInfoItem::Data::makeNull()
{
if (!null)
{
// We deliberately do not reset "null" after it has been destroyed!
// Otherwise we will run into problems later in ~KFileMetaInfoItem
// where the d-pointer is compared against null.
KFileMimeTypeInfo::ItemInfo* info = new KFileMimeTypeInfo::ItemInfo();
null = new Data(info, QString::null, QVariant());
sd_KFileMetaInfoItemData.setObject( null );
}
return null;
}
KFileMetaInfoItem::KFileMetaInfoItem( const KFileMimeTypeInfo::ItemInfo* mti,
const QString& key, const QVariant& value )
: d( new Data( mti, key, value ) )
{
}
KFileMetaInfoItem::KFileMetaInfoItem( const KFileMetaInfoItem& item )
{
// operator= does everything that's necessary
d = Data::makeNull();
*this = item;
}
KFileMetaInfoItem::KFileMetaInfoItem()
{
d = Data::makeNull();
}
KFileMetaInfoItem::~KFileMetaInfoItem()
{
deref();
}
const KFileMetaInfoItem& KFileMetaInfoItem::operator=
(const KFileMetaInfoItem & item )
{
if (d != item.d)
{
// first deref the old one
deref();
d = item.d;
// and now ref the new one
ref();
}
return *this;
}
bool KFileMetaInfoItem::setValue( const QVariant& value )
{
// We don't call makeNull here since it isn't necassery, see deref()
if ( d == Data::null ) return false;
if ( ! (d->mimeTypeInfo->attributes() & KFileMimeTypeInfo::Modifiable ) ||
! (value.canCast(d->mimeTypeInfo->type())))
{
kdDebug(7033) << "setting the value of " << key() << "failed\n";
return false;
}
// kdDebug(7033) << key() << ".setValue()\n";
if ( d->value == value )
return true;
d->dirty = true;
d->value = value;
// If we don't cast (and test for canCast in the above if), QVariant is
// very picky about types (e.g. QString vs. QCString or int vs. uint)
d->value.cast(d->mimeTypeInfo->type());
return true;
}
bool KFileMetaInfoItem::isRemoved() const
{
return d->removed;
}
QString KFileMetaInfoItem::key() const
{
return d->key;
}
QString KFileMetaInfoItem::translatedKey() const
{
// are we a variable key?
if (d->mimeTypeInfo->key().isNull())
{
// then try if we have luck with i18n()
return i18n(d->key.utf8());
}
return d->mimeTypeInfo->translatedKey();
}
const QVariant& KFileMetaInfoItem::value() const
{
return d->value;
}
QString KFileMetaInfoItem::string( bool mangle ) const
{
return d->mimeTypeInfo->string(d->value, mangle);
}
QVariant::Type KFileMetaInfoItem::type() const
{
return d->mimeTypeInfo->type();
}
uint KFileMetaInfoItem::unit() const
{
return d->mimeTypeInfo->unit();
}
bool KFileMetaInfoItem::isModified() const
{
return d->dirty;
}
QString KFileMetaInfoItem::prefix() const
{
return d->mimeTypeInfo->prefix();
}
QString KFileMetaInfoItem::suffix() const
{
return d->mimeTypeInfo->suffix();
}
uint KFileMetaInfoItem::hint() const
{
return d->mimeTypeInfo->hint();
}
uint KFileMetaInfoItem::attributes() const
{
return d->mimeTypeInfo->attributes();
}
bool KFileMetaInfoItem::isEditable() const
{
return d->mimeTypeInfo->attributes() & KFileMimeTypeInfo::Modifiable;
}
bool KFileMetaInfoItem::isValid() const
{
// We don't call makeNull here since it isn't necassery:
// If d is equal to null it means that null is initialized already.
// null is 0L when it hasn't been initialized and d is never 0L.
return d != Data::null;
}
void KFileMetaInfoItem::setAdded()
{
d->added = true;
}
void KFileMetaInfoItem::setRemoved()
{
d->removed = true;
}
void KFileMetaInfoItem::ref()
{
if (d != Data::null) d->ref();
}
void KFileMetaInfoItem::deref()
{
// We don't call makeNull here since it isn't necassery:
// If d is equal to null it means that null is initialized already.
// null is 0L when it hasn't been initialized and d is never 0L.
if ((d != Data::null) && d->deref())
{
// kdDebug(7033) << "item " << d->key
// << " is finally deleted\n";
delete d;
d = 0;
}
}
// shared data of a KFileMetaInfo
class KFileMetaInfo::Data : public QShared
{
public:
Data(const KURL& _url, uint _what)
: QShared(),
url(_url),
what(_what),
mimeTypeInfo( 0L )
{}
// wee use this one for the streaming operators
Data() {};
KURL url;
uint what;
QMap<QString, KFileMetaInfoGroup> groups;
const KFileMimeTypeInfo* mimeTypeInfo;
QStringList removedGroups;
static Data* null;
static Data* makeNull();
};
KFileMetaInfo::KFileMetaInfo( const QString& path, const QString& mimeType,
uint what )
{
KURL u;
u.setPath(path);
init(u, mimeType, what);
}
KFileMetaInfo::KFileMetaInfo( const KURL& url, const QString& mimeType,
uint what )
{
init(url, mimeType, what);
}
void KFileMetaInfo::init( const KURL& url, const QString& mimeType,
uint what )
{
d = new Data( url, what );
QString mT;
if (mimeType.isEmpty())
mT = KMimeType::findByURL(url)->name();
else
mT = mimeType;
// let's "share our property"
KFileMetaInfo item(*this);
//kdDebug() << k_funcinfo << mT << " " << url << endl;
d->mimeTypeInfo = KFileMetaInfoProvider::self()->mimeTypeInfo( mT, url.protocol() );
if ( d->mimeTypeInfo )
{
//kdDebug(7033) << "Found mimetype info for " << mT /* or protocol*/ << endl;
KFilePlugin *p = plugin();
Q_ASSERT( p );
if ( p && !p->readInfo( item, what) )
{
deref();
d = Data::makeNull();
}
}
else
{
// kdDebug(7033) << "No mimetype info for " << mimeType << endl;
deref();
d = Data::makeNull();
}
}
KFileMetaInfo::KFileMetaInfo( const KFileMetaInfo& original )
{
// operator= does everything that's necessary
d = Data::makeNull();
*this = original;
}
KFileMetaInfo::KFileMetaInfo()
{
d = Data::makeNull();
}
KFileMetaInfo::~KFileMetaInfo()
{
deref();
}
QStringList KFileMetaInfo::supportedGroups() const
{
assert(isValid());
return d->mimeTypeInfo->supportedGroups();
}
QStringList KFileMetaInfo::supportedKeys() const
{
assert(isValid());
return d->mimeTypeInfo->supportedKeys();
}
QStringList KFileMetaInfo::groups() const
{
QStringList list;
QMapConstIterator<QString, KFileMetaInfoGroup> it = d->groups.begin();
for ( ; it != d->groups.end(); ++it )
list += (*it).name();
return list;
}
QStringList KFileMetaInfo::editableGroups() const
{
QStringList list;
QStringList supported = supportedGroups();
QStringList::ConstIterator it = supported.begin();
for ( ; it != supported.end(); ++it ) {
const KFileMimeTypeInfo::GroupInfo * groupInfo = d->mimeTypeInfo->groupInfo( *it );
if ( groupInfo && groupInfo->attributes() &
(KFileMimeTypeInfo::Addable | KFileMimeTypeInfo::Removable) )
list.append( *it );
}
return list;
}
QStringList KFileMetaInfo::preferredGroups() const
{
assert(isValid());
QStringList list = groups();
QStringList newlist;
QStringList preferred = d->mimeTypeInfo->preferredGroups();
QStringList::Iterator pref;
// move all keys from the preferred groups that are in our list to a new list
for ( pref = preferred.begin(); pref != preferred.end(); ++pref )
{
QStringList::Iterator group = list.find(*pref);
if ( group != list.end() )
{
newlist.append( *group );
list.remove(group);
}
}
// now the old list only contains the non-preferred items, so we
// add the remaining ones to newlist
newlist += list;
return newlist;
}
QStringList KFileMetaInfo::preferredKeys() const
{
QStringList newlist;
QStringList list = preferredGroups();
for (QStringList::Iterator git = list.begin(); git != list.end(); ++git)
{
newlist += d->groups[*git].preferredKeys();
}
return newlist;
}
KFileMetaInfoGroup KFileMetaInfo::group(const QString& key) const
{
QMapIterator<QString,KFileMetaInfoGroup> it = d->groups.find( key );
if ( it != d->groups.end() )
return it.data();
else
return KFileMetaInfoGroup();
}
bool KFileMetaInfo::addGroup( const QString& name )
{
assert(isValid());
if ( d->mimeTypeInfo->supportedGroups().contains(name) &&
! d->groups.contains(name) )
{
KFileMetaInfoGroup group( name, d->mimeTypeInfo );
// add all the items that can't be added by the user later
const KFileMimeTypeInfo::GroupInfo* ginfo = d->mimeTypeInfo->groupInfo(name);
Q_ASSERT(ginfo);
if (!ginfo) return false;
QStringList keys = ginfo->supportedKeys();
for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it)
{
const KFileMimeTypeInfo::ItemInfo* iteminfo = ginfo->itemInfo(*it);
Q_ASSERT(ginfo);
if (!iteminfo) return false;
if ( !(iteminfo->attributes() & KFileMimeTypeInfo::Addable) &&
(iteminfo->attributes() & KFileMimeTypeInfo::Modifiable))
{
// append it now or never
group.appendItem(iteminfo->key(), QVariant());
}
}
d->groups.insert(name, group);
group.setAdded();
return true;
}
return false;
}
bool KFileMetaInfo::removeGroup( const QString& name )
{
QMapIterator<QString, KFileMetaInfoGroup> it = d->groups.find(name);
if ( (it==d->groups.end()) ||
!((*it).attributes() & KFileMimeTypeInfo::Removable))
return false;
d->groups.remove(it);
d->removedGroups.append(name);
return true;
}
QStringList KFileMetaInfo::removedGroups()
{
return d->removedGroups;
}
const KFileMetaInfo& KFileMetaInfo::operator= (const KFileMetaInfo& info )
{
if (d != info.d)
{
deref();
// first deref the old one
d = info.d;
// and now ref the new one
ref();
}
return *this;
}
bool KFileMetaInfo::isValid() const
{
// We don't call makeNull here since it isn't necassery, see deref()
return d != Data::null;
}
bool KFileMetaInfo::isEmpty() const
{
for (QMapIterator<QString, KFileMetaInfoGroup> it = d->groups.begin();
it!=d->groups.end(); ++it)
if (!(*it).isEmpty())
return false;
return true;
}
bool KFileMetaInfo::applyChanges()
{
return applyChanges( path() );
}
bool KFileMetaInfo::applyChanges( const QString& path )
{
bool doit = false;
// kdDebug(7033) << "KFileMetaInfo::applyChanges()\n";
// look up if we need to write to the file
QMapConstIterator<QString, KFileMetaInfoGroup> it;
for (it = d->groups.begin(); it!=d->groups.end() && !doit; ++it)
{
if ( (*it).isModified() )
doit = true;
else
{
QStringList keys = it.data().keys();
for (QStringList::Iterator it2 = keys.begin(); it2!=keys.end(); ++it2)
{
if ( (*it)[*it2].isModified() )
{
doit = true;
break;
}
}
}
}
if (!doit)
{
kdDebug(7033) << "Don't need to write, nothing changed\n";
return true;
}
KFilePlugin* p = plugin();
if (!p) return false;
// kdDebug(7033) << "Ok, trying to write the info\n";
KURL savedURL = url();
d->url = KURL();
d->url.setPath( path );
bool ret = p->writeInfo(*this);
d->url = savedURL;
return ret;
}
KFilePlugin * const KFileMetaInfo::plugin() const
{
assert(isValid());
KFileMetaInfoProvider* prov = KFileMetaInfoProvider::self();
return prov->plugin( d->mimeTypeInfo->mimeType(), d->url.protocol() );
}
QString KFileMetaInfo::mimeType() const
{
assert(isValid());
return d->mimeTypeInfo->mimeType();
}
bool KFileMetaInfo::contains(const QString& key) const
{
QStringList glist = groups();
for (QStringList::Iterator it = glist.begin(); it != glist.end(); ++it)
{
KFileMetaInfoGroup g = d->groups[*it];
if (g.contains(key)) return true;
}
return false;
}
bool KFileMetaInfo::containsGroup(const QString& key) const
{
return groups().contains(key);
}
KFileMetaInfoItem KFileMetaInfo::item( const QString& key) const
{
QStringList groups = preferredGroups();
for (QStringList::Iterator it = groups.begin(); it != groups.end(); ++it)
{
KFileMetaInfoItem i = d->groups[*it][key];
if (i.isValid()) return i;
}
return KFileMetaInfoItem();
}
KFileMetaInfoItem KFileMetaInfo::item(const KFileMetaInfoItem::Hint hint) const
{
QStringList groups = preferredGroups();
QStringList::ConstIterator it;
for (it = groups.begin(); it != groups.end(); ++it)
{
KFileMetaInfoItem i = d->groups[*it].item(hint);
if (i.isValid()) return i;
}
return KFileMetaInfoItem();
}
KFileMetaInfoItem KFileMetaInfo::saveItem( const QString& key,
const QString& preferredGroup,
bool createGroup )
{
assert(isValid());
// try the preferred groups first
if ( !preferredGroup.isEmpty() ) {
QMapIterator<QString,KFileMetaInfoGroup> it =
d->groups.find( preferredGroup );
// try to create the preferred group, if necessary
if ( it == d->groups.end() && createGroup ) {
const KFileMimeTypeInfo::GroupInfo *groupInfo =
d->mimeTypeInfo->groupInfo( preferredGroup );
if ( groupInfo && groupInfo->supportedKeys().contains( key ) ) {
if ( addGroup( preferredGroup ) )
it = d->groups.find( preferredGroup );
}
}
if ( it != d->groups.end() ) {
KFileMetaInfoItem item = it.data().addItem( key );
if ( item.isValid() )
return item;
}
}
QStringList groups = preferredGroups();
KFileMetaInfoItem item;
QStringList::ConstIterator groupIt = groups.begin();
for ( ; groupIt != groups.end(); ++groupIt )
{
QMapIterator<QString,KFileMetaInfoGroup> it = d->groups.find( *groupIt );
if ( it != d->groups.end() )
{
KFileMetaInfoGroup group = it.data();
item = findEditableItem( group, key );
if ( item.isValid() )
return item;
}
else // not existant -- try to create the group
{
const KFileMimeTypeInfo::GroupInfo *groupInfo =
d->mimeTypeInfo->groupInfo( *groupIt );
if ( groupInfo && groupInfo->supportedKeys().contains( key ) )
{
if ( addGroup( *groupIt ) )
{
KFileMetaInfoGroup group = d->groups[*groupIt];
KFileMetaInfoItem item = group.addItem( key );
if ( item.isValid() )
return item;
// else ### add when removeGroup() is implemented :)
// removeGroup( *groupIt ); // couldn't add item -> remove
}
}
}
}
// finally check for variable items
return item;
}
KFileMetaInfoItem KFileMetaInfo::findEditableItem( KFileMetaInfoGroup& group,
const QString& key )
{
assert(isValid());
KFileMetaInfoItem item = group.addItem( key );
if ( item.isValid() && item.isEditable() )
return item;
if ( (d->mimeTypeInfo->groupInfo( group.name() )->attributes() & KFileMimeTypeInfo::Addable) )
return item;
return KFileMetaInfoItem();
}
KFileMetaInfoGroup KFileMetaInfo::appendGroup(const QString& name)
{
assert(isValid());
if ( d->mimeTypeInfo->supportedGroups().contains(name) &&
! d->groups.contains(name) )
{
KFileMetaInfoGroup group( name, d->mimeTypeInfo );
d->groups.insert(name, group);
return group;
}
else {
kdWarning(7033) << "Someone's trying to add a KFileMetaInfoGroup which is not supported or already existing: " << name << endl;
return KFileMetaInfoGroup();
}
}
QString KFileMetaInfo::path() const
{
return d->url.isLocalFile() ? d->url.path() : QString::null;
}
KURL KFileMetaInfo::url() const
{
return d->url;
}
void KFileMetaInfo::ref()
{
if (d != Data::null) d->ref();
}
void KFileMetaInfo::deref()
{
// We don't call makeNull here since it isn't necassery:
// If d is equal to null it means that null is initialized already.
// null is 0L when it hasn't been initialized and d is never 0L.
if ((d != Data::null) && d->deref())
{
// kdDebug(7033) << "metainfo object for " << d->url.path << " is finally deleted\n";
delete d;
d = 0;
}
}
KFileMetaInfo::Data* KFileMetaInfo::Data::null = 0L;
static KStaticDeleter<KFileMetaInfo::Data> sd_KFileMetaInfoData;
KFileMetaInfo::Data* KFileMetaInfo::Data::makeNull()
{
if (!null)
// We deliberately do not reset "null" after it has been destroyed!
// Otherwise we will run into problems later in ~KFileMetaInfoItem
// where the d-pointer is compared against null.
null = sd_KFileMetaInfoData.setObject( new KFileMetaInfo::Data(KURL(), 0) );
return null;
}
KFilePlugin::KFilePlugin( QObject *parent, const char *name,
const QStringList& /*args*/)
: QObject( parent, name )
{
// kdDebug(7033) << "loaded a plugin for " << name << endl;
}
KFilePlugin::~KFilePlugin()
{
// kdDebug(7033) << "unloaded a plugin for " << name() << endl;
}
KFileMimeTypeInfo * KFilePlugin::addMimeTypeInfo( const QString& mimeType )
{
return KFileMetaInfoProvider::self()->addMimeTypeInfo( mimeType );
}
void KFilePlugin::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
KFileMimeTypeInfo::GroupInfo* KFilePlugin::addGroupInfo(KFileMimeTypeInfo* info,
const QString& key, const QString& translatedKey) const
{
return info->addGroupInfo(key, translatedKey);
}
void KFilePlugin::setAttributes(KFileMimeTypeInfo::GroupInfo* gi, uint attr) const
{
gi->m_attr = attr;
}
void KFilePlugin::addVariableInfo(KFileMimeTypeInfo::GroupInfo* gi,
QVariant::Type type, uint attr) const
{
gi->addVariableInfo(type, attr);
}
KFileMimeTypeInfo::ItemInfo* KFilePlugin::addItemInfo(KFileMimeTypeInfo::GroupInfo* gi,
const QString& key,
const QString& translatedKey,
QVariant::Type type)
{
return gi->addItemInfo(key, translatedKey, type);
}
void KFilePlugin::setAttributes(KFileMimeTypeInfo::ItemInfo* item, uint attr)
{
item->m_attr = attr;
}
void KFilePlugin::setHint(KFileMimeTypeInfo::ItemInfo* item, uint hint)
{
item->m_hint = hint;
}
void KFilePlugin::setUnit(KFileMimeTypeInfo::ItemInfo* item, uint unit)
{
item->m_unit = unit;
// set prefix and suffix
switch (unit)
{
case KFileMimeTypeInfo::Seconds:
item->m_suffix = i18n("s"); break;
case KFileMimeTypeInfo::MilliSeconds:
item->m_suffix = i18n("ms"); break;
case KFileMimeTypeInfo::BitsPerSecond:
item->m_suffix = i18n("bps"); break;
case KFileMimeTypeInfo::Pixels:
item->m_suffix = i18n("pixels"); break;
case KFileMimeTypeInfo::Inches:
item->m_suffix = i18n("in"); break;
case KFileMimeTypeInfo::Centimeters:
item->m_suffix = i18n("cm"); break;
case KFileMimeTypeInfo::Bytes:
item->m_suffix = i18n("B"); break;
case KFileMimeTypeInfo::KiloBytes:
item->m_suffix = i18n("KB"); break;
case KFileMimeTypeInfo::FramesPerSecond:
item->m_suffix = i18n("fps"); break;
case KFileMimeTypeInfo::DotsPerInch:
item->m_suffix = i18n("dpi"); break;
case KFileMimeTypeInfo::BitsPerPixel:
item->m_suffix = i18n("bpp"); break;
case KFileMimeTypeInfo::Hertz:
item->m_suffix = i18n("Hz"); break;
case KFileMimeTypeInfo::Millimeters:
item->m_suffix = i18n("mm");
}
}
void KFilePlugin::setPrefix(KFileMimeTypeInfo::ItemInfo* item, const QString& prefix)
{
item->m_prefix = prefix;
}
void KFilePlugin::setSuffix(KFileMimeTypeInfo::ItemInfo* item, const QString& suffix)
{
item->m_suffix = suffix;
}
KFileMetaInfoGroup KFilePlugin::appendGroup(KFileMetaInfo& info, const QString& key)
{
return info.appendGroup(key);
}
void KFilePlugin::appendItem(KFileMetaInfoGroup& group, const QString& key, QVariant value)
{
group.appendItem(key, value);
}
KFileMetaInfoProvider * KFileMetaInfoProvider::s_self;
static KStaticDeleter<KFileMetaInfoProvider> sd;
KFileMetaInfoProvider * KFileMetaInfoProvider::self()
{
if ( !s_self )
s_self = sd.setObject( s_self, new KFileMetaInfoProvider() );
return s_self;
}
KFileMetaInfoProvider::KFileMetaInfoProvider()
{
m_plugins.setAutoDelete( true );
}
KFileMetaInfoProvider::~KFileMetaInfoProvider()
{
m_plugins.clear();
sd.setObject( 0 );
}
KFilePlugin* KFileMetaInfoProvider::loadPlugin( const QString& mimeType, const QString& protocol )
{
//kdDebug() << "loadPlugin: mimeType=" << mimeType << " protocol=" << protocol << endl;
// Currently the idea is: either the mimetype is set or the protocol, but not both.
// We need PNG fileinfo, and trash: fileinfo, but not "PNG in the trash".
QString queryMimeType, query;
if ( !mimeType.isEmpty() ) {
query = "(not exist [X-KDE-Protocol])";
queryMimeType = mimeType;
} else {
query = QString::fromLatin1( "[X-KDE-Protocol] == '%1'" ).arg(protocol);
// querying for a protocol: we have no mimetype, so we need to use KFilePlugin as one
queryMimeType = "KFilePlugin";
// hopefully using KFilePlugin as genericMimeType too isn't a problem
}
const KTrader::OfferList offers = KTrader::self()->query( queryMimeType, "KFilePlugin", query, QString::null );
if ( offers.isEmpty() )
return 0;
KService::Ptr service = *(offers.begin());
Q_ASSERT( service && service->isValid() );
if ( !service || !service->isValid() )
return 0;
KFilePlugin* plugin = KParts::ComponentFactory::createInstanceFromService<KFilePlugin>
( service, this, mimeType.local8Bit() );
if (!plugin)
kdWarning(7033) << "error loading the plugin from " << service->desktopEntryPath() << endl;
return plugin;
}
KFilePlugin* KFileMetaInfoProvider::loadAndRegisterPlugin( const QString& mimeType, const QString& protocol )
{
Q_ASSERT( m_pendingMimetypeInfos.isEmpty() );
m_pendingMimetypeInfos.clear();
KFilePlugin* plugin = loadPlugin( mimeType, protocol );
if ( !plugin ) {
// No plugin found. Remember that, to save time.
m_plugins.insert( protocol.isEmpty() ? mimeType : protocol, new CachedPluginInfo );
return 0;
}
if ( !protocol.isEmpty() ) {
// Protocol-metainfo: only one entry
Q_ASSERT( m_pendingMimetypeInfos.count() == 1 );
KFileMimeTypeInfo* info = m_pendingMimetypeInfos[ protocol ];
Q_ASSERT( info );
m_plugins.insert( protocol, new CachedPluginInfo( plugin, info, true ) );
} else {
// Mimetype-metainfo: the plugin can register itself for multiple mimetypes, remember them all
bool first = true;
QDictIterator<KFileMimeTypeInfo> it( m_pendingMimetypeInfos );
for( ; it.current(); ++it ) {
KFileMimeTypeInfo* info = it.current();
m_plugins.insert( it.currentKey(), new CachedPluginInfo( plugin, info, first ) );
first = false;
}
// Hopefully the above includes the mimetype we asked for!
if ( m_pendingMimetypeInfos.find( mimeType ) == 0 )
kdWarning(7033) << plugin->className() << " was created for " << mimeType << " but doesn't call addMimeTypeInfo for it!" << endl;
}
m_pendingMimetypeInfos.clear();
return plugin;
}
KFilePlugin * KFileMetaInfoProvider::plugin(const QString& mimeType)
{
return plugin( mimeType, QString::null );
}
KFilePlugin * KFileMetaInfoProvider::plugin(const QString& mimeType, const QString& protocol)
{
//kdDebug(7033) << "plugin() : looking for plugin for protocol=" << protocol << " mimeType=" << mimeType << endl;
if ( !protocol.isEmpty() ) {
CachedPluginInfo *cache = m_plugins.find( protocol );
if ( cache && cache->plugin ) {
return cache->plugin;
}
if ( !cache ) {
KFilePlugin* plugin = loadAndRegisterPlugin( QString::null, protocol );
if ( plugin )
return plugin;
}
}
CachedPluginInfo *cache = m_plugins.find( mimeType );
if ( cache ) {
return cache->plugin;
}
KFilePlugin* plugin = loadAndRegisterPlugin( mimeType, QString::null );
#if 0
kdDebug(7033) << "currently loaded plugins:\n";
QDictIterator<CachedPluginInfo> it( m_plugins );
for( ; it.current(); ++it ) {
CachedPluginInfo* cache = it.current();
kdDebug(7033)
<< it.currentKey() // mimetype or protocol
<< " : " << (cache->plugin ? cache->plugin->className() : "(no plugin)") << endl; // plugin
// TODO print cache->mimeTypeInfo
}
#endif
return plugin;
}
QStringList KFileMetaInfoProvider::preferredKeys( const QString& mimeType ) const
{
KService::Ptr service =
KServiceTypeProfile::preferredService( mimeType, "KFilePlugin");
if ( !service || !service->isValid() )
{
// kdDebug(7033) << "no valid service found\n";
return QStringList();
}
return service->property("PreferredItems").toStringList();
}
QStringList KFileMetaInfoProvider::preferredGroups( const QString& mimeType ) const
{
KService::Ptr service =
KServiceTypeProfile::preferredService( mimeType, "KFilePlugin");
if ( !service || !service->isValid() )
{
// kdDebug(7033) << "no valid service found\n";
return QStringList();
}
return service->property("PreferredGroups").toStringList();
}
const KFileMimeTypeInfo * KFileMetaInfoProvider::mimeTypeInfo( const QString& mimeType )
{
return mimeTypeInfo( mimeType, QString::null );
}
const KFileMimeTypeInfo * KFileMetaInfoProvider::mimeTypeInfo( const QString& mimeType, const QString& protocol )
{
//kdDebug(7033) << "mimeTypeInfo() : looking for plugin for protocol=" << protocol << " mimeType=" << mimeType << endl;
if ( !protocol.isEmpty() ) {
CachedPluginInfo *cache = m_plugins.find( protocol );
if ( cache && cache->mimeTypeInfo ) {
return cache->mimeTypeInfo;
}
if ( !cache ) {
loadAndRegisterPlugin( QString::null, protocol );
cache = m_plugins.find( protocol );
if ( cache && cache->mimeTypeInfo ) {
return cache->mimeTypeInfo;
}
}
}
CachedPluginInfo *cache = m_plugins.find( mimeType );
if ( cache ) {
return cache->mimeTypeInfo;
}
loadAndRegisterPlugin( mimeType, QString::null );
cache = m_plugins.find( mimeType );
if ( cache ) {
return cache->mimeTypeInfo;
}
return 0;
}
KFileMimeTypeInfo * KFileMetaInfoProvider::addMimeTypeInfo(
const QString& mimeType )
{
KFileMimeTypeInfo *info = m_pendingMimetypeInfos.find( mimeType );
Q_ASSERT( !info );
if ( !info )
{
info = new KFileMimeTypeInfo( mimeType );
m_pendingMimetypeInfos.insert( mimeType, info );
}
info->m_preferredKeys = preferredKeys( mimeType );
info->m_preferredGroups = preferredGroups( mimeType );
return info;
}
QStringList KFileMetaInfoProvider::supportedMimeTypes() const
{
QStringList allMimeTypes;
QString kfilePlugin = "KFilePlugin";
KTrader::OfferList offers = KTrader::self()->query( "KFilePlugin" );
KTrader::OfferListIterator it = offers.begin();
for ( ; it != offers.end(); ++it )
{
const QStringList mimeTypes = (*it)->serviceTypes();
QStringList::ConstIterator it2 = mimeTypes.begin();
for ( ; it2 != mimeTypes.end(); ++it2 )
if ( allMimeTypes.find( *it2 ) == allMimeTypes.end() &&
*it2 != kfilePlugin ) // also in serviceTypes()
allMimeTypes.append( *it2 );
}
return allMimeTypes;
}
// shared data of a KFileMetaInfoGroup
class KFileMetaInfoGroup::Data : public QShared
{
public:
Data(const QString& _name)
: QShared(),
name(_name),
mimeTypeInfo(0L),
dirty( false ),
added( false )
{}
// we use this one for the streaming operators
Data() : mimeTypeInfo(0L) {}
~Data() {
if ( this == null )
delete mimeTypeInfo;
};
QString name;
QMap<QString, KFileMetaInfoItem> items;
const KFileMimeTypeInfo* mimeTypeInfo;
QStringList removedItems;
bool dirty :1;
bool added :1;
static Data* null;
static Data* makeNull();
};
KFileMetaInfoGroup::KFileMetaInfoGroup( const QString& name,
const KFileMimeTypeInfo* info )
: d(new Data( name ) )
{
d->mimeTypeInfo = info;
}
KFileMetaInfoGroup::KFileMetaInfoGroup( const KFileMetaInfoGroup& original )
{
// operator= does everything that's necessary
d = Data::makeNull();
*this = original;
}
KFileMetaInfoGroup::KFileMetaInfoGroup()
{
d = Data::makeNull();
}
KFileMetaInfoGroup::~KFileMetaInfoGroup()
{
deref();
}
const KFileMetaInfoGroup& KFileMetaInfoGroup::operator= (const KFileMetaInfoGroup& info )
{
if (d != info.d)
{
deref();
// first deref the old one
d = info.d;
// and now ref the new one
ref();
}
return *this;
}
bool KFileMetaInfoGroup::isValid() const
{
// We don't call makeNull here since it isn't necassery, see deref()
return d != Data::null;
}
bool KFileMetaInfoGroup::isEmpty() const
{
return d->items.isEmpty();
}
QStringList KFileMetaInfoGroup::preferredKeys() const
{
assert(isValid());
QStringList list = keys();
QStringList newlist;
QStringList preferredKeys = d->mimeTypeInfo->preferredKeys();
QStringList::Iterator pref;
QStringList::Iterator begin = preferredKeys.begin();
QStringList::Iterator end = preferredKeys.end();
// move all keys from the preferred keys that are in our list to a new list
for ( pref = begin; pref!=end; ++pref )
{
QStringList::Iterator item = list.find(*pref);
if ( item != list.end() )
{
newlist.append( *item );
list.remove(item);
}
}
// now the old list only contains the non-preferred items, so we
// add the remaining ones to newlist
newlist += list;
return newlist;
}
QStringList KFileMetaInfoGroup::keys() const
{
if (d == Data::makeNull())
kdWarning(7033) << "attempt to get the keys of "
"an invalid metainfo group";
QStringList list;
// make a QStringList with all available keys
QMapConstIterator<QString, KFileMetaInfoItem> it;
for (it = d->items.begin(); it!=d->items.end(); ++it)
{
list.append(it.data().key());
// kdDebug(7033) << "Item " << it.data().key() << endl;
}
return list;
}
QString KFileMetaInfoGroup::translatedName() const
{
assert(isValid());
return d->mimeTypeInfo->groupInfo(d->name)->translatedName();
}
QStringList KFileMetaInfoGroup::supportedKeys() const
{
assert(isValid());
return d->mimeTypeInfo->groupInfo(d->name)->supportedKeys();
}
bool KFileMetaInfoGroup::supportsVariableKeys() const
{
assert(isValid());
return d->mimeTypeInfo->groupInfo(d->name)->supportsVariableKeys();
}
bool KFileMetaInfoGroup::contains( const QString& key ) const
{
return d->items.contains(key);
}
KFileMetaInfoItem KFileMetaInfoGroup::item( const QString& key) const
{
QMapIterator<QString,KFileMetaInfoItem> it = d->items.find( key );
if ( it != d->items.end() )
return it.data();
return KFileMetaInfoItem();
}
KFileMetaInfoItem KFileMetaInfoGroup::item(uint hint) const
{
QMapIterator<QString, KFileMetaInfoItem> it;
for (it = d->items.begin(); it!=d->items.end(); ++it)
if (it.data().hint() == hint)
return it.data();
return KFileMetaInfoItem();
}
QString KFileMetaInfoGroup::name() const
{
return d->name;
}
uint KFileMetaInfoGroup::attributes() const
{
assert(isValid());
return d->mimeTypeInfo->groupInfo(d->name)->attributes();
}
void KFileMetaInfoGroup::setAdded()
{
d->added = true;
}
bool KFileMetaInfoGroup::isModified() const
{
return d->dirty;
}
void KFileMetaInfoGroup::ref()
{
if (d != Data::null) d->ref();
}
void KFileMetaInfoGroup::deref()
{
// We don't call makeNull here since it isn't necassery:
// If d is equal to null it means that null is initialized already.
// null is 0L when it hasn't been initialized and d is never 0L.
if ((d != Data::null) && d->deref())
{
// kdDebug(7033) << "metainfo group " << d->name
// << " is finally deleted\n";
delete d;
d = 0;
}
}
KFileMetaInfoItem KFileMetaInfoGroup::addItem( const QString& key )
{
assert(isValid());
QMapIterator<QString,KFileMetaInfoItem> it = d->items.find( key );
if ( it != d->items.end() )
return it.data();
const KFileMimeTypeInfo::GroupInfo* ginfo = d->mimeTypeInfo->groupInfo(d->name);
if ( !ginfo ) {
Q_ASSERT( ginfo );
return KFileMetaInfoItem();
}
const KFileMimeTypeInfo::ItemInfo* info = ginfo->itemInfo(key);
if ( !info ) {
Q_ASSERT( info );
return KFileMetaInfoItem();
}
KFileMetaInfoItem item;
if (info->isVariableItem())
item = KFileMetaInfoItem(ginfo->variableItemInfo(), key, QVariant());
else
item = KFileMetaInfoItem(info, key, QVariant());
d->items.insert(key, item);
item.setAdded(); // mark as added
d->dirty = true; // mark ourself as dirty, too
return item;
}
bool KFileMetaInfoGroup::removeItem( const QString& key )
{
if (!isValid())
{
kdDebug(7033) << "trying to remove an item from an invalid group\n";
return false;
}
QMapIterator<QString, KFileMetaInfoItem> it = d->items.find(key);
if ( it==d->items.end() )
{
kdDebug(7033) << "trying to remove the non existant item " << key << "\n";
return false;
}
if (!((*it).attributes() & KFileMimeTypeInfo::Removable))
{
kdDebug(7033) << "trying to remove a non removable item\n";
return false;
}
(*it).setRemoved();
d->items.remove(it);
d->removedItems.append(key);
d->dirty = true;
return true;
}
QStringList KFileMetaInfoGroup::removedItems()
{
return d->removedItems;
}
KFileMetaInfoItem KFileMetaInfoGroup::appendItem(const QString& key,
const QVariant& value)
{
//KDE4 enforce (value.type() == d->mimeTypeInfo->type())
assert(isValid());
const KFileMimeTypeInfo::GroupInfo* ginfo = d->mimeTypeInfo->groupInfo(d->name);
if ( !ginfo ) {
kdWarning() << "Trying to append a Metadata item for a non-existant group:" << d->name << endl;
return KFileMetaInfoItem();
}
const KFileMimeTypeInfo::ItemInfo* info = ginfo->itemInfo(key);
if ( !info ) {
kdWarning() << "Trying to append a Metadata item for an unknown key (no ItemInfo): " << key << endl;
return KFileMetaInfoItem();
}
KFileMetaInfoItem item;
if (info->key().isNull())
item = KFileMetaInfoItem(ginfo->variableItemInfo(), key, value);
else
item = KFileMetaInfoItem(info, key, value);
kdDebug(7033) << "KFileMetaInfogroup inserting a " << key << endl;
d->items.insert(key, item);
return item;
}
KFileMetaInfoGroup::Data* KFileMetaInfoGroup::Data::null = 0L;
static KStaticDeleter<KFileMetaInfoGroup::Data> sd_KFileMetaInfoGroupData;
KFileMetaInfoGroup::Data* KFileMetaInfoGroup::Data::makeNull()
{
if (!null)
{
// We deliberately do not reset "null" after it has been destroyed!
// Otherwise we will run into problems later in ~KFileMetaInfoItem
// where the d-pointer is compared against null.
null = new Data(QString::null);
null->mimeTypeInfo = new KFileMimeTypeInfo();
sd_KFileMetaInfoGroupData.setObject( null );
}
return null;
}
KFileMimeTypeInfo::KFileMimeTypeInfo( const QString& mimeType )
: m_mimeType( mimeType )
{
m_groups.setAutoDelete( true );
}
KFileMimeTypeInfo::~KFileMimeTypeInfo()
{
}
const KFileMimeTypeInfo::GroupInfo * KFileMimeTypeInfo::groupInfo( const QString& group ) const
{
return m_groups.find( group );
}
KFileMimeTypeInfo::GroupInfo * KFileMimeTypeInfo::addGroupInfo(
const QString& name, const QString& translatedName )
{
GroupInfo* group = new GroupInfo( name, translatedName );
m_groups.insert(name, group);
return group;
}
QStringList KFileMimeTypeInfo::supportedGroups() const
{
QStringList list;
QDictIterator<GroupInfo> it( m_groups );
for ( ; it.current(); ++it )
list.append( it.current()->name() );
return list;
}
QStringList KFileMimeTypeInfo::translatedGroups() const
{
QStringList list;
QDictIterator<GroupInfo> it( m_groups );
for ( ; it.current(); ++it )
list.append( it.current()->translatedName() );
return list;
}
QStringList KFileMimeTypeInfo::supportedKeys() const
{
// not really efficient, but not those are not large lists, probably.
// maybe cache the result?
QStringList keys;
QStringList::ConstIterator lit;
QDictIterator<GroupInfo> it( m_groups );
for ( ; it.current(); ++it ) { // need to nuke dupes
QStringList list = it.current()->supportedKeys();
for ( lit = list.begin(); lit != list.end(); ++lit ) {
if ( keys.find( *lit ) == keys.end() )
keys.append( *lit );
}
}
return keys;
}
QValidator * KFileMimeTypeInfo::createValidator(const QString& group,
const QString& key,
QObject *parent,
const char *name) const
{
KFilePlugin* plugin = KFileMetaInfoProvider::self()->plugin(m_mimeType);
if (plugin) return plugin->createValidator(mimeType(), group, key,
parent, name);
return 0;
}
KFileMimeTypeInfo::GroupInfo::GroupInfo( const QString& name,
const QString& translatedName )
: m_name( name ),
m_translatedName( translatedName ),
m_attr( 0 ),
m_variableItemInfo( 0 )
{
m_itemDict.setAutoDelete( true );
}
KFileMimeTypeInfo::GroupInfo::~GroupInfo()
{
delete m_variableItemInfo;
}
const KFileMimeTypeInfo::ItemInfo * KFileMimeTypeInfo::GroupInfo::itemInfo( const QString& key ) const
{
ItemInfo* item = m_itemDict.find( key );
// if we the item isn't found and variable keys are supported, we need to
// return the default variable key iteminfo.
if (!item && m_variableItemInfo)
{
return m_variableItemInfo;
}
return item;
}
KFileMimeTypeInfo::ItemInfo* KFileMimeTypeInfo::GroupInfo::addItemInfo(
const QString& key, const QString& translatedKey,
QVariant::Type type)
{
// kdDebug(7034) << key << "(" << translatedKey << ") -> " << QVariant::typeToName(type) << endl;
ItemInfo* item = new ItemInfo(key, translatedKey, type);
m_supportedKeys.append(key);
m_itemDict.insert(key, item);
return item;
}
void KFileMimeTypeInfo::GroupInfo::addVariableInfo( QVariant::Type type,
uint attr )
{
// just make sure that it's not already there
delete m_variableItemInfo;
m_variableItemInfo = new ItemInfo(QString::null, QString::null, type);
m_variableItemInfo->m_attr = attr;
}
QString KFileMimeTypeInfo::ItemInfo::string(const QVariant& value, bool mangle) const
{
QString s;
switch (value.type())
{
case QVariant::Invalid :
return "---";
case QVariant::Bool :
s = value.toBool() ? i18n("Yes") : i18n("No");
break;
case QVariant::Int :
if (unit() == KFileMimeTypeInfo::Seconds)
{
int seconds = value.toInt() % 60;
int minutes = value.toInt() / 60 % 60;
int hours = value.toInt() / 3600;
s = hours ? QString().sprintf("%d:%02d:%02d",hours, minutes, seconds)
: QString().sprintf("%02d:%02d", minutes, seconds);
return s; // no suffix wanted
}
else if (unit() == KFileMimeTypeInfo::Bytes)
{
// convertSize already adds the correct suffix
return KIO::convertSize(value.toInt());
}
else if (unit() == KFileMimeTypeInfo::KiloBytes)
{
// convertSizeFromKB already adds the correct suffix
return KIO::convertSizeFromKB(value.toInt());
}
else
s = KGlobal::locale()->formatNumber( value.toInt() , 0);
break;
case QVariant::LongLong :
s = KGlobal::locale()->formatNumber( value.toLongLong(), 0 );
break;
case QVariant::ULongLong :
if ( unit() == KFileMimeTypeInfo::Bytes )
return KIO::convertSize( value.toULongLong() );
else if ( unit() == KFileMimeTypeInfo::KiloBytes )
return KIO::convertSizeFromKB( value.toULongLong() );
else
s = KGlobal::locale()->formatNumber( value.toULongLong(), 0 );
break;
case QVariant::UInt :
s = KGlobal::locale()->formatNumber( value.toUInt() , 0);
break;
case QVariant::Double :
s = KGlobal::locale()->formatNumber( value.toDouble(), 3);
break;
case QVariant::Date :
s = KGlobal::locale()->formatDate( value.toDate(), true );
break;
case QVariant::Time :
s = KGlobal::locale()->formatTime( value.toTime(), true );
break;
case QVariant::DateTime :
s = KGlobal::locale()->formatDateTime( value.toDateTime(),
true, true );
break;
case QVariant::Size :
s = QString("%1 x %2").arg(value.toSize().width())
.arg(value.toSize().height());
break;
case QVariant::Point :
s = QString("%1/%2").arg(value.toSize().width())
.arg(value.toSize().height());
break;
default:
s = value.toString();
}
if (mangle && !s.isNull())
{
s.prepend(prefix());
s.append(" " + suffix());
}
return s;
}
// stream operators
/* serialization of a KFileMetaInfoItem:
first a bool that says if the items is valid, and if yes,
all the elements of the Data
*/
KIO_EXPORT QDataStream& operator <<(QDataStream& s, const KFileMetaInfoItem& item )
{
KFileMetaInfoItem::Data* d = item.d;
// if the object is invalid, put only a char in the stream
bool isValid = item.isValid();
s << isValid;
// ### what do about mimetypeInfo ?
if (isValid)
s << d->key
<< d->value
<< d->dirty
<< d->added
<< d->removed;
return s;
}
KIO_EXPORT QDataStream& operator >>(QDataStream& s, KFileMetaInfoItem& item )
{
bool isValid;
s >> isValid;
if (!isValid)
{
item = KFileMetaInfoItem();
return s;
}
// we need a new object for our data
item.deref();
item.d = new KFileMetaInfoItem::Data();
// ### what do about mimetypeInfo ?
bool dirty, added, removed;
s >> item.d->key
>> item.d->value
>> dirty
>> added
>> removed;
item.d->dirty = dirty;
item.d->added = added;
item.d->removed = removed;
return s;
}
// serialization of a KFileMetaInfoGroup
// we serialize the name of the mimetype here instead of the mimetype info
// on the other side, we can simply use this to ask the provider for the info
KIO_EXPORT QDataStream& operator <<(QDataStream& s, const KFileMetaInfoGroup& group )
{
KFileMetaInfoGroup::Data* d = group.d;
// if the object is invalid, put only a byte in the stream
bool isValid = group.isValid();
s << isValid;
if (isValid)
{
s << d->name
<< d->items
<< d->mimeTypeInfo->mimeType();
}
return s;
}
KIO_EXPORT QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& group )
{
QString mimeType;
bool isValid;
s >> isValid;
// if it's invalid, there is not much to do
if (!isValid)
{
group = KFileMetaInfoGroup();
return s;
}
// we need a new object for our data
group.deref();
group.d = new KFileMetaInfoGroup::Data();
s >> group.d->name
>> group.d->items
>> mimeType;
group.d->mimeTypeInfo = KFileMetaInfoProvider::self()->mimeTypeInfo(mimeType);
// we need to set the item info for the items here
QMapIterator<QString, KFileMetaInfoItem> it = group.d->items.begin();
for ( ; it != group.d->items.end(); ++it)
{
(*it).d->mimeTypeInfo = group.d->mimeTypeInfo->groupInfo(group.d->name)
->itemInfo((*it).key());
}
return s;
}
// serialization of a KFileMetaInfo object
// we serialize the name of the mimetype here instead of the mimetype info
// on the other side, we can simply use this to ask the provider for the info
KIO_EXPORT QDataStream& operator <<(QDataStream& s, const KFileMetaInfo& info )
{
KFileMetaInfo::Data* d = info.d;
// if the object is invalid, put only a byte that tells this
bool isValid = info.isValid();
s << isValid;
if (isValid)
{
s << d->url
<< d->what
<< d->groups
<< d->mimeTypeInfo->mimeType();
}
return s;
}
KIO_EXPORT QDataStream& operator >>(QDataStream& s, KFileMetaInfo& info )
{
QString mimeType;
bool isValid;
s >> isValid;
// if it's invalid, there is not much to do
if (!isValid)
{
info = KFileMetaInfo();
return s;
}
// we need a new object for our data
info.deref();
info.d = new KFileMetaInfo::Data();
s >> info.d->url
>> info.d->what
>> info.d->groups
>> mimeType;
info.d->mimeTypeInfo = KFileMetaInfoProvider::self()->mimeTypeInfo(mimeType);
return s;
}
#include "kfilemetainfo.moc"
KFileMetaInfoGroup::name
QString name() const
The name of this group.
Definition: kfilemetainfo.cpp:1314
KFileMetaInfo::isValid
bool isValid() const
Returns true if the item is valid, i.e.
Definition: kfilemetainfo.cpp:517
KFilePlugin::addMimeTypeInfo
KFileMimeTypeInfo * addMimeTypeInfo(const QString &mimeType)
Call this from within your constructor to tell the KFile framework what mimetypes your plugin support...
Definition: kfilemetainfo.cpp:793
KFileMimeTypeInfo::GroupInfo
Information about a meta information group.
Definition: kfilemetainfo.h:138
KFileMetaInfoItem
A meta information item about a file.
Definition: kfilemetainfo.h:496
KFileMetaInfo::item
KFileMetaInfoItem item(const QString &key) const
Returns the KFileMetaInfoItem with the given key.
Definition: kfilemetainfo.cpp:614
KFileMimeTypeInfo::Hint
Hint
This enum is mainly for items that have a special meaning for some applications.
Definition: kfilemetainfo.h:89
KFileMimeTypeInfo::Hertz
Sample rates and similar.
Definition: kfilemetainfo.h:123
KFileMetaInfoItem::string
QString string(bool mangle=true) const
Returns a string containing the value, if possible.
Definition: kfilemetainfo.cpp:187
KFileMetaInfoItem::setValue
bool setValue(const QVariant &value)
Changes the value of the item.
Definition: kfilemetainfo.cpp:134
KFileMimeTypeInfo::Modifiable
The value can be edited (no meaning for a group)
Definition: kfilemetainfo.h:68
KFileMetaInfoGroup
A group of meta information items about a file.
Definition: kfilemetainfo.h:684
KFilePlugin::setHint
void setHint(KFileMimeTypeInfo::ItemInfo *item, uint hint)
Defines the meaning of the meta information item.
Definition: kfilemetainfo.cpp:832
KFileMetaInfoGroup::supportedKeys
QStringList supportedKeys() const
Use this method to get a list of keys in the specified group that the plugin knows about...
Definition: kfilemetainfo.cpp:1277
KFileMetaInfoItem::attributes
uint attributes() const
Returns the attributes for this item.
Definition: kfilemetainfo.cpp:222
KFileMimeTypeInfo::ItemInfo::attributes
uint attributes() const
Return the attributes of the item.
Definition: kfilemetainfo.h:341
KFileMetaInfoGroup::keys
QStringList keys() const
Returns a list of all keys.
Definition: kfilemetainfo.cpp:1253
KFileMimeTypeInfo::createValidator
QValidator * createValidator(const QString &group, const QString &key, QObject *parent=0, const char *name=0) const
Creates a validator for this item.
Definition: kfilemetainfo.cpp:1534
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::translatedGroups
QStringList translatedGroups() const
Same as the above function, but returns the strings to display to the user.
Definition: kfilemetainfo.cpp:1506
KFileMimeTypeInfo::GroupInfo::attributes
uint attributes() const
Get the attributes of this group (see Attributes)
Definition: kfilemetainfo.h:196
KFileMetaInfoItem::key
QString key() const
Returns the key of the item.
Definition: kfilemetainfo.cpp:165
KFilePlugin::addItemInfo
KFileMimeTypeInfo::ItemInfo * addItemInfo(KFileMimeTypeInfo::GroupInfo *gi, const QString &key, const QString &translatedKey, QVariant::Type type)
Adds a meta information item to a GroupInfo object as returned by addGroupInfo(). ...
Definition: kfilemetainfo.cpp:819
KFileMetaInfo::groups
QStringList groups() const
Returns a list of all groups.
Definition: kfilemetainfo.cpp:377
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
KFileMimeTypeInfo::BitsPerPixel
A bit depth.
Definition: kfilemetainfo.h:122
KFileMetaInfo::group
KFileMetaInfoGroup group(const QString &key) const
Returns the KFileMetaInfoGroup with the given key.
Definition: kfilemetainfo.cpp:441
KTrader::query
virtual OfferList query(const QString &servicetype, const QString &constraint=QString::null, const QString &preferences=QString::null) const
The main function in the KTrader class.
Definition: ktrader.cpp:106
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
KFileMetaInfoGroup::removedItems
QStringList removedItems()
Returns a list of all removed items.
Definition: kfilemetainfo.cpp:1418
KFileMetaInfo::path
QString path() const
Returns the path of file - or QString::null if file is non-local.
Definition: kfilemetainfo.cpp:734
KFileMimeTypeInfo::Inches
Sizes.
Definition: kfilemetainfo.h:117
KFileMetaInfoGroup::isValid
bool isValid() const
Returns true if the item is valid, i.e.
Definition: kfilemetainfo.cpp:1214
KFileMimeTypeInfo::Pixels
For image dimensions and similar.
Definition: kfilemetainfo.h:116
KFileMimeTypeInfo::FramesPerSecond
A frame rate.
Definition: kfilemetainfo.h:120
KFileMetaInfo
Meta Information about a file.
Definition: kfilemetainfo.h:926
KFilePlugin::setAttributes
void setAttributes(KFileMimeTypeInfo::GroupInfo *gi, uint attr) const
Sets attributes of the GroupInfo object returned by addGroupInfo().
Definition: kfilemetainfo.cpp:808
KFileMetaInfo::applyChanges
bool applyChanges()
This method writes all pending changes of the meta info back to the file.
Definition: kfilemetainfo.cpp:532
KFileMetaInfoGroup::isModified
bool isModified() const
Returns true if an item as added or removed from the group.
Definition: kfilemetainfo.cpp:1330
KFileMetaInfoItem::isRemoved
bool isRemoved() const
If you remove an item, it is only marked for removal for the file.
Definition: kfilemetainfo.cpp:160
KFileMetaInfoItem::suffix
QString suffix() const
This method returns a translated suffix to be displayed after the value.
Definition: kfilemetainfo.cpp:212
KFileMimeTypeInfo::KiloBytes
Some data/file size in kilobytes.
Definition: kfilemetainfo.h:124
KFileMetaInfo::editableGroups
QStringList editableGroups() const
Returns the list of groups that you can add or remove from the file.
Definition: kfilemetainfo.cpp:387
KFileMimeTypeInfo::Centimeters
Sizes.
Definition: kfilemetainfo.h:118
KFilePlugin::addGroupInfo
KFileMimeTypeInfo::GroupInfo * addGroupInfo(KFileMimeTypeInfo *info, const QString &key, const QString &translatedKey) const
Creates a meta information group for KFileMimeTypeInfo object returned by addMimeTypeInfo().
Definition: kfilemetainfo.cpp:802
KFileMetaInfoGroup::translatedName
QString translatedName() const
The translated name of this group.
Definition: kfilemetainfo.cpp:1271
KFileMetaInfo::isEmpty
bool isEmpty() const
Returns false if the object contains data, true if it's empty.
Definition: kfilemetainfo.cpp:523
KFileMetaInfoGroup::addItem
KFileMetaInfoItem addItem(const QString &key)
Add an item to the info.
Definition: kfilemetainfo.cpp:1356
KFileMetaInfo::operator=
const KFileMetaInfo & operator=(const KFileMetaInfo &info)
The assignment operator, so you can do e.g.
Definition: kfilemetainfo.cpp:504
KFileMetaInfo::addGroup
bool addGroup(const QString &name)
Try to add the specified group.
Definition: kfilemetainfo.cpp:450
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: kfilemetainfo.cpp:227
KFileMimeTypeInfo::supportedGroups
QStringList supportedGroups() const
Returns the list of all groups that the plugin for this mimetype supports.
Definition: kfilemetainfo.cpp:1496
KFilePlugin
Base class for a meta information plugin.
Definition: kfilemetainfo.h:1394
KFileMetaInfo::mimeType
QString mimeType() const
Returns the mime type of file.
Definition: kfilemetainfo.cpp:592
KFileMetaInfo::url
KURL url() const
Returns the url of file.
Definition: kfilemetainfo.cpp:739
KFileMimeTypeInfo::groupInfo
const GroupInfo * groupInfo(const QString &group) const
Get the group info for a specific group.
Definition: kfilemetainfo.cpp:1483
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
KFileMetaInfoItem::translatedKey
QString translatedKey() const
Returns a translation of the key for displaying to the user.
Definition: kfilemetainfo.cpp:170
KFileMetaInfoGroup::preferredKeys
QStringList preferredKeys() const
Returns a list of all keys in preference order.
Definition: kfilemetainfo.cpp:1225
KFileMetaInfo::containsGroup
bool containsGroup(const QString &key) const
Checks whether a group with the given key exists.
Definition: kfilemetainfo.cpp:609
KFileMimeTypeInfo::mimeType
QString mimeType() const
Returns the mimetype to which this info belongs.
Definition: kfilemetainfo.h:435
KFileMetaInfoItem::isValid
bool isValid() const
Return true if the item is valid, i.e.
Definition: kfilemetainfo.cpp:232
KFileMetaInfoGroup::removeItem
bool removeItem(const QString &key)
Remove this item from the meta info of the file.
Definition: kfilemetainfo.cpp:1390
KFileMimeTypeInfo::ItemInfo::isVariableItem
bool isVariableItem() const
Is this item the variable item?
Definition: kfilemetainfo.h:319
KFileMimeTypeInfo::ItemInfo::string
QString string(const QVariant &value, bool mangle=true) const
Returns a string for the specified value, if possible.
Definition: kfilemetainfo.cpp:1603
KFileMetaInfoGroup::contains
bool contains(const QString &key) const
Checks whether an item with the given key exists.
Definition: kfilemetainfo.cpp:1289
KFilePlugin::setPrefix
void setPrefix(KFileMimeTypeInfo::ItemInfo *item, const QString &prefix)
Sets a prefix string which is displayed before the item's value.
Definition: kfilemetainfo.cpp:884
KTrader::OfferList
QValueList< KService::Ptr > OfferList
A list of services.
Definition: ktrader.h:92
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
KFileMetaInfoItem::type
QVariant::Type type() const
Return the type of the item.
Definition: kfilemetainfo.cpp:192
KFileMetaInfoGroup::operator=
const KFileMetaInfoGroup & operator=(const KFileMetaInfoGroup &info)
The assignment operator, so you can do:
Definition: kfilemetainfo.cpp:1201
KFileMimeTypeInfo::supportedKeys
QStringList supportedKeys() const
Return a list of all supported keys without looking for a specific group.
Definition: kfilemetainfo.cpp:1516
KFileMetaInfoGroup::item
KFileMetaInfoItem item(const QString &key) const
This method searches for the specified item.
Definition: kfilemetainfo.cpp:1294
KFileMimeTypeInfo::ItemInfo::key
const QString & key() const
Returns the name of the item.
Definition: kfilemetainfo.h:296
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...
KFileMetaInfoGroup::attributes
uint attributes() const
Returns the attributes of this item.
Definition: kfilemetainfo.cpp:1319
KFileMetaInfoItem::hint
uint hint() const
Returns the hint for this item.
Definition: kfilemetainfo.cpp:217
KFileMetaInfoItem::prefix
QString prefix() const
This method returns a translated prefix to be displayed before the value.
Definition: kfilemetainfo.cpp:207
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::Bytes
Some data/file size in bytes.
Definition: kfilemetainfo.h:119
KFileMetaInfoItem::KFileMetaInfoItem
KFileMetaInfoItem()
Default constructor.
Definition: kfilemetainfo.cpp:109
KFileMimeTypeInfo::MilliSeconds
The item represents a time in milliseconds.
Definition: kfilemetainfo.h:114
KTrader::self
static KTrader * self()
This is a static pointer to a KTrader instance.
Definition: ktrader.cpp:90
KFileMetaInfoGroup::KFileMetaInfoGroup
KFileMetaInfoGroup()
Default constructor.
Definition: kfilemetainfo.cpp:1191
KFileMimeTypeInfo::Removable
It can be removed.
Definition: kfilemetainfo.h:67
KFilePlugin::~KFilePlugin
virtual ~KFilePlugin()
Destructor.
Definition: kfilemetainfo.cpp:788
KFileMetaInfoItem::unit
uint unit() const
Returns the unit for this item.
Definition: kfilemetainfo.cpp:197
KFileMimeTypeInfo::GroupInfo::itemInfo
const ItemInfo * itemInfo(const QString &key) const
A group object can contain several item objects (of which you can get the names with supportedKeys() ...
Definition: kfilemetainfo.cpp:1565
KFileMetaInfo::KFileMetaInfo
KFileMetaInfo()
Default constructor.
Definition: kfilemetainfo.cpp:355
KFileMetaInfoGroup::supportsVariableKeys
bool supportsVariableKeys() const
Returns true if this group supports adding or removing arbitrary keys, false if not.
Definition: kfilemetainfo.cpp:1283
KFilePlugin::appendItem
void appendItem(KFileMetaInfoGroup &group, const QString &key, QVariant value)
Call this method from within readInfo() to fill the meta information item identified by key with a va...
Definition: kfilemetainfo.cpp:899
KFileMetaInfo::saveItem
KFileMetaInfoItem saveItem(const QString &key, const QString &preferredGroup=QString::null, bool createGroup=true)
Saves the item with the given key.
Definition: kfilemetainfo.cpp:637
KFilePlugin::virtual_hook
virtual void virtual_hook(int id, void *data)
Helper method to allow binary compatible extensions when needing "new virtual methods".
Definition: kfilemetainfo.cpp:798
KFilePlugin::setUnit
void setUnit(KFileMimeTypeInfo::ItemInfo *item, uint unit)
Sets the unit used in the meta information item.
Definition: kfilemetainfo.cpp:837
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
KFileMetaInfo::preferredGroups
QStringList preferredGroups() const
Returns a list of the preferred groups.
Definition: kfilemetainfo.cpp:402
KFileMetaInfo::removedGroups
QStringList removedGroups()
Returns a list of removed groups.
Definition: kfilemetainfo.cpp:499
KFileMetaInfo::preferredKeys
QStringList preferredKeys() const
Returns a list of all preferred keys.
Definition: kfilemetainfo.cpp:428
KFileMimeTypeInfo::ItemInfo
This is the class for one item of a KFileMimeTypeInfo.
Definition: kfilemetainfo.h:250
KFileMimeTypeInfo::DotsPerInch
Resolution in DPI.
Definition: kfilemetainfo.h:121
KFileMetaInfoItem::isModified
bool isModified() const
If you change an item, it is marked as "dirty".
Definition: kfilemetainfo.cpp:202
KFileMimeTypeInfo::Millimeters
Sizes.
Definition: kfilemetainfo.h:125
KFileMetaInfoGroup::isEmpty
bool isEmpty() const
Returns false if the object contains data, true if it's empty.
Definition: kfilemetainfo.cpp:1220
KFileMetaInfo::supportedGroups
QStringList supportedGroups() const
Returns a list of all supported groups.
Definition: kfilemetainfo.cpp:365
KFileMetaInfo::contains
bool contains(const QString &key) const
Checks whether an item with the given key exists.
Definition: kfilemetainfo.cpp:598
KIO::convertSize
KIO_EXPORT QString convertSize(KIO::filesize_t size)
Converts size from bytes to the string representation.
Definition: global.cpp:53
KFileMetaInfo::removeGroup
bool removeGroup(const QString &name)
Remove the specified group.
Definition: kfilemetainfo.cpp:487
KFilePlugin::setSuffix
void setSuffix(KFileMimeTypeInfo::ItemInfo *item, const QString &suffix)
Sets a suffix string which is displayed before the item's value.
Definition: kfilemetainfo.cpp:889
KFileMetaInfo::plugin
KFilePlugin *const plugin() const
Definition: kfilemetainfo.cpp:585
KIO::convertSizeFromKB
KIO_EXPORT QString convertSizeFromKB(KIO::filesize_t kbSize)
Converts size from kilo-bytes to the string representation.
Definition: global.cpp:91
KFileMetaInfo::supportedKeys
QStringList supportedKeys() const
Returns a list of supported keys.
Definition: kfilemetainfo.cpp:371
KFileMimeTypeInfo::Addable
The item or group can be added by a user.
Definition: kfilemetainfo.h:66
KFilePlugin::KFilePlugin
KFilePlugin(QObject *parent, const char *name, const QStringList &args)
Creates a new KFilePlugin instance.
Definition: kfilemetainfo.cpp:781
KFileMetaInfoItem::value
const QVariant & value() const
Returns the value of the item.
Definition: kfilemetainfo.cpp:182
KServiceTypeProfile::preferredService
static KService::Ptr preferredService(const QString &serviceType, const QString &genericServiceType)
Returns the preferred service for _serviceType and _genericServiceType ("Application", type of component, or null).
Definition: kuserprofile.cpp:303
KFileMimeTypeInfo::BitsPerSecond
A bit rate.
Definition: kfilemetainfo.h:115
KFileMimeTypeInfo::Seconds
The item represents a time in seconds.
Definition: kfilemetainfo.h:113

KDE Home | KDE Accessibility Home | Description of Access Keys