PPDdb.h

Go to the documentation of this file.
00001 /*
00002  * YaST2: Core system
00003  *
00004  * Description:
00005  *   YaST2 SCR: PPD implementation
00006  *
00007  * Authors:
00008  *   Michal Svec <msvec@suse.cz>
00009  *
00010  * $Id: PPDdb.h 19908 2004-10-21 11:27:44Z jsrain $
00011  */
00012 
00013 #ifndef _PPDdb_h
00014 #define _PPDdb_h
00015 
00016 #include <sys/types.h>
00017 
00018 #include <string>
00019 #include <list>
00020 #include <map>
00021 #include <vector>
00022 #include <set>
00023 
00024 #include <ycp/YCPSymbol.h>
00025 #include <ycp/YCPList.h>
00026 #include <ycp/YCPMap.h>
00027 
00028 using namespace std;
00029 
00030 #define MAX        2048
00031 #define WHITESPACE " \t\n"
00032 
00033 #define PPD_DIR "/usr/share/cups/model"
00034 #define PPD_DB  "/var/lib/YaST2/ppd_db.ycp"
00035 
00036 class PPD {
00037     public:
00038 
00039         class PPDInfo {
00040             public:
00041                 string filename;
00042                 string vendor;
00043                 string printer;
00044                 set<string> products;
00045                 string nick;
00046                 string shortnick;
00047                 string lang;
00048                 string pnp_vendor;
00049                 string pnp_printer;
00050                 string checksum;
00051                 off_t size;
00052                 string filter;
00053                 string vendor_db;
00054                 string printer_db;
00055         };
00056 
00057         typedef string VendorKey;
00058         typedef string ModelKey;
00059         typedef string DriverFile;
00060 
00061         /* typedef string Info; */
00062         class DriverInfo {
00063             public:
00064                 string nickname;
00065                 string pnp_vendor;
00066                 string pnp_printer;
00067                 string checksum;
00068                 off_t size;
00069                 string filter;
00070                 string language;
00071             DriverInfo () {
00072                 nickname = "";
00073                 pnp_vendor = "";
00074                 pnp_printer = "";
00075                 checksum = "";
00076                 size = 0;
00077                 filter = "";
00078                 language = "";
00079             }
00080         };
00081 
00082         typedef map<DriverFile, DriverInfo> Drivers;
00083 
00084         class ModelInfo {
00085             public:
00086                 string label;
00087                 string support;
00088                 string mcomment;
00089                 Drivers drivers;
00090                 bool fuzzy_label;
00091             ModelInfo () {
00092                 support = "";
00093                 label = "";
00094                 mcomment = "";
00095                 fuzzy_label = false;
00096             }
00097         };
00098 
00099         typedef map<ModelKey, ModelInfo> Models;
00100 
00101         class VendorInfo {
00102             public:
00103                 string label;
00104                 string vcomment;
00105                 Models models;
00106             VendorInfo () {
00107                 label = "";
00108                 vcomment = "";
00109                 models = Models ();
00110             }
00111         };
00112 
00113         typedef map<VendorKey, VendorInfo> Vendors;
00114 
00115         class PpdFileInfo {
00116             public:
00117                 bool file_newer;
00118                 bool dir_newer;
00119                 bool update;
00120             PpdFileInfo () {
00121                 file_newer = "";
00122                 dir_newer = "";
00123                 update = true;
00124             }
00125         };
00126 
00127         typedef map<string, PpdFileInfo> PpdFiles;
00128 
00129         typedef map<VendorKey, set<string> > ModelLabels;
00130         typedef set<string> VendorLabels;
00131 
00132         PPD(const char *ppddir = PPD_DIR, const char *ppddb = PPD_DB);
00133         ~PPD();
00134 
00135         bool createdb();
00136         static void* startCreatedbThread (void* instance);
00137         void* createdbThread (const char* filename);
00138         int  creationStatus ();
00139         bool changed(int *count);
00140         string getVendorId (string vendor);
00141         string getModelId (string vendor, string model);
00142         string removeVendorFromModel (string vendor, string model);
00143         bool fileinfo(const char *file, PPDInfo *info);
00144         bool setCheckMethod (YCPSymbol method);
00145         YCPList sortItems (const YCPMap& items);
00146 
00147     private:
00148         friend class PPDfile;
00149 
00150         Vendors db;
00151         PpdFiles ppdfiles;
00152         ModelLabels modellabels;
00153         VendorLabels vendorlabels;
00154 
00155         string datadir;
00156         string var_datadir;
00157         char ppd_dir[MAX];
00158         char ppd_db[MAX];
00159         time_t mtime;
00160 
00161         typedef map<string, string> VendorsMap;
00162         VendorsMap vendors_map;
00163         typedef map<string, vector<pair <string, string> > > ModelsMap;
00164         ModelsMap models_map;
00165 
00166         bool mtimes(const char *dirname, time_t mtime, int *count);
00167         int  countFiles (const char *dirname);
00168         bool process_dir(const char *dirname);
00169         bool process_file(const char *filename, PPDInfo *newinfo = NULL);
00170         void preprocess(PPDInfo info, PPDInfo *newinfo);
00171         void addAdditionalInfo ();
00172         void debugdb() const;
00173         // creation status variables
00174         volatile int creation_status;
00175         volatile int total_files;
00176         volatile int done_files;
00177         bool fast_check;
00178 
00179         bool loadPrebuiltDatabase ();
00180         bool createFileList(const char *dirname, time_t mtime);
00181         bool cleanupLists ();
00182         bool processNewFiles ();
00183         bool cleanupEmptyEntries ();
00184         string fileChecksum (const string &filename);
00185         off_t fileSize (const string &filename);
00186         string updateLabel (const string& label);
00187 
00188     protected:
00189         string strupper(const string s);
00190         string killchars(const string s, const string chr);
00191         string killspaces(const string s);
00192         string killbraces(const string s);
00193         string addbrace(const string s);
00194         string first(const string s, const string sep = " -/");
00195         string clean(const char *s);
00196         string filternotchars(const string s, const string chr);
00197         string regexpsub (const string input, const string pattern,
00198                 const string result);
00199         bool validateModel (const string vendor, const string printer);
00200 };
00201 
00202 #endif /* _PPDdb_h */
00203 

Generated on Fri May 18 11:43:15 2007 for yast2-printer by  doxygen 1.4.6