1
/***************************************************************************
2
* Copyright (C) 2005 - 2007 by *
3
* Jono Cole, Last.fm Ltd <jono@last.fm> *
4
* Christian Muehlhaeuser, Last.fm Ltd <chris@last.fm> *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. *
20
***************************************************************************/
23
#include "WebService/Request.h"
24
#include "Scrobbler-1.2.h"
25
#include "DiagnosticsDialog.h"
26
#include "LastFmSettings.h"
27
#include "container.h"
28
#include "lastfmapplication.h"
29
#include "libFingerprint/FingerprintCollector.h"
34
static void smallFontise( QWidget* w )
37
return; //small fonts look wrong on Windows
42
f.setPointSize( f.pointSize() - 2 );
50
DiagnosticsDialog::DiagnosticsDialog( QWidget *parent )
56
ui.radioGroupBox->setVisible( false );
59
// not possible to do this with designer, and varies by platform
60
smallFontise( ui.cachedTracksLabel );
61
smallFontise( ui.cachedTracksTitle );
62
smallFontise( ui.fingerprintedTracksTitle );
65
// Qt 4.3.1 b0rked? as this is specified in Designer, but only works on Linux :(
66
foreach ( QGroupBox* b, findChildren<QGroupBox*>() )
68
b->layout()->setMargin( 9 ); //Qt ignores our setting in Designer :(
70
if ( QSysInfo::WindowsVersion != QSysInfo::WV_VISTA )
77
layout()->setMargin( 7 );
79
ui.cachedTracksList->setAttribute( Qt::WA_MacShowFocusRect, false );
80
ui.vboxLayout1->setSpacing( 18 );
83
ui.httpBufferLabel->setMinimumWidth( ui.httpBufferProgress->fontMetrics().width( "100.0k" ) );
85
ui.httpBufferProgress->setMaximum( 500000 );
86
ui.decodedBufferProgress->setMaximum( 100000 );
87
ui.outputBufferProgress->setMaximum( 100000 );
89
connect( ui.closeButton, SIGNAL( clicked()), SLOT( close() ) );
90
connect( qApp, SIGNAL( event( int, QVariant ) ), SLOT( onAppEvent( int, QVariant ) ) );
91
connect( &The::scrobbler(), SIGNAL( status( int, QVariant ) ), SLOT( onScrobblerEvent() ) );
92
connect( ui.viewLogButton, SIGNAL( clicked() ), &The::container(), SLOT( onAltShiftL() ) );
93
connect( ui.viewHelperLogButton, SIGNAL( clicked() ), &The::container(), SLOT( onAltShiftH() ) );
94
connect( ui.refreshButton, SIGNAL( clicked() ), SLOT( onRefresh() ) );
95
connect( ui.copyToClipboardButton, SIGNAL( clicked() ), SLOT( onCopyToClipboard() ) );
97
// Fingerprint collector
98
ui.fpQueueSizeLabel->setText( "0" );
99
connect( The::app().m_fpCollector, SIGNAL( trackFingerprintingStarted( TrackInfo ) ),
100
this, SLOT( onTrackFingerprintingStarted( TrackInfo ) ),
101
Qt::QueuedConnection );
102
connect( The::app().m_fpCollector, SIGNAL( trackFingerprinted( TrackInfo ) ),
103
this, SLOT( onTrackFingerprinted( TrackInfo ) ),
104
Qt::QueuedConnection );
105
connect( The::app().m_fpCollector, SIGNAL( cantFingerprintTrack( TrackInfo, QString ) ),
106
this, SLOT( onCantFingerprintTrack( TrackInfo, QString ) ),
107
Qt::QueuedConnection );
111
DiagnosticsDialog::~DiagnosticsDialog()
116
DiagnosticsDialog::show()
118
//initialize the progress bars to 0
119
onDecodedBufferSizeChanged( 0 );
120
onHttpBufferSizeChanged( 0 );
121
onOutputBufferSizeChanged( 0 );
123
connect( &The::audioController().m_thread, SIGNAL( httpBufferSizeChanged( int ) ),
124
this, SLOT( onHttpBufferSizeChanged( int ) ),
125
Qt::QueuedConnection );
127
connect( &The::audioController().m_thread, SIGNAL( decodedBufferSizeChanged( int ) ),
128
this, SLOT( onDecodedBufferSizeChanged( int ) ),
129
Qt::QueuedConnection );
131
connect( &The::audioController().m_thread, SIGNAL( outputBufferSizeChanged( int ) ),
132
this, SLOT( onOutputBufferSizeChanged( int ) ),
133
Qt::QueuedConnection );
142
DiagnosticsDialog::close()
144
disconnect( &The::audioController().m_thread, SIGNAL( httpBufferSizeChanged( int ) ),
145
this, SLOT( onHttpBufferSizeChanged( int ) ) );
147
disconnect( &The::audioController().m_thread, SIGNAL( decodedBufferSizeChanged( int ) ),
148
this, SLOT( onDecodedBufferSizeChanged( int ) ) );
150
disconnect( &The::audioController().m_thread, SIGNAL( outputBufferSizeChanged( int ) ),
151
this, SLOT( onOutputBufferSizeChanged( int ) ) );
158
DiagnosticsDialog::onHttpBufferSizeChanged(int bufferSize)
160
ui.httpBufferProgress->setValue( bufferSize );
161
ui.httpBufferLabel->setText( QString::number( bufferSize / 1000.0f, 'f', 1 ) + "k" );
166
DiagnosticsDialog::onDecodedBufferSizeChanged(int bufferSize)
168
ui.decodedBufferProgress->setValue( bufferSize );
169
ui.decodedBufferLabel->setText( QString::number( bufferSize / 1000.0f, 'f', 1 ) + "k" );
174
DiagnosticsDialog::onOutputBufferSizeChanged(int bufferSize)
176
ui.outputBufferProgress->setValue( bufferSize );
177
ui.outputBufferLabel->setText( QString::number( bufferSize / 1000.0f, 'f', 1 ) + "k" );
182
DiagnosticsDialog::onAppEvent( int event, const QVariant& /* data */ )
186
case Event::ScrobblePointReached:
188
populateCacheList( The::settings().currentUser().username() );
199
DiagnosticsDialog::onScrobblerEvent()
201
QString const username = The::settings().currentUser().username();
203
QString submissionStatus = tr( "OK" );
204
if ( The::scrobbler().lastError( username ) != Scrobbler::NoError )
206
submissionStatus = tr( "Error: " ) + Scrobbler::errorDescription( The::scrobbler().lastError( username ) );
209
ui.lastConnectionStatusLabel->setText( QDateTime::currentDateTime().toString( "d/M/yyyy h:mm" ) );
211
ui.submissionServerStatusLabel->setText( submissionStatus );
212
populateCacheList( The::settings().currentUser().username() );
217
DiagnosticsDialog::radioHandshakeReturn( Request* req )
219
Handshake* handshake = static_cast<Handshake*>( req );
220
if ( handshake->failed() )
222
ui.radioServerStatusLabel->setText( tr( "Error: " ) + handshake->errorMessage() );
225
ui.radioServerStatusLabel->setText( tr( "OK" ) );
231
DiagnosticsDialog::populateCacheList( const QString& username )
233
ScrobbleCache scrobbleCache( username );
235
QList<QTreeWidgetItem *> items;
236
const QList<TrackInfo>& cachedTracks = scrobbleCache.tracks();
237
for( QList<TrackInfo>::const_iterator i = cachedTracks.begin(); i != cachedTracks.end(); i++ )
239
if ( i->isScrobbled() )
240
items.append( new QTreeWidgetItem( (QTreeWidget*)0,
241
QStringList() << i->artist() << i->track() << i->album() ) );
244
ui.cachedTracksList->clear();
245
ui.cachedTracksList->insertTopLevelItems( 0, items );
247
if (scrobbleCache.tracks().isEmpty())
248
ui.cachedTracksLabel->setText( tr( "The cache is empty" ) );
250
ui.cachedTracksLabel->setText( tr( "%n cached track(s)", "", items.count() ) );
255
DiagnosticsDialog::onRefresh()
257
LastFmUserSettings& user = The::settings().currentUser();
259
QString username = user.username();
260
QString password = user.password();
261
QString version = The::settings().version();
263
// Not strictly necessary. Will refresh itself via signal, too.
266
// ui.submissionServerStatusLabel->setText( tr( "Checking.." ) );
267
ui.radioServerStatusLabel->setText( tr( "Checking.." ) );
269
Handshake* radioHandshake = new Handshake;
270
radioHandshake->setUsername( username );
271
radioHandshake->setPassword( password );
272
radioHandshake->setVersion( version );
273
radioHandshake->setLanguage( The::settings().appLanguage() );
274
radioHandshake->start();
276
connect( radioHandshake, SIGNAL( result( Request* ) ),
277
this, SLOT ( radioHandshakeReturn( Request* ) ),
278
Qt::QueuedConnection );
280
populateCacheList( username );
285
DiagnosticsDialog::onCopyToClipboard()
287
QClipboard *clipboard = QApplication::clipboard();
288
QString clipboardText;
290
//TODO should read "Last successful submission" - that's what it actually shows at least
291
clipboardText.append( tr( "Last successful connection: " ) + ui.lastConnectionStatusLabel->text() + "\n\n" );
292
clipboardText.append( tr( "Submission Server: " ) + ui.submissionServerStatusLabel->text() + "\n" );
293
clipboardText.append( ui.cachedTracksLabel->text() + ":\n\n" );
295
// Iterate through cached tracks list and add to clipboard contents
296
for(int row = 0; row < ui.cachedTracksList->topLevelItemCount(); row++)
298
QTreeWidgetItem *rowData = ui.cachedTracksList->topLevelItem( row );
299
for(int col = 0; col < rowData->columnCount(); col++)
301
clipboardText.append( rowData->data( col, Qt::DisplayRole ).toString() );
302
clipboardText.append( "\t:\t" );
304
//remove trailing seperators
305
clipboardText.chop(3);
306
clipboardText.append( "\n" );
310
clipboardText.append("\n" + tr( "Radio Server: " ) + ui.radioServerStatusLabel->text() + "\n" );
313
clipboard->setText( clipboardText );
318
DiagnosticsDialog::onTrackFingerprintingStarted( TrackInfo track )
320
ui.fpCurrentTrackLabel->setText( track.toString() );
321
ui.fpQueueSizeLabel->setText( QString::number( The::app().m_fpCollector->queueSize() ) );
326
DiagnosticsDialog::onTrackFingerprinted( TrackInfo track )
328
ui.fpCurrentTrackLabel->setText( "" );
329
ui.fpQueueSizeLabel->setText( QString::number( The::app().m_fpCollector->queueSize() ) );
331
new QTreeWidgetItem( ui.fingerprintedTracksList, QStringList() << track.artist() << track.track() << track.album() );
336
DiagnosticsDialog::onCantFingerprintTrack( TrackInfo /* track */, QString /* reason */ )
338
ui.fpCurrentTrackLabel->setText( "" );
339
ui.fpQueueSizeLabel->setText( QString::number( The::app().m_fpCollector->queueSize() ) );