コード例 #1
0
static void pretty_print(char *buf, char *out, size_t outsize)
{
  memset(out, 0, outsize);

  if(!buf || buf[0] == '\0') return;

  int num_rules = 0;
  char str[400] = { 0 };
  int mode, item;
  int c;
  sscanf(buf, "%d", &num_rules);
  while(buf[0] != '\0' && buf[0] != ':') buf++;
  if(buf[0] == ':') buf++;

  for(int k = 0; k < num_rules; k++)
  {
    int n = sscanf(buf, "%d:%d:%399[^$]", &mode, &item, str);

    if(n == 3)
    {
      if(k > 0) switch(mode)
        {
          case DT_LIB_COLLECT_MODE_AND:
            c = snprintf(out, outsize, "%s", _(" and "));
            out += c;
            outsize -= c;
            break;
          case DT_LIB_COLLECT_MODE_OR:
            c = snprintf(out, outsize, "%s", _(" or "));
            out += c;
            outsize -= c;
            break;
          default: // case DT_LIB_COLLECT_MODE_AND_NOT:
            c = snprintf(out, outsize, "%s", _(" but not "));
            out += c;
            outsize -= c;
            break;
        }
      int i = 0;
      while(str[i] != '\0' && str[i] != '$') i++;
      if(str[i] == '$') str[i] = '\0';

      c = snprintf(out, outsize, "%s %s", _(dt_lib_collect_string[item]),
                   item == 0 ? dt_image_film_roll_name(str) : str);
      out += c;
      outsize -= c;
    }
    while(buf[0] != '$' && buf[0] != '\0') buf++;
    if(buf[0] == '$') buf++;
  }
}
コード例 #2
0
ファイル: image.c プロジェクト: michalfabik/darktable
void dt_image_film_roll(const dt_image_t *img, char *pathname, int len)
{
  sqlite3_stmt *stmt;
  DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
                              "select folder from film_rolls where id = ?1", -1, &stmt, NULL);
  DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, img->film_id);
  if(sqlite3_step(stmt) == SQLITE_ROW)
  {
    char *f = (char *)sqlite3_column_text(stmt, 0);
    const char *c = dt_image_film_roll_name(f);
    snprintf(pathname, len, "%s", c);
  }
  else
  {
    snprintf(pathname, len, "%s", _("orphaned image"));
  }
  sqlite3_finalize(stmt);
  pathname[len-1] = '\0';
}
コード例 #3
0
ファイル: recentcollect.c プロジェクト: EvilBit/darktable
static void
pretty_print(char *buf, char *out)
{
  if(!buf || buf[0] == '\0') return;
  int num_rules = 0;
  char str[400] = {0};
  int mode, item;
  sscanf(buf, "%d", &num_rules);
  while(buf[0] != ':') buf++;
  buf++;
  for(int k=0; k<num_rules; k++)
  {
    sscanf(buf, "%d:%d:%[^$]", &mode, &item, str);
    str[399] = '$';

    if(k > 0) switch(mode)
      {
        case DT_LIB_COLLECT_MODE_AND:
          out += sprintf(out, _(" and "));
          break;
        case DT_LIB_COLLECT_MODE_OR:
          out += sprintf(out, _(" or "));
          break;
        default: //case DT_LIB_COLLECT_MODE_AND_NOT:
          out += sprintf(out, _(" but not "));
          break;
      }
    int i = 0;
    while(str[i] != '$') i++;
    str[i] = '\0';

    out += sprintf(out, "%s %s", _(dt_lib_collect_string[item]), item == 0 ? dt_image_film_roll_name(str) : str);
    while(buf[0] != '$' && buf[0] != '\0') buf++;
    buf++;
  }
}
コード例 #4
0
static gboolean
changed_callback (GtkEntry *entry, dt_lib_collect_rule_t *dr)
{
    // update related list
    dt_lib_collect_t *d = get_collect(dr);
    sqlite3_stmt *stmt;
    GtkTreeIter iter;
    GtkTreeView *view = d->view;
    GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
    g_object_ref(model);
    gtk_tree_view_set_model(GTK_TREE_VIEW(view), NULL);
    gtk_list_store_clear(GTK_LIST_STORE(model));
    char query[1024];
    int property = gtk_combo_box_get_active(dr->combo);
    const gchar *text = gtk_entry_get_text(GTK_ENTRY(dr->text));
    gchar *escaped_text = dt_util_str_replace(text, "'", "''");
    char confname[200];
    snprintf(confname, 200, "plugins/lighttable/collect/string%1ld", dr->num);
    dt_conf_set_string (confname, text);
    snprintf(confname, 200, "plugins/lighttable/collect/item%1ld", dr->num);
    dt_conf_set_int (confname, property);

    switch(property)
    {
    case 0: // film roll
        snprintf(query, 1024, "select distinct folder, id from film_rolls where folder like '%%%s%%'  order by id DESC", escaped_text);
        break;
    case 1: // camera
        snprintf(query, 1024, "select distinct maker || ' ' || model as model, 1 from images where maker || ' ' || model like '%%%s%%' order by model", escaped_text);
        break;
    case 2: // tag
        snprintf(query, 1024, "SELECT distinct name, id FROM tags WHERE name LIKE '%%%s%%' ORDER BY UPPER(name)", escaped_text);
        break;
    case 4: // History, 2 hardcoded alternatives
        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
        gtk_list_store_set (GTK_LIST_STORE(model), &iter,
                            DT_LIB_COLLECT_COL_TEXT,_("altered"),
                            DT_LIB_COLLECT_COL_ID, 0,
                            DT_LIB_COLLECT_COL_TOOLTIP,_("altered"),
                            -1);
        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
        gtk_list_store_set (GTK_LIST_STORE(model), &iter,
                            DT_LIB_COLLECT_COL_TEXT,_("not altered"),
                            DT_LIB_COLLECT_COL_ID, 1,
                            DT_LIB_COLLECT_COL_TOOLTIP,_("not altered"),
                            -1);
        goto entry_key_press_exit;
        break;

    case 5: // colorlabels
        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
        gtk_list_store_set (GTK_LIST_STORE(model), &iter,
                            DT_LIB_COLLECT_COL_TEXT,_("red"),
                            DT_LIB_COLLECT_COL_ID, 0,
                            DT_LIB_COLLECT_COL_TOOLTIP, _("red"),
                            -1);
        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
        gtk_list_store_set (GTK_LIST_STORE(model), &iter,
                            DT_LIB_COLLECT_COL_TEXT,_("yellow"),
                            DT_LIB_COLLECT_COL_ID, 1,
                            DT_LIB_COLLECT_COL_TOOLTIP, _("yellow"),
                            -1);
        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
        gtk_list_store_set (GTK_LIST_STORE(model), &iter,
                            DT_LIB_COLLECT_COL_TEXT,_("green"),
                            DT_LIB_COLLECT_COL_ID, 2,
                            DT_LIB_COLLECT_COL_TOOLTIP, _("green"),
                            -1);
        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
        gtk_list_store_set (GTK_LIST_STORE(model), &iter,
                            DT_LIB_COLLECT_COL_TEXT,_("blue"),
                            DT_LIB_COLLECT_COL_ID, 3,
                            DT_LIB_COLLECT_COL_TOOLTIP, _("blue"),
                            -1);
        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
        gtk_list_store_set (GTK_LIST_STORE(model), &iter,
                            DT_LIB_COLLECT_COL_TEXT,_("purple"),
                            DT_LIB_COLLECT_COL_ID, 4,
                            DT_LIB_COLLECT_COL_TOOLTIP, _("purple"),
                            -1);
        goto entry_key_press_exit;
        break;

    // TODO: Add empty string for metadata?
    // TODO: Autogenerate this code?
    case 6: // title
        snprintf(query, 1024, "select distinct value, 1 from meta_data where key = %d and value like '%%%s%%' order by value",
                 DT_METADATA_XMP_DC_TITLE, escaped_text);
        break;
    case 7: // description
        snprintf(query, 1024, "select distinct value, 1 from meta_data where key = %d and value like '%%%s%%' order by value",
                 DT_METADATA_XMP_DC_DESCRIPTION, escaped_text);
        break;
    case 8: // creator
        snprintf(query, 1024, "select distinct value, 1 from meta_data where key = %d and value like '%%%s%%' order by value",
                 DT_METADATA_XMP_DC_CREATOR, escaped_text);
        break;
    case 9: // publisher
        snprintf(query, 1024, "select distinct value, 1 from meta_data where key = %d and value like '%%%s%%' order by value",
                 DT_METADATA_XMP_DC_PUBLISHER, escaped_text);
        break;
    case 10: // rights
        snprintf(query, 1024, "select distinct value, 1 from meta_data where key = %d and value like '%%%s%%'order by value ",
                 DT_METADATA_XMP_DC_RIGHTS, escaped_text);
        break;
    case 11: // lens
        snprintf(query, 1024, "select distinct lens, 1 from images where lens like '%%%s%%' order by lens", escaped_text);
        break;
    case 12: // iso
        snprintf(query, 1024, "select distinct cast(iso as integer) as iso, 1 from images where iso like '%%%s%%' order by iso", escaped_text);
        break;
    case 13: // aperature
        snprintf(query, 1024, "select distinct round(aperture,1) as aperture, 1 from images where aperture like '%%%s%%' order by aperture", escaped_text);
        break;
    case 14: // filename
        snprintf(query, 1024, "select distinct filename, 1 from images where filename like '%%%s%%' order by filename", escaped_text);
        break;

    default: // case 3: // day
        snprintf(query, 1024, "SELECT DISTINCT datetime_taken, 1 FROM images WHERE datetime_taken LIKE '%%%s%%' ORDER BY datetime_taken DESC", escaped_text);
        break;
    }
    g_free(escaped_text);
    DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL);
    while(sqlite3_step(stmt) == SQLITE_ROW)
    {
        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
        const char *folder = (const char*)sqlite3_column_text(stmt, 0);
        if(property == 0) // film roll
        {
            folder = dt_image_film_roll_name(folder);
        }
        gchar *value =  (gchar *)sqlite3_column_text(stmt, 0);
        gchar *escaped_text = g_markup_escape_text(value, strlen(value));
        gtk_list_store_set (GTK_LIST_STORE(model), &iter,
                            DT_LIB_COLLECT_COL_TEXT, folder,
                            DT_LIB_COLLECT_COL_ID, sqlite3_column_int(stmt, 1),
                            DT_LIB_COLLECT_COL_TOOLTIP, escaped_text,
                            DT_LIB_COLLECT_COL_PATH, value,
                            -1);
    }
    sqlite3_finalize(stmt);
entry_key_press_exit:
    gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(view), DT_LIB_COLLECT_COL_TOOLTIP);
    gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);
    g_object_unref(model);
    return FALSE;
}