summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/gui/iconview.cpp
blob: a41ce9f8199e46a3ce3f7833377de92b828b336d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
/*
 * GPLv2 zecke@handhelds.org
 * No WArranty...
 */

#include "iconview.h"

#include <lib/imagecache.h>
#include <gui/imageinfoui.h>

#include <iface/dirview.h>
#include <iface/dirlister.h>

#include <opie2/oconfig.h>
#include <opie2/okeyconfigwidget.h>
#include <opie2/odebug.h>
#include <opie2/oimagescrollview.h>

#include <qpe/resource.h>
#include <qpe/qpemessagebox.h>
#include <qpe/ir.h>
#include <qpe/qcopenvelope_qws.h>
#include <qpe/qpeapplication.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::Core::OKeyConfigItem;

/*
 * The Icons, Request Cache and IconViewItem for the IconView
 */
namespace {
    static QPixmap* _dirPix = 0;
    static QPixmap* _unkPix = 0;
    static QPixmap* _emptyPix = 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& );
        bool textOnly()const{return m_textOnly;}
        void setTextOnly(bool how){m_textOnly=how;}
        /* just for starting recalc of item rect! */
        virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE );
        /* just for starting recalc of item rect! */
        virtual void setPixmap( const QPixmap & icon);

    protected:
        mutable QPixmap* m_pix;

    private:
        QString m_path;
        bool m_isDir : 1;
        bool m_noInfo :1;
        bool m_textOnly:1;
        bool m_NameOnly:1;
        bool m_Pixset:1;
    };
    class TextViewItem : public IconViewItem {
        TextViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false );
        QPixmap *pixmap()const;
        void setText( const QString& );
    };
    class ThumbViewItem : public IconViewItem {
        ThumbViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false );
        QPixmap *pixmap()const;
        void setText( const QString& );
    };


/*
 * If we request an Image or String
 * we add it to the map
 */
    static QMap<QString, IconViewItem*> g_stringInf;
    static QMap<QString, IconViewItem*> g_stringPix;

    IconViewItem::IconViewItem( QIconView* view,const QString& path,
                                const QString& name, bool isDir )
        : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ),
          m_noInfo( false ),m_textOnly(false),m_Pixset(false)
    {
        if ( isDir && !_dirPix )
            _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser"));
        else if ( !isDir && !_unkPix )
            _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) );
    }

    inline void IconViewItem::setPixmap( const QPixmap & , bool, bool )
    {
        m_Pixset = true;
        calcRect(text());
    }
    inline void IconViewItem::setPixmap( const QPixmap & )
    {
        m_Pixset = true;
        calcRect(text());
    }

    inline QPixmap* IconViewItem::pixmap()const {
//      owarn << "Name is " << m_path.right( 15 ) << " rect is " << rect().x() << " " << rect().y()
//            << " " << rect().width() << " " << rect().height() << " | " << iconView()->contentsX()
//            << " " << iconView()->contentsY() << oendl;

        if (textOnly()&&!m_isDir) {
            if (!_emptyPix) _emptyPix = new QPixmap(0,0,1);
            return _emptyPix;
        }
        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 );
    }
}


/*
 * Set up the GUI.. initialize the slave set up gui
 * and also load a dir
 */
PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg )
    : QVBox( wid ), m_cfg( cfg ), m_updatet( false )
{
    {
        QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" );
    }
    m_path = QDir::homeDirPath();
    m_mode = 0;

    QHBox *hbox = new QHBox( this );
    QLabel* lbl = new QLabel( hbox );
    lbl->setText(  tr("View as" ) );

    m_views = new QComboBox( hbox, "View As" );

    m_view= new QIconView( this );
    connect(m_view, SIGNAL(clicked(QIconViewItem*) ),
            this, SLOT(slotClicked(QIconViewItem*)) );
    connect(m_view, SIGNAL(returnPressed(QIconViewItem*)),
            this, SLOT(slotClicked(QIconViewItem*)) );

    m_view->setArrangement( QIconView::LeftToRight );

    m_mode = m_cfg->readNumEntry("ListViewMode", 1);
    QString lastView = m_cfg->readEntry("LastView","");

    if (m_mode < 1 || m_mode>3) m_mode = 1;

    m_view->setItemTextPos( QIconView::Right );

    calculateGrid();

    initKeys();

    loadViews();
    int cc=0;
    for (; cc<m_views->count();++cc) {
        if (m_views->text(cc)==lastView) {
            break;
        }
    }
    if (cc<m_views->count()) {
        m_views->setCurrentItem(cc);
        slotViewChanged(cc);
    } else {
        slotViewChanged(m_views->currentItem());
    }
    connect( m_views, SIGNAL(activated(int)),
             this, SLOT(slotViewChanged(int)) );
}

/*
 * Unref the slave and save the keyboard manager
 */
PIconView::~PIconView() {
    {
        QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" );
    }
    m_viewManager->save();
    delete m_viewManager;
}

Opie::Core::OKeyConfigManager* PIconView::manager() {
    return m_viewManager;
}


/*
 * init the KeyBoard Shortcuts
 * called from the c'tor
 */
void PIconView::initKeys() {
    Opie::Core::OKeyPair::List lst;
    lst.append( Opie::Core::OKeyPair::upArrowKey() );
    lst.append( Opie::Core::OKeyPair::downArrowKey() );
    lst.append( Opie::Core::OKeyPair::leftArrowKey() );
    lst.append( Opie::Core::OKeyPair::rightArrowKey() );
    lst.append( Opie::Core::OKeyPair::returnKey() );

    m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config",
                                                    lst, false,this, "keyconfig name" );
    m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam",
                                                Resource::loadPixmap("beam"), BeamItem,
                                                Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton),
                                                this, SLOT(slotBeam())) );
    m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete",
                                                Resource::loadPixmap("trash"), DeleteItem,
                                                Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton),
                                                this, SLOT(slotTrash())) );
    m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view",
                                                Resource::loadPixmap("1to1"), ViewItem,
                                                Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton),
                                                this, SLOT(slotShowImage())));
    m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info",
                                                Resource::loadPixmap("DocumentTypeWord"), InfoItem,
                                                Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ),
                                                this, SLOT(slotImageInfo()) ) );
    m_viewManager->addKeyConfig( OKeyConfigItem(tr("Start slideshow"), "slideshow",
                                                Resource::loadPixmap("1to1"), SlideItem,
                                                Opie::Core::OKeyPair(Qt::Key_S, Qt::ShiftButton),
                                                this, SLOT(slotStartSlide())));
    m_viewManager->load();
    m_viewManager->handleWidget( m_view );
}


/*
 * change one dir up
 */
void PIconView::slotDirUp()
{
    slotChangeDir( currentView()->dirLister()->dirUp( m_path ) );
}

/*
 * change the dir
 */
void PIconView::slotChangeDir(const QString& path) {
    if ( !currentView() )
        return;

    PDirLister *lister = currentView()->dirLister();
    if (!lister )
        return;

    /*
     * Say what we want and take what we get
     */
    lister->setStartPath(  path );
    m_path = lister->currentPath();

    m_view->viewport()->setUpdatesEnabled( false );
    m_view->clear();

    /*
     * add files and folders
     */
    addFolders( lister->folders() );
    addFiles( lister->files() );
    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 ) );
}

/**
 * get the current file name
 * @param isDir see if this is a dir or real file
 */
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();
}

QString PIconView::nextFileName(bool &isDir)const
{
    isDir = false;
    QIconViewItem* _it1 = m_view->currentItem();
    if ( !_it1 )
        return QString::null;
    QIconViewItem* _it = _it1->nextItem();
    if ( !_it )
        return QString::null;
    IconViewItem* it = static_cast<IconViewItem*>( _it );
    isDir = it->isDir();
    return it->path();
}

QString PIconView::prevFileName(bool &isDir)const{
    isDir = false;
    QIconViewItem* _it = m_view->currentItem();
    if ( !_it )
        return QString::null;
    _it = _it->prevItem();
    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();
}

/*
 * see what views are available
 */
void PIconView::loadViews() {
    ViewMap::Iterator it;
    ViewMap* map = viewMap();
    for ( it = map->begin(); it != map->end(); ++it )
        m_views->insertItem(  it.key()  );
}

void PIconView::resetView() {
    slotViewChanged(m_views->currentItem());
}

/*
 *swicth view reloadDir and connect signals
 */
void PIconView::slotViewChanged( int i) {
    if (!m_views->count() ) {
        setCurrentView( 0l);
        return;
    }

    PDirView* cur = currentView();
    if (cur) delete cur;
    QString str = m_views->text(i);
    ViewMap* map = viewMap();
    if (!map) {
        setCurrentView(0l);
        return;
    }

    if (map->find(str) == map->end()) {
        owarn << "Key not found" << oendl;
        setCurrentView(0l);
        return;
    }

    m_cfg->writeEntry("LastView",str);
    m_cfg->write();
    cur = (*(*map)[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 with default Path*/
    m_path = lis->defaultPath();
    QTimer::singleShot( 0,  this, SLOT(slotReloadDir()));
}


void PIconView::slotReloadDir() {
    slotChangeDir( m_path );
}


/*
 * add files and folders
 */
void PIconView::addFolders(  const QStringList& lst) {
    QStringList::ConstIterator it;
    IconViewItem * _iv;

    for(it=lst.begin(); it != lst.end(); ++it ) {
        _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it), true );
        if (m_mode==3) _iv->setTextOnly(true);
    }
}

void PIconView::addFiles(  const QStringList& lst) {
    QStringList::ConstIterator it;
    IconViewItem * _iv;
    QPixmap*m_pix = 0;
    QString pre = "";
    if (!m_path.isEmpty()) {
        pre = m_path+"/";
    }
    for (it=lst.begin(); it!= lst.end(); ++it ) {
         m_pix = PPixmapCache::self()->cachedImage( pre+(*it), 64, 64 );
        _iv = new IconViewItem( m_view, pre+(*it), (*it) );
        if (m_mode==3) {
            _iv->setTextOnly(true);
            _iv->setPixmap(QPixmap());



        } else {
            if (m_pix) _iv->setPixmap(*m_pix);
        }
    }

}

/*
 * user clicked on the item. Change dir or view
 */
void PIconView::slotClicked(QIconViewItem* _it) {
    if(!_it )
        return;

    IconViewItem* it = static_cast<IconViewItem*>(_it);
    if( it->isDir() )
        slotChangeDir( it->path() );
    else // view image
        slotShowImage();
}

/*
 * Return was pressed. which is triggered by the keydown
 * handler. The problem is that the key up will be handled
 * by the ImageDisplayer and goes to the next image
 */
void PIconView::slotRetrun( QIconViewItem *_it ) {
    if(!_it )
        return;

    IconViewItem* it = static_cast<IconViewItem*>(_it);
    if( it->isDir() )
        slotChangeDir( it->path() );
    else
        QTimer::singleShot(0, this, SLOT(slotShowImage()) );
}

/*
 * got thumb info add to the cache if items is visible
 * we later need update after processing of slave is done
 */
void PIconView::slotThumbInfo( const QString& _path, const QString& str ) {
    IconViewItem* item = g_stringInf[_path];
    if (!item )
        return;

    if (m_mode == 2) {
        return;
    }
    if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(),
                                 m_view->contentsWidth(), m_view->contentsHeight() ) ) )
        m_updatet = true;

    item->setText( str );
    g_stringInf.remove( _path );
}

/*
 * got thumbnail and see if it is visible so we need to update later
 */
void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) {
    IconViewItem* item = g_stringPix[_path];
    if (!item )
        return;

    if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(),
                                 m_view->contentsWidth(), m_view->contentsHeight() ) ) )
        m_updatet = true;

    if (pix.width()>0) {
        PPixmapCache::self()->insertImage( _path, pix, 64, 64 );
        item->setPixmap(pix,true);
    } else {
        PPixmapCache::self()->insertImage( _path, Resource::loadPixmap( "UnknownDocument" ), 64, 64 );
    }
    g_stringPix.remove( _path );
}


/*
 * FIXME rename
 */
void PIconView::slotRename() {

}


/*
 * BEAM the current file
 */
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" ) );
}

/*
 * BEAM done clean up
 */
void PIconView::slotBeamDone( Ir* ir) {
    delete ir;
}

void PIconView::slotStart() {
    m_view->viewport()->setUpdatesEnabled( false );
}

void PIconView::slotEnd() {
    if ( m_updatet )
        m_view->arrangeItemsInGrid( );
    m_view->viewport()->setUpdatesEnabled( true );
    m_updatet = false;
}

void PIconView::slotShowLast()
{
    QIconViewItem* last_it = m_view->lastItem();
    if (!last_it) return;
    m_view->setCurrentItem(last_it);
    IconViewItem* it = static_cast<IconViewItem*>( last_it );
    bool isDir = it->isDir();
    QString name = it->path();
    if (!isDir && !name.isEmpty()) {
        slotShowImage(name);
        return;
    }
    bool first_loop = true;
    while(isDir==true) {
        if (!first_loop) {
            m_view->setCurrentItem(m_view->currentItem()->prevItem());
        } else {
            first_loop = false;
        }
        name = prevFileName(isDir);
    }

    if (name.isEmpty()) return;
    /* if we got a name we have a prev item */
    m_view->setCurrentItem(m_view->currentItem()->prevItem());
    slotShowImage(name);
}

bool PIconView::slotShowFirst()
{
    /* stop when reached - otherwise we may get an endless loop */
    QIconViewItem* first_it = m_view->firstItem();
    if (!first_it) return false;
    m_view->setCurrentItem(first_it);
    IconViewItem* it = static_cast<IconViewItem*>( first_it );
    bool isDir = it->isDir();
    QString name = it->path();
    if (!isDir && !name.isEmpty()) {
        slotShowImage(name);
        return false;
    }
    bool first_loop = true;
    while(isDir==true) {
        /* if name is empty isDir is false, too. */
        if (!first_loop) {
            m_view->setCurrentItem(m_view->currentItem()->nextItem());
        } else {
            first_loop = false;
        }
        name = nextFileName(isDir);
    }
    if (name.isEmpty()) return false;
    /* if we got a name we have a next item */
    m_view->setCurrentItem(m_view->currentItem()->nextItem());
    slotShowImage(name);
    return true;
}

void PIconView::slotShowNext()
{
    bool isDir = false;
    QString name = nextFileName(isDir);
    while (isDir==true) {
        m_view->setCurrentItem(m_view->currentItem()->nextItem());
        name = nextFileName(isDir);
    }
    if (name.isEmpty()) {
        slotShowFirst();
        return;
    }
    if (isDir) return;
    /* if we got a name we have a next item */
    m_view->setCurrentItem(m_view->currentItem()->nextItem());
    slotShowImage(name);
}

void PIconView::slotShowPrev()
{
    bool isDir = false;
    QString name = prevFileName(isDir);
    while (isDir==true) {
        /* if name is empty isDir is false, too. */
        m_view->setCurrentItem(m_view->currentItem()->prevItem());
        name = prevFileName(isDir);
    }
    if (name.isEmpty()) {
        slotShowLast();
        return;
    }
    if (isDir) return;
    /* if we got a name we have a prev item */
    m_view->setCurrentItem(m_view->currentItem()->prevItem());
    slotShowImage(name);
}

void PIconView::slotShowImage()
{
    bool isDir = false;
    QString name = currentFileName(isDir);
    if (isDir) return;
    slotShowImage( name );
}
void PIconView::slotShowImage( const QString& name) {
    PDirLister *lister = currentView()->dirLister();
    QString r_name = lister->nameToFname(name);
    emit sig_display(r_name);
}

void PIconView::slotStartSlide() {
    bool isDir = false;
    QString name = currentFileName(isDir);
    if (isDir) {
        if (!slotShowFirst())
            return;
    } else {
        slotShowImage( name );
    }
    emit sig_startslide(2);
}

void PIconView::slotImageInfo() {
    bool isDir = false;
    QString name = currentFileName(isDir);
    if (isDir) return;
    slotImageInfo( name );
}

void PIconView::slotImageInfo( const QString& name) {
    PDirLister *lister = currentView()->dirLister();
    QString r_name = lister->nameToFname(name);
    emit sig_showInfo(r_name );
}


void PIconView::slotChangeMode( int mode ) {
    if ( mode >= 1 && mode <= 3 )
        m_mode = mode;

    m_cfg->writeEntry("ListViewMode", m_mode);
    /* performance! */
    m_view->clear();
    calculateGrid();
    slotReloadDir();
}


void PIconView::resizeEvent( QResizeEvent* re ) {
    QVBox::resizeEvent( re );
    calculateGrid();
}


void PIconView::calculateGrid() {
    int dw = QApplication::desktop()->width();
    int viewerWidth = dw-style().scrollBarExtent().width();

    QIconView::ItemTextPos pos;
    switch( m_mode ) {
    case 2:
        pos = QIconView::Bottom;
        break;
    case 3:
    case 1:
    default:
        pos = QIconView::Right;
        break;
    }
    m_view->setItemTextPos( pos );
    switch (m_mode) {
        case 2:
            m_view->setGridX(50);
            m_view->setGridY(20);
            PPixmapCache::self()->setMaxImages(40);
            break;
        case 3:
            m_view->setGridX( fontMetrics().width("testimage.jpg")+20);
            m_view->setGridY(8);
            PPixmapCache::self()->setMaxImages(2);
            break;
        case 1:
        default:
            m_view->setGridX( viewerWidth-3*m_view->spacing());
            m_view->setGridY( fontMetrics().height()*2+40 );
            PPixmapCache::self()->setMaxImages(20);
            break;
    }
}