| 1 | /* |
| 2 | * Copyright 2020-2024 Andrey Kutejko <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * For more details see the file COPYING. |
| 18 | */ |
| 19 | |
| 20 | use crate::bubble::Bubble; |
| 21 | use crate::cursors::make_cursors; |
| 22 | use crate::themes::themes_from_directory; |
| 23 | use gtk::{gdk, gio, prelude::*}; |
| 24 | use std::error::Error; |
| 25 | use std::path::Path; |
| 26 | |
| 27 | pub trait Assets { |
| 28 | fn themes(&self) -> gio::ListModel; |
| 29 | fn aieee_bubble(&self) -> Bubble; |
| 30 | fn yahoo_bubble(&self) -> Bubble; |
| 31 | fn splat_bubble(&self) -> Bubble; |
| 32 | fn cursors(&self) -> Vec<gdk::Cursor>; |
| 33 | } |
| 34 | |
| 35 | pub struct DirectoryAssets { |
| 36 | themes: gio::ListStore, |
| 37 | aieee_bubble: Bubble, |
| 38 | yahoo_bubble: Bubble, |
| 39 | splat_bubble: Bubble, |
| 40 | cursors: Vec<gdk::Cursor>, |
| 41 | } |
| 42 | |
| 43 | impl DirectoryAssets { |
| 44 | pub fn from_directory(directory: &Path) -> Result<Self, Box<dyn Error>> { |
| 45 | let themes = themes_from_directory(&directory.join("themes")); |
| 46 | |
| 47 | let pixmaps = directory.join("pixmaps"); |
| 48 | let yahoo_bubble = Bubble::from_file(&pixmaps.join("yahoo.png"))?; |
| 49 | let aieee_bubble = Bubble::from_file(&pixmaps.join("aieee.png"))?; |
| 50 | let splat_bubble = Bubble::from_file(&pixmaps.join("splat.png"))?; |
| 51 | |
| 52 | let cursors = make_cursors(); |
| 53 | |
| 54 | Ok(Self { |
| 55 | themes, |
| 56 | aieee_bubble, |
| 57 | yahoo_bubble, |
| 58 | splat_bubble, |
| 59 | cursors, |
| 60 | }) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | impl Assets for DirectoryAssets { |
| 65 | fn themes(&self) -> gio::ListModel { |
| 66 | self.themes.clone().upcast() |
| 67 | } |
| 68 | |
| 69 | fn aieee_bubble(&self) -> Bubble { |
| 70 | self.aieee_bubble.clone() |
| 71 | } |
| 72 | |
| 73 | fn yahoo_bubble(&self) -> Bubble { |
| 74 | self.yahoo_bubble.clone() |
| 75 | } |
| 76 | |
| 77 | fn splat_bubble(&self) -> Bubble { |
| 78 | self.splat_bubble.clone() |
| 79 | } |
| 80 | |
| 81 | fn cursors(&self) -> Vec<gdk::Cursor> { |
| 82 | self.cursors.clone() |
| 83 | } |
| 84 | } |