Added ability to auto-update some components.

This commit is contained in:
Gres 2015-10-18 12:19:59 +03:00
parent 01b5d1c919
commit 25d6ccd81a
2 changed files with 37 additions and 3 deletions

View File

@ -23,12 +23,14 @@
#include "LanguageHelper.h"
#include "StAssert.h"
#include "Utils.h"
#include "Updater.h"
Manager::Manager (QObject *parent) :
QObject (parent),
trayIcon_ (new QSystemTrayIcon (this)),
dictionary_ (new LanguageHelper),
resultDialog_ (new ResultDialog (*dictionary_)),
updater_ (new Updater (this)), updateTimer_ (new QTimer (this)),
captureAction_ (NULL), repeatCaptureAction_ (NULL),
repeatAction_ (NULL), clipboardAction_ (NULL),
useResultDialog_ (true), doTranslation_ (true), itemProcessingCount_ (0) {
@ -66,6 +68,11 @@ Manager::Manager (QObject *parent) :
connect (this, SIGNAL (settingsEdited ()), this, SLOT (applySettings ()));
connect (updater_, SIGNAL (updated ()), SIGNAL (settingsEdited ()));
connect (updater_, SIGNAL (error (QString)), SLOT (showError (QString)));
updateTimer_->setSingleShot (true);
connect (updateTimer_, SIGNAL (timeout ()), SLOT (checkForUpdates ()));
resultDialog_->setWindowIcon (trayIcon_->icon ());
connect (this, SIGNAL (settingsEdited ()), resultDialog_, SLOT (applySettings ()));
connect (resultDialog_, SIGNAL (requestRecognize (ProcessingItem)),
@ -78,7 +85,6 @@ Manager::Manager (QObject *parent) :
connect (resultDialog_, SIGNAL (requestEdition (ProcessingItem)),
this, SLOT (editRecognized (ProcessingItem)));
connect (trayIcon_, SIGNAL (activated (QSystemTrayIcon::ActivationReason)),
SLOT (processTrayAction (QSystemTrayIcon::ActivationReason)));
@ -170,6 +176,8 @@ void Manager::applySettings () {
proxy.setPassword (encode (GET (proxyPassword).toString ()));
}
QNetworkProxy::setApplicationProxy (proxy);
scheduleUpdate ();
settings.endGroup ();
settings.beginGroup (settings_names::recogntionGroup);
@ -186,6 +194,27 @@ void Manager::applySettings () {
#undef GET
}
void Manager::scheduleUpdate (bool justChecked) {
#define GET(NAME) settings.value (settings_names::NAME, settings_values::NAME)
QSettings settings;
settings.beginGroup (settings_names::guiGroup);
updateTimer_->stop ();
if (justChecked) {
settings.setValue (settings_names::lastUpdateCheck, QDateTime::currentDateTime ());
}
QDateTime nextUpdateCheck = updater_->nextCheckTime (GET (lastUpdateCheck).toDateTime (),
GET (autoUpdateType).toInt ());
if (nextUpdateCheck.isValid ()) {
updateTimer_->start (QDateTime::currentDateTime ().msecsTo (nextUpdateCheck));
}
#undef GET
}
void Manager::checkForUpdates () {
updater_->checkForUpdates ();
scheduleUpdate (true);
}
Manager::~Manager () {
foreach (SelectionDialog * selection, selections_.values ()) {
selection->hide ();
@ -275,6 +304,7 @@ void Manager::settings () {
SettingsEditor editor (*dictionary_);
editor.setWindowIcon (trayIcon_->icon ());
connect (&editor, SIGNAL (settingsEdited ()), SIGNAL (settingsEdited ()));
connect (&editor, SIGNAL (updateCheckRequested ()), SLOT (checkForUpdates ()));
updateActionsState (false);
editor.exec ();
updateActionsState (true);
@ -285,11 +315,10 @@ void Manager::close () {
}
void Manager::about () {
QString version = "2.0.0";
QString text = tr ("Программа для распознавания текста на экране.\n" \
"Создана с использованием Qt, tesseract-ocr, Google Translate.\n"
"Автор: Gres (translator@gres.biz)\n"
"Версия: %1 от %2 %3").arg (version)
"Версия: %1 от %2 %3").arg (updater_->currentAppVersion ())
.arg (__DATE__).arg (__TIME__);
QString tips = tr ("\n\nПодсказки.\n"
"Клик по иконке в трее:\n"

View File

@ -13,6 +13,7 @@ class QMenu;
class SelectionDialog;
class ResultDialog;
class LanguageHelper;
class Updater;
class Manager : public QObject {
Q_OBJECT
@ -42,6 +43,7 @@ class Manager : public QObject {
void copyLastImageToClipboard ();
void applySettings ();
void checkForUpdates ();
void processTrayAction (QSystemTrayIcon::ActivationReason reason);
@ -56,6 +58,7 @@ class Manager : public QObject {
QMenu * trayContextMenu ();
void updateActionsState (bool isEnabled = true);
void changeIcon (int iconType, int timeoutMsec = 3000);
void scheduleUpdate (bool justChecked = false);
private:
QSystemTrayIcon *trayIcon_;
@ -63,6 +66,8 @@ class Manager : public QObject {
//! Selection dialogs for each screen. Key - screen name.
QMap<QString, SelectionDialog *> selections_;
ResultDialog *resultDialog_;
Updater *updater_;
QTimer *updateTimer_;
QAction *captureAction_;
QAction *repeatCaptureAction_;
QAction *repeatAction_;