~ubuntu-branches/ubuntu/precise/gwenview/precise-proposed

« back to all changes in this revision

Viewing changes to lib/archiveutils.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20111215141754-z043hyx69dulbggf
Tags: upstream-4.7.90
Import upstream version 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// vim: set tabstop=4 shiftwidth=4 noexpandtab
 
1
// vim: set tabstop=4 shiftwidth=4 expandtab
2
2
/*
3
3
Gwenview - A simple image viewer for KDE
4
4
Copyright 2000-2007 Aurélien Gâteau <agateau@kde.org>
27
27
#include <kmimetype.h>
28
28
#include <kprotocolmanager.h>
29
29
 
30
 
namespace Gwenview {
31
 
 
32
 
 
33
 
namespace ArchiveUtils {
34
 
 
35
 
bool fileItemIsArchive(const KFileItem& item) {
36
 
        KMimeType::Ptr mimeType = item.determineMimeType();
37
 
        return !ArchiveUtils::protocolForMimeType(mimeType->name()).isEmpty();
38
 
}
39
 
 
40
 
bool fileItemIsDirOrArchive(const KFileItem& item) {
41
 
        return item.isDir() || fileItemIsArchive(item);
42
 
}
43
 
 
44
 
QString protocolForMimeType(const QString& mimeType) {
45
 
        static QHash<QString, QString> cache;
46
 
        QHash<QString, QString>::ConstIterator it = cache.constFind(mimeType);
47
 
        if (it != cache.constEnd()) {
48
 
                return it.value();
49
 
        }
50
 
 
51
 
        QString protocol = KProtocolManager::protocolForArchiveMimetype(mimeType);
52
 
        if (protocol.isEmpty()) {
53
 
                // No protocol, try with mimeType parents. This is useful for .cbz for
54
 
                // example
55
 
                KMimeType::Ptr ptr = KMimeType::mimeType(mimeType);
56
 
                if (ptr) {
57
 
                        Q_FOREACH(const QString& parentMimeType, ptr->allParentMimeTypes()) {
58
 
                                protocol = KProtocolManager::protocolForArchiveMimetype(parentMimeType);
59
 
                                if (!protocol.isEmpty()) {
60
 
                                        break;
61
 
                                }
62
 
                        }
63
 
                }
64
 
        }
65
 
 
66
 
        cache.insert(mimeType, protocol);
67
 
        return protocol;
 
30
namespace Gwenview
 
31
{
 
32
 
 
33
namespace ArchiveUtils
 
34
{
 
35
 
 
36
bool fileItemIsArchive(const KFileItem& item)
 
37
{
 
38
    KMimeType::Ptr mimeType = item.determineMimeType();
 
39
    return !ArchiveUtils::protocolForMimeType(mimeType->name()).isEmpty();
 
40
}
 
41
 
 
42
bool fileItemIsDirOrArchive(const KFileItem& item)
 
43
{
 
44
    return item.isDir() || fileItemIsArchive(item);
 
45
}
 
46
 
 
47
QString protocolForMimeType(const QString& mimeType)
 
48
{
 
49
    static QHash<QString, QString> cache;
 
50
    QHash<QString, QString>::ConstIterator it = cache.constFind(mimeType);
 
51
    if (it != cache.constEnd()) {
 
52
        return it.value();
 
53
    }
 
54
 
 
55
    QString protocol = KProtocolManager::protocolForArchiveMimetype(mimeType);
 
56
    if (protocol.isEmpty()) {
 
57
        // No protocol, try with mimeType parents. This is useful for .cbz for
 
58
        // example
 
59
        KMimeType::Ptr ptr = KMimeType::mimeType(mimeType);
 
60
        if (ptr) {
 
61
            Q_FOREACH(const QString & parentMimeType, ptr->allParentMimeTypes()) {
 
62
                protocol = KProtocolManager::protocolForArchiveMimetype(parentMimeType);
 
63
                if (!protocol.isEmpty()) {
 
64
                    break;
 
65
                }
 
66
            }
 
67
        }
 
68
    }
 
69
 
 
70
    cache.insert(mimeType, protocol);
 
71
    return protocol;
68
72
}
69
73
 
70
74
} // namespace ArchiveUtils