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

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

View file

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

View file

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

View file

@ -32,16 +32,16 @@ use once_cell::sync::Lazy;
use std::cell::{Cell, RefCell};
use crate::util;
use crate::widgets::IvImage;
use crate::widgets::LpImage;
mod imp {
use super::*;
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/Loupe/gtk/image_view.ui")]
pub struct IvImageView {
pub struct LpImageView {
#[template_child]
pub picture: TemplateChild<IvImage>,
pub picture: TemplateChild<LpImage>,
#[template_child]
pub controls: TemplateChild<gtk::Box>,
#[template_child]
@ -65,9 +65,9 @@ mod imp {
}
#[glib::object_subclass]
impl ObjectSubclass for IvImageView {
const NAME: &'static str = "IvImageView";
type Type = super::IvImageView;
impl ObjectSubclass for LpImageView {
const NAME: &'static str = "LpImageView";
type Type = super::LpImageView;
type ParentType = libadwaita::Bin;
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] {
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
vec![
@ -134,19 +134,19 @@ mod imp {
}
}
impl WidgetImpl for IvImageView {}
impl BinImpl for IvImageView {}
impl WidgetImpl for LpImageView {}
impl BinImpl for LpImageView {}
}
glib::wrapper! {
pub struct IvImageView(ObjectSubclass<imp::IvImageView>)
pub struct LpImageView(ObjectSubclass<imp::LpImageView>)
@extends gtk::Widget, libadwaita::Bin,
@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)> {
let imp = imp::IvImageView::from_instance(&self);
let imp = imp::LpImageView::from_instance(&self);
if let Some(current_file) = imp.picture.file() {
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) {
let imp = imp::IvImageView::from_instance(&self);
let imp = imp::LpImageView::from_instance(&self);
if let Some(parent) = file.parent() {
let parent_path = parent.path().map(|p| p.to_str().unwrap().to_string());
@ -231,7 +231,7 @@ impl IvImageView {
}
fn update_image(&self) {
let imp = imp::IvImageView::from_instance(&self);
let imp = imp::LpImageView::from_instance(&self);
let path = &format!(
"{}/{}",
@ -248,21 +248,21 @@ impl IvImageView {
}
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
imp.index.set(imp.index.get() + 1);
self.update_image();
}
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
imp.index.set(imp.index.get() - 1);
self.update_image();
}
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();
self.action_set_enabled("iv.next", index < imp.directory_pictures.borrow().len() - 1);
self.action_set_enabled("iv.previous", index > 0);
@ -279,7 +279,7 @@ impl IvImageView {
}
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 path = &format!(
@ -320,17 +320,17 @@ impl IvImageView {
}
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()
}
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()
}
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 {
x: x as i32,

View file

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

View file

@ -26,7 +26,7 @@ use gtk::CompositeTemplate;
use libadwaita::subclass::prelude::*;
use crate::config;
use crate::widgets::IvImageView;
use crate::widgets::LpImageView;
mod imp {
use super::*;
@ -47,7 +47,7 @@ mod imp {
// `impl ObjectSubclass for $TYPE` section.
#[derive(Default, Debug, CompositeTemplate)]
#[template(resource = "/org/gnome/Loupe/gtk/window.ui")]
pub struct IvWindow {
pub struct LpWindow {
// Template children are used with the
// TemplateChild<T> wrapper, where T is the
// object type of the template child.
@ -64,15 +64,15 @@ mod imp {
#[template_child]
pub status_page: TemplateChild<libadwaita::StatusPage>,
#[template_child]
pub image_view: TemplateChild<IvImageView>,
pub image_view: TemplateChild<LpImageView>,
#[template_child]
pub open_gesture: TemplateChild<gtk::GestureClick>,
}
#[glib::object_subclass]
impl ObjectSubclass for IvWindow {
const NAME: &'static str = "IvWindow";
type Type = super::IvWindow;
impl ObjectSubclass for LpWindow {
const NAME: &'static str = "LpWindow";
type Type = super::LpWindow;
type ParentType = libadwaita::ApplicationWindow;
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) {
self.parent_constructed(obj);
@ -146,25 +146,25 @@ mod imp {
}
}
impl WidgetImpl for IvWindow {}
impl WindowImpl for IvWindow {}
impl ApplicationWindowImpl for IvWindow {}
impl AdwApplicationWindowImpl for IvWindow {}
impl WidgetImpl for LpWindow {}
impl WindowImpl for LpWindow {}
impl ApplicationWindowImpl for LpWindow {}
impl AdwApplicationWindowImpl for LpWindow {}
}
glib::wrapper! {
pub struct IvWindow(ObjectSubclass<imp::IvWindow>)
pub struct LpWindow(ObjectSubclass<imp::LpWindow>)
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, libadwaita::ApplicationWindow,
@implements gio::ActionMap, gio::ActionGroup;
}
impl IvWindow {
impl LpWindow {
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) {
let imp = imp::IvWindow::from_instance(&self);
let imp = imp::LpWindow::from_instance(&self);
if fullscreen {
imp.flap.set_fold_policy(libadwaita::FlapFoldPolicy::Always);
@ -221,7 +221,7 @@ impl IvWindow {
}
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() {
std::process::Command::new("xdg-open")
@ -234,7 +234,7 @@ impl IvWindow {
}
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() {
log::error!("Failed to set wallpaper: {}", e);
@ -242,7 +242,7 @@ impl IvWindow {
}
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() {
log::error!("Failed to print file: {}", e);
@ -250,7 +250,7 @@ impl IvWindow {
}
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());
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
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_height = img_height;