Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

ClassesConf.h

Go to the documentation of this file.
00001 /* ClassesConf.h -*- c++ -*-
00002  *
00003  * classes for reading classes.conf configuration file
00004  * and writing classes definitions via cups library calls
00005  *
00006  * Author: Petr Blahos <pblahos@suse.cz>
00007  *
00008  * $Id: ClassesConf.h,v 1.3 2004/01/16 17:55:03 jsrain Exp $
00009  */
00010 #ifndef _ClassesConf_h_
00011 #define _ClassesConf_h_
00012 
00013 #include <string>
00014 #include <map>
00015 #include <list>
00016 #include <set>
00017 #include <Y2.h>
00018 
00019 using namespace std;
00020 
00021 #define WHITESPACE      " \t\n"
00022 
00031 class ClassEntry
00032 {
00033 private:
00034   string Name;
00035   bool   Default;  //FIXME: remove this
00036   string Info;
00037   string Location;
00038   string Uri;
00039   string State;
00040   string StateMessage;
00041   bool   Accepting;
00042   string BannerStart;
00043   string BannerEnd;
00044   set<string> AllowUsers;
00045   set<string> DenyUsers;
00046   set<string> Printers;
00047   string ppd;
00048   map<string,string>options;
00049 
00056   bool saved;
00057 public:
00061   ClassEntry() 
00062     : Name(), Default(false), Info(), Location(), Uri(), State(), StateMessage(),
00063       Accepting(false), BannerStart(), BannerEnd(), AllowUsers(), DenyUsers(), Printers(), ppd(), options(),
00064       saved(false)
00065       {
00066       }
00067   
00071   ~ClassEntry()
00072       {
00073       }
00074 
00075   void setSaved()
00076       {
00077         saved = true;
00078       }
00079   void clearSaved()
00080       {
00081         saved = false;
00082       }
00083   bool isSaved()
00084       {
00085         return saved;
00086       }
00098 #define CREATE_SET(x,y) void set##x(const y x##_){x = x##_;}
00099   CREATE_SET(Name,char*);
00100   CREATE_SET(Default,bool);
00101   CREATE_SET(Info,char*);
00102   CREATE_SET(Location,char*);
00103   CREATE_SET(Uri,char*);
00104   CREATE_SET(State,char*);
00105   CREATE_SET(StateMessage,char*);
00106   CREATE_SET(Accepting,bool);
00107   CREATE_SET(BannerStart,char*);
00108   CREATE_SET(BannerEnd,char*);
00109   CREATE_SET(ppd,char*);  
00110 #undef  CREATE_SET
00111 
00116   void addAllowUsers(const string u)
00117       {
00118         AllowUsers.insert(u);
00119       }
00120   void addDenyUsers(const string u)
00121       {
00122         DenyUsers.insert(u);
00123       }
00124   void addPrinters(const string p)
00125       {
00126         Printers.insert(p);
00127       }
00133   void addOption(const string name,const string value)
00134       {
00135         options[name] = value;
00136       }
00141   void delAllowUsers(const string u)
00142       {
00143         AllowUsers.erase(u);
00144       }
00148   void delDenyUsers(const string u)
00149       {
00150         DenyUsers.erase(u);
00151       }
00156   void delOption(const string s)
00157       {
00158         options.erase(s);
00159       }
00164   string getClass() const
00165       {
00166         return Name;
00167       }
00172   const char*getClass_str() const
00173       {
00174         return Name.c_str();
00175       }
00176   
00181   map<string,string>&getOptions()
00182       {
00183         return options;
00184       }
00185 
00186     int getPrintersSize ()
00187             {
00188                 return Printers.size();
00189             }
00190     
00194   void dump() const;
00195 
00200   YCPValue Read() const;
00201 
00208   bool changeClass(const YCPValue&value);
00209 
00213   bool newClass(const YCPValue&value);
00214 };
00215 
00216 class ClassesConf
00217 {
00218 private:
00222   list<ClassEntry> Classes;
00228   bool parseFile(const char*fn);
00229     bool getClasses ();
00235   bool completeEntries();
00239   void Clear()
00240       {
00241         Classes.clear();
00242       }
00246   bool modifyClass(YCPMap clas);
00252   bool readSettings(const char*fn);
00258   list<ClassEntry>::iterator getClassEntry(const string name);
00259   
00265   list<ClassEntry>::iterator findClass(const string name);
00266 
00267 public:
00271   ClassesConf()
00272     : Classes()
00273       {
00274       }
00275 
00279   ~ClassesConf()
00280       {
00281       }
00285   void dump() const;
00286   
00290   YCPValue Read();
00291 
00295   YCPBoolean Write(const YCPPath &path, const YCPValue& value, const YCPValue& arg = YCPNull());
00296 
00297 };
00298 
00299 #endif//_ClassesConf_h_

Generated on Thu Nov 17 21:25:17 2005 for yast2-printer by doxygen 1.3.6