summaryrefslogtreecommitdiff
path: root/src/bin/main_window.c
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2013-09-01 19:41:13 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2014-04-03 16:23:04 -0300
commit196cdb70b84958dd827797f86e78abd798e48cf7 (patch)
treefa94c67c0794b8dd8d64b8e216daccc20801c584 /src/bin/main_window.c
parentc984cf740b8625571a5d1617e0c3911fc27c11f9 (diff)
Adding common code
Init/shutdown used libraries and including common headers.
Diffstat (limited to 'src/bin/main_window.c')
-rw-r--r--src/bin/main_window.c160
1 files changed, 160 insertions, 0 deletions
diff --git a/src/bin/main_window.c b/src/bin/main_window.c
new file mode 100644
index 0000000..6783384
--- /dev/null
+++ b/src/bin/main_window.c
@@ -0,0 +1,160 @@
1#include "main_window.h"
2
3#include "epulse.h"
4#include "playbacks_view.h"
5#include "sinks_view.h"
6#include "sources_view.h"
7
8#define MAIN_WINDOW_DATA "mainwindow.data"
9
10enum MAIN_SUBVIEWS {
11 PLAYBACKS,
12 OUTPUTS,
13 INPUTS
14};
15
16static const char *_views[] = {
17 "Playback",
18 "Output Devices",
19 "Input Devices"
20};
21
22typedef struct _Main_Window Main_Window;
23struct _Main_Window
24{
25 Evas_Object *win;
26 Evas_Object *toolbar;
27 Evas_Object *layout;
28 Evas_Object *naviframe;
29 Evas_Object *playbacks;
30 Evas_Object *inputs;
31 Evas_Object *outputs;
32 Elm_Object_Item *toolbar_items[3];
33 Elm_Object_Item *views[3];
34};
35
36static void
37_del_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED,
38 void *event_info EINA_UNUSED)
39{
40 Main_Window *mw = data;
41
42 free(mw);
43}
44
45static void
46_delete_request_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED,
47 void *event_info EINA_UNUSED)
48{
49 elm_exit();
50}
51
52static void
53_toolbar_item_cb(void *data, Evas_Object *obj EINA_UNUSED,
54 void *event_info EINA_UNUSED)
55{
56 Main_Window *mw = data;
57 Elm_Object_Item *it = elm_toolbar_selected_item_get(obj);
58
59 if (!mw->views[PLAYBACKS] || !mw->views[OUTPUTS] ||
60 !mw->views[INPUTS])
61 return;
62
63 if (it == mw->toolbar_items[PLAYBACKS])
64 elm_naviframe_item_promote(mw->views[PLAYBACKS]);
65 else if (it == mw->toolbar_items[OUTPUTS])
66 elm_naviframe_item_promote(mw->views[OUTPUTS]);
67 else
68 elm_naviframe_item_promote(mw->views[INPUTS]);
69}
70
71Evas_Object *
72main_window_add(void)
73{
74 Main_Window *mw;
75 Evas_Object *tmp, *box;
76 unsigned int i;
77
78 elm_theme_extension_add(NULL, EPULSE_THEME);
79 mw = calloc(1, sizeof(Main_Window));
80 if (!mw)
81 {
82 ERR("Could not allocate memmory to main window");
83 return NULL;
84 }
85
86 tmp = elm_win_add(NULL, PACKAGE_NAME, ELM_WIN_BASIC);
87 EINA_SAFETY_ON_NULL_GOTO(tmp, win_err);
88 evas_object_data_set(tmp, MAIN_WINDOW_DATA, mw);
89 evas_object_event_callback_add(tmp, EVAS_CALLBACK_DEL, _del_cb, mw);
90 elm_win_autodel_set(tmp, EINA_TRUE);
91 elm_win_title_set(tmp, "Efl Volume Control");
92 mw->win = tmp;
93
94 tmp = elm_bg_add(mw->win);
95 evas_object_size_hint_weight_set(tmp, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
96 evas_object_size_hint_align_set(tmp, EVAS_HINT_FILL, EVAS_HINT_FILL);
97 elm_win_resize_object_add(mw->win, tmp);
98 evas_object_show(tmp);
99
100 box = elm_box_add(mw->win);
101 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
102 elm_box_horizontal_set(box, EINA_FALSE);
103 elm_win_resize_object_add(mw->win, box);
104 evas_object_show(box);
105
106 tmp = elm_toolbar_add(mw->win);
107 evas_object_size_hint_weight_set(tmp, EVAS_HINT_EXPAND, 0);
108 evas_object_size_hint_align_set(tmp, EVAS_HINT_FILL, EVAS_HINT_FILL);
109 elm_toolbar_select_mode_set(tmp, ELM_OBJECT_SELECT_MODE_ALWAYS);
110 elm_box_pack_start(box, tmp);
111 mw->toolbar = tmp;
112 evas_object_show(tmp);
113
114 tmp = elm_naviframe_add(mw->win);
115 elm_object_style_set(tmp, "no_transition");
116 elm_naviframe_prev_btn_auto_pushed_set(tmp, EINA_FALSE);
117 evas_object_size_hint_weight_set(tmp, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
118 evas_object_size_hint_align_set(tmp, EVAS_HINT_FILL, EVAS_HINT_FILL);
119 elm_box_pack_end(box, tmp);
120 evas_object_show(tmp);
121 mw->naviframe = tmp;
122
123 for (i = 0; i < EINA_C_ARRAY_LENGTH(_views); i++)
124 {
125 mw->toolbar_items[i] = elm_toolbar_item_append(mw->toolbar, NULL,
126 _views[i],
127 _toolbar_item_cb, mw);
128 }
129
130 evas_object_smart_callback_add(mw->win, "delete,request",
131 _delete_request_cb, mw);
132
133 /* Creating the playbacks view */
134 mw->playbacks = playbacks_view_add(mw->win);
135 evas_object_size_hint_weight_set(mw->playbacks, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
136 evas_object_size_hint_align_set(mw->playbacks, EVAS_HINT_FILL, EVAS_HINT_FILL);
137 evas_object_show(mw->playbacks);
138
139 /* Creating the outputs view */
140 mw->outputs = sinks_view_add(mw->win);
141 evas_object_size_hint_weight_set(mw->outputs, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
142 evas_object_size_hint_align_set(mw->outputs, EVAS_HINT_FILL, EVAS_HINT_FILL);
143 evas_object_show(mw->outputs);
144
145 /* Creating the inputs view */
146 mw->inputs = sources_view_add(mw->win);
147 evas_object_size_hint_weight_set(mw->inputs, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
148 evas_object_size_hint_align_set(mw->inputs, EVAS_HINT_FILL, EVAS_HINT_FILL);
149 evas_object_show(mw->inputs);
150
151 mw->views[INPUTS] = elm_naviframe_item_simple_push(mw->naviframe, mw->inputs);
152 mw->views[OUTPUTS] = elm_naviframe_item_simple_push(mw->naviframe, mw->outputs);
153 mw->views[PLAYBACKS] = elm_naviframe_item_simple_push(mw->naviframe, mw->playbacks);
154
155 return mw->win;
156
157 win_err:
158 free(mw);
159 return NULL;
160}