1 /*****************************************************************************
2 * fingerprintdialog.cpp: Fingerprinter Dialog
3 *****************************************************************************
4 * Copyright (C) 2012 VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #include "fingerprintdialog.hpp"
22 #include "ui/fingerprintdialog.h"
24 #include "adapters/chromaprint.hpp"
28 #include <QListWidgetItem>
30 FingerprintDialog::FingerprintDialog(QWidget *parent, intf_thread_t *p_intf,
31 input_item_t *p_item ) :
33 ui(new Ui::FingerprintDialog), p_r( NULL )
37 ui->stackedWidget->setCurrentWidget( ui->wait );
39 ui->buttonBox->addButton( "&Close",
40 QDialogButtonBox::RejectRole );
42 ui->buttonsBox->addButton( "&Apply this identity to the file",
43 QDialogButtonBox::AcceptRole );
45 ui->buttonsBox->addButton( "&Discard all identities",
46 QDialogButtonBox::RejectRole );
48 CONNECT( ui->buttonsBox, accepted(), this, applyIdentity() );
49 CONNECT( ui->buttonBox, rejected(), this, close() );
50 CONNECT( ui->buttonsBox, rejected(), this, close() );
52 t = new Chromaprint( p_intf );
55 CONNECT( t, finished(), this, handleResults() );
60 void FingerprintDialog::applyIdentity()
63 if ( ui->recordsList->currentIndex().isValid() )
64 t->apply( p_r, ui->recordsList->currentIndex().row() );
65 emit metaApplied( p_r->p_item );
69 void FingerprintDialog::handleResults()
71 p_r = t->fetchResults();
75 ui->stackedWidget->setCurrentWidget( ui->error );
79 if ( vlc_array_count( & p_r->results.metas_array ) == 0 )
81 fingerprint_request_Delete( p_r );
83 ui->stackedWidget->setCurrentWidget( ui->error );
87 ui->stackedWidget->setCurrentWidget( ui->results );
89 for ( int i=0; i< vlc_array_count( & p_r->results.metas_array ) ; i++ )
92 (vlc_meta_t *) vlc_array_item_at_index( & p_r->results.metas_array, i );
93 QListWidgetItem *item = new QListWidgetItem();
94 ui->recordsList->addItem( item );
95 QString mb_id( vlc_meta_GetExtra( p_meta, "musicbrainz-id" ) );
96 QLabel *label = new QLabel(
97 QString( "<h3 style=\"margin: 0\"><a style=\"text-decoration:none\" href=\"%1\">%2</a></h3>"
98 "<span style=\"padding-left:20px\">%3</span>" )
99 .arg( QString( "http://mb.videolan.org/recording/%1" ).arg( mb_id ) )
100 .arg( qfu( vlc_meta_Get( p_meta, vlc_meta_Title ) ) )
101 .arg( qfu( vlc_meta_Get( p_meta, vlc_meta_Artist ) ) )
103 label->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
104 label->setOpenExternalLinks( true );
105 item->setSizeHint( label->sizeHint() );
106 ui->recordsList->setItemWidget( item, label );
108 ui->recordsList->setCurrentIndex( ui->recordsList->model()->index( 0, 0 ) );
111 FingerprintDialog::~FingerprintDialog()
114 if ( p_r ) fingerprint_request_Delete( p_r );