Commit 8d0ad447 authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

Switch to gtk3

Would love to keep using gtk4, but we can't get it into 3.36 otherwise.
parent 894dbdbf
......@@ -5,17 +5,10 @@ authors = ["Bilal Elmoussaoui <bil.elmoussaoui@gmail.com>"]
edition = "2018"
[dependencies]
glib = { git = "https://github.com/gtk-rs/glib.git" }
gio = { git = "https://github.com/gtk-rs/gio.git" }
glib = "0.9"
gdk = "0.12"
gtk = { version = "0.8", features= ["v3_16"] }
gio = "0.8"
log = "0.4"
gettext-rs= { version = "0.4", features = ["gettext-system"] }
[dependencies.gdk]
package = "gdk4"
git = "https://github.com/gtk-rs/gdk4"
[dependencies.gtk]
package = "gtk4"
git = "https://github.com/gtk-rs/gtk4.git"
......@@ -4,27 +4,27 @@ use crate::widgets::Window;
use gio::prelude::*;
use gtk::prelude::*;
use std::env;
use std::rc::Rc;
use std::{cell::RefCell, rc::Rc};
pub struct Application {
app: gtk::Application,
window: Rc<Window>,
window: RefCell<Rc<Option<Window>>>,
}
impl Application {
pub fn new() -> Self {
pub fn new() -> Rc<Self> {
let app = gtk::Application::new(Some(config::APP_ID), gio::ApplicationFlags::FLAGS_NONE).unwrap();
let window = Rc::new(Window::new(&app));
let application = Self { app, window };
let application = Rc::new(Self {
app,
window: RefCell::new(Rc::new(None)),
});
application.setup_gactions();
application.setup_signals();
application.setup_css();
application.setup_signals(application.clone());
application
}
fn setup_gactions(&self) {
fn setup_gactions(&self, application: Rc<Self>) {
// Quit
utils::action(
&self.app,
......@@ -37,8 +37,10 @@ impl Application {
utils::action(
&self.app,
"start-tour",
clone!(@strong self.window as window => move |_, _| {
window.start_tour();
clone!(@strong application => move |_, _| {
if let Some(window) = &*application.window.borrow().clone() {
window.start_tour();
}
}),
);
......@@ -54,32 +56,43 @@ impl Application {
utils::action(
&self.app,
"next-page",
clone!(@strong self.window as window => move |_, _| {
window.next_page();
clone!(@strong application => move |_, _| {
if let Some(window) = &*application.window.borrow().clone() {
window.next_page();
}
}),
);
utils::action(
&self.app,
"previous-page",
clone!(@strong self.window as window => move |_, _| {
window.previous_page();
clone!(@strong application => move |_, _| {
if let Some(window) = &*application.window.borrow().clone() {
window.previous_page();
}
}),
);
self.app.set_accels_for_action("app.quit", &["<primary>q"]);
}
fn setup_signals(&self) {
self.app.connect_activate(clone!(@weak self.window.widget as window => move |app| {
app.add_window(&window);
window.present();
fn setup_signals(&self, app: Rc<Self>) {
self.app.connect_startup(clone!(@weak app => move |_| {
app.setup_css();
app.setup_gactions(app.clone());
}));
self.app.connect_activate(clone!(@weak app => move |gtk_app| {
let window = Window::new(&gtk_app);
gtk_app.add_window(&window.widget);
window.widget.present();
window.widget.show_all();
app.window.replace(Rc::new(Some(window)));
}));
}
fn setup_css(&self) {
let p = gtk::CssProvider::new();
gtk::CssProvider::load_from_resource(&p, "/org/gnome/Tour/style.css");
if let Some(display) = gdk::Display::get_default() {
gtk::StyleContext::add_provider_for_display(&display, &p, 500);
if let Some(screen) = gdk::Screen::get_default() {
gtk::StyleContext::add_provider_for_screen(&screen, &p, 500);
}
}
......
pub static APP_ID: &'static str = @APP_ID@;
pub static PKGDATADIR: &'static str = @PKGDATADIR@;
pub static PROFILE: &'static str = @PROFILE@;
pub static NAME_SUFFIX: &'static str = @NAME_SUFFIX@;
pub static VERSION: &'static str = @VERSION@;
pub static GETTEXT_PACKAGE: &'static str = @GETTEXT_PACKAGE@;
pub static LOCALEDIR: &'static str = @LOCALEDIR@;
pub static DISTRO_NAME: &'static str = @DISTRO_NAME@;
pub static DISTRO_VERSION: &'static str = @DISTRO_VERSION@;
pub static DISTRO_ICON_NAME: &'static str = @DISTRO_ICON_NAME@;
pub static APP_ID: &str = @APP_ID@;
pub static PKGDATADIR: &str = @PKGDATADIR@;
pub static PROFILE: &str = @PROFILE@;
pub static NAME_SUFFIX: &str = @NAME_SUFFIX@;
pub static VERSION: &str = @VERSION@;
pub static GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@;
pub static LOCALEDIR: &str = @LOCALEDIR@;
pub static DISTRO_NAME: &str = @DISTRO_NAME@;
pub static DISTRO_VERSION: &str = @DISTRO_VERSION@;
pub static DISTRO_ICON_NAME: &str = @DISTRO_ICON_NAME@;
......@@ -4,6 +4,7 @@ use gtk::prelude::*;
pub struct HeaderBar {
pub widget: gtk::Stack,
headerbar: gtk::HeaderBar,
title: gtk::Label,
next_btn: gtk::Button,
}
......@@ -11,16 +12,17 @@ impl HeaderBar {
pub fn new() -> Self {
let widget = gtk::Stack::new();
let headerbar = gtk::HeaderBar::new();
let title = gtk::Label::new(None);
let next_btn = gtk::Button::new();
let headerbar = Self { widget, headerbar, next_btn };
let headerbar = Self { widget, headerbar, title, next_btn };
headerbar.init();
headerbar
}
pub fn start_tour(&self) {
self.widget.set_visible_child_name("pages");
self.headerbar.set_show_title_buttons(false);
self.headerbar.set_show_close_button(false);
}
pub fn set_page_nr(&self, page_nr: i32, total_pages: i32) {
......@@ -32,23 +34,26 @@ impl HeaderBar {
}
pub fn set_page_title(&self, title: &str) {
self.headerbar.set_title(Some(title));
self.title.set_label(title);
}
pub fn end_tour(&self) {
self.widget.set_visible_child_name("welcome");
self.headerbar.set_show_title_buttons(true);
self.headerbar.set_show_close_button(true);
}
fn init(&self) {
self.headerbar.set_show_title_buttons(true);
self.headerbar.set_show_close_button(true);
self.headerbar.set_custom_title(Some(&self.title));
self.title.get_style_context().add_class("title");
self.widget.set_hexpand(true);
self.widget.set_transition_type(gtk::StackTransitionType::SlideLeftRight);
self.widget.set_transition_duration(300);
self.widget.get_style_context().add_class("titlebar");
let container = gtk::HeaderBar::new();
container.set_show_title_buttons(true);
container.set_show_close_button(true);
container.set_title(Some(&gettext("Welcome Tour")));
self.widget.add_named(&container, "welcome");
......
......@@ -52,7 +52,7 @@ impl ImagePageWidget {
container.set_valign(gtk::Align::Center);
container.set_property_margin(48);
let image = gtk::Picture::new_for_resource(Some(&self.resource_uri));
let image = gtk::Image::new_from_resource(&self.resource_uri);
image.set_valign(gtk::Align::Start);
container.add(&image);
......
......@@ -22,7 +22,7 @@ impl WelcomePageWidget {
self.widget.set_margin_top(24);
self.widget.set_margin_bottom(24);
let logo = gtk::Image::new_from_icon_name(Some(config::DISTRO_ICON_NAME));
let logo = gtk::Image::new_from_icon_name(Some(config::DISTRO_ICON_NAME), gtk::IconSize::Dialog);
logo.set_pixel_size(196);
self.widget.add(&logo);
......
......@@ -28,7 +28,7 @@ impl PaginatorWidget {
}
pub fn get_current_page_nr(&self) -> i32 {
self.current_page.borrow().clone()
*self.current_page.borrow()
}
pub fn get_current_page(&self) -> Option<&Box<dyn Pageable>> {
......@@ -37,12 +37,12 @@ impl PaginatorWidget {
}
pub fn next(&self) {
let next_page = self.current_page.borrow().clone() + 1;
let next_page = *self.current_page.borrow() + 1;
self.go_to(next_page);
}
pub fn previous(&self) {
let previous_page = self.current_page.borrow().clone() - 1;
let previous_page = *self.current_page.borrow() - 1;
self.go_to(previous_page);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment