This commit is contained in:
Martin Rotter 2014-03-14 11:16:43 +01:00
parent f22f294eba
commit a3a2f38c3e
11 changed files with 59 additions and 29 deletions

View file

@ -46,6 +46,7 @@ set(FILE_VERSION "1,9,9,6")
set(APP_AUTHOR "Martin Rotter") set(APP_AUTHOR "Martin Rotter")
set(APP_URL "http://bitbucket.org/skunkos/rssguard") set(APP_URL "http://bitbucket.org/skunkos/rssguard")
set(APP_URL_ISSUES "http://bitbucket.org/skunkos/rssguard/issues") set(APP_URL_ISSUES "http://bitbucket.org/skunkos/rssguard/issues")
set(APP_URL_ISSUES_NEW "http://bitbucket.org/skunkos/rssguard/issues/new")
set(APP_EMAIL "rotter.martinos@gmail.com") set(APP_EMAIL "rotter.martinos@gmail.com")
set(MINIMUM_QT_VERSION 4.7.3) set(MINIMUM_QT_VERSION 4.7.3)
set(EXE_NAME ${APP_LOW_NAME}) set(EXE_NAME ${APP_LOW_NAME})

View file

@ -37,6 +37,7 @@
#define APP_EMAIL "@APP_EMAIL@" #define APP_EMAIL "@APP_EMAIL@"
#define APP_URL "@APP_URL@" #define APP_URL "@APP_URL@"
#define APP_URL_ISSUES "@APP_URL_ISSUES@" #define APP_URL_ISSUES "@APP_URL_ISSUES@"
#define APP_URL_ISSUES_NEW "@APP_URL_ISSUES_NEW@"
#define APP_VERSION "@APP_VERSION@" #define APP_VERSION "@APP_VERSION@"
#define APP_USERAGENT QString("@APP_NAME@/@APP_VERSION@ (@APP_URL@) on @CMAKE_SYSTEM@; Webkit/") + qWebKitVersion() #define APP_USERAGENT QString("@APP_NAME@/@APP_VERSION@ (@APP_URL@) on @CMAKE_SYSTEM@; Webkit/") + qWebKitVersion()

View file

@ -24,31 +24,11 @@
#include <QEventLoop> #include <QEventLoop>
#include <QTimer> #include <QTimer>
#include <QTextDocument>
#include <QProcess>
#include <QDesktopServices>
NetworkFactory::NetworkFactory() { NetworkFactory::NetworkFactory() {
} }
bool NetworkFactory::openUrlInExternalBrowser(const QString &url) {
if (Settings::instance()->value(APP_CFG_BROWSER,
"custom_external_browser",
false).toBool()) {
QString browser = Settings::instance()->value(APP_CFG_BROWSER,
"external_browser_executable").toString();
QString arguments = Settings::instance()->value(APP_CFG_BROWSER,
"external_browser_arguments",
"%1").toString();
return QProcess::startDetached(browser, QStringList() << arguments.arg(url));
}
else {
return QDesktopServices::openUrl(url);
}
}
QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code) { QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code) {
switch (error_code) { switch (error_code) {
case QNetworkReply::ProtocolUnknownError: case QNetworkReply::ProtocolUnknownError:

View file

@ -32,8 +32,6 @@ class NetworkFactory {
explicit NetworkFactory(); explicit NetworkFactory();
public: public:
static bool openUrlInExternalBrowser(const QString &url);
// Returns human readable text for given network error. // Returns human readable text for given network error.
static QString networkErrorText(QNetworkReply::NetworkError error_code); static QString networkErrorText(QNetworkReply::NetworkError error_code);

View file

@ -6,6 +6,9 @@
#include <QApplication> #include <QApplication>
#include <QRegExp> #include <QRegExp>
#include <QWebSettings> #include <QWebSettings>
#include <QProcess>
#include <QUrl>
#include <QDesktopServices>
QPointer<WebFactory> WebFactory::s_instance; QPointer<WebFactory> WebFactory::s_instance;
@ -29,6 +32,23 @@ void WebFactory::loadState() {
false); false);
} }
bool WebFactory::openUrlInExternalBrowser(const QString &url) {
if (Settings::instance()->value(APP_CFG_BROWSER,
"custom_external_browser",
false).toBool()) {
QString browser = Settings::instance()->value(APP_CFG_BROWSER,
"external_browser_executable").toString();
QString arguments = Settings::instance()->value(APP_CFG_BROWSER,
"external_browser_arguments",
"%1").toString();
return QProcess::startDetached(browser, QStringList() << arguments.arg(url));
}
else {
return QDesktopServices::openUrl(url);
}
}
void WebFactory::switchJavascript(bool enable, bool save_settings) { void WebFactory::switchJavascript(bool enable, bool save_settings) {
if (save_settings) { if (save_settings) {
Settings::instance()->setValue(APP_CFG_BROWSER, Settings::instance()->setValue(APP_CFG_BROWSER,

View file

@ -28,15 +28,19 @@ class WebFactory : public QObject {
QString escapeHtml(const QString &html); QString escapeHtml(const QString &html);
QString deEscapeHtml(const QString &text); QString deEscapeHtml(const QString &text);
// Singleton getter. // Switchers.
static WebFactory *instance();
public slots:
// Operations.
bool javascriptEnabled() const; bool javascriptEnabled() const;
bool pluginsEnabled() const; bool pluginsEnabled() const;
bool autoloadImages() const; bool autoloadImages() const;
// Singleton getter.
static WebFactory *instance();
public slots:
// Opens given string URL in external browser.
bool openUrlInExternalBrowser(const QString &url);
// Switchers.
void switchJavascript(bool enable, bool save_settings = true); void switchJavascript(bool enable, bool save_settings = true);
void switchPlugins(bool enable, bool save_settings = true); void switchPlugins(bool enable, bool save_settings = true);
void switchImages(bool enable, bool save_settings = true); void switchImages(bool enable, bool save_settings = true);

View file

@ -384,6 +384,7 @@ void FormMain::createConnections() {
// Menu "Help" connections. // Menu "Help" connections.
connect(m_ui->m_actionAboutGuard, SIGNAL(triggered()), this, SLOT(showAbout())); connect(m_ui->m_actionAboutGuard, SIGNAL(triggered()), this, SLOT(showAbout()));
connect(m_ui->m_actionCheckForUpdates, SIGNAL(triggered()), this, SLOT(showUpdates())); connect(m_ui->m_actionCheckForUpdates, SIGNAL(triggered()), this, SLOT(showUpdates()));
connect(m_ui->m_actionReportBug, SIGNAL(triggered()), this, SLOT(reportABug()));
// General connections. // General connections.
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit())); connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit()));
@ -478,6 +479,22 @@ void FormMain::showUpdates() {
SystemFactory::instance()->applicationCloseLock()->unlock(); SystemFactory::instance()->applicationCloseLock()->unlock();
} }
void FormMain::reportABug() {
if (!WebFactory::instance()->openUrlInExternalBrowser(APP_URL_ISSUES_NEW)) {
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot open external browser"),
tr("Cannot open external browser. Navigate to application website manually."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
QMessageBox::Warning,
tr("Cannot open external browser"),
tr("Cannot open external browser. Navigate to application website manually."));
}
}
}
void FormMain::showSettings() { void FormMain::showSettings() {
QPointer<FormSettings> form_pointer = new FormSettings(this); QPointer<FormSettings> form_pointer = new FormSettings(this);
form_pointer.data()->exec(); form_pointer.data()->exec();

View file

@ -113,6 +113,7 @@ class FormMain : public QMainWindow {
void showSettings(); void showSettings();
void showAbout(); void showAbout();
void showUpdates(); void showUpdates();
void reportABug();
private: private:
Ui::FormMain *m_ui; Ui::FormMain *m_ui;

View file

@ -62,6 +62,7 @@
<string>&amp;Help</string> <string>&amp;Help</string>
</property> </property>
<addaction name="m_actionCheckForUpdates"/> <addaction name="m_actionCheckForUpdates"/>
<addaction name="m_actionReportBug"/>
<addaction name="m_actionAboutGuard"/> <addaction name="m_actionAboutGuard"/>
</widget> </widget>
<widget class="QMenu" name="m_menuView"> <widget class="QMenu" name="m_menuView">
@ -491,6 +492,11 @@
<string>Auto-load &amp;images</string> <string>Auto-load &amp;images</string>
</property> </property>
</action> </action>
<action name="m_actionReportBug">
<property name="text">
<string>Report a &amp;bug...</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View file

@ -20,6 +20,7 @@
#include "core/defs.h" #include "core/defs.h"
#include "core/systemfactory.h" #include "core/systemfactory.h"
#include "core/networkfactory.h" #include "core/networkfactory.h"
#include "core/webfactory.h"
#include "gui/iconthemefactory.h" #include "gui/iconthemefactory.h"
#include "gui/messagebox.h" #include "gui/messagebox.h"
#include "gui/systemtrayicon.h" #include "gui/systemtrayicon.h"
@ -117,7 +118,7 @@ void FormUpdate::startUpdate() {
url_file = APP_URL; url_file = APP_URL;
} }
if (!NetworkFactory::openUrlInExternalBrowser(url_file)) { if (!WebFactory::instance()->openUrlInExternalBrowser(url_file)) {
if (SystemTrayIcon::isSystemTrayActivated()) { if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot update application"), SystemTrayIcon::instance()->showMessage(tr("Cannot update application"),
tr("Cannot navigate to installation file. Check new installation downloads " tr("Cannot navigate to installation file. Check new installation downloads "

View file

@ -21,6 +21,7 @@
#include "core/messagesmodel.h" #include "core/messagesmodel.h"
#include "core/settings.h" #include "core/settings.h"
#include "core/networkfactory.h" #include "core/networkfactory.h"
#include "core/webfactory.h"
#include "gui/formmain.h" #include "gui/formmain.h"
#include "gui/messagebox.h" #include "gui/messagebox.h"
@ -243,7 +244,7 @@ void MessagesView::openSelectedSourceArticlesExternally() {
foreach (const QModelIndex &index, selectionModel()->selectedRows()) { foreach (const QModelIndex &index, selectionModel()->selectedRows()) {
QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()).m_url; QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()).m_url;
if (!NetworkFactory::openUrlInExternalBrowser(link)) { if (!WebFactory::instance()->openUrlInExternalBrowser(link)) {
MessageBox::show(this, MessageBox::show(this,
QMessageBox::Critical, QMessageBox::Critical,
tr("Problem with starting external web browser"), tr("Problem with starting external web browser"),