Skip to content

Commit 8cc2cf7

Browse files
author
Deren Vural
committed
Working "Add Views" button
Updated GpuPage UI: - Removed some now uneeded comments Updated MainWindow class: - Commented some unused debug print statements Updated GpuPage class: - Commented some unused debug print statements - Removed commented-out object properties - Refactored messages that appear when an empty view is present OR no views at all - Added an "Add View" button, can now add new views! - "Add View" button is only button shown when no views (no edit button) - view id of "-1" given for new views now Updated ModificationWindow class: - Updated "update_stored_data()" function to properly take into account dropdowns (add new cases needed it) - Fixed a bug that made all new views start at position 0, now adds a new view to the end (will probably be changed in future) - Fixed handling in "setup_widgets()" function for new+first views - Updated to hide delete button when adding a new view - Removed some now uneeded psuedocode Signed-off-by: Deren Vural <[email protected]>
1 parent 76e6927 commit 8cc2cf7

File tree

5 files changed

+238
-173
lines changed

5 files changed

+238
-173
lines changed

src/gpu_page/mod.rs

Lines changed: 129 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ impl GpuPage {
155155

156156
// Load list of Views
157157
let loaded_views_data: Vec<String> = settings_obj.get::<Vec<String>>("viewconfigs");
158-
println!("views saved:`{}`", loaded_views_data.len()); //TEST
159-
println!("views saved:`{:?}`", loaded_views_data); //TEST
158+
// println!("views saved:`{}`", loaded_views_data.len()); //TEST
159+
// println!("views saved:`{:?}`", loaded_views_data); //TEST
160160

161161
// Remove old content grid
162162
match self.child_at(0, 0) {
@@ -181,54 +181,39 @@ impl GpuPage {
181181
let new_grid: Grid = Grid::builder()
182182
.name(&new_grid_name)
183183
.orientation(Orientation::Horizontal)
184-
//.margin_start(12)
185-
//.margin_end(12)
186-
//.margin_top(12)
187-
//.margin_bottom(12)
188-
//.halign(Align::Center)
189-
//.valign(Align::Center)
190-
//.hexpand(true)
191-
//.vexpand(true)
192184
.build();
193185
content_grid.attach(&new_grid, 0, 0 as i32, 100, 12);
194186

195-
// Set layout properties of grid
196-
//let child_manager: LayoutChild = grid_manager.layout_child(&new_grid);
197-
//child_manager.set_property("row-span", 1);
198-
//child_manager.set_property("column-span", 1);
199-
200187
// Build title label & add to grid
201188
let label_value: String =
202-
String::from("Please edit the list of Views using 'Edit Views' button");
189+
String::from("Please add a View using 'Add View' button");
203190
let new_title_label: Label = Label::builder()
204191
.label(&label_value)
205192
.name("default")
206193
.hexpand(true)
207194
.hexpand_set(true)
208195
.halign(Align::Center)
209-
//.valign(Align::Center)
210196
.margin_top(40)
211197
.margin_bottom(40)
212-
//.width_chars(space)
213198
.build();
214199
new_grid.attach(&new_title_label, 1, 1, 1, 1);
215200

216201
// Add edit button for current view
217202
// Fetch grid's layout manager
218203
match new_grid.layout_manager() {
219204
Some(grid_manager) => {
220-
// Create edit button
221-
let edit_button: Button = Button::builder()
222-
.name("edit_button")
223-
.label("Edit View")
205+
// Create add_view_button
206+
let add_view_button: Button = Button::builder()
207+
.name("add_view_button")
208+
.label("Add View")
224209
.margin_start(12)
225210
.margin_end(12)
226211
.margin_top(12)
227212
.margin_bottom(12)
228213
.halign(Align::Center)
229214
.build();
230-
new_grid.attach(&edit_button, 0, 80, 1, 1);
231-
edit_button.connect_clicked(clone!(@weak self as gpage => move |_| {
215+
new_grid.attach(&add_view_button, 0, 80 as i32, 1, 1);
216+
add_view_button.connect_clicked(clone!(@weak self as gpage => move |_| {
232217
// Create modification window
233218
// Borrow (mutable) the window's container
234219
let mut modification_window_container: RefMut<ModificationWindowContainer> = gpage.imp().modification_window.borrow_mut();
@@ -239,18 +224,18 @@ impl GpuPage {
239224
// Check if an object is stored
240225
match &modification_window_container.window {
241226
Some(_window) => {
242-
println!("..window exists");//DEBUG
227+
// println!("..window exists");//DEBUG
243228

244229
// Check if the window is already open
245230
match modification_window_container.open {
246231
false => {
247-
println!("....opening window");//DEBUG
232+
// println!("....opening window");//DEBUG
248233

249234
// Create an app object
250235
let app: Application = Application::builder().application_id(APP_ID).build();
251236

252237
// Create new modification window
253-
let new_modification_window: ModificationWindow = ModificationWindow::new(&app, 0, &gpage.property::<String>("uuid"), &gpage);
238+
let new_modification_window: ModificationWindow = ModificationWindow::new(&app, -1, &gpage.property::<String>("uuid"), &gpage);
254239

255240
// Show new modification window
256241
new_modification_window.show();
@@ -265,14 +250,14 @@ impl GpuPage {
265250
}
266251
},
267252
None => {
268-
println!("..window does not exist");//DEBUG
269-
println!("....opening window");//DEBUG
253+
// println!("..window does not exist");//DEBUG
254+
// println!("....opening window");//DEBUG
270255

271256
// Create an app object
272257
let app: Application = Application::builder().application_id(APP_ID).build();
273258

274259
// Create modification window
275-
let new_modification_window: ModificationWindow = ModificationWindow::new(&app, 0, &gpage.property::<String>("uuid"), &gpage);
260+
let new_modification_window: ModificationWindow = ModificationWindow::new(&app, -1, &gpage.property::<String>("uuid"), &gpage);
276261

277262
// Show new modification window
278263
new_modification_window.show();
@@ -288,7 +273,7 @@ impl GpuPage {
288273
}));
289274

290275
// Set layout properties of button
291-
let child_manager: LayoutChild = grid_manager.layout_child(&edit_button);
276+
let child_manager: LayoutChild = grid_manager.layout_child(&add_view_button);
292277
child_manager.set_property("row-span", 2);
293278
child_manager.set_property("column-span", 2);
294279
}
@@ -316,7 +301,7 @@ impl GpuPage {
316301

317302
// For each loaded view
318303
for index in 0..loaded_views_data.len() {
319-
println!("item: `{}`", loaded_views_data[index]); //TEST
304+
// println!("item: `{}`", loaded_views_data[index]); //TEST
320305

321306
// Split current item into the 4 parts
322307
let parts: Vec<&str> = loaded_views_data[index].split(':').collect::<Vec<&str>>();
@@ -354,13 +339,13 @@ impl GpuPage {
354339
// Grab all saved properties
355340
let properties: Vec<String> = self.check_properties_for_view(&loaded_views[index]);
356341

342+
// println!("GOT {} PROPERTIES FOR VIEW {}", properties.len(), index);
343+
357344
// Add property items to the final list
358345
for prop in &properties {
359346
props.push(prop.as_str().clone().to_owned());
360347
}
361348

362-
// println!("GOT {} PROPERTIES FOR VIEW {}", properties.len(), index);
363-
364349
// Create new view
365350
let new_grid_name: String = index.to_string() + "_grid";
366351
let new_grid: Grid = Grid::builder()
@@ -383,6 +368,23 @@ impl GpuPage {
383368
let new_view_grid: Grid = output.0;
384369
labels = output.1;
385370

371+
// If no labels (from no properties)
372+
if labels.len() == 0 {
373+
// Build title label & add to grid
374+
let label_value: String =
375+
String::from("Please edit this View using 'Edit View' button");
376+
let new_title_label: Label = Label::builder()
377+
.label(&label_value)
378+
.name("default")
379+
.hexpand(true)
380+
.hexpand_set(true)
381+
.halign(Align::Center)
382+
.margin_top(40)
383+
.margin_bottom(40)
384+
.build();
385+
new_view_grid.attach(&new_title_label, 1, 1, 1, 1);
386+
}
387+
386388
// Add edit button for current view
387389
// Fetch grid's layout manager
388390
match new_view_grid.layout_manager() {
@@ -409,12 +411,12 @@ impl GpuPage {
409411
// Check if an object is stored
410412
match &modification_window_container.window {
411413
Some(_window) => {
412-
println!("..window exists");//DEBUG
414+
// println!("..window exists");//DEBUG
413415

414416
// Check if the window is already open
415417
match modification_window_container.open {
416418
false => {
417-
println!("....opening window");//DEBUG
419+
// println!("....opening window");//DEBUG
418420

419421
// Create an app object
420422
let app: Application = Application::builder().application_id(APP_ID).build();
@@ -435,8 +437,8 @@ impl GpuPage {
435437
}
436438
},
437439
None => {
438-
println!("..window does not exist");//DEBUG
439-
println!("....opening window");//DEBUG
440+
// println!("..window does not exist");//DEBUG
441+
// println!("....opening window");//DEBUG
440442

441443
// Create an app object
442444
let app: Application = Application::builder().application_id(APP_ID).build();
@@ -461,6 +463,82 @@ impl GpuPage {
461463
let child_manager: LayoutChild = grid_manager.layout_child(&edit_button);
462464
child_manager.set_property("row-span", 2);
463465
child_manager.set_property("column-span", 2);
466+
467+
468+
// Create add_view_button
469+
let add_view_button: Button = Button::builder()
470+
.name("add_view_button")
471+
.label("Add View")
472+
.margin_start(12)
473+
.margin_end(12)
474+
.margin_top(12)
475+
.margin_bottom(12)
476+
.halign(Align::Center)
477+
.build();
478+
new_view_grid.attach(&add_view_button, 0, 82 as i32, 1, 1);
479+
add_view_button.connect_clicked(clone!(@weak self as gpage => move |_| {
480+
// Create modification window
481+
// Borrow (mutable) the window's container
482+
let mut modification_window_container: RefMut<ModificationWindowContainer> = gpage.imp().modification_window.borrow_mut();
483+
484+
// Get state from settings
485+
modification_window_container.open = gpage.imp().get_setting::<bool>("modification-open");
486+
487+
// Check if an object is stored
488+
match &modification_window_container.window {
489+
Some(_window) => {
490+
// println!("..window exists");//DEBUG
491+
492+
// Check if the window is already open
493+
match modification_window_container.open {
494+
false => {
495+
// println!("....opening window");//DEBUG
496+
497+
// Create an app object
498+
let app: Application = Application::builder().application_id(APP_ID).build();
499+
500+
// Create new modification window
501+
let new_modification_window: ModificationWindow = ModificationWindow::new(&app, -1, &gpage.property::<String>("uuid"), &gpage);
502+
503+
// Show new modification window
504+
new_modification_window.show();
505+
506+
// Store object and state back in container
507+
modification_window_container.open = true;
508+
modification_window_container.window = Some(new_modification_window);
509+
},
510+
true => {
511+
println!("....window already open");//DEBUG
512+
},
513+
}
514+
},
515+
None => {
516+
// println!("..window does not exist");//DEBUG
517+
// println!("....opening window");//DEBUG
518+
519+
// Create an app object
520+
let app: Application = Application::builder().application_id(APP_ID).build();
521+
522+
// Create modification window
523+
let new_modification_window: ModificationWindow = ModificationWindow::new(&app, -1, &gpage.property::<String>("uuid"), &gpage);
524+
525+
// Show new modification window
526+
new_modification_window.show();
527+
528+
// Store object and state back in container
529+
modification_window_container.open = true;
530+
modification_window_container.window = Some(new_modification_window);
531+
},
532+
}
533+
534+
// Set new state in settings
535+
gpage.imp().update_setting::<bool>("modification-open", modification_window_container.open);
536+
}));
537+
538+
// Set layout properties of button
539+
let child_manager: LayoutChild = grid_manager.layout_child(&add_view_button);
540+
child_manager.set_property("row-span", 2);
541+
child_manager.set_property("column-span", 2);
464542
}
465543
None => panic!("Cannot fetch layout manager of grid.."),
466544
}
@@ -481,7 +559,12 @@ impl GpuPage {
481559
new_item.set_icon_name(Some("package-x-generic-symbolic"));
482560
}
483561

484-
self.create_updater(labels, props);
562+
// if properties exist, call create_updater() function to add time-delayed callback to update appropriate labels
563+
if props.len() > 0 {
564+
self.create_updater(labels, props);
565+
} // else {
566+
// println!("No properties, no callbacks!");
567+
// }
485568

486569
// Replace current view stack
487570
self.imp().replace_stack(Some(&new_stack));
@@ -511,17 +594,14 @@ impl GpuPage {
511594
// Load list of Properties for current Page
512595
let loaded_properties_data: Vec<String> =
513596
settings_obj.get::<Vec<String>>("viewcomponentconfigs");
514-
// println!("items saved:`{}`", loaded_properties_data.len()); //TEST
597+
// println!("items saved #: `{}`", loaded_properties_data.len()); //TEST
598+
// println!("items saved: `{:?}`", loaded_properties_data); //TEST
515599

516600
// If present in saved settings, use! otherwise follow below defaults
517601
if let 0 = loaded_properties_data.len() {
518-
match self
519-
.property::<Provider>("provider")
520-
.property::<i32>("provider-type")
521-
{
522-
-1 => vec![String::from("choose_provider")],
523-
_ => vec![String::from("choose_properties")],
524-
}
602+
// println!("no properties.."); //TEST
603+
604+
vec![]
525605
} else {
526606
// Create temporary structure for sorting loaded data
527607
let mut loaded_properties: Vec<String> =
@@ -552,8 +632,7 @@ impl GpuPage {
552632
match parts[2].parse::<usize>() {
553633
Ok(position) => {
554634
if position <= loaded_properties_data.len() {
555-
// println!("VALID POSITION INDEX: `{}`", position); //TEST
556-
635+
// println!("VALID POSITION INDEX: `{}`", offset_position); //TEST
557636
// println!("VALID PROPERTY: `{}`", parts[3]); //TEST
558637

559638
// Add to final list
@@ -596,6 +675,7 @@ impl GpuPage {
596675
properties: Vec<String>,
597676
mut labels: Vec<Label>,
598677
) -> (Grid, Vec<Label>) {
678+
599679
// Load properties from struct
600680
let properties_store: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(properties));
601681

src/mainwindow/imp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ impl MainWindow {
13821382
*/
13831383
#[template_callback]
13841384
fn refresh_cards(&self, _button: &Button) {
1385-
println!("GPU Scan Button Pressed!"); //TEST
1385+
// println!("GPU Scan Button Pressed!"); //TEST
13861386

13871387
// Clear current ActionRow objects from GtkListBox
13881388
let mut done: bool = false;
@@ -1512,7 +1512,7 @@ impl MainWindow {
15121512
Ok(gpu_uuids) => {
15131513
// Construct a row for each GPU
15141514
for uuid in gpu_uuids {
1515-
println!("UUID: `{}`", uuid); //TEST
1515+
// println!("UUID: `{}`", uuid); //TEST
15161516
// Grab current provider
15171517
let provider_container: Option<Provider> = self.provider.take();
15181518
self.provider.set(provider_container.clone());

0 commit comments

Comments
 (0)