ufile.hpp

00001 /* ==================================================== ======== ======= *
00002 *
00003 *  ufile.hpp
00004 *  Ubit Project
00005 *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUI
00006 *  (C) 1999-2005 Eric Lecolinet / ENST Paris / http://www.enst.fr/~elc/ubit
00007 *
00008 * ***********************************************************************
00009 * COPYRIGHT NOTICE :
00010 * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
00011 * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00012 * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
00013 * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
00014 * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00015 * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00016 * ***********************************************************************
00017 * ==================================================== [(c)Elc] ======= *
00018 * ==================================================== ======== ======= */
00019 
00020 #ifndef _ufile_hpp_
00021 #define _ufile_hpp_
00022 #include <ubit/ubrick.hpp>
00023 namespace ubit {
00024 
00025 /* ==================================================== ======== ======= */
00028 struct UFileStat {
00029   enum {
00030     UnknownType   = -5,
00031     MiscError     = -4,
00032     NoMemory      = -3,
00033     InvalidData   = -2,
00034     CannotOpen    = -1,
00035     NotOpened     =  0,
00036     Opened        =  1
00037   };
00038 };
00039 
00042 typedef UFileStat UFilestat;
00043 
00044 /* ==================================================== ======== ======= */
00047 struct UFileMode {
00048   static int DIR, FILE, LINK;
00049   
00050   UFileMode(int _mode = 0) : mode(_mode) {}
00051   UFileMode(const char* path);
00052   UFileMode(const UStr& path);
00053 
00054   int  getMode() const {return mode;}
00055   void setMode(int mode);
00056   
00057   void setMode(const char* path);
00058   void setMode(const UStr& path);
00059   // <inits a UFileMode by performing a stat() on this path.
00060 
00061   bool isValid() const;
00062   bool isDir()  const;
00063   bool isFile() const;
00064   bool isLink() const;
00065   bool isExec() const;
00066 
00067 protected:
00068   int mode;  //mode_t mode;
00069 };
00070 
00071 /* ==================================================== ======== ======= */
00074 struct UFileType {
00075   enum {LOCAL, SSH, HTTP, FTP};
00076 
00077   UFileType(int _type = 0) : type(_type) {}
00078   
00079   int  getType() const {return type;}
00080   void setType(int t);
00081 
00082   static int getType(const UStr& path);
00083 
00084 protected:
00085   int type;
00086 };
00087 
00088 /* ==================================================== ======== ======= */
00091 struct UFileInfo : public UFileMode, public UFileType {
00092   UFileInfo();
00093   UFileInfo(const char* name, int mode, int type, UTime time, unsigned long size);
00095   
00096   UFileInfo(const char* path);
00097   UFileInfo(const UStr& path);
00099 
00100   void getInfo(UStr& mode, UStr& time, UStr& size);
00101   
00102   void setInfo(const char* path);
00103   void setInfo(const UStr& path);
00105 
00106   const UStr* getName() const {return pname;}
00107   UStr* name()  {return pname;}
00108   void  setName(UStr* n);
00113   UTime getTime() const {return time;}
00114   void  setTime(UTime t);
00115 
00116   unsigned long getSize() const {return size;}
00117   void setSize(unsigned long s);
00118 
00119   UIma* getSmallIcon() const;
00120   UIma* getLargeIcon() const;
00125 protected:
00126   friend class UDir;
00127   friend class UIconbox;
00128   UTime time;   //time_t mtime;
00129   unsigned long size;
00130   uptr<UStr> pname;
00131 };
00132 
00133 /* ==================================================== ======== ======= */
00136 class UFileCache {
00137 public:
00138   static void createCache();
00139   static void cleanCache();
00140 
00141   static const UStr& getCachePath();
00142   
00143   static UStr* createFullPath(const UStr& path);
00144   //  expands ~, ssh:, http:, ftp:.
00145 
00146   static const UStr* getOrCreateFullPath(const UStr& path);
00147   // same as createFullPath() but fullpath may be shared with path
00148 
00149   static bool getCachePath(const UStr& url, int path_type,
00150                            UStr& server, UStr& path, UStr& cachepath);
00151 protected:
00152   static UStr cache;
00153 };
00154 
00155 }
00156 #endif
00157 /* ==================================================== [TheEnd] ======= */
00158 /* ==================================================== [(c)Elc] ======= */

Generated on Mon Jan 29 00:20:38 2007 for Ubit by  doxygen 1.4.7