/* Away Box 0.0.3 2005-09-18 */ /* (C) 2005 Jeff Kaufman and released under the GPL*/ /* Modified from: One Button Away 0.4 2005-06-19 Public Domain (P) 2005 */ #ifdef HAVE_CONFIG_H # include #endif #ifndef GAIM_PLUGINS # define GAIM_PLUGINS #endif #include "gaim.h" #include "internal.h" // necessary plugin stuff #include "version.h" // necessary plugin stuff #include "gtkplugin.h" // necessary for GAIM_GTK_PLUGIN_TYPE (?!) #include "gtkutils.h" // necessary for GaimButtonOrientation #include "stock.h" // necessary for icon #include "gtkblist.h" // duhh #include "away.h" // duhhhh #include "plugin.h" #include "pluginpref.h" #include "prefs.h" GtkWidget *button = NULL; GtkWidget *textbox = NULL; GtkWidget *hbox_holder = NULL; gboolean show_button_and_box(GaimPlugin* plug); gboolean hide_button_and_box(); // This is run when the button is pressed or they type an enter on the field static void awaybox_cb() { const char* txt = (gtk_entry_get_text(GTK_ENTRY(textbox))); if(txt != NULL && strlen(txt) > 0) { /* fprintf(stderr, "awaybox: setting away to \"%s\".\n",txt);*/ static struct away_message a; if(txt != NULL) g_snprintf(a.message, sizeof(a.message), txt); do_away_message(awayqueue, &a); } } static void handle_account_away(GaimAccount *account, const char *state, const char *message, void* data) { /* fprintf(stderr,"awaybox: Away with message: \"%s\".\n",message);*/ if(message == NULL) show_button_and_box((GaimPlugin*)data); else hide_button_and_box(); } // This is called when the plugin starts up along with gaim static void make_button_and_box(GaimBuddyList *blist) { GaimGtkBuddyList *gtkblist; if(button != NULL || textbox != NULL || hbox_holder != NULL) return; if(blist != NULL) gtkblist = GAIM_GTK_BLIST(blist); else gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); hbox_holder = gtk_hbox_new(FALSE,2); if(gaim_prefs_get_bool("/plugins/gtk/awaybox/button_showtext")) { if(gaim_prefs_get_bool("/plugins/gtk/awaybox/button_showicon")) button = gaim_pixbuf_button_from_stock("Go Away", GAIM_STOCK_ICON_AWAY, GAIM_BUTTON_HORIZONTAL); else button = gaim_pixbuf_button_from_stock("Go Away", NULL, -1); } else { if(gaim_prefs_get_bool("/plugins/gtk/awaybox/button_showicon")) button = gaim_pixbuf_button_from_stock(NULL, GAIM_STOCK_ICON_AWAY, GAIM_BUTTON_HORIZONTAL); else button = NULL; } textbox = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(hbox_holder), textbox, TRUE, TRUE, 0); if(button != NULL) gtk_box_pack_start(GTK_BOX(hbox_holder), button, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(gtkblist->vbox), hbox_holder, FALSE, FALSE, 0); if(button != NULL) gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); if(button != NULL) g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(awaybox_cb), NULL); g_signal_connect(G_OBJECT(textbox), "activate", G_CALLBACK(awaybox_cb), NULL); if(button != NULL) gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, "Set yourself away with this away message.", NULL); gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), textbox, "Enter an away message here.", NULL); if(button != NULL) g_object_set_data(G_OBJECT(button), "button_name", "awaybox_but"); g_object_set_data(G_OBJECT(textbox), "entry_name", "awaybox_box"); gtk_widget_show_all(hbox_holder); gaim_gtk_blist_update_toolbar(); } gboolean show_button_and_box(GaimPlugin* plug) { gaim_signal_connect(gaim_gtk_blist_get_handle(), "gtkblist-created", plug, GAIM_CALLBACK(make_button_and_box), NULL); if (gaim_get_blist() != NULL && GTK_IS_WINDOW((GAIM_GTK_BLIST(gaim_get_blist()))->window)) make_button_and_box(gaim_get_blist()); return TRUE; } static gboolean plugin_load(GaimPlugin *plugin) { /* fprintf(stderr,"awaybox: loaded.\n");*/ gaim_prefs_add_none("/plugins/gtk/awaybox"); gaim_prefs_add_bool("/plugins/gtk/awaybox/button_showicon", TRUE); gaim_prefs_add_bool("/plugins/gtk/awaybox/button_showtext", TRUE); if(show_button_and_box(plugin)) { gaim_signal_connect(gaim_accounts_get_handle(), "account-away", plugin, GAIM_CALLBACK(handle_account_away), plugin); return TRUE; } return FALSE; } static gboolean plugin_unload(GaimPlugin *plugin) { if(hide_button_and_box()) { /* fprintf(stderr,"awaybox: unloaded.\n");*/ return TRUE; } return FALSE; } gboolean hide_button_and_box() { if(button != NULL) { gtk_widget_hide(button); gtk_widget_destroy(button); button = NULL; } if(textbox != NULL) { gtk_widget_hide(textbox); gtk_widget_destroy(textbox); textbox = NULL; } if(hbox_holder != NULL) { gtk_widget_hide(hbox_holder); gtk_widget_destroy(hbox_holder); hbox_holder = NULL; } return TRUE; } static void buttontype_toggle_cb(GaimPlugin* plugin) { if(button != NULL) // aka, if the box isn't already not visible { hide_button_and_box(); show_button_and_box(plugin); } } static GaimPluginPrefFrame * get_plugin_pref_frame(GaimPlugin *plugin) { // fprintf(stderr, "awaybox: begining get_plugin_pref_frame\n"); GaimPluginPrefFrame *frame; GaimPluginPref *ppref; frame = gaim_plugin_pref_frame_new(); // put the label in ppref = gaim_plugin_pref_new_with_label(_("Display of the \"Go Away\" button")); gaim_plugin_pref_frame_add(frame, ppref); ppref = gaim_plugin_pref_new_with_name_and_label( "/plugins/gtk/awaybox/button_showtext",_("Show text?")); gaim_plugin_pref_frame_add(frame, ppref); ppref = gaim_plugin_pref_new_with_name_and_label( "/plugins/gtk/awaybox/button_showicon",_("Show icon?")); gaim_plugin_pref_frame_add(frame, ppref); // fprintf(stderr, "awaybox: ending get_plugin_pref_frame\n"); return frame; } static GaimPluginUiInfo prefs_info = { get_plugin_pref_frame }; static GaimPluginInfo lol = { GAIM_PLUGIN_MAGIC, GAIM_MAJOR_VERSION, GAIM_MINOR_VERSION, GAIM_PLUGIN_STANDARD, GAIM_GTK_PLUGIN_TYPE, 0, NULL, GAIM_PRIORITY_DEFAULT, "gtk-cbr2702-awaybox", "Away Text Box", "0.0.1", "Set all your accounts away with a new away message.", "This plugin adds a text box to the bottom of the buddy list to recieve an away message. When you enter an away message, all of your accounts are set \"away\" with the away message you entered. It is most useful for short, single-use notes about status.", "Jeff Kaufman ", "http://www.jefftk.com/awaybox/", plugin_load, plugin_unload, NULL, NULL, NULL, &prefs_info, NULL }; GAIM_INIT_PLUGIN(awaybox, plugin_load, lol);