~ubuntu-branches/ubuntu/natty/kdemultimedia/natty-proposed

« back to all changes in this revision

Viewing changes to kmix/gui/guiprofile.h

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers
  • Date: 2011-05-26 02:41:36 UTC
  • mfrom: (0.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 108.
  • Revision ID: james.westby@ubuntu.com-20110526024136-jjwsigfy402jhupm
Tags: upstream-4.6.3
ImportĀ upstreamĀ versionĀ 4.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * KMix -- KDE's full featured mini mixer
 
3
 *
 
4
 * Copyright 2006-2007 Christian Esken <esken@kde.org>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 *
 
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 GNU
 
14
 * Library General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Library General Public
 
17
 * License along with this program; if not, write to the Free
 
18
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 */
 
20
 
 
21
#ifndef _GUIPROFILE_H_
 
22
#define _GUIPROFILE_H_
 
23
 
 
24
class Mixer;
 
25
 
 
26
#include <qxml.h>
 
27
#include <QColor>
 
28
#include <QTextStream>
 
29
#include <QString>
 
30
 
 
31
#include <string>
 
32
#include <map>
 
33
#include <set>
 
34
#include <vector>
 
35
#include <ostream>
 
36
 
 
37
#include <KDebug>
 
38
 
 
39
struct SortedStringComparator
 
40
{
 
41
    bool operator()(const std::string&, const std::string&) const;
 
42
};
 
43
 
 
44
 
 
45
struct ProfProduct
 
46
{
 
47
    QString vendor;
 
48
    QString productName;
 
49
    // In case the vendor ships different products under the same productName
 
50
    QString productRelease;
 
51
    QString comment;
 
52
};
 
53
 
 
54
class ProfControlPrivate
 
55
{
 
56
public:
 
57
    // List of controls, e.g: "rec:1-2,recswitch"
 
58
    // THIS IS RAW DATA AS LOADED FROM THE PROFILE. DO NOT USE IT, except for debugging.
 
59
    QString subcontrols;
 
60
 
 
61
};
 
62
 
 
63
class ProfControl
 
64
{
 
65
public:
 
66
    ProfControl(QString& id, QString& subcontrols);
 
67
    ProfControl(const ProfControl &ctl); // copy constructor
 
68
    ~ProfControl();
 
69
    // ID as returned by the Mixer Backend, e.g. Master:0
 
70
    QString id;
 
71
 
 
72
    void setSubcontrols(QString sctls);
 
73
    bool useSubcontrolPlayback() {return _useSubcontrolPlayback;};
 
74
    bool useSubcontrolCapture() {return _useSubcontrolCapture;};
 
75
    bool useSubcontrolPlaybackSwitch() {return _useSubcontrolPlaybackSwitch;};
 
76
    bool useSubcontrolCaptureSwitch() {return _useSubcontrolCaptureSwitch;};
 
77
    bool useSubcontrolEnum() {return _useSubcontrolEnum;};
 
78
    QString renderSubcontrols();
 
79
 
 
80
    QString getBackgroundColor() const    {        return backgroundColor;    }
 
81
    void setBackgroundColor(QString& backgroundColor)    {        this->backgroundColor = backgroundColor;    }
 
82
    QString getSwitchtype() const    {        return switchtype;    }
 
83
    void setSwitchtype(QString switchtype)    {        this->switchtype = switchtype;    }
 
84
 
 
85
    // Visible name for the User ( if name.isNull(), id will be used - And in the future a default lookup table will be consulted ).
 
86
    // Because the name is visible, some kind of i18n() should be used.
 
87
    QString name;
 
88
    // show or hide (contains the GUI type: simple, extended, all)
 
89
    QString show;
 
90
 
 
91
    bool isMandatory() const
 
92
    {
 
93
        return _mandatory;
 
94
    }
 
95
 
 
96
    void setMandatory(bool _mandatory)
 
97
    {
 
98
        this->_mandatory = _mandatory;
 
99
    }
 
100
    void setSplit ( bool split ) {
 
101
      _split = split;
 
102
    }
 
103
    bool isSplit() const { 
 
104
      return _split;
 
105
    }
 
106
 
 
107
private:
 
108
    // The following are the deserialized values of _subcontrols
 
109
    bool _useSubcontrolPlayback;
 
110
    bool _useSubcontrolCapture;
 
111
    bool _useSubcontrolPlaybackSwitch;
 
112
    bool _useSubcontrolCaptureSwitch;
 
113
    bool _useSubcontrolEnum;
 
114
 
 
115
    // For applying custom colors
 
116
    QString backgroundColor;
 
117
    // For defining the switch type when it is not a standard palyback or capture switch
 
118
    QString switchtype;
 
119
 
 
120
    bool _mandatory; // A mandatory control must be included in all GUIProfile copies
 
121
 
 
122
    ProfControlPrivate *d;
 
123
    bool _split; // true if this widget is to show two sliders
 
124
};
 
125
 
 
126
 
 
127
struct ProductComparator
 
128
{
 
129
    bool operator()(const ProfProduct*, const ProfProduct*) const;
 
130
};
 
131
 
 
132
class GUIProfile
 
133
{
 
134
    public:
 
135
    GUIProfile();
 
136
    virtual ~GUIProfile();
 
137
 
 
138
    bool readProfile(const QString& ref_fileNamestring);
 
139
    bool finalizeProfile() const;
 
140
    bool writeProfile();
 
141
    
 
142
    bool isDirty() const;
 
143
    void setDirty();
 
144
    
 
145
    void setId(const QString& id);
 
146
    QString getId() const;
 
147
    QString getMixerId() const { return _mixerId; }
 
148
    
 
149
    static QMap<QString, GUIProfile*>& getProfiles() { return s_profiles; }
 
150
    
 
151
    unsigned long match(Mixer* mixer);
 
152
    friend std::ostream& operator<<(std::ostream& os, const GUIProfile& vol);
 
153
    friend QTextStream& operator<<(QTextStream &outStream, const GUIProfile& guiprof);
 
154
 
 
155
    typedef std::set<ProfProduct*, ProductComparator> ProductSet;
 
156
 
 
157
 
 
158
    ProductSet _products;
 
159
 
 
160
    static GUIProfile* find(Mixer* mixer, QString profileName, bool profileNameIsFullyQualified, bool ignoreCardName);
 
161
    static GUIProfile* selectProfileFromXMLfiles(Mixer*, QString preferredProfile);
 
162
    static GUIProfile* fallbackProfile(Mixer*);
 
163
 
 
164
    typedef QList<ProfControl*> ControlSet;
 
165
 
 
166
    const ControlSet& getControls() const
 
167
    {
 
168
        return _controls;
 
169
    }
 
170
    ControlSet& getControls()
 
171
    {
 
172
        return _controls;
 
173
    }
 
174
    void setControls(ControlSet& newControlSet);
 
175
 
 
176
    QString getName() const    {        return _name;    }
 
177
    void setName(QString _name)    {        this->_name = _name;    }
 
178
 
 
179
    // The values from the <soundcard> tag
 
180
    QString _soundcardDriver;
 
181
    // The driver version: 1000*1000*MAJOR + 1000*MINOR + PATCHLEVEL
 
182
    unsigned long _driverVersionMin;
 
183
    unsigned long _driverVersionMax;
 
184
    QString _soundcardName;
 
185
    QString _soundcardType;
 
186
    unsigned long _generation;
 
187
private:
 
188
    ControlSet _controls;
 
189
    
 
190
    // Loading
 
191
    static QString buildProfileName(Mixer* mixer, QString profileName, bool ignoreCard);
 
192
    static QString buildReadableProfileName(Mixer* mixer, QString profileName);
 
193
 
 
194
    static GUIProfile* loadProfileFromXMLfiles(Mixer* mixer, QString profileName);
 
195
    static void addProfile(GUIProfile* guiprof);
 
196
    static QMap<QString, GUIProfile*> s_profiles;
 
197
    
 
198
    QString _id;
 
199
    QString _name;
 
200
    QString _mixerId;
 
201
    bool _dirty;
 
202
};
 
203
 
 
204
std::ostream& operator<<(std::ostream& os, const GUIProfile& vol);
 
205
QTextStream& operator<<(QTextStream &outStream, const GUIProfile& guiprof);
 
206
 
 
207
class GUIProfileParser : public QXmlDefaultHandler
 
208
{
 
209
public:
 
210
    GUIProfileParser(GUIProfile* ref_gp);
 
211
    // Enumeration for the scope
 
212
    enum ProfileScope { NONE, SOUNDCARD };
 
213
    
 
214
    bool startDocument();
 
215
    bool startElement( const QString&, const QString&, const QString& , const QXmlAttributes& );
 
216
    bool endElement( const QString&, const QString&, const QString& );
 
217
    
 
218
private:
 
219
    void addControl(const QXmlAttributes& attributes);
 
220
    void addProduct(const QXmlAttributes& attributes);
 
221
    void addSoundcard(const QXmlAttributes& attributes);
 
222
    void addProfileInfo(const QXmlAttributes& attributes);
 
223
    void printAttributes(const QXmlAttributes& attributes);
 
224
    void splitPair(const QString& pairString, std::pair<QString,QString>& result, char delim);
 
225
 
 
226
    ProfileScope _scope;
 
227
    GUIProfile* _guiProfile;
 
228
};
 
229
 
 
230
#endif //_GUIPROFILE_H_