Mercurial > pidgin
annotate finch/libgnt/wms/s.c @ 21977:cacc01b50a23
Fixes for incorrectly displaying user tune emblem and empty current media.
We now send an empty tune when not listening to any music, don't interpret
empty tune information as valid tune info and deactivate the "tune" status
when receiving empty tune information.
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Thu, 03 Jan 2008 18:31:58 +0000 |
parents | 6f2e068cf629 |
children | 315151da0dc6 |
rev | line source |
---|---|
15817 | 1 #include <string.h> |
2 #include <sys/types.h> | |
3 | |
18210
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18118
diff
changeset
|
4 #include "internal.h" |
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18118
diff
changeset
|
5 |
15817 | 6 #include "gnt.h" |
7 #include "gntbox.h" | |
8 #include "gntmenu.h" | |
9 #include "gntstyle.h" | |
10 #include "gntwm.h" | |
11 #include "gntwindow.h" | |
12 #include "gntlabel.h" | |
13 | |
14 #include "blist.h" | |
15 | |
16 #define TYPE_S (s_get_gtype()) | |
17 | |
18870 | 18 #ifdef _S |
19 #undef _S | |
20 #endif | |
21 | |
15817 | 22 typedef struct _S |
23 { | |
24 GntWM inherit; | |
25 } S; | |
26 | |
27 typedef struct _SClass | |
28 { | |
29 GntWMClass inherit; | |
30 } SClass; | |
31 | |
32 GType s_get_gtype(void); | |
33 void gntwm_init(GntWM **wm); | |
34 | |
35 static void (*org_new_window)(GntWM *wm, GntWidget *win); | |
36 | |
37 static void | |
38 envelope_buddylist(GntWidget *win) | |
39 { | |
40 int w, h; | |
41 gnt_widget_get_size(win, &w, &h); | |
42 wresize(win->window, h, w + 1); | |
43 mvwvline(win->window, 0, w, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL), h); | |
44 touchwin(win->window); | |
45 } | |
46 | |
47 static void | |
48 envelope_normal_window(GntWidget *win) | |
49 { | |
50 int w, h; | |
51 | |
52 if (GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_NO_BORDER | GNT_WIDGET_TRANSIENT)) | |
53 return; | |
54 | |
55 gnt_widget_get_size(win, &w, &h); | |
56 wbkgdset(win->window, ' ' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
57 mvwprintw(win->window, 0, w - 4, "[X]"); | |
58 } | |
59 | |
60 static void | |
61 s_decorate_window(GntWM *wm, GntWidget *win) | |
62 { | |
63 const char *name; | |
64 | |
65 name = gnt_widget_get_name(win); | |
66 if (name && strcmp(name, "buddylist") == 0) { | |
67 envelope_buddylist(win); | |
68 } else { | |
69 envelope_normal_window(win); | |
70 } | |
71 } | |
72 | |
73 static void | |
74 s_window_update(GntWM *wm, GntNode *node) | |
75 { | |
76 s_decorate_window(wm, node->me); | |
77 } | |
78 | |
79 static void | |
80 s_new_window(GntWM *wm, GntWidget *win) | |
81 { | |
82 int x, y, w, h; | |
83 int maxx, maxy; | |
84 const char *name; | |
85 gboolean blist = FALSE; | |
86 | |
87 if (!GNT_IS_MENU(win)) { | |
88 getmaxyx(stdscr, maxy, maxx); | |
89 | |
90 gnt_widget_get_position(win, &x, &y); | |
91 gnt_widget_get_size(win, &w, &h); | |
92 | |
93 name = gnt_widget_get_name(win); | |
94 | |
95 if (name && strcmp(name, "buddylist") == 0) { | |
96 /* The buddylist doesn't have no border nor nothing! */ | |
97 x = 0; | |
98 y = 0; | |
99 h = maxy - 1; | |
100 blist = TRUE; | |
101 | |
102 gnt_box_set_toplevel(GNT_BOX(win), FALSE); | |
103 GNT_WIDGET_SET_FLAGS(win, GNT_WIDGET_CAN_TAKE_FOCUS); | |
104 | |
105 gnt_widget_set_position(win, x, y); | |
106 mvwin(win->window, y, x); | |
107 | |
108 gnt_widget_set_size(win, -1, h + 2); /* XXX: Why is the +2 needed here? -- sadrul */ | |
109 } else if (!GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_TRANSIENT)) { | |
110 const char *title = GNT_BOX(win)->title; | |
111 if (title == NULL || !g_hash_table_lookup(wm->positions, title)) { | |
112 /* In the middle of the screen */ | |
113 x = (maxx - w) / 2; | |
114 y = (maxy - h) / 2; | |
115 | |
116 gnt_widget_set_position(win, x, y); | |
117 mvwin(win->window, y, x); | |
118 } | |
119 } | |
120 } | |
121 org_new_window(wm, win); | |
122 | |
123 if (blist) | |
124 gnt_wm_raise_window(wm, win); | |
125 } | |
126 | |
127 static GntWidget * | |
128 find_widget(GntWM *wm, const char *wname) | |
129 { | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
17705
diff
changeset
|
130 GList *iter = wm->cws->list; |
15817 | 131 for (; iter; iter = iter->next) { |
132 GntWidget *widget = iter->data; | |
133 const char *name = gnt_widget_get_name(widget); | |
134 if (name && strcmp(name, wname) == 0) { | |
135 return widget; | |
136 } | |
137 } | |
138 return NULL; | |
139 } | |
140 | |
141 static gboolean | |
142 s_mouse_clicked(GntWM *wm, GntMouseEvent event, int cx, int cy, GntWidget *widget) | |
143 { | |
144 int x, y, w, h; | |
145 | |
146 if (!widget) | |
147 return FALSE; | |
148 /* This might be a place to bring up a context menu */ | |
149 | |
150 if (event != GNT_LEFT_MOUSE_DOWN || | |
151 GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
152 return FALSE; | |
153 | |
154 gnt_widget_get_position(widget, &x, &y); | |
155 gnt_widget_get_size(widget, &w, &h); | |
156 | |
157 if (cy == y && cx == x + w - 3) { | |
158 gnt_widget_destroy(widget); | |
159 return TRUE; | |
160 } | |
161 | |
162 return FALSE; | |
163 } | |
164 | |
165 static gboolean | |
166 toggle_buddylist(GntBindable *bindable, GList *null) | |
167 { | |
168 GntWM *wm = GNT_WM(bindable); | |
169 GntWidget *blist = find_widget(wm, "buddylist"); | |
170 if (blist) | |
171 gnt_widget_destroy(blist); | |
172 else | |
15822 | 173 purple_blist_show(); |
15817 | 174 return TRUE; |
175 } | |
176 | |
177 static void | |
178 s_class_init(SClass *klass) | |
179 { | |
180 GntWMClass *pclass = GNT_WM_CLASS(klass); | |
181 | |
182 org_new_window = pclass->new_window; | |
183 | |
184 pclass->new_window = s_new_window; | |
185 pclass->decorate_window = s_decorate_window; | |
186 pclass->window_update = s_window_update; | |
187 pclass->mouse_clicked = s_mouse_clicked; | |
188 | |
189 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "toggle-buddylist", | |
190 toggle_buddylist, "\033" "b", NULL); | |
191 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); | |
192 GNTDEBUG; | |
193 } | |
194 | |
195 void gntwm_init(GntWM **wm) | |
196 { | |
197 *wm = g_object_new(TYPE_S, NULL); | |
198 } | |
199 | |
200 GType s_get_gtype(void) | |
201 { | |
202 static GType type = 0; | |
203 | |
204 if(type == 0) { | |
205 static const GTypeInfo info = { | |
206 sizeof(SClass), | |
207 NULL, /* base_init */ | |
208 NULL, /* base_finalize */ | |
209 (GClassInitFunc)s_class_init, | |
210 NULL, | |
211 NULL, /* class_data */ | |
212 sizeof(S), | |
213 0, /* n_preallocs */ | |
214 NULL, /* instance_init */ | |
215 NULL | |
216 }; | |
217 | |
218 type = g_type_register_static(GNT_TYPE_WM, | |
219 "GntS", | |
220 &info, 0); | |
221 } | |
222 | |
223 return type; | |
224 } | |
225 |