示例#1
0
qq_account* qq_account_new(PurpleAccount* account)
{
	qq_account* ac = g_malloc0(sizeof(qq_account));
	ac->account = account;
	ac->magic = QQ_MAGIC;
	ac->flag = 0;
	//this is auto increment sized array . so don't worry about it.
	const char* username = purple_account_get_username(account);
	const char* password = purple_account_get_password(account);
	ac->qq = lwqq_client_new(username,password);
	ac->js = lwqq_js_init();
	ac->sys_log = purple_log_new(PURPLE_LOG_SYSTEM, "system", account, NULL, time(NULL), NULL);

	ac->font.family = s_strdup("宋体");
	ac->font.size = 12;
	ac->font.style = 0;

	//lwqq_async_set(ac->qq,1);
#if QQ_USE_FAST_INDEX
	ac->qq->find_buddy_by_uin = find_buddy_by_uin;
	ac->qq->find_buddy_by_qqnumber = find_buddy_by_qqnumber;
	ac->fast_index.uin_index = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
	ac->fast_index.qqnum_index = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,NULL);
#endif
	ac->qq->dispatch = qq_dispatch;
	return ac;
}
示例#2
0
qq_account* qq_account_new(PurpleAccount* account)
{
   qq_account* ac = g_malloc0(sizeof(qq_account));
   ac->account = account;
   ac->magic = QQ_MAGIC;
   ac->flag = 0;
   // this is auto increment sized array . so don't worry about it.
   const char* username = purple_account_get_username(account);
   const char* password = purple_account_get_password(account);
   ac->qq = lwqq_client_new(username, password);
   ac->js = lwqq_js_init();
   ac->sys_log = purple_log_new(PURPLE_LOG_SYSTEM, "system", account, NULL,
                                time(NULL), NULL);
   // add ~/.config/lwqq into search path
   lwqq_util_add_path(lwdb_get_config_dir());
#ifdef WITH_MOZJS
   lwqq_hash_add_entry(ac->qq, "hash_local", (LwqqHashFunc)hash_with_local_file,
                       ac->js);
   lwqq_hash_add_entry(ac->qq, "hash_url", (LwqqHashFunc)hash_with_remote_file,
                       ac->js);
   lwqq_hash_add_entry(ac->qq, "hash_db", (LwqqHashFunc)hash_with_db_url, ac);
#endif

   ac->font.family = s_strdup("宋体");
   ac->font.size = 12;
   ac->font.style = 0;

// lwqq_async_set(ac->qq,1);
#if QQ_USE_FAST_INDEX
   ac->qq->find_buddy_by_uin = find_buddy_by_uin;
   ac->qq->find_buddy_by_qqnumber = find_buddy_by_qqnumber;
   ac->fast_index.uin_index
       = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
   ac->fast_index.qqnum_index
       = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
#endif
   ac->qq->dispatch = qq_dispatch;

   char cookie[256];
   snprintf(cookie, sizeof(cookie), "%s/%s.cookie", lwdb_get_config_dir(),
            username);
   LwqqExtension* ext = lwqq_make_cookie_extension(ac->qq, cookie);
   ext->init(ac->qq, ext);

   return ac;
}
示例#3
0
static void
write_message(PurpleBuddy *buddy, const char *message)
{
	PurpleConversation *conv;
	const char *alias = purple_buddy_get_alias(buddy);

	/* Acquire conversion */
	conv = purple_find_conversation_with_account(
		PURPLE_CONV_TYPE_ANY, buddy->name, buddy->account);
	
	if (conv != NULL) {
		/* If conversation is open just place there the message using purple_conversation_write() */
		purple_conversation_write(conv, alias, message, PURPLE_MESSAGE_SYSTEM, time(NULL));
	} else {
		/* No conversation opened. Reopen last or create new */
		if (ONLY_OPENED_CONVERSATIONS)
			return;

		/* Log file to write to */
		PurpleLog *log = NULL;

		if (!try_to_append(buddy, message)) {
			if (DEBUG)
				printf(INTRO "Creating new log file for %s\n", buddy->name);

			log = purple_log_new(PURPLE_LOG_IM, buddy->name, buddy->account, NULL, time(NULL), NULL);
			if (!log) {
				printf(INTRO "Log creation for %s failed!\n", buddy->name);
				return;
			}

			purple_log_write(log, PURPLE_MESSAGE_SYSTEM, alias, time(NULL), message);
			purple_log_free(log);
		}

	}
	return;
}