diff --git a/gwenview/app/browsemainpage.cpp b/gwenview/app/browsemainpage.cpp index 9003843a..9aea9d68 100644 --- a/gwenview/app/browsemainpage.cpp +++ b/gwenview/app/browsemainpage.cpp @@ -51,7 +51,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA #include #include #include -#include #include #include #include @@ -201,7 +200,7 @@ struct BrowseMainPagePrivate : public Ui_BrowseMainPage for (int row = start; row <= end; ++row) { QModelIndex index = mDirModel->index(row, 0, parent); KFileItem item = mDirModel->itemForIndex(index); - if (!ArchiveUtils::fileItemIsDirOrArchive(item)) { + if (!item.isDir()) { ++count; } } diff --git a/gwenview/app/infocontextmanageritem.cpp b/gwenview/app/infocontextmanageritem.cpp index eb18062e..b5215d2b 100644 --- a/gwenview/app/infocontextmanageritem.cpp +++ b/gwenview/app/infocontextmanageritem.cpp @@ -40,7 +40,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Local #include "imagemetainfodialog.h" #include "sidebar.h" -#include #include #include #include @@ -302,7 +301,7 @@ void InfoContextManagerItem::updateSideBarContent() } KFileItem item = itemList.first(); - if (itemList.count() == 1 && !ArchiveUtils::fileItemIsDirOrArchive(item)) { + if (itemList.count() == 1 && !item.isDir()) { fillOneFileGroup(item); } else { fillMultipleItemsGroup(itemList); diff --git a/gwenview/app/mainwindow.cpp b/gwenview/app/mainwindow.cpp index 0f957c9e..32d11d8d 100644 --- a/gwenview/app/mainwindow.cpp +++ b/gwenview/app/mainwindow.cpp @@ -84,7 +84,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "thumbnailviewhelper.h" #include "browsemainpage.h" #include -#include #include #include #include @@ -543,7 +542,6 @@ struct MainWindow::Private { mDirModel->setKindFilter( MimeTypeUtils::KIND_DIR - | MimeTypeUtils::KIND_ARCHIVE | MimeTypeUtils::KIND_RASTER_IMAGE | MimeTypeUtils::KIND_SVG_IMAGE); @@ -565,11 +563,11 @@ struct MainWindow::Private mThumbnailBarModel->setSourceModel(mDirModel); } - bool indexIsDirOrArchive(const QModelIndex& index) const + bool indexIsDir(const QModelIndex& index) const { Q_ASSERT(index.isValid()); KFileItem item = mDirModel->itemForIndex(index); - return ArchiveUtils::fileItemIsDirOrArchive(item); + return item.isDir(); } void goTo(const QModelIndex& index) @@ -586,7 +584,7 @@ struct MainWindow::Private mPreloadDirectionIsForward = offset > 0; QModelIndex index = mContextManager->selectionModel()->currentIndex(); index = mDirModel->index(index.row() + offset, 0); - if (index.isValid() && !indexIsDirOrArchive(index)) { + if (index.isValid() && !indexIsDir(index)) { goTo(index); } } @@ -600,7 +598,7 @@ struct MainWindow::Private return; } - if (!indexIsDirOrArchive(index)) { + if (!indexIsDir(index)) { break; } } @@ -893,16 +891,8 @@ void MainWindow::slotThumbnailViewIndexActivated(const QModelIndex& index) // Item is a dir, open it openDirUrl(item.url()); } else { - QString protocol = ArchiveUtils::protocolForMimeType(item.mimetype()); - if (!protocol.isEmpty()) { - // Item is an archive, tweak url then open it - KUrl url = item.url(); - url.setProtocol(protocol); - openDirUrl(url); - } else { - // Item is a document, switch to view mode - d->mViewAction->trigger(); - } + // Item is a document, switch to view mode + d->mViewAction->trigger(); } } @@ -933,7 +923,7 @@ void MainWindow::openSelectedDocuments() Q_FOREACH(const QModelIndex& index, list) { KFileItem item = d->mDirModel->itemForIndex(index); - if (!item.isNull() && !ArchiveUtils::fileItemIsDirOrArchive(item)) { + if (!item.isNull() && !item.isDir()) { KUrl url = item.url(); if (!firstDocumentIndex.isValid()) { firstDocumentIndex = index; @@ -1107,7 +1097,7 @@ void MainWindow::slotSelectionChanged() item = d->mDirModel->itemForIndex(index); } QUndoGroup* undoGroup = DocumentFactory::instance()->undoGroup(); - if (!item.isNull() && !ArchiveUtils::fileItemIsDirOrArchive(item)) { + if (!item.isNull() && !item.isDir()) { KUrl url = item.url(); Document::Ptr doc = DocumentFactory::instance()->load(url); undoGroup->addStack(doc->undoStack()); @@ -1197,12 +1187,12 @@ void MainWindow::updatePreviousNextActions() bool hasPrevious; bool hasNext; QModelIndex currentIndex = d->mContextManager->selectionModel()->currentIndex(); - if (currentIndex.isValid() && !d->indexIsDirOrArchive(currentIndex)) { + if (currentIndex.isValid() && !d->indexIsDir(currentIndex)) { int row = currentIndex.row(); QModelIndex prevIndex = d->mDirModel->index(row - 1, 0); QModelIndex nextIndex = d->mDirModel->index(row + 1, 0); - hasPrevious = prevIndex.isValid() && !d->indexIsDirOrArchive(prevIndex); - hasNext = nextIndex.isValid() && !d->indexIsDirOrArchive(nextIndex); + hasPrevious = prevIndex.isValid() && !d->indexIsDir(prevIndex); + hasNext = nextIndex.isValid() && !d->indexIsDir(nextIndex); } else { hasPrevious = false; hasNext = false; @@ -1481,7 +1471,7 @@ void MainWindow::preloadNextUrl() } KFileItem item = d->mDirModel->itemForIndex(index); - if (!ArchiveUtils::fileItemIsDirOrArchive(item)) { + if (!item.isDir()) { KUrl url = item.url(); if (url.isLocalFile()) { QSize size = d->mViewStackedWidget->size(); diff --git a/gwenview/importer/documentdirfinder.cpp b/gwenview/importer/documentdirfinder.cpp index f4d80e33..f09c11fe 100644 --- a/gwenview/importer/documentdirfinder.cpp +++ b/gwenview/importer/documentdirfinder.cpp @@ -69,7 +69,6 @@ void DocumentDirFinder::slotItemsAdded(const KUrl& dir, const KFileItemList& lis MimeTypeUtils::Kind kind = MimeTypeUtils::fileItemKind(item); switch (kind) { case MimeTypeUtils::KIND_DIR: - case MimeTypeUtils::KIND_ARCHIVE: if (d->mFoundDirUrl.isValid()) { // This is the second dir we find, stop now finish(dir, MultipleDirsFound); diff --git a/gwenview/importer/thumbnailpage.cpp b/gwenview/importer/thumbnailpage.cpp index aa3a27c3..1a4c33d6 100644 --- a/gwenview/importer/thumbnailpage.cpp +++ b/gwenview/importer/thumbnailpage.cpp @@ -36,7 +36,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA #include // Local -#include #include #include #include @@ -321,7 +320,7 @@ void ThumbnailPage::importList(const QModelIndexList& list) d->mUrlList.clear(); Q_FOREACH(const QModelIndex & index, list) { KFileItem item = itemForIndex(index); - if (!ArchiveUtils::fileItemIsDirOrArchive(item)) { + if (!item.isDir()) { d->mUrlList << item.url(); } // FIXME: Handle dirs (do we want to import recursively?) diff --git a/gwenview/lib/CMakeLists.txt b/gwenview/lib/CMakeLists.txt index 585df1e9..6b9239a4 100644 --- a/gwenview/lib/CMakeLists.txt +++ b/gwenview/lib/CMakeLists.txt @@ -45,7 +45,6 @@ set(gwenviewlib_SRCS binder.cpp eventwatcher.cpp historymodel.cpp - archiveutils.cpp datewidget.cpp exiv2imageloader.cpp flowlayout.cpp diff --git a/gwenview/lib/archiveutils.cpp b/gwenview/lib/archiveutils.cpp deleted file mode 100644 index 2de887a9..00000000 --- a/gwenview/lib/archiveutils.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// vim: set tabstop=4 shiftwidth=4 expandtab -/* -Gwenview - A simple image viewer for KDE -Copyright 2000-2007 Aurélien Gâteau - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ -// Self -#include "archiveutils.h" - -// KDE -#include -#include -#include -#include - -namespace Gwenview -{ - -namespace ArchiveUtils -{ - -bool fileItemIsArchive(const KFileItem& item) -{ - KMimeType::Ptr mimeType = item.determineMimeType(); - if (!mimeType) { - kWarning() << "determineMimeType() returned a null pointer"; - return false; - } - return !ArchiveUtils::protocolForMimeType(mimeType->name()).isEmpty(); -} - -bool fileItemIsDirOrArchive(const KFileItem& item) -{ - return item.isDir() || fileItemIsArchive(item); -} - -QString protocolForMimeType(const QString& mimeType) -{ - static QHash cache; - QHash::ConstIterator it = cache.constFind(mimeType); - if (it != cache.constEnd()) { - return it.value(); - } - - if (mimeType == "image/svg+xml-compressed") { - // We don't want .svgz to be considered as archives because QtSvg knows - // how to decode gzip-ed svg files - cache.insert(mimeType, QString()); - return QString(); - } - - QString protocol = KProtocolManager::protocolForArchiveMimetype(mimeType); - if (protocol.isEmpty()) { - // No protocol, try with mimeType parents. This is useful for .cbz for - // example - KMimeType::Ptr ptr = KMimeType::mimeType(mimeType); - if (ptr) { - Q_FOREACH(const QString & parentMimeType, ptr->allParentMimeTypes()) { - protocol = KProtocolManager::protocolForArchiveMimetype(parentMimeType); - if (!protocol.isEmpty()) { - break; - } - } - } - } - - cache.insert(mimeType, protocol); - return protocol; -} - -} // namespace ArchiveUtils - -} // namespace Gwenview diff --git a/gwenview/lib/archiveutils.h b/gwenview/lib/archiveutils.h deleted file mode 100644 index db797712..00000000 --- a/gwenview/lib/archiveutils.h +++ /dev/null @@ -1,61 +0,0 @@ -// vim: set tabstop=4 shiftwidth=4 expandtab -/* -Gwenview - A simple image viewer for KDE -Copyright 2000-2004 Aurélien Gâteau - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ -#ifndef ARCHIVEUTILS_H -#define ARCHIVEUTILS_H - -#include - -// Qt -#include - -class KFileItem; - -namespace Gwenview -{ - -/** - * Helper functions to deal with archives - */ -namespace ArchiveUtils -{ - -/** - * Returns true if @p item is an archive - */ -GWENVIEWLIB_EXPORT bool fileItemIsArchive(const KFileItem& item); - -/** - * Returns true if @p item is a dir or an archive - */ -GWENVIEWLIB_EXPORT bool fileItemIsDirOrArchive(const KFileItem& item); - -/** - * Returns the protocol for an archive mime type. Similar to - * KProtocolManager::protocolForArchiveMimetype(), except it tries parent - * mimetypes if it can't find anything (useful for .cbz and co) - */ -GWENVIEWLIB_EXPORT QString protocolForMimeType(const QString& mimeType); - -} // namespace ArchiveUtils - -} // namespace Gwenview -#endif - diff --git a/gwenview/lib/documentonlyproxymodel.cpp b/gwenview/lib/documentonlyproxymodel.cpp index 200675a5..2b602048 100644 --- a/gwenview/lib/documentonlyproxymodel.cpp +++ b/gwenview/lib/documentonlyproxymodel.cpp @@ -21,9 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA // Self #include "moc_documentonlyproxymodel.cpp" -// Local -#include - // KDE #include @@ -52,7 +49,7 @@ bool DocumentOnlyProxyModel::filterAcceptsRow(int row, const QModelIndex &parent { const QModelIndex index = sourceModel()->index(row, 0, parent); const KFileItem fileItem = index.data(KDirModel::FileItemRole).value(); - return !ArchiveUtils::fileItemIsDirOrArchive(fileItem); + return !fileItem.isDir(); } diff --git a/gwenview/lib/documentonlyproxymodel.h b/gwenview/lib/documentonlyproxymodel.h index c7e513ec..08d810a9 100644 --- a/gwenview/lib/documentonlyproxymodel.h +++ b/gwenview/lib/documentonlyproxymodel.h @@ -34,7 +34,7 @@ namespace Gwenview struct DocumentOnlyProxyModelPrivate; /** - * A proxy model which lists items which are neither dirs nor archives. + * A proxy model which lists items which are not dirs. * Only works with models which expose a KDirModel::FileItemRole. */ class GWENVIEWLIB_EXPORT DocumentOnlyProxyModel : public QSortFilterProxyModel diff --git a/gwenview/lib/mimetypeutils.cpp b/gwenview/lib/mimetypeutils.cpp index 7ef8f32e..3d1fdae0 100644 --- a/gwenview/lib/mimetypeutils.cpp +++ b/gwenview/lib/mimetypeutils.cpp @@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include // Local -#include #include namespace Gwenview @@ -161,9 +160,6 @@ Kind mimeTypeKind(const QString& mimeType) if (mimeType.startsWith(QLatin1String("inode/directory"))) { return KIND_DIR; } - if (!ArchiveUtils::protocolForMimeType(mimeType).isEmpty()) { - return KIND_ARCHIVE; - } return KIND_FILE; } diff --git a/gwenview/lib/mimetypeutils.h b/gwenview/lib/mimetypeutils.h index 439e29d1..5ad85403 100644 --- a/gwenview/lib/mimetypeutils.h +++ b/gwenview/lib/mimetypeutils.h @@ -49,10 +49,9 @@ GWENVIEWLIB_EXPORT QString urlMimeTypeByContent(const KUrl&); enum Kind { KIND_UNKNOWN = 0, KIND_DIR = 1, - KIND_ARCHIVE = 1 << 2, - KIND_FILE = 1 << 3, - KIND_RASTER_IMAGE = 1 << 4, - KIND_SVG_IMAGE = 1 << 5 + KIND_FILE = 1 << 2, + KIND_RASTER_IMAGE = 1 << 3, + KIND_SVG_IMAGE = 1 << 4 }; Q_DECLARE_FLAGS(Kinds, Kind) diff --git a/gwenview/lib/sorteddirmodel.cpp b/gwenview/lib/sorteddirmodel.cpp index 7e0fc367..b422f2e6 100644 --- a/gwenview/lib/sorteddirmodel.cpp +++ b/gwenview/lib/sorteddirmodel.cpp @@ -29,7 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include // Local -#include #include #include @@ -182,7 +181,7 @@ bool SortedDirModel::filterAcceptsRow(int row, const QModelIndex& parent) const return false; } - if (kind != MimeTypeUtils::KIND_DIR && kind != MimeTypeUtils::KIND_ARCHIVE) { + if (kind != MimeTypeUtils::KIND_DIR) { int dotPos = fileItem.name().lastIndexOf('.'); if (dotPos >= 1) { QString extension = fileItem.name().mid(dotPos + 1).toLower(); @@ -221,11 +220,11 @@ bool SortedDirModel::lessThan(const QModelIndex& left, const QModelIndex& right) const KFileItem leftItem = itemForSourceIndex(left); const KFileItem rightItem = itemForSourceIndex(right); - const bool leftIsDirOrArchive = ArchiveUtils::fileItemIsDirOrArchive(leftItem); - const bool rightIsDirOrArchive = ArchiveUtils::fileItemIsDirOrArchive(rightItem); + const bool leftIsDir = leftItem.isDir(); + const bool rightIsDir = rightItem.isDir(); - if (leftIsDirOrArchive != rightIsDirOrArchive) { - return leftIsDirOrArchive; + if (leftIsDir != rightIsDir) { + return leftIsDir; } if (sortRole() != KDirModel::ModifiedTime) { @@ -247,7 +246,7 @@ bool SortedDirModel::hasDocuments() const for (int row = 0; row < count; ++row) { const QModelIndex idx = index(row, 0); const KFileItem item = itemForIndex(idx); - if (!ArchiveUtils::fileItemIsDirOrArchive(item)) { + if (!item.isDir()) { return true; } } diff --git a/gwenview/lib/thumbnailview/previewitemdelegate.cpp b/gwenview/lib/thumbnailview/previewitemdelegate.cpp index 3cc6a7a8..1c0f9afe 100644 --- a/gwenview/lib/thumbnailview/previewitemdelegate.cpp +++ b/gwenview/lib/thumbnailview/previewitemdelegate.cpp @@ -43,7 +43,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA #include // Local -#include "archiveutils.h" #include "contextbarbutton.h" #include "itemeditor.h" #include "paintutils.h" @@ -349,9 +348,9 @@ struct PreviewItemDelegatePrivate // FIXME: Duplicated from drawText const KFileItem fileItem = fileItemForIndex(index); - const bool isDirOrArchive = ArchiveUtils::fileItemIsDirOrArchive(fileItem); + const bool isDir = fileItem.isDir(); if (mDetails & PreviewItemDelegate::DateDetail) { - if (!ArchiveUtils::fileItemIsDirOrArchive(fileItem)) { + if (!isDir) { const KDateTime dt = TimeUtils::dateTimeForFileItem(fileItem); const QString text = KGlobal::locale()->formatDateTime(dt); elided |= isTextElided(text); @@ -359,7 +358,7 @@ struct PreviewItemDelegatePrivate } } - if (!isDirOrArchive && (mDetails & PreviewItemDelegate::ImageSizeDetail)) { + if (!isDir && (mDetails & PreviewItemDelegate::ImageSizeDetail)) { QSize fullSize; QPixmap thumbnailPix = mView->thumbnailForIndex(index, &fullSize); if (fullSize.isValid()) { @@ -369,7 +368,7 @@ struct PreviewItemDelegatePrivate } } - if (!isDirOrArchive && (mDetails & PreviewItemDelegate::FileSizeDetail)) { + if (!isDir && (mDetails & PreviewItemDelegate::FileSizeDetail)) { const KIO::filesize_t size = fileItem.size(); if (size > 0) { const QString text = KIO::convertSize(size); @@ -485,7 +484,7 @@ struct PreviewItemDelegatePrivate void updateImageButtons() { const KFileItem item = fileItemForIndex(mIndexUnderCursor); - const bool isImage = !ArchiveUtils::fileItemIsDirOrArchive(item); + const bool isImage = !item.isDir(); mFullScreenButton->setEnabled(isImage); mRotateLeftButton->setEnabled(isImage); mRotateRightButton->setEnabled(isImage); @@ -618,7 +617,7 @@ void PreviewItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & QPixmap thumbnailPix = d->mView->thumbnailForIndex(index, &fullSize); const KFileItem fileItem = fileItemForIndex(index); const bool opaque = !thumbnailPix.hasAlphaChannel(); - const bool isDirOrArchive = ArchiveUtils::fileItemIsDirOrArchive(fileItem); + const bool isDir = fileItem.isDir(); QRect rect = option.rect; const bool selected = option.state & QStyle::State_Selected; const bool underMouse = option.state & QStyle::State_MouseOver; @@ -722,18 +721,18 @@ void PreviewItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & rect.top() + 2 * ITEM_MARGIN + thumbnailHeight, rect.width() - 2 * ITEM_MARGIN, d->mView->fontMetrics().height()); - if (isDirOrArchive || (d->mDetails & PreviewItemDelegate::FileNameDetail)) { + if (isDir || (d->mDetails & PreviewItemDelegate::FileNameDetail)) { d->drawText(painter, textRect, fgColor, index.data().toString()); textRect.moveTop(textRect.bottom()); } - if (!isDirOrArchive && (d->mDetails & PreviewItemDelegate::DateDetail)) { + if (!isDir && (d->mDetails & PreviewItemDelegate::DateDetail)) { const KDateTime dt = TimeUtils::dateTimeForFileItem(fileItem); d->drawText(painter, textRect, fgColor, KGlobal::locale()->formatDateTime(dt)); textRect.moveTop(textRect.bottom()); } - if (!isDirOrArchive && (d->mDetails & PreviewItemDelegate::ImageSizeDetail)) { + if (!isDir && (d->mDetails & PreviewItemDelegate::ImageSizeDetail)) { if (fullSize.isValid()) { const QString text = QString("%1x%2").arg(fullSize.width()).arg(fullSize.height()); d->drawText(painter, textRect, fgColor, text); @@ -741,7 +740,7 @@ void PreviewItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & } } - if (!isDirOrArchive && (d->mDetails & PreviewItemDelegate::FileSizeDetail)) { + if (!isDir && (d->mDetails & PreviewItemDelegate::FileSizeDetail)) { const KIO::filesize_t size = fileItem.size(); if (size > 0) { const QString st = KIO::convertSize(size); diff --git a/gwenview/lib/thumbnailview/thumbnailview.cpp b/gwenview/lib/thumbnailview/thumbnailview.cpp index b6575ebf..41be5d75 100644 --- a/gwenview/lib/thumbnailview/thumbnailview.cpp +++ b/gwenview/lib/thumbnailview/thumbnailview.cpp @@ -46,7 +46,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Local #include "abstractdocumentinfoprovider.h" #include "abstractthumbnailviewhelper.h" -#include "archiveutils.h" #include "dragpixmapgenerator.h" #include "mimetypeutils.h" #include "urlutils.h" diff --git a/gwenview/lib/urlutils.cpp b/gwenview/lib/urlutils.cpp index 29550186..6a920473 100644 --- a/gwenview/lib/urlutils.cpp +++ b/gwenview/lib/urlutils.cpp @@ -35,7 +35,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA #include // Local -#include #include namespace Gwenview @@ -98,19 +97,7 @@ KUrl fixUserEnteredUrl(const KUrl& in) QFileInfo info(in.toLocalFile()); QString path = info.absoluteFilePath(); - KUrl out = KUrl::fromPath(path); - QString mimeType = MimeTypeUtils::urlMimeType(out); - - const QString protocol = ArchiveUtils::protocolForMimeType(mimeType); - - if (!protocol.isEmpty()) { - KUrl tmp = out; - tmp.setProtocol(protocol); - if (KProtocolManager::supportsListing(tmp)) { - out = tmp; - } - } - return out; + return KUrl::fromPath(path); } } // namespace