static int wrap_context_closure(lua_State *L) { hexchat_context *old, *context = *(hexchat_context **)luaL_checkudata(L, 1, "context"); lua_pushvalue(L, lua_upvalueindex(1)); lua_replace(L, 1); old = hexchat_get_context(ph); if(!hexchat_set_context(ph, context)) return luaL_error(L, "could not switch into context"); lua_call(L, lua_gettop(L) - 1, LUA_MULTRET); hexchat_set_context(ph, old); return lua_gettop(L); }
void hexchat_globally_back() { std::vector<int> xs; std::vector<int>::iterator xsi; hexchat_list *xl = hexchat_list_get(ph, "channels"); if(xl) { while(hexchat_list_next(ph, xl)) { xsi = std::find(xs.begin(), xs.end(), hexchat_list_int(ph, xl, "id")); if((xsi == xs.end()) && ((strlen(hexchat_list_str(ph, xl, "server")) > 0) || (strlen(hexchat_list_str(ph, xl, "channel")) > 0))) { xs.push_back(hexchat_list_int(ph, xl, "id")); hexchat_set_context(ph, (hexchat_context *)hexchat_list_str(ph, xl, "context")); hexchat_back(); } } hexchat_list_free(ph, xl); } }
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 int api_hexchat_set_context(lua_State *L) { hexchat_context *context = *(hexchat_context **)luaL_checkudata(L, 1, "context"); int success = hexchat_set_context(ph, context); lua_pushboolean(L, success); return 1; }
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; }
static int timer_cb (void *userdata) { HookData *data = (HookData *) userdata; int retVal = 0; int count = 0; dSP; ENTER; SAVETMPS; PUSHMARK (SP); XPUSHs (data->userdata); PUTBACK; if (data->ctx) { hexchat_set_context (ph, data->ctx); } set_current_package (data->package); count = call_sv (data->callback, G_EVAL); set_current_package (&PL_sv_undef); SPAGAIN; if (SvTRUE (ERRSV)) { hexchat_printf (ph, "Error in timer callback %s", SvPV_nolen (ERRSV)); if (!SvOK (POPs)) {} /* remove undef from the top of the stack */ retVal = HEXCHAT_EAT_ALL; } else { if (count != 1) { hexchat_print (ph, "Timer handler should only return 1 value."); retVal = HEXCHAT_EAT_NONE; } else { retVal = POPi; if (retVal == 0) { /* if 0 is return the timer is going to get unhooked */ PUSHMARK (SP); XPUSHs (sv_2mortal (newSViv (PTR2IV (data->hook)))); XPUSHs (sv_mortalcopy (data->package)); PUTBACK; call_pv ("Xchat::unhook", G_EVAL); SPAGAIN; } } } PUTBACK; FREETMPS; LEAVE; return retVal; }
static XS (XS_Xchat_set_context) { hexchat_context *ctx; dXSARGS; if (items != 1) { hexchat_print (ph, "Usage: Xchat::set_context(ctx)"); } else { ctx = INT2PTR (hexchat_context *, SvUV (ST (0))); XSRETURN_IV ((IV) hexchat_set_context (ph, ctx)); } }
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 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); }
HMENU setServerMenu() { HMENU sTemp = CreateMenu(); TCHAR wszServer[128]; TCHAR wszNick[128]; TCHAR wszMenuEntry[256]; std::vector<int> xs; std::vector<int>::iterator xsi; hexchat_list *xl = hexchat_list_get(ph, "channels"); AppendMenu(sTemp, MF_STRING, ACT_AWAY, _T("Set Globally Away")); AppendMenu(sTemp, MF_STRING, ACT_BACK, _T("Set Globally Back")); AppendMenu(sTemp, MF_SEPARATOR, 0, NULL); if(xl) { while(hexchat_list_next(ph, xl)) { xsi = std::find(xs.begin(), xs.end(), hexchat_list_int(ph, xl, "id")); if( (xsi == xs.end()) && ((strlen(hexchat_list_str(ph, xl, "server")) > 0) || (strlen(hexchat_list_str(ph, xl, "channel")) > 0))) { hexchat_set_context(ph, (hexchat_context *)hexchat_list_str(ph, xl, "context")); xs.push_back(hexchat_list_int(ph, xl, "id")); char *network = _strdup(hexchat_list_str(ph, xl, "network")); char *server = _strdup(hexchat_list_str(ph, xl, "server")); char *nick = _strdup(hexchat_get_info(ph, "nick")); if(network != NULL) { ConvertString(network, wszServer, 128); } else { ConvertString(server, wszServer, 128); } if(server != NULL) { ConvertString(nick, wszNick, 128); _sntprintf(wszMenuEntry, 256, _T("%s @ %s\0"), wszNick, wszServer); if(!hexchat_get_info(ph, "away")) { AppendMenu(sTemp, MF_STRING, (hexchat_list_int(ph, xl, "id") + 1), wszMenuEntry); } else { AppendMenu(sTemp, (MF_CHECKED | MF_STRING), (hexchat_list_int(ph, xl, "id") + 1), wszMenuEntry); } } free(network); free(server); free(nick); } } hexchat_list_free(ph, xl); } return sTemp; }
LRESULT CALLBACK sdTrayProc(HWND hWnd, int msg) { switch(msg) { case ACT_EXIT: { g_bCanQuit = true; PostMessage(hWnd, WM_CLOSE, 0, 0); } break; case ACT_RESTORE: { /*************************************************/ /** user wants us to restore the HexChat window **/ /** and of autoaway is on, set as back ******** **/ /*************************************************/ SendMessage(g_hXchatWnd, WM_SYSCOMMAND, SC_RESTORE, 0); SetForegroundWindow(hWnd); if((!g_iIsActive) && (g_dwPrefs & (1<<PREF_AOM))) { hexchat_globally_back(); g_iIsActive = 1; } } break; case ACT_SETTINGS: { ShowWindow(g_hPrefDlg, SW_SHOW); } break; case ACT_AWAY: { hexchat_globally_away(g_szAway); } break; case ACT_BACK: { hexchat_globally_back(); } break; default: { if(msg > 0) { hexchat_set_context(ph, hexchat_find_server(msg-1)); if(!hexchat_get_info(ph, "away")) { hexchat_away(g_szAway); } else { hexchat_back(); } } } break; } return 1; }