Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Commit

Permalink
#48 Add update footer
Browse files Browse the repository at this point in the history
and refactor QML main window a bit
  • Loading branch information
ColinDuquesnoy committed Jul 18, 2017
1 parent 5931948 commit c6e6482
Show file tree
Hide file tree
Showing 29 changed files with 658 additions and 331 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void GithubReleaseQuerier::onReleaseReady(const Release* release) {
}

bool GithubReleaseQuerier::accept(const Release* release) {
bool accepted;
bool accepted = false;

switch (channel_) {
case UpdateChannel::Continuous:
Expand Down
5 changes: 0 additions & 5 deletions lib/MellowPlayer/Application/Updater/IHttpClient.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion lib/MellowPlayer/Application/Updater/IHttpClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MellowPlayer::Application {
class IHttpClient: public QObject {
Q_OBJECT
public:
virtual ~IHttpClient();
virtual ~IHttpClient() = default;
virtual void get(const QString& url) = 0;

signals:
Expand Down
18 changes: 12 additions & 6 deletions lib/MellowPlayer/Application/Updater/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@

using namespace MellowPlayer::Application;

Updater::Updater(IReleaseQuerier& releaseQuerier, /*IPlatformUpdater& platformUpdater, */ Settings& settings,
const Release& currentRelease) :
Updater::Updater(IReleaseQuerier& releaseQuerier, Settings& settings):
logger_(LoggingManager::instance().getLogger("Updater")),
releaseQuerier_(releaseQuerier),
// platformUpdater_(platformUpdater),
autoCheckEnabledSetting_(settings.get(SettingKey::MAIN_CHECK_FOR_UPDATES)),
updateChannelSetting_(settings.get(SettingKey::MAIN_UPDATE_CHANNEL)),
latestRelease_(&currentRelease) {
latestRelease_(&Release::current()) {
releaseQuerier.setChannel(getChannel());
connect(&releaseQuerier, &IReleaseQuerier::latestReceived, this, &Updater::onLatestReleaseReceived);

// Release* r = new Release("1.95.0", QDate::fromString("2017-06-15"), this);
// setCurrentRelease(r);
}

void Updater::check() {
LOG_DEBUG(logger_, "Checking for updated");
LOG_DEBUG(logger_, "Checking for update");
releaseQuerier_.setChannel(getChannel());
releaseQuerier_.getLatest();
}
Expand Down Expand Up @@ -54,7 +55,7 @@ const Release* Updater::getLatestRelease() const {
}

void Updater::onLatestReleaseReceived(const Release* release) {
LOG_DEBUG(logger_, "Latest release received");
LOG_DEBUG(logger_, "Latest release received: " + release->getName());

if (*release > *latestRelease_) {
LOG_DEBUG(logger_, QString("Latest release is an update (%1 < %2)").arg(
Expand All @@ -64,3 +65,8 @@ void Updater::onLatestReleaseReceived(const Release* release) {
emit updateAvailable();
}
}

void Updater::setCurrentRelease(const Release* currentRelease) {
latestRelease_ = currentRelease;

}
5 changes: 3 additions & 2 deletions lib/MellowPlayer/Application/Updater/Updater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace MellowPlayer::Application {
class Updater: public QObject {
Q_OBJECT
public:
Updater(IReleaseQuerier& releaseQuerier, /*IPlatformUpdater& platformUpdater,*/ Settings& settings,
const Release& currentRelease=Release::current());
Updater(IReleaseQuerier& releaseQuerier, Settings& settings);

void setCurrentRelease(const Release* currentRelease);

void check();
void download();
Expand Down
21 changes: 14 additions & 7 deletions lib/MellowPlayer/Presentation/ViewModels/MainWindowViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ using namespace MellowPlayer::Application;
using namespace MellowPlayer::Presentation;

MainWindowViewModel::MainWindowViewModel(StreamingServicesControllerViewModel& streamingServicesModel,
ListeningHistoryViewModel& listeningHistoryModel,
ThemeViewModel& themeViewModel,
IQtApplication& qtApp,
IPlayer& player,
Settings& settings) :
ListeningHistoryViewModel& listeningHistoryModel,
ThemeViewModel& themeViewModel,
UpdaterViewModel& updaterViewModel,
IQtApplication& qtApp,
IPlayer& player,
Settings& settings) :
logger(LoggingManager::instance().getLogger("MainWindowViewModel")),
settings(settings), streamingServices(streamingServicesModel),
listeningHistory(listeningHistoryModel), settingsViewModel(settings, themeViewModel) {
settings(settings),
streamingServices(streamingServicesModel),
listeningHistory(listeningHistoryModel),
settingsViewModel(settings, themeViewModel),
updaterViewModel(updaterViewModel)
{
qmlRegisterUncreatableType<Player>("MellowPlayer", 3, 0, "Player", "Player cannot be instantiated from QML");
qmlRegisterUncreatableType<SettingKey>("MellowPlayer", 3, 0, "SettingKey",
"SettingKey cannot be instantiated from QML");
Expand All @@ -39,6 +44,7 @@ MainWindowViewModel::MainWindowViewModel(StreamingServicesControllerViewModel& s
context->setContextProperty("_settings", &settingsViewModel);
context->setContextProperty("_window", this);
context->setContextProperty("_app", &qtApp);
context->setContextProperty("_updater", &updaterViewModel);

}

Expand All @@ -50,6 +56,7 @@ bool MainWindowViewModel::load() {
listeningHistory.initialize();
qmlApplicationEngine.addImportPath("qrc:/MellowPlayer/Presentation/Views");
qmlApplicationEngine.load(QUrl("qrc:/MellowPlayer/Presentation/Views/main.qml"));
updaterViewModel.check();
LOG_TRACE(logger, "loaded");
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <MellowPlayer/Application/Presentation/IMainWindow.hpp>
#include <MellowPlayer/Presentation/ViewModels/ClipBoardViewModel.hpp>
#include <MellowPlayer/Presentation/ViewModels/Settings/SettingsViewModel.hpp>
#include "UpdaterViewModel.hpp"

namespace MellowPlayer::Application {

Expand All @@ -28,6 +29,7 @@ namespace MellowPlayer::Presentation {
MainWindowViewModel(StreamingServicesControllerViewModel& streamingServicesModel,
ListeningHistoryViewModel& listeningHistoryModel,
ThemeViewModel& themeViewModel,
UpdaterViewModel& updaterViewModel,
Application::IQtApplication& qtApp,
Application::IPlayer& player,
Application::Settings& settings);
Expand All @@ -51,6 +53,7 @@ namespace MellowPlayer::Presentation {
QQmlApplicationEngine qmlApplicationEngine;
ClipBoardViewModel clipBoardModel;
SettingsViewModel settingsViewModel;
UpdaterViewModel& updaterViewModel;
};

}
11 changes: 10 additions & 1 deletion lib/MellowPlayer/Presentation/ViewModels/ThemeViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,16 @@ double ThemeViewModel::getColorScaleFactor(const QString& color) const {
}

bool ThemeViewModel::isDark(const QString &color) const {
return QColor(color).lightness() < 164;
QColor c(color);
int lightness = c.lightness();
int ffCount = 0;
if (c.red() > 250)
ffCount++;
if (c.green() > 250)
ffCount++;
if (c.blue() > 250)
ffCount++;
return lightness < 164 && ffCount < 2;
}

Theme ThemeViewModel::getCustomTheme() const {
Expand Down
63 changes: 63 additions & 0 deletions lib/MellowPlayer/Presentation/ViewModels/UpdaterViewModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "UpdaterViewModel.hpp"

using namespace MellowPlayer::Application;
using namespace MellowPlayer::Presentation;


UpdaterViewModel::UpdaterViewModel(Updater& updater): updater_(updater) {
connect(&updater, &Updater::updateAvailable, this, &UpdaterViewModel::onUpdateAvailable);
}

bool UpdaterViewModel::isVisible() const {
return visible_;
}

bool UpdaterViewModel::canInstall() const {
return canInstall_;
}

int UpdaterViewModel::getProgress() const {
return progress_;
}

void UpdaterViewModel::close() {
setVisible(false);
}

void UpdaterViewModel::check() {
updater_.check();
}

void UpdaterViewModel::install() {
updater_.install();
}

void UpdaterViewModel::setVisible(bool visible) {
if (visible_ == visible)
return;

visible_ = visible;
emit visibleChanged();
}

void UpdaterViewModel::setCanInstall(bool canInstall) {
if (canInstall_ == canInstall)
return;

canInstall_ = canInstall;
emit canInstallChanged();
}

void UpdaterViewModel::setProgress(int progress) {
if (progress_ == progress)
return;

progress_ = progress;
emit progressChanged();
}

void UpdaterViewModel::onUpdateAvailable() {
setCanInstall(updater_.canInstall());
setProgress(-1);
setVisible(true);
}
41 changes: 41 additions & 0 deletions lib/MellowPlayer/Presentation/ViewModels/UpdaterViewModel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include <QtCore/QObject>
#include <MellowPlayer/Application/Updater/Updater.hpp>

namespace MellowPlayer::Presentation {

class UpdaterViewModel: public QObject {
Q_OBJECT
Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
Q_PROPERTY(bool canInstall READ canInstall NOTIFY canInstallChanged)
Q_PROPERTY(int progress READ getProgress NOTIFY progressChanged)
public:
UpdaterViewModel(Application::Updater& updater);

bool isVisible() const;
bool canInstall() const;
int getProgress() const;

Q_INVOKABLE void close();
Q_INVOKABLE void check();
void install();

signals:
void visibleChanged();
void canInstallChanged();
void progressChanged();

private slots:
void setVisible(bool visible);
void setCanInstall(bool canInstall);
void setProgress(int progress);
void onUpdateAvailable();

private:
Application::Updater& updater_;
bool visible_ = false;
bool canInstall_ = false;
int progress_ = -1;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ToolBar {
id: root

property bool isWebViewMode: false
property bool isCurrentServiceRunning_: false
property bool isCurrentServiceRunning: false

signal showOverviewRequested()
signal showWebViewRequested()
Expand Down Expand Up @@ -49,7 +49,7 @@ ToolBar {
font.family: MaterialIcons.family
font.pixelSize: d.iconSize + 2
hoverEnabled: true
visible: isCurrentServiceRunning_ || isWebViewMode
visible: isCurrentServiceRunning || isWebViewMode

onClicked: switchView()

Expand Down
Loading

0 comments on commit c6e6482

Please sign in to comment.