-rw-r--r-- | library/applnk.cpp | 2 | ||||
-rw-r--r-- | library/global.cpp | 4 | ||||
-rw-r--r-- | library/lnkproperties.cpp | 7 | ||||
-rw-r--r-- | library/storage.cpp | 14 |
4 files changed, 16 insertions, 11 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp index 5185b5f..778ccab 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp @@ -247,193 +247,193 @@ const QPixmap& AppLnk::pixmap() const that->mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); that->mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); return that->mPixmap; } return mPixmap; } /*! Returns a large pixmap associated with the application. */ const QPixmap& AppLnk::bigPixmap() const { if ( mBigPixmap.isNull() ) { AppLnk* that = (AppLnk*)this; if ( mIconFile.isEmpty() ) { MimeType mt(type()); that->mBigPixmap = mt.bigPixmap(); if ( that->mBigPixmap.isNull() ) that->mBigPixmap = Resource::loadPixmap("UnknownDocument"); return that->mBigPixmap; } QImage unscaledIcon = Resource::loadImage( that->mIconFile ); that->mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); that->mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); return that->mBigPixmap; } return mBigPixmap; } /*! Returns the type of the application. */ QString AppLnk::type() const { if ( mType.isNull() ) { AppLnk* that = (AppLnk*)this; MimeType mt(file()); that->mType = mt.id(); return that->mType; } return mType; } /*! Returns the file associated with the AppLnk. \sa exec() */ QString AppLnk::file() const { if ( mFile.isNull() ) { AppLnk* that = (AppLnk*)this; // copy? QString ext = MimeType(mType).extension(); if ( !ext.isEmpty() ) ext = "." + ext; if ( !mLinkFile.isEmpty() ) { that->mFile = mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; } else if ( mType.contains('/') ) { that->mFile = QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { // a .desktop with the same name exists int n=1; qWarning("AppLnk::file() n=1 %s", that->mFile.latin1() ); QString nn; while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) || QFile::exists(nn+".desktop")) n++; that->mFile = nn; qWarning("AppLnl::file() now mFile is %s", that->mFile.latin1() ); } that->mLinkFile = that->mFile+".desktop"; that->mFile += ext; } prepareDirectories(that->mFile); QFile f(that->mFile); if ( !f.open(IO_WriteOnly) ) that->mFile = QString::null; return that->mFile; } return mFile; } /*! Returns the desktop file coresponding to this AppLnk. \sa file(), exec() */ QString AppLnk::linkFile() const { if ( mLinkFile.isNull() ) { AppLnk* that = (AppLnk*)this; if ( type().contains('/') ) { StorageInfo storage; const FileSystem *fs = storage.fileSystemOf( that->mFile ); - if ( fs && fs->isRemovable() ) { + if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs" ) ) { that->mLinkFile = fs->path(); } else that->mLinkFile = getenv( "HOME" ); that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); if ( QFile::exists(that->mLinkFile+".desktop") ) { // ok the file exists lets check if we point to the same file int n=1; QString nn; AppLnk lnk( that->mLinkFile+".desktop" ); if(that->file() != lnk.file() ){ qWarning("AppLnk::linkFile exists %s", that->mLinkFile.latin1() ); while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")){ n++; AppLnk lnk(nn ); // just to be sure if(lnk.file() ==that->file() ){ break; } } that->mLinkFile = nn; } } that->mLinkFile += ".desktop"; qWarning("AppLnk::linkFile is %s", that->mLinkFile.latin1() ); storeLink(); } return that->mLinkFile; } return mLinkFile; } /*! Copies \a copy. */ AppLnk::AppLnk( const AppLnk © ) { mName = copy.mName; mPixmap = copy.mPixmap; mBigPixmap = copy.mBigPixmap; mExec = copy.mExec; mType = copy.mType; mRotation = copy.mRotation; mComment = copy.mComment; mFile = copy.mFile; mLinkFile = copy.mLinkFile; mIconFile = copy.mIconFile; mMimeTypes = copy.mMimeTypes; mMimeTypeIcons = copy.mMimeTypeIcons; mId = 0; d = new AppLnkPrivate(); d->mCat = copy.d->mCat; } /*! Destroys the AppLnk. Note that if the AppLnk is current a member of an AppLnkSet, this will produce a run-time warning. \sa AppLnkSet::add(), AppLnkSet::remove() */ AppLnk::~AppLnk() { if ( mId ) qWarning("Deleting AppLnk that is in an AppLnkSet"); if ( d ) delete d; } /*! Executes the application associated with this AppLnk. */ void AppLnk::execute() const { execute(QStringList()); } /*! Executes the application associated with this AppLnk, with \a args as arguments. */ void AppLnk::execute(const QStringList& args) const { #ifdef Q_WS_QWS if ( !mRotation.isEmpty() ) { // ######## this will only work in the server int rot = QPEApplication::defaultRotation(); rot = (rot+mRotation.toInt())%360; QCString old = getenv("QWS_DISPLAY"); setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); invoke(args); setenv("QWS_DISPLAY", old.data(), 1); } else #endif invoke(args); } /*! Invokes the application associated with this AppLnk, with \a args as arguments. Rotation is not taken into account by diff --git a/library/global.cpp b/library/global.cpp index edb7b85..ab27b3f 100644 --- a/library/global.cpp +++ b/library/global.cpp @@ -588,139 +588,143 @@ void Global::execute( const QString &c, const QString& document ) // Convert the command line in to a list of arguments QStringList list = QStringList::split(QRegExp(" *"),c); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) QString ap=list[0]; qDebug("executing %s", ap.latin1() ); if ( ap == "suspend" ) { QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); return; } /* if need be, sending a qcop message will result in an invoke, see preceeding function */ { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } if ( !document.isEmpty() ) { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); env << document; } #endif } /*! Returns the string \a s with the characters backslash, ", and $ quoted by a preceeding backslash. */ QString Global::shellQuote(const QString& s) { QString r="\""; for (int i=0; i<(int)s.length(); i++) { char c = s[i].latin1(); switch (c) { case '\\': case '"': case '$': r+="\\"; } r += s[i]; } r += "\""; return r; } /*! Returns the string \a s with the characters backslash and " quoted by a preceeding backslash. */ QString Global::stringQuote(const QString& s) { QString r="\""; for (int i=0; i<(int)s.length(); i++) { char c = s[i].latin1(); switch (c) { case '\\': case '"': r+="\\"; } r += s[i]; } r += "\""; return r; } /*! Finds all documents on the system's document directories which match the filter \a mimefilter, and appends the resulting DocLnk objects to \a folder. */ void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) { QString homedocs = QString(getenv("HOME")) + "/Documents"; DocLnkSet d(homedocs,mimefilter); folder->appendFrom(d); /** let's do intellegint way of searching these files * a) the user don't want to check mediums global * b) the user wants to check but use the global options for it * c) the user wants to check it but not this medium * d) the user wants to check and this medium as well * * In all cases we need to apply a different mimefilter to * the medium. * a) mimefilter.isEmpty() we need to apply the responding filter * either the global or the one on the medium * * b) mimefilter is set to an application we need to find out if the * mimetypes are included in the mime mask of the medium */ StorageInfo storage; const QList<FileSystem> &fs = storage.fileSystems(); QListIterator<FileSystem> it ( fs ); for ( ; it.current(); ++it ) { if ( (*it)->isRemovable() ) { // let's find out if we should search on it // this is a candidate look at the cf and see if we should search on it QString path = (*it)->path(); if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) continue; DocLnkSet ide( path, mimefilter ); folder->appendFrom(ide); + } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { + QString path = (*it)->path() + "/Documents"; + DocLnkSet ide( path, mimefilter ); + folder->appendFrom(ide); } } } QStringList Global::languageList() { QString lang = getenv("LANG"); QStringList langs; langs.append(lang); int i = lang.find("."); if ( i > 0 ) lang = lang.left( i ); i = lang.find( "_" ); if ( i > 0 ) langs.append(lang.left(i)); return langs; } QStringList Global::helpPath() { QStringList path; QStringList langs = Global::languageList(); for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { QString lang = *it; if ( !lang.isEmpty() ) path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; } path += QPEApplication::qpeDir() + "/pics"; path += QPEApplication::qpeDir() + "/help/en/html"; path += QPEApplication::qpeDir() + "/docs"; QString dir = QDir::current().canonicalPath(); if ( dir == "/" ) dir += "/docs"; else { path += dir + "/../pics"; dir += "/../docs"; path += dir; } return path; } #include "global.moc" diff --git a/library/lnkproperties.cpp b/library/lnkproperties.cpp index e8baca6..c020328 100644 --- a/library/lnkproperties.cpp +++ b/library/lnkproperties.cpp @@ -80,201 +80,202 @@ LnkProperties::LnkProperties( AppLnk* l, QWidget* parent ) connect(d->duplicate,SIGNAL(clicked()),this,SLOT(duplicateLnk())); connect(d->delicon,SIGNAL(clicked()),this,SLOT(unlinkIcon())); d->docname->setReadOnly( FALSE ); d->preload->hide(); d->spacer->hide(); // ### THIS MUST GO, FIX WIERD BUG in QLAYOUT d->categoryEdit->kludge(); d->categoryEdit->setCategories( lnk->categories(), "Document View", tr("Document View") ); setupLocations(); } else { d->unlink->hide(); d->duplicate->hide(); d->beam->hide(); d->hline->hide(); d->locationLabel->hide(); d->locationCombo->hide(); // Can't edit categories, since the app .desktop files are global, // possibly read-only. d->categoryEdit->hide(); d->docname->setReadOnly( TRUE ); if ( l->property("CanFastload") == "0" ) d->preload->hide(); Config cfg("Launcher"); cfg.setGroup("Preload"); QStringList apps = cfg.readListEntry("Apps",','); d->preload->setChecked( apps.contains(l->exec()) ); if ( Global::isBuiltinCommand(lnk->exec()) ) d->preload->hide(); // builtins are always fast currentLocation = 0; // apps not movable (yet) } setCaption( l->file()); } LnkProperties::~LnkProperties() { } void LnkProperties::unlinkLnk() { if ( QPEMessageBox::confirmDelete( this, tr("Delete"), lnk->name() ) ) { if ( QFile::exists(lnk->file()) ) lnk->removeFiles(); else QMessageBox::warning( this, tr("Delete"), tr("File does not exist.") ); if ( QFile::exists(lnk->file()) ) { QMessageBox::warning( this, tr("Delete"), tr("File deletion failed.") ); } else { reject(); } } } /* * remove only the link from documents, not also the file */ void LnkProperties::unlinkIcon() { if ( QPEMessageBox::confirmDelete( this, tr("Delete Icon and leave file"), lnk->name() ) ) { lnk->removeLinkFile(); if ( QFile::exists(lnk->linkFile()) ) { QMessageBox::warning( this, tr("Delete"), tr("Icon deletion failed.") ); } else { reject(); } } } void LnkProperties::setupLocations() { QFileInfo fi( lnk->file() ); fileSize = fi.size(); StorageInfo storage; const QList<FileSystem> &fs = storage.fileSystems(); QListIterator<FileSystem> it ( fs ); QString s; QString homeDir = getenv("HOME"); QString hardDiskHome; QString hardDiskPath; int index = 0; currentLocation = -1; for ( ; it.current(); ++it ) { // we add 10k to the file size so we are sure we can also save the desktop file if ( (*it)->availBlocks() * (*it)->blockSize() > fileSize + 10000 ) { if ( (*it)->isRemovable() || (*it)->disk() == "/dev/mtdblock1" || - (*it)->disk() == "/dev/mtdblock/1" || (*it)->disk().left(13) == "/dev/mtdblock" ) { + (*it)->disk() == "/dev/mtdblock/1" || (*it)->disk().left(13) == "/dev/mtdblock" || + (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { d->locationCombo->insertItem( (*it)->name(), index ); - locations.append( ((*it)->isRemovable() ? (*it)->path() : homeDir) ); + locations.append( ((*it)->isRemovable() || (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ? (*it)->path() : homeDir) ); if ( lnk->file().contains( (*it)->path() ) ) { d->locationCombo->setCurrentItem( index ); currentLocation = index; } index++; - } else if ( (*it)->name().contains( "Hard Disk") && + } else if ( (*it)->name().contains( tr("Hard Disk") ) && homeDir.contains( (*it)->path() ) && (*it)->path().length() > hardDiskHome.length() ) { hardDiskHome = (*it)->name(); hardDiskPath = (*it)->path(); } } } if ( !hardDiskHome.isEmpty() ) { d->locationCombo->insertItem( hardDiskHome ); locations.append( hardDiskPath ); if ( currentLocation == -1 ) { // assume it's the hard disk d->locationCombo->setCurrentItem( index ); currentLocation = index; } } } void LnkProperties::duplicateLnk() { // The duplicate takes the new properties. DocLnk newdoc( *((DocLnk *)lnk) ); if ( d->docname->text() == lnk->name() ) newdoc.setName(tr("Copy of ")+d->docname->text()); else newdoc.setName(d->docname->text()); if ( !copyFile( newdoc ) ) { QMessageBox::warning( this, tr("Duplicate"), tr("File copy failed.") ); return; } reject(); } bool LnkProperties::moveLnk() { DocLnk newdoc( *((DocLnk *)lnk) ); newdoc.setName(d->docname->text()); if ( !copyFile( newdoc ) ) { QMessageBox::warning( this, tr("Details"), tr("Moving Document failed.") ); return FALSE; } // remove old lnk lnk->removeFiles(); return TRUE; } void LnkProperties::beamLnk() { Ir ir; DocLnk doc( *((DocLnk *)lnk) ); ir.send( doc, doc.comment() ); } bool LnkProperties::copyFile( DocLnk &newdoc ) { const char *linkExtn = ".desktop"; QString fileExtn; int extnPos = lnk->file().findRev( '.' ); if ( extnPos > 0 ) fileExtn = lnk->file().mid( extnPos ); QString safename = newdoc.name(); safename.replace(QRegExp("/"),"_"); QString fn = locations[ d->locationCombo->currentItem() ] + "/Documents/" + newdoc.type() + "/" + safename; if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) { int n=1; QString nn = fn + "_" + QString::number(n); while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) { n++; nn = fn + "_" + QString::number(n); } fn = nn; } newdoc.setFile( fn + fileExtn ); newdoc.setLinkFile( fn + linkExtn ); // Copy file FileManager fm; if ( !fm.copyFile( *lnk, newdoc ) ) return FALSE; return TRUE; } void LnkProperties::done(int ok) { if ( ok ) { bool changed=FALSE; if ( lnk->name() != d->docname->text() ) { lnk->setName(d->docname->text()); changed=TRUE; } if ( d->categoryEdit->isVisible() ) { diff --git a/library/storage.cpp b/library/storage.cpp index 2d996fa..13639fe 100644 --- a/library/storage.cpp +++ b/library/storage.cpp @@ -12,185 +12,185 @@ ** 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 <qpe/storage.h> #ifdef QT_QWS_CUSTOM #include <qpe/custom.h> #endif #include <qfile.h> #include <qtimer.h> #include <qcopchannel_qws.h> #include <stdio.h> #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) #include <sys/vfs.h> #include <mntent.h> #endif #include <qstringlist.h> static bool isCF(const QString& m) { FILE* f = fopen("/var/run/stab", "r"); if (!f) f = fopen("/var/state/pcmcia/stab", "r"); if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); if ( f ) { char line[1024]; char devtype[80]; char devname[80]; while ( fgets( line, 1024, f ) ) { // 0 ide ide-cs 0 hda 3 0 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) { if ( QString(devtype) == "ide" && m.find(devname)>0 ) { fclose(f); return TRUE; } } } fclose(f); } return FALSE; } StorageInfo::StorageInfo( QObject *parent ) : QObject( parent ) { mFileSystems.setAutoDelete( TRUE ); channel = new QCopChannel( "QPE/Card", this ); connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); update(); } const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) { for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { if ( filename.startsWith( (*i)->path() ) ) return (*i); } return 0; } void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) { if ( msg == "mtabChanged()" ) update(); } // cause of the lack of a d pointer we need // to store informations in a config file :( void StorageInfo::update() { //qDebug("StorageInfo::updating"); #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) struct mntent *me; FILE *mntfp = setmntent( "/etc/mtab", "r" ); QStringList curdisks; QStringList curopts; QStringList curfs; bool rebuild = FALSE; int n=0; if ( mntfp ) { while ( (me = getmntent( mntfp )) != 0 ) { QString fs = me->mnt_fsname; if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" - || fs.left(8)=="/dev/ram" || fs.left(5)=="tmpfs" ) + || fs.left(5)=="tmpfs" ) { n++; curdisks.append(fs); curopts.append( me->mnt_opts ); //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); curfs.append( me->mnt_dir ); bool found = FALSE; for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { if ( (*i)->disk() == fs ) { found = TRUE; break; } } if ( !found ) rebuild = TRUE; } } endmntent( mntfp ); } if ( rebuild || n != (int)mFileSystems.count() ) { mFileSystems.clear(); QStringList::ConstIterator it=curdisks.begin(); QStringList::ConstIterator fsit=curfs.begin(); QStringList::ConstIterator optsIt=curopts.begin(); for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) { QString opts = *optsIt; QString disk = *it; QString humanname; bool removable = FALSE; if ( isCF(disk) ) { humanname = tr("CF Card"); removable = TRUE; } else if ( disk == "/dev/hda1" ) { humanname = tr("Hard Disk"); } else if ( disk.left(9) == "/dev/mmcd" ) { humanname = tr("SD Card"); removable = TRUE; } else if ( disk.left(7) == "/dev/hd" ) - humanname = tr("Hard Disk") + " " + humanname.mid(7); + humanname = tr("Hard Disk") + " " + disk.mid(7); else if ( disk.left(7) == "/dev/sd" ) - humanname = tr("SCSI Hard Disk") + " " + humanname.mid(7); + humanname = tr("SCSI Hard Disk") + " " + disk.mid(7); else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs - humanname = tr("Ram FS") + " " + humanname.mid(14); + humanname = tr("Internal Memory"); else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) humanname = tr("Internal Storage"); else if ( disk.left(14) == "/dev/mtdblock/" ) - humanname = tr("Internal Storage") + " " + humanname.mid(14); + humanname = tr("Internal Storage") + " " + disk.mid(14); else if ( disk.left(13) == "/dev/mtdblock" ) - humanname = tr("Internal Storage") + " " + humanname.mid(13); + humanname = tr("Internal Storage") + " " + disk.mid(13); else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs - humanname = tr("Ram FS") + " " + humanname.mid(5); + humanname = tr("Internal Memory"); FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); mFileSystems.append( fs ); } emit disksChanged(); } else { // just update them for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) i.current()->update(); } #endif } //--------------------------------------------------------------------------- FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o ) : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o ) { update(); } void FileSystem::update() { #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) struct statfs fs; if ( !statfs( fspath.latin1(), &fs ) ) { blkSize = fs.f_bsize; totalBlks = fs.f_blocks; availBlks = fs.f_bavail; } else { blkSize = 0; totalBlks = 0; availBlks = 0; } #endif } |