Apply compressed license.html 75/123875/3 accepted/tizen/unified/20170420.155445 submit/tizen/20170420.073454
authorKiseok Chang <kiso.chang@samsung.com>
Fri, 7 Apr 2017 09:41:13 +0000 (18:41 +0900)
committerKiseok Chang <kiso.chang@samsung.com>
Thu, 20 Apr 2017 05:39:43 +0000 (14:39 +0900)
- Add licenced.zip instead of license.html
- uncompress zip file before showing doc
- remove tempfile(license.html) after setting-fileview app close

Change-Id: I90550991fe67c84d468e1f89ce9ff8b37ee24e7a
Signed-off-by: Kiseok Chang <kiso.chang@samsung.com>
include/setting-debug.h
packaging/org.tizen.setting.spec
setting-fileview/src/setting-fileview.c [changed mode: 0644->0755]
setting-license/CMakeLists.txt
setting-license/src/setting-license-view.c [changed mode: 0644->0755]

index e65877a75a2aa2b0c57bf733704fe52b36693121..8d167f95051056049bb83854b260d073bb18bb5a 100755 (executable)
 
 /*#endif*/
 
+
+#define SUPPORT_COMPRESSED_LICENSE     1
+
+
 /**< 1 : turn the low batter handlding off */
 #define         LOW_BATTERY_DO_NOTHING         1
 
index b794fc46c7fc960ca2e476afbcabe67e80c30c10..0df5d402772de0c8e34ccfe416cbeff562a2ab58 100755 (executable)
@@ -63,7 +63,8 @@ BuildRequires:  pkgconfig(tts)
 BuildRequires:  pkgconfig(tts-setting)
 BuildRequires:  pkgconfig(ui-gadget-1)
 BuildRequires:  pkgconfig(vconf)
-BuildRequires: pkgconfig(context)
+BuildRequires:  pkgconfig(context)
+BuildRequires:  pkgconfig(minizip)
 BuildRequires:  libcap-devel
 BuildRequires:  cmake
 BuildRequires:  edje-tools
old mode 100644 (file)
new mode 100755 (executable)
index 960decd..8d27387
@@ -101,6 +101,13 @@ static void on_app_control(app_control_h service, void *priv)
        SettingFileview *ad = priv;
        ret_if(!ad);
 
+       if (app_control_init(&ad->md, service) != APP_CONTROL_ERROR_NONE) {
+               SETTING_TRACE_ERROR("Failed to init app_control");
+               ui_app_exit();
+               return;
+       }
+
+
        if (!_get_service_extra_data(service, priv)) {
                SETTING_TRACE_ERROR("Invalid arguement");
                return;
@@ -135,6 +142,9 @@ static void on_app_terminate(void *priv)
        if (ad->input_title)
                FREE(ad->input_title);
 
+       if (app_control_finish(&ad->md) != APP_CONTROL_ERROR_NONE)
+               SETTING_TRACE_ERROR("Failed to finish app_control");
+
        SETTING_TRACE_END;
 }
 
index b24ba478d71550672407c02c36c022cf7775575f..4973a8fdc70083d0e356bb19d80a0059315fd672 100755 (executable)
@@ -9,6 +9,7 @@ pkg_check_modules(pkgs_license REQUIRED
        capi-appfw-application
        dlog
        elementary
+       minizip
 )
 
 FOREACH(flag ${pkgs_license_CFLAGS})
old mode 100644 (file)
new mode 100755 (executable)
index 87955a9..421ca35
@@ -19,6 +19,8 @@
  *
  */
 
+#include <unzip.h>
+
 #include "setting-license.h"
 
 #define TEXT_CLEAR_LICENSE      "IDS_ST_BODY_REMOVE_LICENCE"
 #define SETTING_DIVX_MODE_DEREG 1
 #define SETTING_LICESE_SAMSUNG_LEGAL "IDS_ST_BODY_SAMSUNG_LEGAL"
 
+#if SUPPORT_COMPRESSED_LICENSE
+#define UNCOMPRESSEDFILE_DIR   "/home/owner/apps_rw/org.tizen.setting/data"
+#endif
+
+
 static void __mouse_up_Gendial_list_cb(void *data,
                Evas_Object *obj, void *event_info);
 static int _view_create(void *cb);
@@ -91,6 +98,9 @@ static void _app_reply_cb(app_control_h request, app_control_h reply,
                app_control_result_e result_code, void *priv)
 {
        SETTING_TRACE_BEGIN;
+#if SUPPORT_COMPRESSED_LICENSE
+       char tempfilename[256];         // for temp file
+#endif
        SettingLicenseData *ad = (SettingLicenseData *)priv;
        ret_if(!ad);
 
@@ -101,9 +111,112 @@ static void _app_reply_cb(app_control_h request, app_control_h reply,
                SETTING_TRACE("webkit_address = %s", webkit_address);
                add_app_reply(&ad->md, "webkit_address", webkit_address);
                FREE(webkit_address);
+
+#if SUPPORT_COMPRESSED_LICENSE
+               // remove temorary file
+               snprintf(tempfilename,256, "%s/license.html", UNCOMPRESSEDFILE_DIR);
+               remove(tempfilename);
+#endif
+       }
+
+}
+
+
+
+
+
+
+#if SUPPORT_COMPRESSED_LICENSE
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+
+#define WRITEBUFFERSIZE (1024*1024*3) // 3Mb buffer
+
+static int readZipFile(char *zipFile, char *fileInZip) 
+{
+       SETTING_TRACE_BEGIN;
+       
+       int err = UNZ_OK;                 // error status
+       uInt size_buf = WRITEBUFFERSIZE;  // byte size of buffer to store raw data
+       void* buf;                        // the buffer
+       char filename_inzip[256];         // for unzGetCurrentFileInfo
+       unz_file_info file_info;          // for unzGetCurrentFileInfo
+       char tempfilename[256];         // for temp file
+       FILE *tempfile_fp = 0;
+
+
+       unzFile uf = unzOpen(zipFile); // open zipfile stream
+       if (uf == NULL) {
+               SETTING_TRACE("Cannot open %s", zipFile);
+               return -1;
+       } // file is open
+
+       if ( unzLocateFile(uf,fileInZip,1) ) { // try to locate file inside zip
+               // second argument of unzLocateFile: 1 = case sensitive, 0 = case-insensitive
+               SETTING_TRACE("File %s not found in %s", fileInZip, zipFile);
+               return -1;
+       } // file inside zip found
+
+       if (unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0)) {
+               SETTING_TRACE("Error %d with zipfile %s in unzGetCurrentFileInfo.", err, zipFile);
+               return -1;
+       } // obtained the necessary details about file inside zip
+
+       buf = (void*)malloc(size_buf); // setup buffer
+       if (buf == NULL) {
+               SETTING_TRACE("Error allocating memory for read buffer");
+               return -1;
+       } // buffer ready
+
+       err = unzOpenCurrentFilePassword(uf,NULL); // Open the file inside the zip (password = NULL)
+       if (err != UNZ_OK) {
+               SETTING_TRACE("Error %d with zipfile %s in unzOpenCurrentFilePassword.", err, zipFile);
+               return -1;
+       } // file inside the zip is open
+
+       snprintf(tempfilename,256, "%s/%s", UNCOMPRESSEDFILE_DIR, fileInZip);
+
+       tempfile_fp = fopen(tempfilename,"w");
+       if (tempfile_fp == NULL) {
+               SETTING_TRACE("Error to write tempfile :  %s", tempfilename);
+               return -1;
+       } // open temp file
+
+       // Copy contents of the file inside the zip to the buffer
+       printf("Extracting: %s from %s\n", filename_inzip, zipFile);
+       do {
+               err = unzReadCurrentFile(uf,buf,size_buf);
+               if (err < 0) {
+                       SETTING_TRACE("Error %d with zipfile %s in unzReadCurrentFile", err, zipFile);
+                       break;
+               }
+               // copy the buffer to a string
+               if (err > 0) {
+                       //for (int i = 0; i < (int) err; i++) 
+                               //sout.push_back( *(((char*)buf)+i) );
+                       fwrite(buf, sizeof(char), err, tempfile_fp);
+               }
+       } while (err > 0);
+
+       err = unzCloseCurrentFile (uf);  // close the zipfile
+       if (err!=UNZ_OK) {
+               SETTING_TRACE("Error %d with zipfile %s in unzCloseCurrentFile", err, zipFile);
        }
+
+       free(buf); // free up buffer memory
+
+       fclose(tempfile_fp); // close temp file 
+
+       return 0;
 }
 
+#endif
+
+
+
 static void __main_license_clicked(void *data)
 {
        SETTING_TRACE_BEGIN;
@@ -111,21 +224,40 @@ static void __main_license_clicked(void *data)
        int ret;
        SettingLicenseData *ad = (SettingLicenseData *)data;
        app_control_h svc = NULL;
+#if SUPPORT_COMPRESSED_LICENSE
+       char tempfilename[256];         // for temp file
+#endif
 
        ret_if(app_control_create(&svc) != 0);
+
+
+#if SUPPORT_COMPRESSED_LICENSE
+       ret = readZipFile("/usr/share/license.zip", "license.html");
+       if(ret != 0){
+               app_control_destroy(svc);
+               return;
+       }
+
+       // set path of license.html
+       snprintf(tempfilename,256, "file://%s/license.html", UNCOMPRESSEDFILE_DIR);
+       app_control_add_extra_data(svc, "file", tempfilename);
+#else
        app_control_add_extra_data(svc, "file",
                        SETTING_OPEN_SOURCE_LICENSE_PATH);
+#endif
+
        app_control_add_extra_data(svc, "title",
                        _("IDS_ST_BODY_OPEN_SOURCE_LICENCES"));
 
        ret = app_launcher_svc("org.tizen.setting-fileview", svc,
                        _app_reply_cb, (void *)ad);
-       if (ret != 0)
+       if (ret != 0) {
                setting_create_popup(ad, ad->md.window, NULL,
-                               _(UNSUPPORTED_FUNCTION), NULL, 0, false, false,
-                               0);
+                               _(UNSUPPORTED_FUNCTION), NULL, 0, false, false, 0);
+       }
 
        app_control_destroy(svc);
+
 }
 
 static void __mouse_up_Gendial_list_cb(void *data,