[Sailfish] Open articles in web browser option
This commit is contained in:
parent
b518706f77
commit
fbcda8317c
12 changed files with 168 additions and 16 deletions
|
|
@ -50,6 +50,15 @@ Page {
|
|||
|
||||
model: VisualItemModel {
|
||||
|
||||
SectionHeader {
|
||||
text: qsTr("Version %1").arg("2.2")
|
||||
}
|
||||
|
||||
LogItem {
|
||||
title: 'Open articles in browser'
|
||||
description: "Option to open articles directly in default web browser instead built-in web viewer.";
|
||||
}
|
||||
|
||||
SectionHeader {
|
||||
text: qsTr("Version %1").arg("2.1")
|
||||
}
|
||||
|
|
|
|||
6
qml/sailfish/DebugPage.qml
Normal file
6
qml/sailfish/DebugPage.qml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import QtQuick 2.0
|
||||
|
||||
Item {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -60,6 +60,7 @@ ListItem {
|
|||
signal markedLike
|
||||
signal unmarkedLike
|
||||
signal markedAboveAsRead
|
||||
signal openInBrowser
|
||||
|
||||
enabled: !last && !daterow
|
||||
|
||||
|
|
@ -433,6 +434,17 @@ ListItem {
|
|||
Component {
|
||||
id: contextMenu
|
||||
ContextMenu {
|
||||
|
||||
MenuItem {
|
||||
text: qsTr("Open in browser")
|
||||
visible: enabled
|
||||
enabled: !settings.openInBrowser
|
||||
onClicked: {
|
||||
root.openInBrowser();
|
||||
root.expanded = false;
|
||||
}
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
text: read ? qsTr("Mark as unread") : qsTr("Mark as read")
|
||||
visible: enabled
|
||||
|
|
|
|||
|
|
@ -38,6 +38,19 @@ Page {
|
|||
property string title
|
||||
property int index
|
||||
|
||||
function navigate(url) {
|
||||
var hcolor = Theme.highlightColor.toString().substr(1, 6);
|
||||
var shcolor = Theme.secondaryHighlightColor.toString().substr(1, 6);
|
||||
var imgWidth = settings.fontSize == 1 ? root.width/(1.5) : settings.fontSize == 2 ? root.width/(2.0) : root.width;
|
||||
return url+"?fontsize=18px&width="+imgWidth+"&highlightColor="+hcolor+"&secondaryHighlightColor="+shcolor+"&margin="+Theme.paddingMedium;
|
||||
}
|
||||
|
||||
function openInExaternalBrowser(index, link, uid) {
|
||||
entryModel.setData(index, "read", 1, "");
|
||||
notification.show(qsTr("Launching an external browser..."));
|
||||
Qt.openUrlExternally(settings.offlineMode ? navigate(cache.getUrlbyId(uid)) : link);
|
||||
}
|
||||
|
||||
ActiveDetector {
|
||||
onInit: { bar.flick = listView;}
|
||||
}
|
||||
|
|
@ -220,6 +233,12 @@ Page {
|
|||
}
|
||||
|
||||
expanded = false;
|
||||
|
||||
if (settings.openInBrowser) {
|
||||
openInExaternalBrowser(model.index, model.link, model.uid);
|
||||
return;
|
||||
}
|
||||
|
||||
var onlineUrl = model.link;
|
||||
var offlineUrl = cache.getUrlbyId(model.uid);
|
||||
pageStack.push(Qt.resolvedUrl("WebPreviewPage.qml"),
|
||||
|
|
@ -287,6 +306,36 @@ Page {
|
|||
onMarkedAboveAsRead: {
|
||||
entryModel.setAboveAsRead(model.index);
|
||||
}
|
||||
|
||||
onOpenInBrowser: {
|
||||
// Not allowed while Syncing
|
||||
if (dm.busy || fetcher.busy || dm.removerBusy) {
|
||||
notification.show(qsTr("Please wait until current task is complete."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Entry not cached and offline mode enabled
|
||||
if (settings.offlineMode && !model.cached) {
|
||||
notification.show(qsTr("Offline version not available."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Switch to Offline mode if no network
|
||||
if (!settings.offlineMode && !dm.online) {
|
||||
if (model.cached) {
|
||||
// Entry cached
|
||||
notification.show(qsTr("Network connection is unavailable.\nSwitching to Offline mode."));
|
||||
settings.offlineMode = true;
|
||||
} else {
|
||||
// Entry not cached
|
||||
notification.show(qsTr("Network connection is unavailable."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
openInExaternalBrowser(model.index, model.link, model.uid);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ViewPlaceholder {
|
||||
|
|
|
|||
|
|
@ -574,6 +574,17 @@ Page {
|
|||
}
|
||||
}
|
||||
|
||||
TextSwitch {
|
||||
text: qsTr("Open articles in browser")
|
||||
description: qsTr("Instead built-in web viewer, web pages will be opened in default browser.")
|
||||
onCheckedChanged: {
|
||||
settings.openInBrowser = checked;
|
||||
}
|
||||
Component.onCompleted: {
|
||||
checked = settings.openInBrowser;
|
||||
}
|
||||
}
|
||||
|
||||
TextSwitchWithIcon {
|
||||
text: qsTr("Read mode")
|
||||
description: qsTr("Web pages will be reformatted into an easy to read version.")
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ Name: harbour-kaktus
|
|||
%{!?qtc_make:%define qtc_make make}
|
||||
%{?qtc_builddir:%define _builddir %qtc_builddir}
|
||||
Summary: Kaktus
|
||||
Version: 2.1
|
||||
Release: 6
|
||||
Version: 2.2
|
||||
Release: 1
|
||||
Group: Qt/Qt
|
||||
License: LICENSE
|
||||
URL: https://github.com/mkiol/kaktus
|
||||
|
|
@ -76,7 +76,10 @@ desktop-file-install --delete-original \
|
|||
|
||||
%changelog
|
||||
|
||||
* Sat Oct 10 2015 Michal Kosciesza 2.1-6
|
||||
* Fri Nov 27 2015 Michal Kosciesza 2.2-1
|
||||
- Open articles in web browser option
|
||||
|
||||
* Sat Oct 10 2015 Michal Kosciesza 2.1.1-6
|
||||
- BUG FIX: "Unknown error" while syncing Netvibes account
|
||||
|
||||
* Wed Sep 30 2015 Michal Kosciesza 2.1-5
|
||||
|
|
|
|||
|
|
@ -312,27 +312,30 @@ void FilteringWorker::filter()
|
|||
margin = query.queryItemValue("margin").toInt();
|
||||
#endif
|
||||
|
||||
QString initialScale = "1.0";
|
||||
/*switch (s->getFontSize()) {
|
||||
case 1:
|
||||
width = width/(1.5);
|
||||
initialScale = "1.5";
|
||||
break;
|
||||
case 2:
|
||||
width = width/(2.0);
|
||||
initialScale = "2.0";
|
||||
break;
|
||||
default:
|
||||
initialScale = "1.0";
|
||||
}*/
|
||||
|
||||
width = width-2*margin;
|
||||
|
||||
if (s->getOfflineTheme() == "white") {
|
||||
style = QString("<meta name='viewport' content='device-width'>"
|
||||
"<style>body{margin:%5px;background:#FFF;font-family:sans-serif;font-size:%1;color:#323232;}figure{margin:0;padding:0;}a:link{color:#%3;}a:visited{color:#%4;}a:active{color:#%3;}img{max-width:100%;max-height:device-height;}</style></head>")
|
||||
.arg(fontsize).arg(highlightColor).arg(secondaryHighlightColor).arg(margin);
|
||||
style = QString("<meta name='viewport' content='device-width,initial-scale=%6'>"
|
||||
"<style>body{margin:%5px;background:#FFF;font-family:sans-serif;font-size:%1;color:#323232;}figure{margin:0;padding:0;}a:link{color:#%2;}a:visited{color:#%4;}a:active{color:#%3;}img{max-width:100%;max-height:device-height;}</style></head>")
|
||||
.arg(fontsize).arg(highlightColor).arg(highlightColor).arg(secondaryHighlightColor).arg(margin).arg(initialScale);
|
||||
}
|
||||
|
||||
if (s->getOfflineTheme() == "black") {
|
||||
style = QString("<meta name='viewport' content='device-width'>"
|
||||
"<style>body{margin:%5px;background:#141414;font-family:sans-serif;font-size:%1;color:#FFF;}figure{margin:0;padding:0;}a:link{color:#%3;}a:visited{color:#%4;}a:active{color:#%3;}img{max-width:100%;max-height:device-height;}</style></head>")
|
||||
.arg(fontsize).arg(highlightColor).arg(secondaryHighlightColor).arg(margin);
|
||||
style = QString("<meta name='viewport' content='device-width,initial-scale=%6'>"
|
||||
"<style>body{margin:%5px;background:#141414;font-family:sans-serif;font-size:%1;color:#FFF;}figure{margin:0;padding:0;}a:link{color:#%2;}a:visited{color:#%4;}a:active{color:#%3;}img{max-width:100%;max-height:device-height;}</style></head>")
|
||||
.arg(fontsize).arg(highlightColor).arg(highlightColor).arg(secondaryHighlightColor).arg(margin).arg(initialScale);
|
||||
//qDebug() << style;
|
||||
}
|
||||
|
||||
|
|
@ -438,6 +441,13 @@ CacheServer::~CacheServer()
|
|||
void CacheServer::handle(QHttpRequest *req, QHttpResponse *resp)
|
||||
{
|
||||
//qDebug() << "handle, url=" << req->url().toString();
|
||||
if (req->url().path() == "/test") {
|
||||
resp->setHeader("Content-Type", "text/html");
|
||||
resp->writeHead(200);
|
||||
resp->end("<html><body><h1>It works!</h1></body></html>");
|
||||
return;
|
||||
}
|
||||
|
||||
FilteringWorker *worker = new FilteringWorker();
|
||||
QObject::connect(this, SIGNAL(startWorker(QHttpRequest*,QHttpResponse*)), worker, SLOT(start(QHttpRequest*,QHttpResponse*)));
|
||||
QObject::connect(worker, SIGNAL(finished()), this, SLOT(handleFinish()));
|
||||
|
|
@ -463,7 +473,7 @@ void CacheServer::handleFinish()
|
|||
}
|
||||
|
||||
|
||||
/*#define HOST_FILTER 0x01 // => 0001
|
||||
/*#define HOST_FILTER 0x01 // => 0001
|
||||
#define REMOVE_FILTER 0x02 // => 0010
|
||||
|
||||
void CacheServer::resolveRelativeUrls(QString &content, const QRegExp &rx, const QUrl &baseUrl, int filter)
|
||||
|
|
@ -520,7 +530,8 @@ void CacheServer::resolveRelativeUrls(QString &content, const QRegExp &rx, const
|
|||
|
||||
QString CacheServer::getUrlbyId(const QString &item)
|
||||
{
|
||||
return "http://127.0.0.1:" + QString::number(port) + "/" + item;
|
||||
//return "http://127.0.0.1:" + QString::number(port) + "/" + item;
|
||||
return "http://localhost:" + QString::number(port) + "/" + item;
|
||||
}
|
||||
|
||||
QString CacheServer::getUrlbyUrl(const QString &url)
|
||||
|
|
@ -532,6 +543,7 @@ QString CacheServer::getUrlbyUrl(const QString &url)
|
|||
return url;
|
||||
}
|
||||
|
||||
return "http://127.0.0.1:" + QString::number(port) + "/" + Utils::hash(url);
|
||||
//return "http://127.0.0.1:" + QString::number(port) + "/" + Utils::hash(url);
|
||||
return "http://localhost:" + QString::number(port) + "/" + Utils::hash(url);
|
||||
}
|
||||
|
||||
|
|
|
|||
7
src/debugunit.cpp
Normal file
7
src/debugunit.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include "debugunit.h"
|
||||
|
||||
DebugUnit::DebugUnit(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
17
src/debugunit.h
Normal file
17
src/debugunit.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef DEBUGUNIT_H
|
||||
#define DEBUGUNIT_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class DebugUnit : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DebugUnit(QObject *parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
||||
#endif // DEBUGUNIT_H
|
||||
|
|
@ -33,14 +33,16 @@
|
|||
#include "cacheserver.h"
|
||||
#include "utils.h"
|
||||
#include "settings.h"
|
||||
#include "debugunit.h"
|
||||
#include "networkaccessmanagerfactory.h"
|
||||
|
||||
static const char *APP_NAME = "Kaktus";
|
||||
static const char *AUTHOR = "Michal Kosciesza <michal@mkiol.net>";
|
||||
static const char *PAGE = "https://github.com/mkiol/kaktus";
|
||||
#ifdef KAKTUS_LIGHT
|
||||
static const char *VERSION = "2.1 (light edition)";
|
||||
static const char *VERSION = "2.2 (light edition)";
|
||||
#else
|
||||
static const char *VERSION = "2.1";
|
||||
static const char *VERSION = "2.2";
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
@ -79,12 +81,18 @@ int main(int argc, char *argv[])
|
|||
|
||||
QObject::connect(view->engine(), SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
|
||||
|
||||
NetworkAccessManagerFactory NAMfactory(settings->getDmUserAgent());
|
||||
view->engine()->setNetworkAccessManagerFactory(&NAMfactory);
|
||||
|
||||
view->rootContext()->setContextProperty("db", &db);
|
||||
view->rootContext()->setContextProperty("utils", &utils);
|
||||
view->rootContext()->setContextProperty("dm", &dm);
|
||||
view->rootContext()->setContextProperty("cache", &cache);
|
||||
view->rootContext()->setContextProperty("settings", settings);
|
||||
|
||||
DebugUnit debugUnit;
|
||||
view->rootContext()->setContextProperty("debug", &debugUnit);
|
||||
|
||||
view->setSource(SailfishApp::pathTo("qml/sailfish/main.qml"));
|
||||
view->show();
|
||||
|
||||
|
|
|
|||
|
|
@ -228,6 +228,19 @@ bool Settings::getHint1Done()
|
|||
return settings.value("hint1done", false).toBool();
|
||||
}
|
||||
|
||||
void Settings::setOpenInBrowser(bool value)
|
||||
{
|
||||
if (getOpenInBrowser() != value) {
|
||||
settings.setValue("openinbrowser", value);
|
||||
emit openInBrowserChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool Settings::getOpenInBrowser()
|
||||
{
|
||||
return settings.value("openinbrowser", false).toBool();
|
||||
}
|
||||
|
||||
void Settings::setAutoDownloadOnUpdate(bool value)
|
||||
{
|
||||
if (getAutoDownloadOnUpdate() != value) {
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ class Settings: public QObject
|
|||
Q_PROPERTY (bool showBroadcast READ getShowBroadcast WRITE setShowBroadcast NOTIFY showBroadcastChanged)
|
||||
Q_PROPERTY (bool showOldestFirst READ getShowOldestFirst WRITE setShowOldestFirst NOTIFY showOldestFirstChanged)
|
||||
Q_PROPERTY (bool syncRead READ getSyncRead WRITE setSyncRead NOTIFY syncReadChanged)
|
||||
Q_PROPERTY (bool openInBrowser READ getOpenInBrowser WRITE setOpenInBrowser NOTIFY openInBrowserChanged)
|
||||
|
||||
public:
|
||||
static Settings* instance();
|
||||
|
|
@ -150,6 +151,9 @@ public:
|
|||
void setSyncRead(bool value);
|
||||
bool getSyncRead();
|
||||
|
||||
void setOpenInBrowser(bool value);
|
||||
bool getOpenInBrowser();
|
||||
|
||||
void setTheme(int value);
|
||||
int getTheme();
|
||||
|
||||
|
|
@ -246,6 +250,7 @@ signals:
|
|||
void showBroadcastChanged();
|
||||
void showOldestFirstChanged();
|
||||
void syncReadChanged();
|
||||
void openInBrowserChanged();
|
||||
|
||||
/*
|
||||
501 - Unable create settings dir
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue