check file exist when img item adding
authorHyoyoung Chang <hyoyoung.chang@samsung.com>
Wed, 27 Oct 2010 12:09:23 +0000 (21:09 +0900)
committerHyoyoung Chang <hyoyoung.chang@samsung.com>
Wed, 27 Oct 2010 12:09:23 +0000 (21:09 +0900)
src/cbhm_main.c
src/clipdrawer.c
src/storage.c
src/storage.h
src/xcnphandler.c
src/xcnphandler.h

index 10171f9..63f0a48 100644 (file)
@@ -118,7 +118,6 @@ static Evas_Object* load_edj(Evas_Object *parent, const char *file, const char *
 static int init(struct appdata *ad)
 {
        /* FIXME : add checking multiple instance */
-
        xcnp_init(ad);
        init_appview(ad);
        init_scrcapture(ad);
index afea455..4269921 100644 (file)
@@ -137,7 +137,12 @@ int clipdrawer_add_image_item(char *imagepath)
        char* filepath = NULL;
        Eina_List *igl = NULL;
        unsigned int igl_counter = 0;
-       filepath = &imagepath[7]; // skip 'file://'
+
+       if (!check_regular_file(imagepath))
+       {
+               DTRACE("Error : it isn't normal file = %s\n", imagepath);
+               return -1;
+       }
 
        igl = elm_gengrid_items_get(ad->imggrid);
        igl_counter = eina_list_count(igl);
@@ -148,7 +153,7 @@ int clipdrawer_add_image_item(char *imagepath)
        }
 
        newgenimg = malloc(sizeof(gridimgitem_t));
-       newgenimg->path = eina_stringshare_add(filepath);
+       newgenimg->path = eina_stringshare_add(imagepath);
        newgenimg->item = elm_gengrid_item_append(ad->imggrid, &gic, newgenimg, NULL, NULL);
        
        return TRUE;
@@ -205,10 +210,7 @@ int clipdrawer_init(void *data)
 
        for (i = 0; i < N_IMAGES; i++)
        {
-               newgenimg = malloc(sizeof(gridimgitem_t));
-               newgenimg->path = eina_stringshare_add(g_images_path[i]);
-               newgenimg->item = elm_gengrid_item_append(ad->imggrid, &gic, newgenimg, NULL, NULL);
-//             evas_object_data_set(newgenimg->item, "URI", g_images_path[i]);
+               clipdrawer_add_image_item(g_images_path[i]);
        }
 
        evas_object_show (ad->imggrid);
index 11c32dc..77013a0 100644 (file)
@@ -153,4 +153,15 @@ int close_storage()
        return 0;
 }
 
+int check_regular_file(char *path)
+{
+       struct stat fattr;
+       if (stat(path, &fattr))
+       {
+               DTRACE("Cannot get file at path = %s\n", path);
+               return FALSE;
+       }
+       
+       return S_ISREG(fattr.st_mode);
+}
 
index 352f701..2b25985 100644 (file)
@@ -15,4 +15,6 @@ int get_item_counts();
 char *get_item_contents_by_pos(int pos);
 int close_storage();
 
+int check_regular_file(char *path);
+
 #endif // _storage_h_
index c4b4353..b12ef6e 100755 (executable)
@@ -18,7 +18,7 @@ int xcnp_init(void *data)
        struct appdata *ad = data;
        DTRACE("xcnp_init().. start!\n");
 
-       if(!_cbhm_init())
+       if(!_cbhm_init(ad))
        {
                DTRACE("Failed - _cbhm_init()..!\n");
                return NULL;
@@ -240,10 +240,11 @@ int get_selection_content(void *data)
                1. does the file exist?
                2. dose the file wanted type? */
        if (!strncmp(unesc, "file://", 7) && 
-               (strstr(unesc,".png") || strstr(unesc,".jpg")))
+               (strstr(unesc,".png") || strstr(unesc,".jpg")) &&
+               check_regular_file(unesc+7))
        {
-               DTRACE("clipdrawer add path = %s\n", unesc);
-               clipdrawer_add_image_item(unesc);
+               DTRACE("clipdrawer add path = %s\n", unesc+7);
+               clipdrawer_add_image_item(unesc+7);
        }
        else
                add_to_storage_buffer(ad, unesc, unesc_len);
@@ -339,8 +340,9 @@ int processing_selection_request(Ecore_X_Event_Selection_Request *ev)
        return 0;
 }
 
-static int _cbhm_init()
+static int _cbhm_init(void *data)
 {
+       struct appdata *ad = data;
        //Set default data structure
        //Control that the libraries are properly initialized
        if (!ecore_init()) return EXIT_FAILURE;
@@ -580,7 +582,6 @@ static Ecore_X_Window get_selection_secondary_target_win()
 
 int set_selection_secondary_data(char *sdata)
 {
-//     elm_selection_set(1, obj, /*mark up*/1, p);
        Ecore_X_Window setwin = get_selection_secondary_target_win();
        if (setwin == None)
                return 0;
index ae6bf34..6fedb2b 100755 (executable)
@@ -28,7 +28,7 @@ int set_selection_owner();
 int get_selection_content(void *data);
 int processing_selection_request(Ecore_X_Event_Selection_Request *ev);
 
-static int _cbhm_init();
+static int _cbhm_init(void *data);
 static void _cbhm_fini();
 static int _xsel_clear_cb(void *data, int ev_type, void *event);
 static int _xsel_request_cb(void *data, int ev_type, void *event);