diff --git a/plugins/akregator/CMakeLists.txt b/plugins/akregator/CMakeLists.txt --- a/plugins/akregator/CMakeLists.txt +++ b/plugins/akregator/CMakeLists.txt @@ -1,35 +1,30 @@ + +ecm_qt_declare_logging_category(akregatorplugin_DEBUG_SRCS HEADER akregatorplugindebug.h IDENTIFIER AKREGATORPLUGIN_LOG CATEGORY_NAME org.kde.konqueror.akregatorplugin) + ########### next target ############### -add_definitions(-DTRANSLATION_DOMAIN=\"akregator_konqplugin\") -MESSAGE(STATUS "akregator popupmenu plugin disabled. Doable via servicemenu or should we re-introduce ServiceMenusPlugin?") -#set(akregatorkonqplugin_PART_SRCS akregatorplugin.cpp pluginbase.cpp ) -# -#kde4_add_plugin(akregatorkonqplugin ${akregatorkonqplugin_PART_SRCS} ${akregatorplugin_DEBUG_SRCS}) -# -#target_link_libraries(akregatorkonqplugin ${KDE4_KDE3SUPPORT_LIBS} Qt5::Xml konq -# KF5::KHtml ) -# -#install(TARGETS akregatorkonqplugin DESTINATION ${KDE_INSTALL_PLUGINDIR} ) +set(akregatorplugin_PART_SRCS akregatorplugin.cpp pluginbase.cpp ) +kcoreaddons_add_plugin(akregatorplugin SOURCES ${akregatorplugin_PART_SRCS} ${akregatorplugin_DEBUG_SRCS} INSTALL_NAMESPACE "kf5/kfileitemaction") +kcoreaddons_desktop_to_json(akregatorplugin akregator_konqplugin.desktop) -ecm_qt_declare_logging_category(akregatorplugin_DEBUG_SRCS HEADER akregatorplugindebug.h IDENTIFIER AKREGATORPLUGIN_LOG CATEGORY_NAME org.kde.konqueror.akregatorplugin) +target_compile_definitions(akregatorplugin PRIVATE TRANSLATION_DOMAIN="akregator_konqplugin") +target_link_libraries(akregatorplugin KF5::I18n KF5::KIOWidgets) ########### next target ############### set(akregatorkonqfeedicon_PART_SRCS konqfeedicon.cpp feeddetector.cpp pluginbase.cpp ) add_library(akregatorkonqfeedicon MODULE ${akregatorkonqfeedicon_PART_SRCS} ${akregatorplugin_DEBUG_SRCS}) target_compile_definitions(akregatorkonqfeedicon PRIVATE TRANSLATION_DOMAIN="akregator_konqplugin") - target_link_libraries(akregatorkonqfeedicon KF5::Parts KF5::IconThemes) install(TARGETS akregatorkonqfeedicon DESTINATION ${KDE_INSTALL_PLUGINDIR} ) - ########### install files ############### -#install( FILES akregator_konqplugin.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) +install( FILES akregator_konqplugin.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) install( FILES akregator_konqfeedicon.desktop akregator_konqfeedicon.rc DESTINATION ${KDE_INSTALL_DATADIR}/khtml/kpartplugins ) install( FILES akregator_konqfeedicon.desktop akregator_konqfeedicon.rc DESTINATION ${KDE_INSTALL_DATADIR}/kwebkitpart/kpartplugins ) diff --git a/plugins/akregator/akregator_konqplugin.desktop b/plugins/akregator/akregator_konqplugin.desktop --- a/plugins/akregator/akregator_konqplugin.desktop +++ b/plugins/akregator/akregator_konqplugin.desktop @@ -1,6 +1,9 @@ [Desktop Entry] -Encoding=UTF-8 Type=Service +X-KDE-ServiceTypes=KFileItemAction/Plugin +X-KDE-Library=akregatorplugin +MimeType=application/octet-stream +Icon=akregator Name=Add Feed to Akregator Name[ar]=أضف التغذية إلى Akregator Name[be]=Дадаць стужку ў Akregator @@ -126,5 +129,3 @@ Comment[x-test]=xxAdds selected feed to Akregatorxx Comment[zh_CN]=向 Akregator 添加选中的 RSS 种子 Comment[zh_TW]=將所選取的 RSS feed 加到 Akregator -X-KDE-Library=akregatorkonqplugin -ServiceTypes=KonqPopupMenu/Plugin,all/all diff --git a/plugins/akregator/akregatorplugin.h b/plugins/akregator/akregatorplugin.h --- a/plugins/akregator/akregatorplugin.h +++ b/plugins/akregator/akregatorplugin.h @@ -19,39 +19,36 @@ #ifndef _AKREGATORPLUGIN_H_ #define _AKREGATORPLUGIN_H_ -#include -#include -#include +#include #include "pluginbase.h" -class KHTMLPart; +class KFileItem; +class KFileItemListProperties; namespace Akregator { -class AkregatorMenu : public KonqPopupMenuPlugin, PluginBase +class AkregatorMenu : public KAbstractFileItemActionPlugin, PluginBase { Q_OBJECT + public: - AkregatorMenu(KonqPopupMenu *, const QStringList &list); - virtual ~AkregatorMenu(); + AkregatorMenu(QObject *parent, const QVariantList &args); + virtual ~AkregatorMenu() = default; + + QList actions(const KFileItemListProperties &fileItemInfos, QWidget *parent) override; public slots: void slotAddFeed(); -protected: - bool isFeedUrl(const QString &s); - bool isFeedUrl(const KFileItem &item); +private: + bool isFeedUrl(const KFileItem &item) const; private: QStringList m_feedMimeTypes; -// KConfig *m_conf; - KHTMLPart *m_part; - QString m_feedURL; }; } #endif - diff --git a/plugins/akregator/akregatorplugin.cpp b/plugins/akregator/akregatorplugin.cpp --- a/plugins/akregator/akregatorplugin.cpp +++ b/plugins/akregator/akregatorplugin.cpp @@ -21,35 +21,26 @@ #include "akregatorplugin.h" #include "pluginbase.h" +#include "akregatorplugindebug.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include +#include +#include +#include +#include + +#include +#include using namespace Akregator; -typedef KGenericFactory AkregatorMenuFactory; -K_EXPORT_PLUGIN(AkregatorMenuFactory("akregatorkonqplugin")) +K_PLUGIN_FACTORY_WITH_JSON(AkregatorMenuFactory, "akregator_konqplugin.json", registerPlugin();) -AkregatorMenu::AkregatorMenu(KonqPopupMenu *popupmenu, const QStringList & /* list */) - : KonqPopupMenuPlugin(popupmenu), PluginBase(), /*m_conf(0),*/ m_part(0) +AkregatorMenu::AkregatorMenu(QObject *parent, const QVariantList &args) + : KAbstractFileItemActionPlugin(parent), + PluginBase() { - kDebug() << "AkregatorMenu::AkregatorMenu()"; + Q_UNUSED(args); + #if 0 if (QByteArray(kapp->name()) == "kdesktop" && !KAuthorized::authorizeKAction("editable_desktop_icons")) { return; @@ -64,82 +55,73 @@ if ( !m_conf->readEntry( "Enable", true ) ) return; */ - KHTMLView *view = 0L; - if (popupmenu && popupmenu->parent() && popupmenu->parent()->inherits("KHTMLView")) { - view = static_cast(popupmenu->parent()); - } + m_feedMimeTypes << "application/rss+xml" << "text/rdf" << "application/xml"; +} - if (view) { - m_part = view->part(); - } - //KF5 port: remove this line and define TRANSLATION_DOMAIN in CMakeLists.txt instead -//KLocale::global()->insertCatalog("akregator_konqplugin"); - m_feedMimeTypes << "application/rss+xml" << "text/rdf" << "application/xml"; - // Get the list of URLs clicked on from Konqi. - //KFileItemList m_list = popupmenu->fileItemList(); - // See if any are RSS feeds. - - KFileItemList list = popupmenu->fileItemList(); - foreach (const KFileItem &it, list) { - if (isFeedUrl(it)) { - kDebug() << "AkregatorMenu: found feed URL " << it.url().prettyUrl(); - QAction *action = actionCollection()->addAction("akregatorkonqplugin_mnu"); - action->setText(i18n("Add Feed to Akregator")); - action->setIcon(KIcon("akregator")); +QList AkregatorMenu::actions(const KFileItemListProperties &fileItemInfos, QWidget *parent) +{ + Q_UNUSED(parent); + + QList acts; + const KFileItemList items = fileItemInfos.items(); + foreach (const KFileItem &item, items) { + if (isFeedUrl(item)) { + qCDebug(AKREGATORPLUGIN_LOG) << "found feed" << item.url(); + + QAction *action = new QAction(this); + action->setText(i18nc("@action:inmenu", "Add Feed to Akregator")); + action->setIcon(QIcon::fromTheme("akregator")); + action->setData(item.url()); connect(action, SIGNAL(triggered()), this, SLOT(slotAddFeed())); - //addAction( action ); - addSeparator(); - m_feedURL = it.url().url(); - break; + acts.append(action); } } -} -AkregatorMenu::~AkregatorMenu() -{ - KLocale::global()->removeCatalog("akregator_konqplugin"); - //delete m_conf; + return acts; } -bool AkregatorMenu::isFeedUrl(const QString &url) + +static bool isFeedUrl(const QString &urlPath) { - if (url.contains(".htm", false) != 0) { + // If URL ends in .htm or .html, it is not a feed url. + if (urlPath.endsWith(".htm", Qt::CaseInsensitive) || urlPath.endsWith(".html", Qt::CaseInsensitive)) { return false; } - if (url.contains("rss", false) != 0) { + if (urlPath.contains("rss", Qt::CaseInsensitive)) { return true; } - if (url.contains("rdf", false) != 0) { - return true; - } - if (url.contains("xml", false) != 0) { + if (urlPath.contains("rdf", Qt::CaseInsensitive)) { return true; } return false; } -bool AkregatorMenu::isFeedUrl(const KFileItem &item) +bool AkregatorMenu::isFeedUrl(const KFileItem &item) const { if (m_feedMimeTypes.contains(item.mimetype())) { return true; } else { - QString url = item.url().url(); - // If URL ends in .htm or .html, it is not a feed url. - return isFeedUrl(url); + return ::isFeedUrl(item.url().path()); } return false; } void AkregatorMenu::slotAddFeed() { - QString url = m_part ? fixRelativeURL(m_feedURL, m_part->baseURL()) : m_feedURL; + QAction *action = qobject_cast(sender()); + Q_ASSERT(action!=nullptr); + + QString url = action->data().toUrl().url(); + qCDebug(AKREGATORPLUGIN_LOG) << "for feed url" << url; if (akregatorRunning()) { addFeedsViaDBUS(QStringList(url)); } else { addFeedViaCmdLine(url); } } + +#include "akregatorplugin.moc"