summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.cpp29
-rw-r--r--noncore/graphics/opie-eye/gui/mainwindow.cpp2
-rw-r--r--noncore/graphics/opie-eye/slave/gif_slave.cpp3
-rw-r--r--noncore/graphics/opie-eye/slave/jpeg_slave.cpp5
-rw-r--r--noncore/graphics/opie-eye/slave/png_slave.cpp3
5 files changed, 20 insertions, 22 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp
index b3f0006..ed9fc9c 100644
--- a/noncore/graphics/opie-eye/gui/iconview.cpp
+++ b/noncore/graphics/opie-eye/gui/iconview.cpp
@@ -1,378 +1,375 @@
/*
* GPLv2 zecke@handhelds.org
* No WArranty...
*/
#include "iconview.h"
#include <lib/imagecache.h>
#include <iface/dirview.h>
#include <iface/dirlister.h>
#include <opie2/oconfig.h>
#include <opie2/okeyconfigwidget.h>
+#include <opie2/odebug.h>
#include <qpe/resource.h>
#include <qpe/qpemessagebox.h>
#include <qpe/ir.h>
#include <qpe/qcopenvelope_qws.h>
#include <qiconview.h>
#include <qlabel.h>
#include <qhbox.h>
#include <qcombobox.h>
#include <qdir.h>
#include <qapplication.h>
#include <qmainwindow.h>
#include <qtimer.h>
#include <qstyle.h>
using Opie::Ui::OKeyConfigItem;
namespace {
QPixmap* _dirPix = 0;
QPixmap* _unkPix = 0;
class IconViewItem : public QIconViewItem {
public:
IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false);
QPixmap* pixmap()const;
QString path()const { return m_path; }
bool isDir()const { return m_isDir; }
void setText( const QString& );
- void reCalc();
+
+
private:
mutable QPixmap* m_pix;
QString m_path;
bool m_isDir : 1;
bool m_noInfo :1;
};
/*
* If we request an Image or String
* we add it to the map
*/
QMap<QString, IconViewItem*> g_stringInf;
QMap<QString, IconViewItem*> g_stringPix;
IconViewItem::IconViewItem( QIconView* view,const QString& path,
const QString& name, bool isDir )
: QIconViewItem( view ), m_path( path ), m_isDir( isDir ),
m_noInfo( false )
{
QIconViewItem::setText( name );
if ( isDir && !_dirPix )
_dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser"));
else if ( !isDir && !_unkPix )
_unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) );
}
inline QPixmap* IconViewItem::pixmap()const {
+ qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d",
+ rect().x(),rect().y(),rect().width(),rect().height(),
+ iconView()->contentsX(), iconView()->contentsY());
+
if ( m_isDir )
return _dirPix;
else{
if (!m_noInfo && !g_stringInf.contains( m_path ) ) {
currentView()->dirLister()->imageInfo( m_path );
g_stringInf.insert( m_path, const_cast<IconViewItem*>(this));
}
m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 );
if ( !m_pix && !g_stringPix.contains( m_path )) {
currentView()->dirLister()->thumbNail( m_path, 64, 64 );
g_stringPix.insert( m_path, const_cast<IconViewItem*>(this));
}
return m_pix ? m_pix : _unkPix;
}
}
inline void IconViewItem::setText( const QString& str ) {
QString text = QIconViewItem::text()+"\n"+str;
m_noInfo = true;
QIconViewItem::setText( text );
- reCalc();
- }
-
- inline void IconViewItem::reCalc()
- {
- calcRect();
}
}
PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg )
: QVBox( wid ), m_cfg( cfg )
{
{
QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" );
}
m_path = QDir::homeDirPath();
QHBox *hbox = new QHBox( this );
QLabel* lbl = new QLabel( hbox );
lbl->setText( tr("View as" ) );
m_views = new QComboBox( hbox, "View As" );
connect( m_views, SIGNAL(activated(int)),
this, SLOT(slotViewChanged(int)) );
m_view= new QIconView( this );
connect(m_view, SIGNAL(clicked(QIconViewItem*) ),
this, SLOT(slotClicked(QIconViewItem*)) );
m_view->setArrangement( QIconView::LeftToRight );
m_view->setItemTextPos( QIconView::Right );
- m_view->setResizeMode(QIconView::Adjust);
int dw = QApplication::desktop()->width();
int viewerWidth = dw-style().scrollBarExtent().width();
- m_view->setGridX( viewerWidth-2*m_view->spacing() );
+ m_view->setGridX( viewerWidth-3*m_view->spacing());
m_view->setGridY( fontMetrics().height()*2+40 );
initKeys();
loadViews();
slotViewChanged( m_views->currentItem() );
}
PIconView::~PIconView() {
{
QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" );
}
m_viewManager->save();
delete m_viewManager;
}
Opie::Ui::OKeyConfigManager* PIconView::manager() {
return m_viewManager;
}
void PIconView::initKeys() {
Opie::Ui::OKeyPair::List lst;
lst.append( Opie::Ui::OKeyPair::upArrowKey() );
lst.append( Opie::Ui::OKeyPair::downArrowKey() );
lst.append( Opie::Ui::OKeyPair::leftArrowKey() );
lst.append( Opie::Ui::OKeyPair::rightArrowKey() );
lst.append( Opie::Ui::OKeyPair::returnKey() );
m_viewManager = new Opie::Ui::OKeyConfigManager(m_cfg, "View-KeyBoard-Config",
lst, false,this, "keyconfig name" );
m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam",
QString::fromLatin1("beam"), BeamItem,
Opie::Ui::OKeyPair(Qt::Key_B, Qt::ShiftButton),
this, SLOT(slotBeam())) );
m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete",
QString::fromLatin1("trash"), DeleteItem,
Opie::Ui::OKeyPair(Qt::Key_D, Qt::ShiftButton),
this, SLOT(slotTrash())) );
m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view",
QString::fromLatin1("1to1"), ViewItem,
Opie::Ui::OKeyPair(Qt::Key_V, Qt::ShiftButton),
this, SLOT(slotShowImage())));
m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info",
QString::fromLatin1("DocumentTypeWord"), InfoItem,
Opie::Ui::OKeyPair(Qt::Key_I, Qt::ShiftButton ),
this, SLOT(slotImageInfo()) ) );
m_viewManager->load();
m_viewManager->handleWidget( m_view );
}
void PIconView::slotDirUp() {
QDir dir( m_path );
dir.cdUp();
slotChangeDir( dir.absPath() );
}
void PIconView::slotChangeDir(const QString& path) {
if ( !currentView() )
return;
PDirLister *lister = currentView()->dirLister();
if (!lister )
return;
lister->setStartPath( path );
m_path = lister->currentPath();
- m_view->setUpdatesEnabled( false );
+ m_view->viewport()->setUpdatesEnabled( false );
m_view->clear();
addFolders( lister->folders() );
addFiles( lister->files() );
- m_view->setUpdatesEnabled( true );
+ m_view->viewport()->setUpdatesEnabled( true );
// Also invalidate the cache. We can't cancel the operations anyway
g_stringPix.clear();
g_stringInf.clear();
// looks ugly
static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) );
}
QString PIconView::currentFileName(bool &isDir)const {
isDir = false;
QIconViewItem* _it = m_view->currentItem();
if ( !_it )
return QString::null;
IconViewItem* it = static_cast<IconViewItem*>( _it );
isDir = it->isDir();
return it->path();
}
void PIconView::slotTrash() {
bool isDir;
QString pa = currentFileName( isDir );
if ( isDir && pa.isEmpty() )
return;
if (!QPEMessageBox::confirmDelete( this,
tr("Delete Image" ),
tr("the Image %1" ).arg(pa)))
return
currentView()->dirLister()->deleteImage( pa );
delete m_view->currentItem();
}
void PIconView::loadViews() {
ViewMap::Iterator it;
ViewMap* map = viewMap();
for ( it = map->begin(); it != map->end(); ++it )
m_views->insertItem( QObject::tr(it.key() ) );
}
void PIconView::resetView() {
slotViewChanged(m_views->currentItem());
}
void PIconView::slotViewChanged( int i) {
if (!m_views->count() ) {
setCurrentView( 0l);
return;
}
PDirView* cur = currentView();
delete cur;
QString str = m_views->text(i);
cur = (*(*viewMap())[str])(*m_cfg);
setCurrentView( cur );
/* connect to the signals of the lister */
PDirLister* lis = cur->dirLister();
connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )),
this, SLOT( slotThumbInfo(const QString&, const QString&)));
connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)),
this, SLOT(slotThumbNail(const QString&, const QPixmap&)));
connect(lis, SIGNAL(sig_start()),
this, SLOT(slotStart()));
connect(lis, SIGNAL(sig_end()) ,
this, SLOT(slotEnd()) );
/* reload now */
QTimer::singleShot( 0, this, SLOT(slotReloadDir()));
}
void PIconView::slotReloadDir() {
slotChangeDir( m_path );
}
void PIconView::addFolders( const QStringList& lst) {
QStringList::ConstIterator it;
for(it=lst.begin(); it != lst.end(); ++it ) {
(void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true );
}
}
void PIconView::addFiles( const QStringList& lst) {
QStringList::ConstIterator it;
for (it=lst.begin(); it!= lst.end(); ++it )
(void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) );
}
void PIconView::slotClicked(QIconViewItem* _it) {
if(!_it )
return;
IconViewItem* it = static_cast<IconViewItem*>(_it);
if( it->isDir() )
slotChangeDir( it->path() );
else // view image
;
}
void PIconView::slotThumbInfo( const QString& _path, const QString& str ) {
if ( g_stringInf.contains( _path ) ) {
IconViewItem* item = g_stringInf[_path];
/* if set the view shows nonsens!
I dont know how to fix the format of displayed text :(*/
item->setText( str );
- item->repaint();
g_stringInf.remove( _path );
}
}
void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) {
if ( g_stringPix.contains( _path ) ) {
IconViewItem* item = g_stringPix[_path];
if (pix.width()>0) {
PPixmapCache::self()->insertImage( _path, pix, 64, 64 );
/* required for a recalculated rectangle. otherwise the view show nonsense! */
- item->reCalc();
} else {
PPixmapCache::self()->insertImage(_path,Resource::loadPixmap( "UnknownDocument" ),64,64 );
}
- item->repaint();
g_stringPix.remove( _path );
}
}
void PIconView::slotRename() {
}
void PIconView::slotBeam() {
bool isDir;
QString pa = currentFileName( isDir );
if ( isDir && pa.isEmpty() )
return;
Ir* ir = new Ir( this );
connect( ir, SIGNAL(done(Ir*)),
this, SLOT(slotBeamDone(Ir*)));
ir->send(pa, tr( "Image" ) );
}
void PIconView::slotBeamDone( Ir* ir) {
delete ir;
}
void PIconView::slotStart() {
- m_view->setUpdatesEnabled( false );
+ m_view->viewport()->setUpdatesEnabled( false );
}
void PIconView::slotEnd() {
- m_view->setUpdatesEnabled( true );
+ m_view->arrangeItemsInGrid( );
+ m_view->viewport()->setUpdatesEnabled( true );
}
void PIconView::slotShowImage() {
}
void PIconView::slotShowImage( const QString& ) {
}
void PIconView::slotImageInfo() {
}
void PIconView::slotImageInfo( const QString& ) {
}
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.cpp b/noncore/graphics/opie-eye/gui/mainwindow.cpp
index 0314659..83ff4f1 100644
--- a/noncore/graphics/opie-eye/gui/mainwindow.cpp
+++ b/noncore/graphics/opie-eye/gui/mainwindow.cpp
@@ -1,138 +1,138 @@
/*
* GPLv2 zecke@handhelds.org
* No WArranty...
*/
#include "mainwindow.h"
#include "iconview.h"
#include "filesystem.h"
#include <iface/ifaceinfo.h>
#include <iface/dirview.h>
#include <opie2/oapplicationfactory.h>
#include <opie2/otabwidget.h>
#include <opie2/okeyconfigwidget.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <qpe/ir.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qlayout.h>
#include <qdialog.h>
#include <qmap.h>
OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<PMainWindow> )
PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style)
: QMainWindow( wid, name, style )
{
setCaption( QObject::tr("Opie Eye Caramba" ) );
m_cfg = new Opie::Core::OConfig("phunkview");
m_cfg->setGroup("Zecke_view" );
/*
* Initialize ToolBar and IconView
* And Connect Them
*/
QToolBar *bar = new QToolBar( this );
bar->setHorizontalStretchable( true );
setToolBarsMovable( false );
m_view = new PIconView( this, m_cfg );
setCentralWidget( m_view );
QToolButton *btn = new QToolButton( bar );
btn->setIconSet( Resource::loadIconSet( "up" ) );
connect( btn, SIGNAL(clicked()),
m_view, SLOT(slotDirUp()) );
btn = new PFileSystem( bar );
connect( btn, SIGNAL( changeDir( const QString& ) ),
m_view, SLOT(slotChangeDir( const QString& ) ) );
btn = new QToolButton( bar );
btn->setIconSet( Resource::loadIconSet( "edit" ) );
connect( btn, SIGNAL(clicked()),
m_view, SLOT(slotRename()) );
if ( Ir::supported() ) {
btn = new QToolButton( bar );
btn->setIconSet( Resource::loadIconSet( "beam" ) );
connect( btn, SIGNAL(clicked()),
m_view, SLOT(slotBeam()) );
}
btn = new QToolButton( bar );
btn->setIconSet( Resource::loadIconSet( "trash" ) );
connect( btn, SIGNAL(clicked() ),
m_view, SLOT(slotTrash() ) );
btn = new QToolButton( bar );
btn->setIconSet( Resource::loadIconSet( "SettingsIcon" ) );
connect( btn, SIGNAL(clicked() ),
this, SLOT(slotConfig() ) );
}
PMainWindow::~PMainWindow() {
}
void PMainWindow::slotConfig() {
/*
* have a tab with the possible views
* a tab for globals image cache size.. scaled loading
* and one tab for the KeyConfigs
*/
QDialog dlg(this, 0, true);
dlg.setCaption( tr("Phunk View - Config" ) );
QHBoxLayout *lay = new QHBoxLayout(&dlg);
Opie::Ui::OTabWidget *wid = new Opie::Ui::OTabWidget(&dlg );
lay->addWidget( wid );
ViewMap *vM = viewMap();
ViewMap::Iterator _it = vM->begin();
QMap<PDirView*, QWidget*> lst;
for( ; _it != vM->end(); ++_it ) {
PDirView *view = (_it.data())(*m_cfg);
PInterfaceInfo *inf = view->interfaceInfo();
QWidget *_wid = inf->configWidget( *m_cfg );
_wid->reparent(wid, QPoint() );
lst.insert( view, _wid );
- wid->addTab( _wid, QString::null, inf->name() );
+ wid->addTab( _wid, "fileopen", inf->name() );
}
/*
* Add the KeyConfigWidget
*/
Opie::Ui::OKeyConfigWidget* keyWid = new Opie::Ui::OKeyConfigWidget( wid, "key config" );
keyWid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue );
keyWid->insert( tr("Browser Keyboard Actions"), m_view->manager() );
keyWid->load();
wid->addTab( keyWid, QString::fromLatin1("AppsIcon" ), tr("Keyboard Configuration") );
bool act = ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted );
QMap<PDirView*, QWidget*>::Iterator it;
for ( it = lst.begin(); it != lst.end(); ++it ) {
if ( act )
it.key()->interfaceInfo()->writeConfig(it.data(), *m_cfg);
delete it.key();
}
if ( act ) {
m_view->resetView();
keyWid->save();
}
}
diff --git a/noncore/graphics/opie-eye/slave/gif_slave.cpp b/noncore/graphics/opie-eye/slave/gif_slave.cpp
index feb69b6..f0dc86e 100644
--- a/noncore/graphics/opie-eye/slave/gif_slave.cpp
+++ b/noncore/graphics/opie-eye/slave/gif_slave.cpp
@@ -97,209 +97,210 @@ void skipdata(FILE *src)
(void)fread((void *)&size,1,1,src);
if (debug)
dump(pos,&size,1);
if (debug) {
pos=ftell(src);
(void)fread((void *)buffer,(size_t)size,1,src);
dump(pos,buffer,(size_t)size);
}
else
(void)fseek(src,(long int)size,SEEK_CUR);
} while (!feof(src)&&size>0);
}
void transdata(FILE *src, FILE *dest)
{
unsigned char size,buffer[256];
do {
pos=ftell(src);
(void)fread((void *)&size,1,1,src);
pos=ftell(src);
(void)fread((void *)buffer,(size_t)size,1,src);
if (debug)
dump(pos,buffer,(size_t)size);
if (output)
(void)fwrite((void *)buffer,(size_t)size,1,dest);
} while (!feof(src)&&size>0);
}
void transblock(FILE *src, FILE* dest)
{
unsigned char size,buffer[256];
pos=ftell(src);
(void)fread((void *)&size,1,1,src);
if (debug)
dump(pos,&size,1);
if (output)
(void)fwrite((void *)&size,1,1,dest);
pos=ftell(src);
(void)fread((void *)buffer,(size_t)size,1,src);
if (debug)
dump(pos,buffer,(size_t)size);
if (output)
(void)fwrite((void *)buffer,(size_t)size,1,dest);
}
void dumpcomment(FILE *src, QCString& str)
{
unsigned char size;
pos=ftell(src);
(void)fread((void *)&size,1,1,src);
if (debug)
dump(pos,&size,1);
str.resize( size+1 );
(void)fread((void *)str.data(),size,1,src);
(void)fseek(src,(long int)pos,SEEK_SET);
}
int giftrans(FILE *src, FILE* dest, QString& str, bool full)
{
unsigned char buffer[3*256],lsd[7],gct[3*256];
unsigned int size,gct_size;
/* Header */
pos=ftell(src);
(void)fread((void *)buffer,6,1,src);
if (strncmp((char *)buffer,"GIF",3)) {
str = QObject::tr("Not a GIF file");
(void)fprintf(stderr,"Not GIF file!\n");
return(1);
}
/* Logical Screen Descriptor */
pos=ftell(src);
(void)fread((void *)lsd,7,1,src);
//(void)fprintf(stderr,"Logical Screen Descriptor:\n");
str += QObject::tr("Dimensions: %1x%2\n").arg( readword(lsd) ).arg( readword(lsd+2 ) );
//(void)fprintf(stderr,"Global Color Table Flag: %s\n",readflag(lsd[4]&0x80));
str += QObject::tr("Depth: %1 bits\n").arg( (lsd[4]&0x70>>4 )+1);
//(void)fprintf(stderr,"Depth : %d bits\n",(lsd[4]&0x70>>4)+1);
if (lsd[4]&0x80 && full) {
str += QObject::tr("Sort Flag: %1\n" ).arg(readflag(lsd[4]&0x8) );
str += QObject::tr("Size of Global Color Table: %1 colors\n" ).arg( 2<<(lsd[4]&0x7));
str += QObject::tr("Background Color Index: %1\n" ).arg(lsd[5]);
}
if (lsd[6] && full)
str += QObject::tr("Pixel Aspect Ratio: %1 (Aspect Ratio %2)\n" ).arg( lsd[6] ).
arg( ((double)lsd[6]+15)/64 );
/* Global Color Table */
if (lsd[4]&0x80) {
gct_size=2<<(lsd[4]&0x7);
pos=ftell(src);
(void)fread((void *)gct,gct_size,3,src);
}
do {
pos=ftell(src);
(void)fread((void *)buffer,1,1,src);
switch (buffer[0]) {
case 0x2c: /* Image Descriptor */
(void)fread((void *)(buffer+1),9,1,src);
/* Local Color Table */
if (buffer[8]&0x80) {
size=2<<(buffer[8]&0x7);
pos=ftell(src);
(void)fread((void *)buffer,size,3,src);
}
/* Table Based Image Data */
pos=ftell(src);
(void)fread((void *)buffer,1,1,src);
transdata(src,dest);
break;
case 0x21: /* Extension */
(void)fread((void *)(buffer+1),1,1,src);
switch (buffer[1]) {
case 0xfe: /* Comment Extension */
if (true)
{
QCString st;
dumpcomment(src, st);
str += QObject::tr("Comment: %1\n" ).arg( st );
}
if (skipcomment)
skipdata(src);
else {
transdata(src,dest);
}
break;
case 0x01: /* Plain Text Extension */
case 0xf9: /* Graphic Control Extension */
case 0xff: /* Application Extension */
default:
transblock(src,dest);
transdata(src,dest);
break;
}
break;
case 0x3b: /* Trailer (write comment just before here) */
break;
default:
(void)fprintf(stderr,"0x%08lx: Error, unknown block 0x%02x!\n",ftell(src)-1,buffer[0]);
return(1);
}
} while (buffer[0]!=0x3b&&!feof(src));
return(buffer[0]==0x3b?SUCCESS:FAILURE);
}
/****************************************************************************/
extern void get_gif_info( const char * original_filename, QString& str,
bool full =false)
{
FILE * infile;
if ((infile = fopen(original_filename, READ_BINARY)) == NULL) {
fprintf(stderr, "can't open gif image '%s'\n", original_filename);
return ;
}
output = FALSE;
verbose = TRUE;
debug = FALSE;
skipcomment = FALSE;
giftrans( infile, NULL, str, full );
fclose( infile );
}
}
GifSlave::GifSlave()
: SlaveInterface(QStringList("gif"))
{}
GifSlave::~GifSlave() {
}
QString GifSlave::iconViewName(const QString& str) {
QString st;
get_gif_info(QFile::encodeName( str ).data(), st );
return st;
}
QString GifSlave::fullImageInfo( const QString& str) {
- QString st;
+ QString st = "<qt>";
get_gif_info(QFile::encodeName( str ).data(), st, true );
+ st.append( "</qt>" );
return st;
}
QPixmap GifSlave::pixmap(const QString& path, int width, int height ) {
static QImage img;
img.load( path );
if ( img.isNull() ) {
QPixmap pix;
return pix;
}
return ThumbNailTool::scaleImage( img, width,height );
}
diff --git a/noncore/graphics/opie-eye/slave/jpeg_slave.cpp b/noncore/graphics/opie-eye/slave/jpeg_slave.cpp
index 95055fd..086b47f 100644
--- a/noncore/graphics/opie-eye/slave/jpeg_slave.cpp
+++ b/noncore/graphics/opie-eye/slave/jpeg_slave.cpp
@@ -1111,316 +1111,315 @@ static QString color_mode_to_string( bool b ) {
return b ? QObject::tr( "Colormode: Color\n" ) : QObject::tr( "Colormode: Black and white\n" );
}
static QString compression_to_string( int level ) {
QString str;
switch( level ) {
case 1:
str = QObject::tr( "Basic" );
break;
case 2:
str = QObject::tr( "Normal" );
break;
case 4:
str = QObject::tr( "Fine" );
break;
default:
str = QObject::tr( "Unknown" );
}
return QObject::tr("Quality: %1\n").arg(str);
}
static QDateTime parseDateTime( const QString& string )
{
QDateTime dt;
if ( string.length() != 19 )
return dt;
QString year = string.left( 4 );
QString month = string.mid( 5, 2 );
QString day = string.mid( 8, 2 );
QString hour = string.mid( 11, 2 );
QString minute = string.mid( 14, 2 );
QString seconds = string.mid( 18, 2 );
bool ok;
bool allOk = true;
int y = year.toInt( &ok );
allOk &= ok;
int mo = month.toInt( &ok );
allOk &= ok;
int d = day.toInt( &ok );
allOk &= ok;
int h = hour.toInt( &ok );
allOk &= ok;
int mi = minute.toInt( &ok );
allOk &= ok;
int s = seconds.toInt( &ok );
allOk &= ok;
if ( allOk ) {
dt.setDate( QDate( y, mo, d ) );
dt.setTime( QTime( h, mi, s ) );
}
return dt;
}
static QString white_balance_string( int i ) {
QString balance;
switch ( i ) {
case 0:
balance = QObject::tr( "Unknown" );
break;
case 1:
balance = QObject::tr( "Daylight" );
break;
case 2:
balance = QObject::tr( "Fluorescent" );
break;
case 3:
balance = QObject::tr( "Tungsten" );
break;
case 17:
balance = QObject::tr( "Standard light A" );
break;
case 18:
balance = QObject::tr( "Standard light B" );
break;
case 19:
balance = QObject::tr( "Standard light C" );
break;
case 20:
balance = QObject::tr( "D55" );
break;
case 21:
balance = QObject::tr( "D65" );
break;
case 22:
balance = QObject::tr( "D75" );
break;
case 255:
balance = QObject::tr( "Other" );
break;
default:
balance = QObject::tr( "Unknown" );
}
return QObject::tr( "White Balance: %1\n" ).arg( balance );
}
static QString metering_mode( int i) {
QString meter;
switch( i ) {
case 0:
meter = QObject::tr( "Unknown" );
break;
case 1:
meter = QObject::tr( "Average" );
break;
case 2:
meter = QObject::tr( "Center weighted average" );
break;
case 3:
meter = QObject::tr( "Spot" );
break;
case 4:
meter = QObject::tr( "MultiSpot" );
break;
case 5:
meter = QObject::tr( "Pattern" );
break;
case 6:
meter = QObject::tr( "Partial" );
break;
case 255:
meter = QObject::tr( "Other" );
break;
default:
meter = QObject::tr( "Unknown" );
}
return QObject::tr( "Metering Mode: %1\n" ).arg( meter );
}
static QString exposure_program( int i ) {
QString exp;
switch( i ) {
case 0:
exp = QObject::tr( "Not defined" );
break;
case 1:
exp = QObject::tr( "Manual" );
break;
case 2:
exp = QObject::tr( "Normal progam" );
break;
case 3:
exp = QObject::tr( "Aperture priority" );
break;
case 4:
exp = QObject::tr( "Shutter priority" );
break;
case 5:
exp = QObject::tr( "Creative progam\n(biased toward fast shutter speed" );
break;
case 6:
exp = QObject::tr( "Action progam\n(biased toward fast shutter speed)" );
break;
case 7:
exp = QObject::tr( "Portrait mode\n(for closeup photos with the background out of focus)" );
break;
case 8:
exp = QObject::tr( "Landscape mode\n(for landscape photos with the background in focus)" );
break;
default:
exp = QObject::tr( "Unknown" );
}
return QObject::tr( "Exposure Program: %1\n" ).arg( exp );
}
JpegSlave::JpegSlave()
: SlaveInterface( QStringList::split( " ", "jpeg jpg" ) )
{}
JpegSlave::~JpegSlave() {}
QString JpegSlave::iconViewName( const QString& path) {
ExifData ImageInfo;
if ( !ImageInfo.scan( path ) )
return QString::null;
QString tag;
- tag = QObject::tr( "<qt>Comment: %1\n" ).arg( ImageInfo.getComment() );
+ tag = QObject::tr( "Comment: %1\n" ).arg( ImageInfo.getComment() );
{
// ODP fixme
QString timestring = TimeString::dateString( parseDateTime( ImageInfo.getDateTime() ), FALSE );
tag += QObject::tr( "Date/Time: %1\n" ).arg( timestring );
}
tag += QObject::tr( "Dimensions: %1x%2\n" ).arg(ImageInfo.getWidth())
.arg(ImageInfo.getHeight() );
tag += color_mode_to_string( ImageInfo.getIsColor() );
tag += compression_to_string( ImageInfo.getCompressionLevel() );
- tag += QObject::tr( "</qt>" );
return tag;
}
/*
* messy messy string creation
*/
QString JpegSlave::fullImageInfo( const QString& path) {
ExifData ImageInfo;
if ( !ImageInfo.scan( path ) )
return QString::null;
QString tag, tmp;
- tag = QObject::tr( "Comment: %1\n" ).arg( ImageInfo.getComment() );
+ tag = QObject::tr( "<qt>Comment: %1\n" ).arg( ImageInfo.getComment() );
tmp = ImageInfo.getCameraMake();
if ( tmp.length() )
tag += QObject::tr( "Manufacturer: %1\n" ).arg( tmp );
tmp = ImageInfo.getCameraModel();
if ( tmp.length() )
tag += QObject::tr( "Model: %1\n" ).arg( tmp );
{
// ODP fixme
tmp = TimeString::dateString( parseDateTime( ImageInfo.getDateTime() ), FALSE );
tag += QObject::tr( "Date/Time: %1\n" ).arg( tmp );
}
tag += QObject::tr( "Dimensions: %1x%2\n" ).arg(ImageInfo.getWidth())
.arg(ImageInfo.getHeight() );
tag += color_mode_to_string( ImageInfo.getIsColor() );
tag += compression_to_string( ImageInfo.getCompressionLevel() );
if ( ImageInfo.getOrientation() )
tag += QObject::tr( "Orientation: %1\n" ).arg(ImageInfo.getOrientation() );
{
int flash_used = ImageInfo.getFlashUsed();
if ( flash_used >= 0 )
tag += QObject::tr( "Flash used\n" );
}
if ( ImageInfo.getFocalLength() ) {
tag += QObject::tr( "Focal length: %1\n" ).arg( QString().sprintf( "%4.1f", ImageInfo.getFocalLength() ) );
if ( ImageInfo.getCCDWidth() )
tag += QObject::tr( "35mm equivalent: %1\n" ).arg( (int)(ImageInfo.getFocalLength()/ImageInfo.getCCDWidth()*35 + 0.5) );
}
if ( ImageInfo.getCCDWidth() )
tag += QObject::tr( "CCD width: %1" ).arg( ImageInfo.getCCDWidth() );
if ( ImageInfo.getExposureTime() ) {
tmp = QString().sprintf("%4.2f", ImageInfo.getExposureTime() );
float exposureTime = ImageInfo.getExposureTime();
if ( exposureTime > 0 && exposureTime <= 0.5 )
tmp += QString().sprintf(" (1/%d)", (int)(0.5 +1/exposureTime) );
tag += QObject::tr( "Exposure time: %1\n" ).arg( tmp );
}
if ( ImageInfo.getApertureFNumber() )
tag += QObject::tr( "Aperture: %1\n" ).arg( QString().sprintf("f/%3.1f", (double)ImageInfo.getApertureFNumber() ) );
if ( ImageInfo.getDistance() ) {
if ( ImageInfo.getDistance() < 0 )
tag += QObject::tr( "Distance: %1\n" ).arg( QObject::tr( "Infinite" ) );
else
tag += QObject::tr( "Distance: %1\n" ).arg( QString().sprintf( "%5.2fm", (double)ImageInfo.getDistance() ) );
}
if ( ImageInfo.getExposureBias() ) {
tag += QObject::tr( "Exposure bias: %1\n", QString().sprintf("%4.2f", (double)ImageInfo.getExposureBias() ) );
}
if ( ImageInfo.getWhitebalance() != -1 )
tag += white_balance_string( ImageInfo.getWhitebalance() );
if( ImageInfo.getMeteringMode() != -1 )
tag += metering_mode( ImageInfo.getMeteringMode() );
if ( ImageInfo.getExposureProgram() )
tag += exposure_program( ImageInfo.getExposureProgram() );
if ( ImageInfo.getISOequivalent() )
tag += QObject::tr( "ISO equivalent: %1\n" ).arg( QString().sprintf("%2d", ImageInfo.getISOequivalent() ) );
tmp = ImageInfo.getUserComment();
if ( tmp.length() )
tag += QObject::tr( "EXIF comment: %1" ).arg( tmp );
tag += QObject::tr( "</qt>" );
return tag;
}
QPixmap JpegSlave::pixmap( const QString& path, int wid, int hei) {
ExifData ImageInfo;
if ( !ImageInfo.scan( path ) || ImageInfo.isNullThumbnail() ) {
QImage img;
QImageIO iio( path, 0l );
QString str = QString( "Fast Shrink( 4 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei );
iio.setParameters( str.latin1() );// will be strdupped anyway
img = iio.read() ? iio.image() : QImage();
return ThumbNailTool::scaleImage( img, wid,hei );
}else{
QImage img = ImageInfo.getThumbnail();
return ThumbNailTool::scaleImage( img, wid,hei );
}
}
diff --git a/noncore/graphics/opie-eye/slave/png_slave.cpp b/noncore/graphics/opie-eye/slave/png_slave.cpp
index 72b93cc..86e1cdc 100644
--- a/noncore/graphics/opie-eye/slave/png_slave.cpp
+++ b/noncore/graphics/opie-eye/slave/png_slave.cpp
@@ -6,205 +6,206 @@
#include <qfile.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qstring.h>
/*
* GPLv2 from kfile plugin
*/
PHUNK_VIEW_INTERFACE( "PNG", PNGSlave );
#define CHUNK_SIZE(data, index) ((data[index ]<<24) + (data[index+1]<<16) + \
(data[index+2]<< 8) + data[index+3])
#define CHUNK_TYPE(data, index) &data[index+4]
#define CHUNK_HEADER_SIZE 12
#define CHUNK_DATA(data, index, offset) data[8+index+offset]
/* TRANSLATOR QObject */
// known translations for common png keys
static const char* knownTranslations[]
#ifdef __GNUC__
__attribute__((unused))
#endif
= {
QT_TR_NOOP("Title"),
QT_TR_NOOP("Author"),
QT_TR_NOOP("Description"),
QT_TR_NOOP("Copyright"),
QT_TR_NOOP("Creation Time"),
QT_TR_NOOP("Software"),
QT_TR_NOOP("Disclaimer"),
QT_TR_NOOP("Warning"),
QT_TR_NOOP("Source"),
QT_TR_NOOP("Comment")
};
// and for the colors
static const char* colors[] = {
QT_TR_NOOP("Grayscale"),
QT_TR_NOOP("Unknown"),
QT_TR_NOOP("RGB"),
QT_TR_NOOP("Palette"),
QT_TR_NOOP("Grayscale/Alpha"),
QT_TR_NOOP("Unknown"),
QT_TR_NOOP("RGB/Alpha")
};
// and compressions
static const char* compressions[] =
{
QT_TR_NOOP("Deflate")
};
// interlaced modes
static const char* interlaceModes[] = {
QT_TR_NOOP("None"),
QT_TR_NOOP("Adam7")
};
static void read_comment( const QString& inf,
bool readComments, QString& str ) {
QFile f(inf);
f.open(IO_ReadOnly);
if (f.size() < 26) return;
// the technical group will be read from the first 26 bytes. If the file
// is smaller, we can't even read this.
uchar *data = new uchar[f.size()+1];
f.readBlock(reinterpret_cast<char*>(data), f.size());
data[f.size()]='\n';
// find the start
if (data[0] == 137 && data[1] == 80 && data[2] == 78 && data[3] == 71 &&
data[4] == 13 && data[5] == 10 && data[6] == 26 && data[7] == 10 )
{
// ok
// the IHDR chunk should be the first
if (!strncmp((char*)&data[12], "IHDR", 4))
{
// we found it, get the dimensions
ulong x,y;
x = (data[16]<<24) + (data[17]<<16) + (data[18]<<8) + data[19];
y = (data[20]<<24) + (data[21]<<16) + (data[22]<<8) + data[23];
uint type = data[25];
uint bpp = data[24];
// the bpp are only per channel, so we need to multiply the with
// the channel count
switch (type)
{
case 0: break; // Grayscale
case 2: bpp *= 3; break; // RGB
case 3: break; // palette
case 4: bpp *= 2; break; // grayscale w. alpha
case 6: bpp *= 4; break; // RGBA
default: // we don't get any sensible value here
bpp = 0;
}
str = QObject::tr("Dimensions: %1x%2\n" ).arg(x).arg(y);
str += QObject::tr("Depth: %1\n" ).arg(bpp);
str += QObject::tr("ColorMode: %1\n").arg(
(type < sizeof(colors)/sizeof(colors[0]))
? QObject::tr(colors[data[25]]) : QObject::tr("Unknown") );
str += QObject::tr("Compression: %1\n").arg(
(data[26] < sizeof(compressions)/sizeof(compressions[0]))
? QObject::tr(compressions[data[26]]) : QObject::tr("Unknown") );
str += QObject::tr("InterlaceMode: %1\n" ).arg(
(data[28] < sizeof(interlaceModes)/sizeof(interlaceModes[0]))
? QObject::tr(interlaceModes[data[28]]) : QObject::tr("Unknown"));
}
if ( readComments ) {
uint index = 8;
index += CHUNK_SIZE(data, index) + CHUNK_HEADER_SIZE;
while(index<f.size()-12)
{
while (index < f.size() - 12 &&
strncmp((char*)CHUNK_TYPE(data,index), "tEXt", 4))
{
if (!strncmp((char*)CHUNK_TYPE(data,index), "IEND", 4))
goto end;
index += CHUNK_SIZE(data, index) + CHUNK_HEADER_SIZE;
}
if (index < f.size() - 12)
{
// we found a tEXt field
// get the key, it's a null terminated string at the
// chunk start
uchar* key = &CHUNK_DATA(data,index,0);
int keysize=0;
for (;key[keysize]!=0; keysize++)
// look if we reached the end of the file
// (it might be corrupted)
if (8+index+keysize>=f.size())
goto end;
// the text comes after the key, but isn't null terminated
uchar* text = &CHUNK_DATA(data,index, keysize+1);
uint textsize = CHUNK_SIZE(data, index)-keysize-1;
// security check, also considering overflow wraparound from the addition --
// we may endup with a /smaller/ index if we wrap all the way around
uint firstIndex = (uint)(text - data);
uint onePastLastIndex = firstIndex + textsize;
if ( onePastLastIndex > f.size() || onePastLastIndex <= firstIndex)
goto end;
QByteArray arr(textsize);
arr = QByteArray(textsize).duplicate((const char*)text,
textsize);
str += QObject::tr(
QString(reinterpret_cast<char*>(key)),
QString(arr) );
index += CHUNK_SIZE(data, index) + CHUNK_HEADER_SIZE;
}
}
}
}
end:
delete[] data;
}
PNGSlave::PNGSlave()
: SlaveInterface("png")
{
}
PNGSlave::~PNGSlave() {
}
QString PNGSlave::iconViewName( const QString& path) {
QString str;
read_comment( path, false, str );
return str;
}
QString PNGSlave::fullImageInfo( const QString& path) {
- QString str;
+ QString str = "<qt>";
read_comment( path, true, str );
+ str += "</qt>";
return str;
}
QPixmap PNGSlave::pixmap( const QString& path, int width, int height) {
QImage img; img.load( path );
if ( img.isNull() )
return QPixmap();
else
return ThumbNailTool::scaleImage( img, width,height );
}