This repository has been archived by the owner on May 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
319 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
# build QxtGlobalShortcut lib | ||
if (NOT qxtglobalshortcut_FOUND) | ||
set(SOURCE_FILES ${SOURCE_FILES} ${CMAKE_SOURCE_DIR}/3rdparty/libqxt/src/widgets/qxtglobalshortcut.cpp) | ||
if (WIN32) | ||
set(SOURCE_FILES ${SOURCE_FILES} ${CMAKE_SOURCE_DIR}/3rdparty/libqxt/src/widgets/win/qxtglobalshortcut_win.cpp) | ||
elseif(APPLE) | ||
set(SOURCE_FILES ${SOURCE_FILES} ${CMAKE_SOURCE_DIR}/3rdparty/libqxt/src/widgets/mac/qxtglobalshortcut_mac.cpp) | ||
elseif(UNIX) | ||
set(SOURCE_FILES ${SOURCE_FILES} ${CMAKE_SOURCE_DIR}/3rdparty/libqxt/src/widgets/x11/qxtglobalshortcut_x11.cpp) | ||
endif() | ||
add_definitions(-DBUILD_QXT_CORE -DBUILD_QXT_GUI -DQXT_STATIC) | ||
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/3rdparty/libqxt/src/core) | ||
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/3rdparty/libqxt/src/widgets/) | ||
include_directories(SYSTEM ${Qt5Gui_PRIVATE_INCLUDE_DIRS}) | ||
add_library(qxtglobalshortcut STATIC ${SOURCE_FILES}) | ||
target_link_libraries(qxtglobalshortcut Qt5::Core Qt5::Widgets) | ||
endif() | ||
|
||
add_subdirectory(Domain) | ||
add_subdirectory(Infrastructure) | ||
add_subdirectory(Presentation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#include "Hotkeys.hpp" | ||
#include <MellowPlayer/Domain/Logging/ILogger.hpp> | ||
#include <MellowPlayer/Domain/Logging/LoggingManager.hpp> | ||
#include <MellowPlayer/Domain/Logging/LoggingMacros.hpp> | ||
#include <MellowPlayer/Domain/Player/IPlayer.hpp> | ||
#include <MellowPlayer/Domain/Settings/Setting.hpp> | ||
#include <MellowPlayer/Domain/Settings/Settings.hpp> | ||
#include <MellowPlayer/Presentation/MainWindow.hpp> | ||
#include <qxtglobalshortcut.h> | ||
|
||
using namespace MellowPlayer::Domain; | ||
using namespace MellowPlayer::Presentation; | ||
|
||
Hotkeys::Hotkeys(IPlayer& player, Settings& settings, IMainWindow& mainWindow) | ||
: QObject(nullptr), | ||
logger_(LoggingManager::logger("Hotkeys")), | ||
player_(player), | ||
mainWindow_(mainWindow), | ||
playShortcutSetting_(settings.get(SettingKey::SHORTCUTS_PLAY)), | ||
nextShortcutSetting_(settings.get(SettingKey::SHORTCUTS_NEXT)), | ||
previousShortcutSetting_(settings.get(SettingKey::SHORTCUTS_PREVIOUS)), | ||
favoriteShortcutSetting_(settings.get(SettingKey::SHORTCUTS_FAVORITE)), | ||
restoreWindowShortcutSetting_(settings.get(SettingKey::SHORTCUTS_RESTORE_WINDOW)) | ||
{ | ||
connect(&playShortcutSetting_, &Setting::valueChanged, this, &Hotkeys::updatePlayShortcut); | ||
connect(&nextShortcutSetting_, &Setting::valueChanged, this, &Hotkeys::updateNextShortcut); | ||
connect(&previousShortcutSetting_, &Setting::valueChanged, this, &Hotkeys::updatePreviousShorcut); | ||
connect(&favoriteShortcutSetting_, &Setting::valueChanged, this, &Hotkeys::updateFavoriteShortcut); | ||
connect(&restoreWindowShortcutSetting_, &Setting::valueChanged, this, &Hotkeys::updateRestoreWindowShortcut); | ||
} | ||
|
||
void Hotkeys::togglePlayPause() | ||
{ | ||
player_.togglePlayPause(); | ||
} | ||
|
||
void Hotkeys::next() | ||
{ | ||
player_.next(); | ||
} | ||
|
||
void Hotkeys::previous() | ||
{ | ||
player_.previous(); | ||
} | ||
|
||
void Hotkeys::toggleFavoriteSong() | ||
{ | ||
player_.toggleFavoriteSong(); | ||
} | ||
|
||
Hotkeys::~Hotkeys() | ||
{ | ||
} | ||
|
||
void Hotkeys::start() | ||
{ | ||
|
||
playShortcut_ = new QxtGlobalShortcut(this); | ||
updatePlayShortcut(); | ||
connect(playShortcut_, &QxtGlobalShortcut::activated, this, &Hotkeys::togglePlayPause); | ||
|
||
nextShortcut_ = new QxtGlobalShortcut(this); | ||
updateNextShortcut(); | ||
connect(nextShortcut_, &QxtGlobalShortcut::activated, this, &Hotkeys::next); | ||
|
||
previousShortcut_ = new QxtGlobalShortcut(this); | ||
updatePreviousShorcut(); | ||
connect(previousShortcut_, &QxtGlobalShortcut::activated, this, &Hotkeys::previous); | ||
|
||
favoriteShortcut_ = new QxtGlobalShortcut(this); | ||
updateFavoriteShortcut(); | ||
connect(favoriteShortcut_, &QxtGlobalShortcut::activated, this, &Hotkeys::toggleFavoriteSong); | ||
|
||
restoreWindowShortcut_ = new QxtGlobalShortcut(this); | ||
updateRestoreWindowShortcut(); | ||
connect(restoreWindowShortcut_, &QxtGlobalShortcut::activated, this, &Hotkeys::restoreWindow); | ||
|
||
#ifdef Q_OS_WIN | ||
auto mediaShortcut = new QxtGlobalShortcut(this); | ||
mediaShortcut->setShortcut(QKeySequence(Qt::Key_MediaPlay)); | ||
connect(mediaShortcut, &QxtGlobalShortcut::activated, this, &Hotkeys::togglePlayPause); | ||
|
||
mediaShortcut = new QxtGlobalShortcut(this); | ||
mediaShortcut->setShortcut(QKeySequence(Qt::Key_MediaNext)); | ||
connect(mediaShortcut, &QxtGlobalShortcut::activated, this, &Hotkeys::next); | ||
|
||
mediaShortcut = new QxtGlobalShortcut(this); | ||
mediaShortcut->setShortcut(QKeySequence(Qt::Key_MediaPrevious)); | ||
connect(mediaShortcut, &QxtGlobalShortcut::activated, this, &Hotkeys::previous); | ||
#endif | ||
|
||
LOG_DEBUG(logger_, "service started"); | ||
} | ||
|
||
void Hotkeys::updatePlayShortcut() const | ||
{ | ||
playShortcut_->setShortcut(QKeySequence(playShortcutSetting_.value().toString())); | ||
} | ||
|
||
void Hotkeys::updateNextShortcut() const | ||
{ | ||
nextShortcut_->setShortcut(QKeySequence(nextShortcutSetting_.value().toString())); | ||
} | ||
|
||
void Hotkeys::updatePreviousShorcut() const | ||
{ | ||
previousShortcut_->setShortcut(QKeySequence(previousShortcutSetting_.value().toString())); | ||
} | ||
|
||
void Hotkeys::updateFavoriteShortcut() const | ||
{ | ||
favoriteShortcut_->setShortcut(QKeySequence(favoriteShortcutSetting_.value().toString())); | ||
} | ||
|
||
void Hotkeys::restoreWindow() | ||
{ | ||
mainWindow_.show(); | ||
} | ||
|
||
void Hotkeys::updateRestoreWindowShortcut() const | ||
{ | ||
restoreWindowShortcut_->setShortcut(QKeySequence(restoreWindowShortcutSetting_.value().toString())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#pragma once | ||
|
||
#include <MellowPlayer/Presentation/Hotkeys/IHotkeys.hpp> | ||
#include <QObject> | ||
|
||
class QxtGlobalShortcut; | ||
|
||
namespace MellowPlayer::Domain | ||
{ | ||
class IPlayer; | ||
class ILogger; | ||
class Setting; | ||
class Settings; | ||
class IDeprecatedMainWindow; | ||
} | ||
|
||
namespace MellowPlayer::Presentation | ||
{ | ||
class IMainWindow; | ||
|
||
class Hotkeys : public QObject, public IHotkeys | ||
{ | ||
Q_OBJECT | ||
public: | ||
Hotkeys(Domain::IPlayer& player, Domain::Settings& settings, IMainWindow& mainWindow); | ||
~Hotkeys(); | ||
|
||
void start() override; | ||
|
||
public slots: | ||
void togglePlayPause() override; | ||
void next() override; | ||
void previous() override; | ||
void toggleFavoriteSong() override; | ||
void restoreWindow() override; | ||
|
||
private: | ||
void updateFavoriteShortcut() const; | ||
void updatePreviousShorcut() const; | ||
void updateNextShortcut() const; | ||
void updatePlayShortcut() const; | ||
void updateRestoreWindowShortcut() const; | ||
|
||
Domain::ILogger& logger_; | ||
Domain::IPlayer& player_; | ||
IMainWindow& mainWindow_; | ||
|
||
QxtGlobalShortcut* playShortcut_; | ||
QxtGlobalShortcut* nextShortcut_; | ||
QxtGlobalShortcut* previousShortcut_; | ||
QxtGlobalShortcut* favoriteShortcut_; | ||
QxtGlobalShortcut* restoreWindowShortcut_; | ||
|
||
Domain::Setting& playShortcutSetting_; | ||
Domain::Setting& nextShortcutSetting_; | ||
Domain::Setting& previousShortcutSetting_; | ||
Domain::Setting& favoriteShortcutSetting_; | ||
Domain::Setting& restoreWindowShortcutSetting_; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
namespace MellowPlayer::Presentation | ||
{ | ||
class IHotkeys | ||
{ | ||
public: | ||
virtual ~IHotkeys() = default; | ||
|
||
virtual void start() = 0; | ||
virtual void togglePlayPause() = 0; | ||
virtual void next() = 0; | ||
virtual void previous() = 0; | ||
virtual void toggleFavoriteSong() = 0; | ||
virtual void restoreWindow() = 0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <MellowPlayer/Presentation/MainWindow.hpp> | ||
|
||
namespace MellowPlayer::Presentation::Tests | ||
{ | ||
class FakeMainWindow: public IMainWindow | ||
{ | ||
public: | ||
void load() override | ||
{ | ||
isLoaded = true; | ||
} | ||
|
||
void show() override | ||
{ | ||
isShown = true; | ||
} | ||
|
||
void hide() override | ||
{ | ||
isHidden = true; | ||
} | ||
|
||
bool isLoaded = false; | ||
bool isShown = false; | ||
bool isHidden = false; | ||
}; | ||
} |
Oops, something went wrong.