kdeprint Library API Documentation

cupsdcomment.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  *  Boston, MA 02111-1307, USA.
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                         ; // do nothing
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 /*void CupsdComment::loadComments()
00126 {
00127     QFile   f(locate("data", "kups/cupsd.conf.template"));
00128     if (f.exists() && f.open(IO_ReadOnly))
00129     {
00130         QTextStream t(&f);
00131         QString     comm, line;
00132         while (!t.atEnd())
00133         {
00134             line = t.readLine();
00135             if (line.isEmpty() && !comm.isEmpty())
00136             {
00137                 comments_.append(comm);
00138                 comm.truncate(0);
00139             }
00140             else
00141             {
00142                 comm += (line + "\n");
00143             }
00144         }
00145         if (!comm.isEmpty())
00146             comments_.append(comm);
00147     }
00148     if (comments_.count() < (LOCATIONS_COMM+1))
00149         debug("warning: missing comments in \"%s\"",f.name().data());
00150 }
00151 */
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Mar 3 19:24:20 2005 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003