Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: examples/tracks.c

Issue 2364793002: Revert "Uprev libmtp to 1.1.12" (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libmtp@master
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « examples/thumb.c ('k') | install-sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * \file tracks.c 2 * \file tracks.c
3 * Example program to list the tracks on a device. 3 * Example program to list the tracks on a device.
4 * 4 *
5 * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se> 5 * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se>
6 * Copyright (C) 2007 Ted Bullock <tbullock@canada.com> 6 * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 72 }
73 } 73 }
74 if (track->rating != 0) { 74 if (track->rating != 0) {
75 printf(" User rating: %u (out of 100)\n", track->rating); 75 printf(" User rating: %u (out of 100)\n", track->rating);
76 } 76 }
77 if (track->usecount != 0) { 77 if (track->usecount != 0) {
78 printf(" Use count: %u times\n", track->usecount); 78 printf(" Use count: %u times\n", track->usecount);
79 } 79 }
80 } 80 }
81 81
82 static void
83 dump_tracks(LIBMTP_mtpdevice_t *device, uint32_t storageid, int leaf)
84 {
85 LIBMTP_file_t *files;
86
87 /* Get track listing. */
88 files = LIBMTP_Get_Files_And_Folders(device,
89 storageid,
90 leaf);
91 if (files == NULL) {
92 LIBMTP_Dump_Errorstack(device);
93 LIBMTP_Clear_Errorstack(device);
94 } else {
95 LIBMTP_file_t *file, *tmp;
96
97 file = files;
98 while (file != NULL) {
99 /* Please don't print these */
100 if (file->filetype == LIBMTP_FILETYPE_FOLDER) {
101 dump_tracks(device, storageid, file->item_id);
102 } else if (LIBMTP_FILETYPE_IS_TRACK(file->filetype)) {
103 LIBMTP_track_t *track;
104
105 track = LIBMTP_Get_Trackmetadata(device, file->item_id);
106 dump_trackinfo(track);
107 LIBMTP_destroy_track_t(track);
108 }
109 tmp = file;
110 file = file->next;
111 LIBMTP_destroy_file_t(tmp);
112 }
113 }
114 }
115
116 int main (int argc, char **argv) 82 int main (int argc, char **argv)
117 { 83 {
118 LIBMTP_raw_device_t *rawdevices; 84 LIBMTP_mtpdevice_t *device_list, *device;
119 int numrawdevices; 85 LIBMTP_track_t *tracks;
120 LIBMTP_error_number_t err;
121 int i;
122 86
123 LIBMTP_Init(); 87 LIBMTP_Init();
124 fprintf(stdout, "Attempting to connect device(s)\n"); 88 fprintf(stdout, "Attempting to connect device(s)\n");
125 89
126 err = LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices); 90 switch(LIBMTP_Get_Connected_Devices(&device_list))
127 switch(err)
128 { 91 {
129 case LIBMTP_ERROR_NO_DEVICE_ATTACHED: 92 case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
130 fprintf(stdout, "mtp-tracks: No Devices have been found\n"); 93 fprintf(stdout, "mtp-tracks: No Devices have been found\n");
131 return 0; 94 return 0;
132 case LIBMTP_ERROR_CONNECTING: 95 case LIBMTP_ERROR_CONNECTING:
133 fprintf(stderr, "mtp-tracks: There has been an error connecting. Exit\n"); 96 fprintf(stderr, "mtp-tracks: There has been an error connecting. Exit\n");
134 return 1; 97 return 1;
135 case LIBMTP_ERROR_MEMORY_ALLOCATION: 98 case LIBMTP_ERROR_MEMORY_ALLOCATION:
136 fprintf(stderr, "mtp-tracks: Memory Allocation Error. Exit\n"); 99 fprintf(stderr, "mtp-tracks: Memory Allocation Error. Exit\n");
137 return 1; 100 return 1;
138 101
139 /* Unknown general errors - This should never execute */ 102 /* Unknown general errors - This should never execute */
140 case LIBMTP_ERROR_GENERAL: 103 case LIBMTP_ERROR_GENERAL:
141 default: 104 default:
142 fprintf(stderr, "mtp-tracks: Unknown error, please report " 105 fprintf(stderr, "mtp-tracks: Unknown error, please report "
143 "this to the libmtp developers\n"); 106 "this to the libmtp developers\n");
144 return 1; 107 return 1;
145 108
146 /* Successfully connected at least one device, so continue */ 109 /* Successfully connected at least one device, so continue */
147 case LIBMTP_ERROR_NONE: 110 case LIBMTP_ERROR_NONE:
148 fprintf(stdout, "mtp-tracks: Successfully connected\n"); 111 fprintf(stdout, "mtp-tracks: Successfully connected\n");
149 fflush(stdout); 112 fflush(stdout);
150 break;
151 } 113 }
152 114
153 /* Iterate through connected MTP devices */ 115 /* iterate through connected MTP devices */
154 for (i = 0; i < numrawdevices; i++) { 116 for(device = device_list; device != NULL; device = device->next) {
155 LIBMTP_mtpdevice_t *device;
156 LIBMTP_devicestorage_t *storage;
157 char *friendlyname; 117 char *friendlyname;
158 118
159 device = LIBMTP_Open_Raw_Device_Uncached(&rawdevices[i]);
160 if (device == NULL) {
161 fprintf(stderr, "Unable to open raw device %d\n", i);
162 continue;
163 }
164
165 /* Echo the friendly name so we know which device we are working with */ 119 /* Echo the friendly name so we know which device we are working with */
166 friendlyname = LIBMTP_Get_Friendlyname(device); 120 friendlyname = LIBMTP_Get_Friendlyname(device);
167 if (friendlyname == NULL) { 121 if (friendlyname == NULL) {
168 printf("Friendly name: (NULL)\n"); 122 printf("Friendly name: (NULL)\n");
169 } else { 123 } else {
170 printf("Friendly name: %s\n", friendlyname); 124 printf("Friendly name: %s\n", friendlyname);
171 free(friendlyname); 125 free(friendlyname);
172 } 126 }
173 127 // Get track listing.
174 LIBMTP_Dump_Errorstack(device); 128 tracks = LIBMTP_Get_Tracklisting_With_Callback(device, NULL, NULL);
175 LIBMTP_Clear_Errorstack(device); 129 if (tracks == NULL) {
176 130 printf("No tracks.\n");
177 /* Loop over storages */ 131 } else {
178 for (storage = device->storage; storage != 0; storage = storage->next) { 132 LIBMTP_track_t *track, *tmp;
179 dump_tracks(device, storage->id, 0); 133 track = tracks;
134 while (track != NULL) {
135 » dump_trackinfo(track);
136 » tmp = track;
137 » track = track->next;
138 » LIBMTP_destroy_track_t(tmp);
139 }
180 } 140 }
181
182 LIBMTP_Release_Device(device);
183 } 141 }
184 142
143 LIBMTP_Release_Device_List(device_list);
185 printf("OK.\n"); 144 printf("OK.\n");
186 exit (0); 145 exit (0);
187 } 146 }
188 147
OLDNEW
« no previous file with comments | « examples/thumb.c ('k') | install-sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698