4e25e0653ea4b7f26e1c52e1717fe89ded82913f
[libquvi.git] / src / api / subtitle_lang_get.c
blob4e25e0653ea4b7f26e1c52e1717fe89ded82913f
1 /* libquvi
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_lang_get.c */
23 #include "config.h"
25 #include <glib.h>
27 #include "quvi.h"
28 /* -- */
29 #include "_quvi_s.h"
30 #include "_quvi_subtitle_s.h"
32 static QuviError _get(_quvi_subtitle_lang_t qsl,
33 const QuviSubtitleLangProperty n, ...)
35 QuviError rc;
36 gdouble *dp;
37 va_list arg;
38 gchar **sp;
39 glong *lp;
40 gint type;
42 va_start(arg, n);
43 type = QUVI_SUBTITLE_PROPERTY_TYPE_MASK & (gint) n;
45 rc = QUVI_OK;
46 dp = NULL;
47 sp = NULL;
48 lp = NULL;
50 switch (type)
52 case QUVI_MEDIA_PROPERTY_TYPE_STRING:
53 sp = va_arg(arg, gchar**);
54 if (sp == NULL)
55 rc = QUVI_ERROR_INVALID_ARG;
56 break;
58 case QUVI_MEDIA_PROPERTY_TYPE_LONG:
59 lp = va_arg(arg, glong*);
60 if (lp == NULL)
61 rc = QUVI_ERROR_INVALID_ARG;
62 break;
64 case QUVI_MEDIA_PROPERTY_TYPE_DOUBLE:
65 dp = va_arg(arg, gdouble*);
66 if (dp == NULL)
67 rc = QUVI_ERROR_INVALID_ARG;
68 break;
70 default:
71 rc = QUVI_ERROR_INVALID_ARG;
72 break;
74 va_end(arg);
76 if (rc != QUVI_OK)
77 return (rc);
79 switch (n)
82 * NOTE: Advances to the first item in the 'language' list if the
83 * current pointer is still set to NULL.
86 case QUVI_SUBTITLE_LANG_PROPERTY_TRANSLATED:
87 *sp = qsl->translated->str;
88 break;
90 case QUVI_SUBTITLE_LANG_PROPERTY_ORIGINAL:
91 *sp = qsl->original->str;
92 break;
94 case QUVI_SUBTITLE_LANG_PROPERTY_CODE:
95 *sp = qsl->code->str;
96 break;
98 case QUVI_SUBTITLE_LANG_PROPERTY_URL:
99 *sp = qsl->url->str;
100 break;
102 case QUVI_SUBTITLE_LANG_PROPERTY_ID:
103 *sp = qsl->id->str;
104 break;
106 default:
107 rc = QUVI_ERROR_INVALID_ARG;
108 break;
110 return (rc);
113 /** @brief Return a subtitle property
114 @sa @ref parse_subtitle
115 @ingroup subprop
117 void quvi_subtitle_lang_get(quvi_subtitle_lang_t handle,
118 QuviSubtitleLangProperty n, ...)
120 _quvi_subtitle_lang_t qsl;
121 va_list arg;
122 gpointer p;
123 _quvi_t q;
125 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
126 g_return_if_fail(handle != NULL);
128 va_start(arg, n);
129 p = va_arg(arg, gpointer);
130 va_end(arg);
132 qsl = (_quvi_subtitle_lang_t) handle;
133 q = qsl->handle.quvi;
135 q->status.rc = _get(qsl, n, p);
138 /* vim: set ts=2 sw=2 tw=72 expandtab: */