Skip to content

Commit

Permalink
WIP: Move to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
neochapay committed Sep 12, 2022
1 parent c0aa1d1 commit e925437
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 87 deletions.
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -5,6 +5,8 @@ set(SRC
cover.h
downloader.cpp
downloader.h
glaciermusicplayer.cpp
glaciermusicplayer.h
main.cpp
musicbrainzconnect.cpp
musicbrainzconnect.h
Expand All @@ -15,7 +17,11 @@ qtquick_compiler_add_resources(RESOURCES qml/glacier-music.qrc)

add_subdirectory(lib)
add_subdirectory(plugin)
add_subdirectory(sources)

include_directories("lib")


add_executable(glacier-music ${SRC} ${RESOURCES})

target_link_libraries(glacier-music
Expand Down
84 changes: 84 additions & 0 deletions src/glaciermusicplayer.cpp
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2022 Chupligin Sergey <neochapay@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#include "glaciermusicplayer.h"

GlacierMusicPlayer::GlacierMusicPlayer(QObject *parent)
: QObject(parent)
, m_player(new QMediaPlayer)
, m_settings(new QSettings)
, m_coverAdapter(new Cover)
{
connect(m_player, &QMediaPlayer::volumeChanged, this, &GlacierMusicPlayer::storeVolume);
connect(m_player, &QMediaPlayer::positionChanged, this, &GlacierMusicPlayer::storePosition);
connect(m_player, &QMediaPlayer::stateChanged, this, &GlacierMusicPlayer::storeState);

m_player->setVolume(m_settings->value("volume").toInt());

connect(m_coverAdapter, &Cover::coverLoaing, this, &GlacierMusicPlayer::setDefaultCover);
}

QString GlacierMusicPlayer::cover()
{
QString cover = "/usr/share/glacier-music/images/cover.png";
return cover;
}

float GlacierMusicPlayer::progress()
{
if(m_player->duration() > 0) {
return m_player->position()/m_player->duration();
}
return 1;
}

void GlacierMusicPlayer::setProgress(float progress)
{
qDebug() << Q_FUNC_INFO << "NOT IMPLEMENTED";
}

void GlacierMusicPlayer::storeVolume(int volume)
{
m_settings->setValue("volume", volume);
m_settings->sync();
}

void GlacierMusicPlayer::storePosition(qint64 position)
{
if(m_player->state() == QMediaPlayer::PlayingState) {
m_settings->setValue("seek", position);
m_settings->sync();
}
emit positionChanged(position);
emit progressChanged();
}

void GlacierMusicPlayer::storeState(QMediaPlayer::State newState)
{
m_settings->setValue("playbackState", newState);
}

void GlacierMusicPlayer::setDefaultCover()
{
QString cover = "/usr/share/glacier-music/images/cover.png";
if(cover != m_coverPath) {
m_coverPath = cover;
emit coverChanged();
}
}
68 changes: 68 additions & 0 deletions src/glaciermusicplayer.h
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2022 Chupligin Sergey <neochapay@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#ifndef GLACIERMUSICPLAYER_H
#define GLACIERMUSICPLAYER_H

#include <QObject>
#include <QMediaPlayer>
#include <QSettings>

#include "cover.h"

class GlacierMusicPlayer : public QObject
{
Q_OBJECT
Q_PROPERTY(bool firstRun READ firstRun)
Q_PROPERTY(QString cover READ cover NOTIFY coverChanged)
Q_PROPERTY(float progress READ progress WRITE setProgress NOTIFY progressChanged)

public:
explicit GlacierMusicPlayer(QObject *parent = nullptr);
bool firstRun() {return false;}

QString cover();

float progress();
void setProgress(float progress);

signals:
void noMusicFiles();
void noSourcePlugins();
void coverChanged();

void positionChanged(qint64 position);
void progressChanged();

private slots:
void storeVolume(int volume);
void storePosition(qint64 position);
void storeState(QMediaPlayer::State newState);

void setDefaultCover();

private:
QMediaPlayer *m_player;
QSettings* m_settings;
Cover* m_coverAdapter;

QString m_coverPath;
};

#endif // GLACIERMUSICPLAYER_H
9 changes: 5 additions & 4 deletions src/main.cpp
Expand Up @@ -29,9 +29,8 @@
#include <QCoreApplication>

#include <glacierapp.h>
#include "glaciermusicplayer.h"

#include "collection.h"
#include "cover.h"

Q_DECL_EXPORT int main(int argc, char *argv[])
{
Expand All @@ -40,8 +39,10 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
QGuiApplication *app = GlacierApp::app(argc, argv);
app->setOrganizationName("NemoMobile");

qmlRegisterType<Collection>("org.glacier.music.collection",1,0,"Collection");
qmlRegisterType<Cover>("org.glacier.music.cover",1,0,"Cover");
QQmlApplicationEngine *engine = GlacierApp::engine(app);

GlacierMusicPlayer *player = new GlacierMusicPlayer();
engine->rootContext()->setContextProperty("player", player);

QQuickWindow *window = GlacierApp::showWindow();
window->setTitle(QObject::tr("Music"));
Expand Down
2 changes: 1 addition & 1 deletion src/qml/components/CoverArea.qml
Expand Up @@ -15,7 +15,7 @@ Item{
id: coverImage
width: parent.width*0.8
height: width
source: "file:///usr/share/glacier-music/images/cover.png"
source: "file://"+player.cover
fillMode: Image.PreserveAspectFit
anchors.centerIn: parent
}
Expand Down
4 changes: 2 additions & 2 deletions src/qml/components/ProgressItem.qml
Expand Up @@ -55,7 +55,7 @@ Row {

accentColor: Theme.accentColor
fillColor: Theme.fillColor
progress: rootAudio.position/rootAudio.duration
progress: player.progress

MouseArea{
id: rewindArea
Expand All @@ -78,7 +78,7 @@ Row {
}

Connections {
target: rootAudio
target: player
function onPositionChanged() {
startSec.text = formatTime(rootAudio.position)
endSec.text = formatTime(rootAudio.duration-rootAudio.position)
Expand Down
60 changes: 6 additions & 54 deletions src/qml/glacier-music.qml
Expand Up @@ -25,14 +25,10 @@ import QtQuick.Controls.Styles.Nemo 1.0
import QtQuick.Window 2.1
import QtQuick.Layouts 1.0

import QtMultimedia 5.5

import org.nemomobile.settings 1.0
import org.nemomobile.mpris 1.0

import org.glacier.music.collection 1.0
import org.glacier.music 1.0
import org.glacier.music.cover 1.0

import Nemo.Dialogs 1.0

Expand All @@ -50,74 +46,30 @@ ApplicationWindow {
id: settings;
}

Collection{
/* Collection{
id: collection
}
}*/

PlaylistModel{
id: nextTrackModel
playMode: PlaylistModel.DirectoryShuffle
}

Cover{
/* Cover{
id: coverLoader
}

MediaPlayer{
id: rootAudio

function statusToStr(st) {
switch (st) {
case MediaPlayer.NoMedia: return "no media has been set.";
case MediaPlayer.Loading: return "the media is currently being loaded."
case MediaPlayer.Loaded: return "the media has been loaded."
case MediaPlayer.Buffering: return "the media is buffering data."
case MediaPlayer.Stalled: return "playback has been interrupted while the media is buffering data."
case MediaPlayer.Buffered: return "the media has buffered data."
case MediaPlayer.EndOfMedia: return "the media has played to the end."
case MediaPlayer.InvalidMedia: return "the media cannot be played."
default:
case MediaPlayer.UnknownStatus: return "the status of the media is unknown"
}
}

onStatusChanged: {
console.log("rootAudio.status " + statusToStr(status) + " " + source)
}

onVolumeChanged: {
settings.setValue("volume",volume);
settings.sync();
}

onPositionChanged: {
if(rootAudio.playbackState == MediaPlayer.PlayingState){
settings.setValue("seek",position);
}
}

onPlaybackStateChanged: {
settings.setValue("playbackState",rootAudio.playbackState);
}

Component.onCompleted: {
volume = settings.value("volume",1)
}
}
}*/

initialPage: PlayerPage{}

Component.onCompleted: {
if(collection.isFirstRun())
if(player.isFirstRun)
{
pageStack.push(Qt.resolvedUrl("../pages/SettingsPage.qml"));
}
collection.rescanCollection()
nextTrackModel.loadPlaylistFromDB()
}

Connections{
target: collection
target: player
function onNoMusicFiles() {
noMusicDialog.visible = true
}
Expand Down
26 changes: 0 additions & 26 deletions src/qml/pages/PlayerPage.qml
Expand Up @@ -83,12 +83,6 @@ Page {

}

Connections{
id: playNextConnection
target: rootAudio
function onStopped() { playNext() }
}

Connections{
target: nextTrackModel
function onCurrentIndexChanged(currentIndex) {
Expand Down Expand Up @@ -120,26 +114,6 @@ Page {
if(settings.value("currentTrack") !== track.trackId) {
settings.setValue("currentTrack", track.trackId);
}
// Change cover
var cover = track.cover;
if (cover !== "") {
cover = String(cover).startsWith("/") ? "file://" + cover : cover;
coverArea.cover = cover;
} else {
coverArea.cover = "file:///usr/share/glacier-music/images/cover.png";
coverLoader.getCoverByTrackId(track.trackId)
}
}
}

Connections{
target: coverLoader
function onCoverReady(coverFile) {
coverArea.cover = "file://" + coverFile
}
function onCoverLoaing() {
/*FIXME add loader*/
coverArea.cover = "file:///usr/share/glacier-music/images/cover.png";
}
}

Expand Down
1 change: 1 addition & 0 deletions src/sources/CMakeLists.txt
@@ -0,0 +1 @@
add_subdirectory(local)
Empty file.

0 comments on commit e925437

Please sign in to comment.