Module xdgkit::icon_finder

source ·
Expand description

Icon finder

This is the rustification of the example psuedo code for finding icons a.k.a “the algorithm described in the Icon Theme Specification

to find one single icon use:

use xdgkit::icon_finder::find_icon;
let icon = find_icon("firefox".to_string(), 48, 1);

to find multiple icons use:

use xdgkit::icon_theme::IconTheme;
use xdgkit::icon_finder::{multiple_find_icon, generate_dir_list, user_theme, DirList};

let dir_list_vector = generate_dir_list();
let mut theme = user_theme(dir_list_vector.clone());
if theme.is_none() {
   theme = Some(IconTheme::empty());
}
let theme:IconTheme = theme.unwrap();
let list:Vec<String> = vec![
   "firefox".to_string(),
   "mypaint".to_string(),
   "kate".to_string(),
   "geany".to_string(),
];
for name in list.clone() {
   let icon = match multiple_find_icon(name.clone(), 48, 1, dir_list_vector.clone(), theme.clone()) {
       Some(i) => i,
       None => continue,
   };
   let icon = match icon.to_str() {
       Some(i) => {
           println!("found:{}", i);
           i
       },
       None => {
           println!("Did not find:{}", name.as_str());
           continue
       },
   };
}

Structs

  • A simple structure to hold directory and theme list.

Functions

  • Check to see if the sub directory size is in range
  • You guessed it more pseudo code that turned into rust
  • In some cases you don’t always want to fall back to an icon in an inherited theme. For instance, sometimes you look for a set of icons, preferring any of them before using an icon from an inherited theme. To support such operations implementations can contain a function that finds the first of a list of icon names in the inheritance hierarchy. This is that function!
  • This can be very useful, for example, when handling mime type icons, where there are more and less “specific” versions of icons.
  • Icon Lookup
  • the “helper” function from the free desktop example pseudo code
  • Make the list of DirList structures by reading the $XDG_DATA_DIRS/icons
  • Look in the basic icon directories (like /us/share/pixmaps, /usr/share/icons) for anything that matches the icon name!
  • One of the “following helper functions”
  • This function looks in the ini files of KDE and GTK to find the icon theme!