From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: 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/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- akregator/src/articleviewer.cpp | 797 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 797 insertions(+) create mode 100644 akregator/src/articleviewer.cpp (limited to 'akregator/src/articleviewer.cpp') diff --git a/akregator/src/articleviewer.cpp b/akregator/src/articleviewer.cpp new file mode 100644 index 00000000..942ce623 --- /dev/null +++ b/akregator/src/articleviewer.cpp @@ -0,0 +1,797 @@ +/* + This file is part of Akregator. + + Copyright (C) 2004 Sashmit Bhaduri + 2005 Frank Osterfeld + 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "aboutdata.h" +#include "akregator_run.h" +#include "akregatorconfig.h" +#include "articleviewer.h" +#include "feed.h" +#include "folder.h" +#include "article.h" +#include "treenode.h" +#include "treenodevisitor.h" +#include "tagnode.h" +#include "utils.h" + +namespace Akregator { + +// from kmail::headerstyle.cpp +static inline QString directionOf(const QString &str) +{ + return str.isRightToLeft() ? "rtl" : "ltr" ; +} + +class ArticleViewer::ShowSummaryVisitor : public TreeNodeVisitor +{ + public: + + ShowSummaryVisitor(ArticleViewer* view) : m_view(view) {} + + virtual bool visitFeed(Feed* node) + { + m_view->m_link = QString(); + + QString text; + text = QString("
\n").arg(QApplication::reverseLayout() ? "rtl" : "ltr"); + + text += QString("
").arg(directionOf(Utils::stripTags(node->title()))); + text += node->title(); + if(node->unread() == 0) + text += i18n(" (no unread articles)"); + else + text += i18n(" (1 unread article)", " (%n unread articles)", node->unread()); + text += "
\n"; // headertitle + text += "
\n"; // /headerbox + + if (!node->image().isNull()) // image + { + text += QString("
"); + QString url=node->xmlUrl(); + QString file = url.replace("/", "_").replace(":", "_"); + KURL u(m_view->m_imageDir); + u.setFileName(file); + text += QString("\n").arg(node->htmlUrl()).arg(u.url()); + } + else text += "
"; + + + if( !node->description().isEmpty() ) + { + text += QString("
").arg(Utils::stripTags(directionOf(node->description()))); + text += i18n("Description: %1

").arg(node->description()); + text += "
\n"; // /description + } + + if ( !node->htmlUrl().isEmpty() ) + { + text += QString("
").arg(directionOf(node->htmlUrl())); + text += i18n("Homepage: %2").arg(node->htmlUrl()).arg(node->htmlUrl()); + text += "
\n"; // / link + } + + //text += i18n("Unread articles: %1").arg(node->unread()); + text += "
"; // /body + + m_view->renderContent(text); + return true; + } + + virtual bool visitFolder(Folder* node) + { + m_view->m_link = QString(); + + QString text; + text = QString("
\n").arg(QApplication::reverseLayout() ? "rtl" : "ltr"); + text += QString("
%2").arg(directionOf(Utils::stripTags(node->title()))).arg(node->title()); + if(node->unread() == 0) + text += i18n(" (no unread articles)"); + else + text += i18n(" (1 unread article)", " (%n unread articles)", node->unread()); + text += QString("
\n"); + text += "
\n"; // /headerbox + + m_view->renderContent(text); + return true; + } + + virtual bool visitTagNode(TagNode* node) + { + m_view->m_link = QString(); + + QString text; + text = QString("
\n").arg(QApplication::reverseLayout() ? "rtl" : "ltr"); + text += QString("
%2").arg(directionOf(Utils::stripTags(node->title()))).arg(node->title()); + if(node->unread() == 0) + text += i18n(" (no unread articles)"); + else + text += i18n(" (1 unread article)", " (%n unread articles)", node->unread()); + text += QString("
\n"); + text += "
\n"; // /headerbox + + m_view->renderContent(text); + return true; + } + + private: + + ArticleViewer* m_view; +}; + +ArticleViewer::ArticleViewer(QWidget *parent, const char *name) + : Viewer(parent, name), m_htmlFooter(), m_currentText(), m_node(0), m_viewMode(NormalView) +{ + setJScriptEnabled(false); + setJavaEnabled(false); + setPluginsEnabled(false); + + m_showSummaryVisitor = new ShowSummaryVisitor(this); + setXMLFile(locate("data", "akregator/articleviewer.rc"), true); + + generateNormalModeCSS(); + generateCombinedModeCSS(); + new KAction( i18n("&Scroll Up"), QString::null, "Up", this, SLOT(slotScrollUp()), actionCollection(), "articleviewer_scroll_up" ); + new KAction( i18n("&Scroll Down"), QString::null, "Down", this, SLOT(slotScrollDown()), actionCollection(), "articleviewer_scroll_down" ); + + connect(this, SIGNAL(selectionChanged()), this, SLOT(slotSelectionChanged())); + + connect(kapp, SIGNAL(kdisplayPaletteChanged()), this, SLOT(slotPaletteOrFontChanged()) ); + connect(kapp, SIGNAL(kdisplayFontChanged()), this, SLOT(slotPaletteOrFontChanged()) ); + + m_imageDir.setPath(KGlobal::dirs()->saveLocation("cache", "akregator/Media/")); + m_htmlFooter = ""; +} + +ArticleViewer::~ArticleViewer() +{ + delete m_showSummaryVisitor; +} + +void ArticleViewer::generateNormalModeCSS() +{ + const QColorGroup & cg = QApplication::palette().active(); + + // from kmail::headerstyle.cpp + m_normalModeCSS = QString( + "@media screen, print {" + "body {\n" + " font-family: \"%1\" ! important;\n" + " font-size: %2 ! important;\n" + " color: %3 ! important;\n" + " background: %4 ! important;\n" + "}\n\n").arg(Settings::standardFont()) + .arg(QString::number(pointsToPixel(Settings::mediumFontSize()))+"px") + .arg(cg.text().name()) + .arg(cg.base().name()); + m_normalModeCSS += QString( + "a {\n" + + QString(" color: %1 ! important;\n") + + QString(!Settings::underlineLinks() ? " text-decoration: none ! important;\n" : "") + + "}\n\n" + +".headerbox {\n" + +" background: %2 ! important;\n" + +" color: %3 ! important;\n" + +" border:1px solid #000;\n" + +" margin-bottom: 10pt;\n" +// +" width: 99%;\n" + + "}\n\n") + .arg(cg.link().name()) + .arg(cg.background().name()) + .arg(cg.text().name()); + + m_normalModeCSS += QString(".headertitle a:link { color: %1 ! important; }\n" + ".headertitle a:visited { color: %2 ! important; }\n" + ".headertitle a:hover{ color: %3 ! important; }\n" + ".headertitle a:active { color: %4 ! important; }\n") + .arg(cg.highlightedText().name()) + .arg(cg.highlightedText().name()) + .arg(cg.highlightedText().name()) + .arg(cg.highlightedText().name()); + + m_normalModeCSS += QString( + ".headertitle {\n" + " background: %1 ! important;\n" + " padding:2px;\n" + " color: %2 ! important;\n" + " font-weight: bold;\n" + "}\n\n" + ".header {\n" + " font-weight: bold;\n" + " padding:2px;\n" + " margin-right: 5px;\n" + "}\n\n" + ".headertext {\n" + "}\n\n" + ".headimage {\n" + " float: right;\n" + " margin-left: 5px;\n" + "}\n\n").arg(cg.highlight().name()) + .arg(cg.highlightedText().name()); + + m_normalModeCSS += QString( + "body { clear: none; }\n\n" + ".content {\n" + " display: block;\n" + " margin-bottom: 6px;\n" + "}\n\n" + // these rules make sure that there is no leading space between the header and the first of the text + ".content > P:first-child {\n margin-top: 1px; }\n" + ".content > DIV:first-child {\n margin-top: 1px; }\n" + ".content > BR:first-child {\n display: none; }\n" + "iframe {display: none !important; }\n" + "frame {display: none !important; }\n" + "frameset {display: none !important; }\n" + "object {display: none !important; }\n" + "applet {display: none !important; }\n" + "}\n\n"); // @media screen, print +} + +void ArticleViewer::generateCombinedModeCSS() +{ + const QColorGroup & cg = QApplication::palette().active(); + + // from kmail::headerstyle.cpp + m_combinedModeCSS = QString ( +// "