From 0564dfca779f9481347e943c8a88d8f41b7f14cf Mon Sep 17 00:00:00 2001 From: Tofe Date: Wed, 4 Apr 2012 00:01:26 +0200 Subject: [PATCH] Readability integration - first draft --- qml/QuickNewsReader/content/js/Readability.js | 14 +-- .../content/modelimpl/FavoriteFeedsSourceModel.qml | 25 ++++- .../content/modelimpl/FavoriteRssFeeds.qml | 2 +- .../content/modelimpl/LeMondeSourceModel.qml | 4 +- .../content/modelimpl/YahooSourceModel.qml | 25 ++++- qml/QuickNewsReader/content/view/NewsComments.qml | 86 ---------------- .../content/view/NewsDetailFromURL.qml | 107 ++++++++++++++++++++ 7 files changed, 163 insertions(+), 100 deletions(-) delete mode 100644 qml/QuickNewsReader/content/view/NewsComments.qml create mode 100644 qml/QuickNewsReader/content/view/NewsDetailFromURL.qml diff --git a/qml/QuickNewsReader/content/js/Readability.js b/qml/QuickNewsReader/content/js/Readability.js index d0fd4f7..b7d6e03 100644 --- a/qml/QuickNewsReader/content/js/Readability.js +++ b/qml/QuickNewsReader/content/js/Readability.js @@ -1,9 +1,9 @@ /*jslint undef: true, nomen: true, eqeqeq: true, plusplus: true, newcap: true, immed: true, browser: true, devel: true, passfail: false */ /*global window: false, readConvertLinksToFootnotes: false, readStyle: false, readSize: false, readMargin: false, Typekit: false, ActiveXObject: false */ -var dbg = (typeof console !== 'undefined') ? function(s) { - console.log("Readability: " + s); -} : function() {}; +var dbg = function(s) { + window.console.log("Readability: " + s); +}; /* * Readability. An Arc90 Lab Experiment. @@ -88,7 +88,7 @@ var readability = { /* Pull out any possible next page link first */ var nextPageLink = readability.findNextPageLink(document.body); - + readability.prepDocument(); /* Build readability's DOM tree */ @@ -1411,12 +1411,12 @@ var readability = { articlePage.innerHTML = articlePage.innerHTML + nextPageMarkup; return; } - + /** * Now that we've built the article page DOM element, get the page content * asynchronously and load the cleaned content into the div we created for it. **/ - (function(pageUrl, thisPage) { + var replaceContent = function(pageUrl, thisPage) { readability.ajax(pageUrl, { success: function(r) { @@ -1500,7 +1500,7 @@ var readability = { } } }); - }(nextPageLink, articlePage)); + }(nextPageLink, articlePage); }, /** diff --git a/qml/QuickNewsReader/content/modelimpl/FavoriteFeedsSourceModel.qml b/qml/QuickNewsReader/content/modelimpl/FavoriteFeedsSourceModel.qml index 48ba90e..922f9c3 100644 --- a/qml/QuickNewsReader/content/modelimpl/FavoriteFeedsSourceModel.qml +++ b/qml/QuickNewsReader/content/modelimpl/FavoriteFeedsSourceModel.qml @@ -24,16 +24,37 @@ SourceModel { listViews: [ { viewComponent: 'content/view/Categories.qml' } , - { viewComponent: 'content/view/News.qml' } + { viewComponent: 'content/view/News.qml' }, + { viewComponent: 'content/view/NewsDetailFromURL.qml' } ] listModels: [ categoriesModel, newsModel, + newsModelDetail ] + function getNewsModelItem(prop) + { + var newsIndex = currentPath[2] + + if( typeof newsModel.get(newsIndex) != "undefined" ) + if( typeof newsModel.get(newsIndex)[prop] != "undefined" ) + return newsModel.get(newsIndex)[prop] + + return "" + } + property variant categoriesModel: FavoriteRssFeeds { } property variant newsModel: RssFeedModel { - currentFeed: categoriesModel.get(window.currentCategoryIndex).feed + currentFeed: categoriesModel.get(currentPath[1]).feed + } + property variant newsModelDetail: QtObject { + property variant parentModel: newsModel + property int sourceDepth: 3 + + property string urllink: getNewsModelItem('link') + property string title: getNewsModelItem('title') + property string image: getNewsModelItem('image') } loading: newsModel.loading diff --git a/qml/QuickNewsReader/content/modelimpl/FavoriteRssFeeds.qml b/qml/QuickNewsReader/content/modelimpl/FavoriteRssFeeds.qml index 285fd19..987f8e6 100644 --- a/qml/QuickNewsReader/content/modelimpl/FavoriteRssFeeds.qml +++ b/qml/QuickNewsReader/content/modelimpl/FavoriteRssFeeds.qml @@ -24,5 +24,5 @@ ListModel { property int sourceDepth: 1 ListElement { name: "xkcd"; feed: "xkcd.com/rss.xml" } -// ListElement { name: "Journal du Geek"; feed: "www.journaldugeek.com/rss.php" } + ListElement { name: "Journal du Geek"; feed: "www.journaldugeek.com/rss.php" } } diff --git a/qml/QuickNewsReader/content/modelimpl/LeMondeSourceModel.qml b/qml/QuickNewsReader/content/modelimpl/LeMondeSourceModel.qml index 9dfc387..f033a69 100644 --- a/qml/QuickNewsReader/content/modelimpl/LeMondeSourceModel.qml +++ b/qml/QuickNewsReader/content/modelimpl/LeMondeSourceModel.qml @@ -26,7 +26,7 @@ SourceModel { { viewComponent: 'content/view/Categories.qml' } , { viewComponent: 'content/view/News.qml' }, { viewComponent: 'content/view/NewsDetail.qml' }, - { viewComponent: 'content/view/NewsComments.qml' } + { viewComponent: 'content/view/NewsDetailFromURL.qml' } ] listModels: [ categoriesModel, @@ -72,7 +72,7 @@ SourceModel { property variant parentModel: newsModel property int sourceDepth: 4 - property string commentURL: "http://www.lemonde.fr" + getNewsModelItem('commentURL') + property string urllink: "http://www.lemonde.fr" + getNewsModelItem('commentURL') property string title: getNewsModelItem('title') property string image: getNewsModelItem('image') } diff --git a/qml/QuickNewsReader/content/modelimpl/YahooSourceModel.qml b/qml/QuickNewsReader/content/modelimpl/YahooSourceModel.qml index 26efc2a..8324f4f 100644 --- a/qml/QuickNewsReader/content/modelimpl/YahooSourceModel.qml +++ b/qml/QuickNewsReader/content/modelimpl/YahooSourceModel.qml @@ -24,16 +24,37 @@ SourceModel { listViews: [ { viewComponent: 'content/view/Categories.qml' } , - { viewComponent: 'content/view/News.qml' } + { viewComponent: 'content/view/News.qml' }, + { viewComponent: 'content/view/NewsDetailFromURL.qml' } ] listModels: [ categoriesModel, newsModel, + newsModelDetail ] + function getNewsModelItem(prop) + { + var newsIndex = currentPath[2] + + if( typeof newsModel.get(newsIndex) != "undefined" ) + if( typeof newsModel.get(newsIndex)[prop] != "undefined" ) + return newsModel.get(newsIndex)[prop] + + return "" + } + property variant categoriesModel: YahooRssFeeds { } property variant newsModel: RssFeedModel { - currentFeed: categoriesModel.get(window.currentCategoryIndex).feed + currentFeed: categoriesModel.get(currentPath[1]).feed + } + property variant newsModelDetail: QtObject { + property variant parentModel: newsModel + property int sourceDepth: 3 + + property string urllink: getNewsModelItem('link') + property string title: getNewsModelItem('title') + property string image: getNewsModelItem('image') } loading: newsModel.loading diff --git a/qml/QuickNewsReader/content/view/NewsComments.qml b/qml/QuickNewsReader/content/view/NewsComments.qml deleted file mode 100644 index ae825f8..0000000 --- a/qml/QuickNewsReader/content/view/NewsComments.qml +++ /dev/null @@ -1,86 +0,0 @@ -/*** -** Copyright (C) 2012 Christophe CHAPUIS -** -** This package 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 package 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 package; if not, write to the Free Software -** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -** -***/ -import QtQuick 1.0 -import QtWebKit 1.0 - -Item { - id: newsCommentsRect - width: window.width; height: window.height - - function getNewsModelItem(prop) - { - if( typeof currentSource.listModels[componentDepth-1] != "undefined" ) - if( typeof currentSource.listModels[componentDepth-1][prop] != "undefined" ) - return currentSource.listModels[componentDepth-1][prop] - - return "" - } - - property string commentURL: getNewsModelItem('commentURL') - property string title: getNewsModelItem('title') - property string image: getNewsModelItem('image') - - VisualItemModel { - id: itemModel - - Column { - id: column - x: 10; y: 10 - width: newsCommentsRect.width - 20 -// height: newsCommentsRect.height - - Row { - id: titleRow - spacing: 5 - - Image { - id: detailImage - source: image - } - - Text { - anchors.verticalCenter: titleRow.verticalCenter - text: title; width: column.width - detailImage.width - 10; wrapMode: Text.WordWrap - font { bold: true; family: "Helvetica"; pointSize: 16 } - } - } - - WebView { - width: column.width - id: newsCommentsWebView - url: commentURL - preferredWidth: column.width - - // on the maemo platform, the background is dark gray by default, so change it to white - onLoadFinished: { - newsCommentsWebView.evaluateJavaScript("document.bgColor = '#FFFFFF';") - //newsCommentsWebView.evaluateJavaScript("readConvertLinksToFootnotes=false;readStyle='style-newspaper';readSize='size-medium';readMargin='margin-wide';_readability_script=document.createElement('script');_readability_script.type='text/javascript';_readability_script.src='file:///home/chris/dev/arc90labs-readability/js/readability.js?x='+(Math.random());document.documentElement.appendChild(_readability_script);_readability_css=document.createElement('link');_readability_css.rel='stylesheet';_readability_css.href='file:///home/chris/dev/arc90labs-readability/css/readability.css';_readability_css.type='text/css';_readability_css.media='all';document.documentElement.appendChild(_readability_css);_readability_print_css=document.createElement('link');_readability_print_css.rel='stylesheet';_readability_print_css.href='file:///home/chris/dev/arc90labs-readability/css/readability-print.css';_readability_print_css.media='print';_readability_print_css.type='text/css';document.getElementsByTagName('head')[0].appendChild(_readability_print_css);readability.init();") - } - - onAlert: console.log(message); - } - } - } - ListView { - id: itemListView - anchors.fill: newsCommentsRect - model: itemModel - } - ScrollBar { scrollArea: itemListView; height: itemListView.height; width: 8; anchors.right: itemListView.right } -} diff --git a/qml/QuickNewsReader/content/view/NewsDetailFromURL.qml b/qml/QuickNewsReader/content/view/NewsDetailFromURL.qml new file mode 100644 index 0000000..009dd00 --- /dev/null +++ b/qml/QuickNewsReader/content/view/NewsDetailFromURL.qml @@ -0,0 +1,107 @@ +/*** +** Copyright (C) 2012 Christophe CHAPUIS +** +** This package 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 package 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 package; if not, write to the Free Software +** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +** +***/ +import QtQuick 1.0 +import QtWebKit 1.0 + +Item { + id: newsDetailFromURLRect + width: window.width; height: window.height + + function getNewsModelItem(prop) + { + if( typeof currentSource.listModels[componentDepth-1] != "undefined" ) + if( typeof currentSource.listModels[componentDepth-1][prop] != "undefined" ) + return currentSource.listModels[componentDepth-1][prop] + + return "" + } + + property string detailURL: getNewsModelItem('urllink') + property string title: getNewsModelItem('title') + property string image: getNewsModelItem('image') + + VisualItemModel { + id: itemModel + + Column { + id: column + x: 10; y: 10 + width: newsDetailFromURLRect.width - 20 +// height: newsDetailFromURLRect.height + + Row { + id: titleRow + spacing: 5 + + Image { + id: detailImage + source: image + } + + Text { + anchors.verticalCenter: titleRow.verticalCenter + text: title; width: column.width - detailImage.width - 10; wrapMode: Text.WordWrap + font { bold: true; family: "Helvetica"; pointSize: 16 } + } + } + + WebView { + width: column.width + id: newsDetailWebView + url: detailURL + preferredWidth: column.width + settings.javascriptEnabled: true + settings.autoLoadImages: false + + property bool firstLoad: true; + + javaScriptWindowObjects: QtObject { + WebView.windowObjectName: "console" + + function log(message) { + console.log(message); + } + } + + // on the maemo platform, the background is dark gray by default, so change it to white + onLoadFinished: { + newsDetailWebView.evaluateJavaScript("document.bgColor = '#FFFFFF';") + + if( firstLoad ) + { + newsDetailWebView.evaluateJavaScript("readConvertLinksToFootnotes=false;readStyle='style-newspaper';readSize='size-medium';readMargin='margin-wide';_readability_script=document.createElement('script');_readability_script.type='text/javascript';_readability_script.src='file:///home/chris/dev/projects/QuickNewsReader/qml/QuickNewsReader/content/js/Readability.js?x='+(Math.random());document.documentElement.appendChild(_readability_script);_readability_css=document.createElement('link');_readability_css.rel='stylesheet';_readability_css.href='file:///home/chris/dev/projects/QuickNewsReader/qml/QuickNewsReader/content/css/readability.css';_readability_css.type='text/css';_readability_css.media='all';document.getElementsByTagName('head')[0].appendChild(_readability_css);_readability_print_css=document.createElement('link');_readability_print_css.rel='stylesheet';_readability_print_css.href='file:///home/chris/dev/projects/QuickNewsReader/qml/QuickNewsReader/content/css/readability-print.css';_readability_print_css.media='print';_readability_print_css.type='text/css';document.getElementsByTagName('head')[0].appendChild(_readability_print_css);") + + var currentHtml = newsDetailWebView.html; + newsDetailWebView.html = currentHtml; + + firstLoad = false; + } + } + + onAlert: console.log(message); + } + } + } + ListView { + id: itemListView + anchors.fill: newsDetailFromURLRect + model: itemModel + } + ScrollBar { scrollArea: itemListView; height: itemListView.height; width: 8; anchors.right: itemListView.right } +} -- 1.7.9.5