00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
#include "kdeprintcheck.h"
00040
00041
#include <kstandarddirs.h>
00042
#include <kextsock.h>
00043
00044
static const char*
const config_stddirs[] = {
00045
"/etc/",
00046
"/usr/etc/",
00047
"/usr/local/etc/",
00048
"/opt/etc/",
00049
"/opt/local/etc/",
00050 0
00051 };
00052
00053
bool KdeprintChecker::check(KConfig *conf,
const QString& group)
00054 {
00055
if (!group.
isEmpty())
00056 conf->setGroup(group);
00057
QStringList uris = conf->readListEntry(
"Require");
00058
return check(uris);
00059 }
00060
00061
bool KdeprintChecker::check(
const QStringList& uris)
00062 {
00063
bool state(
true);
00064
for (QStringList::ConstIterator it=uris.begin(); it!=uris.end() && state; ++it)
00065 state = (state && checkURL(KURL(*it)));
00066
return state;
00067 }
00068
00069
bool KdeprintChecker::checkURL(
const KURL& url)
00070 {
00071
QString prot(url.protocol());
00072
if (prot ==
"config")
00073
return checkConfig(url);
00074
else if (prot ==
"exec")
00075
return checkExec(url);
00076
else if (prot ==
"file" || prot ==
"dir")
00077
return KStandardDirs::exists(url.url());
00078
else if (prot ==
"service")
00079
return checkService(url);
00080
return false;
00081 }
00082
00083
bool KdeprintChecker::checkConfig(
const KURL& url)
00084 {
00085
00086
QString f(url.path().mid(1));
00087
bool state(
false);
00088
00089
00090
if (!locate(
"config",f).isEmpty())
00091 state =
true;
00092
else
00093
00094 {
00095
const char*
const *p = config_stddirs;
00096
while (*p)
00097 {
00098
if (KStandardDirs::exists(QString::fromLatin1(*p)+f))
00099 {
00100 state =
true;
00101
break;
00102 }
00103
else
00104 p++;
00105 }
00106 }
00107
return state;
00108 }
00109
00110
bool KdeprintChecker::checkExec(
const KURL& url)
00111 {
00112
QString execname(url.path().mid(1));
00113
return !(KStandardDirs::findExe(execname).isEmpty());
00114 }
00115
00116
bool KdeprintChecker::checkService(
const KURL& url)
00117 {
00118
QString serv(url.path().mid(1));
00119 KExtendedSocket sock;
00120
00121
bool ok;
00122
int port = serv.toInt(&ok);
00123
00124
if (ok) sock.setAddress(
"localhost", port);
00125
else sock.setAddress(
"localhost", serv);
00126
return (sock.connect() == 0);
00127 }