Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gajim-plugins
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
56
Issues
56
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gajim
gajim-plugins
Commits
e52ab4c6
Commit
e52ab4c6
authored
Nov 01, 2017
by
Philipp Hörist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[preview] New Config Dialog
parent
377c9fc9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
250 deletions
+117
-250
url_image_preview/config_dialog.py
url_image_preview/config_dialog.py
+114
-0
url_image_preview/config_dialog.ui
url_image_preview/config_dialog.ui
+0
-188
url_image_preview/url_image_preview.py
url_image_preview/url_image_preview.py
+3
-62
No files found.
url_image_preview/config_dialog.py
0 → 100644
View file @
e52ab4c6
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017 Philipp Hörist <philipp AT hoerist.com>
#
# This file is part of Gajim.
#
# Gajim is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Gajim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
from
gi.repository
import
GObject
from
gi.repository
import
Gtk
from
gajim.options_dialog
import
OptionsDialog
,
GenericOption
,
SpinOption
from
gajim.common.const
import
Option
,
OptionType
class
UrlImagePreviewConfigDialog
(
OptionsDialog
):
def
__init__
(
self
,
plugin
,
parent
):
sizes
=
[(
'256 KiB'
,
'262144'
),
(
'512 KiB'
,
'524288'
),
(
'1 MiB'
,
'1048576'
),
(
'5 MiB'
,
'5242880'
),
(
'10 MiB'
,
'10485760'
)]
actions
=
[
(
_
(
'Open'
),
'open_menuitem'
),
(
_
(
'Save as'
),
'save_as_menuitem'
),
(
_
(
'Copy Link Location'
),
'copy_link_location_menuitem'
),
(
_
(
'Open Link in Browser'
),
'open_link_in_browser_menuitem'
),
(
_
(
'Open File in Browser'
),
'open_file_in_browser_menuitem'
)]
self
.
plugin
=
plugin
options
=
[
Option
(
'PreviewSizeSpinOption'
,
_
(
'Preview size'
),
OptionType
.
VALUE
,
self
.
plugin
.
config
[
'PREVIEW_SIZE'
],
callback
=
self
.
on_option
,
data
=
'PREVIEW_SIZE'
,
props
=
{
'range_'
:
(
100
,
1000
)}),
Option
(
'PreviewComboOption'
,
_
(
'Accepted filesize'
),
OptionType
.
VALUE
,
self
.
plugin
.
config
[
'MAX_FILE_SIZE'
],
callback
=
self
.
on_option
,
data
=
'MAX_FILE_SIZE'
,
props
=
{
'items'
:
sizes
,
'plugin'
:
self
.
plugin
}),
Option
(
'PreviewComboOption'
,
_
(
'Left click action'
),
OptionType
.
VALUE
,
self
.
plugin
.
config
[
'LEFTCLICK_ACTION'
],
callback
=
self
.
on_option
,
data
=
'LEFTCLICK_ACTION'
,
props
=
{
'items'
:
actions
,
'plugin'
:
self
.
plugin
}),
]
OptionsDialog
.
__init__
(
self
,
parent
,
_
(
'UrlImagePreview Options'
),
Gtk
.
DialogFlags
.
MODAL
,
options
,
None
,
extend
=
[
(
'PreviewComboOption'
,
ComboOption
),
(
'PreviewSizeSpinOption'
,
SizeSpinOption
)])
def
on_option
(
self
,
value
,
data
):
self
.
plugin
.
config
[
data
]
=
value
class
SizeSpinOption
(
SpinOption
):
__gproperties__
=
{
"option-value"
:
(
int
,
'Size'
,
''
,
100
,
1000
,
300
,
GObject
.
ParamFlags
.
READWRITE
),
}
def
__init__
(
self
,
*
args
,
**
kwargs
):
SpinOption
.
__init__
(
self
,
*
args
,
**
kwargs
)
class
ComboOption
(
GenericOption
):
__gproperties__
=
{
"option-value"
:
(
str
,
'Value'
,
''
,
''
,
GObject
.
ParamFlags
.
READWRITE
),
}
def
__init__
(
self
,
*
args
,
items
,
plugin
):
GenericOption
.
__init__
(
self
,
*
args
)
self
.
plugin
=
plugin
self
.
combo
=
Gtk
.
ComboBox
()
text_renderer
=
Gtk
.
CellRendererText
()
self
.
combo
.
pack_start
(
text_renderer
,
True
)
self
.
combo
.
add_attribute
(
text_renderer
,
'text'
,
0
)
self
.
store
=
Gtk
.
ListStore
(
str
,
str
)
for
item
in
items
:
self
.
store
.
append
(
item
)
self
.
combo
.
set_model
(
self
.
store
)
self
.
combo
.
set_id_column
(
1
)
self
.
combo
.
set_active_id
(
str
(
self
.
option_value
))
self
.
combo
.
connect
(
'changed'
,
self
.
on_value_change
)
self
.
combo
.
set_valign
(
Gtk
.
Align
.
CENTER
)
self
.
option_box
.
pack_start
(
self
.
combo
,
True
,
True
,
0
)
self
.
show_all
()
def
on_value_change
(
self
,
combo
):
self
.
set_value
(
combo
.
get_active_id
())
def
on_row_activated
(
self
):
pass
url_image_preview/config_dialog.ui
deleted
100644 → 0
View file @
377c9fc9
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires
lib=
"gtk+"
version=
"3.0"
/>
<object
class=
"GtkListStore"
id=
"liststore1"
>
<columns>
<!-- column-name Text -->
<column
type=
"gchararray"
/>
</columns>
<data>
<row>
<col
id=
"0"
translatable=
"yes"
>
256 KiB
</col>
</row>
<row>
<col
id=
"0"
translatable=
"yes"
>
512 KiB
</col>
</row>
<row>
<col
id=
"0"
translatable=
"yes"
>
1 MiB
</col>
</row>
<row>
<col
id=
"0"
translatable=
"yes"
>
5 MiB
</col>
</row>
<row>
<col
id=
"0"
translatable=
"yes"
>
10 MiB
</col>
</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>
<object
class=
"GtkVBox"
id=
"vbox1"
>
<property
name=
"visible"
>
True
</property>
<property
name=
"can_focus"
>
False
</property>
<property
name=
"border_width"
>
9
</property>
<child>
<object
class=
"GtkFrame"
id=
"frame1"
>
<property
name=
"visible"
>
True
</property>
<property
name=
"can_focus"
>
False
</property>
<property
name=
"label_xalign"
>
0
</property>
<property
name=
"shadow_type"
>
none
</property>
<child>
<object
class=
"GtkTable"
id=
"table1"
>
<property
name=
"visible"
>
True
</property>
<property
name=
"can_focus"
>
False
</property>
<property
name=
"n_rows"
>
3
</property>
<property
name=
"n_columns"
>
2
</property>
<child>
<object
class=
"GtkSpinButton"
id=
"preview_size"
>
<property
name=
"visible"
>
True
</property>
<property
name=
"can_focus"
>
True
</property>
<property
name=
"invisible_char"
>
●
</property>
<property
name=
"width_chars"
>
6
</property>
<property
name=
"primary_icon_activatable"
>
False
</property>
<property
name=
"secondary_icon_activatable"
>
False
</property>
<property
name=
"primary_icon_sensitive"
>
True
</property>
<property
name=
"secondary_icon_sensitive"
>
True
</property>
<property
name=
"snap_to_ticks"
>
True
</property>
<property
name=
"numeric"
>
True
</property>
<signal
name=
"value-changed"
handler=
"preview_size_value_changed"
swapped=
"no"
/>
</object>
<packing>
<property
name=
"left_attach"
>
1
</property>
<property
name=
"right_attach"
>
2
</property>
<property
name=
"y_options"
/>
</packing>
</child>
<child>
<object
class=
"GtkComboBox"
id=
"max_size_combobox"
>
<property
name=
"visible"
>
True
</property>
<property
name=
"can_focus"
>
False
</property>
<property
name=
"model"
>
liststore1
</property>
<signal
name=
"changed"
handler=
"max_size_value_changed"
swapped=
"no"
/>
<child>
<object
class=
"GtkCellRendererText"
id=
"cellrenderertext1"
/>
<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"
>
1
</property>
<property
name=
"bottom_attach"
>
2
</property>
<property
name=
"y_options"
>
GTK_EXPAND
</property>
</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>
<property
name=
"xalign"
>
0
</property>
<property
name=
"xpad"
>
13
</property>
<property
name=
"label"
translatable=
"yes"
>
Accept files smaller then
</property>
<property
name=
"track_visited_links"
>
False
</property>
</object>
<packing>
<property
name=
"top_attach"
>
1
</property>
<property
name=
"bottom_attach"
>
2
</property>
<property
name=
"y_options"
>
GTK_EXPAND
</property>
</packing>
</child>
<child>
<object
class=
"GtkLabel"
id=
"preview_size_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"
>
Preview size
</property>
<property
name=
"track_visited_links"
>
False
</property>
</object>
<packing>
<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>
<packing>
<property
name=
"expand"
>
True
</property>
<property
name=
"fill"
>
True
</property>
<property
name=
"padding"
>
6
</property>
<property
name=
"position"
>
0
</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
url_image_preview/url_image_preview.py
View file @
e52ab4c6
...
...
@@ -22,6 +22,7 @@ import binascii
from
urllib.parse
import
urlparse
from
io
import
BytesIO
import
shutil
from
functools
import
partial
import
logging
import
nbxmpp
...
...
@@ -35,6 +36,7 @@ from gajim.plugins.helpers import log_calls
from
gajim.plugins.gui
import
GajimPluginConfigDialog
from
gajim.conversation_textview
import
TextViewImage
from
.http_functions
import
get_http_head
,
get_http_file
from
.config_dialog
import
UrlImagePreviewConfigDialog
log
=
logging
.
getLogger
(
'gajim.plugin_system.url_image_preview'
)
...
...
@@ -68,7 +70,7 @@ class UrlImagePreviewPlugin(GajimPlugin):
def
init
(
self
):
if
not
decryption_available
:
self
.
available_text
=
DEP_MSG
self
.
config_dialog
=
UrlImagePreviewPluginConfigDialog
(
self
)
self
.
config_dialog
=
partial
(
UrlImagePreviewConfigDialog
,
self
)
self
.
events_handlers
=
{}
self
.
events_handlers
[
'message-received'
]
=
(
ged
.
PRECORE
,
self
.
handle_message_received
)
...
...
@@ -626,64 +628,3 @@ class Base(object):
def
disconnect_from_chat_control
(
self
):
pass
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
(
'config_dialog.ui'
)
self
.
xml
=
Gtk
.
Builder
()
self
.
xml
.
set_translation_domain
(
'gajim_plugins'
)
self
.
xml
.
add_objects_from_file
(
self
.
GTK_BUILDER_FILE_PATH
,
[
'vbox1'
,
'liststore1'
,
'liststore2'
])
self
.
preview_size_spinbutton
=
self
.
xml
.
get_object
(
'preview_size'
)
self
.
preview_size_spinbutton
.
get_adjustment
().
configure
(
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
.
get_child
().
pack_start
(
vbox
,
True
,
True
,
0
)
self
.
xml
.
connect_signals
(
self
)
def
on_run
(
self
):
self
.
preview_size_spinbutton
.
set_value
(
self
.
plugin
.
config
[
'PREVIEW_SIZE'
])
value
=
self
.
plugin
.
config
[
'MAX_FILE_SIZE'
]
if
value
:
# this fails if we upgrade from an old version
# which has other file size values than we have now
try
:
self
.
max_size_combobox
.
set_active
(
self
.
max_file_size
.
index
(
value
))
except
:
pass
else
:
self
.
max_size_combobox
.
set_active
(
-
1
)
value
=
self
.
plugin
.
config
[
'LEFTCLICK_ACTION'
]
if
value
:
# this fails if we upgrade from an old version
# which has other file size values than we have now
try
:
self
.
leftclick_action_combobox
.
set_active
(
self
.
leftclick_action
.
index
(
value
))
except
:
pass
else
:
self
.
leftclick_action_combobox
.
set_active
(
0
)
def
preview_size_value_changed
(
self
,
spinbutton
):
self
.
plugin
.
config
[
'PREVIEW_SIZE'
]
=
spinbutton
.
get_value
()
def
max_size_value_changed
(
self
,
widget
):
self
.
plugin
.
config
[
'MAX_FILE_SIZE'
]
=
self
.
max_file_size
[
self
.
max_size_combobox
.
get_active
()]
def
leftclick_action_changed
(
self
,
widget
):
self
.
plugin
.
config
[
'LEFTCLICK_ACTION'
]
=
self
.
leftclick_action
[
self
.
leftclick_action_combobox
.
get_active
()]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment