Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mesonium
gajim
Commits
999f6e9b
Commit
999f6e9b
authored
4 years ago
by
Daniel Brötzmann
Committed by
Philipp Hörist
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
AvatarSelector: Improve error handling
Enable loading images <100px and add multiple fail-safes
parent
023e45fe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gajim/gtk/avatar_selector.py
+14
-6
14 additions, 6 deletions
gajim/gtk/avatar_selector.py
gajim/gtk/profile.py
+7
-2
7 additions, 2 deletions
gajim/gtk/profile.py
with
21 additions
and
8 deletions
gajim/gtk/avatar_selector.py
+
14
−
6
View file @
999f6e9b
...
...
@@ -77,7 +77,6 @@ def __init__(self):
self
.
_crop_area
=
CropArea
()
self
.
_crop_area
.
set_vexpand
(
True
)
# self._crop_area.set_min_size(200, 200)
self
.
add
(
self
.
_crop_area
)
self
.
_helper_label
=
Gtk
.
Label
(
...
...
@@ -145,7 +144,7 @@ def get_avatar_surface(self):
def
get_avatar_bytes
(
self
):
pixbuf
=
self
.
_crop_area
.
get_pixbuf
()
if
pixbuf
is
None
:
return
None
return
False
,
None
,
0
,
0
scaled
,
width
,
height
=
self
.
_scale_for_publish
(
pixbuf
)
success
,
data
=
scaled
.
save_to_bufferv
(
'
png
'
,
[],
[])
...
...
@@ -176,8 +175,8 @@ def __init__(self):
self
.
_active_region
=
Loc
.
OUTSIDE
self
.
_last_press_x
=
-
1
self
.
_last_press_y
=
-
1
self
.
_base_width
=
10
0
self
.
_base_height
=
10
0
self
.
_base_width
=
10
self
.
_base_height
=
10
self
.
_aspect
=
float
(
1.0
)
self
.
set_size_request
(
self
.
_base_width
,
self
.
_base_height
)
...
...
@@ -212,8 +211,8 @@ def set_pixbuf(self, pixbuf):
self
.
_crop
.
width
=
2
*
self
.
_base_width
self
.
_crop
.
height
=
2
*
self
.
_base_height
self
.
_crop
.
x
=
(
width
-
self
.
_crop
.
width
)
/
2
self
.
_crop
.
y
=
(
height
-
self
.
_crop
.
height
)
/
2
self
.
_crop
.
x
=
abs
(
(
width
-
self
.
_crop
.
width
)
/
2
)
self
.
_crop
.
y
=
abs
(
(
height
-
self
.
_crop
.
height
)
/
2
)
self
.
_scale
=
0.0
self
.
_image
.
x
=
0
...
...
@@ -232,6 +231,9 @@ def get_pixbuf(self):
width
=
min
(
self
.
_crop
.
width
,
width
-
self
.
_crop
.
x
)
height
=
min
(
self
.
_crop
.
height
,
height
-
self
.
_crop
.
y
)
if
width
<=
0
or
height
<=
0
:
return
None
return
GdkPixbuf
.
Pixbuf
.
new_subpixbuf
(
self
.
_browse_pixbuf
,
self
.
_crop
.
x
,
self
.
_crop
.
y
,
width
,
height
)
...
...
@@ -653,6 +655,12 @@ def _update_cursor(self, x_coord, y_coord):
@staticmethod
def
_eval_radial_line
(
center_x
,
center_y
,
bounds_x
,
bounds_y
,
user_x
):
slope_y
=
float
(
bounds_y
-
center_y
)
slope_x
=
bounds_x
-
center_x
if
slope_y
==
0
or
slope_x
==
0
:
# Prevent division by zero
return
0
decision_slope
=
float
(
bounds_y
-
center_y
)
/
(
bounds_x
-
center_x
)
decision_intercept
=
-
float
(
decision_slope
*
bounds_x
)
return
int
(
decision_slope
*
user_x
+
decision_intercept
)
...
...
This diff is collapsed.
Click to expand it.
gajim/gtk/profile.py
+
7
−
2
View file @
999f6e9b
...
...
@@ -17,6 +17,7 @@
from
gajim.gui.avatar
import
clip_circle
from
gajim.gui.avatar_selector
import
AvatarSelector
from
gajim.gui.dialogs
import
ErrorDialog
from
gajim.gui.filechoosers
import
AvatarChooserDialog
from
gajim.gui.util
import
get_builder
from
gajim.gui.vcard_grid
import
VCardGrid
...
...
@@ -276,12 +277,16 @@ def _on_cancel_update_avatar(self, _button):
def
_on_update_avatar
(
self
,
_button
):
success
,
data
,
width
,
height
=
self
.
_avatar_selector
.
get_avatar_bytes
()
if
not
success
:
# TODO: Error handling
self
.
_ui
.
profile_stack
.
set_visible_child_name
(
'
profile
'
)
ErrorDialog
(
_
(
'
Error while processing image
'
),
_
(
'
Failed to generate avatar.
'
))
return
sha
=
app
.
interface
.
avatar_storage
.
save_avatar
(
data
)
if
sha
is
None
:
# TODO: Error handling
self
.
_ui
.
profile_stack
.
set_visible_child_name
(
'
profile
'
)
ErrorDialog
(
_
(
'
Error while processing image
'
),
_
(
'
Failed to generate avatar.
'
))
return
self
.
_new_avatar
=
Avatar
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment