Skip to content

Commit

Permalink
Use "as u8" instead of convertion functions.
Browse files Browse the repository at this point in the history
PR to givc(tiiuae/ghaf-givc#13)
is made to ensure proper work.

Signed-off-by: dmitry-erin <[email protected]>
  • Loading branch information
dmitry-erin committed Sep 4, 2024
1 parent 1b235bb commit 3a785c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/info_settings_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl InfoSettingsPage {
//Set filter: only running VM's
let filter_model = FilterListModel::new(Some(model), Some(CustomFilter::new(|item: &Object| {
if let Some(vm_obj) = item.downcast_ref::<VMGObject>() {
if vm_obj.status() == VMGObject::status_u8(VMStatus::Running) {
if vm_obj.status() == (VMStatus::Running as u8) {
return true;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/trust_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ impl Default for TrustLevel {
}
}

/*impl StaticType for TrustLevel {
fn static_type() -> Type {
u8::static_type()
}
}*/


/*unsafe impl<'a> FromValue<'a> for TrustLevel {
type Checker = glib::value::GenericValueTypeChecker<Self>;
Expand Down
24 changes: 4 additions & 20 deletions src/vm_gobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ impl VMGObject {
Object::builder()
.property("name", name)
.property("details", details)
.property("status", Self::status_u8(status))
.property("trust-level", Self::trust_level_u8(trust_level))
.property("status", status as u8)
.property("trust-level", trust_level as u8)
.build()
}

Expand All @@ -61,23 +61,7 @@ impl VMGObject {

pub fn update(&self, query_result: QueryResult) {
self.set_property("details", query_result.description);
self.set_property("status", Self::status_u8(query_result.status));
self.set_property("trust-level", Self::trust_level_u8(query_result.trust_level));
}

pub fn trust_level_u8(value: TrustLevel) -> u8 {
match value {
TrustLevel::Secure => 0,
TrustLevel::Warning => 1,
TrustLevel::NotSecure => 2,
}
}

pub fn status_u8(value: VMStatus) -> u8 {
match value {
VMStatus::Running => 0,
VMStatus::PoweredOff => 1,
VMStatus::Paused => 2,
}
self.set_property("status", query_result.status as u8);
self.set_property("trust-level", query_result.trust_level as u8);
}
}

0 comments on commit 3a785c0

Please sign in to comment.