1 /* VersionChecker.cpp */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "VersionChecker.h"
22 
23 #include "Utils/Utils.h"
24 #include "Utils/WebAccess/AsyncWebAccess.h"
25 #include "Utils/Message/Message.h"
26 #include "Utils/Logger/Logger.h"
27 #include "Utils/Settings/Settings.h"
28 
29 #include "Gui/Utils/Style.h"
30 
VersionChecker(QObject * parent)31 VersionChecker::VersionChecker(QObject* parent) :
32 	QObject(parent)
33 {
34 	auto* awa = new AsyncWebAccess(this);
35 	awa->run("http://sayonara-player.com/current_version");
36 	connect(awa, &AsyncWebAccess::sigFinished, this, &VersionChecker::versionCheckFinished);
37 }
38 
39 VersionChecker::~VersionChecker() = default;
40 
versionCheckFinished()41 void VersionChecker::versionCheckFinished()
42 {
43 	auto* awa = dynamic_cast<AsyncWebAccess*>(sender());
44 	if(!awa)
45 	{
46 		return;
47 	}
48 
49 	const auto status = awa->status();
50 	const auto data = awa->data();
51 
52 	awa->deleteLater();
53 
54 	if(status != AsyncWebAccess::Status::GotData || data.isEmpty())
55 	{
56 		return;
57 	}
58 
59 	const auto newVersion = QString(data).trimmed();
60 	const auto curVersion = GetSetting(Set::Player_Version);
61 
62 	spLog(Log::Info, this) << "Newest Version: " << newVersion;
63 	spLog(Log::Info, this) << "This Version:   " << curVersion;
64 
65 	if(GetSetting(Set::Player_NotifyNewVersion))
66 	{
67 		if(newVersion > curVersion)
68 		{
69 			Message::info(tr("A new version is available!") + "<br />" +
70 			              Util::createLink("http://sayonara-player.com", Style::isDark()));
71 		}
72 	}
73 
74 	emit sigFinished();
75 }
76