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
00019 using namespace std;
00020
00021 #define WHITESPACE " \t\n"
00022
00031 class PrinterEntry
00032 {
00033 private:
00034 string Name;
00035 bool Default;
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 string ppd;
00047 map<string,string>options;
00048
00055 bool saved;
00056 public:
00060 PrinterEntry()
00061 : Name(), Default(false), Info(), Location(), Uri(), State(), StateMessage(),
00062 Accepting(false), BannerStart(), BannerEnd(), AllowUsers(), DenyUsers(), ppd(), options(),
00063 saved(false)
00064 {
00065 }
00069 ~PrinterEntry()
00070 {
00071 }
00072
00073 void setSaved()
00074 {
00075 saved = true;
00076 }
00077 void clearSaved()
00078 {
00079 saved = false;
00080 }
00081 bool isSaved()
00082 {
00083 return saved;
00084 }
00096 #define CREATE_SET(x,y) void set##x(const y x##_){x = x##_;}
00097 CREATE_SET(Name,string);
00098 CREATE_SET(Default,bool);
00099 CREATE_SET(Info,string);
00100 CREATE_SET(Location,string);
00101 CREATE_SET(Uri,string);
00102 CREATE_SET(State,string);
00103 CREATE_SET(StateMessage,string);
00104 CREATE_SET(Accepting,bool);
00105 CREATE_SET(BannerStart,string);
00106 CREATE_SET(BannerEnd,string);
00107 CREATE_SET(ppd,string);
00108 #undef CREATE_SET
00109
00114 void addAllowUsers(const string u)
00115 {
00116 AllowUsers.insert(u);
00117 }
00118 void addDenyUsers(const string u)
00119 {
00120 DenyUsers.insert(u);
00121 }
00127 void addOption(const string name,const string value)
00128 {
00129 options[name] = value;
00130 }
00135 void delAllowUsers(const string u)
00136 {
00137 AllowUsers.erase(u);
00138 }
00142 void delDenyUsers(const string u)
00143 {
00144 DenyUsers.erase(u);
00145 }
00150 void delOption(const string s)
00151 {
00152 options.erase(s);
00153 }
00158 string getPrinter() const
00159 {
00160 return Name;
00161 }
00166 const char*getPrinter_str() const
00167 {
00168 return Name.c_str();
00169 }
00170
00175 map<string,string>&getOptions()
00176 {
00177 return options;
00178 }
00179
00183 void dump() const;
00184
00189 YCPValue Read() const;
00190
00197 bool changePrinter(const YCPValue&value);
00198
00202 bool newPrinter(const YCPValue&value);
00203 };
00204
00205 class PrintersConf
00206 {
00207 private:
00211 list<PrinterEntry> Printers;
00217 bool parseFile(const char*fn);
00223 bool completeEntries();
00227 void Clear()
00228 {
00229 Printers.clear();
00230 }
00234 bool modifyPrinter(YCPMap printer);
00240 bool readSettings(const char*fn);
00241 bool getPrinters ();
00247 list<PrinterEntry>::iterator getPrinterEntry(const string name);
00248
00254 list<PrinterEntry>::iterator findPrinter(const string name);
00255
00256 public:
00260 PrintersConf()
00261 : Printers()
00262 {
00263 }
00264
00268 ~PrintersConf()
00269 {
00270 }
00274 void dump() const;
00275
00279 YCPValue Read();
00280
00284 YCPBoolean Write(const YCPPath &path, const YCPValue& value, const YCPValue& arg = YCPNull());
00285
00286 };
00287
00288 #endif//_PrintersConf_h_