PrintersConf.h

Go to the documentation of this file.
00001 /* PrintersConf.h -*- c++ -*-
00002  *
00003  * classes for reading printers.conf configuration file
00004  * and writing printers definitions via cups library calls
00005  *
00006  * Author: Petr Blahos <pblahos@suse.cz>
00007  *
00008  * $Id: PrintersConf.h 34512 2006-11-21 08:32:44Z mzugec $
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;  //FIXME: remove this
00038   string Info;
00039   string Location;
00040   string Uri;
00041   string State;
00042   string StateMessage;
00043   bool Shared;
00044   bool   Accepting;
00045   string BannerStart;
00046   string BannerEnd;
00047   set<string> AllowUsers;
00048   set<string> DenyUsers;
00049   string ppd;
00050   map<string,string>options;
00051 
00058   bool saved;
00059 public:
00063   PrinterEntry() 
00064     : Name(), Default(false), Info(), Location(), Uri(), State(), StateMessage(), Shared(true),
00065       Accepting(false), BannerStart(), BannerEnd(), AllowUsers(), DenyUsers(), ppd(), options(),
00066       saved(false)
00067       {
00068       }
00072   ~PrinterEntry()
00073       {
00074       }
00075 
00076   void setSaved()
00077       {
00078         saved = true;
00079       }
00080   void clearSaved()
00081       {
00082         saved = false;
00083       }
00084   bool isSaved()
00085       {
00086         return saved;
00087       }
00099 #define CREATE_SET(x,y) void set##x(const y x##_){x = x##_;}
00100   CREATE_SET(Name,string);
00101   CREATE_SET(Default,bool);
00102   CREATE_SET(Shared,bool);
00103   CREATE_SET(Info,string);
00104   CREATE_SET(Location,string);
00105   CREATE_SET(Uri,string);
00106   CREATE_SET(State,string);
00107   CREATE_SET(StateMessage,string);
00108   CREATE_SET(Accepting,bool);
00109   CREATE_SET(BannerStart,string);
00110   CREATE_SET(BannerEnd,string);
00111   CREATE_SET(ppd,string);  
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       }
00131   void addOption(const string name,const string value)
00132       {
00133         options[name] = value;
00134       }
00139   void delAllowUsers(const string u)
00140       {
00141         AllowUsers.erase(u);
00142       }
00146   void delDenyUsers(const string u)
00147       {
00148         DenyUsers.erase(u);
00149       }
00154   void delOption(const string s)
00155       {
00156         options.erase(s);
00157       }
00162   string getPrinter() const
00163       {
00164         return Name;
00165       }
00170   const char*getPrinter_str() const
00171       {
00172         return Name.c_str();
00173       }
00174   
00179   map<string,string>&getOptions()
00180       {
00181         return options;
00182       }
00183   
00187   void dump() const;
00188 
00193   YCPValue Read() const;
00194 
00201   bool changePrinter(const YCPValue&value);
00202 
00206   bool newPrinter(const YCPValue&value);
00207 };
00208 
00209 class PrintersConf
00210 {
00211 private:
00215   list<PrinterEntry> Printers;
00221   bool parseFile(const char*fn);
00227   bool completeEntries();
00231   void Clear()
00232       {
00233         Printers.clear();
00234       }
00238   bool modifyPrinter(YCPMap printer);
00244   bool readSettings();
00245   bool getPrinters ();
00251   list<PrinterEntry>::iterator getPrinterEntry(const string name);
00252   
00258   list<PrinterEntry>::iterator findPrinter(const string name);
00259 
00260 public:
00264   PrintersConf()
00265     : Printers()
00266       {
00267       }
00268 
00272   ~PrintersConf()
00273       {
00274       }
00278   void dump() const;
00279   
00283   YCPValue Read();
00284 
00288   YCPBoolean Write(const YCPPath &path, const YCPValue& value, const YCPValue& arg = YCPNull());
00289 
00290 };
00291 
00292 #endif//_PrintersConf_h_

Generated on Tue Nov 28 18:12:01 2006 for yast2-printer by  doxygen 1.5.0