Commit a6ceabe9 authored by Méven Car's avatar Méven Car
Browse files

Replace slideshow ServiceMenu by SlideShowFileItemAction

Using a KAbstractFileItemActionPlugin allows to have more control over when actions are shown in context menus.

BUG: 429531
BUG: 430048
FIXED-IN: 21.04
parent 12d63937
......@@ -129,5 +129,15 @@ install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/org.kde.gwenview.desktop
DESTINATION ${KDE_INSTALL_APPDIR})
install(FILES org.kde.gwenview.appdata.xml
DESTINATION ${KDE_INSTALL_METAINFODIR})
install(FILES slideshow.desktop
DESTINATION ${KDE_INSTALL_KSERVICES5DIR}/ServiceMenus)
# slideshowfileitemaction plugin
kcoreaddons_add_plugin(slideshowfileitemaction
SOURCES slideshowfileitemaction.cpp
JSON slideshowfileitemaction.json
INSTALL_NAMESPACE "kf5/kfileitemaction")
target_link_libraries(slideshowfileitemaction
KF5::I18n
KF5::KIOWidgets
KF5::Notifications)
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KonqPopupMenu/Plugin,inode/directory
Actions=slideshow;
[Desktop Action slideshow]
Name=Start a Slideshow
Name[ar]=ابدأ عرض شرائح
Name[az]=Slayd şou başlatmaq
Name[bg]=Пускане на прожекция
Name[bs]=Pokreni slajdšou
Name[ca]=Inicia una presentació amb diapositives
Name[ca@valencia]=Inicia una presentació amb diapositives
Name[cs]=Spustit promítání
Name[da]=Start et diasshow
Name[de]=Diaschau starten
Name[el]=Έναρξη προβολής σλάιντ
Name[en_GB]=Start a Slideshow
Name[es]=Comenzar una presentación
Name[et]=Käivita slaidiseanss
Name[eu]=Hasi diapositiba-emanaldi bat
Name[fa]=شروع یک نمایش اسلاید
Name[fi]=Käynnistä diaesitys
Name[fr]=Démarrer un diaporama
Name[ga]=Rith Taispeántas Sleamhnán
Name[gl]=Iniciar unha presentación
Name[he]=התחל מצגת
Name[hne]=स्लाइड सो चालू करव
Name[hr]=Pokreni prezentaciju
Name[hu]=Diavetítés
Name[ia]=Starta un presentation (slideshow)
Name[id]=Memulai sebuah Slideshow
Name[is]=Hefja skyggnusýningu
Name[it]=Avvia una presentazione
Name[ja]=スライドショーを開始
Name[kk]=Слайд көрсетілімін бастау
Name[km]=ចាប់ផ្ដើម​បញ្ចាំង​ស្លាយ
Name[ko]=슬라이드 쇼 시작
Name[ku]=NîşandanaSlayt Bide Destpêkirin
Name[lt]=Pradėti skaidrių rodymą
Name[lv]=Sākt slīdrādi
Name[ml]=സ്ലൈഡ്ഷോ തുടങ്ങുക
Name[mr]=स्लाइडशो सुरु करा
Name[nb]=Start lysbildeframvisning
Name[nds]=En Diaschau starten
Name[nl]=Een diavoorstelling starten
Name[nn]=Start ei lysbiletframvising
Name[pa]=ਇੱਕ ਸਲਾਈਡ-ਸ਼ੋ ਸ਼ੁਰੂ
Name[pl]=Uruchom pokaz slajdów
Name[pt]=Iniciar uma Apresentação
Name[pt_BR]=Iniciar uma apresentação de slides
Name[ro]=Pornește o prezentare
Name[ru]=Запустить слайд-шоу
Name[si]=සලයිඩ දර්ශනය ආරඹන්න
Name[sk]=Spustiť prezentáciu
Name[sl]=Začni predstavitev
Name[sr]=Покрени слајдшоу
Name[sr@ijekavian]=Покрени слајдшоу
Name[sr@ijekavianlatin]=Pokreni slajdšou
Name[sr@latin]=Pokreni slajdšou
Name[sv]=Starta ett bildspel
Name[th]=เริ่มการนำเสนอ
Name[tr]=Bir Slayt Gösterisi Başlat
Name[ug]=تام تەسۋىرى باشلايدۇ
Name[uk]=Почати показ слайдів
Name[x-test]=xxStart a Slideshowxx
Name[zh_CN]=开启幻灯片模式放映照片
Name[zh_TW]=開始投影秀
Icon=gwenview
Exec=gwenview -s %u
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2020 Méven Car <meven.car@kdemail.net>
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 "slideshowfileitemaction.h"
#include <QMenu>
#include <QMimeDatabase>
#include <KPluginFactory>
#include <KLocalizedString>
#include <KFileItem>
#include <KIO/CommandLauncherJob>
#include <KNotificationJobUiDelegate>
#include <QDir>
K_PLUGIN_CLASS_WITH_JSON(SlideShowFileItemAction, "slideshowfileitemaction.json")
SlideShowFileItemAction::SlideShowFileItemAction(QObject* parent, const QVariantList&)
: KAbstractFileItemActionPlugin(parent)
{}
QList<QAction*> SlideShowFileItemAction::actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget)
{
QStringList itemsForSlideShow;
QString text;
const KFileItemList &fileItems = fileItemInfos.items();
if (fileItemInfos.isDirectory() ) {
if (fileItemInfos.isLocal()) {
QMimeDatabase db;
// filter selected dirs containing at least one image
for (const KFileItem &dirItem : fileItems) {
QDir dir = QDir(dirItem.localPath());
const QStringList fileList = dir.entryList(QDir::Filter::Files);
const bool containsAtLeastAnImage = std::any_of(fileList.cbegin(), fileList.cend(), [&db, &dir](const QString& fileName){
const auto mimeType = db.mimeTypeForFile(dir.absoluteFilePath(fileName), QMimeDatabase::MatchExtension);
return mimeType.name().startsWith(QStringLiteral("image"));
});
if (containsAtLeastAnImage) {
itemsForSlideShow << dirItem.localPath();
}
}
}
text = i18nc("@action:inmenu Start a slideshow Dolphin context menu", "Start a Slideshow");
} else if (fileItemInfos.mimeGroup() == QLatin1String("image") &&
fileItems.length() > 1){
for (const KFileItem &fileItem : fileItems) {
itemsForSlideShow << fileItem.url().toString();
}
text = i18nc("@action:inmenu Start a slideshow Dolphin context menu", "Start a Slideshow with selected images");
}
if (itemsForSlideShow.isEmpty()) {
return {};
}
QAction *startSlideShowAction = new QAction(text, parentWidget);
startSlideShowAction->setIcon(QIcon::fromTheme(QStringLiteral("gwenview")));
connect(startSlideShowAction, &QAction::triggered, this, [=]() {
// gwenview -s %u
auto job = new KIO::CommandLauncherJob(QStringLiteral("gwenview"), QStringList("s-") << itemsForSlideShow);
job->setDesktopName("org.kde.gwenview");
job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled));
job->start();
});
return {startSlideShowAction};
}
#include "slideshowfileitemaction.moc"
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2020 Méven Car <meven.car@kdemail.net>
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 SLIDESHOWFILEITEMACTION_H
#define SLIDESHOWFILEITEMACTION_H
#include <KAbstractFileItemActionPlugin>
#include <KFileItemListProperties>
class QAction;
class QWidget;
class KFileItemListProperties;
class SlideShowFileItemAction : public KAbstractFileItemActionPlugin
{
Q_OBJECT
public:
SlideShowFileItemAction(QObject* parent, const QVariantList& args);
QList<QAction*> actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) override;
private:
QAction *createAction(const QIcon& icon, const QString& name, QWidget *parent, const QList<QUrl>& urls, const QString& exec);
};
#endif // SLIDESHOWFILEITEMACTION_H
{
"KPlugin": {
"Icon": "gwenview",
"MimeTypes": [
"application/octet-stream",
"inode/directory"
],
"Name": "Start a Slideshow",
"ServiceTypes": [
"KFileItemAction/Plugin"
]
},
"X-KDE-Require": "Read",
"X-KDE-Show-In-Submenu": true
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment