static void
accounts_widget_generic_setup (McAccount *account,
			       GtkWidget *table_common_settings,
			       GtkWidget *table_advanced_settings)
{
	McProtocol *protocol;
	McProfile  *profile;
	GSList     *params, *l;

	profile = mc_account_get_profile (account);
	protocol = mc_profile_get_protocol (profile);

	if (!protocol) {
		/* The CM is not installed, MC shouldn't list them
		 * see SF bug #1688779
		 * FIXME: We should display something asking the user to
		 * install the CM
		 */
		g_object_unref (profile);
		return;
	}

	params = mc_protocol_get_params (protocol);

	for (l = params; l; l = l->next) {
		McProtocolParam *param;
		GtkWidget       *table_settings;
		guint            n_rows = 0;
		GtkWidget       *widget = NULL;
		gchar           *param_name_formatted;

		param = l->data;
		if (param->flags & MC_PROTOCOL_PARAM_REQUIRED) {
			table_settings = table_common_settings;
		} else {
			table_settings = table_advanced_settings;
		}
		param_name_formatted = account_widget_generic_format_param_name (param->name);
		g_object_get (table_settings, "n-rows", &n_rows, NULL);
		gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);

		if (param->signature[0] == 's') {
			gchar *str;

			str = g_strdup_printf (_("%s:"), param_name_formatted);
			widget = gtk_label_new (str);
			gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
			g_free (str);

			gtk_table_attach (GTK_TABLE (table_settings),
					  widget,
					  0, 1,
					  n_rows - 1, n_rows,
					  GTK_FILL, 0,
					  0, 0);
			gtk_widget_show (widget);

			widget = gtk_entry_new ();
			if (strcmp (param->name, "account") == 0) {
				g_signal_connect (widget, "realize",
						  G_CALLBACK (account_widget_default_entry_realized_cb),
						  NULL);
			}
			gtk_table_attach (GTK_TABLE (table_settings),
					  widget,
					  1, 2,
					  n_rows - 1, n_rows,
					  GTK_FILL | GTK_EXPAND, 0,
					  0, 0);
			gtk_widget_show (widget);
		}
		/* int types: ynqiuxt. double type is 'd' */
		else if (param->signature[0] == 'y' ||
			 param->signature[0] == 'n' ||
			 param->signature[0] == 'q' ||
			 param->signature[0] == 'i' ||
			 param->signature[0] == 'u' ||
			 param->signature[0] == 'x' ||
			 param->signature[0] == 't' ||
			 param->signature[0] == 'd') {
			gchar   *str = NULL;
			gdouble  minint = 0;
			gdouble  maxint = 0;
			gdouble  step = 1;

			switch (param->signature[0]) {
			case 'y': minint = G_MININT8;  maxint = G_MAXINT8;   break;
			case 'n': minint = G_MININT16; maxint = G_MAXINT16;  break;
			case 'q': minint = 0;          maxint = G_MAXUINT16; break;
			case 'i': minint = G_MININT32; maxint = G_MAXINT32;  break;
			case 'u': minint = 0;          maxint = G_MAXUINT32; break;
			case 'x': minint = G_MININT64; maxint = G_MAXINT64;  break;
			case 't': minint = 0;          maxint = G_MAXUINT64; break;
			case 'd': minint = G_MININT32; maxint = G_MAXINT32; step = 0.1; break;
			}

			str = g_strdup_printf (_("%s:"), param_name_formatted);
			widget = gtk_label_new (str);
			gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
			g_free (str);

			gtk_table_attach (GTK_TABLE (table_settings),
					  widget,
					  0, 1,
					  n_rows - 1, n_rows,
					  GTK_FILL, 0,
					  0, 0);
			gtk_widget_show (widget);

			widget = gtk_spin_button_new_with_range (minint, maxint, step);
			gtk_table_attach (GTK_TABLE (table_settings),
					  widget,
					  1, 2,
					  n_rows - 1, n_rows,
					  GTK_FILL | GTK_EXPAND, 0,
					  0, 0);
			gtk_widget_show (widget);
		}
		else if (param->signature[0] == 'b') {
			widget = gtk_check_button_new_with_label (param_name_formatted);
			gtk_table_attach (GTK_TABLE (table_settings),
					  widget,
					  0, 2,
					  n_rows - 1, n_rows,
					  GTK_FILL | GTK_EXPAND, 0,
					  0, 0);
			gtk_widget_show (widget);
		} else {
			DEBUG ("Unknown signature for param %s: %s",
				param_name_formatted, param->signature);
		}

		if (widget) {
			account_widget_setup_widget (widget, account, param->name);
		}

		g_free (param_name_formatted);
	}

	g_slist_free (params);
	g_object_unref (profile);
	g_object_unref (protocol);
}
Ejemplo n.º 2
0
static void
create_salut_account (void)
{
	McProfile  *profile;
	McProtocol *protocol;
	gboolean    salut_created = FALSE;
	McAccount  *account;
	GList      *accounts;
	EBook      *book;
	EContact   *contact;
	gchar      *nickname = NULL;
	gchar      *first_name = NULL;
	gchar      *last_name = NULL;
	gchar      *email = NULL;
	gchar      *jid = NULL;
	GError     *error = NULL;

	/* Check if we already created a salut account */
	empathy_conf_get_bool (empathy_conf_get(),
			       EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
			       &salut_created);
	if (salut_created) {
		return;
	}

	DEBUG ("Try to add a salut account...");

	/* Check if the salut CM is installed */
	profile = mc_profile_lookup ("salut");
	if (!profile) {
		DEBUG ("No salut profile");
		return;
	}
	protocol = mc_profile_get_protocol (profile);
	if (!protocol) {
		DEBUG ("Salut not installed");
		g_object_unref (profile);
		return;
	}
	g_object_unref (protocol);

	/* Get self EContact from EDS */
	if (!e_book_get_self (&contact, &book, &error)) {
		DEBUG ("Failed to get self econtact: %s",
			error ? error->message : "No error given");
		g_clear_error (&error);
		g_object_unref (profile);
		return;
	}

	empathy_conf_set_bool (empathy_conf_get (),
			       EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
			       TRUE);

	/* Check if there is already a salut account */
	accounts = mc_accounts_list_by_profile (profile);
	if (accounts) {
		DEBUG ("There is already a salut account");
		mc_accounts_list_free (accounts);
		g_object_unref (profile);
		return;
	}

	account = mc_account_create (profile);
	mc_account_set_display_name (account, _("People nearby"));
	
	nickname = e_contact_get (contact, E_CONTACT_NICKNAME);
	first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
	last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME);
	email = e_contact_get (contact, E_CONTACT_EMAIL_1);
	jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1);
	
	if (!tp_strdiff (nickname, "nickname")) {
		g_free (nickname);
		nickname = NULL;
	}

	DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n"
		"last-name=%s\nemail=%s\njid=%s\n",
		nickname, first_name, last_name, email, jid);

	mc_account_set_param_string (account, "nickname", nickname ? nickname : "");
	mc_account_set_param_string (account, "first-name", first_name ? first_name : "");
	mc_account_set_param_string (account, "last-name", last_name ? last_name : "");
	mc_account_set_param_string (account, "email", email ? email : "");
	mc_account_set_param_string (account, "jid", jid ? jid : "");

	g_free (nickname);
	g_free (first_name);
	g_free (last_name);
	g_free (email);
	g_free (jid);
	g_object_unref (account);
	g_object_unref (profile);
	g_object_unref (contact);
	g_object_unref (book);
}
Ejemplo n.º 3
0
GtkWidget *
empathy_profile_chooser_new (void)
{
	GList           *profiles, *l, *seen;
	GtkListStore    *store;
	GtkCellRenderer *renderer;
	GtkWidget       *combo_box;
	GtkTreeIter      iter;
	gboolean         iter_set = FALSE;
	McManager       *btf_cm;

	/* set up combo box with new store */
	store = gtk_list_store_new (COL_COUNT,
				    G_TYPE_STRING,    /* Icon name */
				    G_TYPE_STRING,    /* Label     */
				    MC_TYPE_PROFILE); /* Profile   */
	combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));


	renderer = gtk_cell_renderer_pixbuf_new ();
	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
					"icon-name", COL_ICON,
					NULL);
	g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL);

	renderer = gtk_cell_renderer_text_new ();
	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
					"text", COL_LABEL,
					NULL);

	btf_cm = mc_manager_lookup ("butterfly");
	profiles = mc_profiles_list ();
	seen = NULL;
	for (l = profiles; l; l = l->next) {
		McProfile   *profile;
		McProtocol  *protocol;
		const gchar *unique_name;

		profile = l->data;

		/* Check if the CM is installed, otherwise skip that profile.
		 * Workaround SF bug #1688779 */
		protocol = mc_profile_get_protocol (profile);
		if (!protocol) {
			continue;
		}
		g_object_unref (protocol);

		/* Skip MSN-Haze if we have butterfly */
		unique_name = mc_profile_get_unique_name (profile);
		if (btf_cm && strcmp (unique_name, "msn-haze") == 0) {
			continue;
		}

		if (g_list_find_custom (seen, unique_name, (GCompareFunc) strcmp)) {
			continue;
		}
		seen = g_list_append (seen, (char*) unique_name);

		gtk_list_store_insert_with_values (store, &iter, 0,
						   COL_ICON, mc_profile_get_icon_name (profile),
						   COL_LABEL, mc_profile_get_display_name (profile),
						   COL_PROFILE, profile,
						   -1);
                iter_set = TRUE;
	}

	g_list_free (seen);

	if (btf_cm) {
		g_object_unref (btf_cm);
	}

	/* Set the profile sort function */
	gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
					 COL_PROFILE,
					 profile_chooser_sort_func,
					 NULL, NULL);
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
					      COL_PROFILE,
					      GTK_SORT_ASCENDING);

        if (iter_set) {
		gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
        }

	mc_profiles_free_list (profiles);
	g_object_unref (store);

	return combo_box;
}