Added qmafw-gst-subtitles-renderer-0.0.55 for Meego Harmattan 1.2
[mafwsubrenderer] / qmafw-gst-subtitles-renderer / inc / MafwGstRendererPlaylistFileUtility.h
1 #ifndef MafwGstRendererPlaylistFileUtility_H
2 #define MafwGstRendererPlaylistFileUtility_H
3
4 #include <QObject>
5 #include <QStringList>
6 #include <totem-pl-parser/1/plparser/totem-pl-parser.h>
7 #include <MafwError.h>
8
9 class QUrl;
10
11 /**
12  * Utility class for parsing playlist files.
13  */
14 class MafwGstRendererPlaylistFileUtility : public QObject
15 {
16     Q_OBJECT
17 public:
18     /**
19      * Constructor
20      */
21     MafwGstRendererPlaylistFileUtility(QObject* parent);
22
23     /**
24      * Destructor
25      */
26     ~MafwGstRendererPlaylistFileUtility();
27
28     /**
29      * Returns the parsed URI list
30      * @return list of parsed URIs
31      */
32     QStringList getUriList();
33
34     /**
35      * Starts playlist file parsing, parsingReady is signalled when parsing
36      * has been done. Parsed uris can be fetched using getUri() function.
37      * @param uri The absolute uri to the playlist file.
38      */
39     void parsePlaylistFile(const QUrl& uri);
40
41     /**
42      * Removes the first unused uri parsed from playlist and returns it.
43      * @return The first unused playlist uri or empty string if each uris are
44      * used or parsing has been failed.
45      */
46     QString takeFirstUri();
47
48     /**
49      * Saves the pending error that will be fired, if no new URI's are found.
50      * This error saving feature is needed because we don't get the proper
51      * "parsing ended" signals from Totem playlist parser.
52      * @param error The error to be saved.
53      */
54     void setPendingError(MafwError& error);
55
56     /**
57      * Returns the saved error.
58      * @return The saved error.
59      */
60     MafwError takePendingError();
61
62 Q_SIGNALS:
63     /** Signal telling that first uri on playlist file is parsed. */
64     void firstItemParsed();
65     /** Signal telling that parsing is ready. */
66     void parsingReady(bool succeeded);
67
68 private:
69     static void readyCb(TotemPlParser* parser,
70                         GAsyncResult *async_result,
71                         MafwGstRendererPlaylistFileUtility* self);
72     static void uriParsed(TotemPlParser *parser,
73                           gchar* uri,
74                           gpointer metadata,
75                           MafwGstRendererPlaylistFileUtility* self);
76
77 private:
78     /** Modifies the resulting item URI if necessary.
79      * Unfortunately there are various reasons why this is required.
80      */
81     QString manHandleURI(const QString &itemUri) const;
82
83 private:
84     /** Unique id (=pointer) of currently used parser. */
85     TotemPlParser* m_parserId;
86     /** The list of parsed uris. */
87     QStringList m_uriList;
88     /** Parsing the first item */
89     bool m_firstItem;
90     /** The pending error */
91     MafwError m_pendingError;
92 };
93
94 #endif // MafwGstRendererPlaylistFileUtility_H