ubit
ufile.hpp
1 /************************************************************************
2  *
3  * ufile.hpp
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef _ufile_hpp_
18 #define _ufile_hpp_ 1
19 #include <vector>
20 #include <ubit/unode.hpp>
21 namespace ubit {
22 
23  /* ==================================================== ======== ======= */
26  struct UFileStat {
27  enum {
28  UnknownType = -5,
29  MiscError = -4,
30  NoMemory = -3,
31  InvalidData = -2,
32  CannotOpen = -1,
33  NotOpened = 0,
34  Opened = 1
35  };
36  };
37 
40  typedef UFileStat UFilestat;
41 
42  /* ==================================================== ======== ======= */
45  class UFileMode {
46  public:
47  UFileMode(const UStr& pathname);
48 
49  bool isValid() const;
50  bool isDir() const;
51  bool isFile() const;
52  bool isLink() const;
53  bool isExec() const;
54 
55  static const int DIR, FILE, LINK;
56  int getMode() const {return mode;}
57 
58  protected:
59  UFileMode() {}
60  int mode; //mode_t mode;
61  };
62 
63  /* ==================================================== ======== ======= */
66  class UFileInfo : public UFileMode {
67  public:
68  UFileInfo(const UStr& path);
70 
71  UFileInfo(const char* fullpath, const char* fname);
73 
74  void setPath(const UStr& path);
76 
77  const UStr* getFileName() const {return pname;}
79 
80  unsigned long getSize() const {return size;}
81  //< returns the size of the file.
82 
83  unsigned long getModTime() const {return modtime;}
84  //< returns the time when file data was last modified.
85 
86  UIma& getIconImage() const;
91  UIma& getMiniIconImage() const;
96  void getInfoString(UStr& str) const;
98 
99  enum PrefixType {LOCAL, SSH, HTTP, FTP};
100  static int parsePrefix(const UStr& path);
102 
103  protected:
104  friend class UFileDir;
105  friend class UFilebox;
106  unsigned long size;
107  unsigned long modtime;
108  uptr<UStr> pname;
109  void stat(const char* path);
110  };
111 
114  typedef std::vector<UFileInfo*> UFileInfos;
115 
116  /* ==================================================== ======== ======= */
119  class UFileDir {
120  public:
121  UFileDir();
122  UFileDir(const UStr& path);
123  virtual ~UFileDir();
124 
125  void read(const UStr& path);
130  void read(const UStr& path, const UStr& prefix, const UStr& filter, bool with_dot_files);
139  void readRemote(const UStr& path, const UStr& prefix, const UStr& filter, bool with_dot_files);
144  const UStr& getPath() const;
150  const UFileInfos& getFileInfos() const {return file_infos;}
152 
153  static void expandDirPath(UStr& dirpath);
155 
156  // - - - Impl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
157  private:
158  friend class UIconbox;
159  UFileInfo dir_info;
160  UFileInfos file_infos;
161  std::vector<UStr*> filters;
162  static bool compareEntries(const UFileInfo*, const UFileInfo*);
163  static void parseFilter(std::vector<UStr*>& filters, const UStr& filter);
164  };
165 
166  /* ==================================================== ======== ======= */
169  class UFileCache {
170  public:
171  static void createCache();
172  static void cleanCache();
173 
174  static const UStr& getCachePath();
175 
176  static UStr* createFullPath(const UStr& path);
177  // expands ~, ssh:, http:, ftp:.
178 
179  static const UStr* getOrCreateFullPath(const UStr& path);
180  // same as createFullPath() but fullpath may be shared with path
181 
182  static bool getCachePath(const UStr& url, int path_type,
183  UStr& server, UStr& path, UStr& cachepath);
184  protected:
185  static UStr cache;
186  };
187 
188 }
189 #endif
190 /* ==================================================== [TheEnd] ======= */
191 /* ==================================================== [(c)Elc] ======= */
file cache for SSH.
Definition: ufile.hpp:169
file info.
Definition: ufile.hpp:66
Image.
Definition: uima.hpp:50
const UStr * getFileName() const
returns the file name (without the path).
Definition: ufile.hpp:77
Icon box.
Definition: uicon.hpp:52
const UFileInfos & getFileInfos() const
returns the (filtered) file entries of the directory.
Definition: ufile.hpp:150
File Directory.
Definition: ufile.hpp:119
File status returned by functions that open files.
Definition: ufile.hpp:26
file mode.
Definition: ufile.hpp:45
Definition: uhardfont.hpp:31
static const int LINK
modes
Definition: ufile.hpp:55
Definition: ufilebox.hpp:49
Ubit String.
Definition: ustr.hpp:72