diff --git a/src/main.c b/src/main.c
index 1e65cfeb8bf16145b6415dfb2737ae2a28e690fa..a0f7c0c99c7aedd42b204af2cfcb2d64233ebd8c 100644 (file)
--- a/src/main.c
+++ b/src/main.c
#include "screen_utils.h"
#include "strfsong.h"
#include "i18n.h"
-#include "gcc.h"
#ifndef NCMPC_MINI
#include "conf.h"
#include <signal.h>
#include <string.h>
+#ifdef ENABLE_LOCALE
+#include <locale.h>
+#endif
+
/* time between mpd updates [s] */
static const guint update_interval = 500;
}
static void
-error_callback(mpd_unused mpdclient_t *c, gint error, const gchar *msg)
+error_callback(G_GNUC_UNUSED mpdclient_t *c, gint error, const gchar *_msg)
{
+ char *msg = utf8_to_locale(_msg);
+
error = error & 0xFF;
switch (error) {
case MPD_ERROR_CONNPORT:
doupdate();
connected = FALSE;
}
+
+ g_free(msg);
}
#ifndef NCMPC_MINI
}
static void
-catch_sigint(mpd_unused int sig)
+catch_sigint(G_GNUC_UNUSED int sig)
{
g_main_loop_quit(main_loop);
}
static void
-catch_sigcont(mpd_unused int sig)
+catch_sigcont(G_GNUC_UNUSED int sig)
{
screen_resize(mpd);
}
static guint timer_sigwinch_id;
static gboolean
-timer_sigwinch(mpd_unused gpointer data)
+timer_sigwinch(G_GNUC_UNUSED gpointer data)
{
/* the following causes the screen to flicker. There might be
better solutions, but I believe it isn't all that
}
static void
-catch_sigwinch(mpd_unused int sig)
+catch_sigwinch(G_GNUC_UNUSED int sig)
{
if (timer_sigwinch_id != 0)
g_source_remove(timer_sigwinch_id);
* broken. It tries to recover by reconnecting periodically.
*/
static gboolean
-timer_reconnect(mpd_unused gpointer data)
+timer_reconnect(G_GNUC_UNUSED gpointer data)
{
int ret;
#ifndef NCMPC_MINI
/* quit if mpd is pre 0.11.0 - song id not supported by mpd */
if (MPD_VERSION_LT(mpd, 0, 11, 0)) {
- screen_status_printf(_("Error: MPD version %d.%d.%d is to old (0.11.0 needed).\n"),
+ screen_status_printf(_("Error: MPD version %d.%d.%d is to old (%s needed)"),
mpd->connection->version[0],
mpd->connection->version[1],
- mpd->connection->version[2]);
+ mpd->connection->version[2],
+ "0.11.0");
mpdclient_disconnect(mpd);
doupdate();
}
#endif
- screen_status_printf(_("Connected to %s!"), options.host);
+ screen_status_printf(_("Connected to %s"), options.host);
doupdate();
connected = TRUE;
* 500ms. It is used for delayed seeking.
*/
static gboolean
-timer_idle(mpd_unused gpointer data)
+timer_idle(G_GNUC_UNUSED gpointer data)
{
screen_idle(mpd);
return TRUE;
}
-static gboolean
-keyboard_event(mpd_unused GIOChannel *source,
- mpd_unused GIOCondition condition, mpd_unused gpointer data)
+void begin_input_event(void)
{
- command_t cmd;
-
/* remove the idle timeout; add it later with fresh interval */
g_source_remove(idle_source_id);
+}
- if ((cmd=get_keyboard_command()) != CMD_NONE) {
- if (cmd == CMD_QUIT) {
- g_main_loop_quit(main_loop);
- return FALSE;
- }
+void end_input_event(void)
+{
+ screen_update(mpd);
- screen_cmd(mpd, cmd);
+ idle_source_id = g_timeout_add(idle_interval, timer_idle, NULL);
+}
- if (cmd == CMD_VOLUME_UP || cmd == CMD_VOLUME_DOWN) {
- /* make sure we dont update the volume yet */
- g_source_remove(update_source_id);
- update_source_id = g_timeout_add(update_interval,
- timer_mpd_update,
- GINT_TO_POINTER(TRUE));
- }
+int do_input_event(command_t cmd)
+{
+ if (cmd == CMD_QUIT) {
+ g_main_loop_quit(main_loop);
+ return -1;
}
- screen_update(mpd);
+ screen_cmd(mpd, cmd);
- idle_source_id = g_timeout_add(idle_interval, timer_idle, NULL);
- return TRUE;
+ if (cmd == CMD_VOLUME_UP || cmd == CMD_VOLUME_DOWN) {
+ /* make sure we dont update the volume yet */
+ g_source_remove(update_source_id);
+ update_source_id = g_timeout_add(update_interval,
+ timer_mpd_update,
+ GINT_TO_POINTER(TRUE));
+ }
+
+ return 0;
}
-#ifdef ENABLE_LIRC
static gboolean
-lirc_event(mpd_unused GIOChannel *source,
- mpd_unused GIOCondition condition, mpd_unused gpointer data)
+keyboard_event(G_GNUC_UNUSED GIOChannel *source,
+ G_GNUC_UNUSED GIOCondition condition,
+ G_GNUC_UNUSED gpointer data)
{
command_t cmd;
- /* remove the idle timeout; add it later with fresh interval */
- g_source_remove(idle_source_id);
+ begin_input_event();
- if ((cmd = ncmpc_lirc_get_command()) != CMD_NONE) {
- if (cmd == CMD_QUIT) {
- g_main_loop_quit(main_loop);
+ if ((cmd=get_keyboard_command()) != CMD_NONE)
+ if (do_input_event(cmd) != 0)
return FALSE;
- }
-
- screen_cmd(mpd, cmd);
- if (cmd == CMD_VOLUME_UP || cmd == CMD_VOLUME_DOWN) {
- /* make sure we dont update the volume yet */
- g_source_remove(update_source_id);
- update_source_id = g_timeout_add(update_interval,
- timer_mpd_update,
- GINT_TO_POINTER(TRUE));
- }
- }
-
- screen_update(mpd);
-
- idle_source_id = g_timeout_add(idle_interval, timer_idle, NULL);
+ end_input_event();
return TRUE;
}
-#endif
#ifndef NCMPC_MINI
/**
* message every 10 seconds.
*/
static gboolean
-timer_check_key_bindings(mpd_unused gpointer data)
+timer_check_key_bindings(G_GNUC_UNUSED gpointer data)
{
char buf[256];
gboolean key_error;
main(int argc, const char *argv[])
{
struct sigaction act;
-#if defined(HAVE_LOCALE_H) && !defined(NCMPC_MINI)
+#ifdef ENABLE_LOCALE
const char *charset = NULL;
#endif
GIOChannel *keyboard_channel;
GIOChannel *lirc_channel = NULL;
#endif
-#if defined(HAVE_LOCALE_H) && !defined(NCMPC_MINI)
+#ifdef ENABLE_LOCALE
/* time and date formatting */
setlocale(LC_TIME,"");
/* care about sorting order etc */
/* parse command line options - 1 pass get configuration files */
options_parse(argc, argv);
- /* read configuration */
#ifndef NCMPC_MINI
+ /* read configuration */
read_configuration();
-#endif
/* check key bindings */
check_key_bindings(NULL, NULL, 0);
+#endif
/* parse command line options - 2 pass */
options_parse(argc, argv);
#endif
exit_and_cleanup();
+
+#ifdef ENABLE_LYRICS_SCREEN
+ lyrics_deinit();
+#endif
+
ncu_deinit();
return 0;