Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Remember session key if requested

* Allow Logout
* Auto logout on authentication error (ie session key has been revoked)
!! Scrobbler needs behaviour testing when changing user especially regarding scrobble cache etc
  • Loading branch information...
commit 3bba32a3671628286766e88364f03ad5d1f6e0c3 1 parent 0060adf
@jonocole authored
View
27 app/audioscrobbler/Application.cpp
@@ -49,7 +49,9 @@ using audioscrobbler::Application;
#define AS_TRAY_ICON ":systray_icon_rest_mac.png"
#endif
-Application::Application(int& argc, char** argv) : unicorn::Application(argc, argv)
+Application::Application(int& argc, char** argv)
+ : unicorn::Application(argc, argv),
+ as( 0 )
{
/// tray
tray = new QSystemTrayIcon(this);
@@ -100,9 +102,6 @@ Application::Application(int& argc, char** argv) : unicorn::Application(argc, ar
sc->setTagAction( m_tag_action );
sc->setShareAction( m_share_action );
-/// scrobbler
- as = new Audioscrobbler("ass");
-
/// mediator
mediator = new PlayerMediator(this);
connect(mediator, SIGNAL(activeConnectionChanged( PlayerConnection* )), SLOT(setConnection( PlayerConnection* )) );
@@ -140,6 +139,12 @@ Application::Application(int& argc, char** argv) : unicorn::Application(argc, ar
}
+/*void
+Application::onSessionChanged()
+{
+}*/
+
+
void
Application::setConnection(PlayerConnection*c)
{
@@ -185,9 +190,10 @@ Application::onTrackStarted(const Track& t, const Track& oldtrack)
m_title_action->setText( t.title() + " [" + t.durationString() + ']' );
delete watch;
- as->submit();
- as->nowPlaying(t);
-
+ if( as ) {
+ as->submit();
+ as->nowPlaying(t);
+ }
ScrobblePoint timeout(t.duration()/2);
watch = new StopWatch(timeout, connection->elapsed());
watch->resume();
@@ -198,7 +204,7 @@ void
Application::onStopWatchTimedOut()
{
Q_ASSERT(connection);
- as->cache(connection->track());
+ if( as ) as->cache(connection->track());
}
void
@@ -225,7 +231,7 @@ Application::onStopped()
Q_ASSERT(connection);
delete watch;
- as->submit();
+ if( as ) as->submit();
}
void
@@ -274,6 +280,9 @@ Application::onTrayActivated( QSystemTrayIcon::ActivationReason reason )
void
Application::onUserGotInfo()
{
+ /// scrobbler
+ as = new Audioscrobbler("ass");
+
/*QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
Q_ASSERT( reply );
View
4 app/radio/Application.cpp
@@ -21,6 +21,7 @@
#include "lib/unicorn/QMessageBoxBuilder.h"
#include "Radio.h"
#include "ScrobSocket.h"
+#include <QDebug>
using moralistfad::Application;
@@ -37,7 +38,8 @@ Application::onWsError( lastfm::ws::Error e )
switch (e)
{
case lastfm::ws::InvalidSessionKey:
- logout();
+ if(!logout())
+ quit();
break;
default:
break;
View
39 app/radio/MainWindow.cpp
@@ -22,6 +22,7 @@
#include "widgets/MultiStarterWidget.h"
#include "widgets/PlaybackControlsWidget.h"
#include "widgets/NowPlayingWidget.h"
+#include "lib/unicorn/UnicornApplication.h"
#include "lib/unicorn/qtwin.h"
#include "lib/unicorn/AnimatedStatusBar.h"
#include "lib/unicorn/widgets/MessageBar.h"
@@ -47,34 +48,46 @@ MainWindow::MainWindow()
status->addWidget( pcw, 1 );
setStatusBar( status );
- MainWidget* mw;
-
QWidget* w = new QWidget();
new QVBoxLayout( w );
w->layout()->setContentsMargins( 0, 0, 0, 0 );
- w->layout()->addWidget(mw = new MainWidget());
+ w->layout()->addWidget(m_mainWidget = new MainWidget());
- connect( mw, SIGNAL( widgetChanged(QWidget*)), SLOT( onWidgetChanged( QWidget* )));
+ layout()->setSizeConstraint( QLayout::SetFixedSize );
m_messageBar = new MessageBar( w );
- connect(mw, SIGNAL(startRadio(RadioStation)), SIGNAL(startRadio(RadioStation)));
-
- AuthenticatedUser user;
- connect(user.getFriends(), SIGNAL(finished()), mw, SLOT(onUserGotFriends()));
- connect(user.getTopTags(), SIGNAL(finished()), mw, SLOT(onUserGotTopTags()));
- connect(user.getPlaylists(), SIGNAL(finished()), mw, SLOT(onUserGotPlaylists()));
- connect(user.getRecentStations(), SIGNAL(finished()), mw, SLOT(onUserGotRecentStations()));
+ connect(m_mainWidget, SIGNAL(startRadio(RadioStation)), SIGNAL(startRadio(RadioStation)));
- connect(pcw, SIGNAL(startRadio(RadioStation)), mw, SLOT(onStartRadio(RadioStation)));
+ connect(pcw, SIGNAL(startRadio(RadioStation)), m_mainWidget, SLOT(onStartRadio(RadioStation)));
+
+ connect(radio, SIGNAL(stopped()), status, SLOT(hideAnimated()));
+ connect(radio, SIGNAL(tuningIn( const RadioStation&)), status, SLOT(showAnimated()));
+
+ connect( qApp, SIGNAL( sessionChanged( Session, Session )), SLOT( onSessionChanged( Session, Session )));
+
+ //if we've got this far we must already have a session so use
+ //the current session to start things rolling.
+ onSessionChanged( qobject_cast<unicorn::Application*>(qApp)->currentSession(), Session());
setCentralWidget( w );
finishUi();
//todo: bury this:
- menuBar()->addMenu("Normania")->addAction( tr("RQL"), mw, SLOT(rawrql()), QKeySequence(tr("Ctrl+r")) );
+ menuBar()->addMenu("Normania")->addAction( tr("RQL"), m_mainWidget, SLOT(rawrql()), QKeySequence(tr("Ctrl+r")) );
+}
+
+void
+MainWindow::onSessionChanged( const unicorn::Session& s, const unicorn::Session& )
+{
+ AuthenticatedUser user;
+ qDebug() << "fetching friends, tags, playlists and recent stations for" << user;
+ connect(user.getFriends(), SIGNAL(finished()), m_mainWidget, SLOT(onUserGotFriends()));
+ connect(user.getTopTags(), SIGNAL(finished()), m_mainWidget, SLOT(onUserGotTopTags()));
+ connect(user.getPlaylists(), SIGNAL(finished()), m_mainWidget, SLOT(onUserGotPlaylists()));
+ connect(user.getRecentStations(), SIGNAL(finished()), m_mainWidget, SLOT(onUserGotRecentStations()));
}
void
View
6 app/radio/MainWindow.h
@@ -23,6 +23,8 @@
#include "lib/unicorn/UnicornMainWindow.h"
#include <lastfm/RadioStation>
+namespace unicorn{ class Session; }
+using unicorn::Session;
class MessageBar;
class MainWindow : public unicorn::MainWindow
@@ -38,7 +40,11 @@ class MainWindow : public unicorn::MainWindow
public slots:
void onRadioError(int code, const QVariant& data);
+protected slots:
+ void onSessionChanged( const Session& s, const Session& );
+
private:
+ class MainWidget* m_mainWidget;
MessageBar* m_messageBar;
};
View
33 lib/unicorn/UnicornApplication.cpp
@@ -94,29 +94,31 @@ unicorn::Application::Application( int& argc, char** argv ) throw( StubbornUserE
#ifdef __APPLE__
setQuitOnLastWindowClosed( false );
#endif
- QTimer::singleShot( 0, this, SLOT( init()));
+ initiateLogin();
+
+}
+
+void
+unicorn::Application::initiateLogin( bool forceLogout ) throw( StubbornUserException )
+{
if( m_bus.isSigningIn() ) {
- if( !SignalBlocker( &m_bus, SIGNAL( sessionChanged(Session)), -1 ).start())
- {
- quit();
- }
- } else {
-
+ SignalBlocker( &m_bus, SIGNAL( sessionChanged(Session)), -1 ).start();
+ } else if( !forceLogout ) {
Session busSession = m_bus.getSession();
if( busSession.isValid() )
m_currentSession = busSession;
}
- if( !m_currentSession.isValid() )
+ if( forceLogout || !m_currentSession.isValid() )
{
m_signingIn = true;
LoginDialog d( m_currentSession.username() );
connect( &m_bus, SIGNAL( signingInQuery( QString)), &d, SLOT( raise()));
if (d.exec() == QDialog::Accepted)
{
- m_currentSession = d.session();
+ changeSession( d.session());
QByteArray* ba = new QByteArray("");
QDataStream ds( ba, QIODevice::WriteOnly | QIODevice::Truncate);
ds << QByteArray( "SESSIONCHANGED" );
@@ -126,17 +128,10 @@ unicorn::Application::Application( int& argc, char** argv ) throw( StubbornUserE
}
else
{
- quit();
+ throw StubbornUserException();
}
}
m_signingIn = false;
- connect( AuthenticatedUser().getInfo(), SIGNAL(finished()), SLOT(onUserGotInfo()) );
-}
-
-
-void
-unicorn::Application::init()
-{
}
@@ -233,6 +228,10 @@ unicorn::Application::changeSession( const Session& newSession )
{
Session oldSession = currentSession();
m_currentSession = newSession;
+ lastfm::ws::Username = m_currentSession.username();
+ lastfm::ws::SessionKey = m_currentSession.sessionKey();
+
+ connect( AuthenticatedUser().getInfo(), SIGNAL(finished()), SLOT(onUserGotInfo()) );
emit sessionChanged( currentSession(), oldSession );
}
View
14 lib/unicorn/UnicornApplication.h
@@ -111,13 +111,18 @@ namespace unicorn
static unicorn::Application* instance(){ return (unicorn::Application*)qApp; }
public slots:
- void logout()
+ bool logout()
{
- m_logoutAtQuit = true;
- quit();
+ try {
+ initiateLogin( true );
+ } catch( const StubbornUserException& ) {
+ return false;
+ }
+ return true;
}
private:
+ void initiateLogin( bool forceLogout = false ) throw( StubbornUserException );
void translate();
void changeSession( const Session& newSession );
QString m_styleSheet;
@@ -126,7 +131,6 @@ namespace unicorn
bool m_signingIn;
private slots:
- void init();
void onUserGotInfo();
void onSigningInQuery( const QString& );
void onBusSessionQuery( const QString& );
@@ -134,7 +138,7 @@ namespace unicorn
signals:
void userGotInfo( QNetworkReply* );
- void sessionChanged( const Session& newSession, const Session oldSession );
+ void sessionChanged( const Session& newSession, const Session& oldSession );
};
}
View
19 lib/unicorn/UnicornMainWindow.cpp
@@ -56,10 +56,9 @@ unicorn::MainWindow::finishUi()
ui.account = menuBar()->addMenu( AuthenticatedUser().name() );
ui.profile = ui.account->addAction( tr("Visit &Profile"), this, SLOT(visitProfile()) );
ui.account->addSeparator();
- ui.account->addAction( tr("Log &Out && Quit"), qApp, SLOT(logout()) );
-#ifndef __APPLE__
- ui.account->addAction( tr("&Quit"), qApp, SLOT(quit()) );
-#endif
+ ui.account->addAction( tr("Log &Out"), qApp, SLOT(logout()) );
+ QAction* quit = ui.account->addAction( tr("&Quit"), qApp, SLOT(quit()) );
+ quit->setMenuRole( QAction::QuitRole );
menuBar()->insertMenu( menuBar()->actions().first(), ui.account );
QMenu* help = menuBar()->addMenu( tr("Help") );
@@ -77,6 +76,7 @@ unicorn::MainWindow::finishUi()
void
unicorn::MainWindow::onUserGotInfo( QNetworkReply* reply )
{
+ ui.account->setTitle( AuthenticatedUser());
QString const text = AuthenticatedUser::getInfoString( reply );
if (text.size() && ui.account) {
QAction* a = ui.account->addAction( text );
@@ -134,16 +134,17 @@ unicorn::MainWindow::eventFilter( QObject* o, QEvent* event )
{
case QEvent::MouseButtonPress:
m_dragHandleMouseDownPos[ obj ] = e->globalPos() - pos();
- break;
+ return true;
case QEvent::MouseButtonRelease:
m_dragHandleMouseDownPos[ obj ] = QPoint();
- break;
+ return true;
case QEvent::MouseMove:
- if (m_dragHandleMouseDownPos.contains( obj ) && !m_dragHandleMouseDownPos[ obj ].isNull())
- move( e->globalPos() - m_dragHandleMouseDownPos[ obj ]);
- break;
+ if (m_dragHandleMouseDownPos.contains( obj ) && !m_dragHandleMouseDownPos[ obj ].isNull()) {
+ move( e->globalPos() - m_dragHandleMouseDownPos[ obj ] );
+ return true;
+ }
}
return false;
View
6 lib/unicorn/UnicornSession.cpp
@@ -37,12 +37,12 @@ Session::Session()
s.beginGroup( username );
if( s.contains( "SessionKey" )) {
- init( username, s.value( "SessionKey" ).toString(), s.value("subscription", false).toBool());
+ init( username, s.value( "SessionKey" ).toString(), s.value("Subscriber", false).toBool());
}
}
-Session::Session( QNetworkReply* reply ) throw( lastfm::ws::Error )
+Session::Session( QNetworkReply* reply ) throw( lastfm::ws::ParseError )
:d( 0 )
{
lastfm::XmlQuery lfm = lastfm::ws::parse( reply );
@@ -101,8 +101,6 @@ Session::init( const QString& username, const QString& sessionKey, const bool is
d->isSubscriber = isSubscriber;
d->remember = false;
- lastfm::ws::Username = username;
- lastfm::ws::SessionKey = sessionKey;
}
}
View
2  lib/unicorn/UnicornSession.h
@@ -26,7 +26,7 @@ class UNICORN_DLLEXPORT Session
public:
Session();
Session( const Session& other );
- Session( QNetworkReply* reply ) throw( lastfm::ws::Error );
+ Session( QNetworkReply* reply ) throw( lastfm::ws::ParseError );
bool isValid() const
{
View
1  lib/unicorn/widgets/LoginDialog.cpp
@@ -129,6 +129,7 @@ LoginDialog::onAuthenticated()
try {
m_session = unicorn::Session( reply );
+ m_session.setRememberSession( ui.remember->isChecked());
accept();
}
catch (lastfm::ws::ParseError& e)
View
114 lib/unicorn/widgets/LoginDialog.ui
@@ -1,96 +1,104 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
<class>LoginDialog</class>
- <widget class="QDialog" name="LoginDialog" >
- <property name="geometry" >
+ <widget class="QDialog" name="LoginDialog">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>342</width>
- <height>140</height>
+ <width>345</width>
+ <height>163</height>
</rect>
</property>
- <property name="sizePolicy" >
- <sizepolicy vsizetype="MinimumExpanding" hsizetype="Preferred" >
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="windowTitle" >
+ <property name="windowTitle">
<string>Log in to Last.fm</string>
</property>
- <layout class="QVBoxLayout" >
- <property name="spacing" >
+ <layout class="QVBoxLayout">
+ <property name="spacing">
<number>0</number>
</property>
<item>
- <layout class="QHBoxLayout" >
- <property name="spacing" >
+ <layout class="QHBoxLayout">
+ <property name="spacing">
<number>0</number>
</property>
<item>
- <layout class="QGridLayout" >
- <property name="rightMargin" >
+ <layout class="QGridLayout">
+ <property name="rightMargin">
<number>0</number>
</property>
- <property name="spacing" >
+ <property name="spacing">
<number>6</number>
</property>
- <item row="0" column="0" >
- <widget class="QLabel" name="label_2" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Maximum" >
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="text" >
+ <property name="text">
<string>Username:</string>
</property>
</widget>
</item>
- <item row="1" column="0" >
- <widget class="QLabel" name="label_3" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Maximum" >
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="text" >
+ <property name="text">
<string>Password:</string>
</property>
- <property name="buddy" >
+ <property name="buddy">
<cstring>password</cstring>
</property>
</widget>
</item>
- <item row="1" column="1" >
- <widget class="QLineEdit" name="password" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="password">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="echoMode" >
+ <property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
- <item row="0" column="1" >
- <widget class="QLineEdit" name="username" />
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="username"/>
+ </item>
+ <item row="2" column="1">
+ <widget class="QCheckBox" name="remember">
+ <property name="text">
+ <string>Remember Me</string>
+ </property>
+ </widget>
</item>
</layout>
</item>
<item>
<spacer>
- <property name="orientation" >
+ <property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
- <property name="sizeType" >
+ <property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
- <property name="sizeHint" stdset="0" >
+ <property name="sizeHint" stdset="0">
<size>
<width>16</width>
<height>16</height>
@@ -99,29 +107,29 @@
</spacer>
</item>
<item>
- <layout class="QVBoxLayout" >
- <property name="spacing" >
+ <layout class="QVBoxLayout">
+ <property name="spacing">
<number>0</number>
</property>
<item>
- <widget class="SpinnerLabel" name="spinner" >
- <property name="minimumSize" >
+ <widget class="SpinnerLabel" name="spinner">
+ <property name="minimumSize">
<size>
<width>16</width>
<height>0</height>
</size>
</property>
- <property name="text" >
+ <property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer>
- <property name="orientation" >
+ <property name="orientation">
<enum>Qt::Vertical</enum>
</property>
- <property name="sizeHint" stdset="0" >
+ <property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
@@ -135,13 +143,13 @@
</item>
<item>
<spacer>
- <property name="orientation" >
+ <property name="orientation">
<enum>Qt::Vertical</enum>
</property>
- <property name="sizeType" >
+ <property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
- <property name="sizeHint" stdset="0" >
+ <property name="sizeHint" stdset="0">
<size>
<width>314</width>
<height>16</height>
@@ -150,17 +158,17 @@
</spacer>
</item>
<item>
- <layout class="QHBoxLayout" >
+ <layout class="QHBoxLayout">
<item>
- <widget class="QLabel" name="urls" >
- <property name="text" >
- <string>&lt;a href='http://last.fm/join/'>Sign up&lt;/a>&lt;br>&lt;a href='http://last.fm/settings/lostpassword/'>Forgot your password?&lt;/a></string>
+ <widget class="QLabel" name="urls">
+ <property name="text">
+ <string>&lt;a href='http://last.fm/join/'&gt;Sign up&lt;/a&gt;&lt;br&gt;&lt;a href='http://last.fm/settings/lostpassword/'&gt;Forgot your password?&lt;/a&gt;</string>
</property>
</widget>
</item>
<item>
- <widget class="QDialogButtonBox" name="buttonBox" >
- <property name="standardButtons" >
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
@@ -182,7 +190,7 @@
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>
- <include location="../../../common/qrc/common.qrc" />
+ <include location="../qrc/unicorn.qrc"/>
</resources>
<connections/>
</ui>
Please sign in to comment.
Something went wrong with that request. Please try again.