Skip to content

Commit

Permalink
chore: refactor code following clippy guideline
Browse files Browse the repository at this point in the history
  • Loading branch information
acolombier committed Sep 9, 2024
1 parent df43c94 commit 050c882
Show file tree
Hide file tree
Showing 22 changed files with 204 additions and 210 deletions.
4 changes: 2 additions & 2 deletions cosmic-settings/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ impl SettingsApp {
match cmd {
PageCommands::About => self.pages.page_id::<system::about::Page>(),
PageCommands::Appearance => self.pages.page_id::<desktop::appearance::Page>(),
PageCommands::Bluetooth => None,
PageCommands::DateTime => self.pages.page_id::<time::date::Page>(),
PageCommands::Desktop => self.pages.page_id::<desktop::Page>(),
PageCommands::Displays => self.pages.page_id::<display::Page>(),
Expand All @@ -68,7 +67,6 @@ impl SettingsApp {
PageCommands::Input => self.pages.page_id::<input::Page>(),
PageCommands::Keyboard => self.pages.page_id::<input::keyboard::Page>(),
PageCommands::Mouse => self.pages.page_id::<input::mouse::Page>(),
PageCommands::Network => None,
PageCommands::Panel => self.pages.page_id::<desktop::panel::Page>(),
PageCommands::Power => self.pages.page_id::<power::Page>(),
PageCommands::RegionLanguage => self.pages.page_id::<time::region::Page>(),
Expand All @@ -82,6 +80,8 @@ impl SettingsApp {
self.pages.page_id::<desktop::window_management::Page>()
}
PageCommands::Workspaces => self.pages.page_id::<desktop::workspaces::Page>(),
// Unimplemented
PageCommands::Bluetooth | PageCommands::Network => None,
}
}

Expand Down
6 changes: 3 additions & 3 deletions cosmic-settings/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ impl FromStr for PageCommands {
}
}

impl ToString for PageCommands {
fn to_string(&self) -> String {
ron::ser::to_string(self).unwrap()
impl std::fmt::Display for PageCommands {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&ron::ser::to_string(self).map_err(|_| std::fmt::Error)?)
}
}

Expand Down
8 changes: 4 additions & 4 deletions cosmic-settings/src/pages/desktop/appearance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl Page {
.zip(self.icon_handles.iter())
.enumerate()
.map(|(i, (theme, handles))| {
let selected = active.map(|j| i == j).unwrap_or_default();
let selected = active.is_some_and(|j| i == j);
icon_theme_button(&theme.name, handles, i, selected)
})
.collect(),
Expand Down Expand Up @@ -496,7 +496,7 @@ impl Page {
Message::IconTheme(id) => {
if let Some(theme) = self.icon_themes.get(id).cloned() {
self.icon_theme_active = Some(id);
self.tk.icon_theme = theme.id.clone();
self.tk.icon_theme = theme.id;

if let Some(ref config) = self.tk_config {
let _ = self.tk.write_entry(config);
Expand Down Expand Up @@ -598,7 +598,7 @@ impl Page {
self.icon_theme_active = self
.icon_themes
.iter()
.position(|theme| &theme.id == &self.tk.icon_theme);
.position(|theme| theme.id == self.tk.icon_theme);
self.icon_handles = icon_handles;
Command::none()
}
Expand Down Expand Up @@ -1689,7 +1689,7 @@ async fn set_gnome_icon_theme(theme: String) {
.await;
}

/// Generate [icon::Handle]s to use for icon theme previews.
/// Generate [`icon::Handle`]s to use for icon theme previews.
fn preview_handles(theme: String, inherits: Vec<String>) -> [icon::Handle; ICON_PREV_N] {
// Cache current default and set icon theme as a temporary default
let default = cosmic::icon_theme::default();
Expand Down
12 changes: 6 additions & 6 deletions cosmic-settings/src/pages/desktop/dock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use crate::pages::desktop::panel::inner::{
add_panel, behavior_and_position, configuration, reset_button, style,
};

use super::panel::inner::{self, PageInner, PanelPage};
use super::panel::inner;

pub mod applets;

pub struct Page {
inner: PageInner,
inner: inner::Page,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -75,12 +75,12 @@ impl page::AutoBind<crate::pages::Message> for Page {
}
}

impl PanelPage for Page {
fn inner(&self) -> &PageInner {
impl inner::PanelPage for Page {
fn inner(&self) -> &inner::Page {
&self.inner
}

fn inner_mut(&mut self) -> &mut PageInner {
fn inner_mut(&mut self) -> &mut inner::Page {
&mut self.inner
}

Expand Down Expand Up @@ -130,7 +130,7 @@ impl Default for Page {
.ok();
let container_config = CosmicPanelContainerConfig::load().ok();
Self {
inner: PageInner {
inner: inner::Page {
config_helper,
panel_config,
container_config,
Expand Down
17 changes: 8 additions & 9 deletions cosmic-settings/src/pages/desktop/panel/applets_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ impl Page {
.into()
}

/// # Panics
///
/// Panics if the wings of the added applet are None.
#[allow(clippy::too_many_lines)]
pub fn update(&mut self, message: Message) -> Command<app::Message> {
match message {
Expand Down Expand Up @@ -666,7 +669,7 @@ impl<'a, Message: 'static + Clone> AppletReorderList<'a, Message> {
) -> Message
+ 'a,
on_remove: impl Fn(String) -> Message + 'a,
on_details: impl Fn(String) -> Message + 'a,
_on_details: impl Fn(String) -> Message + 'a,
on_reorder: impl Fn(Vec<Applet<'static>>) -> Message + 'a,
on_apply_reorder: Message,
on_cancel: Message,
Expand Down Expand Up @@ -972,7 +975,10 @@ where
}
DraggingState::Dragging(applet) => match &event {
event::Event::PlatformSpecific(PlatformSpecific::Wayland(
wayland::Event::DataSource(wayland::DataSourceEvent::DndFinished),
wayland::Event::DataSource(
wayland::DataSourceEvent::DndFinished
| wayland::DataSourceEvent::DndDropPerformed,
),
)) => {
ret = event::Status::Captured;
DraggingState::None
Expand All @@ -986,13 +992,6 @@ where
}
DraggingState::None
}
event::Event::PlatformSpecific(PlatformSpecific::Wayland(
wayland::Event::DataSource(wayland::DataSourceEvent::DndDropPerformed),
)) => {
ret = event::Status::Captured;

DraggingState::None
}
_ => DraggingState::Dragging(applet),
},
DraggingState::Pressed(start) => {
Expand Down
26 changes: 13 additions & 13 deletions cosmic-settings/src/pages/desktop/panel/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use cosmic_settings_page::{self as page, Section};
use slab::Slab;
use std::collections::HashMap;

pub struct PageInner {
pub struct Page {
pub(crate) config_helper: Option<cosmic_config::Config>,
pub(crate) panel_config: Option<CosmicPanelConfig>,
pub outputs: Vec<String>,
Expand All @@ -31,7 +31,7 @@ pub struct PageInner {
pub(crate) system_container: Option<CosmicPanelContainerConfig>,
}

impl Default for PageInner {
impl Default for Page {
fn default() -> Self {
Self {
config_helper: Option::default(),
Expand Down Expand Up @@ -72,9 +72,9 @@ impl Default for PageInner {
}

pub trait PanelPage {
fn inner(&self) -> &PageInner;
fn inner(&self) -> &Page;

fn inner_mut(&mut self) -> &mut PageInner;
fn inner_mut(&mut self) -> &mut Page;

fn autohide_label(&self) -> String;

Expand Down Expand Up @@ -336,14 +336,14 @@ pub fn reset_button<
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Anchor(PanelAnchor);

impl ToString for Anchor {
fn to_string(&self) -> String {
match self.0 {
impl std::fmt::Display for Anchor {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&match self.0 {
PanelAnchor::Top => fl!("panel-top"),
PanelAnchor::Bottom => fl!("panel-bottom"),
PanelAnchor::Left => fl!("panel-left"),
PanelAnchor::Right => fl!("panel-right"),
}
})
}
}

Expand All @@ -354,13 +354,13 @@ pub enum Appearance {
Dark,
}

impl ToString for Appearance {
fn to_string(&self) -> String {
match self {
impl std::fmt::Display for Appearance {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&match self {
Appearance::Match => fl!("panel-appearance", "match"),
Appearance::Light => fl!("panel-appearance", "light"),
Appearance::Dark => fl!("panel-appearance", "dark"),
}
})
}
}

Expand Down Expand Up @@ -404,7 +404,7 @@ pub enum Message {
FullReset,
}

impl PageInner {
impl Page {
#[allow(clippy::too_many_lines)]
pub fn update(&mut self, message: Message) {
let Some(helper) = self.config_helper.as_ref() else {
Expand Down
12 changes: 5 additions & 7 deletions cosmic-settings/src/pages/desktop/panel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ use crate::pages::desktop::panel::inner::{
add_panel, behavior_and_position, configuration, reset_button, style,
};

use self::inner::{PageInner, PanelPage};

pub mod applets_inner;
pub mod inner;

pub struct Page {
inner: PageInner,
inner: inner::Page,
}

#[derive(Clone, Debug)]
Expand All @@ -33,12 +31,12 @@ impl page::AutoBind<crate::pages::Message> for Page {
}
}

impl PanelPage for Page {
fn inner(&self) -> &PageInner {
impl inner::PanelPage for Page {
fn inner(&self) -> &inner::Page {
&self.inner
}

fn inner_mut(&mut self) -> &mut PageInner {
fn inner_mut(&mut self) -> &mut inner::Page {
&mut self.inner
}

Expand Down Expand Up @@ -87,7 +85,7 @@ impl Default for Page {
.ok();
let container_config = CosmicPanelContainerConfig::load().ok();
Self {
inner: PageInner {
inner: inner::Page {
config_helper,
panel_config,
container_config,
Expand Down
Loading

0 comments on commit 050c882

Please sign in to comment.