Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
juk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
David Planella
juk
Commits
5f8ba395
Commit
5f8ba395
authored
Sep 02, 2013
by
Michael Pyne
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/KDE/4.11'
Conflicts: main.cpp
parents
3b76f972
6ba6d1ef
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
16 deletions
+54
-16
juk.cpp
juk.cpp
+20
-3
juk.h
juk.h
+4
-0
playermanager.cpp
playermanager.cpp
+1
-6
playermanager.h
playermanager.h
+0
-2
scrobbler.cpp
scrobbler.cpp
+25
-4
scrobbler.h
scrobbler.h
+4
-1
No files found.
juk.cpp
View file @
5f8ba395
...
...
@@ -50,6 +50,7 @@
#include "keydialog.h"
#include "tagguesserconfigdlg.h"
#include "filerenamerconfigdlg.h"
#include "scrobbler.h"
#include "scrobbleconfigdlg.h"
#include "actioncollection.h"
#include "cache.h"
...
...
@@ -79,6 +80,7 @@ JuK::JuK(QWidget *parent) :
m_statusLabel
(
0
),
m_systemTray
(
0
),
m_player
(
new
PlayerManager
),
m_scrobbler
(
0
),
m_shuttingDown
(
false
)
{
// Expect segfaults if you change this order.
...
...
@@ -97,7 +99,6 @@ JuK::JuK(QWidget *parent) :
setupActions
();
setupLayout
();
bool
firstRun
=
!
KGlobal
::
config
()
->
hasGroup
(
"MainWindow"
);
if
(
firstRun
)
{
...
...
@@ -124,6 +125,7 @@ JuK::JuK(QWidget *parent) :
connect
(
m_splitter
,
SIGNAL
(
guiReady
()),
SLOT
(
slotSetupSystemTray
()));
readConfig
();
setupGlobalAccels
();
activateScrobblerIfEnabled
();
connect
(
QCoreApplication
::
instance
(),
SIGNAL
(
aboutToQuit
()),
SLOT
(
slotAboutToQuit
()));
...
...
@@ -321,9 +323,9 @@ void JuK::setupActions()
act
=
collection
->
addAction
(
"fileRenamerConfig"
,
this
,
SLOT
(
slotConfigureFileRenamer
()));
act
->
setText
(
i18n
(
"&File Renamer..."
));
act
=
collection
->
addAction
(
"scrobblerConfig"
,
this
,
SLOT
(
slotConfigureScrobbling
()));
act
->
setText
(
i18n
(
"&Configure scrobbling..."
));
act
->
setText
(
i18n
(
"&Configure scrobbling..."
));
//////////////////////////////////////////////////
// just in the toolbar
...
...
@@ -606,8 +608,23 @@ void JuK::slotConfigureFileRenamer()
void
JuK
::
slotConfigureScrobbling
()
{
ScrobbleConfigDlg
(
this
).
exec
();
activateScrobblerIfEnabled
();
}
void
JuK
::
activateScrobblerIfEnabled
()
{
bool
isScrobbling
=
Scrobbler
::
isScrobblingEnabled
();
if
(
!
m_scrobbler
&&
isScrobbling
)
{
m_scrobbler
=
new
Scrobbler
(
this
);
connect
(
m_player
,
SIGNAL
(
signalItemChanged
(
FileHandle
)),
m_scrobbler
,
SLOT
(
nowPlaying
(
FileHandle
)));
}
else
if
(
m_scrobbler
&&
!
isScrobbling
)
{
delete
m_scrobbler
;
m_scrobbler
=
0
;
}
}
void
JuK
::
slotUndo
()
{
...
...
juk.h
View file @
5f8ba395
...
...
@@ -30,6 +30,7 @@ class StatusLabel;
class
SystemTray
;
class
PlayerManager
;
class
PlaylistSplitter
;
class
Scrobbler
;
class
JuK
:
public
KXmlGuiWindow
{
...
...
@@ -53,6 +54,8 @@ private:
void
keyPressEvent
(
QKeyEvent
*
);
void
activateScrobblerIfEnabled
();
/**
* readSettings() is separate from readConfig() in that it contains settings
* that need to be read before the GUI is setup.
...
...
@@ -91,6 +94,7 @@ private:
KToggleAction
*
m_toggleSplashAction
;
PlayerManager
*
m_player
;
Scrobbler
*
m_scrobbler
;
bool
m_startDocked
;
bool
m_showSplash
;
...
...
playermanager.cpp
View file @
5f8ba395
...
...
@@ -71,10 +71,6 @@ PlayerManager::PlayerManager() :
// later, just disable it here. -- mpyne
// setup();
new
PlayerAdaptor
(
this
);
m_scrobbler
=
new
Scrobbler
(
this
);
connect
(
this
,
SIGNAL
(
signalItemChanged
(
FileHandle
)),
m_scrobbler
,
SLOT
(
nowPlaying
(
FileHandle
)));
}
PlayerManager
::~
PlayerManager
()
...
...
@@ -432,7 +428,6 @@ bool PlayerManager::mute()
void
PlayerManager
::
slotNeedNextUrl
()
{
m_scrobbler
->
scrobble
();
if
(
m_file
.
isNull
()
||
!
m_crossfadeTracks
)
return
;
...
...
@@ -537,7 +532,7 @@ void PlayerManager::slotStateChanged(Phonon::State newstate, Phonon::State oldst
QTimer
::
singleShot
(
2000
,
this
,
SLOT
(
slotUpdateGuiIfStopped
()));
JuK
::
JuKInstance
()
->
setWindowTitle
(
i18n
(
"JuK"
));
emit
signalStop
();
}
else
if
(
newstate
==
Phonon
::
PlayingState
)
{
...
...
playermanager.h
View file @
5f8ba395
...
...
@@ -29,7 +29,6 @@
#include <Phonon/Global>
#include <Phonon/Path>
class
Scrobbler
;
class
KSelectAction
;
class
StatusLabel
;
class
PlaylistInterface
;
...
...
@@ -143,7 +142,6 @@ private:
FileHandle
m_file
;
PlaylistInterface
*
m_playlistInterface
;
StatusLabel
*
m_statusLabel
;
Scrobbler
*
m_scrobbler
;
bool
m_muted
;
bool
m_setup
;
bool
m_crossfadeTracks
;
...
...
scrobbler.cpp
View file @
5f8ba395
...
...
@@ -33,7 +33,6 @@
Scrobbler
::
Scrobbler
(
QObject
*
parent
)
:
QObject
(
parent
)
,
m_startedPlaying
(
0
)
,
m_networkAccessManager
(
0
)
{
KConfigGroup
config
(
KGlobal
::
config
(),
"Scrobbling"
);
...
...
@@ -49,6 +48,17 @@ Scrobbler::~Scrobbler()
{
}
bool
Scrobbler
::
isScrobblingEnabled
()
{
KConfigGroup
config
(
KGlobal
::
config
(),
"Scrobbling"
);
// TODO: use kwallet
QString
username
=
config
.
readEntry
(
"Username"
,
""
);
QString
password
=
config
.
readEntry
(
"Password"
,
""
);
return
(
!
username
.
isEmpty
()
&&
!
password
.
isEmpty
());
}
QByteArray
Scrobbler
::
md5
(
QByteArray
data
)
{
return
QCryptographicHash
::
hash
(
data
,
QCryptographicHash
::
Md5
)
...
...
@@ -153,6 +163,10 @@ void Scrobbler::nowPlaying(const FileHandle& file)
return
;
}
if
(
!
m_file
.
isNull
())
{
scrobble
();
// Update time-played info for last track
}
QMap
<
QString
,
QString
>
params
;
params
[
"method"
]
=
"track.updateNowPlaying"
;
params
[
"sk"
]
=
sessionKey
;
...
...
@@ -165,8 +179,8 @@ void Scrobbler::nowPlaying(const FileHandle& file)
sign
(
params
);
post
(
params
);
m_file
=
file
;
m_
startedPlaying
=
QDateTime
::
currentMSecsSinceEpoch
()
/
1000
;
m_file
=
file
;
// May be FileHandle::null()
m_
playbackTimer
=
QDateTime
::
currentDateTime
()
;
}
void
Scrobbler
::
scrobble
()
...
...
@@ -181,6 +195,13 @@ void Scrobbler::scrobble()
return
;
}
int
halfDuration
=
m_file
.
tag
()
->
seconds
()
/
2
;
int
timeElapsed
=
m_playbackTimer
.
secsTo
(
QDateTime
::
currentDateTime
());
if
(
timeElapsed
<
30
||
timeElapsed
<
halfDuration
)
{
return
;
// API says not to scrobble if the user didn't play long enough
}
kDebug
()
<<
"Scrobbling"
<<
m_file
.
tag
()
->
title
();
QMap
<
QString
,
QString
>
params
;
...
...
@@ -189,7 +210,7 @@ void Scrobbler::scrobble()
params
[
"track"
]
=
m_file
.
tag
()
->
title
();
params
[
"artist"
]
=
m_file
.
tag
()
->
artist
();
params
[
"album"
]
=
m_file
.
tag
()
->
album
();
params
[
"timestamp"
]
=
QString
::
number
(
m_
startedPlaying
);
params
[
"timestamp"
]
=
QString
::
number
(
m_
playbackTimer
.
toTime_t
()
);
params
[
"trackNumber"
]
=
QString
::
number
(
m_file
.
tag
()
->
track
());
params
[
"duration"
]
=
QString
::
number
(
m_file
.
tag
()
->
seconds
());
...
...
scrobbler.h
View file @
5f8ba395
...
...
@@ -18,6 +18,7 @@
#include <QObject>
#include <QMap>
#include <QDateTime>
#include "filehandle.h"
...
...
@@ -33,6 +34,8 @@ public:
explicit
Scrobbler
(
QObject
*
parent
=
0
);
virtual
~
Scrobbler
();
static
bool
isScrobblingEnabled
();
public
slots
:
void
nowPlaying
(
const
FileHandle
&
);
void
scrobble
();
...
...
@@ -52,7 +55,7 @@ private:
void
post
(
QMap
<
QString
,
QString
>
&
request
);
QByteArray
md5
(
QByteArray
data
);
qint64
m_startedPlaying
;
QDateTime
m_playbackTimer
;
FileHandle
m_file
;
QNetworkAccessManager
*
m_networkAccessManager
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment