[recipes] Chef cleanup
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Chef cleanup
- Date: Thu, 15 Dec 2016 02:24:13 +0000 (UTC)
commit 678625f67d3e4b5b45d0b3917402eff2f8752864
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Dec 14 18:04:49 2016 -0500
Chef cleanup
Make GrChef a final class. No need to derive this.
And rename properties name -> id and nickname -> name.
Finally, stop showing the id in the importer dialogs as
well. It is purely an internal thing.
src/chef-conflict-dialog.ui | 7 +--
src/gr-chef-tile.c | 2 +-
src/gr-chef.c | 99 +++++++++++++++++++-----------------------
src/gr-chef.h | 9 +---
src/gr-details-page.c | 2 +-
src/gr-edit-page.c | 2 +-
src/gr-list-page.c | 12 +++---
src/gr-preferences.c | 24 +++++-----
src/gr-recipe-exporter.c | 3 +-
src/gr-recipe-importer.c | 101 ++++++++++++++++++++++++++++---------------
src/gr-recipe-store.c | 41 +++++++++--------
src/gr-recipe-tile.c | 2 +-
12 files changed, 160 insertions(+), 144 deletions(-)
---
diff --git a/src/chef-conflict-dialog.ui b/src/chef-conflict-dialog.ui
index 01d705c..4623aa7 100644
--- a/src/chef-conflict-dialog.ui
+++ b/src/chef-conflict-dialog.ui
@@ -7,14 +7,13 @@
<child type="action">
<object class="GtkButton" id="button_same">
<property name="visible">1</property>
- <property name="label" translatable="yes">Merge</property>
+ <property name="label" translatable="yes">Same Chef</property>
</object>
</child>
<child type="action">
<object class="GtkButton" id="button_rename">
<property name="visible">1</property>
- <property name="sensitive">0</property>
- <property name="label" translatable="yes">Rename</property>
+ <property name="label" translatable="yes">Different Chef</property>
</object>
</child>
<child internal-child="vbox">
@@ -212,7 +211,6 @@
<child>
<object class="GtkEntry" id="new_chef_fullname">
<property name="visible">1</property>
- <property name="editable">0</property>
</object>
<packing>
<property name="left-attach">3</property>
@@ -227,7 +225,6 @@
<child>
<object class="GtkTextView" id="new_chef_description">
<property name="visible">1</property>
- <property name="editable">0</property>
</object>
</child>
</object>
diff --git a/src/gr-chef-tile.c b/src/gr-chef-tile.c
index 72ec718..3473e9c 100644
--- a/src/gr-chef-tile.c
+++ b/src/gr-chef-tile.c
@@ -84,7 +84,7 @@ chef_tile_set_chef (GrChefTile *tile,
g_set_object (&tile->chef, chef);
- name = gr_chef_get_nickname (chef);
+ name = gr_chef_get_name (chef);
image_path = gr_chef_get_image (chef);
gtk_label_set_label (GTK_LABEL (tile->label), name);
diff --git a/src/gr-chef.c b/src/gr-chef.c
index a431b06..fecdd66 100644
--- a/src/gr-chef.c
+++ b/src/gr-chef.c
@@ -28,21 +28,23 @@
#include "types.h"
-typedef struct
+struct _GrChef
{
+ GObject parent_instance;
+
+ char *id;
char *name;
- char *nickname;
char *fullname;
char *description;
char *image_path;
-} GrChefPrivate;
+};
-G_DEFINE_TYPE_WITH_PRIVATE (GrChef, gr_chef, G_TYPE_OBJECT)
+G_DEFINE_TYPE (GrChef, gr_chef, G_TYPE_OBJECT)
enum {
PROP_0,
+ PROP_ID,
PROP_NAME,
- PROP_NICKNAME,
PROP_FULLNAME,
PROP_DESCRIPTION,
PROP_IMAGE_PATH,
@@ -53,13 +55,12 @@ static void
gr_chef_finalize (GObject *object)
{
GrChef *self = GR_CHEF (object);
- GrChefPrivate *priv = gr_chef_get_instance_private (self);
- g_free (priv->name);
- g_free (priv->nickname);
- g_free (priv->fullname);
- g_free (priv->description);
- g_free (priv->image_path);
+ g_free (self->id);
+ g_free (self->name);
+ g_free (self->fullname);
+ g_free (self->description);
+ g_free (self->image_path);
G_OBJECT_CLASS (gr_chef_parent_class)->finalize (object);
}
@@ -71,27 +72,26 @@ gr_chef_get_property (GObject *object,
GParamSpec *pspec)
{
GrChef *self = GR_CHEF (object);
- GrChefPrivate *priv = gr_chef_get_instance_private (self);
switch (prop_id) {
- case PROP_NAME:
- g_value_set_string (value, priv->name);
+ case PROP_ID:
+ g_value_set_string (value, self->id);
break;
- case PROP_NICKNAME:
- g_value_set_string (value, priv->nickname);
+ case PROP_NAME:
+ g_value_set_string (value, self->name);
break;
case PROP_FULLNAME:
- g_value_set_string (value, priv->fullname);
+ g_value_set_string (value, self->fullname);
break;
case PROP_DESCRIPTION:
- g_value_set_string (value, priv->description);
+ g_value_set_string (value, self->description);
break;
case PROP_IMAGE_PATH:
- g_value_set_string (value, priv->image_path);
+ g_value_set_string (value, self->image_path);
break;
default:
@@ -106,31 +106,30 @@ gr_chef_set_property (GObject *object,
GParamSpec *pspec)
{
GrChef *self = GR_CHEF (object);
- GrChefPrivate *priv = gr_chef_get_instance_private (self);
switch (prop_id) {
- case PROP_NAME:
- g_free (priv->name);
- priv->name = g_value_dup_string (value);
+ case PROP_ID:
+ g_free (self->id);
+ self->id = g_value_dup_string (value);
break;
- case PROP_NICKNAME:
- g_free (priv->nickname);
- priv->nickname = g_value_dup_string (value);
+ case PROP_NAME:
+ g_free (self->name);
+ self->name = g_value_dup_string (value);
break;
case PROP_FULLNAME:
- g_free (priv->fullname);
- priv->fullname = g_value_dup_string (value);
+ g_free (self->fullname);
+ self->fullname = g_value_dup_string (value);
break;
case PROP_DESCRIPTION:
- g_free (priv->description);
- priv->description = g_value_dup_string (value);
+ g_free (self->description);
+ self->description = g_value_dup_string (value);
break;
case PROP_IMAGE_PATH:
- priv->image_path = g_value_dup_string (value);
+ self->image_path = g_value_dup_string (value);
break;
default:
@@ -148,15 +147,15 @@ gr_chef_class_init (GrChefClass *klass)
object_class->get_property = gr_chef_get_property;
object_class->set_property = gr_chef_set_property;
- pspec = g_param_spec_string ("name", NULL, NULL,
+ pspec = g_param_spec_string ("id", NULL, NULL,
NULL,
G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_NAME, pspec);
+ g_object_class_install_property (object_class, PROP_ID, pspec);
- pspec = g_param_spec_string ("nickname", NULL, NULL,
+ pspec = g_param_spec_string ("name", NULL, NULL,
NULL,
G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_NICKNAME, pspec);
+ g_object_class_install_property (object_class, PROP_NAME, pspec);
pspec = g_param_spec_string ("fullname", NULL, NULL,
NULL,
@@ -186,47 +185,37 @@ gr_chef_new (void)
}
const char *
-gr_chef_get_name (GrChef *chef)
+gr_chef_get_id (GrChef *chef)
{
- GrChefPrivate *priv = gr_chef_get_instance_private (chef);
-
- return priv->name;
+ return chef->id;
}
const char *
-gr_chef_get_nickname (GrChef *chef)
+gr_chef_get_name (GrChef *chef)
{
- GrChefPrivate *priv = gr_chef_get_instance_private (chef);
-
- if (!priv->nickname) {
+ if (!chef->name) {
g_auto(GStrv) strv = NULL;
- strv = g_strsplit (priv->fullname, " ", 0);
- priv->nickname = g_strdup (strv[0]);
+ strv = g_strsplit (chef->fullname, " ", 0);
+ chef->name = g_strdup (strv[0]);
}
- return priv->nickname;
+ return chef->name;
}
const char *
gr_chef_get_fullname (GrChef *chef)
{
- GrChefPrivate *priv = gr_chef_get_instance_private (chef);
-
- return priv->fullname;
+ return chef->fullname;
}
const char *
gr_chef_get_description (GrChef *chef)
{
- GrChefPrivate *priv = gr_chef_get_instance_private (chef);
-
- return priv->description;
+ return chef->description;
}
const char *
gr_chef_get_image (GrChef *chef)
{
- GrChefPrivate *priv = gr_chef_get_instance_private (chef);
-
- return priv->image_path;
+ return chef->image_path;
}
diff --git a/src/gr-chef.h b/src/gr-chef.h
index d6b4fd6..b253db5 100644
--- a/src/gr-chef.h
+++ b/src/gr-chef.h
@@ -26,16 +26,11 @@ G_BEGIN_DECLS
#define GR_TYPE_CHEF (gr_chef_get_type())
-G_DECLARE_DERIVABLE_TYPE (GrChef, gr_chef, GR, CHEF, GObject)
-
-struct _GrChefClass
-{
- GObjectClass parent;
-};
+G_DECLARE_FINAL_TYPE (GrChef, gr_chef, GR, CHEF, GObject)
GrChef *gr_chef_new (void);
+const char *gr_chef_get_id (GrChef *chef);
const char *gr_chef_get_name (GrChef *chef);
-const char *gr_chef_get_nickname (GrChef *chef);
const char *gr_chef_get_fullname (GrChef *chef);
const char *gr_chef_get_description (GrChef *chef);
const char *gr_chef_get_image (GrChef *chef);
diff --git a/src/gr-details-page.c b/src/gr-details-page.c
index 66179e6..b4b009a 100644
--- a/src/gr-details-page.c
+++ b/src/gr-details-page.c
@@ -731,7 +731,7 @@ gr_details_page_set_recipe (GrDetailsPage *page,
g_autofree char *tmp = NULL;
g_autofree char *link = NULL;
- link = g_strdup_printf ("<a href=\"chef\">%s</a>", gr_chef_get_nickname (chef));
+ link = g_strdup_printf ("<a href=\"chef\">%s</a>", gr_chef_get_name (chef));
tmp = g_strdup_printf (_("Recipe by %s"), link);
gtk_widget_show (page->chef_label);
gtk_label_set_markup (GTK_LABEL (page->chef_label), tmp);
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index 7e61616..03ff583 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -477,7 +477,7 @@ account_response (GDBusConnection *connection,
g_variant_lookup (options, "name", "&s", &name);
g_variant_lookup (options, "image", "&s", &uri);
- g_object_set (chef, "name", id, "fullname", name, NULL);
+ g_object_set (chef, "id", id, "fullname", name, NULL);
if (uri && uri[0]) {
g_autoptr(GFile) source = NULL;
diff --git a/src/gr-list-page.c b/src/gr-list-page.c
index 6f9b2da..9f7c8bc 100644
--- a/src/gr-list-page.c
+++ b/src/gr-list-page.c
@@ -204,7 +204,7 @@ gr_list_page_populate_from_chef (GrListPage *self,
GrChef *chef)
{
GrRecipeStore *store;
- const char *name;
+ const char *id;
g_autofree char **keys = NULL;
guint length;
int i;
@@ -252,24 +252,24 @@ gr_list_page_populate_from_chef (GrListPage *self,
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- tmp = g_strdup_printf (_("Recipes by %s"), gr_chef_get_nickname (chef));
+ tmp = g_strdup_printf (_("Recipes by %s"), gr_chef_get_name (chef));
gtk_label_set_label (GTK_LABEL (self->heading), tmp);
g_free (tmp);
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
container_remove_all (GTK_CONTAINER (self->flow_box));
- tmp = g_strdup_printf (_("No recipes by chef %s found"), gr_chef_get_nickname (chef));
+ tmp = g_strdup_printf (_("No recipes by chef %s found"), gr_chef_get_name (chef));
gtk_label_set_label (GTK_LABEL (self->empty_title), tmp);
g_free (tmp);
- if (g_strcmp0 (gr_chef_get_name (chef), gr_recipe_store_get_user_key (store)) == 0)
+ if (g_strcmp0 (gr_chef_get_id (chef), gr_recipe_store_get_user_key (store)) == 0)
gtk_label_set_label (GTK_LABEL (self->empty_subtitle), _("You could add one using the “New
Recipe” button."));
else
gtk_label_set_label (GTK_LABEL (self->empty_subtitle), _("Sorry about this."));
gtk_stack_set_visible_child_name (GTK_STACK (self->list_stack), "empty");
filled = FALSE;
- name = gr_chef_get_name (chef);
+ id = gr_chef_get_id (chef);
keys = gr_recipe_store_get_recipe_keys (store, &length);
for (i = 0; i < length; i++) {
@@ -280,7 +280,7 @@ gr_list_page_populate_from_chef (GrListPage *self,
recipe = gr_recipe_store_get (store, keys[i]);
author = gr_recipe_get_author (recipe);
- if (g_strcmp0 (name, author) != 0)
+ if (g_strcmp0 (id, author) != 0)
continue;
tile = gr_recipe_tile_new (recipe);
diff --git a/src/gr-preferences.c b/src/gr-preferences.c
index a30d385..149ab7e 100644
--- a/src/gr-preferences.c
+++ b/src/gr-preferences.c
@@ -121,8 +121,8 @@ save_preferences (GrPreferences *self,
{
g_autoptr(GrChef) chef = NULL;
GrRecipeStore *store;
+ const char *id;
const char *name;
- const char *nickname;
const char *fullname;
g_autofree char *description = NULL;
GtkTextBuffer *buffer;
@@ -130,18 +130,18 @@ save_preferences (GrPreferences *self,
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
- name = gr_recipe_store_get_user_key (store);
+ id = gr_recipe_store_get_user_key (store);
- nickname = gtk_entry_get_text (GTK_ENTRY (self->name));
+ name = gtk_entry_get_text (GTK_ENTRY (self->name));
fullname = gtk_entry_get_text (GTK_ENTRY (self->fullname));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->description));
gtk_text_buffer_get_bounds (buffer, &start, &end);
description = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
chef = g_object_new (GR_TYPE_CHEF,
- "name", name,
+ "id", id,
"fullname", fullname,
- "nickname", nickname,
+ "name", name,
"description", description,
"image-path", self->image_path,
NULL);
@@ -168,30 +168,30 @@ gr_preferences_init (GrPreferences *self)
{
GrRecipeStore *store;
g_autoptr(GrChef) chef = NULL;
- const char *name;
+ const char *id;
gtk_widget_init_template (GTK_WIDGET (self));
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
- name = gr_recipe_store_get_user_key (store);
+ id = gr_recipe_store_get_user_key (store);
- if (name != NULL && name[0] != '\0')
- chef = gr_recipe_store_get_chef (store, name);
+ if (id != NULL && id[0] != '\0')
+ chef = gr_recipe_store_get_chef (store, id);
if (chef) {
const char *fullname;
- const char *nickname;
+ const char *name;
const char *description;
const char *image_path;
fullname = gr_chef_get_fullname (chef);
- nickname = gr_chef_get_nickname (chef);
+ name = gr_chef_get_name (chef);
description = gr_chef_get_description (chef);
image_path = gr_chef_get_image (chef);
gtk_entry_set_text (GTK_ENTRY (self->fullname), fullname ? fullname : "");
- gtk_entry_set_text (GTK_ENTRY (self->name), nickname ? nickname : "");
+ gtk_entry_set_text (GTK_ENTRY (self->name), name ? name : "");
gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->description)),
description ? description : "", -1);
diff --git a/src/gr-recipe-exporter.c b/src/gr-recipe-exporter.c
index aa6b2a3..f584ced 100644
--- a/src/gr-recipe-exporter.c
+++ b/src/gr-recipe-exporter.c
@@ -287,7 +287,8 @@ prepare_export (GrRecipeExporter *exporter,
path = g_build_filename (exporter->dir, "chefs.db", NULL);
keyfile = g_key_file_new ();
- key = name = gr_chef_get_name (chef);
+ key = gr_chef_get_id (chef);
+ name = gr_chef_get_name (chef);
fullname = gr_chef_get_fullname (chef);
description = gr_chef_get_description (chef);
image_path = gr_chef_get_image (chef);
diff --git a/src/gr-recipe-importer.c b/src/gr-recipe-importer.c
index 5530703..a14baa4 100644
--- a/src/gr-recipe-importer.c
+++ b/src/gr-recipe-importer.c
@@ -44,6 +44,7 @@ struct _GrRecipeImporter
GFile *output;
char *dir;
+ char *chef_id;
char *chef_name;
char *chef_fullname;
char *chef_description;
@@ -66,6 +67,10 @@ struct _GrRecipeImporter
GrDiets recipe_diets;
GDateTime *recipe_ctime;
GDateTime *recipe_mtime;
+
+ GtkWidget *new_chef_name;
+ GtkWidget *new_chef_fullname;
+ GtkWidget *new_chef_description;
};
G_DEFINE_TYPE (GrRecipeImporter, gr_recipe_importer, G_TYPE_OBJECT)
@@ -78,6 +83,7 @@ gr_recipe_importer_finalize (GObject *object)
g_clear_object (&importer->extractor);
g_clear_object (&importer->output);
g_free (importer->dir);
+ g_free (importer->chef_id);
g_free (importer->chef_name);
g_free (importer->chef_fullname);
g_free (importer->chef_description);
@@ -148,6 +154,7 @@ cleanup_import (GrRecipeImporter *importer)
g_clear_pointer (&importer->dir, g_free);
g_clear_object (&importer->extractor);
g_clear_object (&importer->output);
+ g_clear_pointer (&importer->chef_id, g_free);
g_clear_pointer (&importer->chef_name, g_free);
g_clear_pointer (&importer->chef_fullname, g_free);
g_clear_pointer (&importer->chef_description, g_free);
@@ -256,7 +263,7 @@ do_import_recipe (GrRecipeImporter *importer)
recipe = gr_recipe_new ();
g_object_set (recipe,
"name", importer->recipe_name,
- "author", importer->chef_name,
+ "author", importer->chef_id,
"description", importer->recipe_description,
"cuisine", importer->recipe_cuisine,
"season", importer->recipe_season,
@@ -474,6 +481,7 @@ import_chef (GrRecipeImporter *importer)
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
chef = g_object_new (GR_TYPE_CHEF,
+ "id", importer->chef_id,
"name", importer->chef_name,
"fullname", importer->chef_fullname,
"description", importer->chef_description,
@@ -488,19 +496,60 @@ import_chef (GrRecipeImporter *importer)
import_recipe (importer);
}
+static char *
+find_unused_chef_id (const char *base)
+{
+ GrRecipeStore *store;
+ int i;
+
+ store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
+ for (i = 0; i < 100; i++) {
+ g_autofree char *new_id = NULL;
+ g_autoptr(GrChef) chef = NULL;
+
+ new_id = g_strdup_printf ("%s%d", base, i);
+ chef = gr_recipe_store_get_chef (store, new_id);
+ if (!chef)
+ return g_strdup (new_id);
+ }
+
+ return NULL;
+}
+
+static char *
+get_text_view_text (GtkTextView *textview)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter start, end;
+
+ buffer = gtk_text_view_get_buffer (textview);
+ gtk_text_buffer_get_bounds (buffer, &start, &end);
+ return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+}
+
static void
chef_dialog_response (GtkWidget *dialog,
int response_id,
GrRecipeImporter *importer)
{
if (response_id == GTK_RESPONSE_CANCEL) {
- g_message ("Chef %s known after all; not importing", importer->chef_name);
+ g_message ("Chef %s known after all; not importing", importer->chef_id);
import_recipe (importer);
}
else {
+ char *id = find_unused_chef_id (importer->chef_id);
+
+ g_free (importer->chef_id);
g_free (importer->chef_name);
- importer->chef_name = g_strdup (g_object_get_data (G_OBJECT (dialog), "name"));
- g_message ("Renaming chef to %s while importing", importer->chef_name);
+ g_free (importer->chef_fullname);
+ g_free (importer->chef_description);
+
+ importer->chef_id = id;
+ importer->chef_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (importer->new_chef_name)));
+ importer->chef_fullname = g_strdup (gtk_entry_get_text (GTK_ENTRY
(importer->new_chef_fullname)));
+ importer->chef_description = get_text_view_text (GTK_TEXT_VIEW
(importer->new_chef_description));
+
+ g_message ("Renaming chef to %s while importing", importer->chef_id);
import_chef (importer);
}
@@ -508,27 +557,6 @@ chef_dialog_response (GtkWidget *dialog,
}
static void
-chef_name_changed (GtkEntry *entry,
- GrRecipeImporter *importer)
-{
- GrRecipeStore *store;
- const char *name;
- GtkWidget *dialog;
- g_autoptr(GrChef) chef = NULL;
-
- store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
-
- name = gtk_entry_get_text (entry);
- chef = gr_recipe_store_get_chef (store, name);
-
- dialog = gtk_widget_get_ancestor (GTK_WIDGET (entry), GTK_TYPE_DIALOG);
- g_object_set_data_full (G_OBJECT (dialog), "name", g_strdup (name), g_free);
- gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
- GTK_RESPONSE_APPLY,
- name[0] != 0 && chef == NULL);
-}
-
-static void
show_chef_conflict_dialog (GrRecipeImporter *importer,
GrChef *chef)
{
@@ -578,7 +606,10 @@ show_chef_conflict_dialog (GrRecipeImporter *importer,
gtk_image_set_from_pixbuf (GTK_IMAGE (new_chef_picture), pixbuf);
}
- g_signal_connect (new_chef_name, "changed", G_CALLBACK (chef_name_changed), importer);
+ importer->new_chef_name = new_chef_name;
+ importer->new_chef_fullname = new_chef_fullname;
+ importer->new_chef_description = new_chef_description;
+
g_signal_connect (dialog, "response", G_CALLBACK (chef_dialog_response), importer);
gtk_widget_show (dialog);
}
@@ -589,6 +620,7 @@ finish_import (GrRecipeImporter *importer)
g_autoptr(GKeyFile) keyfile = NULL;
g_autofree char *path = NULL;
g_auto(GStrv) groups = NULL;
+ const char *id;
g_autofree char *name = NULL;
g_autofree char *fullname = NULL;
g_autofree char *description = NULL;
@@ -607,42 +639,41 @@ finish_import (GrRecipeImporter *importer)
return;
}
- importer->chef_name = g_strdup ("anonymous");
+ importer->chef_id = g_strdup ("anonymous");
import_recipe (importer);
return;
}
groups = g_key_file_get_groups (keyfile, NULL);
if (!groups || !groups[0]) {
- g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED, _("No recipe found"));
+ g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED, _("No chef found"));
error_cb (importer->extractor, error, importer);
return;
}
+ id = groups[0];
name = g_key_file_get_string (keyfile, groups[0], "Name", &error);
- if (error) {
- error_cb (importer->extractor, error, importer);
- return;
- }
fullname = key_file_get_string (keyfile, groups[0], "Fullname");
description = key_file_get_string (keyfile, groups[0], "Description");
image_path = key_file_get_string (keyfile, groups[0], "Image");
+ importer->chef_id = g_strdup (id);
importer->chef_name = g_strdup (name);
importer->chef_fullname = g_strdup (fullname);
importer->chef_description = g_strdup (description);
importer->chef_image_path = g_strdup (image_path);
- chef = gr_recipe_store_get_chef (store, name);
+ chef = gr_recipe_store_get_chef (store, id);
if (!chef) {
- g_message ("Chef %s not yet known; importing", name);
+ g_message ("Chef %s not yet known; importing", id);
import_chef (importer);
return;
}
if (g_strcmp0 (fullname, gr_chef_get_fullname (chef)) == 0 &&
+ g_strcmp0 (name, gr_chef_get_name (chef)) == 0 &&
g_strcmp0 (description, gr_chef_get_description (chef)) == 0) {
- g_message ("Chef %s already known, not importing", name);
+ g_message ("Chef %s already known, not importing", id);
import_recipe (importer);
return;
}
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index 14aa563..f4535e4 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -707,6 +707,7 @@ load_chefs (GrRecipeStore *self,
groups = g_key_file_get_groups (keyfile, &length);
for (i = 0; i < length; i++) {
GrChef *chef;
+ const char *id;
g_autofree char *name = NULL;
g_autofree char *fullname = NULL;
g_autofree char *description = NULL;
@@ -714,6 +715,7 @@ load_chefs (GrRecipeStore *self,
g_clear_error (&error);
+ id = groups[i];
name = g_key_file_get_string (keyfile, groups[i], "Name", &error);
if (error) {
g_warning ("Failed to load chef %s: %s", groups[i], error->message);
@@ -752,13 +754,14 @@ load_chefs (GrRecipeStore *self,
image_path = tmp;
}
- chef = g_hash_table_lookup (self->chefs, name);
+ chef = g_hash_table_lookup (self->chefs, id);
if (chef == NULL) {
chef = gr_chef_new ();
- g_hash_table_insert (self->chefs, g_strdup (name), chef);
+ g_hash_table_insert (self->chefs, g_strdup (id), chef);
}
g_object_set (chef,
+ "id", id,
"name", name,
"fullname", fullname,
"description", description,
@@ -1124,23 +1127,23 @@ gr_recipe_store_add_chef (GrRecipeStore *self,
GrChef *chef,
GError **error)
{
- const char *name;
+ const char *id;
- name = gr_chef_get_name (chef);
+ id = gr_chef_get_id (chef);
- if (name == NULL || name[0] == '\0') {
+ if (id == NULL || id[0] == '\0') {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- _("You need to provide a name"));
+ _("You need to provide an ID"));
return FALSE;
}
- if (g_hash_table_contains (self->chefs, name)) {
+ if (g_hash_table_contains (self->chefs, id)) {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- _("Sorry, this name is taken"));
+ _("Sorry, this ID is taken"));
return FALSE;
}
- g_hash_table_insert (self->chefs, g_strdup (name), g_object_ref (chef));
+ g_hash_table_insert (self->chefs, g_strdup (id), g_object_ref (chef));
g_signal_emit (self, chefs_changed_signal, 0);
save_chefs (self);
@@ -1153,15 +1156,15 @@ gr_recipe_store_update_user (GrRecipeStore *self,
GrChef *chef,
GError **error)
{
- const char *name;
+ const char *id;
gboolean ret = TRUE;
- name = gr_chef_get_name (chef);
+ id = gr_chef_get_id (chef);
- if (name != NULL && name[0] != '\0') {
+ if (id != NULL && id[0] != '\0') {
g_object_ref (chef);
- if (g_strcmp0 (name, self->user) == 0) {
- g_hash_table_remove (self->chefs, name);
+ if (g_strcmp0 (id, self->user) == 0) {
+ g_hash_table_remove (self->chefs, id);
}
ret = gr_recipe_store_add_chef (self, chef, error);
g_object_unref (chef);
@@ -1169,7 +1172,7 @@ gr_recipe_store_update_user (GrRecipeStore *self,
if (ret) {
g_free (self->user);
- self->user = g_strdup (name);
+ self->user = g_strdup (id);
save_user (self);
}
@@ -1180,14 +1183,14 @@ gboolean
gr_recipe_store_chef_is_featured (GrRecipeStore *self,
GrChef *chef)
{
- const char *name;
+ const char *id;
if (self->featured_chefs == NULL)
return FALSE;
- name = gr_chef_get_name (chef);
+ id = gr_chef_get_id (chef);
- return g_strv_contains ((const char *const*)self->featured_chefs, name);
+ return g_strv_contains ((const char *const*)self->featured_chefs, id);
}
char **
@@ -1319,7 +1322,7 @@ gr_recipe_store_has_chef (GrRecipeStore *self,
g_hash_table_iter_init (&iter, self->recipes);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&recipe)) {
- if (strcmp (gr_chef_get_name (chef), gr_recipe_get_author (recipe)) == 0)
+ if (strcmp (gr_chef_get_id (chef), gr_recipe_get_author (recipe)) == 0)
return TRUE;
}
diff --git a/src/gr-recipe-tile.c b/src/gr-recipe-tile.c
index c64537e..a91cd79 100644
--- a/src/gr-recipe-tile.c
+++ b/src/gr-recipe-tile.c
@@ -112,7 +112,7 @@ recipe_tile_set_recipe (GrRecipeTile *tile,
}
gtk_label_set_label (GTK_LABEL (tile->label), name);
- tmp = g_strdup_printf (_("by %s"), chef ? gr_chef_get_nickname (chef) : _("Anonymous"));
+ tmp = g_strdup_printf (_("by %s"), chef ? gr_chef_get_name (chef) : _("Anonymous"));
gtk_label_set_label (GTK_LABEL (tile->author), tmp);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]