soc.2010.detachablepurple: 5b346272: Updated remotenullclient, so that we can...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Fri Jul 16 01:17:00 EDT 2010


----------------------------------------------------------------------
Revision: 5b3462724abda23a0cbe281274019ca05f81ecff
Parent:   e07ee1656c8706cab8df9b96412b5e000281ff4f
Author:   gillux at soc.pidgin.im
Date:     07/16/10 01:08:49
Branch:   im.pidgin.soc.2010.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/5b3462724abda23a0cbe281274019ca05f81ecff

Changelog: 

Updated remotenullclient, so that we can test a few things.

Changes against parent e07ee1656c8706cab8df9b96412b5e000281ff4f

  patched  libpurple/example/remotenullclient.c

-------------- next part --------------
============================================================
--- libpurple/example/remotenullclient.c	f41b08532f7dd0b6419600dc4f2af1709dab4296
+++ libpurple/example/remotenullclient.c	13add7fe248e2534c4c04e9813ed6889e62ec7fa
@@ -247,33 +247,15 @@ connect_to_signals_for_demonstration_pur
 				PURPLE_CALLBACK(signed_on), NULL);
 }
 
-int main(int argc, char *argv[])
-{
+static PurpleAccount*
+prompt_new_account(void) {
 	GList *iter;
+	char *res;
 	int i, num;
+	char name[128];
 	GList *names = NULL;
 	const char *prpl;
-	char name[128];
-	char *password;
-	GMainLoop *loop = g_main_loop_new(NULL, FALSE);
-	PurpleAccount *account;
-	PurpleSavedStatus *status;
-	char *res;
 
-#ifndef _WIN32
-	/* libpurple's built-in DNS resolution forks processes to perform
-	 * blocking lookups without blocking the main process.  It does not
-	 * handle SIGCHLD itself, so if the UI does not you quickly get an army
-	 * of zombie subprocesses marching around.
-	 */
-	signal(SIGCHLD, SIG_IGN);
-#endif
-
-	init_libpurple();
-
-	printf("libpurple initialized.\n");
-
-#if 0
 	iter = purple_plugins_get_protocols();
 	for (i = 0; iter; iter = iter->next) {
 		PurplePlugin *plugin = iter->data;
@@ -299,19 +281,75 @@ int main(int argc, char *argv[])
 		abort();
 	}
 	name[strlen(name) - 1] = 0;  /* strip the \n at the end */
-#else
-	prpl = "prpl-jabber";
-	strcpy(name, "foobar at exaple.net");
+
+	/* Create the account */
+	return purple_account_new(name, prpl);
+}
+
+static PurpleAccount*
+choose_account(GList* accounts)
+{
+	int i, num;
+	char *res;
+	GList* elem = accounts;
+	PurpleAccount* acc;
+	char choice[128];
+
+	printf("\t[0] Create a new account\n");
+	for (i = 1; elem; elem = elem->next, i++) {
+		acc = elem->data;
+		printf("\t[%i] (%s) %s\n", i,
+		       purple_account_get_protocol_name(acc),
+		       purple_account_get_username(acc));
+	}
+
+	printf("\nYour choice ? ");
+	res = fgets(choice, sizeof(choice), stdin);
+	if (!res) {
+		fprintf(stderr, "Failed to gets choice.");
+		abort();
+	}
+	sscanf(choice, "%d", &num);
+	if (num == 0)
+		return prompt_new_account();
+	else
+		return g_list_nth_data(accounts, --num);
+}
+
+int main(int argc, char *argv[])
+{
+	char *password;
+	GMainLoop *loop = g_main_loop_new(NULL, FALSE);
+	PurpleAccount *account;
+	PurpleSavedStatus *status;
+	GList* accs;
+
+#ifndef _WIN32
+	/* libpurple's built-in DNS resolution forks processes to perform
+	 * blocking lookups without blocking the main process.  It does not
+	 * handle SIGCHLD itself, so if the UI does not you quickly get an army
+	 * of zombie subprocesses marching around.
+	 */
+	//signal(SIGCHLD, SIG_IGN); /* I faced problems with dbus due to this */
 #endif
 
-	/* Create the account */
-	account = purple_account_new(name, prpl);
+	init_libpurple();
 
+	printf("libpurple initialized.\n");
+
+	accs = purple_accounts_all();
+	if (accs) {
+		printf("%u account(s) found on the daemon.\n",
+		       g_list_length(accs));
+		account = choose_account(accs);
+	} else {
+		printf("No accounts found on the daemon, let's create a new one...\n");
+		account = prompt_new_account();
+	}
 	/* Get the password for the account */
-	password = getpass("Password (will be remotely set): ");
+	password = getpass("Password: ");
 	purple_account_set_password(account, password);
 
-#if 0
 	/* It's necessary to enable the account first. */
 	purple_account_set_enabled(account, TRUE);
 
@@ -322,7 +360,6 @@ int main(int argc, char *argv[])
 	connect_to_signals_for_demonstration_purposes_only();
 
 	g_main_loop_run(loop);
-#endif
 	return 0;
 }
 


More information about the Commits mailing list