Tizen 2.1 base
[platform/core/api/efl-util.git] / src / efl_util.c
1 /*
2  * Copyright (c) 2011 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
18 #define LOG_TAG "TIZEN_N_EFL_UTIL"
19
20 #include <efl_util.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <Elementary.h>
25 #include <Ecore_X.h>
26 #include <utilX.h>
27
28
29 int efl_util_set_notification_window_level (Evas_Object* window, efl_util_notification_level_e level)
30 {
31         Ecore_X_Window_Type window_type;
32         
33         if(window == NULL)
34         {
35                 return EFL_UTIL_ERROR_INVALID_PARAMETER;
36         }
37
38         if(level < EFL_UTIL_NOTIFICATION_LEVEL_1 || level > EFL_UTIL_NOTIFICATION_LEVEL_2)
39         {
40                 return EFL_UTIL_ERROR_INVALID_PARAMETER;
41         }
42         
43         Ecore_X_Window xwin = elm_win_xwindow_get(window);
44
45         if(ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
46         {
47                 // success to get window type
48                 if(window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
49                 {
50                         // given EFL window's type is not notification type.
51                         return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
52                 }
53         }
54         else
55         {
56                 // fail to get window type
57                 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
58         }
59         
60         // this api doesn't have return type
61         if(level == EFL_UTIL_NOTIFICATION_LEVEL_1) {
62                 utilx_set_system_notification_level(ecore_x_display_get(), xwin, UTILX_NOTIFICATION_LEVEL_LOW);
63         }
64         else if(level == EFL_UTIL_NOTIFICATION_LEVEL_2)
65         {
66                 utilx_set_system_notification_level(ecore_x_display_get(), xwin, UTILX_NOTIFICATION_LEVEL_NORMAL);
67         }
68         
69         return EFL_UTIL_ERROR_NONE;
70 }
71
72
73
74 int efl_util_get_notification_window_level (Evas_Object* window, efl_util_notification_level_e* level)
75 {
76         Ecore_X_Window_Type window_type;
77
78          Utilx_Notification_Level utilx_level;
79         
80         if(window == NULL)
81         {
82                 return EFL_UTIL_ERROR_INVALID_PARAMETER;
83         }
84
85
86         Ecore_X_Window xwin = elm_win_xwindow_get(window);
87
88         if(ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
89         {
90                 // success to get window type
91                 if(window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
92                 {
93                         // given EFL window's type is not notification type.
94                         return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
95                 }
96                 
97                 utilx_level = utilx_get_system_notification_level (ecore_x_display_get(), xwin);
98
99                 if(utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
100                 {
101                         *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
102                 }
103                 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
104                 {
105                         *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
106                 }
107                 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
108                 {
109                         *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
110                 }
111                 else
112                 {
113                         return EFL_UTIL_ERROR_INVALID_PARAMETER;
114                 }
115                 
116         }
117         else
118         {
119                 // fail to get window type
120                 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
121         }
122         
123         return EFL_UTIL_ERROR_NONE;
124 }