static void save_cb(PurpleBlistNode *node, int choice) { if (PURPLE_BLIST_NODE_IS_BUDDY(node)) node = purple_blist_node_get_parent(node); g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node)); purple_blist_node_set_int(node, "autoaccept", choice); }
BuddyListNode *BuddyListNode::getParentNode() const { PurpleBlistNode *parent = purple_blist_node_get_parent(blist_node); if (!parent) return NULL; return reinterpret_cast<BuddyListNode*>( purple_blist_node_get_ui_data(parent)); }
static gpointer no_group_find_parent(PurpleBlistNode *node) { gpointer ret = NULL; if (PURPLE_IS_BUDDY(node)) { ret = purple_blist_node_get_parent(node); finch_blist_manager_add_node(ret); } return ret; }
static gpointer on_offline_find_parent(PurpleBlistNode *node) { gpointer ret = NULL; if (PURPLE_IS_CONTACT(node)) { node = PURPLE_BLIST_NODE(purple_contact_get_priority_buddy(PURPLE_CONTACT(node))); ret = PURPLE_BUDDY_IS_ONLINE(PURPLE_BUDDY(node)) ? online : offline; } else if (PURPLE_IS_BUDDY(node)) { ret = purple_blist_node_get_parent(node); finch_blist_manager_add_node(ret); } else if (PURPLE_IS_CHAT(node)) { ret = online; } return ret; }
static void set_auto_accept_settings(PurpleBlistNode *node, gpointer plugin) { char *message; if (PURPLE_BLIST_NODE_IS_BUDDY(node)) node = purple_blist_node_get_parent(node); g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node)); message = g_strdup_printf(_("When a file-transfer request arrives from %s"), purple_contact_get_alias((PurpleContact *)node)); purple_request_choice(plugin, _("Set Autoaccept Setting"), message, NULL, purple_blist_node_get_int(node, "autoaccept"), _("_Save"), G_CALLBACK(save_cb), _("_Cancel"), NULL, NULL, NULL, NULL, node, _("Ask"), FT_ASK, _("Auto Accept"), FT_ACCEPT, _("Auto Reject"), FT_REJECT, NULL, purple_contact_get_alias((PurpleContact *)node), NULL, NULL); g_free(message); }
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 file_recv_request_cb(PurpleXfer *xfer, gpointer handle) { PurpleAccount *account; PurpleBlistNode *node; const char *pref; char *filename; char *dirname; int accept_setting; account = xfer->account; node = PURPLE_BLIST_NODE(purple_find_buddy(account, xfer->who)); /* If person is on buddy list, use the buddy setting; otherwise, use the stranger setting. */ if (node) { node = purple_blist_node_get_parent(node); g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node)); accept_setting = purple_blist_node_get_int(node, "autoaccept"); } else { accept_setting = purple_prefs_get_int(PREF_STRANGER); } switch (accept_setting) { case FT_ASK: break; case FT_ACCEPT: pref = purple_prefs_get_string(PREF_PATH); if (ensure_path_exists(pref)) { int count = 1; const char *escape; gchar **name_and_ext; const gchar *name; gchar *ext; if (purple_prefs_get_bool(PREF_NEWDIR)) dirname = g_build_filename(pref, purple_normalize(account, xfer->who), NULL); else dirname = g_build_filename(pref, NULL); if (!ensure_path_exists(dirname)) { g_free(dirname); break; } /* Escape filename (if escaping is turned on) */ if (purple_prefs_get_bool(PREF_ESCAPE)) { escape = purple_escape_filename(xfer->filename); } else { escape = xfer->filename; } filename = g_build_filename(dirname, escape, NULL); /* Split at the first dot, to avoid uniquifying "foo.tar.gz" to "foo.tar-2.gz" */ name_and_ext = g_strsplit(escape, ".", 2); name = name_and_ext[0]; g_return_if_fail(name != NULL); if (name_and_ext[1] != NULL) { /* g_strsplit does not include the separator in each chunk. */ ext = g_strdup_printf(".%s", name_and_ext[1]); } else { ext = g_strdup(""); } /* Make sure the file doesn't exist. Do we want some better checking than this? */ /* FIXME: There is a race here: if the newly uniquified file name gets created between * this g_file_test and the transfer starting, the file created in the meantime * will be clobbered. But it's not at all straightforward to fix. */ while (g_file_test(filename, G_FILE_TEST_EXISTS)) { char *file = g_strdup_printf("%s-%d%s", name, count++, ext); g_free(filename); filename = g_build_filename(dirname, file, NULL); g_free(file); } purple_xfer_request_accepted(xfer, filename); g_strfreev(name_and_ext); g_free(ext); g_free(dirname); g_free(filename); } purple_signal_connect(purple_xfers_get_handle(), "file-recv-complete", handle, PURPLE_CALLBACK(auto_accept_complete_cb), xfer); break; case FT_REJECT: xfer->status = PURPLE_XFER_STATUS_CANCEL_LOCAL; break; } }
void BuddyListNode::sortIn() { CppConsUI::TreeView::NodeReference parent_ref; if (purple_blist_node_get_parent(blist_node)) { /* This blist node has got a logical (libpurple) parent, check if it is * possible to find also a cim node. */ BuddyListNode *parent_node = getParentNode(); if (parent_node) parent_ref = parent_node->getRefNode(); else { // there shouldn't be a cim node only if the flat mode is active g_assert(BUDDYLIST->getListMode() == BuddyList::LIST_FLAT); parent_ref = treeview->getRootNode(); } } else { if (PURPLE_BLIST_NODE_IS_GROUP(blist_node)) { // groups don't have parent nodes parent_ref = treeview->getRootNode(); } else { /* When the new_node() callback is called for a contact/chat/buddy (and * this method is called as a part of that callback) then the node * doesn't have any parent set yet. In such a case, simply return. */ return; } } /* Do the insertion sort. It should be fast enough here because nodes are * usually already sorted and only one node is in a wrong position, so it * kind of runs in O(n). */ CppConsUI::TreeView::SiblingIterator i = parent_ref.end(); i--; while (true) { // sref is a node that we want to sort in CppConsUI::TreeView::SiblingIterator sref = i; // calculate a stop condition bool stop_flag; if (i != parent_ref.begin()) { stop_flag = false; i--; } else stop_flag = true; BuddyListNode *swidget = dynamic_cast<BuddyListNode*>(sref->getWidget()); g_assert(swidget); CppConsUI::TreeView::SiblingIterator j = sref; j++; while (j != parent_ref.end()) { BuddyListNode *n = dynamic_cast<BuddyListNode*>(j->getWidget()); g_assert(n); if (swidget->lessOrEqual(*n)) { treeview->moveNodeBefore(sref, j); break; } j++; } // the node is last in the list if (j == parent_ref.end()) treeview->moveNodeAfter(sref, --j); if (stop_flag) break; } }
static void historize(PurpleConversation *c) { PurpleAccount *account = purple_conversation_get_account(c); const char *name = purple_conversation_get_name(c); GList *logs = NULL; const char *alias = name; guint flags; char *history; PidginConversation *gtkconv; #if 0 /* FIXME: WebView has no options */ GtkIMHtmlOptions options = GTK_IMHTML_NO_COLOURS; #endif char *header; #if 0 /* FIXME: WebView has no protocol setting */ char *protocol; #endif char *escaped_alias; const char *header_date; gtkconv = PIDGIN_CONVERSATION(c); g_return_if_fail(gtkconv != NULL); /* An IM which is the first active conversation. */ g_return_if_fail(gtkconv->convs != NULL); if (PURPLE_IS_IM_CONVERSATION(c) && !gtkconv->convs->next) { GSList *buddies; GSList *cur; /* 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_blist_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(PURPLE_BUDDY(buddies->data)); for (cur = buddies; cur != NULL; cur = cur->next) { PurpleBlistNode *node = cur->data; PurpleBlistNode *prev = purple_blist_node_get_sibling_prev(node); PurpleBlistNode *next = purple_blist_node_get_sibling_next(node); if ((node != NULL) && ((prev != NULL) || (next != NULL))) { PurpleBlistNode *node2; PurpleBlistNode *parent = purple_blist_node_get_parent(node); PurpleBlistNode *child = purple_blist_node_get_first_child(parent); alias = purple_buddy_get_contact_alias(PURPLE_BUDDY(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 = child ; 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(PURPLE_BUDDY(node2)), purple_buddy_get_account(PURPLE_BUDDY(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 (PURPLE_IS_CHAT_CONVERSATION(c)) { /* 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; history = purple_log_read((PurpleLog*)logs->data, &flags); gtkconv = PIDGIN_CONVERSATION(c); #if 0 /* FIXME: WebView has no options */ if (flags & PURPLE_LOG_READ_NO_NEWLINE) options |= GTK_IMHTML_NO_NEWLINE; #endif #if 0 /* FIXME: WebView has no protocol setting */ protocol = g_strdup(gtk_imhtml_get_protocol_name(GTK_IMHTML(gtkconv->imhtml))); gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml), purple_account_get_protocol_name(((PurpleLog*)logs->data)->account)); #endif #if 0 /* TODO WebKit: Do this properly... */ if (!pidgin_webview_is_empty(PIDGIN_WEBVIEW(gtkconv->webview))) pidgin_webview_append_html(PIDGIN_WEBVIEW(gtkconv->webview), "<BR>"); #endif escaped_alias = g_markup_escape_text(alias, -1); if (((PurpleLog *)logs->data)->tm) header_date = purple_date_format_full(((PurpleLog *)logs->data)->tm); else header_date = purple_date_format_full(localtime(&((PurpleLog *)logs->data)->time)); header = g_strdup_printf(_("<b>Conversation with %s on %s:</b><br>"), escaped_alias, header_date); pidgin_webview_append_html(PIDGIN_WEBVIEW(gtkconv->webview), header); g_free(header); g_free(escaped_alias); g_strchomp(history); pidgin_webview_append_html(PIDGIN_WEBVIEW(gtkconv->webview), history); g_free(history); pidgin_webview_append_html(PIDGIN_WEBVIEW(gtkconv->webview), "<hr>"); #if 0 /* FIXME: WebView has no protocol setting */ gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml), protocol); g_free(protocol); #endif g_object_ref(G_OBJECT(gtkconv->webview)); g_idle_add(_scroll_webview_to_end, gtkconv->webview); g_list_foreach(logs, (GFunc)purple_log_free, NULL); g_list_free(logs); }