implement autoupdate function to aw (see #32)

This commit is contained in:
arcan1s
2014-10-11 03:38:19 +04:00
parent 171d545562
commit 9e82210463
3 changed files with 59 additions and 5 deletions

View File

@ -25,7 +25,11 @@
#include <QGraphicsProxyWidget>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QMessageBox>
#include <QNetworkAccessManager>
#include <QNetworkInterface>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QProcessEnvironment>
#include <QTextCodec>
#include <QTimer>
@ -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<answer.split(QString("tag_name")).count(); i++) {
version = answer.split(QString("tag_name"))[1].split(QChar(','))[0];
version.remove(QChar('"'));
version.remove(QChar(':'));
version.remove(QString("V."));
break;
}
if (version != QString(VERSION))
emit(thereIsUpdates(version));
}
@ -381,4 +411,21 @@ void AwesomeWidget::showReadme()
}
void AwesomeWidget::showUpdates(QString version)
{
if (debug) qDebug() << PDEBUG;
QString text;
text += i18n("Current version : %1", QString(VERSION)) + QString("\n");
text += i18n("New version : %2", version) + QString("\n");
text += i18n("Click \"Ok\" to download");
int select = QMessageBox::information(0, i18n("There are updates"), text, QMessageBox::Ok | QMessageBox::Cancel);
switch(select) {
case QMessageBox::Ok:
QDesktopServices::openUrl(QString(RELEASES) + version);
break;
}
}
K_EXPORT_PLASMA_APPLET(awesome-widget, AwesomeWidget)

View File

@ -33,6 +33,7 @@
class CustomLabel;
class QGraphicsGridLayout;
class QGraphicsScene;
class QNetworkReply;
class AwesomeWidget : public Plasma::Applet
{
@ -55,6 +56,7 @@ public slots:
// contextual actions
void showKsysguard();
void showReadme();
void showUpdates(QString version);
// dataengine
void addDiskDevice(const QString source);
void connectToEngine();
@ -70,8 +72,9 @@ public slots:
void updateTooltip();
private slots:
bool checkUpdates();
void checkUpdates();
void reinit();
void replyRecieved(QNetworkReply *reply);
// configuration interface
void addNewCustomCommand(QTableWidgetItem *item);
void addNewPkgCommand(QTableWidgetItem *item);
@ -85,6 +88,9 @@ private slots:
void setFontFormating();
void setFormating();
signals:
void thereIsUpdates(QString version);
protected:
QList<QAction *> contextualActions();
void createConfigurationInterface(KConfigDialog *parent);

View File

@ -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"