Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Unicorn::Application handles login. Unicorn::UserSettings is settings…

… 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...
commit 631f2361c6806e337ac918e2432fc08538396524 1 parent 55ce479
@mxcl mxcl authored
View
0  app/fingerprinter/trunk/COPYING → COPYING
File renamed without changes
View
48 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 *
@@ -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 )) );
@@ -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;
}
View
6 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 *
@@ -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
View
18 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 *
@@ -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 ); }
View
12 app/client/main.cpp
@@ -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;
}
}
View
16 app/fingerprinter/trunk/Fingerprinter.pro
@@ -1,16 +0,0 @@
-TEMPLATE = subdirs
-
-# build directories as they are ordered
-CONFIG = ordered
-
-mac* {
- SUBDIRS += src/libs/taglib/ \
- src/libFingerprint/libs/libmad/libmad.pro
-}
-
-SUBDIRS += \
- src/libLastFmTools/ \
- src/libFingerprint/ \
- src/
-
-
View
11 app/fingerprinter/trunk/src/main.cpp
@@ -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();
}
View
73 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" );
+ }
+}
View
42 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();
+ };
+}
View
55 lib/unicorn/UnicornSettings.h
@@ -1,4 +1,21 @@
-
+/***************************************************************************
+ * 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. *
+ ***************************************************************************/
#ifndef UNICORN_SETTINGS_H
#define UNICORN_SETTINGS_H
@@ -22,7 +39,17 @@ namespace Unicorn
QSettings() : ::QSettings( "Last.fm", "AudioScrobbler" )
{}
};
-
+
+
+ /** Clearly no use until a username() has been assigned. But this is
+ * automatic if you use Unicorn::Application anyway. */
+ class UserSettings : public Unicorn::QSettings
+ {
+ public:
+ UserSettings();
+ };
+
+
/** Settings that may be of use to the entire Last.fm suite
*/
class UNICORN_DLLEXPORT Settings
@@ -32,6 +59,9 @@ namespace Unicorn
{}
QString username() const { return QSettings().value( "Username" ).toString(); }
+ // perhaps should be a UserSetting, but well, only one person can be
+ // logged in at a time and we forget passwords for security reasons
+ // inbetween user switching. So really this makes sense.
QString password() const { return QSettings().value( "Password" ).toString(); }
bool isUseProxy() const { return QSettings().value( "ProxyEnabled" ).toInt() == 1; }
@@ -40,16 +70,28 @@ namespace Unicorn
QString proxyUser() const { return QSettings().value( "ProxyUser" ).toString(); }
QString proxyPassword() const { return QSettings().value( "ProxyPassword" ).toString(); }
+ // all Unicorn::Applications obey this
+ bool logOutOnExit() const { return UserSettings().value( "LogOutOnExit", false ).toBool(); }
+
/** @returns one of our pre-defined 2-letter language codes */
QString language() const;
};
+
+
+ inline UserSettings::UserSettings()
+ {
+ QString const username = Unicorn::Settings().username();
+ beginGroup( username );
+ // it shouldn't be possible, since Unicorn::Application enforces
+ // assignment of the username parameter before anything else
+ Q_ASSERT( !username.isEmpty() );
+ }
- //TODO make most of this private, friend to Settings dialog, or move there
- class MutableSettings : private Settings
+ class UNICORN_DLLEXPORT MutableSettings : private Settings
{
- void setPassword(); // undefined, as basically, you're not
- void setUsername(); // allowed to do this, App.cpp can though
+ void setPassword(); // undefined, as basically, you're not allowed
+ void setUsername(); // to do this, Unicorn::Application can though
public:
MutableSettings()
@@ -61,6 +103,7 @@ namespace Unicorn
void setProxyUser( QString v ) { QSettings().setValue( "ProxyUser", v ); }
void setProxyPassword( QString v ) { QSettings().setValue( "ProxyPassword", v ); }
void setLanguage( QString langCode ) { QSettings().setValue( "AppLanguage", langCode ); }
+ void setLogOutOnExit( bool b ) { UserSettings().setValue( "LogOutOnExit", b ); }
};
}
View
5 lib/unicorn/libunicorn.pro
@@ -8,9 +8,10 @@ QT += gui
include( $$SRC_DIR/common/qmake/include.pro )
-SOURCES += $$findSources( cpp )
-HEADERS += $$findSources( h ) \
+SOURCES = $$findSources( cpp )
+HEADERS = $$findSources( h ) \
QtOverride/QHttp QtOverride/QSystemTrayIcon QtOverride/QMessageBox
+FORMS = $$findSources( ui )
!win32 {
SOURCES -= UnicornCommonWin.cpp
View
0  app/client/widgets/LoginDialog.cpp → lib/unicorn/widgets/LoginDialog.cpp
File renamed without changes
View
0  app/client/widgets/LoginDialog.h → lib/unicorn/widgets/LoginDialog.h
File renamed without changes
View
0  app/client/widgets/LoginDialog.ui → lib/unicorn/widgets/LoginDialog.ui
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.