summaryrefslogtreecommitdiffstats
path: root/src/projects/k3baudiotracktrmlookupdialog.cpp
blob: 0bf23ecec6e56c65c3354696f96817e7a73798f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* 
 *
 * $Id: k3baudiotracktrmlookupdialog.cpp 619556 2007-01-03 17:38:12Z trueg $
 * Copyright (C) 2005 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * See the file "COPYING" for the exact licensing terms.
 */

#include <config.h>

#ifdef HAVE_MUSICBRAINZ

#include "k3baudiotracktrmlookupdialog.h"
#include "k3bmusicbrainzjob.h"

#include <k3bbusywidget.h>
#include <k3baudiotrack.h>
#include <k3baudiofile.h>
#include <k3bpassivepopup.h>

#include <kmessagebox.h>
#include <kinputdialog.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kglobal.h>
#include <kdebug.h>

#include <tqlabel.h>
#include <tqlayout.h>
#include <tqtimer.h>
#include <tqframe.h>
#include <tqeventloop.h>
#include <tqpushbutton.h>
#include <tqapplication.h>


K3bAudioTrackTRMLookupDialog::K3bAudioTrackTRMLookupDialog( TQWidget* parent, const char* name )
  : KDialogBase( KDialogBase::Plain, 
		 i18n("MusicBrainz Query"), 
		 KDialogBase::Cancel,
		 KDialogBase::Cancel,
		 parent, 
		 name,
		 true,
		 true )
{
  TQGridLayout* grid = new TQGridLayout( plainPage() );
  grid->setMargin( marginHint() );
  grid->setSpacing( spacingHint() );

  m_infoLabel = new TQLabel( plainPage() );
  TQLabel* pixLabel = new TQLabel( plainPage() );
  pixLabel->setPixmap( KGlobal::iconLoader()->loadIcon( "musicbrainz", KIcon::NoGroup, 64 ) );
  pixLabel->setScaledContents( false );

  m_busyWidget = new K3bBusyWidget( plainPage() );

  grid->addMultiCellWidget( pixLabel, 0, 1, 0, 0 );
  grid->addWidget( m_infoLabel, 0, 1 );
  grid->addWidget( m_busyWidget, 1, 1 );

  m_inLoop = false;
  m_mbJob = new K3bMusicBrainzJob( this );
  connect( m_mbJob, TQT_SIGNAL(infoMessage(const TQString&, int)), 
	   this, TQT_SLOT(slotMbJobInfoMessage(const TQString&, int)) );
  connect( m_mbJob, TQT_SIGNAL(finished(bool)), this, TQT_SLOT(slotMbJobFinished(bool)) );
  connect( m_mbJob, TQT_SIGNAL(trackFinished(K3bAudioTrack*, bool)), 
	   this, TQT_SLOT(slotTrackFinished(K3bAudioTrack*, bool)) );
}


K3bAudioTrackTRMLookupDialog::~K3bAudioTrackTRMLookupDialog()
{
}


int K3bAudioTrackTRMLookupDialog::lookup( const TQPtrList<K3bAudioTrack>& tracks )
{
  m_mbJob->setTracks( tracks );
  m_mbJob->start();

  m_busyWidget->showBusy(true);
  setModal( true );
  show();
  m_inLoop = true;
  TQApplication::eventLoop()->enterLoop();

  return 0;
}


void K3bAudioTrackTRMLookupDialog::slotMbJobInfoMessage( const TQString& message, int )
{
  m_infoLabel->setText( message );
}


void K3bAudioTrackTRMLookupDialog::slotMbJobFinished( bool )
{
  m_busyWidget->showBusy(false);
  hide();
  if( m_inLoop )
    TQApplication::eventLoop()->exitLoop();
}


void K3bAudioTrackTRMLookupDialog::slotCancel()
{
  actionButton( Cancel )->setEnabled( false );
  m_mbJob->cancel();
}


void K3bAudioTrackTRMLookupDialog::slotTrackFinished( K3bAudioTrack* track, bool success )
{
  if( !success )
    K3bPassivePopup::showPopup( i18n("Track %1 was not found in the MusicBrainz database.")
				.tqarg( track->trackNumber()),
				i18n("Audio Project") );
}

#include "k3baudiotracktrmlookupdialog.moc"

#endif