translate src/main.c

This commit is contained in:
Erica Z 2024-10-29 13:01:42 +01:00
parent 36b2cf989d
commit 5e2d2807c1
4 changed files with 50 additions and 104 deletions

36
src/application.rs Normal file
View file

@ -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<ffi::AudreyApplication, ffi::AudreyApplicationClass>)
@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())
}
}
}

View file

@ -1,91 +0,0 @@
/* main.c generated by valac 0.56.16, the Vala compiler
* generated from main.vala, do not modify */
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
#include "config.h"
#include <locale.h>
#include <adwaita.h>
#include <glib-object.h>
#include <gio/gio.h>
#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"
}

View file

@ -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; extern crate libsecret;
#[link(name = "audrey")] #[link(name = "audrey")]
@ -9,18 +12,17 @@ extern crate libsecret;
#[link(name = "mpv")] #[link(name = "mpv")]
#[link(name = "soup-3.0")] #[link(name = "soup-3.0")]
extern "C" { 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"); gio::resources_register_include!("audrey.gresource").expect("could not register resources");
let args = std::env::args_os(); gtk::disable_setlocale();
let argc = args.len(); // bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
let argv: Vec<std::ffi::CString> = args // bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
.map(|arg| std::ffi::CString::new(std::ffi::OsStr::as_encoded_bytes(&arg)).unwrap()) // textdomain (GETTEXT_PACKAGE);
.collect(); // setlocale (LC_ALL, "");
let argv: Vec<*const std::ffi::c_char> = argv.iter().map(|arg| arg.as_ptr()).collect(); // setlocale (LC_NUMERIC, "C.UTF-8");
let app = Application::new();
unsafe { std::process::exit(c_main(argc as std::ffi::c_int, argv.as_ptr())) } app.run()
} }

View file

@ -1,7 +1,6 @@
audrey_sources = [ audrey_sources = [
'application.c', 'application.c',
'globalconf.c', 'globalconf.c',
'main.c',
'mpris.c', 'mpris.c',
'playbin.c', 'playbin.c',
'subsonic.c', 'subsonic.c',