Tizen 2.0 Release
[apps/core/preloaded/myfiles.git] / src / common / mf-share.c
1 /*
2  * Copyright 2013         Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include <Eina.h>
19 #include <Evas.h>
20 #include <Ethumb.h>
21 #include <assert.h>
22
23 #include "mf-main.h"
24 #include "mf-widget.h"
25 #include "mf-util.h"
26 #include "mf-fs-util.h"
27 #include "mf-launch.h"
28 #include "mf-drm.h"
29 #include "mf-share.h"
30 #include "mf-resource.h"
31
32 int mf_share_mode_get(Eina_List * selected_list)
33 {
34         mf_retvm_if(selected_list == NULL, -1, "selected_list is NULL");
35         int file_mode = SHARE_FILE_MODE_NORMAL;
36
37         Eina_List *l = NULL;
38         GString *pNode = NULL;
39         int image_count = 0;
40         int video_count = 0;
41         EINA_LIST_FOREACH(selected_list, l, pNode) {
42                 if (pNode != NULL) {
43                         char *file_path = pNode->str;
44                         if (ecore_file_is_dir(file_path)) {
45                                 return 0;
46                         }
47
48                         fsFileType category = FILE_TYPE_NONE;
49
50                         mf_file_attr_get_file_category(file_path, &category);
51                         if (category == FILE_TYPE_IMAGE) {
52                                 image_count++;
53                                 if (image_count > 1) {
54                                         file_mode = file_mode | SHARE_FILE_MODE_MULTI_IMAGE;
55                                 } else {
56                                         file_mode = file_mode | SHARE_FILE_MODE_IMAGE;
57                                 }
58                         } else if (category == FILE_TYPE_VIDEO) {
59                                 video_count++;
60                                 if (video_count > 1) {
61                                         file_mode = file_mode | SHARE_FILE_MODE_MULTI_VIDEO;
62                                 } else {
63                                         file_mode = file_mode | SHARE_FILE_MODE_VIDEO;
64                                 }
65                         } else {
66                                 file_mode = file_mode | SHARE_FILE_MODE_OTHERS;
67                         }
68                 }
69         }
70         return file_mode;
71 }
72 static int __mf_share_get_selected_files(void *data, gchar ** selected_files, Eina_List * selected_list)
73 {
74         MF_TRACE_BEGIN;
75         struct appdata *ap = (struct appdata *)data;
76         mf_retvm_if(ap == NULL, -1, "ap is NULL");
77         mf_retvm_if(selected_list == NULL, 0, "selected_list is NULL");
78         mf_retvm_if(selected_files == NULL, -1, "selected_files is NULL");
79
80         int file_count = 0;
81         Eina_List *l = NULL;
82         GString *pNode = NULL;
83         gchar *message = NULL;
84
85         EINA_LIST_FOREACH(ap->mf_FileRecordList.selected_files, l, pNode) {
86                 if (pNode != NULL) {
87                         if (!ecore_file_is_dir(pNode->str) && mf_drm_is_drm_file(pNode->str) == 0) {
88                                 if (mf_drm_is_converted_fl(pNode->str) == 0) {
89                                         message = g_strconcat(GET_STR(MF_POPUP_MESSAGE_SEND_FAIL1), "<br>", ecore_file_file_get(pNode->str),
90                                                         GET_STR(MF_POPUP_MESSAGE_SEND_FAIL2), NULL);
91                                         ap->mf_MainWindow.pNormalPopup = mf_popup_create_popup(ap, POPMODE_TEXT, NULL, message,
92                                                                                          NULL, NULL, NULL, NULL, NULL);
93
94                                         g_free(message);
95                                         message = NULL;
96                                         if (*selected_files != NULL) {
97                                                   g_free(*selected_files);
98                                                   *selected_files = NULL;
99                                         }
100                                         MF_TRACE_END;
101                                         return -1;
102                                 }
103                         } else if (ecore_file_is_dir(pNode->str)) {
104                                 message = GET_STR(MF_POPUP_MESSAGE_SEND_FAIL3);
105                                 ap->mf_MainWindow.pNormalPopup = mf_popup_create_popup(ap, POPMODE_TEXT, NULL, message, NULL, NULL, NULL, NULL, NULL);
106
107                                 if (*selected_files != NULL) {
108                                         g_free(*selected_files);
109                                         *selected_files = NULL;
110                                 }
111                                 MF_TRACE_END;
112                                 return -1;
113                         }
114
115                         if (*selected_files == NULL) {
116                                 *selected_files = g_strconcat(pNode->str, NULL);
117                                 file_count++;
118                         } else {
119                                 gchar *temp = *selected_files;
120                                 if (ap->mf_Status.more == MORE_SENDVIABLUETOOTH
121                                 ) {
122                                         *selected_files = g_strconcat(*selected_files, "?", pNode->str, NULL);
123                                         file_count++;
124                                 }
125                                 else {
126                                         *selected_files = g_strconcat(*selected_files, "\n", pNode->str, NULL);
127                                         file_count++;
128                                 }
129
130                                 g_free(temp);
131                         }
132                 }
133         }
134         MF_TRACE_END;
135         return file_count;
136 }
137
138 void mf_share_launch_multi_file(void *data)
139 {
140         MF_TRACE_BEGIN;
141         struct appdata *ap = (struct appdata *)data;
142         assert(ap);
143         gchar *myFilenames = NULL;
144         int number_of_files = 0;
145         char count_arg[20] = { 0, };
146         const char *message = NULL;
147
148         number_of_files = __mf_share_get_selected_files(ap, &myFilenames, ap->mf_FileRecordList.selected_files);
149         if (number_of_files < 0) {
150                 MF_TRACE_END;
151                 return;
152         } else if (number_of_files == 0) {
153                 message = GET_SYS_STR(MF_LABEL_NOTHING_SELECTED);
154                 ap->mf_MainWindow.pNormalPopup = mf_popup_create_popup(ap, POPMODE_TEXT, NULL, message, NULL, NULL, NULL, NULL, NULL);
155                 MF_TRACE_END;
156                 return;
157         } else {
158                 snprintf(count_arg, sizeof(count_arg), "%d", number_of_files);
159                 if (ap->mf_Status.more == MORE_SENDVIABLUETOOTH) {
160                         mf_debug("::::::::::Send via bluetooth:::::::::::::");
161                         mf_launch_load_ug(ap, myFilenames, MF_LOAD_UG_BLUETOOTH, count_arg);
162                 } else if (ap->mf_Status.more == MORE_SENDVIAEMAIL) {
163                         mf_debug("::::::::::Send via email::::::::::::: files is [%s]", myFilenames);
164                         mf_launch_load_ug(ap, myFilenames, MF_LOAD_UG_EMAIL, count_arg);
165                 } else if (ap->mf_Status.more == MORE_SENDVIAMESSAGE) {
166                         mf_debug("::::::::::Send via message::::::::::::: files is [%s]", myFilenames);
167                         mf_launch_load_ug(ap, myFilenames, MF_LOAD_UG_MESSAGE, count_arg);
168                 }
169
170                 g_free(myFilenames);
171         }
172         MF_TRACE_END;
173 }
174