source code open - cert-svc-ui
[framework/security/cert-svc-ui.git] / view / src / certificates / user_cert / install_certificate.c
1 /*
2  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * This file is part of the Manage Applications
5  * Written by Eunmi Son <eunmi.son@samsung.com>
6  *
7  * Author of this file:
8  * Janusz Kozerski <j.kozerski@samsung.com>
9  *
10  * PROPRIETARY/CONFIDENTIAL
11  *
12  * This software is the confidential and proprietary information of
13  * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
14  * disclose such Confidential Information and shall use it only in
15  * accordance with the terms of the license agreement you entered
16  * into with SAMSUNG ELECTRONICS.
17  *
18  * SAMSUNG make no representations or warranties about the suitability
19  * of the software, either express or implied, including but not limited
20  * to the implied warranties of merchantability, fitness for a particular
21  * purpose, or non-infringement. SAMSUNG shall not be liable for any
22  * damages suffered by licensee as a result of using, modifying or
23  * distributing this software or its derivatives.
24  *
25  */
26 #define _GNU_SOURCE
27
28 #include <stdlib.h>
29
30 #include "certificates/certificate_util.h"
31 #include "certificates/certificates.h"
32
33 static void copy(char *source, char *dest);
34
35 static char *sd_dir_path = PATH_SDCARD;
36 //static char *sd_dir_path = PATH_CERT_WAC; // This path can be use for testing instead PATH_SDCARD
37 static char *user_dir_path = PATH_CERT_USER;
38
39 static struct ug_data *ad;
40 static struct ListElement *firstListElement;
41 static struct ListElement *lastListElement;
42
43 void user_search_cert_cb(void *data, Evas_Object *obj, void *event_info) {
44
45         ad = (struct ug_data *) data;
46         Evas_Object *list = NULL;
47
48         firstListElement = initList();
49         lastListElement = firstListElement;
50
51         list = elm_list_add(ad->win_main);
52         elm_list_mode_set(list, ELM_LIST_COMPRESS);
53         evas_object_smart_callback_add(list, "selected", list_clicked_cb, NULL);
54
55         if(make_list(ad, list, sd_dir_path, lastListElement, TO_INSTALL)){
56                 Evas_Object *no_content = elm_layout_add(ad->win_main);
57                 elm_layout_theme_set(no_content, "layout", "nocontents", "text");
58                 elm_object_part_text_set(no_content, "elm.text", dgettext(PACKAGE, "IDS_COM_BODY_NO_CONTENTS"));
59                 evas_object_size_hint_weight_set(no_content, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
60                 evas_object_show(no_content);
61
62                 elm_naviframe_item_push(ad->navi_bar, dgettext(PACKAGE, "SEARCHED_CERTIFICATE"), NULL, NULL, no_content, NULL);
63         } else {
64                 Elm_Object_Item *itm = NULL;
65                 itm = elm_naviframe_item_push(ad->navi_bar, dgettext(PACKAGE, "SEARCHED_CERTIFICATE"), NULL, NULL, list, NULL);
66
67                 Evas_Object *back = NULL;
68                 back = elm_object_item_part_content_get(itm, "prev_btn");
69                 evas_object_smart_callback_add(back, "clicked", back_cb, ad);
70         }
71
72 }
73
74
75 void install_cb(void *data, Evas_Object *obj, void *event_info) {
76         LOGD("install_cb");
77         struct ListElement *listElement = (struct ListElement *) data;
78         char *file_name = listElement->name;
79         LOGD("%s", file_name);
80         char buf_src[256];
81         char buf_dst[256];
82         sprintf(buf_src, "%s/%s", sd_dir_path, file_name);
83         sprintf(buf_dst, "%s/%s", user_dir_path, file_name);
84         LOGD("Start copying");
85         copy(buf_src, buf_dst);
86         LOGD("End copying");
87
88         deleteList(firstListElement);
89
90         refresh_list(ad);
91         elm_naviframe_item_pop(ad->navi_bar);
92 }
93
94 static void copy(char *source, char *dest) {
95         LOGD("copy()");
96         if (!source || !dest) {
97                 LOGD("Null pointer to files");
98                 return;
99         }
100         char *command;
101         int result;
102         result = asprintf(&command, "cp %s %s", source, dest);
103         if(command == NULL && result != -1){
104                 LOGD("Error while allocating memory");
105                 return; //Error while allocating memory
106         }
107
108         LOGD("%s", command);
109         result = system(command);
110         LOGD("%s --- return %d", command, result);
111
112         free(command);
113         LOGD("copy() - done");
114 }