general: Iv* to Lp*

We're probably going to be keeping `loupe` as the codename
and binary name going forward.
This commit is contained in:
Christopher Davis 2021-12-21 10:55:02 -08:00
parent 4d1141a675
commit d4fca8aae3
8 changed files with 78 additions and 78 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<template class="IvImageView" parent="AdwBin"> <template class="LpImageView" parent="AdwBin">
<property name="css-name">imageview</property> <property name="css-name">imageview</property>
<property name="focusable">True</property> <property name="focusable">True</property>
<property name="focus-on-click">True</property> <property name="focus-on-click">True</property>
@ -8,7 +8,7 @@
<object class="GtkOverlay"> <object class="GtkOverlay">
<property name="hexpand">True</property> <property name="hexpand">True</property>
<child> <child>
<object class="IvImage" id="picture"> <object class="LpImage" id="picture">
<property name="halign">center</property> <property name="halign">center</property>
<property name="valign">center</property> <property name="valign">center</property>
</object> </object>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<template class="IvWindow" parent="AdwApplicationWindow"> <template class="LpWindow" parent="AdwApplicationWindow">
<property name="default-width">600</property> <property name="default-width">600</property>
<property name="default-height">498</property> <property name="default-height">498</property>
<property name="width-request">360</property> <property name="width-request">360</property>
@ -15,7 +15,7 @@
<property name="modal">false</property> <property name="modal">false</property>
<property name="flap"> <property name="flap">
<object class="GtkHeaderBar" id="headerbar"> <object class="GtkHeaderBar" id="headerbar">
<property name="show_title_buttons" bind-source="IvWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean"/> <property name="show_title_buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean"/>
<binding name="opacity"> <binding name="opacity">
<lookup type="GtkWidget" name="opacity"> <lookup type="GtkWidget" name="opacity">
<lookup name="controls">image_view</lookup> <lookup name="controls">image_view</lookup>
@ -51,7 +51,7 @@
</object> </object>
</child> </child>
<child> <child>
<object class="IvImageView" id="image_view"/> <object class="LpImageView" id="image_view"/>
</child> </child>
</object> </object>
</property> </property>

View file

@ -27,7 +27,7 @@ use libadwaita::prelude::*;
use libadwaita::subclass::prelude::*; use libadwaita::subclass::prelude::*;
use crate::config; use crate::config;
use crate::window::IvWindow; use crate::window::LpWindow;
mod imp { mod imp {
use super::*; use super::*;
@ -35,7 +35,7 @@ mod imp {
// The basic struct that holds our // The basic struct that holds our
// state and widgets // state and widgets
#[derive(Debug)] #[derive(Debug)]
pub struct IvApplication { pub struct LpApplication {
pub gtk_settings: gtk::Settings, pub gtk_settings: gtk::Settings,
} }
@ -43,9 +43,9 @@ mod imp {
// The `#[glib::object_subclass] macro implements // The `#[glib::object_subclass] macro implements
// some boilerplate code for the object setup, e.g. get_type() // some boilerplate code for the object setup, e.g. get_type()
#[glib::object_subclass] #[glib::object_subclass]
impl ObjectSubclass for IvApplication { impl ObjectSubclass for LpApplication {
const NAME: &'static str = "IvApplication"; const NAME: &'static str = "LpApplication";
type Type = super::IvApplication; type Type = super::LpApplication;
type ParentType = libadwaita::Application; type ParentType = libadwaita::Application;
// Initialize with default values // Initialize with default values
@ -58,7 +58,7 @@ mod imp {
} }
// Overrides GObject vfuncs // Overrides GObject vfuncs
impl ObjectImpl for IvApplication { impl ObjectImpl for LpApplication {
fn constructed(&self, obj: &Self::Type) { fn constructed(&self, obj: &Self::Type) {
self.parent_constructed(obj); self.parent_constructed(obj);
@ -72,16 +72,16 @@ mod imp {
} }
// Overrides GApplication vfuncs // Overrides GApplication vfuncs
impl ApplicationImpl for IvApplication { impl ApplicationImpl for LpApplication {
fn activate(&self, application: &Self::Type) { fn activate(&self, application: &Self::Type) {
let window = IvWindow::new(application); let window = LpWindow::new(application);
window.present(); window.present();
} }
// Handles opening files from the command line or other applications // Handles opening files from the command line or other applications
fn open(&self, application: &Self::Type, files: &[gio::File], _hint: &str) { fn open(&self, application: &Self::Type, files: &[gio::File], _hint: &str) {
for file in files { for file in files {
let win = IvWindow::new(application); let win = LpWindow::new(application);
win.set_image_from_file(file); win.set_image_from_file(file);
win.show(); win.show();
} }
@ -90,23 +90,23 @@ mod imp {
// This is empty, but we still need to provide an // This is empty, but we still need to provide an
// empty implementation for each type we subclass. // empty implementation for each type we subclass.
impl GtkApplicationImpl for IvApplication {} impl GtkApplicationImpl for LpApplication {}
impl AdwApplicationImpl for IvApplication {} impl AdwApplicationImpl for LpApplication {}
} }
// Creates a wrapper struct that inherits the functions // Creates a wrapper struct that inherits the functions
// from objects listed as @extends or interfaces it @implements. // from objects listed as @extends or interfaces it @implements.
// This is what allows us to do e.g. application.quit() on // This is what allows us to do e.g. application.quit() on
// IvApplication without casting. // LpApplication without casting.
glib::wrapper! { glib::wrapper! {
pub struct IvApplication(ObjectSubclass<imp::IvApplication>) pub struct LpApplication(ObjectSubclass<imp::LpApplication>)
@extends gio::Application, gtk::Application, libadwaita::Application, @extends gio::Application, gtk::Application, libadwaita::Application,
@implements gio::ActionGroup, gio::ActionMap; @implements gio::ActionGroup, gio::ActionMap;
} }
// This is where the member functions of IvApplication go. // This is where the member functions of LpApplication go.
#[allow(clippy::new_without_default)] #[allow(clippy::new_without_default)]
impl IvApplication { impl LpApplication {
pub fn new() -> Self { pub fn new() -> Self {
glib::Object::new(&[ glib::Object::new(&[
("application-id", &config::APP_ID.to_string()), ("application-id", &config::APP_ID.to_string()),
@ -155,7 +155,7 @@ impl IvApplication {
self, self,
"new-window", "new-window",
clone!(@weak self as app => move |_, _| { clone!(@weak self as app => move |_, _| {
let win = IvWindow::new(&app); let win = LpWindow::new(&app);
win.show(); win.show();
}) })
); );

View file

@ -26,7 +26,7 @@ mod util;
mod widgets; mod widgets;
mod window; mod window;
use application::IvApplication; use application::LpApplication;
fn main() { fn main() {
gtk::init().expect("Failed to initialize GTK."); gtk::init().expect("Failed to initialize GTK.");
@ -41,7 +41,7 @@ fn main() {
.expect("Could not load resources"); .expect("Could not load resources");
gio::resources_register(&res); gio::resources_register(&res);
let app = IvApplication::new(); let app = LpApplication::new();
let ret = app.run(); let ret = app.run();
std::process::exit(ret); std::process::exit(ret);
} }

View file

@ -29,7 +29,7 @@ mod imp {
use super::*; use super::*;
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct IvImage { pub struct LpImage {
pub file: RefCell<Option<gio::File>>, pub file: RefCell<Option<gio::File>>,
pub image_width: Cell<i32>, pub image_width: Cell<i32>,
pub image_height: Cell<i32>, pub image_height: Cell<i32>,
@ -37,10 +37,10 @@ mod imp {
} }
#[glib::object_subclass] #[glib::object_subclass]
impl ObjectSubclass for IvImage { impl ObjectSubclass for LpImage {
const NAME: &'static str = "IvImage"; const NAME: &'static str = "LpImage";
type ParentType = gtk::Widget; type ParentType = gtk::Widget;
type Type = super::IvImage; type Type = super::LpImage;
fn new() -> Self { fn new() -> Self {
Self { Self {
@ -52,7 +52,7 @@ mod imp {
} }
} }
impl ObjectImpl for IvImage { impl ObjectImpl for LpImage {
fn properties() -> &'static [glib::ParamSpec] { fn properties() -> &'static [glib::ParamSpec] {
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| { static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
vec![glib::ParamSpec::new_object( vec![glib::ParamSpec::new_object(
@ -93,7 +93,7 @@ mod imp {
} }
} }
impl WidgetImpl for IvImage { impl WidgetImpl for LpImage {
fn snapshot(&self, widget: &Self::Type, snapshot: &gtk::Snapshot) { fn snapshot(&self, widget: &Self::Type, snapshot: &gtk::Snapshot) {
if let Some(texture) = self.texture.borrow().as_ref() { if let Some(texture) = self.texture.borrow().as_ref() {
let width = widget.width() as f64; let width = widget.width() as f64;
@ -168,18 +168,18 @@ mod imp {
} }
glib::wrapper! { glib::wrapper! {
pub struct IvImage(ObjectSubclass<imp::IvImage>) @extends gtk::Widget; pub struct LpImage(ObjectSubclass<imp::LpImage>) @extends gtk::Widget;
} }
impl IvImage { impl LpImage {
pub fn file(&self) -> Option<gio::File> { pub fn file(&self) -> Option<gio::File> {
let imp = imp::IvImage::from_instance(self); let imp = imp::LpImage::from_instance(self);
imp.file.borrow().clone() imp.file.borrow().clone()
} }
pub fn set_file(&self, file: &gio::File) { pub fn set_file(&self, file: &gio::File) {
let imp = imp::IvImage::from_instance(self); let imp = imp::LpImage::from_instance(self);
match gdk::Texture::from_file(file) { match gdk::Texture::from_file(file) {
Ok(texture) => { Ok(texture) => {
@ -197,12 +197,12 @@ impl IvImage {
} }
pub fn image_width(&self) -> i32 { pub fn image_width(&self) -> i32 {
let imp = imp::IvImage::from_instance(&self); let imp = imp::LpImage::from_instance(&self);
imp.image_width.get() imp.image_width.get()
} }
pub fn image_height(&self) -> i32 { pub fn image_height(&self) -> i32 {
let imp = imp::IvImage::from_instance(&self); let imp = imp::LpImage::from_instance(&self);
imp.image_height.get() imp.image_height.get()
} }
} }

View file

@ -32,16 +32,16 @@ use once_cell::sync::Lazy;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use crate::util; use crate::util;
use crate::widgets::IvImage; use crate::widgets::LpImage;
mod imp { mod imp {
use super::*; use super::*;
#[derive(Debug, Default, CompositeTemplate)] #[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/Loupe/gtk/image_view.ui")] #[template(resource = "/org/gnome/Loupe/gtk/image_view.ui")]
pub struct IvImageView { pub struct LpImageView {
#[template_child] #[template_child]
pub picture: TemplateChild<IvImage>, pub picture: TemplateChild<LpImage>,
#[template_child] #[template_child]
pub controls: TemplateChild<gtk::Box>, pub controls: TemplateChild<gtk::Box>,
#[template_child] #[template_child]
@ -65,9 +65,9 @@ mod imp {
} }
#[glib::object_subclass] #[glib::object_subclass]
impl ObjectSubclass for IvImageView { impl ObjectSubclass for LpImageView {
const NAME: &'static str = "IvImageView"; const NAME: &'static str = "LpImageView";
type Type = super::IvImageView; type Type = super::LpImageView;
type ParentType = libadwaita::Bin; type ParentType = libadwaita::Bin;
fn class_init(klass: &mut Self::Class) { fn class_init(klass: &mut Self::Class) {
@ -87,7 +87,7 @@ mod imp {
} }
} }
impl ObjectImpl for IvImageView { impl ObjectImpl for LpImageView {
fn properties() -> &'static [glib::ParamSpec] { fn properties() -> &'static [glib::ParamSpec] {
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| { static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
vec![ vec![
@ -134,19 +134,19 @@ mod imp {
} }
} }
impl WidgetImpl for IvImageView {} impl WidgetImpl for LpImageView {}
impl BinImpl for IvImageView {} impl BinImpl for LpImageView {}
} }
glib::wrapper! { glib::wrapper! {
pub struct IvImageView(ObjectSubclass<imp::IvImageView>) pub struct LpImageView(ObjectSubclass<imp::LpImageView>)
@extends gtk::Widget, libadwaita::Bin, @extends gtk::Widget, libadwaita::Bin,
@implements gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable; @implements gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
} }
impl IvImageView { impl LpImageView {
pub fn set_image_from_file(&self, file: &gio::File) -> anyhow::Result<(i32, i32)> { pub fn set_image_from_file(&self, file: &gio::File) -> anyhow::Result<(i32, i32)> {
let imp = imp::IvImageView::from_instance(&self); let imp = imp::LpImageView::from_instance(&self);
if let Some(current_file) = imp.picture.file() { if let Some(current_file) = imp.picture.file() {
if current_file.path().as_deref() == file.path().as_deref() { if current_file.path().as_deref() == file.path().as_deref() {
@ -170,7 +170,7 @@ impl IvImageView {
} }
fn set_parent_from_file(&self, file: &gio::File) { fn set_parent_from_file(&self, file: &gio::File) {
let imp = imp::IvImageView::from_instance(&self); let imp = imp::LpImageView::from_instance(&self);
if let Some(parent) = file.parent() { if let Some(parent) = file.parent() {
let parent_path = parent.path().map(|p| p.to_str().unwrap().to_string()); let parent_path = parent.path().map(|p| p.to_str().unwrap().to_string());
@ -231,7 +231,7 @@ impl IvImageView {
} }
fn update_image(&self) { fn update_image(&self) {
let imp = imp::IvImageView::from_instance(&self); let imp = imp::LpImageView::from_instance(&self);
let path = &format!( let path = &format!(
"{}/{}", "{}/{}",
@ -248,21 +248,21 @@ impl IvImageView {
} }
pub fn next(&self) { pub fn next(&self) {
let imp = imp::IvImageView::from_instance(&self); let imp = imp::LpImageView::from_instance(&self);
// TODO: Replace with `Cell::update()` once stabilized // TODO: Replace with `Cell::update()` once stabilized
imp.index.set(imp.index.get() + 1); imp.index.set(imp.index.get() + 1);
self.update_image(); self.update_image();
} }
pub fn previous(&self) { pub fn previous(&self) {
let imp = imp::IvImageView::from_instance(&self); let imp = imp::LpImageView::from_instance(&self);
// TODO: Replace with `Cell::update()` once stabilized // TODO: Replace with `Cell::update()` once stabilized
imp.index.set(imp.index.get() - 1); imp.index.set(imp.index.get() - 1);
self.update_image(); self.update_image();
} }
pub fn update_action_state(&self) { pub fn update_action_state(&self) {
let imp = imp::IvImageView::from_instance(&self); let imp = imp::LpImageView::from_instance(&self);
let index = imp.index.get(); let index = imp.index.get();
self.action_set_enabled("iv.next", index < imp.directory_pictures.borrow().len() - 1); self.action_set_enabled("iv.next", index < imp.directory_pictures.borrow().len() - 1);
self.action_set_enabled("iv.previous", index > 0); self.action_set_enabled("iv.previous", index > 0);
@ -279,7 +279,7 @@ impl IvImageView {
} }
pub fn print(&self) -> anyhow::Result<()> { pub fn print(&self) -> anyhow::Result<()> {
let imp = imp::IvImageView::from_instance(&self); let imp = imp::LpImageView::from_instance(&self);
let operation = gtk::PrintOperation::new(); let operation = gtk::PrintOperation::new();
let path = &format!( let path = &format!(
@ -320,17 +320,17 @@ impl IvImageView {
} }
pub fn uri(&self) -> Option<String> { pub fn uri(&self) -> Option<String> {
let imp = imp::IvImageView::from_instance(&self); let imp = imp::LpImageView::from_instance(&self);
imp.uri.borrow().to_owned() imp.uri.borrow().to_owned()
} }
pub fn filename(&self) -> Option<String> { pub fn filename(&self) -> Option<String> {
let imp = imp::IvImageView::from_instance(&self); let imp = imp::LpImageView::from_instance(&self);
imp.filename.borrow().to_owned() imp.filename.borrow().to_owned()
} }
pub fn show_popover_at(&self, x: f64, y: f64) { pub fn show_popover_at(&self, x: f64, y: f64) {
let imp = imp::IvImageView::from_instance(&self); let imp = imp::LpImageView::from_instance(&self);
let rect = gdk::Rectangle { let rect = gdk::Rectangle {
x: x as i32, x: x as i32,

View file

@ -20,5 +20,5 @@
mod image; mod image;
mod image_view; mod image_view;
pub use image::IvImage; pub use image::LpImage;
pub use image_view::IvImageView; pub use image_view::LpImageView;

View file

@ -26,7 +26,7 @@ use gtk::CompositeTemplate;
use libadwaita::subclass::prelude::*; use libadwaita::subclass::prelude::*;
use crate::config; use crate::config;
use crate::widgets::IvImageView; use crate::widgets::LpImageView;
mod imp { mod imp {
use super::*; use super::*;
@ -47,7 +47,7 @@ mod imp {
// `impl ObjectSubclass for $TYPE` section. // `impl ObjectSubclass for $TYPE` section.
#[derive(Default, Debug, CompositeTemplate)] #[derive(Default, Debug, CompositeTemplate)]
#[template(resource = "/org/gnome/Loupe/gtk/window.ui")] #[template(resource = "/org/gnome/Loupe/gtk/window.ui")]
pub struct IvWindow { pub struct LpWindow {
// Template children are used with the // Template children are used with the
// TemplateChild<T> wrapper, where T is the // TemplateChild<T> wrapper, where T is the
// object type of the template child. // object type of the template child.
@ -64,15 +64,15 @@ mod imp {
#[template_child] #[template_child]
pub status_page: TemplateChild<libadwaita::StatusPage>, pub status_page: TemplateChild<libadwaita::StatusPage>,
#[template_child] #[template_child]
pub image_view: TemplateChild<IvImageView>, pub image_view: TemplateChild<LpImageView>,
#[template_child] #[template_child]
pub open_gesture: TemplateChild<gtk::GestureClick>, pub open_gesture: TemplateChild<gtk::GestureClick>,
} }
#[glib::object_subclass] #[glib::object_subclass]
impl ObjectSubclass for IvWindow { impl ObjectSubclass for LpWindow {
const NAME: &'static str = "IvWindow"; const NAME: &'static str = "LpWindow";
type Type = super::IvWindow; type Type = super::LpWindow;
type ParentType = libadwaita::ApplicationWindow; type ParentType = libadwaita::ApplicationWindow;
fn class_init(klass: &mut Self::Class) { fn class_init(klass: &mut Self::Class) {
@ -107,7 +107,7 @@ mod imp {
} }
} }
impl ObjectImpl for IvWindow { impl ObjectImpl for LpWindow {
fn constructed(&self, obj: &Self::Type) { fn constructed(&self, obj: &Self::Type) {
self.parent_constructed(obj); self.parent_constructed(obj);
@ -146,25 +146,25 @@ mod imp {
} }
} }
impl WidgetImpl for IvWindow {} impl WidgetImpl for LpWindow {}
impl WindowImpl for IvWindow {} impl WindowImpl for LpWindow {}
impl ApplicationWindowImpl for IvWindow {} impl ApplicationWindowImpl for LpWindow {}
impl AdwApplicationWindowImpl for IvWindow {} impl AdwApplicationWindowImpl for LpWindow {}
} }
glib::wrapper! { glib::wrapper! {
pub struct IvWindow(ObjectSubclass<imp::IvWindow>) pub struct LpWindow(ObjectSubclass<imp::LpWindow>)
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, libadwaita::ApplicationWindow, @extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, libadwaita::ApplicationWindow,
@implements gio::ActionMap, gio::ActionGroup; @implements gio::ActionMap, gio::ActionGroup;
} }
impl IvWindow { impl LpWindow {
pub fn new<A: IsA<gtk::Application>>(app: &A) -> Self { pub fn new<A: IsA<gtk::Application>>(app: &A) -> Self {
glib::Object::new(&[("application", app)]).expect("Failed to create IvWindow") glib::Object::new(&[("application", app)]).expect("Failed to create LpWindow")
} }
fn toggle_fullscreen(&self, fullscreen: bool) { fn toggle_fullscreen(&self, fullscreen: bool) {
let imp = imp::IvWindow::from_instance(&self); let imp = imp::LpWindow::from_instance(&self);
if fullscreen { if fullscreen {
imp.flap.set_fold_policy(libadwaita::FlapFoldPolicy::Always); imp.flap.set_fold_policy(libadwaita::FlapFoldPolicy::Always);
@ -221,7 +221,7 @@ impl IvWindow {
} }
fn open_with(&self) { fn open_with(&self) {
let imp = imp::IvWindow::from_instance(self); let imp = imp::LpWindow::from_instance(self);
if let Some(uri) = imp.image_view.uri() { if let Some(uri) = imp.image_view.uri() {
std::process::Command::new("xdg-open") std::process::Command::new("xdg-open")
@ -234,7 +234,7 @@ impl IvWindow {
} }
fn set_wallpaper(&self) { fn set_wallpaper(&self) {
let imp = imp::IvWindow::from_instance(self); let imp = imp::LpWindow::from_instance(self);
if let Err(e) = imp.image_view.set_wallpaper() { if let Err(e) = imp.image_view.set_wallpaper() {
log::error!("Failed to set wallpaper: {}", e); log::error!("Failed to set wallpaper: {}", e);
@ -242,7 +242,7 @@ impl IvWindow {
} }
fn print(&self) { fn print(&self) {
let imp = imp::IvWindow::from_instance(self); let imp = imp::LpWindow::from_instance(self);
if let Err(e) = imp.image_view.print() { if let Err(e) = imp.image_view.print() {
log::error!("Failed to print file: {}", e); log::error!("Failed to print file: {}", e);
@ -250,7 +250,7 @@ impl IvWindow {
} }
pub fn set_image_from_file(&self, file: &gio::File) { pub fn set_image_from_file(&self, file: &gio::File) {
let imp = imp::IvWindow::from_instance(self); let imp = imp::LpWindow::from_instance(self);
log::debug!("Loading file: {}", file.uri().to_string()); log::debug!("Loading file: {}", file.uri().to_string());
match imp.image_view.set_image_from_file(file) { match imp.image_view.set_image_from_file(file) {
@ -273,7 +273,7 @@ impl IvWindow {
// Adapted from https://gitlab.gnome.org/GNOME/eog/-/blob/master/src/eog-window.c:eog_window_obtain_desired_size // Adapted from https://gitlab.gnome.org/GNOME/eog/-/blob/master/src/eog-window.c:eog_window_obtain_desired_size
pub fn resize_from_dimensions(&self, img_width: i32, img_height: i32) { pub fn resize_from_dimensions(&self, img_width: i32, img_height: i32) {
let imp = imp::IvWindow::from_instance(self); let imp = imp::LpWindow::from_instance(self);
let mut final_width = img_width; let mut final_width = img_width;
let mut final_height = img_height; let mut final_height = img_height;