DespotifyUtils: fix coding style

This commit is contained in:
Max Kellermann 2014-12-09 22:10:17 +01:00
parent fc0b6d143a
commit c486c5bf5b
2 changed files with 34 additions and 22 deletions

View File

@ -47,13 +47,15 @@ callback(struct despotify_session* ds, int sig,
void (*cb)(struct despotify_session *, int, void *, void *) = registered_callbacks[i]; void (*cb)(struct despotify_session *, int, void *, void *) = registered_callbacks[i];
void *cb_data = registered_callback_data[i]; void *cb_data = registered_callback_data[i];
if (cb) if (cb != nullptr)
cb(ds, sig, data, cb_data); cb(ds, sig, data, cb_data);
} }
} }
bool mpd_despotify_register_callback(void (*cb)(struct despotify_session *, int, void *, void *), bool
void *cb_data) mpd_despotify_register_callback(void (*cb)(struct despotify_session *, int,
void *, void *),
void *cb_data)
{ {
for (size_t i = 0; i < ARRAY_SIZE(registered_callbacks); ++i) { for (size_t i = 0; i < ARRAY_SIZE(registered_callbacks); ++i) {
if (!registered_callbacks[i]) { if (!registered_callbacks[i]) {
@ -67,7 +69,9 @@ bool mpd_despotify_register_callback(void (*cb)(struct despotify_session *, int,
return false; return false;
} }
void mpd_despotify_unregister_callback(void (*cb)(struct despotify_session *, int, void *, void *)) void
mpd_despotify_unregister_callback(void (*cb)(struct despotify_session *, int,
void *, void *))
{ {
for (size_t i = 0; i < ARRAY_SIZE(registered_callbacks); ++i) { for (size_t i = 0; i < ARRAY_SIZE(registered_callbacks); ++i) {
if (registered_callbacks[i] == cb) { if (registered_callbacks[i] == cb) {
@ -79,19 +83,22 @@ void mpd_despotify_unregister_callback(void (*cb)(struct despotify_session *, in
Tag Tag
mpd_despotify_tag_from_track(const ds_track &track) mpd_despotify_tag_from_track(const ds_track &track)
{ {
char tracknum[20];
char comment[80];
char date[20];
if (!track.has_meta_data) if (!track.has_meta_data)
return Tag(); return Tag();
TagBuilder tag; TagBuilder tag;
char tracknum[20];
snprintf(tracknum, sizeof(tracknum), "%d", track.tracknumber); snprintf(tracknum, sizeof(tracknum), "%d", track.tracknumber);
char date[20];
snprintf(date, sizeof(date), "%d", track.year); snprintf(date, sizeof(date), "%d", track.year);
char comment[80];
snprintf(comment, sizeof(comment), "Bitrate %d Kbps, %sgeo restricted", snprintf(comment, sizeof(comment), "Bitrate %d Kbps, %sgeo restricted",
track.file_bitrate / 1000, track.file_bitrate / 1000,
track.geo_restricted ? "" : "not "); track.geo_restricted ? "" : "not ");
tag.AddItem(TAG_TITLE, track.title); tag.AddItem(TAG_TITLE, track.title);
tag.AddItem(TAG_ARTIST, track.artist->name); tag.AddItem(TAG_ARTIST, track.artist->name);
tag.AddItem(TAG_TRACK, tracknum); tag.AddItem(TAG_TRACK, tracknum);
@ -103,18 +110,16 @@ mpd_despotify_tag_from_track(const ds_track &track)
return tag.Commit(); return tag.Commit();
} }
struct despotify_session *mpd_despotify_get_session(void) struct despotify_session *
mpd_despotify_get_session()
{ {
const char *user;
const char *passwd;
bool high_bitrate;
if (g_session) if (g_session)
return g_session; return g_session;
user = config_get_string(CONF_DESPOTIFY_USER, nullptr); const char *const user =
passwd = config_get_string(CONF_DESPOTIFY_PASSWORD, nullptr); config_get_string(CONF_DESPOTIFY_USER, nullptr);
high_bitrate = config_get_bool(CONF_DESPOTIFY_HIGH_BITRATE, true); const char *const passwd =
config_get_string(CONF_DESPOTIFY_PASSWORD, nullptr);
if (user == nullptr || passwd == nullptr) { if (user == nullptr || passwd == nullptr) {
LogDebug(despotify_domain, LogDebug(despotify_domain,
@ -127,6 +132,8 @@ struct despotify_session *mpd_despotify_get_session(void)
return nullptr; return nullptr;
} }
const bool high_bitrate =
config_get_bool(CONF_DESPOTIFY_HIGH_BITRATE, true);
g_session = despotify_init_client(callback, nullptr, g_session = despotify_init_client(callback, nullptr,
high_bitrate, true); high_bitrate, true);
if (!g_session) { if (!g_session) {

View File

@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_DESPOTIFY_H #ifndef MPD_DESPOTIFY_UTILS_HXX
#define MPD_DESPOTIFY_H #define MPD_DESPOTIFY_UTILS_HXX
struct Tag; struct Tag;
struct despotify_session; struct despotify_session;
@ -35,7 +35,8 @@ extern const class Domain despotify_domain;
* @return a pointer to the despotify session, or nullptr if it can't * @return a pointer to the despotify session, or nullptr if it can't
* be initialized (e.g., if the configuration isn't supplied) * be initialized (e.g., if the configuration isn't supplied)
*/ */
struct despotify_session *mpd_despotify_get_session(void); struct despotify_session *
mpd_despotify_get_session();
/** /**
* Create a MPD tags structure from a spotify track * Create a MPD tags structure from a spotify track
@ -57,15 +58,19 @@ mpd_despotify_tag_from_track(const ds_track &track);
* *
* @return true if the callback could be registered * @return true if the callback could be registered
*/ */
bool mpd_despotify_register_callback(void (*cb)(struct despotify_session *, int, void *, void *), bool
void *cb_data); mpd_despotify_register_callback(void (*cb)(struct despotify_session *, int,
void *, void *),
void *cb_data);
/** /**
* Unregister a despotify callback. * Unregister a despotify callback.
* *
* @param cb the callback to unregister. * @param cb the callback to unregister.
*/ */
void mpd_despotify_unregister_callback(void (*cb)(struct despotify_session *, int, void *, void *)); void
mpd_despotify_unregister_callback(void (*cb)(struct despotify_session *, int,
void *, void *));
#endif #endif