mirror of
https://github.com/davatorium/rofi.git
synced 2025-01-27 15:25:24 -05:00
[CI] Update doxygen-coverage.
This commit is contained in:
parent
8b9afa39c8
commit
54ebfa7484
5 changed files with 103 additions and 96 deletions
|
@ -396,6 +396,9 @@ char *helper_string_replace_if_exists(char *string, ...);
|
|||
* @param ext NULL terminated array of file extension passed to option.
|
||||
* @param parent_dir The file that was used to import this file, or NULL.
|
||||
*
|
||||
* Get the full path to the theme, trying to resolve it over the possible
|
||||
* locations.
|
||||
*
|
||||
* @returns path to theme or copy of filename if not found.
|
||||
*/
|
||||
char *helper_get_theme_path(const char *file, const char **ext,
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
/** The log domain for this helper. */
|
||||
#define G_LOG_DOMAIN "Helper"
|
||||
|
||||
#include "helper.h"
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "helper-theme.h"
|
||||
|
|
|
@ -46,7 +46,9 @@
|
|||
#include "xrmoptions.h"
|
||||
|
||||
typedef struct {
|
||||
/** array of strings containing key descriptions */
|
||||
char **messages;
|
||||
/** lengths of the messages array */
|
||||
unsigned int messages_length;
|
||||
} KeysHelpModePrivateData;
|
||||
|
||||
|
@ -118,5 +120,5 @@ Mode help_keys_mode = {.name = "keys",
|
|||
._get_completion = NULL,
|
||||
._get_display_value = _get_display_value,
|
||||
.private_data = NULL,
|
||||
.free = NULL,
|
||||
.type = MODE_TYPE_SWITCHER };
|
||||
.free = NULL,
|
||||
.type = MODE_TYPE_SWITCHER};
|
||||
|
|
|
@ -51,9 +51,10 @@
|
|||
#include "helper.h"
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
// thumbnailers key file's group and file extension
|
||||
/** Desktop entry specifying the thumbnailer. */
|
||||
#define THUMBNAILER_ENTRY_GROUP "Thumbnailer Entry"
|
||||
#define THUMBNAILER_EXTENSION ".thumbnailer"
|
||||
/** Extension used for the thumbnailer. */
|
||||
#define THUMBNAILER_EXTENSION ".thumbnailer"
|
||||
|
||||
typedef struct {
|
||||
// Context for icon-themes.
|
||||
|
@ -125,28 +126,28 @@ static void rofi_icon_fetcher_load_thumbnailers(const gchar *path) {
|
|||
g_warning("Error loading thumbnailer %s: %s", filename, error->message);
|
||||
g_error_free(error);
|
||||
} else {
|
||||
gchar *command = g_key_file_get_string(
|
||||
key_file, THUMBNAILER_ENTRY_GROUP, "Exec", NULL);
|
||||
gchar *command = g_key_file_get_string(key_file, THUMBNAILER_ENTRY_GROUP,
|
||||
"Exec", NULL);
|
||||
gchar **mime_types = g_key_file_get_string_list(
|
||||
key_file, THUMBNAILER_ENTRY_GROUP, "MimeType", NULL, NULL);
|
||||
key_file, THUMBNAILER_ENTRY_GROUP, "MimeType", NULL, NULL);
|
||||
|
||||
if (mime_types && command) {
|
||||
guint i;
|
||||
for (i = 0; mime_types[i] != NULL; i++) {
|
||||
if (!g_hash_table_lookup(
|
||||
rofi_icon_fetcher_data->thumbnailers, mime_types[i])) {
|
||||
g_info("Loading thumbnailer %s for mimetype %s", filename, mime_types[i]);
|
||||
g_hash_table_insert(
|
||||
rofi_icon_fetcher_data->thumbnailers,
|
||||
g_strdup(mime_types[i]),
|
||||
g_strdup(command)
|
||||
);
|
||||
if (!g_hash_table_lookup(rofi_icon_fetcher_data->thumbnailers,
|
||||
mime_types[i])) {
|
||||
g_info("Loading thumbnailer %s for mimetype %s", filename,
|
||||
mime_types[i]);
|
||||
g_hash_table_insert(rofi_icon_fetcher_data->thumbnailers,
|
||||
g_strdup(mime_types[i]), g_strdup(command));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mime_types) g_strfreev(mime_types);
|
||||
if (command) g_free(command);
|
||||
if (mime_types)
|
||||
g_strfreev(mime_types);
|
||||
if (command)
|
||||
g_free(command);
|
||||
}
|
||||
|
||||
g_key_file_free(key_file);
|
||||
|
@ -157,18 +158,17 @@ static void rofi_icon_fetcher_load_thumbnailers(const gchar *path) {
|
|||
g_free(thumb_path);
|
||||
}
|
||||
|
||||
static gchar** setup_thumbnailer_command(const gchar *command,
|
||||
static gchar **setup_thumbnailer_command(const gchar *command,
|
||||
const gchar *filename,
|
||||
const gchar *encoded_uri,
|
||||
const gchar *output_path,
|
||||
int size) {
|
||||
const gchar *output_path, int size) {
|
||||
gchar **command_parts = g_strsplit(command, " ", 0);
|
||||
guint command_parts_count = g_strv_length(command_parts);
|
||||
|
||||
gchar **command_args = NULL;
|
||||
|
||||
if (command_parts) {
|
||||
command_args = g_malloc0(sizeof(gchar*) * (command_parts_count + 3 + 1));
|
||||
command_args = g_malloc0(sizeof(gchar *) * (command_parts_count + 3 + 1));
|
||||
|
||||
// set process niceness value to 19 (low priority)
|
||||
guint current_index = 0;
|
||||
|
@ -206,8 +206,9 @@ static gboolean exec_thumbnailer_command(gchar **command_args) {
|
|||
gint wait_status;
|
||||
GError *error = NULL;
|
||||
|
||||
gboolean spawned = g_spawn_sync(NULL, command_args,
|
||||
NULL, G_SPAWN_DEFAULT | G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &wait_status, &error);
|
||||
gboolean spawned = g_spawn_sync(NULL, command_args, NULL,
|
||||
G_SPAWN_DEFAULT | G_SPAWN_SEARCH_PATH, NULL,
|
||||
NULL, NULL, NULL, &wait_status, &error);
|
||||
|
||||
if (spawned) {
|
||||
return g_spawn_check_wait_status(wait_status, NULL);
|
||||
|
@ -226,8 +227,8 @@ static gboolean rofi_icon_fetcher_create_thumbnail(const gchar *mime_type,
|
|||
int size) {
|
||||
gboolean thumbnail_created = FALSE;
|
||||
|
||||
gchar *command = g_hash_table_lookup(
|
||||
rofi_icon_fetcher_data->thumbnailers, mime_type);
|
||||
gchar *command =
|
||||
g_hash_table_lookup(rofi_icon_fetcher_data->thumbnailers, mime_type);
|
||||
|
||||
if (!command) {
|
||||
return thumbnail_created;
|
||||
|
@ -235,7 +236,7 @@ static gboolean rofi_icon_fetcher_create_thumbnail(const gchar *mime_type,
|
|||
|
||||
// split command string to isolate arguments and expand them in a list
|
||||
gchar **command_args = setup_thumbnailer_command(
|
||||
command, filename, encoded_uri, output_path, size);
|
||||
command, filename, encoded_uri, output_path, size);
|
||||
|
||||
if (command_args) {
|
||||
thumbnail_created = exec_thumbnailer_command(command_args);
|
||||
|
@ -304,16 +305,16 @@ void rofi_icon_fetcher_init(void) {
|
|||
|
||||
// load available thumbnailers from system dirs and user dir
|
||||
rofi_icon_fetcher_data->thumbnailers = g_hash_table_new_full(
|
||||
g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free);
|
||||
g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free);
|
||||
|
||||
const gchar * const *system_data_dirs = g_get_system_data_dirs();
|
||||
const gchar *const *system_data_dirs = g_get_system_data_dirs();
|
||||
const gchar *user_data_dir = g_get_user_data_dir();
|
||||
|
||||
rofi_icon_fetcher_load_thumbnailers(user_data_dir);
|
||||
|
||||
guint i;
|
||||
for (i = 0; system_data_dirs[i] != NULL; i++) {
|
||||
rofi_icon_fetcher_load_thumbnailers(system_data_dirs[i]);
|
||||
rofi_icon_fetcher_load_thumbnailers(system_data_dirs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -459,39 +460,38 @@ gboolean rofi_icon_fetcher_file_is_image(const char *const path) {
|
|||
}
|
||||
|
||||
// build thumbnail's path using md5 hash of an entry name
|
||||
static gchar* rofi_icon_fetcher_get_thumbnail(gchar* name,
|
||||
int requested_size,
|
||||
static gchar *rofi_icon_fetcher_get_thumbnail(gchar *name, int requested_size,
|
||||
int *thumb_size) {
|
||||
// calc entry_name md5 hash
|
||||
GChecksum* checksum = g_checksum_new(G_CHECKSUM_MD5);
|
||||
g_checksum_update(checksum, (guchar*)name, -1);
|
||||
GChecksum *checksum = g_checksum_new(G_CHECKSUM_MD5);
|
||||
g_checksum_update(checksum, (guchar *)name, -1);
|
||||
const gchar *md5_hex = g_checksum_get_string(checksum);
|
||||
|
||||
// determine thumbnail folder based on the request size
|
||||
const gchar* cache_dir = g_get_user_cache_dir();
|
||||
gchar* thumb_dir;
|
||||
gchar* thumb_path;
|
||||
const gchar *cache_dir = g_get_user_cache_dir();
|
||||
gchar *thumb_dir;
|
||||
gchar *thumb_path;
|
||||
|
||||
if (requested_size <= 128) {
|
||||
*thumb_size = 128;
|
||||
thumb_dir = g_strconcat(cache_dir, "/thumbnails/normal/", NULL);
|
||||
thumb_path = g_strconcat(cache_dir, "/thumbnails/normal/",
|
||||
md5_hex, ".png", NULL);
|
||||
thumb_path =
|
||||
g_strconcat(cache_dir, "/thumbnails/normal/", md5_hex, ".png", NULL);
|
||||
} else if (requested_size <= 256) {
|
||||
*thumb_size = 256;
|
||||
thumb_dir = g_strconcat(cache_dir, "/thumbnails/large/", NULL);
|
||||
thumb_path = g_strconcat(cache_dir, "/thumbnails/large/",
|
||||
md5_hex, ".png", NULL);
|
||||
thumb_path =
|
||||
g_strconcat(cache_dir, "/thumbnails/large/", md5_hex, ".png", NULL);
|
||||
} else if (requested_size <= 512) {
|
||||
*thumb_size = 512;
|
||||
thumb_dir = g_strconcat(cache_dir, "/thumbnails/x-large/", NULL);
|
||||
thumb_path = g_strconcat(cache_dir, "/thumbnails/x-large/",
|
||||
md5_hex, ".png", NULL);
|
||||
thumb_path =
|
||||
g_strconcat(cache_dir, "/thumbnails/x-large/", md5_hex, ".png", NULL);
|
||||
} else {
|
||||
*thumb_size = 1024;
|
||||
thumb_dir = g_strconcat(cache_dir, "/thumbnails/xx-large/", NULL);
|
||||
thumb_path = g_strconcat(cache_dir, "/thumbnails/xx-large/",
|
||||
md5_hex, ".png", NULL);
|
||||
thumb_path =
|
||||
g_strconcat(cache_dir, "/thumbnails/xx-large/", md5_hex, ".png", NULL);
|
||||
}
|
||||
|
||||
// create thumbnail directory if it does not exist
|
||||
|
@ -504,7 +504,7 @@ static gchar* rofi_icon_fetcher_get_thumbnail(gchar* name,
|
|||
}
|
||||
|
||||
// retrieves icon key from a .desktop file
|
||||
static gchar* rofi_icon_fetcher_get_desktop_icon(const gchar* file_path) {
|
||||
static gchar *rofi_icon_fetcher_get_desktop_icon(const gchar *file_path) {
|
||||
GKeyFile *kf = g_key_file_new();
|
||||
GError *key_error = NULL;
|
||||
gchar *icon_key = NULL;
|
||||
|
@ -514,8 +514,8 @@ static gchar* rofi_icon_fetcher_get_desktop_icon(const gchar* file_path) {
|
|||
if (res) {
|
||||
icon_key = g_key_file_get_string(kf, "Desktop Entry", "Icon", NULL);
|
||||
} else {
|
||||
g_debug("Failed to parse desktop file %s because: %s.",
|
||||
file_path, key_error->message);
|
||||
g_debug("Failed to parse desktop file %s because: %s.", file_path,
|
||||
key_error->message);
|
||||
|
||||
g_error_free(key_error);
|
||||
}
|
||||
|
@ -559,10 +559,9 @@ static void rofi_icon_fetcher_worker(thread_state *sdata,
|
|||
int argsv = 0;
|
||||
gchar *size_str = g_strdup_printf("%d", thumb_size);
|
||||
|
||||
helper_parse_setup(
|
||||
config.preview_cmd, &command_args, &argsv,
|
||||
"{input}", entry_name,
|
||||
"{output}", icon_path_, "{size}", size_str, NULL);
|
||||
helper_parse_setup(config.preview_cmd, &command_args, &argsv, "{input}",
|
||||
entry_name, "{output}", icon_path_, "{size}",
|
||||
size_str, NULL);
|
||||
|
||||
g_free(size_str);
|
||||
|
||||
|
@ -580,8 +579,8 @@ static void rofi_icon_fetcher_worker(thread_state *sdata,
|
|||
if (icon_key == NULL || strlen(icon_key) == 0) {
|
||||
// no icon in .desktop file, fallback on mimetype icon (text/plain)
|
||||
icon_path = icon_path_ = nk_xdg_theme_get_icon(
|
||||
rofi_icon_fetcher_data->xdg_context, themes, NULL, "text-plain",
|
||||
MIN(sentry->wsize, sentry->hsize), 1, TRUE);
|
||||
rofi_icon_fetcher_data->xdg_context, themes, NULL, "text-plain",
|
||||
MIN(sentry->wsize, sentry->hsize), 1, TRUE);
|
||||
|
||||
g_free(icon_key);
|
||||
} else if (g_path_is_absolute(icon_key)) {
|
||||
|
@ -590,8 +589,8 @@ static void rofi_icon_fetcher_worker(thread_state *sdata,
|
|||
} else {
|
||||
// icon in .desktop file is a standard icon name
|
||||
icon_path = icon_path_ = nk_xdg_theme_get_icon(
|
||||
rofi_icon_fetcher_data->xdg_context, themes, NULL, icon_key,
|
||||
MIN(sentry->wsize, sentry->hsize), 1, TRUE);
|
||||
rofi_icon_fetcher_data->xdg_context, themes, NULL, icon_key,
|
||||
MIN(sentry->wsize, sentry->hsize), 1, TRUE);
|
||||
|
||||
g_free(icon_key);
|
||||
}
|
||||
|
@ -603,7 +602,7 @@ static void rofi_icon_fetcher_worker(thread_state *sdata,
|
|||
|
||||
// look for file thumbnail in appropriate folder based on requested size
|
||||
icon_path = icon_path_ = rofi_icon_fetcher_get_thumbnail(
|
||||
encoded_uri, requested_size, &thumb_size);
|
||||
encoded_uri, requested_size, &thumb_size);
|
||||
|
||||
if (!g_file_test(icon_path, G_FILE_TEST_EXISTS)) {
|
||||
// try to generate thumbnail
|
||||
|
@ -612,24 +611,24 @@ static void rofi_icon_fetcher_worker(thread_state *sdata,
|
|||
|
||||
if (mime_type) {
|
||||
gboolean created = rofi_icon_fetcher_create_thumbnail(
|
||||
mime_type, entry_name, encoded_uri, icon_path_, thumb_size);
|
||||
mime_type, entry_name, encoded_uri, icon_path_, thumb_size);
|
||||
|
||||
if (!created) {
|
||||
// replace forward slashes with minus sign to get the icon's name
|
||||
int index = 0;
|
||||
|
||||
while(mime_type[index]) {
|
||||
if(mime_type[index] == '/')
|
||||
mime_type[index] = '-';
|
||||
index++;
|
||||
while (mime_type[index]) {
|
||||
if (mime_type[index] == '/')
|
||||
mime_type[index] = '-';
|
||||
index++;
|
||||
}
|
||||
|
||||
g_free(icon_path_);
|
||||
|
||||
// try to fetch the mime-type icon
|
||||
icon_path = icon_path_ = nk_xdg_theme_get_icon(
|
||||
rofi_icon_fetcher_data->xdg_context, themes, NULL, mime_type,
|
||||
MIN(sentry->wsize, sentry->hsize), 1, TRUE);
|
||||
rofi_icon_fetcher_data->xdg_context, themes, NULL, mime_type,
|
||||
MIN(sentry->wsize, sentry->hsize), 1, TRUE);
|
||||
}
|
||||
|
||||
g_free(mime_type);
|
||||
|
|
|
@ -82,6 +82,8 @@
|
|||
char *pidfile = NULL;
|
||||
/** Location of Cache directory. */
|
||||
const char *cache_dir = NULL;
|
||||
/** if the cache_dir string is allocated, keep pointer here so it can be freed.
|
||||
*/
|
||||
char *cache_dir_alloc = NULL;
|
||||
|
||||
/** List of error messages.*/
|
||||
|
|
Loading…
Add table
Reference in a new issue