Loads different files by using registered loaders based on MIME-type Has two kinds of mappings. More...
#include <MultiWidgets/Mime.hpp>
Classes | |
| class | Loader |
| A Loader loads different files based on file extensions or mime types. More... | |
| class | LoaderOptions |
| This is passed to all the loaders as a parameter when loading Can only be constructed by Mime-class. More... | |
Public Types | |
| typedef std::list< Loader * > | MimeLoaderList |
| List of different Mime-loaders. | |
|
typedef std::map< QString, MimeLoaderList > | MimeMap |
| Mapping from Mime-descriptors to appropriate Mime-loaders. | |
Public Member Functions | |
| void | insertLoader (const QString &type, Loader *loader) |
| Insert a instance-specific loader for a given type. More... | |
| WidgetPtr | load (const QString &filename, bool guessContent=false) |
| Tries to load file in a suitable Widget. More... | |
| Radiant::TaskPtr | loadAsync (const QString &filename, std::function< void(const WidgetPtr &w)> callback, Valuable::Node::ListenerType type) |
| Load the given file asynchronously. More... | |
| WidgetPtr | loadSynchronous (const QString &filename, bool guessContent=false) |
| Tries to load file in a suitable Widget synchronously Synchronous loading means that the widget is ready to use after this function returns. More... | |
| Mime () | |
| Constructor. More... | |
| virtual | ~Mime () |
| Destructor Deallocates loaders of this Mime. | |
Public Member Functions inherited from Radiant::MimeManager | |
| QStringList | extensionsByMimeRegexp (const QString &mime) const |
| Get a list of file extensions that match the given mime type. More... | |
| void | insertExtension (const QString &extension, const MimeType &type) |
| Add or replace a shared mapping from file extension to mime type. More... | |
| const MimeType * | mimeTypeByExtension (const QString &ext) const |
| Get the mime type by filename extension. More... | |
Static Public Member Functions | |
| static void | insertSharedLoader (const QString &type, Loader *loader) |
| Insert a global loader shared for all Mime-objects. More... | |
Static Public Member Functions inherited from Radiant::MimeManager | |
| static void | insertSharedExtension (const QString &extension, const MimeType &type) |
| Add or replace a shared mapping from file extension to mime type. More... | |
Additional Inherited Members | |
Protected Types inherited from Radiant::MimeManager | |
|
typedef std::map< QString, MimeType > | ExtensionMap |
| Map from file extensions to mime types. | |
Protected Attributes inherited from Radiant::MimeManager | |
| ExtensionMap | m_extensions |
| Extension map specific for this instance. | |
Static Protected Attributes inherited from Radiant::MimeManager | |
| static ExtensionMap | s_sharedExtensions |
| Global extension map shared by all instances. | |
Loads different files by using registered loaders based on MIME-type Has two kinds of mappings.
Usage example:
class MyLoader : public Mime::Loader { virtual WidgetPtr load(const QString & filename, const Mime::LoaderOptions & options) { MyWidgetPtr widget = MultiWidgets::create<MyWidget>(); if (widget->load(filename)) { return widget; } else { delete widget; return 0; } } }; MultiWidgets::Mime mime; mime.addLoader("image/png", new MyLoader()); Widget * w = mime.load("myfile.png"); if (w) w->changeParent(some_widget);
Predefined shared loaders:
| MultiWidgets::Mime::Mime | ( | ) |
Constructor.
Initializes predefined shared loaders.
| void MultiWidgets::Mime::insertLoader | ( | const QString & | type, |
| Loader * | loader | ||
| ) |
|
static |
Insert a global loader shared for all Mime-objects.
Mime-class manages the deallocation of the loaders.
| WidgetPtr MultiWidgets::Mime::load | ( | const QString & | filename, |
| bool | guessContent = false |
||
| ) |
Tries to load file in a suitable Widget.
Widget returned may not be yet ready for the usage because loading requests are asynchronous.
The MIME type is deduced from the file extension. Instance specific loaders take precedence over shared loaders. Multiple loaders can be defined for the same type, the loaders are tried in insertion order. The lookup chain is as follows:
The loaders are tried in order until some loader has successfully loaded the file.
| filename | Filename to load |
| guessContent | This paramter is ignored, not implemented yet |
| Radiant::TaskPtr MultiWidgets::Mime::loadAsync | ( | const QString & | filename, |
| std::function< void(const WidgetPtr &w)> | callback, | ||
| Valuable::Node::ListenerType | type | ||
| ) |
Load the given file asynchronously.
This function creates a task to load the given filename in a background thread. The given callback function will be executed with the created widget as a parameter when the widget is in Valuable::STATE_READY state. The behaviour is similar to that of MultiWidgets::BaseMediaWidget::onReady(). The callback function can be executed in the main-thread or in the background thread depending on the value of the type parameter.
| filename | filename to load |
| callback | callback function to execute when loading is complete |
| type | type of the callback |
| WidgetPtr MultiWidgets::Mime::loadSynchronous | ( | const QString & | filename, |
| bool | guessContent = false |
||
| ) |
Tries to load file in a suitable Widget synchronously Synchronous loading means that the widget is ready to use after this function returns.
For example in the case of images it means that their size is set correctly but some of the mipmap-levels may still be loading.
The MIME type is deduced from the file extension. Instance specific loaders take precedence over shared loaders. Multiple loaders can be defined for the same type, the loaders are tried in insertion order. The lookup chain is as follows:
The loaders are tried in order until some loader has successfully loaded the file.
| filename | Filename to load |