~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to juk/musicbrainzquery.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    begin                : Tue Aug 3 2004
 
3
    copyright            : (C) 2004 by Scott Wheeler
 
4
    email                : wheeler@kde.org
 
5
***************************************************************************/
 
6
 
 
7
/***************************************************************************
 
8
 *                                                                         *
 
9
 *   This program is free software; you can redistribute it and/or modify  *
 
10
 *   it under the terms of the GNU General Public License as published by  *
 
11
 *   the Free Software Foundation; either version 2 of the License, or     *
 
12
 *   (at your option) any later version.                                   *
 
13
 *                                                                         *
 
14
 ***************************************************************************/
 
15
 
 
16
#include "musicbrainzquery.h"
 
17
 
 
18
#if HAVE_MUSICBRAINZ
 
19
 
 
20
#include "trackpickerdialog.h"
 
21
#include "tag.h"
 
22
#include "collectionlist.h"
 
23
#include "tagtransactionmanager.h"
 
24
 
 
25
#include <kmainwindow.h>
 
26
#include <kapplication.h>
 
27
#include <kstatusbar.h>
 
28
#include <klocale.h>
 
29
#include <kdebug.h>
 
30
 
 
31
#include <qfileinfo.h>
 
32
 
 
33
MusicBrainzLookup::MusicBrainzLookup(const FileHandle &file) :
 
34
    KTRMLookup(file.absFilePath()),
 
35
    m_file(file)
 
36
{
 
37
    message(i18n("Querying MusicBrainz server..."));
 
38
}
 
39
 
 
40
void MusicBrainzLookup::recognized()
 
41
{
 
42
    KTRMLookup::recognized();
 
43
    confirmation();
 
44
}
 
45
 
 
46
void MusicBrainzLookup::unrecognized()
 
47
{
 
48
    KTRMLookup::unrecognized();
 
49
    message(i18n("No matches found."));
 
50
}
 
51
 
 
52
void MusicBrainzLookup::collision()
 
53
{
 
54
    KTRMLookup::collision();
 
55
    confirmation();
 
56
}
 
57
 
 
58
void MusicBrainzLookup::error()
 
59
{
 
60
    KTRMLookup::error();
 
61
    message(i18n("Error connecting to MusicBrainz server."));
 
62
}
 
63
 
 
64
void MusicBrainzLookup::message(const QString &s) const
 
65
{
 
66
    KMainWindow *w = static_cast<KMainWindow *>(kapp->mainWidget());
 
67
    w->statusBar()->message(QString("%1 (%2)").arg(s).arg(m_file.fileInfo().fileName()), 3000);
 
68
}
 
69
 
 
70
void MusicBrainzLookup::confirmation()
 
71
{
 
72
    // Here we do a bit of queuing to make sure that we don't pop up multiple
 
73
    // instances of the confirmation dialog at once.
 
74
 
 
75
    static QValueList< QPair<FileHandle, KTRMResultList> > queue;
 
76
 
 
77
    if(results().isEmpty())
 
78
        return;
 
79
 
 
80
    if(!queue.isEmpty()) {
 
81
        queue.append(qMakePair(m_file, results()));
 
82
        return;
 
83
    }
 
84
 
 
85
    queue.append(qMakePair(m_file, results()));
 
86
 
 
87
    while(!queue.isEmpty()) {
 
88
        QPair<FileHandle, KTRMResultList> item = queue.first();
 
89
        FileHandle file = item.first;
 
90
        KTRMResultList results = item.second;
 
91
        TrackPickerDialog dialog(file.fileInfo().fileName(), results);
 
92
 
 
93
        if(dialog.exec() == QDialog::Accepted && !dialog.result().isEmpty()) {
 
94
            KTRMResult result = dialog.result();
 
95
            Tag *tag = TagTransactionManager::duplicateTag(file.tag());
 
96
 
 
97
            if(!result.title().isEmpty())
 
98
                tag->setTitle(result.title());
 
99
            if(!result.artist().isEmpty())
 
100
                tag->setArtist(result.artist());
 
101
            if(!result.album().isEmpty())
 
102
                tag->setAlbum(result.album());
 
103
            if(result.track() != 0)
 
104
                tag->setTrack(result.track());
 
105
            if(result.year() != 0)
 
106
                tag->setYear(result.year());
 
107
 
 
108
            PlaylistItem *item = CollectionList::instance()->lookup(file.absFilePath());
 
109
            TagTransactionManager::instance()->changeTagOnItem(item, tag);
 
110
            TagTransactionManager::instance()->commit();
 
111
        }
 
112
        queue.pop_front();
 
113
    }
 
114
}
 
115
 
 
116
#endif