annotate src/mtp_up/mtp.c @ 2149:cf20f1bd2f1e

- updated German translation - cleaned up alarm, mtp_up and song_change plugins
author mf0102 <0102@gmx.at>
date Thu, 01 Nov 2007 21:20:20 +0100
parents cf4fa45ffd80
children 5ba49a9c053c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
1 /*
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
2 * Audacious MTP upload plugin
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
3 *
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
4 * Copyright (c) 2007 Cristian Magherusan <majeru@atheme.org>
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
5 *
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
8 * the Free Software Foundation; under version 3 of the License.
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
9 *
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
13 * GNU General Public License for more details.
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
14 *
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses>.
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
17 */
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
18
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
19 #include <glib.h>
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
20 #include <sys/types.h>
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
21 #include <libmtp.h>
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
22 #include <audacious/plugin.h>
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
23 #include <audacious/playlist.h>
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
24 #include <audacious/ui_plugin_menu.h>
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
25
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
26 #include <gtk/gtk.h>
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
27 #include <audacious/util.h>
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
28 #include "filetype.h"
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
29 #define DEBUG 1
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
30
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
31 #define ROOT_LABEL "MTP device handler"
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
32 #define UP_DEFAULT_LABEL "Upload selected track(s)"
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
33 #define UP_BUSY_LABEL "Upload in progress..."
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
34 #define FREE_LABEL "Disconnect the device"
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
35 GMutex * mutex = NULL;
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
36 gboolean mtp_initialised = FALSE;
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
37 LIBMTP_mtpdevice_t *mtp_device = NULL;
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
38 LIBMTP_progressfunc_t *callback;
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
39 LIBMTP_file_t *filelist;
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
40 Playlist *active_playlist;
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
41
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
42 static gboolean plugin_active = FALSE,exiting=FALSE;
1461
161d289f335c do not assume that mtp_cleanup is only called after mtp_init (it's not true for general plugins); also, destroy the menuitem as it seems that it still holds a reference after being removed from its menushell
Giacomo Lozito <james@develia.org>
parents: 1458
diff changeset
43
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
44 void mtp_init ( void );
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
45 void mtp_cleanup ( void );
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
46
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
47 GeneralPlugin mtp_gp =
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
48 {
2149
cf20f1bd2f1e - updated German translation
mf0102 <0102@gmx.at>
parents: 2057
diff changeset
49 .description = "MTP Upload",
cf20f1bd2f1e - updated German translation
mf0102 <0102@gmx.at>
parents: 2057
diff changeset
50 .init = mtp_init,
cf20f1bd2f1e - updated German translation
mf0102 <0102@gmx.at>
parents: 2057
diff changeset
51 .cleanup = mtp_cleanup
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
52 };
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
53 GtkWidget *mtp_root_menuitem,*mtp_submenu_item_up,*mtp_submenu_item_free,*mtp_submenu;
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
54
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
55 GeneralPlugin *mtp_gplist[] = { &mtp_gp, NULL };
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
56 DECLARE_PLUGIN(mtp_gp, NULL, NULL, NULL, NULL, NULL, mtp_gplist, NULL, NULL)
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
57
1497
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
58
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
59 void show_dialog(const gchar* message)
1497
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
60 {
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
61 GDK_THREADS_ENTER();
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
62 GtkWidget *dialog = gtk_message_dialog_new (NULL,
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
63 GTK_DIALOG_MODAL,
1497
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
64 GTK_MESSAGE_ERROR,
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
65 GTK_BUTTONS_OK,
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
66 message);
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
67 gtk_dialog_run (GTK_DIALOG (dialog));
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
68 gtk_widget_show(dialog);
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
69 /* gtk_widget_destroy(dialog); */
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
70 GDK_THREADS_LEAVE();
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
71
1497
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
72 }
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
73
1518
abdb27a70322 now i'm free'ing the metadata struct
Cristi Magherusan <majeru@atheme-project.org>
parents: 1517
diff changeset
74 gboolean free_device(void)
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
75 {
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
76 #if DEBUG
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
77 if(mtp_initialised)
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
78 g_print("\n\n !!!CAUTION!!! \n\n"
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
79 "Cleaning up MTP upload plugin, please wait!!!...\n"
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
80 "This will block until the pending tracks are uploaded,\n"
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
81 "then it will gracefully close your device\n\n"
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
82 "!!! FORCING SHUTDOWN NOW MAY CAUSE DAMAGE TO YOUR DEVICE !!!\n\n\n"
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
83 "Waiting for the MTP mutex to unlock...\n");
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
84 #endif
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
85 if(!mutex)
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
86 return TRUE;
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
87 g_mutex_lock(mutex);
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
88 if(mtp_device!= NULL)
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
89 {
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
90 LIBMTP_Release_Device(mtp_device);
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
91 mtp_device = NULL;
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
92 mtp_initialised = FALSE;
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
93 gtk_widget_hide(mtp_submenu_item_free);
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
94 }
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
95 g_mutex_unlock(mutex);
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
96 return TRUE;
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
97 }
1497
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
98
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
99 GList * get_upload_list()
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
100 {
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
101 Tuple *tuple;
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
102 GList *node=NULL,*up_list=NULL;
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
103 PlaylistEntry *entry;
2057
cf4fa45ffd80 playlist API vtabling
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
104 Playlist *current_play = aud_playlist_get_active();
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
105
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
106 node = current_play->entries;
1675
ae9b0327b620 Fix plugins to conform with PLAYLIST_{UN}LOCK() change.
Matti Hamalainen <ccr@tnsp.org>
parents: 1522
diff changeset
107 PLAYLIST_LOCK(current_play); /*needed so that the user doesn't modify the selection*/
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
108 while (node) /*while creating the list of files to be uploaded*/
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
109 {
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
110 entry = PLAYLIST_ENTRY(node->data);
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
111 if (entry->selected)
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
112 {
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
113 tuple = entry->tuple;
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
114 up_list=g_list_prepend(up_list,tuple);
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
115 entry->selected = FALSE;
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
116 }
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
117 node = g_list_next(node);
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
118 }
1675
ae9b0327b620 Fix plugins to conform with PLAYLIST_{UN}LOCK() change.
Matti Hamalainen <ccr@tnsp.org>
parents: 1522
diff changeset
119 PLAYLIST_UNLOCK(current_play);
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
120 return g_list_reverse(up_list);
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
121 }
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
122
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
123 LIBMTP_track_t *track_metadata(Tuple *from_tuple)
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
124 {
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
125 LIBMTP_track_t *tr;
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
126 gchar *filename, *from_path;
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
127 VFSFile *f;
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
128 uint64_t filesize;
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
129 uint32_t parent_id = 0;
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
130 struct stat sb;
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
131
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1702
diff changeset
132 from_path = g_strdup_printf("%s/%s", aud_tuple_get_string(from_tuple, FIELD_FILE_PATH, NULL), aud_tuple_get_string(from_tuple, FIELD_FILE_NAME, NULL));
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
133 gchar *tmp;
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
134 tmp = g_strescape(from_path,NULL);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
135 filename=g_filename_from_uri(tmp,NULL,NULL);
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
136 /* dealing the stream upload (invalidating)*/
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
137 if(filename)
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
138 {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
139 f = aud_vfs_fopen(from_path,"r");
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
140 if(aud_vfs_is_streaming(f))
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
141 {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1976
diff changeset
142 aud_vfs_fclose(f);
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
143 return NULL;
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
144 }
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
145 }
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
146
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
147 if ( stat(from_path, &sb) == -1 )
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
148 {
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
149 #if DEBUG
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
150 g_print("ERROR! encountered while stat()'ing \"%s\"\n",from_path);
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
151 #endif
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
152 return NULL;
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
153 }
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
154 filesize = (uint64_t) sb.st_size;
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
155 parent_id = mtp_device->default_music_folder;
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
156
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
157 /* track metadata*/
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
158 tr = LIBMTP_new_track_t();
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1702
diff changeset
159 tr->title = g_strdup((gchar*) aud_tuple_get_string(from_tuple, FIELD_TITLE, NULL));
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1702
diff changeset
160 tr->artist = g_strdup((gchar*) aud_tuple_get_string(from_tuple, FIELD_ARTIST, NULL));
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1702
diff changeset
161 tr->album = g_strdup((gchar*)aud_tuple_get_string(from_tuple, FIELD_ALBUM, NULL));
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
162 tr->filesize = filesize;
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1702
diff changeset
163 tr->filename = g_strdup(aud_tuple_get_string(from_tuple, FIELD_FILE_NAME, NULL));
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1702
diff changeset
164 tr->duration = (uint32_t)aud_tuple_get_int(from_tuple, FIELD_LENGTH, NULL);
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
165 tr->filetype = find_filetype (from_path);
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1702
diff changeset
166 tr->genre = g_strdup((gchar*)aud_tuple_get_string(from_tuple, FIELD_GENRE, NULL));
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1702
diff changeset
167 tr->date = g_strdup_printf("%d",aud_tuple_get_int(from_tuple, FIELD_YEAR, NULL));
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
168 g_free(filename);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
169 g_free(from_path);
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
170 g_free(tmp);
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
171 return tr;
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
172 }
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
173
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
174 gint upload_file(Tuple *from_tuple)
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
175 {
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
176 int ret;
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
177 gchar *comp, *from_path = NULL;
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
178 uint32_t parent_id = 0;
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
179 LIBMTP_track_t *gentrack;
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
180 gentrack = track_metadata(from_tuple);
1976
5fa26178eaef s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents: 1702
diff changeset
181 from_path = g_strdup_printf("%s/%s", aud_tuple_get_string(from_tuple, FIELD_FILE_PATH, NULL), aud_tuple_get_string(from_tuple, FIELD_FILE_NAME, NULL));
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
182 if(gentrack == NULL) return 1;
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
183 comp = g_strescape(from_path,NULL);
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
184 g_free(from_path);
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
185 parent_id = mtp_device->default_music_folder;
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
186
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
187 #if DEBUG
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
188 g_print("Uploading track '%s'\n",comp);
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
189 #endif
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
190 ret = LIBMTP_Send_Track_From_File(mtp_device, comp , gentrack, NULL , NULL, parent_id);
1518
abdb27a70322 now i'm free'ing the metadata struct
Cristi Magherusan <majeru@atheme-project.org>
parents: 1517
diff changeset
191 LIBMTP_destroy_track_t(gentrack);
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
192 g_free(comp);
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
193 if (ret == 0)
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
194 g_print("Track upload finished!\n");
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
195 else
1494
63144ea14b50 handling device disconnected errors
Cristi Magherusan <majeru@atheme-project.org>
parents: 1491
diff changeset
196 {
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
197 g_print("An error has occured while uploading '%s'...\nUpload failed!!!\n\n",comp);
1494
63144ea14b50 handling device disconnected errors
Cristi Magherusan <majeru@atheme-project.org>
parents: 1491
diff changeset
198 mtp_initialised = FALSE;
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
199 return 1;
1494
63144ea14b50 handling device disconnected errors
Cristi Magherusan <majeru@atheme-project.org>
parents: 1491
diff changeset
200 }
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
201
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
202 return 0;
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
203 }
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
204
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
205
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
206 gpointer upload(gpointer arg)
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
207 {
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
208 gtk_widget_hide(mtp_submenu_item_free);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
209 if(!mutex)
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
210 {
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
211 gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(mtp_submenu_item_up))),UP_DEFAULT_LABEL);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
212 gtk_widget_set_sensitive(mtp_submenu_item_up, TRUE);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
213 return NULL;
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
214 }
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
215 g_mutex_lock(mutex);
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
216 if(!mtp_device)
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
217 {
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
218 gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(mtp_submenu_item_up))),UP_DEFAULT_LABEL);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
219 gtk_widget_set_sensitive(mtp_submenu_item_up, TRUE);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
220 g_mutex_unlock(mutex);
1494
63144ea14b50 handling device disconnected errors
Cristi Magherusan <majeru@atheme-project.org>
parents: 1491
diff changeset
221 return NULL;
63144ea14b50 handling device disconnected errors
Cristi Magherusan <majeru@atheme-project.org>
parents: 1491
diff changeset
222 }
1474
10791910b866 the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents: 1471
diff changeset
223
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
224 Tuple* tuple;
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
225 GList *up_list=NULL,*node;
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
226 node=up_list=get_upload_list();
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
227 gint up_err=0;
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
228 while(node)
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
229 {
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
230 tuple=(Tuple*)(node->data);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
231 up_err = upload_file(tuple);
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
232 if(up_err )
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
233 {
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
234 /*show_dialog("An error has occured while uploading...\nUpload failed!");*/
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
235 break;
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
236 }
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
237 if(exiting)
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
238 {
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
239 /*show_dialog("Shutting down MTP while uploading.\nPending uploads were cancelled");*/
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
240 break;
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
241 }
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
242
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
243 node = g_list_next(node);
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
244 }
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
245 g_list_free(up_list);
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
246 gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(mtp_submenu_item_up))),UP_DEFAULT_LABEL);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
247 gtk_widget_set_sensitive(mtp_submenu_item_up, TRUE);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
248 g_mutex_unlock(mutex);
1497
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
249 #if DEBUG
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
250 g_print("MTP upload process finished\n");
1497
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
251 #endif
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
252 gtk_widget_show(mtp_submenu_item_free);
1497
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
253 g_thread_exit(NULL);
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
254 return NULL;
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
255 }
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
256
1518
abdb27a70322 now i'm free'ing the metadata struct
Cristi Magherusan <majeru@atheme-project.org>
parents: 1517
diff changeset
257 gboolean mtp_press()
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
258 {
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
259 if(!mutex)
1518
abdb27a70322 now i'm free'ing the metadata struct
Cristi Magherusan <majeru@atheme-project.org>
parents: 1517
diff changeset
260 return TRUE;
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
261 g_mutex_lock(mutex);
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
262 if(!mtp_initialised)
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
263 {
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
264 #if DEBUG
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
265 g_print("Initializing the MTP device...\n");
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
266 #endif
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
267 LIBMTP_Init();
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
268 mtp_device = LIBMTP_Get_First_Device();
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
269 mtp_initialised = TRUE;
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
270 gtk_widget_show(mtp_submenu_item_free);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
271
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
272 }
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
273 g_mutex_unlock(mutex);
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
274 if(mtp_device == NULL)
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
275 {
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
276 #if DEBUG
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
277 g_print("No MTP devices have been found !!!\n");
1497
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
278 #endif
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
279 /* show_dialog("No MTP devices have been found !!!"); */
1497
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
280 mtp_initialised = FALSE;
1518
abdb27a70322 now i'm free'ing the metadata struct
Cristi Magherusan <majeru@atheme-project.org>
parents: 1517
diff changeset
281 return TRUE;
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
282
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
283 }
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
284 gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(mtp_submenu_item_up))),UP_BUSY_LABEL);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
285 gtk_widget_set_sensitive(mtp_submenu_item_up, FALSE);
1497
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
286 g_thread_create(upload,NULL,FALSE,NULL);
1518
abdb27a70322 now i'm free'ing the metadata struct
Cristi Magherusan <majeru@atheme-project.org>
parents: 1517
diff changeset
287 return TRUE;
1497
318e3bcdf51d some fixes, more debug info
Cristi Magherusan <majeru@atheme-project.org>
parents: 1495
diff changeset
288
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
289 }
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
290
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
291 void mtp_init(void)
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
292 {
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
293 mtp_root_menuitem=gtk_menu_item_new_with_label(ROOT_LABEL);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
294 mtp_submenu=gtk_menu_new();
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
295
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
296 mtp_submenu_item_up=gtk_menu_item_new_with_label(UP_DEFAULT_LABEL);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
297 mtp_submenu_item_free=gtk_menu_item_new_with_label(FREE_LABEL);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
298
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
299
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
300 gtk_menu_shell_append (GTK_MENU_SHELL (mtp_submenu), mtp_submenu_item_up);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
301 gtk_widget_show (mtp_submenu_item_up);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
302
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
303 gtk_menu_shell_append (GTK_MENU_SHELL (mtp_submenu), mtp_submenu_item_free);
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
304
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
305 gtk_menu_item_set_submenu(GTK_MENU_ITEM(mtp_root_menuitem),mtp_submenu);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
306 gtk_widget_show (mtp_submenu);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
307 gtk_widget_show (mtp_root_menuitem);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
308
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
309
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
310 audacious_menu_plugin_item_add(AUDACIOUS_MENU_PLAYLIST_RCLICK, mtp_root_menuitem);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
311 g_signal_connect (G_OBJECT (mtp_submenu_item_up), "button_press_event",G_CALLBACK (mtp_press), NULL);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
312 g_signal_connect (G_OBJECT (mtp_submenu_item_free), "button_press_event",G_CALLBACK (free_device), NULL);
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
313
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
314 mutex = g_mutex_new();
1461
161d289f335c do not assume that mtp_cleanup is only called after mtp_init (it's not true for general plugins); also, destroy the menuitem as it seems that it still holds a reference after being removed from its menushell
Giacomo Lozito <james@develia.org>
parents: 1458
diff changeset
315 plugin_active = TRUE;
1500
611d8db6b421 made it enabled by default if having libmtp, fixes Chainsaw's bug and adds some improvements
Cristi Magherusan <majeru@atheme-project.org>
parents: 1497
diff changeset
316 exiting=FALSE;
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
317 }
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
318
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
319 void mtp_cleanup(void)
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
320 {
1461
161d289f335c do not assume that mtp_cleanup is only called after mtp_init (it's not true for general plugins); also, destroy the menuitem as it seems that it still holds a reference after being removed from its menushell
Giacomo Lozito <james@develia.org>
parents: 1458
diff changeset
321 if (plugin_active)
161d289f335c do not assume that mtp_cleanup is only called after mtp_init (it's not true for general plugins); also, destroy the menuitem as it seems that it still holds a reference after being removed from its menushell
Giacomo Lozito <james@develia.org>
parents: 1458
diff changeset
322 {
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
323
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
324 #if DEBUG
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
325 if(mtp_initialised)
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
326 {
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
327 g_print("\n\n !!!CAUTION!!! \n\n"
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
328 "Cleaning up MTP upload plugin, please wait!!!...\n"
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
329 "This will block until the pending tracks are uploaded,\n"
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
330 "then it will gracefully close your device\n\n"
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
331 "!!! FORCING SHUTDOWN NOW MAY CAUSE DAMAGE TO YOUR DEVICE !!!\n\n\n"
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
332 "Waiting for the MTP mutex to unlock...\n");
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
333 exiting=TRUE;
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
334 }
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
335 #endif
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
336 if(mutex)
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
337 g_mutex_lock(mutex);
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
338 if(mtp_device!= NULL)
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
339 {
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
340 LIBMTP_Release_Device(mtp_device);
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
341 mtp_device = NULL;
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
342 }
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
343 g_mutex_unlock(mutex);
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
344 #if DEBUG
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
345 if(mtp_initialised)
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
346 g_print("The MTP mutex has been unlocked\n");
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
347 #endif
1517
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
348 audacious_menu_plugin_item_remove(AUDACIOUS_MENU_PLAYLIST_RCLICK, mtp_root_menuitem);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
349 gtk_widget_destroy(mtp_submenu_item_up);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
350
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
351 gtk_widget_destroy(mtp_submenu_item_up);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
352 gtk_widget_destroy(mtp_submenu_item_free);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
353
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
354 gtk_widget_destroy(mtp_submenu);
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
355
d72a44fdb6a3 switched to uploading tracks instead of files, added disconnect option, other misc. fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1500
diff changeset
356 gtk_widget_destroy(mtp_root_menuitem);
1522
88f5ba93f3dd fixed filename
Cristi Magherusan <majeru@atheme-project.org>
parents: 1518
diff changeset
357
1461
161d289f335c do not assume that mtp_cleanup is only called after mtp_init (it's not true for general plugins); also, destroy the menuitem as it seems that it still holds a reference after being removed from its menushell
Giacomo Lozito <james@develia.org>
parents: 1458
diff changeset
358 g_mutex_free (mutex);
161d289f335c do not assume that mtp_cleanup is only called after mtp_init (it's not true for general plugins); also, destroy the menuitem as it seems that it still holds a reference after being removed from its menushell
Giacomo Lozito <james@develia.org>
parents: 1458
diff changeset
359 mutex = NULL;
161d289f335c do not assume that mtp_cleanup is only called after mtp_init (it's not true for general plugins); also, destroy the menuitem as it seems that it still holds a reference after being removed from its menushell
Giacomo Lozito <james@develia.org>
parents: 1458
diff changeset
360 plugin_active = FALSE;
1468
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
361 #if DEBUG
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
362 if(mtp_initialised)
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
363 g_print("MTP upload plugin has been cleaned up successfully\n");
159186076d9a lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents: 1461
diff changeset
364 #endif
1461
161d289f335c do not assume that mtp_cleanup is only called after mtp_init (it's not true for general plugins); also, destroy the menuitem as it seems that it still holds a reference after being removed from its menushell
Giacomo Lozito <james@develia.org>
parents: 1458
diff changeset
365 }
1456
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
366 }
475eac76a8ba MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
367