コード例 #1
0
/* Get method for GObject properties */
static void
purple_counting_node_get_property(GObject *obj, guint param_id, GValue *value,
		GParamSpec *pspec)
{
	PurpleCountingNode *node = PURPLE_COUNTING_NODE(obj);

	switch (param_id) {
		case CNODE_PROP_TOTAL_SIZE:
			g_value_set_int(value, purple_counting_node_get_total_size(node));
			break;
		case CNODE_PROP_CURRENT_SIZE:
			g_value_set_int(value, purple_counting_node_get_current_size(node));
			break;
		case CNODE_PROP_ONLINE_COUNT:
			g_value_set_int(value, purple_counting_node_get_online_count(node));
			break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
			break;
	}
}
コード例 #2
0
static gboolean on_offline_can_add_node(PurpleBlistNode *node)
{
	if (PURPLE_IS_CONTACT(node)) {
		PurpleContact *contact = PURPLE_CONTACT(node);
		if (purple_counting_node_get_current_size(PURPLE_COUNTING_NODE(contact)) > 0)
			return TRUE;
		return FALSE;
	} else if (PURPLE_IS_BUDDY(node)) {
		PurpleBuddy *buddy = PURPLE_BUDDY(node);
		if (PURPLE_BUDDY_IS_ONLINE(buddy))
			return TRUE;
		if (purple_prefs_get_bool("/finch/blist/showoffline") &&
				purple_account_is_connected(purple_buddy_get_account(buddy)))
			return TRUE;
		return FALSE;
	} else if (PURPLE_IS_CHAT(node)) {
		PurpleChat *chat = PURPLE_CHAT(node);
		return purple_account_is_connected(purple_chat_get_account(chat));
	}

	return FALSE;
}
コード例 #3
0
static void
send_online_buddy_cb (PurpleBlistNode *cnode, gpointer data)
{
	PurplePlugin *plugin = (PurplePlugin *)data;
	PurpleConnection *gc;
   GSList *blist;
   PurpleBlistNode *gnode, *node;
   PurpleBuddy *b, *buddy;
   PurpleGroup *g, *check_group;
   const char *name, *gname, *receiver;
   int count = 0;
   PurpleAccount *account;
	PurpleIMConversation *im;
	gchar *buddylist = NULL;
	int total, flag = 0, counter = 0;
	gchar *group_info;

   const gchar *groupname = purple_group_get_name(data);
	purple_debug_info("send-option", "The group selected is: %s", groupname);

   buddy = (PurpleBuddy *)cnode;
	purple_debug_info("send-option", "Inside send_online_buddy_cb");
	receiver = purple_buddy_get_name(buddy); 
	purple_debug_info("send-option", "Receiver name: %s", receiver);
	account = purple_buddy_get_account(buddy);
	gc = purple_account_get_connection(account);

	im = purple_conversations_find_im_with_account(receiver, purple_connection_get_account(gc));
       if(im)
	      purple_debug_info("send-option", "Yayy, IM!");
       else
         purple_debug_info("send-option", "Boo! No IM :(");
	if (im == NULL)
      im = purple_im_conversation_new(purple_connection_get_account(gc), receiver);

   for(gnode = purple_blist_get_buddy_list()->root;
       gnode != NULL;
       gnode = gnode->next)
   {
	    if (PURPLE_IS_GROUP(gnode)) {
         g = (PurpleGroup*)gnode; 
		 /*fishy. It says g may be uninitiliazed here. What can I initilalie g to in the else, to get rid of the warning*/  	
         if (g != data)
			   continue;
			else
            break;
       }
	}

   gname = purple_group_get_name(g);
	total = purple_counting_node_get_online_count(PURPLE_COUNTING_NODE(g));;
   purple_debug_info("send-option", "%s (%d): \n",gname, total);
   group_info = g_strdup_printf("%s (%d):\n",gname, total);
	buddylist = g_strconcat(group_info, "\t","\t", NULL);
			 
   for (blist = purple_blist_get_buddies(); 
	  	  blist != NULL;
		  blist = blist->next)
   {
       node = blist->data;

       if (PURPLE_IS_BUDDY(node)) {
		 b = (PurpleBuddy*)node;
       name = purple_buddy_get_alias(b);                  
       check_group = purple_buddy_get_group(b);
                  
       if (data == check_group && PURPLE_BUDDY_IS_ONLINE(b)) {
          ++count;
			 ++counter;

	       if (flag == 1 && counter != total) {
             buddylist = g_strconcat(name, ",\t", NULL);
             flag = 0;
          } else if (flag == 1 && counter == total) {
             buddylist = g_strconcat(name, ".\t", NULL);
				 purple_debug_info(NULL, "%s", buddylist);	
             purple_conversation_send(PURPLE_CONVERSATION(im), buddylist); 
				 buddylist = NULL;
				 count = 0;
			 } else{
				 if (count <= 20 && counter != total) {
				  buddylist = g_strconcat(buddylist, name, ",\t", NULL);	/*fishy cant insert newline*/	
				 } else {
					if (counter == total)
						 buddylist = g_strconcat(buddylist, name, ".\t", NULL);
					else
                   buddylist = g_strconcat(buddylist, name, ",\t", NULL);
						 
                   purple_debug_info(NULL, "%s", buddylist);	
                   purple_conversation_send(PURPLE_CONVERSATION(im), buddylist); 
						 buddylist = NULL;
						 count = 0;
						 flag = 1;
             }
	       }
          }
	    }
	}
   purple_debug_info("send-option", "The counter is (%d): \n",counter);
   
   purple_notify_message (plugin, PURPLE_NOTIFY_MSG_INFO,
		    "Send online buddies", "Successfully sent your online buddies :)", NULL, NULL,
		     NULL, NULL);
	
	g_free(buddylist);
}
コード例 #4
0
ファイル: roster.c プロジェクト: Distrotech/pidgin
static void ggp_roster_reply_list(PurpleConnection *gc, uint32_t version,
	const char *data)
{
	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
	PurpleXmlNode *xml, *xml_it;
	PurpleAccount *account;
	GSList *local_buddies;
	GHashTable *remove_buddies;
	GList *update_buddies = NULL, *local_groups, *it, *table_values;
	ggp_roster_content *content;

	g_return_if_fail(gc != NULL);
	g_return_if_fail(data != NULL);

	account = purple_connection_get_account(gc);

	purple_debug_info("gg", "ggp_roster_reply_list: got list, version=%u\n",
		version);

	xml = purple_xmlnode_from_str(data, -1);
	if (xml == NULL) {
		purple_debug_warning("gg", "ggp_roster_reply_list: "
			"invalid xml\n");
		return;
	}

	ggp_roster_content_free(rdata->content);
	rdata->content = NULL;
	rdata->is_updating = TRUE;
	content = g_new0(ggp_roster_content, 1);
	content->version = version;
	content->xml = xml;
	content->contact_nodes = g_hash_table_new(NULL, NULL);
	content->group_nodes = g_hash_table_new_full(
		g_str_hash, g_str_equal, g_free, NULL);
	content->group_ids = g_hash_table_new_full(
		g_str_hash, g_str_equal, g_free, g_free);
	content->group_names = g_hash_table_new_full(
		g_str_hash, g_str_equal, g_free, g_free);

#if GGP_ROSTER_DEBUG
	ggp_roster_dump(content);
#endif

	/* reading groups */
	content->groups_node = purple_xmlnode_get_child(xml, "Groups");
	if (content->groups_node == NULL) {
		ggp_roster_content_free(content);
		g_return_if_reached();
	}
	xml_it = purple_xmlnode_get_child(content->groups_node, "Group");
	while (xml_it != NULL) {
		if (!ggp_roster_reply_list_read_group(xml_it, content)) {
			ggp_roster_content_free(content);
			g_return_if_reached();
		}

		xml_it = purple_xmlnode_get_next_twin(xml_it);
	}

	/* dumping current group list */
	local_groups = ggp_purplew_account_get_groups(account, TRUE);

	/* dumping current buddy list
	 * we will:
	 * - remove synchronized ones, if not found in list at server
	 * - upload not synchronized ones
	 */
	local_buddies = purple_blist_find_buddies(account, NULL);
	remove_buddies = g_hash_table_new(g_direct_hash, g_direct_equal);
	while (local_buddies) {
		PurpleBuddy *buddy = local_buddies->data;
		uin_t uin = ggp_str_to_uin(purple_buddy_get_name(buddy));
		local_buddies =
			g_slist_delete_link(local_buddies, local_buddies);

		if (!uin)
			continue;

		if (ggp_roster_is_synchronized(buddy))
			g_hash_table_insert(remove_buddies,
				GINT_TO_POINTER(uin), buddy);
		else
			update_buddies = g_list_append(update_buddies, buddy);
	}

	/* reading buddies */
	content->contacts_node = purple_xmlnode_get_child(xml, "Contacts");
	if (content->contacts_node == NULL) {
		g_hash_table_destroy(remove_buddies);
		g_list_free(update_buddies);
		ggp_roster_content_free(content);
		g_return_if_reached();
	}
	xml_it = purple_xmlnode_get_child(content->contacts_node, "Contact");
	while (xml_it != NULL) {
		if (!ggp_roster_reply_list_read_buddy(gc, xml_it, content,
			remove_buddies))
		{
			g_hash_table_destroy(remove_buddies);
			g_list_free(update_buddies);
			ggp_roster_content_free(content);
			g_return_if_reached();
		}

		xml_it = purple_xmlnode_get_next_twin(xml_it);
	}

	/* removing buddies, which are not present in roster */
	table_values = g_hash_table_get_values(remove_buddies);
	it = g_list_first(table_values);
	while (it) {
		PurpleBuddy *buddy = it->data;
		it = g_list_next(it);
		if (!ggp_roster_is_synchronized(buddy))
			continue;
		purple_debug_info("gg", "ggp_roster_reply_list: "
			"removing %s from buddy list\n",
			purple_buddy_get_name(buddy));
		purple_blist_remove_buddy(buddy);
	}
	g_list_free(table_values);
	g_hash_table_destroy(remove_buddies);

	/* remove groups, which are empty, but had contacts before
	 * synchronization
	 */
	it = g_list_first(local_groups);
	while (it) {
		PurpleGroup *group = it->data;
		it = g_list_next(it);
		if (purple_counting_node_get_total_size(PURPLE_COUNTING_NODE(group)) != 0)
			continue;
		purple_debug_info("gg", "ggp_roster_reply_list: "
			"removing group %s\n", purple_group_get_name(group));
		purple_blist_remove_group(group);
	}
	g_list_free(local_groups);

	/* adding not synchronized buddies */
	it = g_list_first(update_buddies);
	while (it) {
		PurpleBuddy *buddy = it->data;
		uin_t uin = ggp_str_to_uin(purple_buddy_get_name(buddy));
		ggp_roster_change *change;

		it = g_list_next(it);
		g_assert(uin > 0);

		purple_debug_misc("gg", "ggp_roster_reply_list: "
			"adding change of %u for roster\n", uin);
		change = g_new0(ggp_roster_change, 1);
		change->type = GGP_ROSTER_CHANGE_CONTACT_UPDATE;
		change->data.uin = uin;
		rdata->pending_updates =
			g_list_append(rdata->pending_updates, change);
	}
	g_list_free(update_buddies);

	rdata->content = content;
	rdata->is_updating = FALSE;
	purple_debug_info("gg", "ggp_roster_reply_list: "
		"import done, version=%u\n", version);
}