Add misc/url.* with m_url_(un)escaped_form
[libquvi.git] / src / api / script_get.c
blob96e2b4cefc2f7e70eb79b65197ec4f8ec26ca124
1 /* libquvi
2 * Copyright (C) 2012-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 script_get.c */
23 #include "config.h"
25 #include <glib.h>
27 #include "quvi.h"
28 /* -- */
29 #include "_quvi_s.h"
30 #include "_quvi_script_s.h"
32 /** @cond NODOC */
33 typedef _quvi_script_t _qs_t;
34 /** @endcond */
36 static QuviError _get(_quvi_t q, QuviScriptType stype,
37 QuviScriptProperty n, ...)
39 QuviError rc;
40 gpointer *vp;
41 gdouble *dp;
42 va_list arg;
43 gchar **sp;
44 glong *lp;
45 gint type;
46 _qs_t qs;
48 switch (stype)
50 case QUVI_SCRIPT_TYPE_SUBTITLE_EXPORT:
51 qs = (_qs_t) q->scripts.curr.subtitle_export->data;
52 break;
54 case QUVI_SCRIPT_TYPE_SUBTITLE:
55 qs = (_qs_t) q->scripts.curr.subtitle->data;
56 break;
58 case QUVI_SCRIPT_TYPE_PLAYLIST:
59 qs = (_qs_t) q->scripts.curr.playlist->data;
60 break;
62 case QUVI_SCRIPT_TYPE_MEDIA:
63 default:
64 qs = (_qs_t) q->scripts.curr.media->data;
65 break;
67 case QUVI_SCRIPT_TYPE_SCAN:
68 qs = (_qs_t) q->scripts.curr.scan->data;
69 break;
72 va_start(arg, n);
73 type = QUVI_SCRIPT_PROPERTY_MASK & (gint) n;
75 dp = NULL;
76 sp = NULL;
77 vp = NULL;
78 lp = NULL;
80 rc = QUVI_OK;
82 switch (type)
84 case QUVI_SCRIPT_PROPERTY_TYPE_DOUBLE:
85 dp = va_arg(arg, gdouble*);
86 if (dp == NULL)
87 rc = QUVI_ERROR_INVALID_ARG;
88 break;
90 case QUVI_SCRIPT_PROPERTY_TYPE_STRING:
91 sp = va_arg(arg, gchar**);
92 if (sp == NULL)
93 rc = QUVI_ERROR_INVALID_ARG;
94 break;
96 case QUVI_SCRIPT_PROPERTY_TYPE_LONG:
97 lp = va_arg(arg, glong*);
98 if (lp == NULL)
99 rc = QUVI_ERROR_INVALID_ARG;
100 break;
102 case QUVI_SCRIPT_PROPERTY_TYPE_VOID:
103 vp = va_arg(arg, gpointer*);
104 if (vp == NULL)
105 rc = QUVI_ERROR_INVALID_ARG;
106 break;
108 default:
109 rc = QUVI_ERROR_INVALID_ARG;
110 break;
112 va_end(arg);
114 if (rc != QUVI_OK)
115 return (rc);
117 switch (n)
119 /* Export (e.g. subtitle) */
120 case QUVI_SCRIPT_PROPERTY_EXPORT_FORMAT:
121 *sp = qs->export.format->str;
122 break;
124 /* Media, playlist. */
125 case QUVI_SCRIPT_PROPERTY_DOMAINS:
126 *sp = qs->domains->str;
127 break;
129 /* Any */
130 case QUVI_SCRIPT_PROPERTY_FILEPATH:
131 *sp = qs->fpath->str;
132 break;
133 case QUVI_SCRIPT_PROPERTY_FILENAME:
134 *sp = qs->fname->str;
135 break;
136 case QUVI_SCRIPT_PROPERTY_SHA1:
137 *sp = qs->sha1->str;
138 break;
140 default:
141 rc = QUVI_ERROR_INVALID_ARG;
142 break;
144 return (rc);
147 /** @brief Return a script property
148 @ingroup script
150 void quvi_script_get(quvi_t handle, QuviScriptType type,
151 QuviScriptProperty id, ...)
153 va_list arg;
154 gpointer p;
155 _quvi_t q;
157 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
158 g_return_if_fail(handle != NULL);
160 va_start(arg, id);
161 p = va_arg(arg, gpointer);
162 va_end(arg);
164 q = (_quvi_t) handle;
165 q->status.rc = _get(handle, type, id, p);
168 /* vim: set ts=2 sw=2 tw=72 expandtab: */