~ubuntu-branches/ubuntu/wily/pianobar/wily-proposed

« back to all changes in this revision

Viewing changes to src/settings.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Faraone
  • Date: 2011-02-08 17:23:25 UTC
  • mfrom: (1.3.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110208172325-0qf3sxpsu37j5ez9
Tags: 2011.01.24-1
* New upstream version. 
* Switch to DEP5 copyright.
* Augment CFLAGS to use the c99 standard.
* Don't install the now-removed AUTHORS file into docs.
* Drop dep on cmake.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
Copyright (c) 2008-2010
3
 
        Lars-Dominik Braun <PromyLOPh@lavabit.com>
 
3
        Lars-Dominik Braun <lars@6xq.net>
4
4
 
5
5
Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
of this software and associated documentation files (the "Software"), to deal
23
23
 
24
24
/* application settings */
25
25
 
 
26
#define _POSIX_C_SOURCE 1 /* PATH_MAX */
26
27
#define _BSD_SOURCE /* strdup() */
27
28
 
28
29
#include <string.h>
29
30
#include <stdlib.h>
30
31
#include <stdio.h>
 
32
#include <limits.h>
31
33
 
32
34
#include "settings.h"
33
35
#include "config.h"
34
36
 
 
37
#define streq(a, b) (strcmp (a, b) == 0)
 
38
 
35
39
/*      tries to guess your config dir; somehow conforming to
36
40
 *      http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
37
41
 *      @param name of the config file (can contain subdirs too)
77
81
        free (settings->password);
78
82
        free (settings->autostartStation);
79
83
        free (settings->eventCmd);
 
84
        free (settings->loveIcon);
 
85
        free (settings->banIcon);
80
86
        memset (settings, 0, sizeof (*settings));
81
87
}
82
88
 
85
91
 *      @return nothing yet
86
92
 */
87
93
void BarSettingsRead (BarSettings_t *settings) {
88
 
        /* FIXME: what is the max length of a path? */
89
 
        char configfile[1024], key[256], val[256];
 
94
        char configfile[PATH_MAX], key[256], val[256];
90
95
        FILE *configfd;
91
96
        /* _must_ have same order as in BarKeyShortcutId_t */
92
97
        static const char defaultKeys[] = {'?', '+', '-', 'a', 'c', 'd', 'e', 'g',
93
98
                        'h', 'i', 'j', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'x', '$',
94
 
                        'b',
 
99
                        'b', '(', ')',
95
100
                        };
96
101
        static const char *shortcutFileKeys[] = {
97
102
                        "act_help", "act_songlove", "act_songban", "act_stationaddmusic",
100
105
                        "act_addshared", "act_songmove", "act_songnext", "act_songpause",
101
106
                        "act_quit", "act_stationrename", "act_stationchange",
102
107
                        "act_songtired", "act_upcoming", "act_stationselectquickmix",
103
 
                        "act_debug", "act_bookmark",
 
108
                        "act_debug", "act_bookmark", "act_voldown", "act_volup",
104
109
                        };
105
110
 
106
111
        /* apply defaults */
112
117
                #endif
113
118
        #endif
114
119
        settings->history = 5;
 
120
        settings->volume = 0;
115
121
        settings->sortOrder = BAR_SORT_NAME_AZ;
116
122
        memcpy (settings->keys, defaultKeys, sizeof (defaultKeys));
 
123
        settings->loveIcon = strdup ("<3");
 
124
        settings->banIcon = strdup ("</3");
117
125
 
118
126
        BarGetXdgConfigDir (PACKAGE "/config", configfile, sizeof (configfile));
119
127
        if ((configfd = fopen (configfile, "r")) == NULL) {
129
137
                        /* invalid config line */
130
138
                        continue;
131
139
                }
132
 
                if (strcmp ("control_proxy", key) == 0) {
 
140
                if (streq ("control_proxy", key)) {
133
141
                        settings->controlProxy = strdup (val);
134
 
                } else if (strcmp ("proxy", key) == 0) {
 
142
                } else if (streq ("proxy", key)) {
135
143
                        settings->proxy = strdup (val);
136
 
                } else if (strcmp ("user", key) == 0) {
 
144
                } else if (streq ("user", key)) {
137
145
                        settings->username = strdup (val);
138
 
                } else if (strcmp ("password", key) == 0) {
 
146
                } else if (streq ("password", key)) {
139
147
                        settings->password = strdup (val);
140
148
                } else if (memcmp ("act_", key, 4) == 0) {
141
149
                        size_t i;
142
150
                        /* keyboard shortcuts */
143
151
                        for (i = 0; i < BAR_KS_COUNT; i++) {
144
 
                                if (strcmp (shortcutFileKeys[i], key) == 0) {
 
152
                                if (streq (shortcutFileKeys[i], key)) {
145
153
                                        settings->keys[i] = val[0];
146
154
                                        break;
147
155
                                }
148
156
                        }
149
 
                } else if (strcmp ("audio_format", key) == 0) {
150
 
                        if (strcmp (val, "aacplus") == 0) {
 
157
                } else if (streq ("audio_format", key)) {
 
158
                        if (streq (val, "aacplus")) {
151
159
                                settings->audioFormat = PIANO_AF_AACPLUS;
152
 
                        } else if (strcmp (val, "mp3") == 0) {
 
160
                        } else if (streq (val, "mp3")) {
153
161
                                settings->audioFormat = PIANO_AF_MP3;
154
 
                        } else if (strcmp (val, "mp3-hifi") == 0) {
 
162
                        } else if (streq (val, "mp3-hifi")) {
155
163
                                settings->audioFormat = PIANO_AF_MP3_HI;
156
164
                        }
157
 
                } else if (strcmp ("autostart_station", key) == 0) {
 
165
                } else if (streq ("autostart_station", key)) {
158
166
                        settings->autostartStation = strdup (val);
159
 
                } else if (strcmp ("event_command", key) == 0) {
 
167
                } else if (streq ("event_command", key)) {
160
168
                        settings->eventCmd = strdup (val);
161
 
                } else if (strcmp ("history", key) == 0) {
 
169
                } else if (streq ("history", key)) {
162
170
                        settings->history = atoi (val);
163
 
                } else if (strcmp ("sort", key) == 0) {
 
171
                } else if (streq ("sort", key)) {
164
172
                        size_t i;
165
173
                        static const char *mapping[] = {"name_az",
166
174
                                        "name_za",
170
178
                                        "quickmix_10_name_za",
171
179
                                        };
172
180
                        for (i = 0; i < BAR_SORT_COUNT; i++) {
173
 
                                if (strcmp (mapping[i], val) == 0) {
 
181
                                if (streq (mapping[i], val)) {
174
182
                                        settings->sortOrder = i;
175
183
                                        break;
176
184
                                }
177
185
                        }
 
186
                } else if (streq ("love_icon", key)) {
 
187
                        free (settings->loveIcon);
 
188
                        settings->loveIcon = strdup (val);
 
189
                } else if (streq ("ban_icon", key)) {
 
190
                        free (settings->banIcon);
 
191
                        settings->banIcon = strdup (val);
 
192
                } else if (streq ("volume", key)) {
 
193
                        settings->volume = atoi (val);
178
194
                }
179
195
        }
180
196