comparison src/mtp_up/mtp.c @ 1493:f9310819285c

the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
author Cristi Magherusan <majeru@atheme-project.org>
date Tue, 14 Aug 2007 23:33:33 +0300
parents 5a44698a302b
children aad7eb04f0b5
comparison
equal deleted inserted replaced
1492:5a44698a302b 1493:f9310819285c
31 gboolean mtp_initialised = FALSE; 31 gboolean mtp_initialised = FALSE;
32 LIBMTP_mtpdevice_t *mtp_device = NULL; 32 LIBMTP_mtpdevice_t *mtp_device = NULL;
33 LIBMTP_progressfunc_t *callback; 33 LIBMTP_progressfunc_t *callback;
34 LIBMTP_file_t *filelist; 34 LIBMTP_file_t *filelist;
35 Playlist *active_playlist; 35 Playlist *active_playlist;
36 36 static gboolean plugin_active = FALSE,exiting=FALSE;
37 static gboolean plugin_active = FALSE;
38 37
39 void mtp_init ( void ); 38 void mtp_init ( void );
40 void mtp_cleanup ( void ); 39 void mtp_cleanup ( void );
41 void mtp_prefs ( void ); 40 void mtp_prefs ( void );
42 void mtp_about ( void ); 41 void mtp_about ( void );
57 DECLARE_PLUGIN(mtp_gp, NULL, NULL, NULL, NULL, NULL, mtp_gplist, NULL, NULL) 56 DECLARE_PLUGIN(mtp_gp, NULL, NULL, NULL, NULL, NULL, mtp_gplist, NULL, NULL)
58 57
59 GList * get_upload_list() 58 GList * get_upload_list()
60 { 59 {
61 Tuple *tuple; 60 Tuple *tuple;
62 gchar *from_path,*filename; 61 gchar *from_path,*uri;
63 VFSFile*f; 62 VFSFile*f;
64 GList *node=NULL,*up_list=NULL; 63 GList *node=NULL,*up_list=NULL;
65 PlaylistEntry *entry; 64 PlaylistEntry *entry;
66 Playlist *current_play = playlist_get_active(); 65 Playlist *current_play = playlist_get_active();
67 66
72 entry = PLAYLIST_ENTRY(node->data); 71 entry = PLAYLIST_ENTRY(node->data);
73 if (entry->selected) 72 if (entry->selected)
74 { 73 {
75 tuple = entry->tuple; 74 tuple = entry->tuple;
76 from_path = g_strdup_printf("%s/%s", tuple_get_string(tuple, "file-path"), tuple_get_string(tuple, "file-name")); 75 from_path = g_strdup_printf("%s/%s", tuple_get_string(tuple, "file-path"), tuple_get_string(tuple, "file-name"));
77 g_print("From_path: '%s'",from_path); 76 uri=g_filename_to_uri(from_path,NULL,NULL);
78 f = vfs_fopen(from_path,"r"); 77 f = vfs_fopen(uri,"r");
78 g_free(uri);
79 if(!vfs_is_streaming(f)) 79 if(!vfs_is_streaming(f))
80 { 80 up_list=g_list_prepend(up_list,from_path);
81 filename=g_filename_from_uri(from_path,NULL,NULL);
82 g_print("Filename: '%s'\n",filename);
83 if(filename!= NULL)
84 {
85 up_list=g_list_prepend(up_list,filename);
86 g_free(from_path);
87 }
88 else
89 {
90 up_list=g_list_prepend(up_list,from_path);
91 g_free(filename);
92 }
93 }
94 vfs_fclose(f); 81 vfs_fclose(f);
95 entry->selected = FALSE; 82 entry->selected = FALSE;
96 } 83 }
97 node = g_list_next(node); 84 node = g_list_next(node);
98 } 85 }
159 gchar* from_path; 146 gchar* from_path;
160 GList *up_list=NULL,*node; 147 GList *up_list=NULL,*node;
161 node=up_list=get_upload_list(); 148 node=up_list=get_upload_list();
162 while(node) 149 while(node)
163 { 150 {
151 if(exiting)
152 {
153 g_print("\nCancelling pending uploads...\n\n");
154 break;
155 }
164 from_path=(gchar*)(node->data); 156 from_path=(gchar*)(node->data);
165 upload_file(from_path); 157 upload_file(from_path);
166 node = g_list_next(node); 158 node = g_list_next(node);
167 } 159 }
168 g_list_free(up_list); 160 g_list_free(up_list);
218 gtk_widget_show (menuitem); 210 gtk_widget_show (menuitem);
219 audacious_menu_plugin_item_add(AUDACIOUS_MENU_PLAYLIST_RCLICK, menuitem); 211 audacious_menu_plugin_item_add(AUDACIOUS_MENU_PLAYLIST_RCLICK, menuitem);
220 g_signal_connect (G_OBJECT (menuitem), "button_press_event",G_CALLBACK (mtp_press), NULL); 212 g_signal_connect (G_OBJECT (menuitem), "button_press_event",G_CALLBACK (mtp_press), NULL);
221 mutex = g_mutex_new(); 213 mutex = g_mutex_new();
222 plugin_active = TRUE; 214 plugin_active = TRUE;
215 exiting=FALSE;
223 } 216 }
224 217
225 void mtp_cleanup(void) 218 void mtp_cleanup(void)
226 { 219 {
227 if (plugin_active) 220 if (plugin_active)
229 222
230 #if DEBUG 223 #if DEBUG
231 if(mtp_initialised) 224 if(mtp_initialised)
232 g_print("\n\n !!!CAUTION!!! \n\n" 225 g_print("\n\n !!!CAUTION!!! \n\n"
233 "Cleaning up MTP upload plugin, please wait!!!...\n" 226 "Cleaning up MTP upload plugin, please wait!!!...\n"
234 "This will block until the pending tracks are uploaded,\n"
235 "then it will gracefully close your device\n\n"
236 "!!! FORCING SHUTDOWN NOW MAY CAUSE DAMAGE TO YOUR DEVICE !!!\n\n\n" 227 "!!! FORCING SHUTDOWN NOW MAY CAUSE DAMAGE TO YOUR DEVICE !!!\n\n\n"
237 "Waiting for the MTP mutex to unlock...\n"); 228 "Waiting for the MTP mutex to unlock...\n");
238 #endif 229 #endif
230 exiting=TRUE;
239 if(mutex) 231 if(mutex)
240 g_mutex_lock(mutex); 232 g_mutex_lock(mutex);
241 if(mtp_device!= NULL) 233 if(mtp_device!= NULL)
242 { 234 {
243 LIBMTP_Release_Device(mtp_device); 235 LIBMTP_Release_Device(mtp_device);