Mercurial > audlegacy-plugins
annotate 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 |
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> |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
20 #include <libmtp.h> |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
21 #include <audacious/plugin.h> |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
22 #include <audacious/playlist.h> |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
23 #include <audacious/ui_plugin_menu.h> |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
24 #define DEBUG 1 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
25 |
1471
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
26 #define DEFAULT_LABEL "Upload to MTP device" |
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
27 #define DISABLED_LABEL "MTP upload in progress..." |
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
28 |
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
29 |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
30 GMutex * mutex = NULL; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
31 gboolean mtp_initialised = FALSE; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
32 LIBMTP_mtpdevice_t *mtp_device = NULL; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
33 LIBMTP_progressfunc_t *callback; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
34 LIBMTP_file_t *filelist; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
35 Playlist *active_playlist; |
1493
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
36 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
|
37 |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
38 void mtp_init ( void ); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
39 void mtp_cleanup ( void ); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
40 void mtp_prefs ( void ); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
41 void mtp_about ( void ); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
42 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
43 GeneralPlugin mtp_gp = |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
44 { |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
45 NULL, /* handle */ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
46 NULL, /* filename */ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
47 "MTP Upload " , /* description */ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
48 mtp_init, /* init */ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
49 mtp_about, /* about */ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
50 mtp_prefs, /* configure */ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
51 mtp_cleanup /* cleanup */ |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
52 }; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
53 GtkWidget *menuitem; |
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 |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
58 GList * get_upload_list() |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
59 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
60 Tuple *tuple; |
1493
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
61 gchar *from_path,*uri; |
1491
c2fa3728df43
URI-fication
Cristi Magherusan <majeru@atheme-project.org>
parents:
1474
diff
changeset
|
62 VFSFile*f; |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
63 GList *node=NULL,*up_list=NULL; |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
64 PlaylistEntry *entry; |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
65 Playlist *current_play = playlist_get_active(); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
66 |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
67 node = current_play->entries; |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
68 PLAYLIST_LOCK(current_play->mutex); /*needed so that the user doesn't modify the selection*/ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
69 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
|
70 { |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
71 entry = PLAYLIST_ENTRY(node->data); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
72 if (entry->selected) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
73 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
74 tuple = entry->tuple; |
1492
5a44698a302b
fixed the upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1491
diff
changeset
|
75 from_path = g_strdup_printf("%s/%s", tuple_get_string(tuple, "file-path"), tuple_get_string(tuple, "file-name")); |
1493
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
76 uri=g_filename_to_uri(from_path,NULL,NULL); |
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
77 f = vfs_fopen(uri,"r"); |
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
78 g_free(uri); |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
79 if(!vfs_is_streaming(f)) |
1493
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
80 up_list=g_list_prepend(up_list,from_path); |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
81 vfs_fclose(f); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
82 entry->selected = FALSE; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
83 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
84 node = g_list_next(node); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
85 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
86 PLAYLIST_UNLOCK(current_play->mutex); |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
87 return g_list_reverse(up_list); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
88 } |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
89 |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
90 void upload_file(gchar *from_path) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
91 { |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
92 int ret; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
93 gchar *comp, *filename; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
94 uint64_t filesize; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
95 uint32_t parent_id = 0; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
96 struct stat sb; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
97 LIBMTP_file_t *genfile; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
98 |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
99 comp = g_strescape(from_path,NULL); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
100 if ( stat(from_path, &sb) == -1 ) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
101 { |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
102 #if DEBUG |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
103 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
|
104 #endif |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
105 return; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
106 } |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
107 filesize = (uint64_t) sb.st_size; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
108 filename = g_path_get_basename(from_path); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
109 parent_id = 0; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
110 genfile = LIBMTP_new_file_t(); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
111 genfile->filesize = filesize; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
112 genfile->filename = strdup(filename); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
113 #if DEBUG |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
114 g_print("Uploading track '%s'\n",comp); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
115 #endif |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
116 ret = LIBMTP_Send_File_From_File(mtp_device, comp , genfile, NULL , NULL, parent_id); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
117 #if DEBUG |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
118 if (ret == 0) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
119 g_print("Upload finished!\n"); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
120 else |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
121 g_print("An error has occured while uploading '%s'...\nUpload failed!!!",comp); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
122 #endif |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
123 LIBMTP_destroy_file_t(genfile); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
124 g_free(filename); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
125 g_free(comp); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
126 } |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
127 |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
128 |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
129 gpointer upload(gpointer arg) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
130 { |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
131 if(!mutex) |
1474
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
132 { |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
133 gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))),DEFAULT_LABEL); |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
134 gtk_widget_set_sensitive(menuitem, TRUE); |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
135 return NULL; |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
136 } |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
137 g_mutex_lock(mutex); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
138 if(!mtp_device) |
1474
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
139 { |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
140 gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))),DEFAULT_LABEL); |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
141 gtk_widget_set_sensitive(menuitem, TRUE); |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
142 g_mutex_unlock(mutex); |
1471
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
143 return NULL; |
1474
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
144 } |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
145 |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
146 gchar* from_path; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
147 GList *up_list=NULL,*node; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
148 node=up_list=get_upload_list(); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
149 while(node) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
150 { |
1493
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
151 if(exiting) |
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
152 { |
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
153 g_print("\nCancelling pending uploads...\n\n"); |
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
154 break; |
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
155 } |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
156 from_path=(gchar*)(node->data); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
157 upload_file(from_path); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
158 node = g_list_next(node); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
159 } |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
160 g_list_free(up_list); |
1471
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
161 |
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
162 gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))),DEFAULT_LABEL); |
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
163 gtk_widget_set_sensitive(menuitem, TRUE); |
1474
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
164 g_mutex_unlock(mutex); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
165 return NULL; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
166 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
167 |
1474
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
168 void mtp_prefs ( void ) |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
169 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
170 /*pref stub*/ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
171 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
172 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
173 |
1474
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
174 void mtp_about ( void ) |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
175 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
176 /*about stub*/ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
177 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
178 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
179 void mtp_press() |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
180 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
181 if(!mutex) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
182 return; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
183 g_mutex_lock(mutex); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
184 if(!mtp_initialised) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
185 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
186 #if DEBUG |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
187 g_print("Initializing the MTP device...\n"); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
188 #endif |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
189 LIBMTP_Init(); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
190 mtp_device = LIBMTP_Get_First_Device(); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
191 mtp_initialised = TRUE; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
192 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
193 g_mutex_unlock(mutex); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
194 if(mtp_device == NULL) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
195 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
196 #if DEBUG |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
197 g_print("No MTP devices have been found !!!"); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
198 #endif |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
199 return; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
200 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
201 } |
1471
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
202 gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))),DISABLED_LABEL); |
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
203 gtk_widget_set_sensitive(menuitem, FALSE); |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
204 g_thread_create(upload,NULL,FALSE,NULL); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
205 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
206 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
207 void mtp_init(void) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
208 { |
1471
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
209 menuitem=gtk_menu_item_new_with_label(DEFAULT_LABEL); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
210 gtk_widget_show (menuitem); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
211 audacious_menu_plugin_item_add(AUDACIOUS_MENU_PLAYLIST_RCLICK, menuitem); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
212 g_signal_connect (G_OBJECT (menuitem), "button_press_event",G_CALLBACK (mtp_press), NULL); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
213 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
|
214 plugin_active = TRUE; |
1493
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
215 exiting=FALSE; |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
216 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
217 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
218 void mtp_cleanup(void) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
219 { |
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
|
220 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
|
221 { |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
222 |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
223 #if DEBUG |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
224 if(mtp_initialised) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
225 g_print("\n\n !!!CAUTION!!! \n\n" |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
226 "Cleaning up MTP upload plugin, please wait!!!...\n" |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
227 "!!! 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
|
228 "Waiting for the MTP mutex to unlock...\n"); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
229 #endif |
1493
f9310819285c
the pending uploads are cancelled on exit, so it doesnt lock anymore while cleaning up
Cristi Magherusan <majeru@atheme-project.org>
parents:
1492
diff
changeset
|
230 exiting=TRUE; |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
231 if(mutex) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
232 g_mutex_lock(mutex); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
233 if(mtp_device!= NULL) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
234 { |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
235 LIBMTP_Release_Device(mtp_device); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
236 mtp_device = NULL; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
237 } |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
238 g_mutex_unlock(mutex); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
239 #if DEBUG |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
240 if(mtp_initialised) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
241 g_print("The MTP mutex has been unlocked\n"); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
242 #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
|
243 audacious_menu_plugin_item_remove(AUDACIOUS_MENU_PLAYLIST_RCLICK, menuitem); |
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
|
244 gtk_widget_destroy(menuitem); |
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
|
245 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
|
246 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
|
247 plugin_active = FALSE; |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
248 #if DEBUG |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
249 if(mtp_initialised) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
250 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
|
251 #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
|
252 } |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
253 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
254 |