1
/***************************************************************************
2
* Copyright (C) 2005 - 2007 by *
3
* Christian Muehlhaeuser, Last.fm Ltd <chris@last.fm> *
4
* Erik Jaelevik, Last.fm Ltd <erik@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
***************************************************************************/
22
#include "MediaDeviceConfirmDialog.h"
24
#include "container.h"
25
#include "MooseCommon.h"
27
#include "Scrobbler-1.2.h"
32
#include <QDesktopWidget>
35
MediaDeviceConfirmDialog::MediaDeviceConfirmDialog( const QString& username, QWidget *parent )
36
: QDialog( parent, Qt::Sheet ),
37
m_username( username )
39
m_tracks = ScrobbleCache::mediaDeviceCache( m_username ).tracks();
44
MediaDeviceConfirmDialog::setupUi()
50
QPixmap p( MooseUtils::dataPath( "app_55.png" ) );
51
// p = p.scaled( 32, 32, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
52
ui.iconLabel->setPixmap( p );
54
////// This section sizes the dialog as best as possible, it is a shame but
55
// Qt sizeHints usually ignore the view contents size, so we do it manually.
57
//this magnificent hack bought to you by teh mxcl
58
// @short allow access to this protected function so we can determine the
59
// ideal width for the confirm dialog
60
struct NoProtection : QAbstractItemView
62
using QAbstractItemView::sizeHintForColumn;
65
int w = 0, desiredwidth = 0;
66
for (int x = 0; x < ui.tracksWidget->columnCount(); ++x) {
67
desiredwidth = reinterpret_cast<NoProtection*>(ui.tracksWidget)->sizeHintForColumn( x );
71
ui.tracksWidget->setMinimumWidth( w );
72
if (m_tracks.count() > 10 )
73
ui.tracksWidget->setMinimumHeight( ui.tracksWidget->sizeHint().height() * 2 );
75
//make us always the right size
76
layout()->setSizeConstraint( QLayout::SetMinimumSize );
78
int const W = QDesktopWidget().availableGeometry().width();
79
if (sizeHint().width() > W)
80
ui.tracksWidget->setMinimumWidth( W
81
- (sizeHint().width() - ui.tracksWidget->width())
82
- 10 /*small aesthetic gap*/ );
85
connect( ui.scrobble, SIGNAL(clicked()), SLOT(accept()) );
86
connect( ui.cancel, SIGNAL(clicked()), SLOT(reject()) );
87
connect( ui.toggle, SIGNAL(clicked()), SLOT(toggleChecked()) );
95
MediaDeviceConfirmDialog::addTracksToView()
97
QList<QTreeWidgetItem*> items;
99
foreach (TrackInfo t, m_tracks)
101
QDateTime dt = QDateTime::fromTime_t( t.timeStamp() );
102
QTreeWidgetItem* widget = new QTreeWidgetItem;
103
widget->setData( 0, Qt::DisplayRole, t.artist() );
104
widget->setData( 1, Qt::DisplayRole, t.track() );
105
widget->setData( 2, Qt::DisplayRole, dt );
106
widget->setData( 3, Qt::DisplayRole, QString::number(t.playCount()) );
108
widget->setFlags( widget->flags() | Qt::ItemIsUserCheckable );
109
widget->setCheckState( 0, Qt::Checked );
111
widget->setData( 0, Qt::UserRole, index++ );
116
ui.tracksWidget->insertTopLevelItems( 0, items );
117
ui.tracksWidget->resizeColumnToContents( 0 );
118
ui.tracksWidget->resizeColumnToContents( 1 );
119
ui.tracksWidget->resizeColumnToContents( 2 );
120
ui.tracksWidget->resizeColumnToContents( 4 );
122
ui.tracksWidget->setSortingEnabled( true );
123
ui.tracksWidget->sortByColumn( 2, Qt::DescendingOrder );
125
QString text = tr( "<p>Last.fm found %n new track(s) since the last time you synced your iPod.<br/>"
126
"Please select the tracks that you want to be scrobbled from your iPod.",
130
if (The::user().name() != m_username)
131
text += "<p><b>" + tr("This iPod scrobbles to %1's profile!").arg( m_username );
133
ui.messageLabel->setText( text );
138
MediaDeviceConfirmDialog::toggleChecked()
140
for (int x = 0; x < ui.tracksWidget->topLevelItemCount(); ++x)
142
QTreeWidgetItem* i = ui.tracksWidget->topLevelItem( x );
143
i->setCheckState( 0, i->checkState( 0 ) == Qt::Checked ? Qt::Unchecked : Qt::Checked );
149
MediaDeviceConfirmDialog::exec()
151
if (m_tracks.count())
154
return QDialog::exec();
157
return QDialog::Rejected;
162
MediaDeviceConfirmDialog::tracks() const
164
QList<TrackInfo> tracks;
165
for (int x = 0; x < ui.tracksWidget->topLevelItemCount(); ++x)
167
QTreeWidgetItem* item = ui.tracksWidget->topLevelItem( x );
168
if (item->checkState( 0 ) == Qt::Checked)
170
int const index = item->data( 0, Qt::UserRole ).toInt();
171
tracks += m_tracks[index];