summaryrefslogtreecommitdiff
path: root/library
Side-by-side diff
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/applnk.cpp84
1 files changed, 43 insertions, 41 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 80f2c62..c82d3b9 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -335,278 +335,280 @@ const QArray<int>& AppLnk::categories() const
If the with the AppLnk associated file is not equal to QString::null
*/
/*!
\fn bool AppLnk::linkFileKnown()const
The filename of the AppLnk
*/
/*!
\fn void AppLnk::setRotation( const QString& )
The default rotation of the associated application. This
function is included inline for binary compatible issues
*/
/*!
Creates an invalid AppLnk.
\sa isValid()
*/
AppLnk::AppLnk()
{
mId = 0;
d = new AppLnkPrivate();
}
/*!
Loads \a file (e.g. \e app.desktop) as an AppLnk.
\sa writeLink()
*/
AppLnk::AppLnk( const QString &file )
{
QStringList sl;
d = new AppLnkPrivate();
if ( !file.isNull() ) {
Config config( file, Config::File );
if ( config.isValid() ) {
config.setGroup( "Desktop Entry" );
mName = config.readEntry( "Name", file );
mExec = config.readEntry( "Exec" );
mType = config.readEntry( "Type", QString::null );
mIconFile = config.readEntry( "Icon", QString::null );
mRotation = config.readEntry( "Rotation", "" );
mComment = config.readEntry( "Comment", QString::null );
// MIME types are case-insensitive.
mMimeTypes = config.readListEntry( "MimeType", ';' );
for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it)
*it = (*it).lower();
mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' );
mLinkFile = file;
mFile = config.readEntry("File", QString::null);
if ( !mExec. isEmpty ( )) {
mFile = QString::null;
}
else if ( mFile[0] != '/' ) {
int slash = file.findRev('/');
if ( slash >= 0 ) {
mFile = file.left(slash) + '/' + mFile;
}
}
d->mCatList = config.readListEntry("Categories", ';');
if ( d->mCatList[0].toInt() < -1 ) {
// numeric cats in file! convert to text
Categories cat( 0 );
cat.load( categoryFileName() );
d->mCat.resize( d->mCatList.count() );
int i;
QStringList::ConstIterator it;
for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end();
++it, i++ ) {
bool number;
int id = (*it).toInt( &number );
if ( !number ) {
// convert from text
id = cat.id( "Document View", *it );
if ( id == 0 )
id = cat.addCategory( "Document View", *it );
}
d->mCat[i] = id;
}
d->updateCatListFromArray();
}
}
}
mId = 0;
}
AppLnk& AppLnk::operator=(const AppLnk &copy)
{
if ( this == &copy ) return *this;
if ( mId )
qWarning("Deleting AppLnk that is in an AppLnkSet");
if ( d )
delete d;
mName = copy.mName;
/* remove for Qtopia 3.0 -zecke */
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;
d->mCatList = copy.d->mCatList;
d->mPixmaps = copy.d->mPixmaps;
return *this;
}
/*!
protected internally to share code
should I document that at all?
I don't know the TT style for that
*/
const QPixmap& AppLnk::pixmap( int pos, int size ) const {
if ( d->mPixmaps[pos].isNull() ) {
- AppLnk* that = (AppLnk*)this;
- if ( mIconFile.isEmpty() ) {
- MimeType mt(type());
- that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap();
- if ( that->d->mPixmaps[pos].isNull() )
- that->d->mPixmaps[pos].convertFromImage(
- Resource::loadImage("UnknownDocument")
- .smoothScale( size, size ) );
- return that->d->mPixmaps[pos];
- }
- QImage unscaledIcon = Resource::loadImage( that->mIconFile );
- if ( unscaledIcon.isNull() ) {
- // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() );
- that->d->mPixmaps[pos].convertFromImage(
- Resource::loadImage("UnknownDocument")
- .smoothScale( size, size ) );
- } else {
- that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
- that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
- }
- return that->d->mPixmaps[pos];
+ AppLnk* that = (AppLnk*)this;
+ if ( mIconFile.isEmpty() ) {
+ MimeType mt(type());
+ that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap();
+ if ( that->d->mPixmaps[pos].isNull() )
+ that->d->mPixmaps[pos].convertFromImage(
+ Resource::loadImage("UnknownDocument")
+ .smoothScale( size, size ) );
+ return that->d->mPixmaps[pos];
+ }
+
+ QImage unscaledIcon = Resource::loadImage( that->mIconFile );
+ if ( unscaledIcon.isNull() ) {
+ // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() );
+ that->d->mPixmaps[pos].convertFromImage(
+ Resource::loadImage("UnknownDocument")
+ .smoothScale( size, size ) );
+ } else {
+ that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
+ that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
+ }
+ return that->d->mPixmaps[pos];
}
+
return d->mPixmaps[pos];
}
/*!
Returns a small pixmap associated with the application.
\sa bigPixmap() setIcon()
*/
const QPixmap& AppLnk::pixmap() const
{
if ( d->mPixmaps[0].isNull() ) {
return pixmap(AppLnkPrivate::Normal, smallSize );
}
return d->mPixmaps[0];
}
/*!
Returns a large pixmap associated with the application.
\sa pixmap() setIcon()
*/
const QPixmap& AppLnk::bigPixmap() const
{
if ( d->mPixmaps[1].isNull() ) {
return pixmap( AppLnkPrivate::Big, bigSize );
}
return d->mPixmaps[1];
}
/*!
Returns the type of the AppLnk. For applications, games and
settings the type is \c Application; for documents the type is the
document's MIME type.
*/
QString AppLnk::type() const
{
if ( mType.isNull() ) {
AppLnk* that = (AppLnk*)this;
QString f = file();
if ( !f.isNull() ) {
MimeType mt(f);
that->mType = mt.id();
return that->mType;
}
}
return mType;
}
/*!
Returns the file associated with the AppLnk.
\sa exec() name()
*/
QString AppLnk::file() const
{
if ( mExec.isEmpty ( ) && mFile.isNull() ) {
AppLnk* that = (AppLnk*)this;
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;
qDebug("mFile now == %s", mFile.latin1());
} else if ( mType.contains('/') ) {
that->mFile =
QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName);
/*
* A file with the same name or a .desktop file already exists
*/
if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) {
int n=1;
QString nn;
while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext)
|| QFile::exists(nn+".desktop"))
n++;
that->mFile = nn;
}
that->mLinkFile = that->mFile+".desktop";
that->mFile += ext;
}
prepareDirectories(that->mFile);
if ( !that->mFile.isEmpty() ) {
QFile f(that->mFile);
if ( !f.open(IO_WriteOnly) )
that->mFile = QString::null;
return that->mFile;
}
}
return mFile;
}
/*!
Returns the desktop file corresponding to this AppLnk.
\sa file() exec() name()
*/
QString AppLnk::linkFile() const
{
if ( mLinkFile.isNull() ) {
AppLnk* that = (AppLnk*)this;
if ( type().contains('/') ) {
StorageInfo storage;
const FileSystem *fs = storage.fileSystemOf( that->mFile );
/* tmpfs + and ramfs are available too but not removable
* either we fix storage or add this
*/
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);
/* the desktop file exists make sure we don't point to the same file */
if ( QFile::exists(that->mLinkFile+".desktop") ) {
AppLnk lnk( that->mLinkFile + ".desktop" );
/* the linked is different */
if(that->file() != lnk.file() ) {
int n = 1;
QString nn;
while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) {
n++;
/* just to be sure */
AppLnk lnk(nn );
if (lnk.file() == that->file() )
break;
@@ -859,398 +861,398 @@ bool AppLnk::writeLink() const
}
/*!
\internal
*/
void AppLnk::storeLink() const
{
Config config( mLinkFile, Config::File );
config.setGroup("Desktop Entry");
config.writeEntry("Name",mName);
if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile);
config.writeEntry("Type",type());
if(!rotation().isEmpty())
config.writeEntry("Rotation",rotation());
else
config.removeEntry("Rotation");
if ( !mComment.isNull() ) config.writeEntry("Comment",mComment);
QString f = file();
int i = 0;
while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] )
i++;
while ( i && f[i] != '/' )
i--;
// simple case where in the same directory
if ( mLinkFile.find( '/', i + 1 ) < 0 )
f = f.mid(i+1);
// ### could do relative ie ../../otherDocs/file.doc
config.writeEntry("File",f);
config.writeEntry( "Categories", d->mCatList, ';' );
#ifndef QT_NO_COP
QCopEnvelope e("QPE/System", "linkChanged(QString)");
e << mLinkFile;
#endif
}
/*!
Sets the property named \a key to \a value.
\sa property()
*/
void AppLnk::setProperty(const QString& key, const QString& value)
{
if ( ensureLinkExists() ) {
Config cfg(linkFile(), Config::File);
cfg.writeEntry(key,value);
}
}
/*!
Returns the property named \a key.
\sa setProperty()
*/
QString AppLnk::property(const QString& key) const
{
QString lf = linkFile();
if ( !QFile::exists(lf) )
return QString::null;
Config cfg(lf, Config::File);
return cfg.readEntry(key);
}
bool AppLnk::isPreloaded() const {
// Preload information is stored in the Launcher config in v1.5.
Config cfg("Launcher");
cfg.setGroup("Preload");
QStringList apps = cfg.readListEntry("Apps",',');
if (apps.contains(exec()))
return true;
return false;
}
void AppLnk::setPreloaded(bool yesNo) {
// Preload information is stored in the Launcher config in v1.5.
Config cfg("Launcher");
cfg.setGroup("Preload");
QStringList apps = cfg.readListEntry("Apps", ',');
if (apps.contains(exec()) && !yesNo)
apps.remove(exec());
else if (yesNo && !apps.contains(exec()))
apps.append(exec());
cfg.writeEntry("Apps", apps, ',');
}
/*!
Deletes both the linkFile() and the file() associated with this AppLnk.
\sa removeLinkFile()
*/
void AppLnk::removeFiles()
{
bool valid = isValid();
if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) {
if ( QFile::remove(file()) ) {
#ifndef QT_NO_COP
QCopEnvelope e("QPE/System", "linkChanged(QString)");
if ( linkFileKnown() )
e << linkFile();
else
e << file();
#endif
} else if ( valid ) {
// restore link
writeLink();
}
}
}
/*!
Deletes the linkFile(), leaving any file() untouched.
\sa removeFiles()
*/
void AppLnk::removeLinkFile()
{
if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) {
#ifndef QT_NO_COP
QCopEnvelope e("QPE/System", "linkChanged(QString)");
e << linkFile();
#endif
}
}
class AppLnkImagePrivate {
public :
AppLnkImagePrivate( const QString & ImageName ) {
- IconName = ImageName;
- Small = 0;
- Big = 0;
+ IconName = ImageName;
+ Small = 0;
+ Big = 0;
}
~AppLnkImagePrivate( ) {
- if ( Small ) delete Small;
- if ( Big ) delete Big;
+ if ( Small ) delete Small;
+ if ( Big ) delete Big;
}
inline QPixmap * small( void ) {
- if( ! Small ) {
- QImage unscaledIcon = Resource::loadImage( IconName );
- // works as long as smallSize remains static
- Small = new QPixmap();
- Small->convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
- }
- return Small;
+ if( ! Small ) {
+ QImage unscaledIcon = Resource::loadImage( IconName );
+ // works as long as smallSize remains static
+ Small = new QPixmap();
+ Small->convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
+ }
+ return Small;
}
inline QPixmap * big( void ) {
- if( ! Big ) {
- QImage unscaledIcon = Resource::loadImage( IconName );
- // works as long as bigSize remains static
- Big = new QPixmap();
- Big->convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
- }
- return Big;
+ if( ! Big ) {
+ QImage unscaledIcon = Resource::loadImage( IconName );
+ // works as long as bigSize remains static
+ Big = new QPixmap();
+ Big->convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
+ }
+ return Big;
}
QString IconName;
QPixmap * Small;
QPixmap * Big;
};
class AppLnkSetPrivate {
public:
AppLnkSetPrivate()
{
typPix.setAutoDelete(TRUE);
typName.setAutoDelete(TRUE);
}
QDict<AppLnkImagePrivate> typPix;
QDict<QString> typName;
};
/*!
\class AppLnkSet applnk.h
\brief The AppLnkSet class is a set of AppLnk objects.
*/
/*!
\fn QStringList AppLnkSet::types() const
Returns the list of \link applnk.html#Types types\endlink in the set.
For applications, games and settings the type is \c Application;
for documents the type is the document's MIME type.
\sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap()
*/
/*!
\fn const QList<AppLnk>& AppLnkSet::children() const
Returns the members of the set.
*/
/*!
Constructs an empty AppLnkSet.
*/
AppLnkSet::AppLnkSet() :
d(new AppLnkSetPrivate)
{
}
/*!
Constructs an AppLnkSet that contains AppLnk objects representing
all the files in the given \a directory (and any subdirectories
recursively).
\omit
The directories may contain ".directory" files which override
any AppLnk::type() values for AppLnk objects found in the directory.
This allows simple localization of application types.
\endomit
*/
AppLnkSet::AppLnkSet( const QString &directory ) :
d(new AppLnkSetPrivate)
{
QDir dir( directory );
mFile = directory;
findChildren(directory,QString::null,QString::null);
}
/*!
Detaches all AppLnk objects from the set. The set become empty and
the caller becomes responsible for deleting the AppLnk objects.
*/
void AppLnkSet::detachChildren()
{
QListIterator<AppLnk> it( mApps );
for ( ; it.current(); ) {
AppLnk* a = *it;
++it;
a->mId = 0;
}
mApps.clear();
}
/*!
Destroys the set, deleting all the AppLnk objects it contains.
\sa detachChildren()
*/
AppLnkSet::~AppLnkSet()
{
QListIterator<AppLnk> it( mApps );
for ( ; it.current(); ) {
AppLnk* a = *it;
++it;
a->mId = 0;
delete a;
}
delete d;
}
void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth)
{
depth++;
if ( depth > 10 )
return;
QDir dir( dr );
QString typNameLocal = typName;
if ( dir.exists( ".directory" ) ) {
Config config( dr + "/.directory", Config::File );
config.setGroup( "Desktop Entry" );
typNameLocal = config.readEntry( "Name", typNameLocal );
if ( !typ.isEmpty() ) {
- d->typPix.insert( typ,
+ d->typPix.insert( typ,
new AppLnkImagePrivate( config.readEntry( "Icon", "AppsIcon" ) )
);
d->typName.insert(typ, new QString(typNameLocal));
}
}
const QFileInfoList *list = dir.entryInfoList();
if ( list ) {
QFileInfo* fi;
bool cadded=FALSE;
for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
QString bn = fi->fileName();
// qDebug("findChildren "+bn);
if ( bn[0] != '.' && bn != "CVS" ) {
if ( fi->isDir() ) {
QString c = typ.isNull() ? bn : typ+"/"+bn;
QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn;
findChildren(fi->filePath(), c, d, depth );
} else {
if ( fi->extension(FALSE) == "desktop" ) {
AppLnk* app = new AppLnk( fi->filePath() );
#ifdef QT_NO_QWS_MULTIPROCESS
if ( !Global::isBuiltinCommand( app->exec() ) )
delete app;
else
#endif
{
if ( !typ.isEmpty() ) {
if ( !cadded ) {
typs.append(typ);
cadded = TRUE;
}
app->setType(typ);
}
add(app);
}
}
}
}
}
}
}
/*!
Adds AppLnk \a f to the set. The set takes responsibility for
deleting \a f.
\sa remove()
*/
void AppLnkSet::add( AppLnk *f )
{
if ( f->mId == 0 ) {
AppLnk::lastId++;
f->mId = AppLnk::lastId;
mApps.append( f );
} else {
qWarning("Attempt to add an AppLnk twice");
}
}
/*!
Removes AppLnk \a f to the set. The caller becomes responsible for
deleting \a f. Returns TRUE if \a f was in the set; otherwise
returns FALSE.
\sa add()
*/
bool AppLnkSet::remove( AppLnk *f )
{
if ( mApps.remove( f ) ) {
f->mId = 0;
return TRUE;
}
return FALSE;
}
/*!
Returns the localized name for type \a t.
For applications, games and settings the type is \c Application;
for documents the type is the document's MIME type.
*/
QString AppLnkSet::typeName( const QString& t ) const
{
QString *st = d->typName.find(t);
return st ? *st : QString::null;
}
/*!
Returns the small pixmap associated with type \a t.
For applications, games and settings the type is \c Application;
for documents the type is the document's MIME type.
*/
QPixmap AppLnkSet::typePixmap( const QString& t ) const
{
AppLnkImagePrivate *alip = d->typPix.find(t);
return alip ? *(alip->small()) : QPixmap();
}
/*!
Returns the large pixmap associated with type \a t.
For applications, games and settings the type is \c Application;
for documents the type is the document's MIME type.
*/
QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const
{
AppLnkImagePrivate *alip = d->typPix.find(t);
return alip ? *(alip->big()) : QPixmap();
}
/*!
Returns the AppLnk with the given \a id.
*/
const AppLnk *AppLnkSet::find( int id ) const
{
QListIterator<AppLnk> it( children() );
for ( ; it.current(); ++it ) {
const AppLnk *app = it.current();
if ( app->id() == id )
return app;
}
return 0;