2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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
8 * http://floralicense.org/license/
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.
19 #include <sys/types.h>
27 #include <libxml/parser.h>
28 #include <libxml/tree.h>
30 #include <pkgmgr-info.h>
32 #include <widget_service.h>
33 #include <widget_service_internal.h>
34 #include <widget_abi.h>
40 #define DbgPrint(format, arg...) SECURE_LOGD("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
41 #define ErrPrint(format, arg...) SECURE_LOGE("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
42 #define ErrPrintWithConsole(format, arg...) do { fprintf(stderr, "[%s/%s:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg); SECURE_LOGE("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg); } while (0)
46 #define DEFAULT_CATEGORY "http://tizen.org/category/default"
48 #if !defined(WIDGET_COUNT_OF_SIZE_TYPE)
49 #define WIDGET_COUNT_OF_SIZE_TYPE 13
62 * CREATE TABLE version ( version INTEGER )
66 * +-------+-------+-------+-------+-------------------+
67 * | appid | pkgid | uiapp | prime | categ(from ver 2) |
68 * +-------+-------+-------+-------+-------------------+
69 * | - | - | - | - | - |
70 * +-------+-------+-------+-------+-------------------+
71 * CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER, category TEXT )
75 * +-------+---------+-----+---------+----------+---------+-----------+---------+--------+----------+---------+---------+--------+--------+-------+-----------------------+
76 * | pkgid | network | abi | secured | box_type | box_src | box_group | gbar_type | gbar_src | gbar_group | libexec | timeout | period | script | pinup | count(from ver 4) | direct_input | hw_acceleration |
77 * +-------+---------+-----+---------+----------+---------+-----------+---------+--------+----------+---------+---------+--------+--------+-------+-----------------------+-------|---------------|
78 * | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
79 * +-------+---------+-----+---------+----------+---------+-----------+---------+--------+----------+---------+---------+--------+--------+-------+-----------------------+-------|---------------|
80 * CREATE TABLE provider ( pkgid TEXT PRIMARY KEY NOT NULL, network INTEGER, abi TEXT, secured INTEGER, box_type INTEGER, box_src TEXT, box_group TEXT, gbar_type TEXT, gbar_src TEXT, gbar_group TEXT, libexec TEXT, timeout INTEGER, period TEXT, script TEXT, pinup INTEGER, count INTEGER, direct_input INTEGER DEFAULT 0, hw_acceleration TEXT DEFAULT 'none', FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid))
82 * = box_type = { text | buffer | script | image }
83 * = gbar_type = { text | buffer | script }
84 * = network = { 1 | 0 }
85 * = secured = { 1 | 0 }
89 * +-------+------+---------+-------------+-----------+---------+-----------+-------+
90 * | pkgid | Icon | Name | auto_launch | gbar_size | content | nodisplay | setup |
91 * +-------+------+---------+-------------+-----------+---------+-----------+-------+
92 * | - | - | - | - | - | - | - | - |
93 * +-------+------+---------+-------------+-----------+---------+-----------+-------+
94 * CREATE TABLE client ( pkgid TEXT PRIMARY KEY NOT NULL, icon TEXT, name TEXT, auto_launch TEXT, gbar_size TEXT, content TEXT, nodisplay INTEGER, setup TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) )
96 * = auto_launch = UI-APPID
97 * = gbar_size = WIDTHxHEIGHT
101 * +-------+------+------+------+
102 * | fk | lang | name | icon |
103 * +-------+------+------+------+
104 * | pkgid | - | - | - |
105 * +-------+------+------+------+
106 * CREATE TABLE i18n ( pkgid TEXT NOT NULL, lang TEXT COLLATE NOCASE, name TEXT, icon TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) )
110 * +-------+-----------+---------+--------------+------------+-------------------------+
111 * | pkgid | size_type | preview | touch_effect | need_frame | mouse_event(from ver 3) |
112 * +-------+-----------+---------+--------------+------------+-------------------------+
113 * | - | - | - | - | - | - |
114 * +-------+-----------+---------+--------------+------------+-------------------------+
115 * CREATE TABLE box_size ( pkgid TEXT NOT NULL, size_type INTEGER, preview TEXT, INTEGER, touch_effect INTEGER, need_frame INTEGER, mouse_event INTEGER, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) )
117 * = box_size_list = { WIDTHxHEIGHT; WIDTHxHEIGHT; ... }
120 * +----+---------+----------+-------+
121 * | id | cluster | category | pkgid |
122 * +----+---------+----------+-------+
124 * +----+---------+----------+-------|
125 * CREATE TABLE groupinfo ( id INTEGER PRIMARY KEY AUTOINCREMENT, cluster TEXT NOT NULL, category TEXT NOT NULL, appid TEXT NOT NULL, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ))
128 * +-------+----+----------+-----------+
129 * | pkgid | id | ctx_item | option_id |
130 * +-------+----+----------+-----------+
131 * CREATE TABLE groupmap ( option_id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER, pkgid TEXT NOT NULL, ctx_item TEXT NOT NULL, FOREIGN KEY(id) REFERENCES groupinfo(id), FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) )
135 * +-------+-----------+-----+-------+
136 * | pkgid | option_id | key | value |
137 * +-------+-----------+-----+-------+
138 * CREATE TABLE option ( pkgid TEXT NOT NULL, option_id INTEGER, key TEXT NOT NULL, value TEXT NOT NULL, FOREIGN KEY(option_id) REFERENCES groupmap(option_id), FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) )
141 #if !defined(LIBXML_TREE_ENABLED)
142 #error "LIBXML is not supporting the tree"
149 #define LOG_TAG "PKGMGR_WIDGET2"
163 xmlChar *auto_launch;
165 xmlChar *name; /* Default name */
166 xmlChar *icon; /* Default icon */
167 xmlChar *libexec; /* Path of the SO file */
168 xmlChar *timeout; /* INTEGER, timeout */
169 xmlChar *period; /* DOUBLE, update period */
170 xmlChar *script; /* Script engine */
171 xmlChar *content; /* Content information */
173 xmlChar *uiapp; /* UI App Id */
174 xmlChar *category; /* Category of this box */
176 int pinup; /* Is this support the pinup feature? */
177 int primary; /* Is this primary widget? */
179 int count; /* Max count of instances */
180 int direct_input; /* Use the input node to get the event directly */
182 int default_mouse_event; /* Mouse event processing option for widget */
183 int default_touch_effect;
184 int default_need_frame;
186 enum widget_widget_type widget_type;
188 xmlChar *widget_group;
189 int size_list; /* 1x1, 2x1, 2x2, 4x1, 4x2, 4x3, 4x4 */
191 xmlChar *preview[WIDGET_COUNT_OF_SIZE_TYPE];
192 int touch_effect[WIDGET_COUNT_OF_SIZE_TYPE]; /* Touch effect of a widget */
193 int need_frame[WIDGET_COUNT_OF_SIZE_TYPE]; /* Box needs frame which should be cared by viewer */
194 int mouse_event[WIDGET_COUNT_OF_SIZE_TYPE];
196 enum widget_gbar_type gbar_type;
199 xmlChar *gbar_size; /* Default PD size */
200 xmlChar *hw_acceleration;
202 struct dlist *i18n_list;
203 struct dlist *group_list;
210 struct dlist *option_list;
222 .dbfile = "/usr/dbspace/.widget.db",
226 static inline int next_state(int from, char ch)
244 static inline void abspath(const char* pBuffer, char* pRet)
250 int src_len = strlen(pBuffer);
254 while (src_idx <= src_len) {
256 state = next_state(from, pBuffer[src_idx]);
261 pRet[idx] = pBuffer[src_idx];
271 pRet[idx] = pBuffer[src_idx];
276 // Only can go to the 1 or 4
283 while (idx > 1 && pRet[idx] != '/') {
284 idx--; /* Remove .. */
286 if (idx > 1 && pRet[idx] == '/') {
289 while (idx > 1 && pRet[idx] != '/') {
290 idx--; /* Remove parent folder */
294 pRet[idx] = pBuffer[src_idx];
304 static inline xmlChar *abspath_strdup(xmlChar *src)
306 return xmlMalloc(xmlStrlen(src) + 2);
309 int begin_transaction(void)
314 ret = sqlite3_prepare_v2(s_info.handle, "BEGIN TRANSACTION", -1, &stmt, NULL);
316 if (ret != SQLITE_OK) {
317 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
321 if (sqlite3_step(stmt) != SQLITE_DONE) {
322 DbgPrint("Failed to do update (%s)\n",
323 sqlite3_errmsg(s_info.handle));
324 sqlite3_finalize(stmt);
328 sqlite3_finalize(stmt);
332 static inline int rollback_transaction(void)
337 ret = sqlite3_prepare_v2(s_info.handle, "ROLLBACK TRANSACTION", -1, &stmt, NULL);
338 if (ret != SQLITE_OK) {
339 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
343 if (sqlite3_step(stmt) != SQLITE_DONE) {
344 DbgPrint("Failed to do update (%s)\n",
345 sqlite3_errmsg(s_info.handle));
346 sqlite3_finalize(stmt);
350 sqlite3_finalize(stmt);
354 inline int commit_transaction(void)
359 ret = sqlite3_prepare_v2(s_info.handle, "COMMIT TRANSACTION", -1, &stmt, NULL);
360 if (ret != SQLITE_OK) {
361 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
365 if (sqlite3_step(stmt) != SQLITE_DONE) {
366 DbgPrint("Failed to do update (%s)\n",
367 sqlite3_errmsg(s_info.handle));
368 sqlite3_finalize(stmt);
372 sqlite3_finalize(stmt);
376 static void db_create_version(void)
378 static const char *ddl = "CREATE TABLE version (version INTEGER)";
381 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
382 ErrPrint("Failed to execute the DDL (%s)\n", err);
386 if (sqlite3_changes(s_info.handle) == 0) {
387 ErrPrint("No changes to DB\n");
391 static int set_version(int version)
393 static const char *dml = "INSERT INTO version (version) VALUES (?)";
397 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
398 if (ret != SQLITE_OK) {
399 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
403 if (sqlite3_bind_int(stmt, 1, version) != SQLITE_OK) {
404 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
409 ret = sqlite3_step(stmt);
410 if (ret != SQLITE_DONE) {
411 ErrPrint("Failed to execute the DML for version: %d\n", ret);
419 sqlite3_clear_bindings(stmt);
420 sqlite3_finalize(stmt);
424 static int update_version(int version)
426 static const char *dml = "UPDATE version SET version = ?";
430 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
431 if (ret != SQLITE_OK) {
432 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
436 if (sqlite3_bind_int(stmt, 1, version) != SQLITE_OK) {
437 ErrPrint("Failed to bind a version: %s\n", sqlite3_errmsg(s_info.handle));
442 ret = sqlite3_step(stmt);
443 if (ret != SQLITE_DONE) {
444 ErrPrint("Failed to execute DML: %d\n", ret);
452 sqlite3_clear_bindings(stmt);
453 sqlite3_finalize(stmt);
457 static int get_version(void)
459 static const char *dml = "SELECT version FROM version";
463 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
464 if (ret != SQLITE_OK) {
468 if (sqlite3_step(stmt) != SQLITE_ROW) {
471 ret = sqlite3_column_int(stmt, 0);
475 sqlite3_clear_bindings(stmt);
476 sqlite3_finalize(stmt);
482 * From version 1 to 2
484 static void upgrade_pkgmap_for_category(void)
487 static const char *ddl;
489 ddl = "ALTER TABLE pkgmap ADD COLUMN category TEXT DEFAULT \"" DEFAULT_CATEGORY "\"";
490 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
491 ErrPrint("Failed to execute the DDL (%s)\n", err);
495 if (sqlite3_changes(s_info.handle) == 0) {
496 ErrPrint("No changes to DB\n");
503 * From version 4 to 5
504 * "provider" table should have "direct_input" column.
505 * "direct_input" will be used for selecting input event path.
506 * if it is "true", the provider must has to get all events from device node directly.
507 * The file descriptor will be given by data-provider-master
509 static void upgrade_to_version_5(void)
512 static const char *ddl;
516 * Create a new column "direct_input" for provider table
518 ddl = "ALTER TABLE provider ADD COLUMN direct_input INTEGER DEFAULT 0";
519 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
520 ErrPrint("Failed to execute the DDL (%s)\n", err);
524 if (sqlite3_changes(s_info.handle) == 0) {
525 ErrPrint("No changes to DB\n");
530 * Create a new column "hw_acceleration" for provider table
532 ddl = "ALTER TABLE provider ADD COLUMN hw_acceleration TEXT DEFAULT 'none'";
533 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
534 ErrPrint("Failed to execute the DDL (%s)\n", err);
538 if (sqlite3_changes(s_info.handle) == 0) {
539 ErrPrint("No changes to DB\n");
545 * From version 3 to 4
546 * "provider" table should have "count" column.
547 * "count" will be used for limiting creatable count of instances for each widget.
548 * Every widget developer should describe their max count of creatable instances.
550 static void upgrade_to_version_4(void)
553 static const char *ddl;
557 * Create a new column for count to provider table.
559 ddl = "ALTER TABLE provider ADD COLUMN count INTEGER DEFAULT 0";
560 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
561 ErrPrint("Failed to execute the DDL (%s)\n", err);
565 if (sqlite3_changes(s_info.handle) == 0) {
566 ErrPrint("No changes to DB\n");
572 * From version 2 to 3
573 * mouse_event is deleted from client table
574 * mouse_event is added to box_size table
576 * Every size has their own configuration for mouse_event flag.
578 static void upgrade_to_version_3(void)
581 static const char *ddl;
582 static const char *dml;
583 sqlite3_stmt *select_stmt;
588 * Create a new column for mouse_event to box_size table.
590 ddl = "ALTER TABLE box_size ADD COLUMN mouse_event INTEGER DEFAULT 0";
591 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
592 ErrPrint("Failed to execute the DDL (%s)\n", err);
596 if (sqlite3_changes(s_info.handle) == 0) {
597 ErrPrint("No changes to DB\n");
602 * Copy mouse_event values from the client to the box_size table.
604 dml = "SELECT pkgid, mouse_event FROM client";
605 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &select_stmt, NULL);
606 if (ret == SQLITE_OK) {
607 sqlite3_stmt *update_stmt;
609 dml = "UPDATE box_size SET mouse_event = ? WHERE pkgid = ?";
610 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &update_stmt, NULL);
611 if (ret == SQLITE_OK) {
615 while (sqlite3_step(select_stmt) == SQLITE_ROW) {
616 pkgid = (const char *)sqlite3_column_text(select_stmt, 0);
618 ErrPrint("Package Id is not valid\n");
622 mouse_event = sqlite3_column_int(select_stmt, 1);
624 ret = sqlite3_bind_int(update_stmt, 1, mouse_event);
625 if (ret != SQLITE_OK) {
626 ErrPrint("Failed to bind mouse_event [%s], [%d]\n", pkgid, mouse_event);
627 sqlite3_reset(update_stmt);
628 sqlite3_clear_bindings(update_stmt);
632 ret = sqlite3_bind_text(update_stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
633 if (ret != SQLITE_OK) {
634 ErrPrint("Failed to bind pkgid [%s], [%d]\n", pkgid, mouse_event);
635 sqlite3_reset(update_stmt);
636 sqlite3_clear_bindings(update_stmt);
640 ret = sqlite3_step(update_stmt);
641 if (ret != SQLITE_DONE) {
642 ErrPrint("Failed to execute DML: %d\n", ret);
643 sqlite3_reset(update_stmt);
644 sqlite3_clear_bindings(update_stmt);
648 sqlite3_reset(update_stmt);
649 sqlite3_clear_bindings(update_stmt);
652 sqlite3_finalize(update_stmt);
654 ErrPrint("Failed to execute DML\n");
657 sqlite3_reset(select_stmt);
658 sqlite3_clear_bindings(select_stmt);
659 sqlite3_finalize(select_stmt);
661 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
666 * Drop a column from the client table
668 ddl = "ALTER TABLE client DROP COLUMN mouse_event";
669 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
670 ErrPrint("Failed to execute the DDL (%s)\n", err);
674 if (sqlite3_changes(s_info.handle) == 0) {
675 ErrPrint("No changes to DB\n");
681 void db_upgrade_db_schema(void)
685 version = get_version();
690 /* Need to create version table */
692 if (set_version(CUR_VER) < 0) {
693 ErrPrint("Failed to set version\n");
695 /* Need to set version */
697 upgrade_pkgmap_for_category();
699 upgrade_to_version_3();
701 upgrade_to_version_4();
703 upgrade_to_version_5();
705 /* Need to update version */
706 DbgPrint("Old version: %d\n", version);
707 if (update_version(CUR_VER) < 0) {
708 ErrPrint("Failed to update version\n");
715 static inline int db_create_pkgmap(void)
718 static const char *ddl;
720 ddl = "CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER, category TEXT )";
721 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
722 ErrPrint("Failed to execute the DDL (%s)\n", err);
726 if (sqlite3_changes(s_info.handle) == 0) {
727 ErrPrint("No changes to DB\n");
733 static inline int db_insert_pkgmap(const char *appid, const char *pkgid, const char *uiappid, int primary, const char *category)
736 static const char *dml;
739 dml = "INSERT INTO pkgmap ( appid, pkgid, uiapp, prime, category ) VALUES (? ,?, ?, ?, ?)";
740 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
741 if (ret != SQLITE_OK) {
742 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
746 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
747 if (ret != SQLITE_OK) {
748 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
753 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
754 if (ret != SQLITE_OK) {
755 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
760 ret = sqlite3_bind_text(stmt, 3, uiappid, -1, SQLITE_TRANSIENT);
761 if (ret != SQLITE_OK) {
762 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
767 ret = sqlite3_bind_int(stmt, 4, primary);
768 if (ret != SQLITE_OK) {
769 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
774 ret = sqlite3_bind_text(stmt, 5, category, -1, SQLITE_TRANSIENT);
775 if (ret != SQLITE_OK) {
776 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
782 if (sqlite3_step(stmt) != SQLITE_DONE) {
783 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
789 sqlite3_clear_bindings(stmt);
790 sqlite3_finalize(stmt);
794 static inline int db_remove_pkgmap(const char *pkgid)
797 static const char *dml;
800 dml = "DELETE FROM pkgmap WHERE pkgid = ?";
801 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
802 if (ret != SQLITE_OK) {
803 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
807 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
808 if (ret != SQLITE_OK) {
809 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
815 if (sqlite3_step(stmt) != SQLITE_DONE) {
816 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
822 sqlite3_clear_bindings(stmt);
823 sqlite3_finalize(stmt);
827 static inline int db_create_provider(void)
830 static const char *ddl;
832 ddl = "CREATE TABLE provider (" \
833 "pkgid TEXT PRIMARY KEY NOT NULL, network INTEGER, " \
834 "abi TEXT, secured INTEGER, box_type INTEGER, " \
835 "box_src TEXT, box_group TEXT, gbar_type INTEGER, " \
836 "gbar_src TEXT, gbar_group TEXT, libexec TEXT, timeout INTEGER, period TEXT, script TEXT, pinup INTEGER, "\
837 "count INTEGER, direct_input INTEGER DEFAULT 0, hw_acceleration TEXT DEFAULT 'none', "\
838 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
840 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
841 ErrPrint("Failed to execute the DDL (%s)\n", err);
845 if (sqlite3_changes(s_info.handle) == 0) {
846 ErrPrint("No changes to DB\n");
852 static inline int db_remove_provider(const char *pkgid)
854 static const char *dml;
858 dml = "DELETE FROM provider WHERE pkgid = ?";
859 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
860 if (ret != SQLITE_OK) {
861 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
865 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
866 if (ret != SQLITE_OK) {
867 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
873 if (sqlite3_step(stmt) != SQLITE_DONE) {
874 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
880 sqlite3_clear_bindings(stmt);
881 sqlite3_finalize(stmt);
885 static int db_insert_provider(struct widget *widget)
887 static const char *dml;
890 char *abi = (char *)widget->abi;
891 char *box_src = (char *)widget->widget_src;
892 char *box_group = (char *)widget->widget_group;
893 char *gbar_src = (char *)widget->gbar_src;
894 char *gbar_group = (char *)widget->gbar_group;
895 char *libexec = (char *)widget->libexec;
896 char *timeout = (char *)widget->timeout;
897 char *period = (char *)widget->period;
898 char *script = (char *)widget->script;
899 char *hw_acceleration = (char *)widget->hw_acceleration;
917 if (!hw_acceleration) {
918 hw_acceleration = "none";
921 dml = "INSERT INTO provider ( pkgid, network, abi, secured, box_type, box_src, box_group, gbar_type, gbar_src, gbar_group, libexec, timeout, period, script, pinup, count, direct_input, hw_acceleration) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
922 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
923 if (ret != SQLITE_OK) {
924 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
928 ret = sqlite3_bind_text(stmt, 1, (char *)widget->pkgid, -1, SQLITE_TRANSIENT);
929 if (ret != SQLITE_OK) {
930 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
935 ret = sqlite3_bind_int(stmt, 2, widget->network);
936 if (ret != SQLITE_OK) {
937 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
942 ret = sqlite3_bind_text(stmt, 3, abi, -1, SQLITE_TRANSIENT);
943 if (ret != SQLITE_OK) {
944 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
948 ret = sqlite3_bind_int(stmt, 4, widget->secured);
949 if (ret != SQLITE_OK) {
950 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
955 ret = sqlite3_bind_int(stmt, 5, widget->widget_type);
956 if (ret != SQLITE_OK) {
957 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
962 ret = sqlite3_bind_text(stmt, 6, box_src, -1, SQLITE_TRANSIENT);
963 if (ret != SQLITE_OK) {
964 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
969 ret = sqlite3_bind_text(stmt, 7, box_group, -1, SQLITE_TRANSIENT);
970 if (ret != SQLITE_OK) {
971 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
976 ret = sqlite3_bind_int(stmt, 8, widget->gbar_type);
977 if (ret != SQLITE_OK) {
978 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
983 ret = sqlite3_bind_text(stmt, 9, gbar_src, -1, SQLITE_TRANSIENT);
984 if (ret != SQLITE_OK) {
985 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
990 ret = sqlite3_bind_text(stmt, 10, gbar_group, -1, SQLITE_TRANSIENT);
991 if (ret != SQLITE_OK) {
992 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
997 ret = sqlite3_bind_text(stmt, 11, libexec, -1, SQLITE_TRANSIENT);
998 if (ret != SQLITE_OK) {
999 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1004 ret = sqlite3_bind_int(stmt, 12, atoi(timeout));
1005 if (ret != SQLITE_OK) {
1006 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1011 ret = sqlite3_bind_text(stmt, 13, period, -1, SQLITE_TRANSIENT);
1012 if (ret != SQLITE_OK) {
1013 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1018 ret = sqlite3_bind_text(stmt, 14, script, -1, SQLITE_TRANSIENT);
1019 if (ret != SQLITE_OK) {
1020 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1025 ret = sqlite3_bind_int(stmt, 15, widget->pinup);
1026 if (ret != SQLITE_OK) {
1027 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1032 ret = sqlite3_bind_int(stmt, 16, widget->count);
1033 if (ret != SQLITE_OK) {
1034 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1039 ret = sqlite3_bind_int(stmt, 17, widget->direct_input);
1040 if (ret != SQLITE_OK) {
1041 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1046 ret = sqlite3_bind_text(stmt, 18, hw_acceleration, -1, SQLITE_TRANSIENT);
1047 if (ret != SQLITE_OK) {
1048 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1054 if (sqlite3_step(stmt) != SQLITE_DONE) {
1055 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1060 sqlite3_reset(stmt);
1061 sqlite3_clear_bindings(stmt);
1062 sqlite3_finalize(stmt);
1066 static inline int db_create_client(void)
1069 static const char *ddl;
1071 ddl = "CREATE TABLE client (" \
1072 "pkgid TEXT PRIMARY KEY NOT NULL, icon TEXT, name TEXT, " \
1073 "auto_launch TEXT, gbar_size TEXT, content TEXT, nodisplay INTEGER, setup TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1074 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1075 ErrPrint("Failed to execute the DDL (%s)\n", err);
1079 if (sqlite3_changes(s_info.handle) == 0) {
1080 ErrPrint("No changes to DB\n");
1086 static inline int db_insert_client(struct widget *widget)
1088 static const char *dml;
1092 dml = "INSERT INTO client ( pkgid, icon, name, auto_launch, gbar_size, content, nodisplay, setup ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
1093 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1094 if (ret != SQLITE_OK) {
1095 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1099 ret = sqlite3_bind_text(stmt, 1, (char *)widget->pkgid, -1, SQLITE_TRANSIENT);
1100 if (ret != SQLITE_OK) {
1101 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1106 ret = sqlite3_bind_text(stmt, 2, (char *)widget->icon, -1, SQLITE_TRANSIENT);
1107 if (ret != SQLITE_OK) {
1108 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1113 ret = sqlite3_bind_text(stmt, 3, (char *)widget->name, -1, SQLITE_TRANSIENT);
1114 if (ret != SQLITE_OK) {
1115 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1120 ret = sqlite3_bind_text(stmt, 4, (char *)widget->auto_launch, -1, SQLITE_TRANSIENT);
1121 if (ret != SQLITE_OK) {
1122 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1127 ret = sqlite3_bind_text(stmt, 5, (char *)widget->gbar_size, -1, SQLITE_TRANSIENT);
1128 if (ret != SQLITE_OK) {
1129 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1134 ret = sqlite3_bind_text(stmt, 6, (char *)widget->content, -1, SQLITE_TRANSIENT);
1135 if (ret != SQLITE_OK) {
1136 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1141 ret = sqlite3_bind_int(stmt, 7, widget->nodisplay);
1142 if (ret != SQLITE_OK) {
1143 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1148 ret = sqlite3_bind_text(stmt, 8, (char *)widget->setup, -1, SQLITE_TRANSIENT);
1149 if (ret != SQLITE_OK) {
1150 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1156 if (sqlite3_step(stmt) != SQLITE_DONE) {
1157 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1162 sqlite3_reset(stmt);
1163 sqlite3_clear_bindings(stmt);
1164 sqlite3_finalize(stmt);
1168 static inline int db_remove_client(const char *pkgid)
1170 static const char *dml;
1174 dml = "DELETE FROM client WHERE pkgid = ?";
1175 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1176 if (ret != SQLITE_OK) {
1177 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1181 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1182 if (ret != SQLITE_OK) {
1183 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1189 if (sqlite3_step(stmt) != SQLITE_DONE) {
1190 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1195 sqlite3_reset(stmt);
1196 sqlite3_clear_bindings(stmt);
1197 sqlite3_finalize(stmt);
1201 static inline int db_create_i18n(void)
1204 static const char *ddl;
1206 ddl = "CREATE TABLE i18n ( pkgid TEXT NOT NULL, lang TEXT COLLATE NOCASE, name TEXT, " \
1207 "icon TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1208 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1209 ErrPrint("Failed to execute the DDL (%s)\n", err);
1213 if (sqlite3_changes(s_info.handle) == 0) {
1214 ErrPrint("No changes to DB\n");
1220 static inline int db_insert_i18n(const char *pkgid, const char *lang, const char *name, const char *icon)
1222 static const char *dml;
1226 DbgPrint("%s - lang[%s] name[%s] icon[%s]\n", pkgid, lang, name, icon);
1227 dml = "INSERT INTO i18n ( pkgid, lang, name, icon ) VALUES (?, ?, ?, ?)";
1228 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1229 if (ret != SQLITE_OK) {
1230 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1234 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1235 if (ret != SQLITE_OK) {
1236 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1241 ret = sqlite3_bind_text(stmt, 2, lang, -1, SQLITE_TRANSIENT);
1242 if (ret != SQLITE_OK) {
1243 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1248 ret = sqlite3_bind_text(stmt, 3, name, -1, SQLITE_TRANSIENT);
1249 if (ret != SQLITE_OK) {
1250 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1255 ret = sqlite3_bind_text(stmt, 4, icon, -1, SQLITE_TRANSIENT);
1256 if (ret != SQLITE_OK) {
1257 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1263 if (sqlite3_step(stmt) != SQLITE_DONE) {
1264 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1269 sqlite3_reset(stmt);
1270 sqlite3_clear_bindings(stmt);
1271 sqlite3_finalize(stmt);
1275 static inline int db_remove_i18n(const char *pkgid)
1277 static const char *dml;
1281 dml = "DELETE FROM i18n WHERE pkgid = ?";
1282 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1283 if (ret != SQLITE_OK) {
1284 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1288 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1289 if (ret != SQLITE_OK) {
1290 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1296 if (sqlite3_step(stmt) != SQLITE_DONE) {
1297 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1301 if (sqlite3_changes(s_info.handle) == 0) {
1302 DbgPrint("No changes\n");
1306 sqlite3_reset(stmt);
1307 sqlite3_clear_bindings(stmt);
1308 sqlite3_finalize(stmt);
1312 static inline int db_create_group(void)
1315 static const char *ddl;
1317 ddl = "CREATE TABLE groupinfo ( id INTEGER PRIMARY KEY AUTOINCREMENT, cluster TEXT NOT NULL, category TEXT NOT NULL, pkgid TEXT NOT NULL, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1318 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1319 ErrPrint("Failed to execute the DDL (%s)\n", err);
1323 if (sqlite3_changes(s_info.handle) == 0) {
1324 ErrPrint("No changes to DB\n");
1330 static inline int db_insert_group(const char *pkgid, const char *cluster, const char *category)
1332 static const char *dml;
1336 dml = "INSERT INTO groupinfo ( cluster, category, pkgid ) VALUES (?, ?, ?)";
1337 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1338 if (ret != SQLITE_OK) {
1339 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1343 ret = sqlite3_bind_text(stmt, 1, cluster, -1, SQLITE_TRANSIENT);
1344 if (ret != SQLITE_OK) {
1345 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1350 ret = sqlite3_bind_text(stmt, 2, category, -1, SQLITE_TRANSIENT);
1351 if (ret != SQLITE_OK) {
1352 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1357 ret = sqlite3_bind_text(stmt, 3, pkgid, -1, SQLITE_TRANSIENT);
1358 if (ret != SQLITE_OK) {
1359 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1365 if (sqlite3_step(stmt) != SQLITE_DONE) {
1366 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1371 sqlite3_reset(stmt);
1372 sqlite3_clear_bindings(stmt);
1373 sqlite3_finalize(stmt);
1377 static int db_get_group_id(const char *cluster, const char *category)
1379 static const char *dml = "SELECT id FROM groupinfo WHERE cluster = ? AND category = ?";
1383 if (!cluster || !category) {
1384 ErrPrint("Invalid argument\n");
1388 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1389 if (ret != SQLITE_OK) {
1390 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
1395 if (sqlite3_bind_text(stmt, 1, cluster, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
1396 ErrPrint("Failed to bind a cluster(%s) - %s\n", cluster, sqlite3_errmsg(s_info.handle));
1400 if (sqlite3_bind_text(stmt, 2, category, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
1401 ErrPrint("Failed to bind a category(%s) - %s\n", category, sqlite3_errmsg(s_info.handle));
1405 if (sqlite3_step(stmt) != SQLITE_ROW) {
1406 ErrPrint("Failed to execute the DML for %s - %s\n", cluster, category);
1410 ret = sqlite3_column_int(stmt, 0);
1413 sqlite3_reset(stmt);
1414 sqlite3_clear_bindings(stmt);
1415 sqlite3_finalize(stmt);
1419 static inline int db_remove_group(const char *pkgid)
1421 static const char *dml;
1425 dml = "DELETE FROM groupinfo WHERE pkgid = ?";
1426 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1427 if (ret != SQLITE_OK) {
1428 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1432 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1433 if (ret != SQLITE_OK) {
1434 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1440 if (sqlite3_step(stmt) != SQLITE_DONE) {
1441 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1445 if (sqlite3_changes(s_info.handle) == 0) {
1446 DbgPrint("No changes\n");
1450 sqlite3_reset(stmt);
1451 sqlite3_clear_bindings(stmt);
1452 sqlite3_finalize(stmt);
1456 static inline int db_create_groupmap(void)
1459 static const char *ddl;
1461 ddl = "CREATE TABLE groupmap (option_id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER, pkgid TEXT NOT NULL, ctx_item TEXT NOT NULL, FOREIGN KEY(id) REFERENCES groupinfo(id), FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1462 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1463 ErrPrint("Failed to execute the DDL (%s)\n", err);
1467 if (sqlite3_changes(s_info.handle) == 0) {
1468 ErrPrint("No changes to DB\n");
1474 static inline int db_get_option_id(int id, const char *pkgid, const char *ctx_item)
1476 static const char *dml;
1480 dml = "SELECT option_id FROM groupmap WHERE id = ? AND pkgid = ? AND ctx_item = ?";
1481 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1482 if (ret != SQLITE_OK) {
1483 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1487 ret = sqlite3_bind_int(stmt, 1, id);
1488 if (ret != SQLITE_OK) {
1489 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1494 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1495 if (ret != SQLITE_OK) {
1496 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1501 ret = sqlite3_bind_text(stmt, 3, ctx_item, -1, SQLITE_TRANSIENT);
1502 if (ret != SQLITE_OK) {
1503 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1509 if (sqlite3_step(stmt) != SQLITE_ROW) {
1510 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1515 ret = sqlite3_column_int(stmt, 0);
1518 sqlite3_reset(stmt);
1519 sqlite3_clear_bindings(stmt);
1520 sqlite3_finalize(stmt);
1524 static inline int db_insert_groupmap(int id, const char *pkgid, const char *ctx_item)
1526 static const char *dml;
1530 DbgPrint("%d (%s) add to groupmap\n", id, pkgid);
1532 dml = "INSERT INTO groupmap ( id, pkgid, ctx_item ) VALUES (?, ?, ?)";
1533 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1534 if (ret != SQLITE_OK) {
1535 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1539 ret = sqlite3_bind_int(stmt, 1, id);
1540 if (ret != SQLITE_OK) {
1541 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1546 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1547 if (ret != SQLITE_OK) {
1548 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1553 ret = sqlite3_bind_text(stmt, 3, ctx_item, -1, SQLITE_TRANSIENT);
1554 if (ret != SQLITE_OK) {
1555 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1561 if (sqlite3_step(stmt) != SQLITE_DONE) {
1562 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1567 sqlite3_reset(stmt);
1568 sqlite3_clear_bindings(stmt);
1569 sqlite3_finalize(stmt);
1573 static inline int db_remove_groupmap(const char *pkgid)
1575 static const char *dml;
1579 dml = "DELETE FROM groupmap WHERE pkgid = ?";
1580 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1581 if (ret != SQLITE_OK) {
1582 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1586 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1587 if (ret != SQLITE_OK) {
1588 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1594 if (sqlite3_step(stmt) != SQLITE_DONE) {
1595 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1599 if (sqlite3_changes(s_info.handle) == 0) {
1600 DbgPrint("No changes\n");
1604 sqlite3_reset(stmt);
1605 sqlite3_clear_bindings(stmt);
1606 sqlite3_finalize(stmt);
1610 static inline int db_create_option(void)
1613 static const char *ddl;
1615 ddl = "CREATE TABLE option ( pkgid TEXT NOT NULL, option_id INTEGER, key TEXT NOT NULL, value TEXT NOT NULL, " \
1616 "FOREIGN KEY(option_id) REFERENCES groupmap(option_id), " \
1617 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1618 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1619 ErrPrint("Failed to execute the DDL (%s)\n", err);
1623 if (sqlite3_changes(s_info.handle) == 0) {
1624 ErrPrint("No changes to DB\n");
1630 static inline int db_insert_option(const char *pkgid, int option_id, const char *key, const char *value)
1632 static const char *dml;
1636 dml = "INSERT INTO option (pkgid, option_id, key, value) VALUES (?, ?, ?, ?)";
1637 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1638 if (ret != SQLITE_OK) {
1639 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1643 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1644 if (ret != SQLITE_OK) {
1645 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1650 ret = sqlite3_bind_int(stmt, 2, option_id);
1651 if (ret != SQLITE_OK) {
1652 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1657 ret = sqlite3_bind_text(stmt, 3, key, -1, SQLITE_TRANSIENT);
1658 if (ret != SQLITE_OK) {
1659 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1664 ret = sqlite3_bind_text(stmt, 4, value, -1, SQLITE_TRANSIENT);
1665 if (ret != SQLITE_OK) {
1666 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1672 if (sqlite3_step(stmt) != SQLITE_DONE) {
1673 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1677 sqlite3_reset(stmt);
1678 sqlite3_clear_bindings(stmt);
1679 sqlite3_finalize(stmt);
1683 static inline int db_remove_option(const char *pkgid)
1685 static const char *dml;
1689 dml = "DELETE FROM option WHERE pkgid = ?";
1690 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1691 if (ret != SQLITE_OK) {
1692 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1696 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1697 if (ret != SQLITE_OK) {
1698 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1704 if (sqlite3_step(stmt) != SQLITE_DONE) {
1705 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1709 if (sqlite3_changes(s_info.handle) == 0) {
1710 DbgPrint("No changes\n");
1714 sqlite3_reset(stmt);
1715 sqlite3_clear_bindings(stmt);
1716 sqlite3_finalize(stmt);
1720 static inline int db_create_box_size(void)
1723 static const char *ddl;
1725 ddl = "CREATE TABLE box_size ( pkgid TEXT NOT NULL, size_type INTEGER, preview TEXT, touch_effect INTEGER, need_frame INTEGER, mouse_event INTEGER " \
1726 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1727 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1728 ErrPrint("Failed to execute the DDL (%s)\n", err);
1732 if (sqlite3_changes(s_info.handle) == 0) {
1733 ErrPrint("No changes to DB\n");
1739 static int db_insert_box_size(const char *pkgid, int size_type, const char *preview, int touch_effect, int need_frame, int mouse_event)
1741 static const char *dml;
1745 DbgPrint("box size: %s - %d (%s) is added\n", pkgid, size_type, preview);
1746 dml = "INSERT INTO box_size ( pkgid, size_type, preview, touch_effect, need_frame, mouse_event ) VALUES (?, ?, ?, ?, ?, ?)";
1747 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1748 if (ret != SQLITE_OK) {
1749 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1753 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1754 if (ret != SQLITE_OK) {
1755 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1760 ret = sqlite3_bind_int(stmt, 2, size_type);
1761 if (ret != SQLITE_OK) {
1762 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1767 ret = sqlite3_bind_text(stmt, 3, preview, -1, SQLITE_TRANSIENT);
1768 if (ret != SQLITE_OK) {
1769 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1774 ret = sqlite3_bind_int(stmt, 4, touch_effect);
1775 if (ret != SQLITE_OK) {
1776 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1781 ret = sqlite3_bind_int(stmt, 5, need_frame);
1782 if (ret != SQLITE_OK) {
1783 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1788 ret = sqlite3_bind_int(stmt, 6, mouse_event);
1789 if (ret != SQLITE_OK) {
1790 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1796 if (sqlite3_step(stmt) != SQLITE_DONE) {
1797 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1802 sqlite3_reset(stmt);
1803 sqlite3_clear_bindings(stmt);
1804 sqlite3_finalize(stmt);
1808 static inline int db_remove_box_size(const char *pkgid)
1810 static const char *dml;
1814 dml = "DELETE FROM box_size WHERE pkgid = ?";
1815 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1816 if (ret != SQLITE_OK) {
1817 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1821 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1822 if (ret != SQLITE_OK) {
1823 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1829 if (sqlite3_step(stmt) != SQLITE_DONE) {
1830 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1834 if (sqlite3_changes(s_info.handle) == 0) {
1835 DbgPrint("No changes\n");
1839 sqlite3_reset(stmt);
1840 sqlite3_clear_bindings(stmt);
1841 sqlite3_finalize(stmt);
1845 static inline void db_create_table(void)
1848 begin_transaction();
1850 ret = db_create_pkgmap();
1852 rollback_transaction();
1856 ret = db_create_provider();
1858 rollback_transaction();
1862 ret = db_create_client();
1864 rollback_transaction();
1868 ret = db_create_i18n();
1870 rollback_transaction();
1874 ret = db_create_box_size();
1876 rollback_transaction();
1880 ret = db_create_group();
1882 rollback_transaction();
1886 ret = db_create_option();
1888 rollback_transaction();
1892 ret = db_create_groupmap();
1894 rollback_transaction();
1898 commit_transaction();
1906 ret = db_util_open(s_info.dbfile, &s_info.handle, DB_UTIL_REGISTER_HOOK_METHOD);
1907 if (ret != SQLITE_OK) {
1908 ErrPrint("Failed to open a DB\n");
1912 if (lstat(s_info.dbfile, &stat) < 0) {
1913 ErrPrint("%d\n", errno);
1914 db_util_close(s_info.handle);
1915 s_info.handle = NULL;
1919 if (!S_ISREG(stat.st_mode)) {
1920 ErrPrint("Invalid file\n");
1921 db_util_close(s_info.handle);
1922 s_info.handle = NULL;
1926 if (!stat.st_size) {
1935 if (!s_info.handle) {
1939 db_util_close(s_info.handle);
1940 s_info.handle = NULL;
1947 if (s_info.handle == NULL)
1955 static int validate_pkgid(const char *appid, const char *pkgid)
1957 /* Just return 1 Always */
1958 return 1 || !strncmp(appid, pkgid, strlen(appid));
1961 static int widget_destroy(struct widget *widget)
1966 struct group *group;
1967 struct option *option;
1971 xmlFree(widget->auto_launch);
1972 xmlFree(widget->pkgid);
1973 xmlFree(widget->abi);
1974 xmlFree(widget->name);
1975 xmlFree(widget->icon);
1976 xmlFree(widget->widget_src);
1977 xmlFree(widget->widget_group);
1978 xmlFree(widget->gbar_src);
1979 xmlFree(widget->gbar_group);
1980 xmlFree(widget->gbar_size);
1981 xmlFree(widget->libexec);
1982 xmlFree(widget->script);
1983 xmlFree(widget->period);
1984 xmlFree(widget->content);
1985 xmlFree(widget->setup);
1986 xmlFree(widget->category);
1987 xmlFree(widget->preview[0]); /* 1x1 */
1988 xmlFree(widget->preview[1]); /* 2x1 */
1989 xmlFree(widget->preview[2]); /* 2x2 */
1990 xmlFree(widget->preview[3]); /* 4x1 */
1991 xmlFree(widget->preview[4]); /* 4x2 */
1992 xmlFree(widget->preview[5]); /* 4x3 */
1993 xmlFree(widget->preview[6]); /* 4x4 */
1994 xmlFree(widget->preview[7]); /* 4x5 */
1995 xmlFree(widget->preview[8]); /* 4x6 */
1996 xmlFree(widget->preview[9]); /* easy 1x1 */
1997 xmlFree(widget->preview[10]); /* easy 3x1 */
1998 xmlFree(widget->preview[11]); /* easy 3x3 */
1999 xmlFree(widget->preview[12]); /* full */
2000 xmlFree(widget->hw_acceleration);
2002 dlist_foreach_safe(widget->i18n_list, l, n, i18n) {
2003 widget->i18n_list = dlist_remove(widget->i18n_list, l);
2004 xmlFree(i18n->name);
2005 xmlFree(i18n->icon);
2006 xmlFree(i18n->lang);
2010 dlist_foreach_safe(widget->group_list, l, n, group) {
2011 widget->group_list = dlist_remove(widget->group_list, l);
2012 DbgPrint("Release %s/%s\n", group->cluster, group->category);
2014 if (group->ctx_item) {
2015 dlist_foreach_safe(group->option_list, il, in, option) {
2016 group->option_list = dlist_remove(group->option_list, il);
2017 DbgPrint("Release option %s(%s)\n", option->key, option->value);
2018 xmlFree(option->key);
2019 xmlFree(option->value);
2022 xmlFree(group->ctx_item);
2025 xmlFree(group->cluster);
2026 xmlFree(group->category);
2034 static void update_i18n_name(struct widget *widget, xmlNodePtr node)
2041 name = xmlNodeGetContent(node);
2043 ErrPrint("Invalid tag\n");
2047 lang = xmlNodeGetLang(node);
2050 DbgPrint("Override default name: %s\n", widget->name);
2051 xmlFree(widget->name);
2054 widget->name = name;
2058 dlist_foreach(widget->i18n_list, l, i18n) {
2059 if (!xmlStrcasecmp(i18n->lang, lang)) {
2061 DbgPrint("Override name: %s\n", i18n->name);
2062 xmlFree(i18n->name);
2070 i18n = calloc(1, sizeof(*i18n));
2072 ErrPrint("calloc: %d\n", errno);
2080 DbgPrint("Label[%s] - [%s] added\n", i18n->lang, i18n->name);
2081 widget->i18n_list = dlist_append(widget->i18n_list, i18n);
2084 static void update_i18n_icon(struct widget *widget, xmlNodePtr node)
2091 icon = xmlNodeGetContent(node);
2093 ErrPrint("Invalid tag\n");
2097 lang = xmlNodeGetLang(node);
2100 DbgPrint("Override default icon: %s\n", widget->icon);
2101 xmlFree(widget->icon);
2104 widget->icon = icon;
2108 dlist_foreach(widget->i18n_list, l, i18n) {
2109 if (!xmlStrcasecmp(i18n->lang, lang)) {
2111 DbgPrint("Override icon %s for %s\n", i18n->icon, i18n->name);
2112 xmlFree(i18n->icon);
2116 icon = abspath_strdup(i18n->icon);
2118 ErrPrint("strdup: %d\n", errno);
2120 abspath((char *)i18n->icon, (char *)icon);
2121 xmlFree(i18n->icon);
2128 i18n = calloc(1, sizeof(*i18n));
2130 ErrPrint("calloc: %d\n", errno);
2137 icon = abspath_strdup(i18n->icon);
2139 ErrPrint("strdup: %d\n", errno);
2141 abspath((char *)i18n->icon, (char *)icon);
2142 xmlFree(i18n->icon);
2146 DbgPrint("Icon[%s] - [%s] added\n", i18n->lang, i18n->icon);
2147 widget->i18n_list = dlist_append(widget->i18n_list, i18n);
2150 static void update_launch(struct widget *widget, xmlNodePtr node)
2154 launch = xmlNodeGetContent(node);
2156 DbgPrint("Has no launch\n");
2160 if (widget->auto_launch) {
2161 xmlFree(widget->auto_launch);
2164 widget->auto_launch = xmlStrdup(launch);
2165 if (!widget->auto_launch) {
2166 ErrPrint("Failed to duplicate string: %s\n", (char *)launch);
2171 static int update_category(struct widget *widget, xmlNodePtr node)
2175 category = xmlGetProp(node, (const xmlChar *)"name");
2177 DbgPrint("Has no valid category\n");
2181 if (!xmlStrcasecmp(category, (const xmlChar *)CATEGORY_WATCH_CLOCK)) {
2182 ErrPrint("Widget tries to install WATCH: %s\n", widget->pkgid);
2186 if (widget->category) {
2187 xmlFree(widget->category);
2190 widget->category = xmlStrdup(category);
2191 if (!widget->category) {
2192 ErrPrint("Failed to duplicate string: %s\n", (char *)category);
2199 static inline xmlChar *pkgmgr_get_mainapp(char *pkgid)
2201 pkgmgrinfo_pkginfo_h handle;
2205 if (pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle) != PMINFO_R_OK) {
2206 ErrPrint("Unable to get mainapp: %s\n", pkgid);
2212 if (pkgmgrinfo_pkginfo_get_mainappid(handle, &tmp) == PMINFO_R_OK) {
2214 ret = xmlStrdup((xmlChar *)tmp);
2216 ErrPrint("xmlStrdup: %d\n", errno);
2219 ErrPrint("mainappid is NULL (%s)\n", pkgid);
2222 ErrPrint("Failed to get mainappid (%s)\n", pkgid);
2225 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2229 static void update_ui_appid(struct widget *widget, xmlNodePtr node)
2232 uiapp = xmlNodeGetContent(node);
2234 DbgPrint("Has no valid ui-appid\n");
2238 if (widget->uiapp) {
2239 xmlFree(widget->uiapp);
2242 widget->uiapp = xmlStrdup(uiapp);
2243 if (!widget->uiapp) {
2244 ErrPrint("Failed to duplicate string: %s\n", (char *)uiapp);
2249 static void update_setup(struct widget *widget, xmlNodePtr node)
2252 setup = xmlNodeGetContent(node);
2254 DbgPrint("Has no setup\n");
2258 if (widget->setup) {
2259 xmlFree(widget->setup);
2262 widget->setup = xmlStrdup(setup);
2263 if (!widget->setup) {
2264 ErrPrint("Failed to duplicate string: %s\n", (char *)setup);
2269 static void update_content(struct widget *widget, xmlNodePtr node)
2272 content = xmlNodeGetContent(node);
2274 DbgPrint("Has no content\n");
2278 if (widget->content) {
2279 xmlFree(widget->content);
2282 widget->content = xmlStrdup(content);
2283 if (!widget->content) {
2284 ErrPrint("Failed to duplicate string: %s\n", (char *)content);
2289 static void update_size_info(struct widget *widget, int idx, xmlNodePtr node)
2291 if (xmlHasProp(node, (const xmlChar *)"preview")) {
2292 xmlChar *tmp_preview;
2294 widget->preview[idx] = xmlGetProp(node, (const xmlChar *)"preview");
2296 tmp_preview = abspath_strdup(widget->preview[idx]);
2298 ErrPrint("strdup: %d\n", errno);
2300 abspath((char *)widget->preview[idx], (char *)tmp_preview);
2301 xmlFree(widget->preview[idx]);
2302 widget->preview[idx] = tmp_preview;
2306 if (xmlHasProp(node, (const xmlChar *)"need_frame")) {
2307 xmlChar *need_frame;
2309 need_frame = xmlGetProp(node, (const xmlChar *)"need_frame");
2311 widget->need_frame[idx] = !xmlStrcasecmp(need_frame, (const xmlChar *)"true");
2312 xmlFree(need_frame);
2314 widget->need_frame[idx] = widget->default_need_frame;
2317 widget->need_frame[idx] = widget->default_need_frame;
2320 if (xmlHasProp(node, (const xmlChar *)"touch_effect")) {
2321 xmlChar *touch_effect;
2323 touch_effect = xmlGetProp(node, (const xmlChar *)"touch_effect");
2325 widget->touch_effect[idx] = !xmlStrcasecmp(touch_effect, (const xmlChar *)"true");
2326 xmlFree(touch_effect);
2328 widget->touch_effect[idx] = widget->default_touch_effect;
2331 widget->touch_effect[idx] = widget->default_touch_effect;
2334 if (xmlHasProp(node, (const xmlChar *)"mouse_event")) {
2335 xmlChar *mouse_event;
2337 mouse_event = xmlGetProp(node, (const xmlChar *)"mouse_event");
2339 widget->mouse_event[idx] = !xmlStrcasecmp(mouse_event, (const xmlChar *)"true");
2340 xmlFree(mouse_event);
2342 widget->mouse_event[idx] = widget->default_mouse_event;
2345 widget->mouse_event[idx] = widget->default_mouse_event;
2349 static void update_support_size(struct widget *widget, xmlNodePtr node)
2354 size = xmlNodeGetContent(node);
2356 ErrPrint("Invalid size tag\n");
2360 widget->default_mouse_event = 0;
2361 widget->default_touch_effect = 0;
2362 widget->default_need_frame = 0;
2364 if (xmlHasProp(node, (const xmlChar *)"mode")) {
2366 mode = xmlGetProp(node, (const xmlChar *)"mode");
2368 DbgPrint("Easy mode: %s\n", mode);
2369 is_easy = !xmlStrcasecmp(mode, (const xmlChar *)"easy");
2374 if (!xmlStrcasecmp(size, (const xmlChar *)"1x1")) {
2376 widget->size_list |= WIDGET_SIZE_TYPE_EASY_1x1;
2377 update_size_info(widget, 9, node);
2379 widget->size_list |= WIDGET_SIZE_TYPE_1x1;
2380 update_size_info(widget, 0, node);
2382 } else if (!xmlStrcasecmp(size, (const xmlChar *)"3x1")) {
2384 widget->size_list |= WIDGET_SIZE_TYPE_EASY_3x1;
2385 update_size_info(widget, 10, node);
2387 ErrPrint("Invalid size tag (%s)\n", size);
2389 } else if (!xmlStrcasecmp(size, (const xmlChar *)"3x3")) {
2391 widget->size_list |= WIDGET_SIZE_TYPE_EASY_3x3;
2392 update_size_info(widget, 11, node);
2394 ErrPrint("Invalid size tag (%s)\n", size);
2396 } else if (!xmlStrcasecmp(size, (const xmlChar *)"2x1")) {
2397 widget->size_list |= WIDGET_SIZE_TYPE_2x1;
2398 update_size_info(widget, 1, node);
2399 } else if (!xmlStrcasecmp(size, (const xmlChar *)"2x2")) {
2400 widget->size_list |= WIDGET_SIZE_TYPE_2x2;
2401 update_size_info(widget, 2, node);
2402 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x1")) {
2403 widget->size_list |= WIDGET_SIZE_TYPE_4x1;
2404 update_size_info(widget, 3, node);
2405 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x2")) {
2406 widget->size_list |= WIDGET_SIZE_TYPE_4x2;
2407 update_size_info(widget, 4, node);
2408 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x3")) {
2409 widget->size_list |= WIDGET_SIZE_TYPE_4x3;
2410 update_size_info(widget, 5, node);
2411 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x4")) {
2412 widget->size_list |= WIDGET_SIZE_TYPE_4x4;
2413 update_size_info(widget, 6, node);
2414 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x5")) {
2415 widget->size_list |= WIDGET_SIZE_TYPE_4x5;
2416 update_size_info(widget, 7, node);
2417 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x6")) {
2418 widget->size_list |= WIDGET_SIZE_TYPE_4x6;
2419 update_size_info(widget, 8, node);
2420 } else if (!xmlStrcasecmp(size, (const xmlChar *)"21x21")) {
2421 widget->size_list |= WIDGET_SIZE_TYPE_EASY_1x1;
2422 update_size_info(widget, 9, node);
2423 } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x21")) {
2424 widget->size_list |= WIDGET_SIZE_TYPE_EASY_3x1;
2425 update_size_info(widget, 10, node);
2426 } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x23")) {
2427 widget->size_list |= WIDGET_SIZE_TYPE_EASY_3x3;
2428 update_size_info(widget, 11, node);
2429 } else if (!xmlStrcasecmp(size, (const xmlChar *)"0x0")) {
2430 widget->size_list |= WIDGET_SIZE_TYPE_FULL;
2431 update_size_info(widget, 12, node);
2433 ErrPrint("Invalid size tag (%s)\n", size);
2439 static void update_box(struct widget *widget, xmlNodePtr node)
2441 if (!xmlHasProp(node, (const xmlChar *)"type")) {
2442 widget->widget_type = WIDGET_TYPE_FILE;
2446 type = xmlGetProp(node, (const xmlChar *)"type");
2448 ErrPrint("Type is NIL\n");
2449 widget->widget_type = WIDGET_TYPE_FILE;
2451 if (!xmlStrcasecmp(type, (const xmlChar *)"text")) {
2452 widget->widget_type = WIDGET_TYPE_TEXT;
2453 } else if (!xmlStrcasecmp(type, (const xmlChar *)"buffer")) {
2454 widget->widget_type = WIDGET_TYPE_BUFFER;
2455 } else if (!xmlStrcasecmp(type, (const xmlChar *)"script")) {
2456 widget->widget_type = WIDGET_TYPE_SCRIPT;
2457 } else if (!xmlStrcasecmp(type, (const xmlChar *)"elm")) {
2458 widget->widget_type = WIDGET_TYPE_UIFW;
2459 } else { /* Default */
2460 widget->widget_type = WIDGET_TYPE_FILE;
2467 if (!xmlHasProp(node, (const xmlChar *)"mouse_event")) {
2468 widget->default_mouse_event = 0;
2470 xmlChar *mouse_event;
2472 mouse_event = xmlGetProp(node, (const xmlChar *)"mouse_event");
2474 ErrPrint("mouse_event is NIL\n");
2475 widget->default_mouse_event = 0;
2477 widget->default_mouse_event = !xmlStrcasecmp(mouse_event, (const xmlChar *)"true");
2478 xmlFree(mouse_event);
2482 if (!xmlHasProp(node, (const xmlChar *)"touch_effect")) {
2483 widget->default_touch_effect = 0;
2485 xmlChar *touch_effect;
2487 touch_effect = xmlGetProp(node, (const xmlChar *)"touch_effect");
2488 if (!touch_effect) {
2489 ErrPrint("default touch_effect is NIL\n");
2490 widget->default_touch_effect = 0;
2492 widget->default_touch_effect = !xmlStrcasecmp(touch_effect, (const xmlChar *)"true");
2493 xmlFree(touch_effect);
2497 if (!xmlHasProp(node, (const xmlChar *)"need_frame")) {
2498 widget->default_need_frame = 0;
2500 xmlChar *need_frame;
2502 need_frame = xmlGetProp(node, (const xmlChar *)"need_frame");
2504 ErrPrint("default need_frame is NIL\n");
2505 widget->default_need_frame = 0;
2507 widget->default_need_frame = !xmlStrcasecmp(need_frame, (const xmlChar *)"true");
2508 xmlFree(need_frame);
2512 for (node = node->children; node; node = node->next) {
2513 if (!xmlStrcasecmp(node->name, (const xmlChar *)"size")) {
2517 size = xmlNodeGetContent(node);
2519 ErrPrint("Invalid size tag\n");
2523 if (xmlHasProp(node, (const xmlChar *)"mode")) {
2525 mode = xmlGetProp(node, (const xmlChar *)"mode");
2527 DbgPrint("Easy mode: %s\n", mode);
2528 is_easy = !xmlStrcasecmp(mode, (const xmlChar *)"easy");
2533 if (!xmlStrcasecmp(size, (const xmlChar *)"1x1")) {
2535 widget->size_list |= WIDGET_SIZE_TYPE_EASY_1x1;
2536 update_size_info(widget, 9, node);
2538 widget->size_list |= WIDGET_SIZE_TYPE_1x1;
2539 update_size_info(widget, 0, node);
2541 } else if (!xmlStrcasecmp(size, (const xmlChar *)"3x1")) {
2543 widget->size_list |= WIDGET_SIZE_TYPE_EASY_3x1;
2544 update_size_info(widget, 10, node);
2546 ErrPrint("Invalid size tag (%s)\n", size);
2548 } else if (!xmlStrcasecmp(size, (const xmlChar *)"3x3")) {
2550 widget->size_list |= WIDGET_SIZE_TYPE_EASY_3x3;
2551 update_size_info(widget, 11, node);
2553 ErrPrint("Invalid size tag (%s)\n", size);
2555 } else if (!xmlStrcasecmp(size, (const xmlChar *)"2x1")) {
2556 widget->size_list |= WIDGET_SIZE_TYPE_2x1;
2557 update_size_info(widget, 1, node);
2558 } else if (!xmlStrcasecmp(size, (const xmlChar *)"2x2")) {
2559 widget->size_list |= WIDGET_SIZE_TYPE_2x2;
2560 update_size_info(widget, 2, node);
2561 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x1")) {
2562 widget->size_list |= WIDGET_SIZE_TYPE_4x1;
2563 update_size_info(widget, 3, node);
2564 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x2")) {
2565 widget->size_list |= WIDGET_SIZE_TYPE_4x2;
2566 update_size_info(widget, 4, node);
2567 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x3")) {
2568 widget->size_list |= WIDGET_SIZE_TYPE_4x3;
2569 update_size_info(widget, 5, node);
2570 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x4")) {
2571 widget->size_list |= WIDGET_SIZE_TYPE_4x4;
2572 update_size_info(widget, 6, node);
2573 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x5")) {
2574 widget->size_list |= WIDGET_SIZE_TYPE_4x5;
2575 update_size_info(widget, 7, node);
2576 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x6")) {
2577 widget->size_list |= WIDGET_SIZE_TYPE_4x6;
2578 update_size_info(widget, 8, node);
2579 } else if (!xmlStrcasecmp(size, (const xmlChar *)"21x21")) {
2580 widget->size_list |= WIDGET_SIZE_TYPE_EASY_1x1;
2581 update_size_info(widget, 9, node);
2582 } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x21")) {
2583 widget->size_list |= WIDGET_SIZE_TYPE_EASY_3x1;
2584 update_size_info(widget, 10, node);
2585 } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x23")) {
2586 widget->size_list |= WIDGET_SIZE_TYPE_EASY_3x3;
2587 update_size_info(widget, 11, node);
2588 } else if (!xmlStrcasecmp(size, (const xmlChar *)"0x0")) {
2589 widget->size_list |= WIDGET_SIZE_TYPE_FULL;
2590 update_size_info(widget, 12, node);
2592 ErrPrint("Invalid size tag (%s)\n", size);
2596 } else if (!xmlStrcasecmp(node->name, (const xmlChar *)"script")) {
2599 if (!xmlHasProp(node, (const xmlChar *)"src")) {
2600 ErrPrint("Invalid script tag. has no src\n");
2604 src = xmlGetProp(node, (const xmlChar *)"src");
2606 ErrPrint("Invalid script tag. src is NIL\n");
2610 if (widget->widget_src) {
2611 DbgPrint("Override lb src: %s\n", widget->widget_src);
2612 xmlFree(widget->widget_src);
2615 widget->widget_src = src;
2616 src = abspath_strdup(widget->widget_src);
2618 ErrPrint("strdup: %d\n", errno);
2620 abspath((char *)widget->widget_src, (char *)src);
2621 xmlFree(widget->widget_src);
2622 widget->widget_src = src;
2625 if (xmlHasProp(node, (const xmlChar *)"group")) {
2627 group = xmlGetProp(node, (const xmlChar *)"group");
2629 ErrPrint("Group is NIL\n");
2631 if (widget->widget_group) {
2632 DbgPrint("Override lb group: %s\n", widget->widget_group);
2633 xmlFree(widget->widget_group);
2636 widget->widget_group = group;
2643 static void update_group(struct widget *widget, xmlNodePtr node)
2646 xmlNodePtr category;
2647 xmlNodePtr option_item;
2648 xmlChar *cluster_name;
2649 xmlChar *category_name;
2655 struct group *group;
2656 struct option *option;
2659 for (cluster = cluster->children; cluster; cluster = cluster->next) {
2660 if (xmlStrcasecmp(cluster->name, (const xmlChar *)"cluster")) {
2661 DbgPrint("Skip: %s\n", cluster->name);
2665 if (!xmlHasProp(cluster, (const xmlChar *)"name")) {
2666 ErrPrint("Invalid cluster, has no name\n");
2670 cluster_name = xmlGetProp(cluster, (const xmlChar *)"name");
2671 if (!cluster_name) {
2672 ErrPrint("Invalid cluster name. NIL\n");
2676 for (category = cluster->children; category; category = category->next) {
2677 if (xmlStrcasecmp(category->name, (const xmlChar *)"category")) {
2678 DbgPrint("Skip: %s\n", category->name);
2682 if (!xmlHasProp(category, (const xmlChar *)"name")) {
2683 ErrPrint("Invalid category, has no name\n");
2687 category_name = xmlGetProp(category, (const xmlChar *)"name");
2688 if (!category_name) {
2689 ErrPrint("Invalid category name. NIL\n");
2693 group = calloc(1, sizeof(*group));
2695 ErrPrint("calloc: %d\n", errno);
2696 xmlFree(category_name);
2700 group->cluster = xmlStrdup(cluster_name);
2701 if (!group->cluster) {
2702 ErrPrint("xmlStrdup: %d\n", errno);
2703 xmlFree(category_name);
2708 group->category = category_name;
2709 widget->group_list = dlist_append(widget->group_list, group);
2711 if (!xmlHasProp(category, (const xmlChar *)"context")) {
2712 DbgPrint("%s, %s has no ctx info\n", group->cluster, group->category);
2716 ctx_item = xmlGetProp(category, (const xmlChar *)"context");
2718 ErrPrint("Failed to get context ID (%s, %s)\n", group->cluster, group->category);
2722 group->ctx_item = ctx_item;
2723 DbgPrint("Build group item: %s - %s - %s\n", group->cluster, group->category, group->ctx_item);
2725 for (option_item = category->children; option_item; option_item = option_item->next) {
2726 if (xmlStrcasecmp(option_item->name, (const xmlChar *)"option")) {
2727 DbgPrint("Skip: %s\n", option_item->name);
2731 if (!xmlHasProp(option_item, (const xmlChar *)"key")) {
2732 ErrPrint("Invalid option, has no key\n");
2736 if (!xmlHasProp(option_item, (const xmlChar *)"value")) {
2737 ErrPrint("Invalid option, has no value\n");
2741 key = xmlGetProp(option_item, (const xmlChar *)"key");
2743 ErrPrint("Invalid key. NIL\n");
2747 value = xmlGetProp(option_item, (const xmlChar *)"value");
2749 ErrPrint("Invalid valid. NIL\n");
2754 option = calloc(1, sizeof(*option));
2756 ErrPrint("calloc: %d\n", errno);
2763 option->value = value;
2765 group->option_list = dlist_append(group->option_list, option);
2769 xmlFree(cluster_name);
2773 static void update_glance_bar(struct widget *widget, xmlNodePtr node)
2775 if (!xmlHasProp(node, (const xmlChar *)"type")) {
2776 widget->gbar_type = GBAR_TYPE_SCRIPT;
2780 type = xmlGetProp(node, (const xmlChar *)"type");
2782 ErrPrint("type is NIL\n");
2786 if (!xmlStrcasecmp(type, (const xmlChar *)"text")) {
2787 widget->gbar_type = GBAR_TYPE_TEXT;
2788 } else if (!xmlStrcasecmp(type, (const xmlChar *)"buffer")) {
2789 widget->gbar_type = GBAR_TYPE_BUFFER;
2790 } else if (!xmlStrcasecmp(type, (const xmlChar *)"elm")) {
2791 widget->gbar_type = GBAR_TYPE_UIFW;
2793 widget->gbar_type = GBAR_TYPE_SCRIPT;
2799 for (node = node->children; node; node = node->next) {
2800 if (!xmlStrcasecmp(node->name, (const xmlChar *)"size")) {
2803 size = xmlNodeGetContent(node);
2805 ErrPrint("Invalid size tag\n");
2809 if (widget->gbar_size) {
2810 DbgPrint("Override pd size: %s\n", widget->gbar_size);
2811 xmlFree(widget->gbar_size);
2813 widget->gbar_size = size;
2814 } else if (!xmlStrcasecmp(node->name, (const xmlChar *)"script")) {
2817 if (!xmlHasProp(node, (const xmlChar *)"src")) {
2818 ErrPrint("Invalid script tag, has no src\n");
2822 src = xmlGetProp(node, (const xmlChar *)"src");
2824 ErrPrint("src is NIL\n");
2828 if (widget->gbar_src) {
2829 DbgPrint("Overide PD src: %s\n", widget->gbar_src);
2830 xmlFree(widget->gbar_src);
2833 widget->gbar_src = src;
2834 src = abspath_strdup(widget->gbar_src);
2836 ErrPrint("strdup: %d\n", errno);
2838 abspath((char *)widget->gbar_src, (char *)src);
2839 xmlFree(widget->gbar_src);
2840 widget->gbar_src = src;
2843 if (xmlHasProp(node, (const xmlChar *)"group")) {
2845 group = xmlGetProp(node, (const xmlChar *)"group");
2847 ErrPrint("Group is NIL\n");
2849 if (widget->gbar_group) {
2850 DbgPrint("Override PD group : %s\n", widget->gbar_group);
2851 xmlFree(widget->gbar_group);
2854 widget->gbar_group = group;
2861 static int db_insert_widget(struct widget *widget, const char *appid)
2866 struct group *group;
2869 struct option *option;
2871 begin_transaction();
2872 ret = db_insert_pkgmap(appid, (char *)widget->pkgid, (char *)widget->uiapp, widget->primary, (char *)widget->category);
2877 ret = db_insert_provider(widget);
2882 ret = db_insert_client(widget);
2887 dlist_foreach(widget->i18n_list, l, i18n) {
2888 ret = db_insert_i18n((char *)widget->pkgid, (char *)i18n->lang, (char *)i18n->name, (char *)i18n->icon);
2894 if (widget->size_list & WIDGET_SIZE_TYPE_1x1) {
2895 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_1x1, (char *)widget->preview[0], widget->touch_effect[0], widget->need_frame[0], widget->mouse_event[0]);
2901 if (widget->size_list & WIDGET_SIZE_TYPE_2x1) {
2902 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_2x1, (char *)widget->preview[1], widget->touch_effect[1], widget->need_frame[1], widget->mouse_event[1]);
2908 if (widget->size_list & WIDGET_SIZE_TYPE_2x2) {
2909 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_2x2, (char *)widget->preview[2], widget->touch_effect[2], widget->need_frame[2], widget->mouse_event[2]);
2915 if (widget->size_list & WIDGET_SIZE_TYPE_4x1) {
2916 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_4x1, (char *)widget->preview[3], widget->touch_effect[3], widget->need_frame[3], widget->mouse_event[3]);
2922 if (widget->size_list & WIDGET_SIZE_TYPE_4x2) {
2923 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_4x2, (char *)widget->preview[4], widget->touch_effect[4], widget->need_frame[4], widget->mouse_event[4]);
2929 if (widget->size_list & WIDGET_SIZE_TYPE_4x3) {
2930 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_4x3, (char *)widget->preview[5], widget->touch_effect[5], widget->need_frame[5], widget->mouse_event[5]);
2936 if (widget->size_list & WIDGET_SIZE_TYPE_4x4) {
2937 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_4x4, (char *)widget->preview[6], widget->touch_effect[6], widget->need_frame[6], widget->mouse_event[6]);
2943 if (widget->size_list & WIDGET_SIZE_TYPE_4x5) {
2944 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_4x5, (char *)widget->preview[7], widget->touch_effect[7], widget->need_frame[7], widget->mouse_event[7]);
2950 if (widget->size_list & WIDGET_SIZE_TYPE_4x6) {
2951 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_4x6, (char *)widget->preview[8], widget->touch_effect[8], widget->need_frame[8], widget->mouse_event[8]);
2957 if (widget->size_list & WIDGET_SIZE_TYPE_EASY_1x1) {
2958 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_EASY_1x1, (char *)widget->preview[9], widget->touch_effect[9], widget->need_frame[9], widget->mouse_event[9]);
2964 if (widget->size_list & WIDGET_SIZE_TYPE_EASY_3x1) {
2965 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_EASY_3x1, (char *)widget->preview[10], widget->touch_effect[10], widget->need_frame[10], widget->mouse_event[10]);
2971 if (widget->size_list & WIDGET_SIZE_TYPE_EASY_3x3) {
2972 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_EASY_3x3, (char *)widget->preview[11], widget->touch_effect[11], widget->need_frame[11], widget->mouse_event[11]);
2978 if (widget->size_list & WIDGET_SIZE_TYPE_FULL) {
2979 ret = db_insert_box_size((char *)widget->pkgid, WIDGET_SIZE_TYPE_FULL, (char *)widget->preview[12], widget->touch_effect[12], widget->need_frame[12], widget->mouse_event[12]);
2985 dlist_foreach(widget->group_list, l, group) {
2987 id = db_get_group_id((char *)group->cluster, (char *)group->category);
2991 ret = db_insert_group((char *)widget->pkgid, (char *)group->cluster, (char *)group->category);
2993 ErrPrint("[%s]-[%s] is not exists\n", group->cluster, group->category);
2997 DbgPrint("New group name is built - %s/%s\n", group->cluster, group->category);
2998 id = db_get_group_id((char *)group->cluster, (char *)group->category);
3000 ErrPrint("Failed to get group id for %s/%s\n", group->cluster, group->category);
3005 if (!group->ctx_item) {
3006 DbgPrint("%s, %s - has no ctx info\n", group->cluster, group->category);
3010 ret = db_insert_groupmap(id, (char *)widget->pkgid, (char *)group->ctx_item);
3015 /* REUSE "id" from here , option ID */
3016 id = db_get_option_id(id, (char *)widget->pkgid, (char *)group->ctx_item);
3021 dlist_foreach(group->option_list, il, option) {
3022 ret = db_insert_option((char *)widget->pkgid, id, (char *)option->key, (char *)option->value);
3029 commit_transaction();
3030 widget_destroy(widget);
3034 ErrPrint("ROLLBACK\n");
3035 rollback_transaction();
3036 widget_destroy(widget);
3040 static int has_meta_tag(const char *appid, const char *meta_tag)
3044 pkgmgrinfo_appinfo_h handle;
3047 ErrPrint("meta ABI is not valid (%s)\n", appid);
3051 ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
3052 if (ret != PMINFO_R_OK) {
3057 * Not supported from tizen 3.0 yet
3059 ret = pkgmgrinfo_appinfo_get_metadata_value(handle, meta_tag, &value);
3060 if (ret != PMINFO_R_OK) {
3061 pkgmgrinfo_appinfo_destroy_appinfo(handle);
3066 ret = value && value[0] != '\0';
3068 pkgmgrinfo_appinfo_destroy_appinfo(handle);
3072 int db_install_widget(xmlNodePtr node, const char *appid)
3074 struct widget *widget;
3078 if (!xmlHasProp(node, (const xmlChar *)"appid")) {
3079 ErrPrint("Missing appid\n");
3083 pkgid = xmlGetProp(node, (const xmlChar *)"appid");
3084 if (!pkgid || !validate_pkgid(appid, (char *)pkgid)) {
3085 ErrPrint("Invalid appid\n");
3090 DbgPrint("appid: %s\n", (char *)pkgid);
3092 widget = calloc(1, sizeof(*widget));
3094 ErrPrint("calloc: %d\n", errno);
3099 widget->pkgid = pkgid;
3101 if (xmlHasProp(node, (const xmlChar *)"count")) {
3102 tmp = xmlGetProp(node, (const xmlChar *)"count");
3103 if (tmp && sscanf((const char *)tmp, "%d", &widget->count) != 1) {
3104 ErrPrint("Invalid syntax: %s\n", (const char *)tmp);
3111 * "primary" == "main"
3113 if (xmlHasProp(node, (const xmlChar *)"primary")) {
3114 tmp = xmlGetProp(node, (const xmlChar *)"primary");
3115 widget->primary = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
3119 if (xmlHasProp(node, (const xmlChar *)"main")) {
3120 tmp = xmlGetProp(node, (const xmlChar *)"main");
3121 widget->primary = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
3125 if (xmlHasProp(node, (const xmlChar *)"script")) {
3126 widget->script = xmlGetProp(node, (const xmlChar *)"script");
3127 if (!widget->script) {
3128 ErrPrint("script is NIL\n");
3132 if (xmlHasProp(node, (const xmlChar *)"nodisplay")) {
3133 tmp = xmlGetProp(node, (const xmlChar *)"nodisplay");
3134 widget->nodisplay = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
3138 if (xmlHasProp(node, (const xmlChar *)"pinup")) {
3139 tmp = xmlGetProp(node, (const xmlChar *)"pinup");
3140 widget->pinup = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
3146 * "period" == "update-period"
3148 if (xmlHasProp(node, (const xmlChar *)"period")) {
3149 widget->period = xmlGetProp(node, (const xmlChar *)"period");
3150 if (!widget->period) {
3151 ErrPrint("Period is NIL\n");
3155 if (xmlHasProp(node, (const xmlChar *)"update-period")) {
3156 widget->period = xmlGetProp(node, (const xmlChar *)"update-period");
3157 if (!widget->period) {
3158 ErrPrint("Period is NIL\n");
3162 if (xmlHasProp(node, (const xmlChar *)"timeout")) {
3163 widget->timeout = xmlGetProp(node, (const xmlChar *)"timeout");
3164 if (!widget->timeout) {
3165 ErrPrint("Timeout is NIL\n");
3169 if (xmlHasProp(node, (const xmlChar *)"secured")) {
3170 tmp = xmlGetProp(node, (const xmlChar *)"secured");
3171 widget->secured = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
3175 if (xmlHasProp(node, (const xmlChar *)"network")) {
3176 tmp = xmlGetProp(node, (const xmlChar *)"network");
3177 widget->network = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
3181 if (xmlHasProp(node, (const xmlChar *)"direct_input")) {
3182 tmp = xmlGetProp(node, (const xmlChar *)"direct_input");
3183 widget->direct_input = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
3187 if (xmlHasProp(node, (const xmlChar *)"hw-acceleration")) {
3188 widget->hw_acceleration = xmlGetProp(node, (const xmlChar *)"hw-acceleration");
3189 if (!widget->hw_acceleration) {
3190 ErrPrint("hw-acceleration is NIL\n");
3194 if (xmlHasProp(node, (const xmlChar *)"abi")) {
3195 widget->abi = xmlGetProp(node, (const xmlChar *)"abi");
3197 ErrPrint("ABI is NIL\n");
3198 widget_destroy(widget);
3205 * originally, "type" attribute is sticked with "box" tag.
3206 * But for the "widget-application" style tag, this "type" attribute is moved to "widget-application".
3207 * And there is no "box" tag.
3209 if (!xmlHasProp(node, (const xmlChar *)"type")) {
3210 widget->widget_type = WIDGET_TYPE_BUFFER;
3214 type = xmlGetProp(node, (const xmlChar *)"type");
3216 ErrPrint("Type is NIL\n");
3217 widget->widget_type = WIDGET_TYPE_FILE;
3219 if (!xmlStrcasecmp(type, (const xmlChar *)"text")) {
3220 widget->widget_type = WIDGET_TYPE_TEXT;
3221 } else if (!xmlStrcasecmp(type, (const xmlChar *)"buffer")) {
3222 widget->widget_type = WIDGET_TYPE_BUFFER;
3223 } else if (!xmlStrcasecmp(type, (const xmlChar *)"script")) {
3224 widget->widget_type = WIDGET_TYPE_SCRIPT;
3225 } else if (!xmlStrcasecmp(type, (const xmlChar *)"elm")) {
3226 widget->widget_type = WIDGET_TYPE_UIFW;
3227 } else { /* Default */
3228 widget->widget_type = WIDGET_TYPE_BUFFER;
3235 if (xmlHasProp(node, (const xmlChar *)"libexec")) {
3236 xmlChar *tmp_libexec;
3238 widget->libexec = xmlGetProp(node, (const xmlChar *)"libexec");
3239 if (!widget->libexec) {
3240 ErrPrint("libexec is NIL\n");
3241 widget_destroy(widget);
3245 tmp_libexec = abspath_strdup(widget->libexec);
3247 ErrPrint("strdup: %d\n", errno);
3248 widget_destroy(widget);
3252 abspath((char *)widget->libexec, (char *)tmp_libexec);
3253 xmlFree(widget->libexec);
3254 widget->libexec = tmp_libexec;
3259 * If there is no "abi" attribute,
3260 * Assumes it "c" in this case.
3261 * abi="c" can only has the "libexec" attribute
3263 widget->abi = xmlStrdup((const xmlChar *)"c");
3265 ErrPrint("xmlstrdup: %d\n", errno);
3266 widget_destroy(widget);
3269 } else if (xmlStrcasecmp(widget->abi, (const xmlChar *)"c") && xmlStrcasecmp(widget->abi, (const xmlChar *)"cpp")) {
3270 ErrPrint("libexec with unrecognized abi[%s]\n", (const char *)widget->abi);
3272 } else if (xmlHasProp(node, (const xmlChar *)"exec")) {
3273 xmlChar *tmp_libexec;
3275 widget->libexec = xmlGetProp(node, (const xmlChar *)"exec");
3276 if (!widget->libexec) {
3277 ErrPrint("libexec is NIL\n");
3278 widget_destroy(widget);
3282 tmp_libexec = abspath_strdup(widget->libexec);
3284 ErrPrint("strdup: %d\n", errno);
3285 widget_destroy(widget);
3289 abspath((char *)widget->libexec, (char *)tmp_libexec);
3290 xmlFree(widget->libexec);
3291 widget->libexec = tmp_libexec;
3296 * If there is no "abi" attribute,
3297 * Assumes it "app" in this case.
3298 * abi="app" can only has the "exec" attribute
3300 widget->abi = xmlStrdup((const xmlChar *)"app");
3302 ErrPrint("xmlstrdup: %d\n", errno);
3303 widget_destroy(widget);
3306 } else if (xmlStrcasecmp(widget->abi, (const xmlChar *)"app")) {
3307 ErrPrint("exec with unrecognized abi[%s]\n", (const char *)widget->abi);
3312 * Remove old style fallback processing.
3313 * If the element has no attribute for "libexec" or "exec", this is not valid XML
3314 * stop parsing from here.
3316 widget->libexec = xmlStrdup((const xmlChar *)"empty_path");
3317 if (!widget->libexec) {
3318 ErrPrint("xmlStrdup: %d\n", errno);
3322 for (node = node->children; node; node = node->next) {
3323 if (!xmlStrcmp(node->name, (const xmlChar *)"text")) {
3327 DbgPrint("Nodename: %s\n", node->name);
3328 if (!xmlStrcasecmp(node->name, (const xmlChar *)"label")) {
3329 update_i18n_name(widget, node);
3333 if (!xmlStrcasecmp(node->name, (const xmlChar *)"icon")) {
3334 update_i18n_icon(widget, node);
3338 if (!xmlStrcasecmp(node->name, (const xmlChar *)"box")) {
3339 update_box(widget, node);
3343 if (!xmlStrcasecmp(node->name, (const xmlChar *)"support-size")) {
3344 update_support_size(widget, node);
3348 if (!xmlStrcasecmp(node->name, (const xmlChar *)"glancebar")) {
3349 update_glance_bar(widget, node);
3353 if (!xmlStrcasecmp(node->name, (const xmlChar *)"group")) {
3354 update_group(widget, node);
3358 if (!xmlStrcasecmp(node->name, (const xmlChar *)"content")) {
3359 update_content(widget, node);
3363 if (!xmlStrcasecmp(node->name, (const xmlChar *)"setup")) {
3364 update_setup(widget, node);
3368 if (!xmlStrcasecmp(node->name, (const xmlChar *)"launch")) {
3369 update_launch(widget, node);
3373 if (!xmlStrcasecmp(node->name, (const xmlChar *)"ui-appid")) {
3374 update_ui_appid(widget, node);
3378 if (!xmlStrcasecmp(node->name, (const xmlChar *)"category")) {
3379 if (update_category(widget, node) < 0) {
3380 widget_destroy(widget);
3388 if (widget->uiapp) {
3391 * If there is no speicifed UI-App related with this widget,
3392 * Set default to Main UI App.
3394 widget->uiapp = pkgmgr_get_mainapp((char *)appid);
3395 DbgPrint("Default MAIN UI-APP: [%s]\n", (char *)widget->uiapp);
3399 * Check the "meta" tag of this widget.
3400 * If it has speicific meta tag, replace "abi" with "meta".
3402 if (has_meta_tag((const char *)widget->pkgid, widget_abi_get_pkgname_by_abi("meta"))) {
3403 DbgPrint("Meta tag is overrided: %s -> meta\n", (char *)widget->abi);
3406 xmlFree(widget->abi);
3409 widget->abi = xmlStrdup((xmlChar *)"meta");
3412 return db_insert_widget(widget, appid);
3415 int db_install_watchapp(xmlNodePtr node, const char *appid)
3417 struct widget *widget;
3420 if (!xmlHasProp(node, (const xmlChar *)"appid")) {
3421 ErrPrint("Missing appid\n");
3425 pkgid = xmlGetProp(node, (const xmlChar *)"appid");
3426 if (!pkgid || !validate_pkgid(appid, (char *)pkgid)) {
3427 ErrPrint("Invalid appid\n");
3432 DbgPrint("appid: %s\n", (char *)pkgid);
3434 widget = calloc(1, sizeof(*widget));
3436 ErrPrint("strdup: %d\n", errno);
3441 widget->pkgid = pkgid;
3443 widget->primary = 1;
3444 widget->secured = 1;
3445 widget->nodisplay = 1;
3446 widget->hw_acceleration = xmlStrdup((const xmlChar *)"use-sw"); //use-gl
3447 widget->abi = xmlStrdup((const xmlChar *)"app");
3448 widget->category = xmlStrdup((const xmlChar *)CATEGORY_WATCH_CLOCK);
3450 widget->widget_type = WIDGET_TYPE_BUFFER;
3451 widget->default_mouse_event = 1;
3452 widget->default_touch_effect = 0;
3453 widget->default_need_frame = 0;
3454 widget->size_list = WIDGET_SIZE_TYPE_2x2;
3456 if (xmlHasProp(node, (const xmlChar *)"exec")) {
3457 widget->libexec = xmlGetProp(node, (const xmlChar *)"exec");
3458 if (!widget->libexec) {
3459 ErrPrint("libexec is NIL\n");
3460 widget_destroy(widget);
3465 for (node = node->children; node; node = node->next) {
3466 if (!xmlStrcmp(node->name, (const xmlChar *)"text")) {
3470 DbgPrint("Nodename: %s\n", node->name);
3471 if (!xmlStrcasecmp(node->name, (const xmlChar *)"label")) {
3472 update_i18n_name(widget, node);
3476 if (!xmlStrcasecmp(node->name, (const xmlChar *)"icon")) {
3477 update_i18n_icon(widget, node);
3482 return db_insert_widget(widget, appid);
3485 int db_uninstall(xmlNodePtr node, const char *appid)
3490 if (!xmlHasProp(node, (const xmlChar *)"appid")) {
3491 ErrPrint("Missing appid\n");
3495 pkgid = xmlGetProp(node, (const xmlChar *)"appid");
3496 if (!validate_pkgid(appid, (char *)pkgid)) {
3497 ErrPrint("Invalid package\n");
3502 begin_transaction();
3503 ret = db_remove_box_size((const char *)pkgid);
3508 ret = db_remove_i18n((const char *)pkgid);
3513 ret = db_remove_client((const char *)pkgid);
3518 ret = db_remove_provider((const char *)pkgid);
3523 ret = db_remove_option((const char *)pkgid);
3524 DbgPrint("Remove option: %d\n", ret);
3526 ret = db_remove_groupmap((const char *)pkgid);
3527 DbgPrint("Remove groupmap: %d\n", ret);
3529 ret = db_remove_group((const char *)pkgid);
3534 ret = db_remove_pkgmap((const char *)pkgid);
3539 commit_transaction();
3545 rollback_transaction();
3550 int pkglist_get_via_callback(const char *appid, int is_watch_widget, void (*cb)(const char *appid, const char *pkgid, int prime, void *data), void *data)
3559 if (!cb || !appid || !strlen(appid)) {
3563 if (!s_info.handle) {
3564 if (db_init() < 0) {
3565 ErrPrint("Failed to init DB\n");
3570 if (is_watch_widget) { /* Watch */
3571 dml = "SELECT pkgid, prime FROM pkgmap WHERE appid = ? AND category = '" CATEGORY_WATCH_CLOCK "'";
3572 } else { /* Widget */
3573 dml = "SELECT pkgid, prime FROM pkgmap WHERE appid = ? AND (category IS NULL OR category <> '" CATEGORY_WATCH_CLOCK "')";
3576 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
3577 if (ret != SQLITE_OK) {
3578 ErrPrint("Failed to prepare the intial DML(%s)\n", sqlite3_errmsg(s_info.handle));
3583 if (sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
3584 ErrPrint("Failed to bind a cluster - %s\n", sqlite3_errmsg(s_info.handle));
3588 while (sqlite3_step(stmt) == SQLITE_ROW) {
3589 pkgid = (const char *)sqlite3_column_text(stmt, 0);
3590 if (!pkgid || !strlen(pkgid)) {
3594 prime = sqlite3_column_int(stmt, 1);
3595 cb(appid, pkgid, prime, data);
3600 sqlite3_reset(stmt);
3601 sqlite3_clear_bindings(stmt);
3602 sqlite3_finalize(stmt);
3606 void delete_record_cb(const char *appid, const char *pkgid, int prime, void *data)
3610 ErrPrintWithConsole("Remove old package info: appid(%s), pkgid(%s)\n", appid, pkgid);
3612 ret = db_remove_box_size((char *)pkgid);
3614 ErrPrint("Remove box size: %d\n", ret);
3617 ret = db_remove_i18n((char *)pkgid);
3619 ErrPrint("Remove i18n: %d\n", ret);
3622 ret = db_remove_client((char *)pkgid);
3624 ErrPrint("Remove client: %d\n", ret);
3627 ret = db_remove_provider((char *)pkgid);
3629 ErrPrint("Remove provider: %d\n", ret);
3632 ret = db_remove_option((char *)pkgid);
3634 ErrPrint("Remove option: %d\n", ret);
3637 ret = db_remove_groupmap((char *)pkgid);
3639 ErrPrint("Remove groupmap: %d\n", ret);
3642 ret = db_remove_group((char *)pkgid);
3644 ErrPrint("Remove group: %d\n", ret);
3647 ret = db_remove_pkgmap((char *)pkgid);
3649 ErrPrint("Remove pkgmap: %d\n", ret);