mod application_object; use gtk4 as gtk; use gtk::gio; use gtk::prelude::*; use gtk::{ glib, Application, ApplicationWindow, Label, ListView, PolicyType, ScrolledWindow, SignalListItemFactory, SingleSelection, }; use libcosmic::x; use std::{cell::RefCell, rc::Rc}; use self::application_object::ApplicationObject; use self::ipc::LauncherIpc; mod ipc; fn icon_source(icon: >k::Image, source: &Option) { match source { Some(pop_launcher::IconSource::Name(name)) => { icon.set_from_icon_name(Some(name)); } Some(pop_launcher::IconSource::Mime(content_type)) => { icon.set_from_gicon(&gio::content_type_get_icon(content_type)); } _ => { icon.set_from_icon_name(None); } } } fn main() { let launcher = Rc::new(RefCell::new( LauncherIpc::new().expect("failed to connect to launcher service"), )); let app = gtk::Application::builder() .application_id("com.system76.Launcher") .build(); app.connect_activate(move |app| { let window = gtk::ApplicationWindow::builder() .application(app) .decorated(false) .default_width(480) .default_height(440) .title("Launcher") .build(); let vbox = gtk::Box::new(gtk::Orientation::Vertical, 16); vbox.set_margin_start(16); vbox.set_margin_end(16); vbox.set_margin_top(16); vbox.set_margin_bottom(16); window.set_child(Some(&vbox)); let search = gtk::Entry::new(); search.set_placeholder_text(Some(" Type to search apps, or type '?' for more options.")); vbox.append(&search); let listbox = gtk::ListBox::new(); //vbox.append(&listbox); let model = gio::ListStore::new(ApplicationObject::static_type()); let factory = SignalListItemFactory::new(); factory.connect_setup(move |_, list_item| { let label = Label::new(None); list_item.set_child(Some(&label)) }); factory.connect_bind(move |_, list_item| { let application_object = list_item .item() .expect("The item has to exist.") .downcast::() .expect("The item has to be an `ApplicationObject`"); let name = application_object .property("name") .expect("Property name of the wrong type or does not exist!") .get::() .expect("Property name needs to be a String."); let label = list_item .child() .expect("The child has to exist.") .downcast::