-rw-r--r-- | noncore/unsupported/filebrowser/Makefile.in | 2 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/filePermissions.cpp | 274 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/filePermissions.h | 56 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.cpp | 422 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.h | 12 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.pro | 7 |
6 files changed, 566 insertions, 207 deletions
diff --git a/noncore/unsupported/filebrowser/Makefile.in b/noncore/unsupported/filebrowser/Makefile.in index c00d0f5..d1f80b7 100644 --- a/noncore/unsupported/filebrowser/Makefile.in +++ b/noncore/unsupported/filebrowser/Makefile.in | |||
@@ -110,24 +110,26 @@ filebrowser.o: filebrowser.cpp \ | |||
110 | $(OPIEDIR)/include/qpe/global.h \ | 110 | $(OPIEDIR)/include/qpe/global.h \ |
111 | $(OPIEDIR)/include/qpe/mimetype.h \ | 111 | $(OPIEDIR)/include/qpe/mimetype.h \ |
112 | $(OPIEDIR)/include/qpe/applnk.h \ | 112 | $(OPIEDIR)/include/qpe/applnk.h \ |
113 | $(OPIEDIR)/include/qpe/qpetoolbar.h \ | 113 | $(OPIEDIR)/include/qpe/qpetoolbar.h \ |
114 | $(OPIEDIR)/include/qpe/qpemenubar.h | 114 | $(OPIEDIR)/include/qpe/qpemenubar.h |
115 | 115 | ||
116 | inlineedit.o: inlineedit.cpp \ | 116 | inlineedit.o: inlineedit.cpp \ |
117 | inlineedit.h | 117 | inlineedit.h |
118 | 118 | ||
119 | main.o: main.cpp \ | 119 | main.o: main.cpp \ |
120 | filebrowser.h \ | 120 | filebrowser.h \ |
121 | $(OPIEDIR)/include/qpe/qpeapplication.h \ | 121 | $(OPIEDIR)/include/qpe/qpeapplication.h \ |
122 | $(OPIEDIR)/include/qpedecoration_qws.h \ | ||
123 | $(OPIEDIR)/include/timestring.h \ | ||
122 | $(OPIEDIR)/include/qpe/mimetype.h | 124 | $(OPIEDIR)/include/qpe/mimetype.h |
123 | 125 | ||
124 | moc_inlineedit.o: moc_inlineedit.cpp \ | 126 | moc_inlineedit.o: moc_inlineedit.cpp \ |
125 | inlineedit.h | 127 | inlineedit.h |
126 | 128 | ||
127 | moc_filebrowser.o: moc_filebrowser.cpp \ | 129 | moc_filebrowser.o: moc_filebrowser.cpp \ |
128 | filebrowser.h | 130 | filebrowser.h |
129 | 131 | ||
130 | moc_inlineedit.cpp: inlineedit.h | 132 | moc_inlineedit.cpp: inlineedit.h |
131 | $(MOC) inlineedit.h -o moc_inlineedit.cpp | 133 | $(MOC) inlineedit.h -o moc_inlineedit.cpp |
132 | 134 | ||
133 | moc_filebrowser.cpp: filebrowser.h | 135 | moc_filebrowser.cpp: filebrowser.h |
diff --git a/noncore/unsupported/filebrowser/filePermissions.cpp b/noncore/unsupported/filebrowser/filePermissions.cpp new file mode 100644 index 0000000..1938b84 --- a/dev/null +++ b/noncore/unsupported/filebrowser/filePermissions.cpp | |||
@@ -0,0 +1,274 @@ | |||
1 | /**************************************************************************** | ||
2 | ** copyright 2002 ljp ljp@llornkcor.com | ||
3 | ** Created: Sat Feb 23 19:44:40 2002 L.J. Potter | ||
4 | ** | ||
5 | ** This file may be distributed and/or modified under the terms of the | ||
6 | ** GNU General Public License version 2 as published by the Free Software | ||
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
8 | ** packaging of this file. | ||
9 | ** | ||
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
12 | ** | ||
13 | ****************************************************************************/ | ||
14 | #include "filePermissions.h" | ||
15 | |||
16 | #include <qfile.h> | ||
17 | #include <qfileinfo.h> | ||
18 | |||
19 | #include <qcheckbox.h> | ||
20 | #include <qlabel.h> | ||
21 | #include <qlineedit.h> | ||
22 | #include <qlayout.h> | ||
23 | #include <qvariant.h> | ||
24 | #include <qtooltip.h> | ||
25 | #include <qmessagebox.h> | ||
26 | |||
27 | #include <unistd.h> | ||
28 | #include <sys/stat.h> | ||
29 | #include <stdlib.h> | ||
30 | #include <sys/types.h> | ||
31 | #include <pwd.h> | ||
32 | #include <grp.h> | ||
33 | |||
34 | filePermissions::filePermissions( QWidget* parent, const char* name, bool modal, WFlags fl, const QString &fileName ) | ||
35 | : QDialog( parent, name, modal, fl ) | ||
36 | { | ||
37 | if ( !name ) | ||
38 | setName( "filePermissions" ); | ||
39 | qDebug("FilePermissions "+fileName); | ||
40 | resize( 236, 210 ); | ||
41 | setMaximumSize( QSize( 236, 210 ) ); | ||
42 | setCaption( tr( "Set File Permissions" ) ); | ||
43 | |||
44 | TextLabel1 = new QLabel( this, "TextLabel1" ); | ||
45 | TextLabel1->setGeometry( QRect( 25, 5, 175, 20 ) ); | ||
46 | TextLabel1->setText( tr( "Set file permissions for:" ) ); | ||
47 | |||
48 | LineEdit1 = new QLineEdit( this, "LineEdit1" ); | ||
49 | LineEdit1->setGeometry( QRect( 10, 25, 218, 22 ) ); | ||
50 | LineEdit1->setReadOnly(true); | ||
51 | |||
52 | TextLabel4 = new QLabel( this, "TextLabel4" ); | ||
53 | TextLabel4->setGeometry( QRect( 5, 85, 50, 15 ) ); | ||
54 | TextLabel4->setText( tr( "owner" ) ); | ||
55 | |||
56 | TextLabel4_2 = new QLabel( this, "TextLabel4_2" ); | ||
57 | TextLabel4_2->setGeometry( QRect( 5, 105, 50, 15 ) ); | ||
58 | TextLabel4_2->setText( tr( "group" ) ); | ||
59 | |||
60 | TextLabel4_3 = new QLabel( this, "TextLabel4_3" ); | ||
61 | TextLabel4_3->setGeometry( QRect( 5, 125, 50, 15 ) ); | ||
62 | TextLabel4_3->setText( tr( "others" ) ); | ||
63 | |||
64 | CheckBox1 = new QCheckBox( this, "CheckBox1" ); | ||
65 | CheckBox1->setGeometry( QRect( 75, 85, 20, 16 ) ); | ||
66 | connect(CheckBox1, SIGNAL(released()),this,SLOT(ownReadCheck())); | ||
67 | |||
68 | CheckBox1_2 = new QCheckBox( this, "CheckBox1_2" ); | ||
69 | CheckBox1_2->setGeometry( QRect( 135, 85, 20, 16 ) ); | ||
70 | connect(CheckBox1_2, SIGNAL(released()),this,SLOT(ownWriteCheck())); | ||
71 | |||
72 | CheckBox1_3 = new QCheckBox( this, "CheckBox1_3" ); | ||
73 | CheckBox1_3->setGeometry( QRect( 195, 85, 20, 16 ) ); | ||
74 | connect(CheckBox1_3, SIGNAL(released()),this,SLOT(ownExeCheck())); | ||
75 | |||
76 | CheckBox1_4 = new QCheckBox( this, "CheckBox1_4" ); | ||
77 | CheckBox1_4->setGeometry( QRect( 75, 105, 20, 16 ) ); | ||
78 | connect(CheckBox1_4, SIGNAL(released()),this,SLOT(grpReadCheck())); | ||
79 | |||
80 | CheckBox1_5 = new QCheckBox( this, "CheckBox1_5" ); | ||
81 | CheckBox1_5->setGeometry( QRect( 135, 105, 20, 16 ) ); | ||
82 | connect(CheckBox1_5, SIGNAL(released()),this,SLOT(grpWriteCheck())); | ||
83 | |||
84 | CheckBox1_6 = new QCheckBox( this, "CheckBox1_6" ); | ||
85 | CheckBox1_6->setGeometry( QRect( 195, 105, 20, 16 ) ); | ||
86 | connect(CheckBox1_6, SIGNAL(released()),this,SLOT(grpExeCheck())); | ||
87 | |||
88 | CheckBox1_7 = new QCheckBox( this, "CheckBox1_7" ); | ||
89 | CheckBox1_7->setGeometry( QRect( 75, 125, 16, 16 ) ); | ||
90 | connect(CheckBox1_7, SIGNAL(released()),this,SLOT(wrldReadCheck())); | ||
91 | |||
92 | CheckBox1_8 = new QCheckBox( this, "CheckBox1_8" ); | ||
93 | CheckBox1_8->setGeometry( QRect( 135, 125, 20, 16 ) ); | ||
94 | connect(CheckBox1_8, SIGNAL(released()),this,SLOT(wrldWriteCheck())); | ||
95 | |||
96 | CheckBox1_8_2 = new QCheckBox( this, "CheckBox1_8_2" ); | ||
97 | CheckBox1_8_2->setGeometry( QRect( 195, 125, 20, 16 ) ); | ||
98 | connect(CheckBox1_8_2, SIGNAL(released()),this,SLOT(wrldExeCheck())); | ||
99 | |||
100 | GroupLineEdit = new QLineEdit( this, "GroupLineEdit" ); | ||
101 | GroupLineEdit->setGeometry( QRect( 125, 155, 106, 22 ) ); | ||
102 | |||
103 | OwnerLineEdit = new QLineEdit( this, "OwnerLineEdit" ); | ||
104 | OwnerLineEdit->setGeometry( QRect( 10, 155, 106, 22 ) ); | ||
105 | |||
106 | TextLabel5 = new QLabel( this, "TextLabel5" ); | ||
107 | TextLabel5->setGeometry( QRect( 45, 180, 40, 16 ) ); | ||
108 | TextLabel5->setText( tr( "Owner" ) ); | ||
109 | |||
110 | TextLabel5_2 = new QLabel( this, "TextLabel5_2" ); | ||
111 | TextLabel5_2->setGeometry( QRect( 155, 180, 40, 16 ) ); | ||
112 | TextLabel5_2->setText( tr( "Group" ) ); | ||
113 | |||
114 | ModeLine = new QLineEdit( this, "TextLabelMode" ); | ||
115 | ModeLine->setGeometry( QRect( 10, 60, 40, 15 ) ); | ||
116 | |||
117 | TextLabel3_2 = new QLabel( this, "TextLabel3_2" ); | ||
118 | TextLabel3_2->setGeometry( QRect( 60, 55, 50, 20 ) ); | ||
119 | TextLabel3_2->setText( tr( "read" ) ); | ||
120 | TextLabel3_2->setAlignment( int( QLabel::AlignBottom | QLabel::AlignHCenter ) ); | ||
121 | |||
122 | TextLabel3_2_2 = new QLabel( this, "TextLabel3_2_2" ); | ||
123 | TextLabel3_2_2->setGeometry( QRect( 120, 55, 50, 20 ) ); | ||
124 | TextLabel3_2_2->setText( tr( "write" ) ); | ||
125 | TextLabel3_2_2->setAlignment( int( QLabel::AlignBottom | QLabel::AlignHCenter ) ); | ||
126 | |||
127 | TextLabel3 = new QLabel( this, "TextLabel3" ); | ||
128 | TextLabel3->setGeometry( QRect( 180, 55, 50, 20 ) ); | ||
129 | TextLabel3->setText( tr( "execute" ) ); | ||
130 | TextLabel3->setAlignment( int( QLabel::AlignBottom | QLabel::AlignHCenter ) ); | ||
131 | |||
132 | struct stat buf; | ||
133 | mode_t mode; | ||
134 | file = fileName; | ||
135 | QFileInfo fi(file); | ||
136 | |||
137 | LineEdit1->setText( file); | ||
138 | OwnerLineEdit->setText( fi.owner()); | ||
139 | GroupLineEdit->setText( fi.group()); | ||
140 | |||
141 | if( fi.permission( QFileInfo::ReadUser)) { CheckBox1->setChecked(true); } | ||
142 | if( fi.permission( QFileInfo::WriteUser)) { CheckBox1_2->setChecked(true); } | ||
143 | if( fi.permission( QFileInfo::ExeUser)) { CheckBox1_3->setChecked(true); } | ||
144 | |||
145 | if( fi.permission( QFileInfo::ReadGroup)) { CheckBox1_4->setChecked(true); } | ||
146 | if( fi.permission( QFileInfo::WriteGroup)) { CheckBox1_5->setChecked(true); } | ||
147 | if( fi.permission( QFileInfo::ExeGroup)) { CheckBox1_6->setChecked(true); } | ||
148 | |||
149 | if( fi.permission( QFileInfo::ReadOther)) { CheckBox1_7->setChecked(true); } | ||
150 | if( fi.permission( QFileInfo::WriteOther)) { CheckBox1_8->setChecked(true); } | ||
151 | if( fi.permission( QFileInfo::ExeOther)) { CheckBox1_8_2->setChecked(true); } | ||
152 | |||
153 | lstat(file.latin1(), &buf); | ||
154 | mode = buf.st_mode; | ||
155 | modeStr.sprintf("%#o", buf.st_mode & ~(S_IFMT) ); | ||
156 | ModeLine->setText(modeStr); | ||
157 | bool ok; | ||
158 | i_mode = modeStr.toInt(&ok,10); | ||
159 | |||
160 | } | ||
161 | |||
162 | /* | ||
163 | * Destroys the object and frees any allocated resources | ||
164 | */ | ||
165 | filePermissions::~filePermissions() | ||
166 | { | ||
167 | } | ||
168 | |||
169 | |||
170 | // might this be better as a callback routine??? | ||
171 | void filePermissions::ownReadCheck() { | ||
172 | if(CheckBox1->isChecked()) { i_mode +=400; } | ||
173 | else i_mode -=400; | ||
174 | modeStr.sprintf("0%d",i_mode); | ||
175 | ModeLine->setText( modeStr); | ||
176 | // 0400 | ||
177 | } | ||
178 | |||
179 | void filePermissions::ownWriteCheck() { | ||
180 | if(CheckBox1_2->isChecked()) { i_mode +=200; } | ||
181 | else i_mode -=200; | ||
182 | modeStr.sprintf("0%d",i_mode); | ||
183 | ModeLine->setText(modeStr); | ||
184 | // 0200 | ||
185 | } | ||
186 | |||
187 | void filePermissions::ownExeCheck() { | ||
188 | if(CheckBox1_3->isChecked()) { i_mode +=100; } | ||
189 | else i_mode -=100; | ||
190 | modeStr.sprintf("0%d",i_mode); | ||
191 | ModeLine->setText(modeStr); | ||
192 | // 0100 | ||
193 | } | ||
194 | |||
195 | void filePermissions::grpReadCheck() { | ||
196 | if(CheckBox1_4->isChecked()) { i_mode +=40; } | ||
197 | else i_mode -=40; | ||
198 | modeStr.sprintf("0%d",i_mode); | ||
199 | ModeLine->setText(modeStr); | ||
200 | // 0040 | ||
201 | } | ||
202 | |||
203 | void filePermissions::grpWriteCheck() { | ||
204 | if(CheckBox1_5->isChecked()) { i_mode +=20; } | ||
205 | else i_mode -=20; | ||
206 | modeStr.sprintf("0%d",i_mode); | ||
207 | ModeLine->setText(modeStr); | ||
208 | // 0020 | ||
209 | } | ||
210 | |||
211 | void filePermissions::grpExeCheck() { | ||
212 | if(CheckBox1_6->isChecked()) { i_mode +=10; } | ||
213 | else i_mode -=10; | ||
214 | modeStr.sprintf("0%d",i_mode); | ||
215 | ModeLine->setText(modeStr); | ||
216 | // 0010 | ||
217 | } | ||
218 | |||
219 | void filePermissions::wrldReadCheck() { | ||
220 | if(CheckBox1_7->isChecked()) { i_mode +=4; } | ||
221 | else i_mode -=4; | ||
222 | modeStr.sprintf("0%d",i_mode); | ||
223 | ModeLine->setText(modeStr); | ||
224 | // 0004 | ||
225 | } | ||
226 | |||
227 | void filePermissions::wrldWriteCheck() { | ||
228 | if(CheckBox1_8->isChecked()) { i_mode +=2; } | ||
229 | else i_mode -=2; | ||
230 | modeStr.sprintf("0%d",i_mode); | ||
231 | ModeLine->setText(modeStr); | ||
232 | // 0002 | ||
233 | } | ||
234 | |||
235 | void filePermissions::wrldExeCheck() { | ||
236 | if(CheckBox1_8_2->isChecked()) { i_mode +=1; } | ||
237 | else i_mode -=1; | ||
238 | modeStr.sprintf("0%d",i_mode); | ||
239 | ModeLine->setText(modeStr); | ||
240 | // 0001 | ||
241 | } | ||
242 | |||
243 | void filePermissions::accept() { | ||
244 | |||
245 | QFileInfo fi(file); | ||
246 | struct passwd *pwd=0; | ||
247 | struct group *grp=0; | ||
248 | pwd = getpwnam(OwnerLineEdit->text().latin1() ); | ||
249 | if(pwd == NULL) { | ||
250 | perror("getpwnam"); | ||
251 | QMessageBox::warning(this,"Warning","Error- no user"); | ||
252 | return; | ||
253 | } else { | ||
254 | grp = getgrnam(GroupLineEdit->text().latin1()); | ||
255 | if(grp==NULL) { | ||
256 | perror("getgrnam"); | ||
257 | QMessageBox::warning(this,"Warning","Error- no group"); | ||
258 | return; | ||
259 | } | ||
260 | if( chown( file.latin1(), pwd->pw_uid, grp->gr_gid) <0) { | ||
261 | perror("chown"); | ||
262 | QMessageBox::warning(this,"Warning","Error setting ownership or group"); | ||
263 | return; | ||
264 | } | ||
265 | bool ok; | ||
266 | uint moder = modeStr.toUInt(&ok,8); | ||
267 | if( chmod( file.latin1(), moder) < 0) { | ||
268 | perror("chmod"); | ||
269 | QMessageBox::warning(this,"Warning","Error setting mode"); | ||
270 | return; | ||
271 | } | ||
272 | } | ||
273 | close(); | ||
274 | } | ||
diff --git a/noncore/unsupported/filebrowser/filePermissions.h b/noncore/unsupported/filebrowser/filePermissions.h new file mode 100644 index 0000000..880304f --- a/dev/null +++ b/noncore/unsupported/filebrowser/filePermissions.h | |||
@@ -0,0 +1,56 @@ | |||
1 | /**************************************************************************** | ||
2 | ** copyright 2002 ljp ljp@llornkcor.com | ||
3 | ** Created: Sat Feb 23 19:44:17 2002 | ||
4 | ** | ||
5 | ** This file may be distributed and/or modified under the terms of the | ||
6 | ** GNU General Public License version 2 as published by the Free Software | ||
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
8 | ** packaging of this file. | ||
9 | ** | ||
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
12 | ** | ||
13 | ****************************************************************************/ | ||
14 | #ifndef FILEPERMISSIONS_H | ||
15 | #define FILEPERMISSIONS_H | ||
16 | |||
17 | #include <qvariant.h> | ||
18 | #include <qdialog.h> | ||
19 | class QVBoxLayout; | ||
20 | class QHBoxLayout; | ||
21 | class QGridLayout; | ||
22 | class QCheckBox; | ||
23 | class QLabel; | ||
24 | class QLineEdit; | ||
25 | class QString; | ||
26 | |||
27 | class filePermissions : public QDialog | ||
28 | { | ||
29 | Q_OBJECT | ||
30 | |||
31 | public: | ||
32 | filePermissions( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 , const QString & fileName =""); | ||
33 | ~filePermissions(); | ||
34 | |||
35 | QLineEdit *LineEdit1, *ModeLine; | ||
36 | QLabel *TextLabel1, *TextLabel4, *TextLabel4_2, *TextLabel4_3, *TextLabel3_2_2, *TextLabel3_2, *TextLabel3, *TextLabel5_2, *TextLabel5; | ||
37 | QCheckBox*CheckBox1, *CheckBox1_3, *CheckBox1_2, *CheckBox1_4, *CheckBox1_5, *CheckBox1_6, *CheckBox1_7, *CheckBox1_8, *CheckBox1_8_2; | ||
38 | QLineEdit*GroupLineEdit, *OwnerLineEdit; | ||
39 | QString modeStr, file; | ||
40 | int i_mode; | ||
41 | private slots: | ||
42 | void ownReadCheck(); | ||
43 | void ownWriteCheck(); | ||
44 | void ownExeCheck(); | ||
45 | |||
46 | void grpReadCheck(); | ||
47 | void grpWriteCheck(); | ||
48 | void grpExeCheck(); | ||
49 | |||
50 | void wrldReadCheck(); | ||
51 | void wrldWriteCheck(); | ||
52 | void wrldExeCheck(); | ||
53 | void accept(); | ||
54 | }; | ||
55 | |||
56 | #endif // FILEPERMISSIONS_H | ||
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp index 9439bb8..384d7da 100644 --- a/noncore/unsupported/filebrowser/filebrowser.cpp +++ b/noncore/unsupported/filebrowser/filebrowser.cpp | |||
@@ -11,25 +11,25 @@ | |||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "inlineedit.h" | 21 | #include "inlineedit.h" |
22 | #include "filebrowser.h" | 22 | #include "filebrowser.h" |
23 | 23 | #include "filePermissions.h" | |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/global.h> | 25 | #include <qpe/global.h> |
26 | #include <qpe/mimetype.h> | 26 | #include <qpe/mimetype.h> |
27 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
28 | 28 | ||
29 | #include <qcopchannel_qws.h> | 29 | #include <qcopchannel_qws.h> |
30 | #include <qmessagebox.h> | 30 | #include <qmessagebox.h> |
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qregexp.h> | 32 | #include <qregexp.h> |
33 | #include <qheader.h> | 33 | #include <qheader.h> |
34 | #include <qpe/qpetoolbar.h> | 34 | #include <qpe/qpetoolbar.h> |
35 | #include <qpopupmenu.h> | 35 | #include <qpopupmenu.h> |
@@ -51,531 +51,531 @@ FileItem::FileItem( QListView * parent, const QFileInfo & fi ) | |||
51 | : QListViewItem( parent ), | 51 | : QListViewItem( parent ), |
52 | fileInfo( fi ) | 52 | fileInfo( fi ) |
53 | { | 53 | { |
54 | QDate d = fi.lastModified().date(); | 54 | QDate d = fi.lastModified().date(); |
55 | 55 | ||
56 | setText( 0, fi.fileName() ); | 56 | setText( 0, fi.fileName() ); |
57 | setText( 1, sizeString( fi.size() ) + " " ); | 57 | setText( 1, sizeString( fi.size() ) + " " ); |
58 | setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); | 58 | setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); |
59 | 59 | ||
60 | MimeType mt(fi.filePath()); | 60 | MimeType mt(fi.filePath()); |
61 | 61 | ||
62 | if( fi.isDir() ) | 62 | if( fi.isDir() ) |
63 | setText( 3, "directory" ); | 63 | setText( 3, "directory" ); |
64 | else if( isLib() ) | 64 | else if( isLib() ) |
65 | setText( 3, "library" ); | 65 | setText( 3, "library" ); |
66 | else | 66 | else |
67 | setText( 3, mt.description() ); | 67 | setText( 3, mt.description() ); |
68 | 68 | ||
69 | QPixmap pm; | 69 | QPixmap pm; |
70 | if( fi.isDir() ){ | 70 | if( fi.isDir() ){ |
71 | if( !QDir( fi.filePath() ).isReadable() ) | 71 | if( !QDir( fi.filePath() ).isReadable() ) |
72 | pm = Resource::loadPixmap( "lockedfolder" ); | 72 | pm = Resource::loadPixmap( "lockedfolder" ); |
73 | else | 73 | else |
74 | pm = Resource::loadPixmap( "folder" ); | 74 | pm = Resource::loadPixmap( "folder" ); |
75 | } | 75 | } |
76 | else if( !fi.isReadable() ) | 76 | else if( !fi.isReadable() ) |
77 | pm = Resource::loadPixmap( "locked" ); | 77 | pm = Resource::loadPixmap( "locked" ); |
78 | else if( isLib() ) | 78 | else if( isLib() ) |
79 | pm = Resource::loadPixmap( "library" ); | 79 | pm = Resource::loadPixmap( "library" ); |
80 | else | 80 | else |
81 | pm = mt.pixmap(); | 81 | pm = mt.pixmap(); |
82 | if ( pm.isNull() ) | 82 | if ( pm.isNull() ) |
83 | pm = Resource::loadPixmap("UnknownDocument-14"); | 83 | pm = Resource::loadPixmap("UnknownDocument-14"); |
84 | setPixmap(0,pm); | 84 | setPixmap(0,pm); |
85 | } | 85 | } |
86 | 86 | ||
87 | QString FileItem::sizeString( unsigned int s ) | 87 | QString FileItem::sizeString( unsigned int s ) |
88 | { | 88 | { |
89 | double size = s; | 89 | double size = s; |
90 | 90 | ||
91 | if ( size > 1024 * 1024 * 1024 ) | 91 | if ( size > 1024 * 1024 * 1024 ) |
92 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; | 92 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; |
93 | else if ( size > 1024 * 1024 ) | 93 | else if ( size > 1024 * 1024 ) |
94 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; | 94 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; |
95 | else if ( size > 1024 ) | 95 | else if ( size > 1024 ) |
96 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; | 96 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; |
97 | else | 97 | else |
98 | return QString::number( size ) + "B"; | 98 | return QString::number( size ) + "B"; |
99 | } | 99 | } |
100 | 100 | ||
101 | QString FileItem::key( int column, bool ascending ) const | 101 | QString FileItem::key( int column, bool ascending ) const |
102 | { | 102 | { |
103 | QString tmp; | 103 | QString tmp; |
104 | 104 | ||
105 | ascending = ascending; | 105 | ascending = ascending; |
106 | 106 | ||
107 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name | 107 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name |
108 | // We want the directories to appear at the top of the list | 108 | // We want the directories to appear at the top of the list |
109 | tmp = (char) 0; | 109 | tmp = (char) 0; |
110 | return (tmp + text( column ).lower()); | 110 | return (tmp + text( column ).lower()); |
111 | } | 111 | } |
112 | else if( column == 2 ) { // Sort by date | 112 | else if( column == 2 ) { // Sort by date |
113 | QDateTime epoch( QDate( 1980, 1, 1 ) ); | 113 | QDateTime epoch( QDate( 1980, 1, 1 ) ); |
114 | tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); | 114 | tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); |
115 | return tmp; | 115 | return tmp; |
116 | } | 116 | } |
117 | else if( column == 1 ) { // Sort by size | 117 | else if( column == 1 ) { // Sort by size |
118 | return tmp.sprintf( "%08d", fileInfo.size() ); | 118 | return tmp.sprintf( "%08d", fileInfo.size() ); |
119 | } | 119 | } |
120 | 120 | ||
121 | return text( column ).lower(); | 121 | return text( column ).lower(); |
122 | } | 122 | } |
123 | 123 | ||
124 | bool FileItem::isLib() | 124 | bool FileItem::isLib() |
125 | { | 125 | { |
126 | // This is of course not foolproof | 126 | // This is of course not foolproof |
127 | if( !qstrncmp("lib", fileInfo.baseName(), 3) && | 127 | if( !qstrncmp("lib", fileInfo.baseName(), 3) && |
128 | ( fileInfo.extension().contains( "so" ) || | 128 | ( fileInfo.extension().contains( "so" ) || |
129 | fileInfo.extension().contains( "a" ) ) ) | 129 | fileInfo.extension().contains( "a" ) ) ) |
130 | return TRUE; | 130 | return TRUE; |
131 | else | 131 | else |
132 | return FALSE; | 132 | return FALSE; |
133 | } | 133 | } |
134 | 134 | ||
135 | int FileItem::launch() | 135 | int FileItem::launch() |
136 | { | 136 | { |
137 | DocLnk doc( fileInfo.filePath(), FALSE ); | 137 | DocLnk doc( fileInfo.filePath(), FALSE ); |
138 | doc.execute(); | 138 | doc.execute(); |
139 | listView()->clearSelection(); | 139 | listView()->clearSelection(); |
140 | return 1; | 140 | return 1; |
141 | } | 141 | } |
142 | 142 | ||
143 | bool FileItem::rename( const QString & name ) | 143 | bool FileItem::rename( const QString & name ) |
144 | { | 144 | { |
145 | QString oldpath, newpath; | 145 | QString oldpath, newpath; |
146 | 146 | ||
147 | if ( name.isEmpty() ) | 147 | if ( name.isEmpty() ) |
148 | return FALSE; | 148 | return FALSE; |
149 | 149 | ||
150 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) | 150 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) |
151 | return FALSE; | 151 | return FALSE; |
152 | 152 | ||
153 | oldpath = fileInfo.filePath(); | 153 | oldpath = fileInfo.filePath(); |
154 | newpath = fileInfo.dirPath() + "/" + name; | 154 | newpath = fileInfo.dirPath() + "/" + name; |
155 | 155 | ||
156 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) | 156 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) |
157 | return FALSE; | 157 | return FALSE; |
158 | else | 158 | else |
159 | return TRUE; | 159 | return TRUE; |
160 | } | 160 | } |
161 | 161 | ||
162 | // | 162 | // |
163 | // FileView | 163 | // FileView |
164 | // | 164 | // |
165 | FileView::FileView( const QString & dir, QWidget * parent, | 165 | FileView::FileView( const QString & dir, QWidget * parent, |
166 | const char * name ) | 166 | const char * name ) |
167 | : QListView( parent, name ), | 167 | : QListView( parent, name ), |
168 | menuTimer( this ), | 168 | menuTimer( this ), |
169 | le( NULL ), | 169 | le( NULL ), |
170 | itemToRename( NULL ) | 170 | itemToRename( NULL ) |
171 | { | 171 | { |
172 | addColumn( "Name" ); | 172 | addColumn( "Name" ); |
173 | addColumn( "Date" ); | 173 | addColumn( "Date" ); |
174 | addColumn( "Size" ); | 174 | addColumn( "Size" ); |
175 | addColumn( "Type" ); | 175 | addColumn( "Type" ); |
176 | 176 | ||
177 | setMultiSelection( TRUE ); | 177 | setMultiSelection( TRUE ); |
178 | header()->hide(); | 178 | header()->hide(); |
179 | 179 | ||
180 | setColumnWidthMode( 0, Manual ); | 180 | setColumnWidthMode( 0, Manual ); |
181 | setColumnWidthMode( 3, Manual ); | 181 | setColumnWidthMode( 3, Manual ); |
182 | 182 | ||
183 | // right align yize column | 183 | // right align yize column |
184 | setColumnAlignment( 1, AlignRight ); | 184 | setColumnAlignment( 1, AlignRight ); |
185 | 185 | ||
186 | generateDir( dir ); | 186 | generateDir( dir ); |
187 | 187 | ||
188 | connect( this, SIGNAL( clicked( QListViewItem * )), | 188 | connect( this, SIGNAL( clicked( QListViewItem * )), |
189 | SLOT( itemClicked( QListViewItem * )) ); | 189 | SLOT( itemClicked( QListViewItem * )) ); |
190 | connect( this, SIGNAL( doubleClicked( QListViewItem * )), | 190 | connect( this, SIGNAL( doubleClicked( QListViewItem * )), |
191 | SLOT( itemDblClicked( QListViewItem * )) ); | 191 | SLOT( itemDblClicked( QListViewItem * )) ); |
192 | connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); | 192 | connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); |
193 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); | 193 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); |
194 | } | 194 | } |
195 | 195 | ||
196 | void FileView::resizeEvent( QResizeEvent *e ) | 196 | void FileView::resizeEvent( QResizeEvent *e ) |
197 | { | 197 | { |
198 | setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); | 198 | setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); |
199 | 199 | ||
200 | // hide type column, we use it for "sort by type" only | 200 | // hide type column, we use it for "sort by type" only |
201 | setColumnWidth( 3, 0 ); | 201 | setColumnWidth( 3, 0 ); |
202 | QListView::resizeEvent( e ); | 202 | QListView::resizeEvent( e ); |
203 | } | 203 | } |
204 | 204 | ||
205 | void FileView::updateDir() | 205 | void FileView::updateDir() |
206 | { | 206 | { |
207 | generateDir( currentDir ); | 207 | generateDir( currentDir ); |
208 | } | 208 | } |
209 | 209 | ||
210 | void FileView::setDir( const QString & dir ) | 210 | void FileView::setDir( const QString & dir ) |
211 | { | 211 | { |
212 | if ( dir.startsWith( "/dev" ) ) { | 212 | if ( dir.startsWith( "/dev" ) ) { |
213 | QMessageBox::warning( this, tr( "File Manager" ), | 213 | QMessageBox::warning( this, tr( "File Manager" ), |
214 | tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); | 214 | tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); |
215 | return; | 215 | return; |
216 | } | 216 | } |
217 | dirHistory += currentDir; | 217 | dirHistory += currentDir; |
218 | generateDir( dir ); | 218 | generateDir( dir ); |
219 | } | 219 | } |
220 | 220 | ||
221 | void FileView::generateDir( const QString & dir ) | 221 | void FileView::generateDir( const QString & dir ) |
222 | { | 222 | { |
223 | QDir d( dir ); | 223 | QDir d( dir ); |
224 | 224 | ||
225 | if( d.exists() && !d.isReadable() ) return; | 225 | if( d.exists() && !d.isReadable() ) return; |
226 | 226 | ||
227 | currentDir = d.canonicalPath(); | 227 | currentDir = d.canonicalPath(); |
228 | 228 | ||
229 | d.setFilter( QDir::Dirs | QDir::Files ); | 229 | d.setFilter( QDir::Dirs | QDir::Files ); |
230 | d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | | 230 | d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | |
231 | QDir::Reversed ); | 231 | QDir::Reversed ); |
232 | 232 | ||
233 | const QFileInfoList * list = d.entryInfoList(); | 233 | const QFileInfoList * list = d.entryInfoList(); |
234 | QFileInfoListIterator it( *list ); | 234 | QFileInfoListIterator it( *list ); |
235 | QFileInfo *fi; | 235 | QFileInfo *fi; |
236 | 236 | ||
237 | clear(); | 237 | clear(); |
238 | while( (fi = it.current()) ){ | 238 | while( (fi = it.current()) ){ |
239 | if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ | 239 | if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ |
240 | ++it; | 240 | ++it; |
241 | continue; | 241 | continue; |
242 | } | 242 | } |
243 | (void) new FileItem( (QListView *) this, *fi ); | 243 | (void) new FileItem( (QListView *) this, *fi ); |
244 | ++it; | 244 | ++it; |
245 | } | 245 | } |
246 | 246 | ||
247 | emit dirChanged(); | 247 | emit dirChanged(); |
248 | } | 248 | } |
249 | 249 | ||
250 | void FileView::rename() | 250 | void FileView::rename() |
251 | { | 251 | { |
252 | itemToRename = (FileItem *) currentItem(); | 252 | itemToRename = (FileItem *) currentItem(); |
253 | const QPixmap * pm; | 253 | const QPixmap * pm; |
254 | int pmw; | 254 | int pmw; |
255 | 255 | ||
256 | if( itemToRename == NULL ) return; | 256 | if( itemToRename == NULL ) return; |
257 | 257 | ||
258 | if( ( pm = itemToRename->pixmap( 0 ) ) == NULL ) | 258 | if( ( pm = itemToRename->pixmap( 0 ) ) == NULL ) |
259 | pmw = 0; | 259 | pmw = 0; |
260 | else | 260 | else |
261 | pmw = pm->width(); | 261 | pmw = pm->width(); |
262 | 262 | ||
263 | ensureItemVisible( itemToRename ); | 263 | ensureItemVisible( itemToRename ); |
264 | horizontalScrollBar()->setValue( 0 ); | 264 | horizontalScrollBar()->setValue( 0 ); |
265 | horizontalScrollBar()->setEnabled( FALSE ); | 265 | horizontalScrollBar()->setEnabled( FALSE ); |
266 | verticalScrollBar()->setEnabled( FALSE ); | 266 | verticalScrollBar()->setEnabled( FALSE ); |
267 | 267 | ||
268 | selected = isSelected( itemToRename ); | 268 | selected = isSelected( itemToRename ); |
269 | setSelected( itemToRename, FALSE ); | 269 | setSelected( itemToRename, FALSE ); |
270 | 270 | ||
271 | if( le == NULL ){ | 271 | if( le == NULL ){ |
272 | le = new InlineEdit( this ); | 272 | le = new InlineEdit( this ); |
273 | le->setFrame( FALSE ); | 273 | le->setFrame( FALSE ); |
274 | connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) ); | 274 | connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) ); |
275 | } | 275 | } |
276 | 276 | ||
277 | QRect r = itemRect( itemToRename ); | 277 | QRect r = itemRect( itemToRename ); |
278 | r.setTop( r.top() + frameWidth() + 1 ); | 278 | r.setTop( r.top() + frameWidth() + 1 ); |
279 | r.setLeft( r.left() + frameWidth() + pmw ); | 279 | r.setLeft( r.left() + frameWidth() + pmw ); |
280 | r.setBottom( r.bottom() + frameWidth() ); | 280 | r.setBottom( r.bottom() + frameWidth() ); |
281 | r.setWidth( columnWidth( 0 ) - pmw ); | 281 | r.setWidth( columnWidth( 0 ) - pmw ); |
282 | 282 | ||
283 | le->setGeometry( r ); | 283 | le->setGeometry( r ); |
284 | le->setText( itemToRename->text( 0 ) ); | 284 | le->setText( itemToRename->text( 0 ) ); |
285 | le->selectAll(); | 285 | le->selectAll(); |
286 | le->show(); | 286 | le->show(); |
287 | le->setFocus(); | 287 | le->setFocus(); |
288 | } | 288 | } |
289 | 289 | ||
290 | void FileView::endRenaming() | 290 | void FileView::endRenaming() |
291 | { | 291 | { |
292 | if( le && itemToRename ){ | 292 | if( le && itemToRename ){ |
293 | le->hide(); | 293 | le->hide(); |
294 | setSelected( itemToRename, selected ); | 294 | setSelected( itemToRename, selected ); |
295 | 295 | ||
296 | if( !itemToRename->rename( le->text() ) ){ | 296 | if( !itemToRename->rename( le->text() ) ){ |
297 | QMessageBox::warning( this, tr( "Rename file" ), | 297 | QMessageBox::warning( this, tr( "Rename file" ), |
298 | tr( "Rename failed!" ), tr( "&Ok" ) ); | 298 | tr( "Rename failed!" ), tr( "&Ok" ) ); |
299 | } else { | 299 | } else { |
300 | updateDir(); | 300 | updateDir(); |
301 | } | 301 | } |
302 | itemToRename = NULL; | 302 | itemToRename = NULL; |
303 | horizontalScrollBar()->setEnabled( TRUE ); | 303 | horizontalScrollBar()->setEnabled( TRUE ); |
304 | verticalScrollBar()->setEnabled( TRUE ); | 304 | verticalScrollBar()->setEnabled( TRUE ); |
305 | } | 305 | } |
306 | } | 306 | } |
307 | 307 | ||
308 | void FileView::copy() | 308 | void FileView::copy() |
309 | { | 309 | { |
310 | // dont keep cut files any longer than necessary | 310 | // dont keep cut files any longer than necessary |
311 | // ##### a better inmplementation might be to rename the CUT file | 311 | // ##### a better inmplementation might be to rename the CUT file |
312 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. | 312 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. |
313 | system ( "rm -rf /tmp/qpemoving" ); | 313 | system ( "rm -rf /tmp/qpemoving" ); |
314 | 314 | ||
315 | FileItem * i; | 315 | FileItem * i; |
316 | 316 | ||
317 | if((i = (FileItem *) firstChild()) == 0) return; | 317 | if((i = (FileItem *) firstChild()) == 0) return; |
318 | 318 | ||
319 | flist.clear(); | 319 | flist.clear(); |
320 | while( i ){ | 320 | while( i ){ |
321 | if( i->isSelected() /*&& !i->isDir()*/ ){ | 321 | if( i->isSelected() /*&& !i->isDir()*/ ){ |
322 | flist += i->getFilePath(); | 322 | flist += i->getFilePath(); |
323 | } | 323 | } |
324 | i = (FileItem *) i->nextSibling(); | 324 | i = (FileItem *) i->nextSibling(); |
325 | } | 325 | } |
326 | } | 326 | } |
327 | 327 | ||
328 | void FileView::paste() | 328 | void FileView::paste() |
329 | { | 329 | { |
330 | int i, err; | 330 | int i, err; |
331 | QString cmd, dest, basename, cd = currentDir; | 331 | QString cmd, dest, basename, cd = currentDir; |
332 | 332 | ||
333 | if(cd == "/") cd = ""; | 333 | if(cd == "/") cd = ""; |
334 | 334 | ||
335 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { | 335 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { |
336 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); | 336 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); |
337 | 337 | ||
338 | dest = cd + "/" + basename; | 338 | dest = cd + "/" + basename; |
339 | if( QFile( dest ).exists() ){ | 339 | if( QFile( dest ).exists() ){ |
340 | i = 1; | 340 | i = 1; |
341 | dest = cd + "/Copy of " + basename; | 341 | dest = cd + "/Copy of " + basename; |
342 | while( QFile( dest ).exists() ){ | 342 | while( QFile( dest ).exists() ){ |
343 | dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++, | 343 | dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++, |
344 | (const char *) basename ); | 344 | (const char *) basename ); |
345 | } | 345 | } |
346 | } | 346 | } |
347 | 347 | ||
348 | // | 348 | // |
349 | // Copy a directory recursively using the "cp" command - | 349 | // Copy a directory recursively using the "cp" command - |
350 | // may have to be changed | 350 | // may have to be changed |
351 | // | 351 | // |
352 | if( QFileInfo( (*it) ).isDir() ){ | 352 | if( QFileInfo( (*it) ).isDir() ){ |
353 | cmd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\""; | 353 | cmd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\""; |
354 | err = system( (const char *) cmd ); | 354 | err = system( (const char *) cmd ); |
355 | } else if( !copyFile( dest, (*it) ) ){ | 355 | } else if( !copyFile( dest, (*it) ) ){ |
356 | err = -1; | 356 | err = -1; |
357 | } else { | 357 | } else { |
358 | err = 0; | 358 | err = 0; |
359 | } | 359 | } |
360 | 360 | ||
361 | if ( err != 0 ) { | 361 | if ( err != 0 ) { |
362 | QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"), | 362 | QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"), |
363 | tr("Ok") ); | 363 | tr("Ok") ); |
364 | break; | 364 | break; |
365 | } else { | 365 | } else { |
366 | updateDir(); | 366 | updateDir(); |
367 | QListViewItem * i = firstChild(); | 367 | QListViewItem * i = firstChild(); |
368 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); | 368 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); |
369 | 369 | ||
370 | while( i ){ | 370 | while( i ){ |
371 | if( i->text(0) == basename ){ | 371 | if( i->text(0) == basename ){ |
372 | setCurrentItem( i ); | 372 | setCurrentItem( i ); |
373 | ensureItemVisible( i ); | 373 | ensureItemVisible( i ); |
374 | break; | 374 | break; |
375 | } | 375 | } |
376 | i = i->nextSibling(); | 376 | i = i->nextSibling(); |
377 | } | 377 | } |
378 | } | 378 | } |
379 | } | 379 | } |
380 | } | 380 | } |
381 | 381 | ||
382 | bool FileView::copyFile( const QString & dest, const QString & src ) | 382 | bool FileView::copyFile( const QString & dest, const QString & src ) |
383 | { | 383 | { |
384 | char bf[ 50000 ]; | 384 | char bf[ 50000 ]; |
385 | int bytesRead; | 385 | int bytesRead; |
386 | bool success = TRUE; | 386 | bool success = TRUE; |
387 | struct stat status; | 387 | struct stat status; |
388 | 388 | ||
389 | QFile s( src ); | 389 | QFile s( src ); |
390 | QFile d( dest ); | 390 | QFile d( dest ); |
391 | 391 | ||
392 | if( s.open( IO_ReadOnly | IO_Raw ) && | 392 | if( s.open( IO_ReadOnly | IO_Raw ) && |
393 | d.open( IO_WriteOnly | IO_Raw ) ) | 393 | d.open( IO_WriteOnly | IO_Raw ) ) |
394 | { | 394 | { |
395 | while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == | 395 | while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == |
396 | sizeof( bf ) ) | 396 | sizeof( bf ) ) |
397 | { | 397 | { |
398 | if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ | 398 | if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ |
399 | success = FALSE; | 399 | success = FALSE; |
400 | break; | 400 | break; |
401 | } | 401 | } |
402 | } | 402 | } |
403 | if( success && (bytesRead > 0) ){ | 403 | if( success && (bytesRead > 0) ){ |
404 | d.writeBlock( bf, bytesRead ); | 404 | d.writeBlock( bf, bytesRead ); |
405 | } | 405 | } |
406 | } else { | 406 | } else { |
407 | success = FALSE; | 407 | success = FALSE; |
408 | } | 408 | } |
409 | 409 | ||
410 | // Set file permissions | 410 | // Set file permissions |
411 | if( stat( (const char *) src, &status ) == 0 ){ | 411 | if( stat( (const char *) src, &status ) == 0 ){ |
412 | chmod( (const char *) dest, status.st_mode ); | 412 | chmod( (const char *) dest, status.st_mode ); |
413 | } | 413 | } |
414 | 414 | ||
415 | return success; | 415 | return success; |
416 | } | 416 | } |
417 | 417 | ||
418 | void FileView::cut() | 418 | void FileView::cut() |
419 | { | 419 | { |
420 | int err; | 420 | int err; |
421 | // ##### a better inmplementation might be to rename the CUT file | 421 | // ##### a better inmplementation might be to rename the CUT file |
422 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. | 422 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. |
423 | QString cmd, dest, basename, cd = "/tmp/qpemoving"; | 423 | QString cmd, dest, basename, cd = "/tmp/qpemoving"; |
424 | QStringList newflist; | 424 | QStringList newflist; |
425 | newflist.clear(); | 425 | newflist.clear(); |
426 | 426 | ||
427 | cmd = "rm -rf " + cd; | 427 | cmd = "rm -rf " + cd; |
428 | system ( (const char *) cmd ); | 428 | system ( (const char *) cmd ); |
429 | cmd = "mkdir " + cd; | 429 | cmd = "mkdir " + cd; |
430 | system( (const char *) cmd ); | 430 | system( (const char *) cmd ); |
431 | 431 | ||
432 | // get the names of the files to cut | 432 | // get the names of the files to cut |
433 | FileItem * item; | 433 | FileItem * item; |
434 | 434 | ||
435 | if((item = (FileItem *) firstChild()) == 0) return; | 435 | if((item = (FileItem *) firstChild()) == 0) return; |
436 | 436 | ||
437 | flist.clear(); | 437 | flist.clear(); |
438 | while( item ){ | 438 | while( item ){ |
439 | if( item->isSelected() /*&& !item->isDir()*/ ){ | 439 | if( item->isSelected() /*&& !item->isDir()*/ ){ |
440 | flist += item->getFilePath(); | 440 | flist += item->getFilePath(); |
441 | } | 441 | } |
442 | item = (FileItem *) item->nextSibling(); | 442 | item = (FileItem *) item->nextSibling(); |
443 | } | 443 | } |
444 | 444 | ||
445 | // move these files into a tmp dir | 445 | // move these files into a tmp dir |
446 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { | 446 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { |
447 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); | 447 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); |
448 | 448 | ||
449 | dest = cd + "/" + basename; | 449 | dest = cd + "/" + basename; |
450 | 450 | ||
451 | newflist += dest; | 451 | newflist += dest; |
452 | 452 | ||
453 | cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\""; | 453 | cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\""; |
454 | err = system( (const char *) cmd ); | 454 | err = system( (const char *) cmd ); |
455 | 455 | ||
456 | if ( err != 0 ) { | 456 | if ( err != 0 ) { |
457 | QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"), | 457 | QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"), |
458 | tr("Ok") ); | 458 | tr("Ok") ); |
459 | break; | 459 | break; |
460 | } else { | 460 | } else { |
461 | updateDir(); | 461 | updateDir(); |
462 | QListViewItem * im = firstChild(); | 462 | QListViewItem * im = firstChild(); |
463 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); | 463 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); |
464 | 464 | ||
465 | while( im ){ | 465 | while( im ){ |
466 | if( im->text(0) == basename ){ | 466 | if( im->text(0) == basename ){ |
467 | setCurrentItem( im ); | 467 | setCurrentItem( im ); |
468 | ensureItemVisible( im ); | 468 | ensureItemVisible( im ); |
469 | break; | 469 | break; |
470 | } | 470 | } |
471 | im = im->nextSibling(); | 471 | im = im->nextSibling(); |
472 | } | 472 | } |
473 | } | 473 | } |
474 | } | 474 | } |
475 | 475 | ||
476 | // update the filelist to point to tmp dir so paste works nicely | 476 | // update the filelist to point to tmp dir so paste works nicely |
477 | flist = newflist; | 477 | flist = newflist; |
478 | } | 478 | } |
479 | 479 | ||
480 | void FileView::del() | 480 | void FileView::del() |
481 | { | 481 | { |
482 | FileItem * i; | 482 | FileItem * i; |
483 | QStringList fl; | 483 | QStringList fl; |
484 | QString cmd; | 484 | QString cmd; |
485 | int err; | 485 | int err; |
486 | 486 | ||
487 | if((i = (FileItem *) firstChild()) == 0) return; | 487 | if((i = (FileItem *) firstChild()) == 0) return; |
488 | 488 | ||
489 | while( i ){ | 489 | while( i ){ |
490 | if( i->isSelected() ){ | 490 | if( i->isSelected() ){ |
491 | fl += i->getFilePath(); | 491 | fl += i->getFilePath(); |
492 | } | 492 | } |
493 | i = (FileItem *) i->nextSibling(); | 493 | i = (FileItem *) i->nextSibling(); |
494 | } | 494 | } |
495 | if( fl.count() < 1 ) return; | 495 | if( fl.count() < 1 ) return; |
496 | 496 | ||
497 | if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"), | 497 | if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"), |
498 | tr("Yes"), tr("No") ) == 0) | 498 | tr("Yes"), tr("No") ) == 0) |
499 | { | 499 | { |
500 | // | 500 | // |
501 | // Dependant upon the "rm" command - will probably have to be replaced | 501 | // Dependant upon the "rm" command - will probably have to be replaced |
502 | // | 502 | // |
503 | for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { | 503 | for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { |
504 | cmd = "/bin/rm -rf \"" + (*it) + "\""; | 504 | cmd = "/bin/rm -rf \"" + (*it) + "\""; |
505 | err = system( (const char *) cmd ); | 505 | err = system( (const char *) cmd ); |
506 | if ( err != 0 ) { | 506 | if ( err != 0 ) { |
507 | QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"), | 507 | QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"), |
508 | tr("Ok") ); | 508 | tr("Ok") ); |
509 | break; | 509 | break; |
510 | } | 510 | } |
511 | } | 511 | } |
512 | updateDir(); | 512 | updateDir(); |
513 | } | 513 | } |
514 | } | 514 | } |
515 | 515 | ||
516 | void FileView::newFolder() | 516 | void FileView::newFolder() |
517 | { | 517 | { |
518 | int t = 1; | 518 | int t = 1; |
519 | FileItem * i; | 519 | FileItem * i; |
520 | QString nd = currentDir + "/NewFolder"; | 520 | QString nd = currentDir + "/NewFolder"; |
521 | 521 | ||
522 | while( QFile( nd ).exists() ){ | 522 | while( QFile( nd ).exists() ){ |
523 | nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ ); | 523 | nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ ); |
524 | } | 524 | } |
525 | 525 | ||
526 | if( mkdir( (const char *) nd, 0777 ) != 0){ | 526 | if( mkdir( (const char *) nd, 0777 ) != 0){ |
527 | QMessageBox::warning( this, tr( "New folder" ), | 527 | QMessageBox::warning( this, tr( "New folder" ), |
528 | tr( "Folder creation failed!" ), | 528 | tr( "Folder creation failed!" ), |
529 | tr( "Ok" ) ); | 529 | tr( "Ok" ) ); |
530 | return; | 530 | return; |
531 | } | 531 | } |
532 | updateDir(); | 532 | updateDir(); |
533 | 533 | ||
534 | if((i = (FileItem *) firstChild()) == 0) return; | 534 | if((i = (FileItem *) firstChild()) == 0) return; |
535 | 535 | ||
536 | while( i ){ | 536 | while( i ){ |
537 | if( i->isDir() && ( i->getFilePath() == nd ) ){ | 537 | if( i->isDir() && ( i->getFilePath() == nd ) ){ |
538 | setCurrentItem( i ); | 538 | setCurrentItem( i ); |
539 | rename(); | 539 | rename(); |
540 | break; | 540 | break; |
541 | } | 541 | } |
542 | i = (FileItem *) i->nextSibling(); | 542 | i = (FileItem *) i->nextSibling(); |
543 | } | 543 | } |
544 | } | 544 | } |
545 | 545 | ||
546 | void FileView::viewAsText() | 546 | void FileView::viewAsText() |
547 | { | 547 | { |
548 | FileItem * i = (FileItem *) currentItem(); | 548 | FileItem * i = (FileItem *) currentItem(); |
549 | Global::execute( "textedit -f ", i->getFilePath() ); | 549 | Global::execute( "textedit -f ", i->getFilePath() ); |
550 | } | 550 | } |
551 | 551 | ||
552 | void FileView::itemClicked( QListViewItem * i) | 552 | void FileView::itemClicked( QListViewItem * i) |
553 | { | 553 | { |
554 | FileItem * t = (FileItem *) i; | 554 | FileItem * t = (FileItem *) i; |
555 | 555 | ||
556 | if( t == NULL ) return; | 556 | if( t == NULL ) return; |
557 | if( t->isDir() ){ | 557 | if( t->isDir() ){ |
558 | setDir( t->getFilePath() ); | 558 | setDir( t->getFilePath() ); |
559 | } | 559 | } |
560 | } | 560 | } |
561 | 561 | ||
562 | void FileView::itemDblClicked( QListViewItem * i) | 562 | void FileView::itemDblClicked( QListViewItem * i) |
563 | { | 563 | { |
564 | FileItem * t = (FileItem *) i; | 564 | FileItem * t = (FileItem *) i; |
565 | 565 | ||
566 | if(t == NULL) return; | 566 | if(t == NULL) return; |
567 | if(t->launch() == -1){ | 567 | if(t->launch() == -1){ |
568 | QMessageBox::warning( this, tr( "Launch Application" ), | 568 | QMessageBox::warning( this, tr( "Launch Application" ), |
569 | tr( "Launch failed!" ), tr( "Ok" ) ); | 569 | tr( "Launch failed!" ), tr( "Ok" ) ); |
570 | } | 570 | } |
571 | } | 571 | } |
572 | 572 | ||
573 | void FileView::parentDir() | 573 | void FileView::parentDir() |
574 | { | 574 | { |
575 | setDir( currentDir + "./.." ); | 575 | setDir( currentDir + "./.." ); |
576 | } | 576 | } |
577 | 577 | ||
578 | void FileView::lastDir() | 578 | void FileView::lastDir() |
579 | { | 579 | { |
580 | if( dirHistory.count() == 0 ) return; | 580 | if( dirHistory.count() == 0 ) return; |
581 | 581 | ||
@@ -590,99 +590,100 @@ void FileView::contentsMousePressEvent( QMouseEvent * e ) | |||
590 | menuTimer.start( 750, TRUE ); | 590 | menuTimer.start( 750, TRUE ); |
591 | } | 591 | } |
592 | 592 | ||
593 | void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) | 593 | void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) |
594 | { | 594 | { |
595 | QListView::contentsMouseReleaseEvent( e ); | 595 | QListView::contentsMouseReleaseEvent( e ); |
596 | menuTimer.stop(); | 596 | menuTimer.stop(); |
597 | } | 597 | } |
598 | 598 | ||
599 | void FileView::cancelMenuTimer() | 599 | void FileView::cancelMenuTimer() |
600 | { | 600 | { |
601 | if( menuTimer.isActive() ) | 601 | if( menuTimer.isActive() ) |
602 | menuTimer.stop(); | 602 | menuTimer.stop(); |
603 | } | 603 | } |
604 | 604 | ||
605 | void FileView::addToDocuments() | 605 | void FileView::addToDocuments() |
606 | { | 606 | { |
607 | FileItem * i = (FileItem *) currentItem(); | 607 | FileItem * i = (FileItem *) currentItem(); |
608 | DocLnk f; | 608 | DocLnk f; |
609 | QString n = i->text(0); | 609 | QString n = i->text(0); |
610 | n.replace(QRegExp("\\..*"),""); | 610 | n.replace(QRegExp("\\..*"),""); |
611 | f.setName( n ); | 611 | f.setName( n ); |
612 | f.setFile( i->getFilePath() ); | 612 | f.setFile( i->getFilePath() ); |
613 | f.writeLink(); | 613 | f.writeLink(); |
614 | } | 614 | } |
615 | 615 | ||
616 | void FileView::run() | 616 | void FileView::run() |
617 | { | 617 | { |
618 | FileItem * i = (FileItem *) currentItem(); | 618 | FileItem * i = (FileItem *) currentItem(); |
619 | i->launch(); | 619 | i->launch(); |
620 | } | 620 | } |
621 | 621 | ||
622 | void FileView::showFileMenu() | 622 | void FileView::showFileMenu() |
623 | { | 623 | { |
624 | FileItem * i = (FileItem *) currentItem(); | 624 | FileItem * i = (FileItem *) currentItem(); |
625 | if ( !i ) | 625 | if ( !i ) |
626 | return; | 626 | return; |
627 | 627 | ||
628 | QPopupMenu * m = new QPopupMenu( this ); | 628 | QPopupMenu * m = new QPopupMenu( this ); |
629 | 629 | ||
630 | if ( !i->isDir() ) { | 630 | if ( !i->isDir() ) { |
631 | m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) ); | 631 | m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) ); |
632 | m->insertSeparator(); | 632 | m->insertSeparator(); |
633 | } | 633 | } |
634 | 634 | ||
635 | MimeType mt(i->getFilePath()); | 635 | MimeType mt(i->getFilePath()); |
636 | const AppLnk* app = mt.application(); | 636 | const AppLnk* app = mt.application(); |
637 | 637 | ||
638 | if ( !i->isDir() ) { | 638 | if ( !i->isDir() ) { |
639 | if ( app ) | 639 | if ( app ) |
640 | m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) ); | 640 | m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) ); |
641 | else if( i->isExecutable() ) | 641 | else if( i->isExecutable() ) |
642 | m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) ); | 642 | m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) ); |
643 | 643 | ||
644 | m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), | 644 | m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), |
645 | this, SLOT( viewAsText() ) ); | 645 | this, SLOT( viewAsText() ) ); |
646 | 646 | ||
647 | m->insertSeparator(); | 647 | m->insertSeparator(); |
648 | } | 648 | } |
649 | 649 | ||
650 | m->insertItem( tr( "Rename" ), this, SLOT( rename() ) ); | 650 | m->insertItem( tr( "Rename" ), this, SLOT( rename() ) ); |
651 | m->insertItem( Resource::loadPixmap("cut"), | 651 | m->insertItem( Resource::loadPixmap("cut"), |
652 | tr( "Cut" ), this, SLOT( cut() ) ); | 652 | tr( "Cut" ), this, SLOT( cut() ) ); |
653 | m->insertItem( Resource::loadPixmap("copy"), | 653 | m->insertItem( Resource::loadPixmap("copy"), |
654 | tr( "Copy" ), this, SLOT( copy() ) ); | 654 | tr( "Copy" ), this, SLOT( copy() ) ); |
655 | m->insertItem( Resource::loadPixmap("paste"), | 655 | m->insertItem( Resource::loadPixmap("paste"), |
656 | tr( "Paste" ), this, SLOT( paste() ) ); | 656 | tr( "Paste" ), this, SLOT( paste() ) ); |
657 | m->insertItem( tr( "change permissions" ), this, SLOT( chPerm() ) ); | ||
657 | m->insertItem( tr( "Delete" ), this, SLOT( del() ) ); | 658 | m->insertItem( tr( "Delete" ), this, SLOT( del() ) ); |
658 | m->insertSeparator(); | 659 | m->insertSeparator(); |
659 | m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) ); | 660 | m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) ); |
660 | m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) ); | 661 | m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) ); |
661 | m->popup( QCursor::pos() ); | 662 | m->popup( QCursor::pos() ); |
662 | } | 663 | } |
663 | 664 | ||
664 | // | 665 | // |
665 | // FileBrowser | 666 | // FileBrowser |
666 | // | 667 | // |
667 | 668 | ||
668 | FileBrowser::FileBrowser( QWidget * parent, | 669 | FileBrowser::FileBrowser( QWidget * parent, |
669 | const char * name, WFlags f ) : | 670 | const char * name, WFlags f ) : |
670 | QMainWindow( parent, name, f ) | 671 | QMainWindow( parent, name, f ) |
671 | { | 672 | { |
672 | init( QDir::current().canonicalPath() ); | 673 | init( QDir::current().canonicalPath() ); |
673 | } | 674 | } |
674 | 675 | ||
675 | FileBrowser::FileBrowser( const QString & dir, QWidget * parent, | 676 | FileBrowser::FileBrowser( const QString & dir, QWidget * parent, |
676 | const char * name, WFlags f ) : | 677 | const char * name, WFlags f ) : |
677 | QMainWindow( parent, name, f ) | 678 | QMainWindow( parent, name, f ) |
678 | { | 679 | { |
679 | init( dir ); | 680 | init( dir ); |
680 | } | 681 | } |
681 | 682 | ||
682 | void FileBrowser::init(const QString & dir) | 683 | void FileBrowser::init(const QString & dir) |
683 | { | 684 | { |
684 | setCaption( tr("File Manager") ); | 685 | setCaption( tr("File Manager") ); |
685 | setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); | 686 | setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); |
686 | 687 | ||
687 | fileView = new FileView( dir, this ); | 688 | fileView = new FileView( dir, this ); |
688 | fileView->setAllColumnsShowFocus( TRUE ); | 689 | fileView->setAllColumnsShowFocus( TRUE ); |
@@ -703,100 +704,100 @@ void FileBrowser::init(const QString & dir) | |||
703 | sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) ); | 704 | sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) ); |
704 | sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) ); | 705 | sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) ); |
705 | sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) ); | 706 | sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) ); |
706 | sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) ); | 707 | sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) ); |
707 | sortMenu->insertSeparator(); | 708 | sortMenu->insertSeparator(); |
708 | sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) ); | 709 | sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) ); |
709 | sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE ); | 710 | sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE ); |
710 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); | 711 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); |
711 | 712 | ||
712 | toolBar = new QPEToolBar( this ); | 713 | toolBar = new QPEToolBar( this ); |
713 | 714 | ||
714 | lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ), | 715 | lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ), |
715 | QString::null, 0, this, 0 ); | 716 | QString::null, 0, this, 0 ); |
716 | connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) ); | 717 | connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) ); |
717 | lastAction->addTo( toolBar ); | 718 | lastAction->addTo( toolBar ); |
718 | lastAction->setEnabled( FALSE ); | 719 | lastAction->setEnabled( FALSE ); |
719 | 720 | ||
720 | upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ), | 721 | upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ), |
721 | QString::null, 0, this, 0 ); | 722 | QString::null, 0, this, 0 ); |
722 | connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) ); | 723 | connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) ); |
723 | upAction->addTo( toolBar ); | 724 | upAction->addTo( toolBar ); |
724 | 725 | ||
725 | QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ), | 726 | QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ), |
726 | QString::null, 0, this, 0 ); | 727 | QString::null, 0, this, 0 ); |
727 | connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) ); | 728 | connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) ); |
728 | a->addTo( toolBar ); | 729 | a->addTo( toolBar ); |
729 | 730 | ||
730 | a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ), | 731 | a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ), |
731 | QString::null, 0, this, 0 ); | 732 | QString::null, 0, this, 0 ); |
732 | connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) ); | 733 | connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) ); |
733 | a->addTo( toolBar ); | 734 | a->addTo( toolBar ); |
734 | 735 | ||
735 | a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ), | 736 | a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ), |
736 | QString::null, 0, this, 0 ); | 737 | QString::null, 0, this, 0 ); |
737 | connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) ); | 738 | connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) ); |
738 | a->addTo( toolBar ); | 739 | a->addTo( toolBar ); |
739 | 740 | ||
740 | pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), | 741 | pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), |
741 | QString::null, 0, this, 0 ); | 742 | QString::null, 0, this, 0 ); |
742 | connect( pasteAction, SIGNAL( activated() ), fileView, SLOT( paste() ) ); | 743 | connect( pasteAction, SIGNAL( activated() ), fileView, SLOT( paste() ) ); |
743 | pasteAction->addTo( toolBar ); | 744 | pasteAction->addTo( toolBar ); |
744 | 745 | ||
745 | 746 | ||
746 | connect( fileView, SIGNAL( dirChanged() ), SLOT( updateDirMenu() ) ); | 747 | connect( fileView, SIGNAL( dirChanged() ), SLOT( updateDirMenu() ) ); |
747 | updateDirMenu(); | 748 | updateDirMenu(); |
748 | 749 | ||
749 | QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); | 750 | QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); |
750 | connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 751 | connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), |
751 | this, SLOT(pcmciaMessage( const QCString &, const QByteArray &)) ); | 752 | this, SLOT(pcmciaMessage( const QCString &, const QByteArray &)) ); |
752 | } | 753 | } |
753 | 754 | ||
754 | void FileBrowser::pcmciaMessage( const QCString &msg, const QByteArray &) | 755 | void FileBrowser::pcmciaMessage( const QCString &msg, const QByteArray &) |
755 | { | 756 | { |
756 | if ( msg == "mtabChanged()" ) { | 757 | if ( msg == "mtabChanged()" ) { |
757 | // ## Only really needed if current dir is on a card | 758 | // ## Only really needed if current dir is on a card |
758 | fileView->updateDir(); | 759 | fileView->updateDir(); |
759 | } | 760 | } |
760 | } | 761 | } |
761 | 762 | ||
762 | void FileBrowser::dirSelected( int id ) | 763 | void FileBrowser::dirSelected( int id ) |
763 | { | 764 | { |
764 | int i = 0, j; | 765 | int i = 0, j; |
765 | QString dir; | 766 | QString dir; |
766 | 767 | ||
767 | // Bulid target dir from menu | 768 | // Bulid target dir from menu |
768 | while( (j = dirMenu->idAt( i )) != id ){ | 769 | while( (j = dirMenu->idAt( i )) != id ){ |
769 | dir += dirMenu->text( j ).stripWhiteSpace(); | 770 | dir += dirMenu->text( j ).stripWhiteSpace(); |
770 | if( dirMenu->text( j ) != "/" ) dir += "/"; | 771 | if( dirMenu->text( j ) != "/" ) dir += "/"; |
771 | i++; | 772 | i++; |
772 | } | 773 | } |
773 | dir += dirMenu->text( dirMenu->idAt( i ) ).stripWhiteSpace(); | 774 | dir += dirMenu->text( dirMenu->idAt( i ) ).stripWhiteSpace(); |
774 | 775 | ||
775 | fileView->setDir( dir ); | 776 | fileView->setDir( dir ); |
776 | } | 777 | } |
777 | 778 | ||
778 | void FileBrowser::updateDirMenu() | 779 | void FileBrowser::updateDirMenu() |
779 | { | 780 | { |
780 | QString spc, cd = fileView->cd(); | 781 | QString spc, cd = fileView->cd(); |
781 | QStringList l = QStringList::split( "/", cd ); | 782 | QStringList l = QStringList::split( "/", cd ); |
782 | int i = 0; | 783 | int i = 0; |
783 | 784 | ||
784 | dirMenu->clear(); | 785 | dirMenu->clear(); |
785 | dirMenu->insertItem( tr( "/" ), this, SLOT( dirSelected(int) ) ); | 786 | dirMenu->insertItem( tr( "/" ), this, SLOT( dirSelected(int) ) ); |
786 | 787 | ||
787 | for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { | 788 | for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { |
788 | spc.fill( ' ', i++); | 789 | spc.fill( ' ', i++); |
789 | dirMenu->insertItem( spc + (*it), this, | 790 | dirMenu->insertItem( spc + (*it), this, |
790 | SLOT( dirSelected(int) ) ); | 791 | SLOT( dirSelected(int) ) ); |
791 | } | 792 | } |
792 | dirMenu->setItemChecked( dirMenu->idAt( l.count() ), TRUE ); | 793 | dirMenu->setItemChecked( dirMenu->idAt( l.count() ), TRUE ); |
793 | 794 | ||
794 | lastAction->setEnabled( fileView->history().count() != 0 ); | 795 | lastAction->setEnabled( fileView->history().count() != 0 ); |
795 | upAction->setEnabled( cd != "/" ); | 796 | upAction->setEnabled( cd != "/" ); |
796 | } | 797 | } |
797 | 798 | ||
798 | void FileBrowser::sortName() | 799 | void FileBrowser::sortName() |
799 | { | 800 | { |
800 | fileView->setSorting( 0, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); | 801 | fileView->setSorting( 0, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); |
801 | fileView->sort(); | 802 | fileView->sort(); |
802 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); | 803 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); |
@@ -831,20 +832,49 @@ void FileBrowser::sortType() | |||
831 | fileView->sort(); | 832 | fileView->sort(); |
832 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); | 833 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); |
833 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); | 834 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); |
834 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); | 835 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); |
835 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), TRUE ); | 836 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), TRUE ); |
836 | } | 837 | } |
837 | 838 | ||
838 | void FileBrowser::updateSorting() | 839 | void FileBrowser::updateSorting() |
839 | { | 840 | { |
840 | sortMenu->setItemChecked( sortMenu->idAt( 5 ), !sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); | 841 | sortMenu->setItemChecked( sortMenu->idAt( 5 ), !sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); |
841 | 842 | ||
842 | if ( sortMenu->isItemChecked( sortMenu->idAt( 0 ) ) ) | 843 | if ( sortMenu->isItemChecked( sortMenu->idAt( 0 ) ) ) |
843 | sortName(); | 844 | sortName(); |
844 | else if ( sortMenu->isItemChecked( sortMenu->idAt( 1 ) ) ) | 845 | else if ( sortMenu->isItemChecked( sortMenu->idAt( 1 ) ) ) |
845 | sortSize(); | 846 | sortSize(); |
846 | else if ( sortMenu->isItemChecked( sortMenu->idAt( 2 ) ) ) | 847 | else if ( sortMenu->isItemChecked( sortMenu->idAt( 2 ) ) ) |
847 | sortDate(); | 848 | sortDate(); |
848 | else | 849 | else |
849 | sortType(); | 850 | sortType(); |
851 | } | ||
852 | |||
853 | void FileView::chPerm() { | ||
854 | FileItem * i; | ||
855 | QStringList fl; | ||
856 | QString cmd; | ||
857 | int err; | ||
858 | |||
859 | if((i = (FileItem *) firstChild()) == 0) return; | ||
860 | |||
861 | while( i ){ | ||
862 | if( i->isSelected() ){ | ||
863 | fl += i->getFilePath(); | ||
864 | } | ||
865 | i = (FileItem *) i->nextSibling(); | ||
866 | } | ||
867 | if( fl.count() < 1 ) return; | ||
868 | if( QMessageBox::warning( this, tr("Change permissions"), tr("Are you sure?"), | ||
869 | tr("Yes"), tr("No") ) == 0) { | ||
870 | for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { | ||
871 | filePermissions *filePerm; | ||
872 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(*it)); | ||
873 | filePerm->exec(); | ||
874 | if( filePerm) | ||
875 | delete filePerm; | ||
876 | break; | ||
877 | } | ||
878 | updateDir(); | ||
879 | } | ||
850 | } | 880 | } |
diff --git a/noncore/unsupported/filebrowser/filebrowser.h b/noncore/unsupported/filebrowser/filebrowser.h index 2e9e444..c214dbe 100644 --- a/noncore/unsupported/filebrowser/filebrowser.h +++ b/noncore/unsupported/filebrowser/filebrowser.h | |||
@@ -45,42 +45,42 @@ public: | |||
45 | private: | 45 | private: |
46 | QString sizeString( unsigned int size ); | 46 | QString sizeString( unsigned int size ); |
47 | QFileInfo fileInfo; | 47 | QFileInfo fileInfo; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | 50 | ||
51 | class FileView : public QListView | 51 | class FileView : public QListView |
52 | { | 52 | { |
53 | Q_OBJECT | 53 | Q_OBJECT |
54 | 54 | ||
55 | public: | 55 | public: |
56 | FileView( const QString & dir, QWidget * parent = 0, | 56 | FileView( const QString & dir, QWidget * parent = 0, |
57 | const char * name = 0 ); | 57 | const char * name = 0 ); |
58 | void setDir( const QString & dir ); | 58 | void setDir( const QString & dir ); |
59 | QString cd(){ return currentDir; } | 59 | QString cd(){ return currentDir; } |
60 | QStringList history() const { return dirHistory; } | 60 | QStringList history() const { return dirHistory; } |
61 | 61 | ||
62 | public slots: | 62 | public slots: |
63 | void updateDir(); | 63 | void updateDir(); |
64 | void parentDir(); | 64 | void parentDir(); |
65 | void lastDir(); | 65 | void lastDir(); |
66 | 66 | ||
67 | void rename(); | 67 | void rename(); |
68 | void copy(); | 68 | void copy(); |
69 | void paste(); | 69 | void paste(); |
70 | void del(); | 70 | void del(); |
71 | void cut(); | 71 | void cut(); |
72 | void newFolder(); | 72 | void newFolder(); |
73 | void viewAsText(); | 73 | void viewAsText(); |
74 | 74 | void chPerm(); | |
75 | protected: | 75 | protected: |
76 | void generateDir( const QString & dir ); | 76 | void generateDir( const QString & dir ); |
77 | void resizeEvent( QResizeEvent* ); | 77 | void resizeEvent( QResizeEvent* ); |
78 | void contentsMousePressEvent( QMouseEvent * e ); | 78 | void contentsMousePressEvent( QMouseEvent * e ); |
79 | void contentsMouseReleaseEvent( QMouseEvent * e ); | 79 | void contentsMouseReleaseEvent( QMouseEvent * e ); |
80 | 80 | ||
81 | protected slots: | 81 | protected slots: |
82 | void itemClicked( QListViewItem * i ); | 82 | void itemClicked( QListViewItem * i ); |
83 | void itemDblClicked( QListViewItem * i ); | 83 | void itemDblClicked( QListViewItem * i ); |
84 | void showFileMenu(); | 84 | void showFileMenu(); |
85 | void cancelMenuTimer(); | 85 | void cancelMenuTimer(); |
86 | void selectAll(){ QListView::selectAll( TRUE ); } | 86 | void selectAll(){ QListView::selectAll( TRUE ); } |
@@ -102,35 +102,35 @@ private: | |||
102 | signals: | 102 | signals: |
103 | void dirChanged(); | 103 | void dirChanged(); |
104 | void textViewActivated( QWidget * w ); | 104 | void textViewActivated( QWidget * w ); |
105 | void textViewDeactivated(); | 105 | void textViewDeactivated(); |
106 | }; | 106 | }; |
107 | 107 | ||
108 | class FileBrowser : public QMainWindow | 108 | class FileBrowser : public QMainWindow |
109 | { | 109 | { |
110 | Q_OBJECT | 110 | Q_OBJECT |
111 | 111 | ||
112 | public: | 112 | public: |
113 | FileBrowser( QWidget * parent = 0, | 113 | FileBrowser( QWidget * parent = 0, |
114 | const char * name = 0, WFlags f = 0 ); | 114 | const char * name = 0, WFlags f = 0 ); |
115 | FileBrowser( const QString & dir, QWidget * parent = 0, | 115 | FileBrowser( const QString & dir, QWidget * parent = 0, |
116 | const char * name = 0, WFlags f = 0 ); | 116 | const char * name = 0, WFlags f = 0 ); |
117 | private: | 117 | private: |
118 | void init(const QString & dir); | 118 | void init(const QString & dir); |
119 | QString fileToCopy; | 119 | QString fileToCopy; |
120 | QPopupMenu * dirMenu, * sortMenu; | 120 | QPopupMenu * dirMenu, * sortMenu; |
121 | FileView * fileView; | 121 | FileView * fileView; |
122 | QAction * pasteAction; | 122 | QAction * pasteAction; |
123 | QAction*lastAction; | 123 | QAction *lastAction; |
124 | QAction*upAction; | 124 | QAction *upAction; |
125 | 125 | ||
126 | bool copyFile( const QString & dest, const QString & src ); | 126 | bool copyFile( const QString & dest, const QString & src ); |
127 | 127 | ||
128 | private slots: | 128 | private slots: |
129 | void pcmciaMessage( const QCString &msg, const QByteArray &); | 129 | void pcmciaMessage( const QCString &msg, const QByteArray &); |
130 | 130 | ||
131 | void sortName(); | 131 | void sortName(); |
132 | void sortDate(); | 132 | void sortDate(); |
133 | void sortSize(); | 133 | void sortSize(); |
134 | void sortType(); | 134 | void sortType(); |
135 | void updateSorting(); | 135 | void updateSorting(); |
136 | 136 | ||
diff --git a/noncore/unsupported/filebrowser/filebrowser.pro b/noncore/unsupported/filebrowser/filebrowser.pro index 5d8f140..65e51a5 100644 --- a/noncore/unsupported/filebrowser/filebrowser.pro +++ b/noncore/unsupported/filebrowser/filebrowser.pro | |||
@@ -1,12 +1,9 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | CONFIG = qt warn_on release | 2 | CONFIG = qt warn_on release |
3 | DESTDIR = $(OPIEDIR)/bin | 3 | DESTDIR = $(OPIEDIR)/bin |
4 | HEADERS = inlineedit.h \ | 4 | HEADERS = inlineedit.h filebrowser.h filePermissions.h |
5 | filebrowser.h | 5 | SOURCES = filebrowser.cpp inlineedit.cpp filePermissions.cpp main.cpp |
6 | SOURCES = filebrowser.cpp \ | ||
7 | inlineedit.cpp \ | ||
8 | main.cpp | ||
9 | INCLUDEPATH += $(OPIEDIR)/include | 6 | INCLUDEPATH += $(OPIEDIR)/include |
10 | DEPENDPATH+= $(OPIEDIR)/include | 7 | DEPENDPATH+= $(OPIEDIR)/include |
11 | LIBS += -lqpe | 8 | LIBS += -lqpe |
12 | INTERFACES= | 9 | INTERFACES= |