Example #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;
  }
}
Example #2
0
static void
_really_move_to_trash (CheeseWindow *cheese_window, GList *files)
{
  GError    *error = NULL;
  GList     *l     = NULL;
  GList     *d     = NULL;
  gchar     *primary, *secondary;
  GtkWidget *question_dialog;
  gint       response;
  gint       list_length = g_list_length (files);

  g_print ("received %d items to delete\n", list_length);

  for (l = files; l != NULL; l = l->next)
  {
    if (!g_file_test (g_file_get_path (l->data), G_FILE_TEST_EXISTS))
    {
      g_object_unref (l->data);
      break;
    }
    if (!g_file_trash (l->data, NULL, &error))
    {
      primary   = g_strdup (_("Cannot move file to trash, do you want to delete immediately?"));
      secondary = g_strdup_printf (_("The file \"%s\" cannot be moved to the trash. Details: %s"),
                                   g_file_get_basename (l->data), error->message);
      question_dialog = gtk_message_dialog_new (GTK_WINDOW (cheese_window),
                                                GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                                GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", primary);
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (question_dialog), "%s", secondary);
      gtk_dialog_add_button (GTK_DIALOG (question_dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
      if (list_length > 1)
      {
        /* no need for all those buttons we have a single file to delete */
        gtk_dialog_add_button (GTK_DIALOG (question_dialog), CHEESE_BUTTON_SKIP, CHEESE_RESPONSE_SKIP);
        gtk_dialog_add_button (GTK_DIALOG (question_dialog), CHEESE_BUTTON_SKIP_ALL, CHEESE_RESPONSE_SKIP_ALL);
        gtk_dialog_add_button (GTK_DIALOG (question_dialog), CHEESE_BUTTON_DELETE_ALL, CHEESE_RESPONSE_DELETE_ALL);
      }
      gtk_dialog_add_button (GTK_DIALOG (question_dialog), GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT);
      response = gtk_dialog_run (GTK_DIALOG (question_dialog));
      gtk_widget_destroy (question_dialog);
      g_free (primary);
      g_free (secondary);
      g_error_free (error);
      error = NULL;
      switch (response)
      {
        case CHEESE_RESPONSE_DELETE_ALL:

          /* forward the list to cmd_delete */
          _really_delete (cheese_window, l, TRUE);
          return;

        case GTK_RESPONSE_ACCEPT:

          /* create a single file list for cmd_delete */
          d = g_list_append (d, g_object_ref (l->data));
          _really_delete (cheese_window, d, TRUE);
          g_list_free (d);
          break;

        case CHEESE_RESPONSE_SKIP:

          /* do nothing, skip to the next item */
          break;

        case CHEESE_RESPONSE_SKIP_ALL:
        case GTK_RESPONSE_CANCEL:
        case GTK_RESPONSE_DELETE_EVENT:
        default:

          /* cancel the whole delete operation */
          return;
      }
    }
    else
    {
      cheese_thumb_view_remove_item (cheese_window_get_thumbview (cheese_window), l->data);
    }
    g_object_unref (l->data);
  }
}