Source Code (Use browser search to find items of interest.)
Class Index
kfind'KfFileType (./kdeutils/kfind/kftypes.h:18)
class KfFileType
{
public:
/*********************************************************
* Create a KfFileType
*/
KfFileType() {};
/*********************************************************
* Create a KfFileType with pattern.
*/
KfFileType( const char *_pattern);
virtual ~KfFileType() {}
/// Add a pattern which matches this type.
virtual void addPattern( const char *_p )
{ if ( pattern.find( _p ) == -1 ) pattern.append( _p ); }
/*********************************************************
* Returns the extensions assoziated with this FileType, for
* example '.html' or '.cpp'.
*/
virtual QStrList& getPattern() { return pattern; }
/// Returns the name of this binding
/**
The file type in the file '$KDEDIR/filetypes/Spreadsheet.desktop' for
example is called 'Spreadsheet'.
*/
const QString getName() { return name; }
/// Returns this file types comment.
/**
The return value may be 0L if there is no comment at all.
This method does not use _url but some overloading methods do so.
*/
virtual QString getComment( const char * )
{ return comment; }
/// Sets the comment
void setComment( const char *_c) { comment = _c; }
/**
The return may be 0. In this case the user did not specify
a special default binding. That does not mean that there is no
binding at all.
*/
virtual QString getDefaultBinding() { return defaultBinding; }
/// Set the default bindings name
virtual void setDefaultBinding( const char *_b )
{ defaultBinding = _b; }
/*********************************************************
* Tries to find a FileType for the file _url. If no special
* FileType is found, the default FileType is returned.
*/
static KfFileType* findType( const char *_url );
/// Find type by pattern.
/**
If for the given pattern no KfFileType has been created, the function
will retun 0L;
*/
static KfFileType *findByPattern( const char *_pattern );
/// Finds a file type by its name
/**
The file type in the file '$KDEDIR/filetypes/Spreadsheet.desktop' for
example is called 'Spreadsheet'.
*/
static KfFileType *findByName( const QString& _name );
/*********************************************************
* Call this function before you call any other function. This
* function initializes some global variables.
*/
static void init();
/// Scan the $KDEDIR/filetypes directory for the file types
static void initFileTypes( const QString& _path );
/// Return the path for the icons
static const char* getIconPath() { return icon_path; }
static const char* getDefaultPixmap() { return defaultPixmap; }
static const char* getExecutablePixmap() { return executablePixmap; }
static const char* getBatchPixmap() { return batchPixmap; }
static const char* getFolderPixmap() { return folderPixmap; }
protected:
/*********************************************************
* List with all bindings for this type.
*/
// QList<KFileBind> bindings;
/*********************************************************
* The full qualified filename ( not an URL ) of the icons
* pixmap.
*/
QString pixmap_file;
/*********************************************************
* The pattern matching this file. For example: ".html".
*/
QStrList pattern;
/// Holds the default binding
/**
This string may be 0. In this case the user did not specify
a special default binding. That does not mean that there is no
binding at all. Attention: Perhaps a binding with that name does
not exist for a strange reason.
*/
QString defaultBinding;
/// Holds the name of the file type
/**
The file type in the file '$KDEDIR/filetypes/Spreadsheet.desktop' for
example is called 'Spreadsheet'.
*/
QString name;
/// Holds a comment to this file type.
QString comment;
/// The path to the icons
static char icon_path[ 1024 ];
/// Default pixmap for executables
static char executablePixmap[ 1024 ];
/// Default pixmap for batch files
static char batchPixmap[ 1024 ];
/// General default pixmap
static char defaultPixmap[ 1024 ];
/// Default pixmap for folders
static char folderPixmap[ 1024 ];
};
kfind'KfFileType::initFileTypes() (./kdeutils/kfind/kftypes.cpp:25)
void KfFileType::initFileTypes( const QString& _path )
{
DIR *dp;
struct dirent *ep;
dp = opendir( _path.ascii() );
if ( dp == NULL )
return;
// Loop thru all directory entries
while ( ( ep = readdir( dp ) ) != NULL ) {
if ( strcmp( ep->d_name, "." ) != 0 && strcmp( ep->d_name, ".." ) != 0 ) {
QString tmp = ep->d_name;
QString file = _path;
file += '/';
file += ep->d_name;
struct stat buff;
stat( file.ascii(), &buff );
if ( S_ISDIR( buff.st_mode ) )
initFileTypes( file );
else if (KDesktopFile::isDesktopFile(tmp)) {
KDesktopFile config(file);
// Read a new extension group
QString ext = ep->d_name;
if ( ext.right( 8 ) == ".desktop" )
ext = ext.left( ext.length() - 8 );
// Get a ';' separated list of all pattern
QString pats = config.readEntry( "Patterns" );
QString icon = config.readIcon();
QString defapp = config.readEntry( "DefaultApp" );
QString comment = config.readComment();
// Take this type only of it has pattern
if ( (!pats.isNull() && pats!="") && pats!=";" ) {
// Is this file type already registered ?
KfFileType *t = KfFileType::findByName( ext );
// If not then create a new type,
//but only if we have an icon
if ( t == 0L && !icon.isNull() )
types->append( t = new KfFileType(ext));
// Set the default binding
if ( !defapp.isNull() && t != 0L )
t->setDefaultBinding( defapp );
if ( t != 0L )
t->setComment( comment );
int pos2 = 0;
int old_pos2 = 0;
while ( ( pos2 = pats.find( ";", pos2 ) ) != - 1 )
{
// Read a pattern from the list
QString name = pats.mid( old_pos2, pos2 - old_pos2 );
if ( t != 0L )
t->addPattern( name );
pos2++;
old_pos2 = pos2;
}
}
}
}
}
}
kfind'KfFileType::init() (./kdeutils/kfind/kftypes.cpp:92)
void KfFileType::init()
{
types = new KfFileTypeList();
QStringList list = KGlobal::dirs()->resourceDirs("mime");
for (QStringList::ConstIterator it = list.begin(); it != list.end(); it++)
initFileTypes( *it );
types->sort();
};
kfind'KfFileType::findByName() (./kdeutils/kfind/kftypes.cpp:103)
KfFileType* KfFileType::findByName( const QString& _name )
{
KfFileType *typ;
for ( typ = types->first(); typ != 0L; typ = types->next() )
{
if (typ->getName() == _name)
return typ;
};
return 0L;
};
kfind'KfFileType::findByPattern() (./kdeutils/kfind/kftypes.cpp:116)
KfFileType* KfFileType::findByPattern( const char *_pattern )
{
KfFileType *typ;
for ( typ = types->first(); typ != 0L; typ = types->next() )
{
QStrList & pattern = typ->getPattern();
char *s;
for ( s = pattern.first(); s != 0L; s = pattern.next() )
if ( strcmp( s, _pattern ) == 0 )
return typ;
}
return 0L;
};
kfind'KfFileType::KfFileType() (./kdeutils/kfind/kftypes.cpp:132)
KfFileType::KfFileType( const char *_name)
{
name = _name;
};