static gboolean
ol_player_listen_init_dbus ()
{
  /* ol_log_func (); */
  if (connection == NULL)
  {
    connection = dbus_g_bus_get (DBUS_BUS_SESSION,
                               &error);
    if (connection == NULL)
    {
      ol_debugf ("get connection failed: %s\n", error->message);
      g_error_free(error);
      error = NULL;
      return FALSE;
    }
    if (proxy != NULL)
      g_object_unref (proxy);
    proxy = NULL;
  }
  if (proxy == NULL)
  {
    proxy = dbus_g_proxy_new_for_name_owner (connection, service, path, interface, &error);
    if (proxy == NULL)
    {
      ol_debugf ("get proxy failed: %s\n", error->message);
      g_error_free (error);
      error = NULL;
      return FALSE;
    }
  }
  return TRUE;
}
Example #2
0
char *
ol_path_alloc(void)
{
  char *ptr;

  if(pathmax == 0)
  {
    errno = 0;
    if((pathmax = pathconf("/", _PC_PATH_MAX)) < 0)
    {
      if(errno == 0)
      {
        pathmax = PATH_MAX_GUESS;
      }
      else
      {
        ol_debugf ("pathconf error for _PC_PATH_MAX\n");
        return NULL;
      }
    }
    else
    {
      pathmax++;
    }
  }

  if((ptr = calloc(pathmax, sizeof(char))) == NULL) {
    ol_debugf ("malloc error for pathname");
    return NULL;
  }
  return ptr;
}
Example #3
0
static gboolean
ol_player_xmms2_go_rel (int rel)
{
  ol_log_func ();
  ol_debugf ("  rel:%d\n", rel);
  if (!ol_player_xmms2_ensure_connection ())
    return FALSE;
  xmmsc_result_t *result = xmmsc_playlist_set_next_rel (connection, rel);
  xmmsc_result_wait (result);
  xmmsv_t *return_value = xmmsc_result_get_value (result);
  if (xmmsv_is_error (return_value))
  {
    ol_debug ("Error on setting playlist next");
    return FALSE;
  }
  xmmsc_result_unref (result);

  result = xmmsc_playback_tickle (connection);
  xmmsc_result_wait (result);
  if (xmmsc_result_iserror (result))
  {
    ol_debug ("Error on tickle playback");
    return FALSE;
  }
  xmmsc_result_unref (result);
  return TRUE;
}
gboolean
internal_check_path_exist (const char *filename, gpointer data)
{
  ol_debugf ("%s:%s\n", __FUNCTION__, filename);
  ol_assert_ret (filename != NULL, FALSE);
  ol_assert_ret (data != NULL, FALSE);
  gboolean ret = TRUE;
  gchar * dirname = g_path_get_dirname (filename);
  if (dirname == NULL)
    return FALSE;
  if (g_mkdir_with_parents (dirname, S_IRUSR | S_IWUSR | S_IXUSR |
                             S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0)
  {
    ol_errorf ("  make directory '%s' failed\n", dirname);
    ret = FALSE;
  }
  else
  {
    char **ret_val = (char **) data;
    *ret_val = g_strdup (filename);
    ret = TRUE;
  }
  g_free (dirname);
  return ret;
}
static gboolean
internal_for_each (OlMusicInfo *info,
                   OlPathFunc func,
                   gpointer userdata)
{
  ol_log_func ();
  OlConfig *config = ol_config_get_instance ();
  gsize pathlen, namelen;
  char **path_list = ol_config_get_str_list (config, "General", "lrc-path", &pathlen);
  char **name_list = ol_config_get_str_list (config, "General", "lrc-filename", &namelen);
  if (path_list == NULL || name_list == NULL)
    return FALSE;
  if (path_list == NULL || name_list == NULL ||
      info == NULL || func == NULL)
    return FALSE;
  ol_debugf ("  uri: %s\n", info->uri);
  gboolean ret = ol_path_pattern_for_each (path_list,
                                           name_list,
                                           info,
                                           func,
                                           userdata);
  g_strfreev (path_list);
  g_strfreev (name_list);
  return ret;
}
Example #6
0
static gboolean
_get_active_player (void)
{
  ol_log_func ();
  player = ol_player_get_active_player ();
  if (player == NULL)
  {
    gboolean ignore = FALSE;
    if (first_run)
    {
      OlConfig *config = ol_config_get_instance ();
      char *player_cmd = ol_config_get_string (config,
                                               "General",
                                               "startup-player");
      if (!ol_is_string_empty (player_cmd))
      {
        ignore = TRUE;
        ol_debugf ("Running %s\n", player_cmd);
        g_spawn_command_line_async (player_cmd, NULL);
        sleep (5);
      }
      g_free (player_cmd);
    }
    if (!ignore)
    {
      printf (_("No supported player is running, exit.\n"));
      gtk_main_quit ();
    }
  }
  ol_display_module_set_player (module, player);
  first_run = FALSE;
  return player != NULL;
}
Example #7
0
static gboolean
ol_player_listen_get_music_info (OlMusicInfo *info)
{
  /* ol_log_func (); */
  ol_assert (info != NULL);
  if (connection == NULL || proxy == NULL)
    if (!ol_player_listen_init_dbus ())
    {
      ol_debug ("Initialize dbus proxy failed\n");
      return FALSE;
    }
  gchar *buf;
  enum OlPlayerStatus status = ol_player_listen_get_status ();
  ol_debugf ("  status: %d\n", (int)status);
  if (status == OL_PLAYER_PLAYING)
  {
    ol_music_info_clear (info);
    /* gets the title of current music */
    if (!ol_dbus_get_string (proxy,
                             get_title,
                             &info->title))
    {
      ol_error ("  Get title failed");
    }
    /* gets the artist of current music */
    if (!ol_dbus_get_string (proxy,
                             get_artist,
                             &info->artist))
    {
      ol_error ("  Get artist failed");
    }
    /* gets the album of current music */
    if (!ol_dbus_get_string (proxy,
                             get_album,
                             &info->album))
    {
      ol_error ("  Get album failed");
    }
    /* gets the location of the file */
    if (!ol_dbus_get_string (proxy,
                             get_uri,
                             &info->uri))
    {
      ol_error ("  Get track number failed");
    }
    return TRUE;
  }
  else if (status == OL_PLAYER_STOPPED)
  {
    return TRUE;
  }
  else
  {
    ol_errorf ("  unknown status\n");
    return FALSE;
  }
}
Example #8
0
static int
_find_by_info (const OlMusicInfo *info, char **lrcpath)
{
    int code;
    sqlite3_stmt *stmt;
    static char query[QUERY_BUFLEN] = "";
    static char where[FIELD_BUFLEN] = "";
    int ret = 0;
    ol_assert_ret (info->title != NULL, -1);
    ol_assert_ret (lrcpath != NULL, -1);
    _set_where_with_info (info, where, FIELD_BUFLEN);
    snprintf (query, FIELD_BUFLEN, FIND_LYRIC, where);
    ol_debugf ("%s\n", query);
    code = sqlite3_prepare_v2 (db, query, -1, &stmt, NULL);
    if (code != SQLITE_OK)
    {
        _show_error ();
        return -1;
    }
    code = sqlite3_step (stmt);
    if (code != SQLITE_ROW)
    {
        if (code == SQLITE_DONE)
        {
            *lrcpath = NULL;
            ret = 0;
        }
        else
        {
            ret = -1;
            _show_error ();
        }
    }
    else
    {
        const char *path = (const char*)sqlite3_column_text (stmt, 0);
        ol_debugf ("Path is: %s\n", path);
        *lrcpath = g_strdup (path);
        ret = 1;
    }
    sqlite3_finalize (stmt);
    return ret;
}
int
ol_elapse_emulator_get_last_ms (OlElapseEmulator *emulator,
                                int time)
{
  if (emulator->first_time < 0 || emulator->last_time - time > emulator->accuracy || time - emulator->last_time > emulator->accuracy)
  {
    /* reinitialize timer */
    ol_debugf ("prev:%d, time:%d\n", emulator->prev_time, time);
    ol_elapse_emulator_init (emulator, time, emulator->accuracy);
  }
  return emulator->last_time;
}
Example #10
0
int
ol_config_get_int (OlConfig *config, const char *group, const char *name)
{
  ol_assert_ret (config != NULL, 0);
  ol_assert_ret (name != NULL, 0);
  gint value = g_key_file_get_integer (OL_CONFIG_GET_PRIVATE (config)->config,
                                       group,
                                       name,
                                       NULL);
  ol_debugf ("[%s]%s:%d\n", group, name, value);
  return value;
}
Example #11
0
double
ol_config_get_double (OlConfig *config, const char *group, const char *name)
{
  ol_assert_ret (config != NULL, 0.0);
  ol_assert_ret (name != NULL, 0.0);
  double value = g_key_file_get_double (OL_CONFIG_GET_PRIVATE (config)->config,
                                        group,
                                        name,
                                        NULL);
  ol_debugf ("[%s]%s:%lf\n", group, name, value);
  return value;
}
Example #12
0
char*
ol_config_get_string (OlConfig *config, const char *group, const char *name)
{
  ol_assert_ret (config != NULL, NULL);
  ol_assert_ret (name != NULL, NULL);
  char *value = g_key_file_get_string (OL_CONFIG_GET_PRIVATE (config)->config,
                                        group,
                                        name,
                                        NULL);
  ol_debugf ("[%s]%s:%s\n", group, name, value);
  return value;
}
Example #13
0
static gboolean
ol_player_exaile02_get_music_info (OlMusicInfo *info)
{
  if (info == NULL)
    return FALSE;
  if (connection == NULL || proxy == NULL)
    if (!ol_player_exaile02_init_dbus ())
      return FALSE;
  /* gets the title of current music */
  if (info->title)
  {
    g_free (info->title);
    info->title = NULL;
  }
  if (!ol_dbus_get_string (proxy,
                           get_title,
                           &info->title))
  {
    return FALSE;
  }
  /* gets the artist of current music */
  if (info->artist)
  {
    g_free (info->artist);
    info->artist = NULL;
  }
  if (!ol_dbus_get_string (proxy,
                           get_artist,
                           &info->artist))
  {
    return FALSE;
  }
  /* gets the album of current music */
  if (info->album)
  {
    g_free (info->album);
    info->album = NULL;
  }
  if (!ol_dbus_get_string (proxy,
                           get_album,
                           &info->album))
  {
    return FALSE;
  }
  ol_debugf ("%s\n"
             "  title:%s\n"
             "  artist:%s\n",
             __FUNCTION__,
             info->title,
             info->artist);
  return TRUE;
}
Example #14
0
gboolean
internal_check_lyric_file (const char *filename, gpointer data)
{
  ol_log_func ();
  ol_debugf ("  filename:%s\n", filename);
  if (!ol_path_is_file (filename))
  {
    return FALSE;
  }
  char **ret_val = (char **) data;
  *ret_val = g_strdup (filename);
  return TRUE;
}
Example #15
0
struct OlPlayer*
ol_player_get_active_player (void)
{
    ol_log_func ();
    if (players == NULL)
    {
        return NULL;
    }
    int i;
    ol_debugf ("controller count:%d\n", players->len);
    for (i = 0; i < players->len; i++)
    {
        struct OlPlayer *controller = g_array_index (players, struct OlPlayer*, i);
        ol_debugf ("trying %s\n", controller->name);
        if (controller && controller->get_activated ())
        {
            ol_debugf ("Connected to %s\n", controller->name);
            return controller;
        }
    }
    return NULL;
}
Example #16
0
static gboolean
ol_player_xmms2_connect ()
{
  /* ol_log_func (); */
  if (connection == NULL && connected == FALSE && !ol_player_xmms2_init ())
    return FALSE;
  connected = xmmsc_connect (connection, getenv ("XMMS_PATH"));
  if (connected)
  {
    xmmsc_disconnect_callback_set (connection, disconnect_callback, NULL);
    ol_debugf ("connected");
  }
  return connected;
}
Example #17
0
gboolean
ol_dcop_get_boolean (const gchar *cmd, gboolean *returnval)
{
  ol_log_func ();
  ol_assert_ret (cmd != NULL, FALSE);
  ol_assert_ret (returnval != NULL, FALSE);
  gchar *ret = NULL;
  if (!ol_dcop_get_string (cmd, &ret))
    return FALSE;
  *returnval = (strcmp (ret, "true") == 0);
  ol_debugf ("returns %s\n", ret);
  g_free (ret);
  return TRUE;
}
Example #18
0
const char*
ol_config_get_path ()
{
  static char* path = NULL;
  if (path == NULL)
  {
    path = g_strdup_printf ("%s/%s/%s", g_get_user_config_dir (), PACKAGE_NAME, CONFIG_FILE_NAME);
    ol_debugf ("config path: %s\n", path);
    char *dir = g_strdup_printf ("%s/%s/", g_get_user_config_dir (), PACKAGE_NAME);
    g_mkdir_with_parents (dir, 0755);
    g_free (dir);
  }
  return path;
}
Example #19
0
gboolean
ol_app_download_lyric (OlMusicInfo *music_info)
{
  ol_log_func ();
  OlConfig *config = ol_config_get_instance ();
  char *name = ol_config_get_string (config, "Download", "download-engine");
  ol_debugf ("Download engine: %s\n", name);
  OlLrcFetchEngine *engine = ol_lrc_fetch_get_engine (name);
  ol_lrc_fetch_begin_search (engine, 
                             music_info, 
                             _search_callback,
                             NULL);
  if (module != NULL)
    ol_display_module_search_message (module, _("Searching lyrics"));
}
Example #20
0
static void
_on_music_changed ()
{
  ol_debugf("on music change\n");
  if (module != NULL)
  {
    ol_display_module_set_music_info (module, &music_info);
    ol_display_module_set_duration (module, previous_duration);
  }
  ol_display_module_set_lrc (module, NULL);
  if (!_check_lyric_file ())
    ol_app_download_lyric (&music_info);
  OlConfig *config = ol_config_get_instance ();
  if (ol_config_get_bool (config, "General", "notify-music"))
    ol_notify_music_change (&music_info, ol_player_get_icon_path (player));
}
Example #21
0
DBusGConnection
*ol_dbus_get_connection ()
{
  if (connection == NULL)
  {
    connection = dbus_g_bus_get (DBUS_BUS_SESSION,
                                 &error);
    if (connection == NULL)
    {
      ol_debugf ("get connection failed: %s\n", error->message);
      g_error_free(error);
      error = NULL;
    }
  }
  return connection;
}
Example #22
0
static int
ol_lrc_fetch_add_engine (OlLrcFetchEngine *engine)
{
  ol_debugf ("engine:%s\n", engine->name);
  if (engine_count >= OL_LRC_FETCH_ENGINE_MAX)
    return 0;
  int i;
  for (i = 0; i < engine_count; i++)
  {
    if (engines[i] == engine)
      return 0;
  }
  engine_list[engine_count] = engine->name;
  engines[engine_count++] = engine;
  return engine_count;
}
Example #23
0
OlLrcFetchEngine *
ol_lrc_fetch_get_engine (const char *name)
{
  if (engine_count == 0)
    return NULL;
  if (name == NULL)
    return engines[0];
  int i = 0;
  size_t len = strlen (name);
  for (i = 0; i < engine_count; i++)
  {
    ol_debugf ("[%d]:%s\n", i, engines[i]->name);
    if (ol_stricmp (name, engines[i]->name, len) == 0)
      return engines[i];
  }
  return engines[0];
}
Example #24
0
static void
_inactive_color_changed_cb (OlConfigProxy *config,
                            const char *key,
                            OlOsdModule *osd)
{
  gsize len;
  char **color_str = ol_config_proxy_get_str_list (config, key, &len);
  ol_debugf ("len = %d\n", (int)len);
  if (len != OL_LINEAR_COLOR_COUNT) return;
  if (color_str != NULL)
  {
    OlColor *colors = ol_color_from_str_list ((const char**)color_str, NULL);
    ol_osd_window_set_inactive_colors (osd->window, colors[0], colors[1], colors[2]);
    g_free (colors);
    g_strfreev (color_str);
  }
}
Example #25
0
const gchar*
ol_get_string_from_hash_table (GHashTable *hash_table, const gchar *key)
{
  if (!hash_table)
    return NULL;
  GValue *value;
  value = (GValue *) g_hash_table_lookup(hash_table, key);
  if (value != NULL && G_VALUE_HOLDS_STRING (value))
  {
    return (const gchar*) g_value_get_string (value);
  }
  else
  {
    ol_debugf ("Type of %s is %s, not string\n",
               key, value != NULL ? G_VALUE_TYPE_NAME (value) : "NULL");
    return NULL;
  }
}
Example #26
0
static gboolean
ol_player_amarok1_get_music_info (OlMusicInfo *info)
{
  ol_assert_ret (info != NULL, FALSE);
  ol_music_info_clear (info);
  if (!ol_player_amarok1_get_string (TITLE_CMD, &info->title))
    return FALSE;
  if (!ol_player_amarok1_get_string (ARTIST_CMD, &info->artist))
    return FALSE;
  if (!ol_player_amarok1_get_string (ALBUM_CMD, &info->album))
    return FALSE;
  if (!ol_player_amarok1_get_uint (TRACK_CMD, &info->track_number))
    return FALSE;
  ol_debugf ("  title: %s\n"
             "  artist: %s\n"
             "  album: %s\n",
             ol_music_info_get_title (info),
             ol_music_info_get_artist (info),
             ol_music_info_get_album (info));
  return TRUE;
}
Example #27
0
static gboolean
_check_lyric_file ()
{
  ol_log_func ();
  gboolean ret = TRUE;
  char *filename = NULL;
  int code = ol_lrclib_find (&music_info, &filename);
  if (code == 0)
    filename = ol_lyric_find (&music_info);
 
  if (filename != NULL)
  {
    ret = ol_app_assign_lrcfile (&music_info, filename, code == 0);
    g_free (filename);
  }
  else
  {
    ol_debugf("filename;%s\n", filename);
    if (code == 0) ret = FALSE;
  }
  return ret;
}
Example #28
0
void
ol_menu_assign_lrc (GtkWidget *widget, gpointer data)
{
  static char *prev_path = NULL;
  OlMetadata *info = ol_app_get_current_music ();
  GtkFileFilter *lrc_filter = NULL;
  lrc_filter = gtk_file_filter_new ();
  gtk_file_filter_set_name (lrc_filter, _("LRC files"));
  gtk_file_filter_add_pattern (lrc_filter, "*.lrc");
  if (info != NULL)
  {
    ol_debugf ("prev_path: %s\n", prev_path);
    GtkWidget *dialog = NULL;
    dialog = gtk_file_chooser_dialog_new (_("Choose LRC file to assign"),
                                          NULL,
                                          GTK_FILE_CHOOSER_ACTION_OPEN,
                                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                          GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
                                          NULL);
    gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), lrc_filter);
    
    if (prev_path != NULL)
      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), prev_path);

    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
    {
      char *filename;
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
      ol_app_assign_lrcfile (info, filename, TRUE);
      g_free (filename);
      if (prev_path != NULL)
        g_free (prev_path);
      prev_path = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
    }
    gtk_widget_destroy (dialog);
    dialog = NULL;
  }
}
Example #29
0
static void
ol_osd_module_set_message (struct OlDisplayModule *module,
                           const char *message,
                           int duration_ms)
{
  ol_log_func ();
  ol_assert (module != NULL);
  OlOsdModule *priv = ol_display_module_get_data (module);
  ol_assert (priv != NULL);
  ol_assert (message != NULL);
  ol_assert (priv->window != NULL);
  if (priv->lrc != NULL)
    return;
  ol_debugf ("  message:%s\n", message);
  ol_osd_window_set_current_line (priv->window, 0);
  ol_osd_window_set_current_percentage (priv->window, 1.0);
  ol_osd_window_set_lyric (priv->window, 0, message);
  ol_osd_window_set_lyric (priv->window, 1, NULL);
  if (priv->message_source != 0)
    g_source_remove (priv->message_source);
  priv->message_source = g_timeout_add (duration_ms,
                                        (GSourceFunc) hide_message,
                                        (gpointer) priv);
}
Example #30
0
gboolean
ol_dbus_connect (const gchar *service,
                 const gchar *path,
                 const gchar *interface,
                 GCallback disconnect_handler,
                 gpointer disconnect_data,
                 DBusGProxy **proxy)
{
  ol_log_func ();
  GError *error = NULL;
  ol_assert_ret (proxy != NULL, FALSE);
  ol_assert_ret (service != NULL, FALSE);
  ol_assert_ret (path != NULL, FALSE);
  ol_assert_ret (interface != NULL, FALSE);
  DBusGConnection *connection = ol_dbus_get_connection ();
  if (connection == NULL)
    return FALSE;
  *proxy = dbus_g_proxy_new_for_name_owner (connection, service, path, interface, &error);
  if (*proxy == NULL)
  {
    ol_debugf ("get proxy failed: %s\n", error->message);
    g_error_free (error);
    error = NULL;
    return FALSE;
  }
  if (disconnect_handler != NULL)
  {
    if (disconnect_data == NULL)
      disconnect_data = (gpointer) proxy;
    g_signal_connect (*proxy,
                      "destroy",
                      G_CALLBACK (disconnect_handler),
                      disconnect_data);
  }
  return TRUE;
}