static int dccoffer_cb (char *word[], void *userdata) { int result; struct stat buffer; /* buffer for storing file info */ char sum[65]; /* buffer for checksum */ result = stat (word[3], &buffer); if (result == 0) /* stat returns 0 on success */ { if (buffer.st_size <= (unsigned long long) get_limit () * 1048576) { sha256_file (word[3], sum); /* word[3] is the full filename */ hexchat_commandf (ph, "quote PRIVMSG %s :SHA-256 checksum for %s (remote): %s", word[2], word[1], sum); } else { hexchat_set_context (ph, hexchat_find_context (ph, NULL, word[3])); hexchat_printf (ph, "quote PRIVMSG %s :SHA-256 checksum for %s (remote): (size limit reached, no checksum calculated)", word[2], word[1]); } } else { hexchat_printf (ph, "File access error!\n"); } return HEXCHAT_EAT_NONE; }
static XS (XS_Xchat_find_context) { char *server = NULL; char *chan = NULL; hexchat_context *RETVAL; dXSARGS; if (items > 2) hexchat_print (ph, "Usage: Xchat::find_context ([channel, [server]])"); { switch (items) { case 0: /* no server name and no channel name */ /* nothing to do, server and chan are already NULL */ break; case 1: /* channel name only */ /* change channel value only if it is true or 0 */ /* otherwise leave it as null */ if (SvTRUE (ST (0)) || SvNIOK (ST (0))) { chan = SvPV_nolen (ST (0)); /* hexchat_printf( ph, "XSUB - find_context( %s, NULL )", chan ); */ } /* else { hexchat_print( ph, "XSUB - find_context( NULL, NULL )" ); } */ /* chan is already NULL */ break; case 2: /* server and channel */ /* change channel value only if it is true or 0 */ /* otherwise leave it as NULL */ if (SvTRUE (ST (0)) || SvNIOK (ST (0))) { chan = SvPV_nolen (ST (0)); /* hexchat_printf( ph, "XSUB - find_context( %s, NULL )", SvPV_nolen(ST(0) )); */ } /* else { hexchat_print( ph, "XSUB - 2 arg NULL chan" ); } */ /* change server value only if it is true or 0 */ /* otherwise leave it as NULL */ if (SvTRUE (ST (1)) || SvNIOK (ST (1))) { server = SvPV_nolen (ST (1)); /* hexchat_printf( ph, "XSUB - find_context( NULL, %s )", SvPV_nolen(ST(1) )); */ } /* else { hexchat_print( ph, "XSUB - 2 arg NULL server" ); } */ break; } RETVAL = hexchat_find_context (ph, server, chan); if (RETVAL != NULL) { /* hexchat_print (ph, "XSUB - context found"); */ XSRETURN_IV (PTR2IV (RETVAL)); } else { /* hexchat_print (ph, "XSUB - context not found"); */ XSRETURN_UNDEF; } } }
static int dccrecv_cb (char *word[], void *userdata) { int result; struct stat buffer; /* buffer for storing file info */ char sum[65]; /* buffer for checksum */ const char *file; char *cfile; if (hexchat_get_prefs (ph, "dcc_completed_dir", &file, NULL) == 1 && file[0] != 0) { cfile = g_strconcat (file, G_DIR_SEPARATOR_S, word[1], NULL); } else { cfile = g_strdup(word[2]); } result = stat (cfile, &buffer); if (result == 0) /* stat returns 0 on success */ { if (buffer.st_size <= (unsigned long long) get_limit () * 1048576) { sha256_file (cfile, sum); /* file is the full filename even if completed dir set */ /* try to print the checksum in the privmsg tab of the sender */ hexchat_set_context (ph, hexchat_find_context (ph, NULL, word[3])); hexchat_printf (ph, "SHA-256 checksum for %s (local): %s\n", word[1], sum); } else { hexchat_set_context (ph, hexchat_find_context (ph, NULL, word[3])); hexchat_printf (ph, "SHA-256 checksum for %s (local): (size limit reached, no checksum calculated, you can increase it with /CHECKSUM INC)\n", word[1]); } } else { hexchat_printf (ph, "File access error!\n"); } g_free (cfile); return HEXCHAT_EAT_NONE; }
gboolean tray_toggle_visibility (gboolean force_hide) { static int x, y; static GdkScreen *screen; static int maximized; GtkWindow *win; if (!sticon) return FALSE; /* ph may have an invalid context now */ hexchat_set_context (ph, hexchat_find_context (ph, NULL, NULL)); win = GTK_WINDOW (hexchat_get_info (ph, "gtkwin_ptr")); tray_stop_flash (); tray_reset_counts (); if (!win) return FALSE; #if GTK_CHECK_VERSION(2,20,0) if (force_hide || gtk_widget_get_visible (GTK_WIDGET (win))) #else if (force_hide || GTK_WIDGET_VISIBLE (win)) #endif { if (prefs.hex_gui_tray_away) hexchat_command (ph, "ALLSERV AWAY"); gtk_window_get_position (win, &x, &y); screen = gtk_window_get_screen (win); maximized = prefs.hex_gui_win_state; gtk_widget_hide (GTK_WIDGET (win)); } else { if (prefs.hex_gui_tray_away) hexchat_command (ph, "ALLSERV BACK"); gtk_window_set_screen (win, screen); gtk_window_move (win, x, y); if (maximized) gtk_window_maximize (win); gtk_widget_show (GTK_WIDGET (win)); gtk_window_present (win); } return TRUE; }
static int api_hexchat_find_context(lua_State *L) { char const *server = luaL_optstring(L, 1, NULL); char const *channel = luaL_optstring(L, 2, NULL); hexchat_context *context = hexchat_find_context(ph, server, channel); if(context) { hexchat_context **u = lua_newuserdata(L, sizeof(hexchat_context *)); *u = context; luaL_newmetatable(L, "context"); lua_setmetatable(L, -2); return 1; } else { lua_pushnil(L); return 1; } }
static void tray_menu_cb (GtkWidget *widget, guint button, guint time, gpointer userdata) { static GtkWidget *menu; GtkWidget *submenu; GtkWidget *item; int away_status; /* ph may have an invalid context now */ hexchat_set_context (ph, hexchat_find_context (ph, NULL, NULL)); /* close any old menu */ if (G_IS_OBJECT (menu)) { tray_menu_destroy (menu, NULL); } menu = gtk_menu_new (); /*gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));*/ if (tray_get_window_status () == WS_HIDDEN) tray_make_item (menu, _("_Restore Window"), tray_menu_restore_cb, NULL); else tray_make_item (menu, _("_Hide Window"), tray_menu_restore_cb, NULL); tray_make_item (menu, NULL, tray_menu_quit_cb, NULL); #ifndef WIN32 /* submenus are buggy on win32 */ submenu = mg_submenu (menu, _("_Blink on")); blink_item (&prefs.hex_input_tray_chans, submenu, _("Channel Message")); blink_item (&prefs.hex_input_tray_priv, submenu, _("Private Message")); blink_item (&prefs.hex_input_tray_hilight, submenu, _("Highlighted Message")); /*blink_item (BIT_FILEOFFER, submenu, _("File Offer"));*/ submenu = mg_submenu (menu, _("_Change status")); #else /* so show away/back in main tray menu */ submenu = menu; #endif away_status = tray_find_away_status (); item = tray_make_item (submenu, _("_Away"), tray_foreach_server, "away"); if (away_status == 1) gtk_widget_set_sensitive (item, FALSE); item = tray_make_item (submenu, _("_Back"), tray_foreach_server, "back"); if (away_status == 2) gtk_widget_set_sensitive (item, FALSE); menu_add_plugin_items (menu, "\x5$TRAY", NULL); #ifdef WIN32 tray_make_item (menu, NULL, tray_menu_quit_cb, NULL); mg_create_icon_item (_("_Preferences"), GTK_STOCK_PREFERENCES, menu, tray_menu_settings, NULL); #endif tray_make_item (menu, NULL, tray_menu_quit_cb, NULL); mg_create_icon_item (_("_Quit"), GTK_STOCK_QUIT, menu, tray_menu_quit_cb, NULL); g_object_ref (menu); g_object_ref_sink (menu); g_object_unref (menu); g_signal_connect (G_OBJECT (menu), "selection-done", G_CALLBACK (tray_menu_destroy), NULL); #ifdef WIN32 g_signal_connect (G_OBJECT (menu), "leave-notify-event", G_CALLBACK (tray_menu_left_cb), NULL); g_signal_connect (G_OBJECT (menu), "enter-notify-event", G_CALLBACK (tray_menu_enter_cb), NULL); tray_menu_timer = g_timeout_add(500, (GSourceFunc) tray_check_hide, menu); #endif gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, userdata, button, time); }
void hexchat_exec(char *command) { hexchat_set_context(ph, hexchat_find_context(ph, NULL, NULL)); hexchat_command(ph, command); }