Codebase list fcitx-configtool / d827f48
Imported Upstream version 0.2.0 Aron Xu 12 years ago
26 changed file(s) with 3474 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 repo: ca6e0ddbd0d051195154f17ae6b5d04e8690caf3
1 node: 7dc13a5202262322574c91bb562d0e51ec589118
2 branch: default
3 latesttag: 0.2.0
4 latesttagdistance: 2
0 cmake_minimum_required (VERSION 2.6)
1
2 project(fcitx-configtool)
3
4 FIND_PACKAGE(Gettext REQUIRED)
5 FIND_PROGRAM(INTLTOOL_EXTRACT intltool-extract)
6 FIND_PROGRAM(INTLTOOL_UPDATE intltool-update)
7 FIND_PROGRAM(INTLTOOL_MERGE intltool-merge)
8
9 add_subdirectory(gtk)
10 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/>
4 Everyone is permitted to copy and distribute verbatim copies
5 of this license document, but changing it is not allowed.
6
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
19 your programs, too.
20
21 When we speak of free software, we are referring to freedom, not
22 price. Our General Public Licenses are designed to make sure that you
23 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.
32
33 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.
66
67 The precise terms and conditions for copying, distribution and
68 modification follow.
69
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
484 this License.
485
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
542 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
566 be similar in spirit to the present version, but may differ in detail to
567 address new problems or concerns.
568
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
623
624 If you develop a new program, and you want it to be of the greatest
625 possible use to the public, the best way to achieve this is to make it
626 free software which everyone can redistribute and change under these terms.
627
628 To do so, attach the following notices to the program. It is safest
629 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
631 the "copyright" line and a pointer to where the full notice is found.
632
633 <one line to give the program's name and a brief idea of what it does.>
634 Copyright (C) <year> <name of author>
635
636 This program is free software: you can redistribute it and/or modify
637 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
639 (at your option) any later version.
640
641 This program is distributed in the hope that it will be useful,
642 but WITHOUT ANY WARRANTY; without even the implied warranty of
643 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
644 GNU General Public License for more details.
645
646 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/>.
648
649 Also add information on how to contact you by electronic and paper mail.
650
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'.
656 This is free software, and you are welcome to redistribute it
657 under certain conditions; type `show c' for details.
658
659 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>.
0 include(FindPkgConfig)
1
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})
15
16 set( fcitx_config_gtk_sources
17 addon_stuff.c
18 config_widget.c
19 configdesc.c
20 keygrab.c
21 main.c
22 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}")
35
36 add_executable( fcitx-config-gtk ${fcitx_config_gtk_sources} )
37
38 install(TARGETS fcitx-config-gtk RUNTIME DESTINATION bin)
39
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})
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
1 #include "utarray.h"
2 extern UT_array* LoadAddonInfo (void);
0 #include "uthash.h"
1 #include <gtk/gtk.h>
2 #include <fcitx-config/fcitx-config.h>
3 #include <libintl.h>
4 #include <stdlib.h>
5 #include <libgen.h>
6 #include <sys/stat.h>
7 #include <unistd.h>
8
9 #include "config_widget.h"
10 #include "keygrab.h"
11
12 #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;
88 GtkWidget *configNotebook = gtk_notebook_new();
89 GtkWidget *saveButton = NULL;
90 GtkWidget *resetButton = NULL;
91
92 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)
144 {
145 case T_Integer:
146 inputWidget = gtk_spin_button_new_with_range(-1.0, 10000.0, 1.0);
147 argument = inputWidget;
148 break;
149 case T_Color:
150 inputWidget = gtk_color_button_new();
151 argument = inputWidget;
152 break;
153 case T_Boolean:
154 inputWidget = gtk_check_button_new();
155 argument = inputWidget;
156 break;
157 case T_Font:
158 {
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);
167 }
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;
181 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;
194 case T_File:
195 case T_Char:
196 case T_Image:
197 case T_String:
198 inputWidget = gtk_entry_new();
199 argument = inputWidget;
200 break;
201 }
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 }
210 gtk_widget_set_size_request(configNotebook, 500, -1);
211 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)
217 {
218 ConfigOptionDesc *codesc = option->optionDesc;
219 if (!codesc)
220 return;
221 if (sync == Raw2Value)
222 {
223 switch (codesc->type)
224 {
225 case T_Integer:
226 {
227 int value = atoi(option->rawValue);
228 gtk_spin_button_set_value(GTK_SPIN_BUTTON(arg), value);
229 }
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;
299 }
300 }
301 else
302 {
303 if (option->rawValue)
304 free(option->rawValue);
305 switch (codesc->type)
306 {
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 }
0 #include <gtk/gtk.h>
1 #include <fcitx-config/fcitx-config.h>
2
3 #include "main_window.h"
4
5 extern GtkWidget* config_widget_new(ConfigFileDesc *cfdesc, ConfigFile *cfile, ConfigPage *page, gboolean readonly);
6
7 #define CHANGE_DOMAIN_BEGIN(domain) { \
8 char *lastdomain = strdup(textdomain(NULL)); \
9 textdomain(domain);
10
11 #define CHANGE_DOMAIN_END() \
12 textdomain(lastdomain); \
13 free(lastdomain); \
14 }
0 #include "uthash.h"
1 #include <fcitx-config/fcitx-config.h>
2 #include <fcitx-config/xdg.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5
6 #include "configdesc.h"
7
8 typedef struct ConfigDescSet
9 {
10 char *filename;
11 ConfigFileDesc *cfdesc;
12 UT_hash_handle hh;
13 } ConfigDescSet;
14
15 static ConfigDescSet* cdset = NULL;
16
17 ConfigFileDesc *get_config_desc(char *filename)
18 {
19 ConfigDescSet *desc = NULL;
20 HASH_FIND_STR(cdset, filename, desc);
21 if (!desc)
22 {
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);
29
30 HASH_ADD_KEYPTR(hh, cdset, desc->filename, strlen(desc->filename), desc);
31 }
32
33 return desc->cfdesc;
34 }
0
1 #include <fcitx-config/fcitx-config.h>
2
3 extern ConfigFileDesc *get_config_desc(char *filename);
0 #include <gtk/gtk.h>
1 #include <gdk/gdkkeysyms.h>
2 #include <libintl.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include "keygrab.h"
6 #include <fcitx-config/hotkey.h>
7
8 #define _(s) gettext(s)
9 //定义枚举类型,说明信号的名称和次序
10 enum {
11 KEYGRAB_BUTTON_CHANGED,
12 KEYGRAB_BUTTON_CURRENT_CHANGED,
13 LAST_SIGNAL
14 };
15 static gint keygrab_button_signals[LAST_SIGNAL] = { 0 };
16 static void keygrab_button_init(KeyGrabButton *keygrab_button);
17 static void keygrab_button_class_init(KeyGrabButtonClass *keygrabbuttonclass);
18 static void changed(void);
19 static void current_changed(void);
20 static void begin_key_grab(KeyGrabButton* self, gpointer v);
21 static void end_key_grab(KeyGrabButton *self);
22 static GtkWidget* popup_new(GtkWidget* parent, const gchar* text, gboolean mouse);
23 static void on_key_press_event(GtkWidget *self, GdkEventKey *event, gpointer v);
24
25 //注册自定义控件
26 GtkType keygrab_button_get_type(void)
27 {
28 static GtkType keygrab_button_type = 0;
29 if(!keygrab_button_type)
30 {
31 GtkTypeInfo keygrab_button_info = {
32 "KeyGrabButton",
33 sizeof(KeyGrabButton),
34 sizeof(KeyGrabButtonClass),
35 (GtkClassInitFunc)keygrab_button_class_init,
36 (GtkObjectInitFunc)keygrab_button_init,
37 NULL,
38 NULL
39 };
40 keygrab_button_type = gtk_type_unique(GTK_TYPE_BUTTON, &keygrab_button_info);
41 }
42 return keygrab_button_type;
43 }
44
45 static void keygrab_button_init(KeyGrabButton *keygrabbutton)
46 {
47 keygrab_button_set_key(keygrabbutton, 0, 0);
48 gtk_signal_connect(GTK_OBJECT(keygrabbutton), "clicked", GTK_SIGNAL_FUNC(begin_key_grab), NULL);
49 }
50
51 static void keygrab_button_class_init(KeyGrabButtonClass *keygrabbuttonclass)
52 {
53 GtkObjectClass *object_class;
54 object_class = (GtkObjectClass*)keygrabbuttonclass;
55 keygrab_button_signals[KEYGRAB_BUTTON_CHANGED] = g_signal_new("changed",
56 G_TYPE_FROM_CLASS(object_class),
57 G_SIGNAL_RUN_FIRST,
58 G_STRUCT_OFFSET(KeyGrabButtonClass, changed),
59 NULL,NULL,
60 g_cclosure_marshal_VOID__VOID,
61 G_TYPE_NONE, 0, NULL);
62 keygrab_button_signals[KEYGRAB_BUTTON_CURRENT_CHANGED] = g_signal_new("current-changed",
63 G_TYPE_FROM_CLASS(object_class),
64 G_SIGNAL_RUN_FIRST,
65 G_STRUCT_OFFSET(KeyGrabButtonClass, current_changed),
66 NULL,NULL,
67 g_cclosure_marshal_VOID__VOID,
68 G_TYPE_NONE, 0, NULL);
69 }
70 //创建新的自定义控件
71 GtkWidget* keygrab_button_new(void)
72 {
73 return GTK_WIDGET(g_object_new(TYPE_KEYGRAB_BUTTON,0));
74 }
75
76
77 void begin_key_grab(KeyGrabButton* self, gpointer v)
78 {
79 gtk_widget_add_events(GTK_WIDGET(self), GDK_KEY_PRESS_MASK);
80 KeyGrabButton* b = KEYGRAB_BUTTON(self);
81 b->popup = popup_new(GTK_WIDGET(self), _("Please press the new key combination"), FALSE);
82 gtk_widget_show_all(b->popup);
83 b->handler = gtk_signal_connect(GTK_OBJECT(b->popup), "key-press-event", GTK_SIGNAL_FUNC(on_key_press_event), b);
84
85 while(gdk_keyboard_grab(gtk_widget_get_window(GTK_WIDGET(b->popup)), FALSE, GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS)
86 usleep(100);
87 }
88
89 void end_key_grab(KeyGrabButton *self)
90 {
91 KeyGrabButton* b = KEYGRAB_BUTTON(self);
92 gdk_keyboard_ungrab(gtk_get_current_event_time());
93 gtk_signal_disconnect(b->popup, b->handler);
94 gtk_widget_destroy(b->popup);
95 }
96
97 void on_key_press_event(GtkWidget *self, GdkEventKey *event, gpointer v)
98 {
99 KeyGrabButton* b = KEYGRAB_BUTTON(v);
100 guint key;
101 GdkModifierType mods = event->state & gtk_accelerator_get_default_mod_mask();
102
103 if ((event->keyval == GDK_KEY_Escape
104 || event->keyval == GDK_KEY_Return) && !mods)
105 {
106 if (event->keyval == GDK_KEY_Escape)
107 gtk_signal_emit_by_name(GTK_OBJECT(b), "changed", b->key, b->mods);
108 end_key_grab(b);
109 keygrab_button_set_key(b, 0, 0);
110 return;
111 }
112
113 key = gdk_keyval_to_upper(event->keyval);
114 if (key == GDK_KEY_ISO_Left_Tab)
115 key = GDK_KEY_Tab;
116
117 if (gtk_accelerator_valid(key, mods)
118 || (key == GDK_KEY_Tab && mods))
119 {
120 keygrab_button_set_key(b, key, mods);
121 end_key_grab(b);
122 b->key = key;
123 b->mods = mods;
124 gtk_signal_emit_by_name(GTK_OBJECT(b), "changed", b->key, b->mods);
125 return;
126 }
127
128 keygrab_button_set_key(b, key, mods);
129 }
130
131 void keygrab_button_set_key(KeyGrabButton* self, guint key, GdkModifierType mods)
132 {
133 KeyGrabButton* b = KEYGRAB_BUTTON(self);
134 gchar *label;
135 b->key = key;
136 b->mods = mods;
137
138 label = GetKeyString(key, mods);
139
140 if (label == NULL || strlen(label) == 0)
141 {
142 gtk_button_set_label(GTK_BUTTON(b), _("Disabled"));
143 }
144 else
145 {
146 gchar* lb = label;
147 gtk_button_set_label(GTK_BUTTON(b), lb);
148 }
149
150 if (label)
151 free(label);
152 }
153
154 void keygrab_button_get_key(KeyGrabButton* self, guint* key, GdkModifierType* mods)
155 {
156 if (key)
157 *key = self->key;
158 if (mods)
159 *mods = self->mods;
160 }
161
162 GtkWidget* popup_new(GtkWidget* parent, const gchar* text, gboolean mouse)
163 {
164 GtkWidget* w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
165 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);
167 if (parent)
168 gtk_window_set_transient_for(GTK_WINDOW(w), GTK_WINDOW(gtk_widget_get_toplevel(parent)));
169 gtk_window_set_modal(GTK_WINDOW(w), TRUE);
170 gtk_window_set_decorated(GTK_WINDOW(w), TRUE);
171 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(w), TRUE);
172 if (text)
173 {
174 GtkWidget* label = gtk_label_new(text);
175 GtkWidget* align = gtk_alignment_new(0, 0, 1, 1);
176 gtk_alignment_set_padding(GTK_ALIGNMENT(align), 20, 20, 20, 20);
177 gtk_container_add(GTK_CONTAINER(align), label);
178 gtk_container_add(GTK_CONTAINER(w), align);
179 }
180
181 return w;
182 }
0 #ifndef __OUR_ITEM_H__
1 #define __OUR_ITEM_H__
2 #include <gtk/gtk.h>
3 //定义类型宏和转换宏
4 #define TYPE_KEYGRAB_BUTTON (keygrab_button_get_type())
5 #define KEYGRAB_BUTTON(obj) (GTK_CHECK_CAST(obj,TYPE_KEYGRAB_BUTTON,KeyGrabButton))
6 //定义实例结构和类结构
7 typedef struct _KeyGrabButton KeyGrabButton;
8 typedef struct _KeyGrabButtonClass KeyGrabButtonClass;
9 struct _KeyGrabButton {
10 GtkButton parent; //父控件为横向盒状容器
11 GtkWidget* popup;
12 gulong handler;
13 guint key;
14 GdkModifierType mods;
15 };
16 struct _KeyGrabButtonClass {
17 GtkButtonClass parent_class;
18 void (*changed)(int, int);
19 void (*current_changed)(int, int);
20 };
21
22 GtkType keygrab_button_get_type(void);
23 GtkWidget* keygrab_button_new(void);
24 gchar *accelerator_to_fcitx_hotkey(const gchar* str);
25 void keygrab_button_set_key(KeyGrabButton* self, guint key, GdkModifierType mods);
26 void keygrab_button_get_key(KeyGrabButton* self, guint* key, GdkModifierType* mods);
27 #endif //__OUR_ITEM_H__
28
0 #include <gtk/gtk.h>
1 #include <langinfo.h>
2 #include <libintl.h>
3 #include <locale.h>
4 #include <unique/unique.h>
5
6 #include "main_window.h"
7
8 static GtkWidget *window = NULL;
9
10 static UniqueResponse
11 message_received_cb (UniqueApp *app,
12 UniqueCommand command,
13 UniqueMessageData *message,
14 guint time_,
15 gpointer user_data)
16 {
17 UniqueResponse res;
18 switch (command)
19 {
20 case UNIQUE_ACTIVATE:
21 gtk_window_set_screen (GTK_WINDOW (window), unique_message_data_get_screen (message));
22 gtk_window_present_with_time (GTK_WINDOW (window), time_);
23 res = UNIQUE_RESPONSE_OK;
24 break;
25 default:
26 res = UNIQUE_RESPONSE_OK;
27 break;
28 }
29 return res;
30 }
31
32 int
33 main(int argc, char **argv)
34 {
35 UniqueApp *app;
36
37 gtk_init(&argc, &argv);
38
39 app = unique_app_new_with_commands ("org.fcitx.fcitx-configtool", NULL,
40 NULL);
41
42 if (unique_app_is_running(app))
43 {
44 UniqueResponse response = unique_app_send_message (app, UNIQUE_ACTIVATE, NULL);
45 g_object_unref (app);
46 if (response == UNIQUE_RESPONSE_OK)
47 return 0;
48 else
49 return 1;
50 }
51
52 setlocale(LC_ALL, "");
53 bindtextdomain("fcitx-configtool", LOCALEDIR);
54 bindtextdomain("fcitx", LOCALEDIR);
55 textdomain("fcitx-configtool");
56
57 window = fcitx_config_main_window_new (GTK_WINDOW_TOPLEVEL);
58 unique_app_watch_window (app, GTK_WINDOW (window));
59 g_signal_connect (app, "message-received", G_CALLBACK (message_received_cb), NULL);
60
61 gtk_widget_show_all(window);
62
63 gtk_main();
64 g_object_unref (app);
65
66 return 0;
67 }
68
0 #include <gtk/gtk.h>
1 #include <fcitx-config/fcitx-config.h>
2 #include <fcitx-config/xdg.h>
3 #include <stdlib.h>
4 #include <libintl.h>
5 #include <errno.h>
6
7 #include "main_window.h"
8 #include "menu.h"
9 #include "config_widget.h"
10 #include "skin_stuff.h"
11 #include "addon_stuff.h"
12 #include "table_stuff.h"
13 #include "utarray.h"
14 #include "configdesc.h"
15
16 #define _(s) gettext(s)
17
18 static GtkWidget *mainWnd = NULL;
19 static GtkWidget *configTreeView = NULL;
20 static GtkWidget *configNotebook = NULL;
21 static GtkTreeStore *store = NULL;
22 static GtkWidget *hpaned = NULL;
23 static ConfigPage *configPage, *profilePage, *tablePage, *skinPage, *lastPage = NULL, *addonPage;
24
25 static int main_window_close(GtkWidget *theWindow, gpointer data);
26 static GtkTreeModel *fcitx_config_create_model();
27
28 int main_window_close(GtkWidget *theWindow, gpointer data)
29 {
30 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
41 ConfigPage *page = (ConfigPage*) malloc(sizeof(ConfigPage));
42 memset(page, 0, sizeof(ConfigPage));
43
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 }
61
62 g_object_ref(page->page);
63
64 gtk_tree_store_append(store, &page->iter, p);
65 gtk_tree_store_set(store, &page->iter, 0, name, 1, page, -1);
66
67 return page;
68 }
69
70 gboolean selection_changed(GtkTreeSelection *selection, gpointer data) {
71 GtkTreeView *treeView = gtk_tree_selection_get_tree_view(selection);
72 GtkTreeModel *model = gtk_tree_view_get_model(treeView);
73 GtkTreeIter iter;
74 ConfigPage *page;
75
76 if (gtk_tree_selection_get_selected(selection, &model, &iter))
77 {
78 gtk_tree_model_get(model, &iter,
79 1, &page,
80 -1);
81
82 if (lastPage)
83 gtk_container_remove(GTK_CONTAINER(hpaned), lastPage->page);
84 gtk_paned_add2(GTK_PANED(hpaned), page->page);
85 gtk_widget_show_all(mainWnd);
86
87 lastPage = page;
88 }
89 else
90 {
91 gtk_tree_selection_select_iter(selection, &configPage->iter);
92 }
93 }
94
95 GtkTreeModel *fcitx_config_create_model()
96 {
97 store = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
98 return GTK_TREE_MODEL(store);
99 }
100
101 void add_config_file_page()
102 {
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
189 }
190
191 void add_addon_page()
192 {
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
306 }
307
308 GtkWidget* fcitx_config_main_window_new()
309 {
310 if (mainWnd != NULL)
311 return mainWnd;
312
313 GtkWidget *menu = fcitx_config_menu_new();
314 GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
315
316 GtkCellRenderer *renderer;
317 GtkTreeViewColumn *column;
318
319 mainWnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
320 configTreeView = gtk_tree_view_new_with_model(fcitx_config_create_model());
321
322 renderer = gtk_cell_renderer_text_new();
323 column = gtk_tree_view_column_new_with_attributes(
324 _("Config"), renderer,
325 "text", 0,
326 NULL);
327 gtk_tree_view_append_column(GTK_TREE_VIEW (configTreeView), column);
328
329 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(configTreeView), FALSE);
330
331 add_config_file_page();
332 add_profile_file_page();
333 add_table_page();
334 add_skin_page();
335 add_addon_page();
336
337 gtk_widget_set_size_request(configTreeView, 170, -1);
338 gtk_widget_set_size_request(mainWnd, -1, 660);
339
340 hpaned = gtk_hpaned_new();
341 GtkWidget *treescroll = gtk_scrolled_window_new(NULL, NULL);
342 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(treescroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
343
344 gtk_container_add(GTK_CONTAINER(treescroll), configTreeView);
345 gtk_paned_add1(GTK_PANED(hpaned), treescroll);
346
347 gtk_box_pack_start(GTK_BOX(vbox), menu, FALSE, TRUE, 0);
348 gtk_box_pack_start(GTK_BOX(vbox), hpaned, TRUE, TRUE, 0);
349
350 gtk_container_add(GTK_CONTAINER(mainWnd), vbox);
351
352 GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(configTreeView));
353 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
354
355 gtk_signal_connect(GTK_OBJECT(mainWnd), "destroy", GTK_SIGNAL_FUNC(main_window_close), NULL);
356 g_signal_connect(G_OBJECT(selection), "changed",
357 G_CALLBACK(selection_changed), NULL);
358
359 gtk_tree_view_expand_all(GTK_TREE_VIEW(configTreeView));
360 gtk_tree_selection_select_iter(selection, &configPage->iter);
361
362 gtk_window_set_icon_name(GTK_WINDOW(mainWnd), "fcitx-configtool");
363 gtk_window_set_title(GTK_WINDOW(mainWnd), _("Fcitx Config"));
364 return mainWnd;
365 }
0 #ifndef MAIN_WINDOW_H
1
2 #define MAIN_WINDOW_H
3
4 #include <gtk/gtk.h>
5 #include <fcitx-config/fcitx-config.h>
6
7 typedef struct ConfigPage
8 {
9 ConfigFileDesc *cfdesc;
10 GtkWidget* page;
11 struct ConfigPage* parent;
12 GenericConfig config;
13 char *filename;
14 const char *domain;
15 GtkTreeIter iter;
16 } ConfigPage;
17
18 extern GtkWidget* fcitx_config_main_window_new();
19
20 #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
1 #include <gtk/gtk.h>
2
3 GtkWidget* fcitx_config_menu_new();
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 #include "utarray.h"
2 extern UT_array* loadSkinDir();
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 #include "utarray.h"
2 extern UT_array* LoadTableInfo (void);
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)
1
2 set(POT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/fcitx-configtool.pot)
3
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 )
9
10 # Update .po files and compile them to binary .gmo files
11 gettext_create_translations(${POT_FILE} ALL ${PO_FILES})
12
0 gtk/addon_stuff.c
1 gtk/addon_stuff.h
2 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 gtk/main_window.h
14 gtk/skin_stuff.c
15 gtk/configdesc.c
16 gtk/config_widget.h
0 # Header entry was created by Lokalize.
1 #
2 # Weng Xuetian <wengxt@gmail.com>, 2010.
3 msgid ""
4 msgstr ""
5 "Project-Id-Version: \n"
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"
9 "Last-Translator: Weng Xuetian <wengxt@gmail.com>\n"
10 "Language-Team: Chinese Simplified <kde-i18n-doc@kde.org>\n"
11 "Language: \n"
12 "MIME-Version: 1.0\n"
13 "Content-Type: text/plain; charset=UTF-8\n"
14 "Content-Transfer-Encoding: 8bit\n"
15 "X-Generator: Lokalize 1.1\n"
16 "Plural-Forms: nplurals=2; plural=n != 1;\n"
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
23 msgid "Addon Configuration"
24 msgstr "附加组件配置"
25
26 #: /home/saber/Develop/fcitx-config/po/../gtk/config_widget.c:162
27 msgid "Clear font setting"
28 msgstr "清除字体设置"
29
30 #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:122
31 #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:325
32 msgid "Config"
33 msgstr "配置"
34
35 #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:255
36 msgid "Configure"
37 msgstr "配置 "
38
39 #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:364
40 msgid "Fcitx Config"
41 msgstr "Fcitx配置"
42
43 #: /home/saber/Develop/fcitx-config/po/../gtk/main_window.c:145
44 msgid "Profile"
45 msgstr "预置文件"
46
47 #: /home/saber/Develop/fcitx-config/po/../gtk/config_widget.c:95
48 msgid "Reset"
49 msgstr "重置"
50
51 #: /home/saber/Develop/fcitx-config/po/../gtk/config_widget.c:94
52 msgid "Save"
53 msgstr "保存"
54
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 "重新加载配置"
82
83 #~ msgid "Fcitx Config Tool"
84 #~ msgstr "Fcitx配置工具"
85
86 #~ msgid "Fcitx Configuration Tool"
87 #~ msgstr "Fcitx配置工具"
88
89 #~ msgid "Fcitx GUI Config Tool"
90 #~ msgstr "Fcitx图形化配置工具"