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); } }
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; }
static gboolean _sync_default_cb (OlConfigProxy *config) { OlConfigProxyPrivate *priv = OL_CONFIG_PROXY_GET_PRIVATE (config); priv->default_sync_handler = 0; if (priv->default_builder != NULL) { GError *error = NULL; GVariant *ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (config), "SetDefaultValues", g_variant_new ("(a{sv})", priv->default_builder), G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, /* timeout_secs */ NULL, /* cancellable */ &error); if (ret) { g_variant_unref (ret); } else { ol_errorf ("Cannot set config default values: %s\n", error->message); g_error_free (error); } g_variant_builder_unref (priv->default_builder); priv->default_builder = NULL; } return FALSE; }
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; }
void ol_player_chooser_set_info_by_state (OlPlayerChooser *window, enum OlPlayerChooserState state) { ol_assert (OL_IS_PLAYER_CHOOSER (window)); OlPlayerChooserPrivate *priv = OL_PLAYER_CHOOSER_GET_PRIVATE (window); _set_sensitive (window, TRUE); switch (state) { case OL_PLAYER_CHOOSER_STATE_NO_PLAYER: ol_player_chooser_set_info (window, _("There is no supported player running"), _("Please choose a player below to launch")); ol_player_chooser_set_image_by_name (window, GTK_STOCK_DIALOG_INFO); break; case OL_PLAYER_CHOOSER_STATE_LAUNCH_FAIL: { gchar *title = g_strdup_printf (_("Failed to connect to %s"), g_app_info_get_name (priv->launch_app)); gchar *desc = g_strdup_printf (_("%s is not supported by OSD Lyrics, or not running. Please launch another player"), g_app_info_get_name (priv->launch_app)); ol_player_chooser_set_info (window, title, desc); ol_player_chooser_set_image_by_name (window, GTK_STOCK_DIALOG_ERROR); g_free (title); g_free (desc); _set_launch_app (window, NULL); break; } case OL_PLAYER_CHOOSER_STATE_CONNECTED: gtk_widget_hide (GTK_WIDGET (window)); break; default: ol_errorf ("Unknown player chooser state %d\n", (int) state); } }
static void _seek_cb (OlScrollWindow *scroll, guint id, gdouble percentage, gpointer userdata) { OlScrollModule *module = userdata; if (module->lrc) { OlLrcIter *iter = ol_lrc_iter_from_id (module->lrc, id); if (!ol_lrc_iter_is_valid (iter)) { ol_errorf ("Seek to an invalid ID: %u\n", id); ol_lrc_iter_free (iter); return; } gint64 iter_time = ol_lrc_iter_get_timestamp (iter); guint64 duration = ol_lrc_iter_get_duration (iter); ol_lrc_iter_free (iter); gint64 new_time = iter_time + duration * percentage; ol_player_seek (module->player, new_time); ol_scroll_window_set_progress (module->scroll, id, percentage); /* avoid players send played time before seeked. */ g_usleep (200000); } }
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; }
static GList * _prepend_subdirs (GList *list) { gchar *path = list->data; GError *error = NULL; GDir *dir = g_dir_open (path, 0, &error); if (!dir) { ol_errorf ("Cannot open dir %s: %s\n", path, error->message); g_error_free (error); return list; } const gchar *name; while ((name = g_dir_read_name (dir)) != NULL) { gchar *filepath = g_build_filename (path, name, NULL); if (g_file_test (filepath, G_FILE_TEST_IS_DIR)) { list = g_list_prepend (list, filepath); list = _prepend_subdirs (list); } else { g_free (filepath); } } return list; }
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; } }
int ol_is_running () { ol_log_func (); int ret = 1; char *dir = g_strdup_printf ("%s/%s/", g_get_user_config_dir (), PACKAGE_NAME); if (g_mkdir_with_parents (dir, 0755) == -1) { ol_error ("Failed to endure config dir"); } else { char *path = g_strdup_printf ("%s/%s/%s", g_get_user_config_dir (), PACKAGE_NAME, LOCK_FILENAME); int fd = open (path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (fd == -1) { ol_error ("Failed to open or create singleton lock"); } else { if (_lockfile (fd) < 0) { if (errno == EACCES || errno == EAGAIN) { close (fd); } ol_infof ("Can not lock file %s: %s\n", path, strerror (errno)); } else { if (ftruncate (fd, 0) != 0) { ol_errorf ("Failed to truncate singleton lock: %s\n", strerror (errno)); } char buf[16]; sprintf (buf, "%ld", (long)getpid ()); if (write (fd, buf, strlen (buf)) != strlen (buf)) ol_errorf ("Failed to write pid in singleton lock\n"); ret = 0; } } g_free (path); } g_free (dir); return ret; }
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; }
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; } }
static void ol_lyric_source_search_complete_cb (OlLyricSource *source, GVariant *parameters) { GVariantIter *iter = NULL; GVariant *dict = NULL; GList *result = NULL; gint taskid; gint statusid; OlLyricSourceTask *task; g_variant_get (parameters, "(iiaa{sv})", &taskid, &statusid, &iter); task = ol_lyric_source_get_search_task (source, taskid); if (task == NULL) { ol_errorf ("Search task %d not exist\n", taskid); return; } if (statusid < 0 || statusid > OL_LYRIC_SOURCE_STATUS_FALIURE) { ol_errorf ("Invalid search status %d\n", statusid); return; } while (g_variant_iter_loop (iter, "@a{sv}", &dict)) { OlLyricSourceCandidate *candidate; candidate = ol_lyric_source_candidate_new_with_variant (dict); result = g_list_prepend (result, candidate); } g_variant_iter_free (iter); result = g_list_reverse (result); g_signal_emit (task, _search_signals[SEARCH_SIGNAL_COMPLETE], 0, statusid, result); while (result) { OlLyricSourceCandidate *candidate = result->data; g_object_unref (candidate); result = g_list_delete_link (result, result); } ol_lyric_source_remove_search_task (source, taskid); }
static void ol_lyric_source_download_complete_cb (OlLyricSource *source, GVariant *parameters) { OlLyricSourceTask *task; int taskid; int status; GVariantIter *iter; gchar *content = NULL; gsize len = 0; g_variant_get (parameters, "(iiay)", &taskid, &status, &iter); task = ol_lyric_source_get_download_task (source, taskid); if (task == NULL) { ol_errorf ("Download task %d not exist\n", taskid); } else if (status < 0 || status > OL_LYRIC_SOURCE_STATUS_FALIURE) { ol_errorf ("Invalid download status %d\n", status); } else { len = g_variant_iter_n_children (iter); content = g_new (gchar, len + 1); gsize i = 0; while (g_variant_iter_loop (iter, "y", &content[i])) i++; content[len] = '\0'; g_signal_emit (G_OBJECT (task), _download_signals[DOWNLOAD_SIGNAL_COMPLETE], 0, status, content, (guint) len); g_free (content); } g_variant_iter_free (iter); ol_lyric_source_remove_download_task (source, taskid); }
static void ol_config_proxy_g_signal (GDBusProxy *proxy, const gchar *sender_name, const gchar *signal_name, GVariant *parameters) { if (strcmp (signal_name, "ValueChanged") == 0) { ol_config_proxy_value_changed_cb (OL_CONFIG_PROXY (proxy), parameters); } else { ol_errorf ("Unknown D-Bus signal: %s\n", signal_name); } }
static void ol_osd_render_update_font_height (OlOsdRenderContext *context) { PangoFontMetrics *metrics = pango_context_get_metrics (context->pango_context, pango_layout_get_font_description (context->pango_layout), /* font desc */ NULL); /* languague */ if (metrics == NULL) { ol_errorf ("Cannot get font metrics\n"); } context->font_height = 0; int ascent, descent; ascent = pango_font_metrics_get_ascent (metrics); descent = pango_font_metrics_get_descent (metrics); pango_font_metrics_unref (metrics); context->font_height += PANGO_PIXELS (ascent + descent); }
static void _apply_kernel (cairo_surface_t *surface, const int *kernel, int kernel_size) { ol_assert (kernel_size > 0 && kernel_size % 2 == 1); ol_assert (kernel != NULL); static const int DIR[2][2] = {{0, 1}, {1, 0}}; guint32 *pixels = (guint32*) cairo_image_surface_get_data (surface); int width = cairo_image_surface_get_width (surface); int height = cairo_image_surface_get_height (surface); if (pixels == NULL || width <= 0 || height <= 0) { ol_errorf ("Invalid image surface"); return; } int kernel_orig = kernel_size / 2; int d, i, x, y; for (d = 0; d < 2; d++) { guint32 *old_pixels = g_new (guint32, width * height); memcpy (old_pixels, pixels, sizeof (guint32) * width * height); for (x = 0; x < width; x++) for (y = 0; y < height; y++) { struct _pixel final_value = {0}; int sum = 0; for (i = 0; i < kernel_size; i++) { int x1 = x + (i - kernel_orig) * DIR[d][0]; int y1 = y + (i - kernel_orig) * DIR[d][1]; int index1 = _pos_to_index (x1, y1, width, height); if (index1 > 0) { sum += kernel[i]; struct _pixel value = _num_to_pixel_with_factor (old_pixels[index1], kernel[i]); _pixel_plus (&final_value, &value); } } int index = _pos_to_index (x, y, width, height); pixels[index] = _pixel_to_num_with_divisor (&final_value, sum); } g_free (old_pixels); } }
OlLyricSourceSearchTask * ol_lyric_source_search (OlLyricSource *source, OlMetadata *metadata, GList *source_ids) { ol_assert_ret (OL_IS_LYRIC_SOURCE (source), NULL); GVariant *ret; OlLyricSourceSearchTask *task = NULL; GError *error = NULL; GList *id; GVariantBuilder *idbuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); for (id = source_ids; id; id = g_list_next (id)) { g_variant_builder_add (idbuilder, "s", id->data); } GVariant *mdvalue = ol_metadata_to_variant (metadata); ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (source), "Search", g_variant_new ("(@a{sv}as)", mdvalue, idbuilder), G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, /* timeout */ NULL, /* cancellable */ &error); g_variant_builder_unref (idbuilder); if (ret) { OlLyricSourcePrivate *priv; priv = OL_LYRIC_SOURCE_GET_PRIVATE (source); int taskid; g_variant_get (ret, "(i)", &taskid); task = ol_lyric_source_search_task_new (source, taskid); g_hash_table_insert (priv->search_tasks, GINT_TO_POINTER (taskid), task); g_variant_unref (ret); } else { ol_errorf ("Fail to call search: %s\n", error->message); g_error_free (error); } return task; }
void ol_gussian_blur (cairo_surface_t *surface, double sigma) { ol_assert (surface != NULL); ol_assert (sigma > 0); cairo_format_t format = cairo_image_surface_get_format (surface); if (format != CAIRO_FORMAT_ARGB32) { ol_errorf ("The surface format is %d, only ARGB32 is supported\n", format); return; } int kernel_size; int *kernel = _calc_kernel (sigma, &kernel_size); _apply_kernel (surface, kernel, kernel_size); g_free (kernel); }
static gboolean ol_config_proxy_set (OlConfigProxy *config, const gchar *method, const gchar *key, GVariant *value) { ol_assert_ret (key != NULL && key[0] != '\0', FALSE); if (key[0] == '.') { OlConfigProxyPrivate *priv = OL_CONFIG_PROXY_GET_PRIVATE (config); g_variant_ref_sink (value); g_hash_table_insert (priv->temp_values, g_strdup (key), g_variant_new ("(*)", g_variant_ref_sink (value))); g_signal_emit (config, _signals[SIGNAL_CHANGED], g_quark_from_string (key), key); g_variant_unref (value); return TRUE; } else { GError *error = NULL; GVariant *ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (config), method, g_variant_new ("(s*)", key, value), G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, /* timeout_secs */ NULL, /* cancellable */ &error); if (ret) { g_variant_unref (ret); return TRUE; } else { ol_errorf ("Cannot set config value: %s\n", error->message); g_error_free (error); return FALSE; } } }
size_t convert(const char *from_charset, const char *to_charset, char *src, size_t srclen, char *dest, size_t destlen) { ol_log_func (); size_t ret; iconv_t cv; char **input = &src; char **output = &dest; memset(dest, 0, destlen); if((cv = iconv_open(to_charset, from_charset)) == (iconv_t)-1) { ol_errorf (" the conversion from %s to %s is not supported by the implementation.\n", from_charset, to_charset); return (size_t)-1; } ret = iconv(cv, input, &srclen, output, &destlen); iconv_close(cv); return ret; }
int fetch_into_file(const char *url, const char *refer, FILE *fp) { ol_log_func (); CURL *curl; CURLcode code; curl = my_curl_init(NULL, url, refer, NULL, NULL, 0, NULL, fp, cntimeout); if(curl == NULL) return -1; code = curl_easy_perform(curl); if(code != CURLE_OK) { ol_errorf ("failed to perform: [%s]\n", errbuf); curl_easy_cleanup(curl); return -1; } curl_easy_cleanup(curl); return 0; }
int curl_url_encoding(CURL *curl, char *input, char *output, size_t size) { ol_log_func (); char *escp; int flag = 0; if(curl == NULL) { curl = curl_easy_init(); flag = 1; } /* * convert to GBK, this should be done before this function called * char buf[BUFSZ]; iconv_t icv; if(charset != NULL) icv = iconv_open("GBK", charset); else icv = iconv_open("GBK", "UTF-8"); convert_icv(&icv, input, strlen(input), buf, BUFSZ); iconv_close(icv); */ escp = curl_easy_escape(curl, input, 0); if(escp == NULL) { ol_errorf ("curl_easy_escape error.\n"); return -1; } if(strlen(escp) > size) { errno = E2BIG; /* identify that buffer storing the result is too small */ return -1; } strcpy(output, escp); curl_free(escp); if(flag == 1) curl_easy_cleanup(curl); return 0; }
static void ol_lyric_source_search_started_cb (OlLyricSource *source, GVariant *parameters) { OlLyricSourceTask *task; int taskid; gchar *sourceid; gchar *sourcename; g_variant_get (parameters, "(i&s&s)", &taskid, &sourceid, &sourcename); task = ol_lyric_source_get_search_task (source, taskid); if (task == NULL) { ol_errorf ("Search task %d not exist\n", taskid); return; } g_signal_emit (G_OBJECT (task), _search_signals[SEARCH_SIGNAL_STARTED], 0, sourceid, sourcename); }
OlLyricSourceDownloadTask * ol_lyric_source_download (OlLyricSource *source, OlLyricSourceCandidate *candidate) { ol_assert_ret (OL_IS_LYRIC_SOURCE (source), NULL); ol_assert_ret (OL_IS_LYRIC_SOURCE_CANDIDATE (candidate), NULL); OlLyricSourceDownloadTask *task = NULL; GVariant *ret = NULL; GError *error = NULL; ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (source), "Download", g_variant_new ("(sv)", ol_lyric_source_candidate_get_sourceid (candidate), ol_lyric_source_candidate_get_downloadinfo (candidate)), G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, /* timeout */ NULL, /* cancellable */ &error); if (ret) { OlLyricSourcePrivate *priv; priv = OL_LYRIC_SOURCE_GET_PRIVATE (source); int taskid = 0; g_variant_get (ret, "(i)", &taskid); task = ol_lyric_source_download_task_new (source, taskid); g_hash_table_insert (priv->download_tasks, GINT_TO_POINTER (taskid), task); g_variant_unref (ret); } else { ol_errorf ("Fail to call download: %s\n", error->message); g_error_free (error); } return task; }
static void _launch_app (OlPlayerChooser *window, GAppInfo *app_info) { GError *err = NULL; if (!g_app_info_launch (app_info, NULL, NULL, &err)) { ol_errorf ("Cannot launch %s: %s", g_app_info_get_commandline (app_info), err->message); gchar *title = g_strdup_printf (_("Failed to launch %s"), g_app_info_get_name (app_info)); ol_player_chooser_set_info (window, title, err->message); ol_player_chooser_set_image_by_name (window, GTK_STOCK_DIALOG_ERROR); g_free (title); g_error_free (err); } else { _set_launch_app (window, app_info); gchar *title = g_strdup_printf (_("Launching %s"), g_app_info_get_name (app_info)); gchar *desc = g_strdup_printf (_("OSD Lyrics is trying to launch and connect to %s. Please wait for a second."), g_app_info_get_name (app_info)); ol_player_chooser_set_info (window, title, desc); g_free (title); g_free (desc); ol_player_chooser_set_image_by_gicon (window, g_app_info_get_icon (app_info)); _set_sensitive (window, FALSE); if (OL_IS_PLAYER_CHOOSER (window)) { _remember_cmd_if_needed (window, g_app_info_get_commandline (app_info)); gtk_dialog_response (GTK_DIALOG (window), OL_PLAYER_CHOOSER_RESPONSE_LAUNCH); } } }
static void _app_info_set_from_desktop_file (OlAppInfo *info, enum OlAppInfoFlags flags) { GList *path_list = _get_desktop_file_path_list (); gchar *filename = _find_file_in_path_list (path_list, info->binfile, ".desktop", (flags & OL_APP_INFO_WITH_PREFIX) != 0, NULL); if (!filename) { ol_debugf ("Cannot find desktop file for %s\n", info->binfile); return; } GKeyFile *keyfile = g_key_file_new (); GError *error = NULL; if (!g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error)) { ol_errorf ("Cannot open desktop file %s: %s\n", filename, error->message); g_error_free (error); } else { if (flags & OL_APP_INFO_USE_DESKTOP_NAME) { gchar *name = g_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL); if (name != NULL) { if (info->name != NULL) g_free (info->name); info->name = name; } } if (flags & OL_APP_INFO_USE_DESKTOP_CMDLINE) { gchar *cmdline = g_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL, NULL); if (cmdline != NULL) { if (info->cmdline != NULL) g_free (info->cmdline); info->cmdline = cmdline; } } if (flags & OL_APP_INFO_USE_DESKTOP_ICON) { gchar *icon_name = g_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL, NULL); GIcon *icon = _icon_new_from_name (icon_name); if (icon != NULL) { if (info->icon != NULL) g_object_unref (info->icon); info->icon = icon; } } info->should_show = !g_key_file_get_boolean (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, NULL); } g_free (filename); g_key_file_free (keyfile); }
/** * * * @param path_list A GList of gchar*. * @param prefix The prefix of the filename, cannot be #NULL. * @param suffix The suffix of filename. If #match_prefix is #TRUE, #NULL or * empty string means any suffix is acceptable. * @param match_prefix * * @return */ static gchar * _find_file_in_path_list (GList *path_list, const gchar *prefix, const gchar *suffix, gboolean match_prefix, gboolean (*file_test_func) (const gchar *)) { ol_assert_ret (prefix != NULL, NULL); if (suffix == NULL) suffix = ""; if (!file_test_func) file_test_func = _file_exists; GList *pathiter; gchar *ret = NULL; for (pathiter = path_list; pathiter != NULL; pathiter = g_list_next (pathiter)) { gchar *path = pathiter->data; if (!match_prefix) { gchar *filename = NULL; gchar *fullname = g_strdup_printf ("%s%s", prefix, suffix); filename = g_build_filename (path, fullname, NULL); g_free (fullname); if (file_test_func (filename)) ret = filename; else g_free (filename); } /* if !match_prefix */ else { GError *error = NULL; GDir *dir = g_dir_open (path, 0, &error); if (!dir) { ol_errorf ("Cannot open path %s: %s\n", path, error->message); g_error_free (error); continue; } const gchar *name; while ((name = g_dir_read_name (dir)) != NULL) { if (g_str_has_prefix (name, prefix) && g_str_has_suffix (name, suffix)) { gchar *filename = g_build_filename (path, name, NULL); if (file_test_func (filename) && (!ret || strcmp (filename, ret) < 0)) { g_free (ret); ret = filename; } else { g_free (filename); } } } g_dir_close (dir); } if (ret != NULL) break; } return ret; }
GList * ol_lyric_source_list_sources (OlLyricSource* source) { ol_assert_ret (OL_IS_LYRIC_SOURCE (source), NULL); GList *list = NULL; GVariant *ret; GError *error = NULL; ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (source), "ListSources", NULL, /* parameters */ G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, &error); if (ret) { GVariantIter *iter; g_variant_get (ret, "(aa{sv})", &iter); GVariantIter *dictiter; while (g_variant_iter_loop (iter, "a{sv}", &dictiter)) { GVariant *value; gchar *key; gchar *name = NULL, *id = NULL; gboolean enabled = FALSE; while (g_variant_iter_loop (dictiter, "{sv}", &key, &value)) { if (strcmp (key, "id") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) { id = g_variant_dup_string (value, NULL); } else if (strcmp (key, "name") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) { name = g_variant_dup_string (value, NULL); } else if (strcmp (key, "enabled") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)) { enabled = g_variant_get_boolean (value); } } if (id == NULL || name == NULL) { ol_error ("Missing id or name in lyric source info"); } else { list = g_list_prepend (list, ol_lyric_source_info_new (id, name, enabled)); } g_free (id); g_free (name); } g_variant_iter_free (iter); list = g_list_reverse (list); g_variant_unref (ret); return list; } else { ol_errorf ("Fail to get lyric source list: %s\n", error->message); g_error_free (error); return NULL; } }
static enum _GetResult ol_config_proxy_get (OlConfigProxy *config, const gchar *method, const gchar *key, const gchar *format_string, gpointer retval) { ol_assert_ret (OL_IS_CONFIG_PROXY (config), GET_RESULT_FAILED); ol_assert_ret (key != NULL, GET_RESULT_FAILED); enum _GetResult ret = GET_RESULT_OK; GError *error = NULL; GVariant *value = NULL; OlConfigProxyPrivate *priv = OL_CONFIG_PROXY_GET_PRIVATE (config); if (key[0] == '.') { value = g_hash_table_lookup (priv->temp_values, key); if (value) g_variant_ref (value); } else { value = g_dbus_proxy_call_sync (G_DBUS_PROXY (config), method, g_variant_new ("(s)", key), G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, /* timeout_secs */ NULL, /* cancellable */ &error); } if (!value) { if (g_dbus_error_is_remote_error (error)) { gchar *error_name = g_dbus_error_get_remote_error (error); if (strcmp (error_name, OL_ERROR_VALUE_NOT_EXIST) == 0) { ol_debugf ("Key %s not exists, use default value\n", key); ret = GET_RESULT_MISSING; } else { ol_errorf ("Failed to get config %s: %s\n", key, error->message); ret = GET_RESULT_FAILED; } g_free (error_name); } else { ol_errorf ("%s failed. Cannot get value %s from config: %s\n", method, key, error->message); ret = GET_RESULT_FAILED; } g_error_free (error); } else { g_variant_get (value, format_string, retval); g_variant_unref (value); } return ret; }