summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcher.cpp1597
-rw-r--r--core/launcher/launcherview.cpp745
-rw-r--r--core/launcher/launcherview.h30
3 files changed, 929 insertions, 1443 deletions
diff --git a/core/launcher/launcher.cpp b/core/launcher/launcher.cpp
index b612aa2..35d404a 100644
--- a/core/launcher/launcher.cpp
+++ b/core/launcher/launcher.cpp
@@ -1,1356 +1,757 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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 20
21// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT 21#include <qtopia/global.h>
22// have this class. 22#ifdef Q_WS_QWS
23#define QTOPIA_INTERNAL_FSLP 23#include <qtopia/qcopenvelope_qws.h>
24 24#endif
25//#include <opie/ofiledialog.h> 25#include <qtopia/resource.h>
26#include <opie/ofileselector.h> 26#include <qtopia/applnk.h>
27#include <qpe/qcopenvelope_qws.h> 27#include <qtopia/config.h>
28#include <qpe/resource.h> 28#include <qtopia/global.h>
29#include <qpe/applnk.h> 29#include <qtopia/qpeapplication.h>
30#include <qpe/config.h> 30#include <qtopia/mimetype.h>
31#include <qpe/global.h> 31#include <qtopia/private/categories.h>
32#include <qpe/qpeapplication.h> 32#include <qtopia/custom.h>
33#include <qpe/mimetype.h>
34#include <qpe/storage.h>
35#include <qpe/palmtoprecord.h>
36
37#include <qpe/version.h>
38 33
39#include <qdir.h> 34#include <qdir.h>
40#ifdef QWS 35#ifdef Q_WS_QWS
41#include <qwindowsystem_qws.h> 36#include <qwindowsystem_qws.h>
42#endif 37#endif
43#include <qtimer.h> 38#include <qtimer.h>
44#include <qcombobox.h> 39#include <qcombobox.h>
45#include <qvbox.h> 40#include <qvbox.h>
46#include <qlayout.h> 41#include <qlayout.h>
47#include <qstyle.h> 42#include <qstyle.h>
48#include <qpushbutton.h> 43#include <qpushbutton.h>
49#include <qtabbar.h> 44#include <qtabbar.h>
50#include <qwidgetstack.h> 45#include <qwidgetstack.h>
51#include <qlayout.h> 46#include <qlayout.h>
52#include <qregexp.h> 47#include <qregexp.h>
53#include <qmessagebox.h> 48#include <qmessagebox.h>
54#include <qframe.h> 49#include <qframe.h>
55#include <qpainter.h> 50#include <qpainter.h>
56#include <qlabel.h> 51#include <qlabel.h>
57#include <qtextstream.h> 52#include <qtextstream.h>
58#include <qpopupmenu.h> 53#include <qpopupmenu.h>
59 54
60#include <opie/owait.h> 55#include "startmenu.h"
61 56#include "taskbar.h"
62 57
58#include "serverinterface.h"
63#include "launcherview.h" 59#include "launcherview.h"
64#include "launcher.h" 60#include "launcher.h"
65#include "syncdialog.h" 61#include "server.h"
66#include "desktop.h" 62
67#include <qpe/lnkproperties.h> 63#define QTOPIA_INTERNAL_FSLP
68//#include "mrulist.h" 64#include <qtopia/lnkproperties.h>
69#include "qrsync.h"
70#include <stdlib.h> 65#include <stdlib.h>
71#include <unistd.h> 66#include <assert.h>
72 67
73#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 68#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
69#include <unistd.h>
74#include <stdio.h> 70#include <stdio.h>
75#include <sys/vfs.h> 71#include <sys/vfs.h>
76#include <mntent.h> 72#include <mntent.h>
77#endif 73#endif
78 74
79#include <qpe/storage.h> 75#ifdef Q_WS_QWS
80#include "mediummountgui.h" 76#include <qkeyboard_qws.h>
81 77#include <qpe/lnkproperties.h>
82namespace { 78#endif
83 QStringList configToMime( Config *cfg ){
84 QStringList mimes;
85 bool tmpMime = true;
86 cfg->setGroup("mimetypes" );
87 tmpMime = cfg->readBoolEntry("all" ,true);
88 if( tmpMime ){
89 mimes << QString::null;
90 return mimes;
91 }else{
92 tmpMime = cfg->readBoolEntry("audio", true );
93 if(tmpMime )
94 mimes.append("audio/*" );
95
96 tmpMime = cfg->readBoolEntry("image", true );
97 if(tmpMime )
98 mimes.append("image/*" );
99
100 tmpMime = cfg->readBoolEntry("text", true );
101 if(tmpMime )
102 mimes.append("text/*");
103
104 tmpMime = cfg->readBoolEntry("video", true );
105 if(tmpMime )
106 mimes.append("video/*" );
107 }
108 return mimes;
109 }
110 79
111}
112 80
81static bool isVisibleWindow( int );
82//===========================================================================
83
84LauncherTabWidget::LauncherTabWidget( Launcher* parent ) :
85 QVBox( parent )
86{
87 docLoadingWidgetEnabled = false;
88 docLoadingWidget = 0;
89 docLoadingWidgetProgress = 0;
90 launcher = parent;
91 categoryBar = new LauncherTabBar( this );
92 QPalette pal = categoryBar->palette();
93 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) );
94 pal.setColor( QColorGroup::Background, pal.active().background().light(110) );
95 categoryBar->setPalette( pal );
96 stack = new QWidgetStack(this);
97 connect( categoryBar, SIGNAL(selected(int)), this, SLOT(raiseTabWidget()) );
98 categoryBar->show();
99 stack->show();
113 100
101#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
102 QCopChannel *channel = new QCopChannel( "QPE/Launcher", this );
103 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
104 this, SLOT(launcherMessage(const QCString&, const QByteArray&)) );
105 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
106 this, SLOT(appMessage(const QCString&, const QByteArray&)));
107#endif
114 108
115//#define SHOW_ALL 109 createDocLoadingWidget();
110}
116 111
117class CategoryTab : public QTab 112void LauncherTabWidget::createDocLoadingWidget()
118{ 113{
119public: 114 // Construct the 'doc loading widget' shown when finding documents
120 CategoryTab( const QIconSet &icon, const QString &text=QString::null )
121 : QTab( icon, text )
122 {
123 }
124 115
125 QColor bgColor; 116 // ### LauncherView class needs changing to be more generic so
126 QColor fgColor; 117 // this widget can change its background similar to the iconviews
127}; 118 // so the background for this matches
119 docLoadingWidget = new LauncherView( stack );
120 docLoadingWidget->hideIcons();
121 QVBox *docLoadingVBox = new QVBox( docLoadingWidget );
128 122
129//=========================================================================== 123 docLoadingVBox->setSpacing( 20 );
124 docLoadingVBox->setMargin( 10 );
130 125
131CategoryTabWidget::CategoryTabWidget( QWidget* parent ) : 126 QWidget *space1 = new QWidget( docLoadingVBox );
132 QVBox( parent ) 127 docLoadingVBox->setStretchFactor( space1, 1 );
133{
134 categoryBar = 0;
135 stack = 0;
136}
137 128
138void CategoryTabWidget::prevTab() 129 QLabel *waitPixmap = new QLabel( docLoadingVBox );
139{ 130 waitPixmap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, waitPixmap->sizePolicy().hasHeightForWidth() ) );
140 if ( categoryBar ) { 131 waitPixmap->setPixmap( Resource::loadPixmap( "bigwait" ) );
141 int n = categoryBar->count(); 132 waitPixmap->setAlignment( int( QLabel::AlignCenter ) );
142 int tab = categoryBar->currentTab(); 133
143 if ( tab >= 0 ) 134 QLabel *textLabel = new QLabel( docLoadingVBox );
144 categoryBar->setCurrentTab( (tab - 1 + n)%n ); 135 textLabel->setText( tr( "<b>Finding Documents...</b>" ) );
145 } 136 textLabel->setAlignment( int( QLabel::AlignCenter ) );
137
138 docLoadingWidgetProgress = new QProgressBar( docLoadingVBox );
139 docLoadingWidgetProgress->setProgress( 0 );
140 docLoadingWidgetProgress->setCenterIndicator( TRUE );
141 docLoadingWidgetProgress->setBackgroundMode( NoBackground ); // No flicker
142 setProgressStyle();
143
144 QWidget *space2 = new QWidget( docLoadingVBox );
145 docLoadingVBox->setStretchFactor( space2, 1 );
146
147 Config cfg("Launcher");
148 cfg.setGroup( "Tab Documents" ); // No tr
149 setTabViewAppearance( docLoadingWidget, cfg );
150
151 stack->addWidget( docLoadingWidget, 0 );
146} 152}
147 153
148void CategoryTabWidget::nextTab() 154void LauncherTabWidget::initLayout()
149{ 155{
150 if ( categoryBar ) { 156 layout()->activate();
151 int n = categoryBar->count(); 157 docView()->setFocus();
152 int tab = categoryBar->currentTab(); 158 categoryBar->showTab("Documents");
153 categoryBar->setCurrentTab( (tab + 1)%n );
154 }
155} 159}
156 160
157 161void LauncherTabWidget::appMessage(const QCString& message, const QByteArray&)
158void CategoryTabWidget::showTab(const QString& id)
159{ 162{
160 if ( categoryBar ) { 163 if ( message == "nextView()" )
161 int idx = ids.findIndex( id ); 164 categoryBar->nextTab();
162 categoryBar->setCurrentTab( idx );
163 }
164} 165}
165 166
166void CategoryTabWidget::addItem( const QString& linkfile ) 167void LauncherTabWidget::raiseTabWidget()
167{ 168{
168// int i=0; 169 if ( categoryBar->currentView() == docView()
169// AppLnk *app = new AppLnk(linkfile); 170 && docLoadingWidgetEnabled ) {
170// if ( !app->isValid() ) { 171 stack->raiseWidget( docLoadingWidget );
171// delete app; 172 docLoadingWidget->updateGeometry();
172// app=0; 173 } else {
173// } 174 stack->raiseWidget( categoryBar->currentView() );
174// if ( !app || !app->file().isEmpty() ) { 175 }
175 // A document
176// delete app;
177// app = new DocLnk(linkfile);
178// if ( app->fileKnown() ) {
179// ((LauncherView*)(stack->widget(ids.count()-1)))->addItem(app);
180// } else {
181// ((LauncherView*)(stack->widget(ids.count()-1)))->sort();
182// delete app;
183// }
184// return;
185// }
186 // An application
187// for ( QStringList::Iterator it=ids.begin(); it!=ids.end(); ++it) {
188// if ( !(*it).isEmpty() ) {
189// QRegExp tf(*it,FALSE,TRUE);
190// if ( tf.match(app->type()) >= 0 ) {
191// ((LauncherView*)stack->widget(i))->addItem(app);
192// return;
193// }
194// i++;
195 // }
196 // }
197
198 QCopEnvelope e("QPE/TaskBar","reloadApps()");
199} 176}
200 177
201void CategoryTabWidget::initializeCategories(AppLnkSet* rootFolder, 178void LauncherTabWidget::tabProperties()
202 AppLnkSet* /*docFolder*/, const QList<FileSystem> & /*fs*/)
203{ 179{
204 QString current; 180 LauncherView *view = categoryBar->currentView();
205 if ( categoryBar ) { 181 QPopupMenu *m = new QPopupMenu( this );
206 int c = categoryBar->currentTab(); 182 m->insertItem( tr("Icon View"), LauncherView::Icon );
207 if ( c >= 0 ) current = ids[c]; 183 m->insertItem( tr("List View"), LauncherView::List );
184 m->setItemChecked( (int)view->viewMode(), TRUE );
185 int rv = m->exec( QCursor::pos() );
186 if ( rv >= 0 && rv != view->viewMode() ) {
187 view->setViewMode( (LauncherView::ViewMode)rv );
208 } 188 }
209 189
210 delete categoryBar; 190 delete m;
211 categoryBar = new CategoryTabBar( this ); 191}
212 QPalette pal = categoryBar->palette();
213 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) );
214 pal.setColor( QColorGroup::Background, pal.active().background().light(110) );
215 categoryBar->setPalette( pal );
216
217 delete stack;
218 stack = new QWidgetStack(this);
219 tabs=0;
220
221 ids.clear();
222
223 Config cfg("Launcher");
224 192
225 QStringList types = rootFolder->types(); 193void LauncherTabWidget::deleteView( const QString& id )
226 for ( QStringList::Iterator it=types.begin(); it!=types.end(); ++it) { 194{
227 if ( !(*it).isEmpty() ) { 195 LauncherTab *t = categoryBar->launcherTab(id);
228 (void)newView(*it,rootFolder->typePixmap(*it),rootFolder->typeName(*it)); 196 if ( t ) {
229 setTabAppearance( *it, cfg ); 197 stack->removeWidget( t->view );
230 } 198 delete t->view;
231 } 199 categoryBar->removeTab( t );
232 QListIterator<AppLnk> it( rootFolder->children() );
233 AppLnk* l;
234 while ( (l=it.current()) ) {
235 if ( l->type() == "Separator" ) { // No tr
236 rootFolder->remove(l);
237 delete l;
238 } else {
239 int i=0;
240 for ( QStringList::Iterator it=types.begin(); it!=types.end(); ++it) {
241 if ( *it == l->type() )
242 ((LauncherView*)stack->widget(i))->addItem(l,FALSE);
243 i++;
244 }
245 }
246 ++it;
247 } 200 }
248 rootFolder->detachChildren(); 201}
249 for (int i=0; i<tabs; i++)
250 ((LauncherView*)stack->widget(i))->sort();
251
252 // all documents
253 QImage img( Resource::loadImage( "DocsIcon" ) );
254 QPixmap pm;
255 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
256
257 //ljpotter
258 CategoryTab *catTab ;
259 catTab = new CategoryTab( pm, "Documents" );
260
261 categoryBar->addTab( catTab );
262
263 fileSel = new DocumentTab( stack, 4, 0, "/","");
264 stack->addWidget( fileSel, tabs++ );
265 202
266 // fileSel->hide(); 203LauncherView* LauncherTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label )
204{
205 LauncherView* view = new LauncherView( stack );
206 connect( view, SIGNAL(clicked(const AppLnk*)),
207 this, SIGNAL(clicked(const AppLnk*)));
208 connect( view, SIGNAL(rightPressed(AppLnk*)),
209 this, SIGNAL(rightPressed(AppLnk*)));
267 210
268 connect( fileSel, SIGNAL( fileSelected( const DocLnk & )), 211 int n = categoryBar->count();
269 this, SLOT(clickie(const DocLnk&)) ); 212 stack->addWidget( view, n );
270
271// connect( fileSel, SIGNAL( fileSelected( const QString & )),
272// this, SLOT(clickie(const QString&)) );
273 213
274 connect( categoryBar, SIGNAL(selected(int)), stack, SLOT(raiseWidget(int)) ); 214 LauncherTab *tab = new LauncherTab( id, view, pm, label );
215 categoryBar->insertTab( tab, n-1 );
275 216
276 ((LauncherView*)stack->widget(0))->setFocus(); 217 if ( id == "Documents" )
218 docview = view;
277 219
278 cfg. setGroup ( "GUI" ); 220 qDebug("inserting %s at %d", id.latin1(), n-1 );
279 setBusyIndicatorType ( cfg. readEntry ( "BusyType", QString::null ));
280 221
281 if ( !current.isNull() ) { 222 Config cfg("Launcher");
282 showTab(current); 223 setTabAppearance( tab, cfg );
283 }
284 224
285 categoryBar->show(); 225 cfg.setGroup( "GUI" );
286 stack->show(); 226 view->setBusyIndicatorType( cfg.readEntry( "BusyType", QString::null ) );
287 227
228 return view;
229}
288 230
289 QCopEnvelope e("QPE/TaskBar","reloadApps()"); 231LauncherView *LauncherTabWidget::view( const QString &id )
232{
233 LauncherTab *t = categoryBar->launcherTab(id);
234 if ( !t )
235 return 0;
236 return t->view;
290} 237}
291 238
292void CategoryTabWidget::clickie(const DocLnk &lnk) { 239LauncherView *LauncherTabWidget::docView()
293 lnk.execute(); 240{
294 // fileSel->reparse(); 241 return docview;
295} 242}
296 243
297void CategoryTabWidget::clickie(const QString &appStr) { 244void LauncherTabWidget::setLoadingWidgetEnabled( bool v )
298// DocLnk lnk(appStr); 245{
299// lnk.execute(); 246 if ( v != docLoadingWidgetEnabled && docLoadingWidget ) {
247 docLoadingWidgetEnabled = v;
248 raiseTabWidget();
249 }
300} 250}
301 251
302void CategoryTabWidget::setTabAppearance( const QString &id, Config &cfg ) 252void LauncherTabWidget::setLoadingProgress( int percent )
303{ 253{
304 QString grp( "Tab %1" ); // No tr 254 docLoadingWidgetProgress->setProgress( (percent / 4) * 4 );
305 cfg.setGroup( grp.arg(id) ); 255}
306 LauncherView *v = view( id );
307 int idx = ids.findIndex( id );
308 CategoryTab *tab = (CategoryTab *)categoryBar->tab( idx );
309 256
257// ### this function could more to LauncherView
258void LauncherTabWidget::setTabViewAppearance( LauncherView *v, Config &cfg )
259{
310 // View 260 // View
311 QString view = cfg.readEntry( "View", "Icon" ); 261 QString view = cfg.readEntry( "View", "Icon" );
312 if ( view == "List" ) // No tr 262 if ( view == "List" ) // No tr
313 v->setViewMode( LauncherView::List ); 263 v->setViewMode( LauncherView::List );
314 QString bgType = cfg.readEntry( "BackgroundType", "Image" ); 264 QString bgType = cfg.readEntry( "BackgroundType", "Image" );
315 if ( bgType == "Image" ) { // No tr 265 if ( bgType == "Image" ) { // No tr
316 QString pm = cfg.readEntry( "BackgroundImage", "launcher/opie-background" ); 266 QString pm = cfg.readEntry( "BackgroundImage", "launcher/opie-background" );
317 v->setBackgroundType( LauncherView::Image, pm ); 267 v->setBackgroundType( LauncherView::Image, pm );
318 } else if ( bgType == "SolidColor" ) { 268 } else if ( bgType == "SolidColor" ) {
319 QString c = cfg.readEntry( "BackgroundColor" ); 269 QString c = cfg.readEntry( "BackgroundColor" );
320 v->setBackgroundType( LauncherView::SolidColor, c ); 270 v->setBackgroundType( LauncherView::SolidColor, c );
271 } else {
272 v->setBackgroundType( LauncherView::Ruled, QString::null );
321 } 273 }
322 QString textCol = cfg.readEntry( "TextColor" ); 274 QString textCol = cfg.readEntry( "TextColor" );
323 if ( textCol.isEmpty() ) 275 if ( textCol.isEmpty() )
324 v->setTextColor( QColor() ); 276 v->setTextColor( QColor() );
325 else 277 else
326 v->setTextColor( QColor(textCol) ); 278 v->setTextColor( QColor(textCol) );
279// bool customFont = cfg.readBoolEntry( "CustomFont", FALSE );
280
281
327 QStringList font = cfg.readListEntry( "Font", ',' ); 282 QStringList font = cfg.readListEntry( "Font", ',' );
328 if ( font.count() == 4 ) 283 if ( font.count() == 4 )
329 v->setViewFont( QFont(font[0], font[1].toInt(), font[2].toInt(), font[3].toInt()!=0) ); 284 v->setViewFont( QFont(font[0], font[1].toInt(), font[2].toInt(), font[3].toInt()!=0) );
285
286 // ### FIXME TabColor TabTextColor
287
288}
289
290// ### Could move to LauncherTab
291void LauncherTabWidget::setTabAppearance( LauncherTab *tab, Config &cfg )
292{
293 cfg.setGroup( QString( "Tab %1" ).arg(tab->type) ); // No tr
294
295 setTabViewAppearance( tab->view, cfg );
330 296
331 // Tabs 297 // Tabs
332 QString tabCol = cfg.readEntry( "TabColor" ); 298 QString tabCol = cfg.readEntry( "TabColor" );
333 if ( tabCol.isEmpty() ) 299 if ( tabCol.isEmpty() )
334 tab->bgColor = QColor(); 300 tab->bgColor = QColor();
335 else 301 else
336 tab->bgColor = QColor(tabCol); 302 tab->bgColor = QColor(tabCol);
337 QString tabTextCol = cfg.readEntry( "TabTextColor" ); 303 QString tabTextCol = cfg.readEntry( "TabTextColor" );
338 if ( tabTextCol.isEmpty() ) 304 if ( tabTextCol.isEmpty() )
339 tab->fgColor = QColor(); 305 tab->fgColor = QColor();
340 else 306 else
341 tab->fgColor = QColor(tabTextCol); 307 tab->fgColor = QColor(tabTextCol);
342} 308}
343 309
344//void CategoryTabWidget::updateDocs(AppLnkSet* docFolder, const QList<FileSystem> & /*fs*/) 310void LauncherTabWidget::paletteChange( const QPalette &p )
345//{
346 // docFolder->detachChildren();
347//}
348
349void CategoryTabWidget::tabProperties()
350{
351 LauncherView *view = (LauncherView*)stack->widget( categoryBar->currentTab() );
352 QPopupMenu *m = new QPopupMenu( this );
353 m->insertItem( tr("Icon View"), LauncherView::Icon );
354 m->insertItem( tr("List View"), LauncherView::List );
355 m->setItemChecked( (int)view->viewMode(), TRUE );
356 int rv = m->exec( QCursor::pos() );
357 if ( rv >= 0 && rv != view->viewMode() ) {
358 view->setViewMode( (LauncherView::ViewMode)rv );
359 }
360
361 delete m;
362}
363
364QString CategoryTabWidget::getAllDocLinkInfo() const
365{
366 return "";
367}
368
369LauncherView* CategoryTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label )
370{
371 LauncherView* view = new LauncherView( stack );
372 connect( view, SIGNAL(clicked(const AppLnk*)),
373 this, SIGNAL(clicked(const AppLnk*)));
374 connect( view, SIGNAL(rightPressed(AppLnk*)),
375 this, SIGNAL(rightPressed(AppLnk*)));
376 ids.append(id);
377 categoryBar->addTab( new CategoryTab( pm, label ) );
378 stack->addWidget( view, tabs++ );
379 return view;
380}
381
382void CategoryTabWidget::updateLink(const QString& linkfile)
383{
384 int i=0;
385 LauncherView* view;
386 //qApp->processEvents();
387 while ((view = (LauncherView*)stack->widget(i++))) {
388 if ( view->removeLink(linkfile) )
389 break;
390 }
391 addItem(linkfile);
392 docview->updateTools();
393}
394
395void CategoryTabWidget::paletteChange( const QPalette &p )
396{ 311{
397 QVBox::paletteChange( p ); 312 QVBox::paletteChange( p );
398 QPalette pal = palette(); 313 QPalette pal = palette();
399 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); 314 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) );
400 pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); 315 pal.setColor( QColorGroup::Background, pal.active().background().light(110) );
401 categoryBar->setPalette( pal ); 316 categoryBar->setPalette( pal );
402 categoryBar->update(); 317 categoryBar->update();
403} 318}
404 319
405void CategoryTabWidget::setBusy(bool on) 320void LauncherTabWidget::styleChange( QStyle & )
406{ 321{
407 if ( on ) 322 QTimer::singleShot( 0, this, SLOT(setProgressStyle()) );
408 ((LauncherView*)stack->visibleWidget())->setBusy(TRUE);
409 else
410 for (int i=0; i<tabs-1; i++)
411 ((LauncherView*)stack->widget(i))->setBusy(FALSE);
412} 323}
413 324
414LauncherView *CategoryTabWidget::view( const QString &id ) 325void LauncherTabWidget::setProgressStyle()
415{ 326{
416 int idx = ids.findIndex( id ); 327 if (docLoadingWidgetProgress) {
417 return (LauncherView *)stack->widget(idx); 328 docLoadingWidgetProgress->setFrameShape( QProgressBar::Box );
329 docLoadingWidgetProgress->setFrameShadow( QProgressBar::Plain );
330 docLoadingWidgetProgress->setMargin( 1 );
331 docLoadingWidgetProgress->setLineWidth( 1 );
332 }
418} 333}
419 334
420void CategoryTabWidget::setBusyIndicatorType ( const QString &type ) 335void LauncherTabWidget::setBusy(bool on)
421{ 336{
422 for ( QStringList::Iterator it = ids. begin ( ); it != ids. end ( ); ++it ) 337 if ( on )
423 view ( *it )-> setBusyIndicatorType ( type ); 338 currentView()->setBusy(TRUE);
339 else {
340 for ( int i = 0; i < categoryBar->count(); i++ ) {
341 LauncherView *view = ((LauncherTab *)categoryBar->tab(i))->view;
342 view->setBusy( FALSE );
343 }
344 }
424} 345}
425 346
426//=========================================================================== 347void LauncherTabWidget::setBusyIndicatorType( const QString& str ) {
427 348 for (int i = 0; i < categoryBar->count(); i++ ) {
428CategoryTabBar::CategoryTabBar( QWidget *parent, const char *name ) 349 LauncherView* view = static_cast<LauncherTab*>( categoryBar->tab(i) )->view;
429 : QTabBar( parent, name ) 350 view->setBusyIndicatorType( str );
430{ 351 }
431 setFocusPolicy( NoFocus );
432 connect( this, SIGNAL( selected(int) ), this, SLOT( layoutTabs() ) );
433} 352}
434 353
435CategoryTabBar::~CategoryTabBar() 354LauncherView *LauncherTabWidget::currentView(void)
436{ 355{
356 return (LauncherView*)stack->visibleWidget();
437} 357}
438 358
439void CategoryTabBar::layoutTabs()
440{
441 if ( !count() )
442 return;
443
444// int percentFalloffTable[] = { 100, 70, 40, 12, 6, 3, 1, 0 };
445 int available = width()-1;
446 QFontMetrics fm = fontMetrics();
447 int hiddenTabWidth = -7;
448 int middleTab = currentTab();
449 int hframe, vframe, overlap;
450 style().tabbarMetrics( this, hframe, vframe, overlap );
451 int x = 0;
452 QRect r;
453 QTab *t;
454 int required = 0;
455 int eventabwidth = (width()-1)/count();
456 enum Mode { HideBackText, Pack, Even } mode=Even;
457 for ( int i = 0; i < count(); i++ ) {
458 t = tab(i);
459 int iw = fm.width( t->text() ) + hframe - overlap;
460 if ( i != middleTab ) {
461 available -= hiddenTabWidth + hframe - overlap;
462 if ( t->iconSet() != 0 )
463 available -= t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
464 }
465 if ( t->iconSet() != 0 )
466 iw += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
467 required += iw;
468 // As space gets tight, packed looks better than even. "10" must be at least 0.
469 if ( iw >= eventabwidth-10 )
470 mode = Pack;
471 }
472 if ( mode == Pack && required > width()-1 )
473 mode = HideBackText;
474 for ( int i = 0; i < count(); i++ ) {
475 t = tab(i);
476 if ( mode != HideBackText ) {
477 int w = fm.width( t->text() );
478 int ih = 0;
479 if ( t->iconSet() != 0 ) {
480 w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
481 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
482 }
483 int h = QMAX( fm.height(), ih );
484 h = QMAX( h, QApplication::globalStrut().height() );
485
486 h += vframe;
487 w += hframe;
488
489 QRect tr(x, 0,
490 mode == Even ? eventabwidth : w * (width()-1)/required, h);
491 t->setRect(tr);
492 x += tr.width() - overlap;
493 r = r.unite(tr);
494 } else if ( i != middleTab ) {
495 int w = hiddenTabWidth;
496 int ih = 0;
497 if ( t->iconSet() != 0 ) {
498 w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
499 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
500 }
501 int h = QMAX( fm.height(), ih );
502 h = QMAX( h, QApplication::globalStrut().height() );
503
504 h += vframe;
505 w += hframe;
506
507 t->setRect( QRect(x, 0, w, h) );
508 x += t->rect().width() - overlap;
509 r = r.unite( t->rect() );
510 } else {
511 int ih = 0;
512 if ( t->iconSet() != 0 ) {
513 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
514 }
515 int h = QMAX( fm.height(), ih );
516 h = QMAX( h, QApplication::globalStrut().height() );
517
518 h += vframe;
519
520 t->setRect( QRect(x, 0, available, h) );
521 x += t->rect().width() - overlap;
522 r = r.unite( t->rect() );
523 }
524 }
525
526 QRect rr = tab(count()-1)->rect();
527 rr.setRight(width()-1);
528 tab(count()-1)->setRect( rr );
529 359
530 for ( t = tabList()->first(); t; t = tabList()->next() ) {
531 QRect tr = t->rect();
532 tr.setHeight( r.height() );
533 t->setRect( tr );
534 }
535 360
536 update(); 361void LauncherTabWidget::launcherMessage( const QCString &msg, const QByteArray &data)
537}
538
539
540void CategoryTabBar::paint( QPainter * p, QTab * t, bool selected ) const
541{ 362{
542 CategoryTabBar *that = (CategoryTabBar *) this; 363 QDataStream stream( data, IO_ReadOnly );
543 CategoryTab *ct = (CategoryTab *)t; 364 if ( msg == "setTabView(QString,int)" ) {
544 QPalette pal = palette(); 365 QString id;
545 bool setPal = FALSE; 366 stream >> id;
546 if ( ct->bgColor.isValid() ) { 367 int mode;
547 pal.setColor( QPalette::Active, QColorGroup::Background, ct->bgColor ); 368 stream >> mode;
548 pal.setColor( QPalette::Active, QColorGroup::Button, ct->bgColor ); 369 if ( view(id) )
549 pal.setColor( QPalette::Inactive, QColorGroup::Background, ct->bgColor ); 370 view(id)->setViewMode( (LauncherView::ViewMode)mode );
550 pal.setColor( QPalette::Inactive, QColorGroup::Button, ct->bgColor ); 371 } else if ( msg == "setTabBackground(QString,int,QString)" ) {
551 that->setUpdatesEnabled( FALSE ); 372 QString id;
552 that->setPalette( pal ); 373 stream >> id;
553 setPal = TRUE; 374 int mode;
554 } 375 stream >> mode;
555#if QT_VERSION >= 300 376 QString pixmapOrColor;
556 QStyle::SFlags flags = QStyle::Style_Default; 377 stream >> pixmapOrColor;
557 if ( selected ) 378 if ( view(id) )
558 flags |= QStyle::Style_Selected; 379 view(id)->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor );
559 style().drawControl( QStyle::CE_TabBarTab, p, this, t->rect(), 380 if ( id == "Documents" )
560 colorGroup(), flags, QStyleOption(t) ); 381 docLoadingWidget->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor );
561#else 382 } else if ( msg == "setTextColor(QString,QString)" ) {
562 style().drawTab( p, this, t, selected ); 383 QString id;
563#endif 384 stream >> id;
564 385 QString color;
565 QRect r( t->rect() ); 386 stream >> color;
566 QFont f( font() ); 387 if ( view(id) )
567 if ( selected ) 388 view(id)->setTextColor( QColor(color) );
568 f.setBold( TRUE ); 389 if ( id == "Documents" )
569 p->setFont( f ); 390 docLoadingWidget->setTextColor( QColor(color) );
570 391 } else if ( msg == "setFont(QString,QString,int,int,int)" ) {
571 if ( ct->fgColor.isValid() ) { 392 QString id;
572 pal.setColor( QPalette::Active, QColorGroup::Foreground, ct->fgColor ); 393 stream >> id;
573 pal.setColor( QPalette::Inactive, QColorGroup::Foreground, ct->fgColor ); 394 QString fam;
574 that->setUpdatesEnabled( FALSE ); 395 stream >> fam;
575 that->setPalette( pal ); 396 int size;
576 setPal = TRUE; 397 stream >> size;
577 } 398 int weight;
578 int iw = 0; 399 stream >> weight;
579 int ih = 0; 400 int italic;
580 if ( t->iconSet() != 0 ) { 401 stream >> italic;
581 iw = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 2; 402 if ( view(id) ) {
582 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); 403 if ( !fam.isEmpty() ) {
583 } 404 view(id)->setViewFont( QFont(fam, size, weight, italic!=0) );
584 int w = iw + p->fontMetrics().width( t->text() ) + 4; 405 qDebug( "setFont: %s, %d, %d, %d", fam.latin1(), size, weight, italic );
585 int h = QMAX(p->fontMetrics().height() + 4, ih ); 406 } else {
586 paintLabel( p, QRect( r.left() + (r.width()-w)/2 - 3, 407 view(id)->clearViewFont();
587 r.top() + (r.height()-h)/2, w, h ), t, 408 }
588#if QT_VERSION >= 300 409 }
589 t->identifier() == keyboardFocusTab() 410 }else if ( msg == "setBusyIndicatorType(QString)" ) {
590#else 411 QString type;
591 t->identitifer() == keyboardFocusTab() 412 stream >> type;
592#endif 413 setBusyIndicatorType( type );
593 ); 414 }else if ( msg == "home()" ) {
594 if ( setPal ) { 415 if ( isVisibleWindow( static_cast<QWidget*>(parent())->winId() ) ) {
595 that->unsetPalette(); 416 if (categoryBar)
596 that->setUpdatesEnabled( TRUE ); 417 categoryBar->nextTab();
418 }else
419 static_cast<QWidget*>(parent())->raise();
597 } 420 }
598} 421}
599 422
600 423
601void CategoryTabBar::paintLabel( QPainter* p, const QRect&,
602 QTab* t, bool has_focus ) const
603{
604 QRect r = t->rect();
605 // if ( t->id != currentTab() )
606 //r.moveBy( 1, 1 );
607 //
608 if ( t->iconSet() ) {
609 // the tab has an iconset, draw it in the right mode
610 QIconSet::Mode mode = (t->isEnabled() && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled;
611 if ( mode == QIconSet::Normal && has_focus )
612 mode = QIconSet::Active;
613 QPixmap pixmap = t->iconSet()->pixmap( QIconSet::Small, mode );
614 int pixw = pixmap.width();
615 int pixh = pixmap.height();
616 p->drawPixmap( r.left() + 6, r.center().y() - pixh / 2 + 1, pixmap );
617 r.setLeft( r.left() + pixw + 5 );
618 }
619
620 QRect tr = r;
621 424
622 if ( r.width() < 20 ) 425//---------------------------------------------------------------------------
623 return;
624 426
625 if ( t->isEnabled() && isEnabled() ) { 427Launcher::Launcher()
626#if defined(_WS_WIN32_) 428 : QMainWindow( 0, "PDA User Interface", QWidget::WStyle_Customize | QWidget::WGroupLeader )
627 if ( colorGroup().brush( QColorGroup::Button ) == colorGroup().brush( QColorGroup::Background ) ) 429{
628 p->setPen( colorGroup().buttonText() ); 430 tabs = 0;
629 else 431 tb = 0;
630 p->setPen( colorGroup().foreground() );
631#else
632 p->setPen( colorGroup().foreground() );
633#endif
634 p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() );
635 } else {
636 p->setPen( palette().disabled().foreground() );
637 p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() );
638 }
639} 432}
640 433
641//--------------------------------------------------------------------------- 434void Launcher::createGUI()
642
643Launcher::Launcher( QWidget* parent, const char* name, WFlags fl )
644 : QMainWindow( parent, name, fl )
645{ 435{
646 setCaption( tr("Launcher") ); 436 setCaption( tr("Launcher") );
647 437
648 syncDialog = 0;
649
650 // we have a pretty good idea how big we'll be 438 // we have a pretty good idea how big we'll be
651 setGeometry( 0, 0, qApp->desktop()->width(), qApp->desktop()->height() ); 439 setGeometry( 0, 0, qApp->desktop()->width(), qApp->desktop()->height() );
652 440
653 tabs = 0; 441 tb = new TaskBar;
654 rootFolder = 0; 442 tabs = new LauncherTabWidget( this );
655 docsFolder = 0; 443 setCentralWidget( tabs );
656 444
657 int stamp = uidgen.generate(); // this is our timestamp to see which devices we know 445 ServerInterface::dockWidget( tb, ServerInterface::Bottom );
658 //uidgen.store( stamp ); 446 tb->show();
659 m_timeStamp = QString::number( stamp );
660 447
661 tabs = new CategoryTabWidget( this ); 448 qApp->installEventFilter( this );
662 setCentralWidget( tabs );
663 449
450
451 connect( qApp, SIGNAL(symbol()), this, SLOT(toggleSymbolInput()) );
452 connect( qApp, SIGNAL(numLockStateToggle()), this, SLOT(toggleNumLockState()) );
453 connect( qApp, SIGNAL(capsLockStateToggle()), this, SLOT(toggleCapsLockState()) );
454
455 connect( tb, SIGNAL(tabSelected(const QString&)),
456 this, SLOT(showTab(const QString&)) );
664 connect( tabs, SIGNAL(selected(const QString&)), 457 connect( tabs, SIGNAL(selected(const QString&)),
665 this, SLOT(viewSelected(const QString&)) ); 458 this, SLOT(viewSelected(const QString&)) );
666 connect( tabs, SIGNAL(clicked(const AppLnk*)), 459 connect( tabs, SIGNAL(clicked(const AppLnk*)),
667 this, SLOT(select(const AppLnk*))); 460 this, SLOT(select(const AppLnk*)));
668 connect( tabs, SIGNAL(rightPressed(AppLnk*)), 461 connect( tabs, SIGNAL(rightPressed(AppLnk*)),
669 this, SLOT(properties(AppLnk*))); 462 this, SLOT(properties(AppLnk*)));
670 463
671 464#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
672#if !defined(QT_NO_COP)
673 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this ); 465 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this );
674 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)), 466 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)),
675 this, SLOT(systemMessage( const QCString &, const QByteArray &)) ); 467 this, SLOT(systemMessage( const QCString &, const QByteArray &)) );
676 QCopChannel *channel = new QCopChannel( "QPE/Launcher", this );
677 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
678 this, SLOT(launcherMessage(const QCString&, const QByteArray&)) );
679#endif 468#endif
680 469
681 storage = new StorageInfo( this ); 470 // all documents
682 connect( storage, SIGNAL( disksChanged() ), SLOT( storageChanged() ) ); 471 QImage img( Resource::loadImage( "DocsIcon" ) );
683 472 QPixmap pm;
684 updateTabs(); 473 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
474 // It could add this itself if it handles docs
475 tabs->newView("Documents", pm, tr("Documents") )->setToolsEnabled( TRUE );
476 QTimer::singleShot( 0, tabs, SLOT( initLayout() ) );
685 477
686 preloadApps(); 478 qApp->setMainWidget( this );
687 479
688 in_lnk_props = FALSE; 480 QTimer::singleShot( 500, this, SLOT( makeVisible() ) );
689 got_lnk_change = FALSE;
690} 481}
691 482
692Launcher::~Launcher() 483Launcher::~Launcher()
693{ 484{
694 delete rootFolder; 485 if ( tb )
695 delete docsFolder; 486 destroyGUI();
696}
697
698static bool isVisibleWindow(int wid)
699{
700#ifdef QWS
701 const QList<QWSWindow> &list = qwsServer->clientWindows();
702 QWSWindow* w;
703 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
704 if ( w->winId() == wid )
705 return !w->isFullyObscured();
706 }
707#endif
708 return FALSE;
709} 487}
710 488
711void Launcher::showMaximized() 489void Launcher::makeVisible()
712{ 490{
713 if ( isVisibleWindow( winId() ) ) 491 showMaximized();
714 doMaximize();
715 else
716 QTimer::singleShot( 20, this, SLOT(doMaximize()) );
717} 492}
718 493
719void Launcher::doMaximize() 494void Launcher::destroyGUI()
720{ 495{
721 QMainWindow::showMaximized(); 496 delete tb;
722 tabs->setMaximumWidth( qApp->desktop()->width() ); 497 tb = 0;
498 delete tabs;
499 tabs =0;
723} 500}
724 501
725void Launcher::updateMimeTypes() 502bool Launcher::eventFilter( QObject*, QEvent *ev )
726{ 503{
727 MimeType::clear(); 504#ifdef QT_QWS_CUSTOM
728 updateMimeTypes(rootFolder); 505 if ( ev->type() == QEvent::KeyPress ) {
506 QKeyEvent *ke = (QKeyEvent *)ev;
507 if ( ke->key() == Qt::Key_F11 ) { // menu key
508 QWidget *active = qApp->activeWindow();
509 if ( active && active->isPopup() )
510 active->close();
511 else {
512 Global::terminateBuiltin("calibrate"); // No tr
513 tb->launchStartMenu();
514 }
515 return TRUE;
516 }
517 }
518#else
519 Q_UNUSED(ev);
520#endif
521 return FALSE;
729} 522}
730 523
731void Launcher::updateMimeTypes(AppLnkSet* folder) 524void Launcher::toggleSymbolInput()
732{ 525{
733 for ( QListIterator<AppLnk> it( folder->children() ); it.current(); ++it ) { 526 tb->toggleSymbolInput();
734 AppLnk *app = it.current();
735 if ( app->type() == "Folder" ) // No tr
736 updateMimeTypes((AppLnkSet *)app);
737 else {
738 MimeType::registerApp(*app);
739 }
740 }
741} 527}
742 528
743/** This is a HACK.... 529void Launcher::toggleNumLockState()
744 * Reason: scanning huge mediums, microdirvers for examples
745 * consomes time. To avoid that we invented the MediumMountCheck
746 *
747 * a) the user globally disabled medium checking. We can ignore
748 * all removable medium
749 * b) the user enabled medium checking globally and we need to use this mimefilter
750 * c) the user enabled medium checking on a per medium bases
751 * c1) we already checked and its not ask again turns
752 * c2) we need to ask and then apply the mimefilter
753 */
754void Launcher::loadDocs() // ok here comes a hack belonging to Global::
755{ 530{
756 OWait *owait = new OWait(); 531 tb->toggleNumLockState();
757 Global::statusMessage( tr( "Finding documents" ) );
758
759 owait->show();
760 qApp->processEvents();
761 if(docsFolder) delete docsFolder;
762 docsFolder = new DocLnkSet;
763 DocLnkSet *tmp = 0;
764 QString home = QString(getenv("HOME")) + "/Documents";
765 tmp = new DocLnkSet( home , QString::null);
766 docsFolder->appendFrom( *tmp );
767 delete tmp;
768
769 // RAM documents
770 StorageInfo storage;
771 const QList<FileSystem> &fileSystems = storage.fileSystems();
772 QListIterator<FileSystem> it ( fileSystems );
773
774 for ( ; it.current(); ++it ) {
775 if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) {
776 tmp = new DocLnkSet( (*it)->path(), QString::null );
777 docsFolder->appendFrom( *tmp );
778 delete tmp;
779 }
780 }
781
782 Config mediumCfg( "medium");
783 mediumCfg.setGroup("main");
784 // a) -zecke we don't want to check
785 if(!mediumCfg.readBoolEntry("use", true ) ) {
786 owait->hide();
787 delete owait;
788 return;
789 }
790 // find out wich filesystems are new in this round
791 // We will do this by having a timestamp inside each mountpoint
792 // if the current timestamp doesn't match this is a new file system and
793 // come up with our MediumMountGui :) let the hacking begin
794 int stamp = uidgen.generate();
795
796 QString newStamp = QString::number( stamp ); // generates newtime Stamp
797
798 // b)
799 if( mediumCfg.readBoolEntry("global", true ) ){
800 QString mime = configToMime(&mediumCfg).join(";");
801 for( it.toFirst(); it.current(); ++it ){
802 if( (*it)->isRemovable() ){
803 tmp = new DocLnkSet( (*it)->path(), mime );
804 docsFolder->appendFrom( *tmp );
805 delete tmp;
806 }
807 } // done
808 owait->hide();
809 delete owait;
810 return; // save the else
811 }
812 // c) zecke
813 for ( it.toFirst(); it.current(); ++it ) {
814 if ( (*it)->isRemovable() ) { // let's find out if we should search on it
815 Config cfg( (*it)->path() + "/.opiestorage.cf", Config::File);
816 cfg.setGroup("main");
817 QString stamp = cfg.readEntry("timestamp", QDateTime::currentDateTime().toString() );
818 /** This medium is uptodate
819 */
820 if( stamp == m_timeStamp ){ // ok we know this card
821 cfg.writeEntry("timestamp", newStamp ); //just write a new timestamp
822 // we need to scan the list now. Hopefully the cache will be there
823 // read the mimetypes from the config and search for documents
824 QStringList mimetypes = configToMime( &cfg);
825 //qApp->processEvents();
826 Global::statusMessage( tr( "Searching documents" ) );
827 tmp = new DocLnkSet( (*it)->path(), mimetypes.join(";") );
828 docsFolder->appendFrom( *tmp );
829 delete tmp;
830
831 } else { // come up with the gui cause this a new card
832 MediumMountGui medium(&cfg, (*it)->path() );
833 if( medium.check() ){ // we did not ask before or ask again is off
834 /** c2) */
835 if( medium.exec() ){ // he clicked yes so search it
836 // speicher
837 //cfg.read(); // cause of a race we need to reread - fixed
838 cfg.setGroup("main");
839 cfg.writeEntry("timestamp", newStamp );
840 cfg.write();
841
842 //qApp->processEvents();
843 tmp = new DocLnkSet( (*it)->path(), medium.mimeTypes().join(";" ) );
844 docsFolder->appendFrom( *tmp );
845 delete tmp;
846 }// no else
847 /** c1) */
848 } else { // we checked
849 // do something different see what we need to do
850 // let's see if we should check the device
851 cfg.setGroup("main" );
852 bool check = cfg.readBoolEntry("autocheck", true );
853 if( check ){ // find the documents
854
855 //qApp->processEvents();
856 Global::statusMessage( tr( "Searching documents" ) );
857 tmp = new DocLnkSet( (*it)->path(), configToMime(&cfg ).join(";") );
858 docsFolder->appendFrom( *tmp );
859 delete tmp;
860 }
861 }
862 }
863 }
864 }
865 m_timeStamp = newStamp;
866 owait->hide();
867 delete owait;
868} 532}
869 533
870void Launcher::updateTabs() 534void Launcher::toggleCapsLockState()
871{ 535{
872 MimeType::updateApplications(); // ### reads all applnks twice 536 tb->toggleCapsLockState();
873 delete rootFolder;
874 rootFolder = new AppLnkSet( MimeType::appsFolderName() );
875
876 loadDocs();
877
878 tabs->initializeCategories(rootFolder, docsFolder, storage->fileSystems());
879} 537}
880 538
881void Launcher::updateDocs() 539static bool isVisibleWindow(int wid)
882{ 540{
883 loadDocs(); 541#ifdef Q_WS_QWS
884 // tabs->updateDocs(docsFolder,storage->fileSystems()); 542 const QList<QWSWindow> &list = qwsServer->clientWindows();
543 QWSWindow* w;
544 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
545 if ( w->winId() == wid )
546 return !w->isFullyObscured();
547 }
548#endif
549 return FALSE;
885} 550}
886 551
887void Launcher::viewSelected(const QString& s) 552void Launcher::viewSelected(const QString& s)
888{ 553{
889 setCaption( s + tr(" - Launcher") ); 554 setCaption( s + tr(" - Launcher") );
890} 555}
891 556
892void Launcher::nextView()
893{
894 tabs->nextTab();
895}
896
897void Launcher::showTab(const QString& id) 557void Launcher::showTab(const QString& id)
898{ 558{
899 tabs->showTab(id); 559 tabs->categoryBar->showTab(id);
900 raise(); 560 raise();
901} 561}
902 562
903void Launcher::select( const AppLnk *appLnk ) 563void Launcher::select( const AppLnk *appLnk )
904{ 564{
905 if ( appLnk->type() == "Folder" ) { // No tr 565 if ( appLnk->type() == "Folder" ) { // No tr
906 // Not supported: flat is simpler for the user 566 // Not supported: flat is simpler for the user
907 } else { 567 } else {
908 if ( appLnk->exec().isNull() ) { 568 if ( appLnk->exec().isNull() ) {
909 QMessageBox::information(this,tr("No application"), 569 int i = QMessageBox::information(this,tr("No application"),
910 tr("<p>No application is defined for this document." 570 tr("<p>No application is defined for this document."
911 "<p>Type is %1.").arg(appLnk->type())); 571 "<p>Type is %1.").arg(appLnk->type()), tr("OK"), tr("View as text"), 0, 0, 1);
912 return; 572
913 } 573#if 0
914 tabs->setBusy(TRUE); 574 /* ### Fixme */
915 emit executing( appLnk ); 575 if ( i == 1 )
916 appLnk->execute(); 576 Global::execute(Service::app("Open/text/*"),appLnk->file());
577#endif
578 return;
579 }
580 tabs->setBusy(TRUE);
581 emit executing( appLnk );
582 appLnk->execute();
917 } 583 }
918} 584}
919 585
920void Launcher::externalSelected(const AppLnk *appLnk)
921{
922 tabs->setBusy(TRUE);
923 emit executing( appLnk );
924}
925
926void Launcher::properties( AppLnk *appLnk ) 586void Launcher::properties( AppLnk *appLnk )
927{ 587{
928 if ( appLnk->type() == "Folder" ) { // No tr 588 if ( appLnk->type() == "Folder" ) { // No tr
929 // Not supported: flat is simpler for the user 589 // Not supported: flat is simpler for the user
930 } else { 590 } else {
931 in_lnk_props = TRUE; 591/* ### libqtopia FIXME also moving docLnks... */
932 got_lnk_change = FALSE; 592 LnkProperties prop(appLnk,0 );
933 LnkProperties prop(appLnk); 593
934 connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); 594 prop.showMaximized();
935 prop.showMaximized(); 595 prop.exec();
936 prop.exec();
937 in_lnk_props = FALSE;
938 if ( got_lnk_change ) {
939 updateLink(lnk_change);
940 }
941 } 596 }
942} 597}
943 598
944void Launcher::updateLink(const QString& link) 599void Launcher::storageChanged( const QList<FileSystem> &fs )
945{ 600{
946 bool notify_sm = false; 601 // ### update combo boxes if we had a combo box for the storage type
947
948 if (link.isNull()) {
949 updateTabs();
950 notify_sm = true;
951 }
952 else if (link.isEmpty()) {
953 updateDocs();
954 }
955 else {
956 tabs->updateLink(link);
957 notify_sm = true;
958 }
959
960 if ( notify_sm )
961 QCopEnvelope e ( "QPE/TaskBar", "reloadApps()" );
962} 602}
963 603
964void Launcher::systemMessage( const QCString &msg, const QByteArray &data) 604void Launcher::systemMessage( const QCString &msg, const QByteArray &data)
965{ 605{
966 QDataStream stream( data, IO_ReadOnly ); 606 QDataStream stream( data, IO_ReadOnly );
967 if ( msg == "linkChanged(QString)" ) { 607 if ( msg == "busy()" ) {
968 QString link; 608 tb->startWait();
969 stream >> link;
970 if ( in_lnk_props ) {
971 got_lnk_change = TRUE;
972 lnk_change = link;
973 } else {
974 updateLink(link);
975 }
976 } else if ( msg == "busy()" ) {
977 emit busy();
978 } else if ( msg == "notBusy(QString)" ) { 609 } else if ( msg == "notBusy(QString)" ) {
979 QString app; 610 QString app;
980 stream >> app; 611 stream >> app;
981 tabs->setBusy(FALSE); 612 tabs->setBusy(FALSE);
982 emit notBusy(app); 613 tb->stopWait(app);
983 } else if ( msg == "mkdir(QString)" ) { 614 } else if (msg == "applyStyle()") {
984 QString dir; 615 tabs->currentView()->relayout();
985 stream >> dir;
986 if ( !dir.isEmpty() )
987 mkdir( dir );
988 } else if ( msg == "rdiffGenSig(QString,QString)" ) {
989 QString baseFile, sigFile;
990 stream >> baseFile >> sigFile;
991 QRsync::generateSignature( baseFile, sigFile );
992 } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) {
993 QString baseFile, sigFile, deltaFile;
994 stream >> baseFile >> sigFile >> deltaFile;
995 QRsync::generateDiff( baseFile, sigFile, deltaFile );
996 } else if ( msg == "rdiffApplyPatch(QString,QString)" ) {
997 QString baseFile, deltaFile;
998 stream >> baseFile >> deltaFile;
999 if ( !QFile::exists( baseFile ) ) {
1000 QFile f( baseFile );
1001 f.open( IO_WriteOnly );
1002 f.close();
1003 }
1004 QRsync::applyDiff( baseFile, deltaFile );
1005#ifndef QT_NO_COP
1006 QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" );
1007 e << baseFile;
1008#endif
1009 } else if ( msg == "rdiffCleanup()" ) {
1010 mkdir( "/tmp/rdiff" );
1011 QDir dir;
1012 dir.setPath( "/tmp/rdiff" );
1013 QStringList entries = dir.entryList();
1014 for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it )
1015 dir.remove( *it );
1016 } else if ( msg == "sendHandshakeInfo()" ) {
1017 QString home = getenv( "HOME" );
1018#ifndef QT_NO_COP
1019 QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" );
1020 e << home;
1021 int locked = (int) Desktop::screenLocked();
1022 e << locked;
1023#endif
1024 } else if ( msg == "autoStart(QString)" ) {
1025 QString appName;
1026 stream >> appName;
1027 Config cfg( "autostart" );
1028 cfg.setGroup( "AutoStart" );
1029 if ( appName.compare("clear") == 0){
1030 cfg.writeEntry("Apps", "");
1031 }
1032 } else if ( msg == "autoStart(QString,QString)" ) {
1033 QString modifier, appName;
1034 stream >> modifier >> appName;
1035 Config cfg( "autostart" );
1036 cfg.setGroup( "AutoStart" );
1037 if ( modifier.compare("add") == 0 ){
1038 // only add if appname is entered
1039 if (!appName.isEmpty()) {
1040 cfg.writeEntry("Apps", appName);
1041 }
1042 } else if (modifier.compare("remove") == 0 ) {
1043 // need to change for multiple entries
1044 // actually remove is right now simular to clear, but in future there
1045 // should be multiple apps in autostart possible.
1046 QString checkName;
1047 checkName = cfg.readEntry("Apps", "");
1048 if (checkName == appName) {
1049 cfg.writeEntry("Apps", "");
1050 }
1051 }
1052 // case the autostart feature should be delayed
1053 } else if ( msg == "autoStart(QString,QString,QString)") {
1054 QString modifier, appName, delay;
1055 stream >> modifier >> appName >> delay;
1056 Config cfg( "autostart" );
1057 cfg.setGroup( "AutoStart" );
1058 if ( modifier.compare("add") == 0 ){
1059 // only add it appname is entered
1060 if (!appName.isEmpty()) {
1061 cfg.writeEntry("Apps", appName);
1062 cfg.writeEntry("Delay", delay);
1063 }
1064 } else {
1065 }
1066 } 616 }
1067 /* 617}
1068 * QtopiaDesktop relies on the major number
1069 * to start with 1. We're at 0.9
1070 * so wee need to fake at least 1.4 to be able
1071 * to sync with QtopiaDesktop1.6
1072 */
1073 else if ( msg == "sendVersionInfo()" ) {
1074 QCopEnvelope e( "QPE/Desktop", "versionInfo(QString)" );
1075 QString v2 = QString::fromLatin1("1.4");
1076 e << v2;
1077 //qDebug("version %s\n", line.latin1());
1078 } else if ( msg == "sendCardInfo()" ) {
1079#ifndef QT_NO_COP
1080 QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" );
1081#endif
1082 const QList<FileSystem> &fs = storage->fileSystems();
1083 QListIterator<FileSystem> it ( fs );
1084 QString s;
1085 QString homeDir = getenv("HOME");
1086 QString hardDiskHome, hardDiskHomePath;
1087 for ( ; it.current(); ++it ) {
1088 int k4 = (*it)->blockSize()/256;
1089 if ( (*it)->isRemovable() || (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs") {
1090 s += (*it)->name() + "=" + (*it)->path() + "/Documents "
1091 + QString::number( (*it)->availBlocks() * k4/4 )
1092 + "K " + (*it)->options() + ";";
1093 } else if ( (*it)->disk() == "/dev/mtdblock1" ||
1094 (*it)->disk() == "/dev/mtdblock/1" ) {
1095 s += (*it)->name() + "=" + homeDir + "/Documents "
1096 + QString::number( (*it)->availBlocks() * k4/4 )
1097 + "K " + (*it)->options() + ";";
1098 } else if ( (*it)->name().contains( "Hard Disk") &&
1099 homeDir.contains( (*it)->path() ) &&
1100 (*it)->path().length() > hardDiskHomePath.length() ) {
1101 hardDiskHomePath = (*it)->path();
1102 hardDiskHome =
1103 (*it)->name() + "=" + homeDir + "/Documents "
1104 + QString::number( (*it)->availBlocks() * k4/4 )
1105 + "K " + (*it)->options() + ";";
1106 }
1107 }
1108 if ( !hardDiskHome.isEmpty() )
1109 s += hardDiskHome;
1110
1111#ifndef QT_NO_COP
1112 e << s;
1113#endif
1114 } else if ( msg == "sendSyncDate(QString)" ) {
1115 QString app;
1116 stream >> app;
1117 Config cfg( "qpe" );
1118 cfg.setGroup("SyncDate");
1119#ifndef QT_NO_COP
1120 QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" );
1121 e << app << cfg.readEntry( app );
1122#endif
1123 //qDebug("QPE/System sendSyncDate for %s: response %s", app.latin1(),
1124 //cfg.readEntry( app ).latin1() );
1125 } else if ( msg == "setSyncDate(QString,QString)" ) {
1126 QString app, date;
1127 stream >> app >> date;
1128 Config cfg( "qpe" );
1129 cfg.setGroup("SyncDate");
1130 cfg.writeEntry( app, date );
1131 //qDebug("setSyncDate(QString,QString) %s %s", app.latin1(), date.latin1());
1132 } else if ( msg == "startSync(QString)" ) {
1133 QString what;
1134 stream >> what;
1135 delete syncDialog; syncDialog = 0;
1136 syncDialog = new SyncDialog( this, "syncProgress", FALSE,
1137 WStyle_Tool | WStyle_Customize |
1138 Qt::WStyle_StaysOnTop );
1139 syncDialog->showMaximized();
1140 syncDialog->whatLabel->setText( "<b>" + what + "</b>" );
1141 connect( syncDialog->buttonCancel, SIGNAL( clicked() ),
1142 SLOT( cancelSync() ) );
1143 } else if ( msg == "stopSync()") {
1144 delete syncDialog; syncDialog = 0;
1145 } else if ( msg == "getAllDocLinks()" ) {
1146 loadDocs();
1147
1148 // directly show updated docs in document tab
1149 updateDocs();
1150
1151 QString contents;
1152
1153// Categories cats;
1154 for ( QListIterator<DocLnk> it( docsFolder->children() ); it.current(); ++it ) {
1155 DocLnk *doc = it.current();
1156 QFileInfo fi( doc->file() );
1157 if ( !fi.exists() )
1158 continue;
1159
1160 bool fake = !doc->linkFileKnown();
1161 if ( !fake ) {
1162 QFile f( doc->linkFile() );
1163 if ( f.open( IO_ReadOnly ) ) {
1164 QTextStream ts( &f );
1165 ts.setEncoding( QTextStream::UnicodeUTF8 );
1166 contents += ts.read();
1167 f.close();
1168 } else
1169 fake = TRUE;
1170 }
1171 if (fake) {
1172 contents += "[Desktop Entry]\n";
1173 contents += "Categories = " + // No tr
1174// cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr
1175 Qtopia::Record::idsToString( doc->categories() ) + "\n";
1176 contents += "Name = "+doc->name()+"\n"; // No tr
1177 contents += "Type = "+doc->type()+"\n"; // No tr
1178 }
1179 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path)
1180 contents += QString("Size = %1\n").arg( fi.size() ); // No tr
1181 }
1182
1183 //qDebug( "sending length %d", contents.length() );
1184#ifndef QT_NO_COP
1185 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" );
1186 e << contents;
1187#endif
1188 618
1189 //qDebug( "================ \n\n%s\n\n===============", 619// These are the update functions from the server
1190 //contents.latin1() ); 620void Launcher::typeAdded( const QString& type, const QString& name,
1191 621 const QPixmap& pixmap, const QPixmap& )
1192 delete docsFolder; 622{
1193 docsFolder = 0; 623 tabs->newView( type, pixmap, name );
1194#ifdef QWS 624 ids.append( type );
1195 } else if ( msg == "setMouseProto(QString)" ) { 625 tb->refreshStartMenu();
1196 QString mice; 626
1197 stream >> mice; 627 static bool first = TRUE;
1198 setenv("QWS_MOUSE_PROTO",mice.latin1(),1); 628 if ( first ) {
1199 qwsServer->openMouse(); 629 first = FALSE;
1200 } else if ( msg == "setKeyboard(QString)" ) { 630 tabs->categoryBar->showTab(type);
1201 QString kb;
1202 stream >> kb;
1203 setenv("QWS_KEYBOARD",kb.latin1(),1);
1204 qwsServer->openKeyboard();
1205#endif
1206 } 631 }
632
633 tabs->view( type )->setUpdatesEnabled( FALSE );
634 tabs->view( type )->setSortEnabled( FALSE );
1207} 635}
1208 636
1209void Launcher::cancelSync() 637void Launcher::typeRemoved( const QString& type )
1210{ 638{
1211#ifndef QT_NO_COP 639 tabs->view( type )->removeAllItems();
1212 QCopEnvelope e( "QPE/Desktop", "cancelSync()" ); 640 tabs->deleteView( type );
1213#endif 641 ids.remove( type );
642 tb->refreshStartMenu();
1214} 643}
1215 644
1216void Launcher::launcherMessage( const QCString &msg, const QByteArray &data) 645void Launcher::applicationAdded( const QString& type, const AppLnk& app )
1217{ 646{
1218 QDataStream stream( data, IO_ReadOnly ); 647 if ( app.type() == "Separator" ) // No tr
1219 if ( msg == "setTabView(QString,int)" ) { 648 return;
1220 QString id;
1221 stream >> id;
1222 int mode;
1223 stream >> mode;
1224 if ( tabs->view(id) )
1225 tabs->view(id)->setViewMode( (LauncherView::ViewMode)mode );
1226 } else if ( msg == "setTabBackground(QString,int,QString)" ) {
1227 QString id;
1228 stream >> id;
1229 int mode;
1230 stream >> mode;
1231 QString pixmapOrColor;
1232 stream >> pixmapOrColor;
1233 if ( tabs->view(id) )
1234 tabs->view(id)->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor );
1235 } else if ( msg == "setTextColor(QString,QString)" ) {
1236 QString id;
1237 stream >> id;
1238 QString color;
1239 stream >> color;
1240 if ( tabs->view(id) )
1241 tabs->view(id)->setTextColor( QColor(color) );
1242 } else if ( msg == "setFont(QString,QString,int,int,int)" ) {
1243 QString id;
1244 stream >> id;
1245 QString fam;
1246 stream >> fam;
1247 int size;
1248 stream >> size;
1249 int weight;
1250 stream >> weight;
1251 int italic;
1252 stream >> italic;
1253 if ( tabs->view(id) )
1254 if ( !fam. isEmpty ( ))
1255 tabs->view(id)->setViewFont( QFont(fam, size, weight, italic!=0) );
1256 else
1257 tabs->view(id)->unsetViewFont();
1258 qDebug( "setFont: %s, %d, %d, %d", fam.latin1(), size, weight, italic );
1259 }
1260 else if ( msg == "setBusyIndicatorType(QString)" ) {
1261 QString type;
1262 stream >> type;
1263 tabs->setBusyIndicatorType(type);
1264 }
1265 else if ( msg == "home()" ) {
1266 if ( isVisibleWindow( winId ( )))
1267 nextView ( );
1268 else
1269 raise ( );
1270 649
1271 } 650 LauncherView *view = tabs->view( type );
651 if ( view )
652 view->addItem( new AppLnk( app ), FALSE );
653 else
654 qWarning("addAppLnk: No view for type %s. Can't add app %s!",
655 type.latin1(),app.name().latin1() );
656
657 MimeType::registerApp( app );
1272} 658}
1273 659
1274void Launcher::storageChanged() 660void Launcher::applicationRemoved( const QString& type, const AppLnk& app )
1275{ 661{
1276 if ( in_lnk_props ) { 662 LauncherView *view = tabs->view( type );
1277 got_lnk_change = TRUE; 663 if ( view )
1278 lnk_change = QString::null; 664 view->removeLink( app.linkFile() );
1279 } else { 665 else
1280 updateLink( QString::null ); 666 qWarning("removeAppLnk: No view for %s!", type.latin1() );
1281 }
1282} 667}
1283 668
669void Launcher::allApplicationsRemoved()
670{
671 MimeType::clear();
672 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it)
673 tabs->view( (*it) )->removeAllItems();
674}
1284 675
1285bool Launcher::mkdir(const QString &localPath) 676void Launcher::documentAdded( const DocLnk& doc )
1286{ 677{
1287 QDir fullDir(localPath); 678 tabs->docView()->addItem( new DocLnk( doc ), FALSE );
1288 if (fullDir.exists()) 679}
1289 return true;
1290
1291 // at this point the directory doesn't exist
1292 // go through the directory tree and start creating the direcotories
1293 // that don't exist; if we can't create the directories, return false
1294
1295 QString dirSeps = "/";
1296 int dirIndex = localPath.find(dirSeps);
1297 QString checkedPath;
1298
1299 // didn't find any seps; weird, use the cur dir instead
1300 if (dirIndex == -1) {
1301 //qDebug("No seperators found in path %s", localPath.latin1());
1302 checkedPath = QDir::currentDirPath();
1303 }
1304 680
1305 while (checkedPath != localPath) { 681void Launcher::showLoadingDocs()
1306 // no more seperators found, use the local path 682{
1307 if (dirIndex == -1) 683 tabs->docView()->hide();
1308 checkedPath = localPath; 684}
1309 else {
1310 // the next directory to check
1311 checkedPath = localPath.left(dirIndex) + "/";
1312 // advance the iterator; the next dir seperator
1313 dirIndex = localPath.find(dirSeps, dirIndex+1);
1314 }
1315
1316 QDir checkDir(checkedPath);
1317 if (!checkDir.exists()) {
1318 //qDebug("mkdir making dir %s", checkedPath.latin1());
1319
1320 if (!checkDir.mkdir(checkedPath)) {
1321 qDebug("Unable to make directory %s", checkedPath.latin1());
1322 return FALSE;
1323 }
1324 }
1325 685
1326 } 686void Launcher::showDocTab()
1327 return TRUE; 687{
688 if ( tabs->categoryBar->currentView() == tabs->docView() )
689 tabs->docView()->show();
1328} 690}
1329 691
1330void Launcher::preloadApps() 692void Launcher::documentRemoved( const DocLnk& doc )
1331{ 693{
1332 Config cfg("Launcher"); 694 tabs->docView()->removeLink( doc.linkFile() );
1333 cfg.setGroup("Preload");
1334 QStringList apps = cfg.readListEntry("Apps",',');
1335 for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) {
1336#ifndef QT_NO_COP
1337 QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()");
1338#endif
1339 }
1340} 695}
1341 696
1342DocumentTab::DocumentTab( QWidget *parent, int mode, int selector, const QString &dirName, const QString &fileName) 697void Launcher::documentChanged( const DocLnk& oldDoc, const DocLnk& newDoc )
1343 : OFileSelector(parent,mode,selector,dirName,fileName)
1344{ 698{
1345 //setYesCancelVisible(false); 699 documentRemoved( oldDoc );
1346 //setToolbarVisible(false); 700 documentAdded( newDoc );
1347 //setPermissionBarVisible(false);
1348 //setLineEditVisible(false) ;
1349 //setChooserVisible( bool chooser );
1350
1351} 701}
1352 702
1353DocumentTab::~DocumentTab() { 703void Launcher::allDocumentsRemoved()
704{
705 tabs->docView()->removeAllItems();
706}
1354 707
708void Launcher::applicationStateChanged( const QString& name, ApplicationState state )
709{
710 tb->setApplicationState( name, state );
711}
712
713void Launcher::applicationScanningProgress( int percent )
714{
715 switch ( percent ) {
716 case 0: {
717 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) {
718 tabs->view( (*it) )->setUpdatesEnabled( FALSE );
719 tabs->view( (*it) )->setSortEnabled( FALSE );
720 }
721 break;
722 }
723 case 100: {
724 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) {
725 tabs->view( (*it) )->setUpdatesEnabled( TRUE );
726 tabs->view( (*it) )->setSortEnabled( TRUE );
727 }
728 break;
729 }
730 default:
731 break;
732 }
733}
734
735void Launcher::documentScanningProgress( int percent )
736{
737 switch ( percent ) {
738 case 0: {
739 tabs->setLoadingProgress( 0 );
740 tabs->setLoadingWidgetEnabled( TRUE );
741 tabs->docView()->setUpdatesEnabled( FALSE );
742 tabs->docView()->setSortEnabled( FALSE );
743 break;
744 }
745 case 100: {
746 tabs->docView()->updateTools();
747 tabs->docView()->setSortEnabled( TRUE );
748 tabs->docView()->setUpdatesEnabled( TRUE );
749 tabs->setLoadingWidgetEnabled( FALSE );
750 break;
751 }
752 default:
753 tabs->setLoadingProgress( percent );
754 break;
755 }
1355} 756}
1356 757
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index 7117e0b..85163b6 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -1,981 +1,1060 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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 20
21#include "launcherview.h" 21#include "launcherview.h"
22 22
23#include <qpe/qpeapplication.h> 23#include <qtopia/qpeapplication.h>
24#include <qpe/applnk.h> 24#include <qtopia/applnk.h>
25#include <qpe/qpedebug.h> 25#include <qtopia/qpedebug.h>
26#include <qpe/categories.h> 26#include <qtopia/private/categories.h>
27#include <qpe/categoryselect.h> 27#include <qtopia/categoryselect.h>
28#include <qpe/menubutton.h> 28#include <qtopia/menubutton.h>
29#include <qpe/mimetype.h> 29#include <qtopia/mimetype.h>
30#include <qpe/resource.h> 30#include <qtopia/resource.h>
31#include <qpe/qpetoolbar.h> 31#include <qtopia/qpetoolbar.h>
32//#include <qtopia/private/palmtoprecord.h> 32//#include <qtopia/private/palmtoprecord.h>
33 33
34#include <qtimer.h> 34#include <qtimer.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qdict.h> 36#include <qdict.h>
37#include <qfile.h> 37#include <qfile.h>
38#include <qfileinfo.h> 38#include <qfileinfo.h>
39#include <qhbox.h> 39#include <qhbox.h>
40#include <qiconview.h> 40#include <qiconview.h>
41#include <qwidgetstack.h>
41#include <qpainter.h> 42#include <qpainter.h>
42#include <qregexp.h> 43#include <qregexp.h>
43#include <qtoolbutton.h> 44#include <qtoolbutton.h>
44#include <qimage.h> 45#include <qimage.h>
46#include <qlabel.h>
47#include <qobjectlist.h>
48
49
50// These define how the busy icon is animated and highlighted
51#define BRIGHTEN_BUSY_ICON
52//#define ALPHA_FADE_BUSY_ICON
53//#define USE_ANIMATED_BUSY_ICON_OVERLAY
54#define BOUNCE_BUSY_ICON
45 55
46#include <cstdlib>
47 56
48class BgPixmap 57class BgPixmap
49{ 58{
50public: 59public:
51 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} 60 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {}
52 QPixmap pm; 61 QPixmap pm;
53 int ref; 62 int ref;
54}; 63};
55 64
56enum BusyIndicatorType { 65enum BusyIndicatorType {
57 BIT_Normal = 0, 66 BIT_Normal = 0,
58 BIT_Blinking 67 BIT_Blinking
59}; 68};
60 69
61static QMap<QString,BgPixmap*> *bgCache = 0; 70static QMap<QString,BgPixmap*> *bgCache = 0;
62 71
72static void cleanup_cache()
73{
74 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin();
75 while ( it != bgCache->end() ) {
76 QMap<QString,BgPixmap*>::Iterator curr = it;
77 ++it;
78 delete (*curr);
79 bgCache->remove( curr );
80 }
81 delete bgCache;
82 bgCache = 0;
83}
84
85
86class LauncherItem : public QIconViewItem
87{
88public:
89 LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE );
90 ~LauncherItem();
91
92 AppLnk *appLnk() const { return app; }
93 AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; }
94
95 void animateIcon();
96 void resetIcon();
97
98 virtual int compare ( QIconViewItem * i ) const;
99 void paintItem( QPainter *p, const QColorGroup &cg );
100protected:
101 bool isBigIcon;
102 int iteration;
103 AppLnk* app;
104private:
105 void paintAnimatedIcon( QPainter *p );
106};
107
108
63class LauncherIconView : public QIconView { 109class LauncherIconView : public QIconView {
64public: 110public:
65 LauncherIconView( QWidget* parent, const char* name=0 ) : 111 LauncherIconView( QWidget* parent, const char* name=0 ) :
66 QIconView(parent,name), 112 QIconView(parent,name),
67 tf(""), 113 tf(""),
68 cf(0), 114 cf(0),
69 bsy(0), 115 bsy(0),
116 busyTimer(0),
70 bigIcns(TRUE), 117 bigIcns(TRUE),
71 bgColor(white) 118 bgColor(white)
72 { 119 {
73 sortmeth = Name; 120 sortmeth = Name;
74 hidden.setAutoDelete(TRUE); 121 hidden.setAutoDelete(TRUE);
75 ike = FALSE; 122 ike = FALSE;
76 busytimer = 0;
77 calculateGrid( Bottom ); 123 calculateGrid( Bottom );
78 } 124 }
79 125
80 ~LauncherIconView() 126 ~LauncherIconView()
81 { 127 {
82#if 0 // debuggery 128#if 0 // debuggery
83 QListIterator<AppLnk> it(hidden); 129 QListIterator<AppLnk> it(hidden);
84 AppLnk* l; 130 AppLnk* l;
85 while ((l=it.current())) { 131 while ((l=it.current())) {
86 ++it; 132 ++it;
87 //qDebug("%p: hidden (should remove)",l); 133 //qDebug("%p: hidden (should remove)",l);
88 } 134 }
89#endif 135#endif
90 } 136 }
91
92 void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; }
93 137
94 QPixmap* busyPixmap() const { return (QPixmap*)&bpm[abs(busystate)]; }
95 QIconViewItem* busyItem() const { return bsy; } 138 QIconViewItem* busyItem() const { return bsy; }
96 void setBigIcons( bool bi ) { bigIcns = bi; } 139#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
140 QPixmap busyPixmap() const { return busyPix; }
141#endif
142 void setBigIcons( bool bi ) {
143 bigIcns = bi;
144#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
145 busyPix.resize(0,0);
146#endif
147 }
97 148
98 void updateCategoriesAndMimeTypes(); 149 void updateCategoriesAndMimeTypes();
99 150
100 void doAutoScroll() 151 void doAutoScroll()
101 { 152 {
102 // We don't want rubberbanding (yet) 153 // We don't want rubberbanding (yet)
103 } 154 }
104 155
105 void setBusy(bool on) 156 void setBusy(bool on)
106 { 157 {
107 QIconViewItem *c = on ? currentItem() : 0; 158#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
108 159 if ( busyPix.isNull() ) {
109 if ( bsy != c ) { 160 int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize();
110 QIconViewItem *oldbsy = bsy; 161 busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) );
111 bsy = c; 162 }
112 163#endif
113 if ( oldbsy )
114 oldbsy-> repaint ( );
115
116 if ( busytimer ) {
117 killTimer ( busytimer );
118 busytimer = 0;
119 }
120
121 if ( bsy ) {
122 QPixmap *src = bsy-> QIconViewItem::pixmap();
123 for ( int i = 0; i <= 5; i++ ) {
124 QImage img = src->convertToImage();
125 QRgb* rgb;
126 int count;
127 if ( img.depth() == 32 ) {
128 rgb = (QRgb*)img.bits();
129 count = img.bytesPerLine()/sizeof(QRgb)*img.height();
130 } else {
131 rgb = img.colorTable();
132 count = img.numColors();
133 }
134 int rc, gc, bc;
135 int bs = abs ( i * 10 ) + 25;
136 colorGroup().highlight().rgb( &rc, &gc, &bc );
137 rc = rc * bs / 100;
138 gc = gc * bs / 100;
139 bc = bc * bs / 100;
140
141 for ( int r = 0; r < count; r++, rgb++ ) {
142 int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100;
143 int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100;
144 int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100;
145 int ai = qAlpha ( *rgb );
146 *rgb = qRgba ( ri, gi, bi, ai );
147 }
148 164
149 bpm [i].convertFromImage( img ); 165 if ( on ) {
150 } 166 busyTimer = startTimer( 100 );
151 167 } else {
152 if ( busyType == BIT_Blinking ) { 168 if ( busyTimer ) {
153 busystate = 0; 169 killTimer( busyTimer );
154 busytimer = startTimer ( 200 ); 170 busyTimer = 0;
155 }
156 else {
157 busystate = 3;
158 }
159 timerEvent ( 0 );
160 } 171 }
161 } 172 }
162 }
163 173
164 virtual void timerEvent ( QTimerEvent *te ) 174 LauncherItem *c = on ? (LauncherItem*)currentItem() : 0;
165 { 175
166 if ( !te || ( te-> timerId ( ) == busytimer )) { 176 if ( bsy != c ) {
167 if ( bsy ) { 177 LauncherItem *oldBusy = bsy;
168 busystate++; 178 bsy = c;
169 if ( busystate > 5 ) 179 if ( oldBusy )
170 busystate = -4; 180 oldBusy->resetIcon();
171 181 if ( bsy )
172 QScrollView::updateContents ( bsy-> pixmapRect ( false )); 182 bsy->animateIcon();
173 }
174 } 183 }
175 } 184 }
176 185
177 bool inKeyEvent() const { return ike; } 186 bool inKeyEvent() const { return ike; }
178 void keyPressEvent(QKeyEvent* e) 187 void keyPressEvent(QKeyEvent* e)
179 { 188 {
180 ike = TRUE; 189 ike = TRUE;
181 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) 190 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) {
182 returnPressed(currentItem()); 191 if ( (e->state() & ShiftButton) )
192 emit mouseButtonPressed(ShiftButton, currentItem(), QPoint() );
193 else
194 returnPressed(currentItem());
195 }
196
183 QIconView::keyPressEvent(e); 197 QIconView::keyPressEvent(e);
184 ike = FALSE; 198 ike = FALSE;
185 } 199 }
186 200
187 void addItem(AppLnk* app, bool resort=TRUE); 201 void addItem(AppLnk* app, bool resort=TRUE);
188 bool removeLink(const QString& linkfile); 202 bool removeLink(const QString& linkfile);
189 203
190 QStringList mimeTypes() const; 204 QStringList mimeTypes() const;
191 QStringList categories() const; 205 QStringList categories() const;
192 206
193 void clear() 207 void clear()
194 { 208 {
195 mimes.clear(); 209 mimes.clear();
196 cats.clear(); 210 cats.clear();
197 QIconView::clear(); 211 QIconView::clear();
198 hidden.clear(); 212 hidden.clear();
199 } 213 }
200 214
201 void addCatsAndMimes(AppLnk* app) 215 void addCatsAndMimes(AppLnk* app)
202 { 216 {
203 // QStringList c = app->categories(); 217 // QStringList c = app->categories();
204 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { 218 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
205 // cats.replace(*cit,(void*)1); 219 // cats.replace(*cit,(void*)1);
206 // } 220 // }
207 QString maj=app->type(); 221 QString maj=app->type();
208 int sl=maj.find('/'); 222 int sl=maj.find('/');
209 if (sl>=0) { 223 if (sl>=0) {
210 QString k; 224 QString k;
211 k = maj.left(12) == "application/" ? maj : maj.left(sl); 225 k = maj.left(12) == "application/" ? maj : maj.left(sl);
212 mimes.replace(k,(void*)1); 226 mimes.replace(k,(void*)1);
213 } 227 }
214 } 228 }
215 229
230 void setBackgroundOrigin( QWidget::BackgroundOrigin ) {
231 }
232
216 void setBackgroundPixmap( const QPixmap &pm ) { 233 void setBackgroundPixmap( const QPixmap &pm ) {
217 if ( pm. isNull ( )) { 234 bgPixmap = pm;
218 bgPixmap = pm;
219 }
220 else {
221 // This is need for bg images with alpha channel
222
223 QPixmap tmp ( pm. size ( ), pm. depth ( ));
224
225 QPainter p ( &tmp );
226 p. fillRect ( 0, 0, pm. width ( ), pm. height ( ), bgColor. isValid ( ) ? bgColor : white );
227 p. drawPixmap ( 0, 0, pm );
228 p. end ( );
229
230 bgPixmap = tmp;
231 }
232 } 235 }
233 236
234 void setBackgroundColor( const QColor &c ) { 237 void setBackgroundColor( const QColor &c ) {
235 bgColor = c; 238 bgColor = c;
236 } 239 }
237 240
238 void drawBackground( QPainter *p, const QRect &r ) 241 void drawBackground( QPainter *p, const QRect &r )
239 { 242 {
240 if ( !bgPixmap.isNull() ) { 243 if ( !bgPixmap.isNull() ) {
241 //p-> fillRect ( r, bgColor ); 244 p->drawTiledPixmap( r, bgPixmap,
242 p->drawTiledPixmap( r, bgPixmap,
243 QPoint( (r.x() + contentsX()) % bgPixmap.width(), 245 QPoint( (r.x() + contentsX()) % bgPixmap.width(),
244 (r.y() + contentsY()) % bgPixmap.height() ) ); 246 (r.y() + contentsY()) % bgPixmap.height() ) );
245 } else { 247 } else {
246 p->fillRect( r, bgColor ); 248 p->fillRect( r, bgColor );
247 } 249 }
248 } 250 }
249 251
250 void setItemTextPos( ItemTextPos pos ) 252 void setItemTextPos( ItemTextPos pos )
251 { 253 {
252 calculateGrid( pos ); 254 calculateGrid( pos );
253 QIconView::setItemTextPos( pos ); 255 QIconView::setItemTextPos( pos );
254 } 256 }
255 257
256 void hideOrShowItems(bool resort); 258 void hideOrShowItems(bool resort);
257 259
258 void setTypeFilter(const QString& typefilter, bool resort) 260 void setTypeFilter(const QString& typefilter, bool resort)
259 { 261 {
260 tf = QRegExp(typefilter,FALSE,TRUE); 262 tf = QRegExp(typefilter,FALSE,TRUE);
261 hideOrShowItems(resort); 263 hideOrShowItems(resort);
262 } 264 }
263 265
264 void setCategoryFilter( int catfilter, bool resort ) 266 void setCategoryFilter( int catfilter, bool resort )
265 { 267 {
266 Categories cat; 268 Categories cat;
267 cat.load( categoryFileName() ); 269 cat.load( categoryFileName() );
268 QString str; 270 QString str;
269 if ( catfilter == -2 ) 271 if ( catfilter == -2 )
270 cf = 0; 272 cf = 0;
271 else 273 else
272 cf = catfilter; 274 cf = catfilter;
273 hideOrShowItems(resort); 275 hideOrShowItems(resort);
274 } 276 }
275 277
276 enum SortMethod { Name, Date, Type }; 278 enum SortMethod { Name, Date, Type };
277 279
278 void setSortMethod( SortMethod m ) 280 void setSortMethod( SortMethod m )
279 { 281 {
280 if ( sortmeth != m ) { 282 if ( sortmeth != m ) {
281 sortmeth = m; 283 sortmeth = m;
282 sort(); 284 sort();
283 } 285 }
284 } 286 }
285 287
286 int compare(const AppLnk* a, const AppLnk* b) 288 int compare(const AppLnk* a, const AppLnk* b)
287 { 289 {
288 switch (sortmeth) { 290 switch (sortmeth) {
289 case Name: 291 case Name:
290 return a->name().compare(b->name()); 292 return a->name().lower().compare(b->name().lower());
291 case Date: { 293 case Date: {
292 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); 294 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file());
293 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); 295 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file());
294 return fa.lastModified().secsTo(fb.lastModified()); 296 return fa.lastModified().secsTo(fb.lastModified());
295 } 297 }
296 case Type: 298 case Type:
297 return a->type().compare(b->type()); 299 return a->type().compare(b->type());
298 } 300 }
299 return 0; 301 return 0;
300 } 302 }
301 303
302 QString getAllDocLinkInfo() const;
303
304protected: 304protected:
305 305
306 void timerEvent( QTimerEvent *te )
307 {
308 if ( te->timerId() == busyTimer ) {
309 if ( bsy )
310 bsy->animateIcon();
311 } else {
312 QIconView::timerEvent( te );
313 }
314 }
315
306 void styleChange( QStyle &old ) 316 void styleChange( QStyle &old )
307 { 317 {
308 QIconView::styleChange( old ); 318 QIconView::styleChange( old );
309 calculateGrid( itemTextPos() ); 319 calculateGrid( itemTextPos() );
310 } 320 }
311 321
312 void calculateGrid( ItemTextPos pos ) 322 void calculateGrid( ItemTextPos pos )
313 { 323 {
314 int dw = QApplication::desktop()->width(); 324 int dw = QApplication::desktop()->width();
315 int viewerWidth = dw-style().scrollBarExtent().width(); 325 int viewerWidth = dw-style().scrollBarExtent().width();
316 if ( pos == Bottom ) { 326 if ( pos == Bottom ) {
317 int cols = 3; 327 int cols = 3;
318 if ( viewerWidth <= 200 ) 328 if ( viewerWidth <= 200 )
319 cols = 2; 329 cols = 2;
320 else if ( viewerWidth >= 400 ) 330 else if ( viewerWidth >= 400 )
321 cols = viewerWidth/96; 331 cols = viewerWidth/96;
322 setSpacing( 4 ); 332 setSpacing( 4 );
323 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 333 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
324 setGridY( fontMetrics().height()*2+24 ); 334 setGridY( fontMetrics().height()*2+24 );
325 } else { 335 } else {
326 int cols = 2; 336 int cols = 2;
327 if ( viewerWidth < 150 ) 337 if ( viewerWidth < 150 )
328 cols = 1; 338 cols = 1;
329 else if ( viewerWidth >= 400 ) 339 else if ( viewerWidth >= 400 )
330 cols = viewerWidth/150; 340 cols = viewerWidth/150;
331 setSpacing( 2 ); 341 setSpacing( 2 );
332 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 342 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
333 setGridY( fontMetrics().height()+2 ); 343 setGridY( fontMetrics().height()+2 );
334 } 344 }
335 } 345 }
336 346
347 void focusInEvent( QFocusEvent * ) {}
348 void focusOutEvent( QFocusEvent * ) {}
337 349
338 // flicker free redrawing of busy indicator
339 // code was taken from QScrollView::viewportPaintEvent
340 void viewportPaintEvent( QPaintEvent* pe )
341 {
342 static QPixmap *pix = new QPixmap ( );
343
344 QWidget* vp = viewport();
345
346 if ( vp-> size ( ) != pix-> size ( ))
347 pix-> resize ( vp-> size ( ));
348
349 QPainter p(pix, vp);
350 QRect r = pe->rect();
351 if ( clipper ( ) != vp ) {
352 QRect rr(
353 -vp->x(), -vp->y(),
354 clipper()->width(), clipper()->height()
355 );
356 r &= rr;
357 if ( r.isValid() ) {
358 int ex = r.x() + vp->x() + contentsX();
359 int ey = r.y() + vp->y() + contentsY();
360 int ew = r.width();
361 int eh = r.height();
362 drawContentsOffset(&p,
363 contentsX()+vp->x(),
364 contentsY()+vp->y(),
365 ex, ey, ew, eh);
366 }
367 } else {
368 r &= clipper()->rect();
369 int ex = r.x() + contentsX();
370 int ey = r.y() + contentsY();
371 int ew = r.width();
372 int eh = r.height();
373 drawContentsOffset(&p, contentsX(), contentsY(), ex, ey, ew, eh);
374 }
375 bitBlt ( vp, r.topLeft(), pix, r );
376 }
377
378private: 350private:
379 QList<AppLnk> hidden; 351 QList<AppLnk> hidden;
380 QDict<void> mimes; 352 QDict<void> mimes;
381 QDict<void> cats; 353 QDict<void> cats;
382 SortMethod sortmeth; 354 SortMethod sortmeth;
383 QRegExp tf; 355 QRegExp tf;
384 int cf; 356 int cf;
385 QIconViewItem* bsy; 357 LauncherItem* bsy;
358 int busyTimer;
386 bool ike; 359 bool ike;
387 bool bigIcns; 360 bool bigIcns;
388 QPixmap bgPixmap; 361 QPixmap bgPixmap;
389 QPixmap bpm [6];
390 QColor bgColor; 362 QColor bgColor;
391 int busytimer; 363#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
392 int busystate; 364 QPixmap busyPix;
393 BusyIndicatorType busyType; 365#endif
394}; 366};
395 367
396 368
397bool LauncherView::bsy=FALSE; 369bool LauncherView::bsy=FALSE;
398 370
399void LauncherView::setBusy(bool on) 371void LauncherView::setBusy(bool on)
400{ 372{
401 icons->setBusy(on); 373 icons->setBusy(on);
402} 374}
403 375
404class LauncherItem : public QIconViewItem 376void LauncherView::setBusyIndicatorType( const QString& type ) {
377 /* ### FIXME */
378}
379
380LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon )
381 : QIconViewItem( parent, applnk->name(),
382 bigIcon ? applnk->bigPixmap() :applnk->pixmap() ),
383 isBigIcon( bigIcon ),
384 iteration(0),
385 app(applnk) // Takes ownership
405{ 386{
406public: 387}
407 LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE );
408 ~LauncherItem()
409 {
410 LauncherIconView* liv = (LauncherIconView*)iconView();
411 if ( liv->busyItem() == this )
412 liv->setBusy(FALSE);
413 delete app;
414 }
415 388
416 AppLnk* appLnk() const { return app; } 389LauncherItem::~LauncherItem()
417 AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; } 390{
391 LauncherIconView* liv = (LauncherIconView*)iconView();
392 if ( liv->busyItem() == this )
393 liv->setBusy(FALSE);
394 delete app;
395}
418 396
419 virtual int compare ( QIconViewItem * i ) const; 397int LauncherItem::compare ( QIconViewItem * i ) const
398{
399 LauncherIconView* view = (LauncherIconView*)iconView();
400 return view->compare(app,((LauncherItem *)i)->appLnk());
401}
420 402
421 void paintItem( QPainter *p, const QColorGroup &cg ) 403void LauncherItem::paintItem( QPainter *p, const QColorGroup &cg )
422 { 404{
423 LauncherIconView* liv = (LauncherIconView*)iconView(); 405 LauncherIconView* liv = (LauncherIconView*)iconView();
424 QBrush oldBrush( liv->itemTextBackground() ); 406 QBrush oldBrush( liv->itemTextBackground() );
425 QColorGroup mycg( cg ); 407 QColorGroup mycg( cg );
426 if ( liv->currentItem() == this ) { 408 if ( liv->currentItem() == this ) {
427 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); 409 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) );
428 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); 410 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) );
429 }
430 QIconViewItem::paintItem(p,mycg);
431 if ( liv->currentItem() == this )
432 liv->setItemTextBackground( oldBrush );
433 } 411 }
434 412
435 virtual QPixmap* pixmap () const 413 QIconViewItem::paintItem(p,mycg);
436 {
437 const LauncherIconView* liv = (LauncherIconView*)iconView();
438 if ( (const LauncherItem *)liv->busyItem() == this )
439 return liv->busyPixmap();
440 return QIconViewItem::pixmap();
441 }
442 414
443protected: 415 // Paint animation overlay
444 AppLnk* app; 416 if ( liv->busyItem() == this )
445}; 417 paintAnimatedIcon(p);
446 418
419 if ( liv->currentItem() == this )
420 liv->setItemTextBackground( oldBrush );
421}
447 422
448LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) 423void LauncherItem::paintAnimatedIcon( QPainter *p )
449 : QIconViewItem( parent, applnk->name(),
450 bigIcon ? applnk->bigPixmap() :applnk->pixmap() ),
451 app(applnk) // Takes ownership
452{ 424{
425 LauncherIconView* liv = (LauncherIconView*)iconView();
426 int pic = iteration % 16;
427 int w = pixmap()->width(), h = pixmap()->height();
428 QPixmap dblBuf( w, h + 4 );
429 QPainter p2( &dblBuf );
430 int x1, y1;
431 if ( liv->itemTextPos() == QIconView::Bottom ) {
432 x1 = x() + (width() - w) / 2 - liv->contentsX();
433 y1 = y() - liv->contentsY();
434 } else {
435 x1 = x() - liv->contentsX();
436 y1 = y() + (height() - h) / 2 - liv->contentsY();
437 }
438 y1 -= 2;
439 p2.translate(-x1,-y1);
440 liv->drawBackground( &p2, QRect(x1,y1,w,h+4) );
441 int bounceY = 2;
442#ifdef BOUNCE_BUSY_ICON
443 bounceY = 4 - ((iteration+2)%8);
444 bounceY = bounceY < 0 ? -bounceY : bounceY;
445#endif
446 p2.drawPixmap( x1, y1 + bounceY, *pixmap() );
447#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY
448 p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h );
449#endif
450 p->drawPixmap( x1, y1, dblBuf );
453} 451}
454 452
455int LauncherItem::compare ( QIconViewItem * i ) const 453void LauncherItem::animateIcon()
456{ 454{
457 LauncherIconView* view = (LauncherIconView*)iconView(); 455 LauncherIconView* liv = (LauncherIconView*)iconView();
458 return view->compare(app,((LauncherItem *)i)->appLnk()); 456
457 if ( liv->busyItem() != this || !app )
458 return;
459
460 // Highlight the icon
461 if ( iteration == 0 ) {
462 QPixmap src = isBigIcon ? app->bigPixmap() : app->pixmap();
463 QImage img = src.convertToImage();
464 QRgb *rgb;
465 int count;
466 if ( img.depth() == 32 ) {
467 rgb = (QRgb*)img.bits();
468 count = img.bytesPerLine()/sizeof(QRgb)*img.height();
469 } else {
470 rgb = img.colorTable();
471 count = img.numColors();
472 }
473 for ( int r = 0; r < count; r++, rgb++ ) {
474#if defined(BRIGHTEN_BUSY_ICON)
475 QColor c(*rgb);
476 int h, s, v;
477 c.hsv(&h,&s,&v);
478 c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255));
479 *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb));
480#elif defined(ALPHA_FADE_BUSY_ICON)
481 *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2);
482#endif
483 }
484 src.convertFromImage( img );
485 setPixmap( src );
486 }
487
488 iteration++;
489
490 // Paint animation overlay
491 QPainter p( liv->viewport() );
492 paintAnimatedIcon( &p );
493}
494
495void LauncherItem::resetIcon()
496{
497 iteration = 0;
498 setPixmap( isBigIcon ? app->bigPixmap() : app->pixmap() );
459} 499}
460 500
501//===========================================================================
502
461QStringList LauncherIconView::mimeTypes() const 503QStringList LauncherIconView::mimeTypes() const
462{ 504{
463 QStringList r; 505 QStringList r;
464 QDictIterator<void> it(mimes); 506 QDictIterator<void> it(mimes);
465 while (it.current()) { 507 while (it.current()) {
466 r.append(it.currentKey()); 508 r.append(it.currentKey());
467 ++it; 509 ++it;
468 } 510 }
469 r.sort(); 511 r.sort();
470 return r; 512 return r;
471} 513}
472 514
473void LauncherIconView::addItem(AppLnk* app, bool resort) 515void LauncherIconView::addItem(AppLnk* app, bool resort)
474{ 516{
475 addCatsAndMimes(app); 517 addCatsAndMimes(app);
476 518
477 if ( (tf.isEmpty() || tf.match(app->type()) >= 0) 519 if ( (tf.isEmpty() || tf.match(app->type()) >= 0)
478 && (cf == 0 || app->categories().contains(cf) 520 && (cf == 0 || app->categories().contains(cf)
479 || cf == -1 && app->categories().count() == 0 ) ) 521 || cf == -1 && app->categories().count() == 0 ) )
480 (void) new LauncherItem( this, app, bigIcns ); 522 (void) new LauncherItem( this, app, bigIcns );
481 else 523 else
482 hidden.append(app); 524 hidden.append(app);
483 if ( resort ) 525 if ( resort )
484 sort(); 526 sort();
485} 527}
486 528
487void LauncherIconView::updateCategoriesAndMimeTypes() 529void LauncherIconView::updateCategoriesAndMimeTypes()
488{ 530{
489 mimes.clear(); 531 mimes.clear();
490 cats.clear(); 532 cats.clear();
491 LauncherItem* item = (LauncherItem*)firstItem(); 533 LauncherItem* item = (LauncherItem*)firstItem();
492 while (item) { 534 while (item) {
493 addCatsAndMimes(item->appLnk()); 535 addCatsAndMimes(item->appLnk());
494 item = (LauncherItem*)item->nextItem(); 536 item = (LauncherItem*)item->nextItem();
495 } 537 }
496 QListIterator<AppLnk> it(hidden); 538 QListIterator<AppLnk> it(hidden);
497 AppLnk* l; 539 AppLnk* l;
498 while ((l=it.current())) { 540 while ((l=it.current())) {
499 addCatsAndMimes(l); 541 addCatsAndMimes(l);
500 ++it; 542 ++it;
501 } 543 }
502} 544}
503 545
504void LauncherIconView::hideOrShowItems(bool resort) 546void LauncherIconView::hideOrShowItems(bool resort)
505{ 547{
548 viewport()->setUpdatesEnabled( FALSE );
506 hidden.setAutoDelete(FALSE); 549 hidden.setAutoDelete(FALSE);
507 QList<AppLnk> links=hidden; 550 QList<AppLnk> links=hidden;
508 hidden.clear(); 551 hidden.clear();
509 hidden.setAutoDelete(TRUE); 552 hidden.setAutoDelete(TRUE);
510 LauncherItem* item = (LauncherItem*)firstItem(); 553 LauncherItem* item = (LauncherItem*)firstItem();
511 while (item) { 554 while (item) {
512 links.append(item->takeAppLnk()); 555 links.append(item->takeAppLnk());
513 item = (LauncherItem*)item->nextItem(); 556 item = (LauncherItem*)item->nextItem();
514 } 557 }
515 viewport()->setUpdatesEnabled( FALSE );
516 clear(); 558 clear();
517 QListIterator<AppLnk> it(links); 559 QListIterator<AppLnk> it(links);
518 AppLnk* l; 560 AppLnk* l;
519 while ((l=it.current())) { 561 while ((l=it.current())) {
520 addItem(l,FALSE); 562 addItem(l,FALSE);
521 ++it; 563 ++it;
522 } 564 }
523 viewport()->setUpdatesEnabled( TRUE );
524 if ( resort && !autoArrange() ) 565 if ( resort && !autoArrange() )
525 sort(); 566 sort();
567 viewport()->setUpdatesEnabled( TRUE );
526} 568}
527 569
528bool LauncherIconView::removeLink(const QString& linkfile) 570bool LauncherIconView::removeLink(const QString& linkfile)
529{ 571{
530 LauncherItem* item = (LauncherItem*)firstItem(); 572 LauncherItem* item = (LauncherItem*)firstItem();
531 AppLnk* l; 573 AppLnk* l;
532 bool did = FALSE; 574 bool did = FALSE;
533 DocLnk dl(linkfile); 575 DocLnk dl(linkfile);
534 while (item) { 576 while (item) {
535 l = item->appLnk(); 577 l = item->appLnk();
536 if ( ( l->linkFileKnown() && ( l->linkFile() == linkfile )) 578 LauncherItem *nextItem = (LauncherItem *)item->nextItem();
537 || ( l->fileKnown() && ( l->file() == linkfile )) 579 if ( l->linkFileKnown() && l->linkFile() == linkfile
538 || ( dl.fileKnown() && l->fileKnown() && ( dl.file() == l->file() )) ) { 580 || l->fileKnown() && (
581 l->file() == linkfile
582 || dl.isValid() && dl.file() == l->file() ) ) {
539 delete item; 583 delete item;
540 did = TRUE; 584 did = TRUE;
541 } 585 }
542 item = (LauncherItem*)item->nextItem(); 586 item = nextItem;
543 } 587 }
544 QListIterator<AppLnk> it(hidden); 588 QListIterator<AppLnk> it(hidden);
545 while ((l=it.current())) { 589 while ((l=it.current())) {
546 ++it; 590 ++it;
547 if ( ( l->linkFileKnown() && ( l->linkFile() == linkfile )) 591 if ( l->linkFileKnown() && l->linkFile() == linkfile
548 || ( l->file() == linkfile ) 592 || l->file() == linkfile
549 || ( dl.fileKnown() && ( dl.file() == l->file() )) ) { 593 || dl.isValid() && dl.file() == l->file() ) {
550 hidden.removeRef(l); 594 hidden.removeRef(l);
551 did = TRUE; 595 did = TRUE;
552 } 596 }
553 } 597 }
554 return did; 598 return did;
555} 599}
556 600
557static QString docLinkInfo(const Categories& cats, DocLnk* doc)
558{
559 QString contents;
560
561 QFileInfo fi( doc->file() );
562 if ( !fi.exists() )
563 return contents;
564
565 if ( doc->linkFileKnown() ) {
566 QString lfn = doc->linkFile();
567 QFile f( lfn );
568 if ( f.open( IO_ReadOnly ) ) {
569 QTextStream ts( &f );
570 ts.setEncoding( QTextStream::UnicodeUTF8 );
571 contents += ts.read();
572 f.close();
573 goto calcsize;
574 }
575 }
576
577 contents += "[Desktop Entry]\n";
578 contents += "Categories = " // No tr
579 + cats.labels("Document View", doc->categories()).join(";") + "\n"; // No tr
580 contents += "File = "+doc->file()+"\n"; // No tr
581 contents += "Name = "+doc->name()+"\n"; // No tr
582 contents += "Type = "+doc->type()+"\n"; // No tr
583
584calcsize:
585 contents += QString("Size = %1\n").arg( fi.size() ); // No tr
586 return contents;
587}
588
589QString LauncherIconView::getAllDocLinkInfo() const
590{
591 QString contents;
592 LauncherItem* item = (LauncherItem*)firstItem();
593 Categories cats;
594 while (item) {
595 DocLnk* doc = (DocLnk*)item->appLnk();
596 contents += docLinkInfo(cats,doc);
597 item = (LauncherItem*)item->nextItem();
598 }
599 QListIterator<AppLnk> it(hidden);
600 DocLnk* doc;
601 while ((doc=(DocLnk*)it.current())) {
602 contents += docLinkInfo(cats,doc);
603 ++it;
604 }
605 return contents;
606}
607
608//=========================================================================== 601//===========================================================================
609 602
610LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) 603LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl )
611 : QVBox( parent, name, fl ) 604 : QVBox( parent, name, fl )
612{ 605{
606 catmb = 0;
613 icons = new LauncherIconView( this ); 607 icons = new LauncherIconView( this );
614 setFocusProxy(icons); 608 setFocusProxy(icons);
615 QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); 609 QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold );
616 610
617 icons->setItemsMovable( FALSE ); 611 icons->setItemsMovable( FALSE );
618 icons->setAutoArrange( TRUE ); 612 icons->setAutoArrange( TRUE );
619 icons->setSorting( TRUE ); 613 icons->setSorting( TRUE );
620 icons->setFrameStyle( QFrame::NoFrame ); 614 icons->setFrameStyle( QFrame::NoFrame );
621 icons->setMargin( 0 ); 615 icons->setMargin( 0 );
622 icons->setSelectionMode( QIconView::NoSelection ); 616 icons->setSelectionMode( QIconView::NoSelection );
623 icons->setBackgroundMode( PaletteBase ); 617 icons->setBackgroundMode( PaletteBase );
624 icons->setResizeMode( QIconView::Fixed ); 618 icons->setResizeMode( QIconView::Fixed );
625 vmode = (ViewMode)-1; 619 vmode = (ViewMode)-1;
626 setViewMode( Icon ); 620 setViewMode( Icon );
627 621
628 connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)), 622 connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)),
629 SLOT(itemClicked(int, QIconViewItem *)) ); 623 SLOT(itemClicked(int, QIconViewItem *)) );
630 connect( icons, SIGNAL(selectionChanged()), 624 connect( icons, SIGNAL(selectionChanged()),
631 SLOT(selectionChanged()) ); 625 SLOT(selectionChanged()) );
632 connect( icons, SIGNAL(returnPressed(QIconViewItem *)), 626 connect( icons, SIGNAL(returnPressed(QIconViewItem *)),
633 SLOT(returnPressed(QIconViewItem *)) ); 627 SLOT(returnPressed(QIconViewItem *)) );
634 connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)), 628 connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)),
635 SLOT(itemPressed(int, QIconViewItem *)) ); 629 SLOT(itemPressed(int, QIconViewItem *)) );
636 630
637 tools = 0; 631 tools = 0;
638 setBackgroundType( Ruled, QString::null ); 632 setBackgroundType( Ruled, QString::null );
639} 633}
640 634
641LauncherView::~LauncherView() 635LauncherView::~LauncherView()
642{ 636{
637 if ( bgCache && bgCache->contains( bgName ) )
638 (*bgCache)[bgName]->ref--;
639}
640
641void LauncherView::hideIcons()
642{
643 icons->hide();
643} 644}
644 645
645void LauncherView::setToolsEnabled(bool y) 646void LauncherView::setToolsEnabled(bool y)
646{ 647{
647 if ( !y != !tools ) { 648 if ( !y != !tools ) {
648 if ( y ) { 649 if ( y ) {
649 tools = new QHBox(this); 650 tools = new QHBox(this);
650 651
651 // Type filter 652 // Type filter
652 typemb = new QComboBox(tools); 653 typemb = new QComboBox(tools);
654 QSizePolicy p = typemb->sizePolicy();
655 p.setHorData(QSizePolicy::Expanding);
656 typemb->setSizePolicy(p);
653 657
654 // Category filter 658 // Category filter
655 catmb = new CategorySelect(tools);
656
657 updateTools(); 659 updateTools();
658 tools->show(); 660 tools->show();
661
662 // Always show vscrollbar
663 icons->setVScrollBarMode( QScrollView::AlwaysOn );
659 } else { 664 } else {
660 delete tools; 665 delete tools;
661 tools = 0; 666 tools = 0;
662 } 667 }
663 } 668 }
664} 669}
665 670
666void LauncherView::updateTools() 671void LauncherView::updateTools()
667{ 672{
668 disconnect( typemb, SIGNAL(activated(int)), 673 disconnect( typemb, SIGNAL(activated(int)),
669 this, SLOT(showType(int)) ); 674 this, SLOT(showType(int)) );
670 disconnect( catmb, SIGNAL(signalSelected(int)), 675 if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)),
671 this, SLOT(showCategory(int)) ); 676 this, SLOT(showCategory(int)) );
672 677
678 // ### I want to remove this
673 icons->updateCategoriesAndMimeTypes(); 679 icons->updateCategoriesAndMimeTypes();
674 680
675 QString prev; 681 QString prev;
676 682
677 // Type filter 683 // Type filter
678 QStringList types; 684 QStringList types;
679 typelist = icons->mimeTypes(); 685 typelist = icons->mimeTypes();
680 for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { 686 for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) {
681 QString t = *it; 687 QString t = *it;
682 if ( t.left(12) == "application/" ) { 688 if ( t.left(12) == "application/" ) {
683 MimeType mt(t); 689 MimeType mt(t);
684 const AppLnk* app = mt.application(); 690 const AppLnk* app = mt.application();
685 if ( app ) 691 if ( app )
686 t = app->name(); 692 t = app->name();
687 else 693 else
688 t = t.mid(12); 694 t = t.mid(12);
689 } else { 695 } else {
690 t[0] = t[0].upper(); 696 t[0] = t[0].upper();
691 } 697 }
692 types += tr("%1 files").arg(t); 698 types += t;
693 } 699 }
694 types << tr("All types of file"); 700 types << tr("All types");
695 prev = typemb->currentText(); 701 prev = typemb->currentText();
696 typemb->clear(); 702 typemb->clear();
697 typemb->insertStringList(types); 703 typemb->insertStringList(types);
698 for (int i=0; i<typemb->count(); i++) { 704 for (int i=0; i<typemb->count(); i++) {
699 if ( typemb->text(i) == prev ) { 705 if ( typemb->text(i) == prev ) {
700 typemb->setCurrentItem(i); 706 typemb->setCurrentItem(i);
701 break; 707 break;
702 } 708 }
703 } 709 }
704 if ( prev.isNull() ) 710 if ( prev.isNull() )
705 typemb->setCurrentItem(typemb->count()-1); 711 typemb->setCurrentItem(typemb->count()-1);
706 712
713 int pcat = catmb ? catmb->currentCategory() : -2;
714 if ( !catmb )
715 catmb = new CategorySelect(tools);
707 Categories cats( 0 ); 716 Categories cats( 0 );
708 cats.load( categoryFileName() ); 717 cats.load( categoryFileName() );
709 QArray<int> vl( 0 ); 718 QArray<int> vl( 0 );
710 catmb->setCategories( vl, "Document View", // No tr 719 catmb->setCategories( vl, "Document View", // No tr
711 tr("Document View") ); 720 tr("Document View") );
712 catmb->setRemoveCategoryEdit( TRUE ); 721 catmb->setRemoveCategoryEdit( TRUE );
713 catmb->setAllCategories( TRUE ); 722 catmb->setAllCategories( TRUE );
723 catmb->setCurrentCategory(pcat);
724
725 // if type has changed we need to redisplay
726 if ( typemb->currentText() != prev )
727 showType( typemb->currentItem() );
714 728
715 connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); 729 connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int)));
716 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); 730 connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)));
717} 731}
718 732
719void LauncherView::sortBy(int s) 733void LauncherView::sortBy(int s)
720{ 734{
721 icons->setSortMethod((LauncherIconView::SortMethod)s); 735 icons->setSortMethod((LauncherIconView::SortMethod)s);
722} 736}
723 737
724void LauncherView::showType(int t) 738void LauncherView::showType(int t)
725{ 739{
726 if ( t >= (int)typelist.count() ) { 740 if ( t >= (int)typelist.count() ) {
727 icons->setTypeFilter("",TRUE); 741 icons->setTypeFilter("",TRUE);
728 } else { 742 } else {
729 QString ty = typelist[t]; 743 QString ty = typelist[t];
730 if ( !ty.contains('/') ) 744 if ( !ty.contains('/') )
731 ty += "/*"; 745 ty += "/*";
732 icons->setTypeFilter(ty,TRUE); 746 icons->setTypeFilter(ty,TRUE);
733 } 747 }
734} 748}
735 749
736void LauncherView::showCategory( int c ) 750void LauncherView::showCategory( int c )
737{ 751{
738 icons->setCategoryFilter( c, TRUE ); 752 icons->setCategoryFilter( c, TRUE );
739} 753}
740 754
741void LauncherView::setViewMode( ViewMode m ) 755void LauncherView::setViewMode( ViewMode m )
742{ 756{
743 if ( vmode != m ) { 757 if ( vmode != m ) {
744 bool bigIcons = m == Icon; 758 bool bigIcons = m == Icon;
745 icons->viewport()->setUpdatesEnabled( FALSE ); 759 icons->viewport()->setUpdatesEnabled( FALSE );
746 icons->setBigIcons( bigIcons ); 760 icons->setBigIcons( bigIcons );
747 switch ( m ) { 761 switch ( m ) {
748 case List: 762 case List:
749 icons->setItemTextPos( QIconView::Right ); 763 icons->setItemTextPos( QIconView::Right );
750 break; 764 break;
751 case Icon: 765 case Icon:
752 icons->setItemTextPos( QIconView::Bottom ); 766 icons->setItemTextPos( QIconView::Bottom );
753 break; 767 break;
754 } 768 }
755 icons->hideOrShowItems( FALSE ); 769 icons->hideOrShowItems( FALSE );
756 icons->viewport()->setUpdatesEnabled( TRUE ); 770 icons->viewport()->setUpdatesEnabled( TRUE );
757 vmode = m; 771 vmode = m;
758 } 772 }
759} 773}
760 774
775//
776// User images may require scaling.
777//
778QImage LauncherView::loadBackgroundImage(QString &bgName)
779{
780 QImageIO imgio;
781 QSize ds = qApp->desktop()->size(); // should be launcher, not desktop
782 bool further_scaling = TRUE;
783
784 imgio.setFileName( bgName );
785 imgio.setParameters("GetHeaderInformation");
786
787 if (imgio.read() == FALSE) {
788 return imgio.image();
789 }
790
791 if (imgio.image().width() < ds.width() &&
792 imgio.image().height() < ds.height()) {
793 further_scaling = FALSE;
794 }
795
796 if (!imgio.image().bits()) {
797 //
798 // Scale and load. Note we don't scale up.
799 //
800 QString param( "Scale( %1, %2, ScaleMin )" ); // No tr
801 imgio.setParameters(further_scaling ?
802 param.arg(ds.width()).arg(ds.height()).latin1() :
803 "");
804 imgio.read();
805 } else {
806 if (further_scaling) {
807 intt1 = imgio.image().width() * ds.height();
808 int t2 = imgio.image().height() * ds.width();
809 int dsth = ds.height();
810 int dstw = ds.width();
811
812 if (t1 > t2) {
813 dsth = t2 / imgio.image().width();
814 } else {
815 dstw = t1 / imgio.image().height();
816 }
817
818 //
819 // Loader didn't scale for us. Do it manually.
820 //
821 return imgio.image().smoothScale(dstw, dsth);
822 }
823 }
824
825 return imgio.image();
826}
827
761void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) 828void LauncherView::setBackgroundType( BackgroundType t, const QString &val )
762{ 829{
763 if ( !bgCache ) 830 if ( !bgCache ) {
764 bgCache = new QMap<QString,BgPixmap*>; 831 bgCache = new QMap<QString,BgPixmap*>;
832 qAddPostRoutine( cleanup_cache );
833 }
834
765 if ( bgCache->contains( bgName ) ) 835 if ( bgCache->contains( bgName ) )
766 (*bgCache)[bgName]->ref--; 836 (*bgCache)[bgName]->ref--;
837 bgName = "";
838
839 QPixmap bg;
767 840
768 switch ( t ) { 841 switch ( t ) {
769 case Ruled: { 842 case Ruled: {
770 bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr 843 bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr
771 QPixmap bg;
772 if ( bgCache->contains( bgName ) ) { 844 if ( bgCache->contains( bgName ) ) {
773 (*bgCache)[bgName]->ref++; 845 (*bgCache)[bgName]->ref++;
774 bg = (*bgCache)[bgName]->pm; 846 bg = (*bgCache)[bgName]->pm;
775 } else { 847 } else {
776 bg.resize( width(), 9 ); 848 bg.resize( width(), 9 );
777 QPainter painter( &bg ); 849 QPainter painter( &bg );
778 for ( int i = 0; i < 3; i++ ) { 850 for ( int i = 0; i < 3; i++ ) {
779 painter.setPen( white ); 851 painter.setPen( white );
780 painter.drawLine( 0, i*3, width()-1, i*3 ); 852 painter.drawLine( 0, i*3, width()-1, i*3 );
781 painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); 853 painter.drawLine( 0, i*3+1, width()-1, i*3+1 );
782 painter.setPen( colorGroup().background().light(105) ); 854 painter.setPen( colorGroup().background().light(105) );
783 painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); 855 painter.drawLine( 0, i*3+2, width()-1, i*3+2 );
784 } 856 }
785 painter.end(); 857 painter.end();
786 bgCache->insert( bgName, new BgPixmap(bg) ); 858 bgCache->insert( bgName, new BgPixmap(bg) );
787 } 859 }
788 icons->setBackgroundPixmap( bg );
789 break; 860 break;
790 } 861 }
791 862
792 case SolidColor:
793 icons->setBackgroundPixmap( QPixmap() );
794 if ( val.isEmpty() ) {
795 icons->setBackgroundColor( colorGroup().base() );
796 } else {
797 icons->setBackgroundColor( val );
798 }
799 bgName = "";
800 break;
801
802 case Image: 863 case Image:
803 bgName = val; 864 if (!val.isEmpty()) {
804 if ( bgCache->contains( bgName ) ) { 865 bgName = val;
805 (*bgCache)[bgName]->ref++; 866 if ( bgCache->contains( bgName ) ) {
806 icons->setBackgroundPixmap( (*bgCache)[bgName]->pm ); 867 (*bgCache)[bgName]->ref++;
807 } else { 868 bg = (*bgCache)[bgName]->pm;
808 QPixmap bg( Resource::loadPixmap( val ) ); 869 } else {
809 if ( bg.isNull() ) { 870 QString imgFile = bgName;
810 QImageIO imgio; 871 bool tile = FALSE;
811 imgio.setFileName( bgName ); 872 if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) {
812 QSize ds = qApp->desktop()->size(); 873 imgFile = Resource::findPixmap( imgFile );
813 QString param( "Scale( %1, %2, ScaleMin )" ); // No tr 874 tile = TRUE;
814 imgio.setParameters( param.arg(ds.width()).arg(ds.height()).latin1() ); 875 }
815 imgio.read(); 876 QImage img = loadBackgroundImage(imgFile);
816 bg = imgio.image(); 877
878
879 if ( img.depth() == 1 )
880 img = img.convertDepth(8);
881 img.setAlphaBuffer(FALSE);
882 bg.convertFromImage(img);
883 bgCache->insert( bgName, new BgPixmap(bg) );
817 } 884 }
818 bgCache->insert( bgName, new BgPixmap(bg) );
819 icons->setBackgroundPixmap( bg );
820 } 885 }
821 break; 886 break;
887
888 case SolidColor:
889 default:
890 break;
822 } 891 }
823 892
824 // remove unreferenced backgrounds. 893 const QObjectList *list = queryList( "QWidget", 0, FALSE );
825 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); 894 QObject *obj;
826 while ( it != bgCache->end() ) { 895 for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) {
827 QMap<QString,BgPixmap*>::Iterator curr = it; 896 if ( obj->isWidgetType() ) {
828 ++it; 897 QWidget *w = (QWidget*)obj;
829 if ( (*curr)->ref == 0 ) { 898 w->setBackgroundPixmap( bg );
830 delete (*curr); 899 if ( bgName.isEmpty() ) {
831 bgCache->remove( curr ); 900 // Solid Color
901 if ( val.isEmpty() )
902 w->setBackgroundColor( colorGroup().base() );
903 else
904 w->setBackgroundColor( val );
905 } else {
906 // Ruled or Image pixmap
907 w->setBackgroundOrigin( ParentOrigin );
908 }
832 } 909 }
833 } 910 }
911 delete list;
834 912
835 bgType = t; 913 bgType = t;
836 icons->viewport()->update(); 914 icons->viewport()->update();
915
916 QTimer::singleShot( 1000, this, SLOT(flushBgCache()) );
837} 917}
838 918
839void LauncherView::setTextColor( const QColor &tc ) 919void LauncherView::setTextColor( const QColor &tc )
840{ 920{
841 textCol = tc; 921 textCol = tc;
842 QColorGroup cg = icons->colorGroup(); 922 QColorGroup cg = icons->colorGroup();
843 cg.setColor( QColorGroup::Text, tc ); 923 cg.setColor( QColorGroup::Text, tc );
844 icons->setPalette( QPalette(cg,cg,cg) ); 924 icons->setPalette( QPalette(cg,cg,cg) );
845 icons->viewport()->update(); 925 icons->viewport()->update();
846} 926}
847 927
848void LauncherView::setViewFont( const QFont &f ) 928void LauncherView::setViewFont( const QFont &f )
849{ 929{
850 icons->setFont( f ); 930 icons->setFont( f );
931 icons->hideOrShowItems( FALSE );
851} 932}
852 933
853void LauncherView::unsetViewFont( ) 934void LauncherView::clearViewFont()
854{ 935{
855 icons->unsetFont( ); 936 icons->unsetFont();
937 icons->hideOrShowItems( FALSE );
856} 938}
857 939
858void LauncherView::resizeEvent(QResizeEvent *e) 940void LauncherView::resizeEvent(QResizeEvent *e)
859{ 941{
860 QVBox::resizeEvent( e ); 942 QVBox::resizeEvent( e );
861 if ( e->size().width() != e->oldSize().width() ) 943 if ( e->size().width() != e->oldSize().width() )
862 sort(); 944 sort();
863} 945}
864 946
865void LauncherView::populate( AppLnkSet *folder, const QString& typefilter )
866{
867 icons->clear();
868 internalPopulate( folder, typefilter );
869}
870
871QString LauncherView::getAllDocLinkInfo() const
872{
873 return icons->getAllDocLinkInfo();
874}
875
876void LauncherView::selectionChanged() 947void LauncherView::selectionChanged()
877{ 948{
878 QIconViewItem* item = icons->currentItem(); 949 QIconViewItem* item = icons->currentItem();
879 if ( item && item->isSelected() ) { 950 if ( item && item->isSelected() ) {
880 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 951 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
881 if ( icons->inKeyEvent() ) // not for mouse press 952 if ( icons->inKeyEvent() ) // not for mouse press
882 emit clicked( appLnk ); 953 emit clicked( appLnk );
883 item->setSelected(FALSE); 954 item->setSelected(FALSE);
884 } 955 }
885} 956}
886 957
887void LauncherView::returnPressed( QIconViewItem *item ) 958void LauncherView::returnPressed( QIconViewItem *item )
888{ 959{
889 if ( item ) { 960 if ( item ) {
890 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 961 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
891 emit clicked( appLnk ); 962 emit clicked( appLnk );
892 } 963 }
893} 964}
894 965
895void LauncherView::itemClicked( int btn, QIconViewItem *item ) 966void LauncherView::itemClicked( int btn, QIconViewItem *item )
896{ 967{
897 if ( item ) { 968 if ( item ) {
898 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 969 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
899 if ( btn == LeftButton ) { 970 if ( btn == LeftButton ) {
900 // Make sure it's the item we execute that gets highlighted 971 // Make sure it's the item we execute that gets highlighted
901 icons->setCurrentItem( item ); 972 icons->setCurrentItem( item );
902 emit clicked( appLnk ); 973 emit clicked( appLnk );
903 } 974 }
904 item->setSelected(FALSE); 975 item->setSelected(FALSE);
905 } 976 }
906} 977}
907 978
908void LauncherView::itemPressed( int btn, QIconViewItem *item ) 979void LauncherView::itemPressed( int btn, QIconViewItem *item )
909{ 980{
910 if ( item ) { 981 if ( item ) {
911 AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); 982 AppLnk *appLnk = ((LauncherItem *)item)->appLnk();
912 if ( btn == RightButton ) 983 if ( btn == RightButton )
913 emit rightPressed( appLnk ); 984 emit rightPressed( appLnk );
914/* 985 else if ( btn == ShiftButton )
915 else if ( btn == LeftButton ) 986 emit rightPressed( appLnk );
916 emit clicked( appLnk );
917*/
918 item->setSelected(FALSE); 987 item->setSelected(FALSE);
919 } 988 }
920} 989}
921 990
922void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter ) 991void LauncherView::removeAllItems()
923{ 992{
924 QListIterator<AppLnk> it( folder->children() ); 993 icons->clear();
925 icons->setTypeFilter(typefilter,FALSE);
926
927 while ( it.current() ) {
928 // show only the icons for existing files
929 if (QFile(it.current()->file()).exists() || ( it.current()->file().left(4) == "http" )) {
930 icons->addItem(*it,FALSE);
931 }
932 else {
933 //maybe insert some .desktop file deletion code later
934 //maybe dir specific
935 }
936 ++it;
937 }
938
939 icons->sort();
940} 994}
941 995
942bool LauncherView::removeLink(const QString& linkfile) 996bool LauncherView::removeLink(const QString& linkfile)
943{ 997{
944 return icons->removeLink(linkfile); 998 return icons->removeLink(linkfile);
945} 999}
946 1000
1001void LauncherView::setSortEnabled( bool v )
1002{
1003 icons->setSorting( v );
1004 if ( v )
1005 sort();
1006}
1007
1008void LauncherView::setUpdatesEnabled( bool u )
1009{
1010 icons->setUpdatesEnabled( u );
1011}
1012
947void LauncherView::sort() 1013void LauncherView::sort()
948{ 1014{
949 icons->sort(); 1015 icons->sort();
950} 1016}
951 1017
952void LauncherView::addItem(AppLnk* app, bool resort) 1018void LauncherView::addItem(AppLnk* app, bool resort)
953{ 1019{
954 icons->addItem(app,resort); 1020 icons->addItem(app,resort);
955} 1021}
956 1022
957void LauncherView::setFileSystems(const QList<FileSystem> &)
958{
959 // ### does nothing now...
960}
961
962void LauncherView::paletteChange( const QPalette &p ) 1023void LauncherView::paletteChange( const QPalette &p )
963{ 1024{
964 icons->unsetPalette(); 1025 icons->unsetPalette();
965 QVBox::paletteChange( p ); 1026 QVBox::paletteChange( p );
966 if ( bgType == Ruled ) 1027 if ( bgType == Ruled )
967 setBackgroundType( Ruled, QString::null ); 1028 setBackgroundType( Ruled, QString::null );
968 QColorGroup cg = icons->colorGroup(); 1029 QColorGroup cg = icons->colorGroup();
969 cg.setColor( QColorGroup::Text, textCol ); 1030 cg.setColor( QColorGroup::Text, textCol );
970 icons->setPalette( QPalette(cg,cg,cg) ); 1031 icons->setPalette( QPalette(cg,cg,cg) );
971} 1032}
972 1033
1034void LauncherView::fontChanged(const QFont&)
1035{
1036 qDebug("LauncherView::fontChanged()");
1037 icons->hideOrShowItems( FALSE );
1038}
973 1039
974void LauncherView::setBusyIndicatorType ( const QString &type ) 1040void LauncherView::relayout(void)
975{ 1041{
976 if ( type. lower ( ) == "blink" ) 1042 icons->hideOrShowItems(FALSE);
977 icons-> setBusyIndicatorType ( BIT_Blinking ); 1043}
978 else 1044
979 icons-> setBusyIndicatorType ( BIT_Normal ); 1045void LauncherView::flushBgCache()
1046{
1047 if ( !bgCache )
1048 return;
1049 // remove unreferenced backgrounds.
1050 QMap<QString,BgPixmap*>::Iterator it = bgCache->begin();
1051 while ( it != bgCache->end() ) {
1052 QMap<QString,BgPixmap*>::Iterator curr = it;
1053 ++it;
1054 if ( (*curr)->ref == 0 ) {
1055 delete (*curr);
1056 bgCache->remove( curr );
1057 }
1058 }
980} 1059}
981 1060
diff --git a/core/launcher/launcherview.h b/core/launcher/launcherview.h
index 82a319b..7863d6a 100644
--- a/core/launcher/launcherview.h
+++ b/core/launcher/launcherview.h
@@ -1,106 +1,112 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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#ifndef LAUNCHERVIEW_H 20#ifndef LAUNCHERVIEW_H
21#define LAUNCHERVIEW_H 21#define LAUNCHERVIEW_H
22 22
23#include <qpe/storage.h> 23#include <qtopia/storage.h>
24#include <qtopia/applnk.h>
24 25
25#include <qvbox.h> 26#include <qvbox.h>
26 27
27class AppLnk;
28class AppLnkSet;
29class CategorySelect; 28class CategorySelect;
30class LauncherIconView; 29class LauncherIconView;
31class QIconView; 30class QIconView;
32class QIconViewItem; 31class QIconViewItem;
32class QLabel;
33class QWidgetStack;
33class MenuButton; 34class MenuButton;
34class QComboBox; 35class QComboBox;
35 36
36class LauncherView : public QVBox 37class LauncherView : public QVBox
37{ 38{
38 Q_OBJECT 39 Q_OBJECT
39 40
40public: 41public:
41 LauncherView( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 42 LauncherView( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
42 ~LauncherView(); 43 ~LauncherView();
43 44
45 void hideIcons();
46
44 bool removeLink(const QString& linkfile); 47 bool removeLink(const QString& linkfile);
45 void addItem(AppLnk* app, bool resort=TRUE); 48 void addItem(AppLnk* app, bool resort=TRUE);
49 void removeAllItems();
50 void setSortEnabled(bool);
51 void setUpdatesEnabled(bool);
46 void sort(); 52 void sort();
47 53
48 void setFileSystems(const QList<FileSystem> &);
49 void setToolsEnabled(bool); 54 void setToolsEnabled(bool);
50 void updateTools(); 55 void updateTools();
51 56
52 void setBusy(bool); 57 void setBusy(bool);
58 void setBusyIndicatorType( const QString& );
53 59
54 QString getAllDocLinkInfo() const;
55 enum ViewMode { Icon, List }; 60 enum ViewMode { Icon, List };
56 void setViewMode( ViewMode m ); 61 void setViewMode( ViewMode m );
57 ViewMode viewMode() const { return vmode; } 62 ViewMode viewMode() const { return vmode; }
58 63
59 enum BackgroundType { Ruled, SolidColor, Image }; 64 enum BackgroundType { Ruled, SolidColor, Image };
60 void setBackgroundType( BackgroundType t, const QString & ); 65 void setBackgroundType( BackgroundType t, const QString & );
61 BackgroundType backgroundType() const { return bgType; } 66 BackgroundType backgroundType() const { return bgType; }
62 67
63 void setTextColor( const QColor & ); 68 void setTextColor( const QColor & );
64 QColor textColor() const { return textCol; } 69 QColor textColor() const { return textCol; }
65 70
66 void setViewFont( const QFont & ); 71 void setViewFont( const QFont & );
67 void unsetViewFont ( ); 72 void clearViewFont();
68
69 void setBusyIndicatorType ( const QString &type );
70 73
71public slots: 74 void relayout(void);
72 void populate( AppLnkSet *folder, const QString& categoryfilter );
73 75
74signals: 76signals:
75 void clicked( const AppLnk * ); 77 void clicked( const AppLnk * );
76 void rightPressed( AppLnk * ); 78 void rightPressed( AppLnk * );
77 79
78protected slots: 80protected slots:
79 void selectionChanged(); 81 void selectionChanged();
80 void returnPressed( QIconViewItem *item ); 82 void returnPressed( QIconViewItem *item );
81 void itemClicked( int, QIconViewItem * ); 83 void itemClicked( int, QIconViewItem * );
82 void itemPressed( int, QIconViewItem * ); 84 void itemPressed( int, QIconViewItem * );
83 void sortBy(int); 85 void sortBy(int);
84 void showType(int); 86 void showType(int);
85 void showCategory( int ); 87 void showCategory( int );
86 void resizeEvent(QResizeEvent *); 88 void resizeEvent(QResizeEvent *);
89 void flushBgCache();
87 90
88protected: 91protected:
89 void internalPopulate( AppLnkSet *, const QString& categoryfilter );
90 void paletteChange( const QPalette & ); 92 void paletteChange( const QPalette & );
91 93
94 void fontChanged(const QFont &);
95
92private: 96private:
93 static bool bsy; 97 static bool bsy;
94 QWidget* tools; 98 QWidget* tools;
95 LauncherIconView* icons; 99 LauncherIconView* icons;
96 QComboBox *typemb; 100 QComboBox *typemb;
97 QStringList typelist; 101 QStringList typelist;
98 CategorySelect *catmb; 102 CategorySelect *catmb;
99 ViewMode vmode; 103 ViewMode vmode;
100 BackgroundType bgType; 104 BackgroundType bgType;
101 QString bgName; 105 QString bgName;
102 QColor textCol; 106 QColor textCol;
103 int busyType; 107
108 QImage loadBackgroundImage(QString &fname);
109 int m_busyType;
104}; 110};
105 111
106#endif // LAUNCHERVIEW_H 112#endif // LAUNCHERVIEW_H