00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __kmimetype_h__
00021 #define __kmimetype_h__
00022
00023 #include <sys/types.h>
00024 #include <sys/stat.h>
00025
00026 #include <qstringlist.h>
00027 #include <qvaluelist.h>
00028 #include <qpixmap.h>
00029
00030 #include <kicontheme.h>
00031 #include <kurl.h>
00032 #include <ksycocatype.h>
00033 #include <kservicetype.h>
00034
00035 class KSimpleConfig;
00047 class KIO_EXPORT KMimeType : public KServiceType
00048 {
00049 K_SYCOCATYPE( KST_KMimeType, KServiceType )
00050
00051 public:
00052 typedef KSharedPtr<KMimeType> Ptr;
00053 typedef QValueList<Ptr> List;
00054 public:
00068 KMimeType( const QString & _fullpath, const QString& _type, const QString& _icon,
00069 const QString& _comment, const QStringList& _patterns );
00070
00075 KMimeType( const QString & _fullpath );
00076
00081 KMimeType( KDesktopFile *config );
00082
00088 KMimeType( QDataStream& _str, int offset );
00089
00090 virtual ~KMimeType();
00091
00100 virtual QString icon( const QString& , bool ) const { return m_strIcon; }
00101
00110 virtual QString icon( const KURL& , bool ) const { return m_strIcon; }
00111
00129 virtual QPixmap pixmap( KIcon::Group group, int force_size = 0, int state = 0,
00130 QString * path = 0L ) const;
00131
00148 virtual QPixmap pixmap( const KURL& _url, KIcon::Group _group, int _force_size = 0,
00149 int _state = 0, QString * _path = 0L ) const;
00150
00169 static QPixmap pixmapForURL( const KURL & _url, mode_t _mode = 0, KIcon::Group _group = KIcon::Desktop,
00170 int _force_size = 0, int _state = 0, QString * _path = 0L );
00171
00172
00185 static QString iconForURL( const KURL & _url, mode_t _mode = 0 );
00186
00196 static QString favIconForURL( const KURL& url );
00197
00202 QString comment() const { return m_strComment; }
00203
00211 virtual QString comment( const QString&, bool ) const { return m_strComment; }
00212
00220 virtual QString comment( const KURL&, bool ) const { return m_strComment; }
00221
00227 const QStringList& patterns() const { return m_lstPatterns; }
00228
00233 virtual void load( QDataStream &qs );
00234
00239 virtual void save( QDataStream &qs );
00240
00247 virtual QVariant property( const QString& _name ) const;
00248
00255 virtual QStringList propertyNames() const;
00256
00271 static Ptr mimeType( const QString& _name );
00272
00301 static Ptr findByURL( const KURL& _url, mode_t _mode = 0,
00302 bool _is_local_file = false, bool _fast_mode = false );
00303
00304 static Ptr findByURL( const KURL& _url, mode_t _mode,
00305 bool _is_local_file, bool _fast_mode,
00306 bool *accurate);
00333 static Ptr findByPath( const QString& path, mode_t mode = 0, bool fast_mode = false );
00334
00345 static Ptr findByContent( const QByteArray &data, int *accuracy=0 );
00346
00360 static Ptr findByFileContent( const QString &fileName, int *accuracy=0 );
00361
00362 struct Format{
00363 bool text : 1;
00364 enum { NoCompression=0, GZipCompression } compression : 4;
00365 unsigned dummy : 27;
00366 };
00367
00373 static Format findFormatByFileContent( const QString &fileName );
00374
00384 static List allMimeTypes();
00385
00393 static const QString & defaultMimeType();
00394
00402 static KMimeType::Ptr defaultMimeTypePtr();
00403
00420 QString parentMimeType() const;
00421
00428 bool is( const QString& mimeTypeName ) const;
00429
00435 static KMimeType::Ptr diagnoseFileName(const QString &file, QString &pattern);
00436
00437 protected:
00438 void loadInternal( QDataStream& );
00439 void init( KDesktopFile * );
00440
00445 static void errorMissingMimeType( const QString& _type );
00446
00450 static void buildDefaultType();
00451
00455 static void checkEssentialMimeTypes();
00459 static bool s_bChecked;
00460
00461 QStringList m_lstPatterns;
00462
00463 static Ptr s_pDefaultType;
00464
00465 protected:
00466 friend class KServiceTypeFactory;
00467 int patternsAccuracy() const;
00468
00469 protected:
00470 virtual void virtual_hook( int id, void* data );
00471 };
00472
00477 class KIO_EXPORT KFolderType : public KMimeType
00478 {
00479 K_SYCOCATYPE( KST_KFolderType, KMimeType )
00480
00481 public:
00482
00483
00484
00489 KFolderType( KDesktopFile *config) : KMimeType( config ) { }
00491 KFolderType( QDataStream& _str, int offset ) : KMimeType( _str, offset ) { }
00492
00493 virtual QString icon( const QString& _url, bool _is_local ) const;
00494 virtual QString icon( const KURL& _url, bool _is_local ) const;
00495 virtual QString comment( const QString& _url, bool _is_local ) const;
00496 virtual QString comment( const KURL& _url, bool _is_local ) const;
00497 protected:
00498 virtual void virtual_hook( int id, void* data );
00499 };
00500
00506 class KIO_EXPORT KDEDesktopMimeType : public KMimeType
00507 {
00508 K_SYCOCATYPE( KST_KDEDesktopMimeType, KMimeType )
00509
00510 public:
00511 enum ServiceType { ST_MOUNT, ST_UNMOUNT, ST_USER_DEFINED };
00512
00517 struct Service
00518 {
00519 Service() { m_display = true; }
00520 bool isEmpty() const { return m_strName.isEmpty(); }
00521 QString m_strName;
00522 QString m_strIcon;
00523 QString m_strExec;
00524 ServiceType m_type;
00525 bool m_display;
00526 };
00527
00528
00529
00534 KDEDesktopMimeType( KDesktopFile *config) : KMimeType( config ) { }
00536 KDEDesktopMimeType( QDataStream& _str, int offset ) : KMimeType( _str, offset ) { }
00537
00538 virtual QString icon( const QString& _url, bool _is_local ) const;
00539 virtual QString icon( const KURL& _url, bool _is_local ) const;
00540 virtual QPixmap pixmap( const KURL& _url, KIcon::Group _group, int _force_size = 0,
00541 int _state = 0, QString * _path = 0L ) const;
00542 virtual QString comment( const QString& _url, bool _is_local ) const;
00543 virtual QString comment( const KURL& _url, bool _is_local ) const;
00544
00550 static QValueList<Service> builtinServices( const KURL& _url );
00561 static QValueList<Service> userDefinedServices( const QString& path, bool bLocalFiles );
00562
00568 static QValueList<Service> userDefinedServices( const QString& path, KConfig& config, bool bLocalFiles );
00569
00576 static QValueList<Service> userDefinedServices( const QString& path, KConfig& config, bool bLocalFiles, const KURL::List & file_list);
00577
00583 static void executeService( const QString& path, KDEDesktopMimeType::Service& service ) KDE_DEPRECATED;
00584
00590 static void executeService( const KURL::List& urls, KDEDesktopMimeType::Service& service );
00591
00603 static pid_t run( const KURL& _url, bool _is_local );
00604
00605 protected:
00606 virtual QPixmap pixmap( KIcon::Group group, int force_size = 0, int state = 0,
00607 QString * path = 0L ) const
00608 { return KMimeType::pixmap( group, force_size, state, path ); }
00609
00610 static pid_t runFSDevice( const KURL& _url, const KSimpleConfig &cfg );
00611 static pid_t runApplication( const KURL& _url, const QString & _serviceFile );
00612 static pid_t runLink( const KURL& _url, const KSimpleConfig &cfg );
00613 static pid_t runMimeType( const KURL& _url, const KSimpleConfig &cfg );
00614 protected:
00615 virtual void virtual_hook( int id, void* data );
00616 };
00617
00622 class KIO_EXPORT KExecMimeType : public KMimeType
00623 {
00624 K_SYCOCATYPE( KST_KExecMimeType, KMimeType )
00625
00626 public:
00627
00628
00629
00634 KExecMimeType( KDesktopFile *config) : KMimeType( config ) { }
00636 KExecMimeType( QDataStream& _str, int offset ) : KMimeType( _str, offset ) { }
00637 protected:
00638 virtual void virtual_hook( int id, void* data );
00639 };
00640
00641 #endif