static void
selection_changed (GtkTreeSelection * selection, ESource * source)
{
    GtkTreeModel *model;
    GtkTreeIter iter;
    GValue value = { 0, };
    const char *path;

    if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
        char *nruri;
        const char *name;

        gtk_tree_model_get_value (model, &iter, SCM_COL_PATH, &value);

        path = g_value_get_string (&value);
        name = e_source_peek_name (source);

        if (name == NULL || name[0] == '\0') {
            name = "nonameyet";
        }

        if (path == NULL) {
            nruri = g_strdup (name);
        } else {
            nruri = g_build_path ("/", path, name, NULL);
        }

        e_source_set_relative_uri (source, nruri);
        g_free (nruri);

        g_value_unset (&value);
    } else {
        g_warning ("NARF");
    }
}
Beispiel #2
0
GtkWidget *
e_book_file_dummy (EPlugin *epl,
                   EConfigHookItemFactoryData *data)
{
	EABConfigTargetSource *t = (EABConfigTargetSource *) data->target;
	ESource *source = t->source;
	gchar *uri_text;
	const gchar *relative_uri;

	uri_text = e_source_get_uri (source);
	if (strncmp (uri_text, "file", 4)) {
		g_free (uri_text);

		return NULL;
	}

	relative_uri = e_source_peek_relative_uri (source);
	g_free (uri_text);

	if (relative_uri && *relative_uri) {
		return NULL;
	}

	e_source_set_relative_uri (source, e_source_peek_uid (source));

	return NULL;
}
static void
sn_changed (ESource * source, gpointer data)
{
    const char *name;
    const char *ruri;

    //char       **old_name;
    char **sv;
    char *nruri;
    guint n;
    gulong *sig_id;

    sig_id = (gulong *) data;
    name = e_source_peek_name (source);
    ruri = e_source_peek_relative_uri (source);

    /* Must block signal emission or this will give
     * a nice infinit chain and stack overflow */
    g_signal_handler_block (source, *sig_id);

    if (is_toplevel (ruri)) {
        e_source_set_relative_uri (source, name);
    } else {
        sv = g_strsplit (ruri, "/", -1);
        n = g_strv_length (sv);

        if (n < 2) {
            g_print ("Error during split! (%s)\n", ruri);
            g_strfreev (sv);
            return;
        }

        g_free (sv[n - 1]);
        sv[n - 1] = g_strdup (name);

        nruri = g_strjoinv ("/", sv);
        e_source_set_relative_uri (source, nruri);
        g_free (nruri);
        g_strfreev (sv);
    }

    g_signal_handler_unblock (source, *sig_id);

    g_print ("RURI: %s\n", e_source_peek_relative_uri (source));
}
static void
location_clicked (GtkButton * button, ESource * source)
{
    GtkDialog *dialog;
    char *ruri_save;
    const char *ruri;
    int resp;

    dialog = create_store_view_dialog (source);

    if (dialog == NULL)
        return;

    ruri_save = (char *) e_source_peek_relative_uri (source);

    if (ruri_save != NULL) {
        ruri_save = g_strdup (ruri_save);
    }

    resp = gtk_dialog_run (dialog);

    if (resp == GTK_RESPONSE_OK) {
        char *nruri = NULL;

        ruri = e_source_peek_relative_uri (source);

        if (is_toplevel (ruri)) {
            ruri = _("Toplevel");
        } else {
            char *match;

            match = g_strrstr (ruri, "/");
            nruri = g_strndup (ruri, match - ruri);
            ruri = nruri;
        }

        gtk_button_set_label (button, ruri);

        g_free (nruri);

    } else {
        e_source_set_relative_uri (source, ruri_save);
    }

    g_free (ruri_save);
    gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
on_username_entry_changed (GtkEntry *entry,
                           gpointer user_data)
{
	ESource *source = user_data;
	const gchar *text;
	gchar *username;

	text = gtk_entry_get_text (entry);

	if (!text || !*text) {
		username = NULL;
	} else if (strstr (text, "@")) {
		username = g_strdup (text);
	} else {
		username = g_strdup_printf ("*****@*****.**", text);
	}

	e_source_set_relative_uri (source, username);
	e_source_set_property (source, "username", username);
	e_source_set_property (source, "auth", "plain/password");
	g_free (username);
}
Beispiel #6
0
static gint
on_idle_do_stuff (gpointer unused_data)
{
	GConfClient *client = gconf_client_get_default ();
	ESourceGroup *new_group = NULL;
	ESource *new_source = NULL;

	list = e_source_list_new_for_gconf (client, key_arg);
	g_object_unref (client);

	if (add_group_arg != NULL) {
		if (group_arg != NULL) {
			fprintf (stderr, "--add-group and --group cannot be used at the same time.\n");
			exit (1);
		}
		if (set_base_uri_arg == NULL) {
			fprintf (stderr, "When using --add-group, you need to specify a base URI using --set-base-uri.\n");
			exit (1);
		}

		new_group = e_source_group_new (add_group_arg, set_base_uri_arg);
		e_source_list_add_group (list, new_group, -1);
		g_object_unref (new_group);

		e_source_list_sync (list, NULL);
	}

	if (remove_group_arg != NULL) {
		ESourceGroup *group;

		group = e_source_list_peek_group_by_uid (list, remove_group_arg);
		if (group == NULL) {
			fprintf (stderr, "No such group \"%s\".\n", remove_group_arg);
			exit (1);
		}

		e_source_list_remove_group (list, group);
		e_source_list_sync (list, NULL);
	}

	if (add_source_arg != NULL) {
		ESourceGroup *group;

		if (group_arg == NULL && new_group == NULL) {
			fprintf (stderr,
				 "When using --add-source, you need to specify a group using either --group\n"
				 "or --add-group.\n");
			exit (1);
		}
		if (set_relative_uri_arg == NULL) {
			fprintf (stderr,
				 "When using --add-source, you need to specify a relative URI using\n"
				 "--set-relative-uri.\n");
			exit (1);
		}

		if (group_arg == NULL) {
			group = new_group;
		} else {
			group = e_source_list_peek_group_by_uid (list, group_arg);
			if (group == NULL) {
				fprintf (stderr, "No such group \"%s\".\n", group_arg == NULL ? add_group_arg : group_arg);
				exit (1);
			}
		}

		new_source = e_source_new (add_source_arg, set_relative_uri_arg);
		e_source_group_add_source (group, new_source, -1);
		e_source_list_sync (list, NULL);
	}

	if (remove_source_arg != NULL) {
		ESource *source;

		source = e_source_list_peek_source_by_uid (list, remove_source_arg);
		if (source == NULL) {
			fprintf (stderr, "No such source \"%s\".\n", remove_source_arg);
			exit (1);
		}

		e_source_list_remove_source_by_uid (list, remove_source_arg);
		e_source_list_sync (list, NULL);
	}

	if (set_name_arg != NULL) {
		if (group_arg == NULL && source_arg == NULL) {
			fprintf (stderr,
				 "When using --set-name, you need to specify a source (using --source"
				 "alone) or a group (using --group alone).\n");
			exit (1);
		}

		if (source_arg != NULL) {
			ESource *source = e_source_list_peek_source_by_uid (list, source_arg);

			if (source != NULL) {
				e_source_set_name (source, set_name_arg);
			} else {
				fprintf (stderr, "No such source \"%s\".\n", source_arg);
				exit (1);
			}
		} else {
			ESourceGroup *group = e_source_list_peek_group_by_uid (list, group_arg);

			if (group != NULL) {
				e_source_group_set_name (group, set_name_arg);
			} else {
				fprintf (stderr, "No such group \"%s\".\n", group_arg);
				exit (1);
			}
		}

		e_source_list_sync (list, NULL);
	}

	if (set_relative_uri_arg != NULL && add_source_arg == NULL) {
		ESource *source;

		if (source_arg == NULL) {
			fprintf (stderr,
				 "When using --set-relative-uri, you need to specify a source using "
				 "--source.\n");
			exit (1);
		}

		source = e_source_list_peek_source_by_uid (list, source_arg);
		e_source_set_relative_uri (source, set_relative_uri_arg);
		e_source_list_sync (list, NULL);
	}

	if (set_color_arg != NULL) {
		ESource *source;

		if (add_source_arg == NULL && source_arg == NULL) {
			fprintf (stderr,
				 "When using --set-color, you need to specify a source using --source\n");
			exit (1);
		}

		if (add_source_arg != NULL)
			source = new_source;
		else
			source = e_source_list_peek_source_by_uid (list, source_arg);

		e_source_set_color_spec (source, set_color_arg);
		e_source_list_sync (list, NULL);
	}

	if (unset_color) {
		ESource *source;

		if (add_source_arg == NULL && source_arg == NULL) {
			fprintf (stderr,
				 "When using --unset-color, you need to specify a source using --source\n");
			exit (1);
		}

		if (add_source_arg != NULL)
			source = new_source;
		else
			source = e_source_list_peek_source_by_uid (list, source_arg);

		e_source_set_color_spec (source, NULL);
		e_source_list_sync (list, NULL);
	}

	if (set_base_uri_arg != NULL && add_group_arg == NULL) {
		ESourceGroup *group;

		if (group_arg == NULL) {
			fprintf (stderr,
				 "When using --set-base-uri, you need to specify a group using --group.\n");
			exit (1);
		}

		group = e_source_list_peek_group_by_uid (list, group_arg);
		e_source_group_set_base_uri (group, set_base_uri_arg);
		e_source_list_sync (list, NULL);
	}

	if (set_value_arg != NULL) {
		ESource *source;

		if (add_source_arg == NULL && source_arg == NULL) {
			fprintf (stderr,
				 "When using --set-value, you need to specify a source using --source\n");
			exit (1);
		}

		if (property_arg == NULL) {
			fprintf (stderr,
				 "When using --set-value, you need to specify a property using --property\n");
			exit (1);
		}

		if (add_source_arg != NULL)
			source = new_source;
		else
			source = e_source_list_peek_source_by_uid (list, source_arg);

		e_source_set_property (source, property_arg, set_value_arg);
		e_source_list_sync (list, NULL);
	}

	if (unset_value) {
		ESource *source;

		if (add_source_arg == NULL && source_arg == NULL) {
			fprintf (stderr,
				 "When using --unset-value, you need to specify a source using --source\n");
			exit (1);
		}

		if (property_arg == NULL) {
			fprintf (stderr,
				 "When using --unset-value, you need to specify a property using --property\n");
			exit (1);
		}

		if (add_source_arg != NULL)
			source = new_source;
		else
			source = e_source_list_peek_source_by_uid (list, source_arg);

		e_source_set_property (source, property_arg, NULL);
		e_source_list_sync (list, NULL);
	}

	connect_list ();

	if (dump)
		dump_list ();

	if (!listen)
		g_main_loop_quit (main_loop);

	return FALSE;
}
static GtkWidget *
sx_config_source_setup_ui (GtkWidget * parent, ESource * source)
{
    GtkWidget *button;
    GtkWidget *label;
    GtkWidget *text;
    GtkWidget *ret;
    char *uri_text;
    const char *uid;
    const char *ruri;
    const char *name;
    gboolean new_source;
    gulong *sig_id;

    uri_text = e_source_get_uri (source);

    if (!g_str_has_prefix (uri_text, "scalix")) {
        g_free (uri_text);
        return NULL;
    }
    g_free (uri_text);

    g_assert (GTK_IS_BOX (parent) || GTK_IS_TABLE (parent));

    /* Label */
    label = gtk_label_new_with_mnemonic (_("_Location:"));
    gtk_widget_show (label);

    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

    button = gtk_button_new ();

    g_signal_connect (G_OBJECT (button),
                      "clicked", G_CALLBACK (location_clicked), source);

    gtk_widget_show (button);

    uid = e_source_peek_uid (source);
    ruri = e_source_peek_relative_uri (source);
    name = e_source_peek_name (source);

    /* new source */
    new_source = (ruri == NULL || ruri[0] == '\0' || g_str_equal (ruri, uid));

    if (new_source) {

        if (name == NULL || name[0] == '\0')
            name = "nonameyet";

        e_source_set_relative_uri (source, name);
    }

    if (is_toplevel (ruri)) {
        text = gtk_label_new (_("Toplevel"));
    } else {
        text = gtk_label_new (ruri);
    }

    gtk_widget_show (text);

#if (GTK_CHECK_VERSION(2, 6, 0))
    gtk_label_set_ellipsize (GTK_LABEL (text), PANGO_ELLIPSIZE_START);
#endif
    gtk_container_add (GTK_CONTAINER (button), text);

    sig_id = (gulong *) g_malloc0 (sizeof (gulong));

    *sig_id = g_signal_connect (source,
                                "changed", G_CALLBACK (sn_changed), sig_id);

    /* We do not support renames (yet?!) */
    if (new_source == FALSE) {

        gtk_widget_set_sensitive (button, FALSE);

        /* Nasty nasty hack ey ey ey */
        find_entries_and_set_sensitive (parent, FALSE);

    }

    /* attach it */
    if (!GTK_IS_BOX (parent)) {
        int row;

        row = GTK_TABLE (parent)->nrows;

        gtk_table_attach (GTK_TABLE (parent),
                          label, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0);

        gtk_table_attach (GTK_TABLE (parent),
                          button, 1, 2,
                          row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);

        /* HACK for to have a return value != NULL */
        ret = button;

    } else {
        GtkWidget *hbox;

        hbox = gtk_hbox_new (FALSE, 6);
        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 6);
        gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 6);
        gtk_box_pack_start (GTK_BOX (parent), hbox, FALSE, FALSE, 6);
        gtk_widget_show_all (hbox);
        ret = hbox;
    }

    return ret;
}