ladish/gui/studio_list.c

125 lines
3.1 KiB
C
Raw Normal View History

/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains the studio list handling code
**************************************************************************
*
* LADI Session Handler is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LADI Session Handler 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "internal.h"
#include "gtk_builder.h"
#include "../proxies/control_proxy.h"
2010-10-16 01:39:06 +03:00
#include "dynmenu.h"
2010-10-16 01:39:06 +03:00
static ladish_dynmenu_handle g_load_studio_list;
static ladish_dynmenu_handle g_delete_studio_list;
struct ladish_studio_list_closure
{
2010-10-16 01:39:06 +03:00
void
(* callback)(
void * context,
const char * name,
void * data,
ladish_dynmenu_item_activate_callback item_activate_callback,
2010-10-16 01:39:06 +03:00
void (* data_free)());
void * context;
};
2010-10-16 01:39:06 +03:00
#define closure_ptr ((struct ladish_studio_list_closure * )context)
2010-10-16 01:39:06 +03:00
static
void
add_item(
void * context,
const char * studio_name)
{
closure_ptr->callback(closure_ptr->context, studio_name, NULL, NULL, NULL);
}
2010-10-16 01:39:06 +03:00
#undef closure_ptr
2010-10-16 01:39:06 +03:00
static
bool
fill_callback(
void
(* callback)(
void * context,
const char * name,
void * data,
ladish_dynmenu_item_activate_callback item_activate_callback,
2010-10-16 01:39:06 +03:00
void (* data_free)()),
void * context)
{
struct ladish_studio_list_closure closure;
2010-10-16 01:39:06 +03:00
closure.callback = callback;
closure.context = context;
2010-10-16 01:39:06 +03:00
return control_proxy_get_studio_list(add_item, &closure);
}
2010-10-16 01:39:06 +03:00
static void on_load_studio_wrapper(const char * name, void * data)
{
ASSERT(data == NULL);
on_load_studio(name);
}
2010-10-16 01:39:06 +03:00
static void on_delete_studio_wrapper(const char * name, void * data)
{
2010-10-16 01:39:06 +03:00
ASSERT(data == NULL);
on_delete_studio(name);
}
2010-10-16 01:39:06 +03:00
bool create_studio_lists(void)
{
2010-10-16 01:39:06 +03:00
if (!ladish_dynmenu_create(
"menu_item_load_studio",
"load_studio_menu",
fill_callback,
"studio list",
on_load_studio_wrapper,
&g_load_studio_list))
{
2010-10-16 01:39:06 +03:00
return false;
}
2010-10-16 01:39:06 +03:00
if (!ladish_dynmenu_create(
"menu_item_delete_studio",
"delete_studio_menu",
fill_callback,
"studio list",
on_delete_studio_wrapper,
&g_delete_studio_list))
{
2010-10-16 01:39:06 +03:00
ladish_dynmenu_destroy(g_load_studio_list);
return false;
}
2010-10-16 01:39:06 +03:00
return true;
}
2010-10-16 01:39:06 +03:00
void destroy_studio_lists(void)
{
2010-10-16 01:39:06 +03:00
ladish_dynmenu_destroy(g_delete_studio_list);
ladish_dynmenu_destroy(g_load_studio_list);
}