static PurpleCmdRet lastlog_cb(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer null) { FinchConv *ggconv = FINCH_CONV(conv); char **strings = g_strsplit(GNT_TEXT_VIEW(ggconv->tv)->string->str, "\n", 0); GntWidget *win, *tv; int i, j; win = gnt_window_new(); gnt_box_set_title(GNT_BOX(win), _("Lastlog")); tv = gnt_text_view_new(); gnt_box_add_widget(GNT_BOX(win), tv); gnt_widget_show(win); for (i = 0; strings[i]; i++) { if (strstr(strings[i], args[0]) != NULL) { char **finds = g_strsplit(strings[i], args[0], 0); for (j = 0; finds[j]; j++) { if (j) gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv), args[0], GNT_TEXT_FLAG_BOLD); gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv), finds[j], GNT_TEXT_FLAG_NORMAL); } g_strfreev(finds); gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv), "\n", GNT_TEXT_FLAG_NORMAL); } } g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(window_kpress_cb), tv); g_strfreev(strings); return PURPLE_CMD_RET_OK; }
static void url_fetched(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, gpointer _data) { CbInfo *data = (CbInfo *)_data; PurpleConversation *conv = data->conv; GList *convs = purple_conversations_get_all(); const gchar *url; if (purple_http_response_is_successful(response)) { url = purple_http_response_get_data(response, NULL); g_hash_table_insert(tinyurl_cache, data->original_url, g_strdup(url)); } else { url = _("Error while querying TinyURL"); g_free(data->original_url); } /* ensure the conversation still exists */ for (; convs; convs = convs->next) { if ((PurpleConversation *)(convs->data) == conv) { FinchConv *fconv = FINCH_CONV(conv); gchar *str = g_strdup_printf("[%d] %s", data->num, url); GntTextView *tv = GNT_TEXT_VIEW(fconv->tv); gnt_text_view_tag_change(tv, data->tag, str, FALSE); g_free(str); g_free(data->tag); g_free(data); return; } } g_free(data->tag); g_free(data); purple_debug_info("TinyURL", "Conversation no longer exists... :(\n"); }
/* Frees 'urls' */ static void process_urls(PurpleConversation *conv, GList *urls) { GList *iter; int c; FinchConv *fconv = FINCH_CONV(conv); GntTextView *tv = GNT_TEXT_VIEW(fconv->tv); for (iter = urls, c = 1; iter; iter = iter->next, c++) { int i; CbInfo *cbdata; gchar *url, *str; gchar *original_url; const gchar *tiny_url; i = gnt_text_view_get_lines_below(tv); original_url = purple_unescape_html((char *)iter->data); tiny_url = g_hash_table_lookup(tinyurl_cache, original_url); if (tiny_url) { gchar *str = g_strdup_printf("\n[%d] %s", c, tiny_url); g_free(original_url); gnt_text_view_append_text_with_flags(tv, str, GNT_TEXT_FLAG_DIM); if (i == 0) gnt_text_view_scroll(tv, 0); g_free(str); continue; } cbdata = g_new(CbInfo, 1); cbdata->num = c; cbdata->original_url = original_url; cbdata->tag = g_strdup_printf("%s%d", "tiny_", tag_num++); cbdata->conv = conv; if (g_ascii_strncasecmp(original_url, "http://", 7) && g_ascii_strncasecmp(original_url, "https://", 8)) { url = g_strdup_printf("%shttp%%3A%%2F%%2F%s", purple_prefs_get_string(PREF_URL), purple_url_encode(original_url)); } else { url = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL), purple_url_encode(original_url)); } purple_http_get(NULL, url_fetched, cbdata, url); str = g_strdup_printf(_("\nFetching TinyURL...")); gnt_text_view_append_text_with_tag((tv), str, GNT_TEXT_FLAG_DIM, cbdata->tag); g_free(str); if (i == 0) gnt_text_view_scroll(tv, 0); g_free(iter->data); g_free(url); } g_list_free(urls); }
/* * play a sound event for a conversation, honoring make_sound flag * of conversation and checking for focus if conv_focus pref is set */ static void play_conv_event(PurpleConversation *conv, PurpleSoundEventID event) { /* If we should not play the sound for some reason, then exit early */ if (conv != NULL) { FinchConv *gntconv; gboolean has_focus; gntconv = FINCH_CONV(conv); has_focus = purple_conversation_has_focus(conv); if ((gntconv->flags & FINCH_CONV_NO_SOUND) || (has_focus && !purple_prefs_get_bool(make_pref("/conv_focus")))) { return; } } purple_sound_play_event(event, conv ? purple_conversation_get_account(conv) : NULL); }
static void historize(PurpleConversation *c) { PurpleAccount *account = purple_conversation_get_account(c); const char *name = purple_conversation_get_name(c); PurpleConversationType convtype; GList *logs = NULL; const char *alias = name; PurpleLogReadFlags flags; char *history; char *header; PurpleMessageFlags mflag; convtype = purple_conversation_get_type(c); if (convtype == PURPLE_CONV_TYPE_IM) { GSList *buddies; GSList *cur; FinchConv *fc = FINCH_CONV(c); if (fc->list && fc->list->next) /* We were already in the middle of a conversation. */ return; /* If we're not logging, don't show anything. * Otherwise, we might show a very old log. */ if (!purple_prefs_get_bool("/purple/logging/log_ims")) return; /* Find buddies for this conversation. */ buddies = purple_find_buddies(account, name); /* If we found at least one buddy, save the first buddy's alias. */ if (buddies != NULL) alias = purple_buddy_get_contact_alias((PurpleBuddy *)buddies->data); for (cur = buddies; cur != NULL; cur = cur->next) { PurpleBlistNode *node = cur->data; if ((node != NULL) && ((purple_blist_node_get_sibling_prev(node) != NULL) || (purple_blist_node_get_sibling_next(node) != NULL))) { PurpleBlistNode *node2; alias = purple_buddy_get_contact_alias((PurpleBuddy *)node); /* We've found a buddy that matches this conversation. It's part of a * PurpleContact with more than one PurpleBuddy. Loop through the PurpleBuddies * in the contact and get all the logs. */ for (node2 = purple_blist_node_get_first_child(purple_blist_node_get_parent(node)); node2 != NULL ; node2 = purple_blist_node_get_sibling_next(node2)) { logs = g_list_concat( purple_log_get_logs(PURPLE_LOG_IM, purple_buddy_get_name((PurpleBuddy *)node2), purple_buddy_get_account((PurpleBuddy *)node2)), logs); } break; } } g_slist_free(buddies); if (logs == NULL) logs = purple_log_get_logs(PURPLE_LOG_IM, name, account); else logs = g_list_sort(logs, purple_log_compare); } else if (convtype == PURPLE_CONV_TYPE_CHAT) { /* If we're not logging, don't show anything. * Otherwise, we might show a very old log. */ if (!purple_prefs_get_bool("/purple/logging/log_chats")) return; logs = purple_log_get_logs(PURPLE_LOG_CHAT, name, account); } if (logs == NULL) return; mflag = PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_DELAYED; history = purple_log_read((PurpleLog*)logs->data, &flags); header = g_strdup_printf(_("<b>Conversation with %s on %s:</b><br>"), alias, purple_date_format_full(localtime(&((PurpleLog *)logs->data)->time))); purple_conversation_write(c, "", header, mflag, time(NULL)); g_free(header); if (flags & PURPLE_LOG_READ_NO_NEWLINE) purple_str_strip_char(history, '\n'); purple_conversation_write(c, "", history, mflag, time(NULL)); g_free(history); purple_conversation_write(c, "", "<hr>", mflag, time(NULL)); g_list_foreach(logs, (GFunc)purple_log_free, NULL); g_list_free(logs); }
static void notify(PurpleConversation *conv, const char *fmt, ...) { GntWidget *window; GntToast *toast; char *str; int h, w, i; va_list args; if (purple_prefs_get_bool(PREFS_BEEP)) beep(); if (conv != NULL) { FinchConv *fc = FINCH_CONV(conv); if (gnt_widget_has_focus(fc->window)) return; } #ifdef HAVE_X11 if (purple_prefs_get_bool(PREFS_URGENT)) urgent(); #endif window = gnt_vbox_new(FALSE); GNT_WIDGET_SET_FLAGS(window, GNT_WIDGET_TRANSIENT); GNT_WIDGET_UNSET_FLAGS(window, GNT_WIDGET_NO_BORDER); va_start(args, fmt); str = g_strdup_vprintf(fmt, args); va_end(args); gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(str, GNT_TEXT_FLAG_HIGHLIGHT)); g_free(str); gnt_widget_size_request(window); gnt_widget_get_size(window, &w, &h); for (i = 0; i < MAX_COLS && gpsy[i] + h >= getmaxy(stdscr) ; ++i) ; if (i >= MAX_COLS) { purple_debug_warning("GntGf", "Dude, that's way too many popups\n"); gnt_widget_destroy(window); return; } toast = g_new0(GntToast, 1); toast->window = window; toast->column = i; gpsy[i] += h; if (w > gpsw[i]) { if (i == 0) gpsw[i] = w; else gpsw[i] = gpsw[i - 1] + w + 1; } if (i == 0 || (w + gpsw[i - 1] >= getmaxx(stdscr))) { /* if it's going to be too far left, overlap. */ gnt_widget_set_position(window, getmaxx(stdscr) - w - 1, getmaxy(stdscr) - gpsy[i] - 1); } else { gnt_widget_set_position(window, getmaxx(stdscr) - gpsw[i - 1] - w - 1, getmaxy(stdscr) - gpsy[i] - 1); } gnt_widget_draw(window); toast->timer = purple_timeout_add_seconds(4, (GSourceFunc)remove_toaster, toast); toasters = g_list_prepend(toasters, toast); }