libyui-ncurses
Loading...
Searching...
No Matches
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 <errno.h>
42
43
45{
49 NCFileInfo( std::string fileName,
50 struct stat * 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 off_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
83class NCFileSelectionTag : public YTableCell
84{
85
86private:
87
88 NCFileInfo * fileInfo;
89
90public:
91
93
95
96 NCFileInfo * getFileInfo() const { return fileInfo; }
97};
98
99
104{
105public:
106 enum NCFileSelectionType
107 {
108 T_Overview,
109 T_Detailed,
110 T_Unknown
111 };
112
113private:
114
115 NCFileSelection & operator=( const NCFileSelection & );
117
118 // returns the first column of line with 'index' (the tag)
119 NCFileSelectionTag * getTag( int index );
120
121
122protected:
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
133public:
134
138 NCFileSelection( YWidget * parent,
139 YTableHeader * tableHeader,
140 NCFileSelectionType type,
141 const std::string & iniDir );
142
143 virtual ~NCFileSelection();
144
150 NCFileInfo * getFileInfo( int index );
151
156 void setTableType( NCFileSelectionType type ) { tableType = type; };
157
158 virtual void addLine( const std::vector<std::string> & elements,
159 NCFileInfo * fileInfo );
160
164 unsigned getNumLines() { return myPad()->Lines(); }
165
170 void drawList() { return DrawPad(); }
171
175 virtual void deleteAllItems();
176
180 virtual void fillHeader() = 0;
181
185 virtual bool createListEntry( NCFileInfo * fileInfo ) = 0;
186
191 std::string getCurrentDir() { return currentDir; }
192
197 virtual bool fillList() = 0;
198
202 void setStartDir( const std::string & start )
203 {
204 currentDir = start;
205 startDir = start;
206 }
207
208};
209
210
212{
213private:
214
215 std::list<std::string> pattern; // files must match this pattern
216 std::string currentFile; // currently selected file
217
218public:
219
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
248 virtual bool fillList();
249
250 virtual NCursesEvent wHandleInput( wint_t key );
251};
252
253
255{
256public:
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
272 virtual bool fillList();
273
274 virtual NCursesEvent wHandleInput( wint_t key );
275};
276
277
278
279#endif // NCFileSelection_h
Definition NCFileSelection.h:255
virtual bool fillList()
Definition NCFileSelection.cc:702
virtual void fillHeader()
Definition NCFileSelection.cc:658
virtual NCursesEvent wHandleInput(wint_t key)
Definition NCFileSelection.cc:782
virtual bool createListEntry(NCFileInfo *fileInfo)
Definition NCFileSelection.cc:325
Definition NCFileSelection.h:84
Definition NCFileSelection.h:104
virtual void deleteAllItems()
Definition NCFileSelection.cc:280
virtual bool fillList()=0
void setStartDir(const std::string &start)
Definition NCFileSelection.h:202
void drawList()
Definition NCFileSelection.h:170
NCFileInfo * getFileInfo(int index)
Definition NCFileSelection.cc:361
std::string getCurrentDir()
Definition NCFileSelection.h:191
virtual void fillHeader()=0
void setTableType(NCFileSelectionType type)
Definition NCFileSelection.h:156
virtual bool createListEntry(NCFileInfo *fileInfo)=0
unsigned getNumLines()
Definition NCFileSelection.h:164
NCFileSelection(YWidget *parent, YTableHeader *tableHeader, NCFileSelectionType type, const std::string &iniDir)
Definition NCFileSelection.h:212
virtual bool fillList()
Definition NCFileSelection.cc:559
virtual bool createListEntry(NCFileInfo *fileInfo)
Definition NCFileSelection.cc:286
virtual void fillHeader()
Definition NCFileSelection.cc:426
virtual NCursesEvent wHandleInput(wint_t key)
Definition NCFileSelection.cc:521
unsigned Lines() const
Definition NCTablePadBase.h:122
Definition NCTable.h:43
virtual NCTablePad * myPad() const
Definition NCTable.h:289
Definition NCurses.h:73
Definition NCFileSelection.h:45
NCFileInfo(std::string fileName, struct stat *statInfo, bool link=false)