コード例 #1
0
ファイル: protocol.c プロジェクト: N8Fear/purple-facebook
static void
purple_protocol_finalize(GObject *object)
{
	PurpleProtocol *protocol = PURPLE_PROTOCOL(object);
	GList *accounts, *l;

	accounts = purple_accounts_get_all_active();
	for (l = accounts; l != NULL; l = l->next) {
		PurpleAccount *account = PURPLE_ACCOUNT(l->data);
		if (purple_account_is_disconnected(account))
			continue;

		if (purple_strequal(protocol->id,
				purple_account_get_protocol_id(account)))
			purple_account_disconnect(account);
	}

	g_list_free(accounts);

	purple_request_close_with_handle(protocol);
	purple_notify_close_with_handle(protocol);

	purple_signals_disconnect_by_handle(protocol);
	purple_signals_unregister_by_instance(protocol);

	purple_prefs_disconnect_by_handle(protocol);

	user_splits_free(protocol);
	account_options_free(protocol);
	icon_spec_free(protocol);

	PURPLE_DBUS_UNREGISTER_POINTER(protocol);

	parent_class->finalize(object);
}
コード例 #2
0
static gboolean
set_status_all()
{
   trace("status setting..");

   char *ip = purple_network_get_my_ip(-1);
   if (strcmp(str_myip, ip) != 0) {
      strcpy(str_myip, ip);
      myip = ip_atoi(ip);

      /* find the longest prefix rule */
      guint32 i=0;
      guint32 max_len = 0;
      guint32 fit = 0;
      gboolean found = FALSE;
      for (i=0; i<rule_cnt; i++){
         if (!found && rules[i].netmask == 0 ) {
            fit = i; found = TRUE; continue;
         }
         if ((rules[i].netmask > max_len) && \
               (((myip ^ rules[i].ip) & (~0 << (32-rules[i].netmask))) == 0)) {
            max_len = rules[i].netmask;
            fit = i;
            found = TRUE;
         }
      }
      if (found) {
         loc = rules[fit].status;
         trace("Found fit rules, %s", loc);
      }
      else loc = "";
   }

   GList *acnt = NULL, *head = NULL;
   head = acnt = purple_accounts_get_all_active();

   while (acnt != NULL) {
      if ((PurpleAccount *)acnt->data != NULL) {
         set_status (acnt->data, loc);
      }
      acnt = acnt->next;
   }

   if (head != NULL)
      g_list_free(head);

   trace("status set for all accounts");

   return TRUE;
}
コード例 #3
0
ファイル: unity.c プロジェクト: N8Fear/purple-facebook
static PurpleSavedStatus *
create_transient_status(PurpleStatusPrimitive primitive, PurpleStatusType *status_type)
{
	PurpleSavedStatus *saved_status = purple_savedstatus_new(NULL, primitive);

	if(status_type != NULL) {
		GList *tmp, *active_accts = purple_accounts_get_all_active();
		for (tmp = active_accts; tmp != NULL; tmp = tmp->next) {
			purple_savedstatus_set_substatus(saved_status,
				(PurpleAccount*) tmp->data, status_type, NULL);
		}
		g_list_free(active_accts);
	}

	return saved_status;
}
コード例 #4
0
ファイル: gtkconn.c プロジェクト: Draghtnod/pidgin
static void pidgin_connection_network_connected (void)
{
	GList *list, *l;
	PidginBuddyList *gtkblist = pidgin_blist_get_default_gtk_blist();

	if(gtkblist)
		pidgin_status_box_set_network_available(PIDGIN_STATUS_BOX(gtkblist->statusbox), TRUE);

	l = list = purple_accounts_get_all_active();
	while (l) {
		PurpleAccount *account = (PurpleAccount*)l->data;
		g_hash_table_remove(auto_reconns, account);
		if (purple_account_is_disconnected(account))
			do_signon(account);
		l = l->next;
	}
	g_list_free(list);
}
コード例 #5
0
ファイル: gtkconn.c プロジェクト: Draghtnod/pidgin
static void pidgin_connection_network_disconnected (void)
{
	GList *list, *l;
	PidginBuddyList *gtkblist = pidgin_blist_get_default_gtk_blist();

	if(gtkblist)
		pidgin_status_box_set_network_available(PIDGIN_STATUS_BOX(gtkblist->statusbox), FALSE);

	l = list = purple_accounts_get_all_active();
	while (l) {
		PurpleAccount *a = (PurpleAccount*)l->data;
		if (!purple_account_is_disconnected(a)) {
			char *password = g_strdup(purple_account_get_password(a));
			purple_account_disconnect(a);
			purple_account_set_password(a, password);
			g_free(password);
		}
		l = l->next;
	}
	g_list_free(list);
}
コード例 #6
0
std::string get_account_status()
{
    std::string result;
    // :fixme:
    // atm we get the status only for the first account (assuming the status is
    // identical forall active accounts - which may not be true)
    GList *p_accounts = purple_accounts_get_all_active();
    if (p_accounts) {
        PurpleStatus *p_status = purple_account_get_active_status(
          reinterpret_cast<PurpleAccount*>(g_list_first(p_accounts)->data));
        const char *p_status_text = purple_primitive_get_name_from_type(
          purple_status_type_get_primitive(purple_status_get_type(p_status)));
        if (p_status_text) {
            result = p_status_text;
        } else {
            result = "Unknown";
            }
    } else {
        // no active accounts -> offline
        result = "Offline";
    }
    return result;
}
コード例 #7
0
/**
 * This method motivates Purple's Host (e.g. Pidgin) to update its UI
 * by using standard Purple's means of signals and saved statuses.
 *
 * Thus all UI elements get updated: Status Button with Note, docklet.
 * This is ablolutely important as both our status and note can come
 * inbound (roaming) or be updated programmatically (e.g. based on our
 * calendar data).
 */
void sipe_backend_status_and_note(struct sipe_core_public *sipe_public,
				  guint activity,
				  const gchar *message)
{
	struct sipe_backend_private *purple_private = sipe_public->backend_private;
	PurpleAccount *account = purple_private->account;
	const gchar *status_id = sipe_purple_activity_to_token(activity);
	PurpleSavedStatus *saved_status;
	const PurpleStatusType *acct_status_type =
		purple_status_type_find_with_id(account->status_types, status_id);
	PurpleStatusPrimitive primitive = purple_status_type_get_primitive(acct_status_type);

	saved_status = purple_savedstatus_find_transient_by_type_and_message(primitive, message);
	if (saved_status) {
		purple_savedstatus_set_substatus(saved_status, account, acct_status_type, message);
	}

	/* If this type+message is unique then create a new transient saved status
	 * Ref: gtkstatusbox.c
	 */
	if (!saved_status) {
		GList *tmp;
		GList *active_accts = purple_accounts_get_all_active();

		saved_status = purple_savedstatus_new(NULL, primitive);
		purple_savedstatus_set_message(saved_status, message);

		for (tmp = active_accts; tmp != NULL; tmp = tmp->next) {
			purple_savedstatus_set_substatus(saved_status,
							 (PurpleAccount *)tmp->data, acct_status_type, message);
		}
		g_list_free(active_accts);
	}

	/* Set the status for each account */
	purple_savedstatus_activate(saved_status);
}
コード例 #8
0
 */JNIEXPORT jlong JNICALL
Java_im_pidgin_jpurple_account_PurpleAccountManager_getActiveAccounts_1native(
		JNIEnv *env, jobject obj)
{
	return pToLong(purple_accounts_get_all_active());
}
コード例 #9
0
ファイル: gtkmain.c プロジェクト: Lilitana/Pidgin
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_version = FALSE;
	gboolean opt_si = TRUE;     /* Check for single instance? */
	char *opt_config_dir_arg = NULL;
	char *opt_login_arg = NULL;
	char *opt_session_arg = NULL;
	char *search_path;
	GList *accounts;
#ifdef HAVE_SIGNAL_H
	int sig_indx;	/* for setting up signal catching */
	sigset_t sigset;
	RETSIGTYPE (*prev_sig_disp)(int);
	char errmsg[BUFSIZ];
	GIOChannel *signal_channel;
	GIOStatus signal_status;
	guint signal_channel_watcher;
#ifndef DEBUG
	char *segfault_message_tmp;
#endif
	GError *error;
#endif
	int opt;
	gboolean gui_check;
	gboolean debug_enabled;
	gboolean migration_failed = FALSE;
	GList *active_accounts;
	struct stat st;

	struct option long_options[] = {
		{"config",       required_argument, NULL, 'c'},
		{"debug",        no_argument,       NULL, 'd'},
		{"force-online", no_argument,       NULL, 'f'},
		{"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}
	};

#ifdef DEBUG
	debug_enabled = TRUE;
#else
	debug_enabled = FALSE;
#endif

	/* Initialize GThread before calling any Glib or GTK+ functions. */
	g_thread_init(NULL);

	g_set_prgname("Pidgin");

#ifdef ENABLE_NLS
	bindtextdomain(PACKAGE, LOCALEDIR);
	bind_textdomain_codeset(PACKAGE, "UTF-8");
	textdomain(PACKAGE);
#endif

#ifdef HAVE_SETLOCALE
	/* Locale initialization is not complete here.  See gtk_init_check() */
	setlocale(LC_ALL, "");
#endif

#ifdef HAVE_SIGNAL_H

#ifndef DEBUG
		/* We translate this here in case the crash breaks gettext. */
		segfault_message_tmp = g_strdup_printf(_(
			"%s %s has segfaulted and attempted to dump a core file.\n"
			"This is a bug in the software and has happened through\n"
			"no fault of your own.\n\n"
			"If you can reproduce the crash, please notify the developers\n"
			"by reporting a bug at:\n"
			"%ssimpleticket/\n\n"
			"Please make sure to specify what you were doing at the time\n"
			"and post the backtrace from the core file.  If you do not know\n"
			"how to get the backtrace, please read the instructions at\n"
			"%swiki/GetABacktrace\n"),
			PIDGIN_NAME, DISPLAY_VERSION, PURPLE_DEVEL_WEBSITE, PURPLE_DEVEL_WEBSITE
		);

		/* we have to convert the message (UTF-8 to console
		   charset) early because after a segmentation fault
		   it's not a good practice to allocate memory */
		error = NULL;
		segfault_message = g_locale_from_utf8(segfault_message_tmp,
						      -1, NULL, NULL, &error);
		if (segfault_message != NULL) {
			g_free(segfault_message_tmp);
		}
		else {
			/* use 'segfault_message_tmp' (UTF-8) as a fallback */
			g_warning("%s\n", error->message);
			g_error_free(error);
			segfault_message = segfault_message_tmp;
		}
#else
		/* Don't mark this for translation. */
		segfault_message = g_strdup(
			"Hi, user.  We need to talk.\n"
			"I think something's gone wrong here.  It's probably my fault.\n"
			"No, really, it's not you... it's me... no no no, I think we get along well\n"
			"it's just that.... well, I want to see other people.  I... what?!?  NO!  I \n"
			"haven't been cheating on you!!  How many times do you want me to tell you?!  And\n"
			"for the last time, it's just a rash!\n"
		);
#endif

	/*
	 * Create a socket pair for receiving unix signals from a signal
	 * handler.
	 */
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, signal_sockets) < 0) {
		perror("Failed to create sockets for GLib signal handling");
		exit(1);
	}
	signal_channel = g_io_channel_unix_new(signal_sockets[1]);

	/*
	 * Set the channel encoding to raw binary instead of the default of
	 * UTF-8, because we'll be sending integers across instead of strings.
	 */
	error = NULL;
	signal_status = g_io_channel_set_encoding(signal_channel, NULL, &error);
	if (signal_status != G_IO_STATUS_NORMAL) {
		fprintf(stderr, "Failed to set the signal channel to raw "
				"binary: %s", error->message);
		exit(1);
	}
	signal_channel_watcher = g_io_add_watch(signal_channel, G_IO_IN, mainloop_sighandler, NULL);
	g_io_channel_unref(signal_channel);

	/* Let's not violate any PLA's!!!! */
	/* jseymour: whatever the fsck that means */
	/* Robot101: for some reason things like gdm like to block     *
	 * useful signals like SIGCHLD, so we unblock all the ones we  *
	 * declare a handler for. thanks JSeymour and Vann.            */
	if (sigemptyset(&sigset)) {
		snprintf(errmsg, sizeof(errmsg), "Warning: couldn't initialise empty signal set");
		perror(errmsg);
	}
	for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) {
		if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) {
			snprintf(errmsg, sizeof(errmsg), "Warning: couldn't set signal %d for catching",
				catch_sig_list[sig_indx]);
			perror(errmsg);
		}
		if(sigaddset(&sigset, catch_sig_list[sig_indx])) {
			snprintf(errmsg, sizeof(errmsg), "Warning: couldn't include signal %d for unblocking",
				catch_sig_list[sig_indx]);
			perror(errmsg);
		}
	}
	for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) {
		if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) {
			snprintf(errmsg, sizeof(errmsg), "Warning: couldn't set signal %d to ignore",
				ignore_sig_list[sig_indx]);
			perror(errmsg);
		}
	}

	if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) {
		snprintf(errmsg, sizeof(errmsg), "Warning: couldn't unblock signals");
		perror(errmsg);
	}
#endif

	/* scan command-line options */
	opterr = 1;
	while ((opt = getopt_long(argc, argv,
#ifndef _WIN32
				  "c:dfhmnl::s:v",
#else
				  "c:dfhmnl::v",
#endif
				  long_options, NULL)) != -1) {
		switch (opt) {
		case 'c':	/* config dir */
			g_free(opt_config_dir_arg);
			opt_config_dir_arg = g_strdup(optarg);
			break;
		case 'd':	/* debug */
			debug_enabled = TRUE;
			break;
		case 'f':	/* force-online */
			opt_force_online = TRUE;
			break;
		case 'h':	/* help */
			opt_help = TRUE;
			break;
		case 'n':	/* no autologin */
			opt_nologin = TRUE;
			break;
		case 'l':	/* login, option username */
			opt_login = TRUE;
			g_free(opt_login_arg);
			if (optarg != NULL)
				opt_login_arg = g_strdup(optarg);
			break;
		case 's':	/* use existing session ID */
			g_free(opt_session_arg);
			opt_session_arg = g_strdup(optarg);
			break;
		case 'v':	/* version */
			opt_version = TRUE;
			break;
		case 'm':   /* do not ensure single instance. */
			opt_si = FALSE;
			break;
		case 'D':   /* --display */
		case 'S':   /* --sync */
			/* handled by gtk_init_check below */
			break;
		case '?':	/* show terse help */
		default:
			show_usage(argv[0], TRUE);
#ifdef HAVE_SIGNAL_H
			g_free(segfault_message);
#endif
			return 0;
			break;
		}
	}

	/* show help message */
	if (opt_help) {
		show_usage(argv[0], FALSE);
#ifdef HAVE_SIGNAL_H
		g_free(segfault_message);
#endif
		return 0;
	}
	/* show version message */
	if (opt_version) {
		printf("%s %s (libpurple %s)\n", PIDGIN_NAME, DISPLAY_VERSION,
		                                 purple_core_get_version());
#ifdef HAVE_SIGNAL_H
		g_free(segfault_message);
#endif
		return 0;
	}

	/* set a user-specified config directory */
	if (opt_config_dir_arg != NULL) {
		purple_util_set_user_dir(opt_config_dir_arg);
	}

	/*
	 * We're done piddling around with command line arguments.
	 * Fire up this baby.
	 */

	purple_debug_set_enabled(debug_enabled);

	/* If we're using a custom configuration directory, we
	 * do NOT want to migrate, or weird things will happen. */
	if (opt_config_dir_arg == NULL)
	{
		if (!purple_core_migrate())
		{
			migration_failed = TRUE;
		}
	}

	search_path = g_build_filename(purple_user_dir(), "gtkrc-2.0", NULL);
	gtk_rc_add_default_file(search_path);
	g_free(search_path);

	gui_check = gtk_init_check(&argc, &argv);
	if (!gui_check) {
		char *display = gdk_get_display();

		printf("%s %s\n", PIDGIN_NAME, DISPLAY_VERSION);

		g_warning("cannot open display: %s", display ? display : "unset");
		g_free(display);
#ifdef HAVE_SIGNAL_H
		g_free(segfault_message);
#endif

		return 1;
	}

	g_set_application_name(PIDGIN_NAME);

#ifdef _WIN32
	winpidgin_init(hint);
#endif

	if (migration_failed)
	{
		char *old = g_strconcat(purple_home_dir(),
		                        G_DIR_SEPARATOR_S ".gaim", NULL);
		const char *text = _(
			"%s encountered errors migrating your settings "
			"from %s to %s. Please investigate and complete the "
			"migration by hand. Please report this error at http://developer.pidgin.im");
		GtkWidget *dialog;

		dialog = gtk_message_dialog_new(NULL,
		                                0,
		                                GTK_MESSAGE_ERROR,
		                                GTK_BUTTONS_CLOSE,
		                                text, PIDGIN_NAME,
		                                old, purple_user_dir());
		g_free(old);

		g_signal_connect_swapped(dialog, "response",
		                         G_CALLBACK(gtk_main_quit), NULL);

		gtk_widget_show_all(dialog);

		gtk_main();

#ifdef HAVE_SIGNAL_H
		g_free(segfault_message);
#endif
		return 0;
	}

	purple_core_set_ui_ops(pidgin_core_get_ui_ops());
	purple_eventloop_set_ui_ops(pidgin_eventloop_get_ui_ops());

	/*
	 * Set plugin search directories. Give priority to the plugins
	 * in user's home directory.
	 */
	search_path = g_build_filename(purple_user_dir(), "plugins", NULL);
	if (!g_stat(search_path, &st))
		g_mkdir(search_path, S_IRUSR | S_IWUSR | S_IXUSR);
	purple_plugins_add_search_path(search_path);
	g_free(search_path);
	purple_plugins_add_search_path(LIBDIR);

	if (!purple_core_init(PIDGIN_UI)) {
		fprintf(stderr,
				"Initialization of the libpurple core failed. Dumping core.\n"
				"Please report this!\n");
#ifdef HAVE_SIGNAL_H
		g_free(segfault_message);
#endif
		abort();
	}

	if (opt_si && !purple_core_ensure_single_instance()) {
#ifdef HAVE_DBUS
		DBusConnection *conn = purple_dbus_get_connection();
		DBusMessage *message = dbus_message_new_method_call(DBUS_SERVICE_PURPLE, DBUS_PATH_PURPLE,
				DBUS_INTERFACE_PURPLE, "PurpleBlistSetVisible");
		gboolean tr = TRUE;
		dbus_message_append_args(message, DBUS_TYPE_INT32, &tr, DBUS_TYPE_INVALID);
		dbus_connection_send_with_reply_and_block(conn, message, -1, NULL);
		dbus_message_unref(message);
#endif
		gdk_notify_startup_complete();
		purple_core_quit();
		g_printerr(_("Exiting because another libpurple client is already running.\n"));
#ifdef HAVE_SIGNAL_H
		g_free(segfault_message);
#endif
		return 0;
	}

	/* TODO: Move blist loading into purple_blist_init() */
	purple_set_blist(purple_blist_new());
	purple_blist_load();

	/* load plugins we had when we quit */
	purple_plugins_load_saved(PIDGIN_PREFS_ROOT "/plugins/loaded");

	/* TODO: Move pounces loading into purple_pounces_init() */
	purple_pounces_load();

	ui_main();

#ifdef USE_SM
	pidgin_session_init(argv[0], opt_session_arg, opt_config_dir_arg);
#endif
	if (opt_session_arg != NULL) {
		g_free(opt_session_arg);
		opt_session_arg = NULL;
	}
	if (opt_config_dir_arg != NULL) {
		g_free(opt_config_dir_arg);
		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).
	 */
	purple_blist_show();

	if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/debug/enabled"))
		pidgin_debug_window_show();

	if (opt_login) {
		/* disable all accounts */
		for (accounts = purple_accounts_get_all(); accounts != NULL; accounts = accounts->next) {
			PurpleAccount *account = accounts->data;
			purple_account_set_enabled(account, PIDGIN_UI, FALSE);
		}
		/* honor the startup status preference */
		if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status"))
			purple_savedstatus_activate(purple_savedstatus_get_startup());
		/* now enable the requested ones */
		dologin_named(opt_login_arg);
		if (opt_login_arg != NULL) {
			g_free(opt_login_arg);
			opt_login_arg = NULL;
		}
	} else if (opt_nologin)	{
		/* Set all accounts to "offline" */
		PurpleSavedStatus *saved_status;

		/* If we've used this type+message before, lookup the transient status */
		saved_status = purple_savedstatus_find_transient_by_type_and_message(
							PURPLE_STATUS_OFFLINE, NULL);

		/* If this type+message is unique then create a new transient saved status */
		if (saved_status == NULL)
			saved_status = purple_savedstatus_new(NULL, PURPLE_STATUS_OFFLINE);

		/* Set the status for each account */
		purple_savedstatus_activate(saved_status);
	} else {
		/* Everything is good to go--sign on already */
		if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status"))
			purple_savedstatus_activate(purple_savedstatus_get_startup());
		purple_accounts_restore_current_statuses();
	}

	if ((active_accounts = purple_accounts_get_all_active()) == NULL)
	{
		pidgin_accounts_window_show();
	}
	else
	{
		g_list_free(active_accounts);
	}

	/* GTK clears the notification for us when opening the first window,
	 * but we may have launched with only a status icon, so clear the it
	 * just in case. */
	gdk_notify_startup_complete();

#ifdef _WIN32
	winpidgin_post_init();
#endif

	gtk_main();

#ifdef HAVE_SIGNAL_H
	g_free(segfault_message);
	g_source_remove(signal_channel_watcher);
	close(signal_sockets[0]);
	close(signal_sockets[1]);
#endif

#ifdef _WIN32
	winpidgin_cleanup();
#endif

	return 0;
}
コード例 #10
0
ファイル: acct_features.c プロジェクト: gawen947/pidgin-pbar
void init_acct_features_dialog(struct acct_features_dialog *f_diag)
{
  GList *a = purple_accounts_get_all_active();
  /* TODO: should be freed ? */
  GdkPixbuf *yes = gtk_widget_render_icon(f_diag->window, GTK_STOCK_YES,
                                          GTK_ICON_SIZE_MENU, NULL);
  GdkPixbuf *no  = gtk_widget_render_icon(f_diag->window, GTK_STOCK_NO,
                                          GTK_ICON_SIZE_MENU, NULL);

  /* last line summarize all available features */
  GtkTreeIter e_iter;
  GdkPixbuf *e_icon     = gtk_widget_render_icon(f_diag->window,
                                                 PIDGIN_STOCK_INFO,
                                                 GTK_ICON_SIZE_MENU,
                                                 NULL);
  GdkPixbuf *e_pm        = no;
  GdkPixbuf *e_buddyicon = no;
  GdkPixbuf *e_nickname  = no;
  GdkPixbuf *e_mood      = no;
  GdkPixbuf *e_moodmsg   = no;
  GdkPixbuf *e_game      = no;
  GdkPixbuf *e_app       = no;
  GdkPixbuf *e_tune      = no;

  for(; a ; a = a->next) {
    PurpleAccount *acct  = (PurpleAccount *)a->data;
    PurplePlugin *plugin = purple_find_prpl(acct->protocol_id);
    PurplePluginProtocolInfo *protocol = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);

    GtkTreeIter iter;
    gchar *username = g_strdup_printf("%s (%s)",
                                           purple_account_get_username(acct),
                                           purple_account_get_protocol_name(acct));
    GdkPixbuf *a_icon = pidgin_create_prpl_icon(acct, PIDGIN_PRPL_ICON_MEDIUM);
    GHashTable *attrs  = get_account_attrs(acct);

    GdkPixbuf *nickname, *mood, *moodmsg, *game, *app, *tune, *pm, *buddyicon;

    if(g_hash_table_lookup(attrs, "mood"))
      e_mood = mood = yes;
    else
      mood = no;
    if(g_hash_table_lookup(attrs, "moodtext"))
      e_moodmsg = moodmsg = yes;
    else
      moodmsg = no;
    if(g_hash_table_lookup(attrs, "game"))
      e_game = game = yes;
    else
      game = no;
    if(g_hash_table_lookup(attrs, "office"))
      e_app = app = yes;
    else
      app = no;
    if((g_hash_table_lookup(attrs, "tune_title") &&
        g_hash_table_lookup(attrs, "tune_artist") &&
        g_hash_table_lookup(attrs, "tune_album")))
      e_tune = tune = yes;
    else
      tune = no;
    g_hash_table_destroy(attrs);

    if(protocol->set_status)
      e_pm = pm = yes;
    else
      pm = no;
    if(protocol->set_buddy_icon)
      e_buddyicon = buddyicon = yes;
    else
      buddyicon = no;
    /* exception for XMPP
       nickname supported
       manually
       FIXME: however some XMPP account don't support nickname extension */
    if(!strcmp(acct->protocol_id, "prpl-jabber") || protocol->set_public_alias)
      e_nickname = nickname = yes;
    else
      nickname = no;

    gtk_list_store_append(f_diag->list_store, &iter);
    gtk_list_store_set(f_diag->list_store, &iter,
                       ACCT_COLUMN, username,
                       ACCTICON_COLUMN, a_icon,
                       NICKNAME_COLUMN, nickname,
                       PM_COLUMN, pm,
                       ICON_COLUMN, buddyicon,
                       MOOD_COLUMN, mood,
                       MOODMSG_COLUMN, moodmsg,
                       TUNE_COLUMN, tune,
                       GAME_COLUMN, game,
                       APP_COLUMN, app,
                       -1);
    g_free(username);
  }

  /* last line summarize all available features */
  gtk_list_store_append(f_diag->list_store, &e_iter);
  gtk_list_store_set(f_diag->list_store, &e_iter,
                     ACCT_COLUMN, "Available features",
                     ACCTICON_COLUMN, e_icon,
                     NICKNAME_COLUMN, e_nickname,
                     PM_COLUMN, e_pm,
                     ICON_COLUMN, e_buddyicon,
                     MOOD_COLUMN, e_mood,
                     MOODMSG_COLUMN, e_moodmsg,
                     TUNE_COLUMN, e_tune,
                     GAME_COLUMN, e_game,
                     APP_COLUMN, e_app,
                     -1);
}
コード例 #11
0
/////////////////////////////////////////////////////////////////////////////
// The window procedure.  It handles WTS_SESSION_LOCK and WTS_SESSION_UNLOCK
//  messages sent to the LNR window.
/////////////////////////////////////////////////////////////////////////////
static LRESULT CALLBACK LnrWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    GList *accts, *iter;
    PurpleAccount *acct = NULL;
    PurpleStatusType *status_type = NULL;
    PurpleSavedStatus *saved_status = NULL;

    switch(uMsg)
    {
    case WM_WTSSESSION_CHANGE:
        switch(wParam)
        {
        case WTS_SESSION_LOCK:
        case WTS_REMOTE_DISCONNECT:

            saved_status = purple_savedstatus_new(NULL, purple_prefs_get_int(LNR_PREF_STATUS));
            purple_savedstatus_set_message(saved_status, purple_prefs_get_string(LNR_PREF_MESSAGE));

            iter = accts = purple_accounts_get_all_active();
            for(; iter != NULL; iter = iter->next)
            {
                acct = (PurpleAccount*)iter->data;
                if(lnr_should_change_message(acct))
                {
                    status_type = purple_account_get_status_type_with_primitive(acct, purple_prefs_get_int(LNR_PREF_STATUS));
                    if(status_type != NULL)
                    {
                        // Set the substatus for this account
                        purple_savedstatus_set_substatus(saved_status, acct, status_type, purple_prefs_get_string(LNR_PREF_MESSAGE));
                        lnr_accts = g_list_append(lnr_accts, acct);
                    }
                }
            }

            if(g_list_length(lnr_accts))
            {
                lnr_reactivate_status = purple_savedstatus_get_current();
                purple_savedstatus_activate(saved_status);
            }
            else
            {
                lnr_reactivate_status = NULL;
                g_list_free(lnr_accts);
                lnr_accts = NULL;
            }

            g_list_free(accts);
            accts = NULL;

            break;
            
        case WTS_SESSION_UNLOCK:
        case WTS_REMOTE_CONNECT:

            if(lnr_accts != NULL)
            {
                if (lnr_reactivate_status != NULL)
                {
                    purple_savedstatus_activate(lnr_reactivate_status);
                }
                else
                {
                    saved_status = purple_savedstatus_new(NULL, PURPLE_STATUS_AVAILABLE);
                    purple_savedstatus_set_message(saved_status, "");

                    for(iter = lnr_accts; iter != NULL; iter = iter->next)
                    {
                        acct = (PurpleAccount*)iter->data;
                        // Set the status up with a generic "Available" message for each account
                        status_type = purple_account_get_status_type_with_primitive(acct, PURPLE_STATUS_AVAILABLE);
                        if(status_type != NULL)
                        {
                            purple_savedstatus_set_substatus(saved_status, acct, status_type, "");
                        }
                    }

                    purple_savedstatus_activate(saved_status);
                }

                lnr_reactivate_status = NULL;
                g_list_free(lnr_accts);
                lnr_accts = NULL;
            }
            break;
        }
        break;
    }

    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}