|
| 1 | +// SPDX-FileCopyrightText: 2022 Deren Vural |
| 2 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | + |
| 4 | +/* |
| 5 | + * Name: |
| 6 | + * imp.rs |
| 7 | + * |
| 8 | + * Description: |
| 9 | + * Implementation of our custom GObject class (Provider) |
| 10 | + * |
| 11 | + * Made: |
| 12 | + * 06/10/2022 |
| 13 | + * |
| 14 | + * Made by: |
| 15 | + * Deren Vural |
| 16 | + * |
| 17 | + * Notes: |
| 18 | + * |
| 19 | + */ |
| 20 | + |
| 21 | +// Imports |
| 22 | +use gtk::glib::once_cell::sync::Lazy; |
| 23 | +use gtk::glib::{self, ParamSpec, Value}; |
| 24 | +use gtk::prelude::*; |
| 25 | +use gtk::subclass::prelude::*; |
| 26 | +use std::cell::Cell; |
| 27 | + |
| 28 | +// Object holding the State |
| 29 | +#[derive(Default)] |
| 30 | +pub struct Provider; |
| 31 | + |
| 32 | +// The central trait for subclassing a GObject |
| 33 | +#[glib::object_subclass] |
| 34 | +impl ObjectSubclass for Provider { |
| 35 | + //Crate+Obj to avoid collisions |
| 36 | + const NAME: &'static str = "NvidiaExtensionRustProcessor"; |
| 37 | + // the actual GObject that will be created |
| 38 | + type Type = super::Provider; |
| 39 | + // Parent GObject we inherit from |
| 40 | + type ParentType = gtk::Widget; |
| 41 | +} |
| 42 | + |
| 43 | +/* |
| 44 | + * Trait Name: |
| 45 | + * ObjectImpl |
| 46 | + * |
| 47 | + * Description: |
| 48 | + * Trait shared by all GObjects |
| 49 | + * |
| 50 | + * Made: |
| 51 | + * 06/10/2022 |
| 52 | + * |
| 53 | + * Made by: |
| 54 | + * Deren Vural |
| 55 | + * |
| 56 | + * Notes: |
| 57 | + * |
| 58 | + */ |
| 59 | +impl ObjectImpl for Provider { |
| 60 | + /* |
| 61 | + * Name: |
| 62 | + * properties |
| 63 | + * |
| 64 | + * Description: |
| 65 | + * Create list of custom properties for our GObject |
| 66 | + * |
| 67 | + * Made: |
| 68 | + * 06/10/2022 |
| 69 | + * |
| 70 | + * Made by: |
| 71 | + * Deren Vural |
| 72 | + * |
| 73 | + * Notes: |
| 74 | + * beware that you need to use kebab-case (https://en.wikipedia.org/wiki/Letter_case#Kebab_case) |
| 75 | + * |
| 76 | + * ParamSpec Examples: |
| 77 | + * glib::ParamSpecString::builder("icon").build(), |
| 78 | + * glib::ParamSpecUInt::builder("gpu_count").build(), |
| 79 | + * glib::ParamSpecString::builder("call_extension").build(), |
| 80 | + * TODO: these are from property class |
| 81 | + * glib::ParamSpecBoxed::builder("processor").build(), |
| 82 | + * glib::ParamSpecObject::builder("formatter").build(), |
| 83 | + */ |
| 84 | + fn properties() -> &'static [ParamSpec] { |
| 85 | + static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| vec![]); |
| 86 | + |
| 87 | + //println!("PROPERTIES: {:?}", PROPERTIES);//TEST |
| 88 | + //println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST |
| 89 | + |
| 90 | + PROPERTIES.as_ref() |
| 91 | + } |
| 92 | + |
| 93 | + /* |
| 94 | + * Name: |
| 95 | + * set_property |
| 96 | + * |
| 97 | + * Description: |
| 98 | + * Mutator for custom GObject properties |
| 99 | + * |
| 100 | + * Made: |
| 101 | + * 06/10/2022 |
| 102 | + * |
| 103 | + * Made by: |
| 104 | + * Deren Vural |
| 105 | + * |
| 106 | + * Notes: |
| 107 | + * |
| 108 | + */ |
| 109 | + fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) { |
| 110 | + //println!("setting: {:?}", pspec.name());//TEST |
| 111 | + |
| 112 | + match pspec.name() { |
| 113 | + _ => unimplemented!(), //TODO |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + /* |
| 118 | + * Name: |
| 119 | + * property |
| 120 | + * |
| 121 | + * Description: |
| 122 | + * Accessor for custom GObject properties |
| 123 | + * |
| 124 | + * Made: |
| 125 | + * 06/10/2022 |
| 126 | + * |
| 127 | + * Made by: |
| 128 | + * Deren Vural |
| 129 | + * |
| 130 | + * Notes: |
| 131 | + * |
| 132 | + */ |
| 133 | + fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value { |
| 134 | + //println!("getting: {:?}", pspec.name());//TEST |
| 135 | + |
| 136 | + match pspec.name() { |
| 137 | + _ => unimplemented!(), //TODO |
| 138 | + } |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +/* |
| 143 | + * Trait Name: |
| 144 | + * WidgetImpl |
| 145 | + * |
| 146 | + * Description: |
| 147 | + * Trait shared by all widgets |
| 148 | + * |
| 149 | + * Made: |
| 150 | + * 06/10/2022 |
| 151 | + * |
| 152 | + * Made by: |
| 153 | + * Deren Vural |
| 154 | + * |
| 155 | + * Notes: |
| 156 | + * leaving blank atm, boilerplate |
| 157 | + */ |
| 158 | +impl WidgetImpl for Provider {} |
0 commit comments