• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
tdeprintcheck.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 **/
19
20/*
21 * Implementation of simple checking mechanism. Rules are defined in
22 * the form of an URI. Available syntax is:
23 * - exec:/<execname> -> check for an executable in
24 * $PATH variable.
25 * - config:/path/to/file -> check for the existence of a file
26 * or directory in KDE or standard
27 * UNIX config locations
28 * - file:/path/to/file
29 * - dir:/path/to/dir -> simply check the existence of the
30 * a file or directory
31 * - service:/serv -> try to connect to a port on the
32 * specified host (usually localhost)
33 * "serv" can be a port value or service name
34 *
35 * TO BE IMPLEMENTED:
36 * - run:/<execname> -> check for a running executable
37 */
38
39#include "tdeprintcheck.h"
40
41#include <tdestandarddirs.h>
42#include <kdebug.h>
43#include <kextsock.h>
44#include <tqfile.h>
45#include <unistd.h>
46
47static const char* const config_stddirs[] = {
48 "/etc/",
49 "/usr/etc/",
50 "/usr/local/etc/",
51 "/opt/etc/",
52 "/opt/local/etc/",
53 0
54};
55
56bool KdeprintChecker::check(TDEConfig *conf, const TQString& group)
57{
58 if (!group.isEmpty())
59 conf->setGroup(group);
60 TQStringList uris = conf->readListEntry("Require");
61 return check(uris);
62}
63
64bool KdeprintChecker::check(const TQStringList& uris)
65{
66 bool state(true);
67 for (TQStringList::ConstIterator it=uris.begin(); it!=uris.end() && state; ++it)
68 {
69 state = (state && checkURL(KURL(*it)));
70 // kdDebug( 500 ) << "auto-detection uri=" << *it << ", state=" << state << endl;
71 }
72 return state;
73}
74
75bool KdeprintChecker::checkURL(const KURL& url)
76{
77 TQString prot(url.protocol());
78 if (prot == "config")
79 return checkConfig(url);
80 else if (prot == "exec")
81 return checkExec(url);
82 else if (prot == "file" || prot == "dir")
83 return TDEStandardDirs::exists(url.url());
84 else if (prot == "service")
85 return checkService(url);
86 return false;
87}
88
89bool KdeprintChecker::checkConfig(const KURL& url)
90{
91 // get the config filename (may contain a path)
92 TQString f(url.path().mid(1));
93 bool state(false);
94
95 // first check for standard KDE config file
96 if (!locate("config",f).isEmpty())
97 state = true;
98 else
99 // otherwise check in standard UNIX config directories
100 {
101 const char* const *p = config_stddirs;
102 while (*p)
103 {
104 // kdDebug( 500 ) << "checkConfig() with " << TQString::fromLatin1( *p ) + f << endl;
105 if ( TQFile::exists( TQString::fromLatin1( *p ) + f ) )
106 {
107 state = true;
108 break;
109 }
110 else
111 p++;
112 }
113 }
114 return state;
115}
116
117bool KdeprintChecker::checkExec(const KURL& url)
118{
119 TQString execname(url.path().mid(1));
120 return !(TDEStandardDirs::findExe(execname).isEmpty());
121}
122
123bool KdeprintChecker::checkService(const KURL& url)
124{
125 TQString serv(url.path().mid(1));
126 KExtendedSocket sock;
127
128 bool ok;
129 int port = serv.toInt(&ok);
130
131 if (ok) sock.setAddress("localhost", port);
132 else sock.setAddress("localhost", serv);
133 return (sock.connect() == 0);
134}

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.4
This website is maintained by Timothy Pearson.