Mercurial > pidgin.yaz
annotate plugins/gtik.c @ 2515:3ec36a342496
[gaim-migrate @ 2528]
this is better, hopefully.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 16 Oct 2001 18:11:15 +0000 |
parents | 4bd8e3b65402 |
children | 0e0a54e5819a |
rev | line source |
---|---|
426 | 1 /* |
2 * GNOME Stock Ticker | |
3 * (C) 2000 Jayson Lorenzen, Jim Garrison, Rached Blili | |
4 * | |
5 * based on: | |
6 * desire, and the old great slash applet. | |
7 * | |
8 * | |
9 * Authors: Jayson Lorenzen (jaysonl@pacbell.net) | |
10 * Jim Garrison (garrison@users.sourceforge.net) | |
11 * Rached Blili (striker@Dread.net) | |
12 * | |
13 * The Gnome Stock Ticker is a free, Internet based application. | |
14 * These quotes are not guaranteed to be timely or accurate. | |
15 * | |
16 * Do not use the Gnome Stock Ticker for making investment decisions, | |
17 * it is for informational purposes only. | |
18 * | |
2142
4bd8e3b65402
[gaim-migrate @ 2152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2130
diff
changeset
|
19 * Modified by EWarmenhoven to become a gaim plugin. There was little |
426 | 20 * enough that needed to be changed that I can't really claim any credit. |
21 * (you need to add -lghttp to the GTK_LIBS part of the Makefile) | |
22 * TODO: config, saving info | |
23 * | |
24 */ | |
25 | |
26 #define GAIM_PLUGINS | |
27 #include "gaim.h" | |
28 | |
29 #include <gtk/gtk.h> | |
30 #include <time.h> | |
31 #include <stdlib.h> | |
32 #include <stdio.h> | |
33 #include <string.h> | |
34 | |
35 #include "ghttp.h" | |
36 #include <sys/stat.h> | |
37 #include <unistd.h> | |
38 #include <dirent.h> | |
39 #include <gdk/gdkx.h> | |
40 | |
41 | |
42 GtkWidget *applet; /* this will become the main window */ | |
43 GtkWidget *label; | |
44 | |
45 | |
46 static GdkPixmap *pixmap = NULL; | |
47 GtkWidget * drawing_area; | |
48 | |
49 int location; | |
50 int MOVE; | |
51 | |
52 char output[64]; | |
53 | |
54 /** | |
55 * FOR COLOR | |
56 * LEN and the length of output, and colorNum must match | |
57 */ | |
58 const int LEN = 20; | |
59 char outputArray[20][64]; | |
60 char changeArray[20][64]; | |
61 int colorArray[20]; | |
62 | |
63 const int RED = 1; | |
64 const int GREEN = 2; | |
65 | |
66 static const int max_rgb_str_len = 7; | |
67 static const int max_rgb_str_size = 8; | |
68 | |
69 int setCounter, getCounter, setColorCounter,getColorCounter; | |
70 | |
71 GdkGC *gc; | |
72 GdkColor gdkUcolor,gdkDcolor; | |
73 | |
74 /* end of COLOR vars */ | |
75 | |
76 | |
77 char configFileName[256]; | |
78 | |
79 | |
80 /* properties vars */ | |
81 | |
82 GtkWidget *tik_syms_entry; | |
83 gchar tik_syms[256]; | |
84 | |
85 GtkWidget * pb = NULL; | |
86 | |
87 typedef struct | |
88 { | |
89 char *tik_syms; | |
90 char *output; | |
91 char *scroll; | |
92 gint timeout; | |
93 gchar dcolor[8]; | |
94 gchar ucolor[8]; | |
95 | |
96 } gtik_properties; | |
97 | |
98 gtik_properties props = {"cald+rhat+corl","default","right2left", | |
99 5,"#ff0000","#00ff00"}; | |
100 | |
101 /* end prop vars */ | |
102 | |
103 | |
104 gint timeout = 0; | |
105 gint drawTimeID, updateTimeID; | |
106 GdkFont * my_font; | |
107 GdkFont * extra_font; | |
108 GdkFont * small_font; | |
109 static gint symbolfont = 1; | |
110 static gint destroycb; | |
111 | |
112 | |
113 int configured(); | |
114 void timeout_cb( GtkWidget *widget, GtkWidget *spin ); | |
115 static int http_get_to_file(gchar *a_host, gint a_port, | |
116 gchar *a_resource, FILE *a_file); | |
117 int http_got(); | |
118 void properties_save( char *path) ; | |
119 void gaim_plugin_remove(); | |
120 | |
121 | |
122 /* FOR COLOR */ | |
123 | |
124 void updateOutput() ; | |
125 static void reSetOutputArray() ; | |
126 static void setOutputArray(char *param1) ; | |
127 static void setColorArray(int theColor) ; | |
128 void setup_colors(void); | |
129 int create_gc(void) ; | |
130 | |
131 /* end of color funcs */ | |
132 | |
133 | |
134 | |
135 /*-----------------------------------------------------------------*/ | |
136 void remove_self(GtkWidget *w, void *handle) | |
137 { | |
138 gtk_signal_disconnect(GTK_OBJECT(applet), destroycb); | |
139 if (drawTimeID > 0) { gtk_timeout_remove(drawTimeID); } | |
140 if (updateTimeID >0) { gtk_timeout_remove(updateTimeID); } | |
141 gtk_widget_destroy(applet); | |
142 gaim_plugin_unload(handle); | |
143 } | |
144 | |
145 | |
146 /*-----------------------------------------------------------------*/ | |
147 void load_fonts() | |
148 { | |
149 my_font = gdk_font_load ("fixed"); | |
150 extra_font = gdk_font_load ("-urw-symbol-medium-r-normal-*-*-100-*-*-p-*-adobe-fontspecific"); | |
151 small_font = gdk_font_load ("-schumacher-clean-medium-r-normal-*-*-100-*-*-c-*-iso8859-1"); | |
152 | |
153 /* If fonts do not load */ | |
154 if (!my_font) | |
155 g_error("Could not load fonts!"); | |
156 if (!extra_font) { | |
157 extra_font = gdk_font_load("fixed"); | |
158 symbolfont = 0; | |
159 } | |
160 if (!small_font) | |
161 small_font = gdk_font_load("fixed"); | |
162 } | |
163 | |
164 /*-----------------------------------------------------------------*/ | |
165 /*void load_properties( char *path) { | |
166 | |
167 | |
168 gnome_config_push_prefix (path); | |
169 if( gnome_config_get_string ("gtik/tik_syms") != NULL ) | |
170 props.tik_syms = gnome_config_get_string("gtik/tik_syms"); | |
171 | |
172 | |
173 timeout = gnome_config_get_int("gtik/timeout") > 0 ? gnome_config_get_int ("gtik/timeout") : props.timeout; | |
174 | |
175 | |
176 if ( gnome_config_get_string ("gtik/output") != NULL ) | |
177 props.output = gnome_config_get_string("gtik/output"); | |
178 | |
179 if ( gnome_config_get_string ("gtik/scroll") != NULL ) | |
180 props.scroll = gnome_config_get_string("gtik/scroll"); | |
181 | |
182 if ( gnome_config_get_string ("gtik/ucolor") != NULL ) | |
183 strcpy(props.ucolor, gnome_config_get_string("gtik/ucolor")); | |
184 | |
185 if ( gnome_config_get_string ("gtik/dcolor") != NULL ) | |
186 strcpy(props.dcolor, gnome_config_get_string("gtik/dcolor")); | |
187 | |
188 gnome_config_pop_prefix (); | |
189 }*/ | |
190 | |
191 | |
192 | |
193 /*-----------------------------------------------------------------*/ | |
194 /*void properties_save( char *path) { | |
195 | |
196 gnome_config_push_prefix (path); | |
197 gnome_config_set_string( "gtik/tik_syms", props.tik_syms ); | |
198 gnome_config_set_string( "gtik/output", props.output ); | |
199 gnome_config_set_string( "gtik/scroll", props.scroll ); | |
200 gnome_config_set_string( "gtik/ucolor", props.ucolor ); | |
201 gnome_config_set_string( "gtik/dcolor", props.dcolor ); | |
202 | |
203 gnome_config_set_int("gtik/timeout",props.timeout); | |
204 | |
205 gnome_config_pop_prefix (); | |
206 gnome_config_sync(); | |
207 gnome_config_drop_all(); | |
208 }*/ | |
209 | |
210 | |
211 /*-----------------------------------------------------------------*/ | |
212 char * extractText(const char *line) { | |
213 | |
214 int i=0; | |
215 int j=0; | |
216 static char Text[256]=""; | |
217 | |
218 while (i < (strlen(line) -1)) { | |
219 if (line[i] != '>') | |
220 i++; | |
221 else { | |
222 i++; | |
223 while (line[i] != '<') { | |
224 Text[j] = line[i]; | |
225 i++;j++; | |
226 } | |
227 } | |
228 } | |
229 Text[j] = '\0'; | |
230 i = 0; | |
231 while (i < (strlen(Text)) ) { | |
232 if (Text[i] < 32) | |
233 Text[i] = '\0'; | |
234 i++; | |
235 } | |
236 return(Text); | |
237 | |
238 } | |
239 | |
240 /*-----------------------------------------------------------------*/ | |
241 char * parseQuote(FILE *CONFIG, char line[512]) { | |
242 | |
243 char symbol[512]; | |
244 char buff[512]; | |
245 char price[16]; | |
246 char change[16]; | |
247 char percent[16]; | |
248 static char result[512]=""; | |
249 int linenum=0; | |
250 int AllOneLine=0; | |
251 int flag=0; | |
252 char *section; | |
253 char *ptr; | |
254 | |
255 if (strlen(line) > 64) AllOneLine=1; | |
256 | |
257 if (AllOneLine) { | |
258 strcpy(buff,line); | |
259 while (!flag) { | |
260 if ((ptr=strstr(buff,"</td>"))!=NULL) { | |
261 ptr[0] = '|'; | |
262 } | |
263 else flag=1; | |
264 } | |
265 section = strtok(buff,"|"); | |
266 } | |
267 /* Get the stock symbol */ | |
268 if (!AllOneLine) strcpy(symbol,extractText(line)); | |
269 else strcpy(symbol,extractText(section)); | |
270 linenum++; | |
271 | |
272 /* Skip the time... */ | |
273 if (!AllOneLine) fgets(line,255,CONFIG); | |
274 else section = strtok(NULL,"|"); | |
275 linenum++; | |
276 | |
277 while (linenum < 8 ) { | |
278 if (!AllOneLine) { | |
279 fgets(line,255,CONFIG); | |
280 | |
281 if (strstr(line, | |
282 "<td align=center nowrap colspan=2>")) { | |
283 strcpy(change,""); | |
284 strcpy(percent,""); | |
285 linenum=100; | |
286 } | |
287 } | |
288 else { | |
289 section = strtok(NULL,"|"); | |
290 if (strstr(section, | |
291 "<td align=center nowrap colspan=2>")) { | |
292 strcpy(change,""); | |
293 strcpy(percent,""); | |
294 linenum=100; | |
295 } | |
296 } | |
297 | |
298 if (linenum == 2) { | |
299 if (!AllOneLine) | |
300 strcpy(price,extractText(line)); | |
301 else | |
302 strcpy(price,extractText(section)); | |
303 } | |
304 else if (linenum == 3) { | |
305 if (!AllOneLine) | |
306 strcpy(change,extractText(line)); | |
307 else | |
308 strcpy(change,extractText(section)); | |
309 | |
310 if (strstr(change,"-")) { | |
311 setColorArray(RED); | |
312 } | |
313 else if (strstr(change,"+")) { | |
314 setColorArray(GREEN); | |
315 } | |
316 else { | |
317 setColorArray(0); | |
318 } | |
319 | |
320 } | |
321 else if (linenum == 4) { | |
322 if (!AllOneLine) | |
323 strcpy(percent,extractText(line)); | |
324 else | |
325 strcpy(percent,extractText(section)); | |
326 } | |
327 linenum++; | |
328 } | |
329 sprintf(result,"%s:%s:%s:%s", | |
330 symbol,price,change,percent); | |
331 return(result); | |
332 | |
333 } | |
334 | |
335 | |
336 | |
337 /*-----------------------------------------------------------------*/ | |
338 int configured() { | |
339 int retVar; | |
340 | |
341 char buffer[512]; | |
342 static FILE *CONFIG; | |
343 | |
344 CONFIG = fopen((const char *)configFileName,"r"); | |
345 | |
346 retVar = 0; | |
347 | |
348 /* clear the output variable */ | |
349 reSetOutputArray(); | |
350 | |
351 if ( CONFIG ) { | |
352 while ( !feof(CONFIG) ) { | |
353 fgets(buffer,511,CONFIG); | |
354 | |
355 if (strstr(buffer, | |
356 "<td nowrap align=left><a href=\"/q\?s=")) { | |
357 | |
358 setOutputArray(parseQuote(CONFIG,buffer)); | |
359 retVar = 1; | |
360 } | |
361 else { | |
362 retVar = (retVar > 0) ? retVar : 0; | |
363 } | |
364 } | |
365 fclose(CONFIG); | |
366 | |
367 } | |
368 else { | |
369 retVar = 0; | |
370 } | |
371 | |
372 return retVar; | |
373 } | |
374 | |
375 | |
376 /*-----------------------------------------------------------------*/ | |
377 /* Shamelessly stolen from the Slashapp applet | |
378 */ | |
379 static int http_get_to_file(gchar *a_host, gint a_port, | |
380 gchar *a_resource, FILE *a_file) { | |
381 int length = -1; | |
382 ghttp_request *request = NULL; | |
383 gchar s_port[8]; | |
384 gchar *uri = NULL; | |
385 gchar *body; | |
386 gchar *proxy = g_getenv("http_proxy"); | |
387 | |
388 g_snprintf(s_port, 8, "%d", a_port); | |
389 uri = g_strconcat("http://", a_host, ":", s_port, | |
390 a_resource, NULL); | |
391 | |
392 fprintf(stderr,"Asking for %s\n", uri); | |
393 | |
394 request = ghttp_request_new(); | |
395 if (!request) | |
396 goto ec; | |
397 if (proxy && (ghttp_set_proxy(request,proxy) != 0)) | |
398 goto ec; | |
399 | |
400 if (ghttp_set_uri(request, uri) != 0) | |
401 goto ec; | |
402 ghttp_set_header(request, http_hdr_Connection, "close"); | |
403 if (ghttp_prepare(request) != 0) | |
404 goto ec; | |
405 if (ghttp_process(request) != ghttp_done) | |
406 goto ec; | |
407 length = ghttp_get_body_len(request); | |
408 body = ghttp_get_body(request); | |
409 if (body != NULL) | |
410 fwrite(body, length, 1, a_file); | |
411 | |
412 ec: | |
413 if (request) | |
414 ghttp_request_destroy(request); | |
415 if (uri) | |
416 | |
417 g_free(uri); | |
418 return length; | |
419 } | |
420 | |
421 | |
422 | |
423 | |
424 /*-----------------------------------------------------------------*/ | |
425 int http_got() { | |
426 | |
427 int retVar; | |
428 FILE *local_file; | |
429 | |
430 char tmpBuff[256]; | |
431 memset(tmpBuff,0,sizeof(tmpBuff)); | |
432 | |
433 strcat(tmpBuff,"/q?s="); | |
434 strcat(tmpBuff, props.tik_syms); | |
435 strcat(tmpBuff,"&d=v2"); | |
436 | |
437 retVar = 0; | |
438 | |
439 local_file = fopen(configFileName, "w"); | |
440 retVar = http_get_to_file("finance.yahoo.com", 80, | |
441 tmpBuff, local_file); | |
442 | |
443 fclose(local_file); | |
444 | |
445 return retVar; | |
446 } | |
447 | |
448 | |
449 | |
450 | |
451 | |
452 /*-----------------------------------------------------------------*/ | |
453 gint expose_event (GtkWidget *widget,GdkEventExpose *event) { | |
454 | |
455 gdk_draw_pixmap(widget->window, | |
456 widget->style->fg_gc[GTK_WIDGET_STATE(widget)], | |
457 pixmap, | |
458 event->area.x, event->area.y, | |
459 event->area.x, event->area.y, | |
460 event->area.width,event->area.height); | |
461 | |
462 return FALSE; | |
463 } | |
464 | |
465 | |
466 | |
467 /*-----------------------------------------------------------------*/ | |
468 static gint configure_event(GtkWidget *widget,GdkEventConfigure *event){ | |
469 | |
470 if(pixmap) { | |
471 gdk_pixmap_unref (pixmap); | |
472 } | |
473 | |
474 pixmap = gdk_pixmap_new(widget->window, | |
475 widget->allocation.width, | |
476 widget->allocation.height, | |
477 -1); | |
478 | |
479 return TRUE; | |
480 } | |
481 | |
482 | |
483 | |
484 | |
485 | |
486 | |
487 /*-----------------------------------------------------------------*/ | |
488 gint Repaint (gpointer data) { | |
489 GtkWidget* drawing_area = (GtkWidget *) data; | |
490 GdkRectangle update_rect; | |
491 int comp; | |
492 | |
493 /* FOR COLOR */ | |
494 char *tmpSym; | |
495 int totalLoc; | |
496 int totalLen; | |
497 int i; | |
498 | |
499 | |
500 totalLoc = 0; | |
501 totalLen = 0; | |
502 | |
503 /* clear the pixmap */ | |
504 gdk_draw_rectangle (pixmap, | |
505 drawing_area->style->black_gc, | |
506 TRUE, | |
507 0,0, | |
508 drawing_area->allocation.width, | |
509 drawing_area->allocation.height); | |
510 | |
511 | |
512 for(i=0;i<LEN;i++) { | |
513 totalLen += strlen(outputArray[i]); | |
514 } | |
515 if (!strcmp(props.output,"default")) { | |
516 for(i=0;i<LEN;i++) { | |
517 totalLen += strlen(changeArray[i]); | |
518 } | |
519 } | |
520 | |
521 comp = 1 - ( totalLen *8 ); | |
522 | |
523 if (MOVE == 1) { MOVE = 0; } else { MOVE = 1; } | |
524 | |
525 if (MOVE == 1) { | |
526 | |
527 | |
528 if (!strcmp(props.scroll,"right2left")) { | |
529 if (location > comp) { | |
530 location--; | |
531 } | |
532 else { | |
533 location = drawing_area->allocation.width; | |
534 } | |
535 | |
536 } | |
537 else { | |
538 if (location < drawing_area->allocation.width) { | |
539 location ++; | |
540 } | |
541 else { | |
542 location = comp; | |
543 } | |
544 } | |
545 | |
546 | |
547 | |
548 } | |
549 | |
550 for (i=0;i<LEN;i++) { | |
551 | |
552 /* COLOR */ | |
553 if (colorArray[i] == GREEN) { | |
554 gdk_gc_set_foreground( gc, &gdkUcolor ); | |
555 } | |
556 else if (colorArray[i] == RED) { | |
557 gdk_gc_set_foreground( gc, &gdkDcolor ); | |
558 } | |
559 else { | |
560 gdk_gc_copy( gc, drawing_area->style->white_gc ); | |
561 } | |
562 | |
563 tmpSym = outputArray[i]; | |
564 gdk_draw_string (pixmap,my_font, | |
565 gc, | |
566 location + (totalLoc * 6 ) ,12,outputArray[i]); | |
567 totalLoc += (strlen(tmpSym) + 1); | |
568 | |
569 | |
570 if (!strcmp(props.output,"default")) { | |
571 tmpSym = changeArray[i]; | |
572 if (*(changeArray[i])) | |
573 gdk_draw_text (pixmap,extra_font, | |
574 gc, location + (totalLoc * 6) , | |
575 12,changeArray[i],1); | |
576 gdk_draw_string (pixmap,small_font, | |
577 gc, location + ((totalLoc +2) * 6) , | |
578 12, &changeArray[i][1]); | |
579 totalLoc += (strlen(tmpSym) + 1); | |
580 } | |
581 | |
582 } | |
583 update_rect.x = 0; | |
584 update_rect.y = 0; | |
585 update_rect.width = drawing_area->allocation.width; | |
586 update_rect.height = drawing_area->allocation.height; | |
587 | |
588 gtk_widget_draw(drawing_area,&update_rect); | |
589 return 1; | |
590 } | |
591 | |
592 | |
593 | |
594 | |
595 /*-----------------------------------------------------------------*/ | |
596 char *description() { | |
597 return | |
598 " This program uses ghttp to connect to " | |
599 "a popular stock quote site, then downloads " | |
600 "and parses the html returned from the " | |
601 "site to scroll delayed quotes" | |
602 "\n\n The Gnome Stock Ticker is a free, Internet based application. These quotes are not " | |
603 "guaranteed to be timely or accurate. " | |
604 "Do not use the Gnome Stock Ticker for making investment decisions; it is for " | |
605 "informational purposes only." | |
606 "\n\n (C) 2000 Jayson Lorenzen, Jim Garrison, Rached Blili"; | |
607 } | |
608 | |
609 char *name() { | |
610 return "The Gnome Stock Ticker for GAIM"; | |
611 } | |
612 | |
613 | |
614 | |
615 | |
616 | |
617 | |
618 /*-----------------------------------------------------------------*/ | |
619 void changed_cb(GtkWidget *pb, gpointer data) { | |
620 /* gnome_property_box_changed(GNOME_PROPERTY_BOX(pb)); */ | |
621 } | |
622 | |
623 | |
624 /*-----------------------------------------------------------------*/ | |
625 void toggle_output_cb(GtkWidget *widget, gpointer data) { | |
626 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) | |
627 props.output = g_strdup("nochange"); | |
628 else | |
629 props.output = g_strdup("default"); | |
630 | |
631 } | |
632 | |
633 /*-----------------------------------------------------------------*/ | |
634 void toggle_scroll_cb(GtkWidget *widget, gpointer data) { | |
635 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) | |
636 props.scroll = g_strdup("left2right"); | |
637 else | |
638 props.scroll = g_strdup("right2left"); | |
639 | |
640 } | |
641 | |
642 /*-----------------------------------------------------------------*/ | |
643 void timeout_cb( GtkWidget *widget, GtkWidget *spin ) { | |
644 timeout=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin)); | |
645 /* gnome_property_box_changed(GNOME_PROPERTY_BOX(pb)); */ | |
646 } | |
647 | |
648 | |
649 | |
650 | |
651 /*-----------------------------------------------------------------*/ | |
652 static void apply_cb( GtkWidget *widget, void *data ) { | |
653 char *tmpText; | |
654 | |
655 | |
656 tmpText = gtk_entry_get_text(GTK_ENTRY(tik_syms_entry)); | |
657 props.tik_syms = g_strdup(tmpText); | |
658 if (props.timeout) { | |
659 props.timeout = timeout > 0 ? timeout : props.timeout; | |
660 } | |
661 | |
662 /* properties_save(APPLET_WIDGET(applet)->privcfgpath); */ | |
663 | |
664 setup_colors(); | |
665 updateOutput(); | |
666 } | |
667 | |
668 | |
669 | |
670 | |
671 /*-----------------------------------------------------------------*/ | |
672 gint destroy_cb( GtkWidget *widget, void *data ) { | |
673 pb = NULL; | |
674 return FALSE; | |
675 } | |
676 | |
677 | |
678 | |
679 /*-----------------------------------------------------------------*/ | |
680 void gaim_plugin_config() { | |
681 GtkWidget * vbox; | |
682 GtkWidget *urlcheck, *launchcheck; | |
683 | |
684 GtkWidget *panela, *panel1 ,*panel2, *panel3, *panel4; | |
685 GtkWidget *label1,*label2,*label3 ; | |
686 | |
687 | |
688 GtkWidget *timeout_label,*timeout_c; | |
689 GtkObject *timeout_a; | |
690 | |
691 GtkWidget *upColor, *downColor, *upLabel, *downLabel; | |
692 GtkWidget *check,*check2; | |
693 | |
694 int ur,ug,ub, dr,dg,db; | |
695 | |
696 if (pb) return; | |
697 pb = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
698 | |
699 gtk_window_set_title(GTK_WINDOW(pb), _("Gnome Stock Ticker Properties")); | |
700 | |
701 vbox = gtk_vbox_new(FALSE, 8); | |
702 | |
703 panela = gtk_hbox_new(FALSE, 5); | |
704 panel1 = gtk_hbox_new(FALSE, 5); | |
705 panel2 = gtk_hbox_new(FALSE, 5); | |
706 panel3 = gtk_hbox_new(FALSE, 5); | |
707 panel4 = gtk_hbox_new(FALSE, 5); | |
708 | |
709 gtk_container_set_border_width(GTK_CONTAINER(vbox), 8); | |
710 | |
711 timeout_label = gtk_label_new(_("Update Frequency in min")); | |
712 timeout_a = gtk_adjustment_new( timeout, 0.5, 128, 1, 8, 8 ); | |
713 timeout_c = gtk_spin_button_new( GTK_ADJUSTMENT(timeout_a), 1, 0 ); | |
714 | |
715 gtk_box_pack_start_defaults( GTK_BOX(panel2), timeout_label ); | |
716 gtk_box_pack_start_defaults( GTK_BOX(panel2), timeout_c ); | |
717 | |
718 gtk_signal_connect_object(GTK_OBJECT(timeout_c), "changed",GTK_SIGNAL_FUNC(changed_cb),GTK_OBJECT(pb)); | |
719 | |
720 gtk_signal_connect( GTK_OBJECT(timeout_a),"value_changed", | |
721 GTK_SIGNAL_FUNC(timeout_cb), timeout_c ); | |
722 gtk_signal_connect( GTK_OBJECT(timeout_c),"changed", | |
723 GTK_SIGNAL_FUNC(timeout_cb), timeout_c ); | |
724 gtk_spin_button_set_update_policy( GTK_SPIN_BUTTON(timeout_c), | |
725 GTK_UPDATE_ALWAYS ); | |
726 | |
727 label1 = gtk_label_new(_("Enter symbols delimited with \"+\" in the box below.")); | |
728 | |
729 tik_syms_entry = gtk_entry_new_with_max_length(60); | |
730 | |
731 /* tik_syms var is her if want a default value */ | |
732 gtk_entry_set_text(GTK_ENTRY(tik_syms_entry), props.tik_syms ? props.tik_syms : tik_syms); | |
733 gtk_signal_connect_object(GTK_OBJECT(tik_syms_entry), "changed",GTK_SIGNAL_FUNC(changed_cb),GTK_OBJECT(pb)); | |
734 | |
735 /* OUTPUT FORMAT and SCROLL DIRECTION */ | |
736 | |
737 label2 = gtk_label_new(_("Check this box to display only symbols and price:")); | |
738 label3 = gtk_label_new(_("Check this box to scroll left to right:")); | |
739 check = gtk_check_button_new(); | |
740 check2 = gtk_check_button_new(); | |
741 gtk_box_pack_start_defaults(GTK_BOX(panel3),label2); | |
742 gtk_box_pack_start_defaults(GTK_BOX(panel3),check); | |
743 gtk_box_pack_start_defaults(GTK_BOX(panel4),label3); | |
744 gtk_box_pack_start_defaults(GTK_BOX(panel4),check2); | |
745 | |
746 /* Set the checkbox according to current prefs */ | |
747 if (strcmp(props.output,"default")!=0) | |
748 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), | |
749 TRUE); | |
750 gtk_signal_connect_object(GTK_OBJECT(check),"toggled", | |
751 GTK_SIGNAL_FUNC(changed_cb),GTK_OBJECT(pb)); | |
752 gtk_signal_connect(GTK_OBJECT(check),"toggled", | |
753 GTK_SIGNAL_FUNC(toggle_output_cb),NULL); | |
754 | |
755 /* Set the checkbox according to current prefs */ | |
756 if (strcmp(props.scroll,"right2left")!=0) | |
757 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check2), | |
758 TRUE); | |
759 gtk_signal_connect_object(GTK_OBJECT(check2),"toggled", | |
760 GTK_SIGNAL_FUNC(changed_cb),GTK_OBJECT(pb)); | |
761 gtk_signal_connect(GTK_OBJECT(check2),"toggled", | |
762 GTK_SIGNAL_FUNC(toggle_scroll_cb),NULL); | |
763 | |
764 /* COLOR */ | |
765 /* upLabel = gtk_label_new(_("+ Color")); | |
766 upColor = gnome_color_picker_new(); | |
767 | |
768 sscanf( props.ucolor, "#%02x%02x%02x", &ur,&ug,&ub ); | |
769 | |
770 gnome_color_picker_set_i8(GNOME_COLOR_PICKER (upColor), | |
771 ur, ug, ub, 255); | |
772 | |
773 gtk_signal_connect(GTK_OBJECT(upColor), "color_set", | |
774 GTK_SIGNAL_FUNC(ucolor_set_cb), NULL); | |
775 | |
776 gtk_box_pack_start_defaults( GTK_BOX(panela), upLabel ); | |
777 gtk_box_pack_start_defaults( GTK_BOX(panela), upColor ); | |
778 | |
779 downLabel = gtk_label_new(_("- Color")); | |
780 downColor = gnome_color_picker_new(); | |
781 | |
782 sscanf( props.dcolor, "#%02x%02x%02x", &dr,&dg,&db ); | |
783 | |
784 gnome_color_picker_set_i8(GNOME_COLOR_PICKER (downColor), | |
785 dr, dg, db, 255); | |
786 | |
787 gtk_signal_connect(GTK_OBJECT(downColor), "color_set", | |
788 GTK_SIGNAL_FUNC(dcolor_set_cb), NULL); | |
789 | |
790 gtk_box_pack_start_defaults( GTK_BOX(panela), downLabel ); | |
791 gtk_box_pack_start_defaults( GTK_BOX(panela), downColor ); | |
792 | |
793 */ | |
794 gtk_box_pack_start(GTK_BOX(panel1), label1, FALSE, | |
795 FALSE, 8); | |
796 | |
797 gtk_box_pack_start(GTK_BOX(vbox), panel2, FALSE, | |
798 FALSE, 8); | |
799 gtk_box_pack_start(GTK_BOX(vbox), panel3, FALSE, | |
800 FALSE, 8); | |
801 gtk_box_pack_start(GTK_BOX(vbox), panel4, FALSE, | |
802 FALSE, 8); | |
803 gtk_box_pack_start(GTK_BOX(vbox), panela, FALSE, | |
804 FALSE, 8); | |
805 gtk_box_pack_start(GTK_BOX(vbox), panel1, FALSE, | |
806 FALSE, 8); | |
807 | |
808 gtk_box_pack_start(GTK_BOX(vbox), tik_syms_entry, | |
809 FALSE, FALSE, 8); | |
810 | |
811 gtk_container_add(GTK_CONTAINER(pb), vbox); | |
812 | |
813 gtk_signal_connect_object(GTK_OBJECT(tik_syms_entry), | |
814 "changed",GTK_SIGNAL_FUNC(changed_cb), | |
815 GTK_OBJECT(pb)); | |
816 | |
817 gtk_signal_connect(GTK_OBJECT(pb), "apply", | |
818 GTK_SIGNAL_FUNC(apply_cb), NULL); | |
819 | |
820 gtk_widget_show_all(pb); | |
821 } | |
822 | |
823 | |
824 | |
825 | |
826 | |
827 /*-----------------------------------------------------------------*/ | |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
426
diff
changeset
|
828 char *gaim_plugin_init(GModule *handle) { /* used to be main() */ |
426 | 829 GtkWidget *label; |
830 | |
831 GtkWidget * vbox; | |
832 | |
833 memset(configFileName,0,sizeof(configFileName)); | |
834 strcat(configFileName, getenv("HOME")); | |
835 strcat(configFileName, "/.gtik.conf"); | |
836 | |
837 applet = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* or not */ | |
838 | |
839 vbox = gtk_hbox_new (FALSE,0); | |
840 | |
841 drawing_area = gtk_drawing_area_new(); | |
842 gtk_drawing_area_size(GTK_DRAWING_AREA (drawing_area),200,20); | |
843 | |
844 gtk_widget_show(drawing_area); | |
845 gtk_box_pack_start(GTK_BOX (vbox), drawing_area,TRUE,TRUE,0); | |
846 | |
847 gtk_widget_show(vbox); | |
848 | |
849 /* applet_widget_add (APPLET_WIDGET (applet), vbox); */ | |
850 gtk_container_add(GTK_CONTAINER(applet), vbox); | |
851 | |
852 gtk_signal_connect(GTK_OBJECT(drawing_area),"expose_event", | |
853 (GtkSignalFunc) expose_event, NULL); | |
854 | |
855 gtk_signal_connect(GTK_OBJECT(drawing_area),"configure_event", | |
856 (GtkSignalFunc) configure_event, NULL); | |
857 | |
858 | |
859 destroycb = gtk_signal_connect(GTK_OBJECT(applet), "destroy", | |
860 GTK_SIGNAL_FUNC(remove_self), handle); | |
861 | |
862 | |
863 | |
864 gtk_widget_show (applet); | |
865 create_gc(); | |
866 | |
867 /* load_properties(APPLET_WIDGET(applet)->privcfgpath); */ | |
868 | |
869 setup_colors(); | |
870 load_fonts(); | |
871 updateOutput(); | |
872 | |
873 | |
874 /* KEEPING TIMER ID FOR CLEANUP IN DESTROY */ | |
875 drawTimeID = gtk_timeout_add(2,Repaint,drawing_area); | |
876 updateTimeID = gtk_timeout_add(props.timeout * 60000, | |
877 (gpointer)updateOutput,"NULL"); | |
878 | |
879 | |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
426
diff
changeset
|
880 return NULL; |
426 | 881 } |
882 | |
883 | |
884 | |
885 /*-----------------------------------------------------------------*/ | |
886 void updateOutput() { | |
887 if ( http_got() == -1 || !(configured()) ) { | |
888 reSetOutputArray(); | |
889 printf("No data!\n"); | |
890 setOutputArray("No data available or properties not set"); | |
891 } | |
892 } | |
893 | |
894 | |
895 | |
896 | |
897 /* JHACK */ | |
898 /*-----------------------------------------------------------------*/ | |
899 void gaim_plugin_remove() { | |
900 gtk_signal_disconnect(GTK_OBJECT(applet), destroycb); | |
901 if (drawTimeID > 0) { gtk_timeout_remove(drawTimeID); } | |
902 if (updateTimeID >0) { gtk_timeout_remove(updateTimeID); } | |
903 gtk_widget_destroy(applet); | |
904 } | |
905 | |
906 | |
907 | |
908 | |
909 | |
910 /*HERE*/ | |
911 /*-----------------------------------------------------------------*/ | |
912 static void reSetOutputArray() { | |
913 int i; | |
914 | |
915 for (i=0;i<LEN;i++) { | |
916 /* CLEAR EACH SYMBOL'S SPACE */ | |
917 memset(outputArray[i],0,sizeof(outputArray[i])); | |
918 | |
919 /* CLEAR ASSOC COLOR ARRAY */ | |
920 colorArray[i] = 0; | |
921 | |
922 /* CLEAR ADDITIONAL INFO */ | |
923 memset(changeArray[i],0,sizeof(changeArray[i])); | |
924 | |
925 } | |
926 | |
927 setCounter = 0; | |
928 getCounter = 0; | |
929 setColorCounter = 0; | |
930 getColorCounter = 0; | |
931 | |
932 } | |
933 | |
934 | |
935 /*-----------------------------------------------------------------*/ | |
936 char *splitPrice(char *data) { | |
937 char buff[128]=""; | |
938 static char buff2[128]=""; | |
939 char *var1, *var2; | |
940 int i; | |
941 | |
942 strcpy(buff,data); | |
943 var1 = strtok(buff,":"); | |
944 var2 = strtok(NULL,":"); | |
945 | |
946 sprintf(buff2," %s %s",var1,var2); | |
947 return(buff2); | |
948 } | |
949 | |
950 /*-----------------------------------------------------------------*/ | |
951 char *splitChange(char *data) { | |
952 char buff[128]=""; | |
953 static char buff2[128]=""; | |
954 char *var1, *var2, *var3, *var4; | |
955 int i; | |
956 | |
957 strcpy(buff,data); | |
958 var1 = strtok(buff,":"); | |
959 var2 = strtok(NULL,":"); | |
960 var3 = strtok(NULL,":"); | |
961 var4 = strtok(NULL,""); | |
962 | |
963 if (var3[0] == '+') { | |
964 if (symbolfont) | |
965 var3[0] = 221; | |
966 var4[0] = '('; | |
967 } | |
968 else if (var3[0] == '-') { | |
969 if (symbolfont) | |
970 var3[0] = 223; | |
971 var4[0] = '('; | |
972 } | |
973 else { | |
974 var3 = strdup(_("(No")); | |
975 var4 = strdup(_("Change")); | |
976 } | |
977 | |
978 sprintf(buff2,"%s %s)",var3,var4); | |
979 return(buff2); | |
980 } | |
981 | |
982 /*-----------------------------------------------------------------*/ | |
983 static void setOutputArray(char *param1) { | |
984 char *price; | |
985 char *change; | |
986 | |
987 price = splitPrice(param1); | |
988 change = splitChange(param1); | |
989 | |
990 if (setCounter < LEN) { | |
991 | |
992 strcpy(outputArray[setCounter],price); | |
993 strcpy(changeArray[setCounter],change); | |
994 } | |
995 setCounter++; | |
996 } | |
997 | |
998 | |
999 | |
1000 /*-----------------------------------------------------------------*/ | |
1001 static void setColorArray(int theColor) { | |
1002 if (setColorCounter < LEN) { | |
1003 colorArray[setColorCounter] = theColor; | |
1004 } | |
1005 setColorCounter++; | |
1006 } | |
1007 | |
1008 void setup_colors(void) { | |
1009 GdkColormap *colormap; | |
1010 | |
1011 colormap = gtk_widget_get_colormap(drawing_area); | |
1012 | |
1013 gdk_color_parse(props.ucolor, &gdkUcolor); | |
1014 gdk_color_alloc(colormap, &gdkUcolor); | |
1015 | |
1016 gdk_color_parse(props.dcolor, &gdkDcolor); | |
1017 gdk_color_alloc(colormap, &gdkDcolor); | |
1018 } | |
1019 | |
1020 | |
1021 int create_gc(void) { | |
1022 gc = gdk_gc_new( drawing_area->window ); | |
1023 gdk_gc_copy( gc, drawing_area->style->white_gc ); | |
1024 return 0; | |
1025 } |