Initial commit
This commit is contained in:
commit
6238a79854
10 files changed
+1680
No files matched your search
+272
@@ -0,0 +1,272 @@
|
|||||||
|
---
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
AccessModifierOffset: 0
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignArrayOfStructures: None
|
||||||
|
AlignConsecutiveAssignments:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: true
|
||||||
|
AlignConsecutiveBitFields:
|
||||||
|
Enabled: true
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveDeclarations:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveMacros:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveShortCaseStatements:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCaseArrows: false
|
||||||
|
AlignCaseColons: false
|
||||||
|
AlignConsecutiveTableGenBreakingDAGArgColons:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveTableGenCondOperatorColons:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveTableGenDefinitionColons:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignEscapedNewlines: Right
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments:
|
||||||
|
Kind: Always
|
||||||
|
OverEmptyLines: 0
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowBreakBeforeNoexceptSpecifier: Never
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseExpressionOnASingleLine: true
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortCompoundRequirementOnASingleLine: true
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AttributeMacros:
|
||||||
|
- __capability
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: true
|
||||||
|
AfterClass: true
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: true
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: true
|
||||||
|
AfterUnion: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: true
|
||||||
|
BeforeLambdaBody: true
|
||||||
|
BeforeWhile: true
|
||||||
|
IndentBraces: true
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakAdjacentStringLiterals: true
|
||||||
|
BreakAfterAttributes: Leave
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakAfterReturnType: None
|
||||||
|
BreakArrays: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Linux
|
||||||
|
BreakBeforeConceptDeclarations: Always
|
||||||
|
BreakBeforeInlineASMColon: OnlyMultiline
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakFunctionDefinitionParameters: false
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakStringLiterals: true
|
||||||
|
BreakTemplateDeclarations: MultiLine
|
||||||
|
ColumnLimit: 80
|
||||||
|
CommentPragmas: ""
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DerivePointerAlignment: true
|
||||||
|
DisableFormat: false
|
||||||
|
EmptyLineAfterAccessModifier: Always
|
||||||
|
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||||
|
ExperimentalAutoDetectBinPacking: true
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IfMacros:
|
||||||
|
- KJ_IF_MAYBE
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: ^"(llvm|llvm-c|clang|clang-c)/
|
||||||
|
Priority: 2
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: true
|
||||||
|
- Regex: ^(<|"(gtest|gmock|isl|json)/)
|
||||||
|
Priority: 3
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: true
|
||||||
|
- Regex: .*
|
||||||
|
Priority: 1
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: true
|
||||||
|
IncludeIsMainRegex: (Test)?$
|
||||||
|
IncludeIsMainSourceRegex: ""
|
||||||
|
IndentAccessModifiers: true
|
||||||
|
IndentCaseBlocks: true
|
||||||
|
IndentCaseLabels: true
|
||||||
|
IndentExternBlock: AfterExternBlock
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentRequiresClause: true
|
||||||
|
IndentWidth: 4
|
||||||
|
IndentWrappedFunctionNames: true
|
||||||
|
InsertBraces: true
|
||||||
|
InsertNewlineAtEOF: true
|
||||||
|
InsertTrailingCommas: None
|
||||||
|
IntegerLiteralSeparator:
|
||||||
|
Binary: 0
|
||||||
|
BinaryMinDigits: 0
|
||||||
|
Decimal: 0
|
||||||
|
DecimalMinDigits: 0
|
||||||
|
Hex: 0
|
||||||
|
HexMinDigits: 0
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLines:
|
||||||
|
AtEndOfFile: false
|
||||||
|
AtStartOfBlock: true
|
||||||
|
AtStartOfFile: true
|
||||||
|
LambdaBodyIndentation: Signature
|
||||||
|
LineEnding: DeriveLF
|
||||||
|
MacroBlockBegin: ""
|
||||||
|
MacroBlockEnd: ""
|
||||||
|
MainIncludeChar: AngleBracket
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: All
|
||||||
|
ObjCBinPackProtocolList: Auto
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCBreakBeforeNestedBlockParam: true
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PPIndentWidth: -1
|
||||||
|
PackConstructorInitializers: BinPack
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakOpenParenthesis: 0
|
||||||
|
PenaltyBreakScopeResolution: 500
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyIndentedWhitespace: 0
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
PointerAlignment: Right
|
||||||
|
QualifierAlignment: Leave
|
||||||
|
ReferenceAlignment: Pointer
|
||||||
|
ReflowComments: true
|
||||||
|
RemoveBracesLLVM: false
|
||||||
|
RemoveParentheses: Leave
|
||||||
|
RemoveSemicolon: false
|
||||||
|
RequiresClausePosition: OwnLine
|
||||||
|
RequiresExpressionIndentation: OuterScope
|
||||||
|
SeparateDefinitionBlocks: Leave
|
||||||
|
ShortNamespaceLines: 1
|
||||||
|
SkipMacroDefinitionBody: false
|
||||||
|
SortIncludes: CaseSensitive
|
||||||
|
SortJavaStaticImport: Before
|
||||||
|
SortUsingDeclarations: LexicographicNumeric
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceAroundPointerQualifiers: Default
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeJsonColon: false
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeParensOptions:
|
||||||
|
AfterControlStatements: true
|
||||||
|
AfterForeachMacros: true
|
||||||
|
AfterFunctionDeclarationName: false
|
||||||
|
AfterFunctionDefinitionName: false
|
||||||
|
AfterIfMacros: true
|
||||||
|
AfterOverloadedOperator: false
|
||||||
|
AfterPlacementOperator: true
|
||||||
|
AfterRequiresInClause: false
|
||||||
|
AfterRequiresInExpression: false
|
||||||
|
BeforeNonEmptyParentheses: false
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: Never
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInLineCommentPrefix:
|
||||||
|
Minimum: 1
|
||||||
|
Maximum: -1
|
||||||
|
SpacesInParens: Never
|
||||||
|
SpacesInParensOptions:
|
||||||
|
ExceptDoubleParentheses: false
|
||||||
|
InConditionalStatements: false
|
||||||
|
InCStyleCasts: false
|
||||||
|
InEmptyParentheses: false
|
||||||
|
Other: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Latest
|
||||||
|
StatementAttributeLikeMacros:
|
||||||
|
- Q_EMIT
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
TabWidth: 4
|
||||||
|
TableGenBreakInsideDAGArg: DontBreak
|
||||||
|
UseTab: Always
|
||||||
|
VerilogBreakBetweenInstancePorts: true
|
||||||
|
WhitespaceSensitiveMacros:
|
||||||
|
- BOOST_PP_STRINGIZE
|
||||||
|
- CF_SWIFT_NAME
|
||||||
|
- NS_SWIFT_NAME
|
||||||
|
- PP_STRINGIZE
|
||||||
|
- STRINGIZE
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
*build*
|
||||||
|
.cache
|
||||||
|
.idea
|
||||||
|
AGENTS.md
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(EchoionDesktop VERSION 1.0.0 LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 26)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTORCC ON)
|
||||||
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
|
||||||
|
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Network WebSockets)
|
||||||
|
|
||||||
|
add_executable(EchoionDesktop
|
||||||
|
src/main.cpp
|
||||||
|
src/MainWindow.cpp
|
||||||
|
src/MainWindow.hpp
|
||||||
|
src/LoginDialog.cpp
|
||||||
|
src/LoginDialog.hpp
|
||||||
|
src/CoreClient.cpp
|
||||||
|
src/CoreClient.hpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(Echoion::Desktop ALIAS EchoionDesktop)
|
||||||
|
|
||||||
|
target_include_directories(EchoionDesktop PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(EchoionDesktop PRIVATE
|
||||||
|
Echoion::Api
|
||||||
|
Qt6::Core
|
||||||
|
Qt6::Widgets
|
||||||
|
Qt6::Network
|
||||||
|
Qt6::WebSockets
|
||||||
|
)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
target_compile_options(EchoionDesktop PRIVATE /W4 /WX-)
|
||||||
|
target_compile_definitions(EchoionDesktop PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||||
|
else()
|
||||||
|
target_compile_options(EchoionDesktop PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_target_properties(EchoionDesktop PROPERTIES
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||||
|
WIN32_EXECUTABLE TRUE
|
||||||
|
MACOSX_BUNDLE TRUE
|
||||||
|
)
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
install(TARGETS EchoionDesktop
|
||||||
|
EXPORT EchoionDesktopTargets
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(EXPORT EchoionDesktopTargets
|
||||||
|
FILE EchoionDesktopTargets.cmake
|
||||||
|
NAMESPACE Echoion::
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/EchoionDesktop
|
||||||
|
)
|
||||||
@@ -0,0 +1,439 @@
|
|||||||
|
#include "CoreClient.hpp"
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QUuid>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace Echoion::Desktop {
|
||||||
|
|
||||||
|
CoreClient::CoreClient(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, socket_(new QWebSocket(QString(), QWebSocketProtocol::VersionLatest, this)) {
|
||||||
|
|
||||||
|
connect(socket_, &QWebSocket::connected, this, &CoreClient::onConnected);
|
||||||
|
connect(socket_, &QWebSocket::disconnected, this, &CoreClient::onDisconnected);
|
||||||
|
connect(socket_, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error),
|
||||||
|
this, &CoreClient::onError);
|
||||||
|
connect(socket_, &QWebSocket::textMessageReceived, this, &CoreClient::onMessageReceived);
|
||||||
|
connect(socket_, &QWebSocket::binaryMessageReceived, this, &CoreClient::onBinaryMessageReceived);
|
||||||
|
}
|
||||||
|
|
||||||
|
CoreClient::~CoreClient() {
|
||||||
|
disconnectFromCore();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::connectToCore(const QString& host, int port) {
|
||||||
|
QString url = QString("ws://%1:%2/rpc").arg(host).arg(port);
|
||||||
|
socket_->open(QUrl(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::disconnectFromCore() {
|
||||||
|
shouldReconnect_ = false;
|
||||||
|
if (socket_->state() != QAbstractSocket::UnconnectedState) {
|
||||||
|
socket_->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CoreClient::isConnected() const {
|
||||||
|
return socket_->state() == QAbstractSocket::ConnectedState;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::authenticate(const QString& username, const QString& password) {
|
||||||
|
QJsonObject params;
|
||||||
|
params["username"] = username;
|
||||||
|
params["password"] = password;
|
||||||
|
|
||||||
|
sendRpcRequest("auth.login", params, [this](const QJsonObject& result) {
|
||||||
|
if (result["success"].toBool()) {
|
||||||
|
authToken_ = result["token"].toString();
|
||||||
|
emit authenticationSuccess(authToken_);
|
||||||
|
} else {
|
||||||
|
emit authenticationFailed(result["error"].toString("Unknown error"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::logout() {
|
||||||
|
sendRpcRequest("auth.logout");
|
||||||
|
authToken_.clear();
|
||||||
|
emit loggedOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CoreClient::isAuthenticated() const {
|
||||||
|
return !authToken_.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::play(const QString& query) {
|
||||||
|
QJsonObject params;
|
||||||
|
params["query"] = query;
|
||||||
|
sendRpcRequest("playback.play", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::pause() {
|
||||||
|
sendRpcRequest("playback.pause");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::resume() {
|
||||||
|
sendRpcRequest("playback.resume");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::stop() {
|
||||||
|
sendRpcRequest("playback.stop");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::skip(int count) {
|
||||||
|
QJsonObject params;
|
||||||
|
params["count"] = count;
|
||||||
|
sendRpcRequest("playback.skip", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::seek(int positionMs) {
|
||||||
|
QJsonObject params;
|
||||||
|
params["position"] = positionMs;
|
||||||
|
sendRpcRequest("playback.seek", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::setVolume(int volume) {
|
||||||
|
QJsonObject params;
|
||||||
|
params["volume"] = qBound(0, volume, 100);
|
||||||
|
sendRpcRequest("playback.setVolume", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::queueTrack(const QString& query) {
|
||||||
|
QJsonObject params;
|
||||||
|
params["query"] = query;
|
||||||
|
sendRpcRequest("queue.add", params, [this](const QJsonObject& result) {
|
||||||
|
if (result["success"].toBool()) {
|
||||||
|
auto track = parseTrackInfo(result["track"].toObject());
|
||||||
|
emit trackQueued(track, result["position"].toInt());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::removeFromQueue(int position) {
|
||||||
|
QJsonObject params;
|
||||||
|
params["position"] = position;
|
||||||
|
sendRpcRequest("queue.remove", params, [this, position](const QJsonObject& result) {
|
||||||
|
if (result["success"].toBool()) {
|
||||||
|
emit trackRemoved(position);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::clearQueue() {
|
||||||
|
sendRpcRequest("queue.clear");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::moveInQueue(int from, int to) {
|
||||||
|
QJsonObject params;
|
||||||
|
params["from"] = from;
|
||||||
|
params["to"] = to;
|
||||||
|
sendRpcRequest("queue.move", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::shuffle() {
|
||||||
|
sendRpcRequest("queue.shuffle");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::toggleRepeat() {
|
||||||
|
sendRpcRequest("playback.toggleRepeat");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::toggleShuffle() {
|
||||||
|
sendRpcRequest("playback.toggleShuffle");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::search(const QString& query) {
|
||||||
|
QJsonObject params;
|
||||||
|
params["query"] = query;
|
||||||
|
sendRpcRequest("search.query", params, [this](const QJsonObject& result) {
|
||||||
|
auto searchResult = parseSearchResult(result);
|
||||||
|
emit searchResultsReceived(searchResult);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::loadPlaylist(const QString& playlistId) {
|
||||||
|
QJsonObject params;
|
||||||
|
params["playlistId"] = playlistId;
|
||||||
|
sendRpcRequest("playlist.load", params, [this, playlistId](const QJsonObject& result) {
|
||||||
|
emit playlistLoaded(playlistId, result["trackCount"].toInt());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::savePlaylist(const QString& name, const QString& description) {
|
||||||
|
QJsonObject params;
|
||||||
|
params["name"] = name;
|
||||||
|
params["description"] = description;
|
||||||
|
sendRpcRequest("playlist.save", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::getUserPlaylists() {
|
||||||
|
sendRpcRequest("playlist.list", {}, [this](const QJsonObject& result) {
|
||||||
|
std::vector<Echoion::Api::PlaylistInfo> playlists;
|
||||||
|
QJsonArray arr = result["playlists"].toArray();
|
||||||
|
for (const auto& item : arr) {
|
||||||
|
auto obj = item.toObject();
|
||||||
|
Echoion::Api::PlaylistInfo info;
|
||||||
|
info.id = obj["id"].toString().toStdString();
|
||||||
|
info.name = obj["name"].toString().toStdString();
|
||||||
|
playlists.push_back(info);
|
||||||
|
}
|
||||||
|
emit playlistsReceived(playlists);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::requestPlaybackState() {
|
||||||
|
sendRpcRequest("state.getPlayback", {}, [this](const QJsonObject& result) {
|
||||||
|
emit playbackStateReceived(parsePlaybackState(result));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::requestQueue() {
|
||||||
|
sendRpcRequest("queue.get", {}, [this](const QJsonObject& result) {
|
||||||
|
std::vector<Echoion::Api::QueueEntry> queue;
|
||||||
|
QJsonArray arr = result["queue"].toArray();
|
||||||
|
for (const auto& item : arr) {
|
||||||
|
queue.push_back(parseQueueEntry(item.toObject()));
|
||||||
|
}
|
||||||
|
emit queueReceived(queue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::requestCurrentTrack() {
|
||||||
|
sendRpcRequest("state.getCurrentTrack", {}, [this](const QJsonObject& result) {
|
||||||
|
if (!result["track"].isNull()) {
|
||||||
|
emit trackStarted(parseTrackInfo(result["track"].toObject()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::reloadCore() {
|
||||||
|
sendRpcRequest("system.reload");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::onConnected() {
|
||||||
|
reconnectAttempts_ = 0;
|
||||||
|
emit connected();
|
||||||
|
|
||||||
|
// Re-authenticate if we had a token
|
||||||
|
if (!authToken_.isEmpty()) {
|
||||||
|
QJsonObject params;
|
||||||
|
params["token"] = authToken_;
|
||||||
|
sendRpcRequest("auth.validate", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start polling for state updates
|
||||||
|
requestPlaybackState();
|
||||||
|
requestQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::onDisconnected() {
|
||||||
|
emit disconnected();
|
||||||
|
|
||||||
|
// Attempt reconnection
|
||||||
|
if (shouldReconnect_ && reconnectAttempts_ < MAX_RECONNECT_ATTEMPTS) {
|
||||||
|
reconnectAttempts_++;
|
||||||
|
QTimer::singleShot(1000 * reconnectAttempts_, [this]() {
|
||||||
|
connectToCore();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::onError(QAbstractSocket::SocketError error) {
|
||||||
|
QString errorMsg;
|
||||||
|
switch (error) {
|
||||||
|
case QAbstractSocket::ConnectionRefusedError:
|
||||||
|
errorMsg = "Connection refused - is the core running?";
|
||||||
|
break;
|
||||||
|
case QAbstractSocket::RemoteHostClosedError:
|
||||||
|
errorMsg = "Connection closed by server";
|
||||||
|
break;
|
||||||
|
case QAbstractSocket::HostNotFoundError:
|
||||||
|
errorMsg = "Server not found";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
errorMsg = QString("Socket error: %1").arg(socket_->errorString());
|
||||||
|
}
|
||||||
|
emit errorOccurred(errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::onMessageReceived(const QString& message) {
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8());
|
||||||
|
if (doc.isNull() || !doc.isObject()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject obj = doc.object();
|
||||||
|
|
||||||
|
// Check if it's a response or an event
|
||||||
|
if (obj.contains("id")) {
|
||||||
|
handleRpcResponse(obj);
|
||||||
|
} else if (obj.contains("event")) {
|
||||||
|
handleEvent(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::onBinaryMessageReceived(const QByteArray& data) {
|
||||||
|
// Handle binary data if needed (e.g., album art)
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::sendRpcRequest(const QString& method, const QJsonObject& params) {
|
||||||
|
sendRpcRequest(method, params, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::sendRpcRequest(const QString& method, const QJsonObject& params, RpcCallback callback) {
|
||||||
|
if (!isConnected()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject request;
|
||||||
|
QString id = QUuid::createUuid().toString();
|
||||||
|
|
||||||
|
request["jsonrpc"] = "2.0";
|
||||||
|
request["id"] = id;
|
||||||
|
request["method"] = method;
|
||||||
|
request["params"] = params;
|
||||||
|
|
||||||
|
if (!authToken_.isEmpty()) {
|
||||||
|
request["auth"] = authToken_;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
pendingRequests_[id] = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonDocument doc(request);
|
||||||
|
socket_->sendTextMessage(QString::fromUtf8(doc.toJson(QJsonDocument::Compact)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::handleRpcResponse(const QJsonObject& response) {
|
||||||
|
QString id = response["id"].toString();
|
||||||
|
|
||||||
|
auto it = pendingRequests_.find(id);
|
||||||
|
if (it != pendingRequests_.end()) {
|
||||||
|
if (it->second) {
|
||||||
|
QJsonObject result = response.contains("result")
|
||||||
|
? response["result"].toObject()
|
||||||
|
: QJsonObject();
|
||||||
|
if (response.contains("error")) {
|
||||||
|
result["error"] = response["error"];
|
||||||
|
result["success"] = false;
|
||||||
|
} else {
|
||||||
|
result["success"] = true;
|
||||||
|
}
|
||||||
|
it->second(result);
|
||||||
|
}
|
||||||
|
pendingRequests_.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::handleEvent(const QJsonObject& event) {
|
||||||
|
QString eventType = event["event"].toString();
|
||||||
|
QJsonObject data = event["data"].toObject();
|
||||||
|
|
||||||
|
if (eventType == "playback.stateChanged") {
|
||||||
|
emit playbackStateReceived(parsePlaybackState(data));
|
||||||
|
} else if (eventType == "playback.trackStarted") {
|
||||||
|
emit trackStarted(parseTrackInfo(data["track"].toObject()));
|
||||||
|
} else if (eventType == "playback.trackFinished") {
|
||||||
|
emit trackFinished(parseTrackInfo(data["track"].toObject()));
|
||||||
|
} else if (eventType == "playback.paused") {
|
||||||
|
emit playbackPaused();
|
||||||
|
} else if (eventType == "playback.resumed") {
|
||||||
|
emit playbackResumed();
|
||||||
|
} else if (eventType == "playback.volumeChanged") {
|
||||||
|
emit volumeChanged(data["volume"].toInt());
|
||||||
|
} else if (eventType == "queue.updated") {
|
||||||
|
requestQueue();
|
||||||
|
} else if (eventType == "queue.trackAdded") {
|
||||||
|
auto track = parseTrackInfo(data["track"].toObject());
|
||||||
|
emit trackQueued(track, data["position"].toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Echoion::Api::PlaybackState CoreClient::parsePlaybackState(const QJsonObject& obj) {
|
||||||
|
Echoion::Api::PlaybackState state;
|
||||||
|
|
||||||
|
state.isPlaying = obj["isPlaying"].toBool();
|
||||||
|
state.isPaused = obj["isPaused"].toBool();
|
||||||
|
state.volume = static_cast<float>(obj["volume"].toDouble(0.5));
|
||||||
|
state.repeat = obj["repeat"].toBool();
|
||||||
|
state.shuffle = obj["shuffle"].toBool();
|
||||||
|
state.position = std::chrono::milliseconds(obj["position"].toInt());
|
||||||
|
|
||||||
|
if (!obj["currentTrack"].isNull()) {
|
||||||
|
state.currentTrack = parseQueueEntry(obj["currentTrack"].toObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
Echoion::Api::TrackInfo CoreClient::parseTrackInfo(const QJsonObject& obj) {
|
||||||
|
Echoion::Api::TrackInfo track;
|
||||||
|
|
||||||
|
track.title = obj["title"].toString().toStdString();
|
||||||
|
track.artist = obj["artist"].toString().toStdString();
|
||||||
|
track.originalUrl = obj["originalUrl"].toString().toStdString();
|
||||||
|
track.source = static_cast<Echoion::Api::TrackSource>(obj["source"].toInt());
|
||||||
|
|
||||||
|
if (!obj["streamUrl"].isNull()) {
|
||||||
|
track.streamUrl = obj["streamUrl"].toString().toStdString();
|
||||||
|
}
|
||||||
|
if (!obj["thumbnailUrl"].isNull()) {
|
||||||
|
track.thumbnailUrl = obj["thumbnailUrl"].toString().toStdString();
|
||||||
|
}
|
||||||
|
if (!obj["duration"].isNull()) {
|
||||||
|
track.duration = std::chrono::milliseconds(obj["duration"].toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
return track;
|
||||||
|
}
|
||||||
|
|
||||||
|
Echoion::Api::QueueEntry CoreClient::parseQueueEntry(const QJsonObject& obj) {
|
||||||
|
Echoion::Api::QueueEntry entry;
|
||||||
|
|
||||||
|
entry.queueId = static_cast<uint64_t>(obj["queueId"].toDouble());
|
||||||
|
entry.track = parseTrackInfo(obj["track"].toObject());
|
||||||
|
entry.addedBy = obj["addedBy"].toString().toStdString();
|
||||||
|
entry.isPlaying = obj["isPlaying"].toBool();
|
||||||
|
|
||||||
|
if (!obj["position"].isNull()) {
|
||||||
|
entry.position = std::chrono::milliseconds(obj["position"].toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
Echoion::Api::SearchResult CoreClient::parseSearchResult(const QJsonObject& obj) {
|
||||||
|
Echoion::Api::SearchResult result;
|
||||||
|
|
||||||
|
result.query = obj["query"].toString().toStdString();
|
||||||
|
|
||||||
|
QJsonArray tracks = obj["tracks"].toArray();
|
||||||
|
for (const auto& item : tracks) {
|
||||||
|
result.tracks.push_back(parseTrackInfo(item.toObject()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject CoreClient::trackInfoToJson(const Echoion::Api::TrackInfo& track) {
|
||||||
|
QJsonObject obj;
|
||||||
|
obj["title"] = QString::fromStdString(track.title);
|
||||||
|
obj["artist"] = QString::fromStdString(track.artist);
|
||||||
|
obj["originalUrl"] = QString::fromStdString(track.originalUrl);
|
||||||
|
obj["source"] = static_cast<int>(track.source);
|
||||||
|
if (track.streamUrl) {
|
||||||
|
obj["streamUrl"] = QString::fromStdString(*track.streamUrl);
|
||||||
|
}
|
||||||
|
if (track.thumbnailUrl) {
|
||||||
|
obj["thumbnailUrl"] = QString::fromStdString(*track.thumbnailUrl);
|
||||||
|
}
|
||||||
|
if (track.duration) {
|
||||||
|
obj["duration"] = static_cast<int>(track.duration->count());
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Echoion::Desktop
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QWebSocket>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QUuid>
|
||||||
|
#include <echoion/api.hpp>
|
||||||
|
#include <functional>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
namespace Echoion::Desktop {
|
||||||
|
|
||||||
|
// RPC request/response handling
|
||||||
|
using RpcCallback = std::function<void(const QJsonObject&)>;
|
||||||
|
|
||||||
|
class CoreClient : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CoreClient(QObject* parent = nullptr);
|
||||||
|
~CoreClient() override;
|
||||||
|
|
||||||
|
// Connection management
|
||||||
|
void connectToCore(const QString& host = "localhost", int port = 8765);
|
||||||
|
void disconnectFromCore();
|
||||||
|
[[nodiscard]] bool isConnected() const;
|
||||||
|
|
||||||
|
// Authentication
|
||||||
|
void authenticate(const QString& username, const QString& password);
|
||||||
|
void logout();
|
||||||
|
[[nodiscard]] bool isAuthenticated() const;
|
||||||
|
|
||||||
|
// Playback control
|
||||||
|
void play(const QString& query);
|
||||||
|
void pause();
|
||||||
|
void resume();
|
||||||
|
void stop();
|
||||||
|
void skip(int count = 1);
|
||||||
|
void seek(int positionMs);
|
||||||
|
void setVolume(int volume); // 0-100
|
||||||
|
|
||||||
|
// Queue management
|
||||||
|
void queueTrack(const QString& query);
|
||||||
|
void removeFromQueue(int position);
|
||||||
|
void clearQueue();
|
||||||
|
void moveInQueue(int from, int to);
|
||||||
|
void shuffle();
|
||||||
|
void toggleRepeat();
|
||||||
|
void toggleShuffle();
|
||||||
|
|
||||||
|
// Search
|
||||||
|
void search(const QString& query);
|
||||||
|
|
||||||
|
// Playlist management
|
||||||
|
void loadPlaylist(const QString& playlistId);
|
||||||
|
void savePlaylist(const QString& name, const QString& description);
|
||||||
|
void getUserPlaylists();
|
||||||
|
|
||||||
|
// Data requests
|
||||||
|
void requestPlaybackState();
|
||||||
|
void requestQueue();
|
||||||
|
void requestCurrentTrack();
|
||||||
|
|
||||||
|
// Hot reload
|
||||||
|
void reloadCore();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
// Connection signals
|
||||||
|
void connected();
|
||||||
|
void disconnected();
|
||||||
|
void errorOccurred(const QString& error);
|
||||||
|
|
||||||
|
// Authentication signals
|
||||||
|
void authenticationSuccess(const QString& token);
|
||||||
|
void authenticationFailed(const QString& reason);
|
||||||
|
void loggedOut();
|
||||||
|
|
||||||
|
// Playback signals
|
||||||
|
void playbackStateReceived(const Echoion::Api::PlaybackState& state);
|
||||||
|
void trackStarted(const Echoion::Api::TrackInfo& track);
|
||||||
|
void trackFinished(const Echoion::Api::TrackInfo& track);
|
||||||
|
void playbackPaused();
|
||||||
|
void playbackResumed();
|
||||||
|
void volumeChanged(int volume);
|
||||||
|
|
||||||
|
// Queue signals
|
||||||
|
void queueReceived(const std::vector<Echoion::Api::QueueEntry>& queue);
|
||||||
|
void trackQueued(const Echoion::Api::TrackInfo& track, int position);
|
||||||
|
void trackRemoved(int position);
|
||||||
|
|
||||||
|
// Search signals
|
||||||
|
void searchResultsReceived(const Echoion::Api::SearchResult& results);
|
||||||
|
|
||||||
|
// Playlist signals
|
||||||
|
void playlistsReceived(const std::vector<Echoion::Api::PlaylistInfo>& playlists);
|
||||||
|
void playlistLoaded(const QString& playlistId, int trackCount);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onConnected();
|
||||||
|
void onDisconnected();
|
||||||
|
void onError(QAbstractSocket::SocketError error);
|
||||||
|
void onMessageReceived(const QString& message);
|
||||||
|
void onBinaryMessageReceived(const QByteArray& data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void sendRpcRequest(const QString& method, const QJsonObject& params = {});
|
||||||
|
void sendRpcRequest(const QString& method, const QJsonObject& params, RpcCallback callback);
|
||||||
|
void handleRpcResponse(const QJsonObject& response);
|
||||||
|
void handleEvent(const QJsonObject& event);
|
||||||
|
|
||||||
|
// JSON conversion helpers
|
||||||
|
[[nodiscard]] Echoion::Api::PlaybackState parsePlaybackState(const QJsonObject& obj);
|
||||||
|
[[nodiscard]] Echoion::Api::TrackInfo parseTrackInfo(const QJsonObject& obj);
|
||||||
|
[[nodiscard]] Echoion::Api::QueueEntry parseQueueEntry(const QJsonObject& obj);
|
||||||
|
[[nodiscard]] Echoion::Api::SearchResult parseSearchResult(const QJsonObject& obj);
|
||||||
|
[[nodiscard]] QJsonObject trackInfoToJson(const Echoion::Api::TrackInfo& track);
|
||||||
|
|
||||||
|
QWebSocket* socket_ = nullptr;
|
||||||
|
QString authToken_;
|
||||||
|
std::unordered_map<QString, RpcCallback> pendingRequests_;
|
||||||
|
quint64 requestId_ = 0;
|
||||||
|
|
||||||
|
// Reconnection
|
||||||
|
bool shouldReconnect_ = true;
|
||||||
|
int reconnectAttempts_ = 0;
|
||||||
|
static constexpr int MAX_RECONNECT_ATTEMPTS = 5;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Echoion::Desktop
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
#include "LoginDialog.hpp"
|
||||||
|
|
||||||
|
namespace Echoion::Desktop {
|
||||||
|
|
||||||
|
LoginDialog::LoginDialog(QWidget* parent) : QDialog(parent) {
|
||||||
|
setupUi();
|
||||||
|
setWindowTitle("Echoion - Admin Login");
|
||||||
|
setModal(true);
|
||||||
|
setFixedSize(350, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginDialog::setupUi() {
|
||||||
|
auto* mainLayout = new QVBoxLayout(this);
|
||||||
|
|
||||||
|
auto* titleLabel = new QLabel("Echoion Music Bot - Admin Login", this);
|
||||||
|
titleLabel->setAlignment(Qt::AlignCenter);
|
||||||
|
QFont titleFont = titleLabel->font();
|
||||||
|
titleFont.setPointSize(14);
|
||||||
|
titleFont.setBold(true);
|
||||||
|
titleLabel->setFont(titleFont);
|
||||||
|
mainLayout->addWidget(titleLabel);
|
||||||
|
|
||||||
|
mainLayout->addSpacing(20);
|
||||||
|
|
||||||
|
auto* usernameLayout = new QHBoxLayout();
|
||||||
|
auto* usernameLabel = new QLabel("Username:", this);
|
||||||
|
usernameLabel->setFixedWidth(80);
|
||||||
|
usernameEdit_ = new QLineEdit(this);
|
||||||
|
usernameEdit_->setPlaceholderText("Enter username");
|
||||||
|
usernameLayout->addWidget(usernameLabel);
|
||||||
|
usernameLayout->addWidget(usernameEdit_);
|
||||||
|
mainLayout->addLayout(usernameLayout);
|
||||||
|
|
||||||
|
auto* passwordLayout = new QHBoxLayout();
|
||||||
|
auto* passwordLabel = new QLabel("Password:", this);
|
||||||
|
passwordLabel->setFixedWidth(80);
|
||||||
|
passwordEdit_ = new QLineEdit(this);
|
||||||
|
passwordEdit_->setEchoMode(QLineEdit::Password);
|
||||||
|
passwordEdit_->setPlaceholderText("Enter password");
|
||||||
|
passwordLayout->addWidget(passwordLabel);
|
||||||
|
passwordLayout->addWidget(passwordEdit_);
|
||||||
|
mainLayout->addLayout(passwordLayout);
|
||||||
|
|
||||||
|
mainLayout->addSpacing(20);
|
||||||
|
|
||||||
|
auto* buttonLayout = new QHBoxLayout();
|
||||||
|
loginButton_ = new QPushButton("Login", this);
|
||||||
|
loginButton_->setDefault(true);
|
||||||
|
cancelButton_ = new QPushButton("Cancel", this);
|
||||||
|
buttonLayout->addStretch();
|
||||||
|
buttonLayout->addWidget(loginButton_);
|
||||||
|
buttonLayout->addWidget(cancelButton_);
|
||||||
|
mainLayout->addLayout(buttonLayout);
|
||||||
|
|
||||||
|
connect(loginButton_, &QPushButton::clicked, this, &LoginDialog::onLoginClicked);
|
||||||
|
connect(cancelButton_, &QPushButton::clicked, this, &LoginDialog::onCancelClicked);
|
||||||
|
connect(passwordEdit_, &QLineEdit::returnPressed, this, &LoginDialog::onLoginClicked);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LoginDialog::getUsername() const {
|
||||||
|
return usernameEdit_->text();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LoginDialog::getPassword() const {
|
||||||
|
return passwordEdit_->text();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginDialog::onLoginClicked() {
|
||||||
|
if (usernameEdit_->text().isEmpty()) {
|
||||||
|
QMessageBox::warning(this, "Login Error", "Please enter a username.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (passwordEdit_->text().isEmpty()) {
|
||||||
|
QMessageBox::warning(this, "Login Error", "Please enter a password.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginDialog::onCancelClicked() {
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Echoion::Desktop
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
namespace Echoion::Desktop {
|
||||||
|
|
||||||
|
class LoginDialog : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit LoginDialog(QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
[[nodiscard]] QString getUsername() const;
|
||||||
|
[[nodiscard]] QString getPassword() const;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onLoginClicked();
|
||||||
|
void onCancelClicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupUi();
|
||||||
|
|
||||||
|
QLineEdit* usernameEdit_;
|
||||||
|
QLineEdit* passwordEdit_;
|
||||||
|
QPushButton* loginButton_;
|
||||||
|
QPushButton* cancelButton_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Echoion::Desktop
|
||||||
@@ -0,0 +1,419 @@
|
|||||||
|
#include "MainWindow.hpp"
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
namespace Echoion::Desktop {
|
||||||
|
|
||||||
|
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
||||||
|
setupUi();
|
||||||
|
setupMenuBar();
|
||||||
|
updateButtonStates();
|
||||||
|
|
||||||
|
updateTimer_ = new QTimer(this);
|
||||||
|
connect(updateTimer_, &QTimer::timeout, this, &MainWindow::updatePlaybackDisplay);
|
||||||
|
updateTimer_->start(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow() = default;
|
||||||
|
|
||||||
|
void MainWindow::setupUi() {
|
||||||
|
setWindowTitle("Echoion Music Bot");
|
||||||
|
resize(900, 700);
|
||||||
|
|
||||||
|
centralWidget_ = new QWidget(this);
|
||||||
|
setCentralWidget(centralWidget_);
|
||||||
|
|
||||||
|
mainLayout_ = new QVBoxLayout(centralWidget_);
|
||||||
|
|
||||||
|
setupPlaybackControls();
|
||||||
|
setupSearchPanel();
|
||||||
|
setupQueueView();
|
||||||
|
setupStatusBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupMenuBar() {
|
||||||
|
auto* fileMenu = menuBar()->addMenu("&File");
|
||||||
|
|
||||||
|
loginAction_ = fileMenu->addAction("&Login", this, &MainWindow::onLoginLogoutClicked);
|
||||||
|
logoutAction_ = fileMenu->addAction("Log&out", this, &MainWindow::onLoginLogoutClicked);
|
||||||
|
logoutAction_->setEnabled(false);
|
||||||
|
fileMenu->addSeparator();
|
||||||
|
settingsAction_ = fileMenu->addAction("&Settings", this, &MainWindow::onSettingsClicked);
|
||||||
|
settingsAction_->setEnabled(false);
|
||||||
|
fileMenu->addSeparator();
|
||||||
|
exitAction_ = fileMenu->addAction("E&xit", this, &QWidget::close, QKeySequence::Quit);
|
||||||
|
|
||||||
|
auto* controlMenu = menuBar()->addMenu("&Control");
|
||||||
|
reloadAction_ = controlMenu->addAction("&Reload Core", this, &MainWindow::onReloadClicked);
|
||||||
|
reloadAction_->setEnabled(false);
|
||||||
|
|
||||||
|
auto* helpMenu = menuBar()->addMenu("&Help");
|
||||||
|
aboutAction_ = helpMenu->addAction("&About", [this]() {
|
||||||
|
QMessageBox::about(this, "About Echoion",
|
||||||
|
"Echoion Music Bot v1.0.0\n\n"
|
||||||
|
"A modern music bot for TeamSpeak.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupPlaybackControls() {
|
||||||
|
auto* playbackGroup = new QGroupBox("Now Playing", this);
|
||||||
|
auto* playbackLayout = new QVBoxLayout(playbackGroup);
|
||||||
|
|
||||||
|
nowPlayingLabel_ = new QLabel("Nothing is playing", this);
|
||||||
|
QFont titleFont = nowPlayingLabel_->font();
|
||||||
|
titleFont.setPointSize(12);
|
||||||
|
titleFont.setBold(true);
|
||||||
|
nowPlayingLabel_->setFont(titleFont);
|
||||||
|
playbackLayout->addWidget(nowPlayingLabel_);
|
||||||
|
|
||||||
|
artistLabel_ = new QLabel("", this);
|
||||||
|
playbackLayout->addWidget(artistLabel_);
|
||||||
|
|
||||||
|
auto* progressLayout = new QHBoxLayout();
|
||||||
|
progressBar_ = new QProgressBar(this);
|
||||||
|
progressBar_->setRange(0, 100);
|
||||||
|
progressBar_->setValue(0);
|
||||||
|
progressBar_->setTextVisible(false);
|
||||||
|
progressLayout->addWidget(progressBar_);
|
||||||
|
|
||||||
|
timeLabel_ = new QLabel("0:00 / 0:00", this);
|
||||||
|
timeLabel_->setFixedWidth(100);
|
||||||
|
progressLayout->addWidget(timeLabel_);
|
||||||
|
playbackLayout->addLayout(progressLayout);
|
||||||
|
|
||||||
|
auto* controlsLayout = new QHBoxLayout();
|
||||||
|
|
||||||
|
playButton_ = new QPushButton("Play", this);
|
||||||
|
pauseButton_ = new QPushButton("Pause", this);
|
||||||
|
stopButton_ = new QPushButton("Stop", this);
|
||||||
|
skipButton_ = new QPushButton("Skip", this);
|
||||||
|
shuffleButton_ = new QPushButton("Shuffle: Off", this);
|
||||||
|
repeatButton_ = new QPushButton("Repeat: Off", this);
|
||||||
|
|
||||||
|
controlsLayout->addWidget(playButton_);
|
||||||
|
controlsLayout->addWidget(pauseButton_);
|
||||||
|
controlsLayout->addWidget(stopButton_);
|
||||||
|
controlsLayout->addWidget(skipButton_);
|
||||||
|
controlsLayout->addStretch();
|
||||||
|
controlsLayout->addWidget(shuffleButton_);
|
||||||
|
controlsLayout->addWidget(repeatButton_);
|
||||||
|
playbackLayout->addLayout(controlsLayout);
|
||||||
|
|
||||||
|
auto* volumeLayout = new QHBoxLayout();
|
||||||
|
auto* volumeTextLabel = new QLabel("Volume:", this);
|
||||||
|
volumeSlider_ = new QSlider(Qt::Horizontal, this);
|
||||||
|
volumeSlider_->setRange(0, 100);
|
||||||
|
volumeSlider_->setValue(50);
|
||||||
|
volumeLabel_ = new QLabel("50%", this);
|
||||||
|
volumeLabel_->setFixedWidth(40);
|
||||||
|
|
||||||
|
volumeLayout->addWidget(volumeTextLabel);
|
||||||
|
volumeLayout->addWidget(volumeSlider_);
|
||||||
|
volumeLayout->addWidget(volumeLabel_);
|
||||||
|
playbackLayout->addLayout(volumeLayout);
|
||||||
|
|
||||||
|
mainLayout_->addWidget(playbackGroup);
|
||||||
|
|
||||||
|
connect(playButton_, &QPushButton::clicked, this, &MainWindow::onPlayClicked);
|
||||||
|
connect(pauseButton_, &QPushButton::clicked, this, &MainWindow::onPauseClicked);
|
||||||
|
connect(stopButton_, &QPushButton::clicked, this, &MainWindow::onStopClicked);
|
||||||
|
connect(skipButton_, &QPushButton::clicked, this, &MainWindow::onSkipClicked);
|
||||||
|
connect(shuffleButton_, &QPushButton::clicked, this, &MainWindow::onShuffleClicked);
|
||||||
|
connect(repeatButton_, &QPushButton::clicked, this, &MainWindow::onRepeatClicked);
|
||||||
|
connect(volumeSlider_, &QSlider::valueChanged, this, &MainWindow::onVolumeChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupSearchPanel() {
|
||||||
|
auto* searchGroup = new QGroupBox("Search", this);
|
||||||
|
auto* searchLayout = new QVBoxLayout(searchGroup);
|
||||||
|
|
||||||
|
auto* searchInputLayout = new QHBoxLayout();
|
||||||
|
searchEdit_ = new QLineEdit(this);
|
||||||
|
searchEdit_->setPlaceholderText("Enter search query or YouTube URL...");
|
||||||
|
searchButton_ = new QPushButton("Search", this);
|
||||||
|
searchInputLayout->addWidget(searchEdit_);
|
||||||
|
searchInputLayout->addWidget(searchButton_);
|
||||||
|
searchLayout->addLayout(searchInputLayout);
|
||||||
|
|
||||||
|
searchResults_ = new QListWidget(this);
|
||||||
|
searchResults_->setMaximumHeight(150);
|
||||||
|
searchLayout->addWidget(searchResults_);
|
||||||
|
|
||||||
|
mainLayout_->addWidget(searchGroup);
|
||||||
|
|
||||||
|
connect(searchButton_, &QPushButton::clicked, this, &MainWindow::onSearchClicked);
|
||||||
|
connect(searchEdit_, &QLineEdit::returnPressed, this, &MainWindow::onSearchClicked);
|
||||||
|
connect(searchResults_, &QListWidget::itemDoubleClicked, this, &MainWindow::onSearchResultDoubleClicked);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupQueueView() {
|
||||||
|
auto* queueGroup = new QGroupBox("Queue", this);
|
||||||
|
auto* queueLayout = new QVBoxLayout(queueGroup);
|
||||||
|
|
||||||
|
queueList_ = new QListWidget(this);
|
||||||
|
queueLayout->addWidget(queueList_);
|
||||||
|
|
||||||
|
auto* queueButtonsLayout = new QHBoxLayout();
|
||||||
|
clearQueueButton_ = new QPushButton("Clear Queue", this);
|
||||||
|
removeFromQueueButton_ = new QPushButton("Remove Selected", this);
|
||||||
|
queueButtonsLayout->addWidget(clearQueueButton_);
|
||||||
|
queueButtonsLayout->addWidget(removeFromQueueButton_);
|
||||||
|
queueButtonsLayout->addStretch();
|
||||||
|
queueLayout->addLayout(queueButtonsLayout);
|
||||||
|
|
||||||
|
mainLayout_->addWidget(queueGroup);
|
||||||
|
|
||||||
|
connect(clearQueueButton_, &QPushButton::clicked, this, &MainWindow::onClearQueueClicked);
|
||||||
|
connect(removeFromQueueButton_, &QPushButton::clicked, this, &MainWindow::onRemoveFromQueueClicked);
|
||||||
|
connect(queueList_, &QListWidget::itemDoubleClicked, this, &MainWindow::onQueueItemDoubleClicked);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupStatusBar() {
|
||||||
|
statusBar_ = new QStatusBar(this);
|
||||||
|
setStatusBar(statusBar_);
|
||||||
|
|
||||||
|
connectionStatusLabel_ = new QLabel("Disconnected", this);
|
||||||
|
statusBar_->addWidget(connectionStatusLabel_);
|
||||||
|
|
||||||
|
authStatusLabel_ = new QLabel("Not logged in", this);
|
||||||
|
statusBar_->addPermanentWidget(authStatusLabel_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setAuthToken(const QString& token) {
|
||||||
|
authToken_ = token;
|
||||||
|
authStatusLabel_->setText("Logged in as Admin");
|
||||||
|
loginAction_->setEnabled(false);
|
||||||
|
logoutAction_->setEnabled(true);
|
||||||
|
settingsAction_->setEnabled(true);
|
||||||
|
reloadAction_->setEnabled(true);
|
||||||
|
updateButtonStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::clearAuthToken() {
|
||||||
|
authToken_.reset();
|
||||||
|
authStatusLabel_->setText("Not logged in");
|
||||||
|
loginAction_->setEnabled(true);
|
||||||
|
logoutAction_->setEnabled(false);
|
||||||
|
settingsAction_->setEnabled(false);
|
||||||
|
reloadAction_->setEnabled(false);
|
||||||
|
updateButtonStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::isAuthenticated() const {
|
||||||
|
return authToken_.has_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onPlaybackStateChanged(const Api::PlaybackState& state) {
|
||||||
|
currentState_ = state;
|
||||||
|
updatePlaybackDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onQueueUpdated(const std::vector<Api::QueueEntry>& queue) {
|
||||||
|
currentQueue_ = queue;
|
||||||
|
updateQueueDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onConnectionStatusChanged(bool connected) {
|
||||||
|
connectedToCore_ = connected;
|
||||||
|
connectionStatusLabel_->setText(connected ? "Connected" : "Disconnected");
|
||||||
|
if (!connected) {
|
||||||
|
clearAuthToken();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onPlayClicked() {
|
||||||
|
if (!isAuthenticated()) {
|
||||||
|
QMessageBox::warning(this, "Authentication Required", "Please login first.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString query = searchEdit_->text();
|
||||||
|
if (!query.isEmpty()) {
|
||||||
|
emit playRequested(query);
|
||||||
|
} else if (!currentQueue_.empty()) {
|
||||||
|
// Play first item in queue
|
||||||
|
emit playFromQueueRequested(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onPauseClicked() {
|
||||||
|
if (!isAuthenticated()) return;
|
||||||
|
emit pauseRequested();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onStopClicked() {
|
||||||
|
if (!isAuthenticated()) return;
|
||||||
|
emit stopRequested();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onSkipClicked() {
|
||||||
|
if (!isAuthenticated()) return;
|
||||||
|
emit skipRequested();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onVolumeChanged(int value) {
|
||||||
|
volumeLabel_->setText(QString("%1%").arg(value));
|
||||||
|
emit volumeChangeRequested(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onSeekSliderMoved(int value) {
|
||||||
|
if (!isAuthenticated()) return;
|
||||||
|
emit seekRequested(value * 1000); // Convert to ms
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onSearchClicked() {
|
||||||
|
if (!isAuthenticated()) {
|
||||||
|
QMessageBox::warning(this, "Authentication Required", "Please login first.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString query = searchEdit_->text();
|
||||||
|
if (query.isEmpty()) return;
|
||||||
|
|
||||||
|
searchResults_->clear();
|
||||||
|
emit searchRequested(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onSearchResultDoubleClicked(QListWidgetItem* item) {
|
||||||
|
if (!isAuthenticated() || !item) return;
|
||||||
|
|
||||||
|
int index = searchResults_->row(item);
|
||||||
|
emit addSearchResultToQueueRequested(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onQueueItemDoubleClicked(QListWidgetItem* item) {
|
||||||
|
if (!isAuthenticated() || !item) return;
|
||||||
|
|
||||||
|
int index = queueList_->row(item);
|
||||||
|
emit playFromQueueRequested(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onShuffleClicked() {
|
||||||
|
if (!isAuthenticated()) return;
|
||||||
|
emit toggleShuffleRequested();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onRepeatClicked() {
|
||||||
|
if (!isAuthenticated()) return;
|
||||||
|
emit toggleRepeatRequested();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onClearQueueClicked() {
|
||||||
|
if (!isAuthenticated()) return;
|
||||||
|
|
||||||
|
auto reply = QMessageBox::question(this, "Clear Queue",
|
||||||
|
"Are you sure you want to clear the queue?",
|
||||||
|
QMessageBox::Yes | QMessageBox::No);
|
||||||
|
|
||||||
|
if (reply == QMessageBox::Yes) {
|
||||||
|
emit clearQueueRequested();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onRemoveFromQueueClicked() {
|
||||||
|
if (!isAuthenticated()) return;
|
||||||
|
|
||||||
|
auto* item = queueList_->currentItem();
|
||||||
|
if (!item) return;
|
||||||
|
|
||||||
|
int index = queueList_->row(item);
|
||||||
|
emit removeFromQueueRequested(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onSettingsClicked() {
|
||||||
|
if (!isAuthenticated()) return;
|
||||||
|
|
||||||
|
// TODO: Implement settings dialog
|
||||||
|
QMessageBox::information(this, "Settings", "Settings dialog will be implemented here.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onReloadClicked() {
|
||||||
|
if (!isAuthenticated()) return;
|
||||||
|
|
||||||
|
auto reply = QMessageBox::question(this, "Hot Reload",
|
||||||
|
"Are you sure you want to reload the core?\n\n"
|
||||||
|
"This will briefly interrupt playback.",
|
||||||
|
QMessageBox::Yes | QMessageBox::No);
|
||||||
|
|
||||||
|
if (reply == QMessageBox::Yes) {
|
||||||
|
emit reloadCoreRequested();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onLoginLogoutClicked() {
|
||||||
|
if (isAuthenticated()) {
|
||||||
|
clearAuthToken();
|
||||||
|
emit logoutRequested();
|
||||||
|
} else {
|
||||||
|
emit loginRequested();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onSearchResultsReceived(const Echoion::Api::SearchResult& results) {
|
||||||
|
searchResults_->clear();
|
||||||
|
for (const auto& track : results.tracks) {
|
||||||
|
QString text = QString::fromStdString(track.title + " - " + track.artist);
|
||||||
|
searchResults_->addItem(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::updatePlaybackDisplay() {
|
||||||
|
if (currentState_.currentTrack.has_value()) {
|
||||||
|
const auto& track = currentState_.currentTrack->track;
|
||||||
|
nowPlayingLabel_->setText(QString::fromStdString(track.title));
|
||||||
|
artistLabel_->setText(QString::fromStdString(track.artist));
|
||||||
|
|
||||||
|
if (track.duration.has_value()) {
|
||||||
|
auto totalMs = track.duration->count();
|
||||||
|
auto currentMs = currentState_.position.count();
|
||||||
|
progressBar_->setMaximum(static_cast<int>(totalMs / 1000));
|
||||||
|
progressBar_->setValue(static_cast<int>(currentMs / 1000));
|
||||||
|
|
||||||
|
timeLabel_->setText(QString("%1 / %2")
|
||||||
|
.arg(formatDuration(currentState_.position))
|
||||||
|
.arg(formatDuration(*track.duration)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nowPlayingLabel_->setText("Nothing is playing");
|
||||||
|
artistLabel_->setText("");
|
||||||
|
progressBar_->setValue(0);
|
||||||
|
timeLabel_->setText("0:00 / 0:00");
|
||||||
|
}
|
||||||
|
|
||||||
|
shuffleButton_->setText(currentState_.shuffle ? "Shuffle: On" : "Shuffle: Off");
|
||||||
|
repeatButton_->setText(currentState_.repeat ? "Repeat: On" : "Repeat: Off");
|
||||||
|
volumeSlider_->setValue(static_cast<int>(currentState_.volume * 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateQueueDisplay() {
|
||||||
|
queueList_->clear();
|
||||||
|
for (size_t i = 0; i < currentQueue_.size(); ++i) {
|
||||||
|
const auto& entry = currentQueue_[i];
|
||||||
|
QString text = QString("%1. %2 - %3")
|
||||||
|
.arg(i + 1)
|
||||||
|
.arg(QString::fromStdString(entry.track.title))
|
||||||
|
.arg(QString::fromStdString(entry.track.artist));
|
||||||
|
queueList_->addItem(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateButtonStates() {
|
||||||
|
bool hasAuth = isAuthenticated();
|
||||||
|
playButton_->setEnabled(hasAuth);
|
||||||
|
pauseButton_->setEnabled(hasAuth);
|
||||||
|
stopButton_->setEnabled(hasAuth);
|
||||||
|
skipButton_->setEnabled(hasAuth);
|
||||||
|
shuffleButton_->setEnabled(hasAuth);
|
||||||
|
repeatButton_->setEnabled(hasAuth);
|
||||||
|
searchButton_->setEnabled(hasAuth);
|
||||||
|
clearQueueButton_->setEnabled(hasAuth);
|
||||||
|
removeFromQueueButton_->setEnabled(hasAuth);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MainWindow::formatDuration(std::chrono::milliseconds ms) {
|
||||||
|
auto totalSeconds = ms.count() / 1000;
|
||||||
|
auto minutes = totalSeconds / 60;
|
||||||
|
auto seconds = totalSeconds % 60;
|
||||||
|
return QString("%1:%2").arg(minutes).arg(seconds, 2, 10, QChar('0'));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Echoion::Desktop
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QSlider>
|
||||||
|
#include <QProgressBar>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QListWidget>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include <QStatusBar>
|
||||||
|
#include <QMenuBar>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <optional>
|
||||||
|
#include <echoion/api.hpp>
|
||||||
|
|
||||||
|
namespace Echoion::Desktop {
|
||||||
|
|
||||||
|
class MainWindow : public QMainWindow {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit MainWindow(QWidget* parent = nullptr);
|
||||||
|
~MainWindow() override;
|
||||||
|
|
||||||
|
// Authentication
|
||||||
|
void setAuthToken(const QString& token);
|
||||||
|
void clearAuthToken();
|
||||||
|
[[nodiscard]] bool isAuthenticated() const;
|
||||||
|
|
||||||
|
// State updates
|
||||||
|
void onPlaybackStateChanged(const Api::PlaybackState& state);
|
||||||
|
void onQueueUpdated(const std::vector<Api::QueueEntry>& queue);
|
||||||
|
void onConnectionStatusChanged(bool connected);
|
||||||
|
void onSearchResultsReceived(const Api::SearchResult& results);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
// Connection signals
|
||||||
|
void loginRequested();
|
||||||
|
void logoutRequested();
|
||||||
|
|
||||||
|
// Playback control signals
|
||||||
|
void playRequested(const QString& query);
|
||||||
|
void playFromQueueRequested(int index);
|
||||||
|
void pauseRequested();
|
||||||
|
void stopRequested();
|
||||||
|
void resumeRequested();
|
||||||
|
void skipRequested();
|
||||||
|
void seekRequested(int positionMs);
|
||||||
|
void volumeChangeRequested(int volume);
|
||||||
|
void toggleShuffleRequested();
|
||||||
|
void toggleRepeatRequested();
|
||||||
|
|
||||||
|
// Queue signals
|
||||||
|
void clearQueueRequested();
|
||||||
|
void removeFromQueueRequested(int index);
|
||||||
|
void moveInQueueRequested(int from, int to);
|
||||||
|
|
||||||
|
// Search signals
|
||||||
|
void searchRequested(const QString& query);
|
||||||
|
void addSearchResultToQueueRequested(int index);
|
||||||
|
|
||||||
|
// System signals
|
||||||
|
void reloadCoreRequested();
|
||||||
|
void settingsRequested();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onPlayClicked();
|
||||||
|
void onPauseClicked();
|
||||||
|
void onStopClicked();
|
||||||
|
void onSkipClicked();
|
||||||
|
void onVolumeChanged(int value);
|
||||||
|
void onSeekSliderMoved(int value);
|
||||||
|
void onSearchClicked();
|
||||||
|
void onSearchResultDoubleClicked(QListWidgetItem* item);
|
||||||
|
void onQueueItemDoubleClicked(QListWidgetItem* item);
|
||||||
|
void onShuffleClicked();
|
||||||
|
void onRepeatClicked();
|
||||||
|
void onClearQueueClicked();
|
||||||
|
void onRemoveFromQueueClicked();
|
||||||
|
void onSettingsClicked();
|
||||||
|
void onReloadClicked();
|
||||||
|
void onLoginLogoutClicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupUi();
|
||||||
|
void setupMenuBar();
|
||||||
|
void setupPlaybackControls();
|
||||||
|
void setupSearchPanel();
|
||||||
|
void setupQueueView();
|
||||||
|
void setupStatusBar();
|
||||||
|
void updatePlaybackDisplay();
|
||||||
|
void updateQueueDisplay();
|
||||||
|
void updateButtonStates();
|
||||||
|
|
||||||
|
[[nodiscard]] QString formatDuration(std::chrono::milliseconds ms);
|
||||||
|
|
||||||
|
// Central widget
|
||||||
|
QWidget* centralWidget_;
|
||||||
|
QVBoxLayout* mainLayout_;
|
||||||
|
|
||||||
|
// Playback controls
|
||||||
|
QLabel* nowPlayingLabel_;
|
||||||
|
QLabel* artistLabel_;
|
||||||
|
QProgressBar* progressBar_;
|
||||||
|
QLabel* timeLabel_;
|
||||||
|
QPushButton* playButton_;
|
||||||
|
QPushButton* pauseButton_;
|
||||||
|
QPushButton* stopButton_;
|
||||||
|
QPushButton* skipButton_;
|
||||||
|
QPushButton* shuffleButton_;
|
||||||
|
QPushButton* repeatButton_;
|
||||||
|
QSlider* volumeSlider_;
|
||||||
|
QLabel* volumeLabel_;
|
||||||
|
|
||||||
|
// Search panel
|
||||||
|
QLineEdit* searchEdit_;
|
||||||
|
QPushButton* searchButton_;
|
||||||
|
QListWidget* searchResults_;
|
||||||
|
|
||||||
|
// Queue view
|
||||||
|
QListWidget* queueList_;
|
||||||
|
QPushButton* clearQueueButton_;
|
||||||
|
QPushButton* removeFromQueueButton_;
|
||||||
|
|
||||||
|
// Status bar
|
||||||
|
QStatusBar* statusBar_;
|
||||||
|
QLabel* connectionStatusLabel_;
|
||||||
|
QLabel* authStatusLabel_;
|
||||||
|
|
||||||
|
// Menu actions
|
||||||
|
QAction* loginAction_;
|
||||||
|
QAction* logoutAction_;
|
||||||
|
QAction* settingsAction_;
|
||||||
|
QAction* reloadAction_;
|
||||||
|
QAction* exitAction_;
|
||||||
|
QAction* aboutAction_;
|
||||||
|
|
||||||
|
// State
|
||||||
|
QTimer* updateTimer_;
|
||||||
|
std::optional<QString> authToken_;
|
||||||
|
Api::PlaybackState currentState_;
|
||||||
|
std::vector<Api::QueueEntry> currentQueue_;
|
||||||
|
bool connectedToCore_ = false;
|
||||||
|
|
||||||
|
// Buttons for login/logout
|
||||||
|
QPushButton* loginLogoutButton_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Echoion::Desktop
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
#include <QApplication>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include "MainWindow.hpp"
|
||||||
|
#include "LoginDialog.hpp"
|
||||||
|
#include "CoreClient.hpp"
|
||||||
|
#include <echoion/api.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace Echoion::Desktop;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
app.setApplicationName("Echoion Desktop");
|
||||||
|
app.setOrganizationName("Echoion");
|
||||||
|
|
||||||
|
MainWindow mainWindow;
|
||||||
|
CoreClient coreClient;
|
||||||
|
|
||||||
|
// Connect to Core RPC server
|
||||||
|
coreClient.connectToCore("localhost", 8765);
|
||||||
|
|
||||||
|
QObject::connect(&mainWindow, &MainWindow::loginRequested, [&]() {
|
||||||
|
LoginDialog loginDialog(&mainWindow);
|
||||||
|
if (loginDialog.exec() == QDialog::Accepted) {
|
||||||
|
QString username = loginDialog.getUsername();
|
||||||
|
QString password = loginDialog.getPassword();
|
||||||
|
|
||||||
|
coreClient.authenticate(username, password);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(&mainWindow, &MainWindow::logoutRequested, [&]() {
|
||||||
|
coreClient.logout();
|
||||||
|
mainWindow.clearAuthToken();
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(&coreClient, &CoreClient::authenticationSuccess,
|
||||||
|
[&](const QString& token) {
|
||||||
|
mainWindow.setAuthToken(token);
|
||||||
|
QMessageBox::information(&mainWindow, "Login Successful",
|
||||||
|
"You are now logged in as admin.");
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(&coreClient, &CoreClient::authenticationFailed,
|
||||||
|
[&](const QString& error) {
|
||||||
|
QMessageBox::warning(&mainWindow, "Login Failed", error);
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(&coreClient, &CoreClient::playbackStateReceived,
|
||||||
|
[&](const Echoion::Api::PlaybackState& state) {
|
||||||
|
mainWindow.onPlaybackStateChanged(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(&coreClient, &CoreClient::queueReceived,
|
||||||
|
[&](const std::vector<Echoion::Api::QueueEntry>& queue) {
|
||||||
|
mainWindow.onQueueUpdated(queue);
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(&coreClient, &CoreClient::connected,
|
||||||
|
[&]() {
|
||||||
|
mainWindow.onConnectionStatusChanged(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(&coreClient, &CoreClient::disconnected,
|
||||||
|
[&]() {
|
||||||
|
mainWindow.onConnectionStatusChanged(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(&coreClient, &CoreClient::errorOccurred,
|
||||||
|
[&](const QString& error) {
|
||||||
|
QMessageBox::critical(&mainWindow, "Error", error);
|
||||||
|
});
|
||||||
|
|
||||||
|
mainWindow.show();
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
|
}
|
||||||
Reference in new issue
Block a user