7
7
#include "appwin.h"
8
8
#include "sidebar.h"
9
9
10
+ #include "taglib/tag_c.h"
11
+
10
12
struct _OMPContent {
11
13
AdwBin parent ;
12
14
13
15
GtkWidget * content_label ;
14
16
GtkWidget * open_sidebar_overlay_button ;
17
+ GtkWidget * tag_label ;
15
18
};
16
19
17
20
G_DEFINE_TYPE (OMPContent , omp_content , ADW_TYPE_BIN );
@@ -35,6 +38,66 @@ omp_content_change_content (
35
38
omp_content_set_content (content , page_name );
36
39
}
37
40
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
+
38
101
static void
39
102
omp_content_open_sidebar_clicked (GtkButton * source , OMPContent * content )
40
103
{
@@ -118,8 +181,14 @@ omp_content_class_init (OMPContentClass* self)
118
181
gtk_widget_class_bind_template_child (
119
182
GTK_WIDGET_CLASS (self ), OMPContent , open_sidebar_overlay_button
120
183
);
184
+ gtk_widget_class_bind_template_child (
185
+ GTK_WIDGET_CLASS (self ), OMPContent , tag_label
186
+ );
121
187
122
188
// Callbacks
189
+ gtk_widget_class_bind_template_callback (
190
+ GTK_WIDGET_CLASS (self ), omp_content_open_file_clicked
191
+ );
123
192
gtk_widget_class_bind_template_callback (
124
193
GTK_WIDGET_CLASS (self ), omp_content_open_sidebar_clicked
125
194
);
0 commit comments