Commit c156a9d5 authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui
Browse files

make cargo clippy happy

parent 414f3c76
......@@ -41,6 +41,26 @@ dependencies = [
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "backtrace"
version = "0.3.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "backtrace-sys"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.1.0"
......@@ -93,6 +113,7 @@ name = "contrast"
version = "0.0.2"
dependencies = [
"dbus 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gettext-rs 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -128,6 +149,26 @@ dependencies = [
"termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "failure"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.41 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "failure_derive"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "futures-channel"
version = "0.3.4"
......@@ -646,6 +687,11 @@ dependencies = [
"ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-demangle"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "sass-rs"
version = "0.2.2"
......@@ -681,6 +727,17 @@ dependencies = [
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "synstructure"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termcolor"
version = "1.0.5"
......@@ -753,6 +810,8 @@ dependencies = [
"checksum atk 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "444daefa55f229af145ea58d77efd23725024ee1f6f3102743709aa6b18c663e"
"checksum atk-sys 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e552c1776737a4c80110d06b36d099f47c727335f9aaa5d942a72b6863a8ec6f"
"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"
"checksum backtrace 0.3.41 (registry+https://github.com/rust-lang/crates.io-index)" = "a4ed64ae6d9ebfd9893193c4b2532b1292ec97bd8271c9d7d0fa90cd78a34cba"
"checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491"
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101"
"checksum cairo-rs 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "157049ba9618aa3a61c39d5d785102c04d3b1f40632a706c621a9aedc21e6084"
......@@ -761,6 +820,8 @@ dependencies = [
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
"checksum dbus 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "48b5f0f36f1eebe901b0e6bee369a77ed3396334bf3f09abd46454a576f71819"
"checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9"
"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08"
"checksum futures-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c77d04ce8edd9cb903932b608268b3fffec4163dc053b3b402bf47eac1f1a8"
"checksum futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a"
"checksum futures-executor 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f674f3e1bcb15b37284a90cedf55afdba482ab061c407a9c0ebbd0f3109741ba"
......@@ -811,10 +872,12 @@ dependencies = [
"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
"checksum regex 1.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "d9d8297cc20bbb6184f8b45ff61c8ee6a9ac56c156cec8e38c3e5084773c44ad"
"checksum regex-syntax 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "9b01330cce219c1c6b2e209e5ed64ccd587ae5c67bed91c0b49eecf02ae40e21"
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
"checksum sass-rs 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cabcf7c6e55053f359911187ac401409aad2dc14338cae972dec266fee486abd"
"checksum sass-sys 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6e16ac97c2335bc367e2d675f54c1823558f1b19a6c67671d48b70e30ae22972"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5"
"checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"
"checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
......
......@@ -18,3 +18,4 @@ sass-rs = "0.2.2"
pretty_env_logger = "0.4"
dbus = "0.6.5"
rand = "0.7"
failure = "0.1"
......@@ -126,7 +126,6 @@ impl Application {
info!("Version: {} ({})", config::VERSION, config::PROFILE);
info!("Datadir: {}", config::PKGDATADIR);
let app = app.clone();
let receiver = self.receiver.borrow_mut().take().unwrap();
receiver.attach(None, move |action| app.do_action(action));
......
......@@ -6,9 +6,9 @@ pub fn calc_contrast_level(bg_color: &gdk::RGBA, fg_color: &gdk::RGBA) -> f64 {
fn get_srgb(c: f64) -> f64 {
if c <= 0.03928 {
return c / 12.92;
c / 12.92
} else {
return ((c + 0.055) / 1.055).powf(2.4);
((c + 0.055) / 1.055).powf(2.4)
}
}
......
......@@ -47,9 +47,8 @@ impl ColourEntry {
colour_selector_pop.widget.set_pointing_to(&icon_rectangle);
let colour = entry.get_text().unwrap();
match gdk::RGBA::from_str(&colour) {
Ok(rgba) => colour_selector_pop.color_chooser.set_rgba(&rgba),
Err(_) => (),
if let Ok(rgba) = gdk::RGBA::from_str(&colour) {
colour_selector_pop.color_chooser.set_rgba(&rgba);
}
colour_selector_pop.color_chooser.set_property_show_editor(false);
colour_selector_pop.widget.popup();
......@@ -102,9 +101,8 @@ impl ColourEntry {
}
pub fn set_text(&self, colour: Option<String>) {
match colour {
Some(colour) => self.entry.set_text(colour.as_str()),
_ => (),
};
if let Some(colour) = colour {
self.entry.set_text(&colour)
}
}
}
pub static APP_ID: &'static str = @APP_ID@;
pub static PKGDATADIR: &'static str = @PKGDATADIR@;
pub static PROFILE: &'static str = @PROFILE@;
pub static NAME_PREFIX: &'static str = @NAME_PREFIX@;
pub static VERSION: &'static str = @VERSION@;
pub static GETTEXT_PACKAGE: &'static str = @GETTEXT_PACKAGE@;
pub static LOCALEDIR: &'static str = @LOCALEDIR@;
pub static APP_ID: &str = @APP_ID@;
pub static PKGDATADIR: &str = @PKGDATADIR@;
pub static PROFILE: &str = @PROFILE@;
pub static NAME_PREFIX: &str = @NAME_PREFIX@;
pub static VERSION: &str = @VERSION@;
pub static GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@;
pub static LOCALEDIR: &str = @LOCALEDIR@;
use gettextrs::gettext;
use glib::Cast;
use gtk::prelude::*;
use libhandy::prelude::*;
use pango;
......@@ -102,20 +101,12 @@ impl ChartBarWidget {
container.pack_start(filled_container, false, false, 0);
widget.set_maximum_width(900);
// we can't call add as libhandy::Column is not seen as a gtkContainer
// Thanks to Jordan (Podcasts) for the tip :P
let widget = widget.clone();
let column = widget.upcast::<gtk::Widget>();
let column = column.downcast::<gtk::Container>().unwrap();
column.add(&overlay);
column.show();
let weak_instance = Rc::downgrade(&s).clone();
container.connect_size_allocate(move |_, _| {
if let Some(instance) = weak_instance.upgrade() {
instance.borrow().reallocate();
}
});
widget.add(&overlay);
widget.show();
container.connect_size_allocate(clone!(@weak s as chart_bar => move |_, _| {
chart_bar.borrow().reallocate();
}));
}
pub fn set_value(&mut self, value: f64) {
......@@ -182,7 +173,7 @@ impl ContrastLevelBar {
pub fn set_contrast_level(&mut self, contrast_level: f64) {
self.chartbar.borrow_mut().set_value(contrast_level);
let mut level_label = String::from(gettext("Contrast Ratio: "));
let mut level_label = gettext("Contrast Ratio: ");
if contrast_level.fract() != 0.0 {
level_label.push_str(&format!("{:.1}:1", contrast_level));
} else {
......
extern crate pretty_env_logger;
#[macro_use]
extern crate log;
#[macro_use]
extern crate glib;
extern crate gtk;
use gettextrs::*;
mod application;
......
......@@ -76,7 +76,9 @@ impl Window {
let state = self.state.clone();
self.widget.connect_delete_event(move |window, _| {
state.borrow_mut().dump(&window);
if let Err(err) = state.borrow_mut().dump(&window) {
warn!("Failed to save window state {}", err);
}
gtk::Inhibit(false)
});
......
......@@ -7,7 +7,9 @@ use std::str::FromStr;
// Default colors, randomized whenever you launch the app
// (bg, fg)
const DEFAULT_COLORS: [((f64, f64, f64), (f64, f64, f64)); 12] = [
type PaletteColor = ((f64, f64, f64), (f64, f64, f64));
const DEFAULT_COLORS: [PaletteColor; 12] = [
((228.0, 240.0, 252.0), (29.0, 87.0, 119.0)),
((228.0, 220.0, 171.0), (97.0, 53.0, 131.0)),
((251.0, 204.0, 231.0), (36.0, 28.0, 140.0)),
......@@ -82,38 +84,32 @@ impl WindowState {
}
pub fn set_bg_colour(&mut self, colour: Option<&str>) {
match colour {
Some(colour) => {
self.bg_colour = gdk::RGBA::from_str(colour).unwrap_or(gdk::RGBA {
red: 0.0,
green: 0.0,
blue: 0.0,
alpha: 1.0,
});
}
None => (),
if let Some(col) = colour {
self.bg_colour = gdk::RGBA::from_str(col).unwrap_or(gdk::RGBA {
red: 0.0,
green: 0.0,
blue: 0.0,
alpha: 1.0,
});
}
}
pub fn set_fg_colour(&mut self, colour: Option<&str>) {
match colour {
Some(colour) => {
self.fg_colour = gdk::RGBA::from_str(colour).unwrap_or(gdk::RGBA {
red: 1.0,
green: 1.0,
blue: 1.0,
alpha: 1.0,
});
}
None => (),
if let Some(col) = colour {
self.fg_colour = gdk::RGBA::from_str(col).unwrap_or(gdk::RGBA {
red: 1.0,
green: 1.0,
blue: 1.0,
alpha: 1.0,
});
}
}
pub fn dump(&self, window: &gtk::ApplicationWindow) {
pub fn dump(&self, window: &gtk::ApplicationWindow) -> Result<(), failure::Error> {
let position = window.get_position();
self.settings.set_boolean("is-maximized", window.is_maximized());
self.settings.set_int("window-x", position.0);
self.settings.set_int("window-y", position.1);
self.settings.set_boolean("is-maximized", window.is_maximized())?;
self.settings.set_int("window-x", position.0)?;
self.settings.set_int("window-y", position.1)?;
Ok(())
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment