Exemplo n.º 1
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;
}
Exemplo n.º 2
0
gboolean
ol_dbus_set_int (DBusGProxy *proxy,
                 const gchar *method,
                 gint value)
{
  ol_assert_ret (proxy != NULL, FALSE);
  ol_assert_ret (method != NULL, FALSE);
  GError *error = NULL;
  if (dbus_g_proxy_call (proxy,
                         method,
                         &error,
                         G_TYPE_INT,
                         value,
                         G_TYPE_INVALID,
                         G_TYPE_INVALID))
  {
    return TRUE;
  }
  else
  {
    ol_errorf ("call %s failed: %s\n", method, error->message);
    g_error_free (error);
    return FALSE;
  }
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
char * 
ol_lrc_candidate_deserialize (OlLrcCandidate *candidate,
                              char *data)
{
  ol_assert_ret (candidate != NULL, 0);
  ol_assert_ret (data != NULL, 0);
  char *title, *artist, *url, *rank, *ret;
  title = artist = url = rank = ret = NULL;
  title = data;
  artist = ol_split_a_line (title);
  if (artist != NULL)
    url = ol_split_a_line (artist);
  if (url != NULL)
    rank = ol_split_a_line (url);
  if (rank != NULL)
    ret = ol_split_a_line (rank);
  if (ret != NULL)
  {
    ol_lrc_candidate_set_title (candidate, title);
    ol_lrc_candidate_set_artist (candidate, artist);
    ol_lrc_candidate_set_url (candidate, url);
    int rank_int = 0;
    sscanf (rank, "%d", &rank_int);
    ol_lrc_candidate_set_rank (candidate, rank_int);
  }
  return ret;
}
Exemplo n.º 6
0
gboolean
ol_config_set_string (OlConfig *config, const char *group, const char *name, const char* value)
{
  ol_assert_ret (config != NULL, FALSE);
  ol_assert_ret (name != NULL, FALSE);
  g_key_file_set_string (OL_CONFIG_GET_PRIVATE (config)->config, group, name, value);
  ol_config_emit_change (config, group, name);
  ol_config_save (config);
}
Exemplo n.º 7
0
static gboolean
ol_player_amarok1_get_boolean (const char *cmd, gboolean *returnval)
{
  ol_assert_ret (cmd != NULL, FALSE);
  ol_assert_ret (returnval != NULL, FALSE);
  char *dcop_cmd = ol_player_amarok1_get_command (cmd);
  gboolean ret = ol_dcop_get_boolean (dcop_cmd, returnval);
  g_free (dcop_cmd);
  return ret;
}
Exemplo n.º 8
0
gboolean
ol_config_proxy_set_double_default (OlConfigProxy *config,
                                    const gchar *key,
                                    gdouble value)
{
  ol_assert_ret (OL_IS_CONFIG_PROXY (config), FALSE);
  ol_assert_ret (key != NULL, FALSE);
  return ol_config_proxy_set_default (config,
                                      key,
                                      g_variant_new ("d", value));
}
Exemplo n.º 9
0
gboolean
ol_dbus_invoke (DBusGProxy *proxy, const gchar *method)
{
  ol_assert_ret (proxy != NULL, FALSE);
  ol_assert_ret (method != NULL, FALSE);
  return dbus_g_proxy_call (proxy,
                            method,
                            NULL,
                            G_TYPE_INVALID,
                            G_TYPE_INVALID);
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
static PangoLayout*
_get_pango (OlScrollWindow *scroll, cairo_t *cr)
{
  ol_assert_ret (OL_IS_SCROLL_WINDOW (scroll), NULL);
  ol_assert_ret (cr != NULL, NULL);
  OlScrollWindowPrivate *priv = OL_SCROLL_WINDOW_GET_PRIVATE (scroll);
  PangoLayout *layout = pango_cairo_create_layout (cr);
  PangoFontDescription *desc = pango_font_description_from_string (priv->font_name);
  pango_layout_set_font_description (layout, desc);
  pango_font_description_free (desc);
  return layout;
}
Exemplo n.º 12
0
GtkWidget* 
ol_gui_get_widget (const char *name)
{
  ol_assert_ret (name != NULL, NULL);
  internal_init ();
  ol_assert_ret (builder != NULL, NULL);
  GObject *obj = gtk_builder_get_object (builder, name);
  if (obj != NULL && GTK_IS_WIDGET (obj))
    return GTK_WIDGET (obj);
  else
    return NULL;
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
0
gboolean
ol_config_proxy_set_int (OlConfigProxy *config,
                         const gchar *key,
                         gint value)
{
  ol_assert_ret (OL_IS_CONFIG_PROXY (config), FALSE);
  ol_assert_ret (key != NULL, FALSE);
  return ol_config_proxy_set (config,
                              "SetInt",
                              key,
                              g_variant_new ("i", value));
}
Exemplo n.º 16
0
gboolean
ol_dcop_get_uint (const gchar *cmd, guint *returnval)
{
  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 = atoi (ret);
  g_free (ret);
  return TRUE;
}
Exemplo n.º 17
0
gboolean
ol_config_proxy_set_str_list_default (OlConfigProxy *config,
                                      const gchar *key,
                                      const gchar * const *value,
                                      gint len)
{
  ol_assert_ret (OL_IS_CONFIG_PROXY (config), FALSE);
  ol_assert_ret (key != NULL, FALSE);
  ol_assert_ret (value != NULL, FALSE);
  return ol_config_proxy_set_default (config,
                                      key,
                                      _str_list_to_variant (value, len));
}
Exemplo n.º 18
0
static cairo_t*
_get_cairo (OlScrollWindow *scroll, GtkWidget *widget)
{
  ol_assert_ret (OL_IS_SCROLL_WINDOW (scroll), NULL);
  ol_assert_ret (GTK_IS_WIDGET (widget), NULL);
  cairo_t *cr;
  cr = gdk_cairo_create (gtk_widget_get_window (widget));
  cairo_save (cr);
  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint(cr);
  cairo_restore (cr);
  return cr;
}
Exemplo n.º 19
0
/* OlLyricSourceInfo */
static OlLyricSourceInfo *
ol_lyric_source_info_new (const gchar *id,
                          const gchar *name,
                          gboolean enabled)
{
  ol_assert_ret (id != NULL, NULL);
  ol_assert_ret (name != NULL, NULL);
  OlLyricSourceInfo *info = g_new (OlLyricSourceInfo, 1);
  info->id = g_strdup (id);
  info->name = g_strdup (name);
  info->enabled = enabled;
  return info;
}
Exemplo n.º 20
0
static int32_t
ol_player_xmms2_get_dict_int (xmmsv_t *dict, const char *key)
{
  /* ol_log_func (); */
  ol_assert_ret (dict != NULL, 0);
  ol_assert_ret (key != NULL, 0);
  int32_t val = 0;
  if (xmmsv_dict_get_int (dict, key, &val))
  {
    return val;
  }
  return 0;
}
Exemplo n.º 21
0
static char *
ol_player_xmms2_get_dict_string (xmmsv_t *dict, const char *key)
{
  /* ol_log_func (); */
  ol_assert_ret (dict != NULL, NULL);
  ol_assert_ret (key != NULL, NULL);
  const char *val = NULL;
  if (xmmsv_dict_get_string (dict, key, &val))
  {
    return g_strdup (val);
  }
  return NULL;
}
Exemplo n.º 22
0
gboolean
ol_config_proxy_set_string (OlConfigProxy *config,
                            const gchar *key,
                            const gchar* value)
{
  ol_assert_ret (OL_IS_CONFIG_PROXY (config), FALSE);
  ol_assert_ret (key != NULL, FALSE);
  ol_assert_ret (value != NULL, FALSE);
  return ol_config_proxy_set (config,
                              "SetString",
                              key,
                              g_variant_new ("s", value));
}
Exemplo n.º 23
0
struct OlDisplayClass*
ol_display_class_new (const char *name,
                      OlDisplayInitFunc init_func,
                      OlDisplayFreeFunc free_func)
{
  ol_assert_ret (name != NULL, NULL);
  ol_assert_ret (init_func != NULL, NULL);
  ol_assert_ret (free_func != NULL, NULL);
  struct OlDisplayClass *klass = g_new0 (struct OlDisplayClass, 1);
  klass->name = g_strdup (name);
  klass->init = init_func;
  klass->free = free_func;
  return klass;
}
Exemplo n.º 24
0
const char *
ol_lrc_engine_list_get_name (GtkWidget *list)
{
  ol_assert_ret (list != NULL, NULL);
  ol_assert_ret (GTK_IS_COMBO_BOX (list), NULL);
  int index = gtk_combo_box_get_active (GTK_COMBO_BOX (list));
  int count = 0;
  const char **engine_list = ol_lrc_fetch_get_engine_list (&count);
  if (engine_list != NULL && index < count)
  {
    return engine_list[index];
  }
  return NULL;
}
Exemplo n.º 25
0
gboolean
ol_dbus_get_bool (DBusGProxy *proxy, const gchar *method, gboolean *returnval)
{
  ol_assert_ret (proxy != NULL, FALSE);
  ol_assert_ret (method != NULL, FALSE);
  ol_assert_ret (returnval != NULL, FALSE);
  return dbus_g_proxy_call (proxy,
                            method,
                            NULL,
                            G_TYPE_INVALID,
                            G_TYPE_BOOLEAN,
                            returnval,
                            G_TYPE_INVALID);
}
Exemplo n.º 26
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;
}
Exemplo n.º 27
0
static gboolean
ol_player_amarok1_get_string (const char *cmd, char **returnval)
{
  ol_assert_ret (cmd != NULL, FALSE);
  ol_assert_ret (returnval != NULL, FALSE);
  char *dcop_cmd = ol_player_amarok1_get_command (cmd);
  if (*returnval != NULL)
  {
    g_free (*returnval);
    *returnval = NULL;
  }
  gboolean ret = ol_dcop_get_string (dcop_cmd, returnval);
  g_free (dcop_cmd);
  return ret;
}
Exemplo n.º 28
0
gboolean
ol_dbus_set_uint8 (DBusGProxy *proxy,
                   const gchar *method,
                   guint8 value)
{
  ol_assert_ret (proxy != NULL, FALSE);
  ol_assert_ret (method != NULL, FALSE);
  return dbus_g_proxy_call (proxy,
                            method,
                            NULL,
                            G_TYPE_UCHAR,
                            value,
                            G_TYPE_INVALID,
                            G_TYPE_INVALID);
}
Exemplo n.º 29
0
static gboolean
_get_pointer_edge (gint x, gint y,
                   gint width, gint height,
                   gint top, gint bottom,
                   gint left, gint right,
                   GdkWindowEdge *edge)
{
  ol_assert_ret (width > 0 && height > 0, FALSE);
  ol_assert_ret (top >= 0, FALSE);
  ol_assert_ret (bottom >= 0, FALSE);
  ol_assert_ret (left >= 0, FALSE);
  ol_assert_ret (right >= 0, FALSE);
  gboolean ret = TRUE;
  GdkWindowEdge ret_edge = GDK_WINDOW_EDGE_EAST;
  if (x < left)
  {
    if (y < top)
      ret_edge = GDK_WINDOW_EDGE_NORTH_WEST;
    else if (y >= height - bottom)
      ret_edge = GDK_WINDOW_EDGE_SOUTH_WEST;
    else
      ret_edge = GDK_WINDOW_EDGE_WEST;
  }
  else if (x >= width - right)
  {
    if (y < top)
      ret_edge = GDK_WINDOW_EDGE_NORTH_EAST;
    else if (y >= height - bottom)
      ret_edge = GDK_WINDOW_EDGE_SOUTH_EAST;
    else
      ret_edge = GDK_WINDOW_EDGE_EAST;
  }
  else if (y < top)
  {
    ret_edge = GDK_WINDOW_EDGE_NORTH;
  }
  else if (y >= height - bottom)
  {
    ret_edge = GDK_WINDOW_EDGE_SOUTH;
  }
  else
  {
    ret = FALSE;
  }
  if (edge != NULL && ret)
    *edge = ret_edge;
  return ret;
}
Exemplo n.º 30
0
static GIcon *
_icon_new_from_name (const gchar *icon_name)
{
  ol_assert_ret (icon_name != NULL, NULL);
  /* This is taken from gdesktopappinfo.c of GIO */
  GIcon *icon = NULL;
  if (g_path_is_absolute (icon_name))
  {
    GFile *file;
    file = g_file_new_for_path (icon_name);
    icon = g_file_icon_new (file);
    g_object_unref (file);
  }
  else
  {
    char *p;
    /* Work around a common mistake in desktop files */
    if ((p = strrchr (icon_name, '.')) != NULL &&
        (strcmp (p, ".png") == 0 ||
         strcmp (p, ".xpm") == 0 ||
         strcmp (p, ".svg") == 0))
    {
      gchar *real_name = g_strndup (icon_name, p - icon_name);
      icon = g_themed_icon_new (real_name);
      g_free (real_name);
    }
    else
    {
      icon = g_themed_icon_new (icon_name);
    }
  }
  return icon;
}