src/api/: Use intended license header
[libquvi.git] / src / api / script_get.c
bloba189c53de3d1fcd6f476b5f925cc1b9acba26a57
1 /* libquvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA
20 /** @file script_get.c */
22 #include "config.h"
24 #include <glib.h>
26 #include "quvi.h"
27 /* -- */
28 #include "_quvi_s.h"
29 #include "_quvi_script_s.h"
31 /** @cond NODOC */
32 typedef _quvi_script_t _qs_t;
33 /** @endcond */
35 static QuviError _get(_quvi_t q, QuviScriptType stype,
36 QuviScriptProperty n, ...)
38 QuviError rc;
39 gpointer *vp;
40 gdouble *dp;
41 va_list arg;
42 gchar **sp;
43 glong *lp;
44 gint type;
45 _qs_t qs;
47 switch (stype)
49 case QUVI_SCRIPT_TYPE_PLAYLIST:
50 qs = (_qs_t) q->scripts.curr.playlist->data;
51 break;
52 case QUVI_SCRIPT_TYPE_MEDIA:
53 default:
54 qs = (_qs_t) q->scripts.curr.media->data;
55 break;
56 case QUVI_SCRIPT_TYPE_SCAN:
57 qs = (_qs_t) q->scripts.curr.scan->data;
58 break;
61 va_start(arg, n);
62 type = QUVI_SCRIPT_PROPERTY_MASK & (gint) n;
64 dp = NULL;
65 sp = NULL;
66 vp = NULL;
67 lp = NULL;
69 rc = QUVI_OK;
71 switch (type)
73 case QUVI_SCRIPT_PROPERTY_TYPE_DOUBLE:
74 dp = va_arg(arg, gdouble*);
75 if (dp == NULL)
76 rc = QUVI_ERROR_INVALID_ARG;
77 break;
78 case QUVI_SCRIPT_PROPERTY_TYPE_STRING:
79 sp = va_arg(arg, gchar**);
80 if (sp == NULL)
81 rc = QUVI_ERROR_INVALID_ARG;
82 break;
83 case QUVI_SCRIPT_PROPERTY_TYPE_LONG:
84 lp = va_arg(arg, glong*);
85 if (lp == NULL)
86 rc = QUVI_ERROR_INVALID_ARG;
87 break;
88 case QUVI_SCRIPT_PROPERTY_TYPE_VOID:
89 vp = va_arg(arg, gpointer*);
90 if (vp == NULL)
91 rc = QUVI_ERROR_INVALID_ARG;
92 break;
93 default:
94 rc = QUVI_ERROR_INVALID_ARG;
95 break;
97 va_end(arg);
99 if (rc != QUVI_OK)
100 return (rc);
102 switch (n)
104 /* Media, playlist. */
105 case QUVI_SCRIPT_PROPERTY_DOMAINS:
106 *sp = qs->domains->str;
107 break;
108 /* Any */
109 case QUVI_SCRIPT_PROPERTY_FILEPATH:
110 *sp = qs->fpath->str;
111 break;
112 case QUVI_SCRIPT_PROPERTY_FILENAME:
113 *sp = qs->fname->str;
114 break;
115 case QUVI_SCRIPT_PROPERTY_SHA1:
116 *sp = qs->sha1->str;
117 break;
118 default:
119 rc = QUVI_ERROR_INVALID_ARG;
120 break;
122 return (rc);
125 /** @brief Return a media script property
126 @ingroup script
128 void quvi_script_get(quvi_t handle, QuviScriptType type,
129 QuviScriptProperty id, ...)
131 va_list arg;
132 gpointer p;
133 _quvi_t q;
135 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
136 g_return_if_fail(handle != NULL);
138 va_start(arg, id);
139 p = va_arg(arg, gpointer);
140 va_end(arg);
142 q = (_quvi_t) handle;
144 q->status.rc = _get(handle, type, id, p);
147 /* vim: set ts=2 sw=2 tw=72 expandtab: */