Skip to content

Commit

Permalink
torrent upload file chooser (TheKevJames#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkunz committed Nov 29, 2018
1 parent 7998497 commit da06033
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
49 changes: 36 additions & 13 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -1312,20 +1312,24 @@ const TorrentsControls = new Lang.Class({
this.ctrl_btns.add_actor(button.actor);
}
this.actor.show();
button.actor.connect('notify::hover', Lang.bind(this, function(btn) {
this.hover = btn.hover;
if (this.hover) {
if (btn._delegate._info != this.ctrl_info.text) {
this._old_info = this.ctrl_info.text;
}
this.ctrl_info.text = btn._delegate._info;
} else {
this.ctrl_info.text = this._old_info;
}
}));
this.connectHoverInfo(button);
}
},

connectHoverInfo: function(button) {
button.actor.connect('notify::hover', Lang.bind(this, function(btn) {
this.hover = btn.hover;
if (this.hover) {
if (btn._delegate._info != this.ctrl_info.text) {
this._old_info = this.ctrl_info.text;
}
this.ctrl_info.text = btn._delegate._info;
} else {
this.ctrl_info.text = this._old_info;
}
}));
},

removeControl: function(button, name) {
let button_actor = button;
if (button instanceof ControlButton) {
Expand Down Expand Up @@ -1364,10 +1368,17 @@ const TorrentsTopControls = new Lang.Class({
hint_text: _("Torrent URL or Magnet link"),
can_focus: true,
});
this.add_btn = new ControlButton("object-select", "",
Lang.bind(this, this.torrentAdd));
this.upload_btn = new ControlButton("system-file-manager",
_('choose torrent file to upload'),
Lang.bind(this, this.torrentChooseFileToUpload));
this.connectHoverInfo(this.upload_btn);
this.add_btn = new ControlButton("object-select",
_('add torrent from link in text field'),
Lang.bind(this, this.torrentAdd));
this.connectHoverInfo(this.add_btn);
this.add_box.hide();

this.add_box.add(this.upload_btn.actor);
this.add_box.add(this.add_entry, { expand: true, });
this.add_box.add(this.add_btn.actor);

Expand Down Expand Up @@ -1399,6 +1410,18 @@ const TorrentsTopControls = new Lang.Class({
this.add_box.hide();
},

torrentChooseFileToUpload: function() {
var filechooser = new Gtk.FileChooserDialog({
title: _('choose torrent file to upload'),
});
filechooser.add_button(Gtk.STOCK_OPEN, 1);
filechooser.set_default_response(1);
if (filechooser.run() == 1) {
this.add_entry.text = filechooser.get_filenames();
}
filechooser.destroy();
},

torrentAdd: function() {
let url = this.add_entry.text;
if (url.match(/^http/) || url.match(/^magnet:/)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ msgstr ""
msgid "days"
msgstr ""

#: extension.js:1372
msgid "choose torrent file to upload"
msgstr ""

#: extension.js:1376
msgid "add torrent from link in text field"
msgstr ""

#: extension.js:1596
msgid "day"
msgstr ""
Expand Down

3 comments on commit da06033

@philippkunz
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dec 2 10:48:34 test gnome-shell[690]: cannot register existing type 'GtkActionMuxer'
Dec 2 10:48:34 test gnome-shell[690]: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed
Dec 2 10:48:34 test gnome-shell[690]: cannot register existing type 'GtkActionObservable'
Dec 2 10:48:34 test gnome-shell[690]: g_type_interface_add_prerequisite: assertion 'G_TYPE_IS_INTERFACE (interface_type)' failed
Dec 2 10:48:34 test gnome-shell[690]: g_once_init_leave: assertion 'result != 0' failed
Dec 2 10:48:34 test gnome-shell[690]: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed
Dec 2 10:48:34 test gnome-shell[690]: g_once_init_leave: assertion 'result != 0' failed
Dec 2 10:48:34 test gnome-shell[690]: g_object_new: assertion 'G_TYPE_IS_OBJECT (object_type)' failed
Dec 2 10:48:34 test kernel: [ 111.163607] gnome-shell[690]: segfault at 20 ip 00007feb898e43d7 sp 00007ffe9725d860 error 4 in libgtk-3.so.0.2200.11[7feb897ed000+700000]
Dec 2 10:48:34 test gnome-session[575]: gnome-session-binary[575]: WARNING: Application 'org.gnome.Shell.desktop' killed by signal 11

@philippkunz
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philippkunz
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.