pidgin.next.minor: 4a65748e: Add a -f/--force-online option to Pidgin..

rlaager at pidgin.im rlaager at pidgin.im
Mon Dec 1 12:25:46 EST 2008


-----------------------------------------------------------------
Revision: 4a65748e82aa462266320a3bbb78e0170a25ff4b
Ancestor: 5801ff7aebb624cf66810f2a775683d8a175924c
Author: rlaager at pidgin.im
Date: 2008-11-28T06:06:35
Branch: im.pidgin.pidgin.next.minor
URL: http://d.pidgin.im/viewmtn/revision/info/4a65748e82aa462266320a3bbb78e0170a25ff4b

Modified files:
        ChangeLog.API libpurple/network.c libpurple/network.h
        pidgin/gtkmain.c

ChangeLog: 

Add a -f/--force-online option to Pidgin which tells libpurple to claim the
network is available, even if NetworkManager (or Windows) says it isn't.
This is useful for offline development with nullprpl.  If you don't like
-f for this and would just like to keep the long option, I'm fine with that.

Also, remove a -x/--nocrash option in Pidgin that doesn't seem to do anything.

-------------- next part --------------
============================================================
--- ChangeLog.API	68c78585cfd66fe0984372d93116446a16b77232
+++ ChangeLog.API	27a5326a5503d4037972e433d9dce51c8849b098
@@ -21,6 +21,7 @@ version 2.6.0 (??/??/????):
 		* purple_request_field_get_group
 		* purple_request_field_get_ui_data
 		* purple_request_field_set_ui_data
+		* purple_network_force_online
 
 		Deprecated:
 		* purple_buddy_get_local_alias
============================================================
--- libpurple/network.c	6245faabb1ac507e35cb1cc1aa07598fb20ac181
+++ libpurple/network.c	eed41d8dbbd1e203dc780aec11993eed43adc463
@@ -87,6 +87,10 @@ static NMState nm_get_network_state(void
 static NMState nm_get_network_state(void);
 #endif
 
+#if defined(HAVE_NETWORKMANAGER) || defined(_WIN32)
+static gboolean force_online;
+#endif
+
 const unsigned char *
 purple_network_ip_atoi(const char *ip)
 {
@@ -598,6 +602,9 @@ purple_network_is_available(void)
 purple_network_is_available(void)
 {
 #ifdef HAVE_NETWORKMANAGER
+	if (force_online)
+		return TRUE;
+
 	if (!have_nm_state)
 	{
 		have_nm_state = TRUE;
@@ -612,12 +619,20 @@ purple_network_is_available(void)
 	return FALSE;
 
 #elif defined _WIN32
-	return (current_network_count > 0);
+	return (current_network_count > 0 || force_online);
 #else
 	return TRUE;
 #endif
 }
 
+void
+purple_network_force_online()
+{
+#if defined(HAVE_NETWORKMANAGER) || defined(_WIN32)
+	force_online = TRUE;
+#endif
+}
+
 #ifdef HAVE_NETWORKMANAGER
 static void
 nm_update_state(NMState state)
============================================================
--- libpurple/network.h	c8d21a12c3c21bafcc6cc5f070fc9f39847b9bb0
+++ libpurple/network.h	81184e1fdfd56ba44107a4ace8b204c320f2985e
@@ -208,6 +208,17 @@ gboolean purple_network_is_available(voi
 gboolean purple_network_is_available(void);
 
 /**
+ * Makes purple_network_is_available() always return @c TRUE.
+ *
+ * This is what backs the --force-online command line argument in Pidgin,
+ * for example.  This is useful for offline testing, especially when
+ * combined with nullprpl.
+ *
+ * @since 2.6.0
+ */
+void purple_network_force_online(void);
+
+/**
  * Get the handle for the network system
  *
  * @return the handle to the network system
============================================================
--- pidgin/gtkmain.c	2e99f2ab7b6bd71f0713b8296358ad86cbe0ad7f
+++ pidgin/gtkmain.c	df365207042992de9d0bec93e57c83734b319b62
@@ -390,6 +390,7 @@ show_usage(const char *name, gboolean te
 		       "Usage: %s [OPTION]...\n\n"
 		       "  -c, --config=DIR    use DIR for config files\n"
 		       "  -d, --debug         print debugging messages to stdout\n"
+		       "  -f, --force-online  force online, regardless of network status\n"
 		       "  -h, --help          display this help and exit\n"
 		       "  -m, --multiple      do not ensure single instance\n"
 		       "  -n, --nologin       don't automatically login\n"
@@ -403,6 +404,7 @@ show_usage(const char *name, gboolean te
 		       "Usage: %s [OPTION]...\n\n"
 		       "  -c, --config=DIR    use DIR for config files\n"
 		       "  -d, --debug         print debugging messages to stdout\n"
+		       "  -f, --force-online  force online, regardless of network status\n"
 		       "  -h, --help          display this help and exit\n"
 		       "  -m, --multiple      do not ensure single instance\n"
 		       "  -n, --nologin       don't automatically login\n"
@@ -462,10 +464,10 @@ int main(int argc, char *argv[])
 int main(int argc, char *argv[])
 #endif
 {
+	gboolean opt_force_online = FALSE;
 	gboolean opt_help = FALSE;
 	gboolean opt_login = FALSE;
 	gboolean opt_nologin = FALSE;
-	gboolean opt_nocrash = FALSE;
 	gboolean opt_version = FALSE;
 	gboolean opt_si = TRUE;     /* Check for single instance? */
 	char *opt_config_dir_arg = NULL;
@@ -490,17 +492,17 @@ int main(int argc, char *argv[])
 	GList *active_accounts;
 
 	struct option long_options[] = {
-		{"config",   required_argument, NULL, 'c'},
-		{"debug",    no_argument,       NULL, 'd'},
-		{"help",     no_argument,       NULL, 'h'},
-		{"login",    optional_argument, NULL, 'l'},
-		{"multiple", no_argument,       NULL, 'm'},
-		{"nologin",  no_argument,       NULL, 'n'},
-		{"nocrash",  no_argument,       NULL, 'x'},
-		{"session",  required_argument, NULL, 's'},
-		{"version",  no_argument,       NULL, 'v'},
-		{"display",  required_argument, NULL, 'D'},
-		{"sync",     no_argument,       NULL, 'S'},
+		{"config",       required_argument, NULL, 'c'},
+		{"debug",        no_argument,       NULL, 'd'},
+		{"force-online", no_argument,       NULL, 'd'},
+		{"help",         no_argument,       NULL, 'h'},
+		{"login",        optional_argument, NULL, 'l'},
+		{"multiple",     no_argument,       NULL, 'm'},
+		{"nologin",      no_argument,       NULL, 'n'},
+		{"session",      required_argument, NULL, 's'},
+		{"version",      no_argument,       NULL, 'v'},
+		{"display",      required_argument, NULL, 'D'},
+		{"sync",         no_argument,       NULL, 'S'},
 		{0, 0, 0, 0}
 	};
 
@@ -607,9 +609,9 @@ int main(int argc, char *argv[])
 	opterr = 1;
 	while ((opt = getopt_long(argc, argv,
 #ifndef _WIN32
-				  "c:dhmnl::s:v",
+				  "c:dfhmnl::s:v",
 #else
-				  "c:dhmnl::v",
+				  "c:dfhmnl::v",
 #endif
 				  long_options, NULL)) != -1) {
 		switch (opt) {
@@ -620,6 +622,9 @@ int main(int argc, char *argv[])
 		case 'd':	/* debug */
 			debug_enabled = TRUE;
 			break;
+		case 'f':	/* force-online */
+			opt_force_online = TRUE;
+			break;
 		case 'h':	/* help */
 			opt_help = TRUE;
 			break;
@@ -642,9 +647,6 @@ int main(int argc, char *argv[])
 		case 'm':   /* do not ensure single instance. */
 			opt_si = FALSE;
 			break;
-		case 'x':   /* --nocrash */
-			opt_nocrash = TRUE;
-			break;
 		case 'D':   /* --display */
 		case 'S':   /* --sync */
 			/* handled by gtk_init_check below */
@@ -821,6 +823,11 @@ int main(int argc, char *argv[])
 		opt_config_dir_arg = NULL;
 	}
 
+	/* This needs to be before purple_blist_show() so the
+	 * statusbox gets the forced online status. */
+	if (opt_force_online)
+		purple_network_force_online();
+
 	/*
 	 * We want to show the blist early in the init process so the
 	 * user feels warm and fuzzy (not cold and prickley).


More information about the Commits mailing list