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 12, 2024
1 parent 4076aa3 commit 6bd52d5
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 9 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
*.o
*.swp
*.swo
*.un~
.cache
builddir
compile_commands.json
omp
PKGBUILD
TODO
*.o
omp

builddir
/subprojects/blueprint-compiler
66 changes: 66 additions & 0 deletions src/content.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
#include "appwin.h"
#include "sidebar.h"

#include "taglib/tag_c.h"

struct _OMPContent {
AdwBin parent;

GtkWidget* content_label;
GtkWidget* open_sidebar_overlay_button;
GtkWidget* tag_label;
};

G_DEFINE_TYPE (OMPContent, omp_content, ADW_TYPE_BIN);
Expand All @@ -35,6 +38,63 @@ omp_content_change_content (
omp_content_set_content (content, page_name);
}

static void
omp_content_open_file (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
);

OMPContent* content = data;

if (error != NULL) {
}
else {
const char* filename = g_file_get_path (gfile);

TagLib_File* file;
TagLib_Tag* tag;

file = taglib_file_new (filename);

if (file == NULL)
return;

tag = taglib_file_tag (file);

if (tag != NULL) {
char* tag_str = "Title - ";
char year[5];
sprintf (year, "%d", taglib_tag_year (tag));
char track[5];
sprintf (track, "%d", taglib_tag_track (tag));
const char* final_tag_str = g_strconcat (
tag_str, taglib_tag_title (tag), "\n", "Artist - ",
taglib_tag_artist (tag), "\n", "Album - ",
taglib_tag_album (tag), "\n", "Year - ", year, "\n",
"Comment - ", taglib_tag_comment (tag), "\n", "Track - ",
track, "\n", "Genre - ", taglib_tag_genre (tag), "\n", NULL
);
gtk_label_set_text ((GtkLabel*)(content->tag_label), final_tag_str);
}
}
}

static void
omp_content_open_file_clicked (GtkButton* source, OMPContent* content)
{
GtkFileDialog* dialog;
OMPAppWindow* parent_window
= omp_app_get_main_window ((OMPApp*)g_application_get_default ());

dialog = gtk_file_dialog_new ();
gtk_file_dialog_open (
dialog, (GtkWindow*)(parent_window), NULL,
(GAsyncReadyCallback)(omp_content_open_file), (gpointer)(content)
);
}

static void
omp_content_open_sidebar_clicked (GtkButton* source, OMPContent* content)
{
Expand Down Expand Up @@ -118,8 +178,14 @@ omp_content_class_init (OMPContentClass* self)
gtk_widget_class_bind_template_child (
GTK_WIDGET_CLASS (self), OMPContent, open_sidebar_overlay_button
);
gtk_widget_class_bind_template_child (
GTK_WIDGET_CLASS (self), OMPContent, tag_label
);

// 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
27 changes: 24 additions & 3 deletions src/resources/ui/content.blp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,30 @@ 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]
Label tag_label {
label: "";
}

[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 6bd52d5

Please sign in to comment.