1 | /* |
2 | * Copyright (C) 1995 Paul Olav Tvete <paul@troll.no> |
3 | * Copyright (C) 2000-2009 Stephan Kulow <coolo@kde.org> |
4 | * Copyright (C) 2009 Parker Coates <coates@kde.org> |
5 | * |
6 | * License of original code: |
7 | * ------------------------------------------------------------------------- |
8 | * Permission to use, copy, modify, and distribute this software and its |
9 | * documentation for any purpose and without fee is hereby granted, |
10 | * provided that the above copyright notice appear in all copies and that |
11 | * both that copyright notice and this permission notice appear in |
12 | * supporting documentation. |
13 | * |
14 | * This file is provided AS IS with no warranties of any kind. The author |
15 | * shall have no liability with respect to the infringement of copyrights, |
16 | * trade secrets or any patents by this file or any part thereof. In no |
17 | * event will the author be liable for any lost revenue or profits or |
18 | * other special, indirect and consequential damages. |
19 | * ------------------------------------------------------------------------- |
20 | * |
21 | * License of modifications/additions made after 2009-01-01: |
22 | * ------------------------------------------------------------------------- |
23 | * This program is free software; you can redistribute it and/or |
24 | * modify it under the terms of the GNU General Public License as |
25 | * published by the Free Software Foundation; either version 2 of |
26 | * the License, or (at your option) any later version. |
27 | * |
28 | * This program is distributed in the hope that it will be useful, |
29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31 | * GNU General Public License for more details. |
32 | * |
33 | * You should have received a copy of the GNU General Public License |
34 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
35 | * ------------------------------------------------------------------------- |
36 | */ |
37 | |
38 | #include "dealerinfo.h" |
39 | |
40 | #include <KGlobal> |
41 | #include <KLocale> |
42 | |
43 | |
44 | DealerInfo::DealerInfo( const QByteArray & untranslatedBaseName, int baseId ) |
45 | : m_baseName( untranslatedBaseName ), |
46 | m_baseId( baseId ) |
47 | { |
48 | DealerInfoList::self()->add( this ); |
49 | |
50 | QString baseName = QString::fromUtf8( m_baseName ); |
51 | for ( int i = 0; i < baseName.size(); ++i ) |
52 | { |
53 | QChar c = baseName.at( i ); |
54 | if ( c.isLetterOrNumber() ) |
55 | m_baseIdString += c.toLower(); |
56 | } |
57 | } |
58 | |
59 | |
60 | DealerInfo::~DealerInfo() |
61 | { |
62 | } |
63 | |
64 | |
65 | QString DealerInfo::baseName() const |
66 | { |
67 | return i18n( m_baseName ); |
68 | } |
69 | |
70 | |
71 | QByteArray DealerInfo::untranslatedBaseName() const |
72 | { |
73 | return m_baseName; |
74 | } |
75 | |
76 | |
77 | QString DealerInfo::baseIdString() const |
78 | { |
79 | return m_baseIdString; |
80 | } |
81 | |
82 | |
83 | int DealerInfo::baseId() const |
84 | { |
85 | return m_baseId; |
86 | } |
87 | |
88 | |
89 | void DealerInfo::addSubtype( int id, const QByteArray & untranslatedName ) |
90 | { |
91 | m_subtypes.insert( id, untranslatedName ); |
92 | } |
93 | |
94 | |
95 | QList<int> DealerInfo::subtypeIds() const |
96 | { |
97 | return m_subtypes.keys(); |
98 | } |
99 | |
100 | |
101 | QList<int> DealerInfo::distinctIds() const |
102 | { |
103 | if ( m_subtypes.isEmpty() ) |
104 | return QList<int>() << m_baseId; |
105 | else |
106 | return m_subtypes.keys(); |
107 | } |
108 | |
109 | |
110 | bool DealerInfo::providesId( int id ) const |
111 | { |
112 | return id == m_baseId || m_subtypes.contains( id ); |
113 | } |
114 | |
115 | |
116 | QString DealerInfo::nameForId( int id ) const |
117 | { |
118 | if ( id == m_baseId ) |
119 | return baseName(); |
120 | |
121 | QMap<int,QByteArray>::const_iterator it = m_subtypes.find( id ); |
122 | if ( it != m_subtypes.constEnd() ) |
123 | return i18n( it.value().constData() ); |
124 | else |
125 | return QString(); |
126 | } |
127 | |
128 | |
129 | class DealerInfoListPrivate |
130 | { |
131 | public: |
132 | DealerInfoList instance; |
133 | }; |
134 | |
135 | K_GLOBAL_STATIC( DealerInfoListPrivate, dilp ) |
136 | |
137 | |
138 | |
139 | DealerInfoList *DealerInfoList::self() |
140 | { |
141 | return &(dilp->instance); |
142 | } |
143 | |
144 | DealerInfoList::DealerInfoList() |
145 | { |
146 | } |
147 | |
148 | DealerInfoList::~DealerInfoList() |
149 | { |
150 | } |
151 | |
152 | void DealerInfoList::add( DealerInfo * di ) |
153 | { |
154 | m_list.append( di ); |
155 | } |
156 | |
157 | const QList< DealerInfo* > DealerInfoList::games() const |
158 | { |
159 | return m_list; |
160 | } |
161 | |