Add gtk4-video-test

This commit is contained in:
daleclack 2021-03-11 10:10:54 +08:00
parent a015472910
commit 3422edab01
6 changed files with 207 additions and 0 deletions

View File

@ -0,0 +1,39 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
//This is the gtk4 config file on vscode
//Due to no gtk4 on debian and ubuntu till now,the configure only support manjaro(Arch linux may can use it)
"${workspaceFolder}/**",
"/usr/include/gtk-4.0/**",
"/usr/include/pango-1.0/**",
"/usr/include/glib-2.0/**",
"/usr/lib/glib-2.0/include/**",
"/usr/include/harfbuzz/**",
"/usr/include/freetype2/**",
"/usr/include/libpng16/**",
"/usr/include/libmount/**",
"/usr/include/blkid/**",
"/usr/include/fribidi/**",
"/usr/include/cairo/**",
"/usr/include/lzo/**",
"/usr/include/pixman-1/**",
"/usr/include/gdk-pixbuf-2.0/**",
"/usr/include/graphene-1.0/**",
"/usr/lib/graphene-1.0/include/**",
"/usr/include/gio-unix-2.0/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-arm64",
"compilerArgs": [
"`pkg-config --cflags --libs gtk+-3.0`"
],
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}

29
Gtk4/video_test/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/gtk4-video",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}

4
Gtk4/video_test/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"C_Cpp.errorSquiggles": "Disabled",
"cmake.configureOnOpen": false
}

62
Gtk4/video_test/.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,62 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"src/*.cpp",
"-o",
"${workspaceFolder}/bin/gtk4-video",
"-pthread",
"-I${workspaceFolder}/",
"-I/usr/include/gtk-4.0",
"-I/usr/include/pango-1.0",
"-I/usr/include/glib-2.0",
"-I/usr/lib/glib-2.0/include",
"-I/usr/include/harfbuzz",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/libmount",
"-I/usr/include/blkid",
"-I/usr/include/fribidi",
"-I/usr/include/cairo",
"-I/usr/include/lzo",
"-I/usr/include/pixman-1",
"-I/usr/include/gdk-pixbuf-2.0",
"-I/usr/include/graphene-1.0",
"-I/usr/lib/graphene-1.0/include",
"-I/usr/include/gio-unix-2.0",
"-mfpmath=sse",
"-msse",
"-msse2",
"-lgtk-4",
"-lpangocairo-1.0",
"-lpango-1.0",
"-lharfbuzz",
"-lgdk_pixbuf-2.0",
"-lcairo-gobject",
"-lcairo",
"-lvulkan",
"-lgraphene-1.0",
"-lgio-2.0",
"-lgobject-2.0",
"-lglib-2.0"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

Binary file not shown.

View File

@ -0,0 +1,73 @@
#include <gtk/gtk.h>
static GtkWidget *video;
static void dialog_response(GtkWidget *widget,int response,GtkWindow *window){
//Get File and set the file to the mediacontrols
if(response==GTK_RESPONSE_OK){
//Get media File and filename
char *filename=NULL;
char title[100];
GFile *file=gtk_file_chooser_get_file(GTK_FILE_CHOOSER(widget));
gtk_video_set_file(GTK_VIDEO(video),file);
filename=g_file_get_basename(file);
sprintf(title,"%s-gtk4-media",filename);
gtk_window_set_title(GTK_WINDOW(window),title);
//Free the memory
g_object_unref(file);
free(filename);
}
gtk_window_destroy(GTK_WINDOW(widget));
//g_object_unref(widget);
}
static void dialog_open(GtkWidget *widget,GtkWindow *parent){
//Set a dialog and choose the file
GtkWidget *dialog;
GtkFileChooserAction action=GTK_FILE_CHOOSER_ACTION_OPEN;
dialog=gtk_file_chooser_dialog_new("Open Media File",parent,action,
"OK",GTK_RESPONSE_OK,"Cancel",GTK_RESPONSE_CANCEL,NULL);
//Set filter
GtkFileFilter *filter;
filter=gtk_file_filter_new();
gtk_file_filter_add_pattern(filter,"*.mp3");
gtk_file_filter_add_pattern(filter,"*.mp4");
gtk_file_filter_add_pattern(filter,"*.wav");
gtk_file_filter_add_pattern(filter,"*.flac");
gtk_file_filter_add_pattern(filter,"*.aac");
gtk_file_filter_add_pattern(filter,"*.m4a");
gtk_file_filter_add_pattern(filter,"*.3gp");
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog),filter);
g_signal_connect(dialog,"response",G_CALLBACK(dialog_response),parent);
gtk_widget_show(dialog);
}
static void gtkmain(GtkApplication *app,gpointer user_data){
GtkWidget *window,*header,*btnopen;
//Initalize window
window=gtk_application_window_new(app);
gtk_window_set_icon_name(GTK_WINDOW(window),"org.gtk.daleclack");
gtk_window_set_default_size(GTK_WINDOW(window),960,540);
gtk_window_set_title(GTK_WINDOW(window),"Gtk4 video test");
//GtkVideo widget
video=gtk_video_new();
gtk_window_set_child(GTK_WINDOW(window),video);
//Header Bar
header=gtk_header_bar_new();
gtk_header_bar_set_show_title_buttons(GTK_HEADER_BAR(header),TRUE);
gtk_header_bar_set_decoration_layout(GTK_HEADER_BAR(header),"close,minimize,maximize:menu");
//"Open File" button
btnopen=gtk_button_new_with_label("Open Media File");
g_signal_connect(btnopen,"clicked",G_CALLBACK(dialog_open),window);
gtk_header_bar_pack_end(GTK_HEADER_BAR(header),btnopen);
gtk_window_set_titlebar(GTK_WINDOW(window),header);
gtk_window_set_focus(GTK_WINDOW(window),btnopen);
gtk_widget_show(window);
}
int main(int argc,char *argv[]){
GtkApplication *app;
app=gtk_application_new("org.gtk.daleclack",G_APPLICATION_NON_UNIQUE);
g_signal_connect(app,"activate",G_CALLBACK(gtkmain),NULL);
return g_application_run(G_APPLICATION(app),argc,argv);
}