Sun, 14 Aug 2005 03:50:35 +0000
[gaim-migrate @ 13432]
Removed warning from core.
I think you should be able to see others' warning levels in the tooltip,
but I haven't managed to warn myself from any client.
Being able to warn others will be dependent on protocol-specific convo
menus.
| 10643 | 1 | /* |
| 2 | * @file gtkstatusbox.c GTK+ Status Selection Widget | |
| 3 | * @ingroup gtkui | |
| 4 | * | |
| 5 | * gaim | |
| 6 | * | |
| 7 | * Gaim is the legal property of its developers, whose names are too numerous | |
| 8 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 9 | * source distribution. | |
| 10 | * | |
| 11 | * This program is free software; you can redistribute it and/or modify | |
| 12 | * it under the terms of the GNU General Public License as published by | |
| 13 | * the Free Software Foundation; either version 2 of the License, or | |
| 14 | * (at your option) any later version. | |
| 15 | * | |
| 16 | * This program is distributed in the hope that it will be useful, | |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | * GNU General Public License for more details. | |
| 20 | * | |
| 21 | * You should have received a copy of the GNU General Public License | |
| 22 | * along with this program; if not, write to the Free Software | |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 24 | */ | |
| 25 | ||
| 26 | #include "internal.h" | |
| 27 | #include "account.h" | |
| 28 | #include "status.h" | |
| 29 | #include "gtkgaim.h" | |
| 30 | #include "gtkstock.h" | |
| 31 | #include "gtkstatusbox.h" | |
| 32 | ||
| 33 | static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data); | |
| 34 | ||
| 35 | static void gtk_gaim_status_box_changed(GtkComboBox *box); | |
| 36 | static void gtk_gaim_status_box_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
| 37 | static void gtk_gaim_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
| 38 | static gboolean gtk_gaim_status_box_expose_event (GtkWidget *widget, GdkEventExpose *event); | |
| 39 | static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
| 40 | ||
| 41 | static void (*combo_box_size_request)(GtkWidget *widget, GtkRequisition *requisition); | |
| 42 | static void (*combo_box_size_allocate)(GtkWidget *widget, GtkAllocation *allocation); | |
| 43 | static gboolean (*combo_box_expose_event)(GtkWidget *widget, GdkEventExpose *event); | |
| 44 | static void (*combo_box_forall) (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
| 45 | enum { | |
| 46 | ICON_COLUMN, | |
| 47 | TEXT_COLUMN, | |
| 48 | TITLE_COLUMN, | |
| 49 | DESC_COLUMN, | |
| 50 | TYPE_COLUMN, | |
| 51 | NUM_COLUMNS | |
| 52 | }; | |
| 53 | ||
| 54 | static void gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass); | |
| 55 | static void gtk_gaim_status_box_init (GtkGaimStatusBox *status_box); | |
| 56 | ||
| 57 | GType | |
| 58 | gtk_gaim_status_box_get_type (void) | |
| 59 | { | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
60 | static GType status_box_type = 0; |
| 10643 | 61 | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
62 | if (!status_box_type) |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
63 | { |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
64 | static const GTypeInfo status_box_info = |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
65 | { |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
66 | sizeof (GtkGaimStatusBoxClass), |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
67 | NULL, /* base_init */ |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
68 | NULL, /* base_finalize */ |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
69 | (GClassInitFunc) gtk_gaim_status_box_class_init, |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
70 | NULL, /* class_finalize */ |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
71 | NULL, /* class_data */ |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
72 | sizeof (GtkGaimStatusBox), |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
73 | 0, |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
74 | (GInstanceInitFunc) gtk_gaim_status_box_init |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
75 | }; |
| 10643 | 76 | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
77 | status_box_type = g_type_register_static(GTK_TYPE_COMBO_BOX, |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
78 | "GtkGaimStatusBox", |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
79 | &status_box_info, |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
80 | 0); |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
81 | } |
| 10643 | 82 | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
83 | return status_box_type; |
| 10643 | 84 | } |
| 85 | ||
| 86 | static void | |
| 87 | gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass) | |
| 88 | { | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
89 | GObjectClass *object_class; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
90 | GtkWidgetClass *widget_class; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
91 | GtkComboBoxClass *parent_class = (GtkComboBoxClass*)klass; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
92 | GtkContainerClass *container_class = (GtkContainerClass*)klass; |
| 10643 | 93 | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
94 | parent_class->changed = gtk_gaim_status_box_changed; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
95 | widget_class = (GtkWidgetClass*)klass; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
96 | combo_box_size_request = widget_class->size_request; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
97 | widget_class->size_request = gtk_gaim_status_box_size_request; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
98 | combo_box_size_allocate = widget_class->size_allocate; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
99 | widget_class->size_allocate = gtk_gaim_status_box_size_allocate; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
100 | combo_box_expose_event = widget_class->expose_event; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
101 | widget_class->expose_event = gtk_gaim_status_box_expose_event; |
| 10643 | 102 | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
103 | combo_box_forall = container_class->forall; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
104 | container_class->forall = gtk_gaim_status_box_forall; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
105 | |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
106 | object_class = (GObjectClass *)klass; |
| 10643 | 107 | } |
| 108 | ||
| 109 | static void | |
| 110 | gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box) | |
| 111 | { | |
|
10672
225bdbfdc28f
[gaim-migrate @ 12212]
Daniel Atallah <datallah@pidgin.im>
parents:
10661
diff
changeset
|
112 | char *text, *title; |
| 10643 | 113 | char aa_color[8]; |
| 114 | GdkPixbuf *pixbuf; | |
|
10702
55a43c79fd6f
[gaim-migrate @ 12284]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10672
diff
changeset
|
115 | GtkTreePath *path; |
| 10643 | 116 | |
| 117 | GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
| 118 | snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
| 119 | style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
| 120 | style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
| 121 | style->text_aa[GTK_STATE_NORMAL].blue >> 8); | |
|
10672
225bdbfdc28f
[gaim-migrate @ 12212]
Daniel Atallah <datallah@pidgin.im>
parents:
10661
diff
changeset
|
122 | |
|
225bdbfdc28f
[gaim-migrate @ 12212]
Daniel Atallah <datallah@pidgin.im>
parents:
10661
diff
changeset
|
123 | title = status_box->title; |
|
225bdbfdc28f
[gaim-migrate @ 12212]
Daniel Atallah <datallah@pidgin.im>
parents:
10661
diff
changeset
|
124 | if (!title) |
|
225bdbfdc28f
[gaim-migrate @ 12212]
Daniel Atallah <datallah@pidgin.im>
parents:
10661
diff
changeset
|
125 | title = ""; |
|
225bdbfdc28f
[gaim-migrate @ 12212]
Daniel Atallah <datallah@pidgin.im>
parents:
10661
diff
changeset
|
126 | |
| 10643 | 127 | if (status_box->error) { |
| 128 | text = g_strdup_printf("%s\n<span size=\"smaller\" weight=\"bold\" color=\"red\">%s</span>", | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
129 | title, status_box->error); |
| 10643 | 130 | } else if (status_box->typing) { |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
131 | text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
132 | title, aa_color, _("Typing")); |
| 10643 | 133 | } else if (status_box->connecting) { |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
134 | text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
135 | title, aa_color, _("Connecting")); |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
136 | } else if (status_box->desc) { |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
137 | text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
138 | title, aa_color, status_box->desc); |
| 10643 | 139 | } else { |
|
10672
225bdbfdc28f
[gaim-migrate @ 12212]
Daniel Atallah <datallah@pidgin.im>
parents:
10661
diff
changeset
|
140 | text = g_strdup_printf("%s", title); |
| 10643 | 141 | } |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
142 | |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
143 | if (status_box->error) |
| 10643 | 144 | pixbuf = status_box->error_pixbuf; |
| 145 | else if (status_box->typing) | |
| 146 | pixbuf = status_box->typing_pixbufs[status_box->typing_index]; | |
| 147 | else if (status_box->connecting) | |
| 148 | pixbuf = status_box->connecting_pixbufs[status_box->connecting_index]; | |
| 149 | else | |
| 150 | pixbuf = status_box->pixbuf; | |
| 151 | ||
| 152 | gtk_list_store_set(status_box->store, &(status_box->iter), | |
| 153 | ICON_COLUMN, pixbuf, | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
154 | TEXT_COLUMN, text, |
|
10672
225bdbfdc28f
[gaim-migrate @ 12212]
Daniel Atallah <datallah@pidgin.im>
parents:
10661
diff
changeset
|
155 | TITLE_COLUMN, title, |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
156 | DESC_COLUMN, status_box->desc, |
| 10643 | 157 | TYPE_COLUMN, NULL, -1); |
|
10702
55a43c79fd6f
[gaim-migrate @ 12284]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10672
diff
changeset
|
158 | path = gtk_tree_path_new_from_string("0"); |
|
55a43c79fd6f
[gaim-migrate @ 12284]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10672
diff
changeset
|
159 | gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), path); |
|
55a43c79fd6f
[gaim-migrate @ 12284]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10672
diff
changeset
|
160 | gtk_tree_path_free(path); |
| 10643 | 161 | |
| 162 | g_free(text); | |
| 163 | } | |
| 164 | ||
| 165 | static void | |
| 166 | gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) | |
| 167 | { | |
| 168 | GtkCellRenderer *text_rend = gtk_cell_renderer_text_new(); | |
| 169 | GtkCellRenderer *icon_rend = gtk_cell_renderer_pixbuf_new(); | |
| 170 | GtkTextBuffer *buffer; | |
| 171 | GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; | |
| 172 | GtkIconSize icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
| 173 | ||
| 174 | status_box->imhtml_visible = FALSE; | |
| 175 | status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_OFFLINE, | |
| 176 | icon_size, "GtkGaimStatusBox"); | |
| 177 | status_box->connecting_index = 0; | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
178 | status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT0, |
| 10643 | 179 | icon_size, "GtkGaimStatusBox"); |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
180 | status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT1, |
| 10643 | 181 | icon_size, "GtkGaimStatusBox"); |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
182 | status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT2, |
| 10643 | 183 | icon_size, "GtkGaimStatusBox"); |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
184 | status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT3, |
| 10643 | 185 | icon_size, "GtkGaimStatusBox"); |
| 186 | ||
| 187 | status_box->typing_index = 0; | |
| 188 | status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING0, | |
| 189 | icon_size, "GtkGaimStatusBox"); | |
| 190 | status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING1, | |
| 191 | icon_size, "GtkGaimStatusBox"); | |
| 192 | status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING2, | |
| 193 | icon_size, "GtkGaimStatusBox"); | |
| 194 | status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING3, | |
| 195 | icon_size, "GtkGaimStatusBox"); | |
| 196 | status_box->connecting = FALSE; | |
| 197 | status_box->typing = FALSE; | |
| 198 | status_box->title = NULL; | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
199 | status_box->pixbuf = NULL; |
| 10643 | 200 | status_box->cell_view = gtk_cell_view_new(); |
| 201 | gtk_widget_show (status_box->cell_view); | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
202 | |
| 10643 | 203 | status_box->store = gtk_list_store_new(NUM_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
| 204 | status_box->dropdown_store = gtk_list_store_new(NUM_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); | |
| 205 | gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); | |
| 206 | gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
| 207 | gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
| 208 | gtk_list_store_append(status_box->store, &(status_box->iter)); | |
| 209 | gtk_gaim_status_box_refresh(status_box); | |
| 210 | gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), gtk_tree_path_new_from_string("0")); | |
| 211 | gtk_container_add(GTK_CONTAINER(status_box), status_box->cell_view); | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
212 | |
| 10643 | 213 | status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
| 214 | status_box->text_rend = gtk_cell_renderer_text_new(); | |
| 215 | ||
| 216 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
217 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
| 10643 | 218 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
| 219 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
| 220 | ||
| 221 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); | |
| 222 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); | |
| 223 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); | |
| 224 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
| 225 | ||
| 226 | status_box->vbox = gtk_vbox_new(0, FALSE); | |
| 227 | status_box->imhtml = gtk_imhtml_new(NULL, NULL); | |
| 228 | buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); | |
| 229 | g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(imhtml_changed_cb), status_box); | |
| 230 | gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); | |
| 231 | gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); | |
| 232 | status_box->sw = gtk_scrolled_window_new(NULL, NULL); | |
| 233 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
| 234 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); | |
| 235 | gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); | |
| 236 | gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); | |
| 237 | pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_ONLINE, | |
| 238 | icon_size, "GtkGaimStatusBox"); | |
| 239 | pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_AWAY, | |
| 240 | icon_size, "GtkGaimStatusBox"); | |
| 241 | pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_OFFLINE, | |
| 242 | icon_size, "GtkGaimStatusBox"); | |
| 243 | pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_INVISIBLE, | |
| 244 | icon_size, "GtkGaimStatusBox"); | |
| 245 | /* hacks */ | |
| 246 | gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf, _("Available"), NULL, "available"); | |
| 247 | gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf2, _("Away"), NULL, "away"); | |
| 248 | gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf4, _("Invisible"), NULL, "invisible"); | |
| 249 | gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf3, _("Offline"), NULL, "offline"); | |
| 250 | gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
| 251 | ||
| 252 | } | |
| 253 | ||
| 254 | ||
| 255 | static void | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
256 | gtk_gaim_status_box_size_request(GtkWidget *widget, |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
257 | GtkRequisition *requisition) |
| 10643 | 258 | { |
| 259 | GtkRequisition box_req; | |
| 260 | combo_box_size_request(widget, requisition); | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
261 | |
| 10643 | 262 | gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
| 263 | if (box_req.height > 1) | |
| 264 | requisition->height = requisition->height + box_req.height + 6; | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
265 | |
| 10643 | 266 | requisition->width = 1; |
| 267 | ||
| 268 | } | |
| 269 | ||
| 270 | static void | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
271 | gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
272 | GtkAllocation *allocation) |
| 10643 | 273 | { |
| 274 | GtkRequisition req = {0,0}; | |
| 275 | GtkAllocation parent_alc = *allocation, box_alc = *allocation ; | |
| 276 | combo_box_size_request(widget, &req); | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
277 | |
| 10643 | 278 | /* EVIL XXX */ |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
279 | box_alc.height = 80; |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
280 | /* box_alc.height = MAX(1,box_alc.height - req.height - 6); */ |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
281 | |
| 10643 | 282 | box_alc.y = box_alc.y + req.height + 6; |
| 283 | gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
284 | |
| 10643 | 285 | parent_alc.height = MAX(1,req.height); |
| 286 | combo_box_size_allocate(widget, &parent_alc); | |
| 287 | widget->allocation = *allocation; | |
| 288 | } | |
| 289 | ||
| 290 | ||
| 291 | static gboolean | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
292 | gtk_gaim_status_box_expose_event(GtkWidget *widget, |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
293 | GdkEventExpose *event) |
| 10643 | 294 | { |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
295 | GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
296 | combo_box_expose_event(widget, event); |
| 10643 | 297 | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
298 | gtk_container_propagate_expose(GTK_CONTAINER(widget), |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
299 | status_box->vbox, event); |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
300 | return FALSE; |
| 10643 | 301 | } |
| 302 | ||
| 303 | static void | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
304 | gtk_gaim_status_box_forall(GtkContainer *container, |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
305 | gboolean include_internals, |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
306 | GtkCallback callback, |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
307 | gpointer callback_data) |
| 10643 | 308 | { |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
309 | GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
| 10643 | 310 | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
311 | if (include_internals) |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
312 | { |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
313 | (* callback) (status_box->vbox, callback_data); |
|
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
314 | } |
| 10643 | 315 | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
316 | combo_box_forall(container, include_internals, callback, callback_data); |
| 10643 | 317 | } |
| 318 | ||
| 319 | GtkWidget * | |
| 320 | gtk_gaim_status_box_new() | |
| 321 | { | |
| 322 | return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
| 323 | } | |
| 324 | ||
| 325 | ||
| 326 | void | |
| 327 | gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GdkPixbuf *pixbuf, const char *text, const char *sec_text, char *edit) | |
| 328 | { | |
| 329 | GtkTreeIter iter; | |
| 330 | char *t; | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
331 | |
| 10643 | 332 | if (sec_text) { |
| 333 | char aa_color[8]; | |
| 334 | GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
| 335 | snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
| 336 | style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
| 337 | style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
338 | style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
| 10643 | 339 | t = g_strdup_printf("%s\n<span color=\"%s\">%s</span>", text, aa_color, sec_text); |
| 340 | } else { | |
| 341 | t = g_strdup(text); | |
| 342 | } | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
343 | |
| 10643 | 344 | gtk_list_store_append(status_box->dropdown_store, &iter); |
| 345 | gtk_list_store_set(status_box->dropdown_store, &iter, | |
| 346 | ICON_COLUMN, pixbuf, | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
347 | TEXT_COLUMN, t, |
| 10643 | 348 | TITLE_COLUMN, text, |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
349 | DESC_COLUMN, sec_text, |
| 10643 | 350 | TYPE_COLUMN, edit, -1); |
| 351 | } | |
| 352 | ||
| 353 | void | |
| 354 | gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) | |
| 355 | { | |
| 356 | status_box->error = g_strdup(error); | |
| 357 | gtk_gaim_status_box_refresh(status_box); | |
| 358 | } | |
| 359 | ||
| 360 | void | |
| 361 | gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
| 362 | { | |
| 363 | if (!status_box) | |
| 364 | return; | |
| 365 | status_box->connecting = connecting; | |
| 366 | gtk_gaim_status_box_refresh(status_box); | |
| 367 | } | |
| 368 | ||
| 369 | void | |
| 370 | gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
| 371 | { | |
| 372 | if (!status_box) | |
| 373 | return; | |
| 374 | if (status_box->connecting_index == 3) | |
| 375 | status_box->connecting_index = 0; | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
376 | else |
| 10643 | 377 | status_box->connecting_index++; |
| 378 | gtk_gaim_status_box_refresh(status_box); | |
| 379 | } | |
| 380 | ||
| 381 | void | |
| 382 | gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) | |
| 383 | { | |
| 384 | if (status_box->typing_index == 3) | |
| 385 | status_box->typing_index = 0; | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
386 | else |
| 10643 | 387 | status_box->typing_index++; |
| 388 | gtk_gaim_status_box_refresh(status_box); | |
| 389 | } | |
| 390 | ||
| 391 | static void remove_typing_cb(GtkGaimStatusBox *box) | |
| 392 | { | |
| 393 | gchar *status_type_id; | |
| 394 | GList *l; | |
| 395 | GtkTreeIter iter; | |
| 396 | ||
| 397 | gtk_combo_box_get_active_iter(GTK_COMBO_BOX(box), &iter); | |
| 398 | gtk_tree_model_get(GTK_TREE_MODEL(box->dropdown_store), &iter, TYPE_COLUMN, &status_type_id, -1); | |
| 399 | for (l = gaim_accounts_get_all(); l != NULL; l = l->next) { | |
| 400 | GaimAccount *account = (GaimAccount*)l->data; | |
| 401 | GaimStatusType *status_type; | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
402 | |
| 10643 | 403 | if (!gaim_account_get_enabled(account, GAIM_GTK_UI)) |
| 404 | continue; | |
| 405 | ||
| 406 | status_type = gaim_account_get_status_type(account, status_type_id); | |
| 407 | ||
| 408 | if (status_type == NULL) | |
| 409 | continue; | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
410 | gaim_account_set_status(account, status_type_id, TRUE, |
| 10643 | 411 | "message",gtk_imhtml_get_markup(GTK_IMHTML(box->imhtml)), NULL); |
| 412 | } | |
| 413 | g_source_remove(box->typing); | |
| 414 | box->typing = 0; | |
| 415 | gtk_gaim_status_box_refresh(box); | |
| 416 | } | |
| 417 | ||
|
10749
c06247f1e4bb
[gaim-migrate @ 12351]
Mark Doliner <markdoliner@pidgin.im>
parents:
10702
diff
changeset
|
418 | /* |
|
c06247f1e4bb
[gaim-migrate @ 12351]
Mark Doliner <markdoliner@pidgin.im>
parents:
10702
diff
changeset
|
419 | * TODO: This callback is triggered immediately, without the user actually |
|
c06247f1e4bb
[gaim-migrate @ 12351]
Mark Doliner <markdoliner@pidgin.im>
parents:
10702
diff
changeset
|
420 | * changing anything. That's bad. |
|
c06247f1e4bb
[gaim-migrate @ 12351]
Mark Doliner <markdoliner@pidgin.im>
parents:
10702
diff
changeset
|
421 | */ |
| 10643 | 422 | static void gtk_gaim_status_box_changed(GtkComboBox *box) |
| 423 | { | |
| 424 | GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(box); | |
| 425 | GtkTreeIter iter; | |
| 426 | char *text, *sec_text; | |
| 427 | GdkPixbuf *pixbuf; | |
| 428 | gchar *status_type_id; | |
| 429 | GList *l; | |
| 430 | ||
| 431 | gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); | |
| 432 | gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, TITLE_COLUMN, &text, | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
433 | DESC_COLUMN, &sec_text, ICON_COLUMN, &pixbuf, |
| 10643 | 434 | TYPE_COLUMN, &status_type_id, -1); |
| 435 | if (status_box->title) | |
| 436 | g_free(status_box->title); | |
| 437 | status_box->title = g_strdup(text); | |
| 438 | if (status_box->desc && sec_text) | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
439 | g_free(status_box->desc); |
| 10643 | 440 | status_box->desc = g_strdup(sec_text); |
| 441 | if (status_box->pixbuf) | |
| 442 | g_object_unref(status_box->pixbuf); | |
| 443 | status_box->pixbuf = pixbuf; | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
444 | |
| 10643 | 445 | if (!strcmp(status_type_id, "away")) { |
| 446 | gtk_widget_show_all(status_box->vbox); | |
| 447 | status_box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, status_box); | |
| 448 | gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); | |
| 449 | gtk_widget_grab_focus(status_box->imhtml); | |
| 450 | } else { | |
| 451 | if (status_box->typing) { | |
| 452 | g_source_remove(status_box->typing); | |
| 453 | status_box->typing = 0; | |
| 454 | } | |
| 455 | gtk_widget_hide_all(status_box->vbox); | |
| 456 | for (l = gaim_accounts_get_all(); l != NULL; l = l->next) { | |
| 457 | GaimAccount *account = (GaimAccount*)l->data; | |
| 458 | GaimStatusType *status_type; | |
| 459 | ||
| 460 | if (!gaim_account_get_enabled(account, GAIM_GTK_UI)) | |
| 461 | continue; | |
| 462 | ||
| 463 | status_type = gaim_account_get_status_type(account, status_type_id); | |
| 464 | ||
| 465 | if (status_type == NULL) | |
| 466 | continue; | |
| 467 | gaim_account_set_status(account, status_type_id, TRUE, NULL); | |
| 468 | } | |
| 469 | } | |
| 470 | gtk_gaim_status_box_refresh(status_box); | |
| 471 | } | |
| 472 | ||
| 473 | static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) | |
| 474 | { | |
| 475 | GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
| 476 | if (box->typing) { | |
| 477 | gtk_gaim_status_box_pulse_typing(box); | |
| 478 | g_source_remove(box->typing); | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
479 | } |
| 10643 | 480 | box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, box); |
| 481 | gtk_gaim_status_box_refresh(box); | |
| 482 | } | |
| 10649 | 483 | |
| 484 | const char *gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box) | |
| 485 | { | |
| 486 | GtkTreeIter iter; | |
| 487 | char *type; | |
| 488 | gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); | |
|
10861
21977f46cdf4
[gaim-migrate @ 12544]
Mark Doliner <markdoliner@pidgin.im>
parents:
10749
diff
changeset
|
489 | gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
| 10649 | 490 | TYPE_COLUMN, &type, -1); |
| 491 | return type; | |
| 492 | } | |
| 493 | ||
| 494 | const char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) | |
| 495 | { | |
| 496 | if (status_box->imhtml_visible) | |
| 497 | return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
| 498 | else | |
| 499 | return NULL; | |
| 500 | } |