camera icon indicating copy to clipboard operation
camera copied to clipboard

Replace Menu with Popover

Open treppenwitz03 opened this issue 4 years ago • 9 comments

This is an initial work on replacing Gtk.Menu with a Gtk.Popover because Gtk.Menu is dropped in GTK4.

This aims to solve https://github.com/elementary/camera/issues/205

treppenwitz03 avatar Dec 28 '21 07:12 treppenwitz03

Thanks @Marukesu

treppenwitz03 avatar Dec 29 '21 15:12 treppenwitz03

@Marukesu I have tried it but it resulted in Segmentation Fault. There is no better documentation on valadoc about the difference of display_name or name just that display_name is for user-friendly name while there is no definition for name

treppenwitz03 avatar Jan 03 '22 02:01 treppenwitz03

@Marukesu I have tried it but it resulted in Segmentation Fault.

Try it now, i made some changes on the action, it's now an PropertyAction, so we don't need to provide an fallback, or default value, also it's calling change_camera direct as before when finding a new camera.

There is no better documentation on valadoc about the difference of display_name or name just that display_name is for user-friendly name while there is no definition for name

Gst.Object.name is guaranteed to be unique, while display_name isn't. The old code already used this to find the right device when removing it from the menu.

Marukesu avatar Jan 03 '22 03:01 Marukesu

also, it seems that Gtk.MenuButton can use an GLib.MenuModel directly, so we don't need to create the Gtk.Popover.

Marukesu avatar Jan 03 '22 03:01 Marukesu

Okay. I will try it now, Thanks!

treppenwitz03 avatar Jan 03 '22 07:01 treppenwitz03

also, it seems that Gtk.MenuButton can use an GLib.MenuModel directly, so we don't need to create the Gtk.Popover.

I have replaced Gtk.Menu with a GLib.Menu (which is a subclass of GLib.MenuModel we can add items in) and added the bits and pieces you suggested before to easily add and remove a device to the menu. However, I have not yet managed to create a radiobutton-like behavior where we can select which camera device to use, instead, it shows only as a string. I will continue to research from here. Thanks!

treppenwitz03 avatar Jan 03 '22 08:01 treppenwitz03

@Marukesu Is there a way we can pass a Gst.Device as a detailed_action?

Because in add_camera_option, we do

camera_options.append (camera.display_name, GLib.Action.print_detailed_name (
            MainWindow.ACTION_PREFIX + MainWindow.ACTION_CHANGE_CAMERA,
            new GLib.Variant.string (camera.name)
        ));

while the change_camera functions look like this: public void change_camera (Gst.Device camera)

Basically, we cannot pass the camera.name by itself because the function uses a Gst.Device as parameter. I also tried changing the function to public void change_camera (string camera_name), but there are other parts of the function that uses other parts of the Gst.Device aside from the name itself

treppenwitz03 avatar Jan 07 '22 01:01 treppenwitz03

there a way we can pass a Gst.Device as a detailed_action?

Not that i can think of, action parameters need to be a GLib.Variant and we can't store arbitrary objects in thoses.

Basically, we cannot pass the camera.name by itself because the function uses a Gst.Device as parameter. I also tried changing the function to public void change_camera (string camera_name), but there are other parts of the function that uses other parts of the Gst.Device aside from the name itself

Yeah, that's why in the camera_name setter we search the for the camera device in the monitor and then call change_camera.

When a new camera is added, we already have the device in hands, so make more sense to use change_camera directly and notify about the change (the notify_property line) than setting the property and having it to search the device again.

Marukesu avatar Jan 07 '22 02:01 Marukesu

Sorry for the late reply @Marukesu , I will look into it. Thanks!

treppenwitz03 avatar Jan 09 '22 23:01 treppenwitz03

A more updated fix is in the works

treppenwitz03 avatar Jan 06 '23 07:01 treppenwitz03