summaryrefslogtreecommitdiff
authorzecke <zecke>2002-03-05 17:55:08 (UTC)
committer zecke <zecke>2002-03-05 17:55:08 (UTC)
commit7f0e92c12b41207fa75c82bc0b6f30fc57e7e77d (patch) (unidiff)
tree81cd1145d106a8f08b1727f60eed60d3cee306b6
parent81000382c5869cb26c243ec9364b688524c8a566 (diff)
downloadopie-7f0e92c12b41207fa75c82bc0b6f30fc57e7e77d.zip
opie-7f0e92c12b41207fa75c82bc0b6f30fc57e7e77d.tar.gz
opie-7f0e92c12b41207fa75c82bc0b6f30fc57e7e77d.tar.bz2
My fileselector patch mentioned on the list
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/fileselector.cpp41
1 files changed, 27 insertions, 14 deletions
diff --git a/library/fileselector.cpp b/library/fileselector.cpp
index 365f383..013f43a 100644
--- a/library/fileselector.cpp
+++ b/library/fileselector.cpp
@@ -1,340 +1,353 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20
21// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT
22// have this class.
23#define QTOPIA_INTERNAL_FSLP
24
20#include "fileselector.h" 25#include "fileselector.h"
26#include "fileselector_p.h"
21#include "global.h" 27#include "global.h"
22#include "resource.h" 28#include "resource.h"
23#include "config.h" 29#include "config.h"
24#include "applnk.h" 30#include "applnk.h"
25#include "storage.h" 31#include "storage.h"
26#include "qpemenubar.h" 32#include "qpemenubar.h"
27#include "qcopchannel_qws.h" 33#include "qcopchannel_qws.h"
28#include "lnkproperties.h" 34#include "lnkproperties.h"
29#include "applnk.h" 35#include "applnk.h"
30#include "qpeapplication.h" 36#include "qpeapplication.h"
31#include "categorymenu.h" 37#include "categorymenu.h"
32 38
33#include <stdlib.h> 39#include <stdlib.h>
34 40
35#include <qdir.h> 41#include <qdir.h>
36#include <qwidget.h> 42#include <qwidget.h>
37#include <qpopupmenu.h> 43#include <qpopupmenu.h>
38#include <qtoolbutton.h> 44#include <qtoolbutton.h>
39#include <qpushbutton.h> 45#include <qpushbutton.h>
40#include <qheader.h> 46#include <qheader.h>
41#include <qtooltip.h> 47#include <qtooltip.h>
42 48
43 49
44FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f ) 50FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f )
45 : QListViewItem( parent ), fl( f ) 51 : QListViewItem( parent ), fl( f )
46{ 52{
47 setText( 0, f.name() ); 53 setText( 0, f.name() );
48 setPixmap( 0, f.pixmap() ); 54 setPixmap( 0, f.pixmap() );
49} 55}
50 56
51FileSelectorItem::~FileSelectorItem() 57FileSelectorItem::~FileSelectorItem()
52{ 58{
53} 59}
54 60
55class FileSelectorViewPrivate 61class FileSelectorViewPrivate
56{ 62{
57public: 63public:
58 CategoryMenu *cm; 64 CategoryMenu *cm;
65 bool m_noItems:1;
59}; 66};
60 67
61FileSelectorView::FileSelectorView( const QString &f, QWidget *parent, const char *name ) 68FileSelectorView::FileSelectorView( const QString &f, QWidget *parent, const char *name )
62 : QListView( parent, name ), filter( f ), count( 0 ) 69 : QListView( parent, name ), filter( f ), count( 0 )
63{ 70{
64 d = new FileSelectorViewPrivate(); 71 d = new FileSelectorViewPrivate();
65 d->cm = 0; 72 d->cm = 0;
73 d->m_noItems = false;
66 setAllColumnsShowFocus( TRUE ); 74 setAllColumnsShowFocus( TRUE );
67 addColumn( tr( "Name" ) ); 75 addColumn( tr( "Name" ) );
68 header()->hide(); 76 header()->hide();
69 77
70 fileManager = new FileManager; 78 fileManager = new FileManager;
71 reread(); 79 reread();
72 QCopChannel *channel = new QCopChannel( "QPE/Card", this ); 80 QCopChannel *channel = new QCopChannel( "QPE/Card", this );
73 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 81 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
74 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 82 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
75} 83}
76 84
77FileSelectorView::~FileSelectorView() 85FileSelectorView::~FileSelectorView()
78{ 86{
79} 87}
80 88
81void FileSelectorView::reread() 89void FileSelectorView::reread()
82{ 90{
83 FileSelectorItem *item = (FileSelectorItem *)selectedItem();
84 QString oldFile; 91 QString oldFile;
85 if ( item ) 92 FileSelectorItem *item;
86 oldFile = item->file().file(); 93 if( !d->m_noItems ) { // there are items
94 item = (FileSelectorItem *)selectedItem();
95 if ( item )
96 oldFile = item->file().file();
97 }
87 clear(); 98 clear();
88 DocLnkSet files; 99 DocLnkSet files;
89 Global::findDocuments(&files, filter); 100 Global::findDocuments(&files, filter);
90 count = files.children().count(); 101 count = files.children().count();
102 if(count == 0 ){ // No Documents
103 d->m_noItems = true;
104 QListViewItem *it = new QListViewItem(this, tr("There are no files in this directory." ), "empty" );
105 it->setSelectable(FALSE );
106 return;
107 }
91 QListIterator<DocLnk> dit( files.children() ); 108 QListIterator<DocLnk> dit( files.children() );
92 for ( ; dit.current(); ++dit ) { 109 for ( ; dit.current(); ++dit ) {
93 if (d->cm) 110 if (d->cm)
94 if (!d->cm->isSelected((**dit).categories())) 111 if (!d->cm->isSelected((**dit).categories()))
95 continue; 112 continue;
96 item = new FileSelectorItem( this, **dit ); 113 item = new FileSelectorItem( this, **dit );
97 if ( item->file().file() == oldFile ) 114 if ( item->file().file() == oldFile )
98 setCurrentItem( item ); 115 setCurrentItem( item );
99 } 116 }
100 if ( !selectedItem() ) 117 if ( !selectedItem() )
101 setCurrentItem( firstChild() ); 118 setCurrentItem( firstChild() );
102} 119}
103 120
104void FileSelectorView::setCategoryFilter(CategoryMenu *cm) 121void FileSelectorView::setCategoryFilter(CategoryMenu *cm)
105{ 122{
106 d->cm = cm; 123 d->cm = cm;
107 connect(cm, SIGNAL(categoryChange()), this, SLOT(categoryChanged()) ); 124 connect(cm, SIGNAL(categoryChange()), this, SLOT(categoryChanged()) );
108} 125}
109 126
110void FileSelectorView::categoryChanged() { reread(); } 127void FileSelectorView::categoryChanged() { reread(); }
111 128
112void FileSelectorView::cardMessage( const QCString &msg, const QByteArray &) 129void FileSelectorView::cardMessage( const QCString &msg, const QByteArray &)
113{ 130{
114 if ( msg == "mtabChanged()" ) 131 if ( msg == "mtabChanged()" )
115 reread(); 132 reread();
116} 133}
117 134
118void FileSelectorView::keyPressEvent( QKeyEvent *e ) 135void FileSelectorView::keyPressEvent( QKeyEvent *e )
119{ 136{
120 QString txt = e->text(); 137 QString txt = e->text();
121 if (e->key() == Key_Space) 138 if (e->key() == Key_Space)
122 emit returnPressed( currentItem() ); 139 emit returnPressed( currentItem() );
123 else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) 140 else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 )
124 e->ignore(); 141 e->ignore();
125 else 142 else
126 QListView::keyPressEvent(e); 143 QListView::keyPressEvent(e);
127} 144}
128 145
129class FileSelectorPrivate 146class FileSelectorPrivate
130{ 147{
131public: 148public:
132 CategoryMenu *cm; 149 CategoryMenu *cm;
133 QMenuBar *mb; 150 QMenuBar *mb;
134}; 151};
135 152
136/*! 153/*!
137 \class FileSelector fileselector.h 154 \class FileSelector fileselector.h
138 \brief The FileSelector widget allows the user to select DocLnk objects. 155 \brief The FileSelector widget allows the user to select DocLnk objects.
139*/ 156*/
140 157
141/*! 158/*!
142 Constructs a FileSelector with mime filter \a f. 159 Constructs a FileSelector with mime filter \a f.
143 The standard Qt \a parent and \a name parameters are passed to the 160 The standard Qt \a parent and \a name parameters are passed to the
144 parent. 161 parent.
145 162
146 If \a newVisible is TRUE, the widget has an button allowing the user 163 If \a newVisible is TRUE, the widget has an button allowing the user
147 the create "new" documents - editor applications will have this while 164 the create "new" documents - editor applications will have this while
148 viewer applications will not. 165 viewer applications will not.
149 166
150 If \a closeVisible is TRUE, the widget has an button allowinf the user 167 If \a closeVisible is TRUE, the widget has an button allowinf the user
151 to select "no document". 168 to select "no document".
152 169
153 \sa DocLnkSet::DocLnkSet() 170 \sa DocLnkSet::DocLnkSet()
154*/ 171*/
155FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible ) 172FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible )
156 : QVBox( parent, name ), filter( f ) 173 : QVBox( parent, name ), filter( f )
157{ 174{
158 setMargin( 0 ); 175 setMargin( 0 );
159 setSpacing( 0 ); 176 setSpacing( 0 );
160 QHBox *top = new QHBox( this ); 177 QHBox *top = new QHBox( this );
161 top->setBackgroundMode( PaletteButton );// same colour as toolbars 178 top->setBackgroundMode( PaletteButton );// same colour as toolbars
162 top->setSpacing( 0 ); 179 top->setSpacing( 0 );
163 180
164 QWidget *spacer = new QWidget( top ); 181 QWidget *spacer = new QWidget( top );
165 spacer->setBackgroundMode( PaletteButton ); 182 spacer->setBackgroundMode( PaletteButton );
166 183
167 d = new FileSelectorPrivate(); 184 d = new FileSelectorPrivate();
168 d->mb = new QMenuBar(spacer); 185 d->mb = new QMenuBar(spacer);
169 d->cm = new CategoryMenu("Document View", this); 186 d->cm = new CategoryMenu("Document View", this);
170 QPEMenuToolFocusManager::manager()->addWidget( d->mb ); 187 QPEMenuToolFocusManager::manager()->addWidget( d->mb );
171 d->mb->insertItem(tr("View"), d->cm); 188 d->mb->insertItem(tr("View"), d->cm);
172 189
173 190
174 QToolButton *tb = new QToolButton( top ); 191 QToolButton *tb = new QToolButton( top );
175 tb->setPixmap( Resource::loadPixmap( "new" ) ); 192 tb->setPixmap( Resource::loadPixmap( "new" ) );
176 connect( tb, SIGNAL( clicked() ), this, SLOT( createNew() ) ); 193 connect( tb, SIGNAL( clicked() ), this, SLOT( createNew() ) );
177 buttonNew = tb; 194 buttonNew = tb;
178 tb->setFixedSize( 18, 20 ); // tb->sizeHint() ); 195 tb->setFixedSize( 18, 20 ); // tb->sizeHint() );
179 tb->setAutoRaise( TRUE ); 196 tb->setAutoRaise( TRUE );
180 QToolTip::add( tb, tr( "Create a new Document" ) ); 197 QToolTip::add( tb, tr( "Create a new Document" ) );
181 QPEMenuToolFocusManager::manager()->addWidget( tb ); 198 QPEMenuToolFocusManager::manager()->addWidget( tb );
182 199
183 tb = new QToolButton( top ); 200 tb = new QToolButton( top );
184 tb->setPixmap( Resource::loadPixmap( "close" ) ); 201 tb->setPixmap( Resource::loadPixmap( "close" ) );
185 connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) ); 202 connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) );
186 buttonClose = tb; 203 buttonClose = tb;
187 tb->setFixedSize( 18, 20 ); // tb->sizeHint() ); 204 tb->setFixedSize( 18, 20 ); // tb->sizeHint() );
188 tb->setAutoRaise( TRUE ); 205 tb->setAutoRaise( TRUE );
189 QToolTip::add( tb, tr( "Close the File Selector" ) ); 206 QToolTip::add( tb, tr( "Close the File Selector" ) );
190 QPEMenuToolFocusManager::manager()->addWidget( tb ); 207 QPEMenuToolFocusManager::manager()->addWidget( tb );
191 208
192 view = new FileSelectorView( filter, this, "fileview" ); 209 view = new FileSelectorView( filter, this, "fileview" );
193 view->setCategoryFilter(d->cm); 210 view->setCategoryFilter(d->cm);
194 QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold ); 211 QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold );
195 connect( view, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ), 212 connect( view, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ),
196 this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) ); 213 this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) );
197 connect( view, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ), 214 connect( view, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ),
198 this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) ); 215 this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) );
199 connect( view, SIGNAL( returnPressed( QListViewItem * ) ), 216 connect( view, SIGNAL( returnPressed( QListViewItem * ) ),
200 this, SLOT( fileClicked( QListViewItem * ) ) ); 217 this, SLOT( fileClicked( QListViewItem * ) ) );
201 218
202 setNewVisible( newVisible ); 219 setNewVisible( newVisible );
203 setCloseVisible( closeVisible ); 220 setCloseVisible( closeVisible );
204} 221}
205 222
206/*! 223/*!
207 Destroys the widget. 224 Destroys the widget.
208*/ 225*/
209FileSelector::~FileSelector() 226FileSelector::~FileSelector()
210{ 227{
211 228
212} 229}
213 230
214/*! 231/*!
215 Returns the number of files in the view. If this is zero, and editor 232 Returns the number of files in the view. If this is zero, and editor
216 application might avoid using the selector and immediately start with 233 application might avoid using the selector and immediately start with
217 a "new" document. 234 a "new" document.
218*/ 235*/
219int FileSelector::fileCount() 236int FileSelector::fileCount()
220{ 237{
221 return view->fileCount(); 238 return view->fileCount();
222} 239}
223 240
224/*! 241/*!
225 Causes the file selector to act as if the "new" button was chosen. 242 Causes the file selector to act as if the "new" button was chosen.
226 243
227 \sa newSelected(), closeMe() 244 \sa newSelected(), closeMe()
228*/ 245*/
229void FileSelector::createNew() 246void FileSelector::createNew()
230{ 247{
231 DocLnk f; 248 DocLnk f;
232 emit newSelected( f ); 249 emit newSelected( f );
233 emit closeMe(); 250 emit closeMe();
234} 251}
235 252
236void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int ) 253void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int )
237{ 254{
238 if ( !i ) 255 if ( !i )
239 return; 256 return;
257 if(i->text(1) == QString::fromLatin1("empty" ) )
258 return;
259
240 if ( button == Qt::LeftButton ) { 260 if ( button == Qt::LeftButton ) {
241 fileClicked( i ); 261 fileClicked( i );
242 } 262 }
243} 263}
244 264
245void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int ) 265void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int )
246{ 266{
247 if ( !i ) 267 if ( !i )
248 return; 268 return;
269 if(i->text(1) == QString::fromLatin1("empty" ) )
270 return;
271
249 if ( button == Qt::RightButton ) { 272 if ( button == Qt::RightButton ) {
250 DocLnk l = ((FileSelectorItem *)i)->file(); 273 DocLnk l = ((FileSelectorItem *)i)->file();
251 LnkProperties prop( &l ); 274 LnkProperties prop( &l );
252 prop.showMaximized(); 275 prop.showMaximized();
253 prop.exec(); 276 prop.exec();
254 d->cm->reload(); 277 d->cm->reload();
255 reread(); 278 reread();
256 } 279 }
257} 280}
258 281
259void FileSelector::fileClicked( QListViewItem *i ) 282void FileSelector::fileClicked( QListViewItem *i )
260{ 283{
261 if ( !i ) 284 if ( !i )
262 return; 285 return;
263 emit fileSelected( ( (FileSelectorItem*)i )->file() ); 286 emit fileSelected( ( (FileSelectorItem*)i )->file() );
264 emit closeMe(); 287 emit closeMe();
265} 288}
266 289
267/*! 290/*!
268 Returns the selected DocLnk. The caller is responsible for deleting 291 Returns the selected DocLnk. The caller is responsible for deleting
269 the returned value. 292 the returned value.
270*/ 293*/
271const DocLnk *FileSelector::selected() 294const DocLnk *FileSelector::selected()
272{ 295{
273 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); 296 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem();
274 if ( item ) 297 if ( item )
275 return new DocLnk( item->file() ); 298 return new DocLnk( item->file() );
276 return NULL; 299 return NULL;
277} 300}
278 301
279/*! 302/*!
280 \fn void FileSelector::fileSelected( const DocLnk &f ) 303 \fn void FileSelector::fileSelected( const DocLnk &f )
281 304
282 This signal is emitted when the user selects a file. 305 This signal is emitted when the user selects a file.
283 \a f is the file. 306 \a f is the file.
284*/ 307*/
285 308
286/*! 309/*!
287 \fn void FileSelector::newSelected( const DocLnk &f ) 310 \fn void FileSelector::newSelected( const DocLnk &f )
288 311
289 This signal is emitted when the user selects "new" file. 312 This signal is emitted when the user selects "new" file.
290 \a f is a DocLnk for the file. You will need to set the type 313 \a f is a DocLnk for the file. You will need to set the type
291 of the value after copying it. 314 of the value after copying it.
292*/ 315*/
293 316
294/*! 317/*!
295 \fn void FileSelector::closeMe() 318 \fn void FileSelector::closeMe()
296 319
297 This signal is emitted when the user no longer needs to view the widget. 320 This signal is emitted when the user no longer needs to view the widget.
298*/ 321*/
299 322
300 323
301/*! 324/*!
302 Sets whether a "new document" button is visible, according to \a b. 325 Sets whether a "new document" button is visible, according to \a b.
303*/ 326*/
304void FileSelector::setNewVisible( bool b ) 327void FileSelector::setNewVisible( bool b )
305{ 328{
306 if ( b ) 329 if ( b )
307 buttonNew->show(); 330 buttonNew->show();
308 else 331 else
309 buttonNew->hide(); 332 buttonNew->hide();
310} 333}
311 334
312/*! 335/*!
313 Sets whether a "no document" button is visible, according to \a b. 336 Sets whether a "no document" button is visible, according to \a b.
314*/ 337*/
315void FileSelector::setCloseVisible( bool b ) 338void FileSelector::setCloseVisible( bool b )
316{ 339{
317 if ( b ) 340 if ( b )
318 buttonClose->show(); 341 buttonClose->show();
319 else 342 else
320 buttonClose->hide(); 343 buttonClose->hide();
321} 344}
322 345
323/*! 346/*!
324 Sets whether a categories menu is visible, according to \a b.
325*/
326void FileSelector::setCategoriesVisible( bool b )
327{
328 if ( b )
329 d->mb->show();
330 else
331 d->mb->hide();
332}
333
334/*!
335 Rereads the list of files. 347 Rereads the list of files.
336*/ 348*/
337void FileSelector::reread() 349void FileSelector::reread()
338{ 350{
339 view->reread(); 351 view->reread();
340} 352}
353