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 19894 2004-10-19 15:58:12Z jsrain $
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 #include <ycp/YCPMap.h>
00019 #include <ycp/YCPBoolean.h>
00020 
00021 using namespace std;
00022 
00023 #define WHITESPACE      " \t\n"
00024 
00033 class ClassEntry
00034 {
00035 private:
00036   string Name;
00037   bool   Default;  //FIXME: remove this
00038   string Info;
00039   string Location;
00040   string Uri;
00041   string State;
00042   string StateMessage;
00043   bool   Accepting;
00044   string BannerStart;
00045   string BannerEnd;
00046   set<string> AllowUsers;
00047   set<string> DenyUsers;
00048   set<string> Printers;
00049   string ppd;
00050   map<string,string>options;
00051 
00058   bool saved;
00059 public:
00063   ClassEntry() 
00064     : Name(), Default(false), Info(), Location(), Uri(), State(), StateMessage(),
00065       Accepting(false), BannerStart(), BannerEnd(), AllowUsers(), DenyUsers(), Printers(), ppd(), options(),
00066       saved(false)
00067       {
00068       }
00069   
00073   ~ClassEntry()
00074       {
00075       }
00076 
00077   void setSaved()
00078       {
00079         saved = true;
00080       }
00081   void clearSaved()
00082       {
00083         saved = false;
00084       }
00085   bool isSaved()
00086       {
00087         return saved;
00088       }
00100 #define CREATE_SET(x,y) void set##x(const y x##_){x = x##_;}
00101   CREATE_SET(Name,char*);
00102   CREATE_SET(Default,bool);
00103   CREATE_SET(Info,char*);
00104   CREATE_SET(Location,char*);
00105   CREATE_SET(Uri,char*);
00106   CREATE_SET(State,char*);
00107   CREATE_SET(StateMessage,char*);
00108   CREATE_SET(Accepting,bool);
00109   CREATE_SET(BannerStart,char*);
00110   CREATE_SET(BannerEnd,char*);
00111   CREATE_SET(ppd,char*);  
00112 #undef  CREATE_SET
00113 
00118   void addAllowUsers(const string u)
00119       {
00120         AllowUsers.insert(u);
00121       }
00122   void addDenyUsers(const string u)
00123       {
00124         DenyUsers.insert(u);
00125       }
00126   void addPrinters(const string p)
00127       {
00128         Printers.insert(p);
00129       }
00135   void addOption(const string name,const string value)
00136       {
00137         options[name] = value;
00138       }
00143   void delAllowUsers(const string u)
00144       {
00145         AllowUsers.erase(u);
00146       }
00150   void delDenyUsers(const string u)
00151       {
00152         DenyUsers.erase(u);
00153       }
00158   void delOption(const string s)
00159       {
00160         options.erase(s);
00161       }
00166   string getClass() const
00167       {
00168         return Name;
00169       }
00174   const char*getClass_str() const
00175       {
00176         return Name.c_str();
00177       }
00178   
00183   map<string,string>&getOptions()
00184       {
00185         return options;
00186       }
00187 
00188     int getPrintersSize ()
00189             {
00190                 return Printers.size();
00191             }
00192     
00196   void dump() const;
00197 
00202   YCPValue Read() const;
00203 
00210   bool changeClass(const YCPValue&value);
00211 
00215   bool newClass(const YCPValue&value);
00216 };
00217 
00218 class ClassesConf
00219 {
00220 private:
00224   list<ClassEntry> Classes;
00230   bool parseFile(const char*fn);
00231     bool getClasses ();
00237   bool completeEntries();
00241   void Clear()
00242       {
00243         Classes.clear();
00244       }
00248   bool modifyClass(YCPMap clas);
00254   bool readSettings(const char*fn);
00260   list<ClassEntry>::iterator getClassEntry(const string name);
00261   
00267   list<ClassEntry>::iterator findClass(const string name);
00268 
00269 public:
00273   ClassesConf()
00274     : Classes()
00275       {
00276       }
00277 
00281   ~ClassesConf()
00282       {
00283       }
00287   void dump() const;
00288   
00292   YCPValue Read();
00293 
00297   YCPBoolean Write(const YCPPath &path, const YCPValue& value, const YCPValue& arg = YCPNull());
00298 
00299 };
00300 
00301 #endif//_ClassesConf_h_

Generated on Thu Jul 6 00:28:52 2006 for yast2-printer by  doxygen 1.4.6