Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5e086b4

Browse files
committedApr 12, 2024·
Add initial tag reading test support.
1 parent 4076aa3 commit 5e086b4

File tree

3 files changed

+98
-5
lines changed

3 files changed

+98
-5
lines changed
 

‎src/content.c

+69
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
#include "appwin.h"
88
#include "sidebar.h"
99

10+
#include "taglib/tag_c.h"
11+
1012
struct _OMPContent {
1113
AdwBin parent;
1214

1315
GtkWidget* content_label;
1416
GtkWidget* open_sidebar_overlay_button;
17+
GtkWidget* tag_label;
1518
};
1619

1720
G_DEFINE_TYPE (OMPContent, omp_content, ADW_TYPE_BIN);
@@ -35,6 +38,66 @@ omp_content_change_content (
3538
omp_content_set_content (content, page_name);
3639
}
3740

41+
static void
42+
omp_content_open_file (GObject* gobject, GAsyncResult* result, gpointer data)
43+
{
44+
g_autoptr (GError) error = NULL;
45+
g_autoptr (GFile) gfile = gtk_file_dialog_open_finish (
46+
GTK_FILE_DIALOG (gobject), result, &error
47+
);
48+
49+
OMPContent* content = data;
50+
51+
if (error != NULL) {
52+
// the operation failed, or it was cancelled by the user
53+
}
54+
else {
55+
const char* filename = g_file_get_path (gfile);
56+
57+
TagLib_File* file;
58+
TagLib_Tag* tag;
59+
60+
file = taglib_file_new (filename);
61+
62+
if (file == NULL)
63+
return;
64+
65+
tag = taglib_file_tag (file);
66+
67+
if (tag != NULL) {
68+
char* tag_str = "Title - ";
69+
char year[5];
70+
sprintf(year, "%d", taglib_tag_year (tag));
71+
char track[5];
72+
sprintf(track, "%d", taglib_tag_track (tag));
73+
const char* final_tag_str = g_strconcat(tag_str,
74+
taglib_tag_title (tag), "\n",
75+
"Artist - ", taglib_tag_artist (tag), "\n",
76+
"Album - ", taglib_tag_album (tag), "\n",
77+
"Year - ", year, "\n",
78+
"Comment - ", taglib_tag_comment (tag), "\n",
79+
"Track - ", track, "\n",
80+
"Genre - ", taglib_tag_genre (tag), "\n", NULL
81+
);
82+
gtk_label_set_text ((GtkLabel*)(content->tag_label), final_tag_str);
83+
}
84+
}
85+
}
86+
87+
static void
88+
omp_content_open_file_clicked (GtkButton* source, OMPContent* content)
89+
{
90+
// ...
91+
GtkFileDialog* dialog;
92+
OMPAppWindow* parent_window
93+
= omp_app_get_main_window ((OMPApp*)g_application_get_default ());
94+
95+
dialog = gtk_file_dialog_new ();
96+
gtk_file_dialog_open (
97+
dialog, (GtkWindow*) (parent_window), NULL, G_CALLBACK (omp_content_open_file), (gpointer)(content)
98+
);
99+
}
100+
38101
static void
39102
omp_content_open_sidebar_clicked (GtkButton* source, OMPContent* content)
40103
{
@@ -118,8 +181,14 @@ omp_content_class_init (OMPContentClass* self)
118181
gtk_widget_class_bind_template_child (
119182
GTK_WIDGET_CLASS (self), OMPContent, open_sidebar_overlay_button
120183
);
184+
gtk_widget_class_bind_template_child (
185+
GTK_WIDGET_CLASS (self), OMPContent, tag_label
186+
);
121187

122188
// Callbacks
189+
gtk_widget_class_bind_template_callback (
190+
GTK_WIDGET_CLASS (self), omp_content_open_file_clicked
191+
);
123192
gtk_widget_class_bind_template_callback (
124193
GTK_WIDGET_CLASS (self), omp_content_open_sidebar_clicked
125194
);

‎src/meson.build

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
add_project_arguments('-ltag_c', language: 'c')
12
add_project_arguments('-Wno-unused-parameter', language: 'c')
23

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

68
program_name = 'omp'
79

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

2729
executable(
2830
program_name, [
29-
omp_resources,
30-
omp_style_resources,
3131
'app.c',
3232
'sidebar.c',
3333
'content.c',
3434
'appwin.c',
3535
'main.c',
36+
omp_resources,
37+
omp_style_resources,
3638
],
3739
dependencies: [
3840
gtk,
3941
libadwaita,
42+
taglib,
4043
],
4144
install: true,
4245
)

‎src/resources/ui/content.blp

+24-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,30 @@ template $OMPContent : Adw.Bin {
1919
}
2020
}
2121

22-
Adw.Bin main_container {
23-
Label content_label {
24-
label: "Content";
22+
Gtk.CenterBox main_container {
23+
[center]
24+
Box main_box {
25+
orientation: vertical;
26+
27+
[start]
28+
Label content_label {
29+
label: "Content";
30+
}
31+
32+
[end]
33+
Label tag_label {
34+
label: "";
35+
}
36+
37+
[end]
38+
Gtk.Button open_file_button {
39+
can-shrink: true;
40+
clicked => $omp_content_open_file_clicked();
41+
42+
Adw.ButtonContent {
43+
label: "Open File";
44+
}
45+
}
2546
}
2647
}
2748
}

0 commit comments

Comments
 (0)
Please sign in to comment.