Beispiel #1
0
int
gtr_file_trash_or_remove( const char * filename )
{
    if( filename && g_file_test( filename, G_FILE_TEST_EXISTS ) )
    {
        gboolean trashed = FALSE;
#ifdef HAVE_GIO
        GError * err = NULL;
        GFile *  file = g_file_new_for_path( filename );
        trashed = g_file_trash( file, NULL, &err );
        if( err )
            g_message( "Unable to trash file \"%s\": %s", filename, err->message );
        g_clear_error( &err );
        g_object_unref( G_OBJECT( file ) );
#endif

        if( !trashed && g_remove( filename ) )
        {
            const int err = errno;
            g_message( "Unable to remove file \"%s\": %s", filename, g_strerror( err ) );
        }
    }

    return 0;
}
static gboolean
_trash_files_async (GFile* file, gpointer data)
{
    gboolean retval = TRUE;

    TDData* _data = (TDData*) data;

    GError* error = NULL;
    GCancellable* _trash_cancellable = NULL;

    _trash_cancellable = _data->cancellable;
    g_file_trash (file, _trash_cancellable, &error);//By test this function , ensure that the GLIB function-org g_file_trash has bug in too times to trash

    if (error != NULL)
    {
        g_cancellable_cancel (_trash_cancellable);
        g_warning ("_trash_files_async: %s", error->message);
        g_error_free (error);
        g_cancellable_reset (_trash_cancellable);
    }
#if 1
    char* file_uri = g_file_get_uri (file);
    g_debug ("_trash_files_async: trash : %s", file_uri);
    g_free (file_uri);
#endif

    return retval;
}
Beispiel #3
0
int
gtr_file_trash_or_remove (const char * filename)
{
  GFile * file;
  gboolean trashed = FALSE;

  g_return_val_if_fail (filename && *filename, 0);

  file = g_file_new_for_path (filename);

  if (gtr_pref_flag_get (TR_KEY_trash_can_enabled))
    {
      GError * err = NULL;
      trashed = g_file_trash (file, NULL, &err);
      if (err)
        {
          g_message ("Unable to trash file \"%s\": %s", filename, err->message);
          g_clear_error (&err);
        }
    }

  if (!trashed)
    {
      GError * err = NULL;
      g_file_delete (file, NULL, &err);
      if (err)
        {
          g_message ("Unable to delete file \"%s\": %s", filename, err->message);
          g_clear_error (&err);
        }
    }

  g_object_unref (G_OBJECT (file));
  return 0;
}
Beispiel #4
0
/*
 * XAArchive* lsq_new_archive(gchar *path, LSQArchiveType type, gboolean overwrite)
 *
 */
LSQArchive *
lsq_new_archive (
        GFile *file,
        const gchar *mime_type,
        gboolean overwrite,
        GError **error
    )
{
    LSQArchive *archive;

    g_return_val_if_fail( G_IS_FILE( file ), NULL );

    if ( TRUE == overwrite )
    {
        g_file_trash( file, NULL, NULL );
    }

    if ( TRUE == g_file_query_exists( file, NULL ) )
    {
        return NULL;
    }

    archive = lsq_archive_new( file, mime_type, error );

    return archive;
}
int
gtr_file_trash_or_remove( const char * filename )
{
    gboolean trashed = FALSE;
    GFile * file = g_file_new_for_path( filename );

    if( gtr_pref_flag_get( PREF_KEY_TRASH_CAN_ENABLED ) ) {
        GError * err = NULL;
        trashed = g_file_trash( file, NULL, &err );
        if( err ) {
            g_message( "Unable to trash file \"%s\": %s", filename, err->message );
            g_clear_error( &err );
        }
    }

    if( !trashed ) {
        GError * err = NULL;
        g_file_delete( file, NULL, &err );
        if( err ) {
            g_message( "Unable to delete file \"%s\": %s", filename, err->message );
            g_clear_error( &err );
        }
    }

    g_object_unref( G_OBJECT( file ) );
    return 0;
}
    void trash_current_track()
    {
        for (PlayerProxyStore::const_iterator a = ppstore_.begin(); a != ppstore_.end(); ++a)
        {
            gchar *uri;
            if ((uri = (*a)->get_playing_uri()))
            {
                gchar *dlg_text = make_dialog_text(**a);

                g_assert(dlg_text);

                gint response;
                {
                        GtkWidget *dialog = gtk_message_dialog_new(
                                        NULL, (GtkDialogFlags)0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
                                        "Move to Trash?\n\n%s", dlg_text);
                        gtk_dialog_add_buttons(GTK_DIALOG(dialog),
                                GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT,
                                GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
                                NULL);
                        response = gtk_dialog_run(GTK_DIALOG(dialog));
                        gtk_widget_destroy(dialog);
                }
                g_free(dlg_text);

                if (response == GTK_RESPONSE_ACCEPT)
                {
                        /* delete the track */
                        GFile *file = g_file_new_for_uri(uri);
                        GError *error = NULL;
                        g_file_trash(file, NULL, &error);
                        if (error != NULL) {
                                GtkWidget *dialog = gtk_message_dialog_new(
                                                NULL, (GtkDialogFlags)0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
                                                "Error moving file to trash: %s\n", error->message);
                                gtk_dialog_run(GTK_DIALOG(dialog));
                                gtk_widget_destroy(dialog);
                                g_error_free(error);
                        }
                        g_object_unref(file);

                        /* skip to next track if the current uri hasn't changed
                         * (most likely due to track transition waiting for user response)
                         */
                        if (error == NULL) {
                                gchar *new_uri = (*a)->get_playing_uri();
                                if (new_uri) {
                                        if (g_strcmp0(new_uri, uri) == 0)
                                                (*a)->next_track();
                                        g_free(new_uri);
                                }
                        }
                }

                g_free(uri);
            }
        }
    }
void
rb_generic_player_source_trash_or_delete_entries (RBGenericPlayerSource *source,
						  GList *entries,
						  gboolean _delete)
{
	RBGenericPlayerSourcePrivate *priv = GENERIC_PLAYER_SOURCE_GET_PRIVATE (source);
	GList *tem;

	if (priv->read_only != FALSE)
		return;

	for (tem = entries; tem != NULL; tem = tem->next) {
		RhythmDBEntry *entry;
		const char *uri;
		GFile *file;
		GFile *dir;

		entry = tem->data;
		uri = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION);
		file = g_file_new_for_uri (uri);
		if (_delete)
			g_file_delete (file, NULL, NULL);
		else
			g_file_trash (file, NULL, NULL);

		/* now walk up the directory structure and delete empty dirs
		 * until we reach the root or one of the device's audio folders.
		 */
		dir = g_file_get_parent (file);
		while (can_delete_directory (source, dir)) {
			GFile *parent;
			char *path;

			path = g_file_get_path (dir);
			rb_debug ("trying to delete %s", path);
			g_free (path);

			if (g_file_delete (dir, NULL, NULL) == FALSE) {
				break;
			}

			parent = g_file_get_parent (dir);
			if (parent == NULL) {
				break;
			}
			g_object_unref (dir);
			dir = parent;
		}

		g_object_unref (dir);
		g_object_unref (file);

		rhythmdb_entry_delete (priv->db, entry);
	}

	rhythmdb_commit (priv->db);
}
static void move_to_trash (const char * filename)
{
    GFile * gfile = g_file_new_for_path (filename);
    GError * gerror = NULL;

    if (! g_file_trash (gfile, NULL, & gerror))
    {
        SPRINTF (error, _("Error moving %s to trash: %s."), filename, gerror->message);
        aud_interface_show_error (error);
        g_error_free (gerror);
    }

    g_object_unref ((GObject *) gfile);
}
void MoveFileOrDirectoryToTrash(ExtensionString filename, CefRefPtr<CefBrowser> browser, CefRefPtr<CefProcessMessage> response)
{
    int error = NO_ERROR;
    GFile *file = g_file_new_for_path(filename.c_str());
    GError *gerror = NULL;
    if (!g_file_trash(file, NULL, &gerror)) {
        error = ConvertGnomeErrorCode(gerror);
        g_error_free(gerror);
    }
    g_object_unref(file);
    
    response->GetArgumentList()->SetInt(1, error);
    browser->SendProcessMessage(PID_RENDERER, response);
}
Beispiel #10
0
int exio_trash_sub(Value vdst)
{
    GFile *dst = value_to_gfile(vdst);
    GError *error;
    int result = TRUE;

    if (dst == NULL) {
        return FALSE;
    }
    if (!g_file_trash(dst, NULL, &error)) {
        fs->throw_errorf(fs->mod_io, "IOError", "%s", error != NULL ? error->message : "An error occured");
        result = FALSE;
    }
    g_object_unref(G_OBJECT(dst));

    return result;
}
gboolean
bg_pictures_source_remove (BgPicturesSource *bg_source,
			   CcBackgroundItem *item)
{
  GtkTreeModel *model;
  GtkTreeIter iter;
  gboolean cont;
  const char *uri;
  gboolean retval;

  retval = FALSE;
  model = GTK_TREE_MODEL (bg_source_get_liststore (BG_SOURCE (bg_source)));
  uri = cc_background_item_get_uri (item);

  cont = gtk_tree_model_get_iter_first (model, &iter);
  while (cont)
    {
      CcBackgroundItem *tmp_item;
      const char *tmp_uri;

      gtk_tree_model_get (model, &iter, 1, &tmp_item, -1);
      tmp_uri = cc_background_item_get_uri (tmp_item);
      if (g_str_equal (tmp_uri, uri))
        {
          GFile *file;
          char *uuid;

          file = g_file_new_for_uri (uri);
          uuid = g_file_get_basename (file);
          g_hash_table_insert (bg_source->priv->known_items,
			       uuid, NULL);

          gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
          retval = TRUE;
          g_file_trash (file, NULL, NULL);
          g_object_unref (file);
          break;
        }
      g_object_unref (tmp_item);
      cont = gtk_tree_model_iter_next (model, &iter);
    }
  return retval;
}
void
recordings_list_delete_recording (FreetuxTVApp *app, GtkTreePath *pPathRecording, gboolean bWithFile,
    DBSync* dbsync, GError** error)
{
	g_return_if_fail(dbsync != NULL);
	g_return_if_fail(error != NULL);

	FreetuxTVRecordingInfos* pRecordingInfos;
	pRecordingInfos = recordings_list_get_recording (app, pPathRecording);

	gchar* szFileName = g_strdup(pRecordingInfos->szFileName);

	// Delete the channel in the database
	if(*error == NULL){
		dbsync_delete_recording (dbsync, pRecordingInfos, error);
	}
	
	// Delete channel in the treeview
	if(*error == NULL){
		GtkTreeIter iter;
		gtk_tree_model_get_iter (GTK_TREE_MODEL(app->pRecordingList), &iter, pPathRecording);
		if(gtk_list_store_remove (GTK_LIST_STORE(app->pRecordingList), &iter)){
		};

		windowmain_update_statusbar_infos (app);
	}

	// Move the file to trash if needed
	if(*error == NULL && bWithFile){
		if(szFileName){
			GFile *source;
			source = g_file_new_for_path (szFileName);

			if(g_file_query_exists(source, NULL)){
				g_log(FREETUXTV_LOG_DOMAIN, G_LOG_LEVEL_INFO,
					  "Moving '%s' to the trash\n", szFileName);
					g_file_trash (source, NULL, error);
			}
			g_object_unref(source);
		}
	}
}
Beispiel #13
0
static guint
trash_file (XdpAppInfo *app_info,
            const char *sender,
            int fd)
{
  g_autofree char *path = NULL;
  gboolean writable;
  g_autoptr(GFile) file = NULL;

  path = xdp_app_info_get_path_for_fd (app_info, fd, 0, NULL, &writable);

  if (path == NULL || !writable)
    return 0;

  file = g_file_new_for_path (path);
  if (!g_file_trash (file, NULL, NULL))
    return 0;

  return 1;
}
Beispiel #14
0
gboolean
trash_file (GFile *file)
{
	GError *error = NULL;

	if (!g_file_trash (file, NULL, &error)) {
		GFileInfo *info;
		char *str = NULL;
		char *mess;

		info = g_file_query_info (file,
					  G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
					  G_FILE_QUERY_INFO_NONE,
					  NULL,
					  NULL);

		if (info) {
			const char *displayname = g_file_info_get_display_name (info);
			if (displayname)
				str = g_strdup_printf (_("Could not move \"%s\" to the Trash"),
						      displayname);

			g_object_unref (info);
		}

		/* fallback */
		if (str == NULL)
			str = g_strdup (_("Could not move file to the Trash"));

		mess = g_strdup_printf (_("Details: %s"), error->message);
		message (str, mess, GTK_MESSAGE_ERROR, baobab.window);
		g_free (str);
		g_free (mess);
		g_error_free (error);

		return FALSE;		
	}
	
	return TRUE;
}
Beispiel #15
0
static void
close_cb (GObject      *object,
	  GAsyncResult *result,
	  gpointer      user_data)
{
   GomAdapter *adapter = (GomAdapter *)object;
   gboolean *success = user_data;
   gboolean ret;
   GError *error = NULL;
   GFile *file;

   ret = gom_adapter_close_finish(adapter, result, &error);
   g_assert_no_error(error);
   g_assert(ret);

   file = g_file_new_for_path(db_dir_path);
   g_file_trash(file, NULL, NULL);
   g_object_unref(file);

   g_clear_pointer(&db_dir_path, g_free);

   *success = TRUE;
   g_main_loop_quit(gMainLoop);
}
Beispiel #16
0
static void
trash_applet_drag_data_received (GtkWidget        *widget,
                                 GdkDragContext   *context,
                                 gint              x,
                                 gint              y,
                                 GtkSelectionData *selectiondata,
                                 guint             info,
                                 guint             time_)
{
  gchar **list;
  gint i;
  GList *trashed = NULL;
  GList *untrashable = NULL;
  GList *l;
  GError *error = NULL;

  list = g_uri_list_extract_uris ((gchar *)gtk_selection_data_get_data (selectiondata));

  for (i = 0; list[i]; i++)
    {
      GFile *file;

      file = g_file_new_for_uri (list[i]);

      if (!g_file_trash (file, NULL, NULL))
        {
          untrashable = g_list_prepend (untrashable, file);
        }
      else
        {
          trashed = g_list_prepend (trashed, file);
        }
    }

  if (untrashable)
    {
      if (confirm_delete_immediately (widget,
                                      g_list_length (untrashable),
                                      trashed == NULL))
        {
          for (l = untrashable; l; l = l->next)
            {
              if (!g_file_delete (l->data, NULL, &error))
                {
/*
* FIXME: uncomment me after branched (we're string frozen)
                  error_dialog (applet,
                                _("Unable to delete '%s': %s"),
                                g_file_get_uri (l->data),
                                error->message);
*/
                                g_clear_error (&error);
                }
            }
        }
    }

  g_list_foreach (untrashable, (GFunc)g_object_unref, NULL);
  g_list_free (untrashable);
  g_list_foreach (trashed, (GFunc)g_object_unref, NULL);
  g_list_free (trashed);

  g_strfreev (list);

  gtk_drag_finish (context, TRUE, FALSE, time_);
}
Beispiel #17
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);
  }
}
Beispiel #18
0
static void trash_current_rhythmbox_uri(ThisApplet *applet)
{
    /* get the current track URI */
    gchar *uri = get_rhythmbox_playing_uri(applet->rhythmbox_player_proxy);

    if (!uri || g_strcmp0(uri, "") == 0) {
        GtkWidget *dialog = gtk_message_dialog_new(
                NULL, static_cast<GtkDialogFlags>(0), GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
                "No song is currently playing.");
        gtk_dialog_run(GTK_DIALOG(dialog));
        gtk_widget_destroy(dialog);
    }
    else {
        /* get the dialog text */
        gchar *dlg_text = NULL;
        {
            GHashTable *song_props = get_rhythmbox_song_properties(
                    applet->rhythmbox_shell_proxy, uri);

            if (song_props) {
                /* these strings are deleted by the hashtable */
                gchar const *title, *artist, *album;
                title = lookup_variant_string(song_props, "title");
                artist = lookup_variant_string(song_props, "artist");
                album = lookup_variant_string(song_props, "album");

                g_debug("%s / %s / %s", title, artist, album);

                if (title && (artist || album)) {
                    /* combine tags for dialog box */
                    dlg_text = g_strdup_printf("Title: %s", title);
                    gchar *s;
                    if (artist) {
                        s = g_strdup_printf("%s\nArtist: %s", dlg_text, artist);
                        g_free(dlg_text);
                        dlg_text = s;
                    }
                    if (album) {
                        s = g_strdup_printf("%s\nAlbum: %s", dlg_text, album);
                        g_free(dlg_text);
                        dlg_text = s;
                    }
                }
                g_hash_table_destroy(song_props);
            }
            if (dlg_text == NULL) {
                /* text not set by tags */
                dlg_text = g_uri_unescape_string(uri, NULL);
            }
        }
        g_assert(dlg_text);

        gint response;
        {
            GtkWidget *dialog = gtk_message_dialog_new(
                    NULL, static_cast<GtkDialogFlags>(0), GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
                    "Move to Trash?\n\n%s", dlg_text);
            gtk_dialog_add_buttons(GTK_DIALOG(dialog),
                GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT,
                GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
                NULL);
            response = gtk_dialog_run(GTK_DIALOG(dialog));
            gtk_widget_destroy(dialog);
        }
        g_free(dlg_text);

        if (response == GTK_RESPONSE_ACCEPT)
        {
            /* delete the track */
            GFile *file = g_file_new_for_uri(uri);
            GError *error = NULL;
            g_file_trash(file, NULL, &error);
            if (error != NULL) {
                GtkWidget *dialog = gtk_message_dialog_new(
                        NULL, static_cast<GtkDialogFlags>(0), GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
                        "Error moving file to trash: %s\n", error->message);
                gtk_dialog_run(GTK_DIALOG(dialog));
                gtk_widget_destroy(dialog);
                g_error_free(error);
            }
            g_object_unref(file);

            /* skip to next track if the current uri hasn't changed
             * (most likely due to track transition waiting for user response)
             */
            if (error == NULL) {
                gchar *new_uri = get_rhythmbox_playing_uri(applet->rhythmbox_player_proxy);
                if (new_uri) {
                    if (g_strcmp0(new_uri, uri) == 0)
                        rhythmbox_next(applet);
                    g_free(new_uri);
                }
            }
        }

    }
    if (uri) g_free(uri);
}