Commit 0b1762e4 authored by David Barchiesi's avatar David Barchiesi
Browse files

Add "Open in browser" context menu action.

parent cac51be2
add_subdirectory(copyurlitemaction)
add_subdirectory(contextmenuaction)
add_subdirectory(propertiesplugin)
kcoreaddons_add_plugin(gdrivecopyurlitemaction
SOURCES copyurlitemaction.cpp
JSON copyurlitemaction.json
kcoreaddons_add_plugin(gdrivecontextmenuaction
SOURCES contextmenuaction.cpp
JSON contextmenuaction.json
INSTALL_NAMESPACE "kf5/kfileitemaction")
target_link_libraries(gdrivecopyurlitemaction
target_link_libraries(gdrivecontextmenuaction
KF5::I18n
KF5::KIOWidgets)
/*
* Copyright (C) 2019 David Barchiesi <david@barchie.si>
* Copyright (C) 2020 David Barchiesi <david@barchie.si>
*
* 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
......@@ -17,26 +17,26 @@
*
*/
#include "copyurlitemaction.h"
#include "contextmenuaction.h"
#include "../../gdrive_udsentry.h"
#include <QGuiApplication>
#include <QDesktopServices>
#include <QClipboard>
#include <QAction>
#include <QMenu>
#include <KFileItemListProperties>
#include <KLocalizedString>
#include <KPluginFactory>
#include <KFileItem>
K_PLUGIN_CLASS_WITH_JSON(ContextMenuAction, "contextmenuaction.json")
K_PLUGIN_CLASS_WITH_JSON(CopyUrlItemAction, "copyurlitemaction.json")
CopyUrlItemAction::CopyUrlItemAction(QObject* parent, const QVariantList&)
: KAbstractFileItemActionPlugin(parent)
ContextMenuAction::ContextMenuAction(QObject *parent, const QVariantList &)
: KAbstractFileItemActionPlugin(parent)
{}
QList<QAction*> CopyUrlItemAction::actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget)
QList<QAction*> ContextMenuAction::actions(const KFileItemListProperties &fileItemInfos, QWidget *parentWidget)
{
// Ignore if more than one file is selected
if (fileItemInfos.items().size() != 1) {
......@@ -57,23 +57,41 @@ QList<QAction*> CopyUrlItemAction::actions(const KFileItemListProperties& fileIt
return {};
}
QAction *copyUrlAction = createCopyUrlAction(parentWidget, gdriveLink);
return { copyUrlAction };
}
QMenu *gdriveMenu = new QMenu(parentWidget);
gdriveMenu->addAction(createOpenUrlAction(parentWidget, gdriveLink));
gdriveMenu->addAction(createCopyUrlAction(parentWidget, gdriveLink));
QAction *gdriveMenuAction = new QAction(i18n("Google Drive"), parentWidget);
gdriveMenuAction->setMenu(gdriveMenu);
gdriveMenuAction->setIcon(QIcon::fromTheme(QStringLiteral("folder-gdrive")));
return { gdriveMenuAction };
}
QAction *CopyUrlItemAction::createCopyUrlAction(QWidget *parent, const QString& gdriveLink)
QAction *ContextMenuAction::createCopyUrlAction(QWidget *parent, const QString &gdriveLink)
{
const QString name = i18n("Copy Google URL to clipboard");
const QIcon icon = QIcon::fromTheme(QStringLiteral("folder-gdrive"));
const QString name = i18n("Copy URL to clipboard");
const QIcon icon = QIcon::fromTheme(QStringLiteral("edit-copy"));
QAction *action = new QAction(icon, name, parent);
connect(action, &QAction::triggered, this, [gdriveLink]() {
QGuiApplication::clipboard()->setText(gdriveLink);
});
QGuiApplication::clipboard()->setText(gdriveLink);
});
return action;
}
QAction *ContextMenuAction::createOpenUrlAction(QWidget *parent, const QString &gdriveLink)
{
const QString name = i18n("Open in browser");
const QIcon icon = QIcon::fromTheme(QStringLiteral("internet-services"));
QAction *action = new QAction(icon, name, parent);
connect(action, &QAction::triggered, this, [gdriveLink]() {
QDesktopServices::openUrl(QUrl(gdriveLink));
});
return action;
}
#include "copyurlitemaction.moc"
#include "contextmenuaction.moc"
/*
* Copyright (C) 2019 David Barchiesi <david@barchie.si>
* Copyright (C) 2020 David Barchiesi <david@barchie.si>
*
* 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
......@@ -17,24 +17,25 @@
*
*/
#ifndef COPYURLITEMACTION_H
#define COPYURLITEMACTION_H
#ifndef CONTEXTMENUACTION_H
#define CONTEXTMENUACTION_H
#include <KFileItem>
#include <KAbstractFileItemActionPlugin>
class CopyUrlItemAction : public KAbstractFileItemActionPlugin
class ContextMenuAction : public KAbstractFileItemActionPlugin
{
Q_OBJECT
public:
CopyUrlItemAction(QObject* parent, const QVariantList& args);
QList<QAction*> actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) override;
private:
QAction *createCopyUrlAction(QWidget *parent, const QString& gdriveLink);
public:
ContextMenuAction(QObject *parent, const QVariantList &args);
QList<QAction*> actions(const KFileItemListProperties &fileItemInfos, QWidget *parentWidget) override;
private:
QAction *createCopyUrlAction(QWidget *parent, const QString &gdriveLink);
QAction *createOpenUrlAction(QWidget *parent, const QString &gdriveLink);
};
#endif
{
"KPlugin": {
"Icon": "folder-gdrive",
"MimeTypes": [
"application/octet-stream",
"inode/directory"
],
"Name": "'Google Drive' actions menu",
"ServiceTypes": [
"KFileItemAction/Plugin"
]
},
"MimeType": "application/octet-stream;inode/directory;"
}
{
"KPlugin": {
"Icon": "folder-gdrive",
"MimeTypes": [
"application/octet-stream",
"inode/directory"
],
"Name": "'Copy Google URL to clipboard' action",
"Name[ca@valencia]": "Acció «Copia l'URL de Google al porta-retalls»",
"Name[ca]": "Acció «Copia l'URL de Google al porta-retalls»",
"Name[cs]": "Činnost 'Kopírovat URL Google do schránky'",
"Name[da]": "Handlingen \"Kopiér Google-URL til udklipsholder\"",
"Name[de]": "Aktion „Google-URL in die Zwischenablage kopieren“",
"Name[en_GB]": "'Copy Google URL to clipboard' action",
"Name[es]": "Acción «Copiar URL de Google en el portapapeles»",
"Name[et]": "Toiming 'Kopeeri Google'i URL lõikepuhvrisse'",
"Name[eu]": "«Kopiatu Google URLa arbelera» ekintza",
"Name[fi]": "”Kopioi Googlen verkko-osoite leikepöydälle” -toiminto",
"Name[fr]": "Action « Copier l'URL Google dans le presse-papiers »",
"Name[it]": "Azione «Copia l'URL di Google negli appunti»",
"Name[ko]": "'Google URL을 클립보드에 복사' 동작",
"Name[lt]": "\"Kopijuoti Google URL į iškarpinę\" veiksmas",
"Name[nl]": "Actie 'Google-URL kopiëren naar klembord' action",
"Name[nn]": "«Kopier Google-adresse til utklippstavle»-handling",
"Name[pl]": "Działanie 'Skopiuj adres URL Google do schowka'",
"Name[pt]": "Copiar o URL do Google para a acção da área de transferência",
"Name[pt_BR]": "Ação 'Copiar URL do Google para a área de transferência'",
"Name[ru]": "Действие «Скопировать адрес на Google Диск в буфер обмена»",
"Name[sk]": "Akcia 'Kopírovať Google URL do schránky'",
"Name[sl]": "Dejanje 'Kopiraj Google URL v odložišče'",
"Name[sv]": "Åtgärden 'Kopiera Google webbadress till klippbordet'",
"Name[uk]": "Дія «Копіювати адресу Google до буфера обміну»",
"Name[x-test]": "xx'Copy Google URL to clipboard' actionxx",
"Name[zh_TW]": "「複製 Google 網址至剪貼簿」動作",
"ServiceTypes": [
"KFileItemAction/Plugin"
]
},
"MimeType": "application/octet-stream;inode/directory;"
}
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