BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
UpdateNotifier Class Reference
Inheritance diagram for UpdateNotifier:
[legend]
Collaboration diagram for UpdateNotifier:
[legend]

Public Slots

bool hasDefinedUpdatesFlag () const
 Returns true if settings contain record about user choice for updates. More...
 
void replyFinished (QNetworkReply *reply)
 
void setCheckUpdatesFlag (bool flag)
 
bool updatesFlag () const
 Returns true if there is defined flag requiring check for updates. More...
 

Signals

void onUpdateNotification (const QString &text)
 

Public Member Functions

 UpdateNotifier (QObject *parent=0)
 
void checkForUpdates ()
 

Private Attributes

QNetworkAccessManager * m_networkAccessManager
 

Detailed Description

Definition at line 23 of file UpdateNotifier.h.

Constructor & Destructor Documentation

◆ UpdateNotifier()

UpdateNotifier::UpdateNotifier ( QObject *  parent = 0)

Definition at line 20 of file UpdateNotifier.cpp.

21  : QObject(parent), m_networkAccessManager(new QNetworkAccessManager(parent))
22 {
23  connect(m_networkAccessManager, &QNetworkAccessManager::finished, this,
25 }
void replyFinished(QNetworkReply *reply)
QNetworkAccessManager * m_networkAccessManager

References m_networkAccessManager, and replyFinished().

Here is the call graph for this function:

Member Function Documentation

◆ checkForUpdates()

void UpdateNotifier::checkForUpdates ( )

Definition at line 27 of file UpdateNotifier.cpp.

28 {
29  if (hasDefinedUpdatesFlag()) {
30  if (updatesFlag()) {
31  QString address(Constants::S_VERSION_URL);
32  QUrl url(address);
33  QNetworkRequest networkRequest(url);
34  networkRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
35  QNetworkRequest::AlwaysNetwork);
36  QString text = QString("Mozilla/5.0 (BornAgainGUI-%1)")
38  networkRequest.setRawHeader(QByteArray("User-Agent"), text.toLatin1());
39  m_networkAccessManager->get(networkRequest);
40  } else {
41  emit onUpdateNotification("");
42  }
43  }
44 }
bool hasDefinedUpdatesFlag() const
Returns true if settings contain record about user choice for updates.
void onUpdateNotification(const QString &text)
bool updatesFlag() const
Returns true if there is defined flag requiring check for updates.
const char S_VERSION_URL[]
QString getBornAgainVersionString()
Definition: GUIHelpers.cpp:130

References GUIHelpers::getBornAgainVersionString(), hasDefinedUpdatesFlag(), m_networkAccessManager, onUpdateNotification(), Constants::S_VERSION_URL, and updatesFlag().

Referenced by UpdateNotifierWidget::onLinkActivated(), UpdateNotifierWidget::showEvent(), and ActionManager::toggleCheckForUpdates().

Here is the call graph for this function:

◆ hasDefinedUpdatesFlag

bool UpdateNotifier::hasDefinedUpdatesFlag ( ) const
slot

Returns true if settings contain record about user choice for updates.

Definition at line 98 of file UpdateNotifier.cpp.

99 {
100  QSettings settings;
101  return settings.childGroups().contains(Constants::S_UPDATES);
102 }
const char S_UPDATES[]

References Constants::S_UPDATES.

Referenced by UpdateNotifierWidget::UpdateNotifierWidget(), and checkForUpdates().

◆ onUpdateNotification

void UpdateNotifier::onUpdateNotification ( const QString &  text)
signal

◆ replyFinished

void UpdateNotifier::replyFinished ( QNetworkReply *  reply)
slot

Definition at line 46 of file UpdateNotifier.cpp.

47 {
48  QString replyString;
49  if (reply->error() == QNetworkReply::NoError) {
50  if (reply->isReadable()) {
51  // Reading the first line of ChangeLog
52  replyString = QString::fromUtf8(reply->readLine().data());
53  int versionIndex = replyString.indexOf("-") + 1;
54  int versionIndexEnd = replyString.indexOf(",", versionIndex);
55  QString versionString = replyString.mid(versionIndex, versionIndexEnd - versionIndex);
56  QString myVersion = GUIHelpers::getBornAgainVersionString();
57 
58  // Testwise degrade version
59  // myVersion = "1.1.0";
60 
61  if (GUIHelpers::versionCode(versionString) > GUIHelpers::versionCode(myVersion)) {
62  QString message("New version is available: <a href=\"");
63  message.append(Constants::S_DOWNLOAD_LINK);
64  message.append("\">");
65  message.append(replyString);
66  message.append("</a>");
67  emit onUpdateNotification(message);
68  } else {
69  emit onUpdateNotification("");
70  }
71  }
72  };
73  reply->deleteLater();
74 }
const char S_DOWNLOAD_LINK[]
int versionCode(const QString &version)
Definition: GUIHelpers.cpp:173

References GUIHelpers::getBornAgainVersionString(), onUpdateNotification(), Constants::S_DOWNLOAD_LINK, and GUIHelpers::versionCode().

Referenced by UpdateNotifier().

Here is the call graph for this function:

◆ setCheckUpdatesFlag

void UpdateNotifier::setCheckUpdatesFlag ( bool  flag)
slot

Definition at line 76 of file UpdateNotifier.cpp.

77 {
78  QSettings settings;
79  settings.beginGroup(Constants::S_UPDATES);
80  settings.setValue(Constants::S_CHECKFORUPDATES, flag);
81  settings.endGroup();
82 }
const char S_CHECKFORUPDATES[]

References Constants::S_CHECKFORUPDATES, and Constants::S_UPDATES.

Referenced by UpdateNotifierWidget::onLinkActivated(), and ActionManager::toggleCheckForUpdates().

◆ updatesFlag

bool UpdateNotifier::updatesFlag ( ) const
slot

Returns true if there is defined flag requiring check for updates.

Definition at line 86 of file UpdateNotifier.cpp.

87 {
88  QSettings settings;
89  if (settings.childGroups().contains(Constants::S_UPDATES)) {
90  settings.beginGroup(Constants::S_UPDATES);
91  return settings.value(Constants::S_CHECKFORUPDATES).toBool();
92  }
93  return false;
94 }

References Constants::S_CHECKFORUPDATES, and Constants::S_UPDATES.

Referenced by checkForUpdates().

Member Data Documentation

◆ m_networkAccessManager

QNetworkAccessManager* UpdateNotifier::m_networkAccessManager
private

Definition at line 42 of file UpdateNotifier.h.

Referenced by UpdateNotifier(), and checkForUpdates().


The documentation for this class was generated from the following files: