Definately post 0.16 material.

This is how it currently looks:
diff --git a/ufraw.h b/ufraw.h
index 914dfa4..2560c34 100644
--- a/ufraw.h
+++ b/ufraw.h
@@ -21,6 +21,8 @@
 #include <time.h> // for time_t
 #include "dcraw_api.h"
 
+#define ARRAYSIZE(x) ((int)(sizeof (x) / sizeof ((x)[0])))
+
 /* macro to clamp a number between two values */
 #ifndef LIM
 #define LIM(x,min,max) MAX(min,MIN(x,max))
@@ -374,7 +376,7 @@ void ptr_array_insert_index (GPtrArray *array, const void 
*item, int index);
 
 /* prototypes for functions in ufraw_conf.c */
 int conf_load(conf_data *c, const char *confFilename);
-int conf_save(conf_data *c, char *confFilename, char **confBuffer);
+int conf_save(conf_data *c, char *confFilename, char **confBuffer, gboolean 
preset);
 /* copy default config to given instance and initialize non-const fields */
 void conf_init (conf_data *c);
 /* Copy the image manipulation options from *src to *dst */
diff --git a/ufraw_conf.c b/ufraw_conf.c
index 655d883..90665bc 100644
--- a/ufraw_conf.c
+++ b/ufraw_conf.c
@@ -822,7 +822,7 @@ int conf_load(conf_data *c, const char *IDFilename)
     return UFRAW_SUCCESS;
 }
 
-int conf_save(conf_data *c, char *IDFilename, char **confBuffer)
+int conf_save(conf_data *c, char *IDFilename, char **confBuffer, gboolean 
preset)
 {
     char *buf=NULL;
     int i, j;
@@ -831,17 +831,17 @@ int conf_save(conf_data *c, char *IDFilename, char 
**confBuffer)
 
     buf = uf_markup_buf(buf, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
     buf = uf_markup_buf(buf, "<UFRaw Version='%d'>\n", c->version);
-    if (strlen(c->inputFilename)>0 && IDFilename!=NULL) {
+    if (strlen(c->inputFilename)>0 && IDFilename!=NULL && !preset) {
        char *utf8 = g_filename_display_name(c->inputFilename);
        buf = uf_markup_buf(buf, "<InputFilename>%s</InputFilename>\n", utf8);
        g_free(utf8);
     }
-    if (strlen(c->outputFilename)>0 && IDFilename!=NULL) {
+    if (strlen(c->outputFilename)>0 && IDFilename!=NULL && !preset) {
        char *utf8=g_filename_display_name(c->outputFilename);
        buf = uf_markup_buf(buf, "<OutputFilename>%s</OutputFilename>\n", utf8);
        g_free(utf8);
     }
-    if (strlen(c->outputPath)>0) {
+    if (strlen(c->outputPath)>0 && !preset) {
        char *utf8=g_filename_display_name(c->outputPath);
        buf = uf_markup_buf(buf, "<OutputPath>%s</OutputPath>\n", utf8);
        g_free(utf8);
@@ -1147,7 +1147,7 @@ int conf_save(conf_data *c, char *IDFilename, char 
**confBuffer)
      * to know if the WB setting is relevant */
     buf = uf_markup_buf(buf, "<Make>%s</Make>\n", c->make);
     buf = uf_markup_buf(buf, "<Model>%s</Model>\n", c->model);
-    if (IDFilename!=NULL) {
+    if (IDFilename!=NULL && !preset) {
        if (strcmp(c->darkframeFile, conf_default.darkframeFile)!=0)
            buf = uf_markup_buf(buf,
                    "<DarkframeFile>%s</DarkframeFile>\n", c->darkframeFile);
diff --git a/ufraw_preview.c b/ufraw_preview.c
index ddcaf7d..a4f00a1 100644
--- a/ufraw_preview.c
+++ b/ufraw_preview.c
@@ -27,6 +27,7 @@
 #include "uf_gtk.h"
 #include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
+#include <glib/gstdio.h>
 #include "ufraw.h"
 #include "ufraw_ui.h"
 #include "curveeditor_widget.h"
@@ -72,6 +73,14 @@ static const char *grayscaleModeNames[5] = {
     N_("Channel Mixer")
 };
 
+struct preset {
+    char *idfile;
+    char *tooltip_load;
+    char *tooltip_save;
+    GtkWidget *button;
+};
+static struct preset presets[6];
+
 preview_data *get_preview_data(void *object)
 {
     GtkWidget *widget;
@@ -219,7 +228,7 @@ static void load_curve(GtkWidget *widget, long curveType)
            cp = g_path_get_dirname(list->data);
            g_strlcpy(CFG->curvePath, cp, max_path);
            g_strlcpy(RC->curvePath, cp, max_path);
-           conf_save(RC, NULL, NULL);
+           conf_save(RC, NULL, NULL, FALSE);
            g_free(cp);
            g_free(list->data);
        }
@@ -384,7 +393,7 @@ static void load_profile(GtkWidget *widget, long type)
            /* Add profile to .ufrawrc but don't make it default */
            RC->profile[type][RC->profileCount[type]++] = p;
            g_strlcpy(RC->profilePath, cp, max_path);
-           conf_save(RC, NULL, NULL);
+           conf_save(RC, NULL, NULL, FALSE);
            g_free(cp);
            g_free(list->data);
        }
@@ -1482,11 +1491,11 @@ static void update_scales(preview_data *data)
     gtk_widget_set_sensitive(data->ResetWBButton,
            ( strcmp(CFG->wb, data->initialWB)
            ||fabs(CFG->temperature-data->initialTemperature)>1
-           ||fabs(CFG->green-data->initialGreen)>0.001
-           ||CFG->chanMul[0]!=data->initialChanMul[0]
-           ||CFG->chanMul[1]!=data->initialChanMul[1]
-           ||CFG->chanMul[2]!=data->initialChanMul[2]
-           ||CFG->chanMul[3]!=data->initialChanMul[3] ) );
+           ||fabs(CFG->green-data->initialGreen)>0.000001
+           ||fabs(CFG->chanMul[0]-data->initialChanMul[0]) > 0.000001
+           ||fabs(CFG->chanMul[1]-data->initialChanMul[1]) > 0.000001
+           ||fabs(CFG->chanMul[2]-data->initialChanMul[2]) > 0.000001
+           ||fabs(CFG->chanMul[3]-data->initialChanMul[3]) > 0.000001 ) );
     gtk_widget_set_sensitive(data->ResetGammaButton,
            fabs( profile_default_gamma(&CFG->profile[0][CFG->profileIndex[0]])
                - CFG->profile[0][CFG->profileIndex[0]].gamma) > 0.001);
@@ -3318,11 +3327,82 @@ static void delete_from_list(GtkWidget *widget, 
gpointer user_data)
     gtk_dialog_response(dialog, GTK_RESPONSE_APPLY);
 }
 
+static void preset_update_state(GtkWidget *widget, struct preset *p, int state)
+{
+    if (!state) {
+       state = g_file_test(p->idfile, G_FILE_TEST_EXISTS) ? 1 : -1;
+    }
+    if (state > 0) {
+       gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
+       uf_widget_set_tooltip(widget, p->tooltip_load);
+    } else {
+       gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NONE);
+       uf_widget_set_tooltip(widget, p->tooltip_save);
+    }
+}
+
+static void preset_set(GtkWidget *widget, gpointer user_data)
+{
+    preview_data *data = user_data;
+    int i;
+
+    (void)widget;
+    for (i = 0; i < ARRAYSIZE(presets); ++i)
+       preset_update_state(presets[i].button, &presets[i], data->preset_set ? 
0 : -1);
+    data->preset_set = !data->preset_set;
+}
+
+static void preset_clicked(GtkWidget *widget, gpointer user_data)
+{
+    preview_data *data = get_preview_data(widget);
+    struct preset *p = user_data;
+    gboolean load = TRUE;
+    conf_data c;
+
+    if (p) {
+       if (gtk_button_get_relief(GTK_BUTTON(widget)) == GTK_RELIEF_NORMAL) {
+           if (conf_load(&c, p->idfile) != UFRAW_SUCCESS)
+               load = FALSE;
+       } else {
+           conf_save(CFG, p->idfile, NULL, TRUE);
+           preset_update_state(widget, p, 0);
+           load = FALSE;
+       }
+    } else {
+       c = data->restore_image;
+    }
+    if (data->preset_set)
+       preset_set(NULL, data);
+    if (load) {
+       conf_copy_image(CFG, &c);
+       /* TODO: factor out a generic conf_apply_prepare() */
+       if (CFG->autoExposure == enabled_state)
+           CFG->autoExposure = apply_state;
+       if (CFG->autoBlack == enabled_state)
+           CFG->autoBlack = apply_state;
+       curveeditor_widget_set_curve(data->BaseCurveWidget,
+               &CFG->BaseCurve[CFG->BaseCurveIndex]);
+       preview_invalidate_layer(data, ufraw_first_phase);
+       update_scales(data);
+    }
+}
+
+static void preset_clear(GtkWidget *widget, gpointer user_data)
+{
+    preview_data *data = get_preview_data(widget);
+    int i;
+
+    (void)user_data;
+    for (i = 0; i < ARRAYSIZE(presets); ++i)
+       g_unlink(presets[i].idfile);
+    preset_set(NULL, data);
+}
+
 static void configuration_save(GtkWidget *widget, gpointer user_data)
 {
     preview_data *data = get_preview_data(widget);
     user_data = user_data;
-    conf_save(CFG, NULL, NULL);
+    conf_save(CFG, NULL, NULL, FALSE);
     *RC = *data->UF->conf;
 }
 
@@ -3336,7 +3416,7 @@ static void options_dialog(GtkWidget *widget, gpointer 
user_data)
 {
     preview_data *data = get_preview_data(widget);
     GtkWidget *optionsDialog, *profileTable[profile_types];
-    GtkWidget *notebook, *label, *page, *button, *text, *box, *image;
+    GtkWidget *notebook, *label, *page, *button, *text, *box, *hBox, *image;
     GtkTable *baseCurveTable, *curveTable;
     GtkTextBuffer *confBuffer, *buffer;
     char txt[max_name], *buf;
@@ -3355,7 +3435,7 @@ static void options_dialog(GtkWidget *widget, gpointer 
user_data)
            GTK_DIALOG_DESTROY_WITH_PARENT,
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
            GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
-    gtk_window_resize(GTK_WINDOW(optionsDialog), 600, 400);
+    gtk_window_resize(GTK_WINDOW(optionsDialog), 600, 425);
     g_object_set_data(G_OBJECT(optionsDialog), "Preview-Data", data);
     ufraw_focus(optionsDialog, TRUE);
     gtk_dialog_set_default_response(GTK_DIALOG(optionsDialog),
@@ -3414,7 +3494,16 @@ static void options_dialog(GtkWidget *widget, gpointer 
user_data)
     gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
     confBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
 
-    GtkWidget *hBox = gtk_hbox_new(FALSE, 0);
+    hBox = gtk_hbox_new(FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(box), hBox, FALSE, FALSE, 0);
+    button = gtk_button_new_with_label(_("Clear all presets"));
+    gtk_box_pack_start(GTK_BOX(hBox), button, FALSE, FALSE, 0);
+    uf_widget_set_tooltip(button,
+           _("Remove the .ufraw files associated with the numbered preset 
buttons below the preview"));
+    g_signal_connect(G_OBJECT(button), "clicked",
+           G_CALLBACK(preset_clear), NULL);
+
+    hBox = gtk_hbox_new(FALSE, 0);
     gtk_box_pack_start(GTK_BOX(box), hBox, FALSE, FALSE, 0);
     button = gtk_button_new_with_label(_("Save configuration"));
     gtk_box_pack_start(GTK_BOX(hBox), button, FALSE, FALSE, 0);
@@ -3501,7 +3590,7 @@ static void options_dialog(GtkWidget *widget, gpointer 
user_data)
                    G_CALLBACK(delete_from_list), (gpointer)i);
            gtk_table_attach(curveTable, button, 1, 2, i, i+1, 0, 0, 0, 0);
        }
-       conf_save(CFG, NULL, &buf);
+       conf_save(CFG, NULL, &buf, FALSE);
        gtk_text_buffer_set_text(confBuffer, buf, -1);
        g_free(buf);
        gtk_widget_show_all(optionsDialog);
@@ -3549,7 +3638,7 @@ static void options_dialog(GtkWidget *widget, gpointer 
user_data)
                    RC->profile[i][j] = CFG->profile[i][j];
                RC->profileCount[i] = CFG->profileCount[i];
            }
-           conf_save(RC, NULL, NULL);
+           conf_save(RC, NULL, NULL, FALSE);
        } else { /* response==GTK_RESPONSE_CANCEL or window closed */
            /* Copy profiles and curves from RC to CFG */
 
@@ -5216,6 +5305,17 @@ static void exif_fill_interface(preview_data *data,
     /* End of EXIF page */
 }
 
+static const char *ufraw_get_datadir(void)
+{
+    static char *dd;
+
+    if (dd==NULL) {
+       dd = g_build_filename(uf_get_home_dir(), ".ufraw", NULL);
+       g_mkdir(dd, 0755);
+    }
+    return dd;
+}
+
 int ufraw_preview(ufraw_data *uf, conf_data *rc, int plugin,
        long (*save_func)())
 {
@@ -5229,6 +5329,7 @@ int ufraw_preview(ufraw_data *uf, conf_data *rc, int 
plugin,
     int status, curveeditorHeight;
     preview_data PreviewData;
     preview_data *data = &PreviewData;
+    const char *dd = ufraw_get_datadir();
 
     /* Fill the whole structure with zeros, to avoid surprises */
     memset(&PreviewData, 0, sizeof(PreviewData));
@@ -5488,9 +5589,39 @@ int ufraw_preview(ufraw_data *uf, conf_data *rc, int 
plugin,
     gtk_box_pack_start(GTK_BOX(vBox), GTK_WIDGET(data->ProgressBar),
            FALSE, FALSE, 0);
 
-    /* Control buttons at the bottom */
+    /* Start of control buttons. They are at the bottom */
     GtkBox *ControlsBox = GTK_BOX(gtk_hbox_new(FALSE, 6));
     gtk_box_pack_start(GTK_BOX(vBox), GTK_WIDGET(ControlsBox), FALSE, FALSE, 
6);
+
+    // Restore and the preset buttons are aligned to the left
+    box = GTK_BOX(gtk_hbox_new(FALSE, 0));
+    gtk_box_pack_start(GTK_BOX(ControlsBox), GTK_WIDGET(box), FALSE, FALSE, 0);
+    button = gtk_button_new_with_label(_("Restore"));
+    gtk_box_pack_start(box, button, FALSE, FALSE, 0);
+    uf_widget_set_tooltip(button, _("Restore image manipulation parameters"));
+    g_signal_connect(G_OBJECT(button), "clicked",
+           G_CALLBACK(preset_clicked), NULL);
+    for (i = 0; i < ARRAYSIZE(presets); ++i) {
+       struct preset *p = presets + i;
+       char num[10];
+       char name[20];
+       sprintf(num, "%d", i + 1);
+       sprintf(name, "%s.ufraw", num);
+       p->idfile = g_build_filename(dd, name, NULL);
+       p->tooltip_load = g_strdup_printf(_("Load %s"), p->idfile);
+       p->tooltip_save = g_strdup_printf(_("Initialize preset %s"), p->idfile);
+       p->button = gtk_button_new_with_label(_(num));
+       gtk_box_pack_start(box, p->button, FALSE, FALSE, 0);
+       preset_update_state(p->button, p, 0);
+       g_signal_connect(G_OBJECT(p->button), "clicked",
+               G_CALLBACK(preset_clicked), p);
+    }
+    button = gtk_button_new_with_label(_("Set"));
+    gtk_box_pack_start(box, button, FALSE, FALSE, 0);
+    uf_widget_set_tooltip(button, _("Initialize any preset button"));
+    g_signal_connect(G_OBJECT(button), "clicked",
+           G_CALLBACK(preset_set), data);
+
     // Zoom buttons are centered:
     GtkBox *ZoomBox = GTK_BOX(gtk_hbox_new(FALSE, 0));
     gtk_box_pack_start(ControlsBox, GTK_WIDGET(ZoomBox), TRUE, FALSE, 0);
@@ -5529,7 +5660,7 @@ int ufraw_preview(ufraw_data *uf, conf_data *rc, int 
plugin,
 #endif // HAVE_GTKIMAGEVIEW
 
     // The rest of the control button are aligned to the right
-    box = GTK_BOX(gtk_hbox_new(FALSE, 6));
+    box = GTK_BOX(gtk_hbox_new(FALSE, 0));
     gtk_box_pack_start(GTK_BOX(ControlsBox), GTK_WIDGET(box), FALSE, FALSE, 0);
     /* Options button */
     button = gtk_button_new();
@@ -5633,6 +5764,7 @@ int ufraw_preview(ufraw_data *uf, conf_data *rc, int 
plugin,
     ufraw_load_raw(uf);
     gtk_widget_set_sensitive(data->Controls, TRUE);
 
+    data->restore_image = *data->UF->conf;
     create_base_image(data);
 
     /* Collect raw histogram data */
@@ -5698,21 +5830,21 @@ int ufraw_preview(ufraw_data *uf, conf_data *rc, int 
plugin,
        if ( CFG->saveConfiguration==enabled_state ) {
            /* Save configuration from CFG, but not the output filename. */
            strcpy(CFG->outputFilename, "");
-           conf_save(CFG, NULL, NULL);
+           conf_save(CFG, NULL, NULL, FALSE);
        /* If save 'only this once' was chosen, then so be it */
        } else if ( CFG->saveConfiguration==apply_state ) {
            CFG->saveConfiguration = disabled_state;
            /* Save configuration from CFG, but not the output filename. */
            strcpy(CFG->outputFilename, "");
-           conf_save(CFG, NULL, NULL);
+           conf_save(CFG, NULL, NULL, FALSE);
        } else if ( CFG->saveConfiguration==disabled_state ) {
            /* If save 'never again' was set in this session, we still
             * need to save this setting */
            if ( RC->saveConfiguration!=disabled_state ) {
                RC->saveConfiguration = disabled_state;
-               conf_save(RC, NULL, NULL);
+               conf_save(RC, NULL, NULL, FALSE);
            } else if ( SaveRC ) {
-               conf_save(RC, NULL, NULL);
+               conf_save(RC, NULL, NULL, FALSE);
            }
            strcpy(RC->inputFilename, "");
            strcpy(RC->outputFilename, "");
@@ -5729,6 +5861,11 @@ int ufraw_preview(ufraw_data *uf, conf_data *rc, int 
plugin,
     g_free(data->DevLabels);
     g_free(data->OverLabels);
     g_free(data->UnderLabels);
+    for (i = 0; i < ARRAYSIZE(presets); ++i) {
+       g_free(presets[i].idfile);
+       g_free(presets[i].tooltip_load);
+       g_free(presets[i].tooltip_save);
+    }
 
     if (status!=GTK_RESPONSE_OK) return UFRAW_CANCEL;
     return UFRAW_SUCCESS;
diff --git a/ufraw_saver.c b/ufraw_saver.c
index 8b75955..c04338d 100644
--- a/ufraw_saver.c
+++ b/ufraw_saver.c
@@ -91,7 +91,7 @@ long ufraw_send_to_gimp(ufraw_data *uf)
     char *buffer;
     int saveCreateID = uf->conf->createID;
     uf->conf->createID = send_id;
-    conf_save(uf->conf, confFilename, &buffer);
+    conf_save(uf->conf, confFilename, &buffer, FALSE);
     uf->conf->createID = saveCreateID;
     if ( fwrite(buffer, strlen(buffer), 1, out)!=1 ) {
        g_free(buffer);
diff --git a/ufraw_ui.h b/ufraw_ui.h
index fb15416..ceb0050 100644
--- a/ufraw_ui.h
+++ b/ufraw_ui.h
@@ -41,7 +41,7 @@ enum { base_curve, luminosity_curve };
 /* All the "global" information is here: */
 typedef struct {
     ufraw_data *UF;
-    conf_data *rc;
+    conf_data *rc, restore_image;
     char initialWB[max_name];
     double initialTemperature, initialGreen;
     double initialChanMul[4];
@@ -188,6 +188,7 @@ typedef struct {
     int OverUnderTicker;
     /* The event source number when the highlight blink function is enabled. */
     guint BlinkTimer;
+    gboolean preset_set;
 } preview_data;
 
 /* Response can be any unique positive integer */
diff --git a/ufraw_writer.c b/ufraw_writer.c
index 2b601b1..7063315 100644
--- a/ufraw_writer.c
+++ b/ufraw_writer.c
@@ -305,7 +305,7 @@ int ufraw_write_image(ufraw_data *uf)
        }
     }
     if (uf->conf->createID==only_id) {
-       int status = conf_save(uf->conf, confFilename, NULL);
+       int status = conf_save(uf->conf, confFilename, NULL, FALSE);
        g_free(confFilename);
        return status;
     }
@@ -821,7 +821,7 @@ int ufraw_write_image(ufraw_data *uf)
        if ( ufraw_get_message(uf)!=NULL )
            ufraw_message(UFRAW_SET_LOG, ufraw_get_message(uf));
        // TODO: error handling
-       conf_save(uf->conf, confFilename, NULL);
+       conf_save(uf->conf, confFilename, NULL, FALSE);
        g_free(confFilename);
     }
     return ufraw_get_status(uf);

-- 
Frank

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
ufraw-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ufraw-devel

Reply via email to