00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "cupsdcomment.h"
00021
00022
#include <qfile.h>
00023
#include <qregexp.h>
00024
#include <kstandarddirs.h>
00025
00026
QString Comment::comment()
00027 {
00028
QString str = comment_;
00029 str.
replace(
QRegExp(
"<[^>]*>"),
"");
00030 str += (
"#\n" + example_);
00031
return str;
00032 }
00033
00034
QString Comment::toolTip()
00035 {
00036
QString str = comment_;
00037 str.
replace(
QRegExp(
"^#[\\s]*"),
"").replace(
QRegExp(
"\n#"),
"\n");
00038
return str;
00039 }
00040
00041
bool Comment::load(
QFile *f)
00042 {
00043 comment_ =
"";
00044 example_ =
"";
00045
QString line, *current = &comment_;
00046
while (!f->
atEnd())
00047 {
00048 f->
readLine(line, 1024);
00049
if (line.
left(2) ==
"$$")
00050 {
00051 current = &example_;
00052 }
00053
else if (line.
left(2) ==
"@@")
00054 {
00055
return true;
00056 }
00057
else if (line.
stripWhiteSpace().isEmpty())
00058 {
00059 ;
00060 }
00061
else
00062 {
00063
if (line[0] !=
'#')
break;
00064
else
00065 {
00066 current->
append(line);
00067 }
00068 }
00069 }
00070
return false;
00071 }
00072
00073
00074
00075
QString CupsdComment::operator[] (
unsigned int index)
00076 {
00077
return comment(index);
00078 }
00079
00080
QString CupsdComment::comment(uint index)
00081 {
00082
if (comments_.count() != 0 || loadComments())
00083
return comments_.at(index)->comment();
00084
return QString::null;
00085 }
00086
00087
QString CupsdComment::toolTip(uint index)
00088 {
00089
if (comments_.count() != 0 || loadComments())
00090
return comments_.at(index)->toolTip();
00091
return QString::null;
00092 }
00093
00094
bool CupsdComment::loadComments()
00095 {
00096 comments_.setAutoDelete(
true);
00097 comments_.clear();
00098
QFile f(locate(
"data",
"kdeprint/cupsd.conf.template"));
00099
int index(0);
00100
if (f.exists() && f.open(IO_ReadOnly))
00101 {
00102 Comment *comm;
00103
while (index <= LAST_COMM)
00104 {
00105 comm =
new Comment();
00106
if (!comm->load(&f))
00107
break;
00108
else
00109 {
00110 index++;
00111 comments_.append(comm);
00112 }
00113 }
00114 }
00115
if (index != LAST_COMM+1)
00116 {
00117 comments_.clear();
00118 qWarning(
"Problem while loading comment file %s",f.name().latin1());
00119
return false;
00120 }
00121
return true;
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151