foobar2000 SDK  2015-08-03
mainmenu.cpp
Go to the documentation of this file.
1 #include "foobar2000.h"
2 
3 bool mainmenu_commands::g_execute_dynamic(const GUID & p_guid, const GUID & p_subGuid,service_ptr_t<service_base> p_callback) {
4  mainmenu_commands::ptr ptr; t_uint32 index;
5  if (!menu_item_resolver::g_resolve_main_command(p_guid, ptr, index)) return false;
6  mainmenu_commands_v2::ptr v2;
7  if (!ptr->service_query_t(v2)) return false;
8  if (!v2->is_command_dynamic(index)) return false;
9  return v2->dynamic_execute(index, p_subGuid, p_callback);
10 }
12  mainmenu_commands::ptr ptr; t_uint32 index;
13  if (!menu_item_resolver::g_resolve_main_command(p_guid, ptr, index)) return false;
14  ptr->execute(index, p_callback);
15  return true;
16 }
17 
18 bool mainmenu_commands::g_find_by_name(const char * p_name,GUID & p_guid) {
22  while(e.next(ptr)) {
23  const t_uint32 count = ptr->get_command_count();
24  for(t_uint32 n=0;n<count;n++) {
25  ptr->get_name(n,temp);
26  if (stricmp_utf8(temp,p_name) == 0) {
27  p_guid = ptr->get_command(n);
28  return true;
29  }
30  }
31  }
32  return false;
33 
34 }
35 
36 
37 static bool dynamic_execute_recur(mainmenu_node::ptr node, const GUID & subID, service_ptr_t<service_base> callback) {
38  switch(node->get_type()) {
39  case mainmenu_node::type_command:
40  if (subID == node->get_guid()) {
41  node->execute(callback); return true;
42  }
43  break;
44  case mainmenu_node::type_group:
45  {
46  const t_size total = node->get_children_count();
47  for(t_size walk = 0; walk < total; ++walk) {
48  if (dynamic_execute_recur(node->get_child(walk), subID, callback)) return true;
49  }
50  }
51  break;
52  }
53  return false;
54 }
56  return dynamic_execute_recur(dynamic_instantiate(index), subID, callback);
57 }
static bool g_find_by_name(const char *p_name, GUID &p_guid)
Definition: mainmenu.cpp:18
virtual bool dynamic_execute(t_uint32 index, const GUID &subID, service_ptr_t< service_base > callback)
Default fallback implementation provided.
Definition: mainmenu.cpp:55
Definition: pfc.h:71
static bool g_execute_dynamic(const GUID &p_guid, const GUID &p_subGuid, service_ptr_t< service_base > p_callback=NULL)
Definition: mainmenu.cpp:3
int SHARED_EXPORT stricmp_utf8(const char *p1, const char *p2)
static bool g_resolve_main_command(const GUID &id, service_ptr_t< class mainmenu_commands > &out, t_uint32 &out_index)
size_t t_size
Definition: int_types.h:48
static bool dynamic_execute_recur(mainmenu_node::ptr node, const GUID &subID, service_ptr_t< service_base > callback)
Definition: mainmenu.cpp:37
static bool g_execute(const GUID &p_guid, service_ptr_t< service_base > p_callback=NULL)
Definition: mainmenu.cpp:11
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
bool next(service_ptr_t< t_query > &p_out)
Definition: service.h:587
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
Definition: string_base.h:436
uint32_t t_uint32
Definition: int_types.h:5