Save work.
This commit is contained in:
parent
79e1c9d564
commit
cad2fffa87
@ -28,25 +28,20 @@ if [ $# -eq 0 ]; then
|
||||
fi
|
||||
|
||||
ASTYLE_CMD="astyle"
|
||||
ASTYLE_RC=".astylerc"
|
||||
ASTYLE_RC="$(dirname $0)/.astylerc"
|
||||
|
||||
# Check all args.
|
||||
for dir in "$@"; do
|
||||
if [ ! -d "${dir}" ]; then
|
||||
echo "\"${dir}\" is not a directory..."
|
||||
usage
|
||||
fi
|
||||
if [ ! -d "${dir}" ]; then
|
||||
echo "\"${dir}\" is not a directory..."
|
||||
usage
|
||||
fi
|
||||
done
|
||||
|
||||
# Run the thing.
|
||||
for dir in "$@"; do
|
||||
pushd "${dir}"
|
||||
|
||||
if [ ! -r "$ASTYLE_RC" ]; then
|
||||
echo "No $ASTYLE_RC in pwd \"$PWD\"..."
|
||||
continue
|
||||
fi
|
||||
|
||||
|
||||
for f in $(find . \
|
||||
-name '*.c' \
|
||||
-o -name '*.cc' \
|
||||
|
@ -186,7 +186,8 @@ win32 {
|
||||
}
|
||||
}
|
||||
|
||||
DISTFILES += resources/scripts/astyle/.astylerc
|
||||
DISTFILES += resources/scripts/astyle/.astylerc \
|
||||
resources/scripts/uncrustify/uncrustify.cfg
|
||||
|
||||
MOC_DIR = $$OUT_PWD/moc
|
||||
RCC_DIR = $$OUT_PWD/rcc
|
||||
|
@ -29,7 +29,7 @@
|
||||
DynamicShortcutsWidget::DynamicShortcutsWidget(QWidget* parent) : QWidget(parent) {
|
||||
// Create layout for this control and set is as active.
|
||||
m_layout = new QGridLayout(this);
|
||||
m_layout->setMargin(0);
|
||||
m_layout->setMargin(0);
|
||||
setLayout(m_layout);
|
||||
}
|
||||
|
||||
|
@ -20,22 +20,20 @@
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
#include "miscellaneous/settingsproperties.h"
|
||||
#include "gui/guiutilities.h"
|
||||
#include "exceptions/applicationexception.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
|
||||
FormAbout::FormAbout(QWidget* parent) : QDialog(parent), m_ui(new Ui::FormAbout()) {
|
||||
m_ui->setupUi(this);
|
||||
// Set flags and attributes.
|
||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
|
||||
setWindowIcon(qApp->icons()->fromTheme(QSL("help-about")));
|
||||
//: About RSS Guard dialog title.
|
||||
setWindowTitle(tr("About %1").arg(APP_NAME));
|
||||
m_ui->m_lblIcon->setPixmap(QPixmap(APP_ICON_PATH));
|
||||
// Load information from embedded text files.
|
||||
FormAbout::FormAbout(QWidget* parent) : QDialog(parent) {
|
||||
m_ui.setupUi(this);
|
||||
m_ui.m_lblIcon->setPixmap(QPixmap(APP_ICON_PATH));
|
||||
|
||||
GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("help-about")), tr("About %1").arg(APP_NAME));
|
||||
|
||||
loadLicenseAndInformation();
|
||||
// Load additional paths information.
|
||||
loadSettingsAndPaths();
|
||||
}
|
||||
|
||||
@ -45,78 +43,72 @@ FormAbout::~FormAbout() {
|
||||
|
||||
void FormAbout::loadSettingsAndPaths() {
|
||||
if (qApp->settings()->type() == SettingsProperties::Portable) {
|
||||
m_ui->m_txtPathsSettingsType->setText(tr("FULLY portable"));
|
||||
m_ui.m_txtPathsSettingsType->setText(tr("FULLY portable"));
|
||||
}
|
||||
|
||||
else {
|
||||
m_ui->m_txtPathsSettingsType->setText(tr("NOT portable"));
|
||||
m_ui.m_txtPathsSettingsType->setText(tr("NOT portable"));
|
||||
}
|
||||
|
||||
m_ui->m_txtPathsDatabaseRoot->setText(QDir::toNativeSeparators(qApp->getUserDataPath() +
|
||||
QDir::separator() +
|
||||
QString(APP_DB_SQLITE_PATH)));
|
||||
m_ui->m_txtPathsSettingsFile->setText(QDir::toNativeSeparators(qApp->settings()->fileName()));
|
||||
m_ui->m_txtPathsSkinsRoot->setText(QDir::toNativeSeparators(qApp->skins()->getUserSkinBaseFolder()));
|
||||
m_ui.m_txtPathsDatabaseRoot->setText(QDir::toNativeSeparators(qApp->userDataPath() +
|
||||
QDir::separator() +
|
||||
QString(APP_DB_SQLITE_PATH)));
|
||||
m_ui.m_txtPathsSettingsFile->setText(QDir::toNativeSeparators(qApp->settings()->fileName()));
|
||||
m_ui.m_txtPathsSkinsRoot->setText(QDir::toNativeSeparators(qApp->skins()->customSkinBaseFolder()));
|
||||
}
|
||||
|
||||
void FormAbout::loadLicenseAndInformation() {
|
||||
QFile file;
|
||||
file.setFileName(APP_INFO_PATH + QL1S("/COPYING_GNU_GPL_HTML"));
|
||||
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
m_ui->m_txtLicenseGnu->setText(QString::fromUtf8(file.readAll()));
|
||||
try {
|
||||
m_ui.m_txtLicenseGnu->setText(IOFactory::readTextFile(APP_INFO_PATH + QL1S("/COPYING_GNU_GPL_HTML")));
|
||||
}
|
||||
catch (...) {
|
||||
m_ui.m_txtLicenseGnu->setText(tr("License not found."));
|
||||
}
|
||||
|
||||
else {
|
||||
m_ui->m_txtLicenseGnu->setText(tr("License not found."));
|
||||
try {
|
||||
m_ui.m_txtLicenseGnu->setText(IOFactory::readTextFile(APP_INFO_PATH + QL1S("/COPYING_GNU_GPL_HTML")));
|
||||
}
|
||||
catch (...) {
|
||||
m_ui.m_txtLicenseGnu->setText(tr("License not found."));
|
||||
}
|
||||
|
||||
file.close();
|
||||
file.setFileName(APP_INFO_PATH + QL1S("/COPYING_BSD"));
|
||||
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
m_ui->m_txtLicenseBsd->setText(QString::fromUtf8(file.readAll()));
|
||||
try {
|
||||
m_ui.m_txtChangelog->setText(IOFactory::readTextFile(APP_INFO_PATH + QL1S("/CHANGELOG")));
|
||||
}
|
||||
catch (...) {
|
||||
m_ui.m_txtChangelog->setText(tr("Changelog not found."));
|
||||
}
|
||||
|
||||
else {
|
||||
m_ui->m_txtLicenseBsd->setText(tr("License not found."));
|
||||
try {
|
||||
m_ui.m_txtLicenseBsd->setText(IOFactory::readTextFile(APP_INFO_PATH + QL1S("/COPYING_BSD")));
|
||||
}
|
||||
catch (...) {
|
||||
m_ui.m_txtLicenseBsd->setText(tr("License not found."));
|
||||
}
|
||||
|
||||
file.close();
|
||||
file.setFileName(APP_INFO_PATH + QL1S("/CHANGELOG"));
|
||||
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
m_ui->m_txtChangelog->setText(QString::fromUtf8(file.readAll()));
|
||||
}
|
||||
|
||||
else {
|
||||
m_ui->m_txtChangelog->setText(tr("Changelog not found."));
|
||||
}
|
||||
|
||||
file.close();
|
||||
// Set other informative texts.
|
||||
m_ui->m_lblDesc->setText(tr("<b>%8</b><br>"
|
||||
"<b>Version:</b> %1 (built on %2/%3)<br>"
|
||||
"<b>Revision:</b> %4<br>"
|
||||
"<b>Build date:</b> %5<br>"
|
||||
"<b>Qt:</b> %6 (compiled against %7)<br>").arg(qApp->applicationVersion(),
|
||||
APP_SYSTEM_NAME,
|
||||
APP_SYSTEM_VERSION,
|
||||
APP_REVISION,
|
||||
TextFactory::parseDateTime(QString("%1 %2").arg(__DATE__,
|
||||
__TIME__)).toString(Qt::DefaultLocaleShortDate),
|
||||
qVersion(),
|
||||
QT_VERSION_STR,
|
||||
APP_NAME));
|
||||
m_ui->m_txtInfo->setText(tr("<body>%5 is a (very) tiny feed reader."
|
||||
"<br><br>This software is distributed under the terms of GNU General Public License, version 3."
|
||||
"<br><br>Contacts:"
|
||||
"<ul><li><a href=\"mailto://%1\">%1</a> ~e-mail</li>"
|
||||
"<li><a href=\"%2\">%2</a> ~website</li></ul>"
|
||||
"You can obtain source code for %5 from its website."
|
||||
"<br><br><br>Copyright (C) 2011-%3 %4</body>").arg(APP_EMAIL,
|
||||
APP_URL,
|
||||
QString::number(QDateTime::currentDateTime().date().year()),
|
||||
APP_AUTHOR,
|
||||
APP_NAME));
|
||||
m_ui.m_lblDesc->setText(tr("<b>%8</b><br>"
|
||||
"<b>Version:</b> %1 (built on %2/%3)<br>"
|
||||
"<b>Revision:</b> %4<br>"
|
||||
"<b>Build date:</b> %5<br>"
|
||||
"<b>Qt:</b> %6 (compiled against %7)<br>").arg(qApp->applicationVersion(),
|
||||
APP_SYSTEM_NAME,
|
||||
APP_SYSTEM_VERSION,
|
||||
APP_REVISION,
|
||||
TextFactory::parseDateTime(QString("%1 %2").arg(__DATE__,
|
||||
__TIME__)).toString(Qt::DefaultLocaleShortDate),
|
||||
qVersion(),
|
||||
QT_VERSION_STR,
|
||||
APP_NAME));
|
||||
m_ui.m_txtInfo->setText(tr("<body>%5 is a (very) tiny feed reader."
|
||||
"<br><br>This software is distributed under the terms of GNU General Public License, version 3."
|
||||
"<br><br>Contacts:"
|
||||
"<ul><li><a href=\"mailto://%1\">%1</a> ~e-mail</li>"
|
||||
"<li><a href=\"%2\">%2</a> ~website</li></ul>"
|
||||
"You can obtain source code for %5 from its website."
|
||||
"<br><br><br>Copyright (C) 2011-%3 %4</body>").arg(APP_EMAIL,
|
||||
APP_URL,
|
||||
QString::number(QDateTime::currentDateTime().date().year()),
|
||||
APP_AUTHOR,
|
||||
APP_NAME));
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class FormAbout : public QDialog {
|
||||
void loadLicenseAndInformation();
|
||||
void loadSettingsAndPaths();
|
||||
|
||||
QScopedPointer<Ui::FormAbout> m_ui;
|
||||
Ui::FormAbout m_ui;
|
||||
};
|
||||
|
||||
#endif // FORMABOUT_H
|
||||
|
@ -64,19 +64,19 @@
|
||||
FormMain::FormMain(QWidget* parent, Qt::WindowFlags f)
|
||||
: QMainWindow(parent, f), m_ui(new Ui::FormMain) {
|
||||
m_ui->setupUi(this);
|
||||
qApp->setMainForm(this);
|
||||
qApp->setMainForm(this);
|
||||
|
||||
#if defined (USE_WEBENGINE)
|
||||
m_ui->m_menuWebBrowserTabs->addAction(AdBlockManager::instance()->adBlockIcon());
|
||||
m_ui->m_menuWebBrowserTabs->addAction(qApp->web()->engineSettingsAction());
|
||||
m_ui->m_menuWebBrowserTabs->addAction(AdBlockManager::instance()->adBlockIcon());
|
||||
m_ui->m_menuWebBrowserTabs->addAction(qApp->web()->engineSettingsAction());
|
||||
#endif
|
||||
|
||||
// Add these actions to the list of actions of the main window.
|
||||
// This allows to use actions via shortcuts
|
||||
// even if main menu is not visible.
|
||||
addActions(qApp->userActions());
|
||||
addActions(qApp->userActions());
|
||||
|
||||
setStatusBar(m_statusBar = new StatusBar(this));
|
||||
setStatusBar(m_statusBar = new StatusBar(this));
|
||||
|
||||
// Prepare main window and tabs.
|
||||
prepareMenus();
|
||||
@ -85,7 +85,7 @@ FormMain::FormMain(QWidget* parent, Qt::WindowFlags f)
|
||||
tabWidget()->feedMessageViewer()->feedsToolBar()->loadSavedActions();
|
||||
tabWidget()->feedMessageViewer()->messagesToolBar()->loadSavedActions();
|
||||
|
||||
// Establish connections.
|
||||
// Establish connections.
|
||||
createConnections();
|
||||
updateMessageButtonsAvailability();
|
||||
updateFeedButtonsAvailability();
|
||||
@ -582,27 +582,39 @@ void FormMain::createConnections() {
|
||||
connect(m_ui->m_menuAccounts, &QMenu::aboutToShow, this, &FormMain::updateAccountsMenu);
|
||||
connect(m_ui->m_actionServiceDelete, &QAction::triggered, m_ui->m_actionDeleteSelectedItem, &QAction::triggered);
|
||||
connect(m_ui->m_actionServiceEdit, &QAction::triggered, m_ui->m_actionEditSelectedItem, &QAction::triggered);
|
||||
|
||||
// Menu "File" connections.
|
||||
connect(m_ui->m_actionBackupDatabaseSettings, &QAction::triggered, this, &FormMain::backupDatabaseSettings);
|
||||
connect(m_ui->m_actionRestoreDatabaseSettings, &QAction::triggered, this, &FormMain::restoreDatabaseSettings);
|
||||
connect(m_ui->m_actionQuit, &QAction::triggered, qApp, &Application::quit);
|
||||
connect(m_ui->m_actionServiceAdd, &QAction::triggered, this, &FormMain::showAddAccountDialog);
|
||||
connect(m_ui->m_actionRestart, &QAction::triggered, qApp, &Application::restart);
|
||||
|
||||
// Menu "View" connections.
|
||||
connect(m_ui->m_actionFullscreen, &QAction::toggled, this, &FormMain::switchFullscreenMode);
|
||||
connect(m_ui->m_actionSwitchMainMenu, &QAction::toggled, m_ui->m_menuBar, &QMenuBar::setVisible);
|
||||
connect(m_ui->m_actionSwitchMainWindow, &QAction::triggered, this, &FormMain::switchVisibility);
|
||||
connect(m_ui->m_actionSwitchStatusBar, &QAction::toggled, statusBar(), &StatusBar::setVisible);
|
||||
|
||||
// Menu "Tools" connections.
|
||||
connect(m_ui->m_actionSettings, &QAction::triggered, this, &FormMain::showSettings);
|
||||
connect(m_ui->m_actionSettings, &QAction::triggered, [this]() {
|
||||
FormSettings(*this).exec();
|
||||
});
|
||||
|
||||
connect(m_ui->m_actionDownloadManager, &QAction::triggered, m_ui->m_tabWidget, &TabWidget::showDownloadManager);
|
||||
connect(m_ui->m_actionCleanupDatabase, &QAction::triggered, this, &FormMain::showDbCleanupAssistant);
|
||||
|
||||
// Menu "Help" connections.
|
||||
connect(m_ui->m_actionAboutGuard, &QAction::triggered, this, &FormMain::showAbout);
|
||||
connect(m_ui->m_actionCheckForUpdates, &QAction::triggered, this, &FormMain::showUpdates);
|
||||
connect(m_ui->m_actionAboutGuard, &QAction::triggered, [this]() {
|
||||
FormAbout(this).exec();
|
||||
});
|
||||
connect(m_ui->m_actionCheckForUpdates, &QAction::triggered, [this]() {
|
||||
FormUpdate(this).exec();
|
||||
});
|
||||
connect(m_ui->m_actionReportBug, &QAction::triggered, this, &FormMain::reportABug);
|
||||
connect(m_ui->m_actionDonate, &QAction::triggered, this, &FormMain::donate);
|
||||
connect(m_ui->m_actionDisplayWiki, &QAction::triggered, this, &FormMain::showWiki);
|
||||
|
||||
// Tab widget connections.
|
||||
connect(m_ui->m_actionTabsCloseAllExceptCurrent, &QAction::triggered, m_ui->m_tabWidget, &TabWidget::closeAllTabsExceptCurrent);
|
||||
connect(m_ui->m_actionTabsCloseAll, &QAction::triggered, m_ui->m_tabWidget, &TabWidget::closeAllTabs);
|
||||
@ -617,6 +629,7 @@ void FormMain::createConnections() {
|
||||
connect(qApp->feedReader(), &FeedReader::feedUpdatesStarted, this, &FormMain::onFeedUpdatesStarted);
|
||||
connect(qApp->feedReader(), &FeedReader::feedUpdatesProgress, this, &FormMain::onFeedUpdatesProgress);
|
||||
connect(qApp->feedReader(), &FeedReader::feedUpdatesFinished, this, &FormMain::onFeedUpdatesFinished);
|
||||
|
||||
// Toolbar forwardings.
|
||||
connect(m_ui->m_actionAddFeedIntoSelectedAccount, &QAction::triggered,
|
||||
tabWidget()->feedMessageViewer()->feedsView(), &FeedsView::addFeedIntoSelectedAccount);
|
||||
@ -694,10 +707,10 @@ void FormMain::backupDatabaseSettings() {
|
||||
}
|
||||
|
||||
void FormMain::restoreDatabaseSettings() {
|
||||
QScopedPointer<FormRestoreDatabaseSettings> form(new FormRestoreDatabaseSettings(this));
|
||||
form->exec();
|
||||
FormRestoreDatabaseSettings form(*this);
|
||||
form.exec();
|
||||
|
||||
if (form->shouldRestart()) {
|
||||
if (form.shouldRestart()) {
|
||||
qApp->restart();
|
||||
}
|
||||
}
|
||||
@ -722,18 +735,8 @@ void FormMain::changeEvent(QEvent* event) {
|
||||
QMainWindow::changeEvent(event);
|
||||
}
|
||||
|
||||
void FormMain::showAbout() {
|
||||
QScopedPointer<FormAbout> form_pointer(new FormAbout(this));
|
||||
form_pointer->exec();
|
||||
}
|
||||
|
||||
void FormMain::showUpdates() {
|
||||
QScopedPointer<FormUpdate> form_update(new FormUpdate(this));
|
||||
form_update->exec();
|
||||
}
|
||||
|
||||
void FormMain::showWiki() {
|
||||
if (!qApp->web()->openUrlInExternalBrowser(APP_URL_WIKI)) {
|
||||
if (!qApp->web()->openUrlInExternalBrowser(APP_URL_WIKI)) {
|
||||
qApp->showGuiMessage(tr("Cannot open external browser"),
|
||||
tr("Cannot open external browser. Navigate to application website manually."),
|
||||
QSystemTrayIcon::Warning, this, true);
|
||||
@ -748,7 +751,7 @@ void FormMain::showAddAccountDialog() {
|
||||
}
|
||||
|
||||
void FormMain::reportABug() {
|
||||
if (!qApp->web()->openUrlInExternalBrowser(QSL(APP_URL_ISSUES_NEW))) {
|
||||
if (!qApp->web()->openUrlInExternalBrowser(QSL(APP_URL_ISSUES_NEW))) {
|
||||
qApp->showGuiMessage(tr("Cannot open external browser"),
|
||||
tr("Cannot open external browser. Navigate to application website manually."),
|
||||
QSystemTrayIcon::Warning, this, true);
|
||||
@ -756,14 +759,9 @@ void FormMain::reportABug() {
|
||||
}
|
||||
|
||||
void FormMain::donate() {
|
||||
if (!qApp->web()->openUrlInExternalBrowser(QSL(APP_DONATE_URL))) {
|
||||
if (!qApp->web()->openUrlInExternalBrowser(QSL(APP_DONATE_URL))) {
|
||||
qApp->showGuiMessage(tr("Cannot open external browser"),
|
||||
tr("Cannot open external browser. Navigate to application website manually."),
|
||||
QSystemTrayIcon::Warning, this, true);
|
||||
}
|
||||
}
|
||||
|
||||
void FormMain::showSettings() {
|
||||
QScopedPointer<FormSettings> form_pointer(new FormSettings(this));
|
||||
form_pointer->exec();
|
||||
}
|
||||
|
@ -80,9 +80,6 @@ class FormMain : public QMainWindow {
|
||||
// Displays various dialogs.
|
||||
void backupDatabaseSettings();
|
||||
void restoreDatabaseSettings();
|
||||
void showSettings();
|
||||
void showAbout();
|
||||
void showUpdates();
|
||||
void showWiki();
|
||||
void showAddAccountDialog();
|
||||
void showDbCleanupAssistant();
|
||||
|
@ -25,21 +25,24 @@
|
||||
#include "QFileDialog"
|
||||
|
||||
|
||||
FormRestoreDatabaseSettings::FormRestoreDatabaseSettings(QWidget* parent)
|
||||
: QDialog(parent), m_ui(new Ui::FormRestoreDatabaseSettings), m_shouldRestart(false) {
|
||||
m_ui->setupUi(this);
|
||||
m_btnRestart = m_ui->m_buttonBox->addButton(tr("Restart"), QDialogButtonBox::ActionRole);
|
||||
m_ui->m_lblResult->setStatus(WidgetWithStatus::Warning, tr("No operation executed yet."), tr("No operation executed yet."));
|
||||
FormRestoreDatabaseSettings::FormRestoreDatabaseSettings(QWidget& parent)
|
||||
: QDialog(&parent), m_shouldRestart(false) {
|
||||
m_ui.setupUi(this);
|
||||
|
||||
m_btnRestart = m_ui.m_buttonBox->addButton(tr("Restart"), QDialogButtonBox::ActionRole);
|
||||
m_ui.m_lblResult->setStatus(WidgetWithStatus::Warning, tr("No operation executed yet."), tr("No operation executed yet."));
|
||||
|
||||
setWindowIcon(qApp->icons()->fromTheme(QSL("document-import")));
|
||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
|
||||
|
||||
connect(m_btnRestart, &QPushButton::clicked, this, [ = ]() {
|
||||
m_shouldRestart = true;
|
||||
close();
|
||||
});
|
||||
connect(m_ui->m_btnSelectFolder, SIGNAL(clicked()), this, SLOT(selectFolder()));
|
||||
connect(m_ui->m_groupDatabase, SIGNAL(toggled(bool)), this, SLOT(checkOkButton()));
|
||||
connect(m_ui->m_groupSettings, SIGNAL(toggled(bool)), this, SLOT(checkOkButton()));
|
||||
connect(m_ui->m_buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(performRestoration()));
|
||||
connect(m_ui.m_btnSelectFolder, SIGNAL(clicked()), this, SLOT(selectFolder()));
|
||||
connect(m_ui.m_groupDatabase, SIGNAL(toggled(bool)), this, SLOT(checkOkButton()));
|
||||
connect(m_ui.m_groupSettings, SIGNAL(toggled(bool)), this, SLOT(checkOkButton()));
|
||||
connect(m_ui.m_buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(performRestoration()));
|
||||
selectFolder(qApp->getDocumentsFolderPath());
|
||||
}
|
||||
|
||||
@ -48,35 +51,34 @@ FormRestoreDatabaseSettings::~FormRestoreDatabaseSettings() {
|
||||
}
|
||||
|
||||
void FormRestoreDatabaseSettings::performRestoration() {
|
||||
m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
m_ui.m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
|
||||
try {
|
||||
qApp->restoreDatabaseSettings(m_ui->m_groupDatabase->isChecked(),
|
||||
m_ui->m_groupSettings->isChecked(),
|
||||
m_ui->m_listDatabase->currentRow() >= 0 ?
|
||||
m_ui->m_listDatabase->currentItem()->data(Qt::UserRole).toString() :
|
||||
qApp->restoreDatabaseSettings(m_ui.m_groupDatabase->isChecked(),
|
||||
m_ui.m_groupSettings->isChecked(),
|
||||
m_ui.m_listDatabase->currentRow() >= 0 ?
|
||||
m_ui.m_listDatabase->currentItem()->data(Qt::UserRole).toString() :
|
||||
QString(),
|
||||
m_ui->m_listSettings->currentRow() >= 0 ?
|
||||
m_ui->m_listSettings->currentItem()->data(Qt::UserRole).toString() :
|
||||
m_ui.m_listSettings->currentRow() >= 0 ?
|
||||
m_ui.m_listSettings->currentItem()->data(Qt::UserRole).toString() :
|
||||
QString());
|
||||
m_btnRestart->setEnabled(true);
|
||||
m_ui->m_lblResult->setStatus(WidgetWithStatus::Ok, tr("Restoration was initiated. Restart to proceed."),
|
||||
tr("You need to restart application for restoration process to finish."));
|
||||
m_ui.m_lblResult->setStatus(WidgetWithStatus::Ok, tr("Restoration was initiated. Restart to proceed."),
|
||||
tr("You need to restart application for restoration process to finish."));
|
||||
}
|
||||
|
||||
catch (const ApplicationException& ex) {
|
||||
m_ui->m_lblResult->setStatus(WidgetWithStatus::Error, ex.message(),
|
||||
tr("Database and/or settings were not copied to restoration directory successully."));
|
||||
m_ui.m_lblResult->setStatus(WidgetWithStatus::Error, ex.message(),
|
||||
tr("Database and/or settings were not copied to restoration directory successully."));
|
||||
}
|
||||
}
|
||||
|
||||
void FormRestoreDatabaseSettings::checkOkButton() {
|
||||
m_btnRestart->setEnabled(false);
|
||||
m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!m_ui->m_lblSelectFolder->label()->text().isEmpty() &&
|
||||
((m_ui->m_groupDatabase->isChecked() &&
|
||||
m_ui->m_listDatabase->currentRow() >= 0) ||
|
||||
(m_ui->m_groupSettings->isChecked() &&
|
||||
m_ui->m_listSettings->currentRow() >= 0)));
|
||||
m_ui.m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!m_ui.m_lblSelectFolder->label()->text().isEmpty() &&
|
||||
((m_ui.m_groupDatabase->isChecked() &&
|
||||
m_ui.m_listDatabase->currentRow() >= 0) ||
|
||||
(m_ui.m_groupSettings->isChecked() &&
|
||||
m_ui.m_listSettings->currentRow() >= 0)));
|
||||
}
|
||||
|
||||
void FormRestoreDatabaseSettings::selectFolderWithGui() {
|
||||
@ -85,12 +87,12 @@ void FormRestoreDatabaseSettings::selectFolderWithGui() {
|
||||
|
||||
void FormRestoreDatabaseSettings::selectFolder(QString folder) {
|
||||
if (folder.isEmpty()) {
|
||||
folder = QFileDialog::getExistingDirectory(this, tr("Select source directory"), m_ui->m_lblSelectFolder->label()->text());
|
||||
folder = QFileDialog::getExistingDirectory(this, tr("Select source directory"), m_ui.m_lblSelectFolder->label()->text());
|
||||
}
|
||||
|
||||
if (!folder.isEmpty()) {
|
||||
m_ui->m_lblSelectFolder->setStatus(WidgetWithStatus::Ok, QDir::toNativeSeparators(folder),
|
||||
tr("Good source directory is specified."));
|
||||
m_ui.m_lblSelectFolder->setStatus(WidgetWithStatus::Ok, QDir::toNativeSeparators(folder),
|
||||
tr("Good source directory is specified."));
|
||||
}
|
||||
|
||||
else {
|
||||
@ -108,29 +110,29 @@ void FormRestoreDatabaseSettings::selectFolder(QString folder) {
|
||||
QDir::Files | QDir::NoDotAndDotDot | QDir::Readable |
|
||||
QDir::CaseSensitive | QDir::NoSymLinks,
|
||||
QDir::Name);
|
||||
m_ui->m_listDatabase->clear();
|
||||
m_ui->m_listSettings->clear();
|
||||
m_ui.m_listDatabase->clear();
|
||||
m_ui.m_listSettings->clear();
|
||||
|
||||
foreach (const QFileInfo& database_file, available_databases) {
|
||||
QListWidgetItem* database_item = new QListWidgetItem(database_file.fileName(), m_ui->m_listDatabase);
|
||||
QListWidgetItem* database_item = new QListWidgetItem(database_file.fileName(), m_ui.m_listDatabase);
|
||||
database_item->setData(Qt::UserRole, database_file.absoluteFilePath());
|
||||
database_item->setToolTip(QDir::toNativeSeparators(database_file.absoluteFilePath()));
|
||||
}
|
||||
|
||||
foreach (const QFileInfo& settings_file, available_settings) {
|
||||
QListWidgetItem* settings_item = new QListWidgetItem(settings_file.fileName(), m_ui->m_listSettings);
|
||||
QListWidgetItem* settings_item = new QListWidgetItem(settings_file.fileName(), m_ui.m_listSettings);
|
||||
settings_item->setData(Qt::UserRole, settings_file.absoluteFilePath());
|
||||
settings_item->setToolTip(QDir::toNativeSeparators(settings_file.absoluteFilePath()));
|
||||
}
|
||||
|
||||
if (!available_databases.isEmpty()) {
|
||||
m_ui->m_listDatabase->setCurrentRow(0);
|
||||
m_ui.m_listDatabase->setCurrentRow(0);
|
||||
}
|
||||
|
||||
if (!available_settings.isEmpty()) {
|
||||
m_ui->m_listSettings->setCurrentRow(0);
|
||||
m_ui.m_listSettings->setCurrentRow(0);
|
||||
}
|
||||
|
||||
m_ui->m_groupDatabase->setChecked(!available_databases.isEmpty());
|
||||
m_ui->m_groupSettings->setChecked(!available_settings.isEmpty());
|
||||
m_ui.m_groupDatabase->setChecked(!available_databases.isEmpty());
|
||||
m_ui.m_groupSettings->setChecked(!available_settings.isEmpty());
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class FormRestoreDatabaseSettings : public QDialog {
|
||||
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
explicit FormRestoreDatabaseSettings(QWidget* parent = 0);
|
||||
explicit FormRestoreDatabaseSettings(QWidget& parent);
|
||||
virtual ~FormRestoreDatabaseSettings();
|
||||
|
||||
bool shouldRestart() const {
|
||||
@ -42,7 +42,7 @@ class FormRestoreDatabaseSettings : public QDialog {
|
||||
void selectFolder(QString folder = QString());
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::FormRestoreDatabaseSettings> m_ui;
|
||||
Ui::FormRestoreDatabaseSettings m_ui;
|
||||
QPushButton* m_btnRestart;
|
||||
|
||||
bool m_shouldRestart;
|
||||
|
@ -33,27 +33,30 @@
|
||||
#include "gui/settings/settingsshortcuts.h"
|
||||
|
||||
|
||||
FormSettings::FormSettings(QWidget* parent) : QDialog(parent), m_panels(QList<SettingsPanel*>()), m_ui(new Ui::FormSettings),
|
||||
m_settings(qApp->settings()) {
|
||||
m_ui->setupUi(this);
|
||||
FormSettings::FormSettings(QWidget& parent)
|
||||
: QDialog(&parent), m_panels(QList<SettingsPanel*>()), m_settings(*qApp->settings()) {
|
||||
m_ui.setupUi(this);
|
||||
|
||||
// Set flags and attributes.
|
||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint);
|
||||
setWindowIcon(qApp->icons()->fromTheme(QSL("emblem-system")));
|
||||
m_btnApply = m_ui->m_buttonBox->button(QDialogButtonBox::Apply);
|
||||
m_btnApply = m_ui.m_buttonBox->button(QDialogButtonBox::Apply);
|
||||
m_btnApply->setEnabled(false);
|
||||
|
||||
// Establish needed connections.
|
||||
connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &FormSettings::saveSettings);
|
||||
connect(m_ui->m_buttonBox, &QDialogButtonBox::rejected, this, &FormSettings::cancelSettings);
|
||||
connect(m_ui.m_buttonBox, &QDialogButtonBox::accepted, this, &FormSettings::saveSettings);
|
||||
connect(m_ui.m_buttonBox, &QDialogButtonBox::rejected, this, &FormSettings::cancelSettings);
|
||||
connect(m_btnApply, &QPushButton::clicked, this, &FormSettings::applySettings);
|
||||
addSettingsPanel(new SettingsGeneral(m_settings, this));
|
||||
addSettingsPanel(new SettingsDatabase(m_settings, this));
|
||||
addSettingsPanel(new SettingsGui(m_settings, this));
|
||||
addSettingsPanel(new SettingsLocalization(m_settings, this));
|
||||
addSettingsPanel(new SettingsShortcuts(m_settings, this));
|
||||
addSettingsPanel(new SettingsBrowserMail(m_settings, this));
|
||||
addSettingsPanel(new SettingsDownloads(m_settings, this));
|
||||
addSettingsPanel(new SettingsFeedsMessages(m_settings, this));
|
||||
m_ui->m_listSettings->setCurrentRow(0);
|
||||
addSettingsPanel(new SettingsGeneral(&m_settings, this));
|
||||
addSettingsPanel(new SettingsDatabase(&m_settings, this));
|
||||
addSettingsPanel(new SettingsGui(&m_settings, this));
|
||||
addSettingsPanel(new SettingsLocalization(&m_settings, this));
|
||||
addSettingsPanel(new SettingsShortcuts(&m_settings, this));
|
||||
addSettingsPanel(new SettingsBrowserMail(&m_settings, this));
|
||||
addSettingsPanel(new SettingsDownloads(&m_settings, this));
|
||||
addSettingsPanel(new SettingsFeedsMessages(&m_settings, this));
|
||||
|
||||
m_ui.m_listSettings->setCurrentRow(0);
|
||||
}
|
||||
|
||||
FormSettings::~FormSettings() {
|
||||
@ -67,7 +70,7 @@ void FormSettings::saveSettings() {
|
||||
|
||||
void FormSettings::applySettings() {
|
||||
// Save all settings.
|
||||
m_settings->checkSettings();
|
||||
m_settings.checkSettings();
|
||||
QStringList panels_for_restart;
|
||||
|
||||
foreach (SettingsPanel* panel, m_panels) {
|
||||
@ -130,10 +133,11 @@ void FormSettings::cancelSettings() {
|
||||
}
|
||||
|
||||
void FormSettings::addSettingsPanel(SettingsPanel* panel) {
|
||||
m_ui->m_listSettings->addItem(panel->title());
|
||||
m_ui.m_listSettings->addItem(panel->title());
|
||||
m_panels.append(panel);
|
||||
m_ui->m_stackedSettings->addWidget(panel);
|
||||
m_ui.m_stackedSettings->addWidget(panel);
|
||||
panel->loadSettings();
|
||||
|
||||
connect(panel, &SettingsPanel::settingsChanged, [this]() {
|
||||
m_btnApply->setEnabled(true);
|
||||
});
|
||||
|
@ -31,7 +31,7 @@ class FormSettings : public QDialog {
|
||||
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
explicit FormSettings(QWidget* parent = 0);
|
||||
explicit FormSettings(QWidget& parent);
|
||||
virtual ~FormSettings();
|
||||
|
||||
private slots:
|
||||
@ -43,10 +43,11 @@ class FormSettings : public QDialog {
|
||||
private:
|
||||
void addSettingsPanel(SettingsPanel* panel);
|
||||
|
||||
QList<SettingsPanel*> m_panels;
|
||||
QScopedPointer<Ui::FormSettings> m_ui;
|
||||
Ui::FormSettings m_ui;
|
||||
QPushButton* m_btnApply;
|
||||
Settings* m_settings;
|
||||
|
||||
QList<SettingsPanel*> m_panels;
|
||||
Settings& m_settings;
|
||||
};
|
||||
|
||||
#endif // FORMSETTINGS_H
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "network-web/webfactory.h"
|
||||
#include "network-web/downloader.h"
|
||||
#include "gui/messagebox.h"
|
||||
#include "gui/guiutilities.h"
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QProcess>
|
||||
@ -34,21 +35,24 @@
|
||||
|
||||
|
||||
FormUpdate::FormUpdate(QWidget* parent)
|
||||
: QDialog(parent), m_downloader(nullptr), m_readyToInstall(false), m_ui(new Ui::FormUpdate), m_lastDownloadedBytes(0) {
|
||||
m_ui->setupUi(this);
|
||||
m_ui->m_lblCurrentRelease->setText(APP_VERSION);
|
||||
m_ui->m_tabInfo->removeTab(1);
|
||||
: QDialog(parent) {
|
||||
m_ui.setupUi(this);
|
||||
m_ui.m_lblCurrentRelease->setText(APP_VERSION);
|
||||
m_ui.m_tabInfo->removeTab(1);
|
||||
m_ui.m_buttonBox->setEnabled(false);
|
||||
|
||||
// Set flags and attributes.
|
||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint);
|
||||
setWindowIcon(qApp->icons()->fromTheme(QSL("help-about")));
|
||||
GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("help-about")));
|
||||
|
||||
connect(&m_downloader, &Downloader::progress, this, &FormUpdate::updateProgress);
|
||||
connect(&m_downloader, &Downloader::completed, this, &FormUpdate::updateCompleted);
|
||||
|
||||
if (isSelfUpdateSupported()) {
|
||||
m_btnUpdate = m_ui->m_buttonBox->addButton(tr("Download selected update"), QDialogButtonBox::ActionRole);
|
||||
m_btnUpdate = m_ui.m_buttonBox->addButton(tr("Download selected update"), QDialogButtonBox::ActionRole);
|
||||
m_btnUpdate->setToolTip(tr("Download new installation files."));
|
||||
}
|
||||
|
||||
else {
|
||||
m_btnUpdate = m_ui->m_buttonBox->addButton(tr("Go to application website"), QDialogButtonBox::ActionRole);
|
||||
m_btnUpdate = m_ui.m_buttonBox->addButton(tr("Go to application website"), QDialogButtonBox::ActionRole);
|
||||
m_btnUpdate->setToolTip(tr("Go to application website to get update packages manually."));
|
||||
}
|
||||
|
||||
@ -69,62 +73,65 @@ bool FormUpdate::isSelfUpdateSupported() const {
|
||||
}
|
||||
|
||||
void FormUpdate::checkForUpdates() {
|
||||
const QPair<QList<UpdateInfo>, QNetworkReply::NetworkError> update = qApp->system()->checkForUpdates();
|
||||
connect(qApp->system(), &SystemFactory::updatesChecked, [this](QPair<QList<UpdateInfo>, QNetworkReply::NetworkError> update) {
|
||||
m_ui.m_buttonBox->setEnabled(true);
|
||||
disconnect(qApp->system(), &SystemFactory::updatesChecked, nullptr, nullptr);
|
||||
|
||||
if (update.second != QNetworkReply::NoError) {
|
||||
m_updateInfo = UpdateInfo();
|
||||
m_ui->m_tabInfo->setEnabled(false);
|
||||
//: Unknown release.
|
||||
m_ui->m_lblAvailableRelease->setText(tr("unknown"));
|
||||
m_ui->m_txtChanges->clear();
|
||||
m_ui->m_lblStatus->setStatus(WidgetWithStatus::Error,
|
||||
tr("Error: '%1'.").arg(NetworkFactory::networkErrorText(update.second)),
|
||||
tr("List with updates was not\ndownloaded successfully."));
|
||||
}
|
||||
if (update.second != QNetworkReply::NoError) {
|
||||
m_updateInfo = UpdateInfo();
|
||||
m_ui.m_tabInfo->setEnabled(false);
|
||||
//: Unknown release.
|
||||
m_ui.m_lblAvailableRelease->setText(tr("unknown"));
|
||||
m_ui.m_txtChanges->clear();
|
||||
m_ui.m_lblStatus->setStatus(WidgetWithStatus::Error,
|
||||
tr("Error: '%1'.").arg(NetworkFactory::networkErrorText(update.second)),
|
||||
tr("List with updates was not\ndownloaded successfully."));
|
||||
}
|
||||
else {
|
||||
const bool self_update_supported = isSelfUpdateSupported();
|
||||
m_updateInfo = update.first.at(0);
|
||||
m_ui.m_tabInfo->setEnabled(true);
|
||||
m_ui.m_lblAvailableRelease->setText(m_updateInfo.m_availableVersion);
|
||||
m_ui.m_txtChanges->setText(m_updateInfo.m_changes);
|
||||
|
||||
else {
|
||||
const bool self_update_supported = isSelfUpdateSupported();
|
||||
m_updateInfo = update.first.at(0);
|
||||
m_ui->m_tabInfo->setEnabled(true);
|
||||
m_ui->m_lblAvailableRelease->setText(m_updateInfo.m_availableVersion);
|
||||
m_ui->m_txtChanges->setText(m_updateInfo.m_changes);
|
||||
if (SystemFactory::isVersionNewer(m_updateInfo.m_availableVersion, APP_VERSION)) {
|
||||
m_btnUpdate->setVisible(true);
|
||||
m_ui.m_lblStatus->setStatus(WidgetWithStatus::Ok,
|
||||
tr("New release available."),
|
||||
tr("This is new version which can be\ndownloaded."));
|
||||
|
||||
if (SystemFactory::isVersionNewer(m_updateInfo.m_availableVersion, APP_VERSION)) {
|
||||
m_btnUpdate->setVisible(true);
|
||||
m_ui->m_lblStatus->setStatus(WidgetWithStatus::Ok,
|
||||
tr("New release available."),
|
||||
tr("This is new version which can be\ndownloaded."));
|
||||
|
||||
if (self_update_supported) {
|
||||
loadAvailableFiles();
|
||||
if (self_update_supported) {
|
||||
loadAvailableFiles();
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_ui.m_lblStatus->setStatus(WidgetWithStatus::Warning,
|
||||
tr("No new release available."),
|
||||
tr("This release is not newer than\ncurrently installed one."));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
else {
|
||||
m_ui->m_lblStatus->setStatus(WidgetWithStatus::Warning,
|
||||
tr("No new release available."),
|
||||
tr("This release is not newer than\ncurrently installed one."));
|
||||
}
|
||||
}
|
||||
qApp->system()->checkForUpdates();
|
||||
}
|
||||
|
||||
void FormUpdate::updateProgress(qint64 bytes_received, qint64 bytes_total) {
|
||||
if (bytes_received - m_lastDownloadedBytes > 500000 || m_lastDownloadedBytes == 0) {
|
||||
m_ui->m_lblStatus->setStatus(WidgetWithStatus::Information,
|
||||
tr("Downloaded %1% (update size is %2 kB).").arg(QString::number(bytes_total == 0 ? 0 : (bytes_received * 100.0) / bytes_total,
|
||||
'f',
|
||||
2),
|
||||
QString::number(bytes_total / 1000,
|
||||
'f',
|
||||
2)),
|
||||
tr("Downloading update..."));
|
||||
m_ui->m_lblStatus->repaint();
|
||||
m_ui.m_lblStatus->setStatus(WidgetWithStatus::Information,
|
||||
tr("Downloaded %1% (update size is %2 kB).").arg(QString::number(bytes_total == 0 ? 0 : (bytes_received * 100.0) / bytes_total,
|
||||
'f',
|
||||
2),
|
||||
QString::number(bytes_total / 1000,
|
||||
'f',
|
||||
2)),
|
||||
tr("Downloading update..."));
|
||||
m_ui.m_lblStatus->repaint();
|
||||
m_lastDownloadedBytes = bytes_received;
|
||||
}
|
||||
}
|
||||
|
||||
void FormUpdate::saveUpdateFile(const QByteArray& file_contents) {
|
||||
const QString url_file = m_ui->m_listFiles->currentItem()->data(Qt::UserRole).toString();
|
||||
const QString url_file = m_ui.m_listFiles->currentItem()->data(Qt::UserRole).toString();
|
||||
const QString temp_directory = qApp->getTempFolderPath();
|
||||
|
||||
if (!temp_directory.isEmpty()) {
|
||||
@ -141,38 +148,35 @@ void FormUpdate::saveUpdateFile(const QByteArray& file_contents) {
|
||||
m_updateFilePath = output_file.fileName();
|
||||
m_readyToInstall = true;
|
||||
}
|
||||
|
||||
else {
|
||||
qDebug("Cannot save downloaded update file because target temporary file '%s' cannot be "
|
||||
"opened for writing.", qPrintable(output_file_name));
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
qDebug("Cannot save downloaded update file because no TEMP directory is available.");
|
||||
}
|
||||
}
|
||||
|
||||
void FormUpdate::loadAvailableFiles() {
|
||||
m_ui->m_listFiles->clear();
|
||||
m_ui.m_listFiles->clear();
|
||||
|
||||
foreach (const UpdateUrl& url, m_updateInfo.m_urls) {
|
||||
QListWidgetItem* item = new QListWidgetItem(url.m_name + tr(" (size ") + url.m_size + QSL(")"));
|
||||
item->setData(Qt::UserRole, url.m_fileUrl);
|
||||
item->setToolTip(url.m_fileUrl);
|
||||
m_ui->m_listFiles->addItem(item);
|
||||
m_ui.m_listFiles->addItem(item);
|
||||
}
|
||||
|
||||
if (m_ui->m_listFiles->count() > 0) {
|
||||
m_ui->m_listFiles->setCurrentRow(0);
|
||||
if (m_ui.m_listFiles->count() > 0) {
|
||||
m_ui.m_listFiles->setCurrentRow(0);
|
||||
}
|
||||
|
||||
else {
|
||||
m_btnUpdate->setEnabled(false);
|
||||
}
|
||||
|
||||
m_ui->m_tabInfo->addTab(m_ui->tabFiles, tr("Available update files"));
|
||||
m_ui->m_tabInfo->setCurrentIndex(1);
|
||||
m_ui.m_tabInfo->addTab(m_ui.tabFiles, tr("Available update files"));
|
||||
m_ui.m_tabInfo->setCurrentIndex(1);
|
||||
}
|
||||
|
||||
void FormUpdate::updateCompleted(QNetworkReply::NetworkError status, QByteArray contents) {
|
||||
@ -181,14 +185,14 @@ void FormUpdate::updateCompleted(QNetworkReply::NetworkError status, QByteArray
|
||||
switch (status) {
|
||||
case QNetworkReply::NoError:
|
||||
saveUpdateFile(contents);
|
||||
m_ui->m_lblStatus->setStatus(WidgetWithStatus::Ok, tr("Downloaded successfully"),
|
||||
tr("Package was downloaded successfully.\nYou can install it now."));
|
||||
m_ui.m_lblStatus->setStatus(WidgetWithStatus::Ok, tr("Downloaded successfully"),
|
||||
tr("Package was downloaded successfully.\nYou can install it now."));
|
||||
m_btnUpdate->setText(tr("Install"));
|
||||
m_btnUpdate->setEnabled(true);
|
||||
break;
|
||||
|
||||
default:
|
||||
m_ui->m_lblStatus->setStatus(WidgetWithStatus::Error, tr("Error occured"), tr("Error occured during downloading of the package."));
|
||||
m_ui.m_lblStatus->setStatus(WidgetWithStatus::Error, tr("Error occured"), tr("Error occured during downloading of the package."));
|
||||
m_btnUpdate->setText(tr("Error occured"));
|
||||
break;
|
||||
}
|
||||
@ -198,11 +202,10 @@ void FormUpdate::startUpdate() {
|
||||
QString url_file;
|
||||
const bool update_for_this_system = isSelfUpdateSupported();
|
||||
|
||||
if (update_for_this_system && m_ui->m_listFiles->currentItem() != nullptr) {
|
||||
url_file = m_ui->m_listFiles->currentItem()->data(Qt::UserRole).toString();
|
||||
m_ui->m_listFiles->setEnabled(false);
|
||||
if (update_for_this_system && m_ui.m_listFiles->currentItem() != nullptr) {
|
||||
url_file = m_ui.m_listFiles->currentItem()->data(Qt::UserRole).toString();
|
||||
m_ui.m_listFiles->setEnabled(false);
|
||||
}
|
||||
|
||||
else {
|
||||
url_file = APP_URL;
|
||||
}
|
||||
@ -218,13 +221,12 @@ void FormUpdate::startUpdate() {
|
||||
nullptr,
|
||||
SW_NORMAL);
|
||||
|
||||
if (exec_result <= (HINSTANCE)32) {
|
||||
if (exec_result <= (HINSTANCE)32) {
|
||||
qDebug("External updater was not launched due to error.");
|
||||
qApp->showGuiMessage(tr("Cannot update application"),
|
||||
tr("Cannot launch external updater. Update application manually."),
|
||||
QSystemTrayIcon::Warning, this);
|
||||
}
|
||||
|
||||
else {
|
||||
qApp->quit();
|
||||
}
|
||||
@ -233,24 +235,16 @@ void FormUpdate::startUpdate() {
|
||||
}
|
||||
|
||||
else if (update_for_this_system) {
|
||||
// Nothing is downloaded yet, but update for this system
|
||||
// is available and self-update feature is present.
|
||||
if (m_downloader == nullptr) {
|
||||
// Initialie downloader.
|
||||
m_downloader = new Downloader(this);
|
||||
connect(m_downloader, &Downloader::progress, this, &FormUpdate::updateProgress);
|
||||
connect(m_downloader, &Downloader::completed, this, &FormUpdate::updateCompleted);
|
||||
updateProgress(0, 100);
|
||||
}
|
||||
updateProgress(0, 100);
|
||||
|
||||
m_btnUpdate->setText(tr("Downloading update..."));
|
||||
m_btnUpdate->setEnabled(false);
|
||||
m_downloader->downloadFile(url_file);
|
||||
m_downloader.downloadFile(url_file);
|
||||
}
|
||||
|
||||
else {
|
||||
// Self-update and package are not available.
|
||||
if (!qApp->web()->openUrlInExternalBrowser(url_file)) {
|
||||
if (!qApp->web()->openUrlInExternalBrowser(url_file)) {
|
||||
qApp->showGuiMessage(tr("Cannot update application"),
|
||||
tr("Cannot navigate to installation file. Check new installation downloads manually on project website."),
|
||||
QSystemTrayIcon::Warning,
|
||||
|
@ -23,19 +23,18 @@
|
||||
#include "ui_formupdate.h"
|
||||
|
||||
#include "miscellaneous/systemfactory.h"
|
||||
#include "network-web/downloader.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QNetworkReply>
|
||||
|
||||
|
||||
class Downloader;
|
||||
|
||||
class FormUpdate : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
explicit FormUpdate(QWidget* parent = 0);
|
||||
explicit FormUpdate(QWidget* parent);
|
||||
virtual ~FormUpdate();
|
||||
|
||||
// Returns true if application can self-update
|
||||
@ -54,13 +53,14 @@ class FormUpdate : public QDialog {
|
||||
private:
|
||||
void loadAvailableFiles();
|
||||
|
||||
Downloader* m_downloader;
|
||||
bool m_readyToInstall;
|
||||
QString m_updateFilePath;
|
||||
QScopedPointer<Ui::FormUpdate> m_ui;
|
||||
UpdateInfo m_updateInfo;
|
||||
Ui::FormUpdate m_ui;
|
||||
QPushButton* m_btnUpdate;
|
||||
qint64 m_lastDownloadedBytes;
|
||||
|
||||
Downloader m_downloader;
|
||||
QString m_updateFilePath;
|
||||
UpdateInfo m_updateInfo;
|
||||
bool m_readyToInstall = false;
|
||||
qint64 m_lastDownloadedBytes = 0;
|
||||
};
|
||||
|
||||
#endif // FORMUPDATE_H
|
||||
|
@ -19,20 +19,24 @@
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
|
||||
void GuiUtilities::setLabelAsNotice(QLabel* label, bool is_warning) {
|
||||
label->setMargin(6);
|
||||
void GuiUtilities::setLabelAsNotice(QLabel& label, bool is_warning) {
|
||||
label.setMargin(6);
|
||||
|
||||
if (is_warning) {
|
||||
label->setStyleSheet(QSL("font-weight: bold; font-style: italic; color: red"));
|
||||
label.setStyleSheet(QSL("font-weight: bold; font-style: italic; color: red"));
|
||||
}
|
||||
|
||||
else {
|
||||
label->setStyleSheet(QSL("font-style: italic;"));
|
||||
label.setStyleSheet(QSL("font-style: italic;"));
|
||||
}
|
||||
}
|
||||
|
||||
GuiUtilities::GuiUtilities() {
|
||||
void GuiUtilities::applyDialogProperties(QWidget& widget, const QIcon& icon, const QString& title) {
|
||||
widget.setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
|
||||
widget.setWindowIcon(icon);
|
||||
|
||||
if (!title.isEmpty()) {
|
||||
widget.setWindowTitle(title);
|
||||
}
|
||||
}
|
||||
|
@ -18,15 +18,19 @@
|
||||
#ifndef GUIUTILITIES_H
|
||||
#define GUIUTILITIES_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
|
||||
class QLabel;
|
||||
|
||||
class GuiUtilities {
|
||||
public:
|
||||
static void setLabelAsNotice(QLabel* label, bool is_warning);
|
||||
static void setLabelAsNotice(QLabel& label, bool is_warning);
|
||||
static void applyDialogProperties(QWidget& widget, const QIcon& icon, const QString& title = QString());
|
||||
|
||||
private:
|
||||
explicit GuiUtilities();
|
||||
};
|
||||
|
||||
inline GuiUtilities::GuiUtilities() {}
|
||||
|
||||
#endif // GUIUTILITIES_H
|
||||
|
@ -36,7 +36,7 @@ void MessagePreviewer::createConnections() {
|
||||
SETTING(Browser::OpenLinksInExternalBrowserRightAway)).toBool();
|
||||
|
||||
if (open_externally_now) {
|
||||
qApp->web()->openUrlInExternalBrowser(url.toString());
|
||||
qApp->web()->openUrlInExternalBrowser(url.toString());
|
||||
}
|
||||
|
||||
else {
|
||||
@ -59,7 +59,7 @@ void MessagePreviewer::createConnections() {
|
||||
}
|
||||
|
||||
if (box.clickedButton() == btn_open) {
|
||||
qApp->web()->openUrlInExternalBrowser(url.toString());
|
||||
qApp->web()->openUrlInExternalBrowser(url.toString());
|
||||
}
|
||||
|
||||
else if (box.clickedButton() == btn_download) {
|
||||
|
@ -286,7 +286,7 @@ void MessagesView::openSelectedSourceMessagesExternally() {
|
||||
foreach (const QModelIndex& index, selectionModel()->selectedRows()) {
|
||||
const QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()).m_url;
|
||||
|
||||
if (!qApp->web()->openUrlInExternalBrowser(link)) {
|
||||
if (!qApp->web()->openUrlInExternalBrowser(link)) {
|
||||
qApp->showGuiMessage(tr("Problem with starting external web browser"),
|
||||
tr("External web browser could not be started."),
|
||||
QSystemTrayIcon::Critical);
|
||||
@ -316,7 +316,7 @@ void MessagesView::sendSelectedMessageViaEmail() {
|
||||
if (selectionModel()->selectedRows().size() == 1) {
|
||||
const Message message = m_sourceModel->messageAt(m_proxyModel->mapToSource(selectionModel()->selectedRows().at(0)).row());
|
||||
|
||||
if (!qApp->web()->sendMessageViaEmail(message)) {
|
||||
if (!qApp->web()->sendMessageViaEmail(message)) {
|
||||
MessageBox::show(this,
|
||||
QMessageBox::Critical,
|
||||
tr("Problem with starting external e-mail client"),
|
||||
|
@ -29,14 +29,16 @@
|
||||
SettingsBrowserMail::SettingsBrowserMail(Settings* settings, QWidget* parent)
|
||||
: SettingsPanel(settings, parent), m_ui(new Ui::SettingsBrowserMail) {
|
||||
m_ui->setupUi(this);
|
||||
GuiUtilities::setLabelAsNotice(m_ui->label, false);
|
||||
GuiUtilities::setLabelAsNotice(m_ui->m_lblExternalEmailInfo, false);
|
||||
GuiUtilities::setLabelAsNotice(m_ui->m_lblProxyInfo, false);
|
||||
GuiUtilities::setLabelAsNotice(*m_ui->label, false);
|
||||
GuiUtilities::setLabelAsNotice(*m_ui->m_lblExternalEmailInfo, false);
|
||||
GuiUtilities::setLabelAsNotice(*m_ui->m_lblProxyInfo, false);
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
m_ui->m_checkOpenLinksInExternal->setVisible(false);
|
||||
#else
|
||||
connect(m_ui->m_checkOpenLinksInExternal, &QCheckBox::stateChanged, this, &SettingsBrowserMail::dirtifySettings);
|
||||
#endif
|
||||
|
||||
connect(m_ui->m_cmbProxyType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
&SettingsBrowserMail::dirtifySettings);
|
||||
connect(m_ui->m_txtProxyHost, &QLineEdit::textChanged, this, &SettingsBrowserMail::dirtifySettings);
|
||||
@ -76,11 +78,10 @@ void SettingsBrowserMail::selectBrowserExecutable() {
|
||||
qApp->getHomeFolderPath(),
|
||||
//: File filter for external browser selection dialog.
|
||||
#if defined(Q_OS_LINUX)
|
||||
tr("Executables (*)")
|
||||
tr("Executables (*)"));
|
||||
#else
|
||||
tr("Executables (*.*)")
|
||||
tr("Executables (*.*)"));
|
||||
#endif
|
||||
);
|
||||
|
||||
if (!executable_file.isEmpty()) {
|
||||
m_ui->m_txtExternalBrowserExecutable->setText(QDir::toNativeSeparators(executable_file));
|
||||
@ -124,11 +125,10 @@ void SettingsBrowserMail::selectEmailExecutable() {
|
||||
qApp->getHomeFolderPath(),
|
||||
//: File filter for external e-mail selection dialog.
|
||||
#if defined(Q_OS_LINUX)
|
||||
tr("Executables (*)")
|
||||
tr("Executables (*)"));
|
||||
#else
|
||||
tr("Executables (*.*)")
|
||||
tr("Executables (*.*)"));
|
||||
#endif
|
||||
);
|
||||
|
||||
if (!executable_file.isEmpty()) {
|
||||
m_ui->m_txtExternalEmailExecutable->setText(QDir::toNativeSeparators(executable_file));
|
||||
@ -137,10 +137,12 @@ void SettingsBrowserMail::selectEmailExecutable() {
|
||||
|
||||
void SettingsBrowserMail::loadSettings() {
|
||||
onBeginLoadSettings();
|
||||
|
||||
#if !defined(USE_WEBENGINE)
|
||||
m_ui->m_checkOpenLinksInExternal->setChecked(settings()->value(GROUP(Browser),
|
||||
SETTING(Browser::OpenLinksInExternalBrowserRightAway)).toBool());
|
||||
#endif
|
||||
|
||||
// Load settings of web browser GUI.
|
||||
m_ui->m_cmbExternalBrowserPreset->addItem(tr("Opera 12 or older"), QSL("-nosession %1"));
|
||||
m_ui->m_txtExternalBrowserExecutable->setText(settings()->value(GROUP(Browser),
|
||||
@ -148,6 +150,7 @@ void SettingsBrowserMail::loadSettings() {
|
||||
m_ui->m_txtExternalBrowserArguments->setText(settings()->value(GROUP(Browser),
|
||||
SETTING(Browser::CustomExternalBrowserArguments)).toString());
|
||||
m_ui->m_grpCustomExternalBrowser->setChecked(settings()->value(GROUP(Browser), SETTING(Browser::CustomExternalBrowserEnabled)).toBool());
|
||||
|
||||
// Load settings of e-mail.
|
||||
m_ui->m_cmbExternalEmailPreset->addItem(tr("Mozilla Thunderbird"), QSL("-compose \"subject='%1',body='%2'\""));
|
||||
m_ui->m_txtExternalEmailExecutable->setText(settings()->value(GROUP(Browser), SETTING(Browser::CustomExternalEmailExecutable)).toString());
|
||||
@ -157,6 +160,7 @@ void SettingsBrowserMail::loadSettings() {
|
||||
m_ui->m_cmbProxyType->addItem(tr("System proxy"), QNetworkProxy::DefaultProxy);
|
||||
m_ui->m_cmbProxyType->addItem(tr("Socks5"), QNetworkProxy::Socks5Proxy);
|
||||
m_ui->m_cmbProxyType->addItem(tr("Http"), QNetworkProxy::HttpProxy);
|
||||
|
||||
// Load the settings.
|
||||
QNetworkProxy::ProxyType selected_proxy_type = static_cast<QNetworkProxy::ProxyType>(settings()->value(GROUP(Proxy),
|
||||
SETTING(Proxy::Type)).toInt());
|
||||
@ -170,13 +174,16 @@ void SettingsBrowserMail::loadSettings() {
|
||||
|
||||
void SettingsBrowserMail::saveSettings() {
|
||||
onBeginSaveSettings();
|
||||
|
||||
#if !defined(USE_WEBENGINE)
|
||||
settings()->setValue(GROUP(Browser), Browser::OpenLinksInExternalBrowserRightAway, m_ui->m_checkOpenLinksInExternal->isChecked());
|
||||
#endif
|
||||
|
||||
// Save settings of GUI of web browser.
|
||||
settings()->setValue(GROUP(Browser), Browser::CustomExternalBrowserEnabled, m_ui->m_grpCustomExternalBrowser->isChecked());
|
||||
settings()->setValue(GROUP(Browser), Browser::CustomExternalBrowserExecutable, m_ui->m_txtExternalBrowserExecutable->text());
|
||||
settings()->setValue(GROUP(Browser), Browser::CustomExternalBrowserArguments, m_ui->m_txtExternalBrowserArguments->text());
|
||||
|
||||
// Save settings of e-mail.
|
||||
settings()->setValue(GROUP(Browser), Browser::CustomExternalEmailExecutable, m_ui->m_txtExternalEmailExecutable->text());
|
||||
settings()->setValue(GROUP(Browser), Browser::CustomExternalEmailArguments, m_ui->m_txtExternalEmailArguments->text());
|
||||
@ -186,6 +193,7 @@ void SettingsBrowserMail::saveSettings() {
|
||||
settings()->setValue(GROUP(Proxy), Proxy::Username, m_ui->m_txtProxyUsername->text());
|
||||
settings()->setValue(GROUP(Proxy), Proxy::Password, TextFactory::encrypt(m_ui->m_txtProxyPassword->text()));
|
||||
settings()->setValue(GROUP(Proxy), Proxy::Port, m_ui->m_spinProxyPort->value());
|
||||
|
||||
// Reload settings for all network access managers.
|
||||
SilentNetworkAccessManager::instance()->loadSettings();
|
||||
onEndSaveSettings();
|
||||
|
@ -27,9 +27,9 @@
|
||||
SettingsDatabase::SettingsDatabase(Settings* settings, QWidget* parent)
|
||||
: SettingsPanel(settings, parent), m_ui(new Ui::SettingsDatabase) {
|
||||
m_ui->setupUi(this);
|
||||
GuiUtilities::setLabelAsNotice(m_ui->m_lblDataStorageWarning, true);
|
||||
GuiUtilities::setLabelAsNotice(m_ui->m_lblMysqlInfo, false);
|
||||
GuiUtilities::setLabelAsNotice(m_ui->m_lblSqliteInMemoryWarnings, true);
|
||||
GuiUtilities::setLabelAsNotice(*m_ui->m_lblDataStorageWarning, true);
|
||||
GuiUtilities::setLabelAsNotice(*m_ui->m_lblMysqlInfo, false);
|
||||
GuiUtilities::setLabelAsNotice(*m_ui->m_lblSqliteInMemoryWarnings, true);
|
||||
connect(m_ui->m_cmbDatabaseDriver, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
&SettingsDatabase::dirtifySettings);
|
||||
connect(m_ui->m_checkSqliteUseInMemoryDatabase, &QCheckBox::toggled, this, &SettingsDatabase::dirtifySettings);
|
||||
|
@ -11,6 +11,18 @@
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="m_checkOpenManagerWhenDownloadStarts">
|
||||
<property name="text">
|
||||
|
@ -34,7 +34,7 @@ SettingsFeedsMessages::SettingsFeedsMessages(Settings* settings, QWidget* parent
|
||||
: SettingsPanel(settings, parent), m_ui(new Ui::SettingsFeedsMessages) {
|
||||
m_ui->setupUi(this);
|
||||
initializeMessageDateFormats();
|
||||
GuiUtilities::setLabelAsNotice(m_ui->label_9, false);
|
||||
GuiUtilities::setLabelAsNotice(*m_ui->label_9, false);
|
||||
connect(m_ui->m_checkAutoUpdateNotification, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
|
||||
connect(m_ui->m_checkAutoUpdate, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
|
||||
connect(m_ui->m_checkKeppMessagesInTheMiddle, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings);
|
||||
|
@ -38,14 +38,14 @@ void SettingsGeneral::loadSettings() {
|
||||
onBeginLoadSettings();
|
||||
m_ui->m_checkForUpdatesOnStart->setChecked(settings()->value(GROUP(General), SETTING(General::UpdateOnStartup)).toBool());
|
||||
// Load auto-start status.
|
||||
const SystemFactory::AutoStartStatus autostart_status = qApp->system()->getAutoStartStatus();
|
||||
const SystemFactory::AutoStartStatus autostart_status = qApp->system()->autoStartStatus();
|
||||
|
||||
switch (autostart_status) {
|
||||
case SystemFactory::Enabled:
|
||||
case SystemFactory::AutoStartStatus::Enabled:
|
||||
m_ui->m_checkAutostart->setChecked(true);
|
||||
break;
|
||||
|
||||
case SystemFactory::Disabled:
|
||||
case SystemFactory::AutoStartStatus::Disabled:
|
||||
m_ui->m_checkAutostart->setChecked(false);
|
||||
break;
|
||||
|
||||
@ -69,11 +69,11 @@ void SettingsGeneral::saveSettings() {
|
||||
|
||||
// If auto-start feature is available and user wants to turn it on, then turn it on.
|
||||
if (m_ui->m_checkAutostart->isChecked()) {
|
||||
qApp->system()->setAutoStartStatus(SystemFactory::Enabled);
|
||||
qApp->system()->setAutoStartStatus(SystemFactory::AutoStartStatus::Enabled);
|
||||
}
|
||||
|
||||
else {
|
||||
qApp->system()->setAutoStartStatus(SystemFactory::Disabled);
|
||||
qApp->system()->setAutoStartStatus(SystemFactory::AutoStartStatus::Disabled);
|
||||
}
|
||||
|
||||
settings()->setValue(GROUP(General), General::UpdateOnStartup, m_ui->m_checkForUpdatesOnStart->isChecked());
|
||||
|
@ -49,15 +49,14 @@ bool TrayIconMenu::event(QEvent* event) {
|
||||
SystemTrayIcon::SystemTrayIcon(const QString& normal_icon, const QString& plain_icon, FormMain* parent)
|
||||
: QSystemTrayIcon(parent),
|
||||
m_normalIcon(normal_icon),
|
||||
m_plainPixmap(plain_icon),
|
||||
m_font(QFont()),
|
||||
m_bubbleClickTarget(nullptr),
|
||||
m_bubbleClickSlot(nullptr) {
|
||||
m_plainPixmap(plain_icon) {
|
||||
qDebug("Creating SystemTrayIcon instance.");
|
||||
m_font.setBold(true);
|
||||
|
||||
// Initialize icon.
|
||||
setNumber();
|
||||
setContextMenu(parent->trayMenu());
|
||||
|
||||
// Create necessary connections.
|
||||
connect(this, &SystemTrayIcon::activated, this, &SystemTrayIcon::onActivated);
|
||||
}
|
||||
@ -97,9 +96,11 @@ void SystemTrayIcon::showPrivate() {
|
||||
// the settings window) gets closed. Behavior for main window
|
||||
// is handled explicitly by FormMain::closeEvent() method.
|
||||
qApp->setQuitOnLastWindowClosed(false);
|
||||
|
||||
// Display the tray icon.
|
||||
QSystemTrayIcon::show();
|
||||
emit shown();
|
||||
|
||||
qDebug("Tray icon displayed.");
|
||||
}
|
||||
|
||||
@ -120,11 +121,11 @@ void SystemTrayIcon::setNumber(int number, bool any_new_message) {
|
||||
setToolTip(QSL(APP_LONG_NAME));
|
||||
QSystemTrayIcon::setIcon(QIcon(m_normalIcon));
|
||||
}
|
||||
|
||||
else {
|
||||
setToolTip(tr("%1\nUnread news: %2").arg(QSL(APP_LONG_NAME), QString::number(number)));
|
||||
QPixmap background(m_plainPixmap);
|
||||
QPainter tray_painter;
|
||||
|
||||
// FIXME: Here draw different background instead of different color of number.
|
||||
tray_painter.begin(&background);
|
||||
tray_painter.setPen(any_new_message ? Qt::black : Qt::black);
|
||||
@ -138,17 +139,14 @@ void SystemTrayIcon::setNumber(int number, bool any_new_message) {
|
||||
tray_painter.setFont(m_font);
|
||||
tray_painter.drawText(QRect(0, 0, 128, 128), Qt::AlignVCenter | Qt::AlignCenter, QChar(8734));
|
||||
}
|
||||
|
||||
else {
|
||||
// Smaller number if it has 3 digits.
|
||||
if (number > 99) {
|
||||
m_font.setPixelSize(55);
|
||||
}
|
||||
|
||||
else if (number > 9) {
|
||||
m_font.setPixelSize(80);
|
||||
}
|
||||
|
||||
// Bigger number if it has just one digit.
|
||||
else {
|
||||
m_font.setPixelSize(100);
|
||||
@ -164,18 +162,15 @@ void SystemTrayIcon::setNumber(int number, bool any_new_message) {
|
||||
}
|
||||
|
||||
void SystemTrayIcon::showMessage(const QString& title, const QString& message, QSystemTrayIcon::MessageIcon icon,
|
||||
int milliseconds_timeout_hint, QObject* click_target, const char* click_slot) {
|
||||
if (m_bubbleClickTarget != nullptr && m_bubbleClickSlot != nullptr) {
|
||||
int milliseconds_timeout_hint, std::function<void()> functor) {
|
||||
if (m_connection) {
|
||||
// Disconnect previous bubble click signalling.
|
||||
disconnect(this, SIGNAL(messageClicked()), m_bubbleClickTarget, m_bubbleClickSlot);
|
||||
disconnect(m_connection);
|
||||
}
|
||||
|
||||
m_bubbleClickSlot = (char*) click_slot;
|
||||
m_bubbleClickTarget = click_target;
|
||||
|
||||
if (click_target != nullptr && click_slot != nullptr) {
|
||||
if (functor) {
|
||||
// Establish new connection for bubble click.
|
||||
connect(this, SIGNAL(messageClicked()), click_target, click_slot);
|
||||
m_connection = connect(this, &SystemTrayIcon::messageClicked, functor);
|
||||
}
|
||||
|
||||
// NOTE: If connections do not work, then use QMetaObject::invokeMethod(...).
|
||||
|
@ -57,8 +57,7 @@ class SystemTrayIcon : public QSystemTrayIcon {
|
||||
void setNumber(int number = -1, bool any_new_message = false);
|
||||
|
||||
void showMessage(const QString& title, const QString& message, MessageIcon icon = Information,
|
||||
int milliseconds_timeout_hint = TRAY_ICON_BUBBLE_TIMEOUT, QObject* click_target = nullptr,
|
||||
const char* click_slot = nullptr);
|
||||
int milliseconds_timeout_hint = TRAY_ICON_BUBBLE_TIMEOUT, std::function<void()> functor = nullptr);
|
||||
|
||||
// Returns true if tray icon CAN be constructed on this machine.
|
||||
static bool isSystemTrayAvailable();
|
||||
@ -83,10 +82,9 @@ class SystemTrayIcon : public QSystemTrayIcon {
|
||||
private:
|
||||
QIcon m_normalIcon;
|
||||
QPixmap m_plainPixmap;
|
||||
QFont m_font;
|
||||
QFont m_font = QFont();
|
||||
|
||||
QObject* m_bubbleClickTarget;
|
||||
char* m_bubbleClickSlot;
|
||||
QMetaObject::Connection m_connection;
|
||||
};
|
||||
|
||||
#endif // SYSTEMTRAYICON_H
|
||||
|
@ -229,9 +229,9 @@ int TabWidget::addBrowser(bool move_after_current, bool make_active, const QUrl&
|
||||
// Create new WebBrowser.
|
||||
WebBrowser* browser = new WebBrowser(this);
|
||||
int final_index;
|
||||
QString browser_tab_name = tr("Web browser");
|
||||
QString browser_tab_name = tr("Web browser");
|
||||
#if defined (Q_OS_MACOS)
|
||||
browser_tab_name = browser_tab_name.prepend(QSL(" "));
|
||||
browser_tab_name = browser_tab_name.prepend(QSL(" "));
|
||||
#endif
|
||||
|
||||
if (move_after_current) {
|
||||
@ -268,7 +268,7 @@ int TabWidget::addBrowser(bool move_after_current, bool make_active, const QUrl&
|
||||
#else
|
||||
Q_UNUSED(move_after_current)
|
||||
Q_UNUSED(make_active)
|
||||
qApp->web()->openUrlInExternalBrowser(initial_url.toString());
|
||||
qApp->web()->openUrlInExternalBrowser(initial_url.toString());
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class TreeWidget : public QTreeWidget {
|
||||
}
|
||||
void setDefaultItemShowMode(ItemShowMode mode) {
|
||||
m_showMode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
QList<QTreeWidgetItem*> allItems();
|
||||
|
||||
|
@ -147,8 +147,8 @@ void WebViewer::contextMenuEvent(QContextMenuEvent* event) {
|
||||
event->accept();
|
||||
|
||||
QMenu* menu = page()->createStandardContextMenu();
|
||||
menu->addAction(AdBlockManager::instance()->adBlockIcon());
|
||||
menu->addAction(qApp->web()->engineSettingsAction());
|
||||
menu->addAction(AdBlockManager::instance()->adBlockIcon());
|
||||
menu->addAction(qApp->web()->engineSettingsAction());
|
||||
|
||||
const QPoint pos = event->globalPos();
|
||||
QPoint p(pos.x(), pos.y() + 1);
|
||||
|
33
src/main.cpp
33
src/main.cpp
@ -26,6 +26,8 @@
|
||||
#include "gui/feedmessageviewer.h"
|
||||
#include "gui/feedsview.h"
|
||||
#include "gui/messagebox.h"
|
||||
#include "gui/dialogs/formupdate.h"
|
||||
#include "gui/dialogs/formabout.h"
|
||||
#include "network-web/silentnetworkaccessmanager.h"
|
||||
#include "network-web/webfactory.h"
|
||||
|
||||
@ -103,20 +105,20 @@ int main(int argc, char* argv[]) {
|
||||
Application::setOrganizationDomain(APP_URL);
|
||||
Application::setWindowIcon(QIcon(APP_ICON_PATH));
|
||||
|
||||
// Load activated accounts.
|
||||
// Load activated accounts.
|
||||
qApp->feedReader()->feedsModel()->loadActivatedServiceAccounts();
|
||||
|
||||
// Setup single-instance behavior.
|
||||
// Setup single-instance behavior.
|
||||
QObject::connect(&application, &Application::messageReceived, &application, &Application::processExecutionMessage);
|
||||
qDebug().nospace() << "Creating main application form in thread: \'" << QThread::currentThreadId() << "\'.";
|
||||
|
||||
// Instantiate main application window.
|
||||
// Instantiate main application window.
|
||||
FormMain main_window;
|
||||
|
||||
// Set correct information for main window.
|
||||
// Set correct information for main window.
|
||||
main_window.setWindowTitle(APP_LONG_NAME);
|
||||
|
||||
// Now is a good time to initialize dynamic keyboard shortcuts.
|
||||
// Now is a good time to initialize dynamic keyboard shortcuts.
|
||||
DynamicShortcuts::load(qApp->userActions());
|
||||
|
||||
// Display main window.
|
||||
@ -137,8 +139,10 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
if (qApp->isFirstRun() || qApp->isFirstRun(APP_VERSION)) {
|
||||
qApp->showGuiMessage(QSL(APP_NAME), QObject::tr("Welcome to %1.\n\nPlease, check NEW stuff included in this\n"
|
||||
"version by clicking this popup notification.").arg(APP_LONG_NAME),
|
||||
QSystemTrayIcon::NoIcon, 0, false, &main_window, SLOT(showAbout()));
|
||||
"version by clicking this popup notification.").arg(APP_LONG_NAME),
|
||||
QSystemTrayIcon::NoIcon, 0, false, [] {
|
||||
FormAbout(qApp->mainForm()).exec();
|
||||
});
|
||||
}
|
||||
|
||||
else {
|
||||
@ -146,7 +150,20 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
if (qApp->settings()->value(GROUP(General), SETTING(General::UpdateOnStartup)).toBool()) {
|
||||
QTimer::singleShot(STARTUP_UPDATE_DELAY, application.system(), SLOT(checkForUpdatesOnStartup()));
|
||||
QObject::connect(qApp->system(), &SystemFactory::updatesChecked, [](QPair<QList<UpdateInfo>, QNetworkReply::NetworkError> updates) {
|
||||
QObject::disconnect(qApp->system(), &SystemFactory::updatesChecked, nullptr, nullptr);
|
||||
|
||||
if (!updates.first.isEmpty() && updates.second == QNetworkReply::NoError &&
|
||||
!SystemFactory::isVersionNewer(updates.first.at(0).m_availableVersion, APP_VERSION)) {
|
||||
qApp->showGuiMessage(QObject::tr("New version available"),
|
||||
QObject::tr("Click the bubble for more information."),
|
||||
QSystemTrayIcon::Information, qApp->mainForm(), false,
|
||||
[] {
|
||||
FormUpdate(qApp->mainForm()).exec();
|
||||
});
|
||||
}
|
||||
});
|
||||
qApp->system()->checkForUpdates();
|
||||
}
|
||||
|
||||
qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->loadAllExpandStates();
|
||||
|
@ -60,7 +60,7 @@ Application::Application(const QString& id, int& argc, char** argv)
|
||||
|
||||
m_feedReader(nullptr),
|
||||
m_updateFeedsLock(nullptr), m_userActions(QList<QAction*>()), m_mainForm(nullptr),
|
||||
m_trayIcon(nullptr), m_settings(nullptr), m_webFactory(new WebFactory(this)), m_system(nullptr), m_skins(nullptr),
|
||||
m_trayIcon(nullptr), m_settings(nullptr), m_webFactory(new WebFactory(this)), m_system(nullptr), m_skins(nullptr),
|
||||
m_localization(nullptr), m_icons(nullptr), m_database(nullptr), m_downloadManager(nullptr), m_shouldRestart(false) {
|
||||
connect(this, &Application::aboutToQuit, this, &Application::onAboutToQuit);
|
||||
connect(this, &Application::commitDataRequest, this, &Application::onCommitData);
|
||||
@ -74,9 +74,9 @@ Application::Application(const QString& id, int& argc, char** argv)
|
||||
// Will need add that if I add more settings in the future.
|
||||
m_urlInterceptor->loadSettings();
|
||||
|
||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(
|
||||
QByteArray(APP_LOW_NAME),
|
||||
new RssGuardSchemeHandler(QWebEngineProfile::defaultProfile()));
|
||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(
|
||||
QByteArray(APP_LOW_NAME),
|
||||
new RssGuardSchemeHandler(QWebEngineProfile::defaultProfile()));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ QList<QAction*> Application::userActions() {
|
||||
m_userActions = m_mainForm->allActions();
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
m_userActions.append(AdBlockManager::instance()->adBlockIcon());
|
||||
m_userActions.append(AdBlockManager::instance()->adBlockIcon());
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -112,11 +112,11 @@ bool Application::isFirstRun(const QString& version) {
|
||||
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WebFactory* Application::web() {
|
||||
return m_webFactory;
|
||||
return m_webFactory;
|
||||
}
|
||||
|
||||
SystemFactory* Application::system() {
|
||||
@ -224,7 +224,7 @@ QString Application::getUserDataAppPath() {
|
||||
return applicationDirPath() + QDir::separator() + QSL("data");
|
||||
}
|
||||
|
||||
QString Application::getUserDataPath() {
|
||||
QString Application::userDataPath() {
|
||||
if (settings()->type() == SettingsProperties::Portable) {
|
||||
return getUserDataAppPath();
|
||||
}
|
||||
@ -368,17 +368,14 @@ void Application::deleteTrayIcon() {
|
||||
|
||||
void Application::showGuiMessage(const QString& title, const QString& message,
|
||||
QSystemTrayIcon::MessageIcon message_type, QWidget* parent,
|
||||
bool show_at_least_msgbox, QObject* invokation_target,
|
||||
const char* invokation_slot) {
|
||||
bool show_at_least_msgbox, std::function<void()> functor) {
|
||||
if (SystemTrayIcon::areNotificationsEnabled() && SystemTrayIcon::isSystemTrayActivated()) {
|
||||
trayIcon()->showMessage(title, message, message_type, TRAY_ICON_BUBBLE_TIMEOUT, invokation_target, invokation_slot);
|
||||
trayIcon()->showMessage(title, message, message_type, TRAY_ICON_BUBBLE_TIMEOUT, functor);
|
||||
}
|
||||
|
||||
else if (show_at_least_msgbox) {
|
||||
// Tray icon or OSD is not available, display simple text box.
|
||||
MessageBox::show(parent, (QMessageBox::Icon) message_type, title, message);
|
||||
}
|
||||
|
||||
else {
|
||||
qDebug("Silencing GUI message: '%s'.", qPrintable(message));
|
||||
}
|
||||
@ -422,7 +419,6 @@ void Application::onAboutToQuit() {
|
||||
// We locked the lock to exit peacefully, unlock it to avoid warnings.
|
||||
feedUpdateLock()->unlock();
|
||||
}
|
||||
|
||||
else {
|
||||
// Request for write lock timed-out. This means
|
||||
// that some critical action can be processed right now.
|
||||
@ -439,7 +435,6 @@ void Application::onAboutToQuit() {
|
||||
if (QProcess::startDetached(QString("\"") + QDir::toNativeSeparators(applicationFilePath()) + QString("\""))) {
|
||||
qDebug("New application instance was started.");
|
||||
}
|
||||
|
||||
else {
|
||||
qWarning("New application instance was not started successfully.");
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ class Application : public QtSingleApplication {
|
||||
// Check whether GIVEN VERSION of the application starts for the first time.
|
||||
bool isFirstRun(const QString& version);
|
||||
|
||||
WebFactory* web();
|
||||
WebFactory* web();
|
||||
SystemFactory* system();
|
||||
SkinFactory* skins();
|
||||
Localization* localization();
|
||||
@ -101,7 +101,7 @@ class Application : public QtSingleApplication {
|
||||
|
||||
// Returns the base folder to which store user data, the "data" folder.
|
||||
// NOTE: Use this to get correct path under which store user data.
|
||||
QString getUserDataPath();
|
||||
QString userDataPath();
|
||||
|
||||
void setMainForm(FormMain* main_form);
|
||||
|
||||
@ -118,7 +118,7 @@ class Application : public QtSingleApplication {
|
||||
// or in message box if tray icon is disabled.
|
||||
void showGuiMessage(const QString& title, const QString& message, QSystemTrayIcon::MessageIcon message_type,
|
||||
QWidget* parent = nullptr, bool show_at_least_msgbox = false,
|
||||
QObject* invokation_target = nullptr, const char* invokation_slot = nullptr);
|
||||
std::function<void()> functor = nullptr);
|
||||
|
||||
// Returns pointer to "GOD" application singleton.
|
||||
inline static Application* instance() {
|
||||
@ -151,7 +151,7 @@ class Application : public QtSingleApplication {
|
||||
void eliminateFirstRun(const QString& version);
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
NetworkUrlInterceptor* m_urlInterceptor;
|
||||
NetworkUrlInterceptor* m_urlInterceptor;
|
||||
#endif
|
||||
|
||||
FeedReader* m_feedReader;
|
||||
@ -174,7 +174,7 @@ class Application : public QtSingleApplication {
|
||||
FormMain* m_mainForm;
|
||||
SystemTrayIcon* m_trayIcon;
|
||||
Settings* m_settings;
|
||||
WebFactory* m_webFactory;
|
||||
WebFactory* m_webFactory;
|
||||
SystemFactory* m_system;
|
||||
SkinFactory* m_skins;
|
||||
Localization* m_localization;
|
||||
|
@ -195,7 +195,7 @@ void DatabaseFactory::finishRestoration() {
|
||||
}
|
||||
|
||||
void DatabaseFactory::sqliteAssemblyDatabaseFilePath() {
|
||||
m_sqliteDatabaseFilePath = qApp->getUserDataPath() + QDir::separator() + QString(APP_DB_SQLITE_PATH);
|
||||
m_sqliteDatabaseFilePath = qApp->userDataPath() + QDir::separator() + QString(APP_DB_SQLITE_PATH);
|
||||
}
|
||||
|
||||
QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() {
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
|
||||
namespace WebEngineAttributes {
|
||||
KEY ID;
|
||||
KEY ID;
|
||||
}
|
||||
|
||||
namespace AdBlock {
|
||||
|
@ -32,150 +32,150 @@ SkinFactory::~SkinFactory() {
|
||||
}
|
||||
|
||||
void SkinFactory::loadCurrentSkin() {
|
||||
QList<QString> skin_names_to_try;
|
||||
skin_names_to_try.append(selectedSkinName());
|
||||
skin_names_to_try.append(APP_SKIN_DEFAULT);
|
||||
bool skin_parsed;
|
||||
Skin skin_data;
|
||||
QString skin_name;
|
||||
QList<QString> skin_names_to_try;
|
||||
skin_names_to_try.append(selectedSkinName());
|
||||
skin_names_to_try.append(APP_SKIN_DEFAULT);
|
||||
bool skin_parsed;
|
||||
Skin skin_data;
|
||||
QString skin_name;
|
||||
|
||||
while (!skin_names_to_try.isEmpty()) {
|
||||
skin_name = skin_names_to_try.takeFirst();
|
||||
skin_data = skinInfo(skin_name, &skin_parsed);
|
||||
while (!skin_names_to_try.isEmpty()) {
|
||||
skin_name = skin_names_to_try.takeFirst();
|
||||
skin_data = skinInfo(skin_name, &skin_parsed);
|
||||
|
||||
if (skin_parsed) {
|
||||
loadSkinFromData(skin_data);
|
||||
// Set this 'Skin' object as active one.
|
||||
m_currentSkin = skin_data;
|
||||
qDebug("Skin '%s' loaded.", qPrintable(skin_name));
|
||||
return;
|
||||
}
|
||||
if (skin_parsed) {
|
||||
loadSkinFromData(skin_data);
|
||||
// Set this 'Skin' object as active one.
|
||||
m_currentSkin = skin_data;
|
||||
qDebug("Skin '%s' loaded.", qPrintable(skin_name));
|
||||
return;
|
||||
}
|
||||
|
||||
else {
|
||||
qWarning("Failed to load skin '%s'.", qPrintable(skin_name));
|
||||
}
|
||||
}
|
||||
else {
|
||||
qWarning("Failed to load skin '%s'.", qPrintable(skin_name));
|
||||
}
|
||||
}
|
||||
|
||||
qCritical("Failed to load selected or default skin. Quitting!");
|
||||
qCritical("Failed to load selected or default skin. Quitting!");
|
||||
}
|
||||
|
||||
void SkinFactory::loadSkinFromData(const Skin& skin) {
|
||||
if (!skin.m_rawData.isEmpty()) {
|
||||
qApp->setStyleSheet(skin.m_rawData);
|
||||
}
|
||||
if (!skin.m_rawData.isEmpty()) {
|
||||
qApp->setStyleSheet(skin.m_rawData);
|
||||
}
|
||||
|
||||
qApp->setStyle(qApp->settings()->value(GROUP(GUI), SETTING(GUI::Style)).toString());
|
||||
qApp->setStyle(qApp->settings()->value(GROUP(GUI), SETTING(GUI::Style)).toString());
|
||||
}
|
||||
|
||||
void SkinFactory::setCurrentSkinName(const QString& skin_name) {
|
||||
qApp->settings()->setValue(GROUP(GUI), GUI::Skin, skin_name);
|
||||
qApp->settings()->setValue(GROUP(GUI), GUI::Skin, skin_name);
|
||||
}
|
||||
|
||||
QString SkinFactory::getUserSkinBaseFolder() const {
|
||||
return qApp->getUserDataPath() + QDir::separator() + APP_SKIN_USER_FOLDER;
|
||||
QString SkinFactory::customSkinBaseFolder() const {
|
||||
return qApp->userDataPath() + QDir::separator() + APP_SKIN_USER_FOLDER;
|
||||
}
|
||||
|
||||
QString SkinFactory::selectedSkinName() const {
|
||||
return qApp->settings()->value(GROUP(GUI), SETTING(GUI::Skin)).toString();
|
||||
return qApp->settings()->value(GROUP(GUI), SETTING(GUI::Skin)).toString();
|
||||
}
|
||||
|
||||
QString SkinFactory::adBlockedPage(const QString& subscription, const QString& rule) {
|
||||
const QString& adblocked = currentSkin().m_adblocked.arg(tr("This page was blocked by AdBlock"),
|
||||
tr("Blocked by set: \"%1\"<br/>Blocked by filter: \"%2\"")
|
||||
.arg(subscription,
|
||||
rule));
|
||||
const QString& adblocked = currentSkin().m_adblocked.arg(tr("This page was blocked by AdBlock"),
|
||||
tr("Blocked by set: \"%1\"<br/>Blocked by filter: \"%2\"")
|
||||
.arg(subscription,
|
||||
rule));
|
||||
|
||||
return currentSkin().m_layoutMarkupWrapper.arg(tr("This page was blocked by AdBlock"), adblocked);
|
||||
return currentSkin().m_layoutMarkupWrapper.arg(tr("This page was blocked by AdBlock"), adblocked);
|
||||
}
|
||||
|
||||
Skin SkinFactory::skinInfo(const QString& skin_name, bool* ok) const {
|
||||
Skin skin;
|
||||
QStringList base_skin_folders;
|
||||
base_skin_folders.append(APP_SKIN_PATH);
|
||||
base_skin_folders.append(getUserSkinBaseFolder());
|
||||
Skin skin;
|
||||
QStringList base_skin_folders;
|
||||
base_skin_folders.append(APP_SKIN_PATH);
|
||||
base_skin_folders.append(customSkinBaseFolder());
|
||||
|
||||
while (!base_skin_folders.isEmpty()) {
|
||||
const QString skin_folder = base_skin_folders.takeAt(0) + QDir::separator() + skin_name + QDir::separator();
|
||||
const QString metadata_file = skin_folder + APP_SKIN_METADATA_FILE;
|
||||
while (!base_skin_folders.isEmpty()) {
|
||||
const QString skin_folder = base_skin_folders.takeAt(0) + QDir::separator() + skin_name + QDir::separator();
|
||||
const QString metadata_file = skin_folder + APP_SKIN_METADATA_FILE;
|
||||
|
||||
if (QFile::exists(metadata_file)) {
|
||||
QFile skin_file(metadata_file);
|
||||
QDomDocument dokument;
|
||||
if (QFile::exists(metadata_file)) {
|
||||
QFile skin_file(metadata_file);
|
||||
QDomDocument dokument;
|
||||
|
||||
if (!skin_file.open(QIODevice::Text | QIODevice::ReadOnly) || !dokument.setContent(&skin_file, true)) {
|
||||
if (ok) {
|
||||
*ok = false;
|
||||
}
|
||||
if (!skin_file.open(QIODevice::Text | QIODevice::ReadOnly) || !dokument.setContent(&skin_file, true)) {
|
||||
if (ok) {
|
||||
*ok = false;
|
||||
}
|
||||
|
||||
return skin;
|
||||
}
|
||||
return skin;
|
||||
}
|
||||
|
||||
const QDomNode skin_node = dokument.namedItem(QSL("skin"));
|
||||
// Obtain visible skin name.
|
||||
skin.m_visibleName = skin_name;
|
||||
// Obtain author.
|
||||
skin.m_author = skin_node.namedItem(QSL("author")).namedItem(QSL("name")).toElement().text();
|
||||
// Obtain email.
|
||||
skin.m_email = skin_node.namedItem(QSL("author")).namedItem(QSL("email")).toElement().text();
|
||||
// Obtain version.
|
||||
skin.m_version = skin_node.attributes().namedItem(QSL("version")).toAttr().value();
|
||||
// Obtain other information.
|
||||
skin.m_baseName = skin_name;
|
||||
// Free resources.
|
||||
skin_file.close();
|
||||
skin_file.deleteLater();
|
||||
// Here we use "/" instead of QDir::separator() because CSS2.1 url field
|
||||
// accepts '/' as path elements separator.
|
||||
//
|
||||
// "##" is placeholder for the actual path to skin file. This is needed for using
|
||||
// images within the QSS file.
|
||||
// So if one uses "##/images/border.png" in QSS then it is
|
||||
// replaced by fully absolute path and target file can
|
||||
// be safely loaded.
|
||||
skin.m_layoutMarkupWrapper = QString::fromUtf8(IOFactory::readTextFile(skin_folder + QL1S("html_wrapper.html")));
|
||||
skin.m_layoutMarkupWrapper = skin.m_layoutMarkupWrapper.replace(QSL("##"), APP_SKIN_PATH + QL1S("/") + skin_name);
|
||||
skin.m_enclosureImageMarkup = QString::fromUtf8(IOFactory::readTextFile(skin_folder + QL1S("html_enclosure_image.html")));
|
||||
skin.m_enclosureImageMarkup = skin.m_enclosureImageMarkup.replace(QSL("##"), APP_SKIN_PATH + QL1S("/") + skin_name);
|
||||
skin.m_layoutMarkup = QString::fromUtf8(IOFactory::readTextFile(skin_folder + QL1S("html_single_message.html")));
|
||||
skin.m_layoutMarkup = skin.m_layoutMarkup.replace(QSL("##"), APP_SKIN_PATH + QL1S("/") + skin_name);
|
||||
skin.m_enclosureMarkup = QString::fromUtf8(IOFactory::readTextFile(skin_folder + QL1S("html_enclosure_every.html")));
|
||||
skin.m_enclosureMarkup = skin.m_enclosureMarkup.replace(QSL("##"), APP_SKIN_PATH + QL1S("/") + skin_name);
|
||||
skin.m_rawData = QString::fromUtf8(IOFactory::readTextFile(skin_folder + QL1S("theme.css")));
|
||||
skin.m_rawData = skin.m_rawData.replace(QSL("##"), APP_SKIN_PATH + QL1S("/") + skin_name);
|
||||
skin.m_adblocked = QString::fromUtf8(IOFactory::readTextFile(skin_folder + QL1S("html_adblocked.html")));
|
||||
const QDomNode skin_node = dokument.namedItem(QSL("skin"));
|
||||
// Obtain visible skin name.
|
||||
skin.m_visibleName = skin_name;
|
||||
// Obtain author.
|
||||
skin.m_author = skin_node.namedItem(QSL("author")).namedItem(QSL("name")).toElement().text();
|
||||
// Obtain email.
|
||||
skin.m_email = skin_node.namedItem(QSL("author")).namedItem(QSL("email")).toElement().text();
|
||||
// Obtain version.
|
||||
skin.m_version = skin_node.attributes().namedItem(QSL("version")).toAttr().value();
|
||||
// Obtain other information.
|
||||
skin.m_baseName = skin_name;
|
||||
// Free resources.
|
||||
skin_file.close();
|
||||
skin_file.deleteLater();
|
||||
// Here we use "/" instead of QDir::separator() because CSS2.1 url field
|
||||
// accepts '/' as path elements separator.
|
||||
//
|
||||
// "##" is placeholder for the actual path to skin file. This is needed for using
|
||||
// images within the QSS file.
|
||||
// So if one uses "##/images/border.png" in QSS then it is
|
||||
// replaced by fully absolute path and target file can
|
||||
// be safely loaded.
|
||||
skin.m_layoutMarkupWrapper = QString::fromUtf8(IOFactory::readTextFile(skin_folder + QL1S("html_wrapper.html")));
|
||||
skin.m_layoutMarkupWrapper = skin.m_layoutMarkupWrapper.replace(QSL("##"), APP_SKIN_PATH + QL1S("/") + skin_name);
|
||||
skin.m_enclosureImageMarkup = QString::fromUtf8(IOFactory::readTextFile(skin_folder + QL1S("html_enclosure_image.html")));
|
||||
skin.m_enclosureImageMarkup = skin.m_enclosureImageMarkup.replace(QSL("##"), APP_SKIN_PATH + QL1S("/") + skin_name);
|
||||
skin.m_layoutMarkup = QString::fromUtf8(IOFactory::readTextFile(skin_folder + QL1S("html_single_message.html")));
|
||||
skin.m_layoutMarkup = skin.m_layoutMarkup.replace(QSL("##"), APP_SKIN_PATH + QL1S("/") + skin_name);
|
||||
skin.m_enclosureMarkup = QString::fromUtf8(IOFactory::readTextFile(skin_folder + QL1S("html_enclosure_every.html")));
|
||||
skin.m_enclosureMarkup = skin.m_enclosureMarkup.replace(QSL("##"), APP_SKIN_PATH + QL1S("/") + skin_name);
|
||||
skin.m_rawData = QString::fromUtf8(IOFactory::readTextFile(skin_folder + QL1S("theme.css")));
|
||||
skin.m_rawData = skin.m_rawData.replace(QSL("##"), APP_SKIN_PATH + QL1S("/") + skin_name);
|
||||
skin.m_adblocked = QString::fromUtf8(IOFactory::readTextFile(skin_folder + QL1S("html_adblocked.html")));
|
||||
|
||||
if (ok != nullptr) {
|
||||
*ok = !skin.m_author.isEmpty() && !skin.m_version.isEmpty() &&
|
||||
!skin.m_baseName.isEmpty() && !skin.m_email.isEmpty() &&
|
||||
!skin.m_layoutMarkup.isEmpty();
|
||||
}
|
||||
if (ok != nullptr) {
|
||||
*ok = !skin.m_author.isEmpty() && !skin.m_version.isEmpty() &&
|
||||
!skin.m_baseName.isEmpty() && !skin.m_email.isEmpty() &&
|
||||
!skin.m_layoutMarkup.isEmpty();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return skin;
|
||||
return skin;
|
||||
}
|
||||
|
||||
QList<Skin> SkinFactory::installedSkins() const {
|
||||
QList<Skin> skins;
|
||||
bool skin_load_ok;
|
||||
QStringList skin_directories = QDir(APP_SKIN_PATH).entryList(QDir::Dirs |
|
||||
QDir::NoDotAndDotDot |
|
||||
QDir::NoSymLinks |
|
||||
QDir::Readable);
|
||||
skin_directories.append(QDir(getUserSkinBaseFolder()).entryList(QDir::Dirs |
|
||||
QDir::NoDotAndDotDot |
|
||||
QDir::NoSymLinks |
|
||||
QDir::Readable));
|
||||
QList<Skin> skins;
|
||||
bool skin_load_ok;
|
||||
QStringList skin_directories = QDir(APP_SKIN_PATH).entryList(QDir::Dirs |
|
||||
QDir::NoDotAndDotDot |
|
||||
QDir::NoSymLinks |
|
||||
QDir::Readable);
|
||||
skin_directories.append(QDir(customSkinBaseFolder()).entryList(QDir::Dirs |
|
||||
QDir::NoDotAndDotDot |
|
||||
QDir::NoSymLinks |
|
||||
QDir::Readable));
|
||||
|
||||
foreach (const QString& base_directory, skin_directories) {
|
||||
const Skin skin_info = skinInfo(base_directory, &skin_load_ok);
|
||||
foreach (const QString& base_directory, skin_directories) {
|
||||
const Skin skin_info = skinInfo(base_directory, &skin_load_ok);
|
||||
|
||||
if (skin_load_ok) {
|
||||
skins.append(skin_info);
|
||||
}
|
||||
}
|
||||
if (skin_load_ok) {
|
||||
skins.append(skin_info);
|
||||
}
|
||||
}
|
||||
|
||||
return skins;
|
||||
return skins;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ struct Skin {
|
||||
QString m_email;
|
||||
QString m_version;
|
||||
QString m_rawData;
|
||||
QString m_adblocked;
|
||||
QString m_adblocked;
|
||||
QString m_layoutMarkupWrapper;
|
||||
QString m_enclosureImageMarkup;
|
||||
QString m_layoutMarkup;
|
||||
@ -61,7 +61,7 @@ class SkinFactory : public QObject {
|
||||
// after application restart.
|
||||
QString selectedSkinName() const;
|
||||
|
||||
QString adBlockedPage(const QString& subscription, const QString& rule);
|
||||
QString adBlockedPage(const QString& subscription, const QString& rule);
|
||||
|
||||
// Gets skin about a particular skin.
|
||||
Skin skinInfo(const QString& skin_name, bool* ok = nullptr) const;
|
||||
@ -72,7 +72,7 @@ class SkinFactory : public QObject {
|
||||
// Sets the desired skin as the active one if it exists.
|
||||
void setCurrentSkinName(const QString& skin_name);
|
||||
|
||||
QString getUserSkinBaseFolder() const;
|
||||
QString customSkinBaseFolder() const;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -46,7 +46,7 @@ SystemFactory::SystemFactory(QObject* parent) : QObject(parent) {
|
||||
SystemFactory::~SystemFactory() {
|
||||
}
|
||||
|
||||
SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() const {
|
||||
SystemFactory::AutoStartStatus SystemFactory::autoStartStatus() const {
|
||||
// User registry way to auto-start the application on Windows.
|
||||
#if defined(Q_OS_WIN)
|
||||
QSettings registry_key(QSL("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
|
||||
@ -57,17 +57,17 @@ SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() const {
|
||||
Application::applicationFilePath();
|
||||
|
||||
if (autostart_enabled) {
|
||||
return SystemFactory::Enabled;
|
||||
return AutoStartStatus::Enabled;
|
||||
}
|
||||
|
||||
else {
|
||||
return SystemFactory::Disabled;
|
||||
return AutoStartStatus::Disabled;
|
||||
}
|
||||
|
||||
#elif defined(Q_OS_LINUX)
|
||||
// Use proper freedesktop.org way to auto-start the application on Linux.
|
||||
// INFO: http://standards.freedesktop.org/autostart-spec/latest/
|
||||
const QString desktop_file_location = getAutostartDesktopFileLocation();
|
||||
const QString desktop_file_location = autostartDesktopFileLocation();
|
||||
|
||||
// No correct path was found.
|
||||
if (desktop_file_location.isEmpty()) {
|
||||
@ -94,7 +94,7 @@ SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() const {
|
||||
}
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
QString SystemFactory::getAutostartDesktopFileLocation() const {
|
||||
QString SystemFactory::autostartDesktopFileLocation() const {
|
||||
const QString xdg_config_path(qgetenv("XDG_CONFIG_HOME"));
|
||||
QString desktop_file_location;
|
||||
|
||||
@ -119,11 +119,11 @@ QString SystemFactory::getAutostartDesktopFileLocation() const {
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SystemFactory::setAutoStartStatus(const AutoStartStatus& new_status) {
|
||||
const SystemFactory::AutoStartStatus current_status = SystemFactory::getAutoStartStatus();
|
||||
bool SystemFactory::setAutoStartStatus(AutoStartStatus new_status) {
|
||||
const SystemFactory::AutoStartStatus current_status = SystemFactory::autoStartStatus();
|
||||
|
||||
// Auto-start feature is not even available, exit.
|
||||
if (current_status == SystemFactory::Unavailable) {
|
||||
if (current_status == AutoStartStatus::Unavailable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -131,12 +131,12 @@ bool SystemFactory::setAutoStartStatus(const AutoStartStatus& new_status) {
|
||||
QSettings registry_key(QSL("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"), QSettings::NativeFormat);
|
||||
|
||||
switch (new_status) {
|
||||
case SystemFactory::Enabled:
|
||||
case AutoStartStatus::Enabled:
|
||||
registry_key.setValue(APP_LOW_NAME,
|
||||
Application::applicationFilePath().replace(QL1C('/'), QL1C('\\')));
|
||||
return true;
|
||||
|
||||
case SystemFactory::Disabled:
|
||||
case AutoStartStatus::Disabled:
|
||||
registry_key.remove(APP_LOW_NAME);
|
||||
return true;
|
||||
|
||||
@ -147,11 +147,11 @@ bool SystemFactory::setAutoStartStatus(const AutoStartStatus& new_status) {
|
||||
#elif defined(Q_OS_LINUX)
|
||||
// Note that we expect here that no other program uses
|
||||
// "rssguard.desktop" desktop file.
|
||||
const QString destination_file = getAutostartDesktopFileLocation();
|
||||
const QString destination_file = autostartDesktopFileLocation();
|
||||
const QString destination_folder = QFileInfo(destination_file).absolutePath();
|
||||
|
||||
switch (new_status) {
|
||||
case SystemFactory::Enabled: {
|
||||
case AutoStartStatus::Enabled: {
|
||||
if (QFile::exists(destination_file)) {
|
||||
if (!QFile::remove(destination_file)) {
|
||||
return false;
|
||||
@ -166,7 +166,7 @@ bool SystemFactory::setAutoStartStatus(const AutoStartStatus& new_status) {
|
||||
return QFile::copy(source_autostart_desktop_file, destination_file);
|
||||
}
|
||||
|
||||
case SystemFactory::Disabled:
|
||||
case AutoStartStatus::Disabled:
|
||||
return QFile::remove(destination_file);
|
||||
|
||||
default:
|
||||
@ -193,7 +193,7 @@ bool SystemFactory::removeTrolltechJunkRegistryKeys() {
|
||||
}
|
||||
#endif
|
||||
|
||||
QString SystemFactory::getUsername() const {
|
||||
QString SystemFactory::loggedInUser() const {
|
||||
QString name = qgetenv("USER");
|
||||
|
||||
if (name.isEmpty()) {
|
||||
@ -207,17 +207,24 @@ QString SystemFactory::getUsername() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
QPair<QList<UpdateInfo>, QNetworkReply::NetworkError> SystemFactory::checkForUpdates() const {
|
||||
QPair<QList<UpdateInfo>, QNetworkReply::NetworkError> result;
|
||||
QByteArray releases_json;
|
||||
result.second = NetworkFactory::performNetworkOperation(RELEASES_LIST, DOWNLOAD_TIMEOUT, QByteArray(), QString(),
|
||||
releases_json, QNetworkAccessManager::GetOperation).first;
|
||||
void SystemFactory::checkForUpdates() const {
|
||||
Downloader* downloader = new Downloader();
|
||||
|
||||
if (result.second == QNetworkReply::NoError) {
|
||||
result.first = parseUpdatesFile(releases_json);
|
||||
}
|
||||
connect(downloader, &Downloader::completed, [this, downloader]() {
|
||||
QPair<QList<UpdateInfo>, QNetworkReply::NetworkError> result;
|
||||
result.second = downloader->lastOutputError();
|
||||
|
||||
return result;
|
||||
if (result.second == QNetworkReply::NoError) {
|
||||
QByteArray obtained_data = downloader->lastOutputData();
|
||||
result.first = parseUpdatesFile(obtained_data);
|
||||
}
|
||||
|
||||
emit updatesChecked(result);
|
||||
|
||||
downloader->deleteLater();
|
||||
});
|
||||
|
||||
downloader->downloadFile(RELEASES_LIST);
|
||||
}
|
||||
|
||||
bool SystemFactory::isVersionNewer(const QString& new_version, const QString& base_version) {
|
||||
@ -297,15 +304,3 @@ QList<UpdateInfo> SystemFactory::parseUpdatesFile(const QByteArray& updates_file
|
||||
});
|
||||
return updates;
|
||||
}
|
||||
|
||||
void SystemFactory::checkForUpdatesOnStartup() {
|
||||
const QPair<QList<UpdateInfo>, QNetworkReply::NetworkError> updates = checkForUpdates();
|
||||
|
||||
if (!updates.first.isEmpty() && updates.second == QNetworkReply::NoError && isVersionNewer(updates.first.at(0).m_availableVersion,
|
||||
APP_VERSION)) {
|
||||
qApp->showGuiMessage(tr("New version available"),
|
||||
tr("Click the bubble for more information."),
|
||||
QSystemTrayIcon::Information,
|
||||
nullptr, true, qApp->mainFormWidget(), SLOT(showUpdates()));
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "network-web/downloader.h"
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QHash>
|
||||
#include <QPair>
|
||||
@ -35,9 +37,6 @@ class UpdateUrl {
|
||||
|
||||
class UpdateInfo {
|
||||
public:
|
||||
explicit UpdateInfo() : m_availableVersion(QString()), m_changes(QString()), m_urls(QList<UpdateUrl>()) {
|
||||
}
|
||||
|
||||
QString m_availableVersion;
|
||||
QString m_changes;
|
||||
QList<UpdateUrl> m_urls;
|
||||
@ -51,25 +50,22 @@ class SystemFactory : public QObject {
|
||||
|
||||
public:
|
||||
// Specifies possible states of auto-start functionality.
|
||||
enum AutoStartStatus {
|
||||
enum class AutoStartStatus {
|
||||
Enabled,
|
||||
Disabled,
|
||||
Unavailable
|
||||
};
|
||||
|
||||
// Constructors and destructors.
|
||||
explicit SystemFactory(QObject* parent = 0);
|
||||
|
||||
// Constructors and destructors.
|
||||
explicit SystemFactory(QObject* parent = nullptr);
|
||||
virtual ~SystemFactory();
|
||||
|
||||
// Returns current status of auto-start function.
|
||||
SystemFactory::AutoStartStatus getAutoStartStatus() const;
|
||||
SystemFactory::AutoStartStatus autoStartStatus() const;
|
||||
|
||||
// Sets new status for auto-start function.
|
||||
// Function returns false if setting of
|
||||
// new status failed.
|
||||
bool setAutoStartStatus(const SystemFactory::AutoStartStatus& new_status);
|
||||
bool setAutoStartStatus(AutoStartStatus new_status);
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
bool removeTrolltechJunkRegistryKeys();
|
||||
@ -78,14 +74,14 @@ class SystemFactory : public QObject {
|
||||
#if defined(Q_OS_LINUX)
|
||||
// Returns standard location where auto-start .desktop files
|
||||
// should be placed.
|
||||
QString getAutostartDesktopFileLocation() const;
|
||||
QString autostartDesktopFileLocation() const;
|
||||
#endif
|
||||
|
||||
// Retrieves username of currently logged-in user.
|
||||
QString getUsername() const;
|
||||
QString loggedInUser() const;
|
||||
|
||||
// Tries to download list with new updates.
|
||||
QPair<QList<UpdateInfo>, QNetworkReply::NetworkError> checkForUpdates() const;
|
||||
void checkForUpdates() const;
|
||||
|
||||
// Checks if update is newer than current application version.
|
||||
static bool isVersionNewer(const QString& new_version, const QString& base_version);
|
||||
@ -93,8 +89,8 @@ class SystemFactory : public QObject {
|
||||
|
||||
static bool openFolderFile(const QString& file_path);
|
||||
|
||||
public slots:
|
||||
void checkForUpdatesOnStartup();
|
||||
signals:
|
||||
void updatesChecked(QPair<QList<UpdateInfo>, QNetworkReply::NetworkError> updates) const;
|
||||
|
||||
private:
|
||||
// Performs parsing of downloaded file with list of updates.
|
||||
|
@ -27,78 +27,78 @@
|
||||
|
||||
|
||||
AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
|
||||
: QDialog(parent), m_ui(new Ui::AdBlockAddSubscriptionDialog) {
|
||||
m_ui->setupUi(this);
|
||||
m_knownSubscriptions << Subscription(QSL("EasyList (English)"), ADBLOCK_EASYLIST_URL)
|
||||
<< Subscription(QSL("BSI Lista Polska (Polish)"), QSL("http://www.bsi.info.pl/filtrABP.txt"))
|
||||
<< Subscription(QSL("EasyList Czech and Slovak (Czech)"),
|
||||
QSL("https://raw.githubusercontent.com/tomasko126/easylistczechandslovak/master/filters.txt"))
|
||||
<< Subscription(QSL("dutchblock (Dutch)"), QSL("http://groenewoudt.net/dutchblock/list.txt"))
|
||||
<< Subscription(QSL("Filtros Nauscopicos (Spanish)"), QSL("http://abp.mozilla-hispano.org/nauscopio/filtros.txt"))
|
||||
<< Subscription(QSL("IsraelList (Hebrew)"), QSL("http://secure.fanboy.co.nz/israelilist/IsraelList.txt"))
|
||||
<< Subscription(QSL("NLBlock (Dutch)"), QSL("http://www.verzijlbergh.com/adblock/nlblock.txt"))
|
||||
<< Subscription(QSL("Peter Lowe's list (English)"),
|
||||
QSL("http://pgl.yoyo.org/adservers/serverlist.php?hostformat=adblockplus&mimetype=plaintext"))
|
||||
<< Subscription(QSL("PLgeneral (Polish)"), QSL("http://www.niecko.pl/adblock/adblock.txt"))
|
||||
<< Subscription(QSL("Schacks Adblock Plus liste (Danish)"), QSL("http://adblock.schack.dk/block.txt"))
|
||||
<< Subscription(QSL("Xfiles (Italian)"), QSL("http://mozilla.gfsolone.com/filtri.txt"))
|
||||
<< Subscription(QSL("EasyPrivacy (English)"), QSL("http://easylist-downloads.adblockplus.org/easyprivacy.txt"))
|
||||
<< Subscription(QSL("RU Adlist (Russian)"), QSL("https://easylist-downloads.adblockplus.org/advblock.txt"))
|
||||
<< Subscription(QSL("ABPindo (Indonesian)"),
|
||||
QSL("https://raw.githubusercontent.com/heradhis/indonesianadblockrules/master/subscriptions/abpindo.txt"))
|
||||
<< Subscription(QSL("Easylist China (Chinese)"), QSL("https://easylist-downloads.adblockplus.org/easylistchina.txt"))
|
||||
<< Subscription(QSL("Anti-Adblock Killer"),
|
||||
QSL("https://raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt"));
|
||||
: QDialog(parent), m_ui(new Ui::AdBlockAddSubscriptionDialog) {
|
||||
m_ui->setupUi(this);
|
||||
m_knownSubscriptions << Subscription(QSL("EasyList (English)"), ADBLOCK_EASYLIST_URL)
|
||||
<< Subscription(QSL("BSI Lista Polska (Polish)"), QSL("http://www.bsi.info.pl/filtrABP.txt"))
|
||||
<< Subscription(QSL("EasyList Czech and Slovak (Czech)"),
|
||||
QSL("https://raw.githubusercontent.com/tomasko126/easylistczechandslovak/master/filters.txt"))
|
||||
<< Subscription(QSL("dutchblock (Dutch)"), QSL("http://groenewoudt.net/dutchblock/list.txt"))
|
||||
<< Subscription(QSL("Filtros Nauscopicos (Spanish)"), QSL("http://abp.mozilla-hispano.org/nauscopio/filtros.txt"))
|
||||
<< Subscription(QSL("IsraelList (Hebrew)"), QSL("http://secure.fanboy.co.nz/israelilist/IsraelList.txt"))
|
||||
<< Subscription(QSL("NLBlock (Dutch)"), QSL("http://www.verzijlbergh.com/adblock/nlblock.txt"))
|
||||
<< Subscription(QSL("Peter Lowe's list (English)"),
|
||||
QSL("http://pgl.yoyo.org/adservers/serverlist.php?hostformat=adblockplus&mimetype=plaintext"))
|
||||
<< Subscription(QSL("PLgeneral (Polish)"), QSL("http://www.niecko.pl/adblock/adblock.txt"))
|
||||
<< Subscription(QSL("Schacks Adblock Plus liste (Danish)"), QSL("http://adblock.schack.dk/block.txt"))
|
||||
<< Subscription(QSL("Xfiles (Italian)"), QSL("http://mozilla.gfsolone.com/filtri.txt"))
|
||||
<< Subscription(QSL("EasyPrivacy (English)"), QSL("http://easylist-downloads.adblockplus.org/easyprivacy.txt"))
|
||||
<< Subscription(QSL("RU Adlist (Russian)"), QSL("https://easylist-downloads.adblockplus.org/advblock.txt"))
|
||||
<< Subscription(QSL("ABPindo (Indonesian)"),
|
||||
QSL("https://raw.githubusercontent.com/heradhis/indonesianadblockrules/master/subscriptions/abpindo.txt"))
|
||||
<< Subscription(QSL("Easylist China (Chinese)"), QSL("https://easylist-downloads.adblockplus.org/easylistchina.txt"))
|
||||
<< Subscription(QSL("Anti-Adblock Killer"),
|
||||
QSL("https://raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt"));
|
||||
|
||||
foreach (const Subscription& subscription, m_knownSubscriptions) {
|
||||
m_ui->m_cmbPresets->addItem(subscription.m_title);
|
||||
}
|
||||
foreach (const Subscription& subscription, m_knownSubscriptions) {
|
||||
m_ui->m_cmbPresets->addItem(subscription.m_title);
|
||||
}
|
||||
|
||||
connect(m_ui->m_cmbPresets, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
&AdBlockAddSubscriptionDialog::indexChanged);
|
||||
connect(m_ui->m_cbUsePredefined, &QCheckBox::toggled, this, &AdBlockAddSubscriptionDialog::presetsEnabledChanged);
|
||||
connect(m_ui->m_cmbPresets, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
&AdBlockAddSubscriptionDialog::indexChanged);
|
||||
connect(m_ui->m_cbUsePredefined, &QCheckBox::toggled, this, &AdBlockAddSubscriptionDialog::presetsEnabledChanged);
|
||||
|
||||
m_ui->m_cbUsePredefined->setChecked(true);
|
||||
indexChanged(0);
|
||||
m_ui->m_cbUsePredefined->setChecked(true);
|
||||
indexChanged(0);
|
||||
|
||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
|
||||
setWindowIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
|
||||
setWindowIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
}
|
||||
|
||||
QString AdBlockAddSubscriptionDialog::title() const {
|
||||
return m_ui->m_txtTitle->text();
|
||||
return m_ui->m_txtTitle->text();
|
||||
}
|
||||
|
||||
QString AdBlockAddSubscriptionDialog::url() const {
|
||||
return m_ui->m_txtUrl->text();
|
||||
return m_ui->m_txtUrl->text();
|
||||
}
|
||||
|
||||
void AdBlockAddSubscriptionDialog::indexChanged(int index) {
|
||||
const Subscription subscription = m_knownSubscriptions.at(index);
|
||||
const int pos = subscription.m_title.indexOf(QLatin1Char('('));
|
||||
const Subscription subscription = m_knownSubscriptions.at(index);
|
||||
const int pos = subscription.m_title.indexOf(QLatin1Char('('));
|
||||
|
||||
if (pos > 0) {
|
||||
m_ui->m_txtTitle->setText(subscription.m_title.left(pos).trimmed());
|
||||
}
|
||||
else {
|
||||
m_ui->m_txtTitle->setText(subscription.m_title);
|
||||
}
|
||||
if (pos > 0) {
|
||||
m_ui->m_txtTitle->setText(subscription.m_title.left(pos).trimmed());
|
||||
}
|
||||
else {
|
||||
m_ui->m_txtTitle->setText(subscription.m_title);
|
||||
}
|
||||
|
||||
m_ui->m_txtUrl->setText(subscription.m_url);
|
||||
m_ui->m_txtUrl->setText(subscription.m_url);
|
||||
}
|
||||
|
||||
void AdBlockAddSubscriptionDialog::presetsEnabledChanged(bool enabled) {
|
||||
m_ui->m_txtTitle->setEnabled(!enabled);
|
||||
m_ui->m_txtUrl->setEnabled(!enabled);
|
||||
m_ui->m_txtTitle->setEnabled(!enabled);
|
||||
m_ui->m_txtUrl->setEnabled(!enabled);
|
||||
|
||||
if (!enabled) {
|
||||
// Presets are disabled, clear txts.
|
||||
m_ui->m_txtTitle->clear();
|
||||
m_ui->m_txtUrl->clear();
|
||||
m_ui->m_txtTitle->setFocus();
|
||||
}
|
||||
if (!enabled) {
|
||||
// Presets are disabled, clear txts.
|
||||
m_ui->m_txtTitle->clear();
|
||||
m_ui->m_txtUrl->clear();
|
||||
m_ui->m_txtTitle->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
AdBlockAddSubscriptionDialog::~AdBlockAddSubscriptionDialog() {
|
||||
delete m_ui;
|
||||
delete m_ui;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class AdBlockAddSubscriptionDialog : public QDialog {
|
||||
|
||||
private slots:
|
||||
void indexChanged(int index);
|
||||
void presetsEnabledChanged(bool enabled);
|
||||
void presetsEnabledChanged(bool enabled);
|
||||
|
||||
private:
|
||||
Ui::AdBlockAddSubscriptionDialog* m_ui;
|
||||
|
@ -35,135 +35,135 @@
|
||||
|
||||
|
||||
AdBlockDialog::AdBlockDialog(QWidget* parent)
|
||||
: QDialog(parent), m_ui(new Ui::AdBlockDialog), m_manager(AdBlockManager::instance()), m_currentTreeWidget(0), m_currentSubscription(0),
|
||||
m_loaded(false) {
|
||||
m_ui->setupUi(this);
|
||||
m_ui->m_cbEnable->setChecked(m_manager->isEnabled());
|
||||
: QDialog(parent), m_ui(new Ui::AdBlockDialog), m_manager(AdBlockManager::instance()), m_currentTreeWidget(0), m_currentSubscription(0),
|
||||
m_loaded(false) {
|
||||
m_ui->setupUi(this);
|
||||
m_ui->m_cbEnable->setChecked(m_manager->isEnabled());
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
|
||||
setWindowIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
|
||||
setWindowIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
|
||||
QPushButton* btn_options = m_ui->m_buttonBox->addButton(QDialogButtonBox::FirstButton);
|
||||
btn_options->setText(tr("Options"));
|
||||
QPushButton* btn_options = m_ui->m_buttonBox->addButton(QDialogButtonBox::FirstButton);
|
||||
btn_options->setText(tr("Options"));
|
||||
|
||||
QMenu* menu = new QMenu(btn_options);
|
||||
QMenu* menu = new QMenu(btn_options);
|
||||
|
||||
m_actionAddRule = menu->addAction(tr("Add rule"), this, &AdBlockDialog::addRule);
|
||||
m_actionRemoveRule = menu->addAction(tr("Remove rule"), this, &AdBlockDialog::removeRule);
|
||||
m_actionAddRule = menu->addAction(tr("Add rule"), this, &AdBlockDialog::addRule);
|
||||
m_actionRemoveRule = menu->addAction(tr("Remove rule"), this, &AdBlockDialog::removeRule);
|
||||
|
||||
menu->addSeparator();
|
||||
menu->addSeparator();
|
||||
|
||||
m_actionAddSubscription = menu->addAction(tr("Add subscription"), this, &AdBlockDialog::addSubscription);
|
||||
m_actionRemoveSubscription = menu->addAction(tr("Remove subscription"), this, &AdBlockDialog::removeSubscription);
|
||||
m_actionAddSubscription = menu->addAction(tr("Add subscription"), this, &AdBlockDialog::addSubscription);
|
||||
m_actionRemoveSubscription = menu->addAction(tr("Remove subscription"), this, &AdBlockDialog::removeSubscription);
|
||||
|
||||
menu->addAction(tr("Update subscriptions"), m_manager, &AdBlockManager::updateAllSubscriptions);
|
||||
menu->addSeparator();
|
||||
menu->addAction(tr("Learn about writing rules..."), this, &AdBlockDialog::learnAboutRules);
|
||||
btn_options->setMenu(menu);
|
||||
menu->addAction(tr("Update subscriptions"), m_manager, &AdBlockManager::updateAllSubscriptions);
|
||||
menu->addSeparator();
|
||||
menu->addAction(tr("Learn about writing rules..."), this, &AdBlockDialog::learnAboutRules);
|
||||
btn_options->setMenu(menu);
|
||||
|
||||
|
||||
|
||||
connect(menu, &QMenu::aboutToShow, this, &AdBlockDialog::aboutToShowMenu);
|
||||
connect(m_ui->m_cbEnable, &QCheckBox::toggled, this, &AdBlockDialog::enableAdBlock);
|
||||
connect(m_ui->m_tabSubscriptions, &QTabWidget::currentChanged, this, &AdBlockDialog::currentChanged);
|
||||
connect(m_ui->m_buttonBox, &QDialogButtonBox::rejected, this, &AdBlockDialog::close);
|
||||
load();
|
||||
connect(menu, &QMenu::aboutToShow, this, &AdBlockDialog::aboutToShowMenu);
|
||||
connect(m_ui->m_cbEnable, &QCheckBox::toggled, this, &AdBlockDialog::enableAdBlock);
|
||||
connect(m_ui->m_tabSubscriptions, &QTabWidget::currentChanged, this, &AdBlockDialog::currentChanged);
|
||||
connect(m_ui->m_buttonBox, &QDialogButtonBox::rejected, this, &AdBlockDialog::close);
|
||||
load();
|
||||
|
||||
m_ui->m_buttonBox->setFocus();
|
||||
m_ui->m_buttonBox->setFocus();
|
||||
}
|
||||
|
||||
void AdBlockDialog::showRule(const AdBlockRule* rule) const {
|
||||
AdBlockSubscription* subscription = rule->subscription();
|
||||
AdBlockSubscription* subscription = rule->subscription();
|
||||
|
||||
if (subscription) {
|
||||
for (int i = 0; i < m_ui->m_tabSubscriptions->count(); ++i) {
|
||||
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabSubscriptions->widget(i));
|
||||
if (subscription) {
|
||||
for (int i = 0; i < m_ui->m_tabSubscriptions->count(); ++i) {
|
||||
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabSubscriptions->widget(i));
|
||||
|
||||
if (subscription == treeWidget->subscription()) {
|
||||
treeWidget->showRule(rule);
|
||||
m_ui->m_tabSubscriptions->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (subscription == treeWidget->subscription()) {
|
||||
treeWidget->showRule(rule);
|
||||
m_ui->m_tabSubscriptions->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::addRule() {
|
||||
m_currentTreeWidget->addRule();
|
||||
m_currentTreeWidget->addRule();
|
||||
}
|
||||
|
||||
void AdBlockDialog::removeRule() {
|
||||
m_currentTreeWidget->removeRule();
|
||||
m_currentTreeWidget->removeRule();
|
||||
}
|
||||
|
||||
void AdBlockDialog::addSubscription() {
|
||||
AdBlockAddSubscriptionDialog dialog(this);
|
||||
AdBlockAddSubscriptionDialog dialog(this);
|
||||
|
||||
if (dialog.exec() != QDialog::Accepted) {
|
||||
return;
|
||||
}
|
||||
if (dialog.exec() != QDialog::Accepted) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString title = dialog.title();
|
||||
QString url = dialog.url();
|
||||
QString title = dialog.title();
|
||||
QString url = dialog.url();
|
||||
|
||||
if (AdBlockSubscription* subscription = m_manager->addSubscription(title, url)) {
|
||||
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, m_ui->m_tabSubscriptions);
|
||||
int index = m_ui->m_tabSubscriptions->insertTab(m_ui->m_tabSubscriptions->count() - 1, tree, subscription->title());
|
||||
m_ui->m_tabSubscriptions->setCurrentIndex(index);
|
||||
}
|
||||
if (AdBlockSubscription* subscription = m_manager->addSubscription(title, url)) {
|
||||
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, m_ui->m_tabSubscriptions);
|
||||
int index = m_ui->m_tabSubscriptions->insertTab(m_ui->m_tabSubscriptions->count() - 1, tree, subscription->title());
|
||||
m_ui->m_tabSubscriptions->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::removeSubscription() {
|
||||
if (m_manager->removeSubscription(m_currentSubscription)) {
|
||||
delete m_currentTreeWidget;
|
||||
}
|
||||
if (m_manager->removeSubscription(m_currentSubscription)) {
|
||||
delete m_currentTreeWidget;
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::currentChanged(int index) {
|
||||
if (index != -1) {
|
||||
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabSubscriptions->widget(index));
|
||||
m_currentSubscription = m_currentTreeWidget->subscription();
|
||||
}
|
||||
if (index != -1) {
|
||||
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabSubscriptions->widget(index));
|
||||
m_currentSubscription = m_currentTreeWidget->subscription();
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::enableAdBlock(bool state) {
|
||||
m_manager->setEnabled(state);
|
||||
m_manager->setEnabled(state);
|
||||
|
||||
if (state) {
|
||||
load();
|
||||
}
|
||||
if (state) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::aboutToShowMenu() {
|
||||
bool subscriptionEditable = m_currentSubscription && m_currentSubscription->canEditRules();
|
||||
bool subscriptionRemovable = m_currentSubscription && m_currentSubscription->canBeRemoved();
|
||||
m_actionAddRule->setEnabled(subscriptionEditable);
|
||||
m_actionRemoveRule->setEnabled(subscriptionEditable);
|
||||
m_actionRemoveSubscription->setEnabled(subscriptionRemovable);
|
||||
bool subscriptionEditable = m_currentSubscription && m_currentSubscription->canEditRules();
|
||||
bool subscriptionRemovable = m_currentSubscription && m_currentSubscription->canBeRemoved();
|
||||
m_actionAddRule->setEnabled(subscriptionEditable);
|
||||
m_actionRemoveRule->setEnabled(subscriptionEditable);
|
||||
m_actionRemoveSubscription->setEnabled(subscriptionRemovable);
|
||||
}
|
||||
|
||||
void AdBlockDialog::learnAboutRules() {
|
||||
qApp->web()->openUrlInExternalBrowser(QSL(ADBLOCK_HOWTO_FILTERS));
|
||||
qApp->web()->openUrlInExternalBrowser(QSL(ADBLOCK_HOWTO_FILTERS));
|
||||
}
|
||||
|
||||
void AdBlockDialog::loadSubscriptions() {
|
||||
for (int i = 0; i < m_ui->m_tabSubscriptions->count(); ++i) {
|
||||
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabSubscriptions->widget(i));
|
||||
treeWidget->refresh();
|
||||
}
|
||||
for (int i = 0; i < m_ui->m_tabSubscriptions->count(); ++i) {
|
||||
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabSubscriptions->widget(i));
|
||||
treeWidget->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::load() {
|
||||
if (m_loaded || !m_ui->m_cbEnable->isChecked()) {
|
||||
return;
|
||||
}
|
||||
if (m_loaded || !m_ui->m_cbEnable->isChecked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (AdBlockSubscription* subscription, m_manager->subscriptions()) {
|
||||
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, m_ui->m_tabSubscriptions);
|
||||
m_ui->m_tabSubscriptions->addTab(tree, subscription->title());
|
||||
}
|
||||
foreach (AdBlockSubscription* subscription, m_manager->subscriptions()) {
|
||||
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, m_ui->m_tabSubscriptions);
|
||||
m_ui->m_tabSubscriptions->addTab(tree, subscription->title());
|
||||
}
|
||||
|
||||
m_loaded = true;
|
||||
QTimer::singleShot(50, this, SLOT(loadSubscriptions()));
|
||||
m_loaded = true;
|
||||
QTimer::singleShot(50, this, SLOT(loadSubscriptions()));
|
||||
}
|
||||
|
@ -33,15 +33,15 @@
|
||||
|
||||
|
||||
AdBlockIcon::AdBlockIcon(AdBlockManager* parent)
|
||||
: QAction(parent), m_manager(parent), m_flashTimer(0), m_timerTicks(0), m_enabled(m_manager->isEnabled()) {
|
||||
: QAction(parent), m_manager(parent), m_flashTimer(0), m_timerTicks(0), m_enabled(m_manager->isEnabled()) {
|
||||
setToolTip(tr("AdBlock lets you block unwanted content on web pages"));
|
||||
setText(QSL("AdBlock"));
|
||||
setMenu(new QMenu());
|
||||
setIcon(m_enabled ? qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE) : qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||
setText(QSL("AdBlock"));
|
||||
setMenu(new QMenu());
|
||||
setIcon(m_enabled ? qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE) : qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||
|
||||
connect(m_manager, SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool)));
|
||||
connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createMenu()));
|
||||
connect(this, &QAction::triggered, m_manager, &AdBlockManager::showDialog);
|
||||
connect(m_manager, SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool)));
|
||||
connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createMenu()));
|
||||
connect(this, &QAction::triggered, m_manager, &AdBlockManager::showDialog);
|
||||
}
|
||||
|
||||
AdBlockIcon::~AdBlockIcon() {
|
||||
@ -49,16 +49,16 @@ AdBlockIcon::~AdBlockIcon() {
|
||||
delete m_blockedPopups.at(i).first;
|
||||
}
|
||||
|
||||
if (menu() != nullptr) {
|
||||
menu()->deleteLater();
|
||||
}
|
||||
if (menu() != nullptr) {
|
||||
menu()->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockIcon::popupBlocked(const QString& ruleString, const QUrl& url) {
|
||||
int index = ruleString.lastIndexOf(QLatin1String(" ("));
|
||||
const QString subscriptionName = ruleString.left(index);
|
||||
const QString filter = ruleString.mid(index + 2, ruleString.size() - index - 3);
|
||||
AdBlockSubscription* subscription = m_manager->subscriptionByName(subscriptionName);
|
||||
AdBlockSubscription* subscription = m_manager->subscriptionByName(subscriptionName);
|
||||
|
||||
if (filter.isEmpty() || !subscription) {
|
||||
return;
|
||||
@ -93,13 +93,13 @@ void AdBlockIcon::createMenu(QMenu* menu) {
|
||||
}
|
||||
|
||||
menu->clear();
|
||||
AdBlockCustomList* customList = m_manager->customList();
|
||||
AdBlockCustomList* customList = m_manager->customList();
|
||||
WebPage* page = qApp->mainForm()->tabWidget()->currentWidget()->webBrowser()->viewer()->page();
|
||||
const QUrl pageUrl = page->url();
|
||||
menu->addAction(tr("Show AdBlock &settings"), m_manager, SLOT(showDialog()));
|
||||
menu->addAction(tr("Show AdBlock &settings"), m_manager, SLOT(showDialog()));
|
||||
menu->addSeparator();
|
||||
|
||||
if (!pageUrl.host().isEmpty() && m_enabled && m_manager->canRunOnScheme(pageUrl.scheme())) {
|
||||
if (!pageUrl.host().isEmpty() && m_enabled && m_manager->canRunOnScheme(pageUrl.scheme())) {
|
||||
const QString host = page->url().host().contains(QLatin1String("www.")) ? pageUrl.host().mid(4) : pageUrl.host();
|
||||
const QString hostFilter = QString("@@||%1^$document").arg(host);
|
||||
const QString pageFilter = QString("@@|%1|$document").arg(pageUrl.toString());
|
||||
@ -131,7 +131,7 @@ void AdBlockIcon::toggleCustomFilter() {
|
||||
}
|
||||
|
||||
const QString filter = action->data().toString();
|
||||
AdBlockCustomList* customList = m_manager->customList();
|
||||
AdBlockCustomList* customList = m_manager->customList();
|
||||
|
||||
if (customList->containsFilter(filter)) {
|
||||
customList->removeFilter(filter);
|
||||
@ -151,12 +151,12 @@ void AdBlockIcon::animateIcon() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (icon().isNull()) {
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
if (icon().isNull()) {
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
}
|
||||
|
||||
else {
|
||||
setIcon(QIcon());
|
||||
setIcon(QIcon());
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,10 +169,10 @@ void AdBlockIcon::stopAnimation() {
|
||||
|
||||
void AdBlockIcon::setEnabled(bool enabled) {
|
||||
if (enabled) {
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
}
|
||||
else {
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||
}
|
||||
|
||||
m_enabled = enabled;
|
||||
|
@ -36,7 +36,7 @@ class AdBlockIcon : public QAction {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AdBlockIcon(AdBlockManager* parent = 0);
|
||||
explicit AdBlockIcon(AdBlockManager* parent = 0);
|
||||
virtual ~AdBlockIcon();
|
||||
|
||||
void popupBlocked(const QString& ruleString, const QUrl& url);
|
||||
@ -53,7 +53,7 @@ class AdBlockIcon : public QAction {
|
||||
void stopAnimation();
|
||||
|
||||
private:
|
||||
AdBlockManager* m_manager;
|
||||
AdBlockManager* m_manager;
|
||||
QVector<QPair<AdBlockRule*, QUrl>> m_blockedPopups;
|
||||
QTimer* m_flashTimer;
|
||||
|
||||
|
@ -44,8 +44,8 @@ Q_GLOBAL_STATIC(AdBlockManager, qz_adblock_manager)
|
||||
AdBlockManager::AdBlockManager(QObject* parent)
|
||||
: QObject(parent), m_loaded(false), m_enabled(true), m_matcher(new AdBlockMatcher(this)), m_interceptor(new AdBlockUrlInterceptor(this)) {
|
||||
|
||||
m_adblockIcon = new AdBlockIcon(this);
|
||||
m_adblockIcon->setObjectName(QSL("m_adblockIconAction"));
|
||||
m_adblockIcon = new AdBlockIcon(this);
|
||||
m_adblockIcon->setObjectName(QSL("m_adblockIconAction"));
|
||||
|
||||
load();
|
||||
}
|
||||
@ -104,19 +104,19 @@ bool AdBlockManager::block(QWebEngineUrlRequestInfo& request) {
|
||||
|
||||
if (blockedRule) {
|
||||
if (request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) {
|
||||
QUrlQuery query;
|
||||
QUrl url(QSL("rssguard:adblockedpage"));
|
||||
QUrlQuery query;
|
||||
QUrl url(QSL("rssguard:adblockedpage"));
|
||||
|
||||
query.addQueryItem(QSL("rule"), blockedRule->filter());
|
||||
query.addQueryItem(QSL("subscription"), blockedRule->subscription()->title());
|
||||
url.setQuery(query);
|
||||
query.addQueryItem(QSL("rule"), blockedRule->filter());
|
||||
query.addQueryItem(QSL("subscription"), blockedRule->subscription()->title());
|
||||
url.setQuery(query);
|
||||
|
||||
request.redirect(url);
|
||||
request.redirect(url);
|
||||
}
|
||||
|
||||
else {
|
||||
res = true;
|
||||
request.block(true);
|
||||
res = true;
|
||||
request.block(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,7 +223,7 @@ AdBlockCustomList* AdBlockManager::customList() const {
|
||||
}
|
||||
|
||||
QString AdBlockManager::storedListsPath() {
|
||||
return qApp->getUserDataPath() + QDir::separator() + ADBLOCK_LISTS_SUBDIRECTORY;
|
||||
return qApp->userDataPath() + QDir::separator() + ADBLOCK_LISTS_SUBDIRECTORY;
|
||||
}
|
||||
|
||||
void AdBlockManager::load() {
|
||||
@ -367,8 +367,8 @@ AdBlockSubscription* AdBlockManager::subscriptionByName(const QString& name) con
|
||||
|
||||
void AdBlockManager::showDialog() {
|
||||
if (!m_adBlockDialog) {
|
||||
m_adBlockDialog = new AdBlockDialog();
|
||||
m_adBlockDialog = new AdBlockDialog();
|
||||
}
|
||||
|
||||
m_adBlockDialog.data()->exec();
|
||||
m_adBlockDialog.data()->exec();
|
||||
}
|
||||
|
@ -67,9 +67,9 @@ class AdBlockManager : public QObject {
|
||||
|
||||
AdBlockCustomList* customList() const;
|
||||
|
||||
inline AdBlockIcon* adBlockIcon() const {
|
||||
return m_adblockIcon;
|
||||
}
|
||||
inline AdBlockIcon* adBlockIcon() const {
|
||||
return m_adblockIcon;
|
||||
}
|
||||
|
||||
static QString storedListsPath();
|
||||
|
||||
@ -82,7 +82,7 @@ class AdBlockManager : public QObject {
|
||||
void setEnabled(bool enabled);
|
||||
void updateMatcher();
|
||||
void updateAllSubscriptions();
|
||||
void showDialog();
|
||||
void showDialog();
|
||||
|
||||
private:
|
||||
inline bool canBeBlocked(const QUrl& url) const;
|
||||
@ -90,7 +90,7 @@ class AdBlockManager : public QObject {
|
||||
bool m_loaded;
|
||||
bool m_enabled;
|
||||
|
||||
AdBlockIcon* m_adblockIcon;
|
||||
AdBlockIcon* m_adblockIcon;
|
||||
|
||||
QList<AdBlockSubscription*> m_subscriptions;
|
||||
AdBlockMatcher* m_matcher;
|
||||
|
@ -34,7 +34,7 @@ AdBlockTreeWidget::AdBlockTreeWidget(AdBlockSubscription* subscription, QWidget*
|
||||
setHeaderHidden(true);
|
||||
setAlternatingRowColors(true);
|
||||
setLayoutDirection(Qt::LeftToRight);
|
||||
setIndentation(5);
|
||||
setIndentation(5);
|
||||
|
||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
|
||||
connect(this, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(itemChanged(QTreeWidgetItem*)));
|
||||
@ -173,7 +173,7 @@ void AdBlockTreeWidget::subscriptionUpdated() {
|
||||
void AdBlockTreeWidget::subscriptionError(const QString& message) {
|
||||
refresh();
|
||||
m_itemChangingBlock = true;
|
||||
m_topItem->setText(0, tr("%1 (error: %2)").arg(m_subscription->title(), message));
|
||||
m_topItem->setText(0, tr("%1 (error: %2)").arg(m_subscription->title(), message));
|
||||
m_itemChangingBlock = false;
|
||||
}
|
||||
|
||||
|
@ -26,5 +26,5 @@ AdBlockUrlInterceptor::AdBlockUrlInterceptor(AdBlockManager* manager)
|
||||
}
|
||||
|
||||
void AdBlockUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) {
|
||||
info.block(m_manager->block(info));
|
||||
info.block(m_manager->block(info));
|
||||
}
|
||||
|
@ -187,6 +187,7 @@ void Downloader::runGetRequest(const QNetworkRequest& request) {
|
||||
m_activeReply->setProperty("protected", m_targetProtected);
|
||||
m_activeReply->setProperty("username", m_targetUsername);
|
||||
m_activeReply->setProperty("password", m_targetPassword);
|
||||
|
||||
connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal);
|
||||
connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class Downloader : public QObject {
|
||||
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
explicit Downloader(QObject* parent = 0);
|
||||
explicit Downloader(QObject* parent = nullptr);
|
||||
virtual ~Downloader();
|
||||
|
||||
// Access to last received full output data/error/content-type.
|
||||
@ -55,9 +55,6 @@ class Downloader : public QObject {
|
||||
bool protected_contents = false, const QString& username = QString(),
|
||||
const QString& password = QString());
|
||||
|
||||
// Performs asynchronous upload of given data as HTTP POST.
|
||||
// User needs to setup "Content-Encoding" header which
|
||||
// matches encoding of the data.
|
||||
void manipulateData(const QString& url, QNetworkAccessManager::Operation operation,
|
||||
const QByteArray& data = QByteArray(),
|
||||
int timeout = DOWNLOAD_TIMEOUT, bool protected_contents = false,
|
||||
|
@ -416,7 +416,9 @@ void DownloadItem::finished() {
|
||||
if (downloadedSuccessfully()) {
|
||||
qApp->showGuiMessage(tr("Download finished"),
|
||||
tr("File '%1' is downloaded.\nClick here to open parent directory.").arg(QDir::toNativeSeparators(m_output.fileName())),
|
||||
QSystemTrayIcon::Information, 0, false, this, SLOT(openFolder()));
|
||||
QSystemTrayIcon::Information, 0, false, [this] {
|
||||
openFolder();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,65 +1,65 @@
|
||||
// This file is part of RSS Guard.
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "network-web/rssguardschemehandler.h"
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/skinfactory.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QUrlQuery>
|
||||
#include <QWebEngineUrlRequestJob>
|
||||
|
||||
|
||||
RssGuardSchemeHandler::RssGuardSchemeHandler(QObject* parent) : QWebEngineUrlSchemeHandler(parent) {
|
||||
}
|
||||
|
||||
RssGuardSchemeHandler::~RssGuardSchemeHandler() {
|
||||
}
|
||||
|
||||
void RssGuardSchemeHandler::requestStarted(QWebEngineUrlRequestJob* job) {
|
||||
// Decide which data we want.
|
||||
QByteArray data = targetData(job->requestUrl());
|
||||
|
||||
if (data.isEmpty()) {
|
||||
job->fail(QWebEngineUrlRequestJob::UrlNotFound);
|
||||
}
|
||||
else {
|
||||
QBuffer* buf = new QBuffer(job);
|
||||
buf->setData(data);
|
||||
|
||||
job->reply(QByteArray("text/html"), buf);
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray RssGuardSchemeHandler::targetData(const QUrl& url) {
|
||||
const QString& url_string = url.toString();
|
||||
|
||||
if (url_string.contains(QSL(ADBLOCK_ADBLOCKED_PAGE))) {
|
||||
QUrlQuery query(url);
|
||||
|
||||
const QString& subscription = query.queryItemValue(QSL("subscription"));
|
||||
const QString& rule = query.queryItemValue(QSL("rule"));
|
||||
|
||||
return qApp->skins()->adBlockedPage(subscription, rule).toUtf8();
|
||||
}
|
||||
else {
|
||||
return QByteArray();
|
||||
}
|
||||
}
|
||||
// This file is part of RSS Guard.
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "network-web/rssguardschemehandler.h"
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/skinfactory.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QUrlQuery>
|
||||
#include <QWebEngineUrlRequestJob>
|
||||
|
||||
|
||||
RssGuardSchemeHandler::RssGuardSchemeHandler(QObject* parent) : QWebEngineUrlSchemeHandler(parent) {
|
||||
}
|
||||
|
||||
RssGuardSchemeHandler::~RssGuardSchemeHandler() {
|
||||
}
|
||||
|
||||
void RssGuardSchemeHandler::requestStarted(QWebEngineUrlRequestJob* job) {
|
||||
// Decide which data we want.
|
||||
QByteArray data = targetData(job->requestUrl());
|
||||
|
||||
if (data.isEmpty()) {
|
||||
job->fail(QWebEngineUrlRequestJob::UrlNotFound);
|
||||
}
|
||||
else {
|
||||
QBuffer* buf = new QBuffer(job);
|
||||
buf->setData(data);
|
||||
|
||||
job->reply(QByteArray("text/html"), buf);
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray RssGuardSchemeHandler::targetData(const QUrl& url) {
|
||||
const QString& url_string = url.toString();
|
||||
|
||||
if (url_string.contains(QSL(ADBLOCK_ADBLOCKED_PAGE))) {
|
||||
QUrlQuery query(url);
|
||||
|
||||
const QString& subscription = query.queryItemValue(QSL("subscription"));
|
||||
const QString& rule = query.queryItemValue(QSL("rule"));
|
||||
|
||||
return qApp->skins()->adBlockedPage(subscription, rule).toUtf8();
|
||||
}
|
||||
else {
|
||||
return QByteArray();
|
||||
}
|
||||
}
|
||||
|
@ -1,42 +1,42 @@
|
||||
// This file is part of RSS Guard.
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef RSSGUARDSCHEMEHANDLER_H
|
||||
#define RSSGUARDSCHEMEHANDLER_H
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QWebEngineUrlSchemeHandler>
|
||||
|
||||
|
||||
class QWebEngineUrlRequestJob;
|
||||
class QBuffer;
|
||||
|
||||
class RssGuardSchemeHandler : public QWebEngineUrlSchemeHandler {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RssGuardSchemeHandler(QObject* parent = nullptr);
|
||||
virtual ~RssGuardSchemeHandler();
|
||||
|
||||
void requestStarted(QWebEngineUrlRequestJob* job);
|
||||
|
||||
private:
|
||||
QByteArray targetData(const QUrl& url);
|
||||
};
|
||||
|
||||
#endif // RSSGUARDSCHEMEHANDLER_H
|
||||
// This file is part of RSS Guard.
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef RSSGUARDSCHEMEHANDLER_H
|
||||
#define RSSGUARDSCHEMEHANDLER_H
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QWebEngineUrlSchemeHandler>
|
||||
|
||||
|
||||
class QWebEngineUrlRequestJob;
|
||||
class QBuffer;
|
||||
|
||||
class RssGuardSchemeHandler : public QWebEngineUrlSchemeHandler {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RssGuardSchemeHandler(QObject* parent = nullptr);
|
||||
virtual ~RssGuardSchemeHandler();
|
||||
|
||||
void requestStarted(QWebEngineUrlRequestJob* job);
|
||||
|
||||
private:
|
||||
QByteArray targetData(const QUrl& url);
|
||||
};
|
||||
|
||||
#endif // RSSGUARDSCHEMEHANDLER_H
|
||||
|
@ -31,18 +31,18 @@
|
||||
|
||||
|
||||
WebFactory::WebFactory(QObject* parent)
|
||||
: QObject(parent), m_escapes(QMap<QString, QString>()), m_deEscapes(QMap<QString, QString>()) {
|
||||
: QObject(parent), m_escapes(QMap<QString, QString>()), m_deEscapes(QMap<QString, QString>()) {
|
||||
#if defined (USE_WEBENGINE)
|
||||
m_engineSettings = nullptr;
|
||||
m_engineSettings = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
WebFactory::~WebFactory() {
|
||||
#if defined (USE_WEBENGINE)
|
||||
|
||||
if (m_engineSettings != nullptr && m_engineSettings->menu() != nullptr) {
|
||||
m_engineSettings->menu()->deleteLater();
|
||||
}
|
||||
if (m_engineSettings != nullptr && m_engineSettings->menu() != nullptr) {
|
||||
m_engineSettings->menu()->deleteLater();
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
@ -60,7 +60,7 @@ bool WebFactory::sendMessageViaEmail(const Message& message) {
|
||||
// NOTE: http://en.wikipedia.org/wiki/Mailto
|
||||
return QDesktopServices::openUrl(QString("mailto:?subject=%1&body=%2").arg(QString(QUrl::toPercentEncoding(message.m_title)),
|
||||
QString(QUrl::toPercentEncoding(stripTags(message.m_contents)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool WebFactory::openUrlInExternalBrowser(const QString& url) {
|
||||
@ -137,82 +137,82 @@ QString WebFactory::toSecondLevelDomain(const QUrl& url) {
|
||||
domain = domain.mid(domain.indexOf(QL1C('.')) + 1);
|
||||
}
|
||||
|
||||
return domain + top_level_domain;
|
||||
return domain + top_level_domain;
|
||||
}
|
||||
|
||||
#if defined (USE_WEBENGINE)
|
||||
QAction* WebFactory::engineSettingsAction() {
|
||||
if (m_engineSettings == nullptr) {
|
||||
m_engineSettings = new QAction(qApp->icons()->fromTheme(QSL("applications-internet")), tr("Web engine settings"), this);
|
||||
m_engineSettings->setMenu(new QMenu());
|
||||
if (m_engineSettings == nullptr) {
|
||||
m_engineSettings = new QAction(qApp->icons()->fromTheme(QSL("applications-internet")), tr("Web engine settings"), this);
|
||||
m_engineSettings->setMenu(new QMenu());
|
||||
|
||||
createMenu(m_engineSettings->menu());
|
||||
connect(m_engineSettings->menu(), SIGNAL(aboutToShow()), this, SLOT(createMenu()));
|
||||
}
|
||||
createMenu(m_engineSettings->menu());
|
||||
connect(m_engineSettings->menu(), SIGNAL(aboutToShow()), this, SLOT(createMenu()));
|
||||
}
|
||||
|
||||
return m_engineSettings;
|
||||
return m_engineSettings;
|
||||
}
|
||||
|
||||
void WebFactory::createMenu(QMenu* menu) {
|
||||
if (menu == nullptr) {
|
||||
menu = qobject_cast<QMenu*>(sender());
|
||||
if (menu == nullptr) {
|
||||
menu = qobject_cast<QMenu*>(sender());
|
||||
|
||||
if (menu == nullptr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (menu == nullptr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
menu->clear();
|
||||
menu->clear();
|
||||
|
||||
QList<QAction*> actions;
|
||||
actions << createEngineSettingsAction(tr("Auto-load images"), QWebEngineSettings::AutoLoadImages);
|
||||
actions << createEngineSettingsAction(tr("JS enabled"), QWebEngineSettings::JavascriptEnabled);
|
||||
actions << createEngineSettingsAction(tr("JS can open popup windows"), QWebEngineSettings::JavascriptCanOpenWindows);
|
||||
actions << createEngineSettingsAction(tr("JS can access clipboard"), QWebEngineSettings::JavascriptCanAccessClipboard);
|
||||
actions << createEngineSettingsAction(tr("Hyperlinks can get focus"), QWebEngineSettings::LinksIncludedInFocusChain);
|
||||
actions << createEngineSettingsAction(tr("Local storage enabled"), QWebEngineSettings::LocalStorageEnabled);
|
||||
actions << createEngineSettingsAction(tr("Local content can access remote URLs"), QWebEngineSettings::LocalContentCanAccessRemoteUrls);
|
||||
actions << createEngineSettingsAction(tr("XSS auditing enabled"), QWebEngineSettings::XSSAuditingEnabled);
|
||||
actions << createEngineSettingsAction(tr("Spatial navigation enabled"), QWebEngineSettings::SpatialNavigationEnabled);
|
||||
actions << createEngineSettingsAction(tr("Local content can access local files"), QWebEngineSettings::LocalContentCanAccessFileUrls);
|
||||
actions << createEngineSettingsAction(tr("Hyperlink auditing enabled"), QWebEngineSettings::HyperlinkAuditingEnabled);
|
||||
actions << createEngineSettingsAction(tr("Animate scrolling"), QWebEngineSettings::ScrollAnimatorEnabled);
|
||||
actions << createEngineSettingsAction(tr("Error pages enabled"), QWebEngineSettings::ErrorPageEnabled);
|
||||
actions << createEngineSettingsAction(tr("Plugins enabled"), QWebEngineSettings::PluginsEnabled);
|
||||
actions << createEngineSettingsAction(tr("Fullscreen enabled"), QWebEngineSettings::FullScreenSupportEnabled);
|
||||
actions << createEngineSettingsAction(tr("Screen capture enabled"), QWebEngineSettings::ScreenCaptureEnabled);
|
||||
actions << createEngineSettingsAction(tr("WebGL enabled"), QWebEngineSettings::WebGLEnabled);
|
||||
actions << createEngineSettingsAction(tr("Accelerate 2D canvas"), QWebEngineSettings::Accelerated2dCanvasEnabled);
|
||||
actions << createEngineSettingsAction(tr("Print element backgrounds"), QWebEngineSettings::PrintElementBackgrounds);
|
||||
actions << createEngineSettingsAction(tr("Allow running insecure content"), QWebEngineSettings::AllowRunningInsecureContent);
|
||||
QList<QAction*> actions;
|
||||
actions << createEngineSettingsAction(tr("Auto-load images"), QWebEngineSettings::AutoLoadImages);
|
||||
actions << createEngineSettingsAction(tr("JS enabled"), QWebEngineSettings::JavascriptEnabled);
|
||||
actions << createEngineSettingsAction(tr("JS can open popup windows"), QWebEngineSettings::JavascriptCanOpenWindows);
|
||||
actions << createEngineSettingsAction(tr("JS can access clipboard"), QWebEngineSettings::JavascriptCanAccessClipboard);
|
||||
actions << createEngineSettingsAction(tr("Hyperlinks can get focus"), QWebEngineSettings::LinksIncludedInFocusChain);
|
||||
actions << createEngineSettingsAction(tr("Local storage enabled"), QWebEngineSettings::LocalStorageEnabled);
|
||||
actions << createEngineSettingsAction(tr("Local content can access remote URLs"), QWebEngineSettings::LocalContentCanAccessRemoteUrls);
|
||||
actions << createEngineSettingsAction(tr("XSS auditing enabled"), QWebEngineSettings::XSSAuditingEnabled);
|
||||
actions << createEngineSettingsAction(tr("Spatial navigation enabled"), QWebEngineSettings::SpatialNavigationEnabled);
|
||||
actions << createEngineSettingsAction(tr("Local content can access local files"), QWebEngineSettings::LocalContentCanAccessFileUrls);
|
||||
actions << createEngineSettingsAction(tr("Hyperlink auditing enabled"), QWebEngineSettings::HyperlinkAuditingEnabled);
|
||||
actions << createEngineSettingsAction(tr("Animate scrolling"), QWebEngineSettings::ScrollAnimatorEnabled);
|
||||
actions << createEngineSettingsAction(tr("Error pages enabled"), QWebEngineSettings::ErrorPageEnabled);
|
||||
actions << createEngineSettingsAction(tr("Plugins enabled"), QWebEngineSettings::PluginsEnabled);
|
||||
actions << createEngineSettingsAction(tr("Fullscreen enabled"), QWebEngineSettings::FullScreenSupportEnabled);
|
||||
actions << createEngineSettingsAction(tr("Screen capture enabled"), QWebEngineSettings::ScreenCaptureEnabled);
|
||||
actions << createEngineSettingsAction(tr("WebGL enabled"), QWebEngineSettings::WebGLEnabled);
|
||||
actions << createEngineSettingsAction(tr("Accelerate 2D canvas"), QWebEngineSettings::Accelerated2dCanvasEnabled);
|
||||
actions << createEngineSettingsAction(tr("Print element backgrounds"), QWebEngineSettings::PrintElementBackgrounds);
|
||||
actions << createEngineSettingsAction(tr("Allow running insecure content"), QWebEngineSettings::AllowRunningInsecureContent);
|
||||
|
||||
#if !defined(Q_OS_LINUX)
|
||||
actions << createEngineSettingsAction(tr("Allow geolocation on insecure origins"), QWebEngineSettings::AllowGeolocationOnInsecureOrigins);
|
||||
actions << createEngineSettingsAction(tr("Allow geolocation on insecure origins"), QWebEngineSettings::AllowGeolocationOnInsecureOrigins);
|
||||
#endif
|
||||
|
||||
menu->addActions(actions);
|
||||
menu->addActions(actions);
|
||||
}
|
||||
|
||||
void WebFactory::webEngineSettingChanged(bool enabled) {
|
||||
const QAction* const act = qobject_cast<QAction*>(sender());
|
||||
QWebEngineSettings::WebAttribute attribute = static_cast<QWebEngineSettings::WebAttribute>(act->data().toInt());
|
||||
const QAction* const act = qobject_cast<QAction*>(sender());
|
||||
QWebEngineSettings::WebAttribute attribute = static_cast<QWebEngineSettings::WebAttribute>(act->data().toInt());
|
||||
|
||||
qApp->settings()->setValue(WebEngineAttributes::ID, QString::number(static_cast<int>(attribute)), enabled);
|
||||
QWebEngineProfile::defaultProfile()->settings()->setAttribute(attribute, act->isChecked());
|
||||
qApp->settings()->setValue(WebEngineAttributes::ID, QString::number(static_cast<int>(attribute)), enabled);
|
||||
QWebEngineProfile::defaultProfile()->settings()->setAttribute(attribute, act->isChecked());
|
||||
}
|
||||
|
||||
QAction* WebFactory::createEngineSettingsAction(const QString& title, QWebEngineSettings::WebAttribute attribute) {
|
||||
QAction* act = new QAction(title, m_engineSettings->menu());
|
||||
QAction* act = new QAction(title, m_engineSettings->menu());
|
||||
|
||||
act->setData(attribute);
|
||||
act->setCheckable(true);
|
||||
act->setData(attribute);
|
||||
act->setCheckable(true);
|
||||
|
||||
act->setChecked(qApp->settings()->value(WebEngineAttributes::ID, QString::number(static_cast<int>(attribute)), true).toBool());
|
||||
QWebEngineProfile::defaultProfile()->settings()->setAttribute(attribute, act->isChecked());
|
||||
act->setChecked(qApp->settings()->value(WebEngineAttributes::ID, QString::number(static_cast<int>(attribute)), true).toBool());
|
||||
QWebEngineProfile::defaultProfile()->settings()->setAttribute(attribute, act->isChecked());
|
||||
|
||||
connect(act, &QAction::toggled, this, &WebFactory::webEngineSettingChanged);
|
||||
connect(act, &QAction::toggled, this, &WebFactory::webEngineSettingChanged);
|
||||
|
||||
return act;
|
||||
return act;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -34,11 +34,11 @@ class QMenu;
|
||||
#endif
|
||||
|
||||
class WebFactory : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Constructor.
|
||||
explicit WebFactory(QObject* parent = nullptr);
|
||||
// Constructor.
|
||||
explicit WebFactory(QObject* parent = nullptr);
|
||||
|
||||
// Destructor.
|
||||
virtual ~WebFactory();
|
||||
@ -53,7 +53,7 @@ class WebFactory : public QObject {
|
||||
QString toSecondLevelDomain(const QUrl& url);
|
||||
|
||||
#if defined (USE_WEBENGINE)
|
||||
QAction* engineSettingsAction();
|
||||
QAction* engineSettingsAction();
|
||||
#endif
|
||||
|
||||
public slots:
|
||||
@ -62,12 +62,12 @@ class WebFactory : public QObject {
|
||||
bool sendMessageViaEmail(const Message& message);
|
||||
|
||||
#if defined (USE_WEBENGINE)
|
||||
private slots:
|
||||
void createMenu(QMenu* menu = nullptr);
|
||||
void webEngineSettingChanged(bool enabled);
|
||||
private slots:
|
||||
void createMenu(QMenu* menu = nullptr);
|
||||
void webEngineSettingChanged(bool enabled);
|
||||
|
||||
private:
|
||||
QAction* createEngineSettingsAction(const QString& title, QWebEngineSettings::WebAttribute attribute);
|
||||
private:
|
||||
QAction* createEngineSettingsAction(const QString& title, QWebEngineSettings::WebAttribute attribute);
|
||||
#endif
|
||||
|
||||
private:
|
||||
@ -79,7 +79,7 @@ class WebFactory : public QObject {
|
||||
QMap<QString, QString> m_deEscapes;
|
||||
|
||||
#if defined (USE_WEBENGINE)
|
||||
QAction* m_engineSettings;
|
||||
QAction* m_engineSettings;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
|
||||
class LabelsRootItem : public RootItem {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LabelsRootItem(RootItem* parent_item = nullptr);
|
||||
|
@ -31,105 +31,105 @@ AtomParser::~AtomParser() {
|
||||
}
|
||||
|
||||
QString AtomParser::feedAuthor() const {
|
||||
QDomNodeList authors = m_xml.documentElement().elementsByTagNameNS(m_atomNamespace, QSL("author"));
|
||||
QStringList author_str;
|
||||
QDomNodeList authors = m_xml.documentElement().elementsByTagNameNS(m_atomNamespace, QSL("author"));
|
||||
QStringList author_str;
|
||||
|
||||
for (int i = 0; i < authors.size(); i++) {
|
||||
QDomNodeList names = authors.at(i).toElement().elementsByTagNameNS(m_atomNamespace, QSL("name"));
|
||||
for (int i = 0; i < authors.size(); i++) {
|
||||
QDomNodeList names = authors.at(i).toElement().elementsByTagNameNS(m_atomNamespace, QSL("name"));
|
||||
|
||||
if (!names.isEmpty()) {
|
||||
const QString name = names.at(0).toElement().text();
|
||||
if (!names.isEmpty()) {
|
||||
const QString name = names.at(0).toElement().text();
|
||||
|
||||
if (!name.isEmpty() && !author_str.contains(name)) {
|
||||
author_str.append(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!name.isEmpty() && !author_str.contains(name)) {
|
||||
author_str.append(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return author_str.join(", ");
|
||||
return author_str.join(", ");
|
||||
}
|
||||
|
||||
Message AtomParser::extractMessage(const QDomElement& msg_element, QDateTime current_time) const {
|
||||
Message new_message;
|
||||
QString title = textsFromPath(msg_element, m_atomNamespace, QSL("title"), true).join(QSL(", "));
|
||||
QString summary = textsFromPath(msg_element, m_atomNamespace, QSL("content"), true).join(QSL(", "));
|
||||
Message new_message;
|
||||
QString title = textsFromPath(msg_element, m_atomNamespace, QSL("title"), true).join(QSL(", "));
|
||||
QString summary = textsFromPath(msg_element, m_atomNamespace, QSL("content"), true).join(QSL(", "));
|
||||
|
||||
if (summary.isEmpty()) {
|
||||
summary = textsFromPath(msg_element, m_atomNamespace, QSL("summary"), true).join(QSL(", "));
|
||||
}
|
||||
if (summary.isEmpty()) {
|
||||
summary = textsFromPath(msg_element, m_atomNamespace, QSL("summary"), true).join(QSL(", "));
|
||||
}
|
||||
|
||||
// Now we obtained maximum of information for title & description.
|
||||
if (title.isEmpty() && summary.isEmpty()) {
|
||||
// BOTH title and description are empty, skip this message.
|
||||
throw new ApplicationException(QSL("Not enough data for the message."));
|
||||
}
|
||||
// Now we obtained maximum of information for title & description.
|
||||
if (title.isEmpty() && summary.isEmpty()) {
|
||||
// BOTH title and description are empty, skip this message.
|
||||
throw new ApplicationException(QSL("Not enough data for the message."));
|
||||
}
|
||||
|
||||
// Title is not empty, description does not matter.
|
||||
new_message.m_title = qApp->web()->stripTags(title);
|
||||
new_message.m_contents = summary;
|
||||
new_message.m_author = qApp->web()->escapeHtml(messageAuthor(msg_element));
|
||||
QString updated = textsFromPath(msg_element, m_atomNamespace, QSL("updated"), true).join(QSL(", "));
|
||||
// Deal with creation date.
|
||||
new_message.m_created = TextFactory::parseDateTime(updated);
|
||||
new_message.m_createdFromFeed = !new_message.m_created.isNull();
|
||||
// Title is not empty, description does not matter.
|
||||
new_message.m_title = qApp->web()->stripTags(title);
|
||||
new_message.m_contents = summary;
|
||||
new_message.m_author = qApp->web()->escapeHtml(messageAuthor(msg_element));
|
||||
QString updated = textsFromPath(msg_element, m_atomNamespace, QSL("updated"), true).join(QSL(", "));
|
||||
// Deal with creation date.
|
||||
new_message.m_created = TextFactory::parseDateTime(updated);
|
||||
new_message.m_createdFromFeed = !new_message.m_created.isNull();
|
||||
|
||||
if (!new_message.m_createdFromFeed) {
|
||||
// Date was NOT obtained from the feed, set current date as creation date for the message.
|
||||
new_message.m_created = current_time;
|
||||
}
|
||||
if (!new_message.m_createdFromFeed) {
|
||||
// Date was NOT obtained from the feed, set current date as creation date for the message.
|
||||
new_message.m_created = current_time;
|
||||
}
|
||||
|
||||
// Deal with links
|
||||
QDomNodeList elem_links = msg_element.toElement().elementsByTagNameNS(m_atomNamespace, QSL("link"));
|
||||
QString last_link_alternate, last_link_other;
|
||||
// Deal with links
|
||||
QDomNodeList elem_links = msg_element.toElement().elementsByTagNameNS(m_atomNamespace, QSL("link"));
|
||||
QString last_link_alternate, last_link_other;
|
||||
|
||||
for (int i = 0; i < elem_links.size(); i++) {
|
||||
QDomElement link = elem_links.at(i).toElement();
|
||||
QString attribute = link.attribute(QSL("rel"));
|
||||
for (int i = 0; i < elem_links.size(); i++) {
|
||||
QDomElement link = elem_links.at(i).toElement();
|
||||
QString attribute = link.attribute(QSL("rel"));
|
||||
|
||||
if (attribute == QSL("enclosure")) {
|
||||
new_message.m_enclosures.append(Enclosure(link.attribute(QSL("href")), link.attribute(QSL("type"))));
|
||||
qDebug("Adding enclosure '%s' for the message.", qPrintable(new_message.m_enclosures.last().m_url));
|
||||
}
|
||||
if (attribute == QSL("enclosure")) {
|
||||
new_message.m_enclosures.append(Enclosure(link.attribute(QSL("href")), link.attribute(QSL("type"))));
|
||||
qDebug("Adding enclosure '%s' for the message.", qPrintable(new_message.m_enclosures.last().m_url));
|
||||
}
|
||||
|
||||
else if (attribute.isEmpty() || attribute == QSL("alternate")) {
|
||||
last_link_alternate = link.attribute(QSL("href"));
|
||||
}
|
||||
else if (attribute.isEmpty() || attribute == QSL("alternate")) {
|
||||
last_link_alternate = link.attribute(QSL("href"));
|
||||
}
|
||||
|
||||
else {
|
||||
last_link_other = link.attribute(QSL("href"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
last_link_other = link.attribute(QSL("href"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!last_link_alternate.isEmpty()) {
|
||||
new_message.m_url = last_link_alternate;
|
||||
}
|
||||
if (!last_link_alternate.isEmpty()) {
|
||||
new_message.m_url = last_link_alternate;
|
||||
}
|
||||
|
||||
else if (!last_link_other.isEmpty()) {
|
||||
new_message.m_url = last_link_other;
|
||||
}
|
||||
else if (!last_link_other.isEmpty()) {
|
||||
new_message.m_url = last_link_other;
|
||||
}
|
||||
|
||||
else if (!new_message.m_enclosures.isEmpty()) {
|
||||
new_message.m_url = new_message.m_enclosures.first().m_url;
|
||||
}
|
||||
else if (!new_message.m_enclosures.isEmpty()) {
|
||||
new_message.m_url = new_message.m_enclosures.first().m_url;
|
||||
}
|
||||
|
||||
return new_message;
|
||||
return new_message;
|
||||
}
|
||||
|
||||
QString AtomParser::messageAuthor(const QDomElement& msg_element) const {
|
||||
QDomNodeList authors = msg_element.elementsByTagNameNS(m_atomNamespace, QSL("author"));
|
||||
QStringList author_str;
|
||||
QDomNodeList authors = msg_element.elementsByTagNameNS(m_atomNamespace, QSL("author"));
|
||||
QStringList author_str;
|
||||
|
||||
for (int i = 0; i < authors.size(); i++) {
|
||||
QDomNodeList names = authors.at(i).toElement().elementsByTagNameNS(m_atomNamespace, QSL("name"));
|
||||
for (int i = 0; i < authors.size(); i++) {
|
||||
QDomNodeList names = authors.at(i).toElement().elementsByTagNameNS(m_atomNamespace, QSL("name"));
|
||||
|
||||
if (!names.isEmpty()) {
|
||||
author_str.append(names.at(0).toElement().text());
|
||||
}
|
||||
}
|
||||
if (!names.isEmpty()) {
|
||||
author_str.append(names.at(0).toElement().text());
|
||||
}
|
||||
}
|
||||
|
||||
return author_str.join(", ");
|
||||
return author_str.join(", ");
|
||||
}
|
||||
|
||||
QDomNodeList AtomParser::messageElements() {
|
||||
return m_xml.elementsByTagNameNS(m_atomNamespace, QSL("entry"));
|
||||
return m_xml.elementsByTagNameNS(m_atomNamespace, QSL("entry"));
|
||||
}
|
||||
|
@ -54,14 +54,14 @@ QList<Message> RdfParser::parseXmlData(const QString& data) {
|
||||
|
||||
else {
|
||||
// Title is empty but description is not.
|
||||
new_message.m_title = qApp->web()->escapeHtml(qApp->web()->stripTags(elem_description.simplified()));
|
||||
new_message.m_title = qApp->web()->escapeHtml(qApp->web()->stripTags(elem_description.simplified()));
|
||||
new_message.m_contents = elem_description;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
// Title is really not empty, description does not matter.
|
||||
new_message.m_title = qApp->web()->escapeHtml(qApp->web()->stripTags(elem_title));
|
||||
new_message.m_title = qApp->web()->escapeHtml(qApp->web()->stripTags(elem_title));
|
||||
new_message.m_contents = elem_description;
|
||||
}
|
||||
|
||||
|
@ -65,14 +65,14 @@ Message RssParser::extractMessage(const QDomElement& msg_element, QDateTime curr
|
||||
|
||||
else {
|
||||
// Title is empty but description is not.
|
||||
new_message.m_title = qApp->web()->stripTags(elem_description.simplified());
|
||||
new_message.m_title = qApp->web()->stripTags(elem_description.simplified());
|
||||
new_message.m_contents = elem_description;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
// Title is really not empty, description does not matter.
|
||||
new_message.m_title = qApp->web()->stripTags(elem_title);
|
||||
new_message.m_title = qApp->web()->stripTags(elem_title);
|
||||
new_message.m_contents = elem_description;
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ StandardServiceRoot::StandardServiceRoot(RootItem* parent)
|
||||
: ServiceRoot(parent), m_recycleBin(new RecycleBin(this)),
|
||||
m_actionExportFeeds(nullptr), m_actionImportFeeds(nullptr), m_serviceMenu(QList<QAction*>()),
|
||||
m_feedContextMenu(QList<QAction*>()), m_actionFeedFetchMetadata(nullptr) {
|
||||
setTitle(qApp->system()->getUsername() + QL1S("@") + QL1S(APP_LOW_NAME));
|
||||
setTitle(qApp->system()->loggedInUser() + QL1S("@") + QL1S(APP_LOW_NAME));
|
||||
setIcon(StandardServiceEntryPoint().icon());
|
||||
setDescription(tr("This is obligatory service account for standard RSS/RDF/ATOM feeds."));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user