prefs_gtk.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
  3. * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Claws Mail team
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef __PREFS_GTK_H__
  20. #define __PREFS_GTK_H__
  21. #include <glib.h>
  22. #include <gtk/gtkwidget.h>
  23. #include <gtk/gtksignal.h>
  24. #include <gtk/gtklabel.h>
  25. #include <gtk/gtknotebook.h>
  26. #include <gtk/gtkcheckbutton.h>
  27. #include <gtk/gtkbox.h>
  28. #include <stdio.h>
  29. typedef struct _PrefParam PrefParam;
  30. typedef struct _PrefsDialog PrefsDialog;
  31. #include "prefs.h"
  32. #include "account.h"
  33. #include "gtk/prefswindow.h"
  34. #define VSPACING 10
  35. #define VSPACING_NARROW 4
  36. #define VSPACING_NARROW_2 2
  37. #define VBOX_BORDER 8
  38. #define DEFAULT_ENTRY_WIDTH 80
  39. #define PREFSBUFSIZE 1024
  40. typedef enum
  41. {
  42. P_STRING,
  43. P_INT,
  44. P_BOOL,
  45. P_ENUM,
  46. P_USHORT,
  47. P_COLOR,
  48. P_PASSWORD,
  49. P_OTHER
  50. } PrefType;
  51. typedef void (*DataSetFunc) (PrefParam *pparam);
  52. typedef void (*WidgetSetFunc) (PrefParam *pparam);
  53. struct _PrefParam {
  54. gchar *name;
  55. gchar *defval;
  56. gpointer data;
  57. PrefType type;
  58. GtkWidget **widget;
  59. DataSetFunc data_set_func;
  60. WidgetSetFunc widget_set_func;
  61. };
  62. struct _PrefsDialog
  63. {
  64. GtkWidget *window;
  65. GtkWidget *notebook;
  66. GtkWidget *ok_btn;
  67. GtkWidget *cancel_btn;
  68. GtkWidget *apply_btn;
  69. };
  70. #define SET_NOTEBOOK_LABEL(notebook, str, page_num) \
  71. { \
  72. GtkWidget *label; \
  73. gint i = page_num; \
  74. \
  75. label = gtk_label_new_with_mnemonic (str); \
  76. gtk_widget_show (label); \
  77. gtk_notebook_set_tab_label \
  78. (GTK_NOTEBOOK (notebook), \
  79. gtk_notebook_get_nth_page \
  80. (GTK_NOTEBOOK (notebook), i), \
  81. label); \
  82. gtk_notebook_set_menu_label_text \
  83. (GTK_NOTEBOOK (notebook), \
  84. gtk_notebook_get_nth_page \
  85. (GTK_NOTEBOOK (notebook), i), \
  86. str);\
  87. }
  88. #define PACK_CHECK_BUTTON(box, chkbtn, label) \
  89. { \
  90. chkbtn = gtk_check_button_new_with_label(label); \
  91. gtk_widget_show(chkbtn); \
  92. gtk_box_pack_start(GTK_BOX(box), chkbtn, FALSE, TRUE, 0); \
  93. }
  94. #define PACK_END_CHECK_BUTTON(box, chkbtn, label) \
  95. { \
  96. chkbtn = gtk_check_button_new_with_label(label); \
  97. gtk_widget_show(chkbtn); \
  98. gtk_box_pack_end(GTK_BOX(box), chkbtn, FALSE, TRUE, 0); \
  99. }
  100. #define PACK_FRAME(box, frame, label) \
  101. { \
  102. frame = gtk_frame_new(label); \
  103. gtk_widget_show(frame); \
  104. gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0); \
  105. gtk_frame_set_label_align(GTK_FRAME(frame), 0.01, 0.5); \
  106. }
  107. #define PACK_VSPACER(box, vbox, spacing) \
  108. { \
  109. vbox = gtk_vbox_new(FALSE, 0); \
  110. gtk_widget_show(vbox); \
  111. gtk_box_pack_start(GTK_BOX(box), vbox, FALSE, TRUE, spacing); \
  112. }
  113. #define SET_TOGGLE_SENSITIVITY(togglewid, targetwid) \
  114. { \
  115. gtk_widget_set_sensitive(targetwid, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglewid))); \
  116. g_signal_connect(G_OBJECT(togglewid), "toggled", \
  117. G_CALLBACK(prefs_button_toggled), targetwid); \
  118. }
  119. #define SET_TOGGLE_SENSITIVITY_REVERSE(togglewid, targetwid) \
  120. { \
  121. gtk_widget_set_sensitive(targetwid, !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglewid))); \
  122. g_signal_connect(G_OBJECT(togglewid), "toggled", \
  123. G_CALLBACK(prefs_button_toggled_reverse), targetwid); \
  124. }
  125. void prefs_read_config (PrefParam *param,
  126. const gchar *label,
  127. const gchar *rcfile,
  128. const gchar *encoding);
  129. void prefs_config_parse_one_line(PrefParam *param,
  130. const gchar *buf);
  131. void prefs_write_config (PrefParam *param,
  132. const gchar *label,
  133. const gchar *rcfile);
  134. gint prefs_write_param (PrefParam *param,
  135. FILE *fp);
  136. PrefFile *prefs_write_open (const gchar *path);
  137. gint prefs_write_close (PrefFile *pfile);
  138. gint prefs_write_close_revert (PrefFile *pfile);
  139. void prefs_set_default (PrefParam *param);
  140. void prefs_free (PrefParam *param);
  141. void prefs_dialog_create (PrefsDialog *dialog);
  142. void prefs_dialog_destroy (PrefsDialog *dialog);
  143. void prefs_button_toggled (GtkToggleButton *toggle_btn,
  144. GtkWidget *widget);
  145. void prefs_button_toggled_reverse (GtkToggleButton *toggle_btn,
  146. GtkWidget *widget);
  147. void prefs_set_dialog (PrefParam *param);
  148. void prefs_set_data_from_dialog (PrefParam *param);
  149. void prefs_set_dialog_to_default(PrefParam *param);
  150. void prefs_set_data_from_entry (PrefParam *pparam);
  151. void prefs_set_entry (PrefParam *pparam);
  152. void prefs_set_data_from_text (PrefParam *pparam);
  153. void prefs_set_text (PrefParam *pparam);
  154. void prefs_set_data_from_toggle (PrefParam *pparam);
  155. void prefs_set_toggle (PrefParam *pparam);
  156. void prefs_set_data_from_spinbtn(PrefParam *pparam);
  157. void prefs_set_spinbtn (PrefParam *pparam);
  158. void prefs_gtk_open (void);
  159. void prefs_gtk_register_page (PrefsPage *page);
  160. void prefs_gtk_unregister_page (PrefsPage *page);
  161. void prefs_prepare_cache(void);
  162. void prefs_destroy_cache(void);
  163. #endif /* __PREFS_H__ */