changeset a482e3eb7586 in /home/hg/repos/gajim-plugins
author: tmolitor thilo@eightysoft.de branches: details:gajim-plugins?cmd=changeset;node=a482e3eb7586 description: Added ability to configure left click action
diffstat:
url_image_preview/config_dialog.ui | 64 ++++++++++++++++++++++- url_image_preview/context_menu.ui | 22 ++++++++ url_image_preview/url_image_preview.py | 93 +++++++++++++++++++++++++++------ 3 files changed, 159 insertions(+), 20 deletions(-)
diffs (truncated from 328 to 300 lines):
diff -r 0f55bb188e18 -r a482e3eb7586 url_image_preview/config_dialog.ui --- a/url_image_preview/config_dialog.ui Thu Sep 08 14:54:12 2016 +0200 +++ b/url_image_preview/config_dialog.ui Thu Sep 08 18:10:59 2016 +0200 @@ -25,6 +25,29 @@ </row> </data> </object> + <object class="GtkListStore" id="liststore2"> + <columns> + <!-- column-name Text --> + <column type="gchararray"/> + </columns> + <data> + <row> + <col id="0" translatable="yes">Open</col> + </row> + <row> + <col id="0" translatable="yes">Save as</col> + </row> + <row> + <col id="0" translatable="yes">Copy Link Location</col> + </row> + <row> + <col id="0" translatable="yes">Open Link in Browser</col> + </row> + <row> + <col id="0" translatable="yes">Open Downloaded File in Browser</col> + </row> + </data> + </object> <object class="GtkWindow" id="window1"> <property name="can_focus">False</property> <child> @@ -42,7 +65,7 @@ <object class="GtkTable" id="table1"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="n_rows">2</property> + <property name="n_rows">3</property> <property name="n_columns">2</property> <child> <object class="GtkSpinButton" id="preview_size"> @@ -86,6 +109,27 @@ </packing> </child> <child> + <object class="GtkComboBox" id="leftclick_action_combobox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="model">liststore2</property> + <signal name="changed" handler="leftclick_action_changed" swapped="no"/> + <child> + <object class="GtkCellRendererText" id="cellrenderertext2"/> + <attributes> + <attribute name="text">0</attribute> + </attributes> + </child> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="y_options">GTK_EXPAND</property> + </packing> + </child> + <child> <object class="GtkLabel" id="max_size_label"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -113,6 +157,22 @@ <property name="y_options">GTK_EXPAND</property> </packing> </child> + <child> + <object class="GtkLabel" id="leftclick_action_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="xpad">12</property> + <property name="label" translatable="yes">Left click action</property> + <property name="track_visited_links">False</property> + </object> + <packing> + <property name="y_options">GTK_EXPAND</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="y_options">GTK_EXPAND</property> + </packing> + </child> </object> </child> </object> @@ -126,4 +186,4 @@ </object> </child> </object> -</interface> +</interface> \ No newline at end of file diff -r 0f55bb188e18 -r a482e3eb7586 url_image_preview/context_menu.ui --- a/url_image_preview/context_menu.ui Thu Sep 08 14:54:12 2016 +0200 +++ b/url_image_preview/context_menu.ui Thu Sep 08 18:10:59 2016 +0200 @@ -22,6 +22,11 @@ <property name="can_focus">False</property> <property name="stock">gtk-jump-to</property> </object> + <object class="GtkImage" id="image5"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="stock">gtk-jump-to</property> + </object> <object class="GtkMenu" id="context_menu"> <property name="can_focus">False</property> <child> @@ -74,5 +79,22 @@ <property name="always_show_image">True</property> </object> </child> + <child> + <object class="GtkSeparatorMenuItem" id="extras_separator"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + </child> + <child> + <object class="GtkImageMenuItem" id="open_file_in_browser_menuitem"> + <property name="label" translatable="yes">Open _Downloaded File in Browser</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_underline">True</property> + <property name="image">image5</property> + <property name="use_stock">False</property> + <property name="always_show_image">True</property> + </object> + </child> </object> </interface> diff -r 0f55bb188e18 -r a482e3eb7586 url_image_preview/url_image_preview.py --- a/url_image_preview/url_image_preview.py Thu Sep 08 14:54:12 2016 +0200 +++ b/url_image_preview/url_image_preview.py Thu Sep 08 18:10:59 2016 +0200 @@ -9,6 +9,7 @@ from urlparse import urlparse from io import BytesIO import shutil +import webbrowser
import logging import nbxmpp @@ -70,7 +71,8 @@ 'print_special_text': (self.print_special_text, None), } self.config_default_values = { 'PREVIEW_SIZE': (150, 'Preview size(10-512)'), - 'MAX_FILE_SIZE': (524288, 'Max file size for image preview')} + 'MAX_FILE_SIZE': (524288, 'Max file size for image preview'), + 'LEFTCLICK_ACTION': ('open_menuitem', 'Open')} self.controls = {}
# remove oob tag if oob url == message text @@ -445,8 +447,7 @@ gtk.gdk.INTERP_BILINEAR) return (crop_pixbuf, image_width, image_height)
- def make_rightclick_menu(self, event, filepath, original_filename, - url, encrypted): + def make_rightclick_menu(self, event, data): xml = gtk.Builder() xml.set_translation_domain('gajim_plugins') xml.add_from_file(self.plugin.local_file_path('context_menu.ui')) @@ -458,30 +459,37 @@ xml.get_object('copy_link_location_menuitem') open_link_in_browser_menuitem = \ xml.get_object('open_link_in_browser_menuitem') + open_file_in_browser_menuitem = \ + xml.get_object('open_file_in_browser_menuitem')
- if encrypted: + if data["encrypted"]: open_link_in_browser_menuitem.hide()
id_ = open_menuitem.connect( - 'activate', self.on_open_menuitem_activate, filepath) + 'activate', self.on_open_menuitem_activate, data) self.handlers[id_] = open_menuitem id_ = save_as_menuitem.connect( - 'activate', self.on_save_as_menuitem_activate, - filepath, original_filename) + 'activate', self.on_save_as_menuitem_activate, data) self.handlers[id_] = save_as_menuitem id_ = copy_link_location_menuitem.connect( - 'activate', self.on_copy_link_location_menuitem_activate, url) + 'activate', self.on_copy_link_location_menuitem_activate, data) self.handlers[id_] = copy_link_location_menuitem id_ = open_link_in_browser_menuitem.connect( - 'activate', self.on_open_link_in_browser_menuitem_activate, url) + 'activate', self.on_open_link_in_browser_menuitem_activate, data) self.handlers[id_] = open_link_in_browser_menuitem + id_ = open_file_in_browser_menuitem.connect( + 'activate', self.on_open_file_in_browser_menuitem_activate, data) + self.handlers[id_] = open_file_in_browser_menuitem
return menu
- def on_open_menuitem_activate(self, menu, filepath): + def on_open_menuitem_activate(self, menu, data): + filepath = data["filepath"] helpers.launch_file_manager(filepath)
- def on_save_as_menuitem_activate(self, menu, filepath, original_filename): + def on_save_as_menuitem_activate(self, menu, data): + filepath = data["filepath"] + original_filename = data["original_filename"] def on_continue(response, target_path): if response < 0: return @@ -533,12 +541,37 @@ dialog.connect('delete-event', lambda widget, event: on_cancel(widget))
- def on_copy_link_location_menuitem_activate(self, menu, url): + def on_copy_link_location_menuitem_activate(self, menu, data): + url = data["url"] clipboard = gtk.Clipboard() clipboard.set_text(url)
- def on_open_link_in_browser_menuitem_activate(self, menu, url): - helpers.launch_browser_mailer('url', url) + def on_open_link_in_browser_menuitem_activate(self, menu, data): + url = data["url"] + if data["encrypted"]: + dialogs.ErrorDialog( + _('Encrypted file'), + _('You cannot open encrypted files in your ' + 'browser directly. Try "Open Downloaded File ' + 'in Browser" instead.'), + transient_for=self.chat_control.parent_win.window) + else: + helpers.launch_browser_mailer('url', url) + + def on_open_file_in_browser_menuitem_activate(self, menu, data): + filepath = "file://" + data["filepath"] + if not gajim.config.get('autodetect_browser_mailer'): + command = gajim.config.get('custombrowser') + if command == '': # if no app is configured + return + command = helpers.build_command(command, filepath) + try: + helpers.exec_command(command) + except Exception: + pass + else: + log.error(filepath) + webbrowser.open(filepath)
# Change mouse pointer to HAND2 when # mouse enter the eventbox with the image @@ -553,13 +586,18 @@
def on_button_press_event(self, eb, event, filepath, original_filename, url, encrypted): + data = {"filepath": filepath, + "original_filename": original_filename, + "url": url, + "encrypted": encrypted} # left click if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1: - helpers.launch_file_manager(filepath) + method = getattr(self, "on_" + self.plugin.config['LEFTCLICK_ACTION'] + + "_activate") + method(event, data) # right klick elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: - menu = self.make_rightclick_menu(event, filepath, - original_filename, url, encrypted) + menu = self.make_rightclick_menu(event, data) # menu.attach_to_widget(self.tv, None) menu.popup(None, None, None, event.button, event.time)
@@ -569,6 +607,8 @@
class UrlImagePreviewPluginConfigDialog(GajimPluginConfigDialog): max_file_size = [262144, 524288, 1048576, 5242880, 10485760] + leftclick_action = ['open_menuitem', 'save_as_menuitem', 'copy_link_location_menuitem', + 'open_link_in_browser_menuitem', 'open_file_in_browser_menuitem']
def init(self): self.GTK_BUILDER_FILE_PATH = self.plugin.local_file_path( @@ -576,11 +616,12 @@ self.xml = gtk.Builder() self.xml.set_translation_domain('gajim_plugins') self.xml.add_objects_from_file(self.GTK_BUILDER_FILE_PATH, [ - 'vbox1', 'liststore1']) + 'vbox1', 'liststore1', 'liststore2']) self.preview_size_spinbutton = self.xml.get_object('preview_size') self.preview_size_spinbutton.get_adjustment().set_all(20, 10, 512, 1, 10, 0) self.max_size_combobox = self.xml.get_object('max_size_combobox') + self.leftclick_action_combobox = self.xml.get_object('leftclick_action_combobox') vbox = self.xml.get_object('vbox1') self.child.pack_start(vbox)