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

tdeprint

  • tdeprint
  • cups
  • cupsdconf2
cupsdcomment.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#include "cupsdcomment.h"
21
22#include <tqfile.h>
23#include <tqregexp.h>
24#include <tdelocale.h>
25#include <tdestandarddirs.h>
26
27TQString Comment::comment()
28{
29 TQString str = comment_;
30 str.replace(TQRegExp("<[^>]*>"), "");
31 str += ("#\n" + example_);
32 return str;
33}
34
35TQString Comment::toolTip()
36{
37 TQString str = comment_;
38 str.replace(TQRegExp("^#[\\s]*"), "").replace(TQRegExp("\n#[\\s]*"), "\n");
39 return i18n("Do not translate the keyword between brackets (e.g. ServerName, ServerAdmin, etc.)", str.utf8());
40}
41
42TQString Comment::key()
43{
44 return key_;
45}
46
47bool Comment::load(TQFile *f)
48{
49 comment_ = "";
50 example_ = "";
51 key_ = "";
52 TQString line, *current = &comment_;
53 while (!f->atEnd())
54 {
55 f->readLine(line, 1024);
56 if (line.left(2) == "$$")
57 {
58 current = &example_;
59 }
60 else if (line.left(2) == "%%")
61 {
62 key_ = line.mid(2).stripWhiteSpace();
63 }
64 else if (line.left(2) == "@@")
65 {
66 return true;
67 }
68 else if (line.stripWhiteSpace().isEmpty())
69 {
70 ; // do nothing
71 }
72 else
73 {
74 if (line[0] != '#') break;
75 else
76 {
77 current->append(line);
78 }
79 }
80 }
81 return false;
82}
83
84//------------------------------------------------------------------------------------------------------------
85
86TQString CupsdComment::operator[] (const TQString& key)
87{
88 return comment(key);
89}
90
91TQString CupsdComment::comment(const TQString& key)
92{
93 if (comments_.count() != 0 || loadComments())
94 {
95 Comment *comm = comments_.find(key);
96 if (comm)
97 return comm->comment();
98 }
99 return TQString::null;
100}
101
102TQString CupsdComment::toolTip(const TQString& key)
103{
104 if (comments_.count() != 0 || loadComments())
105 {
106 Comment *comm = comments_.find(key);
107 if (comm)
108 return comm->toolTip();
109 }
110 return TQString::null;
111}
112
113bool CupsdComment::loadComments()
114{
115 comments_.setAutoDelete(true);
116 comments_.clear();
117 TQFile f(locate("data", "tdeprint/cupsd.conf.template"));
118 if (f.exists() && f.open(IO_ReadOnly))
119 {
120 Comment *comm;
121 while (!f.atEnd())
122 {
123 comm = new Comment();
124 if (!comm->load(&f))
125 break;
126 else
127 {
128 if (comm->key().isEmpty())
129 delete comm;
130 else
131 comments_.insert(comm->key(), comm);
132 }
133 }
134 }
135 return true;
136}

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.