From e4edf31c86f3ea891fe493450c6eb134542095e5 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 18 Apr 2013 09:04:30 +0200 Subject: Build list of cameras only in one place --- bin/tools/common.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 bin/tools/common.c (limited to 'bin/tools/common.c') 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 + (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; +} -- cgit v1.2.3