15
15
* You should have received a copy of the GNU General Public License *
16
16
* along with this program; if not, write to the *
17
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307, USA. *
18
* 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. *
19
19
***************************************************************************/
21
21
#include "RestStateWidget.h"
23
23
#include "configwizard.h"
24
#include "containerutils.h"
24
#include "MooseCommon.h"
26
26
#include "RestStateMessage.h"
27
27
#include "WebService/Request.h"
28
#include "LastFmSettings.h"
29
29
#include "WebService.h"
31
#include "lastfmapplication.h"
34
#include <QDesktopServices>
35
37
// These are pixel sizes
56
58
m_play_enabled( false )
58
60
//TODO give title tooltips for the tag keyword
60
62
ui.setupUi( this );
62
64
setFontPixelSize( ui.hello, k_helloFontSize );
63
65
setFontPixelSize( ui.label1, k_standardFontSize );
64
66
setFontPixelSize( ui.label2, k_standardFontSize );
67
69
QSize s = QPixmap(":/mac/RestStateWidgetCombo.png").size();
69
71
ui.label2->setText( tr("or listen to your music in %1.", "%1 is a media player").arg( "iTunes" ) );
71
if (The::settings().appLanguage() == "en")
73
if ( The::settings().appLanguage() == "en" )
73
75
// we only show this graphic for english as other languages are too wide
74
76
ui.combo->setFixedSize( s );
76
78
ui.combo->installEventFilter( this );
77
79
ui.hboxLayout1->setSpacing( 6 );
79
81
// this stuff is because for some reason the custom drawing isn't aligned
80
82
// unless we add a few pixels here and there. Bizarre.
81
83
ui.edit->setFixedHeight( ui.combo->height() );
89
91
#elif defined WIN32
91
93
updatePlayerNames();
93
95
// the long line is too wide and makes this->sizeHint huge unless we wordwrap
94
96
ui.label2->setWordWrap( true );
96
98
// Dirty hack to get heights looking the same on Windows
97
99
ui.combo->setFixedHeight( 20 );
98
100
ui.edit->setFixedHeight( 20 );
99
101
ui.play->setFixedHeight( 22 );
101
103
#elif defined LINUX
103
105
ui.label2->hide(); //no plugins on Linux
105
107
QList<QWidget*> widgets; widgets << ui.edit << ui.combo << ui.play;
107
foreach (QWidget* w, widgets)
109
foreach ( QWidget* w, widgets )
108
110
h = qMax( w->height(), h );
109
foreach (QWidget* w, widgets)
110
w->setFixedHeight( h );
111
foreach ( QWidget* w, widgets )
112
w->setFixedHeight( h );
114
connect( ui.edit, SIGNAL(returnPressed()), ui.play, SLOT(animateClick()) );
115
connect( ui.edit, SIGNAL(textChanged( QString )), SLOT(onEditTextChanged( QString )) );
116
connect( ui.play, SIGNAL(clicked()), SLOT(onPlayClicked()) );
118
connect( &The::settings(), SIGNAL(userSwitched( UserSettings& )), SLOT(onUserChanged( UserSettings& )) );
119
connect( The::webService(), SIGNAL(handshakeResult( Handshake* )), SLOT(onHandshaken( Handshake* )) );
116
connect( ui.edit, SIGNAL( returnPressed() ), ui.play, SLOT( animateClick() ) );
117
connect( ui.edit, SIGNAL( textChanged( QString ) ), SLOT( onEditTextChanged( QString ) ) );
118
connect( ui.play, SIGNAL( clicked() ), SLOT( onPlayClicked() ) );
120
connect( &The::settings(), SIGNAL( userSwitched( LastFmUserSettings& ) ), SLOT( onUserChanged( LastFmUserSettings& ) ) );
121
connect( The::webService(), SIGNAL( handshakeResult( Handshake* ) ), SLOT( onHandshaken( Handshake* ) ) );
121
123
setFocusProxy( ui.edit );
122
setWatermark( dataPath("watermark.png") );
124
setWatermark( MooseUtils::dataPath("watermark.png") );
123
125
onUserChanged( The::currentUser() );
125
127
ui.edit->installEventFilter( this );
139
141
QStringList plugins = The::settings().allPlugins( false );
140
142
plugins.removeAll( "" );
144
if ( plugins.count() )
144
146
QString last_plugin = plugins.takeLast();
148
if ( plugins.count() )
148
QString text = tr("or listen to your music in %1 or %2.",
150
QString text = tr( "or listen to your music in %1 or %2.",
149
151
"%1 is a list of plugins, eg. 'Foobar, Winamp, Windows Media Player'" );
151
153
ui.label2->setText( text.arg( plugins.join( ", " ) ).arg( last_plugin ) );
154
ui.label2->setText( tr("or listen to your music in %1.", "%1 is a media player").arg( last_plugin ) );
156
ui.label2->setText( tr( "or listen to your music in %1.", "%1 is a media player" ).arg( last_plugin ) );
157
ui.label2->setText( tr("or install a player plugin to scrobble music from your media player." ) );
159
ui.label2->setText( tr( "or install a player plugin to scrobble music from your media player." ) );
163
RestStateWidget::onUserChanged( UserSettings& user )
165
RestStateWidget::onUserChanged( LastFmUserSettings& user )
165
167
ui.hello->setText( tr("Hello %1,").arg( user.username() ) );
166
168
ui.combo->setCurrentIndex( CurrentUserSettings().value( "RestStateWidgetComboIndex", 0 ).toInt() );
168
170
qDeleteAll( findChildren<RestStateMessage*>() );
172
QString const username = user.username().toLower();
173
177
RestStateWidget::onHandshaken( Handshake* handshake )
175
if ( handshake->isBootstrapPermitted() )
180
// HACK: Checking for isFirstRun prevents the little bootstrap prompt from appearing
181
// if we're in the config wizard.
184
const bool noPluginsInstalled = The::settings().allPlugins().empty();
186
//There's always a Mac itunes "plugin"
187
const bool noPluginsInstalled = false;
190
if ( noPluginsInstalled || !handshake->isBootstrapPermitted() || The::settings().isFirstRun() )
193
// FIXME: this should be moved elsewhere as it isn't really anything to do with
195
if ( QFile::exists( MooseUtils::savePath( The::currentUsername() + "_" +
196
The::currentUser().bootStrapPluginId() +
197
"_bootstrap.xml" ) ) )
177
RestStateMessage* msg = new RestStateMessage( this );
178
msg->setAcceptText( tr("Do It!" ) );
179
msg->setMessage( tr("Do you want to import your iTunes listening history?\n"
180
"This will add charts to your profile based on what you've listened to in the past.") );
183
connect( msg, SIGNAL(accepted()), SLOT(showBootstrapWizard()) );
184
connect( msg, SIGNAL(moreHelpClicked()), SLOT(openBootstrapFaq()) );
199
//Bootstrapping XML is ready to be submitted to the server
200
The::app().onBootstrapReady( The::currentUsername(), The::currentUser().bootStrapPluginId() );
203
if ( !The::currentUser().bootStrapPluginId().isEmpty() )
204
//A bootstrap must have been initiated so don't display bootstrapping message
207
RestStateMessage* msg = new RestStateMessage( this );
208
msg->setAcceptText( tr( "Do It!" ) );
209
msg->setMessage( tr( "Do you want to import your media player listening history?\n"
210
"This will add charts to your profile based on what you've listened to in the past." ) );
213
connect( msg, SIGNAL( accepted() ), SLOT( showBootstrapWizard()) );
214
connect( msg, SIGNAL( moreHelpClicked() ), SLOT( openBootstrapFaq()) );
208
238
RestStateWidget::onPlayClicked()
212
if (ui.edit->text().startsWith( "lastfm://" ))
215
else if (ui.combo->currentIndex() == 0)
216
url = "lastfm://artist/%1/similarartists";
242
if ( ui.edit->text().startsWith( "lastfm://" ) )
243
url = QString( "%1" ).arg( ui.edit->text() );
245
else if ( ui.edit->text().startsWith ( "http://" ) )
248
else if ( ui.combo->currentIndex() == 0 )
249
url = QString( "lastfm://artist/%1/similarartists" ).arg( ui.edit->text() );
219
url = "lastfm://globaltags/%1";
221
The::radio().playStation( StationUrl( url.arg(ui.edit->text()) ) );
252
url = QString( "lastfm://globaltags/%1" ).arg( ui.edit->text() );
254
The::radio().playStation( StationUrl( url ) );
233
266
RestStateWidget::eventFilter( QObject* o, QEvent* e )
237
270
int const key = static_cast<QKeyEvent*>(e)->key();
238
if (key == Qt::Key_Up || key == Qt::Key_Down)
271
if ( key == Qt::Key_Up || key == Qt::Key_Down )
239
272
//send these to the combo as a convenience feature
240
273
ui.combo->event( e );
244
277
// can only do with english as the others have different width texts
245
if (o == ui.combo && e->type() == QEvent::Paint && The::settings().appLanguage() == "en")
278
if ( o == ui.combo && e->type() == QEvent::Paint && The::settings().appLanguage() == "en" )
247
QRect r = ui.combo->rect();
280
QRect r = ui.combo->rect();
248
281
QPainter p( ui.combo );
250
p.drawPixmap( QPoint( 0, 2 ), QPixmap(":/mac/RestStateWidgetCombo.png") );
283
p.drawPixmap( QPoint( 0, 2 ), QPixmap( ":/mac/RestStateWidgetCombo.png" ) );
251
284
r.adjust( 0, 0, -20, 0 );
252
285
p.drawText( r, ui.combo->currentText(), Qt::AlignVCenter | Qt::AlignRight );