static void
_paint_text (OlScrollWindow *scroll, cairo_t *cr)
{
  ol_log_func ();
  ol_assert (OL_IS_SCROLL_WINDOW (scroll));
  ol_assert (cr != NULL);
  GtkWidget *widget = GTK_WIDGET (scroll);
  OlScrollWindowPrivate *priv = OL_SCROLL_WINDOW_GET_PRIVATE (scroll);
  gint width, height;
  PangoRectangle extent;
  PangoLayout *layout;
  gint x, y;
  gdk_drawable_get_size (gtk_widget_get_window (widget),
                         &width, &height);
  
  /* set the font */
  cairo_save (cr);
  cairo_set_source_rgb (cr,
                        priv->inactive_color.r,
                        priv->inactive_color.g,
                        priv->inactive_color.b);
  layout = _get_pango (scroll, cr);
  pango_layout_set_text (layout, priv->text, -1);
  pango_layout_get_pixel_extents (layout, NULL, &extent);
  pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
  x = (width - extent.width) / 2;
  y = (height - extent.height) / 2;
  if (x < 0) x = 0;
  if (y < 0) y = 0;
  cairo_move_to (cr, x, y);
  pango_cairo_update_layout (cr, layout);
  pango_cairo_show_layout (cr, layout);
}
void
ol_lrc_fetch_ui_show (OlLrcFetchEngine *lrcengine,
                      const OlLrcCandidate *candidates,
                      int count,
                      const OlMusicInfo *music_info,
                      const char *filename)
{
  ol_log_func ();
  if (window == NULL && !internal_init ())
    return;
  if (lrcengine == NULL || candidates == NULL || count <= 0 || filename == NULL)
  {
    gtk_widget_hide (window);
    return;
  }
  if (filepath != NULL)
    g_free (filepath);
  filepath = g_strdup (filename);
  engine = lrcengine;
  ol_lrc_candidate_list_set_list (list, candidates, count);
  if (info == NULL)
    info = ol_music_info_new ();
  ol_music_info_copy (info, music_info);
    
  gboolean prompt = TRUE;
  OlConfig *config = ol_config_get_instance ();
  if (config != NULL)
    prompt = ol_config_get_bool (config, "Download", "download-first-lyric");
  if (prompt || count == 1)
    ol_lrc_fetch_ui_download (GTK_WIDGET (download_button), NULL);
  else
    gtk_widget_show (window);
}
void 
ol_scroll_window_set_whole_lyrics (OlScrollWindow *scroll,
                                   GPtrArray *whole_lyrics)
{
  ol_log_func ();
  ol_assert (OL_IS_SCROLL_WINDOW (scroll));
  OlScrollWindowPrivate *priv = OL_SCROLL_WINDOW_GET_PRIVATE (scroll);
  if (scroll->whole_lyrics != NULL)
    g_ptr_array_unref (scroll->whole_lyrics);
  scroll->whole_lyrics = whole_lyrics;
  if (whole_lyrics != NULL)
  {
    g_ptr_array_ref (whole_lyrics);
    priv->saved_lrc_y = -1;
  }
  else
  {
    /* We only queue draw when the lyrics are no available.
       Otherwise the progress will go wrong due to out-dated
       progress info*/
    gtk_widget_queue_draw (GTK_WIDGET (scroll));
  }
  ol_scroll_window_update_tooltip (scroll);
  if (priv->seeking)
    ol_scroll_window_end_seek (scroll);
}
Example #4
0
gboolean
ol_app_assign_lrcfile (const OlMusicInfo *info,
                       const char *filepath,
                       gboolean update)
{
  ol_log_func ();
  ol_assert_ret (info != NULL, FALSE);
  ol_assert_ret (filepath == NULL || ol_path_is_file (filepath), FALSE);
  if (update)
  {
    ol_lrclib_assign_lyric (info, filepath);
  }
  if (ol_music_info_equal (&music_info, info))
  {
    if (lrc_file != NULL)
    {
      ol_lrc_free (lrc_file);
      lrc_file = NULL;
    }
    if (filepath != NULL)
      lrc_file = ol_lrc_new (filepath);
    ol_display_module_set_lrc (module, lrc_file);
  }
  return TRUE;
}
Example #5
0
int 
ol_lrc_fetch_xiami_download(OlLrcCandidate *candidate,
                            const char *pathname,
                            const char *charset)
{
  ol_log_func ();
  ol_assert_ret (candidate != NULL, -1);
  ol_assert_ret (pathname != NULL, -1);
  FILE *fp;
  int ret = 0;

  if ((fp = fopen(pathname, "w")) == NULL)
  {
    ret = -1;
  }
  else
  {
    fetch_into_file (ol_lrc_candidate_get_url (candidate),
                     NULL,
                     fp);
    fclose(fp);
    ret = 0;
  }
  return ret;
}
int
ol_lrc_fetch_add_candidate (const OlMusicInfo *info,
                            OlLrcCandidate *candidate_list,
                            size_t count,
                            size_t size,
                            struct _OlLrcCandidate *new_candidate)
{
  ol_log_func ();
  if (info == NULL || candidate_list == NULL || new_candidate == NULL ||
      count < 0 || size <= 0)
    return 0;
  new_candidate->rank = ol_lrc_fetch_calc_rank (info, new_candidate);
  if (new_candidate->rank < RANK_ACCEPT_FACTOR * RANK_SCALE)
    return count;
  int pos = count;
  while (pos > 0 && new_candidate->rank > candidate_list[pos - 1].rank)
  {
    if (pos < size)
    {
      candidate_list[pos] = candidate_list[pos - 1];
    }
    pos--;
  }
  if (pos < size)
  {
    candidate_list[pos] = *new_candidate;
  }
  if (count < size)
    count++;
  return count;
}
int
curl_url_decoding(CURL *curl, char *input, char *output, size_t size)
{
  ol_log_func ();
  char *unescp;
  int flag = 0;
  if(curl == NULL) {
    curl = curl_easy_init();
    flag = 1;
  }

  unescp = curl_easy_unescape(curl, input, 0, NULL);
  if(unescp == NULL) {
    ol_errorf ("curl_easy_unescape error.\n");
    return -1;
  }
  if(strlen(unescp) > size) {
    errno = E2BIG; /* identify that buffer storing the result is too small */
    return -1;
  }
  strcpy(output, unescp); 

  /* 
   * convert to target charset, this is be done after this function called
   convert("GBK", charset==NULL ? "UTF-8" : charset, unescp, strlen(unescp), output, size);
  */

  curl_free(unescp);
  if(flag == 1)
    curl_easy_cleanup(curl);
  return 0;
}
int
url_decoding(const char *src, const int srclen, char *dest, int destlen)
{
  ol_log_func ();
  char ch;
  int idx1, idx2;
  int i;
  int j = 0; 

  if(src == NULL || dest == NULL || srclen < 0 || destlen < 0)
    return -1;

  for(i=0; (i<srclen && j<destlen); i++) {
    ch = src[i];
    switch(ch) {
    case '+' :
      dest[j++] = ' ';
      break;
    case '%':
      idx1 = chartonum(src[i+1]);
      idx2 = chartonum(src[i+2]);
      dest[j++] = (char)((idx1<<4) | idx2);
      i += 2;
      break;
    default:
      dest[j++] = ch;
    }
  }
  dest[j] = '\0';
  /*
   * convert to target charset, this is be done after this function called
   convert("GBK", charset==NULL ? "UTF-8" : charset, buf, strlen(buf), dest, destlen);
  */
  return 0;
}
Example #9
0
void
ol_scroll_module_set_lrc (struct OlDisplayModule *module,
                          OlLrc *lrc)
{
  ol_log_func ();
  ol_assert (module != NULL);
  ol_assert (module != NULL);
  OlScrollModule *priv = ol_display_module_get_data (module);
  ol_assert (priv != NULL);
  if (priv->lrc != NULL)
    g_object_unref (priv->lrc);
  priv->lrc = lrc;
  if (priv->lrc == NULL)
    ol_scroll_window_set_whole_lyrics(priv->scroll, NULL);
  else
  {
    g_object_ref (priv->lrc);
    /*dump the whole lyrics of a song*/
    GPtrArray *text_array = g_ptr_array_new_with_free_func (g_free);
    OlLrcIter *iter = ol_lrc_iter_from_id (lrc, 0);
    const char *text = NULL;
    while (ol_lrc_iter_loop (iter, NULL, NULL, &text))
    {
      g_ptr_array_add (text_array, g_strdup (text));
    }
    ol_scroll_window_set_whole_lyrics(priv->scroll, text_array);
    g_ptr_array_unref (text_array);
    ol_lrc_iter_free (iter);
  }
}
Example #10
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 #11
0
static gint
_refresh_music_info (gpointer data)
{
  ol_log_func ();
  //printf ("_refresh_music_info:successful\n");
  /* ol_log_func (); */
  if (player == NULL && !_get_active_player ())
    return TRUE;
  guint time = 0;
  if (player && !ol_player_get_played_time (player, &time))
  {
    player = NULL;
  }
  if (previous_position < 0 || time < previous_position ||
      previous_title == NULL)
    _check_music_change ();
  previous_position = time;
  if (player == NULL)
  {
    previous_position = -1;
    return TRUE;
  }
  ol_display_module_set_played_time (module, time);
  return TRUE;
}
Example #12
0
static void
_parse_cmd_args (int *argc, char ***argv)
{
  ol_log_func ();
  GError *error = NULL;
  GOptionContext *context;

  context = g_option_context_new ("- Display your lyrics");
  g_option_context_add_main_entries (context, cmdargs, PACKAGE);
  g_option_context_add_group (context, gtk_get_option_group (TRUE));
  if (!g_option_context_parse (context, argc, argv, &error))
  {
    ol_errorf ("option parsing failed: %s\n", error->message);
  }
  if (debug_level != NULL)
  {
    if (strcmp (debug_level, "none") == 0)
      ol_log_set_level (OL_LOG_NONE);
    else if (strcmp (debug_level, "error") == 0)
      ol_log_set_level (OL_ERROR);
    else if (strcmp (debug_level, "debug") == 0)
      ol_log_set_level (OL_DEBUG);
    else if (strcmp (debug_level, "info") == 0)
      ol_log_set_level (OL_INFO);
    g_free (debug_level);
  }
}
Example #13
0
static void
_update_status (OlOsdToolbar *toolbar)
{
  ol_log_func ();
  OlOsdToolbarPriv *priv = OL_OSD_TOOLBAR_GET_PRIVATE (toolbar);
  enum OlPlayerStatus status;
  if (priv->player)
    status = ol_player_get_status (priv->player);
  else
    status = OL_PLAYER_UNKNOWN;
  switch (status)
  {
  case OL_PLAYER_PLAYING:
    gtk_widget_show (GTK_WIDGET (toolbar->pause_button));
    gtk_widget_hide (GTK_WIDGET (toolbar->play_button));
    break;
  case OL_PLAYER_PAUSED:
  case OL_PLAYER_STOPPED:
    gtk_widget_hide (GTK_WIDGET (toolbar->pause_button));
    gtk_widget_show (GTK_WIDGET (toolbar->play_button));
    break;
  default:
    gtk_widget_show (GTK_WIDGET (toolbar->pause_button));
    gtk_widget_show (GTK_WIDGET (toolbar->play_button));
    break;
  }
  gtk_widget_queue_draw (GTK_WIDGET (toolbar));
}
Example #14
0
static gboolean
ol_player_exaile02_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 #15
0
static gboolean
internal_init ()
{
  ol_log_func ();
  if (window == NULL)
  {
    window = ol_gui_get_widget ("downloaddialog");
    if (window == NULL)
      return FALSE;
    g_signal_connect (G_OBJECT (window),
                      "delete-event",
                      G_CALLBACK (gtk_widget_hide_on_delete),
                      NULL);
  }
  if (download_button == NULL)
  {
    download_button = GTK_BUTTON (ol_gui_get_widget ("lrc-download"));
  }
  if (list == NULL)
  {
    list = GTK_TREE_VIEW (ol_gui_get_widget ("candidate-list"));
    ol_lrc_candidate_list_init (list, 
                                G_CALLBACK (ol_lrc_fetch_select_changed));
  }
  return TRUE;
}
Example #16
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;
}
int
fetch_into_memory (const char *url,
                   const char *refer,
                   const char *user_agent,
                   const char *post_data,
                   size_t post_len,
                   struct memo *dest)
{
  ol_log_func ();
  CURL *curl;
  CURLcode code;
  WriteCallback callback = WriteMemoryCallback;

  curl = my_curl_init(NULL, url, refer, user_agent, post_data, post_len,
                      callback, dest, cntimeout);
  if(curl == NULL)
    return -1;

  code = curl_easy_perform(curl);
  if(code != CURLE_OK) {
    ol_errorf ("failed to perform: [%s]\n", errbuf);
    return -1;
  }
  curl_easy_cleanup(curl);
  return 0;
}
Example #18
0
static void
_search_callback (struct OlLrcFetchResult *result,
                  void *userdata)
{
  ol_log_func ();
  ol_assert (result != NULL);
  ol_assert (result->engine != NULL);
  if (result->count > 0 && result->candidates != 0)
  {
    char *filename = ol_lyric_download_path (&result->info);
    if (filename == NULL)
    {
      ol_display_module_download_fail_message (module, _("Cannot create the lyric directory"));
    }
    else
    {
      if (module != NULL) {
        ol_display_module_clear_message (module);
	ol_display_module_clear_message (module);
      }
      ol_lrc_fetch_ui_show (result->engine, result->candidates, result->count,
                            &result->info,
                            filename);
      g_free (filename);
    }
  }
  else
  {
    if (module != NULL)
      ol_display_module_search_fail_message (module, _("Lyrics not found"));
  }
}
Example #19
0
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 #20
0
int
ol_lrclib_init (const char *filename)
{
    ol_log_func ();
    if (db != NULL)
    {
        ol_error ("Lrclib has been initialized.");
        return 1;
    }
    int code = 0;
    code = sqlite3_open (filename, &db);
    if (code != SQLITE_OK)
    {
        _show_error ();
    }
    else
    {
        code = sqlite3_exec (db, CREATE_TABLE, NULL,
                             NULL, &errmsg);
        if (code != SQLITE_OK)
        {
            ol_error (errmsg);
            sqlite3_free (errmsg);
        }
    }
    return db != NULL;
}
Example #21
0
gboolean
ol_lrc_fetch_ui_cancel (GtkWidget *widget, gpointer data)
{
  ol_log_func ();
  if (window != NULL)
    gtk_widget_hide (window);
  return TRUE;
}
Example #22
0
void
ol_display_module_set_duration (struct OlDisplayModule *module,
                                int duration)
{
  ol_log_func ();
  ol_assert (module != NULL);
  call (module->klass->set_duration, module, duration);
}
Example #23
0
void
ol_display_module_set_music_info (struct OlDisplayModule *module,
                                  OlMusicInfo *music_info)
{
  ol_log_func ();
  ol_assert (module != NULL);
  call (module->klass->set_music_info, module, music_info);
}
Example #24
0
static void
_metadata_changed_cb (OlPlayer *player,
                      OlOsdModule *module)
{
  ol_log_func ();
  _update_metadata (module);
  
}
GtkWidget*
ol_player_chooser_new (GList *supported_players)
{
  ol_log_func ();
  GtkWidget *window = g_object_new (ol_player_chooser_get_type (), NULL);
  _set_supported_players (OL_PLAYER_CHOOSER (window), supported_players);
  return window;
}
Example #26
0
static gboolean
_destroy_dbus (DBusGProxy *_proxy, gboolean shell)
{
  ol_log_func ();
  g_object_unref (_proxy);
  proxy = NULL;
  return FALSE;
}
Example #27
0
static void
ol_lrc_fetch_select_changed (GtkTreeSelection *selection, gpointer data)
{
  ol_log_func ();
  if (download_button != NULL)
    gtk_widget_set_sensitive (GTK_WIDGET (download_button),
                              gtk_tree_selection_get_selected (selection, NULL, NULL));
}
Example #28
0
static OlLyricSourceCandidate *
ol_lyric_source_candidate_new_with_variant (GVariant *dict)
{
  ol_log_func ();
  OlLyricSourceCandidate *candidate = NULL;
  GVariantIter *dictiter = NULL;
  gchar *key = NULL;
  gchar *title, *artist, *album, *comment, *sourceid;
  GVariant *downloadinfo = NULL;
  GVariant *value = NULL;
  title = artist = album = comment = sourceid = NULL;
  g_variant_get (dict, "a{sv}", &dictiter);
  while (g_variant_iter_loop (dictiter, "{sv}", &key, &value))
  {
    if (strcmp (key, "title") == 0 && title == NULL)
    {
      title = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "artist") == 0 && artist == NULL)
    {
      artist = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "album") == 0 && album == NULL)
    {
      album = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "comment") == 0 && comment == NULL)
    {
      comment = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "sourceid") == 0 && sourceid == NULL)
    {
      sourceid = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "downloadinfo") == 0 && downloadinfo == NULL)
    {
      downloadinfo = g_variant_ref (value);
    }
    else
    {
      ol_errorf ("Unknown candidate key: %s\n", key);
    }
  }
  g_variant_iter_free (dictiter);
  candidate = ol_lyric_source_candidate_new (title,
                                             artist,
                                             album,
                                             comment,
                                             sourceid,
                                             downloadinfo);
  g_free (title);
  g_free (artist);
  g_free (album);
  g_free (comment);
  g_free (sourceid);
  g_variant_unref (downloadinfo);
  return candidate;
}
Example #29
0
void
ol_menu_play (GtkWidget *widget, gpointer data)
{
  OlPlayer *player = ol_app_get_player ();
  if (player == NULL)
    return;
  ol_log_func ();
  ol_player_play (player);
}
Example #30
0
static void
_download_callback (struct OlLrcDownloadResult *result)
{
  ol_log_func ();
  if (result->filepath != NULL)
    ol_app_assign_lrcfile (result->info, result->filepath, TRUE);
  else
    ol_display_module_download_fail_message (module, _("Download failed"));
}