summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-20 22:08:38 +0300
committerVika <vika@fireburn.ru>2024-08-20 22:08:38 +0300
commit56c4714da77aa710bc8187ef0f06eb38e238ecb5 (patch)
treee5c9c58ba367699ee024069e1e3fb6564411df27
parente89bd14809aab98fc5edf7f83f8dae2dec923a95 (diff)
downloadbowl-56c4714da77aa710bc8187ef0f06eb38e238ecb5.tar.zst
Visibility selector
-rw-r--r--src/lib.rs105
1 files changed, 84 insertions, 21 deletions
diff --git a/src/lib.rs b/src/lib.rs
index e97a9fa..ce90fec 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,6 +9,8 @@ pub mod micropub;
 pub mod util;
 pub const APPLICATION_ID: &str = "xyz.vikanezrimaya.kittybox.Bowl";
 
+pub const VISIBILITY: [&str; 2] = ["public", "private"];
+
 #[tracker::track]
 #[derive(Debug)]
 pub struct PostComposerModel {
@@ -72,6 +74,8 @@ impl AsyncComponent for PostComposerModel {
         #[root]
         adw::ApplicationWindow {
             set_title: Some("Create post"),
+            set_width_request: 360,
+            set_height_request: 480,
 
             adw::ToolbarView {
                 add_top_bar: &{
@@ -92,7 +96,7 @@ impl AsyncComponent for PostComposerModel {
                 },
                 #[name = "content_wrapper"]
                 adw::BreakpointBin {
-                    set_width_request: 320,
+                    set_width_request: 360,
                     set_height_request: 480,
 
                     #[name = "content"]
@@ -130,7 +134,6 @@ impl AsyncComponent for PostComposerModel {
                             set_orientation: gtk::Orientation::Horizontal,
                             set_css_classes: &["linked"],
 
-                        
                             gtk::Entry {
                                 set_hexpand: true,
                                 set_buffer: &model.summary_buffer,
@@ -210,13 +213,49 @@ impl AsyncComponent for PostComposerModel {
                                 #[track = "model.changed(Self::submit_busy_guard())"]
                                 set_sensitive: model.submit_busy_guard.is_none(),
                             }
-                        }
+                        },
+
+                        #[name = "misc_prop_wrapper"]
+                        gtk::Box {
+                            set_hexpand: true,
+
+                            gtk::FlowBox {
+                                set_hexpand: false,
+                                set_orientation: gtk::Orientation::Horizontal,
+                                set_homogeneous: false,
+                                set_column_spacing: 0,
+                                set_min_children_per_line: 2,
+                                set_max_children_per_line: 6,
+                                set_selection_mode: gtk::SelectionMode::None,
+
+                                append = &gtk::Box {
+                                    set_spacing: 5,
+
+                                    #[name = "visibility_label"]
+                                    gtk::Label {
+                                        set_markup: "Visibility",
+                                        set_halign: gtk::Align::Start,
+                                        set_valign: gtk::Align::Start,
+                                        set_margin_vertical: 10,
+                                        set_margin_horizontal: 10,
+                                    },
+                                    #[name = "visibility_selector"]
+                                    gtk::DropDown {
+                                        set_model: Some(&gtk::StringList::new(&VISIBILITY)),
+                                        set_hexpand: false,
+
+                                    #[track = "model.changed(Self::submit_busy_guard())"]
+                                    set_sensitive: model.submit_busy_guard.is_none(),
+                                    },
+                                },
+                            },
+                        },
                     },
 
                     add_breakpoint = adw::Breakpoint::new(
                         adw::BreakpointCondition::new_length(
                             adw::BreakpointConditionLengthType::MinWidth,
-                            480.0,
+                            512.0,
                             adw::LengthUnit::Px
                         )
                     ) {
@@ -260,23 +299,40 @@ impl AsyncComponent for PostComposerModel {
         layout.set_column_homogeneous(false);
         layout.set_row_spacing(10);
 
-        for (row, (label, field)) in [
-            (&widgets.name_label, widgets.name_field.upcast_ref::<gtk::Widget>()),
-            (&widgets.summary_label, widgets.summary_field.upcast_ref::<gtk::Widget>()),
-            (&widgets.tag_label, widgets.tag_holder.upcast_ref::<gtk::Widget>()),
-            (&widgets.content_label, widgets.content_textarea.upcast_ref::<gtk::Widget>())
+        enum Row<'a> {
+            TwoColumn(&'a gtk::Label, &'a gtk::Widget),
+            Span(&'a gtk::Widget)
+        }
+
+        for (row, content) in [
+            Row::TwoColumn(&widgets.name_label, widgets.name_field.upcast_ref::<gtk::Widget>()),
+            Row::TwoColumn(&widgets.summary_label, widgets.summary_field.upcast_ref::<gtk::Widget>()),
+            Row::TwoColumn(&widgets.tag_label, widgets.tag_holder.upcast_ref::<gtk::Widget>()),
+            Row::TwoColumn(&widgets.content_label, widgets.content_textarea.upcast_ref::<gtk::Widget>()),
+            Row::Span(widgets.misc_prop_wrapper.upcast_ref::<gtk::Widget>()),
         ].into_iter().enumerate() {
-            let label_layout = layout.layout_child(label)
-                .downcast::<GridLayoutChild>()
-                .unwrap();
-            label_layout.set_row(row as i32);
-            label_layout.set_column(0);
-
-            let field_layout = layout.layout_child(field)
-                .downcast::<GridLayoutChild>()
-                .unwrap();
-            field_layout.set_row(row as i32);
-            field_layout.set_column(1);
+            match content {
+                Row::TwoColumn(label, field) => {
+                    let label_layout = layout.layout_child(label)
+                        .downcast::<GridLayoutChild>()
+                        .unwrap();
+                    label_layout.set_row(row as i32);
+                    label_layout.set_column(0);
+
+                    let field_layout = layout.layout_child(field)
+                        .downcast::<GridLayoutChild>()
+                        .unwrap();
+                    field_layout.set_row(row as i32);
+                    field_layout.set_column(1);
+                },
+                Row::Span(widget) => {
+                    let widget_layout = layout.layout_child(widget)
+                        .downcast::<GridLayoutChild>()
+                        .unwrap();
+                    widget_layout.set_row(row as i32);
+                    widget_layout.set_column_span(2);
+                }
+            }
         }
 
         widgets.content.set_layout_manager(Some(model.narrow_layout.clone()));
@@ -344,7 +400,14 @@ impl AsyncComponent for PostComposerModel {
                     ).into()));
                 }
 
-                log::warn!("sending post: {:?}", &mf2);
+                {
+                    let proplist = mf2.properties.entry("visibility".to_owned()).or_default();
+                    let selected = VISIBILITY[widgets.visibility_selector.selected() as usize];
+                    proplist.push(PropertyValue::Plain(selected.to_owned()));
+                }
+
+                log::warn!("sending post: {:#}", serde_json::to_value(&mf2).unwrap());
+
                 match self.micropub.send_post(mf2).await {
                     Ok(location) => {
                         self.name_buffer.set_text("");