summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.cpp153
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.h11
2 files changed, 158 insertions, 6 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 @@
+
#include "inlineedit.h"
@@ -45,2 +46,3 @@
#include <qpainter.h>
+#include <qprogressbar.h>
@@ -49,2 +51,3 @@
#include <sys/stat.h>
+#include <qpe/qpeapplication.h>
@@ -85,2 +88,4 @@ FileItem::FileItem( QListView * parent, const QFileInfo & fi )
pm = Resource::loadPixmap( "library" );
+ else if( ((FileView* )parent)->getShowThumbnails() && mt.id().contains(QRegExp("^image/", FALSE, FALSE)) )
+ pm = drawThumbnail(fi);
else
@@ -89,2 +94,3 @@ FileItem::FileItem( QListView * parent, const QFileInfo & fi )
pm = Resource::loadPixmap("UnknownDocument-14");
+
if( fi.isSymLink() ){
@@ -174,2 +180,53 @@ bool FileItem::rename( const QString & name )
+QPixmap FileItem::drawThumbnail(const QFileInfo &file) {
+
+ /*
+ * this thing is sloooooow, and it also doesn't load
+ * dynamicly (like a web browser). if anyone knows how to
+ * do that, please do!
+ */
+ QString cacheDir = "/tmp/filebrowserThumbnailCache";
+ QFileInfo cachedFile (cacheDir + file.filePath());
+
+ if (cachedFile.exists() && cachedFile.lastModified() == file.lastModified()) {
+
+ QPixmap cachedImage (cachedFile.filePath());
+ return cachedImage;
+ }
+ else {
+
+ QImage image (file.filePath());
+
+ // if inside of cache dir, don't render thumbnails! recursive error!
+ if (image.isNull() || file.filePath().contains(QRegExp("^" + cacheDir))) {
+ DocLnk doc (file.filePath());
+ return doc.pixmap();
+ }
+ Config cfg("Filebrowser");
+ cfg.setGroup("View");
+ int size;
+ size =cfg.readNumEntry("ThumbSize", 72);
+ QPixmap thumb (size, size);
+
+ double scale = (double)image.height() / (double)image.width();
+ int newHeight = int(size * scale);
+ thumb.convertFromImage (image.smoothScale(size, newHeight));
+
+ if (!cachedFile.dir().exists()) {
+ QString cmd = "/bin/mkdir -p \"" + cachedFile.dirPath() +"\"";
+ system( (const char *) cmd );
+ }
+
+ if (thumb.save(cachedFile.filePath(), QPixmap::imageFormat(file.filePath()), 70)) {
+ // make thumbnail modify time the same as the image
+ QString cmd = "/bin/touch -r \"" + file.filePath() +"\" " +
+ "\"" + cachedFile.filePath() + "\"";
+ system( (const char *) cmd );
+
+ }
+
+ return thumb;
+ }
+}
+
//
@@ -179,3 +236,3 @@ FileView::FileView( const QString & dir, QWidget * parent,
const char * name,
- bool hidden, bool symlinks )
+ bool hidden, bool symlinks, bool thumbnails )
: QListView( parent, name ),
@@ -186,2 +243,3 @@ FileView::FileView( const QString & dir, QWidget * parent,
showSymlinks( symlinks),
+ showThumbnails( thumbnails ),
menuKeepsOpen( FALSE )
@@ -255,3 +313,2 @@ void FileView::generateDir( const QString & dir )
-
const QFileInfoList * list = d.entryInfoList();
@@ -260,3 +317,12 @@ void FileView::generateDir( const QString & dir )
+ QProgressBar *thumbProgress = 0;
+ if (showThumbnails) {
+
+ thumbProgress = new QProgressBar(it.count(), this);
+ thumbProgress->show();
+ }
+
clear();
+
+ int fileCount = 1; // used in the thumbnail progress meter
while( (fi = it.current()) ){
@@ -270,6 +336,18 @@ void FileView::generateDir( const QString & dir )
}
+ // thumbnail progress
+ if (showThumbnails) {
+
+ thumbProgress->setProgress(fileCount);
+ }
(void) new FileItem( (QListView *) this, *fi );
+
++it;
+ ++fileCount;
+ }
+
+ if (showThumbnails) {
+ thumbProgress->close();
}
emit dirChanged();
+
}
@@ -465,2 +543,21 @@ void FileView::cut()
while( item ){
+ if( ite
+ // ##### a better inmplementation might be to rename the CUT file
+ // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it.
+ QString cmd, dest, basename, cd = "/tmp/qpemoving";
+ QStringList newflist;
+ newflist.clear();
+
+ cmd = "rm -rf " + cd;
+ system ( (const char *) cmd );
+ cmd = "mkdir " + cd;
+ system( (const char *) cmd );
+
+// get the names of the files to cut
+ FileItem * item;
+
+ if((item = (FileItem *) firstChild()) == 0) return;
+
+ flist.clear();
+ while( item ){
if( item->isSelected() /*&& !item->isDir()*/ ){
@@ -715,2 +812,7 @@ void FileView::setShowSymlinks(bool symlinks)
+void FileView::setShowThumbnails(bool thumbnails)
+{
+ showThumbnails=thumbnails;
+}
+
void FileView::setMenuKeepsOpen(bool keepOpen)
@@ -738,2 +840,4 @@ void FileBrowser::init(const QString & dir)
setIcon( Resource::loadPixmap( "filebrowser_icon" ) );
+ connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
+
@@ -743,2 +847,3 @@ void FileBrowser::init(const QString & dir)
bool showSymlinks=(cfg.readEntry("Symlinks","FALSE") == "TRUE");
+ bool showThumbnails=(cfg.readEntry("Thumbnails","FALSE") == "TRUE");
@@ -748,3 +853,3 @@ void FileBrowser::init(const QString & dir)
- fileView = new FileView( dir, this, 0, showHidden, showSymlinks );
+ fileView = new FileView( dir, this, 0, showHidden, showSymlinks, showThumbnails );
fileView->setAllColumnsShowFocus( TRUE );
@@ -778,4 +883,6 @@ void FileBrowser::init(const QString & dir)
viewMenu->insertItem( tr( "Symlinks"), this, SLOT( updateShowSymlinks() ) );
+ viewMenu->insertItem( tr( "Thumbnails"), this, SLOT( updateShowThumbnails() ) );
viewMenu->setItemChecked( viewMenu->idAt( 0 ), showHidden );
viewMenu->setItemChecked( viewMenu->idAt( 1 ), showSymlinks );
+ viewMenu->setItemChecked( viewMenu->idAt( 2 ), showThumbnails );
@@ -932,3 +1039,2 @@ void FileView::chPerm() {
QString cmd;
- int err;
@@ -984 +1090,40 @@ void FileBrowser::updateShowSymlinks()
}
+
+void FileBrowser::updateShowThumbnails()
+{
+ bool valShowThumbnails=viewMenu->isItemChecked( viewMenu->idAt( 2 ) );
+ valShowThumbnails=!valShowThumbnails;
+ viewMenu->setItemChecked( viewMenu->idAt( 2 ), valShowThumbnails );
+ fileView->setShowThumbnails(valShowThumbnails);
+
+ Config cfg("Filebrowser");
+ cfg.setGroup("View");
+ cfg.writeEntry("Thumbnails",valShowThumbnails?"TRUE":"FALSE");
+
+ fileView->updateDir();
+}
+
+void FileBrowser::cleanUp() {
+ QString cmdr = "rm -rf /tmp/filebrowserThumbnailCache";
+// qDebug("exit");
+ system(cmdr.latin1());
+}
+
+{
+ bool valShowThumbnails=viewMenu->isItemChecked( viewMenu->idAt( 2 ) );
+ valShowThumbnails=!valShowThumbnails;
+ viewMenu->setItemChecked( viewMenu->idAt( 2 ), valShowThumbnails );
+ fileView->setShowThumbnails(valShowThumbnails);
+
+ Config cfg("Filebrowser");
+ cfg.setGroup("View");
+ cfg.writeEntry("Thumbnails",valShowThumbnails?"TRUE":"FALSE");
+
+ fileView->updateDir();
+}
+
+void FileBrowser::cleanUp() {
+ QString cmdr = "rm -rf /tmp/filebrowserThumbnailCache";
+// qDebug("exit");
+ system(cmdr.latin1());
+}
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:
QFileInfo fileInfo;
+ QPixmap FileItem::drawThumbnail(const QFileInfo &file);
};
@@ -58,3 +59,4 @@ public:
bool hidden = FALSE,
- bool symlinks = FALSE );
+ bool symlinks = FALSE,
+ bool thumbnails = FALSE );
@@ -67,2 +69,4 @@ public:
void setShowSymlinks(bool symlinks);
+ void setShowThumbnails(bool thumbnails);
+ bool getShowThumbnails () const { return showThumbnails; }
void setMenuKeepsOpen(bool keepOpen);
@@ -98,3 +102,2 @@ protected slots:
void endRenaming();
-
private:
@@ -108,2 +111,3 @@ private:
bool showSymlinks;
+ bool showThumbnails;
bool menuKeepsOpen;
@@ -150,4 +154,7 @@ private slots:
void updateShowSymlinks();
+ void updateShowThumbnails();
void updateDirMenu();
void dirSelected( int id );
+ void cleanUp();
+
};