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

Commit

Permalink
#48 Show notifications
Browse files Browse the repository at this point in the history
and improve log messages
  • Loading branch information
ColinDuquesnoy committed Mar 12, 2017
1 parent a2cba5b commit 45edb2a
Show file tree
Hide file tree
Showing 64 changed files with 858 additions and 171 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ add_definitions(-DCMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}")

include(scripts/cmake/Macros.cmake)
include(scripts/cmake/Config.cmake)
include(scripts/cmake/Qt5Config.cmake)
include(scripts/cmake/FindDependencies.cmake)

# Options
set_option(CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release).")
Expand All @@ -27,7 +27,7 @@ if(ENABLE_COVERAGE)
endif()
add_subdirectory(lib)
add_subdirectory(src)
if(${BUILD_TESTS})
if(BUILD_TESTS)
enable_testing(true)
add_subdirectory(tests)
endif()
Expand Down
5 changes: 5 additions & 0 deletions lib/MellowPlayer/Infrastructure.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#pragma once


#include "Infrastructure/AlbumArtDownloader.hpp"
#include "Infrastructure/ApplicationSettings.hpp"
#include "Infrastructure/PluginLoader.hpp"

#include "Infrastructure/Applications/Application.hpp"
#include "Infrastructure/Applications/IApplication.hpp"
#include "Infrastructure/Applications/SingleInstanceApplication.hpp"

#include "Infrastructure/Logging/SpdLogger.hpp"
#include "Infrastructure/Logging/SpdLoggerFactory.hpp"

#include "Infrastructure/Services/HotkeysService.hpp"

#include "Infrastructure/System/FileHelper.hpp"

#ifdef Q_OS_LINUX
Expand Down
4 changes: 2 additions & 2 deletions lib/MellowPlayer/Infrastructure/AlbumArtDownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bool AlbumArtDownloader::download(const QString& url, const QString& songId) {
return false;

artUrl = getLocalArtUrl(songId);
LOG_INFO(logger, "downloading " << url << " to " << artUrl.absoluteFilePath());
LOG_DEBUG(logger, "downloading " + url + " to " + artUrl.absoluteFilePath());
if (artUrl.exists()) {
LOG_DEBUG(logger, "album art already exists locally")
emit downloadFinished(artUrl.absoluteFilePath());
Expand Down Expand Up @@ -45,7 +45,7 @@ void AlbumArtDownloader::onDownloadFinished(QNetworkReply* reply) {
file.write(reply->readAll());
file.close();
} else {
LOG_DEBUG(logger, "Could not open file in write only mode: " << artUrl.absoluteFilePath());
LOG_DEBUG(logger, "could not open file in write only mode: " +artUrl.absoluteFilePath());
}
emit downloadFinished(artUrl.absoluteFilePath());
}
25 changes: 25 additions & 0 deletions lib/MellowPlayer/Infrastructure/ApplicationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

USE_MELLOWPLAYER_NAMESPACE(UseCases)
USE_MELLOWPLAYER_NAMESPACE(Infrastructure)
using namespace std;

const QString ApplicationSettings::CURRENT_SERVICE_KEY = "currentService";
const QString ApplicationSettings::SHOW_CLOSE_TO_SYS_TRAY_MESSAGE_KEY = "showCloseToSystemTrayMessage";
const QString ApplicationSettings::TRAY_ICON_KEY = "getTrayIcon";
const QString ApplicationSettings::NOTIFICATIONS_ENABLED_KEY = "notificationsEnabled";
const QString ApplicationSettings::NOTIFICATION_ENABLED_KEY = "notification/%1";

ApplicationSettings::ApplicationSettings(): qSettings() {

Expand Down Expand Up @@ -47,3 +50,25 @@ void ApplicationSettings::setTrayIcon(const QString& trayIcon) {
qSettings.setValue(TRAY_ICON_KEY, trayIcon);
}

bool ApplicationSettings::getNotificationsEnabled() const {
return qSettings.value(NOTIFICATIONS_ENABLED_KEY, true).toBool();
}

void ApplicationSettings::setNotificationsEnabled(bool enable) {
qSettings.setValue(NOTIFICATIONS_ENABLED_KEY, enable);

}

bool ApplicationSettings::isNotificationTypeEnabled(NotificationType notificationType) const {
if (!getNotificationsEnabled())
return false;
return qSettings.value(getNotificationEnabledKey(notificationType), true).toBool();
}

void ApplicationSettings::enableNotificationType(NotificationType notificationType, bool enable) {
qSettings.setValue(getNotificationEnabledKey(notificationType), enable);
}

QString ApplicationSettings::getNotificationEnabledKey(NotificationType type) const {
return NOTIFICATION_ENABLED_KEY.arg(static_cast<int>(type));
}
10 changes: 10 additions & 0 deletions lib/MellowPlayer/Infrastructure/ApplicationSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ class ApplicationSettings: public UseCases::IApplicationSettings {
QString getTrayIcon() const override;
void setTrayIcon(const QString& trayIcon) override;

bool getNotificationsEnabled() const override;
void setNotificationsEnabled(bool enable) override;

bool isNotificationTypeEnabled(UseCases::NotificationType notificationType) const override;
void enableNotificationType(UseCases::NotificationType notificationType, bool enable) override;

static const QString CURRENT_SERVICE_KEY;
static const QString SHOW_CLOSE_TO_SYS_TRAY_MESSAGE_KEY;
static const QString TRAY_ICON_KEY;
static const QString NOTIFICATIONS_ENABLED_KEY;
static const QString NOTIFICATION_ENABLED_KEY;
private:
QString getNotificationEnabledKey(UseCases::NotificationType type) const;

QSettings qSettings;
};

Expand Down
24 changes: 21 additions & 3 deletions lib/MellowPlayer/Infrastructure/Applications/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,43 @@
USE_MELLOWPLAYER_NAMESPACE(UseCases)
USE_MELLOWPLAYER_NAMESPACE(Infrastructure)

Application::Application(IQtApplication& qtApp, IMainWindow& mainWindow, IHotkeysService& kotkeys,
ISystemTrayIcon& systemTrayIcon):
qtApp(qtApp), mainWindow(mainWindow), kotkeys(kotkeys), systemTrayIcon(systemTrayIcon) {
Application::Application(IQtApplication& qtApp,
IMainWindow& mainWindow,
PluginManager& pluginManager,
IHotkeysService& kotkeys,
ISystemTrayIcon& systemTrayIcon,
INotificationService& notificationService) :
logger(LoggingManager::instance().getLogger("Application")),
qtApp(qtApp),
mainWindow(mainWindow),
pluginManager(pluginManager),
kotkeys(kotkeys),
systemTrayIcon(systemTrayIcon),
notificationService(notificationService) {

}

void Application::initialize() {
LOG_TRACE(logger, "initialize");
pluginManager.load();
mainWindow.load();
kotkeys.start();
notificationService.initialize();
mainWindow.show();
systemTrayIcon.show();
}

void Application::restoreWindow() {
LOG_TRACE(logger, "restoreWindow");
mainWindow.show();
}

int Application::run() {
LOG_TRACE(logger, "run");
return qtApp.run();
}

void Application::quit() {
LOG_TRACE(logger, "quit");
qtApp.quit();
}
11 changes: 9 additions & 2 deletions lib/MellowPlayer/Infrastructure/Applications/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@ BEGIN_MELLOWPLAYER_NAMESPACE(Infrastructure)

class Application : public IApplication {
public:
Application(UseCases::IQtApplication& qtApp, UseCases::IMainWindow& mainWindow, UseCases::IHotkeysService& kotkeys,
UseCases::ISystemTrayIcon& systemTrayIcon);
Application(UseCases::IQtApplication& qtApp,
UseCases::IMainWindow& mainWindow,
UseCases::PluginManager& pluginManager,
UseCases::IHotkeysService& kotkeys,
UseCases::ISystemTrayIcon& systemTrayIcon,
UseCases::INotificationService& notificationService);

void initialize() override;
void restoreWindow() override;
int run() override;
void quit() override;

private:
UseCases::ILogger& logger;
UseCases::IQtApplication& qtApp;
UseCases::IMainWindow& mainWindow;
UseCases::PluginManager& pluginManager;
UseCases::IHotkeysService& kotkeys;
UseCases::ISystemTrayIcon& systemTrayIcon;
UseCases::INotificationService& notificationService;
};

END_MELLOWPLAYER_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ USE_MELLOWPLAYER_NAMESPACE(Infrastructure)

LinuxApplication::LinuxApplication(IQtApplication& qtApp,
IMainWindow& mainWindow,
PluginManager& pluginManager,
IHotkeysService& kotkeys,
ISystemTrayIcon& systemTrayIcon,
INotificationService& playerNotificationService,
IMprisService& mprisService) :
Application(qtApp, mainWindow, kotkeys, systemTrayIcon), mprisService(mprisService) {
Application(qtApp, mainWindow, pluginManager, kotkeys, systemTrayIcon, playerNotificationService),
logger(LoggingManager::instance().getLogger("LinuxApplication")),
mprisService(mprisService) {

}

void LinuxApplication::initialize() {
LOG_TRACE(logger, "initialize");
Application::initialize();
mprisService.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ BEGIN_MELLOWPLAYER_NAMESPACE(Infrastructure)

class LinuxApplication: public Application {
public:
LinuxApplication(UseCases::IQtApplication& qtApp, UseCases::IMainWindow& mainWindow,
UseCases::IHotkeysService& kotkeys, UseCases::ISystemTrayIcon& systemTrayIcon,
LinuxApplication(UseCases::IQtApplication& qtApp,
UseCases::IMainWindow& mainWindow,
UseCases::PluginManager& pluginManager,
UseCases::IHotkeysService& kotkeys,
UseCases::ISystemTrayIcon& systemTrayIcon,
UseCases::INotificationService& playerNotificationService,
UseCases::IMprisService& mprisService);
void initialize() override;

private:
UseCases::ILogger& logger;
UseCases::IMprisService& mprisService;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ SingleInstanceApplication::SingleInstanceApplication(IApplication& application):
}

int SingleInstanceApplication::run() {
LOG_DEBUG(logger, "connecting to locale server");
LOG_TRACE(logger, "run");
LOG_DEBUG(logger, "starting, connecting to local server");
localSocket.connectToServer("MellowPlayer3", QIODevice::WriteOnly);
return application.run();
}

void SingleInstanceApplication::onSocketConnected() {
LOG_DEBUG(logger, "Another instance is already running, quitting");
LOG_INFO(logger, "another instance is already running, quitting");
QTimer::singleShot(100, this, &SingleInstanceApplication::quit);
}

void SingleInstanceApplication::onSocketError() {
LOG_DEBUG(logger, "initializaing");
localServer.listen("MellowPlayer3");
connectSignalHandlers();
application.initialize();
application.restoreWindow();
}

void SingleInstanceApplication::onNewConnection() {
Expand All @@ -57,5 +58,6 @@ void SingleInstanceApplication::connectSignalHandlers()
}

void SingleInstanceApplication::quit() {
LOG_TRACE(logger, "quit");
application.quit();
}
18 changes: 8 additions & 10 deletions lib/MellowPlayer/Infrastructure/PluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ USE_MELLOWPLAYER_NAMESPACE(UseCases)
USE_MELLOWPLAYER_NAMESPACE(Infrastructure)
using namespace std;

PluginLoader::PluginLoader():
PluginLoader::PluginLoader() :
logger(LoggingManager::instance().getLogger("PluginManager")) {

}
Expand All @@ -20,22 +20,20 @@ PluginList PluginLoader::load() const {
PluginList plugins;
for (const QString& path: getSearchPaths()) {
if (!QDir(path).exists()) {
LOG_TRACE(logger, "Skipping plugin path: " << path.toStdString().c_str() << " (directory not found)");
LOG_DEBUG(logger, "Skipping plugin path: " << path.toStdString().c_str() << " (directory not found)");
continue;
}
LOG_TRACE(logger, "Looking for plugins in " << path.toStdString().c_str());
LOG_DEBUG(logger, "Looking for plugins in " << path.toStdString().c_str());
for (const QFileInfo& directory: QDir(path).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) {
if (checkPluginDirectory(directory.absoluteFilePath())) {
shared_ptr<Plugin> plugin = loadPlugin(directory.absoluteFilePath());
if (plugin->isValid() && !containsPlugin(plugins, plugin)) {
LOG_DEBUG(logger, plugin->getName().toStdString().c_str()
<< " plugin successfully loaded (from \"" <<
directory.absoluteFilePath().toStdString().c_str() << "\")");
LOG_INFO(logger, plugin->getName() + " plugin successfully loaded (from \"" +
directory.absoluteFilePath() + "\")");
plugins.append(plugin);
} else {
LOG_DEBUG(logger,
"Skipping plugin " << plugin->getName().toStdString().c_str()
<< ", already loaded from another source or invalid");
LOG_DEBUG(logger, "Skipping plugin " + plugin->getName() +
", already loaded from another source or invalid");
}
}
}
Expand Down Expand Up @@ -130,7 +128,7 @@ QStringList PluginLoader::getSearchPaths() const {
}

bool PluginLoader::containsPlugin(const PluginList& plugins,
shared_ptr<Plugin>& toCheck) const {
shared_ptr<Plugin>& toCheck) const {
for (auto plugin: plugins) {
if (*toCheck == *plugin)
return true;
Expand Down
43 changes: 23 additions & 20 deletions lib/MellowPlayer/Infrastructure/Services/HotkeysService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ USE_MELLOWPLAYER_NAMESPACE(Infrastructure)

HotkeysService::HotkeysService(IPlayer& player) :
QObject(nullptr), logger(LoggingManager::instance().getLogger("Hotkeys")), player(player) {
}

void HotkeysService::togglePlayPause() {
player.togglePlayPause();
}

void HotkeysService::next() {
player.next();
}

void HotkeysService::previous() {
player.previous();
}

void HotkeysService::toggleFavoriteSong() {
player.toggleFavoriteSong();
}

HotkeysService::~HotkeysService() {

}

void HotkeysService::start() {

playShortcut = new QxtGlobalShortcut(this);
playShortcut->setShortcut(QKeySequence("Ctrl+Alt+P"));
Expand Down Expand Up @@ -39,23 +62,3 @@ HotkeysService::HotkeysService(IPlayer& player) :

LOG_INFO(logger, "service started");
}

void HotkeysService::togglePlayPause() {
player.togglePlayPause();
}

void HotkeysService::next() {
player.next();
}

void HotkeysService::previous() {
player.previous();
}

void HotkeysService::toggleFavoriteSong() {
player.toggleFavoriteSong();
}

HotkeysService::~HotkeysService() {

}
2 changes: 2 additions & 0 deletions lib/MellowPlayer/Infrastructure/Services/HotkeysService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class HotkeysService: public QObject, public UseCases::IHotkeysService {
HotkeysService(UseCases::IPlayer& player);
~HotkeysService();

void start() override;

public slots:
void togglePlayPause() override;
void next() override;
Expand Down
Loading

0 comments on commit 45edb2a

Please sign in to comment.