summaryrefslogtreecommitdiff
path: root/core/launcher/launcher.cpp
authorzecke <zecke>2003-08-28 14:37:27 (UTC)
committer zecke <zecke>2003-08-28 14:37:27 (UTC)
commit245dcac2f79d7409f80da37f9c6c47fff70dc949 (patch) (unidiff)
treeaa5401e3cea0453da32f6062dba6ac454a3457ae /core/launcher/launcher.cpp
parentf837944e9a404c46efc00e4d5851ea13dbb88ef2 (diff)
downloadopie-245dcac2f79d7409f80da37f9c6c47fff70dc949.zip
opie-245dcac2f79d7409f80da37f9c6c47fff70dc949.tar.gz
opie-245dcac2f79d7409f80da37f9c6c47fff70dc949.tar.bz2
-Make it compile
-apply Opie patches -prepare BusyIndicator changes -add QCOP method for showing the desktop and going to the next tab
Diffstat (limited to 'core/launcher/launcher.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcher.cpp1597
1 files changed, 499 insertions, 1098 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
@@ -20,22 +20,17 @@
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>
@@ -59,16 +54,17 @@
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>
@@ -78,233 +74,187 @@
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
@@ -312,10 +262,12 @@ void CategoryTabWidget::setTabAppearance( const QString &id, Config &cfg )
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 }
@@ -323,8 +275,22 @@ void CategoryTabWidget::setTabAppearance( const QString &id, Config &cfg )
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
@@ -333,64 +299,13 @@ void CategoryTabWidget::setTabAppearance( const QString &id, Config &cfg )
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{
@@ -404,194 +319,102 @@ void CategoryTabWidget::paletteChange( const QPalette &p )
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 }
@@ -600,46 +423,13 @@ void CategoryTabBar::paint( QPainter * p, QTab * t, bool selected ) const
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{
@@ -647,4 +437,2 @@ Launcher::Launcher( QWidget* parent, const char* name, WFlags fl )
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
@@ -652,22 +440,26 @@ Launcher::Launcher( QWidget* parent, const char* name, WFlags fl )
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 );
@@ -675,16 +467,15 @@ Launcher::Launcher( QWidget* parent, const char* name, WFlags fl )
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}
@@ -693,193 +484,67 @@ Launcher::~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}
@@ -891,10 +556,5 @@ void Launcher::viewSelected(const QString& s)
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();
@@ -905,13 +565,19 @@ void Launcher::select( const AppLnk *appLnk )
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 }
@@ -919,8 +585,2 @@ void Launcher::select( const AppLnk *appLnk )
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 )
@@ -928,14 +588,9 @@ void Launcher::properties( AppLnk *appLnk )
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 }
@@ -943,20 +598,5 @@ void Launcher::properties( AppLnk *appLnk )
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}
@@ -965,391 +605,152 @@ void 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}