예제 #1
0
static void
cheese_thumb_view_monitor_cb (GFileMonitor     *file_monitor,
                              GFile            *file,
                              GFile            *other_file,
                              GFileMonitorEvent event_type,
                              CheeseThumbView  *thumb_view)
{
  switch (event_type)
  {
    case G_FILE_MONITOR_EVENT_DELETED:
      cheese_thumb_view_remove_item (thumb_view, file);
      break;

    case G_FILE_MONITOR_EVENT_MOVED:
      cheese_thumb_view_remove_item (thumb_view, file);
      cheese_thumb_view_append_item (thumb_view, other_file);
      break;

    case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
      cheese_thumb_view_append_item (thumb_view, file);
      break;

    case G_FILE_MONITOR_EVENT_CREATED:
    {
      CheeseThumbViewPrivate *priv;
      const char *path_photos;
      char *filename;
      GDir *dir_photos;
      const char *name;
      char *photo_name;
      GFile *photo_file;

      priv = cheese_thumb_view_get_instance_private (thumb_view);
      path_photos = cheese_fileutil_get_photo_path (priv->fileutil);
      filename = g_file_get_path (file);
      if (!strcmp(path_photos, filename))
      {
        dir_photos = g_dir_open (path_photos, 0, NULL);
        while ((name = g_dir_read_name (dir_photos)))
        {
          if (!(g_str_has_suffix (name, CHEESE_PHOTO_NAME_SUFFIX)))
            continue;
          photo_name = g_build_filename (path_photos, name, NULL);
          photo_file = g_file_new_for_path (photo_name);
          cheese_thumb_view_append_item (thumb_view, photo_file);
          g_free (photo_name);
          g_object_unref (photo_file);
        }
        g_dir_close (dir_photos);
      }

      g_free (filename);
      break;
    }

    default:
      break;
  }
}
예제 #2
0
/**
 * cheese_fileutil_get_new_media_filename:
 * @fileutil: a #CheeseFileUtil
 * @mode: the type of media to create a filename for
 *
 * Creates a filename for one of the three media types: photo, photo burst or
 * video. If a filename for a photo burst image was previously created, this
 * function increments the burst count automatically. To start a new burst,
 * first call cheese_fileutil_reset_burst().
 *
 * Returns: (transfer full) (type filename): a new filename
 */
gchar *
cheese_fileutil_get_new_media_filename (CheeseFileUtil *fileutil, CheeseMediaMode mode)
{
  GDateTime *datetime;
  gchar       *time_string;
  const gchar *path;
  gchar       *filename;
  GFile       *file;
  guint        num;
  CheeseFileUtilPrivate *priv;

  g_return_val_if_fail (CHEESE_IS_FILEUTIL (fileutil), NULL);

  priv = fileutil->priv;

  datetime = g_date_time_new_now_local ();

  g_assert (datetime != NULL);

  time_string = g_date_time_format (datetime, "%F-%H%M%S");
  g_date_time_unref (datetime);

  g_assert (time_string != NULL);

  switch (mode)
  {
    case CHEESE_MEDIA_MODE_PHOTO:
    case CHEESE_MEDIA_MODE_BURST:
      path = cheese_fileutil_get_photo_path (fileutil);
      break;
    case CHEESE_MEDIA_MODE_VIDEO:
      path = cheese_fileutil_get_video_path (fileutil);
      break;
    default:
      g_assert_not_reached ();
  }

  g_mkdir_with_parents (path, 0775);

  switch (mode)
  {
    case CHEESE_MEDIA_MODE_PHOTO:
      filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, time_string, CHEESE_PHOTO_NAME_SUFFIX);
      break;
    case CHEESE_MEDIA_MODE_BURST:
      priv->burst_count++;
      if (strlen (priv->burst_raw_name) == 0)
        priv->burst_raw_name = g_strdup_printf ("%s%s%s", path, G_DIR_SEPARATOR_S, time_string);

      filename = g_strdup_printf ("%s_%d%s", priv->burst_raw_name, priv->burst_count, CHEESE_PHOTO_NAME_SUFFIX);
      break;
    case CHEESE_MEDIA_MODE_VIDEO:
      filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, time_string, CHEESE_VIDEO_NAME_SUFFIX);
      break;
    default:
      g_assert_not_reached ();
  }

  file = g_file_new_for_path (filename);
  num = 0;

  while (g_file_query_exists (file, NULL))
  {
    num++;

    g_object_unref (file);
    g_free (filename);

    switch (mode)
    {
      case CHEESE_MEDIA_MODE_PHOTO:
        filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, time_string, num, CHEESE_PHOTO_NAME_SUFFIX);
        break;
      case CHEESE_MEDIA_MODE_BURST:
        filename = g_strdup_printf ("%s_%d (%d)%s", priv->burst_raw_name, priv->burst_count, num, CHEESE_PHOTO_NAME_SUFFIX);
        break;
      case CHEESE_MEDIA_MODE_VIDEO:
        filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, time_string, num, CHEESE_VIDEO_NAME_SUFFIX);
        break;
      default:
        g_assert_not_reached ();
    }

    file = g_file_new_for_path (filename);
  }

  g_free (time_string);
  g_object_unref (file);

  return filename;
}
예제 #3
0
static void
cheese_thumb_view_fill (CheeseThumbView *thumb_view)
{
  CheeseThumbViewPrivate *priv = cheese_thumb_view_get_instance_private (thumb_view);

  GDir       *dir_videos, *dir_photos;
  const char *path_videos, *path_photos;
  const char *name;
  char       *filename;
  GFile      *file;

  gtk_list_store_clear (priv->store);

  path_videos = cheese_fileutil_get_video_path (priv->fileutil);
  path_photos = cheese_fileutil_get_photo_path (priv->fileutil);

  dir_videos = g_dir_open (path_videos, 0, NULL);
  dir_photos = g_dir_open (path_photos, 0, NULL);

  if (!dir_videos && !dir_photos)
    return;

  priv->multiplex_thumbnail_generator = FALSE;
  char *multiplex_file = g_build_filename (path_photos, "cheese, cheese, cheese! all i want is cheese", NULL);
  if (g_file_test (multiplex_file, G_FILE_TEST_EXISTS))
    priv->multiplex_thumbnail_generator = !priv->multiplex_thumbnail_generator;
  g_free (multiplex_file);

  if (dir_videos)
  {
    /* read videos from the vid directory */
    while ((name = g_dir_read_name (dir_videos)))
    {
      if (!(g_str_has_suffix (name, CHEESE_VIDEO_NAME_SUFFIX))
        && !(g_str_has_suffix (name, CHEESE_OLD_VIDEO_NAME_SUFFIX)))
        continue;

      filename = g_build_filename (path_videos, name, NULL);
      file     = g_file_new_for_path (filename);
      cheese_thumb_view_append_item (thumb_view, file);
      g_free (filename);
      g_object_unref (file);
    }
    g_dir_close (dir_videos);
    cheese_thumb_view_start_monitoring_video_path (thumb_view, path_videos);
  }

  if (dir_photos)
  {
    /* read photos from the photo directory */
    while ((name = g_dir_read_name (dir_photos)))
    {
      if (!(g_str_has_suffix (name, CHEESE_PHOTO_NAME_SUFFIX)))
        continue;

      filename = g_build_filename (path_photos, name, NULL);
      file     = g_file_new_for_path (filename);
      cheese_thumb_view_append_item (thumb_view, file);
      g_free (filename);
      g_object_unref (file);
    }
    g_dir_close (dir_photos);
    cheese_thumb_view_start_monitoring_photo_path (thumb_view, path_photos);
  }
}
예제 #4
0
void
cheese_cmd_file_move_all_to_trash (GtkWidget *widget, CheeseWindow *cheese_window)
{
  GtkWidget  *dlg;
  char       *prompt;
  int         response;
  char       *filename;
  GFile      *file;
  GList      *files_list = NULL;
  GDir       *dir_videos, *dir_photos;
  char       *path_videos, *path_photos;
  const char *name;

  prompt = g_strdup_printf (_("Really move all photos and videos to the trash?"));
  dlg    = gtk_message_dialog_new_with_markup (GTK_WINDOW (cheese_window),
                                               GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                               GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
                                               "<span weight=\"bold\" size=\"larger\">%s</span>",
                                               prompt);
  g_free (prompt);
  gtk_dialog_add_button (GTK_DIALOG (dlg), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
  gtk_dialog_add_button (GTK_DIALOG (dlg), _("_Move to Trash"), GTK_RESPONSE_OK);
  gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_OK);
  gtk_window_set_title (GTK_WINDOW (dlg), "");
  gtk_widget_show_all (dlg);

  response = gtk_dialog_run (GTK_DIALOG (dlg));
  gtk_widget_destroy (dlg);

  if (response != GTK_RESPONSE_OK)
    return;

  /* append all videos */
  path_videos = cheese_fileutil_get_video_path (cheese_window_get_fileutil (cheese_window));
  dir_videos  = g_dir_open (path_videos, 0, NULL);
  while ((name = g_dir_read_name (dir_videos)) != NULL)
  {
    if (g_str_has_suffix (name, VIDEO_NAME_SUFFIX))
    {
      filename = g_strjoin (G_DIR_SEPARATOR_S, path_videos, name, NULL);
      file     = g_file_new_for_path (filename);

      files_list = g_list_append (files_list, file);
      g_free (filename);
    }
  }
  g_dir_close (dir_videos);

  /* append all photos */
  path_photos = cheese_fileutil_get_photo_path (cheese_window_get_fileutil (cheese_window));
  dir_photos  = g_dir_open (path_photos, 0, NULL);
  while ((name = g_dir_read_name (dir_photos)) != NULL)
  {
    if (g_str_has_suffix (name, PHOTO_NAME_SUFFIX))
    {
      filename = g_strjoin (G_DIR_SEPARATOR_S, path_photos, name, NULL);
      file     = g_file_new_for_path (filename);

      files_list = g_list_append (files_list, file);
      g_free (filename);
    }
  }

  /* delete all items */
  _really_move_to_trash (cheese_window, files_list);
  g_list_free (files_list);
  g_dir_close (dir_photos);
}