620481e06cd3085ed1a9f281aa94a9abce4ea36d
[profile/ivi/isf.git] / ism / src / isf_query_engines.cpp
1 /*
2  * ISF(Input Service Framework)
3  *
4  * ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable.
5  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6  *
7  * Contact: Haifeng Deng <haifeng.deng@samsung.com>, Hengliang Luo <hl.luo@samsung.com>
8  *
9  * This library is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License as published by the
11  * Free Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
15  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation, Inc., 51
21  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24
25 #define Uses_SCIM_DEBUG
26 #define Uses_SCIM_CONFIG
27 #define Uses_SCIM_CONFIG_MODULE
28 #define Uses_SCIM_CONFIG_PATH
29 #define Uses_SCIM_UTILITY
30 #define Uses_SCIM_PANEL_AGENT
31
32
33 #include <sys/stat.h>
34 #include <string.h>
35 #include <stdio.h>
36 #include <unistd.h>
37 #include <vconf.h>
38 #include "scim_private.h"
39 #include "scim.h"
40 #include "isf_query_utility.h"
41 #include <privilege-control.h>
42
43
44 using namespace scim;
45
46
47 static void print_help (void)
48 {
49     std::cout << "Usage: isf-query-engines [option] ISE_MODULE_NAME\n\n"
50          << "The options are: \n"
51          << "  -u, --uninstall        If this option is not specified, the default action is to install.\n"
52          << "  -t, --type isetype     If this option is not specified, the default type is 0(keyboardISE).\n"
53          << "  -h, --help             Show this help message.\n";
54 }
55
56 int main (int argc, char *argv[])
57 {
58     char *isename = NULL;
59     int isetype = 0;
60     int uninstall = 0;
61
62     control_privilege ();
63
64     int i = 1;
65     while (i < argc) {
66         if (String ("-t") == String (argv[i]) || String ("--type") == String (argv[i])) {
67             if (++i >= argc) {
68                 std::cerr << "No argument for option " << argv [i-1] << "\n";
69                 return -1;
70             }
71             isetype = atoi (argv[i]);
72             i++;
73             continue;
74         }
75
76         if (String ("-u") == String (argv[i]) || String ("--uninstall") == String (argv[i])) {
77             i++;
78             uninstall = 1;
79             continue;
80         }
81
82         if (String ("-h") == String (argv[i]) || String ("--help") == String (argv[i])) {
83             print_help ();
84             return 0;
85         }
86
87         isename = argv[i];
88         i++;
89     }
90
91     String sys_file_name  = String (SYS_ENGINE_FILE_NAME);
92     String user_file_name = String (USER_ENGINE_FILE_NAME);
93     String engine_file_name = sys_file_name;
94
95     if (access (engine_file_name.c_str (), F_OK | W_OK) != 0) {
96         FILE *filp = fopen (engine_file_name.c_str (), "a");
97         if (filp == NULL) {
98             engine_file_name = user_file_name;
99             // Create folder for saving engine list
100             scim_make_dir (USER_ENGINE_LIST_PATH);
101         } else {
102             fclose (filp);
103         }
104     }
105
106     if (uninstall == 1) {
107         isf_remove_ise_info_from_file (engine_file_name.c_str (), isename);
108         return 0;
109     }
110
111     ConfigModule *_config_module = 0;
112     ConfigPointer _config;
113
114     _config_module = new ConfigModule ("simple");
115     if (_config_module != NULL && _config_module->valid ())
116         _config = _config_module->create_config ();
117     if (_config.null ()) {
118         std::cerr << "Config module cannot be loaded, using dummy Config.\n";
119
120         if (_config_module) delete _config_module;
121         _config_module = NULL;
122
123         _config = new DummyConfig ();
124     }
125
126     char *lang_str = vconf_get_str (VCONFKEY_LANGSET);
127
128     if (strlen (lang_str)) {
129         setenv ("LANG", lang_str, 1);
130         setlocale (LC_MESSAGES, lang_str);
131         free(lang_str);
132     } else {
133         setenv ("LANG", "en_US.utf8", 1);
134         setlocale (LC_MESSAGES, "en_US.utf8");
135     }
136
137     if (argc == 1) {
138         isf_update_ise_info_to_file (engine_file_name.c_str (), _config);
139         return 0;
140     }
141
142     if (isetype == 0)
143         isf_add_keyboard_info_to_file (engine_file_name.c_str (), isename, _config);
144     else
145         isf_add_helper_info_to_file (engine_file_name.c_str (), isename);
146
147     return 0;
148 }
149
150 /*
151 vi:ts=4:nowrap:ai:expandtab
152 */