forked from dougma/lastfm-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of git://github.com/jonocole/lastfm-desktop
- Loading branch information
Showing
19 changed files
with
662 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
_build | ||
_files.qmake | ||
_version.h | ||
_build_parameters.pl.h | ||
Makefile* | ||
/_bin | ||
/_include |
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,129 @@ | ||
/*************************************************************************** | ||
* Copyright 2005-2009 Last.fm Ltd. * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program 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 General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program; if not, write to the * | ||
* Free Software Foundation, Inc., * | ||
* 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. * | ||
***************************************************************************/ | ||
|
||
#include "Application.h" | ||
#include "StopWatch.h" | ||
#include "lib/listener/legacy/LegacyPlayerListener.h" | ||
#include "lib/listener/PlayerListener.h" | ||
#include "lib/listener/PlayerMediator.h" | ||
#include <lastfm/Scrobbler> | ||
using audioscrobbler::Application; | ||
|
||
Application::Application(int& argc, char** argv) : unicorn::Application(argc, argv) | ||
{ | ||
tray = new QSystemTrayIcon(this); | ||
connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT(onTrayActivated(QSystemTrayIcon::ActivationReason))); | ||
tray->show(); | ||
|
||
as = new Scrobbler("ass"); | ||
|
||
mediator = new PlayerMediator(this); | ||
connect(mediator, SIGNAL(activeConnectionChanged( PlayerConnection* )), SLOT(setConnection( PlayerConnection* )) ); | ||
connect(new LegacyPlayerListener(mediator), SIGNAL(newConnection(PlayerConnection*)), mediator, SLOT(follow(PlayerConnection*)) ); | ||
|
||
try{ | ||
PlayerListener* listener = new PlayerListener(mediator); | ||
connect(listener, SIGNAL(newConnection(PlayerConnection*)), mediator, SLOT(follow(PlayerConnection*))); | ||
} | ||
catch(std::runtime_error& e){ | ||
qWarning() << e.what(); | ||
//TODO user visible warning | ||
} | ||
} | ||
|
||
void | ||
Application::onTrayActivated(QSystemTrayIcon::ActivationReason) | ||
{} | ||
|
||
void | ||
Application::setConnection(PlayerConnection*c) | ||
{ | ||
if(connection){ | ||
disconnect(connection, 0, this, 0); | ||
if(watch) | ||
connection->setElapsed(watch->elapsed()); | ||
} | ||
connect(c, SIGNAL(trackStarted(Track, Track)), SLOT(onTrackStarted(Track, Track))); | ||
connect(c, SIGNAL(paused()), SLOT(onTrackPaused())); | ||
connect(c, SIGNAL(resumed()), SLOT(onTrackResumed())); | ||
connect(c, SIGNAL(resumed()), SLOT(onTrackStopped())); | ||
connection = c; | ||
|
||
if(c->state() == Playing) | ||
onTrackStarted(c->track(), Track()); | ||
} | ||
|
||
void | ||
Application::onTrackStarted(const Track& t, const Track& oldtrack) | ||
{ | ||
Q_ASSERT(connection); | ||
|
||
//TODO move to playerconnection | ||
if(t == oldtrack){ | ||
qWarning() << "Trying to start the same track as last time, assuming programmer error and doing nothing"; | ||
return; | ||
} | ||
if(t.isNull()){ | ||
qWarning() << "Can't start null track!"; | ||
return; | ||
} | ||
|
||
delete watch; | ||
as->submit(); | ||
as->nowPlaying(t); | ||
|
||
ScrobblePoint timeout(t.duration()/2); | ||
watch = new StopWatch(timeout, connection->elapsed()); | ||
connect(watch, SIGNAL(timeout()), SLOT(onStopWatchTimedOut())); | ||
} | ||
|
||
void | ||
Application::onStopWatchTimedOut() | ||
{ | ||
Q_ASSERT(connection); | ||
as->cache(connection->track()); | ||
} | ||
|
||
void | ||
Application::onPaused() | ||
{ | ||
Q_ASSERT(connection); | ||
Q_ASSERT(watch); | ||
if(watch)watch->pause(); | ||
} | ||
|
||
void | ||
Application::onResumed() | ||
{ | ||
Q_ASSERT(watch); | ||
Q_ASSERT(connection); | ||
Q_ASSERT(connection->state() == Paused); | ||
|
||
if(watch)watch->resume(); | ||
} | ||
|
||
void | ||
Application::onStopped() | ||
{ | ||
Q_ASSERT(watch); | ||
Q_ASSERT(connection); | ||
|
||
delete watch; | ||
as->submit(); | ||
} |
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,55 @@ | ||
/*************************************************************************** | ||
* Copyright 2005-2009 Last.fm Ltd. * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program 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 General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program; if not, write to the * | ||
* Free Software Foundation, Inc., * | ||
* 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. * | ||
***************************************************************************/ | ||
|
||
#include <lastfm/global.h> | ||
#include "lib/unicorn/UnicornApplication.h" | ||
#include <QPointer> | ||
#include <QSystemTrayIcon> | ||
class Scrobbler; | ||
class PlayerMediator; | ||
class PlayerConnection; | ||
class StopWatch; | ||
|
||
|
||
namespace audioscrobbler | ||
{ | ||
class Application : public unicorn::Application | ||
{ | ||
Q_OBJECT | ||
|
||
QPointer<QSystemTrayIcon> tray; | ||
QPointer<Scrobbler> as; | ||
QPointer<PlayerMediator> mediator; | ||
QPointer<PlayerConnection> connection; | ||
QPointer<StopWatch> watch; | ||
|
||
public: | ||
Application(int& argc, char** argv); | ||
|
||
private slots: | ||
void onTrayActivated(QSystemTrayIcon::ActivationReason); | ||
void onStopWatchTimedOut(); | ||
void setConnection(PlayerConnection*); | ||
|
||
void onTrackStarted(const Track&, const Track&); | ||
void onPaused(); | ||
void onResumed(); | ||
void onStopped(); | ||
}; | ||
} |
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,9 @@ | ||
TEMPLATE = app | ||
TARGET = audioscrobbler | ||
CONFIG += unicorn scrobble listener | ||
VERSION = 2.0.0 | ||
|
||
include( $$ROOT_DIR/admin/include.qmake ) | ||
include( _files.qmake ) | ||
|
||
DEFINES += LASTFM_COLLAPSE_NAMESPACE |
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,51 @@ | ||
/*************************************************************************** | ||
* Copyright 2005-2009 Last.fm Ltd. * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program 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 General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program; if not, write to the * | ||
* Free Software Foundation, Inc., * | ||
* 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. * | ||
***************************************************************************/ | ||
|
||
#include "_version.h" | ||
#include "lib/unicorn/UniqueApplication.h" | ||
#include "Application.h" | ||
|
||
|
||
int main( int argc, char** argv ) | ||
{ | ||
QCoreApplication::setApplicationName( "Audioscrobbler" ); | ||
QCoreApplication::setApplicationVersion( VERSION ); | ||
|
||
#ifdef NDEBUG | ||
UniqueApplication uapp( moose::id() ); | ||
if (uapp.isAlreadyRunning()) | ||
return uapp.forward( argc, argv ) ? 0 : 1; | ||
uapp.init1(); | ||
#endif | ||
|
||
try | ||
{ | ||
audioscrobbler::Application app( argc, argv ); | ||
#ifdef NDEBUG | ||
uapp.init2( &app ); | ||
app.connect( &uapp, SIGNAL(arguments( QStringList )), SLOT(parseArguments( QStringList )) ); | ||
#endif | ||
return app.exec(); | ||
} | ||
catch (unicorn::Application::StubbornUserException&) | ||
{ | ||
// user wouldn't log in | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.