-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.cpp | 171 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.h | 33 |
2 files changed, 178 insertions, 26 deletions
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp index 8c01655..10e50f0 100644 --- a/noncore/unsupported/filebrowser/filebrowser.cpp +++ b/noncore/unsupported/filebrowser/filebrowser.cpp | |||
@@ -20,2 +20,3 @@ | |||
20 | 20 | ||
21 | |||
21 | #include "inlineedit.h" | 22 | #include "inlineedit.h" |
@@ -45,2 +46,3 @@ | |||
45 | #include <qpainter.h> | 46 | #include <qpainter.h> |
47 | #include <qprogressbar.h> | ||
46 | 48 | ||
@@ -49,2 +51,3 @@ | |||
49 | #include <sys/stat.h> | 51 | #include <sys/stat.h> |
52 | #include <qpe/qpeapplication.h> | ||
50 | 53 | ||
@@ -85,3 +88,5 @@ FileItem::FileItem( QListView * parent, const QFileInfo & fi ) | |||
85 | pm = Resource::loadPixmap( "library" ); | 88 | pm = Resource::loadPixmap( "library" ); |
86 | else | 89 | else if( ((FileView* )parent)->getShowThumbnails() && mt.id().contains(QRegExp("^image/", FALSE, FALSE)) ) |
90 | pm = drawThumbnail(fi); | ||
91 | else | ||
87 | pm = mt.pixmap(); | 92 | pm = mt.pixmap(); |
@@ -89,2 +94,3 @@ FileItem::FileItem( QListView * parent, const QFileInfo & fi ) | |||
89 | pm = Resource::loadPixmap("UnknownDocument-14"); | 94 | pm = Resource::loadPixmap("UnknownDocument-14"); |
95 | |||
90 | if( fi.isSymLink() ){ | 96 | if( fi.isSymLink() ){ |
@@ -174,2 +180,53 @@ bool FileItem::rename( const QString & name ) | |||
174 | 180 | ||
181 | QPixmap FileItem::drawThumbnail(const QFileInfo &file) { | ||
182 | |||
183 | /* | ||
184 | * this thing is sloooooow, and it also doesn't load | ||
185 | * dynamicly (like a web browser). if anyone knows how to | ||
186 | * do that, please do! | ||
187 | */ | ||
188 | QString cacheDir = "/tmp/filebrowserThumbnailCache"; | ||
189 | QFileInfo cachedFile (cacheDir + file.filePath()); | ||
190 | |||
191 | if (cachedFile.exists() && cachedFile.lastModified() == file.lastModified()) { | ||
192 | |||
193 | QPixmap cachedImage (cachedFile.filePath()); | ||
194 | return cachedImage; | ||
195 | } | ||
196 | else { | ||
197 | |||
198 | QImage image (file.filePath()); | ||
199 | |||
200 | // if inside of cache dir, don't render thumbnails! recursive error! | ||
201 | if (image.isNull() || file.filePath().contains(QRegExp("^" + cacheDir))) { | ||
202 | DocLnk doc (file.filePath()); | ||
203 | return doc.pixmap(); | ||
204 | } | ||
205 | Config cfg("Filebrowser"); | ||
206 | cfg.setGroup("View"); | ||
207 | int size; | ||
208 | size =cfg.readNumEntry("ThumbSize", 72); | ||
209 | QPixmap thumb (size, size); | ||
210 | |||
211 | double scale = (double)image.height() / (double)image.width(); | ||
212 | int newHeight = int(size * scale); | ||
213 | thumb.convertFromImage (image.smoothScale(size, newHeight)); | ||
214 | |||
215 | if (!cachedFile.dir().exists()) { | ||
216 | QString cmd = "/bin/mkdir -p \"" + cachedFile.dirPath() +"\""; | ||
217 | system( (const char *) cmd ); | ||
218 | } | ||
219 | |||
220 | if (thumb.save(cachedFile.filePath(), QPixmap::imageFormat(file.filePath()), 70)) { | ||
221 | // make thumbnail modify time the same as the image | ||
222 | QString cmd = "/bin/touch -r \"" + file.filePath() +"\" " + | ||
223 | "\"" + cachedFile.filePath() + "\""; | ||
224 | system( (const char *) cmd ); | ||
225 | |||
226 | } | ||
227 | |||
228 | return thumb; | ||
229 | } | ||
230 | } | ||
231 | |||
175 | // | 232 | // |
@@ -179,3 +236,3 @@ FileView::FileView( const QString & dir, QWidget * parent, | |||
179 | const char * name, | 236 | const char * name, |
180 | bool hidden, bool symlinks ) | 237 | bool hidden, bool symlinks, bool thumbnails ) |
181 | : QListView( parent, name ), | 238 | : QListView( parent, name ), |
@@ -185,3 +242,4 @@ FileView::FileView( const QString & dir, QWidget * parent, | |||
185 | showHidden( hidden ), | 242 | showHidden( hidden ), |
186 | showSymlinks( symlinks), | 243 | showSymlinks( symlinks ), |
244 | showThumbnails( thumbnails ), | ||
187 | menuKeepsOpen( FALSE ) | 245 | menuKeepsOpen( FALSE ) |
@@ -255,3 +313,2 @@ void FileView::generateDir( const QString & dir ) | |||
255 | 313 | ||
256 | |||
257 | const QFileInfoList * list = d.entryInfoList(); | 314 | const QFileInfoList * list = d.entryInfoList(); |
@@ -260,5 +317,18 @@ void FileView::generateDir( const QString & dir ) | |||
260 | 317 | ||
318 | QProgressBar *thumbProgress = 0; | ||
319 | if (showThumbnails) { | ||
320 | |||
321 | thumbProgress = new QProgressBar(it.count(), this); | ||
322 | thumbProgress->show(); | ||
323 | } | ||
324 | |||
261 | clear(); | 325 | clear(); |
262 | while( (fi = it.current()) ){ | 326 | |
263 | if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ | 327 | int fileCount = 1; // used in the thumbnail progress meter |
328 | while( (fi = it.current()) ){ | ||
329 | if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ | ||
330 | ++it; | ||
331 | continue; | ||
332 | } | ||
333 | if(!showSymlinks && fi->isSymLink()){ | ||
264 | ++it; | 334 | ++it; |
@@ -266,10 +336,18 @@ void FileView::generateDir( const QString & dir ) | |||
266 | } | 336 | } |
267 | if(!showSymlinks && fi->isSymLink()){ | 337 | // thumbnail progress |
338 | if (showThumbnails) { | ||
339 | |||
340 | thumbProgress->setProgress(fileCount); | ||
341 | } | ||
342 | (void) new FileItem( (QListView *) this, *fi ); | ||
343 | |||
268 | ++it; | 344 | ++it; |
269 | continue; | 345 | ++fileCount; |
346 | } | ||
347 | |||
348 | if (showThumbnails) { | ||
349 | thumbProgress->close(); | ||
270 | } | 350 | } |
271 | (void) new FileItem( (QListView *) this, *fi ); | ||
272 | ++it; | ||
273 | } | ||
274 | emit dirChanged(); | 351 | emit dirChanged(); |
352 | |||
275 | } | 353 | } |
@@ -465,2 +543,21 @@ void FileView::cut() | |||
465 | while( item ){ | 543 | while( item ){ |
544 | if( ite | ||
545 | // ##### a better inmplementation might be to rename the CUT file | ||
546 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. | ||
547 | QString cmd, dest, basename, cd = "/tmp/qpemoving"; | ||
548 | QStringList newflist; | ||
549 | newflist.clear(); | ||
550 | |||
551 | cmd = "rm -rf " + cd; | ||
552 | system ( (const char *) cmd ); | ||
553 | cmd = "mkdir " + cd; | ||
554 | system( (const char *) cmd ); | ||
555 | |||
556 | // get the names of the files to cut | ||
557 | FileItem * item; | ||
558 | |||
559 | if((item = (FileItem *) firstChild()) == 0) return; | ||
560 | |||
561 | flist.clear(); | ||
562 | while( item ){ | ||
466 | if( item->isSelected() /*&& !item->isDir()*/ ){ | 563 | if( item->isSelected() /*&& !item->isDir()*/ ){ |
@@ -715,2 +812,7 @@ void FileView::setShowSymlinks(bool symlinks) | |||
715 | 812 | ||
813 | void FileView::setShowThumbnails(bool thumbnails) | ||
814 | { | ||
815 | showThumbnails=thumbnails; | ||
816 | } | ||
817 | |||
716 | void FileView::setMenuKeepsOpen(bool keepOpen) | 818 | void FileView::setMenuKeepsOpen(bool keepOpen) |
@@ -738,2 +840,4 @@ void FileBrowser::init(const QString & dir) | |||
738 | setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); | 840 | setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); |
841 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | ||
842 | |||
739 | 843 | ||
@@ -743,2 +847,3 @@ void FileBrowser::init(const QString & dir) | |||
743 | bool showSymlinks=(cfg.readEntry("Symlinks","FALSE") == "TRUE"); | 847 | bool showSymlinks=(cfg.readEntry("Symlinks","FALSE") == "TRUE"); |
848 | bool showThumbnails=(cfg.readEntry("Thumbnails","FALSE") == "TRUE"); | ||
744 | 849 | ||
@@ -748,3 +853,3 @@ void FileBrowser::init(const QString & dir) | |||
748 | 853 | ||
749 | fileView = new FileView( dir, this, 0, showHidden, showSymlinks ); | 854 | fileView = new FileView( dir, this, 0, showHidden, showSymlinks, showThumbnails ); |
750 | fileView->setAllColumnsShowFocus( TRUE ); | 855 | fileView->setAllColumnsShowFocus( TRUE ); |
@@ -778,4 +883,6 @@ void FileBrowser::init(const QString & dir) | |||
778 | viewMenu->insertItem( tr( "Symlinks"), this, SLOT( updateShowSymlinks() ) ); | 883 | viewMenu->insertItem( tr( "Symlinks"), this, SLOT( updateShowSymlinks() ) ); |
884 | viewMenu->insertItem( tr( "Thumbnails"), this, SLOT( updateShowThumbnails() ) ); | ||
779 | viewMenu->setItemChecked( viewMenu->idAt( 0 ), showHidden ); | 885 | viewMenu->setItemChecked( viewMenu->idAt( 0 ), showHidden ); |
780 | viewMenu->setItemChecked( viewMenu->idAt( 1 ), showSymlinks ); | 886 | viewMenu->setItemChecked( viewMenu->idAt( 1 ), showSymlinks ); |
887 | viewMenu->setItemChecked( viewMenu->idAt( 2 ), showThumbnails ); | ||
781 | 888 | ||
@@ -932,3 +1039,2 @@ void FileView::chPerm() { | |||
932 | QString cmd; | 1039 | QString cmd; |
933 | int err; | ||
934 | 1040 | ||
@@ -984 +1090,40 @@ void FileBrowser::updateShowSymlinks() | |||
984 | } | 1090 | } |
1091 | |||
1092 | void FileBrowser::updateShowThumbnails() | ||
1093 | { | ||
1094 | bool valShowThumbnails=viewMenu->isItemChecked( viewMenu->idAt( 2 ) ); | ||
1095 | valShowThumbnails=!valShowThumbnails; | ||
1096 | viewMenu->setItemChecked( viewMenu->idAt( 2 ), valShowThumbnails ); | ||
1097 | fileView->setShowThumbnails(valShowThumbnails); | ||
1098 | |||
1099 | Config cfg("Filebrowser"); | ||
1100 | cfg.setGroup("View"); | ||
1101 | cfg.writeEntry("Thumbnails",valShowThumbnails?"TRUE":"FALSE"); | ||
1102 | |||
1103 | fileView->updateDir(); | ||
1104 | } | ||
1105 | |||
1106 | void FileBrowser::cleanUp() { | ||
1107 | QString cmdr = "rm -rf /tmp/filebrowserThumbnailCache"; | ||
1108 | // qDebug("exit"); | ||
1109 | system(cmdr.latin1()); | ||
1110 | } | ||
1111 | |||
1112 | { | ||
1113 | bool valShowThumbnails=viewMenu->isItemChecked( viewMenu->idAt( 2 ) ); | ||
1114 | valShowThumbnails=!valShowThumbnails; | ||
1115 | viewMenu->setItemChecked( viewMenu->idAt( 2 ), valShowThumbnails ); | ||
1116 | fileView->setShowThumbnails(valShowThumbnails); | ||
1117 | |||
1118 | Config cfg("Filebrowser"); | ||
1119 | cfg.setGroup("View"); | ||
1120 | cfg.writeEntry("Thumbnails",valShowThumbnails?"TRUE":"FALSE"); | ||
1121 | |||
1122 | fileView->updateDir(); | ||
1123 | } | ||
1124 | |||
1125 | void FileBrowser::cleanUp() { | ||
1126 | QString cmdr = "rm -rf /tmp/filebrowserThumbnailCache"; | ||
1127 | // qDebug("exit"); | ||
1128 | system(cmdr.latin1()); | ||
1129 | } | ||
diff --git a/noncore/unsupported/filebrowser/filebrowser.h b/noncore/unsupported/filebrowser/filebrowser.h index 983e58e..549d463 100644 --- a/noncore/unsupported/filebrowser/filebrowser.h +++ b/noncore/unsupported/filebrowser/filebrowser.h | |||
@@ -47,2 +47,3 @@ private: | |||
47 | QFileInfo fileInfo; | 47 | QFileInfo fileInfo; |
48 | QPixmap FileItem::drawThumbnail(const QFileInfo &file); | ||
48 | }; | 49 | }; |
@@ -56,5 +57,6 @@ public: | |||
56 | FileView( const QString & dir, QWidget * parent = 0, | 57 | FileView( const QString & dir, QWidget * parent = 0, |
57 | const char * name = 0, | 58 | const char * name = 0, |
58 | bool hidden = FALSE, | 59 | bool hidden = FALSE, |
59 | bool symlinks = FALSE ); | 60 | bool symlinks = FALSE, |
61 | bool thumbnails = FALSE ); | ||
60 | 62 | ||
@@ -65,6 +67,8 @@ public: | |||
65 | 67 | ||
66 | void setShowHidden(bool hidden); | 68 | void setShowHidden(bool hidden); |
67 | void setShowSymlinks(bool symlinks); | 69 | void setShowSymlinks(bool symlinks); |
68 | void setMenuKeepsOpen(bool keepOpen); | 70 | void setShowThumbnails(bool thumbnails); |
69 | 71 | bool getShowThumbnails () const { return showThumbnails; } | |
72 | void setMenuKeepsOpen(bool keepOpen); | ||
73 | |||
70 | public slots: | 74 | public slots: |
@@ -98,3 +102,2 @@ protected slots: | |||
98 | void endRenaming(); | 102 | void endRenaming(); |
99 | |||
100 | private: | 103 | private: |
@@ -106,5 +109,6 @@ private: | |||
106 | bool selected; | 109 | bool selected; |
107 | bool showHidden; | 110 | bool showHidden; |
108 | bool showSymlinks; | 111 | bool showSymlinks; |
109 | bool menuKeepsOpen; | 112 | bool showThumbnails; |
113 | bool menuKeepsOpen; | ||
110 | 114 | ||
@@ -148,6 +152,9 @@ private slots: | |||
148 | void updateSorting(); | 152 | void updateSorting(); |
149 | void updateShowHidden(); | 153 | void updateShowHidden(); |
150 | void updateShowSymlinks(); | 154 | void updateShowSymlinks(); |
155 | void updateShowThumbnails(); | ||
151 | void updateDirMenu(); | 156 | void updateDirMenu(); |
152 | void dirSelected( int id ); | 157 | void dirSelected( int id ); |
158 | void cleanUp(); | ||
159 | |||
153 | }; | 160 | }; |