Mercurial > audlegacy-plugins
annotate src/mtp_up/mtp.c @ 1474:10791910b866
the label wasn't restored on failure
author | Cristi Magherusan <majeru@atheme-project.org> |
---|---|
date | Sat, 11 Aug 2007 18:10:34 +0300 |
parents | 355f8e284c94 |
children | c2fa3728df43 |
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; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
36 |
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 static gboolean plugin_active = FALSE; |
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
|
38 |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
39 void mtp_init ( void ); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
40 void mtp_cleanup ( void ); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
41 void mtp_prefs ( void ); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
42 void mtp_about ( void ); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
43 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
44 GeneralPlugin mtp_gp = |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
45 { |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
46 NULL, /* handle */ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
47 NULL, /* filename */ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
48 "MTP Upload " , /* description */ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
49 mtp_init, /* init */ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
50 mtp_about, /* about */ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
51 mtp_prefs, /* configure */ |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
52 mtp_cleanup /* cleanup */ |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
53 }; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
54 GtkWidget *menuitem; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
55 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
56 GeneralPlugin *mtp_gplist[] = { &mtp_gp, NULL }; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
57 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
|
58 |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
59 GList * get_upload_list() |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
60 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
61 Tuple *tuple; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
62 gchar *from_path; |
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; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
75 from_path = g_strdup_printf("%s/%s", tuple_get_string(tuple, "file-path"), tuple_get_string(tuple, "file-name")); |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
76 VFSFile* f = vfs_fopen(from_path,"r"); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
77 if(!vfs_is_streaming(f)) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
78 up_list=g_list_prepend(up_list,from_path); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
79 vfs_fclose(f); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
80 entry->selected = FALSE; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
81 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
82 node = g_list_next(node); |
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 PLAYLIST_UNLOCK(current_play->mutex); |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
85 return g_list_reverse(up_list); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
86 } |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
87 |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
88 void upload_file(gchar *from_path) |
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 int ret; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
91 gchar *comp, *filename; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
92 uint64_t filesize; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
93 uint32_t parent_id = 0; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
94 struct stat sb; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
95 LIBMTP_file_t *genfile; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
96 |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
97 comp = g_strescape(from_path,NULL); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
98 if ( stat(from_path, &sb) == -1 ) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
99 { |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
100 #if DEBUG |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
101 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
|
102 #endif |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
103 return; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
104 } |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
105 filesize = (uint64_t) sb.st_size; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
106 filename = g_path_get_basename(from_path); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
107 parent_id = 0; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
108 genfile = LIBMTP_new_file_t(); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
109 genfile->filesize = filesize; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
110 genfile->filename = strdup(filename); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
111 #if DEBUG |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
112 g_print("Uploading track '%s'\n",comp); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
113 #endif |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
114 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
|
115 #if DEBUG |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
116 if (ret == 0) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
117 g_print("Upload finished!\n"); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
118 else |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
119 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
|
120 #endif |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
121 LIBMTP_destroy_file_t(genfile); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
122 g_free(filename); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
123 g_free(comp); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
124 } |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
125 |
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 gpointer upload(gpointer arg) |
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 if(!mutex) |
1474
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
130 { |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
131 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
|
132 gtk_widget_set_sensitive(menuitem, TRUE); |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
133 return NULL; |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
134 } |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
135 g_mutex_lock(mutex); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
136 if(!mtp_device) |
1474
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
137 { |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
138 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
|
139 gtk_widget_set_sensitive(menuitem, TRUE); |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
140 g_mutex_unlock(mutex); |
1471
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
141 return NULL; |
1474
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
142 } |
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
143 |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
144 gchar* from_path; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
145 GList *up_list=NULL,*node; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
146 node=up_list=get_upload_list(); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
147 while(node) |
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 from_path=(gchar*)(node->data); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
150 upload_file(from_path); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
151 node = g_list_next(node); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
152 } |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
153 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
|
154 |
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
155 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
|
156 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
|
157 g_mutex_unlock(mutex); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
158 return NULL; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
159 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
160 |
1474
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
161 void mtp_prefs ( void ) |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
162 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
163 /*pref stub*/ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
164 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
165 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
166 |
1474
10791910b866
the label wasn't restored on failure
Cristi Magherusan <majeru@atheme-project.org>
parents:
1471
diff
changeset
|
167 void mtp_about ( void ) |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
168 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
169 /*about stub*/ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
170 } |
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 void mtp_press() |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
173 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
174 if(!mutex) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
175 return; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
176 g_mutex_lock(mutex); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
177 if(!mtp_initialised) |
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 #if DEBUG |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
180 g_print("Initializing the MTP device...\n"); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
181 #endif |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
182 LIBMTP_Init(); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
183 mtp_device = LIBMTP_Get_First_Device(); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
184 mtp_initialised = TRUE; |
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 g_mutex_unlock(mutex); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
187 if(mtp_device == NULL) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
188 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
189 #if DEBUG |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
190 g_print("No MTP devices have been found !!!"); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
191 #endif |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
192 return; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
193 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
194 } |
1471
355f8e284c94
the menu item is now disabled during upload
Cristi Magherusan <majeru@atheme-project.org>
parents:
1468
diff
changeset
|
195 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
|
196 gtk_widget_set_sensitive(menuitem, FALSE); |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
197 g_thread_create(upload,NULL,FALSE,NULL); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
198 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
199 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
200 void mtp_init(void) |
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 menuitem=gtk_menu_item_new_with_label(DEFAULT_LABEL); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
203 gtk_widget_show (menuitem); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
204 audacious_menu_plugin_item_add(AUDACIOUS_MENU_PLAYLIST_RCLICK, menuitem); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
205 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
|
206 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
|
207 plugin_active = TRUE; |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
208 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
209 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
210 void mtp_cleanup(void) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
211 { |
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
|
212 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
|
213 { |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
214 |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
215 #if DEBUG |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
216 if(mtp_initialised) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
217 g_print("\n\n !!!CAUTION!!! \n\n" |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
218 "Cleaning up MTP upload plugin, please wait!!!...\n" |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
219 "This will block until the pending tracks are uploaded,\n" |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
220 "then it will gracefully close your device\n\n" |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
221 "!!! 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
|
222 "Waiting for the MTP mutex to unlock...\n"); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
223 #endif |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
224 if(mutex) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
225 g_mutex_lock(mutex); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
226 if(mtp_device!= NULL) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
227 { |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
228 LIBMTP_Release_Device(mtp_device); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
229 mtp_device = NULL; |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
230 } |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
231 g_mutex_unlock(mutex); |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
232 #if DEBUG |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
233 if(mtp_initialised) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
234 g_print("The MTP mutex has been unlocked\n"); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
235 #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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 plugin_active = FALSE; |
1468
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
241 #if DEBUG |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
242 if(mtp_initialised) |
159186076d9a
lots of fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1461
diff
changeset
|
243 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
|
244 #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
|
245 } |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
246 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
247 |