2 * Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 /** @file subtitle_select.c */
25 #include <glib/gi18n-lib.h>
31 #include "_quvi_subtitle_s.h"
35 static _quvi_subtitle_lang_t
_match(_quvi_subtitle_t qsub
, const gchar
*id
)
37 _quvi_subtitle_type_t qst
;
38 _quvi_subtitle_lang_t qsl
;
40 quvi_subtitle_type_reset(qsub
);
42 while ( (qst
= quvi_subtitle_type_next(qsub
)) != NULL
)
44 quvi_subtitle_lang_reset(qst
);
45 while ( (qsl
= quvi_subtitle_lang_next(qst
)) != NULL
)
47 if (m_match(qsl
->id
->str
, id
) == TRUE
)
54 /* Return the first available language of the first available type. */
55 static _quvi_subtitle_lang_t
_default(_quvi_subtitle_t qsub
)
57 _quvi_subtitle_type_t qst
;
59 quvi_subtitle_type_reset(qsub
);
60 qst
= quvi_subtitle_type_next(qsub
);
62 quvi_subtitle_lang_reset(qst
);
63 return (quvi_subtitle_lang_next(qst
));
66 static _quvi_subtitle_lang_t
_select(_quvi_subtitle_t qsub
, const gchar
*id
)
68 _quvi_subtitle_lang_t qsl
;
73 r
= g_strsplit(id
, ",", 0);
74 q
= qsub
->handle
.quvi
;
76 q
->status
.rc
= QUVI_OK
;
79 for (i
=0; (r
[i
] != NULL
&& qsl
== NULL
); ++i
)
81 if (g_strcmp0(r
[i
], "croak") ==0)
83 q
->status
.rc
= QUVI_ERROR_KEYWORD_CROAK
;
87 qsl
= _match(qsub
, r
[i
]);
90 return ((qsl
== NULL
&& q
->status
.rc
== QUVI_OK
)
95 /** @brief Select a @ref sub_lang matching a @ref sub_lang_id
97 Matches the @ref sub_lang_id (pattern) to the available subtitle
98 language IDs and selects the language. This function returns immediately
99 if a matching ID was found. The ID value may be a comma-separated value
100 (e.g. "foo,bar,baz"). The ID may also contain the keyword 'croak' (see
103 - ID value is used as regular expression pattern
104 - ID may contain the keyword 'croak'
105 - This will cause the function to exit immediately when it is reached
106 - The result may be checked with @ref quvi_ok
107 - The code may be retrieved using @ref quvi_get
108 - The error message may be retrieved using @ref quvi_errmsg
109 - If nothing matched (and the 'croak' keyword was specified) the
110 function will return the first (default) available language
111 - Always confirm the result with @ref quvi_ok
112 - Calling this function will reset the list pointers for both
113 @ref sub_type and @ref sub_lang
114 @sa @ref parse_subtitle
115 @sa quvi_subtitle_type_reset
116 @sa quvi_subtitle_lang_reset
117 @sa quvi_subtitle_type_next
118 @sa quvi_subtitle_lang_next
119 @sa quvi_subtitle_new
122 const quvi_subtitle_lang_t
123 quvi_subtitle_select(quvi_subtitle_t handle
, const char *id
)
125 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
126 g_return_val_if_fail(handle
!= NULL
, NULL
);
127 g_return_val_if_fail(id
!= NULL
, NULL
);
129 return (_select(handle
, id
));
132 /* vim: set ts=2 sw=2 tw=72 expandtab: */