mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-02-05 02:38:08 -05:00
Tiny misc code improvements
This commit is contained in:
parent
c2d226d58e
commit
1fde947f36
@ -198,7 +198,7 @@ pub struct NewLimit {
|
|||||||
/// This is expected to be performed from `moonfire-nvr config` when no syncer is running.
|
/// This is expected to be performed from `moonfire-nvr config` when no syncer is running.
|
||||||
/// It potentially flushes the database twice (before and after the actual deletion).
|
/// It potentially flushes the database twice (before and after the actual deletion).
|
||||||
pub fn lower_retention(
|
pub fn lower_retention(
|
||||||
db: Arc<db::Database>,
|
db: &Arc<db::Database>,
|
||||||
dir_id: i32,
|
dir_id: i32,
|
||||||
limits: &[NewLimit],
|
limits: &[NewLimit],
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
@ -77,28 +77,28 @@ fn get_camera(siv: &mut Cursive) -> Camera {
|
|||||||
};
|
};
|
||||||
for &t in &db::ALL_STREAM_TYPES {
|
for &t in &db::ALL_STREAM_TYPES {
|
||||||
let url = siv
|
let url = siv
|
||||||
.find_name::<views::EditView>(&format!("{}_url", t.as_str()))
|
.find_name::<views::EditView>(&format!("{}_url", t))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.get_content()
|
.get_content()
|
||||||
.as_str()
|
.as_str()
|
||||||
.to_owned();
|
.to_owned();
|
||||||
let record = siv
|
let record = siv
|
||||||
.find_name::<views::Checkbox>(&format!("{}_record", t.as_str()))
|
.find_name::<views::Checkbox>(&format!("{}_record", t))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.is_checked();
|
.is_checked();
|
||||||
let rtsp_transport = *siv
|
let rtsp_transport = *siv
|
||||||
.find_name::<views::SelectView<&'static str>>(&format!("{}_rtsp_transport", t.as_str()))
|
.find_name::<views::SelectView<&'static str>>(&format!("{}_rtsp_transport", t))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.selection()
|
.selection()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let flush_if_sec = siv
|
let flush_if_sec = siv
|
||||||
.find_name::<views::EditView>(&format!("{}_flush_if_sec", t.as_str()))
|
.find_name::<views::EditView>(&format!("{}_flush_if_sec", t))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.get_content()
|
.get_content()
|
||||||
.as_str()
|
.as_str()
|
||||||
.to_owned();
|
.to_owned();
|
||||||
let sample_file_dir_id = *siv
|
let sample_file_dir_id = *siv
|
||||||
.find_name::<views::SelectView<Option<i32>>>(&format!("{}_sample_file_dir", t.as_str()))
|
.find_name::<views::SelectView<Option<i32>>>(&format!("{}_sample_file_dir", t))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.selection()
|
.selection()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -367,9 +367,8 @@ fn confirm_deletion(siv: &mut Cursive, db: &Arc<db::Database>, id: i32, to_delet
|
|||||||
let l = db.lock();
|
let l = db.lock();
|
||||||
for (&stream_id, stream) in l.streams_by_id() {
|
for (&stream_id, stream) in l.streams_by_id() {
|
||||||
if stream.camera_id == id {
|
if stream.camera_id == id {
|
||||||
let dir_id = match stream.sample_file_dir_id {
|
let Some(dir_id) = stream.sample_file_dir_id else {
|
||||||
Some(d) => d,
|
continue
|
||||||
None => continue,
|
|
||||||
};
|
};
|
||||||
let l = zero_limits
|
let l = zero_limits
|
||||||
.entry(dir_id)
|
.entry(dir_id)
|
||||||
@ -406,7 +405,7 @@ fn lower_retention(
|
|||||||
let dirs_to_open: Vec<_> = zero_limits.keys().copied().collect();
|
let dirs_to_open: Vec<_> = zero_limits.keys().copied().collect();
|
||||||
db.lock().open_sample_file_dirs(&dirs_to_open[..])?;
|
db.lock().open_sample_file_dirs(&dirs_to_open[..])?;
|
||||||
for (&dir_id, l) in &zero_limits {
|
for (&dir_id, l) in &zero_limits {
|
||||||
writer::lower_retention(db.clone(), dir_id, l)?;
|
writer::lower_retention(db, dir_id, l)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -441,10 +440,7 @@ fn edit_camera_dialog(db: &Arc<db::Database>, siv: &mut Cursive, item: &Option<i
|
|||||||
let camera_list = views::ListView::new()
|
let camera_list = views::ListView::new()
|
||||||
.child(
|
.child(
|
||||||
"id",
|
"id",
|
||||||
views::TextView::new(match *item {
|
views::TextView::new(item.map_or_else(|| "<new>".to_string(), |id| id.to_string())),
|
||||||
None => "<new>".to_string(),
|
|
||||||
Some(id) => id.to_string(),
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
.child("uuid", views::TextView::new("<new>").with_name("uuid"))
|
.child("uuid", views::TextView::new("<new>").with_name("uuid"))
|
||||||
.child("short name", views::EditView::new().with_name("short_name"))
|
.child("short name", views::EditView::new().with_name("short_name"))
|
||||||
@ -481,18 +477,18 @@ fn edit_camera_dialog(db: &Arc<db::Database>, siv: &mut Cursive, item: &Option<i
|
|||||||
views::EditView::new()
|
views::EditView::new()
|
||||||
.on_edit(move |siv, content, _pos| {
|
.on_edit(move |siv, content, _pos| {
|
||||||
let test_button = siv
|
let test_button = siv
|
||||||
.find_name::<views::Button>(&format!("{}_test", type_.as_str()))
|
.find_name::<views::Button>(&format!("{}_test", type_))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
edit_stream_url(type_, content, test_button);
|
edit_stream_url(type_, content, test_button);
|
||||||
})
|
})
|
||||||
.with_name(format!("{}_url", type_.as_str()))
|
.with_name(format!("{}_url", type_))
|
||||||
.full_width(),
|
.full_width(),
|
||||||
)
|
)
|
||||||
.child(views::DummyView)
|
.child(views::DummyView)
|
||||||
.child(
|
.child(
|
||||||
views::Button::new("Test", move |siv| press_test(siv, type_))
|
views::Button::new("Test", move |siv| press_test(siv, type_))
|
||||||
.disabled()
|
.disabled()
|
||||||
.with_name(format!("{}_test", type_.as_str())),
|
.with_name(format!("{}_test", type_)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@ -500,30 +496,30 @@ fn edit_camera_dialog(db: &Arc<db::Database>, siv: &mut Cursive, item: &Option<i
|
|||||||
views::SelectView::<Option<i32>>::new()
|
views::SelectView::<Option<i32>>::new()
|
||||||
.with_all(dirs.iter().map(|(p, id)| (p.display().to_string(), *id)))
|
.with_all(dirs.iter().map(|(p, id)| (p.display().to_string(), *id)))
|
||||||
.popup()
|
.popup()
|
||||||
.with_name(format!("{}_sample_file_dir", type_.as_str())),
|
.with_name(format!("{}_sample_file_dir", type_)),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
"record",
|
"record",
|
||||||
views::Checkbox::new().with_name(format!("{}_record", type_.as_str())),
|
views::Checkbox::new().with_name(format!("{}_record", type_)),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
"rtsp_transport",
|
"rtsp_transport",
|
||||||
views::SelectView::<&str>::new()
|
views::SelectView::<&str>::new()
|
||||||
.with_all([("(default)", ""), ("tcp", "tcp"), ("udp", "udp")])
|
.with_all([("(default)", ""), ("tcp", "tcp"), ("udp", "udp")])
|
||||||
.popup()
|
.popup()
|
||||||
.with_name(format!("{}_rtsp_transport", type_.as_str())),
|
.with_name(format!("{}_rtsp_transport", type_)),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
"flush_if_sec",
|
"flush_if_sec",
|
||||||
views::EditView::new().with_name(format!("{}_flush_if_sec", type_.as_str())),
|
views::EditView::new().with_name(format!("{}_flush_if_sec", type_)),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
"usage/capacity",
|
"usage/capacity",
|
||||||
views::TextView::new("").with_name(format!("{}_usage_cap", type_.as_str())),
|
views::TextView::new("").with_name(format!("{}_usage_cap", type_)),
|
||||||
)
|
)
|
||||||
.min_height(5);
|
.min_height(5);
|
||||||
layout.add_child(views::DummyView);
|
layout.add_child(views::DummyView);
|
||||||
layout.add_child(views::TextView::new(format!("{} stream", type_.as_str())));
|
layout.add_child(views::TextView::new(format!("{} stream", type_)));
|
||||||
layout.add_child(list);
|
layout.add_child(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,14 +592,13 @@ fn edit_camera_dialog(db: &Arc<db::Database>, siv: &mut Cursive, item: &Option<i
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
dialog.call_on_name(
|
dialog.call_on_name(&format!("{}_flush_if_sec", t), |v: &mut views::EditView| {
|
||||||
&format!("{}_flush_if_sec", t.as_str()),
|
v.set_content(s.config.flush_if_sec.to_string())
|
||||||
|v: &mut views::EditView| v.set_content(s.config.flush_if_sec.to_string()),
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
log::debug!("setting {} dir to {}", t.as_str(), selected_dir);
|
log::debug!("setting {} dir to {}", t.as_str(), selected_dir);
|
||||||
dialog.call_on_name(
|
dialog.call_on_name(
|
||||||
&format!("{}_sample_file_dir", t.as_str()),
|
&format!("{}_sample_file_dir", t),
|
||||||
|v: &mut views::SelectView<Option<i32>>| v.set_selection(selected_dir),
|
|v: &mut views::SelectView<Option<i32>>| v.set_selection(selected_dir),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -616,8 +611,7 @@ fn edit_camera_dialog(db: &Arc<db::Database>, siv: &mut Cursive, item: &Option<i
|
|||||||
.config
|
.config
|
||||||
.onvif_base_url
|
.onvif_base_url
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(Url::as_str)
|
.map_or("", Url::as_str),
|
||||||
.unwrap_or(""),
|
|
||||||
),
|
),
|
||||||
("username", &camera.config.username),
|
("username", &camera.config.username),
|
||||||
("password", &camera.config.password),
|
("password", &camera.config.password),
|
||||||
@ -666,7 +660,7 @@ pub fn top_dialog(db: &Arc<db::Database>, siv: &mut Cursive) {
|
|||||||
let db = db.clone();
|
let db = db.clone();
|
||||||
move |siv, item| edit_camera_dialog(&db, siv, item)
|
move |siv, item| edit_camera_dialog(&db, siv, item)
|
||||||
})
|
})
|
||||||
.item("<new camera>".to_string(), None)
|
.item("<new camera>", None)
|
||||||
.with_all(
|
.with_all(
|
||||||
db.lock()
|
db.lock()
|
||||||
.cameras_by_id()
|
.cameras_by_id()
|
||||||
|
@ -140,7 +140,7 @@ fn actually_delete(model: &RefCell<Model>, siv: &mut Cursive) {
|
|||||||
let mut l = model.db.lock();
|
let mut l = model.db.lock();
|
||||||
l.open_sample_file_dirs(&[model.dir_id]).unwrap(); // TODO: don't unwrap.
|
l.open_sample_file_dirs(&[model.dir_id]).unwrap(); // TODO: don't unwrap.
|
||||||
}
|
}
|
||||||
if let Err(e) = writer::lower_retention(model.db.clone(), model.dir_id, &new_limits[..]) {
|
if let Err(e) = writer::lower_retention(&model.db, model.dir_id, &new_limits[..]) {
|
||||||
siv.add_layer(
|
siv.add_layer(
|
||||||
views::Dialog::text(format!("Unable to delete excess video: {e}"))
|
views::Dialog::text(format!("Unable to delete excess video: {e}"))
|
||||||
.title("Error")
|
.title("Error")
|
||||||
|
@ -47,9 +47,9 @@ pub fn run(args: Args) -> Result<i32, Error> {
|
|||||||
views::Dialog::around(
|
views::Dialog::around(
|
||||||
views::SelectView::<fn(&Arc<db::Database>, &mut Cursive)>::new()
|
views::SelectView::<fn(&Arc<db::Database>, &mut Cursive)>::new()
|
||||||
.on_submit(move |siv, item| item(&db, siv))
|
.on_submit(move |siv, item| item(&db, siv))
|
||||||
.item("Cameras and streams".to_string(), cameras::top_dialog)
|
.item("Cameras and streams", cameras::top_dialog)
|
||||||
.item("Directories and retention".to_string(), dirs::top_dialog)
|
.item("Directories and retention", dirs::top_dialog)
|
||||||
.item("Users".to_string(), users::top_dialog),
|
.item("Users", users::top_dialog),
|
||||||
)
|
)
|
||||||
.button("Quit", |siv| siv.quit())
|
.button("Quit", |siv| siv.quit())
|
||||||
.title("Main menu"),
|
.title("Main menu"),
|
||||||
|
@ -127,9 +127,7 @@ fn edit_user_dialog(db: &Arc<db::Database>, siv: &mut Cursive, item: Option<i32>
|
|||||||
let l = db.lock();
|
let l = db.lock();
|
||||||
let u = item.map(|id| l.users_by_id().get(&id).unwrap());
|
let u = item.map(|id| l.users_by_id().get(&id).unwrap());
|
||||||
username = u.map(|u| u.username.clone()).unwrap_or_default();
|
username = u.map(|u| u.username.clone()).unwrap_or_default();
|
||||||
id_str = item
|
id_str = item.map_or_else(|| "<new>".to_string(), |id| id.to_string());
|
||||||
.map(|id| id.to_string())
|
|
||||||
.unwrap_or_else(|| "<new>".to_string());
|
|
||||||
has_password = u.map(|u| u.has_password()).unwrap_or(false);
|
has_password = u.map(|u| u.has_password()).unwrap_or(false);
|
||||||
permissions = u.map(|u| u.permissions.clone()).unwrap_or_default();
|
permissions = u.map(|u| u.permissions.clone()).unwrap_or_default();
|
||||||
}
|
}
|
||||||
@ -138,7 +136,7 @@ fn edit_user_dialog(db: &Arc<db::Database>, siv: &mut Cursive, item: Option<i32>
|
|||||||
.child(
|
.child(
|
||||||
"username",
|
"username",
|
||||||
views::EditView::new()
|
views::EditView::new()
|
||||||
.content(username.clone())
|
.content(&username)
|
||||||
.with_name("username"),
|
.with_name("username"),
|
||||||
);
|
);
|
||||||
let mut layout = views::LinearLayout::vertical()
|
let mut layout = views::LinearLayout::vertical()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user