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

« back to all changes in this revision

Viewing changes to kcontrol/kfontinst/lib/File.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 <QtXml/QDomElement>
 
25
#include <QtCore/QTextStream>
 
26
#include <QtCore/QDir>
 
27
#include "File.h"
 
28
#include "Misc.h"
 
29
#include "XmlStrings.h"
 
30
 
 
31
namespace KFI
 
32
{
 
33
 
 
34
static QString expandHome(const QString &path)
 
35
{
 
36
    QString p(path);
 
37
 
 
38
    return !p.isEmpty() && '~'==p[0]
 
39
        ? 1==p.length() ? QDir::homePath() : p.replace(0, 1, QDir::homePath())
 
40
        : p;
 
41
}
 
42
 
 
43
File::File(const QDomElement &elem, bool disabled)
 
44
{
 
45
    QString path=expandHome(elem.attribute(PATH_ATTR));
 
46
 
 
47
    if(!disabled || Misc::fExists(path)) // Only need to check instance if we are loading the disabled file...
 
48
    {
 
49
        itsFoundry=elem.attribute(FOUNDRY_ATTR);
 
50
        itsIndex=elem.hasAttribute(FACE_ATTR) ? elem.attribute(FACE_ATTR).toInt() : 0;
 
51
        itsPath=path;
 
52
    }
 
53
}
 
54
    
 
55
QString File::toXml(bool disabled, QTextStream &s) const
 
56
{
 
57
    if(!disabled || Misc::isHidden(Misc::getFile(itsPath)))
 
58
    {
 
59
        QString str(PATH_ATTR"=\""+KFI::Misc::encodeText(KFI::Misc::contractHome(itsPath), s)+"\"");
 
60
 
 
61
        if(!itsFoundry.isEmpty() && QString::fromLatin1("unknown")!=itsFoundry)
 
62
            str+=" "FOUNDRY_ATTR"=\""+KFI::Misc::encodeText(itsFoundry, s)+"\"";
 
63
 
 
64
        if(itsIndex>0)
 
65
            str+=" "FACE_ATTR"=\""+QString::number(itsIndex)+"\"";
 
66
 
 
67
        return str;
 
68
    }
 
69
 
 
70
    return QString();
 
71
}
 
72
 
 
73
}
 
74
 
 
75
QDBusArgument & operator<<(QDBusArgument &argument, const KFI::File &obj)
 
76
{
 
77
    argument.beginStructure();
 
78
    argument << obj.path() << obj.foundry() << obj.index();
 
79
    argument.endStructure();
 
80
    return argument;
 
81
}
 
82
 
 
83
const QDBusArgument & operator>>(const QDBusArgument &argument, KFI::File &obj)
 
84
{
 
85
    QString path,
 
86
            foundry;
 
87
    int     index;
 
88
    argument.beginStructure();
 
89
    argument >> path >> foundry >> index;
 
90
    obj=KFI::File(path, foundry, index);
 
91
    argument.endStructure();
 
92
    return argument;
 
93
}