20 #include "cupsdcomment.h"
24 #include <tdelocale.h>
25 #include <kstandarddirs.h>
27 TQString Comment::comment()
29 TQString str = comment_;
30 str.replace(TQRegExp(
"<[^>]*>"),
"");
31 str += (
"#\n" + example_);
35 TQString Comment::toolTip()
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());
42 TQString Comment::key()
47 bool Comment::load(TQFile *f)
52 TQString line, *current = &comment_;
55 f->readLine(line, 1024);
56 if (line.left(2) ==
"$$")
60 else if (line.left(2) ==
"%%")
62 key_ = line.mid(2).stripWhiteSpace();
64 else if (line.left(2) ==
"@@")
68 else if (line.stripWhiteSpace().isEmpty())
74 if (line[0] !=
'#')
break;
77 current->append(line);
86 TQString CupsdComment::operator[] (
const TQString& key)
91 TQString CupsdComment::comment(
const TQString& key)
93 if (comments_.count() != 0 || loadComments())
95 Comment *comm = comments_.find(key);
97 return comm->comment();
99 return TQString::null;
102 TQString CupsdComment::toolTip(
const TQString& key)
104 if (comments_.count() != 0 || loadComments())
106 Comment *comm = comments_.find(key);
108 return comm->toolTip();
110 return TQString::null;
113 bool CupsdComment::loadComments()
115 comments_.setAutoDelete(
true);
117 TQFile f(locate(
"data",
"tdeprint/cupsd.conf.template"));
118 if (f.exists() && f.open(IO_ReadOnly))
123 comm =
new Comment();
128 if (comm->key().isEmpty())
131 comments_.insert(comm->key(), comm);