1 // vim: set tabstop=4 shiftwidth=4 noexpandtab
3 Gwenview - A simple image viewer for KDE
4 Copyright 2000-2007 Aurélien Gâteau <aurelien.gateau@free.fr>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "archiveutils.h"
26 #include <kfileitem.h>
31 namespace ArchiveUtils
{
33 typedef QMap
<QString
,QString
> ArchiveProtocolForMimeTypes
;
35 static const ArchiveProtocolForMimeTypes
& archiveProtocolForMimeTypes() {
36 static ArchiveProtocolForMimeTypes map
;
37 static bool initialized
= false;
39 // FIXME: This code used to work in KDE3. For now stick with an
40 // hardcoded list of mimetypes, stolen from Dolphin code
42 static const char* KDE_PROTOCOL
= "X-KDE-LocalProtocol";
43 KMimeType::List list
= KMimeType::allMimeTypes();
44 KMimeType::List::Iterator it
=list
.begin(), end
=list
.end();
45 for (; it
!=end
; ++it
) {
46 if ( (*it
)->propertyNames().indexOf(KDE_PROTOCOL
)!= -1 ) {
47 QString protocol
= (*it
)->property(KDE_PROTOCOL
).toString();
48 map
[(*it
)->name()] = protocol
;
52 map
["application/zip"] = "zip";
53 map
["application/x-tar"] = "tar";
54 map
["application/x-tarz"] = "tar";
55 map
["application/x-bzip-compressed-tar"] = "tar";
56 map
["application/x-compressed-tar"] = "tar";
57 map
["application/x-tzo"] = "tar";
60 kWarning() << "No archive protocol found.";
66 // We do not use QMap::operator[] because we need to compare using
68 static ArchiveProtocolForMimeTypes::ConstIterator
findProtocol(const KMimeType::Ptr mimeType
) {
69 ArchiveProtocolForMimeTypes::ConstIterator
70 it
= archiveProtocolForMimeTypes().constBegin(),
71 end
= archiveProtocolForMimeTypes().constEnd();
72 for (; it
!=end
; ++it
) {
73 if (mimeType
->is(it
.key())) {
80 bool fileItemIsArchive(const KFileItem
& item
) {
81 KMimeType::Ptr mimeType
= item
.determineMimeType();
82 ArchiveProtocolForMimeTypes::ConstIterator it
= findProtocol(mimeType
);
83 return it
!= archiveProtocolForMimeTypes().end();
86 bool fileItemIsDirOrArchive(const KFileItem
& item
) {
87 return item
.isDir() || fileItemIsArchive(item
);
90 QStringList
mimeTypes() {
91 return archiveProtocolForMimeTypes().keys();
94 QString
protocolForMimeType(const QString
& mimeTypeName
) {
95 KMimeType::Ptr mimeTypePtr
= KMimeType::mimeType(mimeTypeName
);
96 ArchiveProtocolForMimeTypes::ConstIterator it
= findProtocol(mimeTypePtr
);
100 } // namespace ArchiveUtils
102 } // namespace Gwenview