00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef NCFileSelection_h
00020 #define NCFileSelection_h
00021
00022 #include <iosfwd>
00023
00024 #include "NCPadWidget.h"
00025 #include "NCTablePad.h"
00026 #include "NCTable.h"
00027
00028 #include <map>
00029 #include <string>
00030
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 #include <unistd.h>
00034 #include <dirent.h>
00035 #include <sys/errno.h>
00036
00037
00038 struct NCFileInfo
00039 {
00043 NCFileInfo( string fileName,
00044 struct stat * statInfo,
00045 bool link = false );
00046
00047 NCFileInfo ();
00048
00049 ~NCFileInfo() {};
00050
00051
00052
00053 string _name;
00054 string _realName;
00055 string _tag;
00056 string _perm;
00057 string _user;
00058 string _group;
00059 dev_t _device;
00060 mode_t _mode;
00061 nlink_t _links;
00062 off_t _size;
00063 time_t _mtime;
00064
00065 bool isDir() { return ( (S_ISDIR(_mode)) ? true : false ); }
00066 bool isLink() { return ( (S_ISLNK(_mode)) ? true : false ); }
00067 bool isFile() { return ( (S_ISREG(_mode)) ? true : false ); }
00068 };
00069
00070
00076 class NCFileSelectionTag : public NCTableCol {
00077
00078 private:
00079
00080 NCFileInfo fileInfo;
00081
00082 public:
00083
00084 NCFileSelectionTag( const NCFileInfo & info);
00085
00086 virtual ~NCFileSelectionTag() {}
00087
00088 virtual void DrawAt( NCursesWindow & w, const wrect at,
00089 NCTableStyle & tableStyle,
00090 NCTableLine::STATE linestate,
00091 unsigned colidx ) const;
00092
00093 NCFileInfo getFileInfo() const { return fileInfo; }
00094 };
00095
00100 class NCFileSelection : public NCTable {
00101
00102 public:
00103 enum NCFileSelectionType {
00104 T_Overview,
00105 T_Detailed,
00106 T_Unknown
00107 };
00108
00109 private:
00110
00111 NCFileSelection & operator=( const NCFileSelection & );
00112 NCFileSelection ( const NCFileSelection & );
00113
00114
00115 NCFileSelectionTag * getTag ( const int & index );
00116
00117
00118 protected:
00119
00120 string startDir;
00121 string currentDir;
00122 NCFileSelectionType tableType;
00123
00124 void setCurrentDir( );
00125 string getCurrentLine( );
00126
00127 NCursesEvent handleKeyEvents( wint_t key );
00128
00129 public:
00130
00134 NCFileSelection( NCWidget * parent,
00135 const YWidgetOpt & opt,
00136 NCFileSelectionType type,
00137 const YCPString & iniDir );
00138
00139 virtual ~NCFileSelection();
00140
00146 NCFileInfo getFileInfo( int index );
00147
00152 void setTableType( NCFileSelectionType type ) { tableType = type; };
00153
00161 virtual void addLine( const vector<string> & elements,
00162 const NCFileInfo & fileInfo );
00163
00167 unsigned int getNumLines( ) { return pad->Lines(); }
00168
00173 void drawList( ) { return DrawPad(); }
00174
00178 virtual void itemsCleared();
00179
00184 virtual void fillHeader( ) = 0;
00185
00191 virtual bool createListEntry ( const NCFileInfo & fileInfo ) = 0;
00192
00197 string getCurrentDir() { return currentDir; }
00198
00203 virtual bool fillList ( ) = 0;
00204
00208 void setStartDir( const YCPString & start ) {
00209 currentDir = start->value();
00210 startDir = start->value();
00211 }
00212
00213 };
00214
00215 class NCFileTable : public NCFileSelection {
00216
00217 private:
00218
00219 list<string> pattern;
00220 string currentFile;
00221
00222 public:
00223
00227 NCFileTable( NCWidget * parent,
00228 const YWidgetOpt & opt,
00229 NCFileSelectionType type,
00230 const YCPString & filter,
00231 const YCPString & iniDir );
00232
00233 virtual ~NCFileTable(){}
00234
00235 void setCurrentFile( const YCPString & file ) {
00236 currentFile = file->value();
00237 }
00238
00239 bool filterMatch( const string & fileName );
00240
00241 string getCurrentFile() { return currentFile; }
00242
00243 virtual void fillHeader();
00244
00245 virtual bool createListEntry( const NCFileInfo & fileInfo );
00246
00251 virtual bool fillList ( );
00252
00253 virtual NCursesEvent wHandleInput( wint_t key );
00254 };
00255
00256
00257 class NCDirectoryTable : public NCFileSelection {
00258
00259 public:
00263 NCDirectoryTable( NCWidget * parent,
00264 const YWidgetOpt & opt,
00265 NCFileSelectionType type,
00266 const YCPString & iniDir );
00267
00268 virtual ~NCDirectoryTable(){}
00269
00270 virtual void fillHeader();
00271
00272 virtual bool createListEntry( const NCFileInfo & fileInfo );
00273
00278 virtual bool fillList ( );
00279
00280 virtual NCursesEvent wHandleInput( wint_t key );
00281
00282 };
00283
00284
00286
00287 #endif // NCFileSelection_h