Mercurial > audlegacy-plugins
annotate src/mtp_up/mtp.c @ 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
author | Giacomo Lozito <james@develia.org> |
---|---|
date | Sat, 11 Aug 2007 02:50:12 +0200 |
parents | b2debf8c9ec8 |
children | 159186076d9a |
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 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
26 GMutex * mutex = NULL; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
27 gboolean mtp_initialised = FALSE; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
28 LIBMTP_mtpdevice_t *mtp_device = NULL; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
29 LIBMTP_progressfunc_t *callback; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
30 LIBMTP_file_t *filelist; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
31 Playlist *active_playlist; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
32 |
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
|
33 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
|
34 |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
35 void mtp_init ( void ); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
36 void mtp_cleanup ( void ); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
37 void mtp_prefs ( void ); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
38 void mtp_about ( void ); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
39 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
40 GeneralPlugin mtp_gp = |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
41 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
42 NULL, /* handle */ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
43 NULL, /* filename */ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
44 "MTP Upload " , /* description */ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
45 mtp_init, /* init */ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
46 mtp_about, /* about */ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
47 mtp_prefs, /* configure */ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
48 mtp_cleanup /* cleanup */ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
49 }; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
50 GtkWidget *menuitem; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
51 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
52 GeneralPlugin *mtp_gplist[] = { &mtp_gp, NULL }; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
53 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
|
54 |
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 gpointer upload(gpointer arg) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
57 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
58 Playlist *current_play; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
59 Tuple *tuple; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
60 gchar *from_path; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
61 gchar *comp; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
62 char *filename; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
63 uint64_t filesize; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
64 struct stat sb; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
65 LIBMTP_file_t *genfile; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
66 int ret; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
67 uint32_t parent_id = 0; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
68 GList *node; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
69 PlaylistEntry *entry; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
70 current_play = g_new0(Playlist,1); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
71 current_play = playlist_get_active(); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
72 node = current_play->entries; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
73 PLAYLIST_LOCK(current_play->mutex); /*needed so that the user doesn't modify the selection*/ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
74 while (node) { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
75 entry = PLAYLIST_ENTRY(node->data); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
76 if (entry->selected) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
77 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
78 tuple = entry->tuple; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
79 from_path = g_strdup_printf("%s/%s", tuple_get_string(tuple, "file-path"), tuple_get_string(tuple, "file-name")); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
80 comp = g_strescape(from_path,NULL); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
81 if ( stat(from_path, &sb) == -1 ) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
82 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
83 #if DEBUG |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
84 g_print("ERROR!"); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
85 #endif |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
86 return NULL; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
87 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
88 filesize = (uint64_t) sb.st_size; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
89 filename = basename(from_path); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
90 parent_id = 0; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
91 genfile = LIBMTP_new_file_t(); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
92 genfile->filesize = filesize; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
93 genfile->filename = strdup(filename); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
94 #if DEBUG |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
95 g_print("Uploading track '%s'\n",comp); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
96 #endif |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
97 ret = LIBMTP_Send_File_From_File(mtp_device,comp , genfile, NULL , NULL, parent_id); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
98 #if DEBUG |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
99 if (ret == 0) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
100 g_print("Upload finished!\n"); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
101 else |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
102 g_print("An error has occured while uploading '%s'...\nUpload failed!!!",comp); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
103 #endif |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
104 LIBMTP_destroy_file_t(genfile); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
105 g_free(from_path); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
106 g_free(comp); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
107 entry->selected = FALSE; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
108 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
109 node = g_list_next(node); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
110 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
111 PLAYLIST_UNLOCK(current_play->mutex); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
112 return NULL; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
113 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
114 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
115 void |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
116 mtp_prefs ( void ) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
117 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
118 /*pref stub*/ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
119 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
120 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
121 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
122 void |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
123 mtp_about ( void ) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
124 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
125 /*about stub*/ |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
126 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
127 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
128 void mtp_press() |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
129 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
130 if(!mutex) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
131 return; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
132 g_mutex_lock(mutex); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
133 if(!mtp_initialised) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
134 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
135 #if DEBUG |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
136 g_print("Initializing the MTP device...\n"); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
137 #endif |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
138 mtp_device = LIBMTP_Get_First_Device(); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
139 mtp_initialised = TRUE; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
140 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
141 g_mutex_unlock(mutex); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
142 if(mtp_device == NULL) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
143 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
144 #if DEBUG |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
145 g_print("No MTP devices have been found !!!"); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
146 #endif |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
147 return; |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
148 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
149 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
150 g_thread_create(upload,NULL,FALSE,NULL); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
151 } |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
152 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
153 void mtp_init(void) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
154 { |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
155 menuitem=gtk_menu_item_new_with_label("Upload to MTP"); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
156 gtk_widget_show (menuitem); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
157 audacious_menu_plugin_item_add(AUDACIOUS_MENU_PLAYLIST_RCLICK, menuitem); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
158 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
|
159 LIBMTP_Init(); |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
160 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
|
161 plugin_active = TRUE; |
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 |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
164 void mtp_cleanup(void) |
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
165 { |
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
|
166 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
|
167 { |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
168 #if DEBUG |
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
|
169 g_print("Cleaning up MTP_upload\n"); |
1456
475eac76a8ba
MTP upload plugin
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
170 #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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 } |
1456
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 |