summaryrefslogtreecommitdiff
path: root/core/launcher/launcher.cpp
Unidiff
Diffstat (limited to 'core/launcher/launcher.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcher.cpp804
1 files changed, 804 insertions, 0 deletions
diff --git a/core/launcher/launcher.cpp b/core/launcher/launcher.cpp
new file mode 100644
index 0000000..66a2ce5
--- a/dev/null
+++ b/core/launcher/launcher.cpp
@@ -0,0 +1,804 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qpe/qcopenvelope_qws.h>
22#include <qpe/resource.h>
23#include <qpe/applnk.h>
24#include <qpe/config.h>
25#include <qpe/global.h>
26#include <qpe/qpeapplication.h>
27#include <qpe/mimetype.h>
28#include <qpe/storage.h>
29#include <qpe/palmtoprecord.h>
30
31#include <qdir.h>
32#include <qwindowsystem_qws.h>
33#include <qtimer.h>
34#include <qcombobox.h>
35#include <qvbox.h>
36#include <qlayout.h>
37#include <qstyle.h>
38#include <qpushbutton.h>
39#include <qtabbar.h>
40#include <qwidgetstack.h>
41#include <qlayout.h>
42#include <qregexp.h>
43#include <qmessagebox.h>
44#include <qframe.h>
45#include <qpainter.h>
46#include <qlabel.h>
47#include <qtextstream.h>
48
49#include "launcherview.h"
50#include "launcher.h"
51#include "syncdialog.h"
52#include "desktop.h"
53#include <qpe/lnkproperties.h>
54#include "mrulist.h"
55#include "qrsync.h"
56#include <stdlib.h>
57#include <unistd.h>
58
59#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
60#include <stdio.h>
61#include <sys/vfs.h>
62#include <mntent.h>
63#endif
64
65//#define SHOW_ALL
66
67CategoryTabWidget::CategoryTabWidget( QWidget* parent ) :
68 QVBox( parent )
69{
70 categoryBar = 0;
71 stack = 0;
72}
73
74void CategoryTabWidget::prevTab()
75{
76 if ( categoryBar ) {
77 int n = categoryBar->count();
78 int tab = categoryBar->currentTab();
79 if ( tab >= 0 )
80 categoryBar->setCurrentTab( (tab - 1 + n)%n );
81 }
82}
83
84void CategoryTabWidget::nextTab()
85{
86 if ( categoryBar ) {
87 int n = categoryBar->count();
88 int tab = categoryBar->currentTab();
89 categoryBar->setCurrentTab( (tab + 1)%n );
90 }
91}
92
93void CategoryTabWidget::addItem( const QString& linkfile )
94{
95 int i=0;
96 AppLnk *app = new AppLnk(linkfile);
97 if ( !app->isValid() ) {
98 delete app;
99 return;
100 }
101 if ( !app->file().isEmpty() ) {
102 // A document
103 delete app;
104 app = new DocLnk(linkfile);
105 ((LauncherView*)(stack->widget(ids.count()-1)))->addItem(app);
106 return;
107 }
108 for ( QStringList::Iterator it=ids.begin(); it!=ids.end(); ++it) {
109 if ( !(*it).isEmpty() ) {
110 QRegExp tf(*it,FALSE,TRUE);
111 if ( tf.match(app->type()) >= 0 ) {
112 ((LauncherView*)stack->widget(i))->addItem(app);
113 return;
114 }
115 i++;
116 }
117 }
118}
119
120void CategoryTabWidget::initializeCategories(AppLnkSet* rootFolder,
121 AppLnkSet* docFolder, const QList<FileSystem> &fs)
122{
123 delete categoryBar;
124 categoryBar = new CategoryTabBar( this );
125 QPalette pal = categoryBar->palette();
126 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) );
127 pal.setColor( QColorGroup::Background, pal.active().background().light(110) );
128 categoryBar->setPalette( pal );
129
130 delete stack;
131 stack = new QWidgetStack(this);
132 tabs=0;
133
134 ids.clear();
135
136 QStringList types = rootFolder->types();
137 for ( QStringList::Iterator it=types.begin(); it!=types.end(); ++it) {
138 if ( !(*it).isEmpty() ) {
139 newView(*it,rootFolder->typePixmap(*it),rootFolder->typeName(*it));
140 }
141 }
142 QListIterator<AppLnk> it( rootFolder->children() );
143 AppLnk* l;
144 while ( (l=it.current()) ) {
145 if ( l->type() == "Separator" ) {
146 rootFolder->remove(l);
147 delete l;
148 } else {
149 int i=0;
150 for ( QStringList::Iterator it=types.begin(); it!=types.end(); ++it) {
151 if ( *it == l->type() )
152 ((LauncherView*)stack->widget(i))->addItem(l,FALSE);
153 i++;
154 }
155 }
156 ++it;
157 }
158 rootFolder->detachChildren();
159 for (int i=0; i<tabs; i++)
160 ((LauncherView*)stack->widget(i))->sort();
161
162 // all documents
163 docview = newView( QString::null, Resource::loadPixmap("DocsIcon"), tr("Documents"));
164 docview->populate( docFolder, QString::null );
165 docFolder->detachChildren();
166 docview->setFileSystems(fs);
167 docview->setToolsEnabled(TRUE);
168
169 connect( categoryBar, SIGNAL(selected(int)), stack, SLOT(raiseWidget(int)) );
170
171 ((LauncherView*)stack->widget(0))->setFocus();
172
173 categoryBar->show();
174 stack->show();
175}
176
177void CategoryTabWidget::updateDocs(AppLnkSet* docFolder, const QList<FileSystem> &fs)
178{
179 docview->populate( docFolder, QString::null );
180 docFolder->detachChildren();
181 docview->setFileSystems(fs);
182 docview->updateTools();
183}
184
185LauncherView* CategoryTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label )
186{
187 LauncherView* view = new LauncherView( stack );
188 connect( view, SIGNAL(clicked(const AppLnk*)),
189 this, SIGNAL(clicked(const AppLnk*)));
190 connect( view, SIGNAL(rightPressed(AppLnk*)),
191 this, SIGNAL(rightPressed(AppLnk*)));
192 ids.append(id);
193 categoryBar->addTab( new QTab( pm, label ) );
194 stack->addWidget( view, tabs++ );
195 return view;
196}
197
198void CategoryTabWidget::updateLink(const QString& linkfile)
199{
200 int i=0;
201 LauncherView* view;
202 while ((view = (LauncherView*)stack->widget(i++))) {
203 if ( view->removeLink(linkfile) )
204 break;
205 }
206 addItem(linkfile);
207 docview->updateTools();
208}
209
210void CategoryTabWidget::paletteChange( const QPalette &p )
211{
212 QVBox::paletteChange( p );
213 QPalette pal = palette();
214 pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) );
215 pal.setColor( QColorGroup::Background, pal.active().background().light(110) );
216 categoryBar->setPalette( pal );
217 categoryBar->update();
218}
219
220void CategoryTabWidget::setBusy(bool on)
221{
222 if ( on )
223 ((LauncherView*)stack->visibleWidget())->setBusy(TRUE);
224 else
225 for (int i=0; i<tabs; i++)
226 ((LauncherView*)stack->widget(i))->setBusy(FALSE);
227}
228
229
230CategoryTabBar::CategoryTabBar( QWidget *parent, const char *name )
231 : QTabBar( parent, name )
232{
233 setFocusPolicy( NoFocus );
234 connect( this, SIGNAL( selected(int) ), this, SLOT( layoutTabs() ) );
235}
236
237CategoryTabBar::~CategoryTabBar()
238{
239}
240
241void CategoryTabBar::layoutTabs()
242{
243 if ( !count() )
244 return;
245
246// int percentFalloffTable[] = { 100, 70, 40, 12, 6, 3, 1, 0 };
247 int hiddenTabWidth = -12;
248 int middleTab = currentTab();
249 int hframe, vframe, overlap;
250 style().tabbarMetrics( this, hframe, vframe, overlap );
251 QFontMetrics fm = fontMetrics();
252 int x = 0;
253 QRect r;
254 QTab *t;
255 int available = width()-1;
256 int required = 0;
257 for ( int i = 0; i < count(); i++ ) {
258 t = tab(i);
259 // if (( i < (middleTab - 1) ) || ( i > (middleTab + 1) )) {
260 if ( i != middleTab ) {
261 // required += hiddenTabWidth + hframe - overlap;
262 available -= hiddenTabWidth + hframe - overlap;
263 if ( t->iconSet() != 0 )
264 available -= t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
265 } else {
266 required += fm.width( t->text() ) + hframe - overlap;
267 if ( t->iconSet() != 0 )
268 required += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
269 }
270 }
271 for ( int i = 0; i < count(); i++ ) {
272 t = tab(i);
273 // if (( i < (middleTab - 1) ) || ( i > (middleTab + 1) )) {
274 if ( i != middleTab ) {
275 int w = hiddenTabWidth;
276 int ih = 0;
277 if ( t->iconSet() != 0 ) {
278 w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
279 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
280 }
281 int h = QMAX( fm.height(), ih );
282 h = QMAX( h, QApplication::globalStrut().height() );
283
284 h += vframe;
285 w += hframe;
286
287 t->setRect( QRect(x, 0, w, h) );
288 x += t->rect().width() - overlap;
289 r = r.unite( t->rect() );
290 } else {
291 int w = fm.width( t->text() );
292 int ih = 0;
293 if ( t->iconSet() != 0 ) {
294 w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width();
295 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
296 }
297 int h = QMAX( fm.height(), ih );
298 h = QMAX( h, QApplication::globalStrut().height() );
299
300 h += vframe;
301 w += hframe;
302
303 // t->setRect( QRect(x, 0, w * available/required, h) );
304 t->setRect( QRect(x, 0, available, h) );
305 x += t->rect().width() - overlap;
306 r = r.unite( t->rect() );
307 }
308 }
309
310 QRect rr = tab(count()-1)->rect();
311 rr.setRight(width()-1);
312 tab(count()-1)->setRect( rr );
313
314 for ( t = tabList()->first(); t; t = tabList()->next() ) {
315 QRect tr = t->rect();
316 tr.setHeight( r.height() );
317 t->setRect( tr );
318 }
319
320 update();
321}
322
323
324void CategoryTabBar::paint( QPainter * p, QTab * t, bool selected ) const
325{
326#if QT_VERSION >= 300
327 QStyle::SFlags flags = QStyle::Style_Default;
328 if ( selected )
329 flags |= QStyle::Style_Selected;
330 style().drawControl( QStyle::CE_TabBarTab, p, this, t->rect(),
331 colorGroup(), flags, QStyleOption(t) );
332#else
333 style().drawTab( p, this, t, selected );
334#endif
335
336 QRect r( t->rect() );
337 QFont f( font() );
338 if ( selected )
339 f.setBold( TRUE );
340 p->setFont( f );
341
342 int iw = 0;
343 int ih = 0;
344 if ( t->iconSet() != 0 ) {
345 iw = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 2;
346 ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
347 }
348 int w = iw + p->fontMetrics().width( t->text() ) + 4;
349 int h = QMAX(p->fontMetrics().height() + 4, ih );
350 paintLabel( p, QRect( r.left() + (r.width()-w)/2 - 3,
351 r.top() + (r.height()-h)/2, w, h ), t,
352#if QT_VERSION >= 300
353 t->identifier() == keyboardFocusTab()
354#else
355 t->identitifer() == keyboardFocusTab()
356#endif
357 );
358}
359
360
361void CategoryTabBar::paintLabel( QPainter* p, const QRect&,
362 QTab* t, bool has_focus ) const
363{
364 QRect r = t->rect();
365 // if ( t->id != currentTab() )
366 //r.moveBy( 1, 1 );
367 //
368 if ( t->iconSet() ) {
369 // the tab has an iconset, draw it in the right mode
370 QIconSet::Mode mode = (t->isEnabled() && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled;
371 if ( mode == QIconSet::Normal && has_focus )
372 mode = QIconSet::Active;
373 QPixmap pixmap = t->iconSet()->pixmap( QIconSet::Small, mode );
374 int pixw = pixmap.width();
375 int pixh = pixmap.height();
376 p->drawPixmap( r.left() + 6, r.center().y() - pixh / 2 + 1, pixmap );
377 r.setLeft( r.left() + pixw + 5 );
378 }
379
380 QRect tr = r;
381
382 if ( r.width() < 20 )
383 return;
384
385 if ( t->isEnabled() && isEnabled() ) {
386#if defined(_WS_WIN32_)
387 if ( colorGroup().brush( QColorGroup::Button ) == colorGroup().brush( QColorGroup::Background ) )
388 p->setPen( colorGroup().buttonText() );
389 else
390 p->setPen( colorGroup().foreground() );
391#else
392 p->setPen( colorGroup().foreground() );
393#endif
394 p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() );
395 } else {
396 p->setPen( palette().disabled().foreground() );
397 p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() );
398 }
399}
400
401//---------------------------------------------------------------------------
402
403Launcher::Launcher( QWidget* parent, const char* name, WFlags fl )
404 : QMainWindow( parent, name, fl )
405{
406 setCaption( tr("Launcher") );
407
408 syncDialog = 0;
409
410 // we have a pretty good idea how big we'll be
411 setGeometry( 0, 0, qApp->desktop()->width(), qApp->desktop()->height() );
412
413 tabs = 0;
414 rootFolder = 0;
415 docsFolder = 0;
416
417 tabs = new CategoryTabWidget( this );
418 tabs->setMaximumWidth( qApp->desktop()->width() );
419 setCentralWidget( tabs );
420
421 connect( tabs, SIGNAL(selected(const QString&)),
422 this, SLOT(viewSelected(const QString&)) );
423 connect( tabs, SIGNAL(clicked(const AppLnk*)),
424 this, SLOT(select(const AppLnk*)));
425 connect( tabs, SIGNAL(rightPressed(AppLnk*)),
426 this, SLOT(properties(AppLnk*)));
427
428#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
429 QCopChannel* sysChannel = new QCopChannel( "QPE/System", this );
430 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)),
431 this, SLOT(systemMessage( const QCString &, const QByteArray &)) );
432#endif
433
434 storage = new StorageInfo( this );
435 connect( storage, SIGNAL( disksChanged() ), SLOT( storageChanged() ) );
436
437 updateTabs();
438
439 preloadApps();
440
441 in_lnk_props = FALSE;
442 got_lnk_change = FALSE;
443}
444
445Launcher::~Launcher()
446{
447}
448
449static bool isVisibleWindow(int wid)
450{
451 const QList<QWSWindow> &list = qwsServer->clientWindows();
452 QWSWindow* w;
453 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
454 if ( w->winId() == wid )
455 return !w->isFullyObscured();
456 }
457 return FALSE;
458}
459
460void Launcher::showMaximized()
461{
462 if ( isVisibleWindow( winId() ) )
463 doMaximize();
464 else
465 QTimer::singleShot( 20, this, SLOT(doMaximize()) );
466}
467
468void Launcher::doMaximize()
469{
470 QMainWindow::showMaximized();
471}
472
473void Launcher::updateMimeTypes()
474{
475 MimeType::clear();
476 updateMimeTypes(rootFolder);
477}
478
479void Launcher::updateMimeTypes(AppLnkSet* folder)
480{
481 for ( QListIterator<AppLnk> it( folder->children() ); it.current(); ++it ) {
482 AppLnk *app = it.current();
483 if ( app->type() == "Folder" )
484 updateMimeTypes((AppLnkSet *)app);
485 else {
486 MimeType::registerApp(*app);
487 }
488 }
489}
490
491void Launcher::loadDocs()
492{
493 delete docsFolder;
494 docsFolder = new DocLnkSet;
495 Global::findDocuments(docsFolder);
496}
497
498void Launcher::updateTabs()
499{
500 MimeType::updateApplications(); // ### reads all applnks twice
501
502 delete rootFolder;
503 rootFolder = new AppLnkSet( MimeType::appsFolderName() );
504
505 loadDocs();
506
507 tabs->initializeCategories(rootFolder, docsFolder, storage->fileSystems());
508}
509
510void Launcher::updateDocs()
511{
512 loadDocs();
513 tabs->updateDocs(docsFolder,storage->fileSystems());
514}
515
516void Launcher::viewSelected(const QString& s)
517{
518 setCaption( s + tr(" - Launcher") );
519}
520
521void Launcher::nextView()
522{
523 tabs->nextTab();
524}
525
526
527void Launcher::select( const AppLnk *appLnk )
528{
529 if ( appLnk->type() == "Folder" ) {
530 // Not supported: flat is simpler for the user
531 } else {
532 if ( appLnk->exec().isNull() ) {
533 QMessageBox::information(this,tr("No application"),
534 tr("<p>No application is defined for this document."
535 "<p>Type is %1.").arg(appLnk->type()));
536 return;
537 }
538 tabs->setBusy(TRUE);
539 emit executing( appLnk );
540 appLnk->execute();
541 }
542}
543
544void Launcher::externalSelected(const AppLnk *appLnk)
545{
546 tabs->setBusy(TRUE);
547 emit executing( appLnk );
548}
549
550void Launcher::properties( AppLnk *appLnk )
551{
552 if ( appLnk->type() == "Folder" ) {
553 // Not supported: flat is simpler for the user
554 } else {
555 in_lnk_props = TRUE;
556 got_lnk_change = FALSE;
557 LnkProperties prop(appLnk);
558 connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *)));
559 prop.showMaximized();
560 prop.exec();
561 in_lnk_props = FALSE;
562 if ( got_lnk_change ) {
563 updateLink(lnk_change);
564 }
565 }
566}
567
568void Launcher::updateLink(const QString& link)
569{
570 if (link.isNull())
571 updateTabs();
572 else if (link.isEmpty())
573 updateDocs();
574 else
575 tabs->updateLink(link);
576}
577
578void Launcher::systemMessage( const QCString &msg, const QByteArray &data)
579{
580 QDataStream stream( data, IO_ReadOnly );
581 if ( msg == "linkChanged(QString)" ) {
582 QString link;
583 stream >> link;
584 if ( in_lnk_props ) {
585 got_lnk_change = TRUE;
586 lnk_change = link;
587 } else {
588 updateLink(link);
589 }
590 } else if ( msg == "busy()" ) {
591 emit busy();
592 } else if ( msg == "notBusy(QString)" ) {
593 QString app;
594 stream >> app;
595 tabs->setBusy(FALSE);
596 emit notBusy(app);
597 } else if ( msg == "mkdir(QString)" ) {
598 QString dir;
599 stream >> dir;
600 if ( !dir.isEmpty() )
601 mkdir( dir );
602 } else if ( msg == "rdiffGenSig(QString,QString)" ) {
603 QString baseFile, sigFile;
604 stream >> baseFile >> sigFile;
605 QRsync::generateSignature( baseFile, sigFile );
606 } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) {
607 QString baseFile, sigFile, deltaFile;
608 stream >> baseFile >> sigFile >> deltaFile;
609 QRsync::generateDiff( baseFile, sigFile, deltaFile );
610 } else if ( msg == "rdiffApplyPatch(QString,QString)" ) {
611 QString baseFile, deltaFile;
612 stream >> baseFile >> deltaFile;
613 if ( !QFile::exists( baseFile ) ) {
614 QFile f( baseFile );
615 f.open( IO_WriteOnly );
616 f.close();
617 }
618 QRsync::applyDiff( baseFile, deltaFile );
619 QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" );
620 e << baseFile;
621 } else if ( msg == "rdiffCleanup()" ) {
622 mkdir( "/tmp/rdiff" );
623 QDir dir;
624 dir.setPath( "/tmp/rdiff" );
625 QStringList entries = dir.entryList();
626 for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it )
627 dir.remove( *it );
628 } else if ( msg == "sendHandshakeInfo()" ) {
629 QString home = getenv( "HOME" );
630 QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" );
631 e << home;
632 int locked = (int) Desktop::screenLocked();
633 e << locked;
634 } else if ( msg == "sendCardInfo()" ) {
635 QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" );
636 const QList<FileSystem> &fs = storage->fileSystems();
637 QListIterator<FileSystem> it ( fs );
638 QString s;
639 QString homeDir = getenv("HOME");
640 QString hardDiskHome;
641 for ( ; it.current(); ++it ) {
642 if ( (*it)->isRemovable() )
643 s += (*it)->name() + "=" + (*it)->path() + "/Documents "
644 + QString::number( (*it)->availBlocks() * (*it)->blockSize() )
645 + " " + (*it)->options() + ";";
646 else if ( (*it)->disk() == "/dev/mtdblock1" ||
647 (*it)->disk() == "/dev/mtdblock/1" )
648 s += (*it)->name() + "=" + homeDir + "/Documents "
649 + QString::number( (*it)->availBlocks() * (*it)->blockSize() )
650 + " " + (*it)->options() + ";";
651 else if ( (*it)->name().contains( "Hard Disk") &&
652 homeDir.contains( (*it)->path() ) &&
653 (*it)->path().length() > hardDiskHome.length() )
654 hardDiskHome =
655 (*it)->name() + "=" + homeDir + "/Documents "
656 + QString::number( (*it)->availBlocks() * (*it)->blockSize() )
657 + " " + (*it)->options() + ";";
658 }
659 if ( !hardDiskHome.isEmpty() )
660 s += hardDiskHome;
661
662 e << s;
663 } else if ( msg == "sendSyncDate(QString)" ) {
664 QString app;
665 stream >> app;
666 Config cfg( "qpe" );
667 cfg.setGroup("SyncDate");
668 QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" );
669 e << app << cfg.readEntry( app );
670 //qDebug("QPE/System sendSyncDate for %s: response %s", app.latin1(),
671 //cfg.readEntry( app ).latin1() );
672 } else if ( msg == "setSyncDate(QString,QString)" ) {
673 QString app, date;
674 stream >> app >> date;
675 Config cfg( "qpe" );
676 cfg.setGroup("SyncDate");
677 cfg.writeEntry( app, date );
678 //qDebug("setSyncDate(QString,QString) %s %s", app.latin1(), date.latin1());
679 } else if ( msg == "startSync(QString)" ) {
680 QString what;
681 stream >> what;
682 delete syncDialog; syncDialog = 0;
683 syncDialog = new SyncDialog( this, "syncProgress", FALSE,
684 WStyle_Tool | WStyle_Customize |
685 Qt::WStyle_StaysOnTop );
686 syncDialog->showMaximized();
687 syncDialog->whatLabel->setText( "<b>" + what + "</b>" );
688 connect( syncDialog->buttonCancel, SIGNAL( clicked() ),
689 SLOT( cancelSync() ) );
690 }
691 else if ( msg == "stopSync()") {
692 delete syncDialog; syncDialog = 0;
693 } else if ( msg == "getAllDocLinks()" ) {
694 loadDocs();
695
696 QString contents;
697
698 for ( QListIterator<DocLnk> it( docsFolder->children() ); it.current(); ++it ) {
699 DocLnk *doc = it.current();
700 QString lfn = doc->linkFile();
701 QFileInfo fi( doc->file() );
702 if ( !fi.exists() )
703 continue;
704
705
706
707 QFile f( lfn );
708 if ( f.open( IO_ReadOnly ) ) {
709 QTextStream ts( &f );
710 ts.setEncoding( QTextStream::UnicodeUTF8 );
711 contents += ts.read();
712 f.close();
713 } else {
714 contents += "[Desktop Entry]\n";
715 contents += "Categories = " + Qtopia::Record::idsToString( doc->categories() ) + "\n";
716 contents += "File = "+doc->file()+"\n";
717 contents += "Name = "+doc->name()+"\n";
718 contents += "Type = "+doc->type()+"\n";
719 }
720 contents += QString("Size = %1\n").arg( fi.size() );
721 }
722
723 //qDebug( "sending length %d", contents.length() );
724 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" );
725 e << contents;
726
727 //qDebug( "================ \n\n%s\n\n===============",
728 //contents.latin1() );
729
730 delete docsFolder;
731 docsFolder = 0;
732 }
733}
734
735void Launcher::cancelSync()
736{
737 QCopEnvelope e( "QPE/Desktop", "cancelSync()" );
738}
739
740void Launcher::storageChanged()
741{
742 if ( in_lnk_props ) {
743 got_lnk_change = TRUE;
744 lnk_change = "";
745 } else {
746 updateDocs();
747 }
748}
749
750
751bool Launcher::mkdir(const QString &localPath)
752{
753 QDir fullDir(localPath);
754 if (fullDir.exists())
755 return true;
756
757 // at this point the directory doesn't exist
758 // go through the directory tree and start creating the direcotories
759 // that don't exist; if we can't create the directories, return false
760
761 QString dirSeps = "/";
762 int dirIndex = localPath.find(dirSeps);
763 QString checkedPath;
764
765 // didn't find any seps; weird, use the cur dir instead
766 if (dirIndex == -1) {
767 //qDebug("No seperators found in path %s", localPath.latin1());
768 checkedPath = QDir::currentDirPath();
769 }
770
771 while (checkedPath != localPath) {
772 // no more seperators found, use the local path
773 if (dirIndex == -1)
774 checkedPath = localPath;
775 else {
776 // the next directory to check
777 checkedPath = localPath.left(dirIndex) + "/";
778 // advance the iterator; the next dir seperator
779 dirIndex = localPath.find(dirSeps, dirIndex+1);
780 }
781
782 QDir checkDir(checkedPath);
783 if (!checkDir.exists()) {
784 //qDebug("mkdir making dir %s", checkedPath.latin1());
785
786 if (!checkDir.mkdir(checkedPath)) {
787 qDebug("Unable to make directory %s", checkedPath.latin1());
788 return FALSE;
789 }
790 }
791
792 }
793 return TRUE;
794}
795
796void Launcher::preloadApps()
797{
798 Config cfg("Launcher");
799 cfg.setGroup("Preload");
800 QStringList apps = cfg.readListEntry("Apps",',');
801 for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) {
802 QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()");
803 }
804}