1 /*
2  * Smart Common Input Method
3  *
4  * Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn>
5  *
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this program; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA  02111-1307  USA
21  *
22  * $Id: scim_setup_module.cpp,v 1.9 2005/01/10 08:30:45 suzhe Exp $
23  *
24  */
25 
26 #define Uses_SCIM_CONFIG_BASE
27 #define Uses_SCIM_MODULE
28 
29 #include "scim_private.h"
30 #include "scim.h"
31 #include "scim_setup_module.h"
32 
SetupModule()33 SetupModule::SetupModule ()
34     : m_create_ui (0),
35       m_get_category (0),
36       m_get_name (0),
37       m_get_description (0),
38       m_load_config (0),
39       m_save_config (0)
40 {
41 }
42 
SetupModule(const String & name)43 SetupModule::SetupModule (const String &name)
44     : m_create_ui (0),
45       m_get_category (0),
46       m_get_name (0),
47       m_get_description (0),
48       m_load_config (0),
49       m_save_config (0)
50 {
51     load (name);
52 }
53 
54 bool
load(const String & name)55 SetupModule::load (const String &name)
56 {
57     if (!m_module.load (name, "SetupUI"))
58         return false;
59 
60     m_create_ui       = (SetupModuleCreateUIFunc) m_module.symbol ("scim_setup_module_create_ui");
61     m_get_category    = (SetupModuleGetCategoryFunc) m_module.symbol ("scim_setup_module_get_category");
62     m_get_name        = (SetupModuleGetNameFunc) m_module.symbol ("scim_setup_module_get_name");
63     m_get_description = (SetupModuleGetDescriptionFunc) m_module.symbol ("scim_setup_module_get_description");
64     m_load_config     = (SetupModuleLoadConfigFunc) m_module.symbol ("scim_setup_module_load_config");
65     m_save_config     = (SetupModuleSaveConfigFunc) m_module.symbol ("scim_setup_module_save_config");
66     m_query_changed   = (SetupModuleQueryChangedFunc) m_module.symbol ("scim_setup_module_query_changed");
67 
68 
69     if (!m_create_ui || !m_get_category || !m_get_name ||
70         !m_load_config || !m_save_config) {
71         m_module.unload ();
72         m_create_ui = 0;
73         m_get_category = 0;
74         m_get_name = 0;
75         m_get_description = 0;
76         m_load_config = 0;
77         m_save_config = 0;
78         return false;
79     }
80 
81     return true;
82 }
83 
84 bool
valid() const85 SetupModule::valid () const
86 {
87     return (m_module.valid () &&
88             m_create_ui && m_get_category && m_get_name &&
89             m_load_config && m_save_config);
90 }
91 
92 GtkWidget *
create_ui() const93 SetupModule::create_ui () const
94 {
95     if (valid ())
96         return m_create_ui ();
97 
98     return 0;
99 }
100 
101 String
get_category() const102 SetupModule::get_category () const
103 {
104     if (valid ())
105         return m_get_category ();
106 
107     return String ();
108 }
109 
110 String
get_name() const111 SetupModule::get_name () const
112 {
113     if (valid ())
114         return m_get_name ();
115 
116     return String ();
117 }
118 
119 String
get_description() const120 SetupModule::get_description () const
121 {
122     if (valid () && m_get_description)
123         return m_get_description ();
124 
125     return String ();
126 }
127 
128 void
load_config(const ConfigPointer & config) const129 SetupModule::load_config (const ConfigPointer &config) const
130 {
131     if (valid ())
132         m_load_config (config);
133 }
134 
135 void
save_config(const ConfigPointer & config) const136 SetupModule::save_config (const ConfigPointer &config) const
137 {
138     if (valid ())
139         m_save_config (config);
140 }
141 
142 bool
query_changed() const143 SetupModule::query_changed () const
144 {
145     if (valid () && m_query_changed)
146         return m_query_changed ();
147     return false;
148 }
149 
scim_get_setup_module_list(std::vector<String> & mod_list)150 int scim_get_setup_module_list (std::vector <String>& mod_list)
151 {
152     return scim_get_module_list (mod_list, "SetupUI");
153 }
154 
155 
156 /*
157 vi:ts=4:nowrap:ai:expandtab
158 */
159