Modification due to the change of CCtxPopup
[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 "i18n.h"
22 #include "define.h"
23 #include "common.h"
24 #include "Info.h"
25 #include "CtxPopup.h"
26 #include <MediaContentDbListener.h>
27 #include <UsbConnectionListener.h>
28 #include <app-res-defines.h>
29 #include "SourceCtxPopup.h"
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         CUsbConnectionListener usb;
48         usb.Create();
49         if (!usb.FlagConnected())
50                 size--;
51         usb.Destroy();
52
53         t_SetList(sourcetext, size, (int)CInfo::SourceType(),
54                         CCtxPopup::TOPBTN_SOURCE, srcbtnids,
55                         POSITION_SOURCE_POPUP_X, POSITION_SOURCE_POPUP_Y,
56                         FBR_STYLE_HOVER_CTXPOPUP,
57                         FBR_STYLE_HOVER_ENTRY, FBR_STYLE_HOVER_ENTRY, FBR_STYLE_HOVER_ENTRY);
58 }
59
60
61 void CSourceCtxPopup::t_OnBtnClicked(Evas_Object* obj, void* ev)
62 {
63         if (!obj)
64                 return;
65
66         int index = -1;
67         const char *id = (const char*)evas_object_data_get(obj, BTN_ID);
68
69         if (!id)
70                 return;
71
72         // Find Index
73         int i;
74         int arrsize = ARRAY_SIZE(srcbtnids);
75         for (i = 0; i < arrsize; i++) {
76                 if (srcbtnids[i] && !strcmp(srcbtnids[i], id)) {
77                         index = i;
78                         break;
79                 }
80         }
81         if (index == -1 || index == CInfo::SourceType())
82                 return;
83
84         CInfo::SetSourceType(index);
85         CCtxPopup::t_OnBtnClicked(obj, ev);
86
87         Destroy();
88 }
89
90 const char* CSourceCtxPopup::SourceText(int index)
91 {
92         return sourcetext[index];
93 }