diff options
author | Sebastian Reuße <seb@wirrsal.net> | 2018-04-25 16:43:16 +0200 |
---|---|---|
committer | Sebastian Reuße <seb@wirrsal.net> | 2018-04-25 16:57:27 +0200 |
commit | 7716c3003bf23d95c0ea42b5960404d2696050bd (patch) | |
tree | 6ac4641e38874f3a9ab83213ff56728dbeca46a0 /dragon.c | |
parent | Bump version to 1.0.0 (diff) | |
download | dragon-7716c3003bf23d95c0ea42b5960404d2696050bd.tar.gz dragon-7716c3003bf23d95c0ea42b5960404d2696050bd.tar.bz2 dragon-7716c3003bf23d95c0ea42b5960404d2696050bd.zip |
Let GIO handle URI building
Fixes #1, #2.
Diffstat (limited to 'dragon.c')
-rw-r--r-- | dragon.c | 26 |
1 files changed, 11 insertions, 15 deletions
@@ -136,15 +136,18 @@ GtkButton *add_button(char *label, struct draggable_thing *dragdata, int type) { return (GtkButton *)button; } -void add_file_button(char *ufilename, char *filename) { - char *uri = malloc(strlen(filename) + 8); // file:// + NULL - strcpy(uri, "file://"); - strcat(uri, filename); +void add_file_button(char *filename) { + GFile *file = g_file_new_for_path(filename); + if(!g_file_query_exists(file, NULL)) { + fprintf(stderr, "The file `%s' does not exist.\n", + filename); + exit(1); + } + char *uri = g_file_get_uri(file); struct draggable_thing *dragdata = malloc(sizeof(struct draggable_thing)); dragdata->text = filename; dragdata->uri = uri; - GtkButton *button = add_button(ufilename, dragdata, TARGET_TYPE_URI); - GFile *file = g_file_new_for_path(filename); + GtkButton *button = add_button(filename, dragdata, TARGET_TYPE_URI); GFileInfo *fileinfo = g_file_query_info(file, "*", 0, NULL, NULL); GIcon *icon = g_file_info_get_icon(fileinfo); GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon(icon_theme, @@ -256,7 +259,6 @@ void target_mode() { int main (int argc, char **argv) { progname = argv[0]; char *filename = NULL; - char *ufilename = NULL; for (int i=1; i<argc; i++) { if (strcmp(argv[i], "--help") == 0) { mode = MODE_HELP; @@ -337,15 +339,9 @@ int main (int argc, char **argv) { bool had_filename = false; for (int i=1; i<argc; i++) { if (argv[i][0] != '-') { - filename = ufilename = argv[i]; + filename = argv[i]; if (!is_uri(filename)) { - filename = realpath(filename, NULL); - if (!filename) { - fprintf(stderr, "The file `%s' does not exist.\n", - ufilename); - exit(1); - } - add_file_button(ufilename, filename); + add_file_button(filename); } else { add_uri_button(filename); } |