Thu, 23 Mar 2000 03:13:54 +0000
[gaim-migrate @ 10]
The other missing files :)
| 1 | 1 | /************************************************************** |
| 2 | ** | |
| 3 | ** GaimGnomeAppletMgr | |
| 4 | ** Author - Quinticent (John Palmieri: johnp@martianrock.com) | |
| 5 | ** | |
| 6 | ** Purpose - Takes over the task of managing the GNOME applet | |
| 7 | ** code and provides a centralized codebase for | |
| 8 | ** GNOME integration for Gaim. | |
| 9 | ** | |
| 10 | ** | |
| 11 | ** gaim | |
| 12 | ** | |
| 13 | ** Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
| 14 | ** | |
| 15 | ** This program is free software; you can redistribute it and/or modify | |
| 16 | ** it under the terms of the GNU General Public License as published by | |
| 17 | ** the Free Software Foundation; either version 2 of the License, or | |
| 18 | ** (at your option) any later version. | |
| 19 | ** | |
| 20 | ** This program is distributed in the hope that it will be useful, | |
| 21 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 22 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 23 | ** GNU General Public License for more details. | |
| 24 | ** | |
| 25 | ** You should have received a copy of the GNU General Public License | |
| 26 | ** along with this program; if not, write to the Free Software | |
| 27 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 28 | */ | |
| 29 | ||
| 30 | #ifdef USE_APPLET | |
| 31 | #include <string.h> | |
| 32 | #include <gdk_imlib.h> | |
| 33 | #include "gaim.h" | |
| 34 | #include "gnome_applet_mgr.h" | |
| 35 | ||
| 36 | enum gaim_user_states MRI_user_status; | |
| 37 | gint total_num_of_buddies; /* how many buddies I have in my list */ | |
| 38 | gint num_of_buddies_online; /* how many of them are online */ | |
| 39 | ||
| 40 | gboolean buddy_created = FALSE; | |
| 41 | gboolean applet_draw_open = FALSE; | |
| 42 | GtkWidget *applet_popup = NULL; | |
| 43 | ||
| 44 | GtkWidget *applet; | |
| 45 | GtkWidget *button; | |
| 46 | GtkWidget *status_label; | |
| 47 | ||
| 48 | GtkWidget *icon; | |
| 49 | GdkPixmap *icon_offline_pm=NULL; | |
| 50 | GdkPixmap *icon_offline_bm=NULL; | |
| 51 | ||
| 52 | GdkPixmap *icon_online_pm=NULL; | |
| 53 | GdkPixmap *icon_online_bm=NULL; | |
| 54 | ||
| 55 | GdkPixmap *icon_connect_pm=NULL; | |
| 56 | GdkPixmap *icon_connect_bm=NULL; | |
| 57 | ||
| 58 | GdkPixmap *icon_msg_pending_pm=NULL; | |
| 59 | GdkPixmap *icon_msg_pending_bm=NULL; | |
| 60 | ||
| 61 | GdkPixmap *icon_away_pm=NULL; | |
| 62 | GdkPixmap *icon_away_bm=NULL; | |
| 63 | ||
| 64 | /*************************************************************** | |
| 65 | ** | |
| 66 | ** function load_applet_icon | |
| 67 | ** visibility - private | |
| 68 | ** | |
| 69 | ** input: | |
| 70 | ** name - the name of the file to load | |
| 71 | ** height, width - the height and width | |
| 72 | ** that the icon should be | |
| 73 | ** scaled to. | |
| 74 | ** | |
| 75 | ** output: | |
| 76 | ** TRUE - success | |
| 77 | ** FALSE - failure | |
| 78 | ** pm - a GdkPixmap structure that the icon is loaded into | |
| 79 | ** bm - a GdkBitmap structure that the icon's transparancy | |
| 80 | ** mask is loaded into | |
| 81 | ** | |
| 82 | ** description - loads an icon from | |
| 83 | ** /usr/share/pixmap/gaim/gnome/ | |
| 84 | ** and scales it using imlib | |
| 85 | ** | |
| 86 | ****************************************************************/ | |
| 87 | ||
| 88 | gboolean load_applet_icon( const char *name, int height, int width, GdkPixmap **pm, GdkBitmap **bm ){ | |
| 89 | gboolean result = TRUE; | |
| 90 | char path[255] = GAIM_GNOME_PIXMAP_DIR; | |
| 91 | GdkImlibImage *im; | |
| 92 | GdkPixmap *temp_pm; | |
| 93 | GdkPixmap *temp_bm; | |
| 94 | ||
| 95 | strcat( path, name); | |
| 96 | ||
| 97 | im=gdk_imlib_load_image( path ); | |
| 98 | ||
| 99 | if ((*pm)!=NULL) | |
| 100 | gdk_imlib_free_pixmap((*pm)); | |
| 101 | ||
| 102 | if( im!= NULL ){ | |
| 103 | gdk_imlib_render(im,width,height); | |
| 104 | ||
| 105 | (*pm) = gdk_imlib_move_image(im); | |
| 106 | (*bm) = gdk_imlib_move_mask(im); | |
| 107 | ||
| 108 | } else { | |
| 109 | result = FALSE; | |
| 110 | sprintf(debug_buff,"file not found: %s\n",path); | |
| 111 | debug_print(debug_buff); | |
| 112 | } | |
| 113 | ||
| 114 | return result; | |
| 115 | } | |
| 116 | ||
| 117 | /*************************************************************** | |
| 118 | ** | |
| 119 | ** function update_applet | |
| 120 | ** visibility - private | |
| 121 | ** | |
| 122 | ** input: | |
| 123 | ** ap - not in use | |
| 124 | ** | |
| 125 | ** description - takes care of swapping status icons and | |
| 126 | ** updating the status label | |
| 127 | ** | |
| 128 | ****************************************************************/ | |
| 129 | ||
| 130 | gboolean update_applet( gpointer *ap ){ | |
| 131 | char temp_string[25]; | |
| 132 | static enum gaim_user_states old_user_status = offline; | |
| 133 | static gint old_total_num_of_buddies = -1; | |
| 134 | static gint old_num_of_buddies_online = -1; | |
| 135 | if( applet_draw_open ){ | |
| 136 | sprintf(debug_buff, "Drawer is open\n"); | |
| 137 | debug_print(debug_buff); | |
| 138 | } else { | |
| 139 | sprintf(debug_buff, "Drawer is closed\n"); | |
| 140 | debug_print(debug_buff); | |
| 141 | } | |
| 142 | ||
| 143 | if( MRI_user_status != old_user_status ){ | |
| 144 | ||
| 145 | switch( MRI_user_status ){ | |
| 146 | case offline: | |
| 147 | gtk_pixmap_set( GTK_PIXMAP(icon), | |
| 148 | icon_offline_pm, | |
| 149 | icon_offline_bm ); | |
| 150 | gtk_label_set( GTK_LABEL(status_label), _MSG_OFFLINE_ ); | |
| 151 | break; | |
| 152 | case signing_on: | |
| 153 | gtk_pixmap_set( GTK_PIXMAP(icon), | |
| 154 | icon_connect_pm, | |
| 155 | icon_connect_bm ); | |
| 156 | gtk_label_set( GTK_LABEL(status_label), _MSG_CONNECT_ ); | |
| 157 | old_total_num_of_buddies = -1; | |
| 158 | old_num_of_buddies_online = -1; | |
| 159 | break; | |
| 160 | case online: | |
| 161 | gtk_pixmap_set( GTK_PIXMAP(icon), | |
| 162 | icon_online_pm, | |
| 163 | icon_online_bm ); | |
| 164 | ||
| 165 | gtk_label_set( GTK_LABEL(status_label), _MSG_ONLINE_ ); | |
| 166 | break; | |
| 167 | ||
| 168 | case unread_message_pending: | |
| 169 | gtk_pixmap_set( GTK_PIXMAP(icon), | |
| 170 | icon_msg_pending_pm, | |
| 171 | icon_msg_pending_bm ); | |
| 172 | gtk_label_set( GTK_LABEL(status_label), "msg" ); | |
| 173 | break; | |
| 174 | case away: | |
| 175 | gtk_pixmap_set( GTK_PIXMAP(icon), | |
| 176 | icon_away_pm, | |
| 177 | icon_away_bm ); | |
| 178 | gtk_label_set( GTK_LABEL(status_label), "Away" ); | |
| 179 | break; | |
| 180 | } | |
| 181 | old_user_status = MRI_user_status; | |
| 182 | } | |
| 183 | #ifdef _USE_BUDDY_COUNT_ | |
| 184 | if( (( old_total_num_of_buddies != total_num_of_buddies ) || | |
| 185 | ( old_num_of_buddies_online != num_of_buddies_online )) && | |
| 186 | ( MRI_user_status == online ) ){ | |
| 187 | /*make user buffer can not overflow*/ | |
| 188 | if(total_num_of_buddies<1000){ | |
| 189 | sprintf(temp_string, "%i/%i", num_of_buddies_online, total_num_of_buddies); | |
| 190 | } else { | |
| 191 | if(num_of_buddies_online<100000){ | |
| 192 | sprintf(temp_string, "%i", num_of_buddies_online); | |
| 193 | } else { | |
| 194 | /*we most likely will never get to here but | |
| 195 | hey, people also thought computer wouldn't | |
| 196 | be around by the year 2000 :-) */ | |
| 197 | sprintf(temp_string, _MSG_ONLINE_ ); | |
| 198 | } | |
| 199 | } | |
| 200 | gtk_label_set( GTK_LABEL(status_label), temp_string ); | |
| 201 | old_total_num_of_buddies = total_num_of_buddies; | |
| 202 | old_num_of_buddies_online = num_of_buddies_online; | |
| 203 | } | |
| 204 | #endif /*_USE_BUDDY_COUNT_*/ | |
| 205 | return TRUE; | |
| 206 | ||
| 207 | } | |
| 208 | ||
| 209 | ||
| 210 | /*************************************************************** | |
| 211 | ** | |
| 212 | ** function make_buddy | |
| 213 | ** visibility - private | |
| 214 | ** | |
| 215 | ** description - If buddylist is not created create it | |
| 216 | ** else show the buddy list | |
| 217 | ** | |
| 218 | ****************************************************************/ | |
| 219 | void make_buddy(void) { | |
| 220 | set_applet_draw_open(); | |
| 221 | if( !buddy_created ){ | |
| 222 | show_buddy_list(); | |
| 223 | buddy_created = TRUE; | |
| 224 | } else { | |
| 225 | gnome_buddy_show(); | |
| 226 | } | |
| 227 | applet_widget_unregister_callback(APPLET_WIDGET(applet),"buddy"); | |
| 228 | ||
| 229 | } | |
| 230 | ||
| 231 | /*************************************************************** | |
| 232 | ** | |
| 233 | ** function applet_show_login | |
| 234 | ** visibility - private | |
| 235 | ** | |
| 236 | ** input: | |
| 237 | ** | |
| 238 | ** | |
| 239 | ** description - I guess it shows the login dialog | |
| 240 | ** | |
| 241 | ****************************************************************/ | |
| 242 | ||
| 243 | void applet_show_login(AppletWidget *widget, gpointer data) { | |
| 244 | show_login(); | |
| 245 | applet_widget_unregister_callback(APPLET_WIDGET(applet),"signon"); | |
| 246 | applet_widget_register_callback(APPLET_WIDGET(applet), | |
| 247 | "signoff", | |
| 248 | _("Signoff"), | |
| 249 | signoff, | |
| 250 | NULL); | |
| 251 | applet_widget_register_callback(APPLET_WIDGET(applet), | |
| 252 | "away", | |
| 253 | _("Away Message"), | |
| 254 | show_away_mess, | |
| 255 | NULL); | |
| 256 | applet_widget_register_callback(APPLET_WIDGET(applet), | |
| 257 | "buddy", | |
| 258 | _("Buddy List"), | |
| 259 | (AppletCallbackFunc)make_buddy, | |
| 260 | NULL); | |
| 261 | } | |
| 262 | ||
| 263 | /*************************************************************** | |
| 264 | ** | |
| 265 | ** function applet_show_about | |
| 266 | ** visibility - public | |
| 267 | ** | |
| 268 | ** | |
| 269 | ** description - takes care of creating and | |
| 270 | ** displaying the about box | |
| 271 | ** | |
| 272 | ****************************************************************/ | |
| 273 | void applet_show_about(AppletWidget *widget, gpointer data) { | |
| 274 | ||
| 275 | const gchar *authors[] = {"Mark Spencer <markster@marko.net>", | |
| 276 | "Jim Duchek <jimduchek@ou.edu>", | |
| 277 | "Rob Flynn <rflynn@blueridge.net>", | |
| 278 | ||
| 279 | NULL}; | |
| 280 | ||
| 281 | GtkWidget *about=gnome_about_new(_("GAIM"), | |
| 282 | _(VERSION), | |
| 283 | _(""), | |
| 284 | authors, | |
| 285 | "", | |
| 286 | NULL); | |
| 287 | gtk_widget_show(about); | |
| 288 | } | |
| 289 | ||
| 290 | /*************************************************************** | |
| 291 | ** | |
| 292 | ** function AppletCancelLogin (name should be changed to | |
| 293 | ** applet_cancel_login) | |
| 294 | ** visibility - public | |
| 295 | ** | |
| 296 | ** description - called when user cancels login | |
| 297 | ** | |
| 298 | ****************************************************************/ | |
| 299 | void AppletCancelLogon(){ | |
| 300 | applet_widget_unregister_callback(APPLET_WIDGET(applet),"signoff"); | |
| 301 | applet_widget_register_callback(APPLET_WIDGET(applet), | |
| 302 | "signon", | |
| 303 | _("Signon"), | |
| 304 | applet_show_login, | |
| 305 | NULL); | |
| 306 | } | |
| 307 | ||
| 308 | /*************************************************************** | |
| 309 | ** | |
| 310 | ** function get_applet_pos | |
| 311 | ** visibility - private | |
| 312 | ** | |
| 313 | ** output: | |
| 314 | ** GtKAllocation - a Gtk struct that holds the | |
| 315 | ** position of the dialog | |
| 316 | ** | |
| 317 | ** description - returns the x,y position the buddy list should | |
| 318 | ** should be placed based on the position | |
| 319 | ** of the applet and the orientation | |
| 320 | ** of the Gnome panel. | |
| 321 | ** | |
| 322 | ****************************************************************/ | |
| 323 | GtkAllocation get_applet_pos(){ | |
| 324 | GtkAllocation pos; | |
| 325 | gint x,y,pad; | |
| 326 | GtkRequisition buddy_req, applet_req; | |
| 327 | GtkAllocation result; | |
| 328 | GNOME_Panel_OrientType orient = applet_widget_get_panel_orient( APPLET_WIDGET(applet) ); | |
| 329 | pad = 5; | |
| 330 | gdk_window_get_position( gtk_widget_get_parent_window( button ),&x,&y ); | |
| 331 | buddy_req = gnome_buddy_get_dimentions(); | |
| 332 | applet_req = button->requisition; | |
| 333 | switch( orient ){ | |
| 334 | case ORIENT_UP: | |
| 335 | result.x=x; | |
| 336 | result.y=y-(buddy_req.height+pad); | |
| 337 | break; | |
| 338 | case ORIENT_DOWN: | |
| 339 | result.x=x; | |
| 340 | result.y=y+applet_req.height+pad; | |
| 341 | ||
| 342 | break; | |
| 343 | case ORIENT_LEFT: | |
| 344 | result.x=x-(buddy_req.width + pad ); | |
| 345 | result.y=y; | |
| 346 | break; | |
| 347 | case ORIENT_RIGHT: | |
| 348 | result.x=x+applet_req.width+pad; | |
| 349 | result.y=y; | |
| 350 | break; | |
| 351 | } | |
| 352 | ||
| 353 | ||
| 354 | return result; | |
| 355 | } | |
| 356 | ||
| 357 | ||
| 358 | ||
| 359 | void createOfflinePopup(){ | |
| 360 | applet_show_login( APPLET_WIDGET(applet), NULL ); | |
| 361 | } | |
| 362 | ||
| 363 | ||
| 364 | void createSignonPopup(){ | |
| 365 | applet_draw_open = FALSE; | |
| 366 | } | |
| 367 | ||
| 368 | ||
| 369 | void createOnlinePopup(){ | |
| 370 | GtkAllocation al; | |
| 371 | make_buddy(); | |
| 372 | al = get_applet_pos(); | |
| 373 | gnome_buddy_set_pos( al.x, al.y ); | |
| 374 | } | |
| 375 | ||
| 376 | ||
| 377 | void createPendingPopup(){ | |
| 378 | applet_draw_open = FALSE; | |
| 379 | } | |
| 380 | ||
| 381 | ||
| 382 | void createAwayPopup(){ | |
| 383 | applet_draw_open = FALSE; | |
| 384 | } | |
| 385 | ||
| 386 | ||
| 387 | void closeOfflinePopup(){ | |
| 388 | cancel_logon(); | |
| 389 | set_applet_draw_closed(); | |
| 390 | } | |
| 391 | ||
| 392 | ||
| 393 | void closeSignonPopup(){ | |
| 394 | ||
| 395 | } | |
| 396 | ||
| 397 | ||
| 398 | void closeOnlinePopup(){ | |
| 399 | set_applet_draw_closed(); | |
| 400 | applet_destroy_buddy(); | |
| 401 | } | |
| 402 | ||
| 403 | ||
| 404 | void closePendingPopup(){ | |
| 405 | applet_draw_open = FALSE; | |
| 406 | } | |
| 407 | ||
| 408 | ||
| 409 | void closeAwayPopup(){ | |
| 410 | applet_draw_open = FALSE; | |
| 411 | } | |
| 412 | ||
| 413 | /************************************************** | |
| 414 | ** | |
| 415 | ** Dummy function to fix compiles for gnome | |
| 416 | ** Feel free to implement an away message | |
| 417 | ** | |
| 418 | ***************************************************/ | |
| 419 | void show_away_mess( AppletWidget *widget, gpointer data ) { | |
| 420 | } | |
| 421 | ||
| 422 | void AppletClicked( GtkWidget *sender, gpointer data ){ | |
| 423 | ||
| 424 | if( applet_draw_open ){ | |
| 425 | switch( MRI_user_status ){ | |
| 426 | case offline: | |
| 427 | closeOfflinePopup(); | |
| 428 | break; | |
| 429 | case signing_on: | |
| 430 | closeSignonPopup(); | |
| 431 | break; | |
| 432 | case online: | |
| 433 | closeOnlinePopup(); | |
| 434 | ||
| 435 | break; | |
| 436 | case unread_message_pending: | |
| 437 | closePendingPopup(); | |
| 438 | break; | |
| 439 | case away: | |
| 440 | closeAwayPopup(); | |
| 441 | break; | |
| 442 | } | |
| 443 | } else { | |
| 444 | set_applet_draw_open(); | |
| 445 | switch( MRI_user_status ){ | |
| 446 | case offline: | |
| 447 | createOfflinePopup(); | |
| 448 | break; | |
| 449 | case signing_on: | |
| 450 | createSignonPopup(); | |
| 451 | break; | |
| 452 | case online: | |
| 453 | createOnlinePopup(); | |
| 454 | break; | |
| 455 | case unread_message_pending: | |
| 456 | createPendingPopup(); | |
| 457 | break; | |
| 458 | case away: | |
| 459 | createAwayPopup(); | |
| 460 | break; | |
| 461 | } | |
| 462 | ||
| 463 | ||
| 464 | } | |
| 465 | } | |
| 466 | ||
| 467 | ||
| 468 | #ifdef HAVE_PANEL_SIZE | |
| 469 | /*************************************************************** | |
| 470 | ** | |
| 471 | ** Code for panel resizing | |
| 472 | ** | |
| 473 | ****************************************************************/ | |
| 474 | static void applet_change_size(GtkWidget *w, PanelSizeType o, gpointer data) { | |
| 475 | switch(o) { | |
| 476 | case SIZE_TINY: | |
| 477 | /*24x24*/ | |
| 478 | gtk_widget_set_usize( button, 24,24 ); | |
| 479 | ||
| 480 | /*load offline icon*/ | |
| 481 | load_applet_icon( GAIM_GNOME_OFFLINE_ICON, | |
| 482 | 24, 24, &icon_offline_pm, &icon_offline_bm ); | |
| 483 | ||
| 484 | /*load connecting icon*/ | |
| 485 | load_applet_icon( GAIM_GNOME_CONNECT_ICON, | |
| 486 | 24, 24, &icon_connect_pm, &icon_connect_bm ); | |
| 487 | ||
| 488 | /*load online icon*/ | |
| 489 | load_applet_icon( GAIM_GNOME_ONLINE_ICON, | |
| 490 | 24, 24, &icon_online_pm, &icon_online_bm ); | |
| 491 | break; | |
| 492 | ||
| 493 | case SIZE_STANDARD: | |
| 494 | /*48x48*/ | |
| 495 | gtk_widget_set_usize( button, 48,48 ); | |
| 496 | ||
| 497 | /*load offline icon*/ | |
| 498 | load_applet_icon( GAIM_GNOME_OFFLINE_ICON, | |
| 499 | 32, 34, &icon_offline_pm, &icon_offline_bm ); | |
| 500 | ||
| 501 | /*load connecting icon*/ | |
| 502 | load_applet_icon( GAIM_GNOME_CONNECT_ICON, | |
| 503 | 32, 34, &icon_connect_pm, &icon_connect_bm ); | |
| 504 | ||
| 505 | /*load online icon*/ | |
| 506 | load_applet_icon( GAIM_GNOME_ONLINE_ICON, | |
| 507 | 32, 34, &icon_online_pm, &icon_online_bm ); | |
| 508 | break; | |
| 509 | ||
| 510 | case SIZE_LARGE: | |
| 511 | /*64x64*/ | |
| 512 | gtk_widget_set_usize( button, 64, 64 ); | |
| 513 | ||
| 514 | /*load offline icon*/ | |
| 515 | load_applet_icon( GAIM_GNOME_OFFLINE_ICON, | |
| 516 | 55, 55, &icon_offline_pm, &icon_offline_bm ); | |
| 517 | ||
| 518 | /*load connecting icon*/ | |
| 519 | load_applet_icon( GAIM_GNOME_CONNECT_ICON, | |
| 520 | 55, 55, &icon_connect_pm, &icon_connect_bm ); | |
| 521 | ||
| 522 | /*load online icon*/ | |
| 523 | load_applet_icon( GAIM_GNOME_ONLINE_ICON, | |
| 524 | 55, 55, &icon_online_pm, &icon_online_bm ); | |
| 525 | break; | |
| 526 | ||
| 527 | case SIZE_HUGE: | |
| 528 | /*80x80*/ | |
| 529 | gtk_widget_set_usize( button, 80, 80 ); | |
| 530 | ||
| 531 | /*load offline icon*/ | |
| 532 | load_applet_icon( GAIM_GNOME_OFFLINE_ICON, | |
| 533 | 70, 70, &icon_offline_pm, &icon_offline_bm ); | |
| 534 | ||
| 535 | /*load connecting icon*/ | |
| 536 | load_applet_icon( GAIM_GNOME_CONNECT_ICON, | |
| 537 | 70, 70, &icon_connect_pm, &icon_connect_bm ); | |
| 538 | ||
| 539 | /*load online icon*/ | |
| 540 | load_applet_icon( GAIM_GNOME_ONLINE_ICON, | |
| 541 | 70, 70, &icon_online_pm, &icon_online_bm ); | |
| 542 | ||
| 543 | break; | |
| 544 | } | |
| 545 | } | |
| 546 | #endif /*HAVE_PANEL_SIZE*/ | |
| 547 | ||
| 548 | ||
| 549 | /*************************************************************** | |
| 550 | ** | |
| 551 | ** Initialize GNOME stuff | |
| 552 | ** | |
| 553 | ****************************************************************/ | |
| 554 | ||
| 555 | gint InitAppletMgr( int argc, char *argv[] ){ | |
| 556 | GtkWidget *vbox; | |
| 557 | ||
| 558 | GtkStyle *label_style; | |
| 559 | GdkFont *label_font = NULL; | |
| 560 | ||
| 561 | applet_widget_init("GAIM",VERSION,argc,argv,NULL,0,NULL); | |
| 562 | ||
| 563 | /*init imlib for graphics*/ | |
| 564 | gdk_imlib_init(); | |
| 565 | gtk_widget_push_visual(gdk_imlib_get_visual()); | |
| 566 | gtk_widget_push_colormap(gdk_imlib_get_colormap()); | |
| 567 | ||
| 568 | applet=applet_widget_new("gaim_applet"); | |
| 569 | if(!applet) g_error(_("Can't create GAIM applet!")); | |
| 570 | ||
| 571 | button=gtk_button_new(); | |
| 572 | ||
| 573 | ||
| 574 | gtk_widget_set_usize( button, 48,48 ); | |
| 575 | ||
| 576 | ||
| 577 | /*load offline icon*/ | |
| 578 | load_applet_icon( GAIM_GNOME_OFFLINE_ICON, | |
| 579 | 32, 32, &icon_offline_pm, &icon_offline_bm ); | |
| 580 | ||
| 581 | /*load connecting icon*/ | |
| 582 | load_applet_icon( GAIM_GNOME_CONNECT_ICON, | |
| 583 | 32, 32, &icon_connect_pm, &icon_connect_bm ); | |
| 584 | ||
| 585 | /*load online icon*/ | |
| 586 | load_applet_icon( GAIM_GNOME_ONLINE_ICON, | |
| 587 | 32, 32, &icon_online_pm, &icon_online_bm ); | |
| 588 | ||
| 589 | /*icon_away and icon_msg_pennding need to be implemented*/ | |
| 590 | ||
| 591 | icon=gtk_pixmap_new(icon_offline_pm,icon_offline_bm); | |
| 592 | ||
| 593 | gtk_timeout_add( 1500, (GtkFunction)update_applet, NULL ); | |
| 594 | ||
| 595 | vbox = gtk_vbox_new(FALSE,0); | |
| 596 | ||
| 597 | gtk_box_pack_start(GTK_BOX(vbox), icon, FALSE, TRUE, 0); | |
| 598 | ||
| 599 | status_label = gtk_label_new("Offline"); | |
| 600 | /*set this label's font*/ | |
| 601 | label_style = gtk_widget_get_style( status_label ); | |
| 602 | ||
| 603 | label_font = gdk_font_load( _MSG_FONT_ ); | |
| 604 | ||
| 605 | ||
| 606 | if( label_font != NULL ){ | |
| 607 | label_style->font = label_font; | |
| 608 | gtk_widget_set_style( status_label, label_style ); | |
| 609 | } else { | |
| 610 | sprintf(debug_buff, "Font does not exist" ); | |
| 611 | debug_print(debug_buff); | |
| 612 | } | |
| 613 | ||
| 614 | #ifdef HAVE_PANEL_SIZE | |
| 615 | gtk_signal_connect(GTK_OBJECT(applet),"change_size", | |
| 616 | GTK_SIGNAL_FUNC(applet_change_size), | |
| 617 | NULL); | |
| 618 | #endif /*HAVE_PANEL_SIZE*/ | |
| 619 | ||
| 620 | gtk_box_pack_start(GTK_BOX(vbox), status_label, FALSE, TRUE, 0); | |
| 621 | ||
| 622 | gtk_container_add( GTK_CONTAINER(button), vbox ); | |
| 623 | applet_widget_add(APPLET_WIDGET(applet), button); | |
| 624 | ||
| 625 | gtk_widget_show( status_label ); | |
| 626 | gtk_widget_show( vbox ); | |
| 627 | gtk_widget_show( button ); | |
| 628 | ||
| 629 | applet_widget_set_tooltip(APPLET_WIDGET(applet),"GAIM"); | |
| 630 | ||
| 631 | applet_widget_register_stock_callback(APPLET_WIDGET(applet), | |
| 632 | "about", | |
| 633 | GNOME_STOCK_MENU_ABOUT, | |
| 634 | _("About..."), | |
| 635 | applet_show_about, | |
| 636 | NULL); | |
| 637 | ||
| 638 | gtk_signal_connect( GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC( AppletClicked), NULL); | |
| 639 | ||
| 640 | gtk_widget_show(icon); | |
| 641 | gtk_widget_show(applet); | |
| 642 | return 0; | |
| 643 | } | |
| 644 | ||
| 645 | void setUserState( enum gaim_user_states state ){ | |
| 646 | MRI_user_status = state; | |
| 647 | update_applet( (gpointer *)applet ); | |
| 648 | } | |
| 649 | ||
| 650 | void setTotalBuddies( gint num ){ | |
| 651 | total_num_of_buddies = num; | |
| 652 | } | |
| 653 | ||
| 654 | void setNumBuddiesOnline( gint num ){ | |
| 655 | num_of_buddies_online=num; | |
| 656 | } | |
| 657 | ||
| 658 | enum gaim_user_states getUserState(){ | |
| 659 | return MRI_user_status; | |
| 660 | } | |
| 661 | ||
| 662 | gint getTotalBuddies(){ | |
| 663 | return total_num_of_buddies; | |
| 664 | } | |
| 665 | ||
| 666 | gint getNumBuddiesOnline(){ | |
| 667 | return num_of_buddies_online; | |
| 668 | } | |
| 669 | ||
| 670 | void set_applet_draw_open(){ | |
| 671 | applet_draw_open = TRUE; | |
| 672 | } | |
| 673 | ||
| 674 | void set_applet_draw_closed(){ | |
| 675 | applet_draw_open = FALSE; | |
| 676 | } | |
| 677 | ||
| 678 | #endif /*USE_APPLET*/ |