diff --git a/app/extractfileitemaction.cpp b/app/extractfileitemaction.cpp index c770d1a9..7d3b3ed8 100644 --- a/app/extractfileitemaction.cpp +++ b/app/extractfileitemaction.cpp @@ -1,111 +1,111 @@ /* * ark -- archiver for the KDE project * * Copyright (C) 2016 Elvis Angelaccio * * 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. * */ #include "extractfileitemaction.h" #include #include #include #include #include #include "mimetypes.h" #include "pluginmanager.h" K_PLUGIN_FACTORY_WITH_JSON(ExtractFileItemActionFactory, "extractfileitemaction.json", registerPlugin();) using namespace Kerfuffle; ExtractFileItemAction::ExtractFileItemAction(QObject* parent, const QVariantList&) : KAbstractFileItemActionPlugin(parent) , m_pluginManager(new PluginManager(this)) {} QList ExtractFileItemAction::actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) { QList actions; const QIcon icon = QIcon::fromTheme(QStringLiteral("ark")); bool readOnlyParentDir = false; QList supportedUrls; // Filter URLs by supported mimetypes. foreach (const QUrl &url, fileItemInfos.urlList()) { - const QMimeType mimeType = determineMimeType(url.fileName()); + const QMimeType mimeType = determineMimeType(url.path()); if (m_pluginManager->preferredPluginsFor(mimeType).isEmpty()) { continue; } supportedUrls << url; // Check whether we can write in the parent directory of the file. const QString directory = url.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).toLocalFile(); if (!QFileInfo(directory).isWritable()) { readOnlyParentDir = true; } } if (supportedUrls.isEmpty()) { return {}; } QMenu *extractMenu = new QMenu(parentWidget); extractMenu->addAction(createAction(icon, i18nc("@action:inmenu Part of Extract submenu in Dolphin context menu", "Extract archive here"), parentWidget, supportedUrls, QStringLiteral("ark --batch --autodestination %F"))); extractMenu->addAction(createAction(icon, i18nc("@action:inmenu Part of Extract submenu in Dolphin context menu", "Extract archive to..."), parentWidget, supportedUrls, QStringLiteral("ark --batch --autodestination --dialog %F"))); extractMenu->addAction(createAction(icon, i18nc("@action:inmenu Part of Extract submenu in Dolphin context menu", "Extract archive here, autodetect subfolder"), parentWidget, supportedUrls, QStringLiteral("ark --batch --autodestination --autosubfolder %F"))); QAction *extractMenuAction = new QAction(i18nc("@action:inmenu Extract submenu in Dolphin context menu", "Extract"), parentWidget); extractMenuAction->setMenu(extractMenu); // #189177: disable extract menu in read-only folders. if (readOnlyParentDir) { extractMenuAction->setEnabled(false); } actions << extractMenuAction; return actions; } QAction *ExtractFileItemAction::createAction(const QIcon& icon, const QString& name, QWidget *parent, const QList& urls, const QString& exec) { QAction *action = new QAction(icon, name, parent); connect(action, &QAction::triggered, this, [exec, urls, parent]() { KRun::run(exec, urls, parent); }); return action; } #include "extractfileitemaction.moc" diff --git a/kerfuffle/mimetypes.h b/kerfuffle/mimetypes.h index 2a81aa4c..f53264b5 100644 --- a/kerfuffle/mimetypes.h +++ b/kerfuffle/mimetypes.h @@ -1,38 +1,42 @@ /* * Copyright (c) 2016 Ragnar Thomsen * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef MIMETYPES_H #define MIMETYPES_H #include "kerfuffle_export.h" #include namespace Kerfuffle { + /** + * @param filename Absolute path of a file. + * @return The mimetype of the given file. + */ KERFUFFLE_EXPORT QMimeType determineMimeType(const QString& filename); } #endif // MIMETYPES_H