Added ability to auto-update some components.
This commit is contained in:
parent
01b5d1c919
commit
25d6ccd81a
35
Manager.cpp
35
Manager.cpp
@ -23,12 +23,14 @@
|
|||||||
#include "LanguageHelper.h"
|
#include "LanguageHelper.h"
|
||||||
#include "StAssert.h"
|
#include "StAssert.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
#include "Updater.h"
|
||||||
|
|
||||||
Manager::Manager (QObject *parent) :
|
Manager::Manager (QObject *parent) :
|
||||||
QObject (parent),
|
QObject (parent),
|
||||||
trayIcon_ (new QSystemTrayIcon (this)),
|
trayIcon_ (new QSystemTrayIcon (this)),
|
||||||
dictionary_ (new LanguageHelper),
|
dictionary_ (new LanguageHelper),
|
||||||
resultDialog_ (new ResultDialog (*dictionary_)),
|
resultDialog_ (new ResultDialog (*dictionary_)),
|
||||||
|
updater_ (new Updater (this)), updateTimer_ (new QTimer (this)),
|
||||||
captureAction_ (NULL), repeatCaptureAction_ (NULL),
|
captureAction_ (NULL), repeatCaptureAction_ (NULL),
|
||||||
repeatAction_ (NULL), clipboardAction_ (NULL),
|
repeatAction_ (NULL), clipboardAction_ (NULL),
|
||||||
useResultDialog_ (true), doTranslation_ (true), itemProcessingCount_ (0) {
|
useResultDialog_ (true), doTranslation_ (true), itemProcessingCount_ (0) {
|
||||||
@ -66,6 +68,11 @@ Manager::Manager (QObject *parent) :
|
|||||||
|
|
||||||
connect (this, SIGNAL (settingsEdited ()), this, SLOT (applySettings ()));
|
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 ());
|
resultDialog_->setWindowIcon (trayIcon_->icon ());
|
||||||
connect (this, SIGNAL (settingsEdited ()), resultDialog_, SLOT (applySettings ()));
|
connect (this, SIGNAL (settingsEdited ()), resultDialog_, SLOT (applySettings ()));
|
||||||
connect (resultDialog_, SIGNAL (requestRecognize (ProcessingItem)),
|
connect (resultDialog_, SIGNAL (requestRecognize (ProcessingItem)),
|
||||||
@ -78,7 +85,6 @@ Manager::Manager (QObject *parent) :
|
|||||||
connect (resultDialog_, SIGNAL (requestEdition (ProcessingItem)),
|
connect (resultDialog_, SIGNAL (requestEdition (ProcessingItem)),
|
||||||
this, SLOT (editRecognized (ProcessingItem)));
|
this, SLOT (editRecognized (ProcessingItem)));
|
||||||
|
|
||||||
|
|
||||||
connect (trayIcon_, SIGNAL (activated (QSystemTrayIcon::ActivationReason)),
|
connect (trayIcon_, SIGNAL (activated (QSystemTrayIcon::ActivationReason)),
|
||||||
SLOT (processTrayAction (QSystemTrayIcon::ActivationReason)));
|
SLOT (processTrayAction (QSystemTrayIcon::ActivationReason)));
|
||||||
|
|
||||||
@ -170,6 +176,8 @@ void Manager::applySettings () {
|
|||||||
proxy.setPassword (encode (GET (proxyPassword).toString ()));
|
proxy.setPassword (encode (GET (proxyPassword).toString ()));
|
||||||
}
|
}
|
||||||
QNetworkProxy::setApplicationProxy (proxy);
|
QNetworkProxy::setApplicationProxy (proxy);
|
||||||
|
|
||||||
|
scheduleUpdate ();
|
||||||
settings.endGroup ();
|
settings.endGroup ();
|
||||||
|
|
||||||
settings.beginGroup (settings_names::recogntionGroup);
|
settings.beginGroup (settings_names::recogntionGroup);
|
||||||
@ -186,6 +194,27 @@ void Manager::applySettings () {
|
|||||||
#undef GET
|
#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 () {
|
Manager::~Manager () {
|
||||||
foreach (SelectionDialog * selection, selections_.values ()) {
|
foreach (SelectionDialog * selection, selections_.values ()) {
|
||||||
selection->hide ();
|
selection->hide ();
|
||||||
@ -275,6 +304,7 @@ void Manager::settings () {
|
|||||||
SettingsEditor editor (*dictionary_);
|
SettingsEditor editor (*dictionary_);
|
||||||
editor.setWindowIcon (trayIcon_->icon ());
|
editor.setWindowIcon (trayIcon_->icon ());
|
||||||
connect (&editor, SIGNAL (settingsEdited ()), SIGNAL (settingsEdited ()));
|
connect (&editor, SIGNAL (settingsEdited ()), SIGNAL (settingsEdited ()));
|
||||||
|
connect (&editor, SIGNAL (updateCheckRequested ()), SLOT (checkForUpdates ()));
|
||||||
updateActionsState (false);
|
updateActionsState (false);
|
||||||
editor.exec ();
|
editor.exec ();
|
||||||
updateActionsState (true);
|
updateActionsState (true);
|
||||||
@ -285,11 +315,10 @@ void Manager::close () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Manager::about () {
|
void Manager::about () {
|
||||||
QString version = "2.0.0";
|
|
||||||
QString text = tr ("Программа для распознавания текста на экране.\n" \
|
QString text = tr ("Программа для распознавания текста на экране.\n" \
|
||||||
"Создана с использованием Qt, tesseract-ocr, Google Translate.\n"
|
"Создана с использованием Qt, tesseract-ocr, Google Translate.\n"
|
||||||
"Автор: Gres (translator@gres.biz)\n"
|
"Автор: Gres (translator@gres.biz)\n"
|
||||||
"Версия: %1 от %2 %3").arg (version)
|
"Версия: %1 от %2 %3").arg (updater_->currentAppVersion ())
|
||||||
.arg (__DATE__).arg (__TIME__);
|
.arg (__DATE__).arg (__TIME__);
|
||||||
QString tips = tr ("\n\nПодсказки.\n"
|
QString tips = tr ("\n\nПодсказки.\n"
|
||||||
"Клик по иконке в трее:\n"
|
"Клик по иконке в трее:\n"
|
||||||
|
@ -13,6 +13,7 @@ class QMenu;
|
|||||||
class SelectionDialog;
|
class SelectionDialog;
|
||||||
class ResultDialog;
|
class ResultDialog;
|
||||||
class LanguageHelper;
|
class LanguageHelper;
|
||||||
|
class Updater;
|
||||||
|
|
||||||
class Manager : public QObject {
|
class Manager : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -42,6 +43,7 @@ class Manager : public QObject {
|
|||||||
void copyLastImageToClipboard ();
|
void copyLastImageToClipboard ();
|
||||||
|
|
||||||
void applySettings ();
|
void applySettings ();
|
||||||
|
void checkForUpdates ();
|
||||||
|
|
||||||
void processTrayAction (QSystemTrayIcon::ActivationReason reason);
|
void processTrayAction (QSystemTrayIcon::ActivationReason reason);
|
||||||
|
|
||||||
@ -56,6 +58,7 @@ class Manager : public QObject {
|
|||||||
QMenu * trayContextMenu ();
|
QMenu * trayContextMenu ();
|
||||||
void updateActionsState (bool isEnabled = true);
|
void updateActionsState (bool isEnabled = true);
|
||||||
void changeIcon (int iconType, int timeoutMsec = 3000);
|
void changeIcon (int iconType, int timeoutMsec = 3000);
|
||||||
|
void scheduleUpdate (bool justChecked = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSystemTrayIcon *trayIcon_;
|
QSystemTrayIcon *trayIcon_;
|
||||||
@ -63,6 +66,8 @@ class Manager : public QObject {
|
|||||||
//! Selection dialogs for each screen. Key - screen name.
|
//! Selection dialogs for each screen. Key - screen name.
|
||||||
QMap<QString, SelectionDialog *> selections_;
|
QMap<QString, SelectionDialog *> selections_;
|
||||||
ResultDialog *resultDialog_;
|
ResultDialog *resultDialog_;
|
||||||
|
Updater *updater_;
|
||||||
|
QTimer *updateTimer_;
|
||||||
QAction *captureAction_;
|
QAction *captureAction_;
|
||||||
QAction *repeatCaptureAction_;
|
QAction *repeatCaptureAction_;
|
||||||
QAction *repeatAction_;
|
QAction *repeatAction_;
|
||||||
|
Loading…
Reference in New Issue
Block a user