Skip to content

Commit

Permalink
Add a plugin (disabled by default) to delete files from the filesystem.
Browse files Browse the repository at this point in the history
Closes: #76.
  • Loading branch information
jlindgren90 committed Nov 24, 2013
1 parent 83170ec commit 9ee01f2
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 1 deletion.
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dnl ======================
INPUT_PLUGINS="tonegen metronom vtx"
OUTPUT_PLUGINS=""
EFFECT_PLUGINS="compressor crossfade crystalizer ladspa mixer stereo_plugin voice_removal echo_plugin"
GENERAL_PLUGINS="alarm albumart search-tool"
GENERAL_PLUGINS="alarm albumart delete-files search-tool"
VISUALIZATION_PLUGINS="blur_scope cairo-spectrum"
CONTAINER_PLUGINS="asx asx3 audpl m3u pls xspf"
TRANSPORT_PLUGINS="unix-io gio"
Expand Down Expand Up @@ -1076,6 +1076,7 @@ echo " General"
echo " -------"
echo " Alarm: yes"
echo " Album Art: yes"
echo " Delete from Filesystem: yes"
echo " Linux Infrared Remote Control (LIRC) $have_lirc"
echo " MPRIS 2 Server: $have_mpris2"
echo " Search Tool: yes"
Expand Down
12 changes: 12 additions & 0 deletions src/delete-files/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
PLUGIN = delete-files${PLUGIN_SUFFIX}

SRCS = delete-files.c

include ../../buildsys.mk
include ../../extra.mk

plugindir := ${plugindir}/${GENERAL_PLUGIN_DIR}

CPPFLAGS += -I../.. ${GTK_CFLAGS}
CFLAGS += ${PLUGIN_CFLAGS}
LIBS += ${GTK_LIBS}
113 changes: 113 additions & 0 deletions src/delete-files/delete-files.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* delete-files.c
* Copyright 2013 John Lindgren
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions, and the following disclaimer in the documentation
* provided with the distribution.
*
* This software is provided "as is" and without any warranty, express or
* implied. In no event shall the authors be liable for any damages arising from
* the use of this software.
*/


#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <gtk/gtk.h>

#include <audacious/i18n.h>
#include <audacious/misc.h>
#include <audacious/playlist.h>
#include <audacious/plugin.h>
#include <libaudcore/audstrings.h>
#include <libaudgui/libaudgui-gtk.h>

static const int menus[] = {AUD_MENU_MAIN, AUD_MENU_PLAYLIST_RCLICK};

static GtkWidget * dialog = NULL;

static void confirm_delete (void)
{
int playlist = aud_playlist_get_active ();
int entry_count = aud_playlist_entry_count (playlist);

for (int i = 0; i < entry_count; i ++)
{
if (! aud_playlist_entry_get_selected (playlist, i))
continue;

char * uri = aud_playlist_entry_get_filename (playlist, i);
char * filename = uri_to_filename (uri);

if (! filename)
{
SPRINTF (error, _("Error deleting %s: not a local file."), uri);
aud_interface_show_error (error);
}
else if (unlink (filename) < 0)
{
SPRINTF (error, _("Error deleting %s: %s."), filename, strerror (errno));
aud_interface_show_error (error);
}

str_unref (uri);
free (filename);
}

aud_playlist_delete_selected (playlist);
}

static void start_delete (void)
{
if (dialog)
{
gtk_window_present ((GtkWindow *) dialog);
return;
}

GtkWidget * button1 = audgui_button_new (_("Delete"), "edit-delete",
(AudguiCallback) confirm_delete, NULL);
GtkWidget * button2 = audgui_button_new (_("Cancel"), "window-close", NULL, NULL);

dialog = audgui_dialog_new (GTK_MESSAGE_QUESTION,
_("Delete Files"), _("Do you want to permanently delete the selected "
"files from the filesystem?"), button1, button2);

g_signal_connect (dialog, "destroy", (GCallback) gtk_widget_destroyed, & dialog);
gtk_widget_show_all (dialog);
}

static bool_t delete_files_init (void)
{
for (int i = 0; i < G_N_ELEMENTS (menus); i ++)
aud_plugin_menu_add (menus[i], start_delete, _("Delete from Filesystem"), "edit-delete");

return TRUE;
}

static void delete_files_cleanup (void)
{
if (dialog)
gtk_widget_destroy (dialog);

for (int i = 0; i < G_N_ELEMENTS (menus); i ++)
aud_plugin_menu_remove (menus[i], start_delete);
}

AUD_GENERAL_PLUGIN
(
.name = N_("Delete from Filesystem"),
.domain = PACKAGE,
.init = delete_files_init,
.cleanup = delete_files_cleanup,
)

0 comments on commit 9ee01f2

Please sign in to comment.