00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _PrintersConf_h_
00011 #define _PrintersConf_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 PrinterEntry
00034 {
00035 private:
00036 string Name;
00037 bool Default;
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 string ppd;
00049 map<string,string>options;
00050
00057 bool saved;
00058 public:
00062 PrinterEntry()
00063 : Name(), Default(false), Info(), Location(), Uri(), State(), StateMessage(),
00064 Accepting(false), BannerStart(), BannerEnd(), AllowUsers(), DenyUsers(), ppd(), options(),
00065 saved(false)
00066 {
00067 }
00071 ~PrinterEntry()
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,string);
00100 CREATE_SET(Default,bool);
00101 CREATE_SET(Info,string);
00102 CREATE_SET(Location,string);
00103 CREATE_SET(Uri,string);
00104 CREATE_SET(State,string);
00105 CREATE_SET(StateMessage,string);
00106 CREATE_SET(Accepting,bool);
00107 CREATE_SET(BannerStart,string);
00108 CREATE_SET(BannerEnd,string);
00109 CREATE_SET(ppd,string);
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 }
00129 void addOption(const string name,const string value)
00130 {
00131 options[name] = value;
00132 }
00137 void delAllowUsers(const string u)
00138 {
00139 AllowUsers.erase(u);
00140 }
00144 void delDenyUsers(const string u)
00145 {
00146 DenyUsers.erase(u);
00147 }
00152 void delOption(const string s)
00153 {
00154 options.erase(s);
00155 }
00160 string getPrinter() const
00161 {
00162 return Name;
00163 }
00168 const char*getPrinter_str() const
00169 {
00170 return Name.c_str();
00171 }
00172
00177 map<string,string>&getOptions()
00178 {
00179 return options;
00180 }
00181
00185 void dump() const;
00186
00191 YCPValue Read() const;
00192
00199 bool changePrinter(const YCPValue&value);
00200
00204 bool newPrinter(const YCPValue&value);
00205 };
00206
00207 class PrintersConf
00208 {
00209 private:
00213 list<PrinterEntry> Printers;
00219 bool parseFile(const char*fn);
00225 bool completeEntries();
00229 void Clear()
00230 {
00231 Printers.clear();
00232 }
00236 bool modifyPrinter(YCPMap printer);
00242 bool readSettings(const char*fn);
00243 bool getPrinters ();
00249 list<PrinterEntry>::iterator getPrinterEntry(const string name);
00250
00256 list<PrinterEntry>::iterator findPrinter(const string name);
00257
00258 public:
00262 PrintersConf()
00263 : Printers()
00264 {
00265 }
00266
00270 ~PrintersConf()
00271 {
00272 }
00276 void dump() const;
00277
00281 YCPValue Read();
00282
00286 YCPBoolean Write(const YCPPath &path, const YCPValue& value, const YCPValue& arg = YCPNull());
00287
00288 };
00289
00290 #endif//_PrintersConf_h_