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