~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/kfontinst/lib/Family.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * KFontInst - KDE Font Installer
 
3
 *
 
4
 * Copyright 2003-2009 Craig Drummond <craig@kde.org>
 
5
 *
 
6
 * ----
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; see the file COPYING.  If not, write to
 
20
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
21
 * Boston, MA 02110-1301, USA.
 
22
 */
 
23
 
 
24
#include <QtCore/QTextStream>
 
25
#include <QtXml/QDomElement>
 
26
#include <KDE/KDebug>
 
27
#include "Family.h"
 
28
#include "Misc.h"
 
29
#include "XmlStrings.h"
 
30
 
 
31
#define KFI_DBUG kDebug() << time(0L)
 
32
 
 
33
namespace KFI
 
34
{
 
35
 
 
36
Family::Family(const QDomElement &elem, bool loadStyles)
 
37
{
 
38
    if(elem.hasAttribute(FAMILY_ATTR))
 
39
        itsName=elem.attribute(FAMILY_ATTR);
 
40
    if(elem.hasAttribute(NAME_ATTR))
 
41
        itsName=elem.attribute(NAME_ATTR);
 
42
    if(loadStyles)
 
43
    {
 
44
        for(QDomNode n=elem.firstChild(); !n.isNull(); n=n.nextSibling())
 
45
        {
 
46
            QDomElement ent=n.toElement();
 
47
 
 
48
            if(FONT_TAG==ent.tagName())
 
49
            {
 
50
                Style style(ent, loadStyles);
 
51
 
 
52
                if(!style.files().isEmpty())
 
53
                    itsStyles.insert(style);
 
54
            }
 
55
        }
 
56
    }
 
57
}
 
58
 
 
59
void Family::toXml(bool disabled, QTextStream &s) const
 
60
{
 
61
    QString                  family(KFI::Misc::encodeText(itsName, s));
 
62
    QStringList              entries;
 
63
    StyleCont::ConstIterator it(itsStyles.begin()),
 
64
                             end(itsStyles.end());
 
65
 
 
66
    for(; it!=end; ++it)
 
67
    {
 
68
        QString entry((*it).toXml(disabled, disabled ? family : QString(), s));
 
69
 
 
70
        if(!entry.isEmpty())
 
71
            entries.append(entry);
 
72
    }
 
73
 
 
74
    if(entries.count()>0)
 
75
    {
 
76
        if(!disabled)
 
77
            s << " <"FAMILY_TAG" "NAME_ATTR"=\"" << KFI::Misc::encodeText(itsName, s) << "\">\n";
 
78
 
 
79
        QStringList::ConstIterator it(entries.begin()),
 
80
                                   end(entries.end());
 
81
 
 
82
        for(; it!=end; ++it)
 
83
            s << *it << endl;
 
84
 
 
85
        if(!disabled)
 
86
            s << " </"FAMILY_TAG">" << endl;
 
87
    }
 
88
}
 
89
 
 
90
}
 
91
 
 
92
QDBusArgument & operator<<(QDBusArgument &argument, const KFI::Family &obj)
 
93
{
 
94
    argument.beginStructure();
 
95
    argument << obj.name();
 
96
 
 
97
    argument.beginArray(qMetaTypeId<KFI::Style>());
 
98
    KFI::StyleCont::ConstIterator it(obj.styles().begin()),
 
99
                                  end(obj.styles().end());
 
100
    for(; it!=end; ++it)
 
101
        argument << *it;
 
102
    argument.endArray();
 
103
    argument.endStructure();
 
104
    return argument;
 
105
}
 
106
 
 
107
const QDBusArgument & operator>>(const QDBusArgument &argument, KFI::Family &obj)
 
108
{
 
109
    QString name;
 
110
    argument.beginStructure();
 
111
    argument >> name;
 
112
    obj=KFI::Family(name);
 
113
    argument.beginArray();
 
114
    while(!argument.atEnd())
 
115
    {
 
116
        KFI::Style st;
 
117
        argument >> st;
 
118
        obj.add(st);
 
119
    }
 
120
    argument.endArray();
 
121
    argument.endStructure();
 
122
    return argument;
 
123
}
 
124
 
 
125
QDBusArgument & operator<<(QDBusArgument &argument, const KFI::Families &obj)
 
126
{
 
127
    argument.beginStructure();
 
128
    argument << obj.isSystem;
 
129
 
 
130
    argument.beginArray(qMetaTypeId<KFI::Family>());
 
131
    KFI::FamilyCont::ConstIterator it(obj.items.begin()),
 
132
                                   end(obj.items.end());
 
133
 
 
134
    for(; it!=end; ++it)
 
135
        argument << *it;
 
136
    argument.endArray();
 
137
    argument.endStructure();
 
138
    return argument;
 
139
}
 
140
 
 
141
const QDBusArgument & operator>>(const QDBusArgument &argument, KFI::Families &obj)
 
142
{
 
143
    argument.beginStructure();
 
144
    argument >> obj.isSystem;
 
145
    argument.beginArray();
 
146
    while(!argument.atEnd())
 
147
    {
 
148
        KFI::Family fam;
 
149
        argument >> fam;
 
150
        obj.items.insert(fam);
 
151
    }
 
152
    argument.endArray();
 
153
    argument.endStructure();
 
154
    return argument;
 
155
}