libyui-ncurses  2.44.1
 All Classes Functions Variables
NCFileSelection.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: NCFileSelection.h
20 
21  Author: Gabriele Strattner <gs@suse.de>
22 
23 /-*/
24 
25 #ifndef NCFileSelection_h
26 #define NCFileSelection_h
27 
28 #include <iosfwd>
29 
30 #include "NCPadWidget.h"
31 #include "NCTablePad.h"
32 #include "NCTable.h"
33 
34 #include <map>
35 #include <string>
36 
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <unistd.h>
40 #include <dirent.h>
41 #include <sys/errno.h>
42 
43 
44 struct NCFileInfo
45 {
46  /**
47  * Constructor from a stat buffer (i.e. based on an lstat64() call).
48  **/
49  NCFileInfo( std::string fileName,
50  struct stat64 * statInfo,
51  bool link = false );
52 
53  NCFileInfo();
54 
55  ~NCFileInfo() {};
56 
57  // Data members.
58 
59  std::string _name; // the file name (without path!)
60  std::string _realName; // actual file name
61  std::string _tag; // short label
62  std::string _perm; // permission std::string
63  std::string _user; // user name
64  std::string _group; // group name
65  dev_t _device; // device this object resides on
66  mode_t _mode; // file permissions + object type
67  nlink_t _links; // number of links
68  off64_t _size; // size in bytes
69  time_t _mtime; // modification time
70 
71  bool isDir() { return (( S_ISDIR( _mode ) ) ? true : false ); }
72 
73  bool isLink() { return (( S_ISLNK( _mode ) ) ? true : false ); }
74 
75  bool isFile() { return (( S_ISREG( _mode ) ) ? true : false ); }
76 };
77 
78 
79 /**
80  * This class is used for the first column of the file table.
81  * Contains the file data.
82  **/
83 class NCFileSelectionTag : public YTableCell
84 {
85 
86 private:
87 
88  NCFileInfo * fileInfo;
89 
90 public:
91 
93 
95 
96  NCFileInfo * getFileInfo() const { return fileInfo; }
97 };
98 
99 
100 /**
101  * The class which provides methods to handle a std::list of files or directories.
102  **/
103 class NCFileSelection : public NCTable
104 {
105 public:
106  enum NCFileSelectionType
107  {
108  T_Overview,
109  T_Detailed,
110  T_Unknown
111  };
112 
113 private:
114 
115  NCFileSelection & operator=( const NCFileSelection & );
116  NCFileSelection( const NCFileSelection & );
117 
118  // returns the first column of line with 'index' (the tag)
119  NCFileSelectionTag * getTag( const int & index );
120 
121 
122 protected:
123 
124  std::string startDir;
125  std::string currentDir;
126  NCFileSelectionType tableType; // T_Overview or T_Detailed
127 
128  void setCurrentDir( );
129  std::string getCurrentLine( );
130 
131  NCursesEvent handleKeyEvents( wint_t key );
132 
133 public:
134 
135  /**
136  * Constructor
137  */
138  NCFileSelection( YWidget * parent,
139  YTableHeader * tableHeader,
140  NCFileSelectionType type,
141  const std::string & iniDir );
142 
143  virtual ~NCFileSelection();
144 
145  /**
146  * Get the file info.
147  * index: The std::list index
148  * return: fileInfo Information about the file (directory)
149  */
150  NCFileInfo * getFileInfo( int index );
151 
152  /**
153  * Set the type of the table widget
154  * type: Possible values: NCFileSelection::T_Overview, NCFileSelection::T_Detailed
155  */
156  void setTableType( NCFileSelectionType type ) { tableType = type; };
157 
158  virtual void addLine( const std::vector<std::string> & elements,
159  NCFileInfo * fileInfo );
160 
161  /**
162  * Get number of lines ( std::list entries )
163  */
164  unsigned int getNumLines( ) { return myPad()->Lines(); }
165 
166  /**
167  * Draws the file std::list (has to be called after the loop with
168  * addLine() calls)
169  */
170  void drawList( ) { return DrawPad(); }
171 
172  /**
173  * Clears the package std::list
174  */
175  virtual void deleteAllItems();
176 
177  /**
178  * Fills the header of the table
179  */
180  virtual void fillHeader() = 0;
181 
182  /**
183  * Creates a line in the package table.
184  */
185  virtual bool createListEntry( NCFileInfo * fileInfo ) = 0;
186 
187  /**
188  * Get the current directory
189  * return: The currently selected directory
190  */
191  std::string getCurrentDir() { return currentDir; }
192 
193  /**
194  * Fill the std::list of diretcories or files
195  * Returns 'true' on success.
196  */
197  virtual bool fillList( ) = 0;
198 
199  /**
200  * Set the start directory
201  */
202  void setStartDir( const std::string & start )
203  {
204  currentDir = start;
205  startDir = start;
206  }
207 
208 };
209 
210 
212 {
213 private:
214 
215  std::list<std::string> pattern; // files must match this pattern
216  std::string currentFile; // currently selected file
217 
218 public:
219 
220  /**
221  * Constructor
222  */
223  NCFileTable( YWidget * parent,
224  YTableHeader * tableHeader,
225  NCFileSelectionType type,
226  const std::string & filter,
227  const std::string & iniDir );
228 
229  virtual ~NCFileTable() {}
230 
231  void setCurrentFile( const std::string & file )
232  {
233  currentFile = file;
234  }
235 
236  bool filterMatch( const std::string & fileName );
237 
238  std::string getCurrentFile() { return currentFile; }
239 
240  virtual void fillHeader();
241 
242  virtual bool createListEntry( NCFileInfo * fileInfo );
243 
244  /**
245  * Fill the std::list of files
246  * Returns 'true' on success.
247  */
248  virtual bool fillList( );
249 
250  virtual NCursesEvent wHandleInput( wint_t key );
251 };
252 
253 
255 {
256 public:
257  NCDirectoryTable( YWidget * parent,
258  YTableHeader * tableHeader,
259  NCFileSelectionType type,
260  const std::string & iniDir );
261 
262  virtual ~NCDirectoryTable() {}
263 
264  virtual void fillHeader();
265 
266  virtual bool createListEntry( NCFileInfo * fileInfo );
267 
268  /**
269  * Fill the std::list of directories.
270  * Returns 'true' on success.
271  */
272  virtual bool fillList( );
273 
274  virtual NCursesEvent wHandleInput( wint_t key );
275 };
276 
277 
278 
279 #endif // NCFileSelection_h
NCFileInfo * getFileInfo(int index)
virtual bool fillList()=0
virtual NCTablePad * myPad() const
Definition: NCTable.h:102
virtual bool fillList()
virtual void fillHeader()
void setStartDir(const std::string &start)
void setTableType(NCFileSelectionType type)
NCFileTable(YWidget *parent, YTableHeader *tableHeader, NCFileSelectionType type, const std::string &filter, const std::string &iniDir)
virtual bool createListEntry(NCFileInfo *fileInfo)=0
virtual void fillHeader()=0
virtual bool createListEntry(NCFileInfo *fileInfo)
std::string getCurrentDir()
virtual void fillHeader()
virtual bool createListEntry(NCFileInfo *fileInfo)
virtual bool fillList()
virtual void deleteAllItems()
unsigned int getNumLines()