settings_view.c 20.8 KB
Newer Older
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
1
/*****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
2
 * Copyright © 2015-2016 VideoLAN, VideoLabs SAS
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
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
 *****************************************************************************
 *
 * Authors: Nicolas Rechatin [nicolas@videolabs.io]
 *
 * This program 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.
 *
 * This program 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 this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
/*
 * By committing to this project, you allow VideoLAN and VideoLabs to relicense
 * the code to a different OSI approved license, in case it is required for
 * compatibility with the Store
 *****************************************************************************/

#include "common.h"

#include "settings_view.h"
30
#include "preferences/preferences.h"
31
#include "ui/settings/settings.h"
32
#include "ui/interface.h"
33
#include "ui/utils.h"
34
#include "playback_service.h"
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
35

Ludovic Fauvet's avatar
Ludovic Fauvet committed
36 37
#include <app_preference.h>

38 39
#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))

40 41 42 43 44 45 46 47 48 49 50 51
void
menu_directories_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent);
void
menu_hwacceleration_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent);
void
menu_subsenc_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent);
void
menu_vorientation_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent);
void
menu_performance_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent);
void
menu_deblocking_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent);
52 53
void
menu_developer_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent);
54

55
struct view_sys {
56
    interface* p_intf;
57
    Evas_Object *nav;
58
    Evas_Object *popup;
59 60
};

Ludovic Fauvet's avatar
Ludovic Fauvet committed
61
settings_item settings_menu[] =
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
62
{
Ludovic Fauvet's avatar
Ludovic Fauvet committed
63
        {0,                             "General",                      NULL,                               SETTINGS_TYPE_CATEGORY},
64
        {SETTINGS_ID_DIRECTORIES,       "Directories",                  "ic_menu_folder.png",               SETTINGS_TYPE_ITEM,         menu_directories_selected_cb},
65 66
        {SETTINGS_ID_HWACCELERATION,    "Hardware acceleration",        "ic_menu_preferences.png",          SETTINGS_TYPE_ITEM,         menu_hwacceleration_selected_cb},
        {SETTINGS_ID_SUBSENC,           "Subtitles text encoding",      "ic_browser_subtitle_normal.png",   SETTINGS_TYPE_ITEM,         menu_subsenc_selected_cb},
67
        {SETTINGS_ID_VORIENTATION,      "Video orientation",            "ic_menu_video.png",                SETTINGS_TYPE_ITEM,         menu_vorientation_selected_cb},
Ludovic Fauvet's avatar
Ludovic Fauvet committed
68
        {0,                             "Extra settings",               NULL,                               SETTINGS_TYPE_CATEGORY},
69
        {SETTINGS_ID_PERFORMANCES,      "Performances",                 "ic_menu_preferences.png",          SETTINGS_TYPE_ITEM,         menu_performance_selected_cb},
70 71
        {SETTINGS_ID_DEBLOCKING,        "Deblocking filter settings",   "ic_menu_preferences.png",          SETTINGS_TYPE_ITEM,         menu_deblocking_selected_cb},
        {SETTINGS_ID_DEVELOPER,         "Developer",                    "ic_menu_preferences.png",          SETTINGS_TYPE_ITEM,         menu_developer_selected_cb}
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
72 73 74 75
};

/* Create the setting submenu items */

76
settings_item directory_menu[] =
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
77
{
78
        {DIRECTORIES_INTERNAL,  "Internal memory",              NULL,   SETTINGS_TYPE_TOGGLE},
79
        {DIRECTORIES_EXTERNAL,  "External memory (SD card)",    NULL,   SETTINGS_TYPE_TOGGLE},
80
        //{DIRECTORIES_ADDLOCATION,   "Add location",    "call_button_add_call_press.png",   SETTINGS_TYPE_ITEM}
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
81 82
};

83
settings_item hardware_acceleration_menu[] =
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
84
{
Ludovic Fauvet's avatar
Ludovic Fauvet committed
85 86 87 88
        {HWACCELERATION_AUTOMATIC,  "Automatic",                NULL, SETTINGS_TYPE_TOGGLE},
        {HWACCELERATION_DISABLED,   "Disabled",                 NULL, SETTINGS_TYPE_TOGGLE},
        {HWACCELERATION_DECODING,   "Decoding acceleration",    NULL, SETTINGS_TYPE_TOGGLE},
        {HWACCELERATION_FULL,       "Full acceleration",        NULL, SETTINGS_TYPE_TOGGLE}
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
89 90
};

91
settings_item video_orientation_menu[] =
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
92
{
Ludovic Fauvet's avatar
Ludovic Fauvet committed
93 94 95 96 97 98
        {ORIENTATION_AUTOMATIC,     "Automatic (sensor)",   NULL, SETTINGS_TYPE_TOGGLE},
        {ORIENTATION_LOCKED,        "Locked at start",      NULL, SETTINGS_TYPE_TOGGLE},
        {ORIENTATION_LANDSCAPE,     "Landscape",            NULL, SETTINGS_TYPE_TOGGLE},
        {ORIENTATION_PORTRAIT,      "Portrait",             NULL, SETTINGS_TYPE_TOGGLE},
        {ORIENTATION_R_LANDSCAPE,   "Reverse landscape",    NULL, SETTINGS_TYPE_TOGGLE},
        {ORIENTATION_R_PORTRAIT,    "Reverse portrait",     NULL, SETTINGS_TYPE_TOGGLE}
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
99 100
};

101
settings_item subtitles_text_encoding_menu[] =
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
102
{
Ludovic Fauvet's avatar
Ludovic Fauvet committed
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
        {42, "Default (Windows-1252)",                  NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Universal (UTF-8)",                       NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Universal (UTF-16)",                      NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Universal (big endian UTF-16)",           NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Universal (little endian UTF-16)",        NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Universal, Chinese (GB18030)",            NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Western European (Latin-9)",              NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Western European (Windows-1252)",         NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Western European (IBM 00850)",            NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Eastern European (Latin-2)",              NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Eastern European (Windows-1250)",         NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Esperanto (Latin-3)",                     NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Nordic (Latin-6)",                        NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Cyrillic (Windows-1251)",                 NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Russian (KOI8-R)",                        NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Ukrainian (KOI8-U)",                      NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Arabic (ISO 8859-6)",                     NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Arabic (Windows-1256)",                   NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Greek (ISO 8859-7)",                      NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Greek (Windows-1253)",                    NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Hebrew (ISO 8859-8)",                     NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Hebrew (Windows-1255)",                   NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Turkish (ISO 8859-9)",                    NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Turkish (Windows-1254)",                  NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Thai (TIS 620-2533/ISO 8859-11)",         NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Thai (Windows-874)",                      NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Baltic (Latin-7)",                        NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Baltic (Windows-1257)",                   NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Celtic (Latin-8)",                        NULL, SETTINGS_TYPE_TOGGLE},
        {42, "South-Estearn (Latin-10)",                NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Simplified Chinese (ISO-2022-CN-EXT)",    NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Simplified Chinese Unix (EUC-CN)",        NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Japanese (7-bits JIS/ISO-2022-JP-2)",     NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Japanese (Shift JIS)",                    NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Korean (EUC-KR/CP949)",                   NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Korean (ISO-2022-KR)",                    NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Traditional Chinese (Big5)",              NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Traditional Chinese Unix (EUC-TW)",       NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Hong-Kong Supplementary (HKSCS)",         NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Vietnamese (VISCII)",                     NULL, SETTINGS_TYPE_TOGGLE},
        {42, "Vietnamese (Windows-1258)",               NULL, SETTINGS_TYPE_TOGGLE}
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
144 145 146

};

147
settings_item performance_menu[] =
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
148
{
Ludovic Fauvet's avatar
Ludovic Fauvet committed
149 150
        {PERFORMANCE_FRAME_SKIP, "Enable frame skip",   NULL, SETTINGS_TYPE_TOGGLE},
        {PERFORMANCE_STRETCH, "Time-stretching audio",  NULL, SETTINGS_TYPE_TOGGLE}
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
151 152 153

};

154
settings_item deblocking_filter_settings_menu[] =
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
155
{
Ludovic Fauvet's avatar
Ludovic Fauvet committed
156 157 158 159 160
        {DEBLOCKING_AUTOMATIC, "Automatic",             NULL, SETTINGS_TYPE_TOGGLE},
        {DEBLOCKING_FULL, "Full deblocking (slowest)",  NULL, SETTINGS_TYPE_TOGGLE},
        {DEBLOCKING_MEDIUM, "Medium deblocking",        NULL, SETTINGS_TYPE_TOGGLE},
        {DEBLOCKING_LOW, "Low deblocking",              NULL, SETTINGS_TYPE_TOGGLE},
        {DEBLOCKING_NO, "No deblocking (fastest)",      NULL, SETTINGS_TYPE_TOGGLE}
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
161 162 163

};

164 165 166 167 168
settings_item developer_menu[] =
{
        {DEVELOPER_VERBOSE, "Verbose", NULL, SETTINGS_TYPE_TOGGLE}
};

169
void
170
settings_view_directories_save(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent)
171 172 173 174 175 176 177 178
{
    switch (selected->menu[selected->index].id)
    {
    case DIRECTORIES_INTERNAL:
    {
        bool newvalue = !selected->menu[selected->index].toggled;
        settings_toggle_set_one_by_id(directory_menu, 2, DIRECTORIES_INTERNAL, newvalue, false);
        elm_genlist_item_update(selected->item);
179
        preferences_set_bool(PREF_DIRECTORIES_INTERNAL, newvalue ? true : false);
180 181
        break;
    }
182 183 184 185 186 187 188 189
    case DIRECTORIES_EXTERNAL:
    {
        bool newvalue = !selected->menu[selected->index].toggled;
        settings_toggle_set_one_by_id(directory_menu, 2, DIRECTORIES_EXTERNAL, newvalue, false);
        elm_genlist_item_update(selected->item);
        preferences_set_bool(PREF_DIRECTORIES_EXTERNAL, newvalue ? true : false);
        break;
    }
190 191 192 193 194 195 196
    case DIRECTORIES_ADDLOCATION:
        break;
    default:
        break;
    }
}

197
void
198
settings_view_simple_save_toggle(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent)
199 200 201 202 203 204 205 206 207 208 209 210
{
    settings_menu_context *ctx = data;

    if (ctx == NULL)
        return;

    switch (ctx->menu_id)
    {
    case SETTINGS_ID_HWACCELERATION:
        // Select the item (and unselect others)
        settings_toggle_set_one_by_index(selected->menu, selected->menu_len, selected->index, true, true);
        // Save the value
211
        preferences_set_enum(PREF_HWACCELERATION, selected->menu[selected->index].id);
212
        // Close the popup
213
        settings_popup_close(p_view_sys->popup);
214
        break;
215 216
    case SETTINGS_ID_SUBSENC:
        settings_toggle_set_one_by_index(selected->menu, selected->menu_len, selected->index, true, true);
217
        preferences_set_index(PREF_SUBSENC, selected->index);
218
        settings_popup_close(p_view_sys->popup);
219
        break;
220 221
    case SETTINGS_ID_VORIENTATION:
        settings_toggle_set_one_by_index(selected->menu, selected->menu_len, selected->index, true, true);
222
        preferences_set_enum(PREF_ORIENTATION, selected->menu[selected->index].id);
223
        settings_popup_close(p_view_sys->popup);
224
        break;
225 226 227 228 229
    case SETTINGS_ID_PERFORMANCES:
    {
        bool newvalue = !selected->menu[selected->index].toggled;
        settings_toggle_set_one_by_index(selected->menu, selected->menu_len, selected->index, newvalue, false);
        if (selected->menu[selected->index].id == PERFORMANCE_FRAME_SKIP)
230
            preferences_set_bool(PREF_FRAME_SKIP, newvalue);
231
        else if (selected->menu[selected->index].id == PERFORMANCE_STRETCH)
232
            preferences_set_bool(PREF_AUDIO_STRETCH, newvalue);
233
        settings_popup_close(p_view_sys->popup);
234 235
        break;
    }
236 237
    case SETTINGS_ID_DEBLOCKING:
        settings_toggle_set_one_by_index(selected->menu, selected->menu_len, selected->index, true, true);
238
        preferences_set_enum(PREF_DEBLOCKING, selected->menu[selected->index].id);
239
        settings_popup_close(p_view_sys->popup);
240
        break;
241 242 243 244 245 246 247 248 249
    case SETTINGS_ID_DEVELOPER:
    {
        bool newvalue = !selected->menu[selected->index].toggled;
        settings_toggle_set_one_by_index(selected->menu, selected->menu_len, selected->index, newvalue, false);
        elm_genlist_item_update(selected->item);
        if (selected->menu[selected->index].id == DEVELOPER_VERBOSE)
            preferences_set_bool(PREF_DEVELOPER_VERBOSE, newvalue);
        break;
    }
250 251
    default:
        break;
252
    }
253
}
254

255
void settings_view_delete_context_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
256 257
{
    settings_menu_context *ctx = data;
258 259 260
    free(ctx);
}

261 262 263 264 265 266
void settings_view_popup_clear_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
    view_sys *p_sys = data;
    p_sys->popup = NULL;
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
267
void
268
menu_directories_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent)
269
{
270
    bool internal = preferences_get_bool(PREF_DIRECTORIES_INTERNAL, true);
271
    bool sdcard = preferences_get_bool(PREF_DIRECTORIES_EXTERNAL, true);
272
    int len = COUNT_OF(directory_menu);
273
    Evas_Object *genlist = settings_list_add_styled(directory_menu, len, settings_view_directories_save, NULL, p_view_sys, parent);
274
    settings_toggle_set_one_by_id(directory_menu, len, DIRECTORIES_INTERNAL, internal, false);
275
    settings_toggle_set_one_by_id(directory_menu, len, DIRECTORIES_EXTERNAL, sdcard, false);
276
    elm_naviframe_item_push(p_view_sys->nav, "Media library", NULL, NULL, genlist, NULL);
277
    evas_object_show(genlist);
278 279
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
280
void
281
menu_hwacceleration_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent)
282
{
283 284 285
    settings_menu_context *ctx = malloc(sizeof(*ctx));
    ctx->menu_id = SETTINGS_ID_HWACCELERATION;

286
    menu_id value = preferences_get_enum(PREF_HWACCELERATION, HWACCELERATION_AUTOMATIC);
287
    int len = COUNT_OF(hardware_acceleration_menu);
288
    p_view_sys->popup = settings_popup_add(hardware_acceleration_menu, len, settings_view_simple_save_toggle, ctx, p_view_sys, parent);
289
    settings_toggle_set_one_by_id(hardware_acceleration_menu, len, value, true, true);
290 291
    evas_object_show(p_view_sys->popup);
    evas_object_event_callback_add(p_view_sys->popup, EVAS_CALLBACK_FREE, settings_view_delete_context_cb, ctx);
292
    evas_object_event_callback_add(p_view_sys->popup, EVAS_CALLBACK_FREE, settings_view_popup_clear_cb, p_view_sys);
293 294
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
295
void
296
menu_subsenc_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent)
297
{
298 299 300
    settings_menu_context *ctx = malloc(sizeof(*ctx));
    ctx->menu_id = SETTINGS_ID_SUBSENC;

301
    int value = preferences_get_index(PREF_SUBSENC, 0);
302
    int len = COUNT_OF(subtitles_text_encoding_menu);
303
    p_view_sys->popup = settings_popup_add(subtitles_text_encoding_menu, len, settings_view_simple_save_toggle, ctx, p_view_sys, parent);
304
    settings_toggle_set_one_by_index(subtitles_text_encoding_menu, len, value, true, true);
305 306
    evas_object_show(p_view_sys->popup);
    evas_object_event_callback_add(p_view_sys->popup, EVAS_CALLBACK_FREE, settings_view_delete_context_cb, ctx);
307
    evas_object_event_callback_add(p_view_sys->popup, EVAS_CALLBACK_FREE, settings_view_popup_clear_cb, p_view_sys);
308 309
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
310
void
311
menu_vorientation_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent)
312
{
313 314 315
    settings_menu_context *ctx = malloc(sizeof(*ctx));
    ctx->menu_id = SETTINGS_ID_VORIENTATION;

316
    menu_id value = preferences_get_enum(PREF_ORIENTATION, ORIENTATION_AUTOMATIC);
317
    int len = COUNT_OF(video_orientation_menu);
318
    p_view_sys->popup = settings_popup_add(video_orientation_menu, len, settings_view_simple_save_toggle, ctx, p_view_sys, parent);
319
    settings_toggle_set_one_by_id(video_orientation_menu, len, value, true, true);
320 321
    evas_object_show(p_view_sys->popup);
    evas_object_event_callback_add(p_view_sys->popup, EVAS_CALLBACK_FREE, settings_view_delete_context_cb, ctx);
322
    evas_object_event_callback_add(p_view_sys->popup, EVAS_CALLBACK_FREE, settings_view_popup_clear_cb, p_view_sys);
323 324
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
325
void
326
menu_performance_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent)
327
{
328 329 330
    settings_menu_context *ctx = malloc(sizeof(*ctx));
    ctx->menu_id = SETTINGS_ID_PERFORMANCES;

331
    int len = COUNT_OF(performance_menu);
332
    p_view_sys->popup = settings_popup_add(performance_menu, len, settings_view_simple_save_toggle, ctx, p_view_sys, parent);
333

334 335
    bool frameskip = preferences_get_bool(PREF_FRAME_SKIP, false);
    bool stretch = preferences_get_bool(PREF_AUDIO_STRETCH, false);
336 337 338 339

    settings_toggle_set_one_by_id(performance_menu, len, PERFORMANCE_FRAME_SKIP, frameskip, false);
    settings_toggle_set_one_by_id(performance_menu, len, PERFORMANCE_STRETCH, stretch, false);

340 341
    evas_object_show(p_view_sys->popup);
    evas_object_event_callback_add(p_view_sys->popup, EVAS_CALLBACK_FREE, settings_view_delete_context_cb, ctx);
342
    evas_object_event_callback_add(p_view_sys->popup, EVAS_CALLBACK_FREE, settings_view_popup_clear_cb, p_view_sys);
343 344
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
345
void
346
menu_deblocking_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent)
347
{
348 349 350
    settings_menu_context *ctx = malloc(sizeof(*ctx));
    ctx->menu_id = SETTINGS_ID_DEBLOCKING;

351
    int value = preferences_get_enum(PREF_DEBLOCKING, DEBLOCKING_AUTOMATIC);
352
    int len = COUNT_OF(deblocking_filter_settings_menu);
353
    p_view_sys->popup = settings_popup_add(deblocking_filter_settings_menu, len, settings_view_simple_save_toggle, ctx, p_view_sys, parent);
354
    settings_toggle_set_one_by_id(deblocking_filter_settings_menu, len, value, true, true);
355 356
    evas_object_show(p_view_sys->popup);
    evas_object_event_callback_add(p_view_sys->popup, EVAS_CALLBACK_FREE, settings_view_delete_context_cb, ctx);
357
    evas_object_event_callback_add(p_view_sys->popup, EVAS_CALLBACK_FREE, settings_view_popup_clear_cb, p_view_sys);
358 359
}

360 361 362 363 364 365 366 367
void
menu_developer_selected_cb(settings_menu_selected *selected, view_sys* p_view_sys, void *data, Evas_Object *parent)
{
    settings_menu_context *ctx = malloc(sizeof(*ctx));
    ctx->menu_id = SETTINGS_ID_DEVELOPER;

    bool verbose = preferences_get_bool(PREF_DEVELOPER_VERBOSE, false);
    int len = COUNT_OF(developer_menu);
368
    Evas_Object *genlist = settings_list_add_styled(developer_menu, len, settings_view_simple_save_toggle, ctx, p_view_sys, parent);
369 370 371
    settings_toggle_set_one_by_id(developer_menu, len, DEVELOPER_VERBOSE, verbose, false);
    elm_naviframe_item_push(p_view_sys->nav, "Developer options", NULL, NULL, genlist, NULL);
    evas_object_show(genlist);
372
    evas_object_event_callback_add(genlist, EVAS_CALLBACK_FREE, settings_view_delete_context_cb, ctx);
373 374
}

375 376 377 378 379 380
static bool
settings_event(view_sys *p_view_sys, interface_view_event event)
{
    if(event == INTERFACE_VIEW_EVENT_BACK && p_view_sys->popup)
    {
        // Close any visible popup
381
        settings_popup_close(p_view_sys->popup);
382 383 384 385 386 387
        p_view_sys->popup = NULL;
        return true;
    }
    return false;
}

388
Eina_Bool
389
settings_view_last_view_pop(void *data, Elm_Object_Item *it)
390 391 392 393 394
{
    view_sys *p_view_sys = data;
    application *p_app = intf_get_application(p_view_sys->p_intf);
    playback_service *p_ps = application_get_playback_service(p_app);

395
    playback_service_restart_emotion(p_ps, false);
396 397 398
    return EINA_TRUE;
}

399
void
400
settings_view_start(view_sys *p_view_sys)
401
{
402 403 404 405 406 407
    // The settings has been pushed to top
    Elm_Object_Item *it = elm_naviframe_top_item_get(p_view_sys->nav);
    if (it == NULL)
        return;

    // Attach a callback for reloading the settings
408
    elm_naviframe_item_pop_cb_set(it, settings_view_last_view_pop, p_view_sys);
409 410
}

411
interface_view*
412
create_settings_view(interface *intf, Evas_Object *parent)
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
413
{
414
    interface_view *view = calloc(1, sizeof(*view));
415

416
    view->p_view_sys = calloc(1, sizeof(*view->p_view_sys));
417
    view->p_view_sys->nav = intf_get_main_naviframe(intf);
418
    view->pf_start = settings_view_start;
419
    view->pf_event = settings_event;
420
    view->p_view_sys->p_intf = intf;
421

422
    int len = COUNT_OF(settings_menu);
423
    view->view = settings_list_add_styled(settings_menu, len, NULL, NULL, view->p_view_sys, view->p_view_sys->nav);
424
    evas_object_show(view->view);
425 426

    return view;
Nicolas Pomepuy's avatar
Nicolas Pomepuy committed
427
}
428 429

void
430
destroy_settings_view(interface_view *view)
431
{
432 433
    elm_naviframe_item_pop_cb_set(view->nf_item, NULL, NULL);

Ludovic Fauvet's avatar
Ludovic Fauvet committed
434
    evas_object_del(view->view);
435
    free(view->p_view_sys);
436
    free(view);
437
}
438 439

#undef COUNT_OF