push for now

This commit is contained in:
apa420 2018-08-19 19:02:49 +02:00
parent 21c4880ace
commit 8d5b93fe82
10 changed files with 170 additions and 90 deletions

View file

@ -256,7 +256,7 @@ SOURCES += \
src/util/FunctionEventFilter.cpp \
src/controllers/notifications/NotificationModel.cpp \
src/singletons/Toasts.cpp \
src/singletons/DownloadManager.cpp
src/common/DownloadManager.cpp
HEADERS += \
src/Application.hpp \
@ -458,9 +458,8 @@ HEADERS += \
src/util/FormatTime.hpp \
src/util/FunctionEventFilter.hpp \
src/controllers/notifications/NotificationModel.hpp \
src/controllers/notifications/NotificationPhrase.hpp \
src/singletons/Toasts.hpp \
src/singletons/DownloadManager.hpp
src/common/DownloadManager.hpp
RESOURCES += \
resources/resources.qrc \

View file

@ -12,7 +12,6 @@
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/twitch/PubsubClient.hpp"
#include "providers/twitch/TwitchServer.hpp"
#include "singletons/DownloadManager.hpp"
#include "singletons/Fonts.hpp"
#include "singletons/Logging.hpp"
#include "singletons/NativeMessaging.hpp"
@ -46,8 +45,8 @@ Application::Application(Settings &_settings, Paths &_paths)
, fonts(&this->emplace<Fonts>())
, emotes(&this->emplace<Emotes>())
, windows(&this->emplace<WindowManager>())
, toasts(&this->emplace<Toasts>())
, accounts(&this->emplace<AccountController>())
, commands(&this->emplace<CommandController>())
, highlights(&this->emplace<HighlightController>())
@ -57,7 +56,7 @@ Application::Application(Settings &_settings, Paths &_paths)
, moderationActions(&this->emplace<ModerationActions>())
, twitch2(&this->emplace<TwitchServer>())
, logging(&this->emplace<Logging>())
, downloads(&this->emplace<DownloadManager>())
{
this->instance = this;

View file

@ -29,7 +29,6 @@ class Settings;
class Fonts;
class Resources;
class Toasts;
class DownloadManager;
class Application
{
@ -59,7 +58,6 @@ public:
Emotes *const emotes{};
WindowManager *const windows{};
Toasts *const toasts{};
DownloadManager *const downloads{};
AccountController *const accounts{};
CommandController *const commands{};

View file

@ -0,0 +1,80 @@
#include "DownloadManager.hpp"
#include <QDesktopServices>
namespace chatterino {
DownloadManager::DownloadManager(QObject *parent)
: QObject(parent)
{
manager = new QNetworkAccessManager;
}
DownloadManager::~DownloadManager()
{
manager->deleteLater();
}
void DownloadManager::setFile(QString fileURL, const QString &channelName)
{
QString filePath = fileURL;
QString saveFilePath;
QStringList filePathList = filePath.split('/');
// QString fileName = filePathList.at(filePathList.count() - 1);
saveFilePath = QString(
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) +
"2/cache/profileAvatars/twitch/" + channelName + ".png");
QNetworkRequest request;
request.setUrl(QUrl(fileURL));
reply = manager->get(request);
file = new QFile;
file->setFileName(saveFilePath);
file->open(QIODevice::WriteOnly);
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this,
SLOT(onDownloadProgress(qint64, qint64)));
connect(manager, SIGNAL(finished(QNetworkReply *)), this,
SLOT(onFinished(QNetworkReply *)));
connect(reply, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
connect(reply, SIGNAL(finished()), this, SLOT(onReplyFinished()));
}
void DownloadManager::onDownloadProgress(qint64 bytesRead, qint64 bytesTotal)
{
qDebug(QString::number(bytesRead).toLatin1() + " - " +
QString::number(bytesTotal).toLatin1());
}
void DownloadManager::onFinished(QNetworkReply *reply)
{
switch (reply->error()) {
case QNetworkReply::NoError: {
qDebug("file is downloaded successfully.");
} break;
default: {
qDebug(reply->errorString().toLatin1());
};
}
if (file->isOpen()) {
file->close();
file->deleteLater();
}
emit downloadComplete();
}
void DownloadManager::onReadyRead()
{
file->write(reply->readAll());
}
void DownloadManager::onReplyFinished()
{
if (file->isOpen()) {
file->close();
file->deleteLater();
}
}
} // namespace chatterino

View file

@ -0,0 +1,36 @@
#pragma once
#include "Application.hpp"
#include <QFile>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QObject>
#include <QStringList>
namespace chatterino {
class DownloadManager : public QObject
{
Q_OBJECT
public:
explicit DownloadManager(QObject *parent = 0);
virtual ~DownloadManager();
void setFile(QString fileURL, const QString &channelName);
private:
QNetworkAccessManager *manager;
QNetworkReply *reply;
QFile *file;
private slots:
void onDownloadProgress(qint64, qint64);
void onFinished(QNetworkReply *);
void onReadyRead();
void onReplyFinished();
signals:
void downloadComplete();
};
} // namespace chatterino

View file

@ -146,6 +146,8 @@ public:
false};
BoolSetting notificationToast = {"/notifications/enableToast", false};
BoolSetting notificationDot = {"/notifications/enableDot", false};
BoolSetting notificationSplitheaderHighlight = {
"/notifications/enableSplitheaderHighlight", false};
/// External tools
// Streamlink

View file

@ -1,6 +1,7 @@
#include "Toasts.hpp"
#include "Application.hpp"
#include "common/DownloadManager.hpp"
#include "common/NetworkRequest.hpp"
#include "controllers/notifications/NotificationController.hpp"
#include "providers/twitch/TwitchChannel.hpp"
@ -15,7 +16,6 @@
#include <QDesktopServices>
#include <QFileInfo>
//#include <QtNetwork>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QUrl>
@ -32,15 +32,38 @@ bool Toasts::isEnabled()
void Toasts::sendChannelNotification(const QString &channelName, Platform p)
{
// Fetch user profile avatar
if (p == Platform::Twitch) {
QFileInfo check_file(
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) +
"2/cache/profileAvatars/twitch/" + channelName + ".png");
if (check_file.exists() && check_file.isFile()) {
#ifdef Q_OS_WIN
sendWindowsNotification(channelName, p);
return;
this->sendWindowsNotification(channelName, p);
#endif
// OSX
// OSX
// LINUX
// LINUX
} else {
this->fetchChannelAvatar(
channelName, [this, channelName, p](QString avatarLink) {
DownloadManager *manager = new DownloadManager();
manager->setFile(avatarLink, channelName);
manager->connect(
manager, &DownloadManager::downloadComplete,
[this, channelName, p]() {
#ifdef Q_OS_WIN
this->sendWindowsNotification(channelName, p);
#endif
// OSX
// LINUX
});
});
}
}
return;
}
#ifdef Q_OS_WIN
@ -84,29 +107,6 @@ public:
};
void Toasts::sendWindowsNotification(const QString &channelName, Platform p)
{
// Fetch user profile avatar
if (p == Platform::Twitch) {
QFileInfo check_file(
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) +
"2/cache/profileAvatars/twitch/" + channelName + ".png");
if (check_file.exists() && check_file.isFile()) {
qDebug() << " OMEGA2NAM ";
this->sendActualWindowsNotification(channelName, p);
} else {
qDebug() << " OMEGA1NAM ";
this->fetchChannelAvatar(
channelName, [this, channelName, p](QString avatarLink) {
qDebug() << " OMEGANAM " << avatarLink;
this->sendActualWindowsNotification(channelName, p);
});
}
}
qDebug() << " YOU'RE TOO SLOW! ";
}
void Toasts::sendActualWindowsNotification(const QString &channelName,
Platform p)
{
WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate(
WinToastLib::WinToastTemplate::ImageAndText02);
@ -145,51 +145,7 @@ void Toasts::sendActualWindowsNotification(const QString &channelName,
}
#endif
/*
void Toasts::fetchChannelAvatar(const QString &channelName,
std::function<void(QString)> successCallback)
{
QString requestUrl("https://api.twitch.tv/kraken/users?login=" +
channelName);
NetworkRequest request(requestUrl, NetworkRequestType::Put);
request.setCaller(QThread::currentThread());
request.makeAuthorizedV5(getDefaultClientID());
request.setTimeout(30000);
request.onSuccess([successCallback](auto result) -> Outcome {
auto root = result.parseJson();
if (!root.value("users").isArray()) {
Log("API Error while getting user id, users is not an array");
successCallback("");
return Failure;
}
auto users = root.value("users").toArray();
if (users.size() != 1) {
Log("API Error while getting user id, users array size is not 1");
successCallback("");
return Failure;
}
if (!users[0].isObject()) {
Log("API Error while getting user id, first user is not an object");
successCallback("");
return Failure;
}
auto firstUser = users[0].toObject();
auto avatar = firstUser.value("logo");
if (!avatar.isString()) {
Log("API Error: while getting user logo, first user object `logo` "
"key "
"is not a "
"string");
successCallback("");
return Failure;
}
successCallback(avatar.toString());
return Success;
});
request.execute();
}
*/
void Toasts::fetchChannelAvatar(const QString channelName,
std::function<void(QString)> successCallback)
{

View file

@ -2,13 +2,7 @@
#include "Application.hpp"
#include "common/Singleton.hpp"
/*
#ifdef Q_OS_WIN
#include "wintoastlib.h"
#endif
*/
namespace chatterino {
enum class Platform : uint8_t;
@ -22,7 +16,6 @@ public:
private:
void sendWindowsNotification(const QString &channelName, Platform p);
void sendActualWindowsNotification(const QString &channelName, Platform p);
static void fetchChannelAvatar(
const QString channelName,
std::function<void(QString)> successCallback);

View file

@ -41,6 +41,9 @@ NotificationPage::NotificationPage()
settings.append(
this->createCheckBox("Red dot next to live splits",
getApp()->settings->notificationDot));
settings.append(this->createCheckBox(
"Change color of Splitheader (click to remove)",
getApp()->settings->notificationSplitheaderHighlight));
settings->addStretch(1);
}

View file

@ -549,7 +549,21 @@ void SplitHeader::themeChangedEvent()
getApp()->resources->buttons.menuLight);
}
this->titleLabel->setPalette(palette);
// this->titleLabel->setPalette(palette);
auto darkPalette = palette;
darkPalette.setColor(QPalette::Window, QColor(53, 53, 53));
darkPalette.setColor(QPalette::WindowText, Qt::white);
darkPalette.setColor(QPalette::Base, QColor(25, 25, 25));
darkPalette.setColor(QPalette::AlternateBase, QColor(53, 53, 53));
darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
darkPalette.setColor(QPalette::ToolTipText, Qt::white);
darkPalette.setColor(QPalette::Text, Qt::white);
darkPalette.setColor(QPalette::Button, QColor(53, 53, 53));
darkPalette.setColor(QPalette::ButtonText, Qt::white);
darkPalette.setColor(QPalette::BrightText, Qt::red);
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
this->titleLabel->setPalette(darkPalette);
}
void SplitHeader::menuMoveSplit()