summaryrefslogtreecommitdiff
path: root/core/launcher/launcher.cpp
Unidiff
Diffstat (limited to 'core/launcher/launcher.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/launcher.cpp1501
1 files changed, 451 insertions, 1050 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
@@ -15,32 +15,27 @@
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>
@@ -54,283 +49,254 @@
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 79
96 tmpMime = cfg->readBoolEntry("image", true );
97 if(tmpMime )
98 mimes.append("image/*" );
99 80
100 tmpMime = cfg->readBoolEntry("text", true ); 81static bool isVisibleWindow( int );
101 if(tmpMime ) 82//===========================================================================
102 mimes.append("text/*");
103 83
104 tmpMime = cfg->readBoolEntry("video", true ); 84LauncherTabWidget::LauncherTabWidget( Launcher* parent ) :
105 if(tmpMime ) 85 QVBox( parent )
106 mimes.append("video/*" ); 86{
107 } 87 docLoadingWidgetEnabled = false;
108 return mimes; 88 docLoadingWidget = 0;
109 } 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();
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
110 108
109 createDocLoadingWidget();
111} 110}
112 111
112void LauncherTabWidget::createDocLoadingWidget()
113{
114 // Construct the 'doc loading widget' shown when finding documents
113 115
116 // ### LauncherView class needs changing to be more generic so
117 // this widget can change its background similar to the iconviews
118 // so the background for this matches
119 docLoadingWidget = new LauncherView( stack );
120 docLoadingWidget->hideIcons();
121 QVBox *docLoadingVBox = new QVBox( docLoadingWidget );
114 122
115//#define SHOW_ALL 123 docLoadingVBox->setSpacing( 20 );
124 docLoadingVBox->setMargin( 10 );
116 125
117class CategoryTab : public QTab 126 QWidget *space1 = new QWidget( docLoadingVBox );
118{ 127 docLoadingVBox->setStretchFactor( space1, 1 );
119public:
120 CategoryTab( const QIconSet &icon, const QString &text=QString::null )
121 : QTab( icon, text )
122 {
123 }
124 128
125 QColor bgColor; 129 QLabel *waitPixmap = new QLabel( docLoadingVBox );
126 QColor fgColor; 130 waitPixmap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, waitPixmap->sizePolicy().hasHeightForWidth() ) );
127}; 131 waitPixmap->setPixmap( Resource::loadPixmap( "bigwait" ) );
132 waitPixmap->setAlignment( int( QLabel::AlignCenter ) );
128 133
129//=========================================================================== 134 QLabel *textLabel = new QLabel( docLoadingVBox );
135 textLabel->setText( tr( "<b>Finding Documents...</b>" ) );
136 textLabel->setAlignment( int( QLabel::AlignCenter ) );
130 137
131CategoryTabWidget::CategoryTabWidget( QWidget* parent ) : 138 docLoadingWidgetProgress = new QProgressBar( docLoadingVBox );
132 QVBox( parent ) 139 docLoadingWidgetProgress->setProgress( 0 );
133{ 140 docLoadingWidgetProgress->setCenterIndicator( TRUE );
134 categoryBar = 0; 141 docLoadingWidgetProgress->setBackgroundMode( NoBackground ); // No flicker
135 stack = 0; 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 );
136} 152}
137 153
138void CategoryTabWidget::prevTab() 154void LauncherTabWidget::initLayout()
139{ 155{
140 if ( categoryBar ) { 156 layout()->activate();
141 int n = categoryBar->count(); 157 docView()->setFocus();
142 int tab = categoryBar->currentTab(); 158 categoryBar->showTab("Documents");
143 if ( tab >= 0 )
144 categoryBar->setCurrentTab( (tab - 1 + n)%n );
145 }
146} 159}
147 160
148void CategoryTabWidget::nextTab() 161void LauncherTabWidget::appMessage(const QCString& message, const QByteArray&)
149{ 162{
150 if ( categoryBar ) { 163 if ( message == "nextView()" )
151 int n = categoryBar->count(); 164 categoryBar->nextTab();
152 int tab = categoryBar->currentTab();
153 categoryBar->setCurrentTab( (tab + 1)%n );
154 }
155} 165}
156 166
157 167void LauncherTabWidget::raiseTabWidget()
158void CategoryTabWidget::showTab(const QString& id)
159{ 168{
160 if ( categoryBar ) { 169 if ( categoryBar->currentView() == docView()
161 int idx = ids.findIndex( id ); 170 && docLoadingWidgetEnabled ) {
162 categoryBar->setCurrentTab( idx ); 171 stack->raiseWidget( docLoadingWidget );
172 docLoadingWidget->updateGeometry();
173 } else {
174 stack->raiseWidget( categoryBar->currentView() );
163 } 175 }
164} 176}
165 177
166void CategoryTabWidget::addItem( const QString& linkfile ) 178void LauncherTabWidget::tabProperties()
167{
168// int i=0;
169// AppLnk *app = new AppLnk(linkfile);
170// if ( !app->isValid() ) {
171// delete app;
172// app=0;
173// }
174// if ( !app || !app->file().isEmpty() ) {
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}
200
201void CategoryTabWidget::initializeCategories(AppLnkSet* rootFolder,
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 );
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
225 QStringList types = rootFolder->types();
226 for ( QStringList::Iterator it=types.begin(); it!=types.end(); ++it) {
227 if ( !(*it).isEmpty() ) {
228 (void)newView(*it,rootFolder->typePixmap(*it),rootFolder->typeName(*it));
229 setTabAppearance( *it, cfg );
230 }
231 }
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 } 191 }
192
193void LauncherTabWidget::deleteView( const QString& id )
194{
195 LauncherTab *t = categoryBar->launcherTab(id);
196 if ( t ) {
197 stack->removeWidget( t->view );
198 delete t->view;
199 categoryBar->removeTab( t );
245 } 200 }
246 ++it;
247 } 201 }
248 rootFolder->detachChildren();
249 for (int i=0; i<tabs; i++)
250 ((LauncherView*)stack->widget(i))->sort();
251 202
252 // all documents 203LauncherView* LauncherTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label )
253 QImage img( Resource::loadImage( "DocsIcon" ) ); 204{
254 QPixmap pm; 205 LauncherView* view = new LauncherView( stack );
255 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 206 connect( view, SIGNAL(clicked(const AppLnk*)),
256 207 this, SIGNAL(clicked(const AppLnk*)));
257 //ljpotter 208 connect( view, SIGNAL(rightPressed(AppLnk*)),
258 CategoryTab *catTab ; 209 this, SIGNAL(rightPressed(AppLnk*)));
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 210
266 // fileSel->hide(); 211 int n = categoryBar->count();
212 stack->addWidget( view, n );
267 213
268 connect( fileSel, SIGNAL( fileSelected( const DocLnk & )), 214 LauncherTab *tab = new LauncherTab( id, view, pm, label );
269 this, SLOT(clickie(const DocLnk&)) ); 215 categoryBar->insertTab( tab, n-1 );
270 216
271// connect( fileSel, SIGNAL( fileSelected( const QString & )), 217 if ( id == "Documents" )
272// this, SLOT(clickie(const QString&)) ); 218 docview = view;
273 219
274 connect( categoryBar, SIGNAL(selected(int)), stack, SLOT(raiseWidget(int)) ); 220 qDebug("inserting %s at %d", id.latin1(), n-1 );
275 221
276 ((LauncherView*)stack->widget(0))->setFocus(); 222 Config cfg("Launcher");
223 setTabAppearance( tab, cfg );
277 224
278 cfg. setGroup ( "GUI" ); 225 cfg. setGroup ( "GUI" );
279 setBusyIndicatorType ( cfg. readEntry ( "BusyType", QString::null )); 226 view->setBusyIndicatorType( cfg.readEntry( "BusyType", QString::null ) );
280 227
281 if ( !current.isNull() ) { 228 return view;
282 showTab(current);
283 } 229 }
284 230
285 categoryBar->show(); 231LauncherView *LauncherTabWidget::view( const QString &id )
286 stack->show(); 232{
287 233 LauncherTab *t = categoryBar->launcherTab(id);
288 234 if ( !t )
289 QCopEnvelope e("QPE/TaskBar","reloadApps()"); 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) );
330 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 );
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);
@@ -338,1019 +304,454 @@ void CategoryTabWidget::setTabAppearance( const QString &id, Config &cfg )
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 );
418} 332}
419
420void CategoryTabWidget::setBusyIndicatorType ( const QString &type )
421{
422 for ( QStringList::Iterator it = ids. begin ( ); it != ids. end ( ); ++it )
423 view ( *it )-> setBusyIndicatorType ( type );
424} 333}
425 334
426//=========================================================================== 335void LauncherTabWidget::setBusy(bool on)
427
428CategoryTabBar::CategoryTabBar( QWidget *parent, const char *name )
429 : QTabBar( parent, name )
430{ 336{
431 setFocusPolicy( NoFocus ); 337 if ( on )
432 connect( this, SIGNAL( selected(int) ), this, SLOT( layoutTabs() ) ); 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 );
433} 343}
434
435CategoryTabBar::~CategoryTabBar()
436{
437} 344}
438
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 } 345 }
515 int h = QMAX( fm.height(), ih );
516 h = QMAX( h, QApplication::globalStrut().height() );
517
518 h += vframe;
519 346
520 t->setRect( QRect(x, 0, available, h) ); 347void LauncherTabWidget::setBusyIndicatorType( const QString& str ) {
521 x += t->rect().width() - overlap; 348 for (int i = 0; i < categoryBar->count(); i++ ) {
522 r = r.unite( t->rect() ); 349 LauncherView* view = static_cast<LauncherTab*>( categoryBar->tab(i) )->view;
350 view->setBusyIndicatorType( str );
523 } 351 }
524 } 352 }
525 353
526 QRect rr = tab(count()-1)->rect(); 354LauncherView *LauncherTabWidget::currentView(void)
527 rr.setRight(width()-1); 355{
528 tab(count()-1)->setRect( rr ); 356 return (LauncherView*)stack->visibleWidget();
529
530 for ( t = tabList()->first(); t; t = tabList()->next() ) {
531 QRect tr = t->rect();
532 tr.setHeight( r.height() );
533 t->setRect( tr );
534 } 357 }
535 358
536 update();
537}
538 359
539 360
540void CategoryTabBar::paint( QPainter * p, QTab * t, bool selected ) const 361void LauncherTabWidget::launcherMessage( const QCString &msg, const QByteArray &data)
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,
588#if QT_VERSION >= 300
589 t->identifier() == keyboardFocusTab()
590#else
591 t->identitifer() == keyboardFocusTab()
592#endif
593 );
594 if ( setPal ) {
595 that->unsetPalette();
596 that->setUpdatesEnabled( TRUE );
597 } 408 }
598} 409}
599 410 }else if ( msg == "setBusyIndicatorType(QString)" ) {
600 411 QString type;
601void CategoryTabBar::paintLabel( QPainter* p, const QRect&, 412 stream >> type;
602 QTab* t, bool has_focus ) const 413 setBusyIndicatorType( type );
603{ 414 }else if ( msg == "home()" ) {
604 QRect r = t->rect(); 415 if ( isVisibleWindow( static_cast<QWidget*>(parent())->winId() ) ) {
605 // if ( t->id != currentTab() ) 416 if (categoryBar)
606 //r.moveBy( 1, 1 ); 417 categoryBar->nextTab();
607 // 418 }else
608 if ( t->iconSet() ) { 419 static_cast<QWidget*>(parent())->raise();
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
622 if ( r.width() < 20 )
623 return;
624
625 if ( t->isEnabled() && isEnabled() ) {
626#if defined(_WS_WIN32_)
627 if ( colorGroup().brush( QColorGroup::Button ) == colorGroup().brush( QColorGroup::Background ) )
628 p->setPen( colorGroup().buttonText() );
629 else
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 } 420 }
639} 421}
640 422
423
424
641//--------------------------------------------------------------------------- 425//---------------------------------------------------------------------------
642 426
643Launcher::Launcher( QWidget* parent, const char* name, WFlags fl ) 427Launcher::Launcher()
644 : QMainWindow( parent, name, fl ) 428 : QMainWindow( 0, "PDA User Interface", QWidget::WStyle_Customize | QWidget::WGroupLeader )
645{ 429{
646 setCaption( tr("Launcher") ); 430 tabs = 0;
431 tb = 0;
432}
647 433
648 syncDialog = 0; 434void Launcher::createGUI()
435{
436 setCaption( tr("Launcher") );
649 437
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}
710
711void Launcher::showMaximized()
712{
713 if ( isVisibleWindow( winId() ) )
714 doMaximize();
715 else
716 QTimer::singleShot( 20, this, SLOT(doMaximize()) );
717} 487}
718 488
719void Launcher::doMaximize() 489void Launcher::makeVisible()
720{ 490{
721 QMainWindow::showMaximized(); 491 showMaximized();
722 tabs->setMaximumWidth( qApp->desktop()->width() );
723} 492}
724 493
725void Launcher::updateMimeTypes() 494void Launcher::destroyGUI()
726{ 495{
727 MimeType::clear(); 496 delete tb;
728 updateMimeTypes(rootFolder); 497 tb = 0;
498 delete tabs;
499 tabs =0;
729} 500}
730 501
731void Launcher::updateMimeTypes(AppLnkSet* folder) 502bool Launcher::eventFilter( QObject*, QEvent *ev )
732{ 503{
733 for ( QListIterator<AppLnk> it( folder->children() ); it.current(); ++it ) { 504#ifdef QT_QWS_CUSTOM
734 AppLnk *app = it.current(); 505 if ( ev->type() == QEvent::KeyPress ) {
735 if ( app->type() == "Folder" ) // No tr 506 QKeyEvent *ke = (QKeyEvent *)ev;
736 updateMimeTypes((AppLnkSet *)app); 507 if ( ke->key() == Qt::Key_F11 ) { // menu key
508 QWidget *active = qApp->activeWindow();
509 if ( active && active->isPopup() )
510 active->close();
737 else { 511 else {
738 MimeType::registerApp(*app); 512 Global::terminateBuiltin("calibrate"); // No tr
513 tb->launchStartMenu();
514 }
515 return TRUE;
739 } 516 }
740 } 517 }
518#else
519 Q_UNUSED(ev);
520#endif
521 return FALSE;
741} 522}
742 523
743/** This is a HACK.... 524void Launcher::toggleSymbolInput()
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{ 525{
756 OWait *owait = new OWait(); 526 tb->toggleSymbolInput();
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 } 527 }
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}
869
870void Launcher::updateTabs()
871{
872 MimeType::updateApplications(); // ### reads all applnks twice
873 delete rootFolder;
874 rootFolder = new AppLnkSet( MimeType::appsFolderName() );
875
876 loadDocs();
877 528
878 tabs->initializeCategories(rootFolder, docsFolder, storage->fileSystems()); 529void Launcher::toggleNumLockState()
530{
531 tb->toggleNumLockState();
879} 532}
880 533
881void Launcher::updateDocs() 534void Launcher::toggleCapsLockState()
882{ 535{
883 loadDocs(); 536 tb->toggleCapsLockState();
884 // tabs->updateDocs(docsFolder,storage->fileSystems());
885} 537}
886 538
887void Launcher::viewSelected(const QString& s) 539static bool isVisibleWindow(int wid)
888{ 540{
889 setCaption( s + tr(" - Launcher") ); 541#ifdef Q_WS_QWS
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;
890} 550}
891 551
892void Launcher::nextView() 552void Launcher::viewSelected(const QString& s)
893{ 553{
894 tabs->nextTab(); 554 setCaption( s + tr(" - Launcher") );
895} 555}
896 556
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);
572
573#if 0
574 /* ### Fixme */
575 if ( i == 1 )
576 Global::execute(Service::app("Open/text/*"),appLnk->file());
577#endif
912 return; 578 return;
913 } 579 }
914 tabs->setBusy(TRUE); 580 tabs->setBusy(TRUE);
915 emit executing( appLnk ); 581 emit executing( appLnk );
916 appLnk->execute(); 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 *)));
935 prop.showMaximized(); 594 prop.showMaximized();
936 prop.exec(); 595 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 }
1067 /*
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 } 616 }
1179 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path)
1180 contents += QString("Size = %1\n").arg( fi.size() ); // No tr
1181 } 617 }
1182 618
1183 //qDebug( "sending length %d", contents.length() ); 619// These are the update functions from the server
1184#ifndef QT_NO_COP 620void Launcher::typeAdded( const QString& type, const QString& name,
1185 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); 621 const QPixmap& pixmap, const QPixmap& )
1186 e << contents; 622{
1187#endif 623 tabs->newView( type, pixmap, name );
624 ids.append( type );
625 tb->refreshStartMenu();
1188 626
1189 //qDebug( "================ \n\n%s\n\n===============", 627 static bool first = TRUE;
1190 //contents.latin1() ); 628 if ( first ) {
1191 629 first = FALSE;
1192 delete docsFolder; 630 tabs->categoryBar->showTab(type);
1193 docsFolder = 0;
1194#ifdef QWS
1195 } else if ( msg == "setMouseProto(QString)" ) {
1196 QString mice;
1197 stream >> mice;
1198 setenv("QWS_MOUSE_PROTO",mice.latin1(),1);
1199 qwsServer->openMouse();
1200 } else if ( msg == "setKeyboard(QString)" ) {
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; 649
1221 stream >> id; 650 LauncherView *view = tabs->view( type );
1222 int mode; 651 if ( view )
1223 stream >> mode; 652 view->addItem( new AppLnk( app ), FALSE );
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 653 else
1269 raise ( ); 654 qWarning("addAppLnk: No view for type %s. Can't add app %s!",
655 type.latin1(),app.name().latin1() );
1270 656
1271 } 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 } 667 }
668
669void Launcher::allApplicationsRemoved()
670{
671 MimeType::clear();
672 for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it)
673 tabs->view( (*it) )->removeAllItems();
1282} 674}
1283 675
676void Launcher::documentAdded( const DocLnk& doc )
677{
678 tabs->docView()->addItem( new DocLnk( doc ), FALSE );
679}
1284 680
1285bool Launcher::mkdir(const QString &localPath) 681void Launcher::showLoadingDocs()
1286{ 682{
1287 QDir fullDir(localPath); 683 tabs->docView()->hide();
1288 if (fullDir.exists()) 684}
1289 return true;
1290 685
1291 // at this point the directory doesn't exist 686void Launcher::showDocTab()
1292 // go through the directory tree and start creating the direcotories 687{
1293 // that don't exist; if we can't create the directories, return false 688 if ( tabs->categoryBar->currentView() == tabs->docView() )
689 tabs->docView()->show();
690}
1294 691
1295 QString dirSeps = "/"; 692void Launcher::documentRemoved( const DocLnk& doc )
1296 int dirIndex = localPath.find(dirSeps); 693{
1297 QString checkedPath; 694 tabs->docView()->removeLink( doc.linkFile() );
695}
1298 696
1299 // didn't find any seps; weird, use the cur dir instead 697void Launcher::documentChanged( const DocLnk& oldDoc, const DocLnk& newDoc )
1300 if (dirIndex == -1) { 698{
1301 //qDebug("No seperators found in path %s", localPath.latin1()); 699 documentRemoved( oldDoc );
1302 checkedPath = QDir::currentDirPath(); 700 documentAdded( newDoc );
1303 } 701 }
1304 702
1305 while (checkedPath != localPath) { 703void Launcher::allDocumentsRemoved()
1306 // no more seperators found, use the local path 704{
1307 if (dirIndex == -1) 705 tabs->docView()->removeAllItems();
1308 checkedPath = localPath;
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 } 706 }
1315 707
1316 QDir checkDir(checkedPath); 708void Launcher::applicationStateChanged( const QString& name, ApplicationState state )
1317 if (!checkDir.exists()) { 709{
1318 //qDebug("mkdir making dir %s", checkedPath.latin1()); 710 tb->setApplicationState( name, state );
711}
1319 712
1320 if (!checkDir.mkdir(checkedPath)) { 713void Launcher::applicationScanningProgress( int percent )
1321 qDebug("Unable to make directory %s", checkedPath.latin1()); 714{
1322 return FALSE; 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 );
1323 } 720 }
721 break;
1324 } 722 }
1325 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 );
1326 } 727 }
1327 return TRUE; 728 break;
1328} 729}
1329 730 default:
1330void Launcher::preloadApps() 731 break;
1331{
1332 Config cfg("Launcher");
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 } 732 }
1340} 733}
1341 734
1342DocumentTab::DocumentTab( QWidget *parent, int mode, int selector, const QString &dirName, const QString &fileName) 735void Launcher::documentScanningProgress( int percent )
1343 : OFileSelector(parent,mode,selector,dirName,fileName)
1344{ 736{
1345 //setYesCancelVisible(false); 737 switch ( percent ) {
1346 //setToolbarVisible(false); 738 case 0: {
1347 //setPermissionBarVisible(false); 739 tabs->setLoadingProgress( 0 );
1348 //setLineEditVisible(false) ; 740 tabs->setLoadingWidgetEnabled( TRUE );
1349 //setChooserVisible( bool chooser ); 741 tabs->docView()->setUpdatesEnabled( FALSE );
1350 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;
1351} 755}
1352
1353DocumentTab::~DocumentTab() {
1354
1355} 756}
1356 757