Changeset View
Changeset View
Standalone View
Standalone View
plugins/akregator/konqfeedicon.cpp
Show All 19 Lines | 1 | /* | |||
---|---|---|---|---|---|
20 | As a special exception, permission is given to link this program | 20 | As a special exception, permission is given to link this program | ||
21 | with any edition of Qt, and distribute the resulting executable, | 21 | with any edition of Qt, and distribute the resulting executable, | ||
22 | without including the source code for Qt in the source distribution. | 22 | without including the source code for Qt in the source distribution. | ||
23 | */ | 23 | */ | ||
24 | 24 | | |||
25 | #include "konqfeedicon.h" | 25 | #include "konqfeedicon.h" | ||
26 | #include "feeddetector.h" | 26 | #include "feeddetector.h" | ||
27 | #include "pluginbase.h" | 27 | #include "pluginbase.h" | ||
28 | #include "akregatorplugindebug.h" | ||||
28 | 29 | | |||
29 | #include <kdebug.h> | | |||
30 | #include <kpluginfactory.h> | 30 | #include <kpluginfactory.h> | ||
31 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
32 | #include <kiconloader.h> | 32 | #include <kiconloader.h> | ||
33 | #include <kparts/part.h> | 33 | #include <kparts/part.h> | ||
34 | #include <kparts/statusbarextension.h> | 34 | #include <kparts/statusbarextension.h> | ||
35 | #include <KParts/ReadOnlyPart> | 35 | #include <KParts/ReadOnlyPart> | ||
36 | #include <KParts/HtmlExtension> | 36 | #include <KParts/HtmlExtension> | ||
37 | #include <KParts/SelectorInterface> | 37 | #include <KParts/SelectorInterface> | ||
38 | #include <kprocess.h> | 38 | #include <kprocess.h> | ||
39 | #include <kstandarddirs.h> | | |||
40 | #include <kstatusbar.h> | | |||
41 | #include <kurllabel.h> | 39 | #include <kurllabel.h> | ||
42 | | ||||
43 | #include <kprotocolinfo.h> | 40 | #include <kprotocolinfo.h> | ||
44 | 41 | | |||
45 | #include <qcursor.h> | 42 | #include <qstatusbar.h> | ||
46 | #include <qobject.h> | | |||
47 | #include <qpixmap.h> | | |||
48 | #include <qstringlist.h> | | |||
49 | #include <QTextDocument> | | |||
50 | #include <KLocalizedString> | | |||
51 | | ||||
52 | //KDELibs4Support | | |||
53 | #include <kurl.h> | | |||
54 | 43 | | |||
55 | using namespace Akregator; | 44 | using namespace Akregator; | ||
56 | 45 | | |||
57 | K_PLUGIN_FACTORY(KonqFeedIconFactory, registerPlugin<KonqFeedIcon>();) | 46 | K_PLUGIN_FACTORY(KonqFeedIconFactory, registerPlugin<KonqFeedIcon>();) | ||
58 | 47 | | |||
59 | static KUrl baseUrl(KParts::ReadOnlyPart *part) | 48 | static QUrl baseUrl(KParts::ReadOnlyPart *part) | ||
60 | { | 49 | { | ||
61 | KUrl url; | 50 | QUrl url; | ||
62 | KParts::HtmlExtension *ext = KParts::HtmlExtension::childObject(part); | 51 | KParts::HtmlExtension *ext = KParts::HtmlExtension::childObject(part); | ||
63 | if (ext) { | 52 | if (ext) { | ||
64 | url = ext->baseUrl(); | 53 | url = ext->baseUrl(); | ||
65 | } | 54 | } | ||
66 | return url; | 55 | return url; | ||
67 | } | 56 | } | ||
68 | 57 | | |||
69 | KonqFeedIcon::KonqFeedIcon(QObject *parent, const QVariantList &) | 58 | KonqFeedIcon::KonqFeedIcon(QObject *parent, const QVariantList &) | ||
Show All 27 Lines | 78 | { | |||
97 | m_feedIcon = 0; | 86 | m_feedIcon = 0; | ||
98 | delete m_menu; | 87 | delete m_menu; | ||
99 | m_menu = 0; | 88 | m_menu = 0; | ||
100 | } | 89 | } | ||
101 | 90 | | |||
102 | bool KonqFeedIcon::feedFound() | 91 | bool KonqFeedIcon::feedFound() | ||
103 | { | 92 | { | ||
104 | // Ensure that it is safe to use the URL, before doing anything else with it | 93 | // Ensure that it is safe to use the URL, before doing anything else with it | ||
105 | const KUrl partUrl(m_part->url()); | 94 | const QUrl partUrl(m_part->url()); | ||
106 | if (!partUrl.isValid()) { | 95 | if (!partUrl.isValid()) { | ||
107 | return false; | 96 | return false; | ||
108 | } | 97 | } | ||
109 | // Since attempting to determine feed info for about:blank crashes khtml, | 98 | // Since attempting to determine feed info for about:blank crashes khtml, | ||
110 | // lets prevent such look up for local urls (about, file, man, etc...) | 99 | // lets prevent such look up for local urls (about, file, man, etc...) | ||
111 | if (KProtocolInfo::protocolClass(partUrl.scheme()).compare(QLatin1String(":local"), Qt::CaseInsensitive) == 0) { | 100 | if (KProtocolInfo::protocolClass(partUrl.scheme()).compare(QLatin1String(":local"), Qt::CaseInsensitive) == 0) { | ||
112 | return false; | 101 | return false; | ||
113 | } | 102 | } | ||
114 | 103 | | |||
115 | KParts::HtmlExtension *ext = KParts::HtmlExtension::childObject(m_part); | 104 | KParts::HtmlExtension *ext = KParts::HtmlExtension::childObject(m_part); | ||
116 | KParts::SelectorInterface *selectorInterface = qobject_cast<KParts::SelectorInterface *>(ext); | 105 | KParts::SelectorInterface *selectorInterface = qobject_cast<KParts::SelectorInterface *>(ext); | ||
117 | QString doc; | 106 | QString doc; | ||
118 | if (selectorInterface) { | 107 | if (selectorInterface) { | ||
119 | QList<KParts::SelectorInterface::Element> linkNodes = selectorInterface->querySelectorAll(QStringLiteral("head > link[rel=\"alternate\"]"), KParts::SelectorInterface::EntireContent); | 108 | QList<KParts::SelectorInterface::Element> linkNodes = selectorInterface->querySelectorAll(QStringLiteral("head > link[rel=\"alternate\"]"), KParts::SelectorInterface::EntireContent); | ||
120 | //kDebug() << linkNodes.length() << "links"; | | |||
121 | for (int i = 0; i < linkNodes.count(); i++) { | 109 | for (int i = 0; i < linkNodes.count(); i++) { | ||
122 | const KParts::SelectorInterface::Element element = linkNodes.at(i); | 110 | const KParts::SelectorInterface::Element element = linkNodes.at(i); | ||
123 | 111 | | |||
124 | // TODO parse the attributes directly here, rather than re-assembling | 112 | // TODO parse the attributes directly here, rather than re-assembling | ||
125 | // and then re-parsing in extractFromLinkTags! | 113 | // and then re-parsing in extractFromLinkTags! | ||
126 | doc += QLatin1String("<link "); | 114 | doc += QLatin1String("<link "); | ||
127 | Q_FOREACH (const QString &attrName, element.attributeNames()) { | 115 | Q_FOREACH (const QString &attrName, element.attributeNames()) { | ||
128 | doc += attrName + "=\""; | 116 | doc += attrName + "=\""; | ||
129 | doc += element.attribute(attrName).toHtmlEscaped().replace(QLatin1String("\""), QLatin1String(""")); | 117 | doc += element.attribute(attrName).toHtmlEscaped().replace(QLatin1String("\""), QLatin1String(""")); | ||
130 | doc += QLatin1String("\" "); | 118 | doc += QLatin1String("\" "); | ||
131 | } | 119 | } | ||
132 | doc += QLatin1String("/>"); | 120 | doc += QLatin1String("/>"); | ||
133 | } | 121 | } | ||
134 | kDebug() << doc; | 122 | qCDebug(AKREGATORPLUGIN_LOG) << doc; | ||
135 | } | 123 | } | ||
136 | 124 | | |||
137 | m_feedList = FeedDetector::extractFromLinkTags(doc); | 125 | m_feedList = FeedDetector::extractFromLinkTags(doc); | ||
138 | return m_feedList.count() != 0; | 126 | return m_feedList.count() != 0; | ||
139 | } | 127 | } | ||
140 | 128 | | |||
141 | void KonqFeedIcon::contextMenu() | 129 | void KonqFeedIcon::contextMenu() | ||
142 | { | 130 | { | ||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | |||||
220 | { | 208 | { | ||
221 | if (akregatorRunning()) { | 209 | if (akregatorRunning()) { | ||
222 | QStringList list; | 210 | QStringList list; | ||
223 | for (FeedDetectorEntryList::Iterator it = m_feedList.begin(); it != m_feedList.end(); ++it) { | 211 | for (FeedDetectorEntryList::Iterator it = m_feedList.begin(); it != m_feedList.end(); ++it) { | ||
224 | list.append(fixRelativeURL((*it).url(), baseUrl(m_part))); | 212 | list.append(fixRelativeURL((*it).url(), baseUrl(m_part))); | ||
225 | } | 213 | } | ||
226 | addFeedsViaDBUS(list); | 214 | addFeedsViaDBUS(list); | ||
227 | } else { | 215 | } else { | ||
228 | kDebug() << "KonqFeedIcon::addFeeds(): use command line"; | 216 | qCDebug(AKREGATORPLUGIN_LOG) << "use command line"; | ||
229 | KProcess proc; | 217 | KProcess proc; | ||
230 | proc << QStringLiteral("akregator") << QStringLiteral("-g") << i18n("Imported Feeds"); | 218 | proc << QStringLiteral("akregator") << QStringLiteral("-g") << i18n("Imported Feeds"); | ||
231 | 219 | | |||
232 | for (FeedDetectorEntryList::Iterator it = m_feedList.begin(); it != m_feedList.end(); ++it) { | 220 | for (FeedDetectorEntryList::Iterator it = m_feedList.begin(); it != m_feedList.end(); ++it) { | ||
233 | proc << QStringLiteral("-a") << fixRelativeURL((*it).url(), baseUrl(m_part)); | 221 | proc << QStringLiteral("-a") << fixRelativeURL((*it).url(), baseUrl(m_part)); | ||
234 | } | 222 | } | ||
235 | 223 | | |||
236 | proc.startDetached(); | 224 | proc.startDetached(); | ||
237 | 225 | | |||
238 | } | 226 | } | ||
239 | } | 227 | } | ||
240 | 228 | | |||
241 | #include "konqfeedicon.moc" | 229 | #include "konqfeedicon.moc" |