libyui-ncurses
2.44.1
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: NCFileSelection.h 00020 00021 Author: Gabriele Strattner <gs@suse.de> 00022 00023 /-*/ 00024 00025 #ifndef NCFileSelection_h 00026 #define NCFileSelection_h 00027 00028 #include <iosfwd> 00029 00030 #include "NCPadWidget.h" 00031 #include "NCTablePad.h" 00032 #include "NCTable.h" 00033 00034 #include <map> 00035 #include <string> 00036 00037 #include <sys/types.h> 00038 #include <sys/stat.h> 00039 #include <unistd.h> 00040 #include <dirent.h> 00041 #include <sys/errno.h> 00042 00043 00044 struct NCFileInfo 00045 { 00046 /** 00047 * Constructor from a stat buffer (i.e. based on an lstat64() call). 00048 **/ 00049 NCFileInfo( std::string fileName, 00050 struct stat64 * statInfo, 00051 bool link = false ); 00052 00053 NCFileInfo(); 00054 00055 ~NCFileInfo() {}; 00056 00057 // Data members. 00058 00059 std::string _name; // the file name (without path!) 00060 std::string _realName; // actual file name 00061 std::string _tag; // short label 00062 std::string _perm; // permission std::string 00063 std::string _user; // user name 00064 std::string _group; // group name 00065 dev_t _device; // device this object resides on 00066 mode_t _mode; // file permissions + object type 00067 nlink_t _links; // number of links 00068 off64_t _size; // size in bytes 00069 time_t _mtime; // modification time 00070 00071 bool isDir() { return (( S_ISDIR( _mode ) ) ? true : false ); } 00072 00073 bool isLink() { return (( S_ISLNK( _mode ) ) ? true : false ); } 00074 00075 bool isFile() { return (( S_ISREG( _mode ) ) ? true : false ); } 00076 }; 00077 00078 00079 /** 00080 * This class is used for the first column of the file table. 00081 * Contains the file data. 00082 **/ 00083 class NCFileSelectionTag : public YTableCell 00084 { 00085 00086 private: 00087 00088 NCFileInfo * fileInfo; 00089 00090 public: 00091 00092 NCFileSelectionTag( NCFileInfo * info ); 00093 00094 ~NCFileSelectionTag(); 00095 00096 NCFileInfo * getFileInfo() const { return fileInfo; } 00097 }; 00098 00099 00100 /** 00101 * The class which provides methods to handle a std::list of files or directories. 00102 **/ 00103 class NCFileSelection : public NCTable 00104 { 00105 public: 00106 enum NCFileSelectionType 00107 { 00108 T_Overview, 00109 T_Detailed, 00110 T_Unknown 00111 }; 00112 00113 private: 00114 00115 NCFileSelection & operator=( const NCFileSelection & ); 00116 NCFileSelection( const NCFileSelection & ); 00117 00118 // returns the first column of line with 'index' (the tag) 00119 NCFileSelectionTag * getTag( const int & index ); 00120 00121 00122 protected: 00123 00124 std::string startDir; 00125 std::string currentDir; 00126 NCFileSelectionType tableType; // T_Overview or T_Detailed 00127 00128 void setCurrentDir( ); 00129 std::string getCurrentLine( ); 00130 00131 NCursesEvent handleKeyEvents( wint_t key ); 00132 00133 public: 00134 00135 /** 00136 * Constructor 00137 */ 00138 NCFileSelection( YWidget * parent, 00139 YTableHeader * tableHeader, 00140 NCFileSelectionType type, 00141 const std::string & iniDir ); 00142 00143 virtual ~NCFileSelection(); 00144 00145 /** 00146 * Get the file info. 00147 * index: The std::list index 00148 * return: fileInfo Information about the file (directory) 00149 */ 00150 NCFileInfo * getFileInfo( int index ); 00151 00152 /** 00153 * Set the type of the table widget 00154 * type: Possible values: NCFileSelection::T_Overview, NCFileSelection::T_Detailed 00155 */ 00156 void setTableType( NCFileSelectionType type ) { tableType = type; }; 00157 00158 virtual void addLine( const std::vector<std::string> & elements, 00159 NCFileInfo * fileInfo ); 00160 00161 /** 00162 * Get number of lines ( std::list entries ) 00163 */ 00164 unsigned int getNumLines( ) { return myPad()->Lines(); } 00165 00166 /** 00167 * Draws the file std::list (has to be called after the loop with 00168 * addLine() calls) 00169 */ 00170 void drawList( ) { return DrawPad(); } 00171 00172 /** 00173 * Clears the package std::list 00174 */ 00175 virtual void deleteAllItems(); 00176 00177 /** 00178 * Fills the header of the table 00179 */ 00180 virtual void fillHeader() = 0; 00181 00182 /** 00183 * Creates a line in the package table. 00184 */ 00185 virtual bool createListEntry( NCFileInfo * fileInfo ) = 0; 00186 00187 /** 00188 * Get the current directory 00189 * return: The currently selected directory 00190 */ 00191 std::string getCurrentDir() { return currentDir; } 00192 00193 /** 00194 * Fill the std::list of diretcories or files 00195 * Returns 'true' on success. 00196 */ 00197 virtual bool fillList( ) = 0; 00198 00199 /** 00200 * Set the start directory 00201 */ 00202 void setStartDir( const std::string & start ) 00203 { 00204 currentDir = start; 00205 startDir = start; 00206 } 00207 00208 }; 00209 00210 00211 class NCFileTable : public NCFileSelection 00212 { 00213 private: 00214 00215 std::list<std::string> pattern; // files must match this pattern 00216 std::string currentFile; // currently selected file 00217 00218 public: 00219 00220 /** 00221 * Constructor 00222 */ 00223 NCFileTable( YWidget * parent, 00224 YTableHeader * tableHeader, 00225 NCFileSelectionType type, 00226 const std::string & filter, 00227 const std::string & iniDir ); 00228 00229 virtual ~NCFileTable() {} 00230 00231 void setCurrentFile( const std::string & file ) 00232 { 00233 currentFile = file; 00234 } 00235 00236 bool filterMatch( const std::string & fileName ); 00237 00238 std::string getCurrentFile() { return currentFile; } 00239 00240 virtual void fillHeader(); 00241 00242 virtual bool createListEntry( NCFileInfo * fileInfo ); 00243 00244 /** 00245 * Fill the std::list of files 00246 * Returns 'true' on success. 00247 */ 00248 virtual bool fillList( ); 00249 00250 virtual NCursesEvent wHandleInput( wint_t key ); 00251 }; 00252 00253 00254 class NCDirectoryTable : public NCFileSelection 00255 { 00256 public: 00257 NCDirectoryTable( YWidget * parent, 00258 YTableHeader * tableHeader, 00259 NCFileSelectionType type, 00260 const std::string & iniDir ); 00261 00262 virtual ~NCDirectoryTable() {} 00263 00264 virtual void fillHeader(); 00265 00266 virtual bool createListEntry( NCFileInfo * fileInfo ); 00267 00268 /** 00269 * Fill the std::list of directories. 00270 * Returns 'true' on success. 00271 */ 00272 virtual bool fillList( ); 00273 00274 virtual NCursesEvent wHandleInput( wint_t key ); 00275 }; 00276 00277 00278 00279 #endif // NCFileSelection_h