Imported Upstream version 0.3.1
Aron Xu
12 years ago
0 | 0 | repo: ca6e0ddbd0d051195154f17ae6b5d04e8690caf3 |
1 | node: 7dc13a5202262322574c91bb562d0e51ec589118 | |
1 | node: fb6aee7892ceb852d2e51746eb07966cb084d4f6 | |
2 | 2 | branch: default |
3 | latesttag: 0.2.0 | |
4 | latesttagdistance: 2 | |
3 | tag: 0.3.1 |
0 | # use glob syntax. | |
1 | syntax: glob | |
2 | *~ | |
3 | build/* | |
4 | data/pinyin.tar.gz | |
5 | data/pinyin.tar.gz.md5 | |
6 | data/table/table.tar.gz | |
7 | data/table/table.tar.gz.md5 | |
8 | *.kdev4 | |
9 | tools/pybase.mb | |
10 | tools/pyphrase.mb | |
11 | data/desc.po | |
12 | .kdev_include_paths | |
13 | .directory | |
14 | *.kate-swp | |
15 | *.orig |
0 | 135a76844b3230d6ae705ef880e2d9a171d8df5d 0.1.3 | |
1 | 4dcb1c5d971b89979a65a1666ad88a93e96f5ce2 0.1.1 | |
2 | f816e5ed0abdeb3efc98a5a7387afe4b794dbec2 0.1 | |
3 | c5952292040db98bde1bacee34e7fef6772292bd 0.1.4 | |
4 | 667dc5e1d1aa13fed217a8a8803e84d9691fe4cd 0.2.0 | |
5 | 73c63d96ba5e32bf941cf4465f0a88f754130535 0.3.0 |
1 | 1 | |
2 | 2 | project(fcitx-configtool) |
3 | 3 | |
4 | # uninstall target | |
5 | configure_file( | |
6 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" | |
7 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" | |
8 | IMMEDIATE @ONLY) | |
9 | ||
10 | add_custom_target(uninstall | |
11 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) | |
12 | ||
13 | include(FindPkgConfig) | |
4 | 14 | FIND_PACKAGE(Gettext REQUIRED) |
15 | find_package(Fcitx REQUIRED) | |
16 | PKG_CHECK_MODULES (GTK2 "gtk+-2.0" REQUIRED) | |
17 | PKG_CHECK_MODULES(UNIQUE "unique-1.0") | |
5 | 18 | FIND_PROGRAM(INTLTOOL_EXTRACT intltool-extract) |
6 | 19 | FIND_PROGRAM(INTLTOOL_UPDATE intltool-update) |
7 | 20 | FIND_PROGRAM(INTLTOOL_MERGE intltool-merge) |
21 | set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -fvisibility=hidden ${CMAKE_C_FLAGS}") | |
22 | set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -fvisibility=hidden ${CMAKE_CXX_FLAGS}") | |
23 | set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined,--as-needed ${CMAKE_SHARED_LINKER_FLAGS}") | |
24 | set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined,--as-needed ${CMAKE_MODULE_LINKER_FLAGS}") | |
25 | ||
26 | set(datadir ${CMAKE_INSTALL_PREFIX}/share) | |
27 | set(localedir ${CMAKE_INSTALL_PREFIX}/share/locale) | |
28 | set(exec_prefix "${CMAKE_INSTALL_PREFIX}") | |
29 | ||
30 | configure_file(config.h.in config.h) | |
31 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) | |
8 | 32 | |
9 | 33 | add_subdirectory(gtk) |
10 | 34 | add_subdirectory(po) |
0 | GNU GENERAL PUBLIC LICENSE | |
1 | Version 3, 29 June 2007 | |
2 | ||
3 | Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> | |
0 | GNU GENERAL PUBLIC LICENSE | |
1 | Version 2, June 1991 | |
2 | ||
3 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. | |
4 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
4 | 5 | Everyone is permitted to copy and distribute verbatim copies |
5 | 6 | of this license document, but changing it is not allowed. |
6 | 7 | |
7 | Preamble | |
8 | ||
9 | The GNU General Public License is a free, copyleft license for | |
10 | software and other kinds of works. | |
11 | ||
12 | The licenses for most software and other practical works are designed | |
13 | to take away your freedom to share and change the works. By contrast, | |
14 | the GNU General Public License is intended to guarantee your freedom to | |
15 | share and change all versions of a program--to make sure it remains free | |
16 | software for all its users. We, the Free Software Foundation, use the | |
17 | GNU General Public License for most of our software; it applies also to | |
18 | any other work released this way by its authors. You can apply it to | |
8 | Preamble | |
9 | ||
10 | The licenses for most software are designed to take away your | |
11 | freedom to share and change it. By contrast, the GNU General Public | |
12 | License is intended to guarantee your freedom to share and change free | |
13 | software--to make sure the software is free for all its users. This | |
14 | General Public License applies to most of the Free Software | |
15 | Foundation's software and to any other program whose authors commit to | |
16 | using it. (Some other Free Software Foundation software is covered by | |
17 | the GNU Library General Public License instead.) You can apply it to | |
19 | 18 | your programs, too. |
20 | 19 | |
21 | 20 | When we speak of free software, we are referring to freedom, not |
22 | 21 | price. Our General Public Licenses are designed to make sure that you |
23 | 22 | have the freedom to distribute copies of free software (and charge for |
24 | them if you wish), that you receive source code or can get it if you | |
25 | want it, that you can change the software or use pieces of it in new | |
26 | free programs, and that you know you can do these things. | |
27 | ||
28 | To protect your rights, we need to prevent others from denying you | |
29 | these rights or asking you to surrender the rights. Therefore, you have | |
30 | certain responsibilities if you distribute copies of the software, or if | |
31 | you modify it: responsibilities to respect the freedom of others. | |
23 | this service if you wish), that you receive source code or can get it | |
24 | if you want it, that you can change the software or use pieces of it | |
25 | in new free programs; and that you know you can do these things. | |
26 | ||
27 | To protect your rights, we need to make restrictions that forbid | |
28 | anyone to deny you these rights or to ask you to surrender the rights. | |
29 | These restrictions translate to certain responsibilities for you if you | |
30 | distribute copies of the software, or if you modify it. | |
32 | 31 | |
33 | 32 | For example, if you distribute copies of such a program, whether |
34 | gratis or for a fee, you must pass on to the recipients the same | |
35 | freedoms that you received. You must make sure that they, too, receive | |
36 | or can get the source code. And you must show them these terms so they | |
37 | know their rights. | |
38 | ||
39 | Developers that use the GNU GPL protect your rights with two steps: | |
40 | (1) assert copyright on the software, and (2) offer you this License | |
41 | giving you legal permission to copy, distribute and/or modify it. | |
42 | ||
43 | For the developers' and authors' protection, the GPL clearly explains | |
44 | that there is no warranty for this free software. For both users' and | |
45 | authors' sake, the GPL requires that modified versions be marked as | |
46 | changed, so that their problems will not be attributed erroneously to | |
47 | authors of previous versions. | |
48 | ||
49 | Some devices are designed to deny users access to install or run | |
50 | modified versions of the software inside them, although the manufacturer | |
51 | can do so. This is fundamentally incompatible with the aim of | |
52 | protecting users' freedom to change the software. The systematic | |
53 | pattern of such abuse occurs in the area of products for individuals to | |
54 | use, which is precisely where it is most unacceptable. Therefore, we | |
55 | have designed this version of the GPL to prohibit the practice for those | |
56 | products. If such problems arise substantially in other domains, we | |
57 | stand ready to extend this provision to those domains in future versions | |
58 | of the GPL, as needed to protect the freedom of users. | |
59 | ||
60 | Finally, every program is threatened constantly by software patents. | |
61 | States should not allow patents to restrict development and use of | |
62 | software on general-purpose computers, but in those that do, we wish to | |
63 | avoid the special danger that patents applied to a free program could | |
64 | make it effectively proprietary. To prevent this, the GPL assures that | |
65 | patents cannot be used to render the program non-free. | |
33 | gratis or for a fee, you must give the recipients all the rights that | |
34 | you have. You must make sure that they, too, receive or can get the | |
35 | source code. And you must show them these terms so they know their | |
36 | rights. | |
37 | ||
38 | We protect your rights with two steps: (1) copyright the software, and | |
39 | (2) offer you this license which gives you legal permission to copy, | |
40 | distribute and/or modify the software. | |
41 | ||
42 | Also, for each author's protection and ours, we want to make certain | |
43 | that everyone understands that there is no warranty for this free | |
44 | software. If the software is modified by someone else and passed on, we | |
45 | want its recipients to know that what they have is not the original, so | |
46 | that any problems introduced by others will not reflect on the original | |
47 | authors' reputations. | |
48 | ||
49 | Finally, any free program is threatened constantly by software | |
50 | patents. We wish to avoid the danger that redistributors of a free | |
51 | program will individually obtain patent licenses, in effect making the | |
52 | program proprietary. To prevent this, we have made it clear that any | |
53 | patent must be licensed for everyone's free use or not licensed at all. | |
66 | 54 | |
67 | 55 | The precise terms and conditions for copying, distribution and |
68 | 56 | modification follow. |
69 | 57 | |
70 | TERMS AND CONDITIONS | |
71 | ||
72 | 0. Definitions. | |
73 | ||
74 | "This License" refers to version 3 of the GNU General Public License. | |
75 | ||
76 | "Copyright" also means copyright-like laws that apply to other kinds of | |
77 | works, such as semiconductor masks. | |
78 | ||
79 | "The Program" refers to any copyrightable work licensed under this | |
80 | License. Each licensee is addressed as "you". "Licensees" and | |
81 | "recipients" may be individuals or organizations. | |
82 | ||
83 | To "modify" a work means to copy from or adapt all or part of the work | |
84 | in a fashion requiring copyright permission, other than the making of an | |
85 | exact copy. The resulting work is called a "modified version" of the | |
86 | earlier work or a work "based on" the earlier work. | |
87 | ||
88 | A "covered work" means either the unmodified Program or a work based | |
89 | on the Program. | |
90 | ||
91 | To "propagate" a work means to do anything with it that, without | |
92 | permission, would make you directly or secondarily liable for | |
93 | infringement under applicable copyright law, except executing it on a | |
94 | computer or modifying a private copy. Propagation includes copying, | |
95 | distribution (with or without modification), making available to the | |
96 | public, and in some countries other activities as well. | |
97 | ||
98 | To "convey" a work means any kind of propagation that enables other | |
99 | parties to make or receive copies. Mere interaction with a user through | |
100 | a computer network, with no transfer of a copy, is not conveying. | |
101 | ||
102 | An interactive user interface displays "Appropriate Legal Notices" | |
103 | to the extent that it includes a convenient and prominently visible | |
104 | feature that (1) displays an appropriate copyright notice, and (2) | |
105 | tells the user that there is no warranty for the work (except to the | |
106 | extent that warranties are provided), that licensees may convey the | |
107 | work under this License, and how to view a copy of this License. If | |
108 | the interface presents a list of user commands or options, such as a | |
109 | menu, a prominent item in the list meets this criterion. | |
110 | ||
111 | 1. Source Code. | |
112 | ||
113 | The "source code" for a work means the preferred form of the work | |
114 | for making modifications to it. "Object code" means any non-source | |
115 | form of a work. | |
116 | ||
117 | A "Standard Interface" means an interface that either is an official | |
118 | standard defined by a recognized standards body, or, in the case of | |
119 | interfaces specified for a particular programming language, one that | |
120 | is widely used among developers working in that language. | |
121 | ||
122 | The "System Libraries" of an executable work include anything, other | |
123 | than the work as a whole, that (a) is included in the normal form of | |
124 | packaging a Major Component, but which is not part of that Major | |
125 | Component, and (b) serves only to enable use of the work with that | |
126 | Major Component, or to implement a Standard Interface for which an | |
127 | implementation is available to the public in source code form. A | |
128 | "Major Component", in this context, means a major essential component | |
129 | (kernel, window system, and so on) of the specific operating system | |
130 | (if any) on which the executable work runs, or a compiler used to | |
131 | produce the work, or an object code interpreter used to run it. | |
132 | ||
133 | The "Corresponding Source" for a work in object code form means all | |
134 | the source code needed to generate, install, and (for an executable | |
135 | work) run the object code and to modify the work, including scripts to | |
136 | control those activities. However, it does not include the work's | |
137 | System Libraries, or general-purpose tools or generally available free | |
138 | programs which are used unmodified in performing those activities but | |
139 | which are not part of the work. For example, Corresponding Source | |
140 | includes interface definition files associated with source files for | |
141 | the work, and the source code for shared libraries and dynamically | |
142 | linked subprograms that the work is specifically designed to require, | |
143 | such as by intimate data communication or control flow between those | |
144 | subprograms and other parts of the work. | |
145 | ||
146 | The Corresponding Source need not include anything that users | |
147 | can regenerate automatically from other parts of the Corresponding | |
148 | Source. | |
149 | ||
150 | The Corresponding Source for a work in source code form is that | |
151 | same work. | |
152 | ||
153 | 2. Basic Permissions. | |
154 | ||
155 | All rights granted under this License are granted for the term of | |
156 | copyright on the Program, and are irrevocable provided the stated | |
157 | conditions are met. This License explicitly affirms your unlimited | |
158 | permission to run the unmodified Program. The output from running a | |
159 | covered work is covered by this License only if the output, given its | |
160 | content, constitutes a covered work. This License acknowledges your | |
161 | rights of fair use or other equivalent, as provided by copyright law. | |
162 | ||
163 | You may make, run and propagate covered works that you do not | |
164 | convey, without conditions so long as your license otherwise remains | |
165 | in force. You may convey covered works to others for the sole purpose | |
166 | of having them make modifications exclusively for you, or provide you | |
167 | with facilities for running those works, provided that you comply with | |
168 | the terms of this License in conveying all material for which you do | |
169 | not control copyright. Those thus making or running the covered works | |
170 | for you must do so exclusively on your behalf, under your direction | |
171 | and control, on terms that prohibit them from making any copies of | |
172 | your copyrighted material outside their relationship with you. | |
173 | ||
174 | Conveying under any other circumstances is permitted solely under | |
175 | the conditions stated below. Sublicensing is not allowed; section 10 | |
176 | makes it unnecessary. | |
177 | ||
178 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. | |
179 | ||
180 | No covered work shall be deemed part of an effective technological | |
181 | measure under any applicable law fulfilling obligations under article | |
182 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or | |
183 | similar laws prohibiting or restricting circumvention of such | |
184 | measures. | |
185 | ||
186 | When you convey a covered work, you waive any legal power to forbid | |
187 | circumvention of technological measures to the extent such circumvention | |
188 | is effected by exercising rights under this License with respect to | |
189 | the covered work, and you disclaim any intention to limit operation or | |
190 | modification of the work as a means of enforcing, against the work's | |
191 | users, your or third parties' legal rights to forbid circumvention of | |
192 | technological measures. | |
193 | ||
194 | 4. Conveying Verbatim Copies. | |
195 | ||
196 | You may convey verbatim copies of the Program's source code as you | |
197 | receive it, in any medium, provided that you conspicuously and | |
198 | appropriately publish on each copy an appropriate copyright notice; | |
199 | keep intact all notices stating that this License and any | |
200 | non-permissive terms added in accord with section 7 apply to the code; | |
201 | keep intact all notices of the absence of any warranty; and give all | |
202 | recipients a copy of this License along with the Program. | |
203 | ||
204 | You may charge any price or no price for each copy that you convey, | |
205 | and you may offer support or warranty protection for a fee. | |
206 | ||
207 | 5. Conveying Modified Source Versions. | |
208 | ||
209 | You may convey a work based on the Program, or the modifications to | |
210 | produce it from the Program, in the form of source code under the | |
211 | terms of section 4, provided that you also meet all of these conditions: | |
212 | ||
213 | a) The work must carry prominent notices stating that you modified | |
214 | it, and giving a relevant date. | |
215 | ||
216 | b) The work must carry prominent notices stating that it is | |
217 | released under this License and any conditions added under section | |
218 | 7. This requirement modifies the requirement in section 4 to | |
219 | "keep intact all notices". | |
220 | ||
221 | c) You must license the entire work, as a whole, under this | |
222 | License to anyone who comes into possession of a copy. This | |
223 | License will therefore apply, along with any applicable section 7 | |
224 | additional terms, to the whole of the work, and all its parts, | |
225 | regardless of how they are packaged. This License gives no | |
226 | permission to license the work in any other way, but it does not | |
227 | invalidate such permission if you have separately received it. | |
228 | ||
229 | d) If the work has interactive user interfaces, each must display | |
230 | Appropriate Legal Notices; however, if the Program has interactive | |
231 | interfaces that do not display Appropriate Legal Notices, your | |
232 | work need not make them do so. | |
233 | ||
234 | A compilation of a covered work with other separate and independent | |
235 | works, which are not by their nature extensions of the covered work, | |
236 | and which are not combined with it such as to form a larger program, | |
237 | in or on a volume of a storage or distribution medium, is called an | |
238 | "aggregate" if the compilation and its resulting copyright are not | |
239 | used to limit the access or legal rights of the compilation's users | |
240 | beyond what the individual works permit. Inclusion of a covered work | |
241 | in an aggregate does not cause this License to apply to the other | |
242 | parts of the aggregate. | |
243 | ||
244 | 6. Conveying Non-Source Forms. | |
245 | ||
246 | You may convey a covered work in object code form under the terms | |
247 | of sections 4 and 5, provided that you also convey the | |
248 | machine-readable Corresponding Source under the terms of this License, | |
249 | in one of these ways: | |
250 | ||
251 | a) Convey the object code in, or embodied in, a physical product | |
252 | (including a physical distribution medium), accompanied by the | |
253 | Corresponding Source fixed on a durable physical medium | |
254 | customarily used for software interchange. | |
255 | ||
256 | b) Convey the object code in, or embodied in, a physical product | |
257 | (including a physical distribution medium), accompanied by a | |
258 | written offer, valid for at least three years and valid for as | |
259 | long as you offer spare parts or customer support for that product | |
260 | model, to give anyone who possesses the object code either (1) a | |
261 | copy of the Corresponding Source for all the software in the | |
262 | product that is covered by this License, on a durable physical | |
263 | medium customarily used for software interchange, for a price no | |
264 | more than your reasonable cost of physically performing this | |
265 | conveying of source, or (2) access to copy the | |
266 | Corresponding Source from a network server at no charge. | |
267 | ||
268 | c) Convey individual copies of the object code with a copy of the | |
269 | written offer to provide the Corresponding Source. This | |
270 | alternative is allowed only occasionally and noncommercially, and | |
271 | only if you received the object code with such an offer, in accord | |
272 | with subsection 6b. | |
273 | ||
274 | d) Convey the object code by offering access from a designated | |
275 | place (gratis or for a charge), and offer equivalent access to the | |
276 | Corresponding Source in the same way through the same place at no | |
277 | further charge. You need not require recipients to copy the | |
278 | Corresponding Source along with the object code. If the place to | |
279 | copy the object code is a network server, the Corresponding Source | |
280 | may be on a different server (operated by you or a third party) | |
281 | that supports equivalent copying facilities, provided you maintain | |
282 | clear directions next to the object code saying where to find the | |
283 | Corresponding Source. Regardless of what server hosts the | |
284 | Corresponding Source, you remain obligated to ensure that it is | |
285 | available for as long as needed to satisfy these requirements. | |
286 | ||
287 | e) Convey the object code using peer-to-peer transmission, provided | |
288 | you inform other peers where the object code and Corresponding | |
289 | Source of the work are being offered to the general public at no | |
290 | charge under subsection 6d. | |
291 | ||
292 | A separable portion of the object code, whose source code is excluded | |
293 | from the Corresponding Source as a System Library, need not be | |
294 | included in conveying the object code work. | |
295 | ||
296 | A "User Product" is either (1) a "consumer product", which means any | |
297 | tangible personal property which is normally used for personal, family, | |
298 | or household purposes, or (2) anything designed or sold for incorporation | |
299 | into a dwelling. In determining whether a product is a consumer product, | |
300 | doubtful cases shall be resolved in favor of coverage. For a particular | |
301 | product received by a particular user, "normally used" refers to a | |
302 | typical or common use of that class of product, regardless of the status | |
303 | of the particular user or of the way in which the particular user | |
304 | actually uses, or expects or is expected to use, the product. A product | |
305 | is a consumer product regardless of whether the product has substantial | |
306 | commercial, industrial or non-consumer uses, unless such uses represent | |
307 | the only significant mode of use of the product. | |
308 | ||
309 | "Installation Information" for a User Product means any methods, | |
310 | procedures, authorization keys, or other information required to install | |
311 | and execute modified versions of a covered work in that User Product from | |
312 | a modified version of its Corresponding Source. The information must | |
313 | suffice to ensure that the continued functioning of the modified object | |
314 | code is in no case prevented or interfered with solely because | |
315 | modification has been made. | |
316 | ||
317 | If you convey an object code work under this section in, or with, or | |
318 | specifically for use in, a User Product, and the conveying occurs as | |
319 | part of a transaction in which the right of possession and use of the | |
320 | User Product is transferred to the recipient in perpetuity or for a | |
321 | fixed term (regardless of how the transaction is characterized), the | |
322 | Corresponding Source conveyed under this section must be accompanied | |
323 | by the Installation Information. But this requirement does not apply | |
324 | if neither you nor any third party retains the ability to install | |
325 | modified object code on the User Product (for example, the work has | |
326 | been installed in ROM). | |
327 | ||
328 | The requirement to provide Installation Information does not include a | |
329 | requirement to continue to provide support service, warranty, or updates | |
330 | for a work that has been modified or installed by the recipient, or for | |
331 | the User Product in which it has been modified or installed. Access to a | |
332 | network may be denied when the modification itself materially and | |
333 | adversely affects the operation of the network or violates the rules and | |
334 | protocols for communication across the network. | |
335 | ||
336 | Corresponding Source conveyed, and Installation Information provided, | |
337 | in accord with this section must be in a format that is publicly | |
338 | documented (and with an implementation available to the public in | |
339 | source code form), and must require no special password or key for | |
340 | unpacking, reading or copying. | |
341 | ||
342 | 7. Additional Terms. | |
343 | ||
344 | "Additional permissions" are terms that supplement the terms of this | |
345 | License by making exceptions from one or more of its conditions. | |
346 | Additional permissions that are applicable to the entire Program shall | |
347 | be treated as though they were included in this License, to the extent | |
348 | that they are valid under applicable law. If additional permissions | |
349 | apply only to part of the Program, that part may be used separately | |
350 | under those permissions, but the entire Program remains governed by | |
351 | this License without regard to the additional permissions. | |
352 | ||
353 | When you convey a copy of a covered work, you may at your option | |
354 | remove any additional permissions from that copy, or from any part of | |
355 | it. (Additional permissions may be written to require their own | |
356 | removal in certain cases when you modify the work.) You may place | |
357 | additional permissions on material, added by you to a covered work, | |
358 | for which you have or can give appropriate copyright permission. | |
359 | ||
360 | Notwithstanding any other provision of this License, for material you | |
361 | add to a covered work, you may (if authorized by the copyright holders of | |
362 | that material) supplement the terms of this License with terms: | |
363 | ||
364 | a) Disclaiming warranty or limiting liability differently from the | |
365 | terms of sections 15 and 16 of this License; or | |
366 | ||
367 | b) Requiring preservation of specified reasonable legal notices or | |
368 | author attributions in that material or in the Appropriate Legal | |
369 | Notices displayed by works containing it; or | |
370 | ||
371 | c) Prohibiting misrepresentation of the origin of that material, or | |
372 | requiring that modified versions of such material be marked in | |
373 | reasonable ways as different from the original version; or | |
374 | ||
375 | d) Limiting the use for publicity purposes of names of licensors or | |
376 | authors of the material; or | |
377 | ||
378 | e) Declining to grant rights under trademark law for use of some | |
379 | trade names, trademarks, or service marks; or | |
380 | ||
381 | f) Requiring indemnification of licensors and authors of that | |
382 | material by anyone who conveys the material (or modified versions of | |
383 | it) with contractual assumptions of liability to the recipient, for | |
384 | any liability that these contractual assumptions directly impose on | |
385 | those licensors and authors. | |
386 | ||
387 | All other non-permissive additional terms are considered "further | |
388 | restrictions" within the meaning of section 10. If the Program as you | |
389 | received it, or any part of it, contains a notice stating that it is | |
390 | governed by this License along with a term that is a further | |
391 | restriction, you may remove that term. If a license document contains | |
392 | a further restriction but permits relicensing or conveying under this | |
393 | License, you may add to a covered work material governed by the terms | |
394 | of that license document, provided that the further restriction does | |
395 | not survive such relicensing or conveying. | |
396 | ||
397 | If you add terms to a covered work in accord with this section, you | |
398 | must place, in the relevant source files, a statement of the | |
399 | additional terms that apply to those files, or a notice indicating | |
400 | where to find the applicable terms. | |
401 | ||
402 | Additional terms, permissive or non-permissive, may be stated in the | |
403 | form of a separately written license, or stated as exceptions; | |
404 | the above requirements apply either way. | |
405 | ||
406 | 8. Termination. | |
407 | ||
408 | You may not propagate or modify a covered work except as expressly | |
409 | provided under this License. Any attempt otherwise to propagate or | |
410 | modify it is void, and will automatically terminate your rights under | |
411 | this License (including any patent licenses granted under the third | |
412 | paragraph of section 11). | |
413 | ||
414 | However, if you cease all violation of this License, then your | |
415 | license from a particular copyright holder is reinstated (a) | |
416 | provisionally, unless and until the copyright holder explicitly and | |
417 | finally terminates your license, and (b) permanently, if the copyright | |
418 | holder fails to notify you of the violation by some reasonable means | |
419 | prior to 60 days after the cessation. | |
420 | ||
421 | Moreover, your license from a particular copyright holder is | |
422 | reinstated permanently if the copyright holder notifies you of the | |
423 | violation by some reasonable means, this is the first time you have | |
424 | received notice of violation of this License (for any work) from that | |
425 | copyright holder, and you cure the violation prior to 30 days after | |
426 | your receipt of the notice. | |
427 | ||
428 | Termination of your rights under this section does not terminate the | |
429 | licenses of parties who have received copies or rights from you under | |
430 | this License. If your rights have been terminated and not permanently | |
431 | reinstated, you do not qualify to receive new licenses for the same | |
432 | material under section 10. | |
433 | ||
434 | 9. Acceptance Not Required for Having Copies. | |
435 | ||
436 | You are not required to accept this License in order to receive or | |
437 | run a copy of the Program. Ancillary propagation of a covered work | |
438 | occurring solely as a consequence of using peer-to-peer transmission | |
439 | to receive a copy likewise does not require acceptance. However, | |
440 | nothing other than this License grants you permission to propagate or | |
441 | modify any covered work. These actions infringe copyright if you do | |
442 | not accept this License. Therefore, by modifying or propagating a | |
443 | covered work, you indicate your acceptance of this License to do so. | |
444 | ||
445 | 10. Automatic Licensing of Downstream Recipients. | |
446 | ||
447 | Each time you convey a covered work, the recipient automatically | |
448 | receives a license from the original licensors, to run, modify and | |
449 | propagate that work, subject to this License. You are not responsible | |
450 | for enforcing compliance by third parties with this License. | |
451 | ||
452 | An "entity transaction" is a transaction transferring control of an | |
453 | organization, or substantially all assets of one, or subdividing an | |
454 | organization, or merging organizations. If propagation of a covered | |
455 | work results from an entity transaction, each party to that | |
456 | transaction who receives a copy of the work also receives whatever | |
457 | licenses to the work the party's predecessor in interest had or could | |
458 | give under the previous paragraph, plus a right to possession of the | |
459 | Corresponding Source of the work from the predecessor in interest, if | |
460 | the predecessor has it or can get it with reasonable efforts. | |
461 | ||
462 | You may not impose any further restrictions on the exercise of the | |
463 | rights granted or affirmed under this License. For example, you may | |
464 | not impose a license fee, royalty, or other charge for exercise of | |
465 | rights granted under this License, and you may not initiate litigation | |
466 | (including a cross-claim or counterclaim in a lawsuit) alleging that | |
467 | any patent claim is infringed by making, using, selling, offering for | |
468 | sale, or importing the Program or any portion of it. | |
469 | ||
470 | 11. Patents. | |
471 | ||
472 | A "contributor" is a copyright holder who authorizes use under this | |
473 | License of the Program or a work on which the Program is based. The | |
474 | work thus licensed is called the contributor's "contributor version". | |
475 | ||
476 | A contributor's "essential patent claims" are all patent claims | |
477 | owned or controlled by the contributor, whether already acquired or | |
478 | hereafter acquired, that would be infringed by some manner, permitted | |
479 | by this License, of making, using, or selling its contributor version, | |
480 | but do not include claims that would be infringed only as a | |
481 | consequence of further modification of the contributor version. For | |
482 | purposes of this definition, "control" includes the right to grant | |
483 | patent sublicenses in a manner consistent with the requirements of | |
58 | GNU GENERAL PUBLIC LICENSE | |
59 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
60 | ||
61 | 0. This License applies to any program or other work which contains | |
62 | a notice placed by the copyright holder saying it may be distributed | |
63 | under the terms of this General Public License. The "Program", below, | |
64 | refers to any such program or work, and a "work based on the Program" | |
65 | means either the Program or any derivative work under copyright law: | |
66 | that is to say, a work containing the Program or a portion of it, | |
67 | either verbatim or with modifications and/or translated into another | |
68 | language. (Hereinafter, translation is included without limitation in | |
69 | the term "modification".) Each licensee is addressed as "you". | |
70 | ||
71 | Activities other than copying, distribution and modification are not | |
72 | covered by this License; they are outside its scope. The act of | |
73 | running the Program is not restricted, and the output from the Program | |
74 | is covered only if its contents constitute a work based on the | |
75 | Program (independent of having been made by running the Program). | |
76 | Whether that is true depends on what the Program does. | |
77 | ||
78 | 1. You may copy and distribute verbatim copies of the Program's | |
79 | source code as you receive it, in any medium, provided that you | |
80 | conspicuously and appropriately publish on each copy an appropriate | |
81 | copyright notice and disclaimer of warranty; keep intact all the | |
82 | notices that refer to this License and to the absence of any warranty; | |
83 | and give any other recipients of the Program a copy of this License | |
84 | along with the Program. | |
85 | ||
86 | You may charge a fee for the physical act of transferring a copy, and | |
87 | you may at your option offer warranty protection in exchange for a fee. | |
88 | ||
89 | 2. You may modify your copy or copies of the Program or any portion | |
90 | of it, thus forming a work based on the Program, and copy and | |
91 | distribute such modifications or work under the terms of Section 1 | |
92 | above, provided that you also meet all of these conditions: | |
93 | ||
94 | a) You must cause the modified files to carry prominent notices | |
95 | stating that you changed the files and the date of any change. | |
96 | ||
97 | b) You must cause any work that you distribute or publish, that in | |
98 | whole or in part contains or is derived from the Program or any | |
99 | part thereof, to be licensed as a whole at no charge to all third | |
100 | parties under the terms of this License. | |
101 | ||
102 | c) If the modified program normally reads commands interactively | |
103 | when run, you must cause it, when started running for such | |
104 | interactive use in the most ordinary way, to print or display an | |
105 | announcement including an appropriate copyright notice and a | |
106 | notice that there is no warranty (or else, saying that you provide | |
107 | a warranty) and that users may redistribute the program under | |
108 | these conditions, and telling the user how to view a copy of this | |
109 | License. (Exception: if the Program itself is interactive but | |
110 | does not normally print such an announcement, your work based on | |
111 | the Program is not required to print an announcement.) | |
112 | ||
113 | These requirements apply to the modified work as a whole. If | |
114 | identifiable sections of that work are not derived from the Program, | |
115 | and can be reasonably considered independent and separate works in | |
116 | themselves, then this License, and its terms, do not apply to those | |
117 | sections when you distribute them as separate works. But when you | |
118 | distribute the same sections as part of a whole which is a work based | |
119 | on the Program, the distribution of the whole must be on the terms of | |
120 | this License, whose permissions for other licensees extend to the | |
121 | entire whole, and thus to each and every part regardless of who wrote it. | |
122 | ||
123 | Thus, it is not the intent of this section to claim rights or contest | |
124 | your rights to work written entirely by you; rather, the intent is to | |
125 | exercise the right to control the distribution of derivative or | |
126 | collective works based on the Program. | |
127 | ||
128 | In addition, mere aggregation of another work not based on the Program | |
129 | with the Program (or with a work based on the Program) on a volume of | |
130 | a storage or distribution medium does not bring the other work under | |
131 | the scope of this License. | |
132 | ||
133 | 3. You may copy and distribute the Program (or a work based on it, | |
134 | under Section 2) in object code or executable form under the terms of | |
135 | Sections 1 and 2 above provided that you also do one of the following: | |
136 | ||
137 | a) Accompany it with the complete corresponding machine-readable | |
138 | source code, which must be distributed under the terms of Sections | |
139 | 1 and 2 above on a medium customarily used for software interchange; or, | |
140 | ||
141 | b) Accompany it with a written offer, valid for at least three | |
142 | years, to give any third party, for a charge no more than your | |
143 | cost of physically performing source distribution, a complete | |
144 | machine-readable copy of the corresponding source code, to be | |
145 | distributed under the terms of Sections 1 and 2 above on a medium | |
146 | customarily used for software interchange; or, | |
147 | ||
148 | c) Accompany it with the information you received as to the offer | |
149 | to distribute corresponding source code. (This alternative is | |
150 | allowed only for noncommercial distribution and only if you | |
151 | received the program in object code or executable form with such | |
152 | an offer, in accord with Subsection b above.) | |
153 | ||
154 | The source code for a work means the preferred form of the work for | |
155 | making modifications to it. For an executable work, complete source | |
156 | code means all the source code for all modules it contains, plus any | |
157 | associated interface definition files, plus the scripts used to | |
158 | control compilation and installation of the executable. However, as a | |
159 | special exception, the source code distributed need not include | |
160 | anything that is normally distributed (in either source or binary | |
161 | form) with the major components (compiler, kernel, and so on) of the | |
162 | operating system on which the executable runs, unless that component | |
163 | itself accompanies the executable. | |
164 | ||
165 | If distribution of executable or object code is made by offering | |
166 | access to copy from a designated place, then offering equivalent | |
167 | access to copy the source code from the same place counts as | |
168 | distribution of the source code, even though third parties are not | |
169 | compelled to copy the source along with the object code. | |
170 | ||
171 | 4. You may not copy, modify, sublicense, or distribute the Program | |
172 | except as expressly provided under this License. Any attempt | |
173 | otherwise to copy, modify, sublicense or distribute the Program is | |
174 | void, and will automatically terminate your rights under this License. | |
175 | However, parties who have received copies, or rights, from you under | |
176 | this License will not have their licenses terminated so long as such | |
177 | parties remain in full compliance. | |
178 | ||
179 | 5. You are not required to accept this License, since you have not | |
180 | signed it. However, nothing else grants you permission to modify or | |
181 | distribute the Program or its derivative works. These actions are | |
182 | prohibited by law if you do not accept this License. Therefore, by | |
183 | modifying or distributing the Program (or any work based on the | |
184 | Program), you indicate your acceptance of this License to do so, and | |
185 | all its terms and conditions for copying, distributing or modifying | |
186 | the Program or works based on it. | |
187 | ||
188 | 6. Each time you redistribute the Program (or any work based on the | |
189 | Program), the recipient automatically receives a license from the | |
190 | original licensor to copy, distribute or modify the Program subject to | |
191 | these terms and conditions. You may not impose any further | |
192 | restrictions on the recipients' exercise of the rights granted herein. | |
193 | You are not responsible for enforcing compliance by third parties to | |
484 | 194 | this License. |
485 | 195 | |
486 | Each contributor grants you a non-exclusive, worldwide, royalty-free | |
487 | patent license under the contributor's essential patent claims, to | |
488 | make, use, sell, offer for sale, import and otherwise run, modify and | |
489 | propagate the contents of its contributor version. | |
490 | ||
491 | In the following three paragraphs, a "patent license" is any express | |
492 | agreement or commitment, however denominated, not to enforce a patent | |
493 | (such as an express permission to practice a patent or covenant not to | |
494 | sue for patent infringement). To "grant" such a patent license to a | |
495 | party means to make such an agreement or commitment not to enforce a | |
496 | patent against the party. | |
497 | ||
498 | If you convey a covered work, knowingly relying on a patent license, | |
499 | and the Corresponding Source of the work is not available for anyone | |
500 | to copy, free of charge and under the terms of this License, through a | |
501 | publicly available network server or other readily accessible means, | |
502 | then you must either (1) cause the Corresponding Source to be so | |
503 | available, or (2) arrange to deprive yourself of the benefit of the | |
504 | patent license for this particular work, or (3) arrange, in a manner | |
505 | consistent with the requirements of this License, to extend the patent | |
506 | license to downstream recipients. "Knowingly relying" means you have | |
507 | actual knowledge that, but for the patent license, your conveying the | |
508 | covered work in a country, or your recipient's use of the covered work | |
509 | in a country, would infringe one or more identifiable patents in that | |
510 | country that you have reason to believe are valid. | |
511 | ||
512 | If, pursuant to or in connection with a single transaction or | |
513 | arrangement, you convey, or propagate by procuring conveyance of, a | |
514 | covered work, and grant a patent license to some of the parties | |
515 | receiving the covered work authorizing them to use, propagate, modify | |
516 | or convey a specific copy of the covered work, then the patent license | |
517 | you grant is automatically extended to all recipients of the covered | |
518 | work and works based on it. | |
519 | ||
520 | A patent license is "discriminatory" if it does not include within | |
521 | the scope of its coverage, prohibits the exercise of, or is | |
522 | conditioned on the non-exercise of one or more of the rights that are | |
523 | specifically granted under this License. You may not convey a covered | |
524 | work if you are a party to an arrangement with a third party that is | |
525 | in the business of distributing software, under which you make payment | |
526 | to the third party based on the extent of your activity of conveying | |
527 | the work, and under which the third party grants, to any of the | |
528 | parties who would receive the covered work from you, a discriminatory | |
529 | patent license (a) in connection with copies of the covered work | |
530 | conveyed by you (or copies made from those copies), or (b) primarily | |
531 | for and in connection with specific products or compilations that | |
532 | contain the covered work, unless you entered into that arrangement, | |
533 | or that patent license was granted, prior to 28 March 2007. | |
534 | ||
535 | Nothing in this License shall be construed as excluding or limiting | |
536 | any implied license or other defenses to infringement that may | |
537 | otherwise be available to you under applicable patent law. | |
538 | ||
539 | 12. No Surrender of Others' Freedom. | |
540 | ||
541 | If conditions are imposed on you (whether by court order, agreement or | |
196 | 7. If, as a consequence of a court judgment or allegation of patent | |
197 | infringement or for any other reason (not limited to patent issues), | |
198 | conditions are imposed on you (whether by court order, agreement or | |
542 | 199 | otherwise) that contradict the conditions of this License, they do not |
543 | excuse you from the conditions of this License. If you cannot convey a | |
544 | covered work so as to satisfy simultaneously your obligations under this | |
545 | License and any other pertinent obligations, then as a consequence you may | |
546 | not convey it at all. For example, if you agree to terms that obligate you | |
547 | to collect a royalty for further conveying from those to whom you convey | |
548 | the Program, the only way you could satisfy both those terms and this | |
549 | License would be to refrain entirely from conveying the Program. | |
550 | ||
551 | 13. Use with the GNU Affero General Public License. | |
552 | ||
553 | Notwithstanding any other provision of this License, you have | |
554 | permission to link or combine any covered work with a work licensed | |
555 | under version 3 of the GNU Affero General Public License into a single | |
556 | combined work, and to convey the resulting work. The terms of this | |
557 | License will continue to apply to the part which is the covered work, | |
558 | but the special requirements of the GNU Affero General Public License, | |
559 | section 13, concerning interaction through a network will apply to the | |
560 | combination as such. | |
561 | ||
562 | 14. Revised Versions of this License. | |
563 | ||
564 | The Free Software Foundation may publish revised and/or new versions of | |
565 | the GNU General Public License from time to time. Such new versions will | |
200 | excuse you from the conditions of this License. If you cannot | |
201 | distribute so as to satisfy simultaneously your obligations under this | |
202 | License and any other pertinent obligations, then as a consequence you | |
203 | may not distribute the Program at all. For example, if a patent | |
204 | license would not permit royalty-free redistribution of the Program by | |
205 | all those who receive copies directly or indirectly through you, then | |
206 | the only way you could satisfy both it and this License would be to | |
207 | refrain entirely from distribution of the Program. | |
208 | ||
209 | If any portion of this section is held invalid or unenforceable under | |
210 | any particular circumstance, the balance of the section is intended to | |
211 | apply and the section as a whole is intended to apply in other | |
212 | circumstances. | |
213 | ||
214 | It is not the purpose of this section to induce you to infringe any | |
215 | patents or other property right claims or to contest validity of any | |
216 | such claims; this section has the sole purpose of protecting the | |
217 | integrity of the free software distribution system, which is | |
218 | implemented by public license practices. Many people have made | |
219 | generous contributions to the wide range of software distributed | |
220 | through that system in reliance on consistent application of that | |
221 | system; it is up to the author/donor to decide if he or she is willing | |
222 | to distribute software through any other system and a licensee cannot | |
223 | impose that choice. | |
224 | ||
225 | This section is intended to make thoroughly clear what is believed to | |
226 | be a consequence of the rest of this License. | |
227 | ||
228 | 8. If the distribution and/or use of the Program is restricted in | |
229 | certain countries either by patents or by copyrighted interfaces, the | |
230 | original copyright holder who places the Program under this License | |
231 | may add an explicit geographical distribution limitation excluding | |
232 | those countries, so that distribution is permitted only in or among | |
233 | countries not thus excluded. In such case, this License incorporates | |
234 | the limitation as if written in the body of this License. | |
235 | ||
236 | 9. The Free Software Foundation may publish revised and/or new versions | |
237 | of the General Public License from time to time. Such new versions will | |
566 | 238 | be similar in spirit to the present version, but may differ in detail to |
567 | 239 | address new problems or concerns. |
568 | 240 | |
569 | Each version is given a distinguishing version number. If the | |
570 | Program specifies that a certain numbered version of the GNU General | |
571 | Public License "or any later version" applies to it, you have the | |
572 | option of following the terms and conditions either of that numbered | |
573 | version or of any later version published by the Free Software | |
574 | Foundation. If the Program does not specify a version number of the | |
575 | GNU General Public License, you may choose any version ever published | |
576 | by the Free Software Foundation. | |
577 | ||
578 | If the Program specifies that a proxy can decide which future | |
579 | versions of the GNU General Public License can be used, that proxy's | |
580 | public statement of acceptance of a version permanently authorizes you | |
581 | to choose that version for the Program. | |
582 | ||
583 | Later license versions may give you additional or different | |
584 | permissions. However, no additional obligations are imposed on any | |
585 | author or copyright holder as a result of your choosing to follow a | |
586 | later version. | |
587 | ||
588 | 15. Disclaimer of Warranty. | |
589 | ||
590 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY | |
591 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT | |
592 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY | |
593 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, | |
594 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
595 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM | |
596 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF | |
597 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. | |
598 | ||
599 | 16. Limitation of Liability. | |
600 | ||
601 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | |
602 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS | |
603 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY | |
604 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE | |
605 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF | |
606 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD | |
607 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), | |
608 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF | |
609 | SUCH DAMAGES. | |
610 | ||
611 | 17. Interpretation of Sections 15 and 16. | |
612 | ||
613 | If the disclaimer of warranty and limitation of liability provided | |
614 | above cannot be given local legal effect according to their terms, | |
615 | reviewing courts shall apply local law that most closely approximates | |
616 | an absolute waiver of all civil liability in connection with the | |
617 | Program, unless a warranty or assumption of liability accompanies a | |
618 | copy of the Program in return for a fee. | |
619 | ||
620 | END OF TERMS AND CONDITIONS | |
621 | ||
622 | How to Apply These Terms to Your New Programs | |
241 | Each version is given a distinguishing version number. If the Program | |
242 | specifies a version number of this License which applies to it and "any | |
243 | later version", you have the option of following the terms and conditions | |
244 | either of that version or of any later version published by the Free | |
245 | Software Foundation. If the Program does not specify a version number of | |
246 | this License, you may choose any version ever published by the Free Software | |
247 | Foundation. | |
248 | ||
249 | 10. If you wish to incorporate parts of the Program into other free | |
250 | programs whose distribution conditions are different, write to the author | |
251 | to ask for permission. For software which is copyrighted by the Free | |
252 | Software Foundation, write to the Free Software Foundation; we sometimes | |
253 | make exceptions for this. Our decision will be guided by the two goals | |
254 | of preserving the free status of all derivatives of our free software and | |
255 | of promoting the sharing and reuse of software generally. | |
256 | ||
257 | NO WARRANTY | |
258 | ||
259 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | |
260 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | |
261 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | |
262 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | |
263 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
264 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | |
265 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | |
266 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | |
267 | REPAIR OR CORRECTION. | |
268 | ||
269 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | |
270 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | |
271 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, | |
272 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING | |
273 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | |
274 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | |
275 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | |
276 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | |
277 | POSSIBILITY OF SUCH DAMAGES. | |
278 | ||
279 | END OF TERMS AND CONDITIONS | |
280 | ||
281 | How to Apply These Terms to Your New Programs | |
623 | 282 | |
624 | 283 | If you develop a new program, and you want it to be of the greatest |
625 | 284 | possible use to the public, the best way to achieve this is to make it |
627 | 286 | |
628 | 287 | To do so, attach the following notices to the program. It is safest |
629 | 288 | to attach them to the start of each source file to most effectively |
630 | state the exclusion of warranty; and each file should have at least | |
289 | convey the exclusion of warranty; and each file should have at least | |
631 | 290 | the "copyright" line and a pointer to where the full notice is found. |
632 | 291 | |
633 | 292 | <one line to give the program's name and a brief idea of what it does.> |
634 | 293 | Copyright (C) <year> <name of author> |
635 | 294 | |
636 | This program is free software: you can redistribute it and/or modify | |
295 | This program is free software; you can redistribute it and/or modify | |
637 | 296 | it under the terms of the GNU General Public License as published by |
638 | the Free Software Foundation, either version 3 of the License, or | |
297 | the Free Software Foundation; either version 2 of the License, or | |
639 | 298 | (at your option) any later version. |
640 | 299 | |
641 | 300 | This program is distributed in the hope that it will be useful, |
644 | 303 | GNU General Public License for more details. |
645 | 304 | |
646 | 305 | You should have received a copy of the GNU General Public License |
647 | along with this program. If not, see <http://www.gnu.org/licenses/>. | |
306 | along with this program; if not, write to the Free Software | |
307 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
308 | ||
648 | 309 | |
649 | 310 | Also add information on how to contact you by electronic and paper mail. |
650 | 311 | |
651 | If the program does terminal interaction, make it output a short | |
652 | notice like this when it starts in an interactive mode: | |
653 | ||
654 | <program> Copyright (C) <year> <name of author> | |
655 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | |
312 | If the program is interactive, make it output a short notice like this | |
313 | when it starts in an interactive mode: | |
314 | ||
315 | Gnomovision version 69, Copyright (C) year name of author | |
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | |
656 | 317 | This is free software, and you are welcome to redistribute it |
657 | 318 | under certain conditions; type `show c' for details. |
658 | 319 | |
659 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate |
660 | parts of the General Public License. Of course, your program's commands | |
661 | might be different; for a GUI interface, you would use an "about box". | |
662 | ||
663 | You should also get your employer (if you work as a programmer) or school, | |
664 | if any, to sign a "copyright disclaimer" for the program, if necessary. | |
665 | For more information on this, and how to apply and follow the GNU GPL, see | |
666 | <http://www.gnu.org/licenses/>. | |
667 | ||
668 | The GNU General Public License does not permit incorporating your program | |
669 | into proprietary programs. If your program is a subroutine library, you | |
670 | may consider it more useful to permit linking proprietary applications with | |
671 | the library. If this is what you want to do, use the GNU Lesser General | |
672 | Public License instead of this License. But first, please read | |
673 | <http://www.gnu.org/philosophy/why-not-lgpl.html>. | |
321 | parts of the General Public License. Of course, the commands you use may | |
322 | be called something other than `show w' and `show c'; they could even be | |
323 | mouse-clicks or menu items--whatever suits your program. | |
324 | ||
325 | You should also get your employer (if you work as a programmer) or your | |
326 | school, if any, to sign a "copyright disclaimer" for the program, if | |
327 | necessary. Here is a sample; alter the names: | |
328 | ||
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program | |
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. | |
331 | ||
332 | <signature of Ty Coon>, 1 April 1989 | |
333 | Ty Coon, President of Vice | |
334 | ||
335 | This General Public License does not permit incorporating your program into | |
336 | proprietary programs. If your program is a subroutine library, you may | |
337 | consider it more useful to permit linking proprietary applications with the | |
338 | library. If this is what you want to do, use the GNU Library General | |
339 | Public License instead of this License. |
0 | fcitx-configtool install instructions | |
1 | ================================================= | |
2 | ||
3 | To compile and install, go in the source directory and type: | |
4 | mkdir build; cd build | |
5 | cmake .. | |
6 | (If you want to install in a different path, use instead: | |
7 | cmake .. -DCMAKE_INSTALL_PREFIX=/install/path) | |
8 | make | |
9 | ||
10 | To install, become root if required: | |
11 | ||
12 | make install | |
13 | ||
14 | Once installed, you can restart fcitx and it will be enabled by default. |
0 | if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") | |
1 | message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") | |
2 | endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") | |
3 | ||
4 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) | |
5 | string(REGEX REPLACE "\n" ";" files "${files}") | |
6 | foreach (file ${files}) | |
7 | message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") | |
8 | if (EXISTS "$ENV{DESTDIR}${file}" OR IS_SYMLINK "$ENV{DESTDIR}${file}") | |
9 | execute_process( | |
10 | COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}" | |
11 | OUTPUT_VARIABLE rm_out | |
12 | RESULT_VARIABLE rm_retval | |
13 | ) | |
14 | if(NOT ${rm_retval} EQUAL 0) | |
15 | message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") | |
16 | endif (NOT ${rm_retval} EQUAL 0) | |
17 | else (EXISTS "$ENV{DESTDIR}${file}" OR IS_SYMLINK "$ENV{DESTDIR}${file}") | |
18 | message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") | |
19 | endif (EXISTS "$ENV{DESTDIR}${file}" OR IS_SYMLINK "$ENV{DESTDIR}${file}") | |
20 | endforeach(file)⏎ |
0 | #define VERSION_STRING_FULL "@VERSION_STRING_FULL@" | |
1 | #define DATADIR "@datadir@" | |
2 | #define LOCALEDIR "@localedir@" | |
3 | #define EXEC_PREFIX "@exec_prefix@" | |
4 | #define PACKAGE "@FCITX4_PACKAGE_NAME@" | |
5 | #cmakedefine HAVE_UNIQUE⏎ |
0 | include(FindPkgConfig) | |
0 | include_directories ( | |
1 | ${GTK2_INCLUDE_DIRS} | |
2 | ${FCITX4_FCITX_INCLUDE_DIRS} | |
3 | ${FCITX4_FCITX_UTILS_INCLUDE_DIRS} | |
4 | ${FCITX4_FCITX_CONFIG_INCLUDE_DIRS} | |
5 | ) | |
1 | 6 | |
2 | find_package (GTK2 REQUIRED gtk) | |
3 | ||
4 | message (STATUS "GTK2 includes:" ${GTK2_INCLUDE_DIRS}) | |
5 | message (STATUS "GTK2 libraries:" ${GTK2_LIBRARIES}) | |
6 | ||
7 | PKG_CHECK_MODULES(FCITX_CONFIG REQUIRED "fcitx-config >= 1.0" ) | |
8 | PKG_CHECK_MODULES(FCITX REQUIRED "fcitx" ) | |
9 | PKG_CHECK_MODULES(UNIQUE REQUIRED "unique-1.0" ) | |
10 | ||
11 | include_directories (${GTK2_INCLUDE_DIRS}) | |
12 | include_directories (${FCITX_CONFIG_INCLUDE_DIRS}) | |
13 | include_directories (${FCITX_INCLUDE_DIRS}) | |
14 | include_directories (${UNIQUE_INCLUDE_DIRS}) | |
7 | link_directories ( | |
8 | ${GTK2_LIBRARY_DIRS} | |
9 | ${FCITX4_FCITX_LIBRARY_DIRS} | |
10 | ${FCITX4_FCITX_UTILS_LIBRARY_DIRS} | |
11 | ${FCITX4_FCITX_CONFIG_LIBRARY_DIRS} | |
12 | ) | |
13 | if (HAVE_UNIQUE) | |
14 | include_directories (${UNIQUE_INCLUDE_DIRS}) | |
15 | link_directories (${UNIQUE_LIBRARY_DIRS}) | |
16 | endif (HAVE_UNIQUE) | |
15 | 17 | |
16 | 18 | set( fcitx_config_gtk_sources |
17 | addon_stuff.c | |
19 | sub_config_parser.c | |
20 | sub_config_widget.c | |
18 | 21 | config_widget.c |
19 | 22 | configdesc.c |
20 | 23 | keygrab.c |
21 | 24 | main.c |
22 | 25 | main_window.c |
23 | menu.c | |
24 | skin_stuff.c | |
25 | table_stuff.c | |
26 | ) | |
27 | ||
28 | set(exec_prefix "${CMAKE_INSTALL_PREFIX}/bin") | |
29 | set(datadir "${CMAKE_INSTALL_PREFIX}/share") | |
30 | set(localedir "${datadir}/locale") | |
31 | ||
32 | add_definitions(-DDATADIR="${datadir}") | |
33 | add_definitions(-DLOCALEDIR="${localedir}") | |
34 | add_definitions(-DBINDIR="${exec_prefix}") | |
26 | ) | |
35 | 27 | |
36 | 28 | add_executable( fcitx-config-gtk ${fcitx_config_gtk_sources} ) |
37 | 29 | |
38 | 30 | install(TARGETS fcitx-config-gtk RUNTIME DESTINATION bin) |
39 | 31 | |
40 | target_link_libraries (fcitx-config-gtk ${GTK2_LIBRARIES}) | |
41 | target_link_libraries (fcitx-config-gtk ${FCITX_CONFIG_LIBRARIES}) | |
42 | target_link_libraries (fcitx-config-gtk ${FCITX_LIBRARIES}) | |
43 | target_link_libraries (fcitx-config-gtk ${UNIQUE_LIBRARIES}) | |
32 | target_link_libraries (fcitx-config-gtk | |
33 | ${GTK2_LIBRARIES} | |
34 | ${FCITX4_FCITX_UTILS_LIBRARIES} | |
35 | ${FCITX4_FCITX_CONFIG_LIBRARIES} | |
36 | ${FCITX4_FCITX_LIBRARIES} | |
37 | ) | |
38 | ||
39 | if (HAVE_UNIQUE) | |
40 | target_link_libraries (fcitx-config-gtk ${UNIQUE_LIBRARIES}) | |
41 | endif (HAVE_UNIQUE) |
0 | #include <limits.h> | |
1 | #include <dirent.h> | |
2 | #include <sys/stat.h> | |
3 | #include <stdlib.h> | |
4 | #include <stdio.h> | |
5 | #include <fcitx-config/xdg.h> | |
6 | ||
7 | #include "utarray.h" | |
8 | #include "uthash.h" | |
9 | #include "addon_stuff.h" | |
10 | ||
11 | typedef struct StringHashSet { | |
12 | char *name; | |
13 | UT_hash_handle hh; | |
14 | } StringHashSet; | |
15 | ||
16 | static UT_array* addonBuf = NULL; | |
17 | ||
18 | /* | |
19 | * 读取码表输入法的名称和文件路径 | |
20 | */ | |
21 | UT_array* LoadAddonInfo (void) | |
22 | { | |
23 | if (!addonBuf) | |
24 | { | |
25 | addonBuf = malloc(sizeof(UT_array)); | |
26 | utarray_init(addonBuf, &ut_str_icd); | |
27 | } | |
28 | else | |
29 | { | |
30 | utarray_clear(addonBuf); | |
31 | } | |
32 | ||
33 | char **addonPath; | |
34 | size_t len; | |
35 | char pathBuf[PATH_MAX]; | |
36 | int i = 0; | |
37 | DIR *dir; | |
38 | struct dirent *drt; | |
39 | struct stat fileStat; | |
40 | ||
41 | StringHashSet* sset = NULL; | |
42 | ||
43 | addonPath = GetXDGPath(&len, "XDG_CONFIG_HOME", ".config", "fcitx/addon" , DATADIR, "fcitx/data/addon" ); | |
44 | ||
45 | for(i = 0; i< len; i++) | |
46 | { | |
47 | snprintf(pathBuf, sizeof(pathBuf), "%s", addonPath[i]); | |
48 | pathBuf[sizeof(pathBuf) - 1] = '\0'; | |
49 | ||
50 | dir = opendir(pathBuf); | |
51 | if (dir == NULL) | |
52 | continue; | |
53 | ||
54 | /* collect all *.conf files */ | |
55 | while((drt = readdir(dir)) != NULL) | |
56 | { | |
57 | size_t nameLen = strlen(drt->d_name); | |
58 | if (nameLen <= strlen(".conf") ) | |
59 | continue; | |
60 | memset(pathBuf,0,sizeof(pathBuf)); | |
61 | ||
62 | if (strcmp(drt->d_name + nameLen -strlen(".conf"), ".conf") != 0) | |
63 | continue; | |
64 | snprintf(pathBuf, sizeof(pathBuf), "%s/%s", addonPath[i], drt->d_name ); | |
65 | ||
66 | if (stat(pathBuf, &fileStat) == -1) | |
67 | continue; | |
68 | ||
69 | if (fileStat.st_mode & S_IFREG) | |
70 | { | |
71 | StringHashSet *string; | |
72 | HASH_FIND_STR(sset, drt->d_name, string); | |
73 | if (!string) | |
74 | { | |
75 | char *bStr = strdup(drt->d_name); | |
76 | string = malloc(sizeof(StringHashSet)); | |
77 | memset(string, 0, sizeof(StringHashSet)); | |
78 | string->name = bStr; | |
79 | HASH_ADD_KEYPTR(hh, sset, string->name, strlen(string->name), string); | |
80 | } | |
81 | } | |
82 | } | |
83 | ||
84 | closedir(dir); | |
85 | } | |
86 | ||
87 | StringHashSet* string; | |
88 | for (string = sset; | |
89 | string != NULL; | |
90 | string = (StringHashSet*)string->hh.next) | |
91 | { | |
92 | char *temp = string->name; | |
93 | utarray_push_back(addonBuf, &temp); | |
94 | } | |
95 | ||
96 | FreeXDGPath(addonPath); | |
97 | ||
98 | StringHashSet *curStr; | |
99 | while(sset) | |
100 | { | |
101 | curStr = sset; | |
102 | HASH_DEL(sset, curStr); | |
103 | free(curStr->name); | |
104 | free(curStr); | |
105 | } | |
106 | ||
107 | return addonBuf; | |
108 | } | |
109 |
0 | #include "uthash.h" | |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
19 | #include "config.h" | |
20 | ||
1 | 21 | #include <gtk/gtk.h> |
2 | #include <fcitx-config/fcitx-config.h> | |
3 | 22 | #include <libintl.h> |
4 | 23 | #include <stdlib.h> |
5 | 24 | #include <libgen.h> |
6 | 25 | #include <sys/stat.h> |
7 | 26 | #include <unistd.h> |
8 | 27 | |
28 | #include <fcitx-config/fcitx-config.h> | |
29 | #include <fcitx-utils/uthash.h> | |
30 | #include <fcitx-config/hotkey.h> | |
31 | #include <fcitx-config/xdg.h> | |
32 | ||
9 | 33 | #include "config_widget.h" |
10 | 34 | #include "keygrab.h" |
35 | #include "sub_config_widget.h" | |
11 | 36 | |
12 | 37 | #define _(s) gettext(s) |
13 | #define D_(x) dgettext (page->domain, x) | |
14 | ||
15 | static void make_path (const char *path); | |
16 | ||
17 | void | |
18 | make_path (const char *path) | |
19 | { | |
20 | char opath[PATH_MAX]; | |
21 | char *p; | |
22 | size_t len; | |
23 | ||
24 | strncpy(opath, path, sizeof(opath)); | |
25 | opath[PATH_MAX - 1] = '\0'; | |
26 | len = strlen(opath); | |
27 | while(opath[len - 1] == '/') | |
28 | { | |
29 | opath[len - 1] = '\0'; | |
30 | len --; | |
31 | } | |
32 | for(p = opath; *p; p++) | |
33 | if(*p == '/') { | |
34 | *p = '\0'; | |
35 | if(access(opath, F_OK)) | |
36 | mkdir(opath, S_IRWXU); | |
37 | *p = '/'; | |
38 | } | |
39 | if(access(opath, F_OK)) /* if path is not terminated with / */ | |
40 | mkdir(opath, S_IRWXU); | |
41 | } | |
42 | ||
43 | static void sync_filter(ConfigGroup *group, ConfigOption *option, void *value, ConfigSync sync, void *arg); | |
44 | ||
45 | static void set_none_font_clicked(GtkWidget *button, gpointer arg) | |
46 | { | |
47 | gtk_font_button_set_font_name(GTK_FONT_BUTTON(arg), ""); | |
48 | } | |
49 | ||
50 | static void reset_config_clicked(GtkWidget* button, gpointer arg) | |
51 | { | |
52 | ConfigPage *page = (ConfigPage*) arg; | |
53 | ConfigBindSync(&page->config); | |
54 | } | |
55 | ||
56 | static void save_config_clicked(GtkWidget* button, gpointer arg) | |
57 | { | |
58 | ConfigPage *page = (ConfigPage*) arg; | |
59 | ||
60 | FILE *fp; | |
61 | ||
62 | fp = fopen(page->filename, "w"); | |
63 | fprintf(stderr, "%s\n", page->filename); | |
64 | if (!fp) | |
65 | { | |
66 | char *sbak = strdup(page->filename); | |
67 | char *dir = dirname(sbak); | |
68 | make_path(dir); | |
69 | fp = fopen (page->filename, "w"); | |
70 | free(sbak); | |
71 | } | |
72 | if (fp) | |
73 | { | |
74 | CHANGE_DOMAIN_BEGIN(page->domain); | |
75 | SaveConfigFileFp(fp, page->config.configFile, page->cfdesc); | |
76 | CHANGE_DOMAIN_END(); | |
77 | fclose(fp); | |
78 | fp = fopen(page->filename, "rt"); | |
79 | page->config.configFile = ParseIniFp(fp, page->config.configFile); | |
80 | fclose(fp); | |
81 | } | |
82 | } | |
83 | ||
84 | GtkWidget* config_widget_new(ConfigFileDesc *cfdesc, ConfigFile *cfile, ConfigPage *page, gboolean readonly) | |
85 | { | |
86 | GtkWidget *cvbox = gtk_vbox_new(FALSE, 0); | |
87 | GtkWidget *chbox = NULL; | |
38 | #define D_(d, x) dgettext (d, x) | |
39 | ||
40 | G_DEFINE_TYPE (FcitxConfigWidget, fcitx_config_widget, GTK_TYPE_VBOX) | |
41 | ||
42 | typedef struct { | |
43 | int i; | |
44 | FcitxConfigWidget* widget; | |
45 | GtkWidget* table; | |
46 | } HashForeachContext; | |
47 | ||
48 | enum | |
49 | { | |
50 | PROP_0, | |
51 | ||
52 | PROP_CONFIG_DESC, | |
53 | PROP_PREFIX, | |
54 | PROP_NAME, | |
55 | PROP_SUBCONFIG | |
56 | }; | |
57 | ||
58 | static void | |
59 | fcitx_config_widget_set_property (GObject *gobject, | |
60 | guint prop_id, | |
61 | const GValue *value, | |
62 | GParamSpec *pspec); | |
63 | ||
64 | ||
65 | static void sync_filter(GenericConfig* gconfig, ConfigGroup *group, ConfigOption *option, void *value, ConfigSync sync, void *arg); | |
66 | ||
67 | static void set_none_font_clicked(GtkWidget *button, gpointer arg); | |
68 | ||
69 | static void hash_foreach_cb (gpointer key, | |
70 | gpointer value, | |
71 | gpointer user_data); | |
72 | ||
73 | static void | |
74 | fcitx_config_widget_setup_ui (FcitxConfigWidget *self); | |
75 | ||
76 | static void | |
77 | fcitx_config_widget_finalize (GObject *object); | |
78 | ||
79 | static void | |
80 | fcitx_config_widget_class_init (FcitxConfigWidgetClass *klass) | |
81 | { | |
82 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass); | |
83 | gobject_class->set_property = fcitx_config_widget_set_property; | |
84 | gobject_class->finalize = fcitx_config_widget_finalize; | |
85 | g_object_class_install_property (gobject_class, | |
86 | PROP_CONFIG_DESC, | |
87 | g_param_spec_pointer ("cfdesc", | |
88 | "Configuration Description", | |
89 | "Configuration Description for this widget", | |
90 | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); | |
91 | ||
92 | g_object_class_install_property (gobject_class, | |
93 | PROP_PREFIX, | |
94 | g_param_spec_string ("prefix", | |
95 | "Prefix of path", | |
96 | "Prefix of configuration path", | |
97 | NULL, | |
98 | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); | |
99 | ||
100 | g_object_class_install_property (gobject_class, | |
101 | PROP_NAME, | |
102 | g_param_spec_string ("name", | |
103 | "File name", | |
104 | "File name of configuration file", | |
105 | NULL, | |
106 | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); | |
107 | ||
108 | g_object_class_install_property (gobject_class, | |
109 | PROP_SUBCONFIG, | |
110 | g_param_spec_string ("subconfig", | |
111 | "subconfig", | |
112 | "subconfig", | |
113 | NULL, | |
114 | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); | |
115 | } | |
116 | ||
117 | static void | |
118 | fcitx_config_widget_init (FcitxConfigWidget *self) | |
119 | { | |
120 | } | |
121 | ||
122 | static void | |
123 | fcitx_config_widget_setup_ui (FcitxConfigWidget *self) | |
124 | { | |
125 | ConfigFileDesc* cfdesc = self->cfdesc; | |
126 | GtkWidget *cvbox = GTK_WIDGET(self); | |
88 | 127 | GtkWidget *configNotebook = gtk_notebook_new(); |
89 | GtkWidget *saveButton = NULL; | |
90 | GtkWidget *resetButton = NULL; | |
91 | ||
92 | 128 | gtk_box_pack_start(GTK_BOX(cvbox), configNotebook, TRUE, TRUE, 0); |
93 | saveButton = gtk_button_new_with_label(_("Save")); | |
94 | resetButton = gtk_button_new_with_label(_("Reset")); | |
95 | chbox = gtk_hbox_new(FALSE, 0); | |
96 | gtk_box_pack_start(GTK_BOX(chbox), saveButton, FALSE, FALSE, 0); | |
97 | gtk_box_pack_start(GTK_BOX(chbox), resetButton, FALSE, FALSE, 0); | |
98 | gtk_box_pack_start(GTK_BOX(cvbox), chbox, FALSE, FALSE, 0); | |
99 | ||
100 | gtk_signal_connect(GTK_OBJECT(resetButton), "clicked", GTK_SIGNAL_FUNC(reset_config_clicked), page); | |
101 | gtk_signal_connect(GTK_OBJECT(saveButton), "clicked", GTK_SIGNAL_FUNC(save_config_clicked), page); | |
102 | ||
103 | ConfigGroupDesc *cgdesc = NULL; | |
104 | ConfigOptionDesc *codesc = NULL; | |
105 | for(cgdesc = cfdesc->groupsDesc; | |
106 | cgdesc != NULL; | |
107 | cgdesc = (ConfigGroupDesc*)cgdesc->hh.next) | |
108 | { | |
109 | codesc = cgdesc->optionsDesc; | |
110 | if (codesc == NULL) | |
111 | continue; | |
112 | ||
113 | GtkWidget *table = gtk_table_new(2, HASH_COUNT(codesc), FALSE); | |
114 | GtkWidget *plabel = gtk_label_new(D_(cgdesc->groupName)); | |
115 | GtkWidget *scrollwnd = gtk_scrolled_window_new(NULL, NULL); | |
116 | GtkWidget *viewport = gtk_viewport_new(NULL, NULL); | |
117 | ||
118 | gtk_container_set_border_width(GTK_CONTAINER(table), 4); | |
119 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwnd), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
120 | gtk_container_add(GTK_CONTAINER(scrollwnd), viewport); | |
121 | gtk_container_add(GTK_CONTAINER(viewport), table); | |
122 | gtk_notebook_append_page(GTK_NOTEBOOK(configNotebook), | |
123 | scrollwnd, | |
124 | plabel); | |
125 | ||
126 | int i = 0; | |
127 | for ( ; codesc != NULL; | |
128 | codesc = (ConfigOptionDesc*)codesc->hh.next, i++) | |
129 | { | |
130 | const char *s; | |
131 | if (codesc->desc && strlen(codesc->desc) != 0) | |
132 | s = D_(codesc->desc); | |
133 | else | |
134 | s = D_(codesc->optionName); | |
135 | GtkWidget* label = gtk_label_new(s); | |
136 | g_object_set(label, "xalign", 0.0f, NULL); | |
137 | ||
138 | GtkWidget *inputWidget = NULL; | |
139 | void *argument = NULL; | |
140 | ||
141 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, i, i+1, GTK_FILL, GTK_SHRINK, 5, 5); | |
142 | ||
143 | switch(codesc->type) | |
129 | if (cfdesc) | |
130 | { | |
131 | bindtextdomain ( cfdesc->domain, LOCALEDIR ); | |
132 | bind_textdomain_codeset ( cfdesc->domain, "UTF-8" ); | |
133 | ||
134 | FILE *fp; | |
135 | fp = GetXDGFileWithPrefix ( self->prefix, self->name, "rt", NULL ); | |
136 | self->gconfig.configFile = ParseConfigFileFp ( fp, cfdesc ); | |
137 | ||
138 | ConfigGroupDesc *cgdesc = NULL; | |
139 | ConfigOptionDesc *codesc = NULL; | |
140 | for (cgdesc = cfdesc->groupsDesc; | |
141 | cgdesc != NULL; | |
142 | cgdesc = (ConfigGroupDesc*)cgdesc->hh.next) | |
143 | { | |
144 | codesc = cgdesc->optionsDesc; | |
145 | if (codesc == NULL) | |
146 | continue; | |
147 | ||
148 | GtkWidget *table = gtk_table_new(2, HASH_COUNT(codesc), FALSE); | |
149 | GtkWidget *plabel = gtk_label_new(D_(cfdesc->domain, cgdesc->groupName)); | |
150 | GtkWidget *scrollwnd = gtk_scrolled_window_new(NULL, NULL); | |
151 | GtkWidget *viewport = gtk_viewport_new(NULL, NULL); | |
152 | ||
153 | gtk_container_set_border_width(GTK_CONTAINER(table), 4); | |
154 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwnd), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
155 | gtk_container_add(GTK_CONTAINER(scrollwnd), viewport); | |
156 | gtk_container_add(GTK_CONTAINER(viewport), table); | |
157 | gtk_notebook_append_page(GTK_NOTEBOOK(configNotebook), | |
158 | scrollwnd, | |
159 | plabel); | |
160 | ||
161 | int i = 0; | |
162 | for ( ; codesc != NULL; | |
163 | codesc = (ConfigOptionDesc*)codesc->hh.next, i++) | |
144 | 164 | { |
165 | const char *s; | |
166 | if (codesc->desc && strlen(codesc->desc) != 0) | |
167 | s = D_(cfdesc->domain, codesc->desc); | |
168 | else | |
169 | s = D_(cfdesc->domain, codesc->optionName); | |
170 | ||
171 | GtkWidget *inputWidget = NULL; | |
172 | void *argument = NULL; | |
173 | ||
174 | switch (codesc->type) | |
175 | { | |
145 | 176 | case T_Integer: |
146 | 177 | inputWidget = gtk_spin_button_new_with_range(-1.0, 10000.0, 1.0); |
147 | 178 | argument = inputWidget; |
155 | 186 | argument = inputWidget; |
156 | 187 | break; |
157 | 188 | case T_Font: |
189 | { | |
190 | inputWidget = gtk_hbox_new(FALSE, 0); | |
191 | argument = gtk_font_button_new(); | |
192 | GtkWidget *button = gtk_button_new_with_label(_("Clear font setting")); | |
193 | gtk_box_pack_start(GTK_BOX(inputWidget), argument, TRUE, TRUE, 0); | |
194 | gtk_box_pack_start(GTK_BOX(inputWidget), button, FALSE, FALSE, 0); | |
195 | gtk_font_button_set_use_size(GTK_FONT_BUTTON(argument), FALSE); | |
196 | gtk_font_button_set_show_size(GTK_FONT_BUTTON(argument), FALSE); | |
197 | gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_none_font_clicked), argument); | |
198 | } | |
199 | break; | |
200 | case T_Enum: | |
201 | { | |
202 | int i; | |
203 | ConfigEnum *e = &codesc->configEnum; | |
204 | inputWidget = gtk_combo_box_new_text(); | |
205 | for (i = 0; i < e->enumCount; i ++) | |
158 | 206 | { |
159 | inputWidget = gtk_hbox_new(FALSE, 0); | |
160 | argument = gtk_font_button_new(); | |
161 | GtkWidget *button = gtk_button_new_with_label(_("Clear font setting")); | |
162 | gtk_box_pack_start(GTK_BOX(inputWidget), argument, TRUE, TRUE, 0); | |
163 | gtk_box_pack_start(GTK_BOX(inputWidget), button, FALSE, FALSE, 0); | |
164 | gtk_font_button_set_use_size(GTK_FONT_BUTTON(argument), FALSE); | |
165 | gtk_font_button_set_show_size(GTK_FONT_BUTTON(argument), FALSE); | |
166 | gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_none_font_clicked), argument); | |
207 | gtk_combo_box_append_text(GTK_COMBO_BOX(inputWidget), D_(cfdesc->domain, e->enumDesc[i])); | |
167 | 208 | } |
168 | break; | |
169 | case T_Enum: | |
170 | { | |
171 | int i; | |
172 | ConfigEnum *e = &codesc->configEnum; | |
173 | inputWidget = gtk_combo_box_new_text(); | |
174 | for (i = 0; i < e->enumCount; i ++) | |
175 | { | |
176 | gtk_combo_box_append_text(GTK_COMBO_BOX(inputWidget), D_(e->enumDesc[i])); | |
177 | } | |
178 | argument = inputWidget; | |
179 | } | |
180 | break; | |
209 | argument = inputWidget; | |
210 | } | |
211 | break; | |
181 | 212 | case T_Hotkey: |
182 | { | |
183 | GtkWidget *button[2]; | |
184 | button[0] = keygrab_button_new(); | |
185 | button[1] = keygrab_button_new(); | |
186 | inputWidget = gtk_hbox_new(FALSE, 0); | |
187 | gtk_box_pack_start(GTK_BOX(inputWidget), button[0], FALSE, TRUE, 0); | |
188 | gtk_box_pack_start(GTK_BOX(inputWidget), button[1], FALSE, TRUE, 0); | |
189 | argument = g_array_new(FALSE, FALSE, sizeof(void*)); | |
190 | g_array_append_val(argument, button[0]); | |
191 | g_array_append_val(argument, button[1]); | |
192 | } | |
193 | break; | |
213 | { | |
214 | GtkWidget *button[2]; | |
215 | button[0] = keygrab_button_new(); | |
216 | button[1] = keygrab_button_new(); | |
217 | inputWidget = gtk_hbox_new(FALSE, 0); | |
218 | gtk_box_pack_start(GTK_BOX(inputWidget), button[0], FALSE, TRUE, 0); | |
219 | gtk_box_pack_start(GTK_BOX(inputWidget), button[1], FALSE, TRUE, 0); | |
220 | argument = g_array_new(FALSE, FALSE, sizeof(void*)); | |
221 | g_array_append_val(argument, button[0]); | |
222 | g_array_append_val(argument, button[1]); | |
223 | } | |
224 | break; | |
194 | 225 | case T_File: |
195 | 226 | case T_Char: |
196 | case T_Image: | |
197 | 227 | case T_String: |
198 | 228 | inputWidget = gtk_entry_new(); |
199 | 229 | argument = inputWidget; |
200 | 230 | break; |
231 | default: | |
232 | break; | |
233 | } | |
234 | ||
235 | if (inputWidget) | |
236 | { | |
237 | GtkWidget* label = gtk_label_new(s); | |
238 | g_object_set(label, "xalign", 0.0f, NULL); | |
239 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, i, i+1, GTK_FILL, GTK_SHRINK, 5, 5); | |
240 | gtk_table_attach(GTK_TABLE(table), inputWidget, 1, 2, i, i+1, GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 4); | |
241 | ConfigBindValue(self->gconfig.configFile, cgdesc->groupName, codesc->optionName, NULL, sync_filter, argument); | |
242 | } | |
201 | 243 | } |
202 | gtk_table_attach(GTK_TABLE(table), inputWidget, 1, 2, i, i+1, GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 4); | |
203 | if (readonly && strcmp(codesc->optionName, "Enabled") != 0) | |
204 | { | |
205 | gtk_widget_set_sensitive(GTK_WIDGET(argument), FALSE); | |
206 | } | |
207 | ConfigBindValue(cfile, cgdesc->groupName, codesc->optionName, NULL, sync_filter, argument); | |
208 | } | |
209 | } | |
244 | } | |
245 | ||
246 | ConfigBindSync(&self->gconfig); | |
247 | } | |
248 | ||
249 | if (self->parser) | |
250 | { | |
251 | GHashTable* subconfigs = self->parser->subconfigs; | |
252 | if (g_hash_table_size(subconfigs) != 0) | |
253 | { | |
254 | GtkWidget *table = gtk_table_new(2, g_hash_table_size(subconfigs), FALSE); | |
255 | GtkWidget *plabel = gtk_label_new(_("Other")); | |
256 | GtkWidget *scrollwnd = gtk_scrolled_window_new(NULL, NULL); | |
257 | GtkWidget *viewport = gtk_viewport_new(NULL, NULL); | |
258 | ||
259 | gtk_container_set_border_width(GTK_CONTAINER(table), 4); | |
260 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwnd), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
261 | gtk_container_add(GTK_CONTAINER(scrollwnd), viewport); | |
262 | gtk_container_add(GTK_CONTAINER(viewport), table); | |
263 | gtk_notebook_append_page(GTK_NOTEBOOK(configNotebook), | |
264 | scrollwnd, | |
265 | plabel); | |
266 | ||
267 | HashForeachContext context; | |
268 | context.i = 0; | |
269 | context.table = table; | |
270 | context.widget = self; | |
271 | g_hash_table_foreach(subconfigs, hash_foreach_cb, &context); | |
272 | } | |
273 | } | |
274 | ||
210 | 275 | gtk_widget_set_size_request(configNotebook, 500, -1); |
211 | 276 | gtk_notebook_set_scrollable(GTK_NOTEBOOK(configNotebook), TRUE); |
212 | ||
213 | return cvbox; | |
214 | } | |
215 | ||
216 | void sync_filter(ConfigGroup *group, ConfigOption *option, void *value, ConfigSync sync, void *arg) | |
277 | } | |
278 | FcitxConfigWidget* | |
279 | fcitx_config_widget_new (ConfigFileDesc* cfdesc, const gchar* prefix, const gchar* name, const char* subconfig) | |
280 | { | |
281 | FcitxConfigWidget* widget = | |
282 | g_object_new (FCITX_TYPE_CONFIG_WIDGET, | |
283 | "cfdesc", cfdesc, | |
284 | "prefix", prefix, | |
285 | "name", name, | |
286 | "subconfig", subconfig, | |
287 | NULL | |
288 | ); | |
289 | fcitx_config_widget_setup_ui(widget); | |
290 | return widget; | |
291 | } | |
292 | ||
293 | static void | |
294 | fcitx_config_widget_set_property (GObject *gobject, | |
295 | guint prop_id, | |
296 | const GValue *value, | |
297 | GParamSpec *pspec) | |
298 | { | |
299 | FcitxConfigWidget* config_widget = FCITX_CONFIG_WIDGET(gobject); | |
300 | switch (prop_id) | |
301 | { | |
302 | case PROP_CONFIG_DESC: | |
303 | config_widget->cfdesc = g_value_get_pointer(value); | |
304 | break; | |
305 | case PROP_PREFIX: | |
306 | if (config_widget->prefix) | |
307 | g_free(config_widget->prefix); | |
308 | config_widget->prefix = g_strdup(g_value_get_string(value)); | |
309 | break; | |
310 | case PROP_NAME: | |
311 | if (config_widget->name) | |
312 | g_free(config_widget->name); | |
313 | config_widget->name = g_strdup(g_value_get_string(value)); | |
314 | break; | |
315 | case PROP_SUBCONFIG: | |
316 | if (config_widget->parser) | |
317 | sub_config_parser_free(config_widget->parser); | |
318 | config_widget->parser = sub_config_parser_new(g_value_get_string(value)); | |
319 | break; | |
320 | default: | |
321 | G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); | |
322 | break; | |
323 | } | |
324 | } | |
325 | ||
326 | static void set_none_font_clicked(GtkWidget *button, gpointer arg) | |
327 | { | |
328 | gtk_font_button_set_font_name(GTK_FONT_BUTTON(arg), ""); | |
329 | } | |
330 | ||
331 | void sync_filter(GenericConfig* gconfig, ConfigGroup *group, ConfigOption *option, void *value, ConfigSync sync, void *arg) | |
217 | 332 | { |
218 | 333 | ConfigOptionDesc *codesc = option->optionDesc; |
219 | 334 | if (!codesc) |
222 | 337 | { |
223 | 338 | switch (codesc->type) |
224 | 339 | { |
225 | case T_Integer: | |
340 | case T_I18NString: | |
341 | break; | |
342 | case T_Integer: | |
343 | { | |
344 | int value = atoi(option->rawValue); | |
345 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(arg), value); | |
346 | } | |
347 | break; | |
348 | case T_Color: | |
349 | { | |
350 | int r = 0,g = 0,b = 0; | |
351 | char scolor[9]; | |
352 | sscanf(option->rawValue, "%d %d %d",&r,&g,&b); | |
353 | r = RoundColor(r); | |
354 | g = RoundColor(g); | |
355 | b = RoundColor(b); | |
356 | snprintf(scolor, 8 , "#%02X%02X%02X", r, g, b); | |
357 | GdkColor color; | |
358 | gdk_color_parse(scolor, &color); | |
359 | gtk_color_button_set_color(GTK_COLOR_BUTTON(arg), &color); | |
360 | } | |
361 | break; | |
362 | case T_Boolean: | |
363 | { | |
364 | gboolean bl; | |
365 | if (strcmp(option->rawValue, "True") == 0) | |
366 | bl = TRUE; | |
367 | else | |
368 | bl = FALSE; | |
369 | ||
370 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(arg), bl); | |
371 | } | |
372 | break; | |
373 | case T_Font: | |
374 | { | |
375 | gtk_font_button_set_font_name(GTK_FONT_BUTTON(arg), option->rawValue); | |
376 | } | |
377 | break; | |
378 | case T_Enum: | |
379 | { | |
380 | ConfigEnum* cenum = &codesc->configEnum; | |
381 | int index = 0, i; | |
382 | for (i = 0; i< cenum->enumCount; i++) | |
383 | { | |
384 | if ( strcmp(cenum->enumDesc[i], option->rawValue) == 0) | |
226 | 385 | { |
227 | int value = atoi(option->rawValue); | |
228 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(arg), value); | |
386 | index = i; | |
229 | 387 | } |
230 | break; | |
231 | case T_Color: | |
232 | { | |
233 | int r = 0,g = 0,b = 0; | |
234 | char scolor[9]; | |
235 | sscanf(option->rawValue, "%d %d %d",&r,&g,&b); | |
236 | r = RoundColor(r); | |
237 | g = RoundColor(g); | |
238 | b = RoundColor(b); | |
239 | snprintf(scolor, 8 , "#%02X%02X%02X", r, g, b); | |
240 | GdkColor color; | |
241 | gdk_color_parse(scolor, &color); | |
242 | gtk_color_button_set_color(GTK_COLOR_BUTTON(arg), &color); | |
243 | } | |
244 | break; | |
245 | case T_Boolean: | |
246 | { | |
247 | gboolean bl; | |
248 | if (strcmp(option->rawValue, "True") == 0) | |
249 | bl = TRUE; | |
250 | else | |
251 | bl = FALSE; | |
252 | ||
253 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(arg), bl); | |
254 | } | |
255 | break; | |
256 | case T_Font: | |
257 | { | |
258 | gtk_font_button_set_font_name(GTK_FONT_BUTTON(arg), option->rawValue); | |
259 | } | |
260 | break; | |
261 | case T_Enum: | |
262 | { | |
263 | ConfigEnum* cenum = &codesc->configEnum; | |
264 | int index = 0, i; | |
265 | for (i = 0; i< cenum->enumCount; i++) | |
266 | { | |
267 | if ( strcmp(cenum->enumDesc[i], option->rawValue) == 0) | |
268 | { | |
269 | index = i; | |
270 | } | |
271 | } | |
272 | gtk_combo_box_set_active(GTK_COMBO_BOX(arg), index); | |
273 | } | |
274 | break; | |
275 | case T_Hotkey: | |
276 | { | |
277 | HOTKEYS hotkey[2]; | |
278 | int j; | |
279 | SetHotKey(option->rawValue, hotkey); | |
280 | GArray *array = (GArray*) arg; | |
281 | ||
282 | for (j = 0; j < 2; j ++) | |
283 | { | |
284 | GtkWidget *button = g_array_index(array, GtkWidget*, j); | |
285 | keygrab_button_set_key(KEYGRAB_BUTTON(button), hotkey[j].sym, hotkey[j].state); | |
286 | if (hotkey[j].desc) | |
287 | free(hotkey[j].desc); | |
288 | } | |
289 | } | |
290 | break; | |
291 | case T_File: | |
292 | case T_Char: | |
293 | case T_Image: | |
294 | case T_String: | |
295 | { | |
296 | gtk_entry_set_text(GTK_ENTRY(arg), option->rawValue); | |
297 | } | |
298 | break; | |
388 | } | |
389 | gtk_combo_box_set_active(GTK_COMBO_BOX(arg), index); | |
390 | } | |
391 | break; | |
392 | case T_Hotkey: | |
393 | { | |
394 | HOTKEYS hotkey[2]; | |
395 | int j; | |
396 | SetHotKey(option->rawValue, hotkey); | |
397 | GArray *array = (GArray*) arg; | |
398 | ||
399 | for (j = 0; j < 2; j ++) | |
400 | { | |
401 | GtkWidget *button = g_array_index(array, GtkWidget*, j); | |
402 | keygrab_button_set_key(KEYGRAB_BUTTON(button), hotkey[j].sym, hotkey[j].state); | |
403 | if (hotkey[j].desc) | |
404 | free(hotkey[j].desc); | |
405 | } | |
406 | } | |
407 | break; | |
408 | case T_File: | |
409 | case T_Char: | |
410 | case T_String: | |
411 | { | |
412 | gtk_entry_set_text(GTK_ENTRY(arg), option->rawValue); | |
413 | } | |
414 | break; | |
299 | 415 | } |
300 | 416 | } |
301 | 417 | else |
302 | 418 | { |
303 | if (option->rawValue) | |
304 | free(option->rawValue); | |
419 | if ( codesc->type != T_I18NString && option->rawValue ) | |
420 | { | |
421 | free ( option->rawValue ); | |
422 | option->rawValue = NULL; | |
423 | } | |
305 | 424 | switch (codesc->type) |
306 | 425 | { |
307 | case T_Integer: | |
308 | { | |
309 | int value; | |
310 | value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(arg)); | |
311 | asprintf(&option->rawValue, "%d", value); | |
312 | } | |
313 | break; | |
314 | case T_Color: | |
315 | { | |
316 | int r = 0,g = 0,b = 0; | |
317 | GdkColor color; | |
318 | gtk_color_button_get_color(GTK_COLOR_BUTTON(arg), &color); | |
319 | r = color.red / 256; | |
320 | g = color.green / 256; | |
321 | b = color.blue / 256; | |
322 | r = RoundColor(r); | |
323 | g = RoundColor(g); | |
324 | b = RoundColor(b); | |
325 | asprintf(&option->rawValue, "%d %d %d",r,g,b); | |
326 | } | |
327 | break; | |
328 | case T_Boolean: | |
329 | { | |
330 | gboolean bl; | |
331 | bl = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(arg)); | |
332 | if (bl) | |
333 | option->rawValue = strdup("True"); | |
334 | else | |
335 | option->rawValue = strdup("False"); | |
336 | } | |
337 | break; | |
338 | case T_Font: | |
339 | { | |
340 | const char *font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(arg)); | |
341 | PangoFontDescription *fontdesc = pango_font_description_from_string(font); | |
342 | if (fontdesc) | |
343 | { | |
344 | const char *family = pango_font_description_get_family(fontdesc); | |
345 | if (family) | |
346 | option->rawValue = strdup(family); | |
347 | else | |
348 | option->rawValue = strdup(""); | |
349 | pango_font_description_free(fontdesc); | |
350 | } | |
351 | else | |
352 | option->rawValue = strdup(""); | |
353 | } | |
354 | break; | |
355 | case T_Enum: | |
356 | { | |
357 | ConfigEnum* cenum = &codesc->configEnum; | |
358 | int index = 0; | |
359 | index = gtk_combo_box_get_active(GTK_COMBO_BOX(arg)); | |
360 | option->rawValue = strdup(cenum->enumDesc[index]); | |
361 | } | |
362 | break; | |
363 | case T_Hotkey: | |
364 | { | |
365 | GArray *array = (GArray*) arg; | |
366 | GtkWidget *button; | |
367 | guint key; | |
368 | GdkModifierType mods; | |
369 | char *strkey[2] = { NULL, NULL }; | |
370 | int j = 0, k = 0; | |
371 | ||
372 | for (j = 0; j < 2 ; j ++) | |
373 | { | |
374 | button = g_array_index(array, GtkWidget*, j); | |
375 | keygrab_button_get_key(KEYGRAB_BUTTON(button), &key, &mods); | |
376 | strkey[k] = GetKeyString(key, mods); | |
377 | if (strkey[k]) | |
378 | k ++; | |
379 | } | |
380 | if (strkey[1]) | |
381 | asprintf(&option->rawValue, "%s %s", strkey[0], strkey[1]); | |
382 | else if (strkey[0]) | |
383 | { | |
384 | option->rawValue = strdup(strkey[0]); | |
385 | } | |
386 | else | |
387 | option->rawValue = strdup(""); | |
388 | ||
389 | for (j = 0 ; j < k ; j ++) | |
390 | free(strkey[j]); | |
391 | ||
392 | } | |
393 | break; | |
394 | case T_File: | |
395 | case T_Char: | |
396 | case T_Image: | |
397 | case T_String: | |
398 | { | |
399 | option->rawValue = strdup(gtk_entry_get_text(GTK_ENTRY(arg))); | |
400 | } | |
401 | break; | |
402 | } | |
403 | ||
404 | } | |
405 | } | |
426 | case T_I18NString: | |
427 | break; | |
428 | case T_Integer: | |
429 | { | |
430 | int value; | |
431 | value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(arg)); | |
432 | option->rawValue = g_strdup_printf("%d", value); | |
433 | } | |
434 | break; | |
435 | case T_Color: | |
436 | { | |
437 | int r = 0,g = 0,b = 0; | |
438 | GdkColor color; | |
439 | gtk_color_button_get_color(GTK_COLOR_BUTTON(arg), &color); | |
440 | r = color.red / 256; | |
441 | g = color.green / 256; | |
442 | b = color.blue / 256; | |
443 | r = RoundColor(r); | |
444 | g = RoundColor(g); | |
445 | b = RoundColor(b); | |
446 | option->rawValue = g_strdup_printf("%d %d %d",r,g,b); | |
447 | } | |
448 | break; | |
449 | case T_Boolean: | |
450 | { | |
451 | gboolean bl; | |
452 | bl = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(arg)); | |
453 | if (bl) | |
454 | option->rawValue = strdup("True"); | |
455 | else | |
456 | option->rawValue = strdup("False"); | |
457 | } | |
458 | break; | |
459 | case T_Font: | |
460 | { | |
461 | const char *font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(arg)); | |
462 | PangoFontDescription *fontdesc = pango_font_description_from_string(font); | |
463 | if (fontdesc) | |
464 | { | |
465 | const char *family = pango_font_description_get_family(fontdesc); | |
466 | if (family) | |
467 | option->rawValue = strdup(family); | |
468 | else | |
469 | option->rawValue = strdup(""); | |
470 | pango_font_description_free(fontdesc); | |
471 | } | |
472 | else | |
473 | option->rawValue = strdup(""); | |
474 | } | |
475 | break; | |
476 | case T_Enum: | |
477 | { | |
478 | ConfigEnum* cenum = &codesc->configEnum; | |
479 | int index = 0; | |
480 | index = gtk_combo_box_get_active(GTK_COMBO_BOX(arg)); | |
481 | option->rawValue = strdup(cenum->enumDesc[index]); | |
482 | } | |
483 | break; | |
484 | case T_Hotkey: | |
485 | { | |
486 | GArray *array = (GArray*) arg; | |
487 | GtkWidget *button; | |
488 | guint key; | |
489 | GdkModifierType mods; | |
490 | char *strkey[2] = { NULL, NULL }; | |
491 | int j = 0, k = 0; | |
492 | ||
493 | for (j = 0; j < 2 ; j ++) | |
494 | { | |
495 | button = g_array_index(array, GtkWidget*, j); | |
496 | keygrab_button_get_key(KEYGRAB_BUTTON(button), &key, &mods); | |
497 | strkey[k] = GetKeyString(key, mods); | |
498 | if (strkey[k]) | |
499 | k ++; | |
500 | } | |
501 | if (strkey[1]) | |
502 | option->rawValue = g_strdup_printf("%s %s", strkey[0], strkey[1]); | |
503 | else if (strkey[0]) | |
504 | { | |
505 | option->rawValue = strdup(strkey[0]); | |
506 | } | |
507 | else | |
508 | option->rawValue = strdup(""); | |
509 | ||
510 | for (j = 0 ; j < k ; j ++) | |
511 | free(strkey[j]); | |
512 | ||
513 | } | |
514 | break; | |
515 | case T_File: | |
516 | case T_Char: | |
517 | case T_String: | |
518 | { | |
519 | option->rawValue = strdup(gtk_entry_get_text(GTK_ENTRY(arg))); | |
520 | } | |
521 | break; | |
522 | } | |
523 | ||
524 | } | |
525 | } | |
526 | ||
527 | void fcitx_config_widget_response( | |
528 | FcitxConfigWidget* config_widget, | |
529 | ConfigWidgetAction action | |
530 | ) | |
531 | { | |
532 | if (!config_widget->cfdesc) | |
533 | return; | |
534 | ||
535 | if ( action == CONFIG_WIDGET_DEFAULT ) | |
536 | { | |
537 | ResetConfigToDefaultValue ( &config_widget->gconfig ); | |
538 | ConfigBindSync ( &config_widget->gconfig ); | |
539 | } | |
540 | else if ( action == CONFIG_WIDGET_SAVE ) | |
541 | { | |
542 | FILE* fp = GetXDGFileUserWithPrefix ( config_widget->prefix, config_widget->name, "wt", NULL ); | |
543 | ||
544 | if ( fp ) | |
545 | { | |
546 | SaveConfigFileFp ( fp, &config_widget->gconfig, config_widget->cfdesc ); | |
547 | fclose ( fp ); | |
548 | ||
549 | GError* error; | |
550 | gchar* argv[3]; | |
551 | argv[0] = EXEC_PREFIX "/bin/fcitx-remote"; | |
552 | argv[1] = "-r"; | |
553 | argv[2] = 0; | |
554 | g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error); | |
555 | } | |
556 | } | |
557 | } | |
558 | ||
559 | void fcitx_config_widget_finalize (GObject *object) | |
560 | { | |
561 | FcitxConfigWidget* config_widget = FCITX_CONFIG_WIDGET(object); | |
562 | g_free(config_widget->name); | |
563 | g_free(config_widget->prefix); | |
564 | sub_config_parser_free(config_widget->parser); | |
565 | G_OBJECT_CLASS (fcitx_config_widget_parent_class)->finalize (object); | |
566 | } | |
567 | ||
568 | void hash_foreach_cb (gpointer key, | |
569 | gpointer value, | |
570 | gpointer user_data) | |
571 | { | |
572 | HashForeachContext* context = user_data; | |
573 | FcitxConfigWidget* widget = context->widget; | |
574 | ||
575 | FcitxSubConfigPattern* pattern = value; | |
576 | FcitxSubConfig* subconfig = sub_config_new(key, pattern); | |
577 | ||
578 | if (subconfig == NULL) | |
579 | return; | |
580 | ||
581 | int i = context->i; | |
582 | ||
583 | GtkWidget* label = gtk_label_new(dgettext(widget->parser->domain, subconfig->name)); | |
584 | g_object_set(label, "xalign", 0.0f, NULL); | |
585 | ||
586 | GtkWidget *inputWidget = GTK_WIDGET( fcitx_sub_config_widget_new(subconfig)); | |
587 | ||
588 | gtk_table_attach(GTK_TABLE(context->table), label, 0, 1, i, i+1, GTK_FILL, GTK_SHRINK, 5, 5); | |
589 | gtk_table_attach(GTK_TABLE(context->table), inputWidget, 1, 2, i, i+1, GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 4); | |
590 | context->i ++; | |
591 | } |
0 | #include <gtk/gtk.h> | |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
19 | /* fcitx-config-widget.h */ | |
20 | ||
21 | #ifndef _FCITX_CONFIG_WIDGET | |
22 | #define _FCITX_CONFIG_WIDGET | |
23 | ||
24 | #include <gtk/gtkwidget.h> | |
25 | #include <glib/gstring.h> | |
1 | 26 | #include <fcitx-config/fcitx-config.h> |
27 | #include <gtk/gtkvbox.h> | |
28 | #include "sub_config_parser.h" | |
2 | 29 | |
3 | #include "main_window.h" | |
30 | G_BEGIN_DECLS | |
4 | 31 | |
5 | extern GtkWidget* config_widget_new(ConfigFileDesc *cfdesc, ConfigFile *cfile, ConfigPage *page, gboolean readonly); | |
32 | #define FCITX_TYPE_CONFIG_WIDGET fcitx_config_widget_get_type() | |
6 | 33 | |
7 | #define CHANGE_DOMAIN_BEGIN(domain) { \ | |
8 | char *lastdomain = strdup(textdomain(NULL)); \ | |
9 | textdomain(domain); | |
34 | #define FCITX_CONFIG_WIDGET(obj) \ | |
35 | (G_TYPE_CHECK_INSTANCE_CAST ((obj), FCITX_TYPE_CONFIG_WIDGET, FcitxConfigWidget)) | |
10 | 36 | |
11 | #define CHANGE_DOMAIN_END() \ | |
12 | textdomain(lastdomain); \ | |
13 | free(lastdomain); \ | |
14 | } | |
37 | #define FCITX_CONFIG_WIDGET_CLASS(klass) \ | |
38 | (G_TYPE_CHECK_CLASS_CAST ((klass), FCITX_TYPE_CONFIG_WIDGET, FcitxConfigWidgetClass)) | |
39 | ||
40 | #define FCITX_IS_CONFIG_WIDGET(obj) \ | |
41 | (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FCITX_TYPE_CONFIG_WIDGET)) | |
42 | ||
43 | #define FCITX_IS_CONFIG_WIDGET_CLASS(klass) \ | |
44 | (G_TYPE_CHECK_CLASS_TYPE ((klass), FCITX_TYPE_CONFIG_WIDGET)) | |
45 | ||
46 | #define FCITX_CONFIG_WIDGET_GET_CLASS(obj) \ | |
47 | (G_TYPE_INSTANCE_GET_CLASS ((obj), FCITX_TYPE_CONFIG_WIDGET, FcitxConfigWidgetClass)) | |
48 | ||
49 | typedef struct { | |
50 | GtkVBox parent; | |
51 | ConfigFileDesc* cfdesc; | |
52 | gchar* prefix; | |
53 | gchar* name; | |
54 | FcitxSubConfigParser* parser; | |
55 | GenericConfig gconfig; | |
56 | } FcitxConfigWidget; | |
57 | ||
58 | typedef struct { | |
59 | GtkVBoxClass parent_class; | |
60 | } FcitxConfigWidgetClass; | |
61 | ||
62 | typedef enum { | |
63 | CONFIG_WIDGET_SAVE, | |
64 | CONFIG_WIDGET_CANCEL, | |
65 | CONFIG_WIDGET_DEFAULT | |
66 | } ConfigWidgetAction; | |
67 | ||
68 | GType fcitx_config_widget_get_type (void); | |
69 | ||
70 | FcitxConfigWidget* fcitx_config_widget_new (ConfigFileDesc* cfdesc, const gchar* prefix, const gchar* name, const char* subconfig); | |
71 | void fcitx_config_widget_response(FcitxConfigWidget* config_widget, ConfigWidgetAction action); | |
72 | G_END_DECLS | |
73 | ||
74 | #endif /* _FCITX_CONFIG_WIDGET */ |
0 | #include "uthash.h" | |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
19 | #include <fcitx-utils/uthash.h> | |
1 | 20 | #include <fcitx-config/fcitx-config.h> |
2 | 21 | #include <fcitx-config/xdg.h> |
3 | 22 | #include <stdlib.h> |
20 | 39 | HASH_FIND_STR(cdset, filename, desc); |
21 | 40 | if (!desc) |
22 | 41 | { |
23 | FILE * tmpfp = GetXDGFileData(filename, "r", NULL); | |
24 | desc = malloc(sizeof(ConfigDescSet)); | |
25 | memset(desc, 0 ,sizeof(ConfigDescSet)); | |
26 | desc->filename = strdup(filename); | |
27 | desc->cfdesc = ParseConfigFileDescFp(tmpfp); | |
28 | fclose(tmpfp); | |
42 | FILE * tmpfp = GetXDGFileWithPrefix("configdesc", filename, "r", NULL); | |
43 | if (tmpfp) | |
44 | { | |
45 | desc = malloc(sizeof(ConfigDescSet)); | |
46 | memset(desc, 0 ,sizeof(ConfigDescSet)); | |
47 | desc->filename = strdup(filename); | |
48 | desc->cfdesc = ParseConfigFileDescFp(tmpfp); | |
49 | fclose(tmpfp); | |
29 | 50 | |
30 | HASH_ADD_KEYPTR(hh, cdset, desc->filename, strlen(desc->filename), desc); | |
51 | HASH_ADD_KEYPTR(hh, cdset, desc->filename, strlen(desc->filename), desc); | |
52 | } | |
53 | else | |
54 | return NULL; | |
31 | 55 | } |
32 | 56 | |
33 | 57 | return desc->cfdesc; |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
19 | #ifndef CONFIG_DESC_H | |
20 | #define CONFIG_DESC_H | |
0 | 21 | |
1 | 22 | #include <fcitx-config/fcitx-config.h> |
2 | 23 | |
3 | extern ConfigFileDesc *get_config_desc(char *filename); | |
24 | ConfigFileDesc *get_config_desc(char *filename); | |
25 | ||
26 | #endif |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
0 | 19 | #include <gtk/gtk.h> |
1 | 20 | #include <gdk/gdkkeysyms.h> |
2 | 21 | #include <libintl.h> |
15 | 34 | static gint keygrab_button_signals[LAST_SIGNAL] = { 0 }; |
16 | 35 | static void keygrab_button_init(KeyGrabButton *keygrab_button); |
17 | 36 | static void keygrab_button_class_init(KeyGrabButtonClass *keygrabbuttonclass); |
18 | static void changed(void); | |
19 | static void current_changed(void); | |
20 | 37 | static void begin_key_grab(KeyGrabButton* self, gpointer v); |
21 | 38 | static void end_key_grab(KeyGrabButton *self); |
22 | 39 | static GtkWidget* popup_new(GtkWidget* parent, const gchar* text, gboolean mouse); |
34 | 51 | sizeof(KeyGrabButtonClass), |
35 | 52 | (GtkClassInitFunc)keygrab_button_class_init, |
36 | 53 | (GtkObjectInitFunc)keygrab_button_init, |
54 | NULL, | |
37 | 55 | NULL, |
38 | 56 | NULL |
39 | 57 | }; |
83 | 101 | b->handler = gtk_signal_connect(GTK_OBJECT(b->popup), "key-press-event", GTK_SIGNAL_FUNC(on_key_press_event), b); |
84 | 102 | |
85 | 103 | while(gdk_keyboard_grab(gtk_widget_get_window(GTK_WIDGET(b->popup)), FALSE, GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS) |
86 | usleep(100); | |
104 | usleep(100); | |
87 | 105 | } |
88 | 106 | |
89 | 107 | void end_key_grab(KeyGrabButton *self) |
100 | 118 | guint key; |
101 | 119 | GdkModifierType mods = event->state & gtk_accelerator_get_default_mod_mask(); |
102 | 120 | |
121 | #if GTK_MINOR_VERSION < 22 | |
122 | if ((event->keyval == GDK_Escape | |
123 | || event->keyval == GDK_Return) && !mods) | |
124 | #else | |
103 | 125 | if ((event->keyval == GDK_KEY_Escape |
104 | 126 | || event->keyval == GDK_KEY_Return) && !mods) |
105 | { | |
127 | #endif | |
128 | { | |
129 | #if GTK_MINOR_VERSION < 22 | |
130 | if (event->keyval == GDK_Escape) | |
131 | #else | |
106 | 132 | if (event->keyval == GDK_KEY_Escape) |
133 | #endif | |
107 | 134 | gtk_signal_emit_by_name(GTK_OBJECT(b), "changed", b->key, b->mods); |
108 | 135 | end_key_grab(b); |
109 | 136 | keygrab_button_set_key(b, 0, 0); |
111 | 138 | } |
112 | 139 | |
113 | 140 | key = gdk_keyval_to_upper(event->keyval); |
141 | #if GTK_MINOR_VERSION < 22 | |
142 | if (key == GDK_ISO_Left_Tab) | |
143 | key = GDK_Tab; | |
144 | #else | |
114 | 145 | if (key == GDK_KEY_ISO_Left_Tab) |
115 | 146 | key = GDK_KEY_Tab; |
147 | #endif | |
116 | 148 | |
117 | 149 | if (gtk_accelerator_valid(key, mods) |
118 | || (key == GDK_KEY_Tab && mods)) | |
150 | || (key == GDK_Tab && mods)) | |
119 | 151 | { |
120 | 152 | keygrab_button_set_key(b, key, mods); |
121 | 153 | end_key_grab(b); |
163 | 195 | { |
164 | 196 | GtkWidget* w = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
165 | 197 | gtk_window_set_type_hint(GTK_WINDOW(w), GDK_WINDOW_TYPE_HINT_UTILITY); |
166 | gtk_window_set_position(GTK_WINDOW(w), mouse && GTK_WIN_POS_MOUSE || GTK_WIN_POS_CENTER_ALWAYS); | |
198 | gtk_window_set_position(GTK_WINDOW(w), mouse ? GTK_WIN_POS_MOUSE : GTK_WIN_POS_CENTER_ALWAYS); | |
167 | 199 | if (parent) |
168 | 200 | gtk_window_set_transient_for(GTK_WINDOW(w), GTK_WINDOW(gtk_widget_get_toplevel(parent))); |
169 | 201 | gtk_window_set_modal(GTK_WINDOW(w), TRUE); |
0 | #ifndef __OUR_ITEM_H__ | |
1 | #define __OUR_ITEM_H__ | |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
19 | #ifndef KEYGRAB_H | |
20 | #define KEYGRAB_H | |
21 | ||
2 | 22 | #include <gtk/gtk.h> |
3 | 23 | //定义类型宏和转换宏 |
4 | 24 | #define TYPE_KEYGRAB_BUTTON (keygrab_button_get_type()) |
24 | 44 | gchar *accelerator_to_fcitx_hotkey(const gchar* str); |
25 | 45 | void keygrab_button_set_key(KeyGrabButton* self, guint key, GdkModifierType mods); |
26 | 46 | void keygrab_button_get_key(KeyGrabButton* self, guint* key, GdkModifierType* mods); |
27 | #endif //__OUR_ITEM_H__ | |
28 | 47 | |
48 | #endif |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
0 | 19 | #include <gtk/gtk.h> |
1 | 20 | #include <langinfo.h> |
2 | 21 | #include <libintl.h> |
3 | 22 | #include <locale.h> |
4 | #include <unique/unique.h> | |
5 | ||
23 | #include "config.h" | |
6 | 24 | #include "main_window.h" |
7 | 25 | |
8 | 26 | static GtkWidget *window = NULL; |
27 | ||
28 | #ifdef HAVE_UNIQUE | |
29 | #include <unique/unique.h> | |
9 | 30 | |
10 | 31 | static UniqueResponse |
11 | 32 | message_received_cb (UniqueApp *app, |
28 | 49 | } |
29 | 50 | return res; |
30 | 51 | } |
52 | #endif | |
31 | 53 | |
32 | 54 | int |
33 | 55 | main(int argc, char **argv) |
34 | 56 | { |
57 | gtk_init(&argc, &argv); | |
58 | ||
59 | #ifdef HAVE_UNIQUE | |
35 | 60 | UniqueApp *app; |
36 | 61 | |
37 | gtk_init(&argc, &argv); | |
38 | ||
39 | 62 | app = unique_app_new_with_commands ("org.fcitx.fcitx-configtool", NULL, |
40 | NULL); | |
63 | NULL, NULL); | |
41 | 64 | |
42 | 65 | if (unique_app_is_running(app)) |
43 | 66 | { |
48 | 71 | else |
49 | 72 | return 1; |
50 | 73 | } |
74 | #endif | |
51 | 75 | |
52 | 76 | setlocale(LC_ALL, ""); |
53 | 77 | bindtextdomain("fcitx-configtool", LOCALEDIR); |
78 | bind_textdomain_codeset("fcitx-configtool", "UTF-8"); | |
54 | 79 | bindtextdomain("fcitx", LOCALEDIR); |
80 | bind_textdomain_codeset("fcitx", "UTF-8"); | |
55 | 81 | textdomain("fcitx-configtool"); |
56 | 82 | |
57 | window = fcitx_config_main_window_new (GTK_WINDOW_TOPLEVEL); | |
83 | window = fcitx_config_main_window_new (); | |
84 | ||
85 | #ifdef HAVE_UNIQUE | |
58 | 86 | unique_app_watch_window (app, GTK_WINDOW (window)); |
59 | 87 | g_signal_connect (app, "message-received", G_CALLBACK (message_received_cb), NULL); |
88 | #endif | |
60 | 89 | |
61 | 90 | gtk_widget_show_all(window); |
62 | 91 | |
63 | 92 | gtk_main(); |
93 | ||
94 | #ifdef HAVE_UNIQUE | |
64 | 95 | g_object_unref (app); |
96 | #endif | |
65 | 97 | |
66 | 98 | return 0; |
67 | 99 | } |
68 | ||
100 |
0 | #include <gtk/gtk.h> | |
1 | #include <fcitx-config/fcitx-config.h> | |
2 | #include <fcitx-config/xdg.h> | |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
3 | 19 | #include <stdlib.h> |
4 | 20 | #include <libintl.h> |
5 | 21 | #include <errno.h> |
6 | 22 | |
23 | #include <fcitx/addon.h> | |
24 | #include <fcitx-utils/utarray.h> | |
25 | #include <fcitx-config/fcitx-config.h> | |
26 | #include <fcitx-config/xdg.h> | |
27 | ||
28 | #include "config.h" | |
7 | 29 | #include "main_window.h" |
8 | #include "menu.h" | |
9 | 30 | #include "config_widget.h" |
10 | #include "skin_stuff.h" | |
11 | #include "addon_stuff.h" | |
12 | #include "table_stuff.h" | |
13 | #include "utarray.h" | |
14 | 31 | #include "configdesc.h" |
15 | 32 | |
33 | enum | |
34 | { | |
35 | LIST_ADDON, | |
36 | N_COLUMNS | |
37 | }; | |
38 | ||
16 | 39 | #define _(s) gettext(s) |
40 | ||
41 | ||
42 | static void | |
43 | enabled_data_func (GtkCellLayout *cell_layout, | |
44 | GtkCellRenderer *renderer, | |
45 | GtkTreeModel *tree_model, | |
46 | GtkTreeIter *iter, | |
47 | gpointer user_data); | |
48 | ||
49 | static void | |
50 | name_data_func (GtkCellLayout *cell_layout, | |
51 | GtkCellRenderer *renderer, | |
52 | GtkTreeModel *tree_model, | |
53 | GtkTreeIter *iter, | |
54 | gpointer user_data); | |
55 | ||
56 | static void configure_button_clicked (GtkButton *button, | |
57 | gpointer user_data); | |
58 | static void apply_button_clicked (GtkButton *button, | |
59 | gpointer user_data); | |
60 | static void | |
61 | toggled_cb (GtkCellRenderer *renderer, | |
62 | gchar* str_path, | |
63 | gpointer user_data); | |
17 | 64 | |
18 | 65 | static GtkWidget *mainWnd = NULL; |
19 | 66 | static GtkWidget *configTreeView = NULL; |
20 | static GtkWidget *configNotebook = NULL; | |
21 | 67 | static GtkTreeStore *store = NULL; |
22 | 68 | static GtkWidget *hpaned = NULL; |
23 | static ConfigPage *configPage, *profilePage, *tablePage, *skinPage, *lastPage = NULL, *addonPage; | |
69 | static ConfigPage *configPage, *lastPage = NULL, *addonPage; | |
70 | static GtkWidget* configureButton = NULL; | |
71 | const UT_icd addonicd= {sizeof ( FcitxAddon ), 0, 0, FreeAddon}; | |
72 | UT_array* addonBuf; | |
24 | 73 | |
25 | 74 | static int main_window_close(GtkWidget *theWindow, gpointer data); |
26 | 75 | static GtkTreeModel *fcitx_config_create_model(); |
27 | 76 | |
28 | 77 | int main_window_close(GtkWidget *theWindow, gpointer data) |
29 | 78 | { |
79 | utarray_free(addonBuf); | |
30 | 80 | gtk_main_quit(); |
31 | } | |
32 | ||
33 | ConfigPage* main_window_add_page(char *cdesc, char* name, char *filename, ConfigFile *cfile, ConfigPage* parent, const char* domain, gboolean readonly) | |
34 | { | |
35 | GtkTreeIter *p; | |
36 | if (parent) | |
37 | p = &parent->iter; | |
38 | else | |
39 | p = NULL; | |
40 | ||
81 | return 0; | |
82 | } | |
83 | ||
84 | ConfigPage* main_window_add_page(const char* name, GtkWidget* widget) | |
85 | { | |
41 | 86 | ConfigPage *page = (ConfigPage*) malloc(sizeof(ConfigPage)); |
42 | 87 | memset(page, 0, sizeof(ConfigPage)); |
43 | 88 | |
44 | if (filename) | |
45 | { | |
46 | page->filename = strdup(filename); | |
47 | page->config.configFile = cfile; | |
48 | page->cfdesc = get_config_desc(cdesc); | |
49 | page->parent = parent; | |
50 | page->domain = domain; | |
51 | page->page = config_widget_new(page->cfdesc, cfile, page, readonly); | |
52 | ConfigBindSync(&page->config); | |
53 | } | |
54 | else | |
55 | { | |
56 | page->parent = parent; | |
57 | page->cfdesc = NULL; | |
58 | GtkWidget *label = gtk_label_new(_(cdesc)); | |
59 | page->page = label; | |
60 | } | |
89 | page->page = widget; | |
61 | 90 | |
62 | 91 | g_object_ref(page->page); |
63 | 92 | |
64 | gtk_tree_store_append(store, &page->iter, p); | |
93 | gtk_widget_show_all(widget); | |
94 | ||
95 | gtk_tree_store_append(store, &page->iter, NULL); | |
65 | 96 | gtk_tree_store_set(store, &page->iter, 0, name, 1, page, -1); |
66 | 97 | |
67 | 98 | return page; |
68 | 99 | } |
69 | 100 | |
70 | gboolean selection_changed(GtkTreeSelection *selection, gpointer data) { | |
101 | void selection_changed(GtkTreeSelection *selection, gpointer data) { | |
71 | 102 | GtkTreeView *treeView = gtk_tree_selection_get_tree_view(selection); |
72 | 103 | GtkTreeModel *model = gtk_tree_view_get_model(treeView); |
73 | 104 | GtkTreeIter iter; |
74 | ConfigPage *page; | |
75 | ||
105 | ConfigPage* page; | |
106 | ||
76 | 107 | if (gtk_tree_selection_get_selected(selection, &model, &iter)) |
77 | 108 | { |
78 | 109 | gtk_tree_model_get(model, &iter, |
92 | 123 | } |
93 | 124 | } |
94 | 125 | |
126 | ||
127 | void addon_selection_changed(GtkTreeSelection *selection, gpointer data) { | |
128 | GtkTreeView *treeView = gtk_tree_selection_get_tree_view(selection); | |
129 | GtkTreeModel *model = gtk_tree_view_get_model(treeView); | |
130 | GtkTreeIter iter; | |
131 | FcitxAddon *addon = NULL; | |
132 | ||
133 | if (!configureButton) | |
134 | return; | |
135 | ||
136 | if (gtk_tree_selection_get_selected(selection, &model, &iter)) | |
137 | { | |
138 | gtk_tree_model_get(model, &iter, | |
139 | LIST_ADDON, &addon, | |
140 | -1); | |
141 | gchar* config_desc_name = g_strdup_printf("%s.desc",addon->name); | |
142 | ConfigFileDesc* cfdesc = get_config_desc ( config_desc_name ); | |
143 | g_free(config_desc_name); | |
144 | gboolean configurable = ( gboolean ) ( cfdesc != NULL || strlen ( addon->subconfig ) != 0 ); | |
145 | gtk_widget_set_sensitive(configureButton, configurable); | |
146 | } | |
147 | else | |
148 | { | |
149 | gtk_widget_set_sensitive(configureButton, FALSE); | |
150 | } | |
151 | } | |
152 | ||
95 | 153 | GtkTreeModel *fcitx_config_create_model() |
96 | 154 | { |
97 | 155 | store = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER); |
100 | 158 | |
101 | 159 | void add_config_file_page() |
102 | 160 | { |
103 | FILE *fp; | |
104 | char *file; | |
105 | ConfigFileDesc* configDesc = get_config_desc("config.desc"); | |
106 | reload_config: | |
107 | fp = GetXDGFileUser( "config", "rt", &file); | |
108 | if (!fp) { | |
109 | if (errno == ENOENT) | |
110 | { | |
111 | fp = GetXDGFileUser("config", "wt", NULL); | |
112 | SaveConfigFileFp(fp, NULL, configDesc); | |
113 | fclose(fp); | |
114 | fp = NULL; | |
115 | goto reload_config; | |
116 | } | |
117 | } | |
118 | ConfigFile *cfile = ParseConfigFileFp(fp, configDesc); | |
119 | fclose(fp); | |
120 | ||
121 | configPage = main_window_add_page("config.desc", _("Config"), file, cfile, NULL, "fcitx", FALSE); | |
122 | } | |
123 | ||
124 | void add_profile_file_page() | |
125 | { | |
126 | FILE *fp; | |
127 | char *file; | |
128 | ConfigFileDesc* configDesc = get_config_desc("profile.desc"); | |
129 | reload_profile: | |
130 | fp = GetXDGFileUser( "profile", "rt", &file); | |
131 | if (!fp) { | |
132 | if (errno == ENOENT) | |
133 | { | |
134 | fp = GetXDGFileUser("profile", "wt", NULL); | |
135 | SaveConfigFileFp(fp, NULL, configDesc); | |
136 | fclose(fp); | |
137 | fp = NULL; | |
138 | goto reload_profile; | |
139 | } | |
140 | } | |
141 | ConfigFile *cfile = ParseConfigFileFp(fp, configDesc); | |
142 | fclose(fp); | |
143 | ||
144 | profilePage = main_window_add_page("profile.desc", _("Profile"), file, cfile, NULL, "fcitx", FALSE); | |
145 | ||
146 | } | |
147 | ||
148 | void add_skin_page() | |
149 | { | |
150 | skinPage = main_window_add_page(_("Skin Configuration"), _("Skin"), NULL, NULL, NULL, NULL, FALSE); | |
151 | UT_array *skinBuf = loadSkinDir(); | |
152 | int j = 0; | |
153 | char buf[PATH_MAX]; | |
154 | for(j=0;j<skinBuf->i;j++) | |
155 | { | |
156 | char **sskin = (char**)utarray_eltptr(skinBuf, j); | |
157 | snprintf(buf, PATH_MAX, "%s/fcitx_skin.conf", *sskin); | |
158 | buf[PATH_MAX-1] ='\0'; | |
159 | size_t len; | |
160 | char ** path = GetXDGPath(&len, "XDG_CONFIG_HOME", ".config", "fcitx/skin" , DATADIR, "fcitx/skin" ); | |
161 | char *file; | |
162 | ConfigFile *cfile; | |
163 | ||
164 | FILE* fp = GetXDGFile(buf, path, "r", len, NULL); | |
165 | ||
166 | FreeXDGPath(path); | |
167 | ||
168 | if (fp) | |
169 | { | |
170 | ConfigFileDesc* skinDesc = get_config_desc("skin.desc"); | |
171 | cfile = ParseConfigFileFp(fp, skinDesc); | |
172 | if (!cfile) | |
173 | { | |
174 | fclose(fp); | |
175 | continue; | |
176 | } | |
177 | path = GetXDGPath(&len, "XDG_CONFIG_HOME", ".config", "fcitx/skin" , NULL, NULL ); | |
178 | FILE * fp = GetXDGFile(buf, path, NULL, len, &file); | |
179 | if (fp) fclose(fp); | |
180 | FreeXDGPath(path); | |
181 | } | |
182 | else | |
183 | continue; | |
184 | ||
185 | main_window_add_page("skin.desc", *sskin, file, cfile, skinPage, "fcitx", FALSE); | |
186 | free(file); | |
187 | } | |
188 | ||
161 | GtkWidget* vbox = gtk_vbox_new(0, 0); | |
162 | ||
163 | FcitxConfigWidget* config_widget = fcitx_config_widget_new( | |
164 | get_config_desc("config.desc"), | |
165 | "", | |
166 | "config", | |
167 | NULL | |
168 | ); | |
169 | gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(config_widget), TRUE, TRUE, 0); | |
170 | ||
171 | GtkWidget* hbuttonbox = gtk_hbutton_box_new(); | |
172 | gtk_box_pack_start(GTK_BOX(vbox), hbuttonbox, FALSE, TRUE, 0); | |
173 | ||
174 | GtkWidget* applybutton = gtk_button_new_from_stock(GTK_STOCK_APPLY); | |
175 | gtk_box_pack_start(GTK_BOX(hbuttonbox), applybutton, TRUE, TRUE, 0); | |
176 | g_signal_connect(G_OBJECT(applybutton), "clicked", G_CALLBACK(apply_button_clicked), config_widget); | |
177 | ||
178 | ||
179 | configPage = main_window_add_page(_("Global Config"), vbox); | |
189 | 180 | } |
190 | 181 | |
191 | 182 | void add_addon_page() |
192 | 183 | { |
193 | int i, j; | |
194 | addonPage = main_window_add_page(_("Addon Configuration"), _("Addon"), NULL, NULL, NULL, NULL, FALSE); | |
195 | UT_array *addonBuf = LoadAddonInfo(); | |
196 | ||
197 | size_t len; | |
198 | char **addonPath = GetXDGPath(&len, "XDG_CONFIG_HOME", ".config", "fcitx/addon" , DATADIR, "fcitx/data/addon" ); | |
199 | char **paths = malloc(sizeof(char*) *len); | |
200 | for (i = 0;i < len ;i ++) | |
201 | paths[i] = malloc(sizeof(char) *PATH_MAX); | |
202 | ||
203 | for(j=0;j<addonBuf->i;j++) | |
204 | { | |
205 | char *file; | |
206 | ConfigFile *cfile; | |
207 | char **saddon = (char**)utarray_eltptr(addonBuf, j); | |
208 | for (i = len -1; i >= 0; i--) | |
209 | snprintf(paths[i], PATH_MAX, "%s/%s", addonPath[len - i - 1], *saddon); | |
210 | ||
211 | cfile = ParseMultiConfigFile(paths, len, get_config_desc("addon.desc")); | |
212 | ||
213 | if (!cfile) | |
214 | continue; | |
215 | ||
216 | { | |
217 | size_t l; | |
218 | char **path = GetXDGPath(&l, "XDG_CONFIG_HOME", ".config", "fcitx/addon" , DATADIR, "fcitx/data/addon" ); | |
219 | FILE *fp =GetXDGFile(*saddon, path, "r", l, &file); | |
220 | if (fp) fclose(fp); | |
221 | FreeXDGPath(path); | |
222 | } | |
223 | ConfigPage *page = main_window_add_page("addon.desc", *saddon, file, cfile, addonPage, "fcitx", TRUE); | |
224 | { | |
225 | /* add addon config page */ | |
226 | size_t len = strlen(*saddon) - strlen(".conf"); | |
227 | char *name = malloc((len + 1) * sizeof(char)); | |
228 | char *descfilename = malloc((1 + len + strlen("addon/.desc")) * sizeof(char)); | |
229 | char *filename = malloc((1 + len + strlen("addon/.config")) * sizeof(char)); | |
230 | char *rfile = NULL; | |
231 | FILE *fp = NULL; | |
232 | gboolean reload = FALSE; | |
233 | strncpy(name ,*saddon ,len); | |
234 | name[len] = '\0'; | |
235 | sprintf(descfilename, "addon/%s.desc", name); | |
236 | sprintf(filename, "addon/%s.config", name); | |
237 | ConfigFileDesc* addonConfigDesc = get_config_desc(descfilename); | |
238 | reload_config: | |
239 | fp = GetXDGFileUser(filename, "rt", &rfile); | |
240 | if (!fp && !reload) { | |
241 | if (errno == ENOENT) | |
242 | { | |
243 | fp = GetXDGFileUser(filename, "wt", NULL); | |
244 | SaveConfigFileFp(fp, NULL, addonConfigDesc); | |
245 | fclose(fp); | |
246 | fp = NULL; | |
247 | reload = TRUE; | |
248 | } | |
249 | } | |
250 | if (fp) | |
251 | { | |
252 | ConfigFile *addoncfile = ParseConfigFileFp(fp, addonConfigDesc); | |
253 | bindtextdomain(name, LOCALEDIR); | |
254 | main_window_add_page(descfilename, _("Configure"), rfile, addoncfile, page, strdup(name), FALSE); | |
255 | } | |
256 | free(name); | |
257 | free(descfilename); | |
258 | free(filename); | |
259 | } | |
260 | free(file); | |
261 | } | |
262 | ||
263 | for (i = 0;i < len ;i ++) | |
264 | free(paths[i]); | |
265 | free(paths); | |
266 | FreeXDGPath(addonPath); | |
267 | ||
268 | } | |
269 | ||
270 | void add_table_page() | |
271 | { | |
272 | int i, j; | |
273 | tablePage = main_window_add_page(_("Table Configuration"), _("Table"), NULL, NULL, NULL, NULL, FALSE); | |
274 | UT_array *tableBuf = LoadTableInfo(); | |
275 | ||
276 | size_t len; | |
277 | char **tablePath = GetXDGPath(&len, "XDG_CONFIG_HOME", ".config", "fcitx/table" , DATADIR, "fcitx/data/table" ); | |
278 | char **paths = malloc(sizeof(char*) *len); | |
279 | for (i = 0;i < len ;i ++) | |
280 | paths[i] = malloc(sizeof(char) *PATH_MAX); | |
281 | ||
282 | for(j=0;j<tableBuf->i;j++) | |
283 | { | |
284 | char *file; | |
285 | ConfigFile *cfile; | |
286 | char **stable = (char**)utarray_eltptr(tableBuf, j); | |
287 | for (i = len -1; i >= 0; i--) | |
288 | snprintf(paths[i], PATH_MAX, "%s/%s", tablePath[len - i - 1], *stable); | |
289 | ||
290 | cfile = ParseMultiConfigFile(paths, len, get_config_desc("table.desc")); | |
291 | ||
292 | if (!cfile) | |
293 | continue; | |
294 | ||
295 | FILE *fp = GetXDGFileTable(*stable, "r", &file, True); | |
296 | if (fp) fclose(fp); | |
297 | main_window_add_page("table.desc", *stable, file, cfile, tablePage, "fcitx", FALSE); | |
298 | free(file); | |
299 | } | |
300 | ||
301 | for (i = 0;i < len ;i ++) | |
302 | free(paths[i]); | |
303 | free(paths); | |
304 | FreeXDGPath(tablePath); | |
305 | ||
184 | FcitxAddon* addon; | |
185 | utarray_new ( addonBuf, &addonicd ); | |
186 | LoadAddonInfo(addonBuf); | |
187 | ||
188 | GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | |
189 | ||
190 | GtkWidget* swin = gtk_scrolled_window_new ( NULL, NULL ); | |
191 | gtk_box_pack_start(GTK_BOX(vbox), swin, TRUE, TRUE, 0); | |
192 | g_object_set(swin, "hscrollbar-policy", GTK_POLICY_NEVER, NULL); | |
193 | GtkWidget* list = gtk_tree_view_new(); | |
194 | g_object_set(list, "headers-visible", FALSE, NULL); | |
195 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(swin), list); | |
196 | GtkCellRenderer *renderer; | |
197 | GtkTreeViewColumn *column; | |
198 | GtkListStore *store; | |
199 | ||
200 | store = gtk_list_store_new(N_COLUMNS, G_TYPE_POINTER); | |
201 | ||
202 | renderer = gtk_cell_renderer_toggle_new(); | |
203 | column = gtk_tree_view_column_new_with_attributes("Enable", renderer, NULL); | |
204 | gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); | |
205 | gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), | |
206 | renderer, | |
207 | enabled_data_func, | |
208 | list, | |
209 | NULL); | |
210 | g_signal_connect(G_OBJECT(renderer), "toggled", | |
211 | G_CALLBACK(toggled_cb), GTK_TREE_MODEL(store)); | |
212 | ||
213 | renderer = gtk_cell_renderer_text_new(); | |
214 | column = gtk_tree_view_column_new_with_attributes("Name", renderer, NULL); | |
215 | gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); | |
216 | gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), | |
217 | renderer, | |
218 | name_data_func, | |
219 | list, | |
220 | NULL); | |
221 | ||
222 | gtk_tree_view_set_model(GTK_TREE_VIEW(list), | |
223 | GTK_TREE_MODEL(store)); | |
224 | ||
225 | g_object_unref(store); | |
226 | ||
227 | for ( addon = ( FcitxAddon * ) utarray_front ( addonBuf ); | |
228 | addon != NULL; | |
229 | addon = ( FcitxAddon * ) utarray_next ( addonBuf, addon ) ) | |
230 | { | |
231 | GtkTreeIter iter; | |
232 | store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list))); | |
233 | gtk_list_store_append(store, &iter); | |
234 | gtk_list_store_set(store, &iter, LIST_ADDON, addon, -1); | |
235 | } | |
236 | ||
237 | GtkWidget* hbuttonbox = gtk_hbutton_box_new(); | |
238 | gtk_box_pack_start(GTK_BOX(vbox), hbuttonbox, FALSE, TRUE, 0); | |
239 | ||
240 | configureButton = gtk_button_new_with_label(_("Configure")); | |
241 | gtk_button_set_image(GTK_BUTTON(configureButton), gtk_image_new_from_stock (GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_BUTTON)); | |
242 | gtk_box_pack_start(GTK_BOX(hbuttonbox), configureButton, TRUE, TRUE, 0); | |
243 | g_signal_connect(G_OBJECT(configureButton), "clicked", G_CALLBACK(configure_button_clicked), list); | |
244 | ||
245 | GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list)); | |
246 | gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); | |
247 | g_signal_connect(G_OBJECT(selection), "changed", | |
248 | G_CALLBACK(addon_selection_changed), NULL); | |
249 | ||
250 | addonPage = main_window_add_page(_("Addon Configuration"), vbox); | |
306 | 251 | } |
307 | 252 | |
308 | 253 | GtkWidget* fcitx_config_main_window_new() |
310 | 255 | if (mainWnd != NULL) |
311 | 256 | return mainWnd; |
312 | 257 | |
313 | GtkWidget *menu = fcitx_config_menu_new(); | |
314 | 258 | GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
315 | ||
259 | ||
316 | 260 | GtkCellRenderer *renderer; |
317 | 261 | GtkTreeViewColumn *column; |
318 | 262 | |
329 | 273 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(configTreeView), FALSE); |
330 | 274 | |
331 | 275 | add_config_file_page(); |
332 | add_profile_file_page(); | |
333 | add_table_page(); | |
334 | add_skin_page(); | |
335 | 276 | add_addon_page(); |
336 | 277 | |
337 | 278 | gtk_widget_set_size_request(configTreeView, 170, -1); |
338 | gtk_widget_set_size_request(mainWnd, -1, 660); | |
279 | gtk_widget_set_size_request(mainWnd, -1, 500); | |
339 | 280 | |
340 | 281 | hpaned = gtk_hpaned_new(); |
341 | 282 | GtkWidget *treescroll = gtk_scrolled_window_new(NULL, NULL); |
344 | 285 | gtk_container_add(GTK_CONTAINER(treescroll), configTreeView); |
345 | 286 | gtk_paned_add1(GTK_PANED(hpaned), treescroll); |
346 | 287 | |
347 | gtk_box_pack_start(GTK_BOX(vbox), menu, FALSE, TRUE, 0); | |
348 | 288 | gtk_box_pack_start(GTK_BOX(vbox), hpaned, TRUE, TRUE, 0); |
349 | 289 | |
350 | 290 | gtk_container_add(GTK_CONTAINER(mainWnd), vbox); |
363 | 303 | gtk_window_set_title(GTK_WINDOW(mainWnd), _("Fcitx Config")); |
364 | 304 | return mainWnd; |
365 | 305 | } |
306 | ||
307 | static void | |
308 | toggled_cb (GtkCellRenderer *renderer, | |
309 | gchar* str_path, | |
310 | gpointer user_data) | |
311 | { | |
312 | GtkTreeModel *model = (GtkTreeModel *)user_data; | |
313 | GtkTreePath *path= gtk_tree_path_new_from_string(str_path); | |
314 | GtkTreeIter iter; | |
315 | gtk_tree_model_get_iter(model, &iter, path); | |
316 | FcitxAddon* addon = NULL; | |
317 | gtk_tree_path_free(path); | |
318 | gtk_tree_model_get (model, | |
319 | &iter, | |
320 | LIST_ADDON, &addon, | |
321 | -1); | |
322 | ||
323 | if (!addon) | |
324 | return; | |
325 | ||
326 | addon->bEnabled = !addon->bEnabled; | |
327 | char buf[PATH_MAX]; | |
328 | snprintf(buf, PATH_MAX, "%s.conf", addon->name); | |
329 | buf[PATH_MAX - 1] = 0; | |
330 | FILE* fp = GetXDGFileUserWithPrefix("addon", buf, "w", NULL); | |
331 | if (fp) | |
332 | { | |
333 | fprintf(fp, "[Addon]\nEnabled=%s\n", addon->bEnabled ? "True": "False"); | |
334 | fclose(fp); | |
335 | } | |
336 | g_object_set (renderer, | |
337 | "active", (gboolean) addon->bEnabled, | |
338 | NULL); | |
339 | } | |
340 | ||
341 | static void | |
342 | enabled_data_func (GtkCellLayout *cell_layout, | |
343 | GtkCellRenderer *renderer, | |
344 | GtkTreeModel *tree_model, | |
345 | GtkTreeIter *iter, | |
346 | gpointer user_data) | |
347 | { | |
348 | FcitxAddon* addon; | |
349 | ||
350 | gtk_tree_model_get (tree_model, | |
351 | iter, | |
352 | LIST_ADDON, &addon, | |
353 | -1); | |
354 | g_object_set (renderer, | |
355 | "active", (gboolean) addon->bEnabled, | |
356 | NULL); | |
357 | } | |
358 | ||
359 | static void | |
360 | name_data_func (GtkCellLayout *cell_layout, | |
361 | GtkCellRenderer *renderer, | |
362 | GtkTreeModel *tree_model, | |
363 | GtkTreeIter *iter, | |
364 | gpointer user_data) | |
365 | { | |
366 | FcitxAddon* addon; | |
367 | ||
368 | gtk_tree_model_get (tree_model, | |
369 | iter, | |
370 | LIST_ADDON, &addon, | |
371 | -1); | |
372 | gchar* string = g_strdup_printf("%s\n%s", addon->generalname, addon->comment); | |
373 | g_object_set (renderer, | |
374 | "text", string, | |
375 | NULL); | |
376 | ||
377 | g_free(string); | |
378 | } | |
379 | ||
380 | ||
381 | void apply_button_clicked(GtkButton* button, gpointer user_data) | |
382 | { | |
383 | FcitxConfigWidget* config_widget = user_data; | |
384 | fcitx_config_widget_response(config_widget, CONFIG_WIDGET_SAVE); | |
385 | } | |
386 | ||
387 | void configure_button_clicked (GtkButton *button, | |
388 | gpointer user_data) | |
389 | { | |
390 | GtkTreeView* view = user_data; | |
391 | GtkTreeSelection *selection = gtk_tree_view_get_selection(view); | |
392 | GtkTreeModel *model = gtk_tree_view_get_model(view); | |
393 | GtkTreeIter iter; | |
394 | FcitxAddon *addon = NULL; | |
395 | if (gtk_tree_selection_get_selected(selection, &model, &iter)) | |
396 | { | |
397 | gtk_tree_model_get(model, &iter, | |
398 | LIST_ADDON, &addon, | |
399 | -1); | |
400 | gchar* config_desc_name = g_strdup_printf("%s.desc",addon->name); | |
401 | ConfigFileDesc* cfdesc = get_config_desc ( config_desc_name ); | |
402 | g_free(config_desc_name); | |
403 | gboolean configurable = ( gboolean ) ( cfdesc != NULL || strlen ( addon->subconfig ) != 0 ); | |
404 | if (configurable) | |
405 | { | |
406 | GtkWidget* dialog = gtk_dialog_new_with_buttons(addon->generalname, | |
407 | GTK_WINDOW(mainWnd), | |
408 | GTK_DIALOG_MODAL, | |
409 | GTK_STOCK_OK, | |
410 | GTK_RESPONSE_OK, | |
411 | GTK_STOCK_CANCEL, | |
412 | GTK_RESPONSE_CANCEL, | |
413 | NULL | |
414 | ); | |
415 | ||
416 | gchar* config_file_name = g_strdup_printf("%s.config", addon->name); | |
417 | FcitxConfigWidget* config_widget = fcitx_config_widget_new(cfdesc, "conf", config_file_name, addon->subconfig); | |
418 | GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); | |
419 | gtk_box_pack_start(GTK_BOX(content_area), GTK_WIDGET(config_widget), TRUE, TRUE, 0); | |
420 | g_free(config_file_name); | |
421 | gtk_widget_set_size_request(GTK_WIDGET(config_widget), -1, 400); | |
422 | ||
423 | g_signal_connect (dialog, "response", | |
424 | G_CALLBACK (response_cb), | |
425 | config_widget); | |
426 | ||
427 | gtk_widget_show_all (GTK_WIDGET(dialog)); | |
428 | } | |
429 | } | |
430 | } | |
431 | ||
432 | gboolean response_cb (GtkDialog *dialog, | |
433 | gint response, | |
434 | gpointer user_data) | |
435 | { | |
436 | if (response == GTK_RESPONSE_OK) | |
437 | { | |
438 | FcitxConfigWidget* config_widget = (FcitxConfigWidget*) user_data; | |
439 | fcitx_config_widget_response(config_widget, CONFIG_WIDGET_SAVE); | |
440 | } | |
441 | gtk_widget_destroy(GTK_WIDGET(dialog)); | |
442 | return FALSE; | |
443 | } |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
0 | 19 | #ifndef MAIN_WINDOW_H |
1 | 20 | |
2 | 21 | #define MAIN_WINDOW_H |
6 | 25 | |
7 | 26 | typedef struct ConfigPage |
8 | 27 | { |
9 | ConfigFileDesc *cfdesc; | |
10 | 28 | GtkWidget* page; |
11 | struct ConfigPage* parent; | |
12 | GenericConfig config; | |
13 | char *filename; | |
14 | const char *domain; | |
15 | 29 | GtkTreeIter iter; |
16 | 30 | } ConfigPage; |
17 | 31 | |
18 | extern GtkWidget* fcitx_config_main_window_new(); | |
32 | GtkWidget* fcitx_config_main_window_new(void); | |
33 | ||
34 | gboolean response_cb (GtkDialog *dialog, | |
35 | gint response, | |
36 | gpointer user_data); | |
19 | 37 | |
20 | 38 | #endif |
0 | #include <gtk/gtk.h> | |
1 | #include <libintl.h> | |
2 | ||
3 | #define _(x) gettext(x) | |
4 | static void fcitx_reload_config(GtkMenuItem *menuitem, gpointer user_data); | |
5 | ||
6 | GtkWidget* fcitx_config_menu_new() | |
7 | { | |
8 | GtkWidget *menu = gtk_menu_bar_new(); | |
9 | ||
10 | GtkWidget *menuItemFile = gtk_menu_item_new_with_mnemonic(_("_File")); | |
11 | GtkWidget *menuFile = gtk_menu_new(); | |
12 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuItemFile), menuFile); | |
13 | gtk_menu_bar_append(menu,menuItemFile); | |
14 | ||
15 | GtkWidget *menuitem, *image; | |
16 | ||
17 | menuitem = gtk_image_menu_item_new_with_mnemonic(_("_Reload Config")); | |
18 | image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON); | |
19 | gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
20 | gtk_menu_append(menuFile, menuitem); | |
21 | gtk_signal_connect(GTK_OBJECT(menuitem), "activate", G_CALLBACK(fcitx_reload_config), NULL); | |
22 | ||
23 | menuitem = gtk_image_menu_item_new_with_mnemonic(_("_Exit")); | |
24 | image = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON); | |
25 | gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
26 | gtk_menu_append(menuFile, menuitem); | |
27 | gtk_signal_connect(GTK_OBJECT(menuitem), "activate", G_CALLBACK(gtk_main_quit), NULL); | |
28 | ||
29 | return menu; | |
30 | } | |
31 | ||
32 | void fcitx_reload_config(GtkMenuItem *menuitem, gpointer user_data) | |
33 | { | |
34 | system(BINDIR"/fcitx-remote -r"); | |
35 | } |
0 | #include <dirent.h> | |
1 | #include <sys/stat.h> | |
2 | #include "utarray.h" | |
3 | #include "skin_stuff.h" | |
4 | #include <fcitx-config/fcitx-config.h> | |
5 | #include <fcitx-config/xdg.h> | |
6 | ||
7 | static UT_array* skinBuf = NULL; | |
8 | ||
9 | UT_array* loadSkinDir() | |
10 | { | |
11 | if (!skinBuf) | |
12 | { | |
13 | skinBuf = malloc(sizeof(UT_array)); | |
14 | utarray_init(skinBuf, &ut_str_icd); | |
15 | } | |
16 | else | |
17 | { | |
18 | utarray_clear(skinBuf); | |
19 | } | |
20 | int i ; | |
21 | DIR *dir; | |
22 | struct dirent *drt; | |
23 | struct stat fileStat; | |
24 | size_t len; | |
25 | char pathBuf[PATH_MAX]; | |
26 | char **skinPath = GetXDGPath(&len, "XDG_CONFIG_HOME", ".config", "fcitx/skin" , DATADIR, "fcitx/skin" ); | |
27 | for(i = 0; i< len; i++) | |
28 | { | |
29 | dir = opendir(skinPath[i]); | |
30 | if (dir == NULL) | |
31 | continue; | |
32 | ||
33 | while((drt = readdir(dir)) != NULL) | |
34 | { | |
35 | if (strcmp(drt->d_name , ".") == 0 || strcmp(drt->d_name, "..") == 0) | |
36 | continue; | |
37 | sprintf(pathBuf,"%s/%s",skinPath[i],drt->d_name); | |
38 | ||
39 | if( stat(pathBuf,&fileStat) == -1) | |
40 | { | |
41 | continue; | |
42 | } | |
43 | if ( fileStat.st_mode & S_IFDIR) | |
44 | { | |
45 | /* check duplicate name */ | |
46 | int j = 0; | |
47 | for(;j<skinBuf->i;j++) | |
48 | { | |
49 | char **name = (char**) utarray_eltptr(skinBuf, j); | |
50 | if (strcmp(*name, drt->d_name) == 0) | |
51 | break; | |
52 | } | |
53 | if (j == skinBuf->i) | |
54 | { | |
55 | char *temp = drt->d_name; | |
56 | utarray_push_back(skinBuf, &temp); | |
57 | } | |
58 | } | |
59 | } | |
60 | ||
61 | closedir(dir); | |
62 | } | |
63 | ||
64 | FreeXDGPath(skinPath); | |
65 | ||
66 | return skinBuf; | |
67 | } | |
68 | ||
69 |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
19 | #include <limits.h> | |
20 | #include <stdlib.h> | |
21 | #include <dirent.h> | |
22 | #include <string.h> | |
23 | #include <sys/stat.h> | |
24 | #include <glib/gstrfuncs.h> | |
25 | #include <glib/gpattern.h> | |
26 | ||
27 | #include <fcitx-config/xdg.h> | |
28 | #include <fcitx-utils/log.h> | |
29 | ||
30 | #include "config.h" | |
31 | ||
32 | #include "sub_config_parser.h" | |
33 | ||
34 | static void sub_config_pattern_free(void* pattern); | |
35 | static GList* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern); | |
36 | static GList* get_files_by_pattern(const gchar* dirpath, FcitxSubConfigPattern* pattern, int index); | |
37 | static void sub_file_list_free(gpointer data, gpointer user_data); | |
38 | ||
39 | static SubConfigType parse_type(const gchar* str); | |
40 | ||
41 | static SubConfigType parse_type(const gchar* str) | |
42 | { | |
43 | if (strcmp(str, "native") == 0) | |
44 | { | |
45 | return SC_NativeFile; | |
46 | } | |
47 | if (strcmp(str, "configfile") == 0) | |
48 | { | |
49 | return SC_ConfigFile; | |
50 | } | |
51 | return SC_None; | |
52 | } | |
53 | ||
54 | FcitxSubConfigParser* sub_config_parser_new(const gchar* subconfig) | |
55 | { | |
56 | if (subconfig == NULL) | |
57 | return NULL; | |
58 | ||
59 | FcitxSubConfigParser* parser = g_malloc0(sizeof(FcitxSubConfigParser)); | |
60 | parser->subconfigs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, sub_config_pattern_free); | |
61 | gchar** strv = g_strsplit(subconfig, ",", 0); | |
62 | ||
63 | gchar** str; | |
64 | for (str = &strv[0]; *str != NULL; str++) | |
65 | { | |
66 | if (strchr(*str, ':') == NULL) | |
67 | continue; | |
68 | ||
69 | gchar** items = g_strsplit(*str, ":", 0); | |
70 | ||
71 | if (g_strv_length(items) < 2) | |
72 | goto end; | |
73 | if (strlen(items[0]) == 0) | |
74 | goto end; | |
75 | ||
76 | if (strcmp(items[1], "domain") == 0) | |
77 | { | |
78 | parser->domain = g_strdup(items[0]); | |
79 | goto end; | |
80 | } | |
81 | ||
82 | SubConfigType type = parse_type(items[1]); | |
83 | if (type == SC_None) | |
84 | goto end; | |
85 | if (g_hash_table_lookup (parser->subconfigs, items[0]) != NULL) | |
86 | continue; | |
87 | ||
88 | if (type == SC_ConfigFile) | |
89 | { | |
90 | if (g_strv_length(items) != 4) | |
91 | goto end; | |
92 | if (strlen(items[2]) == 0 || items[2][0] == '/') | |
93 | goto end; | |
94 | } | |
95 | else if (type == SC_NativeFile) | |
96 | { | |
97 | if (g_strv_length(items) != 3) | |
98 | goto end; | |
99 | if (strchr(items[2], '*') != NULL) | |
100 | goto end; | |
101 | } | |
102 | ||
103 | gchar** paths = g_strsplit(items[2], "/", 0); | |
104 | if (paths[0] == 0) | |
105 | { | |
106 | g_strfreev(paths); | |
107 | goto end; | |
108 | } | |
109 | gchar** path; | |
110 | for (path = &paths[0]; *path != NULL; path++) | |
111 | { | |
112 | if (strlen(*path) == 0) | |
113 | break; | |
114 | if (strcmp(*path, ".") == 0) | |
115 | break; | |
116 | if (strcmp(*path, "..") == 0) | |
117 | break; | |
118 | } | |
119 | if (*path != NULL) | |
120 | { | |
121 | g_strfreev(paths); | |
122 | goto end; | |
123 | } | |
124 | FcitxSubConfigPattern* pattern = g_malloc0(sizeof(FcitxSubConfigPattern)); | |
125 | pattern->type = type; | |
126 | pattern->patternlist = paths; | |
127 | if (type == SC_ConfigFile) | |
128 | pattern->configdesc = g_strdup(items[3]); | |
129 | else if (type == SC_NativeFile) | |
130 | pattern->nativepath = g_strdup(items[2]); | |
131 | ||
132 | g_hash_table_insert(parser->subconfigs, g_strdup(items[0]), pattern); | |
133 | end: | |
134 | g_strfreev(items); | |
135 | } | |
136 | g_strfreev(strv); | |
137 | if (g_hash_table_size(parser->subconfigs) == 0 || parser->domain == NULL) | |
138 | { | |
139 | sub_config_parser_free(parser); | |
140 | parser = NULL; | |
141 | } | |
142 | ||
143 | return parser; | |
144 | } | |
145 | ||
146 | void sub_config_parser_free(FcitxSubConfigParser* parser) | |
147 | { | |
148 | if (parser == NULL) | |
149 | return; | |
150 | ||
151 | g_hash_table_destroy(parser->subconfigs); | |
152 | if (parser->domain) | |
153 | g_free(parser->domain); | |
154 | } | |
155 | ||
156 | void sub_config_pattern_free(void* data) | |
157 | { | |
158 | FcitxSubConfigPattern* pattern = data; | |
159 | if (pattern->patternlist) | |
160 | g_strfreev(pattern->patternlist); | |
161 | ||
162 | if (pattern->configdesc) | |
163 | g_free(pattern->configdesc); | |
164 | ||
165 | if (pattern->nativepath) | |
166 | g_free(pattern->nativepath); | |
167 | ||
168 | g_free(pattern); | |
169 | } | |
170 | ||
171 | FcitxSubConfig* sub_config_new(const gchar* name, FcitxSubConfigPattern* pattern) | |
172 | { | |
173 | if (pattern->type == SC_None) | |
174 | return NULL; | |
175 | ||
176 | FcitxSubConfig* subconfig = g_malloc0(sizeof(FcitxSubConfig)); | |
177 | subconfig->type = pattern->type; | |
178 | subconfig->configdesc = g_strdup(pattern->configdesc); | |
179 | subconfig->nativepath = g_strdup(pattern->nativepath); | |
180 | subconfig->name = g_strdup(name); | |
181 | subconfig->filelist = sub_config_pattern_get_filelist(pattern); | |
182 | ||
183 | return subconfig; | |
184 | } | |
185 | ||
186 | void sub_file_list_free(gpointer data, gpointer user_data) | |
187 | { | |
188 | g_free(data); | |
189 | } | |
190 | ||
191 | void sub_config_free(FcitxSubConfig* subconfig) | |
192 | { | |
193 | if (!subconfig) | |
194 | return; | |
195 | ||
196 | g_free(subconfig->configdesc); | |
197 | g_free(subconfig->nativepath); | |
198 | g_free(subconfig->name); | |
199 | g_list_foreach(subconfig->filelist, sub_file_list_free, NULL); | |
200 | g_list_free(subconfig->filelist); | |
201 | g_free(subconfig); | |
202 | } | |
203 | ||
204 | GList* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern) | |
205 | { | |
206 | size_t size, i; | |
207 | GList* result = NULL; | |
208 | char** xdgpath = GetXDGPath(&size, "XDG_CONFIG_HOME", ".config" , PACKAGE , DATADIR, PACKAGE); | |
209 | ||
210 | for (i = 0; i < size; i ++) | |
211 | { | |
212 | char* dirpath = realpath(xdgpath[i], NULL); | |
213 | ||
214 | GList* list = get_files_by_pattern(dirpath, pattern, 0), *l; | |
215 | ||
216 | for (l = g_list_first(list); | |
217 | l != NULL; | |
218 | l = l->next) | |
219 | { | |
220 | if (strncmp(dirpath, (gchar*) l->data, strlen(dirpath)) == 0) | |
221 | { | |
222 | gchar* filename = (gchar*) l->data; | |
223 | gchar* name = filename + strlen(dirpath); | |
224 | while (name[0] == '/') | |
225 | name ++; | |
226 | result = g_list_append(result, g_strdup(name)); | |
227 | } | |
228 | } | |
229 | g_list_foreach(list, sub_file_list_free, NULL); | |
230 | g_list_free(list); | |
231 | ||
232 | free(dirpath); | |
233 | } | |
234 | ||
235 | FreeXDGPath(xdgpath); | |
236 | ||
237 | return result; | |
238 | } | |
239 | ||
240 | GList* get_files_by_pattern(const gchar* dirpath, FcitxSubConfigPattern* pattern, int index) | |
241 | { | |
242 | GList* result = NULL; | |
243 | ||
244 | DIR* dir = opendir(dirpath); | |
245 | if (!dir) | |
246 | return result; | |
247 | ||
248 | gchar* filter = pattern->patternlist[index]; | |
249 | ||
250 | struct dirent* drt; | |
251 | GPatternSpec * patternspec = g_pattern_spec_new(filter); | |
252 | while ((drt = readdir(dir)) != NULL) | |
253 | { | |
254 | if (strcmp(drt->d_name , ".") == 0 || strcmp(drt->d_name, "..") == 0) | |
255 | continue; | |
256 | ||
257 | if (!g_pattern_match_string(patternspec, drt->d_name)) | |
258 | continue; | |
259 | ||
260 | if (pattern->patternlist[index + 1] == 0) | |
261 | { | |
262 | char path[PATH_MAX]; | |
263 | snprintf(path, PATH_MAX, "%s/%s", dirpath, drt->d_name); | |
264 | path[PATH_MAX - 1] = '\0'; | |
265 | struct stat statbuf; | |
266 | if (stat(path, &statbuf) == 0) | |
267 | { | |
268 | result = g_list_append(result, realpath(path, NULL)); | |
269 | } | |
270 | } | |
271 | else | |
272 | { | |
273 | char path[PATH_MAX]; | |
274 | snprintf(path, PATH_MAX, "%s/%s", dirpath, drt->d_name); | |
275 | path[PATH_MAX - 1] = '\0'; | |
276 | GList* r = get_files_by_pattern(path, pattern, index + 1); | |
277 | result = g_list_concat(result, r); | |
278 | } | |
279 | } | |
280 | ||
281 | closedir(dir); | |
282 | g_pattern_spec_free(patternspec); | |
283 | return result; | |
284 | } |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
19 | #ifndef _SUB_CONFIG_PARSER_H | |
20 | #define _SUB_CONFIG_PARSER_H | |
21 | #include <glib/ghash.h> | |
22 | ||
23 | typedef enum | |
24 | { | |
25 | SC_None, | |
26 | SC_ConfigFile, | |
27 | SC_NativeFile | |
28 | } SubConfigType; | |
29 | ||
30 | typedef struct | |
31 | { | |
32 | SubConfigType type; | |
33 | gchar* configdesc; | |
34 | gchar* nativepath; | |
35 | gchar** patternlist; | |
36 | } FcitxSubConfigPattern; | |
37 | ||
38 | typedef struct | |
39 | { | |
40 | gchar* name; | |
41 | SubConfigType type; | |
42 | GList* filelist; | |
43 | gchar* nativepath; | |
44 | gchar* configdesc; | |
45 | } FcitxSubConfig; | |
46 | ||
47 | typedef struct | |
48 | { | |
49 | GHashTable* subconfigs; | |
50 | gchar* domain; | |
51 | } FcitxSubConfigParser; | |
52 | ||
53 | FcitxSubConfigParser* sub_config_parser_new(const gchar* subconfig); | |
54 | void sub_config_parser_free(FcitxSubConfigParser* parser); | |
55 | FcitxSubConfig* sub_config_new(const gchar* name, FcitxSubConfigPattern* pattern); | |
56 | void sub_config_free(FcitxSubConfig* subconfig); | |
57 | ||
58 | #endif |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
19 | #include <fcitx-config/xdg.h> | |
20 | #include <stdlib.h> | |
21 | ||
22 | #include "sub_config_widget.h" | |
23 | #include "main_window.h" | |
24 | #include "configdesc.h" | |
25 | #include "config_widget.h" | |
26 | ||
27 | G_DEFINE_TYPE (FcitxSubConfigWidget, fcitx_sub_config_widget, GTK_TYPE_VBOX) | |
28 | ||
29 | static void open_subconfig_file (GtkButton *button, gpointer user_data); | |
30 | static void open_native_file (GtkButton *button, gpointer user_data); | |
31 | static void push_into_store_cb (gpointer data, gpointer user_data); | |
32 | ||
33 | static void | |
34 | fcitx_sub_config_widget_get_property (GObject *object, guint property_id, | |
35 | GValue *value, GParamSpec *pspec) | |
36 | { | |
37 | switch (property_id) { | |
38 | default: | |
39 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | |
40 | } | |
41 | } | |
42 | ||
43 | static void | |
44 | fcitx_sub_config_widget_set_property (GObject *object, guint property_id, | |
45 | const GValue *value, GParamSpec *pspec) | |
46 | { | |
47 | switch (property_id) { | |
48 | default: | |
49 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | |
50 | } | |
51 | } | |
52 | ||
53 | static void | |
54 | fcitx_sub_config_widget_finalize (GObject *object) | |
55 | { | |
56 | FcitxSubConfigWidget* widget = FCITX_SUB_CONFIG_WIDGET(object); | |
57 | sub_config_free(widget->subconfig); | |
58 | G_OBJECT_CLASS (fcitx_sub_config_widget_parent_class)->finalize (object); | |
59 | } | |
60 | ||
61 | static void | |
62 | fcitx_sub_config_widget_class_init (FcitxSubConfigWidgetClass *klass) | |
63 | { | |
64 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
65 | ||
66 | ||
67 | object_class->get_property = fcitx_sub_config_widget_get_property; | |
68 | object_class->set_property = fcitx_sub_config_widget_set_property; | |
69 | object_class->finalize = fcitx_sub_config_widget_finalize; | |
70 | } | |
71 | ||
72 | static void | |
73 | fcitx_sub_config_widget_init (FcitxSubConfigWidget *self) | |
74 | { | |
75 | } | |
76 | ||
77 | FcitxSubConfigWidget* | |
78 | fcitx_sub_config_widget_new (FcitxSubConfig* subconfig) | |
79 | { | |
80 | FcitxSubConfigWidget* widget = g_object_new (FCITX_TYPE_SUB_CONFIG_WIDGET, NULL); | |
81 | ||
82 | widget->subconfig = subconfig; | |
83 | switch(subconfig->type) | |
84 | { | |
85 | case SC_ConfigFile: | |
86 | { | |
87 | GtkWidget* view = gtk_tree_view_new(); | |
88 | gtk_box_pack_start(GTK_BOX(widget), view, FALSE, FALSE, 0); | |
89 | ||
90 | GtkCellRenderer* renderer = gtk_cell_renderer_text_new(); | |
91 | GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("Name", renderer, "text", 0, NULL); | |
92 | gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); | |
93 | GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); | |
94 | gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); | |
95 | ||
96 | GtkListStore* store = gtk_list_store_new(1, G_TYPE_STRING); | |
97 | ||
98 | gtk_tree_view_set_model(GTK_TREE_VIEW(view), | |
99 | GTK_TREE_MODEL(store)); | |
100 | ||
101 | g_list_foreach(widget->subconfig->filelist, push_into_store_cb, store); | |
102 | ||
103 | GtkWidget* button = gtk_button_new(); | |
104 | gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_stock(GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_BUTTON)); | |
105 | g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(open_subconfig_file), widget); | |
106 | gtk_box_pack_start(GTK_BOX(widget), button, FALSE, FALSE, 0); | |
107 | widget->view = view; | |
108 | } | |
109 | break; | |
110 | case SC_NativeFile: | |
111 | { | |
112 | GtkWidget* button = gtk_button_new(); | |
113 | gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON)); | |
114 | g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(open_native_file), widget); | |
115 | gtk_box_pack_start(GTK_BOX(widget), button, FALSE, FALSE, 0); | |
116 | } | |
117 | break; | |
118 | default: | |
119 | break; | |
120 | } | |
121 | ||
122 | return widget; | |
123 | } | |
124 | ||
125 | void open_subconfig_file (GtkButton *button, | |
126 | gpointer user_data) | |
127 | { | |
128 | FcitxSubConfigWidget* widget = (FcitxSubConfigWidget*) user_data; | |
129 | GtkTreeView* view = GTK_TREE_VIEW(widget->view); | |
130 | GtkTreeSelection *selection = gtk_tree_view_get_selection(view); | |
131 | GtkTreeModel *model = gtk_tree_view_get_model(view); | |
132 | GtkTreeIter iter; | |
133 | gchar* configfile; | |
134 | if (gtk_tree_selection_get_selected(selection, &model, &iter)) | |
135 | { | |
136 | gtk_tree_model_get(model, &iter, | |
137 | 0, &configfile, | |
138 | -1); | |
139 | ConfigFileDesc* cfdesc = get_config_desc(widget->subconfig->configdesc); | |
140 | if (cfdesc) | |
141 | { | |
142 | GtkWidget* dialog = gtk_dialog_new_with_buttons(configfile, | |
143 | GTK_WINDOW(gtk_widget_get_ancestor(GTK_WIDGET(widget), GTK_TYPE_WINDOW)), | |
144 | GTK_DIALOG_MODAL, | |
145 | GTK_STOCK_OK, | |
146 | GTK_RESPONSE_OK, | |
147 | GTK_STOCK_CANCEL, | |
148 | GTK_RESPONSE_CANCEL, | |
149 | NULL | |
150 | ); | |
151 | FcitxConfigWidget* config_widget = fcitx_config_widget_new(cfdesc, "", configfile, NULL); | |
152 | GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); | |
153 | gtk_box_pack_start(GTK_BOX(content_area), GTK_WIDGET(config_widget), TRUE, TRUE, 0); | |
154 | gtk_widget_set_size_request(GTK_WIDGET(config_widget), -1, 400); | |
155 | ||
156 | g_signal_connect (dialog, "response", | |
157 | G_CALLBACK (response_cb), | |
158 | config_widget); | |
159 | ||
160 | gtk_widget_show_all (GTK_WIDGET(dialog)); | |
161 | } | |
162 | } | |
163 | } | |
164 | ||
165 | void open_native_file (GtkButton *button, | |
166 | gpointer user_data) | |
167 | { | |
168 | FcitxSubConfigWidget* widget = (FcitxSubConfigWidget*) user_data; | |
169 | char *newpath = NULL; | |
170 | if (g_list_length(widget->subconfig->filelist) > 0) | |
171 | { | |
172 | FILE* fp = GetXDGFileWithPrefix("", widget->subconfig->filelist->data, "r", &newpath); | |
173 | if (fp) | |
174 | fclose(fp); | |
175 | } | |
176 | else | |
177 | { | |
178 | FILE* fp = GetXDGFileUserWithPrefix("", widget->subconfig->nativepath, "w", &newpath); | |
179 | if (fp) | |
180 | { | |
181 | widget->subconfig->filelist = g_list_append(widget->subconfig->filelist, widget->subconfig->nativepath); | |
182 | fclose(fp); | |
183 | } | |
184 | } | |
185 | ||
186 | if (newpath) | |
187 | { | |
188 | GError* error; | |
189 | gchar* filename = newpath; | |
190 | gchar* argv[3]; | |
191 | argv[0] = "xdg-open"; | |
192 | argv[1] = filename; | |
193 | argv[2] = 0; | |
194 | g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error); | |
195 | free(newpath); | |
196 | } | |
197 | } | |
198 | ||
199 | ||
200 | void push_into_store_cb (gpointer data, | |
201 | gpointer user_data) | |
202 | { | |
203 | GtkListStore* store = user_data; | |
204 | ||
205 | GtkTreeIter iter; | |
206 | ||
207 | gtk_list_store_append(store, &iter); | |
208 | gtk_list_store_set(store, &iter, | |
209 | 0, data, | |
210 | -1); | |
211 | } |
0 | /*************************************************************************** | |
1 | * Copyright (C) 2010~2011 by CSSlayer * | |
2 | * * | |
3 | * This program is free software; you can redistribute it and/or modify * | |
4 | * it under the terms of the GNU General Public License as published by * | |
5 | * the Free Software Foundation; either version 2 of the License, or * | |
6 | * (at your option) any later version. * | |
7 | * * | |
8 | * This program is distributed in the hope that it will be useful, * | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
11 | * GNU General Public License for more details. * | |
12 | * * | |
13 | * You should have received a copy of the GNU General Public License * | |
14 | * along with this program; if not, write to the * | |
15 | * Free Software Foundation, Inc., * | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
17 | ***************************************************************************/ | |
18 | ||
19 | #ifndef _FCITX_SUB_CONFIG_WIDGET | |
20 | #define _FCITX_SUB_CONFIG_WIDGET | |
21 | ||
22 | #include <gtk/gtk.h> | |
23 | #include "sub_config_parser.h" | |
24 | ||
25 | G_BEGIN_DECLS | |
26 | ||
27 | #define FCITX_TYPE_SUB_CONFIG_WIDGET fcitx_sub_config_widget_get_type() | |
28 | ||
29 | #define FCITX_SUB_CONFIG_WIDGET(obj) \ | |
30 | (G_TYPE_CHECK_INSTANCE_CAST ((obj), FCITX_TYPE_SUB_CONFIG_WIDGET, FcitxSubConfigWidget)) | |
31 | ||
32 | #define FCITX_SUB_CONFIG_WIDGET_CLASS(klass) \ | |
33 | (G_TYPE_CHECK_CLASS_CAST ((klass), FCITX_TYPE_SUB_CONFIG_WIDGET, FcitxSubConfigWidgetClass)) | |
34 | ||
35 | #define FCITX_IS_SUB_CONFIG_WIDGET(obj) \ | |
36 | (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FCITX_TYPE_SUB_CONFIG_WIDGET)) | |
37 | ||
38 | #define FCITX_IS_SUB_CONFIG_WIDGET_CLASS(klass) \ | |
39 | (G_TYPE_CHECK_CLASS_TYPE ((klass), FCITX_TYPE_SUB_CONFIG_WIDGET)) | |
40 | ||
41 | #define FCITX_SUB_CONFIG_WIDGET_GET_CLASS(obj) \ | |
42 | (G_TYPE_INSTANCE_GET_CLASS ((obj), FCITX_TYPE_SUB_CONFIG_WIDGET, FcitxSubConfigWidgetClass)) | |
43 | ||
44 | typedef struct { | |
45 | GtkVBox parent; | |
46 | FcitxSubConfig* subconfig; | |
47 | GtkWidget* view; | |
48 | } FcitxSubConfigWidget; | |
49 | ||
50 | typedef struct { | |
51 | GtkVBoxClass parent_class; | |
52 | } FcitxSubConfigWidgetClass; | |
53 | ||
54 | GType fcitx_sub_config_widget_get_type (void); | |
55 | ||
56 | FcitxSubConfigWidget* fcitx_sub_config_widget_new (FcitxSubConfig* subconfig); | |
57 | ||
58 | G_END_DECLS | |
59 | ||
60 | #endif /* _FCITX_SUB_CONFIG_WIDGET */ |
0 | #include <limits.h> | |
1 | #include <dirent.h> | |
2 | #include <sys/stat.h> | |
3 | #include <stdlib.h> | |
4 | #include <stdio.h> | |
5 | #include <fcitx-config/xdg.h> | |
6 | ||
7 | #include "utarray.h" | |
8 | #include "uthash.h" | |
9 | #include "table_stuff.h" | |
10 | ||
11 | typedef struct StringHashSet { | |
12 | char *name; | |
13 | UT_hash_handle hh; | |
14 | } StringHashSet; | |
15 | ||
16 | static UT_array* tableBuf = NULL; | |
17 | ||
18 | /* | |
19 | * 读取码表输入法的名称和文件路径 | |
20 | */ | |
21 | UT_array* LoadTableInfo (void) | |
22 | { | |
23 | if (!tableBuf) | |
24 | { | |
25 | tableBuf = malloc(sizeof(UT_array)); | |
26 | utarray_init(tableBuf, &ut_str_icd); | |
27 | } | |
28 | else | |
29 | { | |
30 | utarray_clear(tableBuf); | |
31 | } | |
32 | ||
33 | char **tablePath; | |
34 | size_t len; | |
35 | char pathBuf[PATH_MAX]; | |
36 | int i = 0; | |
37 | DIR *dir; | |
38 | struct dirent *drt; | |
39 | struct stat fileStat; | |
40 | ||
41 | StringHashSet* sset = NULL; | |
42 | ||
43 | tablePath = GetXDGPath(&len, "XDG_CONFIG_HOME", ".config", "fcitx/table" , DATADIR, "fcitx/data/table" ); | |
44 | ||
45 | for(i = 0; i< len; i++) | |
46 | { | |
47 | snprintf(pathBuf, sizeof(pathBuf), "%s", tablePath[i]); | |
48 | pathBuf[sizeof(pathBuf) - 1] = '\0'; | |
49 | ||
50 | dir = opendir(pathBuf); | |
51 | if (dir == NULL) | |
52 | continue; | |
53 | ||
54 | /* collect all *.conf files */ | |
55 | while((drt = readdir(dir)) != NULL) | |
56 | { | |
57 | size_t nameLen = strlen(drt->d_name); | |
58 | if (nameLen <= strlen(".conf") ) | |
59 | continue; | |
60 | memset(pathBuf,0,sizeof(pathBuf)); | |
61 | ||
62 | if (strcmp(drt->d_name + nameLen -strlen(".conf"), ".conf") != 0) | |
63 | continue; | |
64 | snprintf(pathBuf, sizeof(pathBuf), "%s/%s", tablePath[i], drt->d_name ); | |
65 | ||
66 | if (stat(pathBuf, &fileStat) == -1) | |
67 | continue; | |
68 | ||
69 | if (fileStat.st_mode & S_IFREG) | |
70 | { | |
71 | StringHashSet *string; | |
72 | HASH_FIND_STR(sset, drt->d_name, string); | |
73 | if (!string) | |
74 | { | |
75 | char *bStr = strdup(drt->d_name); | |
76 | string = malloc(sizeof(StringHashSet)); | |
77 | memset(string, 0, sizeof(StringHashSet)); | |
78 | string->name = bStr; | |
79 | HASH_ADD_KEYPTR(hh, sset, string->name, strlen(string->name), string); | |
80 | } | |
81 | } | |
82 | } | |
83 | ||
84 | closedir(dir); | |
85 | } | |
86 | ||
87 | StringHashSet* string; | |
88 | for (string = sset; | |
89 | string != NULL; | |
90 | string = (StringHashSet*)string->hh.next) | |
91 | { | |
92 | char *temp = string->name; | |
93 | utarray_push_back(tableBuf, &temp); | |
94 | } | |
95 | ||
96 | FreeXDGPath(tablePath); | |
97 | ||
98 | StringHashSet *curStr; | |
99 | while(sset) | |
100 | { | |
101 | curStr = sset; | |
102 | HASH_DEL(sset, curStr); | |
103 | free(curStr->name); | |
104 | free(curStr); | |
105 | } | |
106 | ||
107 | return tableBuf; | |
108 | } | |
109 |
0 | /* | |
1 | Copyright (c) 2008-2010, Troy D. Hanson http://uthash.sourceforge.net | |
2 | All rights reserved. | |
3 | ||
4 | Redistribution and use in source and binary forms, with or without | |
5 | modification, are permitted provided that the following conditions are met: | |
6 | ||
7 | * Redistributions of source code must retain the above copyright | |
8 | notice, this list of conditions and the following disclaimer. | |
9 | ||
10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | |
11 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
12 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
13 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER | |
14 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
15 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
16 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
17 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
18 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
19 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
20 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
21 | */ | |
22 | ||
23 | /* a dynamic array implementation using macros | |
24 | * see http://uthash.sourceforge.net/utarray | |
25 | */ | |
26 | #ifndef UTARRAY_H | |
27 | #define UTARRAY_H | |
28 | ||
29 | #define UTARRAY_VERSION 1.9 | |
30 | ||
31 | #ifdef __GNUC__ | |
32 | #define _UNUSED_ __attribute__ ((__unused__)) | |
33 | #else | |
34 | #define _UNUSED_ | |
35 | #endif | |
36 | ||
37 | #include <stddef.h> /* size_t */ | |
38 | #include <string.h> /* memset, etc */ | |
39 | #include <stdlib.h> /* exit */ | |
40 | ||
41 | #define oom() exit(-1) | |
42 | ||
43 | typedef void (ctor_f)(void *dst, const void *src); | |
44 | typedef void (dtor_f)(void *elt); | |
45 | typedef void (init_f)(void *elt); | |
46 | typedef struct { | |
47 | size_t sz; | |
48 | init_f *init; | |
49 | ctor_f *copy; | |
50 | dtor_f *dtor; | |
51 | } UT_icd; | |
52 | ||
53 | typedef struct { | |
54 | unsigned i,n;/* i: index of next available slot, n: num slots */ | |
55 | const UT_icd *icd; /* initializer, copy and destructor functions */ | |
56 | char *d; /* n slots of size icd->sz*/ | |
57 | } UT_array; | |
58 | ||
59 | #define utarray_init(a,_icd) do { \ | |
60 | memset(a,0,sizeof(UT_array)); \ | |
61 | (a)->icd=_icd; \ | |
62 | } while(0) | |
63 | ||
64 | #define utarray_done(a) do { \ | |
65 | if ((a)->n) { \ | |
66 | if ((a)->icd->dtor) { \ | |
67 | size_t _ut_i; \ | |
68 | for(_ut_i=0; _ut_i < (a)->i; _ut_i++) { \ | |
69 | (a)->icd->dtor(utarray_eltptr(a,_ut_i)); \ | |
70 | } \ | |
71 | } \ | |
72 | free((a)->d); \ | |
73 | } \ | |
74 | (a)->n=0; \ | |
75 | } while(0) | |
76 | ||
77 | #define utarray_new(a,_icd) do { \ | |
78 | a=(UT_array*)malloc(sizeof(UT_array)); \ | |
79 | utarray_init(a,_icd); \ | |
80 | } while(0) | |
81 | ||
82 | #define utarray_free(a) do { \ | |
83 | utarray_done(a); \ | |
84 | free(a); \ | |
85 | } while(0) | |
86 | ||
87 | #define utarray_reserve(a,by) do { \ | |
88 | if (((a)->i+by) > ((a)->n)) { \ | |
89 | while(((a)->i+by) > ((a)->n)) { (a)->n = ((a)->n ? (2*(a)->n) : 8); } \ | |
90 | if ( ((a)->d=(char*)realloc((a)->d, (a)->n*(a)->icd->sz)) == NULL) oom(); \ | |
91 | } \ | |
92 | } while(0) | |
93 | ||
94 | #define utarray_push_back(a,p) do { \ | |
95 | utarray_reserve(a,1); \ | |
96 | if ((a)->icd->copy) { (a)->icd->copy( _utarray_eltptr(a,(a)->i++), p); } \ | |
97 | else { memcpy(_utarray_eltptr(a,(a)->i++), p, (a)->icd->sz); }; \ | |
98 | } while(0) | |
99 | ||
100 | #define utarray_pop_back(a) do { \ | |
101 | if ((a)->icd->dtor) { (a)->icd->dtor( _utarray_eltptr(a,--((a)->i))); } \ | |
102 | else { (a)->i--; } \ | |
103 | } while(0) | |
104 | ||
105 | #define utarray_extend_back(a) do { \ | |
106 | utarray_reserve(a,1); \ | |
107 | if ((a)->icd->init) { (a)->icd->init(_utarray_eltptr(a,(a)->i)); } \ | |
108 | else { memset(_utarray_eltptr(a,(a)->i),0,(a)->icd->sz); } \ | |
109 | (a)->i++; \ | |
110 | } while(0) | |
111 | ||
112 | #define utarray_len(a) ((a)->i) | |
113 | ||
114 | #define utarray_eltptr(a,j) (((j) < (a)->i) ? _utarray_eltptr(a,j) : NULL) | |
115 | #define _utarray_eltptr(a,j) ((char*)((a)->d + ((a)->icd->sz*(j) ))) | |
116 | ||
117 | #define utarray_insert(a,p,j) do { \ | |
118 | utarray_reserve(a,1); \ | |
119 | if (j > (a)->i) break; \ | |
120 | if ((j) < (a)->i) { \ | |
121 | memmove( _utarray_eltptr(a,(j)+1), _utarray_eltptr(a,j), \ | |
122 | ((a)->i - (j))*((a)->icd->sz)); \ | |
123 | } \ | |
124 | if ((a)->icd->copy) { (a)->icd->copy( _utarray_eltptr(a,j), p); } \ | |
125 | else { memcpy(_utarray_eltptr(a,j), p, (a)->icd->sz); }; \ | |
126 | (a)->i++; \ | |
127 | } while(0) | |
128 | ||
129 | #define utarray_inserta(a,w,j) do { \ | |
130 | if (utarray_len(w) == 0) break; \ | |
131 | if (j > (a)->i) break; \ | |
132 | utarray_reserve(a,utarray_len(w)); \ | |
133 | if ((j) < (a)->i) { \ | |
134 | memmove(_utarray_eltptr(a,(j)+utarray_len(w)), \ | |
135 | _utarray_eltptr(a,j), \ | |
136 | ((a)->i - (j))*((a)->icd->sz)); \ | |
137 | } \ | |
138 | if (a->icd->copy) { \ | |
139 | size_t _ut_i; \ | |
140 | for(_ut_i=0;_ut_i<(w)->i;_ut_i++) { \ | |
141 | (a)->icd->copy(_utarray_eltptr(a,j+_ut_i), _utarray_eltptr(w,_ut_i)); \ | |
142 | } \ | |
143 | } else { \ | |
144 | memcpy(_utarray_eltptr(a,j), _utarray_eltptr(w,0), \ | |
145 | utarray_len(w)*((a)->icd->sz)); \ | |
146 | } \ | |
147 | (a)->i += utarray_len(w); \ | |
148 | } while(0) | |
149 | ||
150 | #define utarray_resize(dst,num) do { \ | |
151 | size_t _ut_i; \ | |
152 | if (dst->i > (size_t)(num)) { \ | |
153 | if ((dst)->icd->dtor) { \ | |
154 | for(_ut_i=num; _ut_i < dst->i; _ut_i++) { \ | |
155 | (dst)->icd->dtor(utarray_eltptr(dst,_ut_i)); \ | |
156 | } \ | |
157 | } \ | |
158 | } else if (dst->i < (size_t)(num)) { \ | |
159 | utarray_reserve(dst,num-dst->i); \ | |
160 | if ((dst)->icd->init) { \ | |
161 | for(_ut_i=dst->i; _ut_i < num; _ut_i++) { \ | |
162 | (dst)->icd->init(utarray_eltptr(dst,_ut_i)); \ | |
163 | } \ | |
164 | } else { \ | |
165 | memset(_utarray_eltptr(dst,dst->i),0,(dst)->icd->sz*(num-dst->i)); \ | |
166 | } \ | |
167 | } \ | |
168 | dst->i = num; \ | |
169 | } while(0) | |
170 | ||
171 | #define utarray_concat(dst,src) do { \ | |
172 | utarray_inserta(dst,src,utarray_len(dst)); \ | |
173 | } while(0) | |
174 | ||
175 | #define utarray_erase(a,pos,len) do { \ | |
176 | if ((a)->icd->dtor) { \ | |
177 | size_t _ut_i; \ | |
178 | for(_ut_i=0; _ut_i < len; _ut_i++) { \ | |
179 | (a)->icd->dtor(utarray_eltptr(a,pos+_ut_i)); \ | |
180 | } \ | |
181 | } \ | |
182 | if ((a)->i > (pos+len)) { \ | |
183 | memmove( _utarray_eltptr(a,pos), _utarray_eltptr(a,pos+len), \ | |
184 | ((a->i)-(pos+len))*((a)->icd->sz)); \ | |
185 | } \ | |
186 | (a)->i -= (len); \ | |
187 | } while(0) | |
188 | ||
189 | #define utarray_clear(a) do { \ | |
190 | if ((a)->i > 0) { \ | |
191 | if ((a)->icd->dtor) { \ | |
192 | size_t _ut_i; \ | |
193 | for(_ut_i=0; _ut_i < (a)->i; _ut_i++) { \ | |
194 | (a)->icd->dtor(utarray_eltptr(a,_ut_i)); \ | |
195 | } \ | |
196 | } \ | |
197 | (a)->i = 0; \ | |
198 | } \ | |
199 | } while(0) | |
200 | ||
201 | #define utarray_sort(a,cmp) do { \ | |
202 | qsort((a)->d, (a)->i, (a)->icd->sz, cmp); \ | |
203 | } while(0) | |
204 | ||
205 | #define utarray_front(a) (((a)->i) ? (_utarray_eltptr(a,0)) : NULL) | |
206 | #define utarray_next(a,e) (((e)==NULL) ? utarray_front(a) : ((((a)->i) > (utarray_eltidx(a,e)+1)) ? _utarray_eltptr(a,utarray_eltidx(a,e)+1) : NULL)) | |
207 | #define utarray_back(a) (((a)->i) ? (_utarray_eltptr(a,(a)->i-1)) : NULL) | |
208 | #define utarray_eltidx(a,e) (((char*)(e) >= (char*)((a)->d)) ? (((char*)(e) - (char*)((a)->d))/(a)->icd->sz) : -1) | |
209 | ||
210 | /* last we pre-define a few icd for common utarrays of ints and strings */ | |
211 | static void utarray_str_cpy(void *dst, const void *src) { | |
212 | char **_src = (char**)src, **_dst = (char**)dst; | |
213 | *_dst = (*_src == NULL) ? NULL : strdup(*_src); | |
214 | } | |
215 | static void utarray_str_dtor(void *elt) { | |
216 | char **eltc = (char**)elt; | |
217 | if (*eltc) free(*eltc); | |
218 | } | |
219 | static const UT_icd ut_str_icd _UNUSED_ = {sizeof(char*),NULL,utarray_str_cpy,utarray_str_dtor}; | |
220 | static const UT_icd ut_int_icd _UNUSED_ = {sizeof(int),NULL,NULL,NULL}; | |
221 | ||
222 | #define utarray_custom_bsearch(key, a, acc, cmp) custom_bsearch((key), (a)->d, (a)->i, (a)->icd->sz, (acc), cmp ) | |
223 | ||
224 | #endif /* UTARRAY_H */ |
0 | /* | |
1 | Copyright (c) 2003-2009, Troy D. Hanson http://uthash.sourceforge.net | |
2 | All rights reserved. | |
3 | ||
4 | Redistribution and use in source and binary forms, with or without | |
5 | modification, are permitted provided that the following conditions are met: | |
6 | ||
7 | * Redistributions of source code must retain the above copyright | |
8 | notice, this list of conditions and the following disclaimer. | |
9 | ||
10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | |
11 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
12 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
13 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER | |
14 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
15 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
16 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
17 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
18 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
19 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
20 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
21 | */ | |
22 | ||
23 | #ifndef UTHASH_H | |
24 | #define UTHASH_H | |
25 | ||
26 | #include <string.h> /* memcmp,strlen */ | |
27 | #include <stddef.h> /* ptrdiff_t */ | |
28 | #include <inttypes.h> /* uint32_t etc */ | |
29 | ||
30 | #define UTHASH_VERSION 1.8 | |
31 | ||
32 | /* C++ requires extra stringent casting */ | |
33 | #if defined __cplusplus | |
34 | #define TYPEOF(x) (typeof(x)) | |
35 | #else | |
36 | #define TYPEOF(x) | |
37 | #endif | |
38 | ||
39 | ||
40 | #define uthash_fatal(msg) exit(-1) /* fatal error (out of memory,etc) */ | |
41 | #define uthash_malloc(sz) malloc(sz) /* malloc fcn */ | |
42 | #define uthash_free(ptr) free(ptr) /* free fcn */ | |
43 | ||
44 | #define uthash_noexpand_fyi(tbl) /* can be defined to log noexpand */ | |
45 | #define uthash_expand_fyi(tbl) /* can be defined to log expands */ | |
46 | ||
47 | /* initial number of buckets */ | |
48 | #define HASH_INITIAL_NUM_BUCKETS 32 /* initial number of buckets */ | |
49 | #define HASH_INITIAL_NUM_BUCKETS_LOG2 5 /* lg2 of initial number of buckets */ | |
50 | #define HASH_BKT_CAPACITY_THRESH 10 /* expand when bucket count reaches */ | |
51 | ||
52 | /* calculate the element whose hash handle address is hhe */ | |
53 | #define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)hhp) - (tbl)->hho)) | |
54 | ||
55 | #define HASH_FIND(hh,head,keyptr,keylen,out) \ | |
56 | do { \ | |
57 | unsigned _hf_bkt,_hf_hashv; \ | |
58 | out=TYPEOF(out)NULL; \ | |
59 | if (head) { \ | |
60 | HASH_FCN(keyptr,keylen, (head)->hh.tbl->num_buckets, _hf_hashv, _hf_bkt); \ | |
61 | if (HASH_BLOOM_TEST((head)->hh.tbl, _hf_hashv)) { \ | |
62 | HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ], \ | |
63 | keyptr,keylen,out); \ | |
64 | } \ | |
65 | } \ | |
66 | } while (0) | |
67 | ||
68 | #ifdef HASH_BLOOM | |
69 | #define HASH_BLOOM_BITLEN (1ULL << HASH_BLOOM) | |
70 | #define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8) + ((HASH_BLOOM_BITLEN%8) ? 1:0) | |
71 | #define HASH_BLOOM_MAKE(tbl) \ | |
72 | do { \ | |
73 | (tbl)->bloom_nbits = HASH_BLOOM; \ | |
74 | (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN); \ | |
75 | if (!((tbl)->bloom_bv)) { uthash_fatal( "out of memory"); } \ | |
76 | memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN); \ | |
77 | (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE; \ | |
78 | } while (0); | |
79 | ||
80 | #define HASH_BLOOM_FREE(tbl) \ | |
81 | do { \ | |
82 | uthash_free((tbl)->bloom_bv); \ | |
83 | } while (0); | |
84 | ||
85 | #define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8))) | |
86 | #define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8))) | |
87 | ||
88 | #define HASH_BLOOM_ADD(tbl,hashv) \ | |
89 | HASH_BLOOM_BITSET((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) | |
90 | ||
91 | #define HASH_BLOOM_TEST(tbl,hashv) \ | |
92 | HASH_BLOOM_BITTEST((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) | |
93 | ||
94 | #else | |
95 | #define HASH_BLOOM_MAKE(tbl) | |
96 | #define HASH_BLOOM_FREE(tbl) | |
97 | #define HASH_BLOOM_ADD(tbl,hashv) | |
98 | #define HASH_BLOOM_TEST(tbl,hashv) (1) | |
99 | #endif | |
100 | ||
101 | #define HASH_MAKE_TABLE(hh,head) \ | |
102 | do { \ | |
103 | (head)->hh.tbl = (UT_hash_table*)uthash_malloc( \ | |
104 | sizeof(UT_hash_table)); \ | |
105 | if (!((head)->hh.tbl)) { uthash_fatal( "out of memory"); } \ | |
106 | memset((head)->hh.tbl, 0, sizeof(UT_hash_table)); \ | |
107 | (head)->hh.tbl->tail = &((head)->hh); \ | |
108 | (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \ | |
109 | (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \ | |
110 | (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head); \ | |
111 | (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc( \ | |
112 | HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ | |
113 | if (! (head)->hh.tbl->buckets) { uthash_fatal( "out of memory"); } \ | |
114 | memset((head)->hh.tbl->buckets, 0, \ | |
115 | HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ | |
116 | HASH_BLOOM_MAKE((head)->hh.tbl); \ | |
117 | (head)->hh.tbl->signature = HASH_SIGNATURE; \ | |
118 | } while(0) | |
119 | ||
120 | #define HASH_ADD(hh,head,fieldname,keylen_in,add) \ | |
121 | HASH_ADD_KEYPTR(hh,head,&add->fieldname,keylen_in,add) | |
122 | ||
123 | #define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add) \ | |
124 | do { \ | |
125 | unsigned _ha_bkt; \ | |
126 | (add)->hh.next = NULL; \ | |
127 | (add)->hh.key = (char*)keyptr; \ | |
128 | (add)->hh.keylen = keylen_in; \ | |
129 | if (!(head)) { \ | |
130 | head = (add); \ | |
131 | (head)->hh.prev = NULL; \ | |
132 | HASH_MAKE_TABLE(hh,head); \ | |
133 | } else { \ | |
134 | (head)->hh.tbl->tail->next = (add); \ | |
135 | (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail); \ | |
136 | (head)->hh.tbl->tail = &((add)->hh); \ | |
137 | } \ | |
138 | (head)->hh.tbl->num_items++; \ | |
139 | (add)->hh.tbl = (head)->hh.tbl; \ | |
140 | HASH_FCN(keyptr,keylen_in, (head)->hh.tbl->num_buckets, \ | |
141 | (add)->hh.hashv, _ha_bkt); \ | |
142 | HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt],&(add)->hh); \ | |
143 | HASH_BLOOM_ADD((head)->hh.tbl,(add)->hh.hashv); \ | |
144 | HASH_EMIT_KEY(hh,head,keyptr,keylen_in); \ | |
145 | HASH_FSCK(hh,head); \ | |
146 | } while(0) | |
147 | ||
148 | #define HASH_TO_BKT( hashv, num_bkts, bkt ) \ | |
149 | do { \ | |
150 | bkt = ((hashv) & ((num_bkts) - 1)); \ | |
151 | } while(0) | |
152 | ||
153 | /* delete "delptr" from the hash table. | |
154 | * "the usual" patch-up process for the app-order doubly-linked-list. | |
155 | * The use of _hd_hh_del below deserves special explanation. | |
156 | * These used to be expressed using (delptr) but that led to a bug | |
157 | * if someone used the same symbol for the head and deletee, like | |
158 | * HASH_DELETE(hh,users,users); | |
159 | * We want that to work, but by changing the head (users) below | |
160 | * we were forfeiting our ability to further refer to the deletee (users) | |
161 | * in the patch-up process. Solution: use scratch space in the table to | |
162 | * copy the deletee pointer, then the latter references are via that | |
163 | * scratch pointer rather than through the repointed (users) symbol. | |
164 | */ | |
165 | #define HASH_DELETE(hh,head,delptr) \ | |
166 | do { \ | |
167 | unsigned _hd_bkt; \ | |
168 | struct UT_hash_handle *_hd_hh_del; \ | |
169 | if ( ((delptr)->hh.prev == NULL) && ((delptr)->hh.next == NULL) ) { \ | |
170 | uthash_free((head)->hh.tbl->buckets ); \ | |
171 | HASH_BLOOM_FREE((head)->hh.tbl); \ | |
172 | uthash_free((head)->hh.tbl); \ | |
173 | head = NULL; \ | |
174 | } else { \ | |
175 | _hd_hh_del = &((delptr)->hh); \ | |
176 | if ((delptr) == ELMT_FROM_HH((head)->hh.tbl,(head)->hh.tbl->tail)) { \ | |
177 | (head)->hh.tbl->tail = \ | |
178 | (UT_hash_handle*)((char*)((delptr)->hh.prev) + \ | |
179 | (head)->hh.tbl->hho); \ | |
180 | } \ | |
181 | if ((delptr)->hh.prev) { \ | |
182 | ((UT_hash_handle*)((char*)((delptr)->hh.prev) + \ | |
183 | (head)->hh.tbl->hho))->next = (delptr)->hh.next; \ | |
184 | } else { \ | |
185 | head = TYPEOF(head)((delptr)->hh.next); \ | |
186 | } \ | |
187 | if (_hd_hh_del->next) { \ | |
188 | ((UT_hash_handle*)((char*)_hd_hh_del->next + \ | |
189 | (head)->hh.tbl->hho))->prev = \ | |
190 | _hd_hh_del->prev; \ | |
191 | } \ | |
192 | HASH_TO_BKT( _hd_hh_del->hashv, (head)->hh.tbl->num_buckets, _hd_bkt); \ | |
193 | HASH_DEL_IN_BKT(hh,(head)->hh.tbl->buckets[_hd_bkt], _hd_hh_del); \ | |
194 | (head)->hh.tbl->num_items--; \ | |
195 | } \ | |
196 | HASH_FSCK(hh,head); \ | |
197 | } while (0) | |
198 | ||
199 | ||
200 | /* convenience forms of HASH_FIND/HASH_ADD/HASH_DEL */ | |
201 | #define HASH_FIND_STR(head,findstr,out) \ | |
202 | HASH_FIND(hh,head,findstr,strlen(findstr),out) | |
203 | #define HASH_ADD_STR(head,strfield,add) \ | |
204 | HASH_ADD(hh,head,strfield,strlen(add->strfield),add) | |
205 | #define HASH_FIND_INT(head,findint,out) \ | |
206 | HASH_FIND(hh,head,findint,sizeof(int),out) | |
207 | #define HASH_ADD_INT(head,intfield,add) \ | |
208 | HASH_ADD(hh,head,intfield,sizeof(int),add) | |
209 | #define HASH_DEL(head,delptr) \ | |
210 | HASH_DELETE(hh,head,delptr) | |
211 | ||
212 | /* HASH_FSCK checks hash integrity on every add/delete when HASH_DEBUG is defined. | |
213 | * This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined. | |
214 | */ | |
215 | #ifdef HASH_DEBUG | |
216 | #define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); exit(-1); } while (0) | |
217 | #define HASH_FSCK(hh,head) \ | |
218 | do { \ | |
219 | unsigned _bkt_i; \ | |
220 | unsigned _count, _bkt_count; \ | |
221 | char *_prev; \ | |
222 | struct UT_hash_handle *_thh; \ | |
223 | if (head) { \ | |
224 | _count = 0; \ | |
225 | for( _bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; _bkt_i++) { \ | |
226 | _bkt_count = 0; \ | |
227 | _thh = (head)->hh.tbl->buckets[_bkt_i].hh_head; \ | |
228 | _prev = NULL; \ | |
229 | while (_thh) { \ | |
230 | if (_prev != (char*)(_thh->hh_prev)) { \ | |
231 | HASH_OOPS("invalid hh_prev %p, actual %p\n", \ | |
232 | _thh->hh_prev, _prev ); \ | |
233 | } \ | |
234 | _bkt_count++; \ | |
235 | _prev = (char*)(_thh); \ | |
236 | _thh = _thh->hh_next; \ | |
237 | } \ | |
238 | _count += _bkt_count; \ | |
239 | if ((head)->hh.tbl->buckets[_bkt_i].count != _bkt_count) { \ | |
240 | HASH_OOPS("invalid bucket count %d, actual %d\n", \ | |
241 | (head)->hh.tbl->buckets[_bkt_i].count, _bkt_count); \ | |
242 | } \ | |
243 | } \ | |
244 | if (_count != (head)->hh.tbl->num_items) { \ | |
245 | HASH_OOPS("invalid hh item count %d, actual %d\n", \ | |
246 | (head)->hh.tbl->num_items, _count ); \ | |
247 | } \ | |
248 | /* traverse hh in app order; check next/prev integrity, count */ \ | |
249 | _count = 0; \ | |
250 | _prev = NULL; \ | |
251 | _thh = &(head)->hh; \ | |
252 | while (_thh) { \ | |
253 | _count++; \ | |
254 | if (_prev !=(char*)(_thh->prev)) { \ | |
255 | HASH_OOPS("invalid prev %p, actual %p\n", \ | |
256 | _thh->prev, _prev ); \ | |
257 | } \ | |
258 | _prev = (char*)ELMT_FROM_HH((head)->hh.tbl, _thh); \ | |
259 | _thh = ( _thh->next ? (UT_hash_handle*)((char*)(_thh->next) + \ | |
260 | (head)->hh.tbl->hho) : NULL ); \ | |
261 | } \ | |
262 | if (_count != (head)->hh.tbl->num_items) { \ | |
263 | HASH_OOPS("invalid app item count %d, actual %d\n", \ | |
264 | (head)->hh.tbl->num_items, _count ); \ | |
265 | } \ | |
266 | } \ | |
267 | } while (0) | |
268 | #else | |
269 | #define HASH_FSCK(hh,head) | |
270 | #endif | |
271 | ||
272 | /* When compiled with -DHASH_EMIT_KEYS, length-prefixed keys are emitted to | |
273 | * the descriptor to which this macro is defined for tuning the hash function. | |
274 | * The app can #include <unistd.h> to get the prototype for write(2). */ | |
275 | #ifdef HASH_EMIT_KEYS | |
276 | #define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) \ | |
277 | do { \ | |
278 | unsigned _klen = fieldlen; \ | |
279 | write(HASH_EMIT_KEYS, &_klen, sizeof(_klen)); \ | |
280 | write(HASH_EMIT_KEYS, keyptr, fieldlen); \ | |
281 | } while (0) | |
282 | #else | |
283 | #define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) | |
284 | #endif | |
285 | ||
286 | /* default to Jenkin's hash unless overridden e.g. DHASH_FUNCTION=HASH_SAX */ | |
287 | #ifdef HASH_FUNCTION | |
288 | #define HASH_FCN HASH_FUNCTION | |
289 | #else | |
290 | #define HASH_FCN HASH_JEN | |
291 | #endif | |
292 | ||
293 | /* The Bernstein hash function, used in Perl prior to v5.6 */ | |
294 | #define HASH_BER(key,keylen,num_bkts,hashv,bkt) \ | |
295 | do { \ | |
296 | unsigned _hb_keylen=keylen; \ | |
297 | char *_hb_key=(char*)key; \ | |
298 | (hashv) = 0; \ | |
299 | while (_hb_keylen--) { (hashv) = ((hashv) * 33) + *_hb_key++; } \ | |
300 | bkt = (hashv) & (num_bkts-1); \ | |
301 | } while (0) | |
302 | ||
303 | ||
304 | /* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at | |
305 | * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */ | |
306 | #define HASH_SAX(key,keylen,num_bkts,hashv,bkt) \ | |
307 | do { \ | |
308 | unsigned _sx_i; \ | |
309 | char *_hs_key=(char*)key; \ | |
310 | hashv = 0; \ | |
311 | for(_sx_i=0; _sx_i < keylen; _sx_i++) \ | |
312 | hashv ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i]; \ | |
313 | bkt = hashv & (num_bkts-1); \ | |
314 | } while (0) | |
315 | ||
316 | #define HASH_FNV(key,keylen,num_bkts,hashv,bkt) \ | |
317 | do { \ | |
318 | unsigned _fn_i; \ | |
319 | char *_hf_key=(char*)key; \ | |
320 | hashv = 2166136261UL; \ | |
321 | for(_fn_i=0; _fn_i < keylen; _fn_i++) \ | |
322 | hashv = (hashv * 16777619) ^ _hf_key[_fn_i]; \ | |
323 | bkt = hashv & (num_bkts-1); \ | |
324 | } while(0); | |
325 | ||
326 | #define HASH_OAT(key,keylen,num_bkts,hashv,bkt) \ | |
327 | do { \ | |
328 | unsigned _ho_i; \ | |
329 | char *_ho_key=(char*)key; \ | |
330 | hashv = 0; \ | |
331 | for(_ho_i=0; _ho_i < keylen; _ho_i++) { \ | |
332 | hashv += _ho_key[_ho_i]; \ | |
333 | hashv += (hashv << 10); \ | |
334 | hashv ^= (hashv >> 6); \ | |
335 | } \ | |
336 | hashv += (hashv << 3); \ | |
337 | hashv ^= (hashv >> 11); \ | |
338 | hashv += (hashv << 15); \ | |
339 | bkt = hashv & (num_bkts-1); \ | |
340 | } while(0) | |
341 | ||
342 | #define HASH_JEN_MIX(a,b,c) \ | |
343 | do { \ | |
344 | a -= b; a -= c; a ^= ( c >> 13 ); \ | |
345 | b -= c; b -= a; b ^= ( a << 8 ); \ | |
346 | c -= a; c -= b; c ^= ( b >> 13 ); \ | |
347 | a -= b; a -= c; a ^= ( c >> 12 ); \ | |
348 | b -= c; b -= a; b ^= ( a << 16 ); \ | |
349 | c -= a; c -= b; c ^= ( b >> 5 ); \ | |
350 | a -= b; a -= c; a ^= ( c >> 3 ); \ | |
351 | b -= c; b -= a; b ^= ( a << 10 ); \ | |
352 | c -= a; c -= b; c ^= ( b >> 15 ); \ | |
353 | } while (0) | |
354 | ||
355 | #define HASH_JEN(key,keylen,num_bkts,hashv,bkt) \ | |
356 | do { \ | |
357 | unsigned _hj_i,_hj_j,_hj_k; \ | |
358 | char *_hj_key=(char*)key; \ | |
359 | hashv = 0xfeedbeef; \ | |
360 | _hj_i = _hj_j = 0x9e3779b9; \ | |
361 | _hj_k = keylen; \ | |
362 | while (_hj_k >= 12) { \ | |
363 | _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) \ | |
364 | + ( (unsigned)_hj_key[2] << 16 ) \ | |
365 | + ( (unsigned)_hj_key[3] << 24 ) ); \ | |
366 | _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) \ | |
367 | + ( (unsigned)_hj_key[6] << 16 ) \ | |
368 | + ( (unsigned)_hj_key[7] << 24 ) ); \ | |
369 | hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) \ | |
370 | + ( (unsigned)_hj_key[10] << 16 ) \ | |
371 | + ( (unsigned)_hj_key[11] << 24 ) ); \ | |
372 | \ | |
373 | HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ | |
374 | \ | |
375 | _hj_key += 12; \ | |
376 | _hj_k -= 12; \ | |
377 | } \ | |
378 | hashv += keylen; \ | |
379 | switch ( _hj_k ) { \ | |
380 | case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); \ | |
381 | case 10: hashv += ( (unsigned)_hj_key[9] << 16 ); \ | |
382 | case 9: hashv += ( (unsigned)_hj_key[8] << 8 ); \ | |
383 | case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); \ | |
384 | case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); \ | |
385 | case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); \ | |
386 | case 5: _hj_j += _hj_key[4]; \ | |
387 | case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); \ | |
388 | case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); \ | |
389 | case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); \ | |
390 | case 1: _hj_i += _hj_key[0]; \ | |
391 | } \ | |
392 | HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ | |
393 | bkt = hashv & (num_bkts-1); \ | |
394 | } while(0) | |
395 | ||
396 | /* The Paul Hsieh hash function */ | |
397 | #undef get16bits | |
398 | #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ | |
399 | || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) | |
400 | #define get16bits(d) (*((const uint16_t *) (d))) | |
401 | #endif | |
402 | ||
403 | #if !defined (get16bits) | |
404 | #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) \ | |
405 | +(uint32_t)(((const uint8_t *)(d))[0]) ) | |
406 | #endif | |
407 | #define HASH_SFH(key,keylen,num_bkts,hashv,bkt) \ | |
408 | do { \ | |
409 | char *_sfh_key=(char*)key; \ | |
410 | uint32_t _sfh_tmp, _sfh_len = keylen; \ | |
411 | \ | |
412 | int _sfh_rem = _sfh_len & 3; \ | |
413 | _sfh_len >>= 2; \ | |
414 | hashv = 0xcafebabe; \ | |
415 | \ | |
416 | /* Main loop */ \ | |
417 | for (;_sfh_len > 0; _sfh_len--) { \ | |
418 | hashv += get16bits (_sfh_key); \ | |
419 | _sfh_tmp = (get16bits (_sfh_key+2) << 11) ^ hashv; \ | |
420 | hashv = (hashv << 16) ^ _sfh_tmp; \ | |
421 | _sfh_key += 2*sizeof (uint16_t); \ | |
422 | hashv += hashv >> 11; \ | |
423 | } \ | |
424 | \ | |
425 | /* Handle end cases */ \ | |
426 | switch (_sfh_rem) { \ | |
427 | case 3: hashv += get16bits (_sfh_key); \ | |
428 | hashv ^= hashv << 16; \ | |
429 | hashv ^= _sfh_key[sizeof (uint16_t)] << 18; \ | |
430 | hashv += hashv >> 11; \ | |
431 | break; \ | |
432 | case 2: hashv += get16bits (_sfh_key); \ | |
433 | hashv ^= hashv << 11; \ | |
434 | hashv += hashv >> 17; \ | |
435 | break; \ | |
436 | case 1: hashv += *_sfh_key; \ | |
437 | hashv ^= hashv << 10; \ | |
438 | hashv += hashv >> 1; \ | |
439 | } \ | |
440 | \ | |
441 | /* Force "avalanching" of final 127 bits */ \ | |
442 | hashv ^= hashv << 3; \ | |
443 | hashv += hashv >> 5; \ | |
444 | hashv ^= hashv << 4; \ | |
445 | hashv += hashv >> 17; \ | |
446 | hashv ^= hashv << 25; \ | |
447 | hashv += hashv >> 6; \ | |
448 | bkt = hashv & (num_bkts-1); \ | |
449 | } while(0); | |
450 | ||
451 | #ifdef HASH_USING_NO_STRICT_ALIASING | |
452 | /* The MurmurHash exploits some CPU's (e.g. x86) tolerance for unaligned reads. | |
453 | * For other types of CPU's (e.g. Sparc) an unaligned read causes a bus error. | |
454 | * So MurmurHash comes in two versions, the faster unaligned one and the slower | |
455 | * aligned one. We only use the faster one on CPU's where we know it's safe. | |
456 | * | |
457 | * Note the preprocessor built-in defines can be emitted using: | |
458 | * | |
459 | * gcc -m64 -dM -E - < /dev/null (on gcc) | |
460 | * cc -## a.c (where a.c is a simple test file) (Sun Studio) | |
461 | */ | |
462 | #if (defined(__i386__) || defined(__x86_64__)) | |
463 | #define HASH_MUR HASH_MUR_UNALIGNED | |
464 | #else | |
465 | #define HASH_MUR HASH_MUR_ALIGNED | |
466 | #endif | |
467 | ||
468 | /* Appleby's MurmurHash fast version for unaligned-tolerant archs like i386 */ | |
469 | #define HASH_MUR_UNALIGNED(key,keylen,num_bkts,hashv,bkt) \ | |
470 | do { \ | |
471 | const unsigned int _mur_m = 0x5bd1e995; \ | |
472 | const int _mur_r = 24; \ | |
473 | hashv = 0xcafebabe ^ keylen; \ | |
474 | char *_mur_key = (char *)key; \ | |
475 | uint32_t _mur_tmp, _mur_len = keylen; \ | |
476 | \ | |
477 | for (;_mur_len >= 4; _mur_len-=4) { \ | |
478 | _mur_tmp = *(uint32_t *)_mur_key; \ | |
479 | _mur_tmp *= _mur_m; \ | |
480 | _mur_tmp ^= _mur_tmp >> _mur_r; \ | |
481 | _mur_tmp *= _mur_m; \ | |
482 | hashv *= _mur_m; \ | |
483 | hashv ^= _mur_tmp; \ | |
484 | _mur_key += 4; \ | |
485 | } \ | |
486 | \ | |
487 | switch(_mur_len) \ | |
488 | { \ | |
489 | case 3: hashv ^= _mur_key[2] << 16; \ | |
490 | case 2: hashv ^= _mur_key[1] << 8; \ | |
491 | case 1: hashv ^= _mur_key[0]; \ | |
492 | hashv *= _mur_m; \ | |
493 | }; \ | |
494 | \ | |
495 | hashv ^= hashv >> 13; \ | |
496 | hashv *= _mur_m; \ | |
497 | hashv ^= hashv >> 15; \ | |
498 | \ | |
499 | bkt = hashv & (num_bkts-1); \ | |
500 | } while(0) | |
501 | ||
502 | /* Appleby's MurmurHash version for alignment-sensitive archs like Sparc */ | |
503 | #define HASH_MUR_ALIGNED(key,keylen,num_bkts,hashv,bkt) \ | |
504 | do { \ | |
505 | const unsigned int _mur_m = 0x5bd1e995; \ | |
506 | const int _mur_r = 24; \ | |
507 | hashv = 0xcafebabe ^ keylen; \ | |
508 | char *_mur_key = (char *)key; \ | |
509 | uint32_t _mur_len = keylen; \ | |
510 | int _mur_align = (int)_mur_key & 3; \ | |
511 | \ | |
512 | if (_mur_align && (_mur_len >= 4)) { \ | |
513 | unsigned _mur_t = 0, _mur_d = 0; \ | |
514 | switch(_mur_align) { \ | |
515 | case 1: _mur_t |= _mur_key[2] << 16; \ | |
516 | case 2: _mur_t |= _mur_key[1] << 8; \ | |
517 | case 3: _mur_t |= _mur_key[0]; \ | |
518 | } \ | |
519 | _mur_t <<= (8 * _mur_align); \ | |
520 | _mur_key += 4-_mur_align; \ | |
521 | _mur_len -= 4-_mur_align; \ | |
522 | int _mur_sl = 8 * (4-_mur_align); \ | |
523 | int _mur_sr = 8 * _mur_align; \ | |
524 | \ | |
525 | for (;_mur_len >= 4; _mur_len-=4) { \ | |
526 | _mur_d = *(unsigned *)_mur_key; \ | |
527 | _mur_t = (_mur_t >> _mur_sr) | (_mur_d << _mur_sl); \ | |
528 | unsigned _mur_k = _mur_t; \ | |
529 | _mur_k *= _mur_m; \ | |
530 | _mur_k ^= _mur_k >> _mur_r; \ | |
531 | _mur_k *= _mur_m; \ | |
532 | hashv *= _mur_m; \ | |
533 | hashv ^= _mur_k; \ | |
534 | _mur_t = _mur_d; \ | |
535 | _mur_key += 4; \ | |
536 | } \ | |
537 | _mur_d = 0; \ | |
538 | if(_mur_len >= _mur_align) { \ | |
539 | switch(_mur_align) { \ | |
540 | case 3: _mur_d |= _mur_key[2] << 16; \ | |
541 | case 2: _mur_d |= _mur_key[1] << 8; \ | |
542 | case 1: _mur_d |= _mur_key[0]; \ | |
543 | } \ | |
544 | unsigned _mur_k = (_mur_t >> _mur_sr) | (_mur_d << _mur_sl); \ | |
545 | _mur_k *= _mur_m; \ | |
546 | _mur_k ^= _mur_k >> _mur_r; \ | |
547 | _mur_k *= _mur_m; \ | |
548 | hashv *= _mur_m; \ | |
549 | hashv ^= _mur_k; \ | |
550 | _mur_k += _mur_align; \ | |
551 | _mur_len -= _mur_align; \ | |
552 | \ | |
553 | switch(_mur_len) \ | |
554 | { \ | |
555 | case 3: hashv ^= _mur_key[2] << 16; \ | |
556 | case 2: hashv ^= _mur_key[1] << 8; \ | |
557 | case 1: hashv ^= _mur_key[0]; \ | |
558 | hashv *= _mur_m; \ | |
559 | } \ | |
560 | } else { \ | |
561 | switch(_mur_len) \ | |
562 | { \ | |
563 | case 3: _mur_d ^= _mur_key[2] << 16; \ | |
564 | case 2: _mur_d ^= _mur_key[1] << 8; \ | |
565 | case 1: _mur_d ^= _mur_key[0]; \ | |
566 | case 0: hashv ^= (_mur_t >> _mur_sr) | (_mur_d << _mur_sl); \ | |
567 | hashv *= _mur_m; \ | |
568 | } \ | |
569 | } \ | |
570 | \ | |
571 | hashv ^= hashv >> 13; \ | |
572 | hashv *= _mur_m; \ | |
573 | hashv ^= hashv >> 15; \ | |
574 | } else { \ | |
575 | for (;_mur_len >= 4; _mur_len-=4) { \ | |
576 | unsigned _mur_k = *(unsigned*)_mur_key; \ | |
577 | _mur_k *= _mur_m; \ | |
578 | _mur_k ^= _mur_k >> _mur_r; \ | |
579 | _mur_k *= _mur_m; \ | |
580 | hashv *= _mur_m; \ | |
581 | hashv ^= _mur_k; \ | |
582 | _mur_key += 4; \ | |
583 | } \ | |
584 | switch(_mur_len) \ | |
585 | { \ | |
586 | case 3: hashv ^= _mur_key[2] << 16; \ | |
587 | case 2: hashv ^= _mur_key[1] << 8; \ | |
588 | case 1: hashv ^= _mur_key[0]; \ | |
589 | hashv *= _mur_m; \ | |
590 | } \ | |
591 | \ | |
592 | hashv ^= hashv >> 13; \ | |
593 | hashv *= _mur_m; \ | |
594 | hashv ^= hashv >> 15; \ | |
595 | } \ | |
596 | bkt = hashv & (num_bkts-1); \ | |
597 | } while(0) | |
598 | #endif /* HASH_USING_NO_STRICT_ALIASING */ | |
599 | ||
600 | /* key comparison function; return 0 if keys equal */ | |
601 | #define HASH_KEYCMP(a,b,len) memcmp(a,b,len) | |
602 | ||
603 | /* iterate over items in a known bucket to find desired item */ | |
604 | #define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,out) \ | |
605 | out = TYPEOF(out)((head.hh_head) ? ELMT_FROM_HH(tbl,head.hh_head) : NULL); \ | |
606 | while (out) { \ | |
607 | if (out->hh.keylen == keylen_in) { \ | |
608 | if ((HASH_KEYCMP(out->hh.key,keyptr,keylen_in)) == 0) break; \ | |
609 | } \ | |
610 | out= TYPEOF(out)((out->hh.hh_next) ? \ | |
611 | ELMT_FROM_HH(tbl,out->hh.hh_next) : NULL); \ | |
612 | } | |
613 | ||
614 | /* add an item to a bucket */ | |
615 | #define HASH_ADD_TO_BKT(head,addhh) \ | |
616 | do { \ | |
617 | head.count++; \ | |
618 | (addhh)->hh_next = head.hh_head; \ | |
619 | (addhh)->hh_prev = NULL; \ | |
620 | if (head.hh_head) { (head).hh_head->hh_prev = (addhh); } \ | |
621 | (head).hh_head=addhh; \ | |
622 | if (head.count >= ((head.expand_mult+1) * HASH_BKT_CAPACITY_THRESH) \ | |
623 | && (addhh)->tbl->noexpand != 1) { \ | |
624 | HASH_EXPAND_BUCKETS((addhh)->tbl); \ | |
625 | } \ | |
626 | } while(0) | |
627 | ||
628 | /* remove an item from a given bucket */ | |
629 | #define HASH_DEL_IN_BKT(hh,head,hh_del) \ | |
630 | (head).count--; \ | |
631 | if ((head).hh_head == hh_del) { \ | |
632 | (head).hh_head = hh_del->hh_next; \ | |
633 | } \ | |
634 | if (hh_del->hh_prev) { \ | |
635 | hh_del->hh_prev->hh_next = hh_del->hh_next; \ | |
636 | } \ | |
637 | if (hh_del->hh_next) { \ | |
638 | hh_del->hh_next->hh_prev = hh_del->hh_prev; \ | |
639 | } | |
640 | ||
641 | /* Bucket expansion has the effect of doubling the number of buckets | |
642 | * and redistributing the items into the new buckets. Ideally the | |
643 | * items will distribute more or less evenly into the new buckets | |
644 | * (the extent to which this is true is a measure of the quality of | |
645 | * the hash function as it applies to the key domain). | |
646 | * | |
647 | * With the items distributed into more buckets, the chain length | |
648 | * (item count) in each bucket is reduced. Thus by expanding buckets | |
649 | * the hash keeps a bound on the chain length. This bounded chain | |
650 | * length is the essence of how a hash provides constant time lookup. | |
651 | * | |
652 | * The calculation of tbl->ideal_chain_maxlen below deserves some | |
653 | * explanation. First, keep in mind that we're calculating the ideal | |
654 | * maximum chain length based on the *new* (doubled) bucket count. | |
655 | * In fractions this is just n/b (n=number of items,b=new num buckets). | |
656 | * Since the ideal chain length is an integer, we want to calculate | |
657 | * ceil(n/b). We don't depend on floating point arithmetic in this | |
658 | * hash, so to calculate ceil(n/b) with integers we could write | |
659 | * | |
660 | * ceil(n/b) = (n/b) + ((n%b)?1:0) | |
661 | * | |
662 | * and in fact a previous version of this hash did just that. | |
663 | * But now we have improved things a bit by recognizing that b is | |
664 | * always a power of two. We keep its base 2 log handy (call it lb), | |
665 | * so now we can write this with a bit shift and logical AND: | |
666 | * | |
667 | * ceil(n/b) = (n>>lb) + ( (n & (b-1)) ? 1:0) | |
668 | * | |
669 | */ | |
670 | #define HASH_EXPAND_BUCKETS(tbl) \ | |
671 | do { \ | |
672 | unsigned _he_bkt; \ | |
673 | unsigned _he_bkt_i; \ | |
674 | struct UT_hash_handle *_he_thh, *_he_hh_nxt; \ | |
675 | UT_hash_bucket *_he_new_buckets, *_he_newbkt; \ | |
676 | _he_new_buckets = (UT_hash_bucket*)uthash_malloc( \ | |
677 | 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ | |
678 | if (!_he_new_buckets) { uthash_fatal( "out of memory"); } \ | |
679 | memset(_he_new_buckets, 0, \ | |
680 | 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ | |
681 | tbl->ideal_chain_maxlen = \ | |
682 | (tbl->num_items >> (tbl->log2_num_buckets+1)) + \ | |
683 | ((tbl->num_items & ((tbl->num_buckets*2)-1)) ? 1 : 0); \ | |
684 | tbl->nonideal_items = 0; \ | |
685 | for(_he_bkt_i = 0; _he_bkt_i < tbl->num_buckets; _he_bkt_i++) \ | |
686 | { \ | |
687 | _he_thh = tbl->buckets[ _he_bkt_i ].hh_head; \ | |
688 | while (_he_thh) { \ | |
689 | _he_hh_nxt = _he_thh->hh_next; \ | |
690 | HASH_TO_BKT( _he_thh->hashv, tbl->num_buckets*2, _he_bkt); \ | |
691 | _he_newbkt = &(_he_new_buckets[ _he_bkt ]); \ | |
692 | if (++(_he_newbkt->count) > tbl->ideal_chain_maxlen) { \ | |
693 | tbl->nonideal_items++; \ | |
694 | _he_newbkt->expand_mult = _he_newbkt->count / \ | |
695 | tbl->ideal_chain_maxlen; \ | |
696 | } \ | |
697 | _he_thh->hh_prev = NULL; \ | |
698 | _he_thh->hh_next = _he_newbkt->hh_head; \ | |
699 | if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev = \ | |
700 | _he_thh; \ | |
701 | _he_newbkt->hh_head = _he_thh; \ | |
702 | _he_thh = _he_hh_nxt; \ | |
703 | } \ | |
704 | } \ | |
705 | tbl->num_buckets *= 2; \ | |
706 | tbl->log2_num_buckets++; \ | |
707 | uthash_free( tbl->buckets ); \ | |
708 | tbl->buckets = _he_new_buckets; \ | |
709 | tbl->ineff_expands = (tbl->nonideal_items > (tbl->num_items >> 1)) ? \ | |
710 | (tbl->ineff_expands+1) : 0; \ | |
711 | if (tbl->ineff_expands > 1) { \ | |
712 | tbl->noexpand=1; \ | |
713 | uthash_noexpand_fyi(tbl); \ | |
714 | } \ | |
715 | uthash_expand_fyi(tbl); \ | |
716 | } while(0) | |
717 | ||
718 | ||
719 | /* This is an adaptation of Simon Tatham's O(n log(n)) mergesort */ | |
720 | /* Note that HASH_SORT assumes the hash handle name to be hh. | |
721 | * HASH_SRT was added to allow the hash handle name to be passed in. */ | |
722 | #define HASH_SORT(head,cmpfcn) HASH_SRT(hh,head,cmpfcn) | |
723 | #define HASH_SRT(hh,head,cmpfcn) \ | |
724 | do { \ | |
725 | unsigned _hs_i; \ | |
726 | unsigned _hs_looping,_hs_nmerges,_hs_insize,_hs_psize,_hs_qsize; \ | |
727 | struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, *_hs_tail; \ | |
728 | if (head) { \ | |
729 | _hs_insize = 1; \ | |
730 | _hs_looping = 1; \ | |
731 | _hs_list = &((head)->hh); \ | |
732 | while (_hs_looping) { \ | |
733 | _hs_p = _hs_list; \ | |
734 | _hs_list = NULL; \ | |
735 | _hs_tail = NULL; \ | |
736 | _hs_nmerges = 0; \ | |
737 | while (_hs_p) { \ | |
738 | _hs_nmerges++; \ | |
739 | _hs_q = _hs_p; \ | |
740 | _hs_psize = 0; \ | |
741 | for ( _hs_i = 0; _hs_i < _hs_insize; _hs_i++ ) { \ | |
742 | _hs_psize++; \ | |
743 | _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ | |
744 | ((void*)((char*)(_hs_q->next) + \ | |
745 | (head)->hh.tbl->hho)) : NULL); \ | |
746 | if (! (_hs_q) ) break; \ | |
747 | } \ | |
748 | _hs_qsize = _hs_insize; \ | |
749 | while ((_hs_psize > 0) || ((_hs_qsize > 0) && _hs_q )) { \ | |
750 | if (_hs_psize == 0) { \ | |
751 | _hs_e = _hs_q; \ | |
752 | _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ | |
753 | ((void*)((char*)(_hs_q->next) + \ | |
754 | (head)->hh.tbl->hho)) : NULL); \ | |
755 | _hs_qsize--; \ | |
756 | } else if ( (_hs_qsize == 0) || !(_hs_q) ) { \ | |
757 | _hs_e = _hs_p; \ | |
758 | _hs_p = (UT_hash_handle*)((_hs_p->next) ? \ | |
759 | ((void*)((char*)(_hs_p->next) + \ | |
760 | (head)->hh.tbl->hho)) : NULL); \ | |
761 | _hs_psize--; \ | |
762 | } else if (( \ | |
763 | cmpfcn(TYPEOF(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_p)), \ | |
764 | TYPEOF(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_q))) \ | |
765 | ) <= 0) { \ | |
766 | _hs_e = _hs_p; \ | |
767 | _hs_p = (UT_hash_handle*)((_hs_p->next) ? \ | |
768 | ((void*)((char*)(_hs_p->next) + \ | |
769 | (head)->hh.tbl->hho)) : NULL); \ | |
770 | _hs_psize--; \ | |
771 | } else { \ | |
772 | _hs_e = _hs_q; \ | |
773 | _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ | |
774 | ((void*)((char*)(_hs_q->next) + \ | |
775 | (head)->hh.tbl->hho)) : NULL); \ | |
776 | _hs_qsize--; \ | |
777 | } \ | |
778 | if ( _hs_tail ) { \ | |
779 | _hs_tail->next = ((_hs_e) ? \ | |
780 | ELMT_FROM_HH((head)->hh.tbl,_hs_e) : NULL); \ | |
781 | } else { \ | |
782 | _hs_list = _hs_e; \ | |
783 | } \ | |
784 | _hs_e->prev = ((_hs_tail) ? \ | |
785 | ELMT_FROM_HH((head)->hh.tbl,_hs_tail) : NULL); \ | |
786 | _hs_tail = _hs_e; \ | |
787 | } \ | |
788 | _hs_p = _hs_q; \ | |
789 | } \ | |
790 | _hs_tail->next = NULL; \ | |
791 | if ( _hs_nmerges <= 1 ) { \ | |
792 | _hs_looping=0; \ | |
793 | (head)->hh.tbl->tail = _hs_tail; \ | |
794 | (head) = TYPEOF(head)ELMT_FROM_HH((head)->hh.tbl, _hs_list); \ | |
795 | } \ | |
796 | _hs_insize *= 2; \ | |
797 | } \ | |
798 | HASH_FSCK(hh,head); \ | |
799 | } \ | |
800 | } while (0) | |
801 | ||
802 | /* This function selects items from one hash into another hash. | |
803 | * The end result is that the selected items have dual presence | |
804 | * in both hashes. There is no copy of the items made; rather | |
805 | * they are added into the new hash through a secondary hash | |
806 | * hash handle that must be present in the structure. */ | |
807 | #define HASH_SELECT(hh_dst, dst, hh_src, src, cond) \ | |
808 | do { \ | |
809 | unsigned _src_bkt, _dst_bkt; \ | |
810 | void *_last_elt=NULL, *_elt; \ | |
811 | UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh=NULL; \ | |
812 | ptrdiff_t _dst_hho = ((char*)(&(dst)->hh_dst) - (char*)(dst)); \ | |
813 | if (src) { \ | |
814 | for(_src_bkt=0; _src_bkt < (src)->hh_src.tbl->num_buckets; _src_bkt++) { \ | |
815 | for(_src_hh = (src)->hh_src.tbl->buckets[_src_bkt].hh_head; \ | |
816 | _src_hh; \ | |
817 | _src_hh = _src_hh->hh_next) { \ | |
818 | _elt = ELMT_FROM_HH((src)->hh_src.tbl, _src_hh); \ | |
819 | if (cond(_elt)) { \ | |
820 | _dst_hh = (UT_hash_handle*)(((char*)_elt) + _dst_hho); \ | |
821 | _dst_hh->key = _src_hh->key; \ | |
822 | _dst_hh->keylen = _src_hh->keylen; \ | |
823 | _dst_hh->hashv = _src_hh->hashv; \ | |
824 | _dst_hh->prev = _last_elt; \ | |
825 | _dst_hh->next = NULL; \ | |
826 | if (_last_elt_hh) { _last_elt_hh->next = _elt; } \ | |
827 | if (!dst) { \ | |
828 | dst = TYPEOF(dst)_elt; \ | |
829 | HASH_MAKE_TABLE(hh_dst,dst); \ | |
830 | } else { \ | |
831 | _dst_hh->tbl = (dst)->hh_dst.tbl; \ | |
832 | } \ | |
833 | HASH_TO_BKT(_dst_hh->hashv, _dst_hh->tbl->num_buckets, _dst_bkt); \ | |
834 | HASH_ADD_TO_BKT(_dst_hh->tbl->buckets[_dst_bkt],_dst_hh); \ | |
835 | (dst)->hh_dst.tbl->num_items++; \ | |
836 | _last_elt = _elt; \ | |
837 | _last_elt_hh = _dst_hh; \ | |
838 | } \ | |
839 | } \ | |
840 | } \ | |
841 | } \ | |
842 | HASH_FSCK(hh_dst,dst); \ | |
843 | } while (0) | |
844 | ||
845 | #define HASH_CLEAR(hh,head) \ | |
846 | do { \ | |
847 | if (head) { \ | |
848 | uthash_free((head)->hh.tbl->buckets ); \ | |
849 | uthash_free((head)->hh.tbl); \ | |
850 | (head)=NULL; \ | |
851 | } \ | |
852 | } while(0) | |
853 | ||
854 | /* obtain a count of items in the hash */ | |
855 | #define HASH_COUNT(head) HASH_CNT(hh,head) | |
856 | #define HASH_CNT(hh,head) (head?(head->hh.tbl->num_items):0) | |
857 | ||
858 | typedef struct UT_hash_bucket { | |
859 | struct UT_hash_handle *hh_head; | |
860 | unsigned count; | |
861 | ||
862 | /* expand_mult is normally set to 0. In this situation, the max chain length | |
863 | * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If | |
864 | * the bucket's chain exceeds this length, bucket expansion is triggered). | |
865 | * However, setting expand_mult to a non-zero value delays bucket expansion | |
866 | * (that would be triggered by additions to this particular bucket) | |
867 | * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH. | |
868 | * (The multiplier is simply expand_mult+1). The whole idea of this | |
869 | * multiplier is to reduce bucket expansions, since they are expensive, in | |
870 | * situations where we know that a particular bucket tends to be overused. | |
871 | * It is better to let its chain length grow to a longer yet-still-bounded | |
872 | * value, than to do an O(n) bucket expansion too often. | |
873 | */ | |
874 | unsigned expand_mult; | |
875 | ||
876 | } UT_hash_bucket; | |
877 | ||
878 | /* random signature used only to find hash tables in external analysis */ | |
879 | #define HASH_SIGNATURE 0xa0111fe1 | |
880 | #define HASH_BLOOM_SIGNATURE 0xb12220f2 | |
881 | ||
882 | typedef struct UT_hash_table { | |
883 | UT_hash_bucket *buckets; | |
884 | unsigned num_buckets, log2_num_buckets; | |
885 | unsigned num_items; | |
886 | struct UT_hash_handle *tail; /* tail hh in app order, for fast append */ | |
887 | ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */ | |
888 | ||
889 | /* in an ideal situation (all buckets used equally), no bucket would have | |
890 | * more than ceil(#items/#buckets) items. that's the ideal chain length. */ | |
891 | unsigned ideal_chain_maxlen; | |
892 | ||
893 | /* nonideal_items is the number of items in the hash whose chain position | |
894 | * exceeds the ideal chain maxlen. these items pay the penalty for an uneven | |
895 | * hash distribution; reaching them in a chain traversal takes >ideal steps */ | |
896 | unsigned nonideal_items; | |
897 | ||
898 | /* ineffective expands occur when a bucket doubling was performed, but | |
899 | * afterward, more than half the items in the hash had nonideal chain | |
900 | * positions. If this happens on two consecutive expansions we inhibit any | |
901 | * further expansion, as it's not helping; this happens when the hash | |
902 | * function isn't a good fit for the key domain. When expansion is inhibited | |
903 | * the hash will still work, albeit no longer in constant time. */ | |
904 | unsigned ineff_expands, noexpand; | |
905 | ||
906 | uint32_t signature; /* used only to find hash tables in external analysis */ | |
907 | #ifdef HASH_BLOOM | |
908 | uint32_t bloom_sig; /* used only to test bloom exists in external analysis */ | |
909 | uint8_t *bloom_bv; | |
910 | char bloom_nbits; | |
911 | #endif | |
912 | ||
913 | } UT_hash_table; | |
914 | ||
915 | typedef struct UT_hash_handle { | |
916 | struct UT_hash_table *tbl; | |
917 | void *prev; /* prev element in app order */ | |
918 | void *next; /* next element in app order */ | |
919 | struct UT_hash_handle *hh_prev; /* previous hh in bucket order */ | |
920 | struct UT_hash_handle *hh_next; /* next hh in bucket order */ | |
921 | void *key; /* ptr to enclosing struct's key */ | |
922 | unsigned keylen; /* enclosing struct's key len */ | |
923 | unsigned hashv; /* result of hash-fcn(key) */ | |
924 | } UT_hash_handle; | |
925 | ||
926 | #endif /* UTHASH_H */ |
0 | file(GLOB PO_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.po) | |
0 | file(GLOB PO_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.po) | |
1 | 1 | |
2 | 2 | set(POT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/fcitx-configtool.pot) |
3 | 3 | |
4 | 4 | add_custom_command( |
5 | OUTPUT ${POT_FILE} | |
6 | COMMAND INTLTOOL_EXTRACT=${INTLTOOL_EXTRACT} srcdir=${CMAKE_CURRENT_SOURCE_DIR} ${INTLTOOL_UPDATE} --gettext-package fcitx-configtool --pot | |
7 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | |
8 | ) | |
5 | OUTPUT ${POT_FILE} | |
6 | COMMAND INTLTOOL_EXTRACT=${INTLTOOL_EXTRACT} srcdir=${CMAKE_CURRENT_SOURCE_DIR} ${INTLTOOL_UPDATE} --gettext-package fcitx-configtool --pot | |
7 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | |
8 | ) | |
9 | 9 | |
10 | 10 | # Update .po files and compile them to binary .gmo files |
11 | 11 | gettext_create_translations(${POT_FILE} ALL ${PO_FILES}) |
0 | gtk/addon_stuff.c | |
1 | gtk/addon_stuff.h | |
0 | gtk/config_widget.c | |
1 | gtk/config_widget.h | |
2 | gtk/configdesc.c | |
3 | gtk/configdesc.h | |
4 | gtk/keygrab.h | |
5 | gtk/main.c | |
2 | 6 | gtk/main_window.c |
3 | gtk/configdesc.h | |
4 | gtk/table_stuff.h | |
5 | gtk/uthash.h | |
6 | gtk/table_stuff.c | |
7 | gtk/menu.h | |
8 | gtk/menu.c | |
9 | gtk/config_widget.c | |
10 | gtk/main.c | |
11 | gtk/utarray.h | |
12 | gtk/skin_stuff.h | |
13 | 7 | gtk/main_window.h |
14 | gtk/skin_stuff.c | |
15 | gtk/configdesc.c | |
16 | gtk/config_widget.h | |
8 | gtk/keygrab.c | |
9 | gtk/sub_config_parser.c | |
10 | gtk/sub_config_parser.h | |
11 | gtk/sub_config_widget.c | |
12 | gtk/sub_config_widget.h⏎ |
0 | # SOME DESCRIPTIVE TITLE. | |
1 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | |
2 | # This file is distributed under the same license as the PACKAGE package. | |
3 | # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | |
4 | # | |
5 | #, fuzzy | |
6 | msgid "" | |
7 | msgstr "" | |
8 | "Project-Id-Version: PACKAGE VERSION\n" | |
9 | "Report-Msgid-Bugs-To: \n" | |
10 | "POT-Creation-Date: 2011-09-03 09:31+0800\n" | |
11 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |
12 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
13 | "Language-Team: LANGUAGE <LL@li.org>\n" | |
14 | "Language: \n" | |
15 | "MIME-Version: 1.0\n" | |
16 | "Content-Type: text/plain; charset=CHARSET\n" | |
17 | "Content-Transfer-Encoding: 8bit\n" | |
18 | ||
19 | #: /home/saber/Develop/fcitx-config/po/../gtk/config_widget.c:197 | |
20 | msgid "Clear font setting" | |
21 | msgstr "" | |
22 | ||
23 | #: /home/saber/Develop/fcitx-config/po/../gtk/config_widget.c:258 | |
24 | msgid "Other" | |
25 | msgstr "" | |
26 | ||
27 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:180 | |
28 | msgid "Global Config" | |
29 | msgstr "" | |
30 | ||
31 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:240 | |
32 | msgid "Configure" | |
33 | msgstr "" | |
34 | ||
35 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:250 | |
36 | msgid "Addon Configuration" | |
37 | msgstr "" | |
38 | ||
39 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:268 | |
40 | msgid "Config" | |
41 | msgstr "" | |
42 | ||
43 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:303 | |
44 | msgid "Fcitx Config" | |
45 | msgstr "" | |
46 | ||
47 | #: /home/saber/Develop/fcitx-config/po/../gtk/keygrab.c:101 | |
48 | msgid "Please press the new key combination" | |
49 | msgstr "" | |
50 | ||
51 | #: /home/saber/Develop/fcitx-config/po/../gtk/keygrab.c:176 | |
52 | msgid "Disabled" | |
53 | msgstr "" |
0 | 0 | # Header entry was created by Lokalize. |
1 | 1 | # |
2 | # Weng Xuetian <wengxt@gmail.com>, 2010. | |
2 | # Weng Xuetian <wengxt@gmail.com>, 2010, 2011. | |
3 | 3 | msgid "" |
4 | 4 | msgstr "" |
5 | 5 | "Project-Id-Version: \n" |
6 | 6 | "Report-Msgid-Bugs-To: \n" |
7 | "POT-Creation-Date: 2010-12-17 14:00+0800\n" | |
8 | "PO-Revision-Date: 2010-12-17 14:02+0800\n" | |
7 | "POT-Creation-Date: 2011-09-03 09:31+0800\n" | |
8 | "PO-Revision-Date: 2011-09-03 09:32+0800\n" | |
9 | 9 | "Last-Translator: Weng Xuetian <wengxt@gmail.com>\n" |
10 | 10 | "Language-Team: Chinese Simplified <kde-i18n-doc@kde.org>\n" |
11 | 11 | "Language: \n" |
12 | 12 | "MIME-Version: 1.0\n" |
13 | 13 | "Content-Type: text/plain; charset=UTF-8\n" |
14 | 14 | "Content-Transfer-Encoding: 8bit\n" |
15 | "X-Generator: Lokalize 1.1\n" | |
15 | "X-Generator: Lokalize 1.2\n" | |
16 | 16 | "Plural-Forms: nplurals=2; plural=n != 1;\n" |
17 | 17 | |
18 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:195 | |
19 | msgid "Addon" | |
20 | msgstr "附加组件" | |
21 | ||
22 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:195 | |
18 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:250 | |
23 | 19 | msgid "Addon Configuration" |
24 | 20 | msgstr "附加组件配置" |
25 | 21 | |
26 | #: /home/saber/Develop/fcitx-config/po/../gtk/config_widget.c:162 | |
22 | #: /home/saber/Develop/fcitx-config/po/../gtk/config_widget.c:197 | |
27 | 23 | msgid "Clear font setting" |
28 | 24 | msgstr "清除字体设置" |
29 | 25 | |
30 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:122 | |
31 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:325 | |
26 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:268 | |
32 | 27 | msgid "Config" |
33 | 28 | msgstr "配置" |
34 | 29 | |
35 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:255 | |
30 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:240 | |
36 | 31 | msgid "Configure" |
37 | 32 | msgstr "配置 " |
38 | 33 | |
39 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:364 | |
34 | #: /home/saber/Develop/fcitx-config/po/../gtk/keygrab.c:176 | |
35 | msgid "Disabled" | |
36 | msgstr "禁用" | |
37 | ||
38 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:303 | |
40 | 39 | msgid "Fcitx Config" |
41 | 40 | msgstr "Fcitx配置" |
42 | 41 | |
43 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:145 | |
44 | msgid "Profile" | |
45 | msgstr "预置文件" | |
42 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:180 | |
43 | msgid "Global Config" | |
44 | msgstr "全局配置" | |
46 | 45 | |
47 | #: /home/saber/Develop/fcitx-config/po/../gtk/config_widget.c:95 | |
48 | msgid "Reset" | |
49 | msgstr "重置" | |
46 | #: /home/saber/Develop/fcitx-config/po/../gtk/config_widget.c:258 | |
47 | msgid "Other" | |
48 | msgstr "其他" | |
50 | 49 | |
51 | #: /home/saber/Develop/fcitx-config/po/../gtk/config_widget.c:94 | |
52 | msgid "Save" | |
53 | msgstr "保存" | |
50 | #: /home/saber/Develop/fcitx-config/po/../gtk/keygrab.c:101 | |
51 | msgid "Please press the new key combination" | |
52 | msgstr "请按下新按键组合" | |
54 | 53 | |
55 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:151 | |
56 | msgid "Skin" | |
57 | msgstr "皮肤" | |
58 | ||
59 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:151 | |
60 | msgid "Skin Configuration" | |
61 | msgstr "皮肤配置" | |
62 | ||
63 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:274 | |
64 | msgid "Table" | |
65 | msgstr "码表" | |
66 | ||
67 | #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:274 | |
68 | msgid "Table Configuration" | |
69 | msgstr "码表配置" | |
70 | ||
71 | #: /home/saber/Develop/fcitx-config/po/../gtk/menu.c:24 | |
72 | msgid "_Exit" | |
73 | msgstr "退出(_E)" | |
74 | ||
75 | #: /home/saber/Develop/fcitx-config/po/../gtk/menu.c:11 | |
76 | msgid "_File" | |
77 | msgstr "文件(_F)" | |
78 | ||
79 | #: /home/saber/Develop/fcitx-config/po/../gtk/menu.c:18 | |
80 | msgid "_Reload Config" | |
81 | msgstr "重新加载配置" | |
54 | #~ msgid "Addon" | |
55 | #~ msgstr "附加组件" | |
82 | 56 | |
83 | 57 | #~ msgid "Fcitx Config Tool" |
84 | 58 | #~ msgstr "Fcitx配置工具" |
88 | 62 | |
89 | 63 | #~ msgid "Fcitx GUI Config Tool" |
90 | 64 | #~ msgstr "Fcitx图形化配置工具" |
65 | ||
66 | #~ msgid "Profile" | |
67 | #~ msgstr "预置文件" | |
68 | ||
69 | #~ msgid "Reset" | |
70 | #~ msgstr "重置" | |
71 | ||
72 | #~ msgid "Save" | |
73 | #~ msgstr "保存" | |
74 | ||
75 | #~ msgid "Skin" | |
76 | #~ msgstr "皮肤" | |
77 | ||
78 | #~ msgid "Skin Configuration" | |
79 | #~ msgstr "皮肤配置" | |
80 | ||
81 | #~ msgid "Table Configuration" | |
82 | #~ msgstr "码表配置" | |
83 | ||
84 | #~ msgid "_Exit" | |
85 | #~ msgstr "退出(_E)" | |
86 | ||
87 | #~ msgid "_File" | |
88 | #~ msgstr "文件(_F)" |