summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp
index f173ecc..5472ead 100644
--- a/noncore/graphics/opie-eye/gui/iconview.cpp
+++ b/noncore/graphics/opie-eye/gui/iconview.cpp
@@ -1,634 +1,637 @@
1/* 1/*
2 * GPLv2 zecke@handhelds.org 2 * GPLv2 zecke@handhelds.org
3 * No WArranty... 3 * No WArranty...
4 */ 4 */
5 5
6#include "iconview.h" 6#include "iconview.h"
7 7
8#include <lib/imagecache.h> 8#include <lib/imagecache.h>
9#include <gui/imageinfoui.h> 9#include <gui/imageinfoui.h>
10 10
11#include <iface/dirview.h> 11#include <iface/dirview.h>
12#include <iface/dirlister.h> 12#include <iface/dirlister.h>
13 13
14#include <opie2/oconfig.h> 14#include <opie2/oconfig.h>
15#include <opie2/okeyconfigwidget.h> 15#include <opie2/okeyconfigwidget.h>
16#include <opie2/odebug.h> 16#include <opie2/odebug.h>
17#include <opie2/oimagescrollview.h> 17#include <opie2/oimagescrollview.h>
18 18
19#include <qpe/resource.h> 19#include <qpe/resource.h>
20#include <qpe/qpemessagebox.h> 20#include <qpe/qpemessagebox.h>
21#include <qpe/ir.h> 21#include <qpe/ir.h>
22#include <qpe/qcopenvelope_qws.h> 22#include <qpe/qcopenvelope_qws.h>
23#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24 24
25#include <qiconview.h> 25#include <qiconview.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qhbox.h> 27#include <qhbox.h>
28#include <qcombobox.h> 28#include <qcombobox.h>
29#include <qdir.h> 29#include <qdir.h>
30#include <qapplication.h> 30#include <qapplication.h>
31#include <qmainwindow.h> 31#include <qmainwindow.h>
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qstyle.h> 33#include <qstyle.h>
34 34
35 35
36using Opie::Core::OKeyConfigItem; 36using Opie::Core::OKeyConfigItem;
37 37
38/* 38/*
39 * The Icons, Request Cache and IconViewItem for the IconView 39 * The Icons, Request Cache and IconViewItem for the IconView
40 */ 40 */
41namespace { 41namespace {
42 static QPixmap* _dirPix = 0; 42 static QPixmap* _dirPix = 0;
43 static QPixmap* _unkPix = 0; 43 static QPixmap* _unkPix = 0;
44 static QPixmap* _cpyPix = 0; 44 static QPixmap* _cpyPix = 0;
45 static QPixmap* _emptyPix = 0; 45 static QPixmap* _emptyPix = 0;
46 class IconViewItem : public QIconViewItem { 46 class IconViewItem : public QIconViewItem {
47 public: 47 public:
48 IconViewItem( QIconView*, const QString& path, const QString& name,int a_iconsize, bool isDir = false); 48 IconViewItem( QIconView*, const QString& path, const QString& name,int a_iconsize, bool isDir = false);
49 QPixmap* pixmap()const; 49 QPixmap* pixmap()const;
50 QString path()const { return m_path; } 50 QString path()const { return m_path; }
51 bool isDir()const { return m_isDir; } 51 bool isDir()const { return m_isDir; }
52 void setText( const QString& ); 52 void setText( const QString& );
53 bool textOnly()const{return m_textOnly;} 53 bool textOnly()const{return m_textOnly;}
54 void setTextOnly(bool how){m_textOnly=how;} 54 void setTextOnly(bool how){m_textOnly=how;}
55 /* just for starting recalc of item rect! */ 55 /* just for starting recalc of item rect! */
56 virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE ); 56 virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE );
57 /* just for starting recalc of item rect! */ 57 /* just for starting recalc of item rect! */
58 virtual void setPixmap( const QPixmap & icon); 58 virtual void setPixmap( const QPixmap & icon);
59 59
60 protected: 60 protected:
61 mutable QPixmap* m_pix; 61 mutable QPixmap* m_pix;
62 int m_iconsize; 62 int m_iconsize;
63 void check_pix()const; 63 void check_pix()const;
64 64
65 private: 65 private:
66 QString m_path; 66 QString m_path;
67 bool m_isDir : 1; 67 bool m_isDir : 1;
68 bool m_noInfo :1; 68 bool m_noInfo :1;
69 bool m_textOnly:1; 69 bool m_textOnly:1;
70 bool m_NameOnly:1; 70 bool m_NameOnly:1;
71 bool m_Pixset:1; 71 bool m_Pixset:1;
72 }; 72 };
73 class TextViewItem : public IconViewItem { 73 class TextViewItem : public IconViewItem {
74 TextViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize , bool isDir = false); 74 TextViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize , bool isDir = false);
75 QPixmap *pixmap()const; 75 QPixmap *pixmap()const;
76 void setText( const QString& ); 76 void setText( const QString& );
77 }; 77 };
78 class ThumbViewItem : public IconViewItem { 78 class ThumbViewItem : public IconViewItem {
79 ThumbViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize, bool isDir = false ); 79 ThumbViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize, bool isDir = false );
80 QPixmap *pixmap()const; 80 QPixmap *pixmap()const;
81 void setText( const QString& ); 81 void setText( const QString& );
82 }; 82 };
83 83
84 84
85/* 85/*
86 * If we request an Image or String 86 * If we request an Image or String
87 * we add it to the map 87 * we add it to the map
88 */ 88 */
89 static QMap<QString, IconViewItem*> g_stringInf; 89 static QMap<QString, IconViewItem*> g_stringInf;
90 static QMap<QString, IconViewItem*> g_stringPix; 90 static QMap<QString, IconViewItem*> g_stringPix;
91 91
92 IconViewItem::IconViewItem( QIconView* view,const QString& path, 92 IconViewItem::IconViewItem( QIconView* view,const QString& path,
93 const QString& name, int a_iconsize, bool isDir) 93 const QString& name, int a_iconsize, bool isDir)
94 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), 94 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ),
95 m_noInfo( false ),m_textOnly(false),m_Pixset(false) 95 m_noInfo( false ),m_textOnly(false),m_Pixset(false)
96 { 96 {
97 m_iconsize = a_iconsize; 97 m_iconsize = a_iconsize;
98 if ( isDir ) { 98 if ( isDir ) {
99 if (!_dirPix ) { 99 if (!_dirPix ) {
100 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); 100 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser"));
101 } 101 }
102 } else { 102 } else {
103 if (!_unkPix ) { 103 if (!_unkPix ) {
104 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); 104 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) );
105 } 105 }
106 } 106 }
107 check_pix(); 107 check_pix();
108 } 108 }
109 109
110 inline void IconViewItem::check_pix()const 110 inline void IconViewItem::check_pix()const
111 { 111 {
112 if (_dirPix && _dirPix->width()>m_iconsize) { 112 if (_dirPix && _dirPix->width()>m_iconsize) {
113 QPixmap*Pix = new QPixmap(*_dirPix); 113 QImage Pix = _dirPix->convertToImage();
114 Pix->resize(m_iconsize,m_iconsize); 114 *_dirPix = Pix.smoothScale(m_iconsize,m_iconsize);
115 delete _dirPix;
116 _dirPix = Pix;
117 } 115 }
118 if (!_cpyPix && _unkPix) { 116 if (!_cpyPix && _unkPix) {
119 if (_unkPix->width()>=m_iconsize) { 117 if (_unkPix->width()>=m_iconsize) {
120 _cpyPix = new QPixmap(*_unkPix); 118 QImage Pix = _unkPix->convertToImage();
121 if (_unkPix->width()>m_iconsize) 119 _cpyPix = new QPixmap();
122 _cpyPix->resize(m_iconsize,m_iconsize); 120 if (_unkPix->width()>m_iconsize) {
121 *_cpyPix = Pix.smoothScale(m_iconsize,m_iconsize);
122 } else {
123 _cpyPix->convertFromImage(Pix);
124 }
125
123 } else { 126 } else {
124 _cpyPix = new QPixmap(m_iconsize,m_iconsize); 127 _cpyPix = new QPixmap(m_iconsize,m_iconsize);
125 _cpyPix->fill(); 128 _cpyPix->fill();
126 QPainter pa(_cpyPix); 129 QPainter pa(_cpyPix);
127 int offset = (m_iconsize-_unkPix->width())/2; 130 int offset = (m_iconsize-_unkPix->width())/2;
128 int offy = (m_iconsize-_unkPix->height())/2; 131 int offy = (m_iconsize-_unkPix->height())/2;
129 if (offy<0) offy=0; 132 if (offy<0) offy=0;
130 pa.drawPixmap(offset,offy,*_unkPix); 133 pa.drawPixmap(offset,offy,*_unkPix);
131 pa.end(); 134 pa.end();
132 } 135 }
133 } 136 }
134 } 137 }
135 138
136 inline void IconViewItem::setPixmap( const QPixmap & , bool, bool ) 139 inline void IconViewItem::setPixmap( const QPixmap & , bool, bool )
137 { 140 {
138 m_Pixset = true; 141 m_Pixset = true;
139 calcRect(text()); 142 calcRect(text());
140 } 143 }
141 inline void IconViewItem::setPixmap( const QPixmap & ) 144 inline void IconViewItem::setPixmap( const QPixmap & )
142 { 145 {
143 m_Pixset = true; 146 m_Pixset = true;
144 calcRect(text()); 147 calcRect(text());
145 } 148 }
146 149
147 inline QPixmap* IconViewItem::pixmap()const { 150 inline QPixmap* IconViewItem::pixmap()const {
148// owarn << "Name is " << m_path.right( 15 ) << " rect is " << rect().x() << " " << rect().y() 151// owarn << "Name is " << m_path.right( 15 ) << " rect is " << rect().x() << " " << rect().y()
149// << " " << rect().width() << " " << rect().height() << " | " << iconView()->contentsX() 152// << " " << rect().width() << " " << rect().height() << " | " << iconView()->contentsX()
150// << " " << iconView()->contentsY() << oendl; 153// << " " << iconView()->contentsY() << oendl;
151 154
152 if (textOnly()&&!m_isDir) { 155 if (textOnly()&&!m_isDir) {
153 if (!_emptyPix) _emptyPix = new QPixmap(0,0,1); 156 if (!_emptyPix) _emptyPix = new QPixmap(0,0,1);
154 return _emptyPix; 157 return _emptyPix;
155 } 158 }
156 if ( m_isDir ) 159 if ( m_isDir )
157 return _dirPix; 160 return _dirPix;
158 else{ 161 else{
159 if (!m_noInfo && !g_stringInf.contains( m_path ) ) { 162 if (!m_noInfo && !g_stringInf.contains( m_path ) ) {
160 g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); 163 g_stringInf.insert( m_path, const_cast<IconViewItem*>(this));
161 currentView()->dirLister()->imageInfo( m_path ); 164 currentView()->dirLister()->imageInfo( m_path );
162 } 165 }
163 166
164 m_pix = PPixmapCache::self()->cachedImage( m_path, m_iconsize, m_iconsize ); 167 m_pix = PPixmapCache::self()->cachedImage( m_path, m_iconsize, m_iconsize );
165 if (!m_pix && !g_stringPix.contains( m_path )) { 168 if (!m_pix && !g_stringPix.contains( m_path )) {
166 check_pix(); 169 check_pix();
167 g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); 170 g_stringPix.insert( m_path, const_cast<IconViewItem*>(this));
168 currentView()->dirLister()->thumbNail( m_path, m_iconsize, m_iconsize); 171 currentView()->dirLister()->thumbNail( m_path, m_iconsize, m_iconsize);
169 } 172 }
170 return m_pix ? m_pix : _cpyPix; 173 return m_pix ? m_pix : _cpyPix;
171 } 174 }
172 } 175 }
173 inline void IconViewItem::setText( const QString& str ) { 176 inline void IconViewItem::setText( const QString& str ) {
174 QString text = QIconViewItem::text()+"\n"+str; 177 QString text = QIconViewItem::text()+"\n"+str;
175 m_noInfo = true; 178 m_noInfo = true;
176 QIconViewItem::setText( text ); 179 QIconViewItem::setText( text );
177 } 180 }
178} 181}
179 182
180 183
181/* 184/*
182 * Set up the GUI.. initialize the slave set up gui 185 * Set up the GUI.. initialize the slave set up gui
183 * and also load a dir 186 * and also load a dir
184 */ 187 */
185PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) 188PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg )
186 : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) 189 : QVBox( wid ), m_cfg( cfg ), m_updatet( false )
187{ 190{
188 { 191 {
189 QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); 192 QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" );
190 } 193 }
191 m_path = QDir::homeDirPath(); 194 m_path = QDir::homeDirPath();
192 m_mode = 0; 195 m_mode = 0;
193 m_iconsize = 32; 196 m_iconsize = 32;
194 m_internalReset = false; 197 m_internalReset = false;
195 198
196 QHBox *hbox = new QHBox( this ); 199 QHBox *hbox = new QHBox( this );
197 QLabel* lbl = new QLabel( hbox ); 200 QLabel* lbl = new QLabel( hbox );
198 lbl->setText( tr("View as" ) ); 201 lbl->setText( tr("View as" ) );
199 202
200 m_views = new QComboBox( hbox, "View As" ); 203 m_views = new QComboBox( hbox, "View As" );
201 204
202 m_view= new QIconView( this ); 205 m_view= new QIconView( this );
203 connect(m_view, SIGNAL(clicked(QIconViewItem*) ), 206 connect(m_view, SIGNAL(clicked(QIconViewItem*) ),
204 this, SLOT(slotClicked(QIconViewItem*)) ); 207 this, SLOT(slotClicked(QIconViewItem*)) );
205 connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), 208 connect(m_view, SIGNAL(returnPressed(QIconViewItem*)),
206 this, SLOT(slotClicked(QIconViewItem*)) ); 209 this, SLOT(slotClicked(QIconViewItem*)) );
207 210
208 m_view->setArrangement( QIconView::LeftToRight ); 211 m_view->setArrangement( QIconView::LeftToRight );
209 212
210 m_mode = m_cfg->readNumEntry("ListViewMode", 1); 213 m_mode = m_cfg->readNumEntry("ListViewMode", 1);
211 QString lastView = m_cfg->readEntry("LastView",""); 214 QString lastView = m_cfg->readEntry("LastView","");
212 215
213 if (m_mode < 1 || m_mode>3) m_mode = 1; 216 if (m_mode < 1 || m_mode>3) m_mode = 1;
214 217
215 m_view->setItemTextPos( QIconView::Right ); 218 m_view->setItemTextPos( QIconView::Right );
216 if (m_mode >1) { 219 if (m_mode >1) {
217 m_view->setResizeMode(QIconView::Adjust); 220 m_view->setResizeMode(QIconView::Adjust);
218 } else { 221 } else {
219 m_view->setResizeMode(QIconView::Fixed); 222 m_view->setResizeMode(QIconView::Fixed);
220 } 223 }
221 m_iconsize = m_cfg->readNumEntry("iconsize", 32); 224 m_iconsize = m_cfg->readNumEntry("iconsize", 32);
222 if (m_iconsize<12)m_iconsize = 12; 225 if (m_iconsize<12)m_iconsize = 12;
223 if (m_iconsize>64)m_iconsize = 64; 226 if (m_iconsize>64)m_iconsize = 64;
224 227
225 calculateGrid(); 228 calculateGrid();
226 229
227 initKeys(); 230 initKeys();
228 231
229 loadViews(); 232 loadViews();
230 int cc=0; 233 int cc=0;
231 for (; cc<m_views->count();++cc) { 234 for (; cc<m_views->count();++cc) {
232 if (m_views->text(cc)==lastView) { 235 if (m_views->text(cc)==lastView) {
233 break; 236 break;
234 } 237 }
235 } 238 }
236 if (cc<m_views->count()) { 239 if (cc<m_views->count()) {
237 m_views->setCurrentItem(cc); 240 m_views->setCurrentItem(cc);
238 slotViewChanged(cc); 241 slotViewChanged(cc);
239 } else { 242 } else {
240 slotViewChanged(m_views->currentItem()); 243 slotViewChanged(m_views->currentItem());
241 } 244 }
242 connect( m_views, SIGNAL(activated(int)), 245 connect( m_views, SIGNAL(activated(int)),
243 this, SLOT(slotViewChanged(int)) ); 246 this, SLOT(slotViewChanged(int)) );
244} 247}
245 248
246/* 249/*
247 * Unref the slave and save the keyboard manager 250 * Unref the slave and save the keyboard manager
248 */ 251 */
249PIconView::~PIconView() { 252PIconView::~PIconView() {
250 { 253 {
251 QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); 254 QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" );
252 } 255 }
253 m_viewManager->save(); 256 m_viewManager->save();
254 delete m_viewManager; 257 delete m_viewManager;
255} 258}
256 259
257Opie::Core::OKeyConfigManager* PIconView::manager() { 260Opie::Core::OKeyConfigManager* PIconView::manager() {
258 return m_viewManager; 261 return m_viewManager;
259} 262}
260 263
261 264
262/* 265/*
263 * init the KeyBoard Shortcuts 266 * init the KeyBoard Shortcuts
264 * called from the c'tor 267 * called from the c'tor
265 */ 268 */
266void PIconView::initKeys() { 269void PIconView::initKeys() {
267 Opie::Core::OKeyPair::List lst; 270 Opie::Core::OKeyPair::List lst;
268 lst.append( Opie::Core::OKeyPair::upArrowKey() ); 271 lst.append( Opie::Core::OKeyPair::upArrowKey() );
269 lst.append( Opie::Core::OKeyPair::downArrowKey() ); 272 lst.append( Opie::Core::OKeyPair::downArrowKey() );
270 lst.append( Opie::Core::OKeyPair::leftArrowKey() ); 273 lst.append( Opie::Core::OKeyPair::leftArrowKey() );
271 lst.append( Opie::Core::OKeyPair::rightArrowKey() ); 274 lst.append( Opie::Core::OKeyPair::rightArrowKey() );
272 lst.append( Opie::Core::OKeyPair::returnKey() ); 275 lst.append( Opie::Core::OKeyPair::returnKey() );
273 276
274 m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", 277 m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config",
275 lst, false,this, "keyconfig name" ); 278 lst, false,this, "keyconfig name" );
276 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", 279 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam",
277 Resource::loadPixmap("beam"), BeamItem, 280 Resource::loadPixmap("beam"), BeamItem,
278 Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton), 281 Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton),
279 this, SLOT(slotBeam())) ); 282 this, SLOT(slotBeam())) );
280 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", 283 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete",
281 Resource::loadPixmap("trash"), DeleteItem, 284 Resource::loadPixmap("trash"), DeleteItem,
282 Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton), 285 Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton),
283 this, SLOT(slotTrash())) ); 286 this, SLOT(slotTrash())) );
284 m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", 287 m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view",
285 Resource::loadPixmap("1to1"), ViewItem, 288 Resource::loadPixmap("1to1"), ViewItem,
286 Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), 289 Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton),
287 this, SLOT(slotShowImage()))); 290 this, SLOT(slotShowImage())));
288 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", 291 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info",
289 Resource::loadPixmap("DocumentTypeWord"), InfoItem, 292 Resource::loadPixmap("DocumentTypeWord"), InfoItem,
290 Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ), 293 Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ),
291 this, SLOT(slotImageInfo()) ) ); 294 this, SLOT(slotImageInfo()) ) );
292 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Start slideshow"), "slideshow", 295 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Start slideshow"), "slideshow",
293 Resource::loadPixmap("1to1"), SlideItem, 296 Resource::loadPixmap("1to1"), SlideItem,
294 Opie::Core::OKeyPair(Qt::Key_S, Qt::ShiftButton), 297 Opie::Core::OKeyPair(Qt::Key_S, Qt::ShiftButton),
295 this, SLOT(slotStartSlide()))); 298 this, SLOT(slotStartSlide())));
296 m_viewManager->load(); 299 m_viewManager->load();
297 m_viewManager->handleWidget( m_view ); 300 m_viewManager->handleWidget( m_view );
298} 301}
299 302
300 303
301/* 304/*
302 * change one dir up 305 * change one dir up
303 */ 306 */
304void PIconView::slotDirUp() 307void PIconView::slotDirUp()
305{ 308{
306 slotChangeDir( currentView()->dirLister()->dirUp( m_path ) ); 309 slotChangeDir( currentView()->dirLister()->dirUp( m_path ) );
307} 310}
308 311
309/* 312/*
310 * change the dir 313 * change the dir
311 */ 314 */
312void PIconView::slotChangeDir(const QString& path) { 315void PIconView::slotChangeDir(const QString& path) {
313 if ( !currentView() ) 316 if ( !currentView() )
314 return; 317 return;
315 318
316 PDirLister *lister = currentView()->dirLister(); 319 PDirLister *lister = currentView()->dirLister();
317 if (!lister ) 320 if (!lister )
318 return; 321 return;
319 322
320 /* 323 /*
321 * Say what we want and take what we get 324 * Say what we want and take what we get
322 */ 325 */
323 lister->setStartPath( path ); 326 lister->setStartPath( path );
324 m_path = lister->currentPath(); 327 m_path = lister->currentPath();
325 328
326 m_view->viewport()->setUpdatesEnabled( false ); 329 m_view->viewport()->setUpdatesEnabled( false );
327 m_view->clear(); 330 m_view->clear();
328 331
329 // Also invalidate the cache. We can't cancel the operations anyway 332 // Also invalidate the cache. We can't cancel the operations anyway
330 g_stringPix.clear(); 333 g_stringPix.clear();
331 g_stringInf.clear(); 334 g_stringInf.clear();
332 335
333 /* 336 /*
334 * add files and folders 337 * add files and folders
335 */ 338 */
336 addFolders( lister->folders() ); 339 addFolders( lister->folders() );
337 addFiles( lister->files() ); 340 addFiles( lister->files() );
338 m_view->viewport()->setUpdatesEnabled( true ); 341 m_view->viewport()->setUpdatesEnabled( true );
339 342
340 // looks ugly 343 // looks ugly
341 static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); 344 static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) );
342} 345}
343 346
344/** 347/**
345 * get the current file name 348 * get the current file name
346 * @param isDir see if this is a dir or real file 349 * @param isDir see if this is a dir or real file
347 */ 350 */
348QString PIconView::currentFileName(bool &isDir)const { 351QString PIconView::currentFileName(bool &isDir)const {
349 isDir = false; 352 isDir = false;
350 QIconViewItem* _it = m_view->currentItem(); 353 QIconViewItem* _it = m_view->currentItem();
351 if ( !_it ) 354 if ( !_it )
352 return QString::null; 355 return QString::null;
353 356
354 IconViewItem* it = static_cast<IconViewItem*>( _it ); 357 IconViewItem* it = static_cast<IconViewItem*>( _it );
355 isDir = it->isDir(); 358 isDir = it->isDir();
356 return it->path(); 359 return it->path();
357} 360}
358 361
359QString PIconView::nextFileName(bool &isDir)const 362QString PIconView::nextFileName(bool &isDir)const
360{ 363{
361 isDir = false; 364 isDir = false;
362 QIconViewItem* _it1 = m_view->currentItem(); 365 QIconViewItem* _it1 = m_view->currentItem();
363 if ( !_it1 ) 366 if ( !_it1 )
364 return QString::null; 367 return QString::null;
365 QIconViewItem* _it = _it1->nextItem(); 368 QIconViewItem* _it = _it1->nextItem();
366 if ( !_it ) 369 if ( !_it )
367 return QString::null; 370 return QString::null;
368 IconViewItem* it = static_cast<IconViewItem*>( _it ); 371 IconViewItem* it = static_cast<IconViewItem*>( _it );
369 isDir = it->isDir(); 372 isDir = it->isDir();
370 return it->path(); 373 return it->path();
371} 374}
372 375
373QString PIconView::prevFileName(bool &isDir)const{ 376QString PIconView::prevFileName(bool &isDir)const{
374 isDir = false; 377 isDir = false;
375 QIconViewItem* _it = m_view->currentItem(); 378 QIconViewItem* _it = m_view->currentItem();
376 if ( !_it ) 379 if ( !_it )
377 return QString::null; 380 return QString::null;
378 _it = _it->prevItem(); 381 _it = _it->prevItem();
379 if ( !_it ) 382 if ( !_it )
380 return QString::null; 383 return QString::null;
381 IconViewItem* it = static_cast<IconViewItem*>( _it ); 384 IconViewItem* it = static_cast<IconViewItem*>( _it );
382 isDir = it->isDir(); 385 isDir = it->isDir();
383 return it->path(); 386 return it->path();
384} 387}
385 388
386void PIconView::slotTrash() { 389void PIconView::slotTrash() {
387 bool isDir; 390 bool isDir;
388 QString pa = currentFileName( isDir ); 391 QString pa = currentFileName( isDir );
389 if ( isDir && pa.isEmpty() ) 392 if ( isDir && pa.isEmpty() )
390 return; 393 return;
391 394
392 if (!QPEMessageBox::confirmDelete( this, 395 if (!QPEMessageBox::confirmDelete( this,
393 tr("Delete Image" ), 396 tr("Delete Image" ),
394 tr("the Image %1" ).arg(pa))) 397 tr("the Image %1" ).arg(pa)))
395 return 398 return
396 399
397 400
398 currentView()->dirLister()->deleteImage( pa ); 401 currentView()->dirLister()->deleteImage( pa );
399 delete m_view->currentItem(); 402 delete m_view->currentItem();
400} 403}
401 404
402/* 405/*
403 * see what views are available 406 * see what views are available
404 */ 407 */
405void PIconView::loadViews() { 408void PIconView::loadViews() {
406 ViewMap::Iterator it; 409 ViewMap::Iterator it;
407 ViewMap* map = viewMap(); 410 ViewMap* map = viewMap();
408 for ( it = map->begin(); it != map->end(); ++it ) 411 for ( it = map->begin(); it != map->end(); ++it )
409 m_views->insertItem( it.key() ); 412 m_views->insertItem( it.key() );
410} 413}
411 414
412void PIconView::resetView() { 415void PIconView::resetView() {
413 m_internalReset = true; 416 m_internalReset = true;
414 // Also invalidate the cache. We can't cancel the operations anyway 417 // Also invalidate the cache. We can't cancel the operations anyway
415 g_stringPix.clear(); 418 g_stringPix.clear();
416 g_stringInf.clear(); 419 g_stringInf.clear();
417 if (m_mode>1) { 420 if (m_mode>1) {
418 int osize = m_iconsize; 421 int osize = m_iconsize;
419 m_iconsize = m_cfg->readNumEntry("iconsize", 32); 422 m_iconsize = m_cfg->readNumEntry("iconsize", 32);
420 if (m_iconsize<12)m_iconsize = 12; 423 if (m_iconsize<12)m_iconsize = 12;
421 if (m_iconsize>64)m_iconsize = 64; 424 if (m_iconsize>64)m_iconsize = 64;
422 if (osize != m_iconsize) { 425 if (osize != m_iconsize) {
423 if (_dirPix){ 426 if (_dirPix){
424 delete _dirPix; 427 delete _dirPix;
425 _dirPix = 0; 428 _dirPix = 0;
426 } 429 }
427 if (_cpyPix){ 430 if (_cpyPix){
428 delete _cpyPix; 431 delete _cpyPix;
429 _cpyPix = 0; 432 _cpyPix = 0;
430 } 433 }
431 calculateGrid(); 434 calculateGrid();
432 } 435 }
433 } else { 436 } else {
434 m_iconsize = 64; 437 m_iconsize = 64;
435 } 438 }
436 slotViewChanged(m_views->currentItem()); 439 slotViewChanged(m_views->currentItem());
437 m_internalReset = false; 440 m_internalReset = false;
438} 441}
439 442
440/* 443/*
441 *swicth view reloadDir and connect signals 444 *swicth view reloadDir and connect signals
442 */ 445 */
443void PIconView::slotViewChanged( int i) { 446void PIconView::slotViewChanged( int i) {
444 if (!m_views->count() ) { 447 if (!m_views->count() ) {
445 setCurrentView( 0l); 448 setCurrentView( 0l);
446 return; 449 return;
447 } 450 }
448 451
449 PDirView* cur = currentView(); 452 PDirView* cur = currentView();
450 if (cur) delete cur; 453 if (cur) delete cur;
451 QString str = m_views->text(i); 454 QString str = m_views->text(i);
452 ViewMap* map = viewMap(); 455 ViewMap* map = viewMap();
453 if (!map) { 456 if (!map) {
454 setCurrentView(0l); 457 setCurrentView(0l);
455 return; 458 return;
456 } 459 }
457 460
458 if (map->find(str) == map->end()) { 461 if (map->find(str) == map->end()) {
459 owarn << "Key not found" << oendl; 462 owarn << "Key not found" << oendl;
460 setCurrentView(0l); 463 setCurrentView(0l);
461 return; 464 return;
462 } 465 }
463 466
464 m_cfg->writeEntry("LastView",str); 467 m_cfg->writeEntry("LastView",str);
465 m_cfg->write(); 468 m_cfg->write();
466 cur = (*(*map)[str])(*m_cfg); 469 cur = (*(*map)[str])(*m_cfg);
467 setCurrentView( cur ); 470 setCurrentView( cur );
468 471
469 /* connect to the signals of the lister */ 472 /* connect to the signals of the lister */
470 PDirLister* lis = cur->dirLister(); 473 PDirLister* lis = cur->dirLister();
471 connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), 474 connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )),
472 this, SLOT( slotThumbInfo(const QString&, const QString&))); 475 this, SLOT( slotThumbInfo(const QString&, const QString&)));
473 connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), 476 connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)),
474 this, SLOT(slotThumbNail(const QString&, const QPixmap&))); 477 this, SLOT(slotThumbNail(const QString&, const QPixmap&)));
475 connect(lis, SIGNAL(sig_start()), 478 connect(lis, SIGNAL(sig_start()),
476 this, SLOT(slotStart())); 479 this, SLOT(slotStart()));
477 connect(lis, SIGNAL(sig_end()) , 480 connect(lis, SIGNAL(sig_end()) ,
478 this, SLOT(slotEnd()) ); 481 this, SLOT(slotEnd()) );
479 482
480 483
481 /* reload now with default Path 484 /* reload now with default Path
482 * but only if it isn't a reset like from setupdlg 485 * but only if it isn't a reset like from setupdlg
483 */ 486 */
484 if (!m_internalReset) { 487 if (!m_internalReset) {
485 m_path = lis->defaultPath(); 488 m_path = lis->defaultPath();
486 } 489 }
487 QTimer::singleShot( 0, this, SLOT(slotReloadDir())); 490 QTimer::singleShot( 0, this, SLOT(slotReloadDir()));
488} 491}
489 492
490 493
491void PIconView::slotReloadDir() { 494void PIconView::slotReloadDir() {
492 slotChangeDir( m_path ); 495 slotChangeDir( m_path );
493} 496}
494 497
495 498
496/* 499/*
497 * add files and folders 500 * add files and folders
498 */ 501 */
499void PIconView::addFolders( const QStringList& lst) { 502void PIconView::addFolders( const QStringList& lst) {
500 QStringList::ConstIterator it; 503 QStringList::ConstIterator it;
501 IconViewItem * _iv; 504 IconViewItem * _iv;
502 505
503 for(it=lst.begin(); it != lst.end(); ++it ) { 506 for(it=lst.begin(); it != lst.end(); ++it ) {
504 _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it),m_iconsize, true ); 507 _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it),m_iconsize, true );
505 if (m_mode==3) _iv->setTextOnly(true); 508 if (m_mode==3) _iv->setTextOnly(true);
506 } 509 }
507} 510}
508 511
509void PIconView::addFiles( const QStringList& lst) { 512void PIconView::addFiles( const QStringList& lst) {
510 QStringList::ConstIterator it; 513 QStringList::ConstIterator it;
511 IconViewItem * _iv; 514 IconViewItem * _iv;
512 QPixmap*m_pix = 0; 515 QPixmap*m_pix = 0;
513 QString pre = ""; 516 QString pre = "";
514 if (!m_path.isEmpty()) { 517 if (!m_path.isEmpty()) {
515 pre = m_path+"/"; 518 pre = m_path+"/";
516 } 519 }
517 for (it=lst.begin(); it!= lst.end(); ++it ) { 520 for (it=lst.begin(); it!= lst.end(); ++it ) {
518 m_pix = PPixmapCache::self()->cachedImage( pre+(*it), m_iconsize, m_iconsize ); 521 m_pix = PPixmapCache::self()->cachedImage( pre+(*it), m_iconsize, m_iconsize );
519 _iv = new IconViewItem( m_view, pre+(*it), (*it),m_iconsize ); 522 _iv = new IconViewItem( m_view, pre+(*it), (*it),m_iconsize );
520 if (m_mode==3) { 523 if (m_mode==3) {
521 _iv->setTextOnly(true); 524 _iv->setTextOnly(true);
522 _iv->setPixmap(QPixmap()); 525 _iv->setPixmap(QPixmap());
523 526
524 527
525 528
526 } else { 529 } else {
527 if (m_pix) _iv->setPixmap(*m_pix); 530 if (m_pix) _iv->setPixmap(*m_pix);
528 } 531 }
529 } 532 }
530 533
531} 534}
532 535
533/* 536/*
534 * user clicked on the item. Change dir or view 537 * user clicked on the item. Change dir or view
535 */ 538 */
536void PIconView::slotClicked(QIconViewItem* _it) { 539void PIconView::slotClicked(QIconViewItem* _it) {
537 if(!_it ) 540 if(!_it )
538 return; 541 return;
539 542
540 IconViewItem* it = static_cast<IconViewItem*>(_it); 543 IconViewItem* it = static_cast<IconViewItem*>(_it);
541 if( it->isDir() ) 544 if( it->isDir() )
542 slotChangeDir( it->path() ); 545 slotChangeDir( it->path() );
543 else // view image 546 else // view image
544 slotShowImage(); 547 slotShowImage();
545} 548}
546 549
547/* 550/*
548 * Return was pressed. which is triggered by the keydown 551 * Return was pressed. which is triggered by the keydown
549 * handler. The problem is that the key up will be handled 552 * handler. The problem is that the key up will be handled
550 * by the ImageDisplayer and goes to the next image 553 * by the ImageDisplayer and goes to the next image
551 */ 554 */
552void PIconView::slotRetrun( QIconViewItem *_it ) { 555void PIconView::slotRetrun( QIconViewItem *_it ) {
553 if(!_it ) 556 if(!_it )
554 return; 557 return;
555 558
556 IconViewItem* it = static_cast<IconViewItem*>(_it); 559 IconViewItem* it = static_cast<IconViewItem*>(_it);
557 if( it->isDir() ) 560 if( it->isDir() )
558 slotChangeDir( it->path() ); 561 slotChangeDir( it->path() );
559 else 562 else
560 QTimer::singleShot(0, this, SLOT(slotShowImage()) ); 563 QTimer::singleShot(0, this, SLOT(slotShowImage()) );
561} 564}
562 565
563/* 566/*
564 * got thumb info add to the cache if items is visible 567 * got thumb info add to the cache if items is visible
565 * we later need update after processing of slave is done 568 * we later need update after processing of slave is done
566 */ 569 */
567void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { 570void PIconView::slotThumbInfo( const QString& _path, const QString& str ) {
568 IconViewItem* item = g_stringInf[_path]; 571 IconViewItem* item = g_stringInf[_path];
569 if (!item ) 572 if (!item )
570 return; 573 return;
571 574
572 if (m_mode == 2) { 575 if (m_mode == 2) {
573 return; 576 return;
574 } 577 }
575 if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), 578 if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(),
576 m_view->contentsWidth(), m_view->contentsHeight() ) ) ) 579 m_view->contentsWidth(), m_view->contentsHeight() ) ) )
577 m_updatet = true; 580 m_updatet = true;
578 581
579 item->setText( str ); 582 item->setText( str );
580 g_stringInf.remove( _path ); 583 g_stringInf.remove( _path );
581} 584}
582 585
583/* 586/*
584 * got thumbnail and see if it is visible so we need to update later 587 * got thumbnail and see if it is visible so we need to update later
585 */ 588 */
586void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { 589void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) {
587 IconViewItem* item = g_stringPix[_path]; 590 IconViewItem* item = g_stringPix[_path];
588 if (!item ) 591 if (!item )
589 return; 592 return;
590 593
591 if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), 594 if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(),
592 m_view->contentsWidth(), m_view->contentsHeight() ) ) ) 595 m_view->contentsWidth(), m_view->contentsHeight() ) ) )
593 m_updatet = true; 596 m_updatet = true;
594 597
595 if (pix.width()>0) { 598 if (pix.width()>0) {
596 if (pix.width()<m_iconsize) { 599 if (pix.width()<m_iconsize) {
597 QPixmap p(m_iconsize,m_iconsize); 600 QPixmap p(m_iconsize,m_iconsize);
598 p.fill(); 601 p.fill();
599 QPainter pa(&p); 602 QPainter pa(&p);
600 int offset = (m_iconsize-pix.width())/2; 603 int offset = (m_iconsize-pix.width())/2;
601 int offy = (m_iconsize-pix.height())/2; 604 int offy = (m_iconsize-pix.height())/2;
602 if (offy<0) offy=0; 605 if (offy<0) offy=0;
603 pa.drawPixmap(offset,offy,pix); 606 pa.drawPixmap(offset,offy,pix);
604 pa.end(); 607 pa.end();
605 PPixmapCache::self()->insertImage( _path, p, m_iconsize, m_iconsize ); 608 PPixmapCache::self()->insertImage( _path, p, m_iconsize, m_iconsize );
606 item->setPixmap(p,true); 609 item->setPixmap(p,true);
607 } else { 610 } else {
608 PPixmapCache::self()->insertImage( _path, pix, m_iconsize, m_iconsize ); 611 PPixmapCache::self()->insertImage( _path, pix, m_iconsize, m_iconsize );
609 item->setPixmap(pix,true); 612 item->setPixmap(pix,true);
610 } 613 }
611 614
612 } else { 615 } else {
613 PPixmapCache::self()->insertImage( _path, Resource::loadPixmap( "UnknownDocument" ), m_iconsize, m_iconsize ); 616 PPixmapCache::self()->insertImage( _path, Resource::loadPixmap( "UnknownDocument" ), m_iconsize, m_iconsize );
614 } 617 }
615 g_stringPix.remove( _path ); 618 g_stringPix.remove( _path );
616 m_view->arrangeItemsInGrid(true); 619 m_view->arrangeItemsInGrid(true);
617} 620}
618 621
619 622
620/* 623/*
621 * FIXME rename 624 * FIXME rename
622 */ 625 */
623void PIconView::slotRename() { 626void PIconView::slotRename() {
624 627
625} 628}
626 629
627 630
628/* 631/*
629 * BEAM the current file 632 * BEAM the current file
630 */ 633 */
631void PIconView::slotBeam() { 634void PIconView::slotBeam() {
632 bool isDir; 635 bool isDir;
633 QString pa = currentFileName( isDir ); 636 QString pa = currentFileName( isDir );
634 if ( isDir && pa.isEmpty() ) 637 if ( isDir && pa.isEmpty() )