about summary refs log tree commit diff stats
path: root/src/command/cmd_funcs.c
diff options
context:
space:
mode:
authorWilliam Wennerström <william@wstrm.dev>2020-12-08 20:01:17 +0100
committerWilliam Wennerström <william@wstrm.dev>2020-12-08 20:01:17 +0100
commitd7848e38bc2d916f88e889352f337a5c617fb26d (patch)
tree11faca1055e3bd9afb12361ebdf64e0338fa3deb /src/command/cmd_funcs.c
parent7f0165a91278647e9ddb72890e58a6db6b265a5d (diff)
downloadprofani-tty-d7848e38bc2d916f88e889352f337a5c617fb26d.tar.gz
Remove scheme and filetype matching for url (save|open)
Diffstat (limited to 'src/command/cmd_funcs.c')
-rw-r--r--src/command/cmd_funcs.c98
1 files changed, 53 insertions, 45 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index d2ec46ee..fd9d2ffd 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -9135,9 +9135,9 @@ cmd_url_open(ProfWin* window, const char* const command, gchar** args)
         goto out;
     }
 
-    cmd_template = prefs_get_string_with_option(PREF_URL_OPEN_CMD, scheme);
+    cmd_template = prefs_get_string(PREF_URL_OPEN_CMD);
     if (cmd_template == NULL) {
-        cons_show("No default open command found in url open preferences");
+        cons_show("No default `url open` command found in executables preferences.");
         goto out;
     }
 
@@ -9195,20 +9195,17 @@ cmd_url_save(ProfWin* window, const char* const command, gchar** args)
         goto out;
     }
 
-    cmd_template = prefs_get_string_with_option(PREF_URL_SAVE_CMD, scheme);
-    if (cmd_template == NULL) {
-        if (g_strcmp0(scheme, "http") == 0
-            || g_strcmp0(scheme, "https") == 0) {
-            _url_http_method(window, cmd_template, url, filename);
+    cmd_template = prefs_get_string(PREF_URL_SAVE_CMD);
+    if (cmd_template == NULL && (g_strcmp0(scheme, "http") == 0 || g_strcmp0(scheme, "https") == 0)) {
+        _url_http_method(window, cmd_template, url, filename);
 #ifdef HAVE_OMEMO
-        } else if (g_strcmp0(scheme, "aesgcm") == 0) {
-            _url_aesgcm_method(window, cmd_template, url, filename);
+    } else if (g_strcmp0(scheme, "aesgcm") == 0) {
+        _url_aesgcm_method(window, cmd_template, url, filename);
 #endif
-        } else {
-            cons_show_error("No download method defined for the scheme '%s'.", scheme);
-        }
-    } else {
+    } else if (cmd_template != NULL) {
         _url_external_method(cmd_template, url, filename);
+    } else {
+        cons_show_error("No download method defined for the scheme '%s'.", scheme);
     }
 
 out:
@@ -9223,48 +9220,59 @@ out:
 }
 
 gboolean
-cmd_executable(ProfWin* window, const char* const command, gchar** args)
+cmd_executable_avatar(ProfWin* window, const char* const command, gchar** args)
 {
-    guint num_args = g_strv_length(args);
-
-    if (g_strcmp0(args[0], "avatar") == 0) {
-        prefs_set_string(PREF_AVATAR_CMD, args[1]);
-        cons_show("Avatar command set to: %s", args[1]);
+    prefs_set_string(PREF_AVATAR_CMD, args[1]);
+    cons_show("`avatar` command set to invoke '%s'", args[1]);
+    return TRUE;
+}
 
-    } else if (g_strcmp0(args[0], "urlopen") == 0) {
-        if (num_args < 4) {
-            cons_bad_cmd_usage(command);
-            return TRUE;
-        }
+gboolean
+cmd_executable_urlopen(ProfWin* window, const char* const command, gchar** args)
+{
+    guint num_args = g_strv_length(args);
+    if (num_args < 2) {
+        cons_bad_cmd_usage(command);
+        return TRUE;
+    }
 
-        gchar* str = g_strjoinv(" ", &args[3]);
-        const gchar* const list[] = { args[2], str, NULL };
-        prefs_set_string_list_with_option(PREF_URL_OPEN_CMD, args[1], list);
-        cons_show("`url open` command set to: %s for %s files", str, args[1]);
+    if (g_strcmp0(args[1], "set") == 0 && num_args >= 3) {
+        gchar* str = g_strjoinv(" ", &args[2]);
+        prefs_set_string(PREF_URL_OPEN_CMD, str);
+        cons_show("`url open` command set to invoke '%s'", str);
         g_free(str);
 
-    } else if (g_strcmp0(args[0], "urlsave") == 0) {
+    } else if (g_strcmp0(args[1], "default") == 0) {
+        prefs_set_string(PREF_URL_SAVE_CMD, NULL);
+        gchar* def = prefs_get_string(PREF_URL_SAVE_CMD);
+        cons_show("`url open` command set to invoke %s (default)", def);
+        g_free(def);
+    } else {
+        cons_bad_cmd_usage(command);
+    }
 
-        if (num_args < 3) {
-            cons_bad_cmd_usage(command);
-            return TRUE;
-        }
+    return TRUE;
+}
 
-        if (g_strcmp0(args[1], "set") == 0 && num_args >= 4) {
-            gchar* str = g_strjoinv(" ", &args[3]);
-            prefs_set_string_with_option(PREF_URL_SAVE_CMD, args[2], str);
-            cons_show("`url save` command set to: %s for scheme %s", str, args[2]);
-            g_free(str);
+gboolean
+cmd_executable_urlsave(ProfWin* window, const char* const command, gchar** args)
+{
 
-        } else if (g_strcmp0(args[1], "clear") == 0) {
-            prefs_set_string_with_option(PREF_URL_SAVE_CMD, args[2], NULL);
-            cons_show("`url save` will use internal download method for scheme %s", args[2]);
+    guint num_args = g_strv_length(args);
+    if (num_args < 2) {
+        cons_bad_cmd_usage(command);
+        return TRUE;
+    }
 
-        } else {
-            cons_bad_cmd_usage(command);
-            return TRUE;
-        }
+    if (g_strcmp0(args[1], "set") == 0 && num_args >= 3) {
+        gchar* str = g_strjoinv(" ", &args[2]);
+        prefs_set_string(PREF_URL_SAVE_CMD, str);
+        cons_show("`url save` command set to invoke '%s'", str);
+        g_free(str);
 
+    } else if (g_strcmp0(args[1], "default") == 0) {
+        prefs_set_string(PREF_URL_SAVE_CMD, NULL);
+        cons_show("`url save` will use built-in download method (default)");
     } else {
         cons_bad_cmd_usage(command);
     }
s revision' href='/akspecs/ranger/blame/doc/ranger.gui.defaultui.html?h=v1.4.2&id=4e01caf19cfbc798862e6b8b2dbd77328c8f99a2'>^
4c13e1f2 ^











f07bb12f ^
4c13e1f2 ^
f07bb12f ^









1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179