~ubuntu-branches/ubuntu/lucid/lastfm/lucid

« back to all changes in this revision

Viewing changes to src/RestStateWidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2007-12-31 09:49:54 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071231094954-ix1amvcsj9pk61ya
Tags: 1:1.4.1.57486.dfsg-1ubuntu1
* Merge from Debian unstable (LP: #180254), remaining changes:
  - debian/rules;
    - Added dh_icons
  - Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 ***************************************************************************/
20
20
 
21
21
#include "RestStateWidget.h"
22
22
 
23
23
#include "configwizard.h"
24
 
#include "containerutils.h"
 
24
#include "MooseCommon.h"
25
25
#include "Radio.h"
26
26
#include "RestStateMessage.h"
27
27
#include "WebService/Request.h"
28
 
#include "Settings.h"
 
28
#include "LastFmSettings.h"
29
29
#include "WebService.h"
30
 
#include "winutils.h"
31
 
 
32
 
#include <QtGui>
33
 
 
 
30
 
 
31
#include "lastfmapplication.h"
 
32
 
 
33
#include <QKeyEvent>
 
34
#include <QDesktopServices>
 
35
#include <QPainter>
34
36
 
35
37
// These are pixel sizes
36
38
#ifdef WIN32
56
58
          m_play_enabled( false )
57
59
{
58
60
    //TODO give title tooltips for the tag keyword
59
 
    
 
61
 
60
62
    ui.setupUi( this );
61
 
    
 
63
 
62
64
    setFontPixelSize( ui.hello, k_helloFontSize );
63
65
    setFontPixelSize( ui.label1, k_standardFontSize );
64
66
    setFontPixelSize( ui.label2, k_standardFontSize );
65
 
    
 
67
 
66
68
    #ifdef Q_WS_MAC
67
69
        QSize s = QPixmap(":/mac/RestStateWidgetCombo.png").size();
68
70
 
69
71
        ui.label2->setText( tr("or listen to your music in %1.", "%1 is a media player").arg( "iTunes" ) );
70
72
 
71
 
        if (The::settings().appLanguage() == "en")
 
73
        if ( The::settings().appLanguage() == "en" )
72
74
        {
73
75
            // we only show this graphic for english as other languages are too wide
74
76
            ui.combo->setFixedSize( s );
75
 
            
 
77
 
76
78
            ui.combo->installEventFilter( this );
77
79
            ui.hboxLayout1->setSpacing( 6 );
78
 
        
 
80
 
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
90
92
 
91
93
        updatePlayerNames();
92
 
            
 
94
 
93
95
        // the long line is too wide and makes this->sizeHint huge unless we wordwrap
94
96
        ui.label2->setWordWrap( true );
95
 
        
 
97
 
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 );
100
 
        
 
102
 
101
103
    #elif defined LINUX
102
104
 
103
105
        ui.label2->hide(); //no plugins on Linux
104
 
        
 
106
 
105
107
        QList<QWidget*> widgets; widgets << ui.edit << ui.combo << ui.play;
106
108
        int h = 0;
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 );
111
113
 
112
114
    #endif
113
 
    
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()) );
117
 
    
118
 
    connect( &The::settings(), SIGNAL(userSwitched( UserSettings& )), SLOT(onUserChanged( UserSettings& )) );
119
 
    connect( The::webService(), SIGNAL(handshakeResult( Handshake* )), SLOT(onHandshaken( Handshake* )) );
120
 
    
 
115
 
 
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() ) );
 
119
 
 
120
    connect( &The::settings(), SIGNAL( userSwitched( LastFmUserSettings& ) ), SLOT( onUserChanged( LastFmUserSettings& ) ) );
 
121
    connect( The::webService(), SIGNAL( handshakeResult( Handshake* ) ), SLOT( onHandshaken( Handshake* ) ) );
 
122
 
121
123
    setFocusProxy( ui.edit );
122
 
    setWatermark( dataPath("watermark.png") );
 
124
    setWatermark( MooseUtils::dataPath("watermark.png") );
123
125
    onUserChanged( The::currentUser() );
124
 
    
 
126
 
125
127
    ui.edit->installEventFilter( this );
126
128
}
127
129
 
139
141
    QStringList plugins = The::settings().allPlugins( false );
140
142
    plugins.removeAll( "" );
141
143
 
142
 
    if (plugins.count())
 
144
    if ( plugins.count() )
143
145
    {
144
146
        QString last_plugin = plugins.takeLast();
145
 
        
146
 
        if (plugins.count())
 
147
 
 
148
        if ( plugins.count() )
147
149
        {
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'" );
150
 
            
 
152
 
151
153
            ui.label2->setText( text.arg( plugins.join( ", " ) ).arg( last_plugin ) );
152
154
        }
153
155
        else
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 ) );
155
157
    }
156
158
    else
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." ) );
158
160
#endif
159
161
}
160
162
 
161
163
 
162
164
void
163
 
RestStateWidget::onUserChanged( UserSettings& user )
 
165
RestStateWidget::onUserChanged( LastFmUserSettings& user )
164
166
{
165
167
    ui.hello->setText( tr("Hello %1,").arg( user.username() ) );
166
168
    ui.combo->setCurrentIndex( CurrentUserSettings().value( "RestStateWidgetComboIndex", 0 ).toInt() );
167
169
 
168
170
    qDeleteAll( findChildren<RestStateMessage*>() );
 
171
 
 
172
    QString const username = user.username().toLower();
169
173
}
170
174
 
171
175
 
172
176
void
173
177
RestStateWidget::onHandshaken( Handshake* handshake )
174
178
{
175
 
    if ( handshake->isBootstrapPermitted() )
 
179
 
 
180
    // HACK: Checking for isFirstRun prevents the little bootstrap prompt from appearing
 
181
    // if we're in the config wizard.
 
182
 
 
183
    #ifndef Q_WS_MAC
 
184
        const bool noPluginsInstalled = The::settings().allPlugins().empty();
 
185
    #else
 
186
        //There's always a Mac itunes "plugin"
 
187
        const bool noPluginsInstalled = false;
 
188
    #endif
 
189
 
 
190
    if ( noPluginsInstalled || !handshake->isBootstrapPermitted() || The::settings().isFirstRun() )
 
191
        return;
 
192
 
 
193
    // FIXME: this should be moved elsewhere as it isn't really anything to do with
 
194
    // the RestState.
 
195
    if ( QFile::exists( MooseUtils::savePath( The::currentUsername() + "_" +
 
196
                                             The::currentUser().bootStrapPluginId() +
 
197
                                             "_bootstrap.xml" ) ) )
176
198
    {
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.") );
181
 
        msg->show();
182
 
 
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() );
185
201
    }
 
202
 
 
203
    if ( !The::currentUser().bootStrapPluginId().isEmpty() )
 
204
        //A bootstrap must have been initiated so don't display bootstrapping message
 
205
        return;
 
206
 
 
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." ) );
 
211
    msg->show();
 
212
 
 
213
    connect( msg, SIGNAL( accepted() ), SLOT( showBootstrapWizard()) );
 
214
    connect( msg, SIGNAL( moreHelpClicked() ), SLOT( openBootstrapFaq()) );
 
215
 
186
216
}
187
217
 
188
218
 
197
227
RestStateWidget::setPlayEnabled( bool b )
198
228
{
199
229
    m_play_enabled = b;
200
 
    if (!b)
 
230
    if ( !b )
201
231
        ui.play->setEnabled( false );
202
232
    else
203
233
        ui.play->setEnabled( !ui.edit->text().isEmpty() );
208
238
RestStateWidget::onPlayClicked()
209
239
{
210
240
    QString url;
211
 
    
212
 
    if (ui.edit->text().startsWith( "lastfm://" ))
213
 
        url = "%1";
214
 
 
215
 
    else if (ui.combo->currentIndex() == 0)
216
 
        url = "lastfm://artist/%1/similarartists";
217
 
    
 
241
 
 
242
    if ( ui.edit->text().startsWith( "lastfm://" ) )
 
243
        url = QString( "%1" ).arg( ui.edit->text() );
 
244
 
 
245
    else if ( ui.edit->text().startsWith ( "http://" ) )
 
246
        url = "";
 
247
 
 
248
    else if ( ui.combo->currentIndex() == 0 )
 
249
        url = QString( "lastfm://artist/%1/similarartists" ).arg( ui.edit->text() );
 
250
 
218
251
    else
219
 
        url = "lastfm://globaltags/%1";
220
 
            
221
 
    The::radio().playStation( StationUrl( url.arg(ui.edit->text()) ) );
 
252
        url = QString( "lastfm://globaltags/%1" ).arg( ui.edit->text() );
 
253
 
 
254
    The::radio().playStation( StationUrl( url ) );
222
255
}
223
256
 
224
257
 
232
265
bool
233
266
RestStateWidget::eventFilter( QObject* o, QEvent* e )
234
267
{
235
 
    if (o == ui.edit)
 
268
    if ( o == ui.edit )
236
269
    {
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 );
241
274
    }
242
 
    
 
275
 
243
276
    #ifdef Q_WS_MAC
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" )
246
279
    {
247
 
                QRect r = ui.combo->rect();
 
280
        QRect r = ui.combo->rect();
248
281
        QPainter p( ui.combo );
249
282
 
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 );
253
286
        return true;
254
287
    }
255
288
    #endif
256
 
    
 
289
 
257
290
    return false;
258
291
}
259
292
 
261
294
RestStateWidget::showBootstrapWizard()
262
295
{
263
296
    ConfigWizard d( this, ConfigWizard::BootStrap );
264
 
    
265
 
    if (d.exec() == QDialog::Accepted)
 
297
 
 
298
    if ( d.exec() == QDialog::Accepted )
266
299
        sender()->deleteLater();
267
300
}
268
301
 
270
303
void
271
304
RestStateWidget::openBootstrapFaq()
272
305
{
273
 
    QDesktopServices::openUrl( QUrl("http://www.last.fm/help/faq/?category=Bootstrapping") );
 
306
    // TODO: might wanna link to the actual bootstrapping category in the faq
 
307
    // disabled for now as we don't have wanna hack on localized urls just one day before release
 
308
    QDesktopServices::openUrl(
 
309
        QUrl( "http://" + UnicornUtils::localizedHostName( The::settings().appLanguage() ) + "/help/faq/" ) ); // ?category=Listening History Importing" ) );
274
310
}