From 5e2d2807c1b81e3361a3e404a2b8887e512416ae Mon Sep 17 00:00:00 2001 From: Erica Z Date: Tue, 29 Oct 2024 13:01:42 +0100 Subject: [PATCH] translate src/main.c --- src/application.rs | 36 ++++++++++++++++++ src/main.c | 91 ---------------------------------------------- src/main.rs | 26 +++++++------ src/meson.build | 1 - 4 files changed, 50 insertions(+), 104 deletions(-) create mode 100644 src/application.rs delete mode 100644 src/main.c diff --git a/src/application.rs b/src/application.rs new file mode 100644 index 0000000..1895315 --- /dev/null +++ b/src/application.rs @@ -0,0 +1,36 @@ +use gtk::{glib, gio}; + +pub mod ffi { + #[repr(C)] + pub struct AudreyApplication { + pub parent_instance: adw::ffi::AdwApplication, + } + + #[repr(C)] + pub struct AudreyApplicationClass { + pub parent_class: adw::ffi::AdwApplicationClass, + } +} + +extern "C" { + fn audrey_application_get_type() -> glib::ffi::GType; + fn audrey_application_new() -> *mut ffi::AudreyApplication; +} + +glib::wrapper! { + pub struct Application(Object) + @extends adw::Application, gtk::Application, gio::Application, + @implements gio::ActionGroup, gio::ActionMap; + + match fn { + type_ => || audrey_application_get_type(), + } +} + +impl Application { + pub fn new() -> Self { + unsafe { + glib::translate::from_glib_full(audrey_application_new()) + } + } +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index c7f7610..0000000 --- a/src/main.c +++ /dev/null @@ -1,91 +0,0 @@ -/* main.c generated by valac 0.56.16, the Vala compiler - * generated from main.vala, do not modify */ - -#include -#include -#include -#include -#include -#include "config.h" -#include -#include -#include -#include - -#if !defined(VALA_STRICT_C) -#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14) -#pragma GCC diagnostic warning "-Wincompatible-pointer-types" -#elif defined(__clang__) && (__clang_major__ >= 16) -#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types" -#pragma clang diagnostic ignored "-Wincompatible-pointer-types" -#endif -#endif -#if !defined(VALA_EXTERN) -#if defined(_MSC_VER) -#define VALA_EXTERN __declspec(dllexport) extern -#elif __GNUC__ >= 4 -#define VALA_EXTERN __attribute__((visibility("default"))) extern -#else -#define VALA_EXTERN extern -#endif -#endif - -#define AUDREY_TYPE_APPLICATION (audrey_application_get_type ()) -#define AUDREY_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AUDREY_TYPE_APPLICATION, AudreyApplication)) -#define AUDREY_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AUDREY_TYPE_APPLICATION, AudreyApplicationClass)) -#define AUDREY_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AUDREY_TYPE_APPLICATION)) -#define AUDREY_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AUDREY_TYPE_APPLICATION)) -#define AUDREY_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AUDREY_TYPE_APPLICATION, AudreyApplicationClass)) - -typedef struct _AudreyApplication AudreyApplication; -typedef struct _AudreyApplicationClass AudreyApplicationClass; -#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) - -static gint _vala_main (gchar** args, - gint args_length1); -VALA_EXTERN GType audrey_application_get_type (void) G_GNUC_CONST ; -G_DEFINE_AUTOPTR_CLEANUP_FUNC (AudreyApplication, g_object_unref) -VALA_EXTERN AudreyApplication* audrey_application_new (void); -VALA_EXTERN AudreyApplication* audrey_application_construct (GType object_type); - -static gint -_vala_main (gchar** args, - gint args_length1) -{ - AudreyApplication* app = NULL; - AudreyApplication* _tmp0_; - gint result; -#line 3 "../src/main.vala" - gtk_disable_setlocale (); -#line 4 "../src/main.vala" - bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); -#line 5 "../src/main.vala" - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); -#line 6 "../src/main.vala" - textdomain (GETTEXT_PACKAGE); -#line 7 "../src/main.vala" - setlocale (LC_ALL, ""); -#line 8 "../src/main.vala" - setlocale (LC_NUMERIC, "C.UTF-8"); -#line 10 "../src/main.vala" - _tmp0_ = audrey_application_new (); -#line 10 "../src/main.vala" - app = _tmp0_; -#line 11 "../src/main.vala" - result = g_application_run ((GApplication*) app, (gint) args_length1, args); -#line 11 "../src/main.vala" - _g_object_unref0 (app); -#line 11 "../src/main.vala" - return result; -#line 81 "main.c" -} - -int -c_main (int argc, - char ** argv) -{ -#line 1 "../src/main.vala" - return _vala_main (argv, argc); -#line 90 "main.c" -} - diff --git a/src/main.rs b/src/main.rs index 5c9f657..300c310 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,9 @@ -use gtk::gio; +mod application; +use application::{Application}; + +use gtk::prelude::*; +use gtk::{glib, gio}; -extern crate adw; extern crate libsecret; #[link(name = "audrey")] @@ -9,18 +12,17 @@ extern crate libsecret; #[link(name = "mpv")] #[link(name = "soup-3.0")] extern "C" { - fn c_main(argc: std::ffi::c_int, argv: *const *const std::ffi::c_char) -> std::ffi::c_int; } -fn main() { +fn main() -> glib::ExitCode { gio::resources_register_include!("audrey.gresource").expect("could not register resources"); - let args = std::env::args_os(); - let argc = args.len(); - let argv: Vec = args - .map(|arg| std::ffi::CString::new(std::ffi::OsStr::as_encoded_bytes(&arg)).unwrap()) - .collect(); - let argv: Vec<*const std::ffi::c_char> = argv.iter().map(|arg| arg.as_ptr()).collect(); - - unsafe { std::process::exit(c_main(argc as std::ffi::c_int, argv.as_ptr())) } + gtk::disable_setlocale(); + // bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + // bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + // textdomain (GETTEXT_PACKAGE); + // setlocale (LC_ALL, ""); + // setlocale (LC_NUMERIC, "C.UTF-8"); + let app = Application::new(); + app.run() } diff --git a/src/meson.build b/src/meson.build index e8c845e..c163034 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,7 +1,6 @@ audrey_sources = [ 'application.c', 'globalconf.c', - 'main.c', 'mpris.c', 'playbin.c', 'subsonic.c',