Kestrel Interface
Loading...
Searching...
No Matches
kest_page_id.c
Go to the documentation of this file.
1#include "kest_int.h"
2
3#ifndef PRINTLINES_ALLOWED
4#define PRINTLINES_ALLOWED 0
5#endif
6
7static const char *FNAME = "kest_page_id.c";
8
10{
11 KEST_PRINTF("kest_page_id_find_page; searching for the page described by {.type = %d, .id = %d, .fname = \"%s\"}\n",
12 id.type, id.id, id.fname);
13
14 if (!cxt)
15 return NULL;
16
17 kest_ui_page *page;
19 kest_effect *effect = NULL;
20 kest_profile *profile = NULL;
21 kest_sequence *seq = NULL;
22
23 switch (id.type)
24 {
25 case KEST_UI_PAGE_MAIN_MENU: KEST_PRINTF("It is simply the main menu !\n"); return &cxt->pages.main_menu;
26 case KEST_UI_PAGE_SEQ_LIST: KEST_PRINTF("It is simply the sequence list !\n"); return &cxt->pages.sequence_list;
27 case KEST_UI_PAGE_MSV: KEST_PRINTF("It is simply the main sequence view !\n"); return &cxt->pages.main_sequence_view;
29 KEST_PRINTF("It is a sequence view.\n");
30 seq = cxt_get_sequence_by_fname(cxt, id.fname);
31
32 if (!seq) return NULL;
33 else return seq->view_page;
34
36 KEST_PRINTF("It is a profile view.\n");
37 profile = cxt_get_profile_by_fname(cxt, id.fname);
38
39 if (!profile) return NULL;
40 else return profile->view_page;
41
43 KEST_PRINTF("It is a effect view. First, search for the profile with fname \"%s\"\n", id.fname);
44 profile = cxt_get_profile_by_fname(cxt, id.fname);
45 KEST_PRINTF("The returned profile: %p\n", profile);
46 if (!profile)
47 {
48 KEST_PRINTF("Unforunately, it is NULL! All is lost!\n");
49 return NULL;
50 }
51
52 KEST_PRINTF("It is non-NULL! Yay!. Now we must try to find among it the desired effect; it has ID %d\n", id.id);
53
54 effect = kest_profile_get_effect_by_id(profile, id.id);
55
56 if (!effect)
57 {
58 KEST_PRINTF("The effect was not found. No chance of locating the page. Return NULL\n");
59 return NULL;
60 }
61 else
62 {
63 KEST_PRINTF("The effect was found! Its view page is %p.\n", effect->view_page);
64 KEST_PRINTF("Send it.\n");
65 return effect->view_page;
66 }
67
69 KEST_PRINTF("It is a effect settings page.\n");
70 profile = cxt_get_profile_by_fname(cxt, id.fname);
71
72 if (!profile) return NULL;
73
74 effect = kest_profile_get_effect_by_id(profile, id.id);
75
76 if (!effect) return NULL;
77 page = effect->view_page;
78 tv_str = (kest_effect_view_str*)page->data_struct;
79
80 if (!tv_str) return NULL;
81 else return tv_str->settings_page;
82
83 default:
84 return NULL;
85 }
86
87 KEST_PRINTF("Couldn't find it :(\n");
88
89 return NULL;
90}
91
93{
94 KEST_PRINTF("kest_ui_page_create_identifier(page = %p, id = %p)\n", page, id);
95
96 if (!page || !id)
97 return ERR_NULL_PTR;
98
99 KEST_PRINTF("page->type = %d\n", page->type);
100
101 id->type = page->type;
102 id->fname[0] = 0;
103 id->id = 0;
104
105 if (page->type == KEST_UI_PAGE_MAIN_MENU
106 || page->type == KEST_UI_PAGE_SEQ_LIST
107 || page->type == KEST_UI_PAGE_MSV)
108 {
109 return NO_ERROR;
110 }
111
112 if (!page->data_struct)
113 return ERR_BAD_ARGS;
114
119 kest_effect *effect = NULL;
120 kest_profile *profile = NULL;
121 kest_sequence *seq = NULL;
122
123 char *fname = NULL;
124
125 switch (page->type)
126 {
128 seq = sv_str->sequence;
129 break;
130
132 profile = pv_str->profile;
133 break;
134
136 effect = tv_str->effect;
137
138 if (!effect) return ERR_BAD_ARGS;
139 break;
140
142 effect = ts_str->effect;
143
144 if (!effect) return ERR_BAD_ARGS;
145 break;
146
147 default:
148 return ERR_BAD_ARGS;
149 }
150
151 if (effect)
152 {
153 id->id = effect->id;
154 profile = effect->profile;
155 }
156
157 if (seq)
158 fname = seq->fname;
159 else if (profile)
160 fname = profile->fname;
161 else
162 return ERR_BAD_ARGS;
163
164 if (fname)
165 {
166 for (int i = 0; i < 32; i++)
167 {
168 id->fname[i] = fname[i];
169 if (!fname[i])
170 break;
171 else if (i == 31)
172 fname[i] = 0;
173 }
174 }
175
176 return NO_ERROR;
177}
kest_sequence * cxt_get_sequence_by_fname(kest_context *cxt, const char *fname)
kest_profile * cxt_get_profile_by_fname(kest_context *cxt, const char *fname)
#define ERR_BAD_ARGS
#define NO_ERROR
#define ERR_NULL_PTR
kest_ui_page * kest_page_id_find_page(kest_context *cxt, kest_page_identifier id)
Definition kest_page_id.c:9
int kest_ui_page_create_identifier(kest_ui_page *page, kest_page_identifier *id)
#define KEST_PRINTF(...)
Definition kest_printf.h:10
kest_effect * kest_profile_get_effect_by_id(kest_profile *profile, int id)
#define KEST_UI_PAGE_MAIN_MENU
Definition kest_ui.h:76
#define KEST_UI_PAGE_SEQ_VIEW
Definition kest_ui.h:79
#define KEST_UI_PAGE_MSV
Definition kest_ui.h:78
#define KEST_UI_PAGE_PROF_VIEW
Definition kest_ui.h:80
#define KEST_UI_PAGE_SEQ_LIST
Definition kest_ui.h:77
#define KEST_UI_PAGE_TRANS_SET
Definition kest_ui.h:82
#define KEST_UI_PAGE_TRANS_VIEW
Definition kest_ui.h:81
kest_ui_page * settings_page
uint16_t id
Definition kest_effect.h:21
struct kest_profile * profile
Definition kest_effect.h:37
char fname[KEST_FILENAME_LEN]
char fname[KEST_FILENAME_LEN]
void * data_struct
Definition kest_ui.h:104