Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

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

Generated on Thu Nov 17 21:26:41 2005 for yast2-printer by doxygen 1.3.6