Skip to content

Commit

Permalink
Unicorn::Application handles login. Unicorn::UserSettings is settings…
Browse files Browse the repository at this point in the history
… per user for all apps in the suite. But we prolly will use it sparingly.

git-svn-id: svn+ssh://svn.last.fm/svn/clientside/trunk/desktop@86489 ab8f4a45-97f9-0310-bbd1-854ce3dcee89
  • Loading branch information
mxcl committed Jul 3, 2008
1 parent 55ce479 commit 631f236
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 95 deletions.
File renamed without changes.
48 changes: 5 additions & 43 deletions app/client/App.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
* Copyright 2005-2008 Last.fm Ltd *
* Copyright 2005-2008 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 *
Expand Down Expand Up @@ -27,48 +27,18 @@
#include "mac/ITunesListener.h"
#include "scrobbler/Scrobbler.h"
#include "widgets/DiagnosticsDialog.h"
#include "widgets/LoginDialog.h"
#include "widgets/MainWindow.h"
#include "lib/unicorn/LastMessageBox.h"
#include <QLineEdit>
#include <QSystemTrayIcon>


App::App( int argc, char** argv )
: QApplication( argc, argv )
: Unicorn::Application( argc, argv )
{
#ifdef Q_WS_MAC
if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_4)
{
LastMessageBox::critical(
QObject::tr( "Unsupported OS X Version" ),
QObject::tr( "We are sorry, but Last.fm requires OS X Tiger or above." ) );
throw 1; //FIXME using exceptions for flow control? eww!
}
#endif

//TODO bootstrapping

Settings::instance = new Settings( VERSION, applicationFilePath() );

if (The::settings().username().isEmpty() || The::settings().logOutOnExit())
{
LoginDialog d;
if (d.exec() == QDialog::Accepted)
{
// we shouldn't store this really, if LogOutOnExit is enabled
// but we delete the setting on exit, and it means other apps can
// log in while the client is loaded, and prevents us having to
// store these datas for the use case where LogOutOnExit is disabled
// during the session
Unicorn::QSettings().setValue( "Username", d.username() );
Unicorn::QSettings().setValue( "Password", d.password() );

//TODO bootstrapping
}
else
{
throw 0; //FIXME using exceptions for flow control? eww!
}
}

m_playerListener = new PlayerListener( this );
connect( m_playerListener, SIGNAL(bootstrapCompleted( QString, QString )), SLOT(onBootstrapCompleted( QString, QString )) );

Expand All @@ -90,14 +60,6 @@ App::App( int argc, char** argv )

App::~App()
{
// we do this here, rather than in the SettingsDialog in case the user
// changes their mind
if (The::settings().logOutOnExit())
{
Unicorn::QSettings().remove( "Username" );
Unicorn::QSettings().remove( "Password" );
}

delete Settings::instance;
}

Expand Down
6 changes: 3 additions & 3 deletions app/client/App.h
@@ -1,5 +1,5 @@
/***************************************************************************
* Copyright 2005-2008 Last.fm Ltd *
* Copyright 2005-2008 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 *
Expand All @@ -18,10 +18,10 @@
***************************************************************************/

#include "PlaybackState.h"
#include <QApplication>
#include "lib/unicorn/UnicornApplication.h"


class App : public QApplication
class App : public Unicorn::Application
{
Q_OBJECT

Expand Down
18 changes: 3 additions & 15 deletions app/client/Settings.h
@@ -1,5 +1,5 @@
/***************************************************************************
* Copyright 2005-2008 Last.fm Ltd *
* Copyright 2005-2008 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 *
Expand Down Expand Up @@ -34,33 +34,21 @@ class Settings : public Moose::Settings
friend class App;
friend Settings& The::settings();

protected:
Settings( const Settings& )
{
// we appear odd, but it enforces encapsulation, since the compiler
// requires an instance of Settings to use this ctor, and only main()
// can create one, well you could cast something else, but we may
// actually require something from the Settings instance at some point
// and then your code will crash :P
}

public:
QByteArray containerGeometry() const { return QSettings().value( "MainWindowGeometry" ).toByteArray(); }
Qt::WindowState containerWindowState() const { return (Qt::WindowState) QSettings().value( "MainWindowState" ).toInt(); }
bool logOutOnExit() const { return QSettings().value( "LogOutOnExit", false ).toBool(); }

private:
bool m_weWereJustUpgraded;
};


class MutableSettings : private Settings
class MutableSettings : public Unicorn::MutableSettings
{
public:
MutableSettings( const Settings& that ) : Settings( that )
MutableSettings( const ::Settings& )
{}

void setLogOutOnExit( bool b ) { QSettings().setValue( "LogOutOnExit", b ); }
void setControlPort( int v ) { QSettings().setValue( "ControlPort", v ); }
void setScrobblePoint( int scrobblePoint ) { QSettings().setValue( "ScrobblePoint", scrobblePoint ); }
void setContainerWindowState( int state ) { QSettings().setValue( "MainWindowState", state ); }
Expand Down
12 changes: 10 additions & 2 deletions app/client/main.cpp
Expand Up @@ -62,12 +62,20 @@ int main( int argc, char** argv )
}
catch (PlayerListener::SocketFailure& e)
{
//TODO
//TODO message to user
//FIXME can't have it so that there is no radio option if listener socket fails!
qDebug() << "Socket failure:" << e.what();
return 1;
}
catch (int)
catch (Unicorn::Application::UnsupportedPlatformException&)
{
// a message box was displayed to the user by Unicorn::Application
qDebug() << "Unsupport platform";
return 2;
}
catch (Unicorn::Application::StubbornUserException&)
{
// user wouldn't log in
return 0;
}
}
16 changes: 0 additions & 16 deletions app/fingerprinter/trunk/Fingerprinter.pro

This file was deleted.

11 changes: 3 additions & 8 deletions app/fingerprinter/trunk/src/main.cpp
Expand Up @@ -19,24 +19,19 @@
***************************************************************************/

#include "FingerprinterApplication.h"
#include "libLastFmTools/logger.h"
#include "containerutils.h"
#include "lib/unicorn/Logger.h"
#include "lib/unicorn/UnicornCommon.h"


/******************************************************************************
main
******************************************************************************/
int main( int argc, char *argv[] )
{
// used by some Qt stuff, eg QSettings
// leave first! As FingerprinterSettings object is created quickly
QCoreApplication::setApplicationName( "Fingerprinter" );
QCoreApplication::setOrganizationName( "Last.fm" );
QCoreApplication::setOrganizationDomain( "last.fm" );

FingerprinterApplication app( argc, argv );

Logger::GetLogger().Init( savePath( "fingerprinter.log" ) );
Logger::GetLogger().Init( Unicorn::savePath( "fingerprinter.log" ) );

return app.exec();
}
73 changes: 73 additions & 0 deletions lib/unicorn/UnicornApplication.cpp
@@ -0,0 +1,73 @@
/***************************************************************************
* Copyright 2005-2008 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 "UnicornApplication.h"
#include "LastMessageBox.h"
#include "UnicornSettings.h"
#include "widgets/LoginDialog.h"


Unicorn::Application::Application( int argc, char** argv ) throw( StubbornUserException, UnsupportedPlatformException )
: QApplication( argc, argv )
{
#ifdef Q_WS_MAC
if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_4)
{
LastMessageBox::critical(
QObject::tr( "Unsupported OS X Version" ),
QObject::tr( "We are sorry, but Last.fm requires OS X Tiger or above." ) );
throw UnsupportedPlatformException();
}
#endif

Settings s;

if (s.username().isEmpty() || s.logOutOnExit())
{
LoginDialog d;
if (d.exec() == QDialog::Accepted)
{
// we shouldn't store this really, if LogOutOnExit is enabled
// but we delete the setting on exit, and it means other apps can
// log in while the client is loaded, and prevents us having to
// store these datas for the use case where LogOutOnExit is disabled
// during the session
Unicorn::QSettings s;
s.setValue( "Username", d.username() );
s.setValue( "Password", d.password() );
}
else
{
throw StubbornUserException();
}
}
}


Unicorn::Application::~Application()
{
// we do this here, rather than when the setting is changed because if we
// did it then the user would be unable to change their mind
if (Unicorn::Settings().logOutOnExit())
{
Unicorn::QSettings s;
s.remove( "Username" );
s.remove( "Password" );
}
}
42 changes: 42 additions & 0 deletions lib/unicorn/UnicornApplication.h
@@ -0,0 +1,42 @@
/***************************************************************************
* Copyright 2005-2008 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 <QApplication>


namespace Unicorn
{
class Application : public QApplication
{
Q_OBJECT

public:
// shows a message box advising user of error before throwing
class UnsupportedPlatformException
{};

class StubbornUserException
{};

/** will put up the log in dialog if necessary, throwing if the user
* cancels, ie. they refuse to log in */
Application( int, char** ) throw( StubbornUserException, UnsupportedPlatformException );
~Application();
};
}

0 comments on commit 631f236

Please sign in to comment.