Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
World
Design Tooling
App Icon Preview
Commits
96ce0056
Commit
96ce0056
authored
Jul 31, 2020
by
Bilal Elmoussaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
project icon: format icon name
fixes
#62
parent
a8983f98
Pipeline
#200418
passed with stage
in 10 minutes and 40 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
5 deletions
+32
-5
src/common.rs
src/common.rs
+30
-2
src/widgets/icon.rs
src/widgets/icon.rs
+2
-3
No files found.
src/common.rs
View file @
96ce0056
...
...
@@ -3,6 +3,34 @@ use glib::Cast;
use
rsvg_internals
::{
Dpi
,
Handle
,
LoadOptions
,
SizeCallback
};
use
std
::
path
::
PathBuf
;
pub
fn
format_name
(
name
:
&
str
)
->
String
{
let
name
=
name
.trim_end_matches
(
".svg"
)
.trim_end_matches
(
".Source"
)
.split
(
'.'
)
.last
()
.unwrap
();
let
mut
formatted_chars
=
vec!
[];
let
mut
chars
=
name
.chars
()
.into_iter
();
name
.chars
()
.into_iter
()
.for_each
(|
c
|
{
if
c
.is_uppercase
()
&&
!
chars
.next
()
.unwrap_or
(
' '
)
.is_uppercase
()
{
formatted_chars
.push
(
' '
);
}
formatted_chars
.push
(
c
);
});
let
formatted_name
:
String
=
formatted_chars
.iter
()
.collect
();
formatted_name
}
#[cfg(test)]
mod
tests
{
use
super
::
format_name
;
#[test]
fn
test_format_name
()
{
assert_eq!
(
format_name
(
"org.gnome.design.AppIconPreview"
),
"App Icon Preview"
.to_string
());
assert_eq!
(
format_name
(
"org.gnome.GTG"
),
"GTG"
.to_string
());
assert_eq!
(
format_name
(
"org.gnome.design.BannerViewer"
),
"Banner Viewer"
.to_string
());
assert_eq!
(
format_name
(
"org.gnome.design.Contrast"
),
"Contrast"
.to_string
());
}
}
pub
fn
create_tmp
(
filename
:
&
str
)
->
anyhow
::
Result
<
PathBuf
>
{
let
mut
temp_path
=
glib
::
get_user_cache_dir
()
.unwrap
()
.join
(
"app-icon-preview"
);
std
::
fs
::
create_dir_all
(
&
temp_path
)
?
;
...
...
@@ -14,7 +42,7 @@ pub fn render(file: &gio::File, output_size: f64, dest: Option<PathBuf>) -> anyh
let
stream
=
file
.read
(
gio
::
NONE_CANCELLABLE
)
?
.upcast
::
<
gio
::
InputStream
>
();
let
handle
=
Handle
::
from_stream
(
&
LoadOptions
::
new
(
None
),
&
stream
,
gio
::
NONE_CANCELLABLE
)
?
;
let
dest
=
dest
.unwrap_or
(
{
create_tmp
(
&
format!
(
"#hicolor-{}-{}"
,
output_size
,
file
.get_basename
()
.unwrap
()
.to_str
()
.unwrap
()))
?
}
);
let
dest
=
dest
.unwrap_or
(
create_tmp
(
&
format!
(
"#hicolor-{}-{}"
,
output_size
,
file
.get_basename
()
.unwrap
()
.to_str
()
.unwrap
()))
?
);
let
mut
surface
=
cairo
::
SvgSurface
::
new
(
output_size
,
output_size
,
Some
(
dest
.clone
()))
.unwrap
();
surface
.set_document_unit
(
cairo
::
SvgUnit
::
Px
);
...
...
@@ -40,7 +68,7 @@ pub fn render_by_id(file: &gio::File, id: &str, output_size: f64, dest: Option<P
let
stream
=
file
.read
(
gio
::
NONE_CANCELLABLE
)
?
.upcast
::
<
gio
::
InputStream
>
();
let
mut
handle
=
Handle
::
from_stream
(
&
LoadOptions
::
new
(
None
),
&
stream
,
gio
::
NONE_CANCELLABLE
)
?
;
let
dest
=
dest
.unwrap_or
(
{
create_tmp
(
&
format!
(
"{}-{}-{}"
,
id
,
output_size
,
file
.get_basename
()
.unwrap
()
.to_str
()
.unwrap
()))
?
}
);
let
dest
=
dest
.unwrap_or
(
create_tmp
(
&
format!
(
"{}-{}-{}"
,
id
,
output_size
,
file
.get_basename
()
.unwrap
()
.to_str
()
.unwrap
()))
?
);
handle
.set_stylesheet
(
"#layer3,#layer2 {visibility: hidden}"
)
?
;
if
handle
.has_sub
(
id
)
?
{
...
...
src/widgets/icon.rs
View file @
96ce0056
use
crate
::
common
;
use
gio
::
prelude
::
*
;
use
gtk
::
prelude
::
*
;
...
...
@@ -24,9 +25,7 @@ impl Icon {
pub
fn
set_file
(
&
self
,
file
:
&
gio
::
File
)
{
let
filename
=
file
.get_basename
()
.unwrap
();
let
filename
=
filename
.to_str
()
.unwrap
()
.trim_end_matches
(
".svg"
)
.trim_end_matches
(
".Source"
)
.split
(
'.'
)
.last
();
self
.label
.set_text
(
filename
.unwrap
());
self
.label
.set_text
(
&
common
::
format_name
(
filename
.to_str
()
.unwrap
()));
let
gicon
=
gio
::
FileIcon
::
new
(
file
);
self
.image
.set_from_gicon
(
&
gicon
,
gtk
::
IconSize
::
Dialog
);
...
...
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