Codebase list midori / 1929c51
new extension to download a file with a specified command André Stösel authored 11 years ago Christian Dywan committed 11 years ago
1 changed file(s) with 95 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
205205 this.deactivate.connect (deactivated);
206206 }
207207 }
208
209 private class CommandLinePreferences : Dialog {
210 protected Entry input;
211 protected CommandLine commandline;
212
213 public CommandLinePreferences(CommandLine cl) {
214 this.commandline = cl;
215
216 string ext_name;
217 this.get ("name",out ext_name);
218
219 this.title = _("Preferences for %s").printf (ext_name);
220 if (this.get_class ().find_property ("has-separator") != null)
221 this.set ("has-separator", false);
222 this.border_width = 5;
223 this.set_modal (true);
224 this.set_default_size (400, 100);
225 this.create_widgets ();
226
227 this.response.connect (response_cb);
228 }
229
230 private void response_cb (Dialog source, int response_id) {
231 switch (response_id) {
232 case ResponseType.APPLY:
233 this.commandline.set_string ("commandline", this.input.get_text ());
234 this.destroy ();
235 break;
236 case ResponseType.CANCEL:
237 this.destroy ();
238 break;
239 }
240 }
241
242 private void create_widgets () {
243 Label text = new Label ("%s:".printf (_("Command")));
244 this.input = new Entry ();
245 this.input.set_text (this.commandline.get_string ("commandline"));
246
247
248 #if HAVE_GTK3
249 Gtk.Box vbox = get_content_area () as Gtk.Box;
250 vbox.pack_start (text, false, false, 0);
251 vbox.pack_start (this.input, false, true, 0);
252 #else
253 this.vbox.pack_start (text, false, false, 0);
254 this.vbox.pack_start (this.input, false, true, 0);
255 #endif
256
257 this.add_button (Gtk.STOCK_CANCEL, ResponseType.CANCEL);
258 this.add_button (Gtk.STOCK_APPLY, ResponseType.APPLY);
259
260 this.show_all ();
261 }
262 }
263
264 private class CommandLine : ExternalDownloadManager {
265 private void show_preferences () {
266 CommandLinePreferences dialog = new CommandLinePreferences (this);
267 dialog.show ();
268 }
269
270 public override bool download (DownloadRequest dlReq) {
271 try {
272 string cmd = this.get_string ("commandline");
273 cmd = cmd.replace("{REFERER}", GLib.Shell.quote (dlReq.referer));
274 if (dlReq.cookie_header != null) {
275 cmd = cmd.replace("{COOKIES}", GLib.Shell.quote ("Cookie: " + dlReq.cookie_header));
276 } else {
277 cmd = cmd.replace("{COOKIES}", "\'\'");
278 }
279 cmd = cmd.replace("{URL}", GLib.Shell.quote (dlReq.uri));
280 GLib.Process.spawn_command_line_async (cmd);
281 return true;
282 } catch (Error e) {
283 this.handle_exception (e);
284 }
285 return false;
286 }
287
288 internal CommandLine () {
289 GLib.Object (name: _("External Download Manager - CommandLine"),
290 description: _("Download files with a specified command"),
291 version: "0.1" + Midori.VERSION_SUFFIX,
292 authors: "André Stösel <andre@stoesel.de>",
293 key: "commandline");
294
295 this.install_string ("commandline", "wget --no-check-certificate --referer={REFERER} --header={COOKIES} {URL}");
296
297 this.activate.connect (activated);
298 this.deactivate.connect (deactivated);
299 this.open_preferences.connect (show_preferences);
300 }
301 }
208302 }
209303
210304 public Katze.Array extension_init () {
213307 var extensions = new Katze.Array( typeof (Midori.Extension));
214308 extensions.add_item (new EDM.Aria2 ());
215309 extensions.add_item (new EDM.SteadyFlow ());
310 extensions.add_item (new EDM.CommandLine ());
216311 return extensions;
217312 }
218313