From 9e82210463aed66743ae7ae9cccc260e69596b25 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sat, 11 Oct 2014 03:38:19 +0400 Subject: [PATCH] implement autoupdate function to aw (see #32) --- sources/awesome-widget/awesome-widget.cpp | 55 +++++++++++++++++++++-- sources/awesome-widget/awesome-widget.h | 8 +++- sources/version.h.in | 1 + 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/sources/awesome-widget/awesome-widget.cpp b/sources/awesome-widget/awesome-widget.cpp index 9408a2e..bd4f59d 100644 --- a/sources/awesome-widget/awesome-widget.cpp +++ b/sources/awesome-widget/awesome-widget.cpp @@ -25,7 +25,11 @@ #include #include #include +#include +#include #include +#include +#include #include #include #include @@ -63,13 +67,13 @@ AwesomeWidget::~AwesomeWidget() } -bool AwesomeWidget::checkUpdates() +void AwesomeWidget::checkUpdates() { if (debug) qDebug() << PDEBUG; - bool needUpdate = false; - - return needUpdate; + QNetworkAccessManager *manager = new QNetworkAccessManager(this); + connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyRecieved(QNetworkReply *))); + manager->get(QNetworkRequest(QUrl(VERSION_API))); } @@ -97,6 +101,9 @@ void AwesomeWidget::createActions() connect(contextMenu[2], SIGNAL(triggered(bool)), this, SLOT(updateNetworkDevice())); connect(contextMenu[2], SIGNAL(triggered(bool)), extsysmonEngine, SLOT(updateAllSources())); connect(contextMenu[2], SIGNAL(triggered(bool)), sysmonEngine, SLOT(updateAllSources())); + contextMenu.append(new QAction(QIcon::fromTheme(QString("system-software-update")), + i18n("Check for updates"), this)); + connect(contextMenu[3], SIGNAL(triggered(bool)), this, SLOT(checkUpdates())); } @@ -225,6 +232,29 @@ void AwesomeWidget::init() connect(timer, SIGNAL(timeout()), this, SLOT(updateText())); connect(timer, SIGNAL(timeout()), this, SLOT(updateTooltip())); timer->start(); + // check for updates + connect(this, SIGNAL(thereIsUpdates(QString)), this, SLOT(showUpdates(QString))); + checkUpdates(); +} + + +void AwesomeWidget::replyRecieved(QNetworkReply *reply) +{ + if (debug) qDebug() << PDEBUG; + + QString answer = reply->readAll(); + if (!answer.contains(QString("tag_name"))) return; + QString version = QString(VERSION); + if (debug) qDebug() << PDEBUG << answer; + for (int i=0; i contextualActions(); void createConfigurationInterface(KConfigDialog *parent); diff --git a/sources/version.h.in b/sources/version.h.in index 5886127..05705bb 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -13,6 +13,7 @@ // links #define HOMEPAGE "http://arcanis.name/projects/awesome-widgets/" #define REPOSITORY "https://github.com/arcan1s/awesome-widgets" +#define RELEASES "https://github.com/arcan1s/awesome-widgets/releases/tag/V." #define VERSION_API "https://api.github.com/repos/arcan1s/awesome-widgets/releases" #define BUGTRACKER "https://github.com/arcan1s/awesome-widgets/issues" #define TRANSLATION "https://github.com/arcan1s/awesome-widgets/issues/14"