mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
kdecore: deal with KMimeType TODO
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
63a5c48126
commit
5290bf44e0
12 changed files with 116 additions and 192 deletions
|
@ -30,15 +30,10 @@
|
|||
class KFolderMimeTypePrivate : public KMimeTypePrivate
|
||||
{
|
||||
public:
|
||||
K_SYCOCATYPE( KST_KFolderMimeType, KMimeTypePrivate )
|
||||
|
||||
KFolderMimeTypePrivate(const QString &s)
|
||||
: KMimeTypePrivate(s)
|
||||
{}
|
||||
|
||||
KFolderMimeTypePrivate(QDataStream& str, int offset)
|
||||
: KMimeTypePrivate(str, offset)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
QString comment(const KUrl &url = KUrl()) const final;
|
||||
QString iconName(const KUrl &url) const final;
|
||||
|
@ -56,19 +51,15 @@ KFolderMimeType::KFolderMimeType( const QString& fullpath, const QString& name,
|
|||
{
|
||||
}
|
||||
|
||||
KFolderMimeType::KFolderMimeType( QDataStream& str, int offset )
|
||||
: KMimeType( *new KFolderMimeTypePrivate(str, offset))
|
||||
{
|
||||
}
|
||||
|
||||
KFolderMimeType::~KFolderMimeType()
|
||||
{
|
||||
}
|
||||
|
||||
QString KFolderMimeTypePrivate::iconName(const KUrl &_url) const
|
||||
{
|
||||
if ( _url.isEmpty() || !_url.isLocalFile() )
|
||||
if (_url.isEmpty() || !_url.isLocalFile()) {
|
||||
return KMimeTypePrivate::iconName(_url);
|
||||
}
|
||||
|
||||
// Stating .directory files can cause long freezes when e.g. /home
|
||||
// uses autofs for every user's home directory, i.e. opening /home
|
||||
|
@ -89,15 +80,13 @@ QString KFolderMimeTypePrivate::iconName( const KUrl& _url ) const
|
|||
QString icon;
|
||||
// using KStandardDirs as this one checks for path being
|
||||
// a file instead of a directory
|
||||
if ( KGlobal::dirs()->exists( u.toLocalFile() ) )
|
||||
{
|
||||
if (KGlobal::dirs()->exists(u.toLocalFile())) {
|
||||
KDesktopFile cfg(u.toLocalFile());
|
||||
KConfigGroup group = cfg.desktopGroup();
|
||||
icon = group.readEntry("Icon");
|
||||
QString empty_icon = group.readEntry("EmptyIcon");
|
||||
|
||||
if ( !empty_icon.isEmpty() )
|
||||
{
|
||||
if (!empty_icon.isEmpty()) {
|
||||
bool isempty = true;
|
||||
QDirIterator dirIt(_url.toLocalFile(), QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
||||
while (dirIt.hasNext() ) {
|
||||
|
@ -107,13 +96,15 @@ QString KFolderMimeTypePrivate::iconName( const KUrl& _url ) const
|
|||
break;
|
||||
}
|
||||
}
|
||||
if ( isempty )
|
||||
if (isempty) {
|
||||
return empty_icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( icon.isEmpty() )
|
||||
if (icon.isEmpty()) {
|
||||
return KMimeTypePrivate::iconName(_url);
|
||||
}
|
||||
|
||||
if (icon.startsWith(QLatin1String("./"))) {
|
||||
// path is relative with respect to the location
|
||||
|
|
|
@ -30,6 +30,7 @@ class KFolderMimeTypePrivate;
|
|||
* Folder mime type. Handles the .directory file inside a folder, which modifies
|
||||
* the comment and icon for this folder.
|
||||
* @short Mimetype for a folder (inode/directory)
|
||||
* @todo merge into KMimeType
|
||||
*/
|
||||
class KDECORE_EXPORT KFolderMimeType : public KMimeType
|
||||
{
|
||||
|
@ -39,9 +40,6 @@ public:
|
|||
/** \internal */
|
||||
KFolderMimeType(const QString &fullpath, const QString &name, const QString &comment);
|
||||
|
||||
/** \internal */
|
||||
KFolderMimeType( QDataStream& str, int offset );
|
||||
|
||||
/** Destructor. */
|
||||
~KFolderMimeType();
|
||||
};
|
||||
|
|
|
@ -382,62 +382,34 @@ bool KMimeType::isBinaryData(const QString &fileName)
|
|||
|
||||
KMimeType::KMimeType(KMimeTypePrivate &dd, const QString &name,
|
||||
const QString &comment)
|
||||
: KServiceType(dd, name, comment)
|
||||
: d_ptr(&dd)
|
||||
{
|
||||
d_ptr->m_strName = name;
|
||||
d_ptr->m_strComment = comment;
|
||||
}
|
||||
|
||||
KMimeType::KMimeType(const QString &fullpath, const QString &name,
|
||||
const QString &comment)
|
||||
: KServiceType(*new KMimeTypePrivate(fullpath), name, comment)
|
||||
: QSharedData(),
|
||||
d_ptr(new KMimeTypePrivate(fullpath))
|
||||
{
|
||||
d_ptr->m_strName = name;
|
||||
d_ptr->m_strComment = comment;
|
||||
}
|
||||
|
||||
KMimeType::KMimeType(KMimeTypePrivate &dd)
|
||||
: KServiceType(dd)
|
||||
: QSharedData(),
|
||||
d_ptr(&dd)
|
||||
{
|
||||
}
|
||||
|
||||
KMimeType::KMimeType(QDataStream &str, int offset)
|
||||
: KServiceType(*new KMimeTypePrivate(str, offset))
|
||||
{
|
||||
}
|
||||
|
||||
void KMimeTypePrivate::save(QDataStream &str)
|
||||
{
|
||||
KServiceTypePrivate::save(str);
|
||||
// Warning adding fields here involves a binary incompatible change - update version
|
||||
// number in ksycoca.h. Never remove fields.
|
||||
str << m_lstPatterns << QString() << QStringList() << m_iconName;
|
||||
}
|
||||
|
||||
QVariant KMimeTypePrivate::property(const QString &name) const
|
||||
{
|
||||
if (name == QLatin1String("Patterns")) {
|
||||
return patterns();
|
||||
} else if (name == QLatin1String("Comment")) {
|
||||
return comment();
|
||||
} else if (name == QLatin1String("Icon")) {
|
||||
return QVariant(iconName(KUrl()));
|
||||
}
|
||||
return KServiceTypePrivate::property(name);
|
||||
}
|
||||
|
||||
QStringList KMimeTypePrivate::propertyNames() const
|
||||
{
|
||||
QStringList res = KServiceTypePrivate::propertyNames();
|
||||
res.append(QString::fromLatin1("Patterns"));
|
||||
res.append(QString::fromLatin1("Icon"));
|
||||
return res;
|
||||
}
|
||||
|
||||
KMimeType::~KMimeType()
|
||||
{
|
||||
}
|
||||
|
||||
QString KMimeType::iconNameForUrl(const KUrl &_url, mode_t mode)
|
||||
{
|
||||
const KMimeType::Ptr mt = findByUrl(_url, mode, _url.isLocalFile(),
|
||||
false /*HACK*/);
|
||||
const KMimeType::Ptr mt = findByUrl(_url, mode, _url.isLocalFile(), false /*HACK*/);
|
||||
if (!mt) {
|
||||
return QString();
|
||||
}
|
||||
|
@ -561,6 +533,12 @@ QString KMimeType::defaultMimeType()
|
|||
return QString::fromLatin1("application/octet-stream");
|
||||
}
|
||||
|
||||
QString KMimeType::name() const
|
||||
{
|
||||
Q_D(const KMimeType);
|
||||
return d->m_strName;
|
||||
}
|
||||
|
||||
QString KMimeType::iconName(const KUrl &url) const
|
||||
{
|
||||
Q_D(const KMimeType);
|
||||
|
@ -722,11 +700,6 @@ bool KMimeType::matchFileName(const QString &filename, const QString &pattern)
|
|||
return KMimeTypeRepository::matchFileName(filename, pattern);
|
||||
}
|
||||
|
||||
int KMimeTypePrivate::serviceOffersOffset() const
|
||||
{
|
||||
return KMimeTypeFactory::self()->serviceOffersOffset(name());
|
||||
}
|
||||
|
||||
QString KMimeTypePrivate::iconName(const KUrl &url) const
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#define KMIMETYPE_H
|
||||
|
||||
#include <kurl.h>
|
||||
#include <kservicetype.h>
|
||||
#include <ksharedptr.h>
|
||||
|
||||
class KMimeTypePrivate;
|
||||
|
||||
|
@ -31,12 +31,9 @@ class KMimeTypePrivate;
|
|||
*
|
||||
* The starting point you need is often the static methods.
|
||||
*
|
||||
* KMimeType inherits KServiceType because "text/plain" can be used to find
|
||||
* services (apps and components) "which can open text/plain".
|
||||
*
|
||||
* @see KServiceType
|
||||
*/
|
||||
class KDECORE_EXPORT KMimeType : public KServiceType // TODO KDE5: drop kservicetype inheritance, inherit kshared
|
||||
class KDECORE_EXPORT KMimeType : public QSharedData
|
||||
{
|
||||
Q_DECLARE_PRIVATE(KMimeType)
|
||||
public:
|
||||
|
@ -45,6 +42,8 @@ public:
|
|||
|
||||
virtual ~KMimeType();
|
||||
|
||||
QString name() const;
|
||||
|
||||
/**
|
||||
* Return the filename of the icon associated with the mimetype.
|
||||
* Use KIconLoader::loadMimeTypeIcon to load the icon.
|
||||
|
@ -402,16 +401,8 @@ public:
|
|||
static int sharedMimeInfoVersion();
|
||||
|
||||
protected:
|
||||
|
||||
friend class KMimeTypeRepository; // for KMimeType(QString,QString,QString)
|
||||
|
||||
/**
|
||||
* @internal Construct a service from a stream.
|
||||
*
|
||||
* The stream must already be positionned at the correct offset
|
||||
*/
|
||||
KMimeType(QDataStream &str, int offset);
|
||||
|
||||
/**
|
||||
* Construct a mimetype and take all information from an XML file.
|
||||
* @param fullpath the path to the xml that describes the mime type
|
||||
|
@ -439,9 +430,8 @@ protected:
|
|||
KMimeType(KMimeTypePrivate &dd, const QString &name, const QString &comment);
|
||||
|
||||
private:
|
||||
// Forbidden nowadays in KMimeType
|
||||
int offset() const;
|
||||
void save(QDataStream &s);
|
||||
friend class KFolderMimeType;
|
||||
KMimeTypePrivate* d_ptr;
|
||||
|
||||
static void checkEssentialMimeTypes();
|
||||
static KMimeType::Ptr findByUrlHelper(const KUrl& url, mode_t mode,
|
||||
|
|
|
@ -16,34 +16,20 @@
|
|||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
#ifndef __kmimetype_p_h__
|
||||
#define __kmimetype_p_h__
|
||||
#ifndef KMIMETYPE_P_H
|
||||
#define KMIMETYPE_P_H
|
||||
|
||||
#include "kservicetype_p.h"
|
||||
#include <QStringList>
|
||||
|
||||
class KMimeTypePrivate: public KServiceTypePrivate
|
||||
class KMimeTypePrivate
|
||||
{
|
||||
public:
|
||||
K_SYCOCATYPE( KST_KMimeType, KServiceTypePrivate )
|
||||
|
||||
KMimeTypePrivate(const QString &path)
|
||||
: KServiceTypePrivate(path),
|
||||
: m_path(path),
|
||||
m_xmlDataLoaded(false)
|
||||
{
|
||||
}
|
||||
|
||||
KMimeTypePrivate(QDataStream &str, int offset)
|
||||
: KServiceTypePrivate(str, offset),
|
||||
m_xmlDataLoaded(false)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void save(QDataStream &str);
|
||||
|
||||
virtual QVariant property(const QString &name) const;
|
||||
|
||||
virtual QStringList propertyNames() const;
|
||||
|
||||
virtual QString comment(const KUrl &url = KUrl()) const
|
||||
{
|
||||
ensureXmlDataLoaded();
|
||||
|
@ -61,11 +47,13 @@ public:
|
|||
|
||||
bool inherits(const QString &mime) const;
|
||||
void ensureXmlDataLoaded() const;
|
||||
virtual int serviceOffersOffset() const;
|
||||
|
||||
mutable QString m_path;
|
||||
mutable QString m_strName;
|
||||
mutable QString m_strComment;
|
||||
mutable QStringList m_lstPatterns;
|
||||
mutable QString m_iconName; // user-specified
|
||||
mutable bool m_xmlDataLoaded;
|
||||
};
|
||||
|
||||
#endif // __kmimetype_p_h__
|
||||
#endif // KMIMETYPE_P_H
|
||||
|
|
|
@ -75,28 +75,22 @@ int KMimeTypeFactory::serviceOffersOffset(const QString& mimeTypeName)
|
|||
|
||||
KMimeTypeFactory::MimeTypeEntry * KMimeTypeFactory::createEntry(int offset) const
|
||||
{
|
||||
MimeTypeEntry *newEntry = 0;
|
||||
MimeTypeEntry *newEntry = nullptr;
|
||||
KSycocaType type;
|
||||
QDataStream *str = KSycoca::self()->findEntry(offset, type);
|
||||
if (!str) return 0;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case KST_KMimeTypeEntry:
|
||||
switch(type) {
|
||||
case KST_KMimeTypeEntry: {
|
||||
newEntry = new MimeTypeEntry(*str, offset);
|
||||
break;
|
||||
|
||||
// Old, now unused
|
||||
case KST_KMimeType:
|
||||
case KST_KFolderMimeType:
|
||||
return 0;
|
||||
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
kError(7011) << "KMimeTypeFactory: unexpected object entry in KSycoca database (type=" << int(type) << ")";
|
||||
break;
|
||||
}
|
||||
if (newEntry && !newEntry->isValid())
|
||||
{
|
||||
}
|
||||
if (newEntry && !newEntry->isValid()) {
|
||||
kError(7011) << "KMimeTypeFactory: corrupt object in KSycoca database!\n";
|
||||
delete newEntry;
|
||||
newEntry = 0;
|
||||
|
|
|
@ -88,9 +88,9 @@ KMimeType::Ptr KMimeTypeRepository::findMimeTypeByName(const QString &_name, KMi
|
|||
return KMimeType::Ptr(); // Not found
|
||||
}
|
||||
|
||||
if (name == QLatin1String("inode/directory"))
|
||||
if (name == QLatin1String("inode/directory")) {
|
||||
return KMimeType::Ptr(new KFolderMimeType(filename, name, QString() /*comment*/));
|
||||
else
|
||||
}
|
||||
return KMimeType::Ptr(new KMimeType(filename, name, QString() /*comment*/));
|
||||
}
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@
|
|||
* To use it, call the macro K_SYCOCATYPE( your_typecode, parent_class )
|
||||
* at the top of your class definition.
|
||||
*/
|
||||
enum KSycocaType { KST_KSycocaEntry = 0, KST_KService = 1, KST_KServiceType = 2, KST_KMimeType = 3,
|
||||
KST_KFolderMimeType = 4, KST_KMimeTypeEntry = 5 /*internal*/,
|
||||
KST_KServiceGroup = 6, KST_KProtocolInfo = 7, KST_KServiceSeparator = 8,
|
||||
enum KSycocaType { KST_KSycocaEntry = 0, KST_KService = 1, KST_KServiceType = 2,
|
||||
KST_KMimeTypeEntry = 3 /*internal*/,
|
||||
KST_KServiceGroup = 4, KST_KProtocolInfo = 5, KST_KServiceSeparator = 6,
|
||||
KST_KCustom = 1000 };
|
||||
|
||||
/**
|
||||
|
|
|
@ -495,7 +495,6 @@ void KMimeTypeTest::testAllMimeTypes()
|
|||
//qDebug( "%s", qPrintable( name ) );
|
||||
QVERIFY( !name.isEmpty() );
|
||||
QCOMPARE( name.count( '/' ), 1 );
|
||||
QVERIFY( mime->isType( KST_KMimeType ) );
|
||||
|
||||
const KMimeType::Ptr lookedupMime = KMimeType::mimeType( name );
|
||||
QVERIFY( lookedupMime ); // not null
|
||||
|
@ -977,14 +976,4 @@ void KMimeTypeTest::testThreads()
|
|||
future10.wait();
|
||||
}
|
||||
|
||||
void KMimeTypeTest::testProperties()
|
||||
{
|
||||
KMimeType::Ptr pngMimeType = KMimeType::mimeType("image/png");
|
||||
QVariant comment = pngMimeType->property("Comment");
|
||||
QVariant patterns = pngMimeType->property("Patterns");
|
||||
|
||||
QCOMPARE(comment.toString(), pngMimeType->comment());
|
||||
QCOMPARE(patterns.toStringList(), pngMimeType->patterns());
|
||||
}
|
||||
|
||||
#include "moc_kmimetypetest.cpp"
|
||||
|
|
|
@ -61,7 +61,6 @@ private Q_SLOTS:
|
|||
void testHelperProtocols();
|
||||
void testFromThread();
|
||||
void testThreads();
|
||||
void testProperties();
|
||||
private:
|
||||
QList<KMimeMagicRule> m_rules;
|
||||
QString m_nonKdeApp;
|
||||
|
|
|
@ -25,14 +25,15 @@
|
|||
#include "ksycocadict_p.h"
|
||||
#include "ksycocaresourcelist.h"
|
||||
#include "kdesktopfile.h"
|
||||
|
||||
#include "kservicetype.h"
|
||||
#include <kglobal.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <klocale.h>
|
||||
#include <kdebug.h>
|
||||
#include <assert.h>
|
||||
#include <kmimetypefactory.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
KBuildServiceFactory::KBuildServiceFactory( KSycocaFactory *serviceTypeFactory,
|
||||
KBuildMimeTypeFactory *mimeTypeFactory,
|
||||
KBuildServiceGroupFactory *serviceGroupFactory ) :
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "kfile_export.h"
|
||||
#include "kabstractfilewidget.h"
|
||||
#include "kconfiggroup.h"
|
||||
|
||||
class KJob;
|
||||
class KFileItem;
|
||||
|
|
Loading…
Add table
Reference in a new issue