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

« back to all changes in this revision

Viewing changes to kcontrol/kfontinst/kcmfontinst/FcQuery.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-2007 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 "FcQuery.h"
 
25
#include "Fc.h"
 
26
#include <QtCore/QProcess>
 
27
#include <stdio.h>
 
28
 
 
29
namespace KFI
 
30
{
 
31
 
 
32
// key: 0(i)(s)
 
33
static int getInt(const QString &str)
 
34
{
 
35
    int rv=KFI_NULL_SETTING,
 
36
        start=str.lastIndexOf(':')+1,
 
37
        end=str.lastIndexOf("(i)(s)");
 
38
 
 
39
    if(end>start)
 
40
        rv=str.mid(start, end-start).trimmed().toInt();
 
41
 
 
42
    return rv;
 
43
}
 
44
 
 
45
CFcQuery::~CFcQuery()
 
46
{
 
47
}
 
48
 
 
49
void CFcQuery::run(const QString &query)
 
50
{
 
51
    QStringList args;
 
52
 
 
53
    itsFile=itsFont=QString();
 
54
    itsBuffer=QByteArray();
 
55
 
 
56
    if(itsProc)
 
57
        itsProc->kill();
 
58
    else
 
59
        itsProc=new QProcess(this);
 
60
 
 
61
    args << "-v" << query;
 
62
 
 
63
    connect(itsProc, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(procExited()));
 
64
    connect(itsProc, SIGNAL(readyReadStandardOutput()), SLOT(data()));
 
65
 
 
66
    itsProc->start("fc-match", args);
 
67
}
 
68
 
 
69
void CFcQuery::procExited()
 
70
{
 
71
    QString     family;
 
72
    int         weight(KFI_NULL_SETTING), slant(KFI_NULL_SETTING), width(KFI_NULL_SETTING);
 
73
    QStringList results(QString::fromUtf8(itsBuffer, itsBuffer.length()).split('\n'));
 
74
 
 
75
    if(results.size())
 
76
    {
 
77
        QStringList::ConstIterator it(results.begin()),
 
78
                                   end(results.end());
 
79
 
 
80
        for(; it!=end; ++it)
 
81
        {
 
82
            QString line((*it).trimmed());
 
83
 
 
84
            if(0==line.indexOf("file:"))  // file: "Wibble"(s)
 
85
            {
 
86
                int endPos=line.indexOf("\"(s)");
 
87
 
 
88
                if(-1!=endPos)
 
89
                    itsFile=line.mid(7, endPos-7);
 
90
            }
 
91
            else if(0==line.indexOf("family:"))  // family: "Wibble"(s)
 
92
            {
 
93
                int endPos=line.indexOf("\"(s)");
 
94
 
 
95
                if(-1!=endPos)
 
96
                    family=line.mid(9, endPos-9);
 
97
            }
 
98
            else if(0==line.indexOf("slant:"))  // slant: 0(i)(s)
 
99
                slant=getInt(line);
 
100
            else if(0==line.indexOf("weight:"))  // weight: 0(i)(s)
 
101
                weight=getInt(line);
 
102
            else if(0==line.indexOf("width:"))  // width: 0(i)(s)
 
103
                width=getInt(line);
 
104
        }
 
105
    }
 
106
 
 
107
    if(!family.isEmpty())
 
108
        itsFont=FC::createName(family, weight, width, slant);
 
109
 
 
110
    emit finished();
 
111
}
 
112
 
 
113
void CFcQuery::data()
 
114
{
 
115
    itsBuffer+=itsProc->readAllStandardOutput();
 
116
}
 
117
 
 
118
}
 
119
 
 
120
#include "FcQuery.moc"