diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 84da08d7b7fcda12c85caeb5a10b4903770a6f69 (patch) | |
tree | 2a6aea76f2dfffb4cc04bb907c4725af94f70e72 /konq-plugins/akregator | |
download | tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.tar.gz tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'konq-plugins/akregator')
-rw-r--r-- | konq-plugins/akregator/Makefile.am | 25 | ||||
-rw-r--r-- | konq-plugins/akregator/akregator_konqfeedicon.desktop | 116 | ||||
-rw-r--r-- | konq-plugins/akregator/akregator_konqfeedicon.rc | 3 | ||||
-rw-r--r-- | konq-plugins/akregator/akregator_konqplugin.desktop | 54 | ||||
-rw-r--r-- | konq-plugins/akregator/akregatorplugin.cpp | 135 | ||||
-rw-r--r-- | konq-plugins/akregator/akregatorplugin.h | 60 | ||||
-rw-r--r-- | konq-plugins/akregator/feeddetector.cpp | 147 | ||||
-rw-r--r-- | konq-plugins/akregator/feeddetector.h | 77 | ||||
-rw-r--r-- | konq-plugins/akregator/konqfeedicon.cpp | 222 | ||||
-rw-r--r-- | konq-plugins/akregator/konqfeedicon.h | 77 | ||||
-rw-r--r-- | konq-plugins/akregator/pluginbase.cpp | 102 | ||||
-rw-r--r-- | konq-plugins/akregator/pluginbase.h | 60 | ||||
-rw-r--r-- | konq-plugins/akregator/rss.png | bin | 0 -> 1158 bytes | |||
-rw-r--r-- | konq-plugins/akregator/rss.svgz | bin | 0 -> 2075 bytes |
14 files changed, 1078 insertions, 0 deletions
diff --git a/konq-plugins/akregator/Makefile.am b/konq-plugins/akregator/Makefile.am new file mode 100644 index 0000000..c6964d1 --- /dev/null +++ b/konq-plugins/akregator/Makefile.am @@ -0,0 +1,25 @@ +INCLUDES = $(all_includes) +METASOURCES = AUTO + + +# Install this plugin in the KDE modules directory +kde_module_LTLIBRARIES = libakregatorkonqplugin.la libakregatorkonqfeedicon.la + +libakregatorkonqplugin_la_SOURCES = akregatorplugin.cpp pluginbase.cpp +libakregatorkonqplugin_la_LIBADD = -lkonq $(LIB_KHTML) +libakregatorkonqplugin_la_LDFLAGS = -module $(KDE_PLUGIN) -avoid-version -no-undefined $(all_libraries) + +libakregatorkonqfeedicon_la_SOURCES = konqfeedicon.cpp feeddetector.cpp pluginbase.cpp +libakregatorkonqfeedicon_la_LIBADD = -lkonq $(LIB_KHTML) +libakregatorkonqfeedicon_la_LDFLAGS = -module $(KDE_PLUGIN) -avoid-version -no-undefined $(all_libraries) + +konqplugindir = $(kde_servicesdir) +konqplugin_DATA = akregator_konqplugin.desktop +konqfeedicondir = $(kde_datadir)/khtml/kpartplugins +konqfeedicon_DATA = akregator_konqfeedicon.desktop akregator_konqfeedicon.rc + +rssicondir = $(kde_datadir)/akregator/pics +rssicon_DATA = rss.png + +messages: rc.cpp + $(XGETTEXT) *.cpp *.h -o $(podir)/akregator_konqplugin.pot diff --git a/konq-plugins/akregator/akregator_konqfeedicon.desktop b/konq-plugins/akregator/akregator_konqfeedicon.desktop new file mode 100644 index 0000000..9f304f7 --- /dev/null +++ b/konq-plugins/akregator/akregator_konqfeedicon.desktop @@ -0,0 +1,116 @@ +[Desktop Entry] +Name=Konq Feed Icon Plugin +Name[bg]=Икона на новини +Name[ca]=Icona de l'extensió d'enllaços del Konq +Name[cs]=Modul pro zdroje +Name[da]=Konq Kilde-ikon plugin +Name[de]=RSS-Quellen-Symbol in Konqueror +Name[el]=Πρόσθετο εικονιδίου ροής του Konq +Name[eo]=Enhavpiktograma kromaĵo por Konkeranto +Name[es]=Icono del complemento de fuentes para Konq +Name[et]=Konquerori RSS-kanali ikooni plugin +Name[eu]=Konq Feed ikono plugina +Name[fa]=وصلۀ شمایل خوراندن Konq +Name[fi]=Konq syöte kuvakesovelma +Name[fr]=Module d'icône de flux pour Konqueror +Name[fy]=Konq Feed-piktogram-plugin +Name[ga]=Breiseán Deilbhín Fotha Konq +Name[gl]=Plugin de Ícone RSS de Konqueror +Name[hi]=कॉन्क. फ़ीड प्रतीक प्लगइन +Name[hr]=Konq dodatak ikone tekućih novosti +Name[hu]=Konqueror csatornaikon-modul +Name[is]=Konq íforrit fyrir flæðismámyndir +Name[it]=Plugin di visualizzazione icone per fonti +Name[ja]=Konq フィードアイコン プラグイン +Name[ka]=Konq არხის ხატულის მოდული +Name[kk]=Konq ақпар таңбашасының плагин модулі +Name[km]=កម្មវិធីជំនួយរូបតំណាងមតិព័ត៌មានរបស់ Konq +Name[lt]=Konq kanalų ženkliuko priedas +Name[mk]=Приклучок за икона за довод за Konqueror +Name[ms]=Plugin Ikon Suapan Konq +Name[nb]=Programtillegg for Konq-ikon for nyhetskilde +Name[nds]=Konqueror-Moduul för't RSS-Stroomlüttbild +Name[ne]=कङ्क फिड प्रतिमा प्लगइन +Name[nl]=Konq Feed-pictogram-plugin +Name[nn]=Programtillegg for kjeldeikon i Konqueror +Name[pa]=Konq ਫੀਡ ਆਈਕਾਨ ਪਲੱਗਇਨ +Name[pl]=Wtyczka Konq z ikoną RSS +Name[pt]='Plugin' de Ícone de Fonte do Konqueror +Name[pt_BR]=Plug-in do Ícone de Fontes do Konq +Name[ru]=Модуль лент новостей Konq +Name[sk]=Modul ikony kŕmitka pre Konq +Name[sl]=Vstavek za Konqueror z ikono vira +Name[sr]=Прикључак Konqueror-а за икону довода +Name[sr@Latn]=Priključak Konqueror-a za ikonu dovoda +Name[sv]=Konqueror-insticksprogram med kanalikon +Name[ta]=Konq பீட் சின்னச் சொருகுப்பொருள் +Name[tr]=Konq Besleme Simge Eklentisi +Name[uk]=Втулок піктограми подачі для Konqueoror +Name[uz]=Konqueror yangiliklar tasmasi nishonchasi plagini +Name[uz@cyrillic]=Konqueror янгиликлар тасмаси нишончаси плагини +Name[vi]=Bổ sung biểu tượng nguồn tin Konq +Name[zh_CN]=Konq 种子图标插件 +Name[zh_TW]=Konq Feed 圖示外掛程式 +Icon=akregator +Comment=Displays feed icon in statusbar when the page has RSS feed +Comment[bg]=Показване на иконата на новите, ако сайта има новини във формат RSS +Comment[ca]=Mostra la icona d'enllaços a la barra d'estat quan la pàgina té enllaç RSS +Comment[cs]=Zobrazí na panelu ikonku, pokud má stránka RSS +Comment[da]=Viser kildeikon i statusfelt når siden har RSS-kilde +Comment[de]=Zeigt das Quellen-Symbol in der Statusleiste, wenn die Seite eine RSS-Quelle hat +Comment[el]=Εμφανίζει το εικονίδιο ροής στη γραμμή κατάστασης όταν η σελίδα έχει ροή RSS +Comment[eo]=Montras enhavan piktogramon en statolistelo kiam la paĝo havas RSS enhavon +Comment[es]=Muestra el icono de las fuentes en la barra de estado cuando la página tiene fuentes RSS +Comment[et]=Näitab olekuribal kanaliikooni, kui saidil on RSS-kanal +Comment[eu]=Orriak RSS iturbururik badu, egoera-barran ikonoa bistaratzen du +Comment[fa]=هنگامی که صفحه خوراندن RSS را دارد، شمایل خوراندن را در میله وضعیت نمایش میدهد +Comment[fi]=Näyttää syötekuvakkeen tilapalkissa jos sivulla on RSS-syöte +Comment[fr]=Affiche une icône de flux RSS dans la barre d'état lorsque la page en possède +Comment[fy]=Toant in feed-piktogram yn de statusbalke as der in RSS-feed op de side stiet +Comment[ga]=Taispeáin deilbhín fotha sa bharra stádais nuair atá fotha RSS ar an leathanach +Comment[gl]=Mostra o ícone de fonte na barra de estado cando a páxina ten unha fonte RSS +Comment[hr]=Prikazivanje ikone tekućih novosti u traci stanja ako web-stranica ima RSS novosti +Comment[hu]=Csatornaikont jelenít meg az állapotsorban, ha az oldalhoz RSS-csatorna tartozik +Comment[is]=Sýna straumtáknmynd í stöðuslá þegar síða inniheldur RSS straum +Comment[it]=Mostra l'icona nella barra di stato quando la pagina ha una fonte RSS +Comment[ja]=RSS フィードを提供しているページでステータスバーにフィードアイコンを表示します +Comment[ka]=სტატუსის ზოლზე აჩვენებს არხის ხატულას როდესაც გვერდს RSS არხი აქვს +Comment[kk]=Бетте RSS ақпары бар болса күй-жай жолағында оның таңбашасын көрсету +Comment[km]=បង្ហាញរូបតំណាងមតិព័ត៌មាននៅក្នុងរបារស្ថានភាព នៅពេលទំព័រមានមតិព័ត៌មាន RSS +Comment[lt]=Rodo kanalo ikoną būsenos juostoje kai puslapis turi RSS kanalą +Comment[mk]=Прикажува икона на доток во статусната линија кога страницата има RSS-доток +Comment[ms]=Memaparkan ikon suapan dalam bar status apabila halaman mempunyai suapan RSS +Comment[nb]=Viser ikon for nyhetskilde på statuslinja når nettstedet har en RSS-kilde +Comment[nds]=Wiest dat RSS-Lüttbild op den Statusbalken, wenn de Siet en RSS-Narichtenstroom bargt. +Comment[ne]=पृष्ठमा आरएसएस फिड हुदाँ स्थितिपट्टीमा फिड प्रतिमा प्रदर्शन गर्दछ +Comment[nl]=Toont een feed-pictogram in de statusbalk als de pagina een RSS-feed bevat +Comment[nn]=Viser eit kjeldeikon på statuslinja når sida har ei RSS-kjelde +Comment[pl]=Wyświetla ikonę RSS w pasku stanu, jeśli strona zawiera źródło wiadomości RSS +Comment[pt]=Mostra o ícone de fonte na barra de estado quando a página tem uma fonte RSS +Comment[pt_BR]=Mostra um ícone na barra de status quando a página possui uma fonte de notícias RSS +Comment[ru]=Показать в строке состояния значок ленты, если у страницы есть лента новостей +Comment[sk]=Zobrazí ikonu kŕmitka v stavovom riadku keď strana obsahuje RSS kŕmitko +Comment[sl]=Prikaže ikono vira v vrstici stanja, če ima stran vir RSS ali Atom +Comment[sr]=Приказује икону довода у статусној траци када страна има RSS довод +Comment[sr@Latn]=Prikazuje ikonu dovoda u statusnoj traci kada strana ima RSS dovod +Comment[sv]=Visar kanalikon i statusraden när sidan har en RSS-kanal +Comment[ta]=RSS ஃபீட் இருக்கும்போது நிலைப்பட்டியலில் ஃபீட் சின்னத்தை காட்டுகிறது +Comment[tr]=Eğer sayfa RSS kaynaklı ise kaynak simgesini durum çubuğunda göster +Comment[uk]=Показує піктограму подачі в рядку стану, коли сторінка має подачу RSS +Comment[uz]=Sahifada RSS tasmasi mavjud boʻlsa, holat panelida RSS nishonchasini koʻrsatish +Comment[uz@cyrillic]=Саҳифада RSS тасмаси мавжуд бўлса, ҳолат панелида RSS нишончасини кўрсатиш +Comment[vi]=Hiển thị biểu tương nguồn tin trên thanh trạng thái khi trang Mạng có nguồn tin RSS +Comment[zh_CN]=当页面有 RSS 种子的时候在状态栏显示种子图标 +Comment[zh_TW]=當網頁有 RSS feed 時,於狀態列顯示 feed 圖示 +Type=Service +X-KDE-Library=libakregatorkonqfeedicon +X-KDE-PluginInfo-Author=Teemu Rytilahti +X-KDE-PluginInfo-Name=konqfeedicon +X-KDE-PluginInfo-Version=1.0.0 +X-KDE-PluginInfo-Website=http://akregator.sourceforge.net +X-KDE-PluginInfo-Category=Statusbar +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-ParentApp=konqueror diff --git a/konq-plugins/akregator/akregator_konqfeedicon.rc b/konq-plugins/akregator/akregator_konqfeedicon.rc new file mode 100644 index 0000000..63f97fe --- /dev/null +++ b/konq-plugins/akregator/akregator_konqfeedicon.rc @@ -0,0 +1,3 @@ +<!DOCTYPE kpartgui> +<kpartplugin name="konqfeedicon" library="libakregatorkonqfeedicon" version="1"> +</kpartplugin> diff --git a/konq-plugins/akregator/akregator_konqplugin.desktop b/konq-plugins/akregator/akregator_konqplugin.desktop new file mode 100644 index 0000000..d033ce5 --- /dev/null +++ b/konq-plugins/akregator/akregator_konqplugin.desktop @@ -0,0 +1,54 @@ +[Desktop Entry] +Type=Service +Name=Add Feed to Akregator +Name[bg]=Добавяне на източник към Akregator +Name[ca]=Afegeix un enllaç a aKregator +Name[cs]=Přidat zprávy do aKregatoru +Name[da]=Tilføj kilde til Akregator +Name[de]=Nachrichtenquelle zu Akregator hinzufügen +Name[el]=Προσθήκη ροής στον aKregator +Name[eo]=Aldonu enhavon al Akregatoro +Name[es]=Añadir fuente a aKregator +Name[et]=Lisa kanal Akregatorile +Name[eu]=Akregator-era sarrera bat gehitzen du +Name[fa]=افزودن خوراندن به Akregator +Name[fi]=Lisää syöte aKregatoriin +Name[fr]=Ajouter ce flux à Akregator +Name[fy]=Feed oan Akregator taheakje +Name[ga]=Cuir Fotha le Akregator +Name[gl]=Engadir Fonte ao Akregator +Name[hr]=Dodaj tekuće novosti u Akregator +Name[hu]=Csatorna hozzáadása az Akregatorhoz +Name[is]=Bæta straum við Akregator +Name[it]=Aggiunge fonti ad aKregator +Name[ja]=AKregator にフィードを追加 +Name[ka]=არხის Akregator-ისთვის დამატება +Name[kk]=Ақпарды Akregator-ға қосу +Name[km]=បន្ថែមមតិព័ត៌មានទៅ Akregator +Name[lt]=Įdėti kanalą į Akregator +Name[mk]=Додај доток кон Акрегатор +Name[ms]=Tambah Suapan kepada Akregator +Name[nb]=Legg til kilde til aKregator +Name[nds]=Nachrichtenstroom na Akregator tofögen +Name[ne]=एक्रिगेटरमा फिड थप्नुहोस् +Name[nl]=Feed aan Akregator toevoegen +Name[nn]=Legg til kjelde i Akregator +Name[pl]=Dodaj źródło wiadomości do aKregatora +Name[pt]=Adicionar Fonte ao Akregator +Name[pt_BR]=Adicionar fonte de notícias ao aKregator +Name[ru]=Добавить ленту новостей в Akregator +Name[sk]=Pridať kŕmitko do Akregator +Name[sl]=Dodaj vir v Akregator +Name[sr]=Додај довод у Akregator +Name[sr@Latn]=Dodaj dovod u Akregator +Name[sv]=Lägg till en kanal till Akregator +Name[ta]=aKregatorக்கு உள்ளீட்டை சேர் +Name[tr]=Akregator'a Besleme Ekle +Name[uk]=Додати подачу в Akregator +Name[uz]=Akregator dasturiga yangiliklar tasmasini qoʻshish +Name[uz@cyrillic]=Akregator дастурига янгиликлар тасмасини қўшиш +Name[vi]=Thêm nguồn tin vào Akregator +Name[zh_CN]=在 Akregator 中添加种子 +Name[zh_TW]=將 Feed 加入 Akregator +X-KDE-Library=libakregatorkonqplugin +ServiceTypes=KonqPopupMenu/Plugin,all/all diff --git a/konq-plugins/akregator/akregatorplugin.cpp b/konq-plugins/akregator/akregatorplugin.cpp new file mode 100644 index 0000000..a2a82f2 --- /dev/null +++ b/konq-plugins/akregator/akregatorplugin.cpp @@ -0,0 +1,135 @@ +/* This file is part of the KDE project + + Copyright (C) 2004 Gary Cramblitt <[email protected]> + + Adapted from kdeutils/ark/konqplugin by + Georg Robbers <[email protected]> + + 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; version 2 + of the License. + + 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; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "akregatorplugin.h" +#include "pluginbase.h" + +#include <kapplication.h> +#include <kmimetype.h> +#include <kdebug.h> +#include <kaction.h> +#include <kinstance.h> +#include <klocale.h> +#include <konq_popupmenu.h> +#include <kpopupmenu.h> +#include <kgenericfactory.h> +#include <kurl.h> +#include <khtml_part.h> +#include <khtmlview.h> +#include <kmessagebox.h> + +#include <qdir.h> +#include <qcstring.h> +#include <qobject.h> +#include <qstringlist.h> + +using namespace Akregator; + +typedef KGenericFactory<AkregatorMenu, KonqPopupMenu> AkregatorMenuFactory; +K_EXPORT_COMPONENT_FACTORY( libakregatorkonqplugin, AkregatorMenuFactory("akregatorkonqplugin") ) + +AkregatorMenu::AkregatorMenu( KonqPopupMenu * popupmenu, const char *name, const QStringList& /* list */ ) + : KonqPopupMenuPlugin( popupmenu, name), PluginBase(), m_conf(0), m_part(0) +{ + kdDebug() << "AkregatorMenu::AkregatorMenu()" << endl; + if ( QCString( kapp->name() ) == "kdesktop" && !kapp->authorize("editable_desktop_icons" ) ) + return; + + // Do nothing if user has turned us off. + // TODO: Not yet implemented in aKregator settings. + /*m_conf = new KConfig( "akregatorrc" ); + m_conf->setGroup( "AkregatorKonqPlugin" ); + if ( !m_conf->readBoolEntry( "Enable", true ) ) + return; + */ + + KHTMLView* view = 0L; + + if (popupmenu && popupmenu->parent() && popupmenu->parent()->inherits("KHTMLView")) + view = static_cast<KHTMLView*>(popupmenu->parent()); + + if (view) + m_part = view->part(); + + KGlobal::locale()->insertCatalogue("akregator_konqplugin"); + m_feedMimeTypes << "text/rss" << "text/rdf" << "text/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(); + KFileItem* it = list.first(); + while (it != 0) + { + if (isFeedUrl(it)) + { + kdDebug() << "AkregatorMenu: found feed URL " << it->url().prettyURL() << endl; + KAction *action = new KAction( i18n( "Add Feed to Akregator" ), "akregator", 0, this, SLOT( slotAddFeed() ), actionCollection(), "akregatorkonqplugin_mnu" ); + addAction( action ); + addSeparator(); + m_feedURL = it->url().url(); + break; + } + + it = list.next(); + } +} + +AkregatorMenu::~AkregatorMenu() +{ + KGlobal::locale()->removeCatalogue("akregator_konqplugin"); + delete m_conf; +} + +bool AkregatorMenu::isFeedUrl(const QString &url) +{ + if (url.contains(".htm", false) != 0) return false; + if (url.contains("rss", false) != 0) return true; + if (url.contains("rdf", false) != 0) return true; + if (url.contains("xml", false) != 0) return true; + return false; +} + +bool AkregatorMenu::isFeedUrl(const KFileItem * item) +{ + 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 false; +} + +void AkregatorMenu::slotAddFeed() +{ + QString url = m_part ? fixRelativeURL(m_feedURL, m_part->baseURL()) : m_feedURL; + if(akregatorRunning()) + addFeedsViaDCOP(QStringList(url)); + else + addFeedViaCmdLine(url); +} + +#include "akregatorplugin.moc" diff --git a/konq-plugins/akregator/akregatorplugin.h b/konq-plugins/akregator/akregatorplugin.h new file mode 100644 index 0000000..8074f2f --- /dev/null +++ b/konq-plugins/akregator/akregatorplugin.h @@ -0,0 +1,60 @@ +/* This file is part of the KDE project + + Copyright (C) 2003 Georg Robbers <[email protected]> + + 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; version 2 + of the License. + + 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; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _AKREGATORPLUGIN_H_ +#define _AKREGATORPLUGIN_H_ + +#include <konq_popupmenu.h> +#include <kfileitem.h> +#include <kconfig.h> + +#include "pluginbase.h" + +class KAction; +class KHTMLPart; + +namespace Akregator +{ + +class AkregatorMenu : public KonqPopupMenuPlugin, PluginBase +{ + Q_OBJECT +public: + AkregatorMenu( KonqPopupMenu *, const char *name, const QStringList &list ); + virtual ~AkregatorMenu(); + +public slots: + void slotAddFeed(); + +protected: + bool isFeedUrl(const QString &s); + bool isFeedUrl(const KFileItem *item); + +private: + QStringList m_feedMimeTypes; + KConfig *m_conf; + KHTMLPart *m_part; + QString m_feedURL; +}; + +} + +#endif + diff --git a/konq-plugins/akregator/feeddetector.cpp b/konq-plugins/akregator/feeddetector.cpp new file mode 100644 index 0000000..928a282 --- /dev/null +++ b/konq-plugins/akregator/feeddetector.cpp @@ -0,0 +1,147 @@ +/* + This file is part of Akregator. + + Copyright (C) 2004 Teemu Rytilahti <[email protected]> + + 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. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <qregexp.h> +#include <qstring.h> +#include <qstringlist.h> +#include <qvaluelist.h> +#include <kcharsets.h> + +#include "feeddetector.h" + + +using namespace Akregator; + +FeedDetectorEntryList FeedDetector::extractFromLinkTags(const QString& s) +{ + //reduce all sequences of spaces, newlines etc. to one space: + QString str = s.simplifyWhiteSpace(); + + // extracts <link> tags + QRegExp reLinkTag("<[\\s]?LINK[^>]*REL[\\s]?=[\\s]?\\\"[\\s]?(ALTERNATE|SERVICE\\.FEED)[\\s]?\\\"[^>]*>", false); + + // extracts the URL (href="url") + QRegExp reHref("HREF[\\s]?=[\\s]?\\\"([^\\\"]*)\\\"", false); + // extracts type attribute + QRegExp reType("TYPE[\\s]?=[\\s]?\\\"([^\\\"]*)\\\"", false); + // extracts the title (title="title") + QRegExp reTitle("TITLE[\\s]?=[\\s]?\\\"([^\\\"]*)\\\"", false); + + int pos = 0; + int matchpos = 0; + + // get all <link> tags + QStringList linkTags; + //int strlength = str.length(); + while ( matchpos != -1 ) + { + matchpos = reLinkTag.search(str, pos); + if (matchpos != -1) + { + linkTags.append( str.mid(matchpos, reLinkTag.matchedLength()) ); + pos = matchpos + reLinkTag.matchedLength(); + } + } + + FeedDetectorEntryList list; + + for ( QStringList::Iterator it = linkTags.begin(); it != linkTags.end(); ++it ) + { + QString type; + int pos = reType.search(*it, 0); + if (pos != -1) + type = reType.cap(1).lower(); + + // we accept only type attributes indicating a feed + if ( type != "application/rss+xml" && type != "application/rdf+xml" + && type != "application/atom+xml" && type != "text/xml" ) + continue; + + QString title; + pos = reTitle.search(*it, 0); + if (pos != -1) + title = reTitle.cap(1); + + title = KCharsets::resolveEntities(title); + + QString url; + pos = reHref.search(*it, 0); + if (pos != -1) + url = reHref.cap(1); + + url = KCharsets::resolveEntities(url); + + // if feed has no title, use the url as preliminary title (until feed is parsed) + if ( title.isEmpty() ) + title = url; + + if ( !url.isEmpty() ) + list.append(FeedDetectorEntry(url, title) ); + } + + + return list; +} + +QStringList FeedDetector::extractBruteForce(const QString& s) +{ + QString str = s.simplifyWhiteSpace(); + + QRegExp reAhrefTag("<[\\s]?A[^>]?HREF=[\\s]?\\\"[^\\\"]*\\\"[^>]*>", false); + + // extracts the URL (href="url") + QRegExp reHref("HREF[\\s]?=[\\s]?\\\"([^\\\"]*)\\\"", false); + + QRegExp rssrdfxml(".*(RSS|RDF|XML)", false); + + int pos = 0; + int matchpos = 0; + + // get all <a href> tags and capture url + QStringList list; + //int strlength = str.length(); + while ( matchpos != -1 ) + { + matchpos = reAhrefTag.search(str, pos); + if ( matchpos != -1 ) + { + QString ahref = str.mid(matchpos, reAhrefTag.matchedLength()); + int hrefpos = reHref.search(ahref, 0); + if ( hrefpos != -1 ) + { + QString url = reHref.cap(1); + + url = KCharsets::resolveEntities(url); + + if ( rssrdfxml.exactMatch(url) ) + list.append(url); + } + + pos = matchpos + reAhrefTag.matchedLength(); + } + } + + return list; + +} diff --git a/konq-plugins/akregator/feeddetector.h b/konq-plugins/akregator/feeddetector.h new file mode 100644 index 0000000..b557e33 --- /dev/null +++ b/konq-plugins/akregator/feeddetector.h @@ -0,0 +1,77 @@ +/* + This file is part of Akregator. + + Copyright (C) 2004 Teemu Rytilahti <[email protected]> + + 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. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef AKREGATORFEEDDETECTOR_H +#define AKREGATORFEEDDETECTOR_H + +#include <qstring.h> +#include <qvaluelist.h> + +class QStringList; + +namespace Akregator +{ + + class FeedDetectorEntry + { + public: + FeedDetectorEntry() {} + FeedDetectorEntry(const QString& url, const QString& title) + : m_url(url), m_title(title) {} + + const QString& url() const { return m_url; } + const QString& title() const { return m_title; } + + private: + const QString m_url; + const QString m_title; + }; + + typedef QValueList<FeedDetectorEntry> FeedDetectorEntryList; + + /** a class providing functions to detect linked feeds in HTML sources */ + class FeedDetector + { + public: + /** \brief searches an HTML page for feeds listed in @c <link> tags + @c <link> tags with @c rel attribute values @c alternate or + @c service.feed are considered as feeds + @param s the html source to scan (the actual source, no URI) + @return a list containing the detected feeds + */ + static FeedDetectorEntryList extractFromLinkTags(const QString& s); + + /** \brief searches an HTML page for slightly feed-like looking links and catches everything not running away quickly enough. + Extracts links from @c <a @c href> tags which end with @c xml, @c rss or @c rdf + @param s the html source to scan (the actual source, no URI) + @return a list containing the detected feeds + */ + static QStringList extractBruteForce(const QString& s); + + private: + FeedDetector() {} + }; +} + +#endif //AKREGATORFEEDDETECTOR_H diff --git a/konq-plugins/akregator/konqfeedicon.cpp b/konq-plugins/akregator/konqfeedicon.cpp new file mode 100644 index 0000000..436a4be --- /dev/null +++ b/konq-plugins/akregator/konqfeedicon.cpp @@ -0,0 +1,222 @@ +/* + This file is part of Akregator. + + Copyright (C) 2004 Teemu Rytilahti <[email protected]> + + 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. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include "konqfeedicon.h" +#include "feeddetector.h" +#include "pluginbase.h" + +#include <dcopref.h> +#include <kapplication.h> +#include <kdebug.h> +#include <kgenericfactory.h> +#include <khtml_part.h> +#include <kiconloader.h> +#include <klibloader.h> +#include <kmessagebox.h> +#include <kparts/statusbarextension.h> +#include <kprocess.h> +#include <kstandarddirs.h> +#include <kstatusbar.h> +#include <kurllabel.h> +#include <kurl.h> + +#include <qcursor.h> +#include <qobjectlist.h> +#include <qpixmap.h> +#include <qstringlist.h> +#include <qstylesheet.h> +#include <qtimer.h> +#include <qtooltip.h> + +using namespace Akregator; + +typedef KGenericFactory<KonqFeedIcon> KonqFeedIconFactory; +K_EXPORT_COMPONENT_FACTORY(libakregatorkonqfeedicon, + KonqFeedIconFactory("akregatorkonqfeedicon")) + +KonqFeedIcon::KonqFeedIcon(QObject *parent, const char *name, const QStringList &) + : KParts::Plugin(parent, name), PluginBase(), m_part(0), m_feedIcon(0), m_statusBarEx(0), m_menu(0) +{ + KGlobal::locale()->insertCatalogue("akregator_konqplugin"); + + m_part = dynamic_cast<KHTMLPart*>(parent); + if(!m_part) { kdDebug() << "couldn't get part" << endl; return; } + // FIXME: need to do this because of a bug in khtmlpart, it's fixed now for 3.4 (and prolly backported for 3.3.3?) + //connect(m_part->view(), SIGNAL(finishedLayout()), this, SLOT(addFeedIcon())); + QTimer::singleShot(0, this, SLOT(waitPartToLoad())); +} + +void KonqFeedIcon::waitPartToLoad() +{ + connect(m_part, SIGNAL(completed()), this, SLOT(addFeedIcon())); + connect(m_part, SIGNAL(completed(bool)), this, SLOT(addFeedIcon())); // to make pages with metarefresh to work + connect(m_part, SIGNAL(started(KIO::Job *)), this, SLOT(removeFeedIcon())); + addFeedIcon(); +} + +KonqFeedIcon::~KonqFeedIcon() +{ + KGlobal::locale()->removeCatalogue("akregator_konqplugin"); + m_statusBarEx = KParts::StatusBarExtension::childObject(m_part); + if (m_statusBarEx) + { + m_statusBarEx->removeStatusBarItem(m_feedIcon); + // the feed icon is child of the statusbar extension, so if the statusbar is deleted, + // the icon was deleted by the status bar + delete m_feedIcon; + } + // the icon is deleted in every case + m_feedIcon = 0L; + + delete m_menu; + m_menu = 0L; +} + +bool KonqFeedIcon::feedFound() +{ + DOM::NodeList linkNodes = m_part->document().getElementsByTagName("link"); + + if (linkNodes.length() == 0) + return false; + + unsigned int i; + QString doc = ""; + + for (i = 0; i < linkNodes.length(); i++) + { + DOM::Node node = linkNodes.item(i); + doc += "<link "; + for (unsigned int j = 0; j < node.attributes().length(); j++) + { + doc += node.attributes().item(j).nodeName().string() + "=\""; + doc += QStyleSheet::escape(node.attributes().item(j).nodeValue().string()).replace("\"", """); + doc += "\" "; + } + doc += "/>"; + } + + m_feedList = FeedDetector::extractFromLinkTags(doc); + return m_feedList.count() != 0; +} + +void KonqFeedIcon::contextMenu() +{ + delete m_menu; + m_menu = new KPopupMenu(m_part->widget()); + if(m_feedList.count() == 1) { + m_menu->insertTitle(m_feedList.first().title()); + m_menu->insertItem(SmallIcon("bookmark_add"), i18n("Add Feed to Akregator"), this, SLOT(addFeeds()) ); + } + else { + m_menu->insertTitle(i18n("Add Feeds to Akregator")); + connect(m_menu, SIGNAL(activated(int)), this, SLOT(addFeed(int))); + int id = 0; + for(FeedDetectorEntryList::Iterator it = m_feedList.begin(); it != m_feedList.end(); ++it) { + m_menu->insertItem(SmallIcon("bookmark_add"), (*it).title(), id); + id++; + } + //disconnect(m_menu, SIGNAL(activated(int)), this, SLOT(addFeed(int))); + m_menu->insertSeparator(); + m_menu->insertItem(SmallIcon("bookmark_add"), i18n("Add All Found Feeds to Akregator"), this, SLOT(addFeeds()), 0, 50000 ); + } + m_menu->popup(QCursor::pos()); +} + +void KonqFeedIcon::addFeedIcon() +{ + if(!feedFound() || m_feedIcon) { + return; + } + + m_statusBarEx = KParts::StatusBarExtension::childObject(m_part); + if(!m_statusBarEx) return; + + m_feedIcon = new KURLLabel(m_statusBarEx->statusBar()); + + // from khtmlpart's ualabel + m_feedIcon->setFixedHeight(instance()->iconLoader()->currentSize(KIcon::Small)); + m_feedIcon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); + m_feedIcon->setUseCursor(false); + //FIXME hackish + m_feedIcon->setPixmap(QPixmap(locate("data", "akregator/pics/rss.png"))); + + QToolTip::remove(m_feedIcon); + QToolTip::add(m_feedIcon, i18n("Monitor this site for updates (using news feed)")); + + m_statusBarEx->addStatusBarItem(m_feedIcon, 0, true); + + connect(m_feedIcon, SIGNAL(leftClickedURL()), this, SLOT(contextMenu())); +} + +void KonqFeedIcon::removeFeedIcon() +{ + m_feedList.clear(); + if(m_feedIcon) + { + m_statusBarEx->removeStatusBarItem(m_feedIcon); + delete m_feedIcon; + m_feedIcon = 0L; + } + + // Close the popup if it's open, otherwise we crash + delete m_menu; + m_menu = 0L; +} + +void KonqFeedIcon::addFeed(int id) +{ + if(id == 50000) return; + if(akregatorRunning()) + addFeedsViaDCOP(QStringList(fixRelativeURL(m_feedList[id].url(), m_part->baseURL()))); + else + addFeedViaCmdLine(fixRelativeURL(m_feedList[id].url(), m_part->baseURL())); +} + +// from akregatorplugin.cpp +void KonqFeedIcon::addFeeds() +{ + if(akregatorRunning()) + { + QStringList list; + for ( FeedDetectorEntryList::Iterator it = m_feedList.begin(); it != m_feedList.end(); ++it ) + list.append(fixRelativeURL((*it).url(), m_part->baseURL())); + addFeedsViaDCOP(list); + } + else { + kdDebug() << "KonqFeedIcon::addFeeds(): use command line" << endl; + KProcess *proc = new KProcess; + *proc << "akregator" << "-g" << i18n("Imported Feeds"); + + for ( FeedDetectorEntryList::Iterator it = m_feedList.begin(); it != m_feedList.end(); ++it ) { + *proc << "-a" << fixRelativeURL((*it).url(), m_part->baseURL()); + } + + proc->start(KProcess::DontCare); + delete proc; + + } +} + +#include "konqfeedicon.moc" +// vim: ts=4 sw=4 et diff --git a/konq-plugins/akregator/konqfeedicon.h b/konq-plugins/akregator/konqfeedicon.h new file mode 100644 index 0000000..ba3bb8c --- /dev/null +++ b/konq-plugins/akregator/konqfeedicon.h @@ -0,0 +1,77 @@ +/* + This file is part of Akregator. + + Copyright (C) 2004 Teemu Rytilahti <[email protected]> + + 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. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef KONQFEEDICON_H +#define KONQFEEDICON_H + +#include <qguardedptr.h> +#include <kparts/plugin.h> +#include <kpopupmenu.h> +#include "feeddetector.h" +#include "pluginbase.h" + +/** +@author Teemu Rytilahti +*/ +class KURLLabel; +class KHTMLPart; +class QStringList; + +namespace KParts { + class StatusBarExtension; +} + +namespace Akregator { +class KonqFeedIcon : public KParts::Plugin, PluginBase +{ + Q_OBJECT +public: + KonqFeedIcon(QObject *parent, const char *name, const QStringList &); + + ~KonqFeedIcon(); + +private: + /** + * Tells you if there is feed(s) on the page. + * @return true when there is feed(s) available + */ + bool feedFound(); + + QGuardedPtr<KHTMLPart> m_part; + KURLLabel *m_feedIcon; + KParts::StatusBarExtension *m_statusBarEx; + FeedDetectorEntryList m_feedList; + QGuardedPtr<KPopupMenu> m_menu; + +private slots: + void waitPartToLoad(); + void contextMenu(); + void addFeedIcon(); + void removeFeedIcon(); + void addFeeds(); + void addFeed(int id); +}; + +} +#endif diff --git a/konq-plugins/akregator/pluginbase.cpp b/konq-plugins/akregator/pluginbase.cpp new file mode 100644 index 0000000..4c6b5b1 --- /dev/null +++ b/konq-plugins/akregator/pluginbase.cpp @@ -0,0 +1,102 @@ +/* + This file is part of Akregator. + + Copyright (C) 2004 Teemu Rytilahti <[email protected]> + + 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. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <kurl.h> +#include <kprocess.h> +#include <dcopref.h> +#include <khtml_part.h> +#include <klocale.h> + +#include "feeddetector.h" +#include "pluginbase.h" +#include <qstringlist.h> + +#include <kdebug.h> + +using namespace Akregator; + +PluginBase::PluginBase() +{} + +PluginBase::~PluginBase() +{} + +bool PluginBase::akregatorRunning() +{ + DCOPRef akr("akregator", "akregator"); + DCOPReply reply = akr.call("interfaces"); // FIXME hackish but works :) -tpr 20041203 + return reply.isValid(); +} + +void PluginBase::addFeedsViaDCOP(const QStringList& urls) +{ + kdDebug() << "PluginBase::addFeedsViaDCOP" << endl; + DCOPRef akr("akregator", "AkregatorIface"); + akr.send("addFeedsToGroup", urls, i18n("Imported Feeds") ); + /*if(!reply.isValid()) { + KMessageBox::error( 0, i18n( "Akregator feed icon - DCOP Call failed" ), + i18n( "The DCOP call addFeedToGroup failed" )); +}*/ +} + +void PluginBase::addFeedViaCmdLine(QString url) +{ + KProcess *proc = new KProcess; + *proc << "akregator" << "-g" << i18n("Imported Feeds"); + *proc << "-a" << url; + proc->start(KProcess::DontCare); + delete proc; +} + +// handle all the wild stuff that KURL doesn't handle +QString PluginBase::fixRelativeURL(const QString &s, const KURL &baseurl) +{ + QString s2=s; + KURL u; + if (KURL::isRelativeURL(s2)) + { + if (s2.startsWith("//")) + { + s2=s2.prepend(baseurl.protocol()+":"); + u=s2; + } + else if (s2.startsWith("/")) + { + KURL b2(baseurl); + b2.setPath(QString()); // delete path and query, so that only protocol://host remains + b2.setQuery(QString()); + u = KURL(b2, s2.remove(0,1)); // remove leading "/" + } + else + { + u = KURL(baseurl, s2); + } + } + else + u=s2; + + u.cleanPath(); + //kdDebug() << "AKREGATOR_PLUGIN_FIXURL: " << "url=" << s << " baseurl=" << baseurl.url() << " fixed=" << u.url() << endl; + return u.url(); +} diff --git a/konq-plugins/akregator/pluginbase.h b/konq-plugins/akregator/pluginbase.h new file mode 100644 index 0000000..8dcecf5 --- /dev/null +++ b/konq-plugins/akregator/pluginbase.h @@ -0,0 +1,60 @@ +/* + This file is part of Akregator. + + Copyright (C) 2004 Teemu Rytilahti <[email protected]> + + 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. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef PLUGINBASE_H +#define PLUGINBASE_H + +class FeedDetectorEntry; +class KHTMLPart; +class QString; +class QStringList; + +namespace Akregator +{ + +class PluginBase +{ + public: + PluginBase(); + ~PluginBase(); + + public: + /** + * Tells you if aKregator is running. + * @return true when aKregator is running + */ + bool akregatorRunning(); + /** + * Adds feed to aKregator via DCOP. + */ + void addFeedsViaDCOP(const QStringList& urls); + /** + * Adds feed to aKregator via command line. + */ + void addFeedViaCmdLine(QString url); + QString fixRelativeURL(const QString &s, const KURL &baseurl); +}; + +} +#endif diff --git a/konq-plugins/akregator/rss.png b/konq-plugins/akregator/rss.png Binary files differnew file mode 100644 index 0000000..3008a51 --- /dev/null +++ b/konq-plugins/akregator/rss.png diff --git a/konq-plugins/akregator/rss.svgz b/konq-plugins/akregator/rss.svgz Binary files differnew file mode 100644 index 0000000..498d5e3 --- /dev/null +++ b/konq-plugins/akregator/rss.svgz |