1 /***************************************************************************
2 * Copyright (C) 2008-2009 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
24 # include <sys/stat.h>
35 #include "media_library.h"
38 #include "playlist_editor.h"
39 #include "search_engine.h"
41 #include "tag_editor.h"
42 #include "visualizer.h"
44 #ifdef HAVE_LANGINFO_H
45 # include <langinfo.h>
48 const std::string config_file
= config_dir
+ "config";
49 const std::string keys_config_file
= config_dir
+ "keys";
51 ncmpcpp_config Config
;
56 void GetKeys(std::string
&line
, int *key
)
58 size_t i
= line
.find("=")+1;
59 line
= line
.substr(i
, line
.length()-i
);
62 while (line
[++i
] == ' ') { }
63 line
= line
.substr(i
, line
.length()-i
);
67 if (i
!= std::string::npos
)
69 one
= line
.substr(0, i
);
71 two
= line
.substr(i
, line
.length()-i
);
75 key
[0] = !one
.empty() && one
[0] == '\'' ? one
[1] : (atoi(one
.c_str()) == 0 ? null_key
: atoi(one
.c_str()));
76 key
[1] = !two
.empty() && two
[0] == '\'' ? two
[1] : (atoi(two
.c_str()) == 0 ? null_key
: atoi(two
.c_str()));
79 Border
IntoBorder(const std::string
&color
)
81 return Border(IntoColor(color
));
84 BasicScreen
*IntoScreen(int n
)
99 return myPlaylistEditor
;
100 # ifdef HAVE_TAGLIB_H
103 # endif // HAVE_TAGLIB_H
104 # ifdef ENABLE_OUTPUTS
107 # endif // ENABLE_OUTPUTS
108 # ifdef ENABLE_VISUALIZER
111 # endif // ENABLE_VISUALIZER
115 # endif // ENABLE_CLOCK
122 void CreateConfigDir()
124 mkdir(config_dir
.c_str()
131 void SetWindowsDimensions(size_t &header_height
, size_t &footer_start_y
, size_t &footer_height
)
133 Global::MainStartY
= Config
.new_design
? 5 : 2;
134 Global::MainHeight
= LINES
-(Config
.new_design
? 7 : 4);
136 if (!Config
.header_visibility
)
138 Global::MainStartY
-= 2;
139 Global::MainHeight
+= 2;
141 if (!Config
.statusbar_visibility
)
142 Global::MainHeight
++;
144 header_height
= Config
.new_design
? (Config
.header_visibility
? 5 : 3) : 1;
145 footer_start_y
= LINES
-(Config
.statusbar_visibility
? 2 : 1);
146 footer_height
= Config
.statusbar_visibility
? 2 : 1;
149 void DefaultKeys(ncmpcpp_keys
&keys
)
152 keys
.Down
[0] = KEY_DOWN
;
153 keys
.PageUp
[0] = KEY_PPAGE
;
154 keys
.PageDown
[0] = KEY_NPAGE
;
155 keys
.Home
[0] = KEY_HOME
;
156 keys
.End
[0] = KEY_END
;
159 keys
.Delete
[0] = KEY_DC
;
160 keys
.VolumeUp
[0] = KEY_RIGHT
;
161 keys
.VolumeDown
[0] = KEY_LEFT
;
162 keys
.ScreenSwitcher
[0] = 9;
164 keys
.Playlist
[0] = '2';
165 keys
.Browser
[0] = '3';
166 keys
.SearchEngine
[0] = '4';
167 keys
.MediaLibrary
[0] = '5';
168 keys
.PlaylistEditor
[0] = '6';
169 keys
.TagEditor
[0] = '7';
170 keys
.Outputs
[0] = '8';
171 keys
.Visualizer
[0] = '9';
173 keys
.ServerInfo
[0] = '@';
178 keys
.SeekForward
[0] = 'f';
179 keys
.SeekBackward
[0] = 'b';
180 keys
.ToggleRepeat
[0] = 'r';
181 keys
.ToggleRandom
[0] = 'z';
182 keys
.ToggleSingle
[0] = 'y';
183 keys
.ToggleConsume
[0] = 'R';
184 keys
.ToggleReplayGainMode
[0] = 'Y';
185 keys
.ToggleSpaceMode
[0] = 't';
186 keys
.ToggleAddMode
[0] = 'T';
187 keys
.ToggleMouse
[0] = '|';
188 keys
.Shuffle
[0] = 'Z';
189 keys
.ToggleCrossfade
[0] = 'x';
190 keys
.SetCrossfade
[0] = 'X';
191 keys
.UpdateDB
[0] = 'u';
192 keys
.SortPlaylist
[0] = 22;
193 keys
.ApplyFilter
[0] = 6;
194 keys
.FindForward
[0] = '/';
195 keys
.FindBackward
[0] = '?';
196 keys
.NextFoundPosition
[0] = '.';
197 keys
.PrevFoundPosition
[0] = ',';
198 keys
.ToggleFindMode
[0] = 'w';
199 keys
.EditTags
[0] = 'e';
200 keys
.SongInfo
[0] = 'i';
201 keys
.ArtistInfo
[0] = 'I';
202 keys
.GoToPosition
[0] = 'g';
203 keys
.Lyrics
[0] = 'l';
204 keys
.ReverseSelection
[0] = 'v';
205 keys
.DeselectAll
[0] = 'V';
206 keys
.AddSelected
[0] = 'A';
209 keys
.MvSongUp
[0] = 'm';
210 keys
.MvSongDown
[0] = 'n';
211 keys
.MoveTo
[0] = 'M';
213 keys
.SavePlaylist
[0] = 'S';
214 keys
.GoToNowPlaying
[0] = 'o';
215 keys
.GoToContainingDir
[0] = 'G';
216 keys
.GoToMediaLibrary
[0] = '~';
217 keys
.ToggleAutoCenter
[0] = 'U';
218 keys
.ToggleDisplayMode
[0] = 'p';
219 keys
.ToggleInterface
[0] = '\\';
220 keys
.ToggleLyricsDB
[0] = 'L';
221 keys
.GoToParentDir
[0] = KEY_BACKSPACE
;
222 keys
.SwitchTagTypeList
[0] = '`';
227 keys
.PageUp
[1] = null_key
;
228 keys
.PageDown
[1] = null_key
;
229 keys
.Home
[1] = null_key
;
230 keys
.End
[1] = null_key
;
231 keys
.Space
[1] = null_key
;
232 keys
.Enter
[1] = null_key
;
233 keys
.Delete
[1] = 'd';
234 keys
.VolumeUp
[1] = '+';
235 keys
.VolumeDown
[1] = '-';
236 keys
.ScreenSwitcher
[1] = null_key
;
238 keys
.Playlist
[1] = 266;
239 keys
.Browser
[1] = 267;
240 keys
.SearchEngine
[1] = 268;
241 keys
.MediaLibrary
[1] = 269;
242 keys
.PlaylistEditor
[1] = 270;
243 keys
.TagEditor
[1] = 271;
244 keys
.Outputs
[1] = 272;
245 keys
.Visualizer
[1] = 273;
247 keys
.ServerInfo
[1] = null_key
;
248 keys
.Stop
[1] = null_key
;
249 keys
.Pause
[1] = null_key
;
250 keys
.Next
[1] = null_key
;
251 keys
.Prev
[1] = null_key
;
252 keys
.SeekForward
[1] = null_key
;
253 keys
.SeekBackward
[1] = null_key
;
254 keys
.ToggleRepeat
[1] = null_key
;
255 keys
.ToggleRandom
[1] = null_key
;
256 keys
.ToggleSingle
[1] = null_key
;
257 keys
.ToggleConsume
[1] = null_key
;
258 keys
.ToggleReplayGainMode
[1] = null_key
;
259 keys
.ToggleSpaceMode
[1] = null_key
;
260 keys
.ToggleAddMode
[1] = null_key
;
261 keys
.ToggleMouse
[1] = null_key
;
262 keys
.Shuffle
[1] = null_key
;
263 keys
.ToggleCrossfade
[1] = null_key
;
264 keys
.SetCrossfade
[1] = null_key
;
265 keys
.UpdateDB
[1] = null_key
;
266 keys
.SortPlaylist
[1] = null_key
;
267 keys
.ApplyFilter
[1] = null_key
;
268 keys
.FindForward
[1] = null_key
;
269 keys
.FindBackward
[1] = null_key
;
270 keys
.NextFoundPosition
[1] = null_key
;
271 keys
.PrevFoundPosition
[1] = null_key
;
272 keys
.ToggleFindMode
[1] = null_key
;
273 keys
.EditTags
[1] = null_key
;
274 keys
.SongInfo
[1] = null_key
;
275 keys
.ArtistInfo
[1] = null_key
;
276 keys
.GoToPosition
[1] = null_key
;
277 keys
.Lyrics
[1] = null_key
;
278 keys
.ReverseSelection
[1] = null_key
;
279 keys
.DeselectAll
[1] = null_key
;
280 keys
.AddSelected
[1] = null_key
;
281 keys
.Clear
[1] = null_key
;
282 keys
.Crop
[1] = null_key
;
283 keys
.MvSongUp
[1] = null_key
;
284 keys
.MvSongDown
[1] = null_key
;
285 keys
.MoveTo
[1] = null_key
;
286 keys
.Add
[1] = null_key
;
287 keys
.SavePlaylist
[1] = null_key
;
288 keys
.GoToNowPlaying
[1] = null_key
;
289 keys
.GoToContainingDir
[1] = null_key
;
290 keys
.GoToMediaLibrary
[1] = null_key
;
291 keys
.ToggleAutoCenter
[1] = null_key
;
292 keys
.ToggleDisplayMode
[1] = null_key
;
293 keys
.ToggleInterface
[1] = null_key
;
294 keys
.ToggleLyricsDB
[1] = null_key
;
295 keys
.GoToParentDir
[1] = 127;
296 keys
.SwitchTagTypeList
[1] = null_key
;
300 void DefaultConfiguration(ncmpcpp_config
&conf
)
302 conf
.mpd_host
= "localhost";
303 conf
.empty_tag
= "<empty>";
304 conf
.song_list_columns_format
= "(7f)[green]{l} (25)[cyan]{a} (40)[]{t} (30)[red]{b}";
305 conf
.song_list_format
= "{{%a - }{%t}|{$8%f$9}$R{$3(%l)$9}}";
306 conf
.song_status_format
= "{{{%a{ \"%b\"{ (%y)}} - }{%t}}|{%f}}";
307 conf
.song_status_format_no_colors
= conf
.song_status_format
;
308 conf
.song_window_title_format
= "{{%a - }{%t}|{%f}}";
309 conf
.song_library_format
= "{{%n - }{%t}|{%f}}";
310 conf
.tag_editor_album_format
= "{{(%y) }%b}";
311 conf
.new_header_first_line
= "{$b$1$aqqu$/a$9 {%t}|{%f} $1$atqq$/a$9$/b}";
312 conf
.new_header_second_line
= "{{{$4$b%a$/b$9}{ - $7%b$9}{ ($4%y$9)}}|{%D}}";
313 conf
.browser_playlist_prefix
<< clRed
<< "(playlist)" << clEnd
<< ' ';
314 conf
.progressbar
= U("=>");
315 conf
.pattern
= "%n - %t";
316 conf
.selected_item_prefix
<< clMagenta
;
317 conf
.selected_item_suffix
<< clEnd
;
318 conf
.now_playing_prefix
<< fmtBold
;
319 conf
.now_playing_suffix
<< fmtBoldEnd
;
320 conf
.color1
= clWhite
;
321 conf
.color2
= clGreen
;
322 conf
.empty_tags_color
= clCyan
;
323 conf
.header_color
= clDefault
;
324 conf
.volume_color
= clDefault
;
325 conf
.state_line_color
= clDefault
;
326 conf
.state_flags_color
= clDefault
;
327 conf
.main_color
= clYellow
;
328 conf
.main_highlight_color
= conf
.main_color
;
329 conf
.progressbar_color
= clDefault
;
330 conf
.statusbar_color
= clDefault
;
331 conf
.alternative_ui_separator_color
= clBlack
;
332 conf
.active_column_color
= clRed
;
333 conf
.window_border
= brGreen
;
334 conf
.active_window_border
= brRed
;
335 conf
.media_lib_primary_tag
= MPD_TAG_ARTIST
;
336 conf
.enable_idle_notifications
= false;
337 conf
.colors_enabled
= true;
338 conf
.fancy_scrolling
= true;
339 conf
.playlist_show_remaining_time
= false;
340 conf
.columns_in_playlist
= false;
341 conf
.columns_in_browser
= false;
342 conf
.columns_in_search_engine
= false;
343 conf
.header_visibility
= true;
344 conf
.header_text_scrolling
= true;
345 conf
.statusbar_visibility
= true;
346 conf
.centered_cursor
= false;
347 conf
.screen_switcher_previous
= false;
348 conf
.autocenter_mode
= false;
349 conf
.wrapped_search
= true;
350 conf
.space_selects
= false;
351 conf
.ncmpc_like_songs_adding
= false;
352 conf
.albums_in_tag_editor
= false;
353 conf
.incremental_seeking
= true;
354 conf
.now_playing_lyrics
= false;
355 conf
.local_browser_show_hidden_files
= false;
356 conf
.search_in_db
= true;
357 conf
.display_screens_numbers_on_start
= true;
358 conf
.jump_to_now_playing_song_at_start
= true;
359 conf
.clock_display_seconds
= false;
360 conf
.display_bitrate
= false;
361 conf
.display_remaining_time
= false;
362 conf
.ignore_leading_the
= false;
363 conf
.block_search_constraints_change
= true;
364 conf
.use_console_editor
= false;
365 conf
.use_cyclic_scrolling
= false;
366 conf
.allow_physical_files_deletion
= false;
367 conf
.allow_physical_directories_deletion
= false;
368 conf
.ask_before_clearing_main_playlist
= false;
369 conf
.mouse_support
= true;
370 conf
.mouse_list_scroll_whole_page
= true;
371 conf
.new_design
= false;
372 conf
.visualizer_use_wave
= true;
373 conf
.browser_sort_by_mtime
= false;
374 conf
.tag_editor_extended_numeration
= false;
375 conf
.media_library_display_date
= true;
376 conf
.set_window_title
= true;
377 conf
.mpd_port
= 6600;
378 conf
.mpd_connection_timeout
= 15;
379 conf
.crossfade_time
= 5;
381 conf
.playlist_disable_highlight_delay
= 5;
382 conf
.message_delay_time
= 4;
385 conf
.lines_scrolled
= 2;
386 conf
.search_engine_default_search_mode
= 0;
387 conf
.selected_item_suffix_length
= 0;
388 # ifdef HAVE_LANGINFO_H
389 conf
.system_encoding
= nl_langinfo(CODESET
);
390 if (conf
.system_encoding
== "UTF-8") // mpd uses utf-8 by default so no need to convert
391 conf
.system_encoding
.clear();
392 # endif // HAVE_LANGINFO_H
394 // default screens sequence
395 conf
.screens_seq
.push_back(myPlaylist
);
396 conf
.screens_seq
.push_back(myBrowser
);
399 void ReadKeys(ncmpcpp_keys
&keys
)
401 std::ifstream
f(keys_config_file
.c_str());
410 if (!key
.empty() && key
[0] != '#')
412 if (key
.find("key_up ") != std::string::npos
)
413 GetKeys(key
, keys
.Up
);
414 else if (key
.find("key_down ") != std::string::npos
)
415 GetKeys(key
, keys
.Down
);
416 else if (key
.find("key_page_up ") != std::string::npos
)
417 GetKeys(key
, keys
.PageUp
);
418 else if (key
.find("key_page_down ") != std::string::npos
)
419 GetKeys(key
, keys
.PageDown
);
420 else if (key
.find("key_home ") != std::string::npos
)
421 GetKeys(key
, keys
.Home
);
422 else if (key
.find("key_end ") != std::string::npos
)
423 GetKeys(key
, keys
.End
);
424 else if (key
.find("key_space ") != std::string::npos
)
425 GetKeys(key
, keys
.Space
);
426 else if (key
.find("key_enter ") != std::string::npos
)
427 GetKeys(key
, keys
.Enter
);
428 else if (key
.find("key_delete ") != std::string::npos
)
429 GetKeys(key
, keys
.Delete
);
430 else if (key
.find("key_volume_up ") != std::string::npos
)
431 GetKeys(key
, keys
.VolumeUp
);
432 else if (key
.find("key_volume_down ") != std::string::npos
)
433 GetKeys(key
, keys
.VolumeDown
);
434 else if (key
.find("key_screen_switcher ") != std::string::npos
)
435 GetKeys(key
, keys
.ScreenSwitcher
);
436 else if (key
.find("key_help ") != std::string::npos
)
437 GetKeys(key
, keys
.Help
);
438 else if (key
.find("key_playlist ") != std::string::npos
)
439 GetKeys(key
, keys
.Playlist
);
440 else if (key
.find("key_browser ") != std::string::npos
)
441 GetKeys(key
, keys
.Browser
);
442 else if (key
.find("key_search_engine ") != std::string::npos
)
443 GetKeys(key
, keys
.SearchEngine
);
444 else if (key
.find("key_media_library ") != std::string::npos
)
445 GetKeys(key
, keys
.MediaLibrary
);
446 else if (key
.find("key_playlist_editor ") != std::string::npos
)
447 GetKeys(key
, keys
.PlaylistEditor
);
448 else if (key
.find("key_tag_editor ") != std::string::npos
)
449 GetKeys(key
, keys
.TagEditor
);
450 else if (key
.find("key_outputs ") != std::string::npos
)
451 GetKeys(key
, keys
.Outputs
);
452 else if (key
.find("key_music_visualizer ") != std::string::npos
)
453 GetKeys(key
, keys
.Visualizer
);
454 else if (key
.find("key_clock ") != std::string::npos
)
455 GetKeys(key
, keys
.Clock
);
456 else if (key
.find("key_server_info ") != std::string::npos
)
457 GetKeys(key
, keys
.ServerInfo
);
458 else if (key
.find("key_stop ") != std::string::npos
)
459 GetKeys(key
, keys
.Stop
);
460 else if (key
.find("key_pause ") != std::string::npos
)
461 GetKeys(key
, keys
.Pause
);
462 else if (key
.find("key_next ") != std::string::npos
)
463 GetKeys(key
, keys
.Next
);
464 else if (key
.find("key_prev ") != std::string::npos
)
465 GetKeys(key
, keys
.Prev
);
466 else if (key
.find("key_seek_forward ") != std::string::npos
)
467 GetKeys(key
, keys
.SeekForward
);
468 else if (key
.find("key_seek_backward ") != std::string::npos
)
469 GetKeys(key
, keys
.SeekBackward
);
470 else if (key
.find("key_toggle_repeat ") != std::string::npos
)
471 GetKeys(key
, keys
.ToggleRepeat
);
472 else if (key
.find("key_toggle_random ") != std::string::npos
)
473 GetKeys(key
, keys
.ToggleRandom
);
474 else if (key
.find("key_toggle_single ") != std::string::npos
)
475 GetKeys(key
, keys
.ToggleSingle
);
476 else if (key
.find("key_toggle_consume ") != std::string::npos
)
477 GetKeys(key
, keys
.ToggleConsume
);
478 else if (key
.find("key_toggle_replay_gain_mode ") != std::string::npos
)
479 GetKeys(key
, keys
.ToggleReplayGainMode
);
480 else if (key
.find("key_toggle_space_mode ") != std::string::npos
)
481 GetKeys(key
, keys
.ToggleSpaceMode
);
482 else if (key
.find("key_toggle_add_mode ") != std::string::npos
)
483 GetKeys(key
, keys
.ToggleAddMode
);
484 else if (key
.find("key_toggle_mouse ") != std::string::npos
)
485 GetKeys(key
, keys
.ToggleMouse
);
486 else if (key
.find("key_shuffle ") != std::string::npos
)
487 GetKeys(key
, keys
.Shuffle
);
488 else if (key
.find("key_toggle_crossfade ") != std::string::npos
)
489 GetKeys(key
, keys
.ToggleCrossfade
);
490 else if (key
.find("key_set_crossfade ") != std::string::npos
)
491 GetKeys(key
, keys
.SetCrossfade
);
492 else if (key
.find("key_update_db ") != std::string::npos
)
493 GetKeys(key
, keys
.UpdateDB
);
494 else if (key
.find("key_sort_playlist ") != std::string::npos
)
495 GetKeys(key
, keys
.SortPlaylist
);
496 else if (key
.find("key_apply_filter ") != std::string::npos
)
497 GetKeys(key
, keys
.ApplyFilter
);
498 else if (key
.find("key_find_forward ") != std::string::npos
)
499 GetKeys(key
, keys
.FindForward
);
500 else if (key
.find("key_find_backward ") != std::string::npos
)
501 GetKeys(key
, keys
.FindBackward
);
502 else if (key
.find("key_next_found_position ") != std::string::npos
)
503 GetKeys(key
, keys
.NextFoundPosition
);
504 else if (key
.find("key_prev_found_position ") != std::string::npos
)
505 GetKeys(key
, keys
.PrevFoundPosition
);
506 else if (key
.find("key_toggle_find_mode ") != std::string::npos
)
507 GetKeys(key
, keys
.ToggleFindMode
);
508 else if (key
.find("key_edit_tags ") != std::string::npos
)
509 GetKeys(key
, keys
.EditTags
);
510 else if (key
.find("key_go_to_position ") != std::string::npos
)
511 GetKeys(key
, keys
.GoToPosition
);
512 else if (key
.find("key_song_info ") != std::string::npos
)
513 GetKeys(key
, keys
.SongInfo
);
514 else if (key
.find("key_artist_info ") != std::string::npos
)
515 GetKeys(key
, keys
.ArtistInfo
);
516 else if (key
.find("key_lyrics ") != std::string::npos
)
517 GetKeys(key
, keys
.Lyrics
);
518 else if (key
.find("key_reverse_selection ") != std::string::npos
)
519 GetKeys(key
, keys
.ReverseSelection
);
520 else if (key
.find("key_deselect_all ") != std::string::npos
)
521 GetKeys(key
, keys
.DeselectAll
);
522 else if (key
.find("key_add_selected_items ") != std::string::npos
)
523 GetKeys(key
, keys
.AddSelected
);
524 else if (key
.find("key_clear ") != std::string::npos
)
525 GetKeys(key
, keys
.Clear
);
526 else if (key
.find("key_crop ") != std::string::npos
)
527 GetKeys(key
, keys
.Crop
);
528 else if (key
.find("key_move_song_up ") != std::string::npos
)
529 GetKeys(key
, keys
.MvSongUp
);
530 else if (key
.find("key_move_song_down ") != std::string::npos
)
531 GetKeys(key
, keys
.MvSongDown
);
532 else if (key
.find("key_move_to ") != std::string::npos
)
533 GetKeys(key
, keys
.MoveTo
);
534 else if (key
.find("key_add ") != std::string::npos
)
535 GetKeys(key
, keys
.Add
);
536 else if (key
.find("key_save_playlist ") != std::string::npos
)
537 GetKeys(key
, keys
.SavePlaylist
);
538 else if (key
.find("key_go_to_now_playing ") != std::string::npos
)
539 GetKeys(key
, keys
.GoToNowPlaying
);
540 else if (key
.find("key_toggle_auto_center ") != std::string::npos
)
541 GetKeys(key
, keys
.ToggleAutoCenter
);
542 else if (key
.find("key_toggle_display_mode ") != std::string::npos
)
543 GetKeys(key
, keys
.ToggleDisplayMode
);
544 else if (key
.find("key_toggle_lyrics_db ") != std::string::npos
)
545 GetKeys(key
, keys
.ToggleLyricsDB
);
546 else if (key
.find("key_go_to_containing_directory ") != std::string::npos
)
547 GetKeys(key
, keys
.GoToContainingDir
);
548 else if (key
.find("key_go_to_media_library ") != std::string::npos
)
549 GetKeys(key
, keys
.GoToMediaLibrary
);
550 else if (key
.find("key_go_to_parent_dir ") != std::string::npos
)
551 GetKeys(key
, keys
.GoToParentDir
);
552 else if (key
.find("key_switch_tag_type_list ") != std::string::npos
)
553 GetKeys(key
, keys
.SwitchTagTypeList
);
554 else if (key
.find("key_quit ") != std::string::npos
)
555 GetKeys(key
, keys
.Quit
);
561 void ReadConfiguration(ncmpcpp_config
&conf
)
563 std::ifstream
f(config_file
.c_str());
566 while (f
.is_open() && !f
.eof())
569 if (!cl
.empty() && cl
[0] != '#')
571 v
= GetLineValue(cl
);
572 if (cl
.find("mpd_host") != std::string::npos
)
577 else if (cl
.find("mpd_music_dir") != std::string::npos
)
581 // if ~ is used at the beginning, replace it with user's home folder
583 v
.replace(0, 1, home_path
);
584 conf
.mpd_music_dir
= v
+ "/";
587 else if (cl
.find("visualizer_fifo_path") != std::string::npos
)
590 conf
.visualizer_fifo_path
= v
;
592 else if (cl
.find("visualizer_output_name") != std::string::npos
)
595 conf
.visualizer_output_name
= v
;
597 else if (cl
.find("mpd_port") != std::string::npos
)
600 conf
.mpd_port
= StrToInt(v
);
602 else if (cl
.find("mpd_connection_timeout") != std::string::npos
)
605 conf
.mpd_connection_timeout
= StrToInt(v
);
607 else if (cl
.find("mpd_crossfade_time") != std::string::npos
)
610 conf
.crossfade_time
= StrToInt(v
);
612 else if (cl
.find("seek_time") != std::string::npos
)
615 conf
.seek_time
= StrToInt(v
);
617 else if (cl
.find("playlist_disable_highlight_delay") != std::string::npos
)
619 if (StrToInt(v
) >= 0)
620 conf
.playlist_disable_highlight_delay
= StrToInt(v
);
622 else if (cl
.find("message_delay_time") != std::string::npos
)
625 conf
.message_delay_time
= StrToInt(v
);
627 else if (cl
.find("song_list_format") != std::string::npos
)
631 MPD::Song::ValidateFormat("song_list_format", v
);
632 conf
.song_list_format
= '{';
633 conf
.song_list_format
+= v
;
634 conf
.song_list_format
+= '}';
637 else if (cl
.find("song_columns_list_format") != std::string::npos
)
640 conf
.song_list_columns_format
= v
;
642 else if (cl
.find("song_status_format") != std::string::npos
)
646 MPD::Song::ValidateFormat("song_status_format", v
);
647 conf
.song_status_format
= '{';
648 conf
.song_status_format
+= v
;
649 conf
.song_status_format
+= '}';
650 // make version without colors
651 if (conf
.song_status_format
.find("$") != std::string::npos
)
653 Buffer status_no_colors
;
654 String2Buffer(conf
.song_status_format
, status_no_colors
);
655 conf
.song_status_format_no_colors
= status_no_colors
.Str();
658 conf
.song_status_format_no_colors
= conf
.song_status_format
;
661 else if (cl
.find("song_library_format") != std::string::npos
)
665 MPD::Song::ValidateFormat("song_library_format", v
);
666 conf
.song_library_format
= '{';
667 conf
.song_library_format
+= v
;
668 conf
.song_library_format
+= '}';
671 else if (cl
.find("tag_editor_album_format") != std::string::npos
)
675 MPD::Song::ValidateFormat("tag_editor_album_format", v
);
676 conf
.tag_editor_album_format
= '{';
677 conf
.tag_editor_album_format
+= v
;
678 conf
.tag_editor_album_format
+= '}';
681 else if (cl
.find("external_editor") != std::string::npos
)
684 conf
.external_editor
= v
;
686 else if (cl
.find("system_encoding") != std::string::npos
)
689 conf
.system_encoding
= v
+ "//TRANSLIT";
691 else if (cl
.find("execute_on_song_change") != std::string::npos
)
694 conf
.execute_on_song_change
= v
;
696 else if (cl
.find("alternative_header_first_line_format") != std::string::npos
)
700 MPD::Song::ValidateFormat("alternative_header_first_line_format", v
);
701 conf
.new_header_first_line
= '{';
702 conf
.new_header_first_line
+= v
;
703 conf
.new_header_first_line
+= '}';
706 else if (cl
.find("alternative_header_second_line_format") != std::string::npos
)
710 MPD::Song::ValidateFormat("alternative_header_second_line_format", v
);
711 conf
.new_header_second_line
= '{';
712 conf
.new_header_second_line
+= v
;
713 conf
.new_header_second_line
+= '}';
716 else if (cl
.find("browser_playlist_prefix") != std::string::npos
)
720 conf
.browser_playlist_prefix
.Clear();
721 String2Buffer(v
, conf
.browser_playlist_prefix
);
724 else if (cl
.find("progressbar_look") != std::string::npos
)
726 conf
.progressbar
= TO_WSTRING(v
);
727 if (conf
.progressbar
.length() != 2)
728 FatalError("the length of progressbar_look is not two characters long!");
730 else if (cl
.find("default_tag_editor_pattern") != std::string::npos
)
735 else if (cl
.find("selected_item_prefix") != std::string::npos
)
739 conf
.selected_item_prefix
.Clear();
740 String2Buffer(v
, conf
.selected_item_prefix
);
743 else if (cl
.find("selected_item_suffix") != std::string::npos
)
747 conf
.selected_item_suffix
.Clear();
748 String2Buffer(v
, conf
.selected_item_suffix
);
749 conf
.selected_item_suffix_length
= Window::Length(TO_WSTRING(conf
.selected_item_suffix
.Str()));
752 else if (cl
.find("now_playing_prefix") != std::string::npos
)
756 conf
.now_playing_prefix
.Clear();
757 String2Buffer(v
, conf
.now_playing_prefix
);
760 else if (cl
.find("now_playing_suffix") != std::string::npos
)
764 conf
.now_playing_suffix
.Clear();
765 String2Buffer(TO_WSTRING(v
), conf
.now_playing_suffix
);
768 else if (cl
.find("color1") != std::string::npos
)
771 conf
.color1
= IntoColor(v
);
773 else if (cl
.find("color2") != std::string::npos
)
776 conf
.color2
= IntoColor(v
);
778 else if (cl
.find("mpd_communication_mode") != std::string::npos
)
780 conf
.enable_idle_notifications
= v
== "notifications";
782 else if (cl
.find("colors_enabled") != std::string::npos
)
784 conf
.colors_enabled
= v
== "yes";
786 else if (cl
.find("fancy_scrolling") != std::string::npos
)
788 conf
.fancy_scrolling
= v
== "yes";
790 else if (cl
.find("cyclic_scrolling") != std::string::npos
)
792 conf
.use_cyclic_scrolling
= v
== "yes";
794 else if (cl
.find("playlist_show_remaining_time") != std::string::npos
)
796 conf
.playlist_show_remaining_time
= v
== "yes";
798 else if (cl
.find("playlist_display_mode") != std::string::npos
)
800 conf
.columns_in_playlist
= v
== "columns";
802 else if (cl
.find("browser_display_mode") != std::string::npos
)
804 conf
.columns_in_browser
= v
== "columns";
806 else if (cl
.find("search_engine_display_mode") != std::string::npos
)
808 conf
.columns_in_search_engine
= v
== "columns";
810 else if (cl
.find("header_visibility") != std::string::npos
)
812 conf
.header_visibility
= v
== "yes";
814 else if (cl
.find("header_text_scrolling") != std::string::npos
)
816 conf
.header_text_scrolling
= v
== "yes";
818 else if (cl
.find("statusbar_visibility") != std::string::npos
)
820 conf
.statusbar_visibility
= v
== "yes";
822 else if (cl
.find("screen_switcher_mode") != std::string::npos
)
824 if (v
.find("previous") != std::string::npos
)
826 conf
.screen_switcher_previous
= true;
828 else if (v
.find("sequence") != std::string::npos
)
830 conf
.screen_switcher_previous
= false;
831 conf
.screens_seq
.clear();
832 for (std::string::const_iterator it
= v
.begin(); it
!= v
.end(); )
834 while (it
!= v
.end() && !isdigit(*it
))
838 if (BasicScreen
*screen
= IntoScreen(atoi(&*it
)))
839 conf
.screens_seq
.push_back(screen
);
840 while (it
!= v
.end() && isdigit(*it
))
843 // throw away duplicates
844 conf
.screens_seq
.unique();
847 else if (cl
.find("autocenter_mode") != std::string::npos
)
849 conf
.autocenter_mode
= v
== "yes";
851 else if (cl
.find("centered_cursor") != std::string::npos
)
853 conf
.centered_cursor
= v
== "yes";
855 else if (cl
.find("default_find_mode") != std::string::npos
)
857 conf
.wrapped_search
= v
== "wrapped";
859 else if (cl
.find("default_space_mode") != std::string::npos
)
861 conf
.space_selects
= v
== "select";
863 else if (cl
.find("default_tag_editor_left_col") != std::string::npos
)
865 conf
.albums_in_tag_editor
= v
== "albums";
867 else if (cl
.find("incremental_seeking") != std::string::npos
)
869 conf
.incremental_seeking
= v
== "yes";
871 else if (cl
.find("show_hidden_files_in_local_browser") != std::string::npos
)
873 conf
.local_browser_show_hidden_files
= v
== "yes";
875 else if (cl
.find("follow_now_playing_lyrics") != std::string::npos
)
877 conf
.now_playing_lyrics
= v
== "yes";
879 else if (cl
.find("ncmpc_like_songs_adding") != std::string::npos
)
881 conf
.ncmpc_like_songs_adding
= v
== "yes";
883 else if (cl
.find("default_place_to_search_in") != std::string::npos
)
885 conf
.search_in_db
= v
== "database";
887 else if (cl
.find("display_screens_numbers_on_start") != std::string::npos
)
889 conf
.display_screens_numbers_on_start
= v
== "yes";
891 else if (cl
.find("jump_to_now_playing_song_at_start") != std::string::npos
)
893 conf
.jump_to_now_playing_song_at_start
= v
== "yes";
895 else if (cl
.find("clock_display_seconds") != std::string::npos
)
897 conf
.clock_display_seconds
= v
== "yes";
899 else if (cl
.find("display_bitrate") != std::string::npos
)
901 conf
.display_bitrate
= v
== "yes";
903 else if (cl
.find("display_remaining_time") != std::string::npos
)
905 conf
.display_remaining_time
= v
== "yes";
907 else if (cl
.find("ignore_leading_the") != std::string::npos
)
909 conf
.ignore_leading_the
= v
== "yes";
911 else if (cl
.find("use_console_editor") != std::string::npos
)
913 conf
.use_console_editor
= v
== "yes";
915 else if (cl
.find("block_search_constraints_change_if_items_found") != std::string::npos
)
917 conf
.block_search_constraints_change
= v
== "yes";
919 else if (cl
.find("allow_physical_files_deletion") != std::string::npos
)
921 conf
.allow_physical_files_deletion
= v
== "yes";
923 else if (cl
.find("allow_physical_directories_deletion") != std::string::npos
)
925 conf
.allow_physical_directories_deletion
= v
== "yes";
927 else if (cl
.find("ask_before_clearing_main_playlist") != std::string::npos
)
929 conf
.ask_before_clearing_main_playlist
= v
== "yes";
931 else if (cl
.find("visualizer_type") != std::string::npos
)
933 conf
.visualizer_use_wave
= v
== "wave";
935 else if (cl
.find("mouse_support") != std::string::npos
)
937 conf
.mouse_support
= v
== "yes";
939 else if (cl
.find("mouse_list_scroll_whole_page") != std::string::npos
)
941 conf
.mouse_list_scroll_whole_page
= v
== "yes";
943 else if (cl
.find("user_interface") != std::string::npos
)
945 conf
.new_design
= v
== "alternative";
947 else if (cl
.find("tag_editor_extended_numeration") != std::string::npos
)
949 conf
.tag_editor_extended_numeration
= v
== "yes";
951 else if (cl
.find("media_library_display_date") != std::string::npos
)
953 conf
.media_library_display_date
= v
== "yes";
955 else if (cl
.find("enable_window_title") != std::string::npos
)
957 conf
.set_window_title
= v
== "yes";
959 else if (cl
.find("regular_expressions") != std::string::npos
)
961 conf
.regex_type
= REG_EXTENDED
* (v
!= "basic");
963 # ifdef HAVE_CURL_CURL_H
964 else if (cl
.find("lyrics_database") != std::string::npos
)
968 unsigned n
= StrToInt(v
)-1;
969 conf
.lyrics_db
= n
< Lyrics::DBs
? n
: 0;
972 # endif // HAVE_CURL_CURL_H
973 else if (cl
.find("lines_scrolled") != std::string::npos
)
976 conf
.lines_scrolled
= StrToInt(v
);
978 else if (cl
.find("search_engine_default_search_mode") != std::string::npos
)
982 unsigned mode
= StrToInt(v
);
984 conf
.search_engine_default_search_mode
= mode
;
987 else if (cl
.find("song_window_title_format") != std::string::npos
)
991 MPD::Song::ValidateFormat("song_window_title_format", v
);
992 conf
.song_window_title_format
= '{';
993 conf
.song_window_title_format
+= v
;
994 conf
.song_window_title_format
+= '}';
997 else if (cl
.find("empty_tag_marker") != std::string::npos
)
999 conf
.empty_tag
= v
; // is this case empty string is allowed
1001 else if (cl
.find("empty_tag_color") != std::string::npos
)
1004 conf
.empty_tags_color
= IntoColor(v
);
1006 else if (cl
.find("header_window_color") != std::string::npos
)
1009 conf
.header_color
= IntoColor(v
);
1011 else if (cl
.find("volume_color") != std::string::npos
)
1014 conf
.volume_color
= IntoColor(v
);
1016 else if (cl
.find("state_line_color") != std::string::npos
)
1019 conf
.state_line_color
= IntoColor(v
);
1021 else if (cl
.find("state_flags_color") != std::string::npos
)
1024 conf
.state_flags_color
= IntoColor(v
);
1026 else if (cl
.find("main_window_color") != std::string::npos
)
1029 conf
.main_color
= IntoColor(v
);
1031 else if (cl
.find("main_window_highlight_color") != std::string::npos
)
1034 conf
.main_highlight_color
= IntoColor(v
);
1036 else if (cl
.find("progressbar_color") != std::string::npos
)
1039 conf
.progressbar_color
= IntoColor(v
);
1041 else if (cl
.find("statusbar_color") != std::string::npos
)
1044 conf
.statusbar_color
= IntoColor(v
);
1046 else if (cl
.find("alternative_ui_separator_color") != std::string::npos
)
1049 conf
.alternative_ui_separator_color
= IntoColor(v
);
1051 else if (cl
.find("active_column_color") != std::string::npos
)
1054 conf
.active_column_color
= IntoColor(v
);
1056 else if (cl
.find("window_border_color ") != std::string::npos
)
1059 conf
.window_border
= IntoBorder(v
);
1061 else if (cl
.find("active_window_border") != std::string::npos
)
1064 conf
.active_window_border
= IntoBorder(v
);
1066 else if (cl
.find("media_library_left_column") != std::string::npos
)
1069 conf
.media_lib_primary_tag
= IntoTagItem(v
[0]);
1075 for (std::string width
= GetLineValue(conf
.song_list_columns_format
, '(', ')', 1); !width
.empty(); width
= GetLineValue(conf
.song_list_columns_format
, '(', ')', 1))
1078 col
.color
= IntoColor(GetLineValue(conf
.song_list_columns_format
, '[', ']', 1));
1079 std::string tag_type
= GetLineValue(conf
.song_list_columns_format
, '{', '}', 1);
1080 if (tag_type
.length() > 0) // at least tag type was specified
1081 col
.type
= tag_type
[0];
1085 col
.display_empty_tag
= 0;
1087 col
.fixed
= *width
.rbegin() == 'f';
1088 for (std::string::const_iterator it
= tag_type
.begin()+(tag_type
.length() > 0); it
!= tag_type
.end(); ++it
)
1093 col
.right_alignment
= 1;
1096 col
.display_empty_tag
= 0;
1100 col
.width
= StrToInt(width
);
1101 conf
.columns
.push_back(col
);