Skip to content

Commit

Permalink
Add initial tag reading test support.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWiseNoob committed Apr 9, 2024
1 parent 4076aa3 commit 66fb019
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 5 deletions.
64 changes: 64 additions & 0 deletions src/content.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "appwin.h"
#include "sidebar.h"

#include "taglib/tag_c.h"

struct _OMPContent {
AdwBin parent;

Expand Down Expand Up @@ -35,6 +37,65 @@ omp_content_change_content (
omp_content_set_content (content, page_name);
}

static void
on_open_response (GObject* gobject, GAsyncResult* result, gpointer data)
{
g_autoptr (GError) error = NULL;
g_autoptr (GFile) gfile = gtk_file_dialog_open_finish (
GTK_FILE_DIALOG (gobject), result, &error
);

if (error != NULL) {
// the operation failed, or it was cancelled by the user
}
else {
const char* filename = g_file_get_path (gfile);

TagLib_File* file;
TagLib_Tag* tag;
const TagLib_AudioProperties* properties;
char** propertiesMap;
char** complexKeys;

file = taglib_file_new (filename);

if (file == NULL)
return;

tag = taglib_file_tag (file);
properties = taglib_file_audioproperties (file);
propertiesMap = taglib_property_keys (file);
complexKeys = taglib_complex_property_keys (file);

if (tag != NULL) {
printf ("-- TAG (basic) --\n");
printf ("title - \"%s\"\n", taglib_tag_title (tag));
printf ("artist - \"%s\"\n", taglib_tag_artist (tag));
printf ("album - \"%s\"\n", taglib_tag_album (tag));
printf ("year - \"%u\"\n", taglib_tag_year (tag));
printf ("comment - \"%s\"\n", taglib_tag_comment (tag));
printf ("track - \"%u\"\n", taglib_tag_track (tag));
printf ("genre - \"%s\"\n", taglib_tag_genre (tag));
}
// do something with the file
}
}

static void
omp_content_open_file_clicked (GtkButton* source, OMPContent* content)
{
// ...
GtkWidget* dialog;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
OMPAppWindow* parent_window
= omp_app_get_main_window ((OMPApp*)g_application_get_default ());

dialog = gtk_file_dialog_new ();
gtk_file_dialog_open (
dialog, parent_window, NULL, G_CALLBACK (on_open_response), NULL
);
}

static void
omp_content_open_sidebar_clicked (GtkButton* source, OMPContent* content)
{
Expand Down Expand Up @@ -120,6 +181,9 @@ omp_content_class_init (OMPContentClass* self)
);

// Callbacks
gtk_widget_class_bind_template_callback (
GTK_WIDGET_CLASS (self), omp_content_open_file_clicked
);
gtk_widget_class_bind_template_callback (
GTK_WIDGET_CLASS (self), omp_content_open_sidebar_clicked
);
Expand Down
7 changes: 5 additions & 2 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
add_project_arguments('-ltag_c', language: 'c')
add_project_arguments('-Wno-unused-parameter', language: 'c')

gtk = dependency('gtk4', version: '>= 4.6.9')
libadwaita = dependency('libadwaita-1', version: '>= 1.4.alpha')
taglib = dependency('taglib_c', version: '>= 2.0')

program_name = 'omp'

Expand All @@ -26,17 +28,18 @@ omp_style_resources = gnome.compile_resources(

executable(
program_name, [
omp_resources,
omp_style_resources,
'app.c',
'sidebar.c',
'content.c',
'appwin.c',
'main.c',
omp_resources,
omp_style_resources,
],
dependencies: [
gtk,
libadwaita,
taglib,
],
install: true,
)
Expand Down
22 changes: 19 additions & 3 deletions src/resources/ui/content.blp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,25 @@ template $OMPContent : Adw.Bin {
}
}

Adw.Bin main_container {
Label content_label {
label: "Content";
Gtk.CenterBox main_container {
[center]
Box main_box {
orientation: vertical;

[start]
Label content_label {
label: "Content";
}

[end]
Gtk.Button open_file_button {
can-shrink: true;
clicked => $omp_content_open_file_clicked();

Adw.ButtonContent {
label: "Open File";
}
}
}
}
}
Expand Down

0 comments on commit 66fb019

Please sign in to comment.