f7b4690128e5eda6b225ffeae01b6222fb0bc12a
[profile/tv/apps/native/filebrowser.git] / src / views / BaseView / SourceCtxPopup.cpp
1 /*
2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <Elementary.h>
18 #include <Eina.h>
19 #include <Ecore.h>
20 #include <aul.h>
21 #include "dbg.h"
22 #include <AppCommon.h>
23 #include "define.h"
24 #include "common.h"
25 #include "i18n.h"
26 #include "Info.h"
27 #include "SourceCtxPopup.h"
28
29 #define BTN_ID                   "BTN_ID"
30
31 const char *srcbtnids[] = {
32         "ALL",
33         "TV",
34         "USB"
35 };
36
37 const char *sourcetext[] = {
38         N_("All Source"),
39         N_("TV"),
40         N_("USB"),
41 };
42
43 void CSourceCtxPopup::t_OnConfiguration(void)
44 {
45         int size = ARRAY_SIZE(sourcetext);
46
47         CUsbListener usb;
48         if(usb.Create()) {
49                 if (!usb.FlagConnected())
50                         size--;
51                 usb.Destroy();
52         }
53         else
54                 size--;
55
56         t_SetList(sourcetext, size, (int)CInfo::SourceType(),
57                         CContextPopup::TOPBTN_SOURCE, srcbtnids,
58                         POSITION_SOURCE_POPUP_X, POSITION_SOURCE_POPUP_Y,
59                         NULL,
60                         FBR_STYLE_HOVER_ENTRY, FBR_STYLE_HOVER_ENTRY, FBR_STYLE_HOVER_ENTRY);
61 }
62
63
64 void CSourceCtxPopup::t_OnBtnClicked(Evas_Object* obj, void* ev)
65 {
66         if (!obj)
67                 return;
68
69         int index = -1;
70         const char *id = (const char*)evas_object_data_get(obj, BTN_ID);
71
72         if (!id)
73                 return;
74
75         // Find Index
76         int i;
77         int arrsize = ARRAY_SIZE(srcbtnids);
78         for (i = 0; i < arrsize; i++) {
79                 if (srcbtnids[i] && !strcmp(srcbtnids[i], id)) {
80                         index = i;
81                         break;
82                 }
83         }
84         if (index == -1 || index == CInfo::SourceType())
85                 return;
86
87         CInfo::SetSourceType(index);
88         CContextPopup::t_OnBtnClicked(obj, ev);
89
90         Destroy();
91 }
92
93 const char* CSourceCtxPopup::SourceText(int index)
94 {
95         return sourcetext[index];
96 }