summaryrefslogtreecommitdiff
path: root/src/bin/main_window.c
blob: a620b2c3d1cd959a5d570f933e3f5942324e502a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include "main_window.h"

#include "playbacks_view.h"
#include "sinks_view.h"
#include "sources_view.h"

#include <emix.h>

#define MAIN_WINDOW_DATA "mainwindow.data"

enum MAIN_SUBVIEWS {
   PLAYBACKS,
   OUTPUTS,
   INPUTS,
   ADVANCED
};

typedef struct _Main_Window Main_Window;
struct _Main_Window
{
   Evas_Object *win;
   Evas_Object *toolbar;
   Evas_Object *layout;
   Evas_Object *naviframe;
   Evas_Object *playbacks;
   Evas_Object *inputs;
   Evas_Object *outputs;
   Evas_Object *advanced_options;
   Elm_Object_Item *toolbar_items[3];
   Elm_Object_Item *views[3];
};

static void
_del_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED,
        void *event_info EINA_UNUSED)
{
   Main_Window *mw = data;

   free(mw);
}

static void
_delete_request_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED,
                   void *event_info EINA_UNUSED)
{
   elm_exit();
}

static void
_toolbar_item_cb(void *data, Evas_Object *obj EINA_UNUSED,
                 void *event_info EINA_UNUSED)
{
   Main_Window *mw = data;
   Elm_Object_Item *it = elm_toolbar_selected_item_get(obj);

   if (!mw->views[PLAYBACKS] || !mw->views[OUTPUTS] ||
       !mw->views[INPUTS])
      return;

   if (it == mw->toolbar_items[PLAYBACKS])
      elm_naviframe_item_promote(mw->views[PLAYBACKS]);
   else if (it == mw->toolbar_items[OUTPUTS])
      elm_naviframe_item_promote(mw->views[OUTPUTS]);
   else
      elm_naviframe_item_promote(mw->views[INPUTS]);
}

Evas_Object *
main_window_add(void)
{
   Main_Window *mw;
   Evas_Object *tmp, *box, *icon;
   char buf[4096];

   elm_theme_extension_add(NULL, EMIXER_THEME);
   mw = calloc(1, sizeof(Main_Window));
   if (!mw)
     {
        ERR("Could not allocate memmory to main window");
        return NULL;
     }

   tmp = elm_win_add(NULL, PACKAGE_NAME, ELM_WIN_BASIC);
   EINA_SAFETY_ON_NULL_GOTO(tmp, win_err);
   evas_object_data_set(tmp, MAIN_WINDOW_DATA, mw);
   evas_object_event_callback_add(tmp, EVAS_CALLBACK_DEL, _del_cb, mw);
   elm_win_autodel_set(tmp, EINA_TRUE);
   elm_win_title_set(tmp, _("Efl Volume Control"));
   mw->win = tmp;

   icon = evas_object_image_add(evas_object_evas_get(mw->win));
   snprintf(buf, sizeof(buf), "%s/icons/emixer.png",
            elm_app_data_dir_get());
   evas_object_image_file_set(icon, buf, NULL);
   elm_win_icon_object_set(mw->win, icon);
   elm_win_icon_name_set(mw->win, "emixer");

   tmp = elm_bg_add(mw->win);
   evas_object_size_hint_weight_set(tmp, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(tmp, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_win_resize_object_add(mw->win, tmp);
   evas_object_show(tmp);

   box = elm_box_add(mw->win);
   evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_box_horizontal_set(box, EINA_FALSE);
   elm_win_resize_object_add(mw->win, box);
   evas_object_show(box);

   tmp = elm_toolbar_add(mw->win);
   evas_object_size_hint_weight_set(tmp, EVAS_HINT_EXPAND, 0);
   evas_object_size_hint_align_set(tmp, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_toolbar_select_mode_set(tmp, ELM_OBJECT_SELECT_MODE_ALWAYS);
   elm_box_pack_start(box, tmp);
   mw->toolbar = tmp;
   evas_object_show(tmp);

   tmp = elm_naviframe_add(mw->win);
   elm_object_style_set(tmp, "no_transition");
   elm_naviframe_prev_btn_auto_pushed_set(tmp, EINA_FALSE);
   evas_object_size_hint_weight_set(tmp, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(tmp, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_box_pack_end(box, tmp);
   evas_object_show(tmp);
   mw->naviframe = tmp;

   mw->toolbar_items[0] = elm_toolbar_item_append(mw->toolbar, NULL,
                                                  _("Playback"),
                                                  _toolbar_item_cb, mw);
   mw->toolbar_items[1] = elm_toolbar_item_append(mw->toolbar, NULL,
                                                  _("Outputs"),
                                                  _toolbar_item_cb, mw);
   mw->toolbar_items[2] = elm_toolbar_item_append(mw->toolbar, NULL,
                                                  _("Inputs"),
                                                  _toolbar_item_cb, mw);

   evas_object_smart_callback_add(mw->win, "delete,request",
                                  _delete_request_cb, mw);

   /* Creating the playbacks view */
   mw->playbacks = playbacks_view_add(mw->win);
   evas_object_size_hint_weight_set(mw->playbacks, EVAS_HINT_EXPAND,
                                    EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(mw->playbacks, EVAS_HINT_FILL,
                                   EVAS_HINT_FILL);
   evas_object_show(mw->playbacks);

   /* Creating the outputs view */
   mw->outputs = sinks_view_add(mw->win);
   evas_object_size_hint_weight_set(mw->outputs, EVAS_HINT_EXPAND,
                                    EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(mw->outputs, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_show(mw->outputs);

   /* Creating the inputs view */
   mw->inputs = sources_view_add(mw->win);
   evas_object_size_hint_weight_set(mw->inputs, EVAS_HINT_EXPAND,
                                    EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(mw->inputs, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_show(mw->inputs);

   /* Creating the advanced view */
   mw->advanced_options = emix_advanced_options_add(mw->win);
   if (mw->advanced_options)
     {
        evas_object_size_hint_weight_set(mw->advanced_options, EVAS_HINT_EXPAND,
                                         EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(mw->advanced_options, EVAS_HINT_FILL,
                                        EVAS_HINT_FILL);
        evas_object_show(mw->advanced_options);

        mw->views[ADVANCED] = elm_naviframe_item_simple_push(mw->naviframe,
                                                         mw->advanced_options);
     }

   mw->views[INPUTS] = elm_naviframe_item_simple_push(mw->naviframe,
                                                      mw->inputs);
   mw->views[OUTPUTS] = elm_naviframe_item_simple_push(mw->naviframe,
                                                       mw->outputs);
   mw->views[PLAYBACKS] = elm_naviframe_item_simple_push(mw->naviframe,
                                                         mw->playbacks);

   return mw->win;

 win_err:
   free(mw);
   return NULL;
}