Mercurial > audlegacy-plugins
changeset 1456:475eac76a8ba
MTP upload plugin
author | Cristi Magherusan <majeru@atheme-project.org> |
---|---|
date | Sat, 11 Aug 2007 01:52:28 +0300 |
parents | 68c9906e0ac4 |
children | 71138874c5fd |
files | configure.ac src/mtp_up/Makefile src/mtp_up/mtp.c |
diffstat | 3 files changed, 206 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac Fri Aug 10 23:06:50 2007 +0300 +++ b/configure.ac Sat Aug 11 01:52:28 2007 +0300 @@ -1225,6 +1225,22 @@ AC_MSG_RESULT([*** mms plugin disabled by request ***]) fi + +dnl *** MTP Upload + +AC_ARG_ENABLE(mtp_up, +[ --enable-mtp_up enable mtp upload support. (default=disabled)], +[have_mtp_up=$enableval], +[have_mtp_up=no]) + +if test "x$have_mtp_up" = "xyes"; then + have_mtp_up=yes + PKG_CHECK_MODULES(MTP, [libmtp >= 0.1.0], [GENERAL_PLUGINS="$GENERAL_PLUGINS mtp_up" ], [have_mtp_up="no"]) + MTP_LIBS=`pkg-config --libs libmtp` +else + have_mtp_up=no +fi + dnl *** libparanormal checks AC_ARG_ENABLE(paranormal, @@ -1501,6 +1517,7 @@ echo " Control via event device (evdev-plug): $have_evdevplug" echo " LIRC: $have_lirc" echo " AudioScrobbler Client: $scrobbler" +echo " Upload to MTP device: $have_mtp_up" echo echo " Effect" echo " ------"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mtp_up/Makefile Sat Aug 11 01:52:28 2007 +0300 @@ -0,0 +1,19 @@ +include ../../mk/rules.mk +include ../../mk/init.mk + +SUBDIRS = + +OBJECTIVE_LIBS = libmtp_up$(SHARED_SUFFIX) + +LIBDIR = $(plugindir)/$(GENERAL_PLUGIN_DIR) + +LIBADD += $(MTP_LIBS) $(GTK_LIBS) $(GLIB_LIBS) $(PANGO_LIBS) +SOURCES = mtp.c + +CFLAGS += $(PICFLAGS) $(GTK_CFLAGS) $(GLIB_CFLAGS) $(PANGO_CFLAGS) $(BEEP_DEFINES) -I../../intl -I../.. + +CFLAGS += -Wall -pedantic -std=c99 $(GCC42_CFLAGS) -D_BSD_SOURCE + +OBJECTS = ${SOURCES:.c=.o} + +include ../../mk/objective.mk
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mtp_up/mtp.c Sat Aug 11 01:52:28 2007 +0300 @@ -0,0 +1,170 @@ +/* + * Audacious MTP upload plugin + * + * Copyright (c) 2007 Cristian Magherusan <majeru@atheme.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses>. + */ + +#include <glib.h> +#include <libmtp.h> +#include <audacious/plugin.h> +#include <audacious/playlist.h> +#include <audacious/ui_plugin_menu.h> +#define DEBUG 1 + +GMutex * mutex = NULL; +gboolean mtp_initialised = FALSE; +LIBMTP_mtpdevice_t *mtp_device = NULL; +LIBMTP_progressfunc_t *callback; +LIBMTP_file_t *filelist; +Playlist *active_playlist; + +void mtp_init ( void ); +void mtp_cleanup ( void ); +void mtp_prefs ( void ); +void mtp_about ( void ); + +GeneralPlugin mtp_gp = +{ + NULL, /* handle */ + NULL, /* filename */ + "MTP Upload " , /* description */ + mtp_init, /* init */ + mtp_about, /* about */ + mtp_prefs, /* configure */ + mtp_cleanup /* cleanup */ +}; +GtkWidget *menuitem; + +GeneralPlugin *mtp_gplist[] = { &mtp_gp, NULL }; +DECLARE_PLUGIN(mtp_gp, NULL, NULL, NULL, NULL, NULL, mtp_gplist, NULL, NULL) + + +gpointer upload(gpointer arg) +{ + Playlist *current_play; + Tuple *tuple; + gchar *from_path; + gchar *comp; + char *filename; + uint64_t filesize; + struct stat sb; + LIBMTP_file_t *genfile; + int ret; + uint32_t parent_id = 0; + GList *node; + PlaylistEntry *entry; + current_play = g_new0(Playlist,1); + current_play = playlist_get_active(); + node = current_play->entries; + PLAYLIST_LOCK(current_play->mutex); /*needed so that the user doesn't modify the selection*/ + while (node) { + entry = PLAYLIST_ENTRY(node->data); + if (entry->selected) + { + tuple = entry->tuple; + from_path = g_strdup_printf("%s/%s", tuple_get_string(tuple, "file-path"), tuple_get_string(tuple, "file-name")); + comp = g_strescape(from_path,NULL); + if ( stat(from_path, &sb) == -1 ) + { +#if DEBUG + g_print("ERROR!"); +#endif + return NULL; + } + filesize = (uint64_t) sb.st_size; + filename = basename(from_path); + parent_id = 0; + genfile = LIBMTP_new_file_t(); + genfile->filesize = filesize; + genfile->filename = strdup(filename); +#if DEBUG + g_print("Uploading track '%s'\n",comp); +#endif + ret = LIBMTP_Send_File_From_File(mtp_device,comp , genfile, NULL , NULL, parent_id); +#if DEBUG + if (ret == 0) + g_print("Upload finished!\n"); + else + g_print("An error has occured while uploading '%s'...\nUpload failed!!!",comp); +#endif + LIBMTP_destroy_file_t(genfile); + g_free(from_path); + g_free(comp); + entry->selected = FALSE; + } + node = g_list_next(node); + } + PLAYLIST_UNLOCK(current_play->mutex); + return NULL; +} + + void +mtp_prefs ( void ) +{ + /*pref stub*/ +} + + + void +mtp_about ( void ) +{ + /*about stub*/ +} + +void mtp_press() +{ + if(!mutex) + return; + g_mutex_lock(mutex); + if(!mtp_initialised) + { +#if DEBUG + g_print("Initializing the MTP device...\n"); +#endif + mtp_device = LIBMTP_Get_First_Device(); + mtp_initialised = TRUE; + } + g_mutex_unlock(mutex); + if(mtp_device == NULL) + { +#if DEBUG + g_print("No MTP devices have been found !!!"); +#endif + return; + + } + g_thread_create(upload,NULL,FALSE,NULL); +} + +void mtp_init(void) +{ + menuitem=gtk_menu_item_new_with_label("Upload to MTP"); + gtk_widget_show (menuitem); + audacious_menu_plugin_item_add(AUDACIOUS_MENU_PLAYLIST_RCLICK, menuitem); + g_signal_connect (G_OBJECT (menuitem), "button_press_event",G_CALLBACK (mtp_press), NULL); + LIBMTP_Init(); + mutex = g_mutex_new(); +} + +void mtp_cleanup(void) +{ +#if DEBUG + g_print("Cleaning up MTP_upload\n"); +#endif +// audacious_menu_plugin_item_remove(AUDACIOUS_MENU_PLAYLIST, menuitem ); + g_mutex_free (mutex); + mutex = NULL; +} +