Пример #1
0
void
ol_lrc_engine_list_set_name (GtkWidget *list, 
                             const char *name)
{
  ol_assert (list != NULL);
  ol_assert (GTK_IS_COMBO_BOX (list));
  GtkTreeModel *tree = gtk_combo_box_get_model (GTK_COMBO_BOX (list));
  GtkTreeIter iter;
  gboolean valid = gtk_tree_model_get_iter_first (tree, &iter);
  while (valid)
  {
    char *engine_name = NULL;
    gtk_tree_model_get (tree, &iter,
                        0, &engine_name,
                        -1);
    if (ol_stricmp (engine_name,
                    _(name),
                    strlen (engine_name)) == 0)
    {
      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (list),
                                     &iter);
      g_free (engine_name);
      return;
    }
    g_free (engine_name);
    valid = gtk_tree_model_iter_next (tree, &iter);
  }
}
Пример #2
0
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);
}
Пример #3
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"));
  }
}
Пример #4
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);
  }
}
Пример #5
0
void
ol_log_set_level (enum OlDebugLevel level)
{
  ol_assert (level >= -1);
  ol_assert (level < OL_N_LEVELS);
  debug_level = level;
}
Пример #6
0
void
ol_osd_render_set_outline_width (OlOsdRenderContext *context,
                                 const int width)
{
  ol_assert (context != NULL);
  ol_assert (width >= 0);
  context->outline_width = width;
}
Пример #7
0
void
ol_player_register (struct OlPlayer *controller)
{
    ol_assert (controller != NULL);
    ol_assert (ol_player_get_name (controller) != NULL);
    /* controller->get_activated (); */
    g_array_append_val (players, controller);
}
Пример #8
0
void
ol_osd_render_set_linear_color (OlOsdRenderContext *context,
                                int index,
                                OlColor color)
{
  ol_assert (context != NULL);
  ol_assert (index >= 0 && index < OL_LINEAR_COLOR_COUNT);
  context->linear_colors[index] = color;
}
Пример #9
0
static void
_update_caps (OlScrollModule *module)
{
  ol_assert (module != NULL);
  ol_assert (module->player != NULL);
  ol_assert (module->scroll != NULL);
  ol_scroll_window_set_can_seek (module->scroll,
                                 ol_player_get_caps (module->player) & OL_PLAYER_SEEK);
}
Пример #10
0
void
ol_player_chooser_set_image_by_name (OlPlayerChooser *window,
                                     const char *icon_name)
{
  ol_assert (OL_IS_PLAYER_CHOOSER (window));
  ol_assert (icon_name != NULL);
  OlPlayerChooserPrivate *priv = OL_PLAYER_CHOOSER_GET_PRIVATE (window);
  gtk_image_set_from_icon_name (priv->info_icon, icon_name, GTK_ICON_SIZE_DIALOG);
}
Пример #11
0
void
ol_player_chooser_set_image_by_gicon (OlPlayerChooser *window,
                                      GIcon *icon)
{
  ol_assert (OL_IS_PLAYER_CHOOSER (window));
  ol_assert (G_IS_ICON (icon));
  OlPlayerChooserPrivate *priv = OL_PLAYER_CHOOSER_GET_PRIVATE (window);
  gtk_image_set_from_gicon (priv->info_icon, icon, GTK_ICON_SIZE_DIALOG);
}
Пример #12
0
void
ol_osd_render_paint_text (OlOsdRenderContext *context,
                          cairo_t *cr,
                          const char *text,
                          double xpos,
                          double ypos)
{
  ol_assert (context != NULL);
  ol_assert (cr != NULL);
  ol_assert (text != NULL);
  ol_osd_render_set_text (context, text);
  int width, height;
  xpos += context->outline_width / 2.0 + context->blur_radius;
  ypos += context->outline_width / 2.0 + context->blur_radius;
  pango_layout_get_pixel_size (context->pango_layout, &width, &height);
  /* draws the outline of the text */
  cairo_move_to (cr, xpos, ypos);
  cairo_save (cr);
  pango_cairo_layout_path(cr, context->pango_layout);
  cairo_set_source_rgb (cr, ol_color_black.r, ol_color_black.g, ol_color_black.b);
  if (context->outline_width > 0)
  {
    cairo_set_line_width (cr, context->outline_width);
    if (context->blur_radius > 1e-4)
    {
      cairo_stroke_preserve (cr);
      cairo_fill (cr);
      ol_gussian_blur (cairo_get_target (cr), context->blur_radius);
    }
    else
    {
      cairo_stroke (cr);
    }
  }
  cairo_restore (cr);
  cairo_save (cr);
  cairo_new_path (cr);
  /* creates the linear pattern */
  cairo_pattern_t *pattern = cairo_pattern_create_linear (xpos, ypos, xpos, ypos + height);
  int i;
  for (i = 0; i < OL_LINEAR_COLOR_COUNT; i++)
  {
    cairo_pattern_add_color_stop_rgb(pattern,
                                     context->linear_pos[i],
                                     context->linear_colors[i].r,
                                     context->linear_colors[i].g,
                                     context->linear_colors[i].b);
  }
  cairo_set_source (cr, pattern);
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
  /* draws the text */
  cairo_move_to (cr, xpos, ypos);
  pango_cairo_show_layout (cr, context->pango_layout);
  cairo_pattern_destroy (pattern);
  cairo_restore (cr);
}
Пример #13
0
static void
ol_scroll_module_set_message (struct OlDisplayModule *module,
                              const char *message)
{
  ol_assert (module != NULL);
  OlScrollModule *priv = ol_display_module_get_data (module);
  ol_assert (priv != NULL);
  if (priv->scroll != NULL && message != NULL)
  {
    ol_scroll_window_set_text (priv->scroll, message);
  }
}
Пример #14
0
static void
ol_scroll_module_clear_message (struct OlDisplayModule *module)
{
  ol_assert (module != NULL);
  OlScrollModule *priv = ol_display_module_get_data (module);
  ol_assert (priv != NULL);
  _set_metadata_as_text (priv);
  if (priv->message_timer > 0)
  {
    g_source_remove (priv->message_timer);
    priv->message_timer = 0;
  }
}
Пример #15
0
void
ol_osd_render_set_font_name (OlOsdRenderContext *context,
                             const char *font_name)
{
  ol_assert (context != NULL);
  ol_assert (font_name != NULL);
  char *new_name = g_strdup (font_name);
  if (context->font_name != NULL)
  {
    g_free (context->font_name);
  }
  context->font_name = new_name;
  ol_osd_render_update_font (context);
}
Пример #16
0
static void
ol_scroll_module_set_last_message (struct OlDisplayModule *module,
                                   const char *message)
{
  ol_assert (module != NULL);
  OlScrollModule *priv = ol_display_module_get_data (module);
  ol_assert (priv != NULL);
  ol_scroll_module_set_message (module, message);
  if (priv->message_timer != 0)
    g_source_remove (priv->message_timer);
  priv->message_timer = g_timeout_add (MESSAGE_TIMEOUT_MS,
                                       (GSourceFunc) ol_scroll_module_clear_message,
                                       module);
}
Пример #17
0
static void
ol_osd_module_clear_message (struct OlDisplayModule *module)
{
  ol_log_func ();
  ol_assert (module != NULL);
  OlOsdModule *priv = ol_display_module_get_data (module);
  ol_assert (priv != NULL);
  if (priv->message_source != 0)
  {
    g_source_remove (priv->message_source);
    hide_message (priv);
  }
  ol_debug ("  clear message done");
}
Пример #18
0
static void
ol_osd_module_set_played_time (struct OlDisplayModule *module,
                               guint64 played_time)
{
  ol_assert (module != NULL);
  OlOsdModule *priv = ol_display_module_get_data (module);
  ol_assert (priv != NULL);
  if (priv->lrc != NULL && priv->window != NULL)
  {
    OlLrcIter *iter = ol_lrc_iter_from_timestamp (priv->lrc,
                                                  played_time);
    if (_advance_to_nonempty_lyric (iter))
    {
      gint id = ol_lrc_iter_get_id (iter);
      if (id != priv->lrc_id)
      {
        if (id == priv->lrc_next_id)
        {
          /* advance to the next line */
          ol_osd_window_set_percentage (priv->window, priv->current_line, 1.0);
          priv->current_line = 1 - priv->current_line;
          priv->lrc_id = priv->lrc_next_id;
          priv->lrc_next_id = -1;
          ol_osd_window_set_current_line (priv->window, priv->current_line);
        }
        else
        {
          /* The user seeks the position or there is only 1 line in OSD window.
             Reset the lyrics. */
          priv->lrc_id = id;
          priv->current_line = 0;
          ol_osd_window_set_current_line (priv->window, 0);
          ol_osd_window_set_lyric (priv->window, priv->current_line,
                                   ol_lrc_iter_get_text (iter));
          ol_osd_module_update_next_lyric (priv, iter);
        }
      }
      gdouble percentage = ol_lrc_iter_compute_percentage (iter, played_time);
      ol_osd_window_set_current_percentage (priv->window, percentage);
      if (percentage > 0.5 && priv->lrc_next_id == -1)
        ol_osd_module_update_next_lyric (priv, iter);
    }
    else if (priv->lrc_id != -1)
    {
      clear_lyrics (priv);
    }
    ol_lrc_iter_free (iter);
  }
}
Пример #19
0
void
ol_osd_render_set_text (OlOsdRenderContext* context,
                        const char *text)
{
  ol_assert (context != NULL);
  ol_assert (text != NULL);
  if (context->text != NULL)
  {
    if (strcmp (context->text, text) == 0)
      return;
    g_free (context->text);
  }
  context->text = g_strdup (text);
  pango_layout_set_text (context->pango_layout, text, -1);
}
Пример #20
0
void
ol_display_module_free (struct OlDisplayModule *module)
{
  ol_assert (module != NULL);
  module->klass->free (module);
  g_free (module);
}
Пример #21
0
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);
}
Пример #22
0
void
ol_player_chooser_set_info (OlPlayerChooser *window,
                            const char *info,
                            const char *description)
{
  ol_assert (OL_IS_PLAYER_CHOOSER (window));
  ol_assert (info != NULL);
  OlPlayerChooserPrivate *priv = OL_PLAYER_CHOOSER_GET_PRIVATE (window);
  gchar *text;
  if (description != NULL)
    text = g_strdup_printf ("%s\n\n%s", info, description);
  else
    text = g_strdup (info);
  gtk_label_set_text (priv->info_label, text);
  g_free (text);
}
Пример #23
0
static void
_show_page (OlPlayerChooser *window,
            OlPlayerChooserPage *page)
{
  ol_assert (page != NULL);
  gtk_toggle_button_set_active (page->page_button, TRUE);
}
Пример #24
0
void
ol_display_module_download_fail_message (struct OlDisplayModule *module,
                                         const char *message)
{
  ol_assert (module != NULL);
  call (module->klass->download_fail_message, module, message);
}
Пример #25
0
void
ol_display_module_search_message (struct OlDisplayModule *module,
                                  const char *message)
{
  ol_assert (module != NULL);
  call (module->klass->search_message, module, message);
}
Пример #26
0
void
ol_display_module_set_lrc (struct OlDisplayModule *module,
                           struct OlLrc *lrc_file)
{
  ol_assert (module != NULL);
  call (module->klass->set_lrc, module, lrc_file);
}
Пример #27
0
void
ol_display_module_set_played_time (struct OlDisplayModule *module,
                                   int played_time)
{
  ol_assert (module != NULL);
  call (module->klass->set_played_time, module, played_time);
}
Пример #28
0
void
ol_display_module_set_status (struct OlDisplayModule *module,
                              enum OlPlayerStatus status)
{
  ol_assert (module != NULL);
  call (module->klass->set_status, module, status);
}
Пример #29
0
void
ol_display_module_set_player (struct OlDisplayModule *module,
                              struct OlPlayer *player)
{
  ol_assert (module != NULL);
  call (module->klass->set_player, module, player);
}
Пример #30
0
void
ol_osd_toolbar_set_player (OlOsdToolbar *toolbar,
                           OlPlayer *player)
{
  ol_assert (OL_IS_OSD_TOOLBAR (toolbar));
  OlOsdToolbarPriv *priv = OL_OSD_TOOLBAR_GET_PRIVATE (toolbar);
  if (player == priv->player)
    return;
  if (player != NULL)
  {
    g_object_ref (player);
    g_signal_connect (player,
                      "status-changed",
                      G_CALLBACK (_status_changed_cb),
                      toolbar);
    g_signal_connect (player,
                      "caps-changed",
                      G_CALLBACK (_caps_changed_cb),
                      toolbar);
  }
  if (priv->player != NULL)
  {
    g_signal_handlers_disconnect_by_func (priv->player,
                                          _status_changed_cb,
                                          toolbar);
    g_signal_handlers_disconnect_by_func (priv->player,
                                          _caps_changed_cb,
                                          toolbar);
    g_object_unref (priv->player);
  }
  priv->player = player;
  _update_caps (toolbar);
  _update_status (toolbar);
}