gschecker.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include "gschecker.h"
00021 #include "kpipeprocess.h"
00022 
00023 #include <qfile.h>
00024 #include <qtextstream.h>
00025 
00026 GsChecker::GsChecker(QObject *parent, const char *name)
00027 : QObject(parent,name)
00028 {
00029 }
00030 
00031 bool GsChecker::checkGsDriver(const QString& name)
00032 {
00033     if (m_driverlist.count() == 0)
00034         loadDriverList();
00035     return m_driverlist.contains(name);
00036 }
00037 
00038 void GsChecker::loadDriverList()
00039 {
00040     KPipeProcess    proc;
00041     if (proc.open("gs -h",IO_ReadOnly))
00042     {
00043         QTextStream t(&proc);
00044         QString buffer, line;
00045         bool    ok(false);
00046         while (!t.eof())
00047         {
00048             line = t.readLine().stripWhiteSpace();
00049             if (ok)
00050             {
00051                 if (line.find(':') != -1)
00052                     break;
00053                 else
00054                     buffer.append(line).append(" ");
00055             }
00056             else if (line.startsWith(QString::fromLatin1("Available devices:")))
00057                 ok = true;
00058         }
00059         m_driverlist = QStringList::split(' ',buffer,false);
00060     }
00061 }
KDE Home | KDE Accessibility Home | Description of Access Keys