summaryrefslogtreecommitdiffstats
path: root/bin/tools/common.c
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@gmail.com>2013-04-18 09:04:30 +0200
committerMatthias Vogelgesang <matthias.vogelgesang@gmail.com>2013-04-18 09:04:30 +0200
commite4edf31c86f3ea891fe493450c6eb134542095e5 (patch)
treefe103e514b64afc2142171eff4831fc26830d278 /bin/tools/common.c
parent39ecb01bbc9fe9a75d444484e3e3ec9028fe1484 (diff)
downloaduca-e4edf31c86f3ea891fe493450c6eb134542095e5.tar.gz
uca-e4edf31c86f3ea891fe493450c6eb134542095e5.tar.bz2
uca-e4edf31c86f3ea891fe493450c6eb134542095e5.tar.xz
uca-e4edf31c86f3ea891fe493450c6eb134542095e5.zip
Build list of cameras only in one place
Diffstat (limited to 'bin/tools/common.c')
-rw-r--r--bin/tools/common.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/bin/tools/common.c b/bin/tools/common.c
new file mode 100644
index 0000000..6ada379
--- /dev/null
+++ b/bin/tools/common.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 2011-2013 Matthias Vogelgesang <matthias.vogelgesang@kit.edu>
+ (Karlsruhe Institute of Technology)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License along
+ with this library; if not, write to the Free Software Foundation, Inc., 51
+ Franklin St, Fifth Floor, Boston, MA 02110, USA */
+
+#include "common.h"
+
+
+static gchar *
+get_camera_list (UcaPluginManager *manager)
+{
+ GList *types;
+ GString *str;
+
+ manager = uca_plugin_manager_new ();
+ types = uca_plugin_manager_get_available_cameras (manager);
+ str = g_string_new ("[ ");
+
+ if (types != NULL) {
+ for (GList *it = g_list_first (types); it != NULL; it = g_list_next (it)) {
+ gchar *name = (gchar *) it->data;
+
+ if (g_list_next (it) == NULL)
+ g_string_append_printf (str, "%s ]", name);
+ else
+ g_string_append_printf (str, "%s, ", name);
+ }
+ }
+ else {
+ g_string_append (str, "]");
+ }
+
+ g_object_unref (manager);
+ return g_string_free (str, FALSE);
+}
+
+GOptionContext *
+uca_option_context_new (UcaPluginManager *manager)
+{
+ GOptionContext *context;
+ gchar *camera_list;
+
+ camera_list = get_camera_list (manager);
+ context = g_option_context_new (camera_list);
+ g_free (camera_list);
+
+ return context;
+}