Beispiel #1
0
void
dt_styles_create_from_image (const char *name,const char *description,int32_t imgid,GList *filter)
{
  int id=0;
  sqlite3_stmt *stmt;

  /* first create the style header */
  if (!dt_styles_create_style_header(name,description) ) return;

  if ((id=dt_styles_get_id_by_name(name)) != 0)
  {
    /* create the style_items from source image history stack */
    if (filter)
    {
      GList *list=filter;
      char tmp[64];
      char include[2048]= {0};
      g_strlcat(include,"num in (", 2048);
      do
      {
        if(list!=g_list_first(list))
          g_strlcat(include,",", 2048);
        sprintf(tmp,"%ld",(long int)list->data);
        g_strlcat(include,tmp, 2048);
      }
      while ((list=g_list_next(list)));
      g_strlcat(include,")", 2048);
      char query[4096]= {0};
      sprintf(query,"insert into style_items (styleid,num,module,operation,op_params,enabled,blendop_params,blendop_version,multi_priority,multi_name) select ?1, num,module,operation,op_params,enabled,blendop_params,blendop_version,multi_priority,multi_name from history where imgid=?2 and %s",include);
      DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL);
    }
    else
      DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "insert into style_items (styleid,num,module,operation,op_params,enabled,blendop_params,blendop_version,multi_priority,multi_name) select ?1, num,module,operation,op_params,enabled,blendop_params,blendop_version,multi_priority,multi_name from history where imgid=?2", -1, &stmt, NULL);
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid);
    sqlite3_step (stmt);
    sqlite3_finalize (stmt);

    /* backup style to disk */
    char stylesdir[1024];
    dt_loc_get_user_config_dir(stylesdir, 1024);
    g_strlcat(stylesdir,"/styles",1024);
    g_mkdir_with_parents(stylesdir,00755);

    dt_styles_save_to_file(name,stylesdir,FALSE);

    char tmp_accel[1024];
    gchar* tmp_name = g_strdup(name); // freed by _destro_style_shortcut_callback
    snprintf(tmp_accel,1024,"styles/Apply %s",name);
    dt_accel_register_global( tmp_accel, 0, 0);
    GClosure *closure;
    closure = g_cclosure_new(
                G_CALLBACK(_apply_style_shortcut_callback),
                tmp_name, _destroy_style_shortcut_callback);
    dt_accel_connect_global(tmp_accel, closure);
    dt_control_log(_("style named '%s' successfully created"),name);
  }
}
Beispiel #2
0
static void dt_style_save(StyleData *style)
{
  int id = 0;
  if(style == NULL) return;

  /* first create the style header */
  if(!dt_styles_create_style_header(style->info->name->str, style->info->description->str)) return;

  if((id = dt_styles_get_id_by_name(style->info->name->str)) != 0)
  {
    g_list_foreach(style->plugins, (GFunc)dt_style_plugin_save, GINT_TO_POINTER(id));
    dt_control_log(_("style %s was successfully imported"), style->info->name->str);
  }
}
Beispiel #3
0
gboolean dt_styles_create_from_image(const char *name, const char *description, int32_t imgid, GList *filter)
{
  int id = 0;
  sqlite3_stmt *stmt;

  /* first create the style header */
  if(!dt_styles_create_style_header(name, description)) return FALSE;

  if((id = dt_styles_get_id_by_name(name)) != 0)
  {
    /* create the style_items from source image history stack */
    if(filter)
    {
      GList *list = filter;
      char tmp[64];
      char include[2048] = { 0 };
      g_strlcat(include, "num in (", sizeof(include));
      do
      {
        if(list != g_list_first(list)) g_strlcat(include, ",", sizeof(include));
        snprintf(tmp, sizeof(tmp), "%d", GPOINTER_TO_INT(list->data));
        g_strlcat(include, tmp, sizeof(include));
      } while((list = g_list_next(list)));
      g_strlcat(include, ")", sizeof(include));
      char query[4096] = { 0 };
      snprintf(query, sizeof(query), "insert into style_items "
                                     "(styleid,num,module,operation,op_params,enabled,blendop_params,blendop_"
                                     "version,multi_priority,multi_name) select ?1, "
                                     "num,module,operation,op_params,enabled,blendop_params,blendop_version,"
                                     "multi_priority,multi_name from history where imgid=?2 and %s",
               include);
      DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL);
    }
    else
      DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
                                  "insert into style_items "
                                  "(styleid,num,module,operation,op_params,enabled,blendop_params,blendop_"
                                  "version,multi_priority,multi_name) select ?1, "
                                  "num,module,operation,op_params,enabled,blendop_params,blendop_version,"
                                  "multi_priority,multi_name from history where imgid=?2",
                                  -1, &stmt, NULL);
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid);
    sqlite3_step(stmt);
    sqlite3_finalize(stmt);

    _dt_style_cleanup_multi_instance(id);

    /* backup style to disk */
    char stylesdir[PATH_MAX] = { 0 };
    dt_loc_get_user_config_dir(stylesdir, sizeof(stylesdir));
    g_strlcat(stylesdir, "/styles", sizeof(stylesdir));
    g_mkdir_with_parents(stylesdir, 00755);

    dt_styles_save_to_file(name, stylesdir, FALSE);

    char tmp_accel[1024];
    gchar *tmp_name = g_strdup(name); // freed by _destroy_style_shortcut_callback
    snprintf(tmp_accel, sizeof(tmp_accel), C_("accel", "styles/apply %s"), name);
    dt_accel_register_global(tmp_accel, 0, 0);
    GClosure *closure;
    closure = g_cclosure_new(G_CALLBACK(_apply_style_shortcut_callback), tmp_name,
                             _destroy_style_shortcut_callback);
    dt_accel_connect_global(tmp_accel, closure);
    dt_control_signal_raise(darktable.signals, DT_SIGNAL_STYLE_CHANGED);
    return TRUE;
  }
  return FALSE;
}
Beispiel #4
0
void dt_styles_create_from_style(const char *name, const char *newname, const char *description,
                                 GList *filter, int imgid, GList *update)
{
    sqlite3_stmt *stmt;
    int id = 0;
    int oldid = 0;

    oldid = dt_styles_get_id_by_name(name);
    if(oldid == 0) return;

    /* create the style header */
    if(!dt_styles_create_style_header(newname, description)) return;

    if((id = dt_styles_get_id_by_name(newname)) != 0)
    {
        if(filter)
        {
            GList *list = filter;
            char tmp[64];
            char include[2048] = { 0 };
            g_strlcat(include, "num IN (", sizeof(include));
            do
            {
                if(list != g_list_first(list)) g_strlcat(include, ",", sizeof(include));
                snprintf(tmp, sizeof(tmp), "%d", GPOINTER_TO_INT(list->data));
                g_strlcat(include, tmp, sizeof(include));
            } while((list = g_list_next(list)));
            g_strlcat(include, ")", sizeof(include));
            char query[4096] = { 0 };

            snprintf(query, sizeof(query), "INSERT INTO data.style_items "
                     "(styleid,num,module,operation,op_params,enabled,blendop_params,blendop_"
                     "version,multi_priority,multi_name) SELECT ?1, "
                     "num,module,operation,op_params,enabled,blendop_params,blendop_version,"
                     "multi_priority,multi_name FROM data.style_items WHERE styleid=?2 AND %s",
                     include);
            DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL);
        }
        else
            DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
                                        "INSERT INTO data.style_items "
                                        "(styleid,num,module,operation,op_params,enabled,blendop_params,blendop_"
                                        "version,multi_priority,multi_name) SELECT ?1, "
                                        "num,module,operation,op_params,enabled,blendop_params,blendop_version,"
                                        "multi_priority,multi_name FROM data.style_items WHERE styleid=?2",
                                        -1, &stmt, NULL);
        DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
        DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, oldid);
        sqlite3_step(stmt);
        sqlite3_finalize(stmt);

        /* insert items from imgid if defined */

        _dt_style_update_from_image(id, imgid, filter, update);

        _dt_style_cleanup_multi_instance(id);

        /* backup style to disk */
        char stylesdir[PATH_MAX] = { 0 };
        dt_loc_get_user_config_dir(stylesdir, sizeof(stylesdir));
        g_strlcat(stylesdir, "/styles", sizeof(stylesdir));
        g_mkdir_with_parents(stylesdir, 00755);

        dt_styles_save_to_file(newname, stylesdir, FALSE);

        char tmp_accel[1024];
        gchar *tmp_name = g_strdup(newname); // freed by _destroy_style_shortcut_callback
        snprintf(tmp_accel, sizeof(tmp_accel), C_("accel", "styles/apply %s"), newname);
        dt_accel_register_global(tmp_accel, 0, 0);
        GClosure *closure;
        closure = g_cclosure_new(G_CALLBACK(_apply_style_shortcut_callback), tmp_name,
                                 _destroy_style_shortcut_callback);
        dt_accel_connect_global(tmp_accel, closure);
        dt_control_log(_("style named '%s' successfully created"), newname);
        dt_control_signal_raise(darktable.signals, DT_SIGNAL_STYLE_CHANGED);
    }
}