3
by Scott Wheeler
This is a complete rewrite of the genre system to be based on XML. |
1 |
/***************************************************************************
|
2 |
genrelist.cpp - description
|
|
3 |
-------------------
|
|
4 |
begin : Sun Mar 3 2002
|
|
5 |
copyright : (C) 2002 by Scott Wheeler
|
|
6 |
email : scott@slackorama.net
|
|
7 |
***************************************************************************/
|
|
8 |
||
9 |
/***************************************************************************
|
|
10 |
* *
|
|
11 |
* This program is free software; you can redistribute it and/or modify *
|
|
12 |
* it under the terms of the GNU General Public License as published by *
|
|
13 |
* the Free Software Foundation; either version 2 of the License, or *
|
|
14 |
* (at your option) any later version. *
|
|
15 |
* *
|
|
16 |
***************************************************************************/
|
|
17 |
||
18 |
#include <kdebug.h> |
|
19 |
||
20 |
#include "genrelist.h" |
|
21 |
#include "genrelistreader.h" |
|
22 |
||
23 |
////////////////////////////////////////////////////////////////////////////////
|
|
24 |
// public members
|
|
25 |
////////////////////////////////////////////////////////////////////////////////
|
|
26 |
||
27 |
GenreList::GenreList() |
|
28 |
{
|
|
29 |
// index = 0;
|
|
30 |
}
|
|
31 |
||
32 |
GenreList::GenreList(QString file, bool createIndex = false) |
|
33 |
{
|
|
34 |
// index = 0;
|
|
35 |
load(file); |
|
36 |
||
37 |
if(createIndex) |
|
38 |
initializeIndex(); |
|
39 |
}
|
|
40 |
||
41 |
GenreList::~GenreList() |
|
42 |
{
|
|
43 |
}
|
|
44 |
||
45 |
void GenreList::load(QString file) |
|
46 |
{
|
|
47 |
GenreListReader *handler = new GenreListReader(this); |
|
48 |
QFile input(file); |
|
49 |
QXmlInputSource source(input); |
|
50 |
QXmlSimpleReader reader; |
|
51 |
reader.setContentHandler(handler); |
|
52 |
reader.parse(source); |
|
53 |
}
|
|
54 |
||
55 |
QString GenreList::name(int id3v1) |
|
56 |
{
|
|
57 |
if(id3v1 >= 0 && id3v1 < int(index.size())) |
|
58 |
return(index[id3v1]); |
|
59 |
else
|
|
60 |
return(QString::null); |
|
61 |
}
|
|
62 |
||
63 |
////////////////////////////////////////////////////////////////////////////////
|
|
64 |
// private members
|
|
65 |
////////////////////////////////////////////////////////////////////////////////
|
|
66 |
||
67 |
void GenreList::initializeIndex() |
|
68 |
{
|
|
69 |
index.clear(); |
|
70 |
index.resize(count()); |
|
71 |
for(GenreList::Iterator it = begin(); it != end(); ++it) { |
|
72 |
index[(*it).getId3v1()] = (*it).getName(); |
|
73 |
}
|
|
74 |
}
|