advotracker: update copyright header

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2020-07-11 14:45:06 +02:00
parent c5334ac898
commit b579d039f1
7 changed files with 164 additions and 115 deletions

View File

@@ -1,3 +1,10 @@
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/
use orbtk::prelude::*; use orbtk::prelude::*;
use crate::{ use crate::{

View File

@@ -1,3 +1,10 @@
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/
// CSS => transform to RON based theme system // CSS => transform to RON based theme system
// https://github.com/ron-rs/ronRon // https://github.com/ron-rs/ronRon

View File

@@ -1,8 +1,15 @@
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/
use std::error::Error; use std::error::Error;
use std::io; use std::io;
use std::process; use std::process;
/// import from csv format (Standard in) /// Testing: import from csv format (Standard in)
fn import() -> Result<(), Box<dyn Error>> { fn import() -> Result<(), Box<dyn Error>> {
// Build the CSV reader and iterate over each record. // Build the CSV reader and iterate over each record.
let mut csv_reader = csv::Reader::from_reader(io::stdin()); let mut csv_reader = csv::Reader::from_reader(io::stdin());

View File

@@ -1,3 +1,10 @@
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/
use orbtk::prelude::*; use orbtk::prelude::*;
//use orbtk::theme::vector_graphics::material_icons_font; //use orbtk::theme::vector_graphics::material_icons_font;

View File

@@ -1,3 +1,10 @@
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/
use orbtk::prelude::*; use orbtk::prelude::*;
use crate::{ use crate::{

View File

@@ -1,3 +1,10 @@
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/
use orbtk::prelude::*; use orbtk::prelude::*;
use crate::{ use crate::{
@@ -34,163 +41,163 @@ impl BaseState for PolicyListState {}
impl PolicyListState { impl PolicyListState {
/// Sets a new action. /// Sets a new action.
pub fn action(&mut self, action: Action) { pub fn action(&mut self, action: Action) {
self.action = action.into(); self.action = action.into();
} }
/// If policy data element 'name' is empty, disable the add button /// If policy data element 'name' is empty, disable the add button
/// otherwise otherwise enabled it. /// otherwise otherwise enabled it.
fn adjust_add_button_enabled(&self, text_box: Entity, ctx: &mut Context) { fn adjust_add_button_enabled(&self, text_box: Entity, ctx: &mut Context) {
/* Old syntax /* Old syntax
if ctx.get_widget(text_box).get::<String>("name").is_empty() { if ctx.get_widget(text_box).get::<String>("name").is_empty() {
ctx.get_widget(self.add_button).set("enabled", false); ctx.get_widget(self.add_button).set("enabled", false);
} else { } else {
ctx.get_widget(self.add_button).set("enabled", true); ctx.get_widget(self.add_button).set("enabled", true);
} }
ctx.get_widget(self.add_button).update_theme_by_state(true); ctx.get_widget(self.add_button).update_theme_by_state(true);
*/ */
if TextBox::get(ctx.get_widget(text_box)).text().is_empty() { if TextBox::get(ctx.get_widget(text_box)).text().is_empty() {
Button::get(ctx.child("add_button")).set_enabled(false); Button::get(ctx.child("add_button")).set_enabled(false);
} else { } else {
Button::get(ctx.child("add_button")).set_enabled(true); Button::get(ctx.child("add_button")).set_enabled(true);
} }
// new syntax not implemented yet // new syntax not implemented yet
ctx.get_widget(self.add_button).update_theme_by_state(true); ctx.get_widget(self.add_button).update_theme_by_state(true);
} }
/// update number of available policy list entries. /// update number of available policy list entries.
fn adjust_count(&self, ctx: &mut Context) { fn adjust_count(&self, ctx: &mut Context) {
let policy_list_count = ctx.widget().get::<PolicyList>(PROP_POLICY_LIST).len(); let policy_list_count = ctx.widget().get::<PolicyList>(PROP_POLICY_LIST).len();
ctx.widget().set(PROP_POLICY_LIST_COUNT, policy_list_count); ctx.widget().set(PROP_POLICY_LIST_COUNT, policy_list_count);
} }
// Creates a new policy data list. // Creates a new policy data list.
fn new_entry(&self, name: String, registry: &mut Registry, ctx: &mut Context) { fn new_entry(&self, name: String, registry: &mut Registry, ctx: &mut Context) {
ctx.widget() ctx.widget()
.get_mut::<PolicyList>(PROP_POLICY_LIST) .get_mut::<PolicyList>(PROP_POLICY_LIST)
.push(PolicyList::new(name)); .push(PolicyList::new(name));
self.adjust_count(ctx); self.adjust_count(ctx);
self.save(registry, ctx); self.save(registry, ctx);
} }
// opens a given policy list name. // opens a given policy list name.
fn open_policy_list(&self, index: usize, ctx: &mut Context) { fn open_policy_list(&self, index: usize, ctx: &mut Context) {
ctx.get_widget(self.text_box) ctx.get_widget(self.text_box)
.set("text", String16::from("")); .set("text", String16::from(""));
ctx.get_widget(self.policydata_view) ctx.get_widget(self.policydata_view)
.set("list_index", Some(index)); .set("list_index", Some(index));
self.navigate(self.policydata_view, ctx); self.navigate(self.policydata_view, ctx);
} }
// removes a policy list. // removes a policy list.
fn remove_entry(&self, index: usize, registry: &mut Registry, ctx: &mut Context) { fn remove_entry(&self, index: usize, registry: &mut Registry, ctx: &mut Context) {
ctx.widget() ctx.widget()
.get_mut::<PolicyList>(PROP_POLICY_LIST) .get_mut::<PolicyList>(PROP_POLICY_LIST)
.remove(index); .remove(index);
self.adjust_count(ctx); self.adjust_count(ctx);
self.save(registry, ctx); self.save(registry, ctx);
} }
/// Change status of given text box to edit mode. /// Change status of given text box to edit mode.
fn set_entry(&self, text_box: Entity, ctx: &mut Context) { fn set_entry(&self, text_box: Entity, ctx: &mut Context) {
if *ctx.get_widget(text_box).get::<bool>("focused") { if *ctx.get_widget(text_box).get::<bool>("focused") {
ctx.get_widget(text_box).set("enabled", false); ctx.get_widget(text_box).set("enabled", false);
ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box)); ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box));
return; return;
} }
if let Some(old_focused_element) = ctx.window().get::<Global>("global").focused_widget { if let Some(old_focused_element) = ctx.window().get::<Global>("global").focused_widget {
ctx.push_event_by_window(FocusEvent::RemoveFocus(old_focused_element)); ctx.push_event_by_window(FocusEvent::RemoveFocus(old_focused_element));
} }
ctx.get_widget(text_box).set("enabled", true); ctx.get_widget(text_box).set("enabled", true);
// select all // select all
ctx.get_widget(text_box) ctx.get_widget(text_box)
.get_mut::<TextSelection>("text_selection") .get_mut::<TextSelection>("text_selection")
.start_index = 0; .start_index = 0;
ctx.get_widget(text_box) ctx.get_widget(text_box)
.get_mut::<TextSelection>("text_selection") .get_mut::<TextSelection>("text_selection")
.length = ctx.get_widget(text_box).get::<String16>("name").len(); .length = ctx.get_widget(text_box).get::<String16>("name").len();
ctx.push_event_by_window(FocusEvent::RequestFocus(text_box)); ctx.push_event_by_window(FocusEvent::RequestFocus(text_box));
} }
} }
impl State for PolicyListState { impl State for PolicyListState {
fn init(&mut self, registry: &mut Registry, ctx: &mut Context) { fn init(&mut self, registry: &mut Registry, ctx: &mut Context) {
self.text_box = ctx self.text_box = ctx
.entity_of_child(ID_POLICY_LIST_TEXT_BOX) .entity_of_child(ID_POLICY_LIST_TEXT_BOX)
.expect("PolicyListState.init: Child 'Text box' not found."); .expect("PolicyListState.init: Child 'Text box' not found.");
self.add_button = ctx self.add_button = ctx
.entity_of_child(ID_POLICY_LIST_ADD_BUTTON) .entity_of_child(ID_POLICY_LIST_ADD_BUTTON)
.expect("PolicyListState.init: Child 'Add button' not found."); .expect("PolicyListState.init: Child 'Add button' not found.");
self.items_widget = ctx self.items_widget = ctx
.entity_of_child(ID_POLICY_LIST_ITEMS_WIDGET) .entity_of_child(ID_POLICY_LIST_ITEMS_WIDGET)
.expect("PolicyListState.init: Child 'Items widget' not found."); .expect("PolicyListState.init: Child 'Items widget' not found.");
self.policydata_view = (*ctx.widget() self.policydata_view = (*ctx.widget()
.get::<u32>("policy_list_view")).into(); .get::<u32>("policy_list_view")).into();
if let Ok(policy_list_name) = registry if let Ok(policy_list_name) = registry
.get::<Settings>("settings") .get::<Settings>("settings")
.load::<PolicyList>(PROP_POLICY_LIST) .load::<PolicyList>(PROP_POLICY_LIST)
{ {
ctx.widget().set(PROP_POLICY_LIST, policy_list_name); ctx.widget().set(PROP_POLICY_LIST, policy_list_name);
} }
self.adjust_count(ctx); self.adjust_count(ctx);
} }
fn update(&mut self, registry: &mut Registry, ctx: &mut Context) { fn update(&mut self, registry: &mut Registry, ctx: &mut Context) {
// clear focus on focus moved // clear focus on focus moved
if self.last_focused != ctx.window().get::<Global>("global").focused_widget { if self.last_focused != ctx.window().get::<Global>("global").focused_widget {
if let Some(last_focused) = self.last_focused { if let Some(last_focused) = self.last_focused {
ctx.get_widget(last_focused).set("focused", false); ctx.get_widget(last_focused).set("focused", false);
ctx.get_widget(last_focused) ctx.get_widget(last_focused)
.set("visibility", Visibility::Collapsed); .set("visibility", Visibility::Collapsed);
} }
} }
if let Some(action) = self.action { if let Some(action) = self.action {
match action { match action {
Action::InputTextChanged(text_box) => { Action::InputTextChanged(text_box) => {
self.adjust_add_button_enabled(text_box, ctx); self.adjust_add_button_enabled(text_box, ctx);
} }
Action::NewEntry(entity) => { Action::NewEntry(entity) => {
if let Some(name) = self.fetch_text(ctx, entity) { if let Some(name) = self.fetch_text(ctx, entity) {
self.new_entry(name, registry, ctx); self.new_entry(name, registry, ctx);
} }
} }
Action::RemoveEntry(index) => { Action::RemoveEntry(index) => {
self.remove_entry(index, registry, ctx); self.remove_entry(index, registry, ctx);
} }
Action::TextChanged(entity, index) => { Action::TextChanged(entity, index) => {
let text: String16 = ctx.get_widget(entity).clone("text"); let text: String16 = ctx.get_widget(entity).clone("text");
if let Some(header) = ctx if let Some(header) = ctx
.widget() .widget()
.get_mut::<PolicyList>("policy_list") .get_mut::<PolicyList>("policy_list")
.get_mut(index) .get_mut(index)
{ {
header.name = text.to_string(); header.name = text.to_string();
} }
self.save(registry, ctx); self.save(registry, ctx);
} }
Action::SetEntry(text_box) => { Action::SetEntry(text_box) => {
self.last_focused = Some(text_box); self.last_focused = Some(text_box);
self.set_entry(text_box, ctx); self.set_entry(text_box, ctx);
} }
Action::RemoveFocus(text_box) => { Action::RemoveFocus(text_box) => {
self.last_focused = None; self.last_focused = None;
ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box)); ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box));
} }
Action::OpenPolicyList(index) => { Action::OpenPolicyList(index) => {
self.open_policy_list(index, ctx); self.open_policy_list(index, ctx);
} }
} }
} }
self.action = None; self.action = None;
} }
} }

View File

@@ -1,3 +1,10 @@
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/
use orbtk::prelude::*; use orbtk::prelude::*;
use crate::{ use crate::{