~ubuntu-branches/ubuntu/precise/libmtp/precise-proposed

« back to all changes in this revision

Viewing changes to src/playlist-spl.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2009-12-14 22:32:10 UTC
  • mto: (16.1.3 sid) (0.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20091214223210-vekc5340wzmz54bw
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * \file playlist-spl.c
 
2
 * \File playlist-spl.c
3
3
 *
4
4
 * Playlist_t to Samsung (.spl) and back conversion functions.
5
5
 *
21
21
 * Boston, MA 02111-1307, USA.
22
22
 */
23
23
 
 
24
#include <config.h>
 
25
 
24
26
#include <stdio.h>
25
27
#include <stdlib.h> // mkstmp()
26
28
#include <unistd.h>
27
29
#include <errno.h>
28
30
#include <sys/stat.h>
29
31
#include <sys/types.h>
 
32
#ifdef HAVE_SYS_UIO_H
30
33
#include <sys/uio.h>
 
34
#endif
31
35
#include <fcntl.h>
32
36
 
33
37
#include <string.h>
91
95
         (strcmp((oi->Filename + strlen(oi->Filename) -4), ".spl") == 0);
92
96
}
93
97
 
 
98
#ifndef HAVE_MKSTEMP
 
99
# ifdef __WIN32__
 
100
#  include <fcntl.h>
 
101
#  define mkstemp(_pattern) _open(_mktemp(_pattern), _O_CREAT | _O_SHORT_LIVED | _O_EXCL)
 
102
# else
 
103
#  error Missing mkstemp() function.
 
104
# endif
 
105
#endif
 
106
 
94
107
/**
95
108
 * Take an object ID, a .spl playlist on the MTP device,
96
109
 * and convert it to a playlist_t object.
108
121
  // Use the Filename as the playlist name, dropping the ".spl" extension
109
122
  pl->name = malloc(sizeof(char)*(strlen(oi->Filename) -4 +1));
110
123
  memcpy(pl->name, oi->Filename, strlen(oi->Filename) -4);
 
124
  // Set terminating character
 
125
  pl->name[strlen(oi->Filename) - 4] = 0;
111
126
  pl->playlist_id = id;
112
127
  pl->parent_id = oi->ParentObject;
113
128
  pl->storage_id = oi->StorageID;
245
260
 * @return 0 on success, any other value means failure.
246
261
 */
247
262
int update_spl_playlist(LIBMTP_mtpdevice_t *device,
248
 
                          LIBMTP_playlist_t * const new)
 
263
                          LIBMTP_playlist_t * const newlist)
249
264
{
250
 
  IF_DEBUG() printf("pl->name='%s'\n",new->name);
 
265
  IF_DEBUG() printf("pl->name='%s'\n",newlist->name);
251
266
 
252
267
  // read in the playlist of interest
253
 
  LIBMTP_playlist_t * old = LIBMTP_Get_Playlist(device, new->playlist_id);
 
268
  LIBMTP_playlist_t * old = LIBMTP_Get_Playlist(device, newlist->playlist_id);
 
269
  
 
270
  // check to see if we found it
 
271
  if (!old)
 
272
    return -1;
254
273
 
255
274
  // check if the playlists match
256
275
  int delta = 0;
257
276
  int i;
258
 
  if(old->no_tracks != new->no_tracks)
 
277
  if(old->no_tracks != newlist->no_tracks)
259
278
    delta++;
260
 
  for(i=0;i<new->no_tracks && delta==0;i++) {
261
 
    if(old->tracks[i] != new->tracks[i])
 
279
  for(i=0;i<newlist->no_tracks && delta==0;i++) {
 
280
    if(old->tracks[i] != newlist->tracks[i])
262
281
      delta++;
263
282
  }
264
283
 
271
290
      return -1;
272
291
 
273
292
    IF_DEBUG() {
274
 
      if(strcmp(old->name,new->name) == 0)
 
293
      if(strcmp(old->name,newlist->name) == 0)
275
294
        printf("name unchanged\n");
276
295
      else
277
 
        printf("name is changing too -> %s\n",new->name);
 
296
        printf("name is changing too -> %s\n",newlist->name);
278
297
    }
279
298
 
280
 
    return LIBMTP_Create_New_Playlist(device, new);
 
299
    return LIBMTP_Create_New_Playlist(device, newlist);
281
300
  }
282
301
 
283
302
 
284
303
  // update the name only
285
 
  if(strcmp(old->name,new->name) != 0) {
286
 
    IF_DEBUG() printf("ONLY name is changing -> %s\n",new->name);
 
304
  if(strcmp(old->name,newlist->name) != 0) {
 
305
    IF_DEBUG() printf("ONLY name is changing -> %s\n",newlist->name);
287
306
    IF_DEBUG() printf("playlist_id will remain unchanged\n");
288
 
    char* s = malloc(sizeof(char)*(strlen(new->name)+5));
289
 
    strcpy(s, new->name);
 
307
    char* s = malloc(sizeof(char)*(strlen(newlist->name)+5));
 
308
    strcpy(s, newlist->name);
290
309
    strcat(s,".spl"); // FIXME check for success
291
 
    int ret = LIBMTP_Set_Playlist_Name(device, new, s);
 
310
    int ret = LIBMTP_Set_Playlist_Name(device, newlist, s);
292
311
    free(s);
293
312
    return ret;
294
313
  }