Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]: Implement Language & Region page #3

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ gio = { version = "0.20.0", features = ["v2_74"] }
clap = { version = "4.4", features = ["derive"] }

prost = "0.12"
tokio = {version = "1.0", features = ["rt-multi-thread", "time", "macros"]}
tokio = {version = "1.0", features = ["rt", "time", "macros"]}
tokio-stream = "0.1"
tonic = {version="0.11.0", features = ["tls"]}
async-channel = "2.3"

givc-client = { git = "https://github.com/tiiuae/ghaf-givc", branch = "main" }
givc-common = { git = "https://github.com/tiiuae/ghaf-givc", branch = "main" }
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
);

Ok(())
}
}
39 changes: 20 additions & 19 deletions src/add_network_popup.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::cell::RefCell;
use std::sync::OnceLock;
use glib::subclass::Signal;
use glib::Binding;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{gio, glib, CompositeTemplate, Entry, Button};
use glib::Binding;
use glib::subclass::Signal;
use gtk::{gio, glib, Button, CompositeTemplate, Entry};
use std::cell::RefCell;
use std::sync::OnceLock;

mod imp {
use super::*;
Expand Down Expand Up @@ -34,8 +34,8 @@ mod imp {
type ParentType = gtk::Window;

fn class_init(klass: &mut Self::Class) {
klass.bind_template();
klass.bind_template_callbacks();
klass.bind_template();
klass.bind_template_callbacks();
}

fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
Expand All @@ -48,20 +48,21 @@ mod imp {
#[template_callback]
fn on_switch_state_changed(&self, value: bool) -> bool {
self.password_entry.set_visibility(value);
false//propagate event futher
false //propagate event futher
}
#[template_callback]
fn on_save_clicked(&self) {
let name = self.name_entry.text().to_string();
let sec = self.security_entry.text().to_string();
let passwd = self.password_entry.text().to_string();
self.obj().emit_by_name::<()>("new-network", &[&name, &sec, &passwd]);
self.obj()
.emit_by_name::<()>("new-network", &[&name, &sec, &passwd]);
}
#[template_callback]
fn on_cancel_clicked(&self) {
self.obj().close();
}
}//end #[gtk::template_callbacks]
} //end #[gtk::template_callbacks]

impl ObjectImpl for AddNetworkPopup {
fn constructed(&self) {
Expand All @@ -76,11 +77,13 @@ mod imp {
fn signals() -> &'static [Signal] {
static SIGNALS: OnceLock<Vec<Signal>> = OnceLock::new();
SIGNALS.get_or_init(|| {
vec![
Signal::builder("new-network")
.param_types([String::static_type(), String::static_type(), String::static_type()])
.build()
]
vec![Signal::builder("new-network")
.param_types([
String::static_type(),
String::static_type(),
String::static_type(),
])
.build()]
})
}
}
Expand All @@ -105,7 +108,5 @@ impl AddNetworkPopup {
glib::Object::builder().build()
}

pub fn init(&self) {

}
}
pub fn init(&self) {}
}
25 changes: 10 additions & 15 deletions src/admin_settings_page.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::cell::RefCell;
use std::sync::OnceLock;
use glib::subclass::Signal;
use glib::Binding;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{glib, CompositeTemplate, Notebook};
use glib::Binding;
use glib::subclass::Signal;
use std::cell::RefCell;
use std::sync::OnceLock;

use crate::settings_gobject::SettingsGObject;

Expand All @@ -28,8 +28,8 @@ mod imp {
type ParentType = gtk::Box;

fn class_init(klass: &mut Self::Class) {
klass.bind_template();
klass.bind_template_callbacks();
klass.bind_template();
klass.bind_template_callbacks();
}

fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
Expand All @@ -44,7 +44,7 @@ mod imp {
println!("Update clicked!");
self.obj().emit_by_name::<()>("update-request", &[]);
}
}//end #[gtk::template_callbacks]
} //end #[gtk::template_callbacks]

impl ObjectImpl for AdminSettingsPage {
fn constructed(&self) {
Expand All @@ -58,11 +58,9 @@ mod imp {
fn signals() -> &'static [Signal] {
static SIGNALS: OnceLock<Vec<Signal>> = OnceLock::new();
SIGNALS.get_or_init(|| {
vec![
Signal::builder("update-request")
vec![Signal::builder("update-request")
//.param_types([u32::static_type()])
.build(),
]
.build()]
})
}
}
Expand All @@ -85,9 +83,7 @@ impl AdminSettingsPage {
pub fn new() -> Self {
glib::Object::builder().build()
}
pub fn init(&self) {

}
pub fn init(&self) {}

pub fn bind(&self, settings_object: &SettingsGObject) {
//unbind previous ones
Expand All @@ -102,4 +98,3 @@ impl AdminSettingsPage {
}
}
}

115 changes: 71 additions & 44 deletions src/application.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@

use std::cell::RefCell;
use std::rc::Rc;
use gtk::prelude::*;
use adw::subclass::prelude::*;
use gtk::{gio, glib, gdk};
use gtk::CssProvider;
use glib::Variant;
use gtk::prelude::*;
use gtk::CssProvider;
use gtk::{gdk, gio, glib};
use std::cell::RefCell;
use std::rc::Rc;

use crate::ControlPanelGuiWindow;
use crate::data_provider::imp::DataProvider;
use crate::add_network_popup::AddNetworkPopup;
use crate::connection_config::ConnectionConfig;
use crate::vm_control_action::VMControlAction;
use crate::data_provider::imp::DataProvider;
use crate::settings_action::SettingsAction;
use crate::add_network_popup::AddNetworkPopup;
use crate::vm_control_action::VMControlAction;
use crate::ControlPanelGuiWindow;

mod imp {
use super::*;
Expand Down Expand Up @@ -65,7 +64,11 @@ mod imp {
// Ask the window manager/compositor to present the window
window.present();
//connect on start
application.imp().data_provider.borrow().establish_connection();
application
.imp()
.data_provider
.borrow()
.establish_connection();
}
}

Expand All @@ -80,13 +83,21 @@ glib::wrapper! {
}

impl ControlPanelGuiApplication {
pub fn new(application_id: &str, flags: &gio::ApplicationFlags, address: String, port: u16) -> Self {
pub fn new(
application_id: &str,
flags: &gio::ApplicationFlags,
address: String,
port: u16,
) -> Self {
let app: Self = glib::Object::builder()
.property("application-id", application_id)
.property("flags", flags)
.build();

app.imp().data_provider.borrow().set_service_address(address, port);
app.imp()
.data_provider
.borrow()
.set_service_address(address, port);

app
}
Expand Down Expand Up @@ -117,30 +128,38 @@ impl ControlPanelGuiApplication {
let about_action = gio::ActionEntry::builder("about")
.activate(move |app: &Self, _, _| app.show_about())
.build();
self.add_action_entries([reconnect_action, show_config_action, quit_action, about_action]);
self.add_action_entries([
reconnect_action,
show_config_action,
quit_action,
about_action,
]);
}

pub fn show_config(&self) {
let window = self.active_window().unwrap();
let address = self.imp().data_provider.borrow().get_current_service_address();
let address = self
.imp()
.data_provider
.borrow()
.get_current_service_address();
let config = ConnectionConfig::new(address.0, address.1);
config.set_transient_for(Some(&window));
config.set_modal(true);

let app = self.clone();

config.connect_local(
"new-config-applied",
false,
move |values| {
//the value[0] is self
let addr = values[1].get::<String>().unwrap();
let port = values[2].get::<u32>().unwrap();
println!("New config applied: address {addr}, port {port}");
app.imp().data_provider.borrow().reconnect(Some((addr, port as u16)));
None
},
);
config.connect_local("new-config-applied", false, move |values| {
//the value[0] is self
let addr = values[1].get::<String>().unwrap();
let port = values[2].get::<u32>().unwrap();
println!("New config applied: address {addr}, port {port}");
app.imp()
.data_provider
.borrow()
.reconnect(Some((addr, port as u16)));
None
});

config.present();
}
Expand All @@ -164,7 +183,7 @@ impl ControlPanelGuiApplication {
self.imp().data_provider.borrow().reconnect(None);
}

pub fn get_store(&self) -> gio::ListStore{
pub fn get_store(&self) -> gio::ListStore {
self.imp().data_provider.borrow().get_store()
}

Expand All @@ -183,7 +202,17 @@ impl ControlPanelGuiApplication {
match action {
SettingsAction::AddNetwork => todo!(),
SettingsAction::RemoveNetwork => todo!(),
SettingsAction::RegionNLanguage => todo!(),
SettingsAction::RegionNLanguage => {
let (locale, timezone) : (String, String) = value.get().unwrap();
self.imp()
.data_provider
.borrow()
.set_locale(locale);
self.imp()
.data_provider
.borrow()
.set_timezone(timezone);
}
SettingsAction::DateNTime => todo!(),
SettingsAction::MouseSpeed => todo!(),
SettingsAction::KeyboardLayout => todo!(),
Expand All @@ -197,23 +226,21 @@ impl ControlPanelGuiApplication {
let popup = AddNetworkPopup::new();
popup.set_transient_for(Some(&window));
popup.set_modal(true);
popup.connect_local(
"new-network",
false,
move |values| {
//the value[0] is self
let name = values[1].get::<String>().unwrap();
let security = values[2].get::<String>().unwrap();
let password = values[3].get::<String>().unwrap();
println!("New network: {name}, {security}, {password}");
app.imp().data_provider.borrow().add_network(name, security, password);
None
},
);
popup.connect_local("new-network", false, move |values| {
//the value[0] is self
let name = values[1].get::<String>().unwrap();
let security = values[2].get::<String>().unwrap();
let password = values[3].get::<String>().unwrap();
println!("New network: {name}, {security}, {password}");
app.imp()
.data_provider
.borrow()
.add_network(name, security, password);
None
});
popup.present();
},
SettingsAction::ShowAddKeyboardPopup => {
}
SettingsAction::ShowAddKeyboardPopup => {}
};
}

Expand Down
Loading