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
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
TSRh
gajim
Commits
ed1893ee
Commit
ed1893ee
authored
19 years ago
by
dkirov
Browse files
Options
Downloads
Patches
Plain Diff
moved convert bytes to common/helpers
parent
9c2b9e4b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/common/helpers.py
+39
-0
39 additions, 0 deletions
src/common/helpers.py
src/dialogs.py
+6
-7
6 additions, 7 deletions
src/dialogs.py
src/gtkgui_helpers.py
+1
-38
1 addition, 38 deletions
src/gtkgui_helpers.py
with
46 additions
and
45 deletions
src/common/helpers.py
+
39
−
0
View file @
ed1893ee
...
...
@@ -20,9 +20,48 @@
import
sre
import
os
import
gajim
from
common
import
i18n
_
=
i18n
.
_
def
convert_bytes
(
string
):
suffix
=
''
# IEC standard says KiB = 1024 bytes KB = 1000 bytes
use_kib_mib
=
gajim
.
config
.
get
(
'
use_kib_mib
'
)
align
=
1024.
bytes
=
float
(
string
)
if
bytes
>=
align
:
bytes
=
round
(
bytes
/
align
,
1
)
if
bytes
>=
align
:
bytes
=
round
(
bytes
/
align
,
1
)
if
bytes
>=
align
:
bytes
=
round
(
bytes
/
align
,
1
)
if
use_kib_mib
:
#GiB means gibibyte
suffix
=
_
(
'
%s GiB
'
)
else
:
#GB means gigabyte
suffix
=
_
(
'
%s GB
'
)
else
:
if
use_kib_mib
:
#MiB means mibibyte
suffix
=
_
(
'
%s MiB
'
)
else
:
#MB means megabyte
suffix
=
_
(
'
%s MB
'
)
else
:
if
use_kib_mib
:
#KiB means kibibyte
suffix
=
_
(
'
%s KiB
'
)
else
:
#KB means kilo bytes
suffix
=
_
(
'
%s KB
'
)
else
:
#B means bytes
suffix
=
_
(
'
%s B
'
)
return
suffix
%
str
(
bytes
)
def
get_uf_show
(
show
):
'''
returns a userfriendly string for dnd/xa/chat
and makes all strings translatable
'''
...
...
This diff is collapsed.
Click to expand it.
src/dialogs.py
+
6
−
7
View file @
ed1893ee
...
...
@@ -754,15 +754,14 @@ def populate(self, file_props):
receiver
=
receiver
.
split
(
'
/
'
)[
0
]
name
=
gajim
.
get_first_contact_instance_from_jid
(
file_props
[
'
tt_account
'
],
receiver
).
name
text
+=
gtkgui_helpers
.
escape_for_pango_markup
(
receiver
)
text
+=
gtkgui_helpers
.
escape_for_pango_markup
(
name
)
text
+=
'
\n
<b>
'
+
_
(
'
Size:
'
)
+
'
</b>
'
text
+=
gtkgui_
helpers
.
convert_bytes
(
file_props
[
'
size
'
])
text
+=
helpers
.
convert_bytes
(
file_props
[
'
size
'
])
text
+=
'
\n
<b>
'
+
_
(
'
Transfered:
'
)
+
'
</b>
'
transfered_len
=
0
if
file_props
.
has_key
(
'
received-len
'
):
transfered_len
=
file_props
[
'
received-len
'
]
text
+=
gtkgui_
helpers
.
convert_bytes
(
transfered_len
)
text
+=
helpers
.
convert_bytes
(
transfered_len
)
text
+=
'
\n
<b>
'
+
_
(
'
Status:
'
)
+
'
</b>
'
status
=
''
if
not
file_props
.
has_key
(
'
started
'
)
or
not
file_props
[
'
started
'
]:
...
...
@@ -1605,7 +1604,7 @@ def show_completed(self, jid, file_props):
sectext
=
'
\t
'
+
_
(
'
Filename: %s
'
)
%
\
gtkgui_helpers
.
escape_for_pango_markup
(
file_props
[
'
name
'
])
sectext
+=
'
\n\t
'
+
_
(
'
Size: %s
'
)
%
\
gtkgui_
helpers
.
convert_bytes
(
file_props
[
'
size
'
])
helpers
.
convert_bytes
(
file_props
[
'
size
'
])
sectext
+=
'
\n\t
'
+
_
(
'
Sender: %s
'
)
%
\
gtkgui_helpers
.
escape_for_pango_markup
(
jid
)
InformationDialog
(
_
(
'
File transfer completed
'
),
sectext
).
get_response
()
...
...
@@ -1667,7 +1666,7 @@ def show_file_request(self, account, contact, file_props):
gtkgui_helpers
.
escape_for_pango_markup
(
file_props
[
'
name
'
])
if
file_props
.
has_key
(
'
size
'
):
sec_text
+=
'
\n\t
'
+
_
(
'
Size: %s
'
)
%
\
gtkgui_
helpers
.
convert_bytes
(
file_props
[
'
size
'
])
helpers
.
convert_bytes
(
file_props
[
'
size
'
])
if
file_props
.
has_key
(
'
mime-type
'
):
sec_text
+=
'
\n\t
'
+
_
(
'
Type: %s
'
)
%
\
gtkgui_helpers
.
escape_for_pango_markup
(
file_props
[
'
mime-type
'
])
...
...
@@ -1752,8 +1751,8 @@ def set_progress(self, typ, sid, transfered_size, iter = None):
if
transfered_size
==
0
:
text
+=
'
0
'
else
:
text
+=
gtkgui_
helpers
.
convert_bytes
(
transfered_size
)
text
+=
'
/
'
+
gtkgui_
helpers
.
convert_bytes
(
full_size
)
text
+=
helpers
.
convert_bytes
(
transfered_size
)
text
+=
'
/
'
+
helpers
.
convert_bytes
(
full_size
)
self
.
model
.
set
(
iter
,
3
,
text
)
if
file_props
[
'
type
'
]
==
'
r
'
:
status
=
'
download
'
...
...
This diff is collapsed.
Click to expand it.
src/gtkgui_helpers.py
+
1
−
38
View file @
ed1893ee
...
...
@@ -55,44 +55,7 @@ def _cut_if_long(str):
if
reduced_text
!=
text
and
widget
is
not
None
:
pass
# FIXME show tooltip
return
reduced_text
def
convert_bytes
(
string
):
suffix
=
''
# IEC standard says KiB = 1024 bytes KB = 1000 bytes
use_kib_mib
=
gajim
.
config
.
get
(
'
use_kib_mib
'
)
align
=
1024.
bytes
=
float
(
string
)
if
bytes
>=
align
:
bytes
=
round
(
bytes
/
align
,
1
)
if
bytes
>=
align
:
bytes
=
round
(
bytes
/
align
,
1
)
if
bytes
>=
align
:
bytes
=
round
(
bytes
/
align
,
1
)
if
use_kib_mib
:
#GiB means gibibyte
suffix
=
_
(
'
%s GiB
'
)
else
:
#GB means gigabyte
suffix
=
_
(
'
%s GB
'
)
else
:
if
use_kib_mib
:
#MiB means mibibyte
suffix
=
_
(
'
%s MiB
'
)
else
:
#MB means megabyte
suffix
=
_
(
'
%s MB
'
)
else
:
if
use_kib_mib
:
#KiB means kibibyte
suffix
=
_
(
'
%s KiB
'
)
else
:
#KB means kilo bytes
suffix
=
_
(
'
%s KB
'
)
else
:
#B means bytes
suffix
=
_
(
'
%s B
'
)
return
suffix
%
str
(
bytes
)
def
escape_for_pango_markup
(
string
):
# escapes < > & \ "
# for pango markup not to break
...
...
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