コード例 #1
0
ファイル: styles_dialog.c プロジェクト: AntonSh/darktable
static void
_gui_styles_dialog_run (gboolean edit,const char *name,int imgid)
{
  char title[512];

  /* check if style exists */
  if (name && (dt_styles_exists (name))==0)
    return;

  /* initialize the dialog */
  dt_gui_styles_dialog_t *sd=(dt_gui_styles_dialog_t *)g_malloc (sizeof (dt_gui_styles_dialog_t));
  sd->nameorig = g_strdup(name);

  if (edit)
  {
    sprintf (title,_("edit style"));
    g_strlcat (title, " \"", 512);
    g_strlcat(title, name, 512);
    g_strlcat(title, "\"", 512);
    sd->duplicate = gtk_check_button_new_with_label(_("duplicate style"));
    g_object_set (sd->duplicate, "tooltip-text", _("creates a duplicate of the style before applying changes"), (char *)NULL);
  }
  else
  {
    sd->imgid = imgid;
    sprintf (title,"%s",_("create new style"));
    sd->duplicate = NULL;
  }
  GtkWidget *window = dt_ui_main_window(darktable.gui->ui);
  GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new_with_buttons (title,
                                  GTK_WINDOW(window),
                                  GTK_DIALOG_DESTROY_WITH_PARENT,
                                  GTK_STOCK_CANCEL,
                                  GTK_RESPONSE_REJECT,
                                  GTK_STOCK_SAVE,
                                  GTK_RESPONSE_ACCEPT,
                                  NULL));

  GtkContainer *content_area = GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog)));
  GtkWidget *alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
  gtk_alignment_set_padding (GTK_ALIGNMENT(alignment), 5, 5, 5, 5);
  gtk_container_add (content_area, alignment);
  GtkBox *box = GTK_BOX (gtk_vbox_new(FALSE, 5));
  gtk_container_add (GTK_CONTAINER (alignment), GTK_WIDGET (box));
  
  sd->name = gtk_entry_new();
  g_object_set (sd->name, "tooltip-text", _("enter a name for the new style"), (char *)NULL);

  sd->description = gtk_entry_new();
  g_object_set (sd->description, "tooltip-text", _("enter a description for the new style, this description is searchable"), (char *)NULL);

  /*set values*/
  if (edit)
  {
    /* name */
    gtk_entry_set_text(GTK_ENTRY(sd->name), name);
    /* description */
    gchar *desc = dt_styles_get_description (name);
    if (desc)
    {
      gtk_entry_set_text (GTK_ENTRY (sd->description),desc);
      g_free (desc);
    }
  }

  gtk_box_pack_start (box,sd->name,FALSE,FALSE,0);
  gtk_box_pack_start (box,sd->description,FALSE,FALSE,0);

  /* create the list of items */
  sd->items = GTK_TREE_VIEW (gtk_tree_view_new ());
  GtkListStore *liststore = gtk_list_store_new (DT_STYLE_ITEMS_NUM_COLS, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_UINT);

  /* enabled */
  GtkCellRenderer *renderer = gtk_cell_renderer_toggle_new ();
  gtk_cell_renderer_toggle_set_activatable (GTK_CELL_RENDERER_TOGGLE (renderer), TRUE);
  g_object_set_data (G_OBJECT (renderer), "column", (gint *)DT_STYLE_ITEMS_COL_ENABLED);
  g_signal_connect (renderer, "toggled", G_CALLBACK (_gui_styles_item_toggled), sd);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (sd->items),
      -1, _("include"),
      renderer,
      "active",
      DT_STYLE_ITEMS_COL_ENABLED,
      NULL);

  /* name */
  renderer = gtk_cell_renderer_text_new ();
  g_object_set_data (G_OBJECT (renderer), "column", (gint *)DT_STYLE_ITEMS_COL_NAME);
  g_object_set (renderer, "xalign", 0.0, NULL);
  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (sd->items),
      -1, _("item"),
      renderer,
      "text",
      DT_STYLE_ITEMS_COL_NAME,
      NULL);


  gtk_tree_selection_set_mode (gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->items)), GTK_SELECTION_SINGLE);
  gtk_tree_view_set_model (GTK_TREE_VIEW(sd->items), GTK_TREE_MODEL(liststore));

  gtk_box_pack_start (box,GTK_WIDGET (sd->items),TRUE,TRUE,0);
  
  if (edit)
    gtk_box_pack_start (box,GTK_WIDGET (sd->duplicate),FALSE,FALSE,0);


  /* fill list with history items */
  GtkTreeIter iter;
  if (edit)
  {
    /* get history items for named style and populate the items list */
    GList *items = dt_styles_get_item_list (name, FALSE);
    if (items)
    {
      do
      {
        dt_style_item_t *item=(dt_style_item_t *)items->data;

        gtk_list_store_append (GTK_LIST_STORE(liststore), &iter);
        gtk_list_store_set (GTK_LIST_STORE(liststore), &iter,
                            DT_STYLE_ITEMS_COL_ENABLED, TRUE,
                            DT_STYLE_ITEMS_COL_NAME, item->name,
                            DT_STYLE_ITEMS_COL_NUM, (guint)item->num,
                            -1);

        g_free(item->name);
        g_free(item);
      }
      while ((items=g_list_next(items)));
    }
  }
  else
  {
    GList *items = dt_history_get_items (imgid,FALSE);
    if (items)
    {
      do
      {
        dt_history_item_t *item = (dt_history_item_t *)items->data;

        /* lookup history item module */
        gboolean enabled = TRUE;
        dt_iop_module_t *module=NULL;
        GList *modules = g_list_first(darktable.develop->iop);
        if (modules)
        {
          GList *result = g_list_find_custom (modules, item->op, _g_list_find_module_by_name); // (dt_iop_module_t *)(modules->data);
          if( result )
          {
            module = (dt_iop_module_t *)(result->data);
            enabled  = (module->flags() & IOP_FLAGS_INCLUDE_IN_STYLES)?TRUE:FALSE;
          }
        }

        gchar name[256]= {0};
        g_snprintf(name,256,"%s",item->name);

        gtk_list_store_append (GTK_LIST_STORE(liststore), &iter);
        gtk_list_store_set (GTK_LIST_STORE(liststore), &iter,
                            DT_STYLE_ITEMS_COL_ENABLED, enabled,
                            DT_STYLE_ITEMS_COL_NAME, name,
                            DT_STYLE_ITEMS_COL_NUM, (guint)item->num,
                            -1);

        g_free(item->op);
        g_free(item->name);
        g_free(item);
      }
      while ((items=g_list_next(items)));
    }
    else
    {
      dt_control_log(_("can't create style out of unaltered image"));
      return;
    }
  }

  g_object_unref (liststore);


  /* run dialog */
  if (edit)
    g_signal_connect (dialog, "response", G_CALLBACK (_gui_styles_edit_style_response), sd);
  else
    g_signal_connect (dialog, "response", G_CALLBACK (_gui_styles_new_style_response), sd);

  gtk_widget_show_all (GTK_WIDGET (dialog));
  gtk_dialog_run(GTK_DIALOG(dialog));

}
コード例 #2
0
ファイル: hist_dialog.c プロジェクト: CChiappa/darktable
int dt_gui_hist_dialog_new(dt_gui_hist_dialog_t *d, int imgid, gboolean iscopy)
{
  int res;
  GtkWidget *window = dt_ui_main_window(darktable.gui->ui);

  GtkDialog *dialog = GTK_DIALOG(gtk_dialog_new_with_buttons(
      _("select parts"), GTK_WINDOW(window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, _("_cancel"),
      GTK_RESPONSE_CANCEL, _("select _all"), GTK_RESPONSE_YES, _("select _none"), GTK_RESPONSE_NONE, _("_ok"),
      GTK_RESPONSE_OK, NULL));
#ifdef GDK_WINDOWING_QUARTZ
  dt_osx_disallow_fullscreen(GTK_WIDGET(dialog));
#endif

  GtkContainer *content_area = GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
  GtkBox *box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 3));
  gtk_widget_set_margin_start(GTK_WIDGET(box), DT_PIXEL_APPLY_DPI(5));
  gtk_widget_set_margin_end(GTK_WIDGET(box), DT_PIXEL_APPLY_DPI(5));
  gtk_widget_set_margin_top(GTK_WIDGET(box), DT_PIXEL_APPLY_DPI(5));
  gtk_widget_set_margin_bottom(GTK_WIDGET(box), DT_PIXEL_APPLY_DPI(5));
  gtk_container_add(content_area, GTK_WIDGET(box));

  /* create the list of items */
  d->items = GTK_TREE_VIEW(gtk_tree_view_new());
  GtkListStore *liststore
      = gtk_list_store_new(DT_HIST_ITEMS_NUM_COLS, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_UINT);

  /* enabled */
  GtkCellRenderer *renderer = gtk_cell_renderer_toggle_new();
  gtk_cell_renderer_toggle_set_activatable(GTK_CELL_RENDERER_TOGGLE(renderer), TRUE);
  g_object_set_data(G_OBJECT(renderer), "column", (gint *)DT_HIST_ITEMS_COL_ENABLED);
  g_signal_connect(renderer, "toggled", G_CALLBACK(_gui_hist_item_toggled), d);

  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(d->items), -1, _("include"), renderer, "active",
                                              DT_HIST_ITEMS_COL_ENABLED, NULL);

  /* name */
  renderer = gtk_cell_renderer_text_new();
  g_object_set_data(G_OBJECT(renderer), "column", (gint *)DT_HIST_ITEMS_COL_NAME);
  g_object_set(renderer, "xalign", 0.0, (gchar *)0);
  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(d->items), -1, _("item"), renderer, "text",
                                              DT_HIST_ITEMS_COL_NAME, NULL);


  gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(d->items)), GTK_SELECTION_SINGLE);
  gtk_tree_view_set_model(GTK_TREE_VIEW(d->items), GTK_TREE_MODEL(liststore));

  gtk_box_pack_start(box, GTK_WIDGET(d->items), TRUE, TRUE, 0);

  /* fill list with history items */
  GtkTreeIter iter;
  GList *items = dt_history_get_items(imgid, FALSE);
  if(items)
  {
    do
    {
      dt_history_item_t *item = (dt_history_item_t *)items->data;

      gtk_list_store_append(GTK_LIST_STORE(liststore), &iter);
      gtk_list_store_set(GTK_LIST_STORE(liststore), &iter, DT_HIST_ITEMS_COL_ENABLED,
                         iscopy ? TRUE : _gui_is_set(d->selops, item->num), DT_HIST_ITEMS_COL_NAME,
                         item->name, DT_HIST_ITEMS_COL_NUM, (guint)item->num, -1);

    } while((items = g_list_next(items)));
    g_list_free_full(items, dt_history_item_free);
  }
  else
  {
    dt_control_log(_("can't copy history out of unaltered image"));
    return GTK_RESPONSE_CANCEL;
  }

  g_object_unref(liststore);

  g_signal_connect(dialog, "response", G_CALLBACK(_gui_hist_copy_response), d);

  gtk_widget_show_all(GTK_WIDGET(dialog));

  while(1)
  {
    res = gtk_dialog_run(GTK_DIALOG(dialog));
    if(res == GTK_RESPONSE_CANCEL || res == GTK_RESPONSE_DELETE_EVENT || res == GTK_RESPONSE_OK) break;
  }

  gtk_widget_destroy(GTK_WIDGET(dialog));
  return res;
}