Esempio n. 1
0
void
mex_content_set_last_used_metadatas (MexContent *content)
{
  guint count;
  gchar str[20], *nstr;
  const gchar *play_count;
  GDateTime *datetime;
  GTimeVal tv;

  play_count = mex_content_get_metadata (content,
                                         MEX_CONTENT_METADATA_PLAY_COUNT);
  if (play_count) {
    count = atoi (play_count);
    count++;
  } else
    count = 1;
  snprintf (str, sizeof (str), "%u", count);
  mex_content_set_metadata (content, MEX_CONTENT_METADATA_PLAY_COUNT, str);

  datetime = g_date_time_new_now_local ();
  if (datetime) {
    if (g_date_time_to_timeval (datetime, &tv)) {
      tv.tv_usec = 0;
      nstr = g_time_val_to_iso8601 (&tv);
      if (nstr) {
        mex_content_set_metadata (content,
                                  MEX_CONTENT_METADATA_LAST_PLAYED_DATE,
                                  nstr);
        g_free (nstr);
      }
    }
    g_date_time_unref (datetime);
  }
}
Esempio n. 2
0
/**
 * CacheUtilDatetimeToString:
 * @value: Date to create string from. Must be UTC.
 *
 * Returns: (allow-none): Date in "{yyyy}-{mm}-{dd}T{hh}:{mm}:{ss}Z" format
 * (ISO 8601) or #NULL if the date couldn't be serialized.
 */
gchar *CacheUtilDatetimeToString(GDateTime *value) {
  GTimeVal tv = {0, 0};

  if (!value)
    return NULL;

  if (g_date_time_to_timeval(value, &tv)) {
    return g_time_val_to_iso8601(&tv);
  } else {
    return NULL;
  }
}
Esempio n. 3
0
void
accounts_set_last_activity(const char *const account_name)
{
    if (accounts_account_exists(account_name)) {
        GDateTime *nowdt = g_date_time_new_now_utc();
        GTimeVal nowtv;
        gboolean res = g_date_time_to_timeval(nowdt, &nowtv);
        g_date_time_unref(nowdt);

        if (res) {
            char *timestr = g_time_val_to_iso8601(&nowtv);
            g_key_file_set_string(accounts, account_name, "last.activity", timestr);
            free(timestr);
            _save_accounts();
        }
    }
}
Esempio n. 4
0
/**
 * mongo_bson_append_date_time:
 * @bson: (in): A #MongoBson.
 * @key: (in): A string containing the key.
 * @value: (in): A #GDateTime to store.
 *
 * Appends the #GDateTime to the #MongoBson under @key.
 */
void
mongo_bson_append_date_time (MongoBson   *bson,
                             const gchar *key,
                             GDateTime   *value)
{
   GTimeVal tv;

   g_return_if_fail(bson != NULL);
   g_return_if_fail(key != NULL);
   g_return_if_fail(value != NULL);

   if (!g_date_time_to_timeval(value, &tv)) {
      g_warning("GDateTime is outside of storable range, ignoring!");
      return;
   }

   mongo_bson_append_timeval(bson, key, &tv);
}
Esempio n. 5
0
int32_t dt_control_gpx_apply_job_run(dt_job_t *job)
{
  dt_control_image_enumerator_t *t1 = (dt_control_image_enumerator_t *)job->param;
  GList *t = t1->index;
  struct dt_gpx_t *gpx = NULL;
  uint32_t cntr = 0;
  const dt_control_gpx_apply_t *d = t1->data;
  const gchar *filename = d->filename;
  const gchar *tz = d->tz;

  /* do we have any selected images */
  if (!t)
    goto bail_out;

  /* try parse the gpx data */
  gpx = dt_gpx_new(filename);
  if (!gpx)
  {
    dt_control_log(_("failed to parse gpx file"));
    goto bail_out;
  }

  GTimeZone *tz_camera = (tz == NULL)?g_time_zone_new_utc():g_time_zone_new(tz);
  if(!tz_camera)
    goto bail_out;
  GTimeZone *tz_utc = g_time_zone_new_utc();

  /* go thru each selected image and lookup location in gpx */
  do
  {
    GTimeVal timestamp;
    GDateTime *exif_time, *utc_time;
    gdouble lon,lat;
    uint32_t imgid = (long int)t->data;

    /* get image */
    const dt_image_t *cimg = dt_image_cache_read_get(darktable.image_cache, imgid);
    if (!cimg)
      continue;

    /* convert exif datetime
       TODO: exiv2 dates should be iso8601 and we are probably doing some ugly
       convertion before inserting into database.
     */
    gint year;
    gint month;
    gint day;
    gint hour;
    gint minute;
    gint  seconds;

    if (sscanf(cimg->exif_datetime_taken, "%d:%d:%d %d:%d:%d",
               (int*)&year, (int*)&month, (int*)&day,
               (int*)&hour,(int*)&minute,(int*)&seconds) != 6)
    {
      fprintf(stderr,"broken exif time in db, '%s'\n", cimg->exif_datetime_taken);
      dt_image_cache_read_release(darktable.image_cache, cimg);
      continue;
    }

    /* release the lock */
    dt_image_cache_read_release(darktable.image_cache, cimg);

    exif_time = g_date_time_new(tz_camera, year, month, day, hour, minute, seconds);
    if(!exif_time)
      continue;
    utc_time = g_date_time_to_timezone(exif_time, tz_utc);
    g_date_time_unref(exif_time);
    if(!utc_time)
      continue;
    gboolean res = g_date_time_to_timeval(utc_time, &timestamp);
    g_date_time_unref(utc_time);
    if(!res)
      continue;

    /* only update image location if time is within gpx tack range */
    if(dt_gpx_get_location(gpx, &timestamp, &lon, &lat))
    {
      dt_image_set_location(imgid, lon, lat);
      cntr++;
    }

  }
  while((t = g_list_next(t)) != NULL);

  dt_control_log(_("applied matched gpx location onto %d image(s)"), cntr);

  g_time_zone_unref(tz_camera);
  g_time_zone_unref(tz_utc);
  dt_gpx_destroy(gpx);
  g_free(d->filename);
  g_free(d->tz);
  g_free(t1->data);
  return 0;

bail_out:
  if (gpx)
    dt_gpx_destroy(gpx);

  g_free(d->filename);
  g_free(d->tz);
  g_free(t1->data);
  return 1;
}