-rw-r--r-- | core/launcher/launcher.cpp | 7 | ||||
-rw-r--r-- | core/launcher/mrulist.cpp | 46 | ||||
-rw-r--r-- | core/launcher/mrulist.h | 1 |
3 files changed, 26 insertions, 28 deletions
diff --git a/core/launcher/launcher.cpp b/core/launcher/launcher.cpp index 17a30e6..1449269 100644 --- a/core/launcher/launcher.cpp +++ b/core/launcher/launcher.cpp @@ -491,385 +491,390 @@ Launcher::Launcher( QWidget* parent, const char* name, WFlags fl ) Launcher::~Launcher() { } static bool isVisibleWindow(int wid) { const QList<QWSWindow> &list = qwsServer->clientWindows(); QWSWindow* w; for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { if ( w->winId() == wid ) return !w->isFullyObscured(); } return FALSE; } void Launcher::showMaximized() { if ( isVisibleWindow( winId() ) ) doMaximize(); else QTimer::singleShot( 20, this, SLOT(doMaximize()) ); } void Launcher::doMaximize() { QMainWindow::showMaximized(); } void Launcher::updateMimeTypes() { MimeType::clear(); updateMimeTypes(rootFolder); } void Launcher::updateMimeTypes(AppLnkSet* folder) { for ( QListIterator<AppLnk> it( folder->children() ); it.current(); ++it ) { AppLnk *app = it.current(); if ( app->type() == "Folder" ) updateMimeTypes((AppLnkSet *)app); else { MimeType::registerApp(*app); } } } void Launcher::loadDocs() // ok here comes a hack belonging to Global:: { qWarning("loading Documents" ); qWarning("The currentTimeStamp is: %s", m_timeStamp.latin1() ); delete docsFolder; docsFolder = new DocLnkSet; qWarning("new DocLnkSet" ); DocLnkSet *tmp = 0; QString home = QString(getenv("HOME")) + "/Documents"; tmp = new DocLnkSet( home , QString::null); docsFolder->appendFrom( *tmp ); delete tmp; // find out wich filesystems are new in this round // We will do this by having a timestamp inside each mountpoint // if the current timestamp doesn't match this is a new file system and // come up with our MediumMountGui :) let the hacking begin int stamp = uidgen.generate(); QString newStamp = QString::number( stamp ); // generates newtime Stamp StorageInfo storage; const QList<FileSystem> &fileSystems = storage.fileSystems(); QListIterator<FileSystem> it ( fileSystems ); for ( ; it.current(); ++it ) { if ( (*it)->isRemovable() ) { // let's find out if we should search on it qWarning("%s is removeable", (*it)->path().latin1() ); OConfig cfg( (*it)->path() + "/.opiestorage.cf"); cfg.setGroup("main"); QString stamp = cfg.readEntry("timestamp", QDateTime::currentDateTime().toString() ); if( stamp == m_timeStamp ){ // ok we know this card cfg.writeEntry("timestamp", newStamp ); //just write a new timestamp // we need to scan the list now. Hopefully the cache will be there // read the mimetypes from the config and search for documents QStringList mimetypes = configToMime( &cfg); tmp = new DocLnkSet( (*it)->path(), mimetypes.join(";") ); docsFolder->appendFrom( *tmp ); delete tmp; }else{ // come up with the gui cause this a new card MediumMountGui medium((*it)->path() ); if( medium.check() ){ // we did not ask before or ask again is off if( medium.exec() ){ // he clicked yes so search it // speicher cfg.read(); // cause of a race we need to reread cfg.writeEntry("timestamp", newStamp ); }// no else }else{ // we checked // do something different see what we need to do // let's see if we should check the device cfg.setGroup("main" ); bool check = cfg.readBoolEntry("autocheck", true ); if( check ){ // find the documents tmp = new DocLnkSet( (*it)->path(), configToMime(&cfg ).join(";") ); docsFolder->appendFrom( *tmp ); delete tmp; } } } } } m_timeStamp = newStamp; } void Launcher::updateTabs() { MimeType::updateApplications(); // ### reads all applnks twice delete rootFolder; rootFolder = new AppLnkSet( MimeType::appsFolderName() ); loadDocs(); tabs->initializeCategories(rootFolder, docsFolder, storage->fileSystems()); } void Launcher::updateDocs() { loadDocs(); tabs->updateDocs(docsFolder,storage->fileSystems()); } void Launcher::viewSelected(const QString& s) { setCaption( s + tr(" - Launcher") ); } void Launcher::nextView() { tabs->nextTab(); } void Launcher::select( const AppLnk *appLnk ) { if ( appLnk->type() == "Folder" ) { // Not supported: flat is simpler for the user } else { if ( appLnk->exec().isNull() ) { QMessageBox::information(this,tr("No application"), tr("<p>No application is defined for this document." "<p>Type is %1.").arg(appLnk->type())); return; } tabs->setBusy(TRUE); emit executing( appLnk ); appLnk->execute(); } } void Launcher::externalSelected(const AppLnk *appLnk) { tabs->setBusy(TRUE); emit executing( appLnk ); } void Launcher::properties( AppLnk *appLnk ) { if ( appLnk->type() == "Folder" ) { // Not supported: flat is simpler for the user } else { in_lnk_props = TRUE; got_lnk_change = FALSE; LnkProperties prop(appLnk); connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); prop.showMaximized(); prop.exec(); in_lnk_props = FALSE; if ( got_lnk_change ) { updateLink(lnk_change); } } } void Launcher::updateLink(const QString& link) { if (link.isNull()) updateTabs(); else if (link.isEmpty()) updateDocs(); else tabs->updateLink(link); } void Launcher::systemMessage( const QCString &msg, const QByteArray &data) { QDataStream stream( data, IO_ReadOnly ); - if ( msg == "linkChanged(QString)" ) { + if ( msg == "closing(QString)" ){ + QString app; + stream >> app; + qWarning("app closed %s", app.latin1() ); + MRUList::removeTask( app ); + }else if ( msg == "linkChanged(QString)" ) { QString link; stream >> link; if ( in_lnk_props ) { got_lnk_change = TRUE; lnk_change = link; } else { updateLink(link); } } else if ( msg == "busy()" ) { emit busy(); } else if ( msg == "notBusy(QString)" ) { QString app; stream >> app; tabs->setBusy(FALSE); emit notBusy(app); } else if ( msg == "mkdir(QString)" ) { QString dir; stream >> dir; if ( !dir.isEmpty() ) mkdir( dir ); } else if ( msg == "rdiffGenSig(QString,QString)" ) { QString baseFile, sigFile; stream >> baseFile >> sigFile; QRsync::generateSignature( baseFile, sigFile ); } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) { QString baseFile, sigFile, deltaFile; stream >> baseFile >> sigFile >> deltaFile; QRsync::generateDiff( baseFile, sigFile, deltaFile ); } else if ( msg == "rdiffApplyPatch(QString,QString)" ) { QString baseFile, deltaFile; stream >> baseFile >> deltaFile; if ( !QFile::exists( baseFile ) ) { QFile f( baseFile ); f.open( IO_WriteOnly ); f.close(); } QRsync::applyDiff( baseFile, deltaFile ); QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" ); e << baseFile; } else if ( msg == "rdiffCleanup()" ) { mkdir( "/tmp/rdiff" ); QDir dir; dir.setPath( "/tmp/rdiff" ); QStringList entries = dir.entryList(); for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) dir.remove( *it ); } else if ( msg == "sendHandshakeInfo()" ) { QString home = getenv( "HOME" ); QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" ); e << home; int locked = (int) Desktop::screenLocked(); e << locked; // register an app for autostart // if clear is send the list is cleared. } else if ( msg == "autoStart(QString)" ) { QString appName; stream >> appName; Config cfg( "autostart" ); cfg.setGroup( "AutoStart" ); if ( appName.compare("clear") == 0){ cfg.writeEntry("Apps", ""); } } else if ( msg == "autoStart(QString,QString)" ) { QString modifier, appName; stream >> modifier >> appName; Config cfg( "autostart" ); cfg.setGroup( "AutoStart" ); if ( modifier.compare("add") == 0 ){ // only add it appname is entered if (!appName.isEmpty()) { cfg.writeEntry("Apps", appName); } } else if (modifier.compare("remove") == 0 ) { // need to change for multiple entries // actually remove is right now simular to clear, but in future there // should be multiple apps in autostart possible. QString checkName; checkName = cfg.readEntry("Apps", ""); if (checkName == appName) { cfg.writeEntry("Apps", ""); } } } else if ( msg == "sendCardInfo()" ) { QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" ); const QList<FileSystem> &fs = storage->fileSystems(); QListIterator<FileSystem> it ( fs ); QString s; QString homeDir = getenv("HOME"); QString hardDiskHome; for ( ; it.current(); ++it ) { if ( (*it)->isRemovable() ) s += (*it)->name() + "=" + (*it)->path() + "/Documents " + QString::number( (*it)->availBlocks() * (*it)->blockSize() ) + " " + (*it)->options() + ";"; else if ( (*it)->disk() == "/dev/mtdblock1" || (*it)->disk() == "/dev/mtdblock/1" ) s += (*it)->name() + "=" + homeDir + "/Documents " + QString::number( (*it)->availBlocks() * (*it)->blockSize() ) + " " + (*it)->options() + ";"; else if ( (*it)->name().contains( "Hard Disk") && homeDir.contains( (*it)->path() ) && (*it)->path().length() > hardDiskHome.length() ) hardDiskHome = (*it)->name() + "=" + homeDir + "/Documents " + QString::number( (*it)->availBlocks() * (*it)->blockSize() ) + " " + (*it)->options() + ";"; } if ( !hardDiskHome.isEmpty() ) s += hardDiskHome; e << s; } else if ( msg == "sendSyncDate(QString)" ) { QString app; stream >> app; Config cfg( "qpe" ); cfg.setGroup("SyncDate"); QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" ); e << app << cfg.readEntry( app ); //qDebug("QPE/System sendSyncDate for %s: response %s", app.latin1(), //cfg.readEntry( app ).latin1() ); } else if ( msg == "setSyncDate(QString,QString)" ) { QString app, date; stream >> app >> date; Config cfg( "qpe" ); cfg.setGroup("SyncDate"); cfg.writeEntry( app, date ); //qDebug("setSyncDate(QString,QString) %s %s", app.latin1(), date.latin1()); } else if ( msg == "startSync(QString)" ) { QString what; stream >> what; delete syncDialog; syncDialog = 0; syncDialog = new SyncDialog( this, "syncProgress", FALSE, WStyle_Tool | WStyle_Customize | Qt::WStyle_StaysOnTop ); syncDialog->showMaximized(); syncDialog->whatLabel->setText( "<b>" + what + "</b>" ); connect( syncDialog->buttonCancel, SIGNAL( clicked() ), SLOT( cancelSync() ) ); } else if ( msg == "stopSync()") { delete syncDialog; syncDialog = 0; } else if ( msg == "getAllDocLinks()" ) { loadDocs(); QString contents; for ( QListIterator<DocLnk> it( docsFolder->children() ); it.current(); ++it ) { DocLnk *doc = it.current(); QFileInfo fi( doc->file() ); if ( !fi.exists() ) continue; bool fake = !doc->linkFileKnown(); if ( !fake ) { QFile f( doc->linkFile() ); if ( f.open( IO_ReadOnly ) ) { QTextStream ts( &f ); ts.setEncoding( QTextStream::UnicodeUTF8 ); contents += ts.read(); f.close(); } else fake = TRUE; } if (fake) { contents += "[Desktop Entry]\n"; contents += "Categories = " + Qtopia::Record::idsToString( doc->categories() ) + "\n"; contents += "File = "+doc->file()+"\n"; contents += "Name = "+doc->name()+"\n"; contents += "Type = "+doc->type()+"\n"; } contents += QString("Size = %1\n").arg( fi.size() ); } //qDebug( "sending length %d", contents.length() ); QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); e << contents; qDebug( "================ \n\n%s\n\n===============", contents.latin1() ); delete docsFolder; docsFolder = 0; } } void Launcher::cancelSync() { QCopEnvelope e( "QPE/Desktop", "cancelSync()" ); } void Launcher::storageChanged() { diff --git a/core/launcher/mrulist.cpp b/core/launcher/mrulist.cpp index 6066dac..5590d38 100644 --- a/core/launcher/mrulist.cpp +++ b/core/launcher/mrulist.cpp @@ -1,231 +1,223 @@ /********************************************************************** ** Copyright (C) 2002 Holger 'zecke' Freyther ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "mrulist.h" #include <qpe/global.h> #include <qpe/applnk.h> #include <qpe/resource.h> #include <qframe.h> #include <qpushbutton.h> #include <qtoolbutton.h> #include <qpopupmenu.h> #include <qpainter.h> #include <qwindowsystem_qws.h> QList<MRUList> *MRUList::MRUListWidgets = NULL; QList<AppLnk> *MRUList::task = NULL; MRUList::MRUList( QWidget *parent ) : QFrame( parent ), selected(-1), oldsel(-1) { setBackgroundMode( PaletteButton ); if (!MRUListWidgets) MRUListWidgets = new QList<MRUList>; if (!task) task = new QList<AppLnk>; MRUListWidgets->append( this ); } MRUList::~MRUList() { if (MRUListWidgets) MRUListWidgets->remove( this ); if (task) task->setAutoDelete( TRUE ); } QSize MRUList::sizeHint() const { return QSize( frameWidth(), 16 ); } +// thanks to John from Trolltech +void MRUList::removeTask(const QString &appName ) +{ + qWarning("MRULList::removeTask( %s)", appName.latin1() ); + if(appName.isEmpty() ) + return; + + if(!task ) // at least it should be called once before + return; + unsigned int i= 0; + for ( ; i < task->count(); i++ ) { + AppLnk *t = task->at(i); + if ( t->exec() == appName ) + task->remove(); + } + for (unsigned i = 0; i < MRUListWidgets->count(); i++ ) + MRUListWidgets->at(i)->update(); +} void MRUList::addTask( const AppLnk *appLnk ) { + qWarning("Add Task" ); if ( !appLnk ) return; unsigned int i = 0; if ( !task ) return; - // ok we wan't to delete old icons from the taskbar - // get the window list and see which windows aren't there any more - QList<AppLnk> cleanUp; - cleanUp.setAutoDelete( TRUE ); - const QList<QWSWindow> &list = qwsServer->clientWindows(); - QWSWindow* w; - bool running = false; // to see what we should do - for ( ; i < task->count(); i++ ) { - AppLnk *t = task->at(i); - running = false; - for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { - QString app = w->client()->identity(); - if( app == t->exec( ) ){ - running = true; - break; - } - } - if(!running ) { // gues what we do now - cleanUp.append( t); - } - } - // no do a clean up of these old icons - AppLnk *lnk; - for( lnk = cleanUp.first(); lnk != 0; lnk = cleanUp.next() ){ - task->remove( lnk ); - } - cleanUp.clear(); // should be deleted too i = 0; for ( ; i < task->count(); i++ ) { AppLnk *t = task->at(i); if ( t->exec() == appLnk->exec() ) { if (i != 0) { task->remove(); task->prepend( t ); } for (unsigned i = 0; i < MRUListWidgets->count(); i++ ) MRUListWidgets->at(i)->update(); return; } } // check which tasks are running and delete them from the list AppLnk *t = new AppLnk( *appLnk ); // DocLnks have an overloaded virtual function exec() t->setExec( appLnk->exec() ); task->prepend( t ); if ( task->count() > 6 ) { t = task->last(); task->remove(); Global::terminate(t); delete t; } for (unsigned i = 0; i < MRUListWidgets->count(); i++ ) MRUListWidgets->at(i)->update(); } bool MRUList::quitOldApps() { QStringList appsstarted; QStringList appsrunning; for ( int i=task->count()-1; i>=0; --i ) { AppLnk *t = task->at(i); appsstarted.append(t->exec()); } const QList<QWSWindow> &list = qwsServer->clientWindows(); QWSWindow* w; for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { QString app = w->client()->identity(); if ( appsstarted.contains(app) && !appsrunning.contains(app) ) appsrunning.append(app); } if ( appsrunning.count() > 1 ) { QStringList::ConstIterator it = appsrunning.begin(); ++it; // top stays running! for (; it != appsrunning.end(); it++) { for ( int i=task->count()-1; i>=0; --i ) { AppLnk *t = task->at(i); if ( t->exec() == *it ){ task->remove(i ); delete t; Global::terminate(t); } } } return TRUE; } else { return FALSE; } } void MRUList::mousePressEvent(QMouseEvent *e) { selected = 0; int x=0; QListIterator<AppLnk> it( *task ); for ( ; it.current(); ++it,++selected,x+=15 ) { if ( x + 15 <= width() ) { if ( e->x() >= x && e->x() < x+15 ) { if ( selected < (int)task->count() ) { repaint(FALSE); return; } } } else { break; } } selected = -1; repaint( FALSE ); } void MRUList::mouseReleaseEvent(QMouseEvent *) { if ( selected >= 0 ) { if ( parentWidget() ) if ( parentWidget()->isA( "QPopupMenu" ) ) parentWidget()->hide(); Global::execute( task->at(selected)->exec() ); selected = -1; oldsel = -1; update(); } } void MRUList::paintEvent( QPaintEvent * ) { QPainter p( this ); AppLnk *t; int x = 0; int y = (height() - 14) / 2; int i = 0; p.fillRect( 0, 0, width(), height(), colorGroup().background() ); if ( task ) { QListIterator<AppLnk> it( *task ); for ( ; it.current(); i++, ++it ) { if ( x + 15 <= width() ) { t = it.current(); if ( (int)i == selected ) p.fillRect( x, y, 15, t->pixmap().height()+1, colorGroup().highlight() ); else if ( (int)i == oldsel ) p.eraseRect( x, y, 15, t->pixmap().height()+1 ); p.drawPixmap( x, y, t->pixmap() ); x += 15; } } } } diff --git a/core/launcher/mrulist.h b/core/launcher/mrulist.h index 141a09b..ff111ce 100644 --- a/core/launcher/mrulist.h +++ b/core/launcher/mrulist.h @@ -1,55 +1,56 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef __MRU_LIST_H__ #define __MRU_LIST_H__ #include <qpe/applnk.h> #include <qframe.h> #include <qlist.h> #include <qpixmap.h> class MRUList : public QFrame { public: MRUList( QWidget *parent ); ~MRUList(); virtual QSize sizeHint() const; static void addTask( const AppLnk *appLnk ); + static void removeTask(const QString &appName ); bool quitOldApps(); protected: void mousePressEvent(QMouseEvent *e); void mouseReleaseEvent(QMouseEvent *e); void paintEvent( QPaintEvent *event ); private: static QList<MRUList> *MRUListWidgets; static QList<AppLnk> *task; int selected; int oldsel; }; #endif // __MRU_LIST_H__ |