From da418698e45d3431a3c65e9a56495b279c655682 Mon Sep 17 00:00:00 2001 From: daleclack Date: Sat, 16 Mar 2024 22:44:24 +0800 Subject: [PATCH] Add media player for My Gtk UI --- Gtk4_Reset/CMakeLists.txt | 30 +- .../scalable/status/media-app-running.svg | 454 ++++++++++++++++++ .../res/icons/scalable/status/media-app.svg | 110 +++++ Gtk4_Reset/res/mydock.ui | 41 ++ Gtk4_Reset/src/apps/MyMediaPlayer.h | 2 +- Gtk4_Reset/src/media_app/MyMediaPlayer.cpp | 5 +- Gtk4_Reset/src/ui/MyDock.cpp | 79 ++- 7 files changed, 703 insertions(+), 18 deletions(-) create mode 100644 Gtk4_Reset/res/icons/scalable/status/media-app-running.svg create mode 100644 Gtk4_Reset/res/icons/scalable/status/media-app.svg diff --git a/Gtk4_Reset/CMakeLists.txt b/Gtk4_Reset/CMakeLists.txt index 4245017..9bd40e0 100644 --- a/Gtk4_Reset/CMakeLists.txt +++ b/Gtk4_Reset/CMakeLists.txt @@ -128,7 +128,35 @@ set(RESOURCE_LIST icons/scalable/status/calcapp.svg icons/scalable/status/calcapp_running.svg icons/scalable/status/mines_app.svg - icons/scalable/status/mines_app_running.svg) + icons/scalable/status/mines_app_running.svg + icons/scalable/status/media-app.svg + icons/scalable/status/media-app-running.svg + icons/scalable/status/media-eject-dark.svg + icons/scalable/status/media-eject.svg + icons/scalable/status/media-mount-dark.svg + icons/scalable/status/media-mount.svg + icons/scalable/status/media-playback-pause-dark.svg + icons/scalable/status/media-playback-pause.svg + icons/scalable/status/media-playback-start-dark.svg + icons/scalable/status/media-playback-start.svg + icons/scalable/status/media-playback-stop-dark.svg + icons/scalable/status/media-playback-stop.svg + icons/scalable/status/media-playlist-append-dark.svg + icons/scalable/status/media-playlist-append.svg + icons/scalable/status/media-playlist-normal-dark.svg + icons/scalable/status/media-playlist-normal.svg + icons/scalable/status/media-playlist-play-dark.svg + icons/scalable/status/media-playlist-play.svg + icons/scalable/status/media-playlist-repeat-dark.svg + icons/scalable/status/media-playlist-repeat-one-dark.svg + icons/scalable/status/media-playlist-repeat.svg + icons/scalable/status/media-playlist-repeat-one.svg + icons/scalable/status/media-playlist-shuffle-dark.svg + icons/scalable/status/media-playlist-shuffle.svg + icons/scalable/status/media-seek-backward-dark.svg + icons/scalable/status/media-seek-backward.svg + icons/scalable/status/media-seek-forward-dark.svg + icons/scalable/status/media-seek-forward.svg) compile_gresources(RESOURCE_FILE XML_OUT diff --git a/Gtk4_Reset/res/icons/scalable/status/media-app-running.svg b/Gtk4_Reset/res/icons/scalable/status/media-app-running.svg new file mode 100644 index 0000000..b982db9 --- /dev/null +++ b/Gtk4_Reset/res/icons/scalable/status/media-app-running.svg @@ -0,0 +1,454 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Gtk4_Reset/res/icons/scalable/status/media-app.svg b/Gtk4_Reset/res/icons/scalable/status/media-app.svg new file mode 100644 index 0000000..f84a757 --- /dev/null +++ b/Gtk4_Reset/res/icons/scalable/status/media-app.svg @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Gtk4_Reset/res/mydock.ui b/Gtk4_Reset/res/mydock.ui index e47cef9..026eee7 100644 --- a/Gtk4_Reset/res/mydock.ui +++ b/Gtk4_Reset/res/mydock.ui @@ -153,6 +153,19 @@ 0 + + + 1 + 1 + + + media-app + 48 + + + 0 + + @@ -676,6 +689,34 @@ + + + 1 + 1 + + + vertical + 5 + + + media-app + 48 + + + + + Media Player + + + + + 0 + + 2 + 2 + + + diff --git a/Gtk4_Reset/src/apps/MyMediaPlayer.h b/Gtk4_Reset/src/apps/MyMediaPlayer.h index eb97f61..c649108 100644 --- a/Gtk4_Reset/src/apps/MyMediaPlayer.h +++ b/Gtk4_Reset/src/apps/MyMediaPlayer.h @@ -34,4 +34,4 @@ void my_media_player_load_random_audio(MyMediaPlayer *player); void my_media_player_reload_audio(MyMediaPlayer *player); -MyMediaPlayer *my_media_player_new(GtkApplication *app); +MyMediaPlayer *my_media_player_new(); diff --git a/Gtk4_Reset/src/media_app/MyMediaPlayer.cpp b/Gtk4_Reset/src/media_app/MyMediaPlayer.cpp index ac76ad6..d956b4e 100644 --- a/Gtk4_Reset/src/media_app/MyMediaPlayer.cpp +++ b/Gtk4_Reset/src/media_app/MyMediaPlayer.cpp @@ -754,9 +754,8 @@ static void my_media_player_class_init(MyMediaPlayerClass *klass) GTK_WINDOW_CLASS(klass)->close_request = my_media_player_close_request; } -MyMediaPlayer *my_media_player_new(GtkApplication *app) +MyMediaPlayer *my_media_player_new() { // Create a window for media player - return MYMEDIA_PLAYER(g_object_new(my_media_player_get_type(), - "application", app, NULL)); + return MYMEDIA_PLAYER(g_object_new(my_media_player_get_type(), NULL)); } diff --git a/Gtk4_Reset/src/ui/MyDock.cpp b/Gtk4_Reset/src/ui/MyDock.cpp index 1c1b131..bf2457a 100644 --- a/Gtk4_Reset/src/ui/MyDock.cpp +++ b/Gtk4_Reset/src/ui/MyDock.cpp @@ -10,6 +10,7 @@ #include "TextEditor.h" #include "ImageApp.h" #include "MineSweeper.h" +#include "MyMediaPlayer.h" #include #include @@ -31,26 +32,27 @@ struct _MyDock *launchpad_page, *apps_stack, *default_box, *addon_box, *apps_switcher, *apps_view, *appgrid_box, *appgrid_label; GtkWidget *btnfiles, *btndraw, *btncalc, *btnedit, *btnimage, // Dock buttons - *btnset, *btngame, *btngame24, *btnmine; + *btnset, *btngame, *btngame24, *btnmine, *btnmedia; GtkWidget *image_file, *image_draw, *image_calc, *image_game, // Image widget for dock buttons - *image_edit, *image_viewer, *image_game24, *image_mine, *image_set; + *image_edit, *image_viewer, *image_game24, *image_mine, *image_set, *image_media; GtkWidget *padabout, *padaud, *paddraw, *padfile, *padgedit, // Launchpad icons *padgame, *padimage, *padnote, *padedit, *padvlc, *padvlc_win32, - *padrun, *padset, *padgame24, *padcalc, *padmine; + *padrun, *padset, *padgame24, *padcalc, *padmine, *padmedia; PadPage current_page; GtkBuilder *menu_builder; GMenuModel *menu_model; GtkGesture *gesture; - GtkWidget *context_menu; // Context menu - MyPrefs *prefs_win; // Prefs window - FileWindow *file_win; // File Broswer window - GameApp *game_win; // The Guess Game - CalcApp *calc_win; // Calc App - Game24App *game24_win; // 24 Game Window - DrawApp *draw_win; // A Drawing App - TextEditor *edit_win; // Text Editor - ImageApp *image_app; // Image Viewer - MineSweeper *mine_app; // Mine Sweeper + GtkWidget *context_menu; // Context menu + MyPrefs *prefs_win; // Prefs window + FileWindow *file_win; // File Broswer window + GameApp *game_win; // The Guess Game + CalcApp *calc_win; // Calc App + Game24App *game24_win; // 24 Game Window + DrawApp *draw_win; // A Drawing App + TextEditor *edit_win; // Text Editor + ImageApp *image_app; // Image Viewer + MineSweeper *mine_app; // Mine Sweeper + MyMediaPlayer *media_app; // Media Player }; G_DEFINE_TYPE(MyDock, my_dock, GTK_TYPE_BOX) @@ -516,6 +518,48 @@ static gboolean mine_win_closed(GtkWidget *win, MyDock *dock) return TRUE; } +// Media Player control functions +static void padmedia_clicked(GtkWidget *widget, MyDock *dock) +{ + // When the window visible, unminimize it + if (gtk_widget_get_visible(GTK_WIDGET((dock->media_app)))) + { + gtk_window_unminimize(GTK_WINDOW(dock->media_app)); + } + else + { + // Show the window + gtk_window_set_transient_for(GTK_WINDOW(dock->media_app), dock->parent_win); + gtk_window_present(GTK_WINDOW(dock->media_app)); + } + gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_media), "media-app-running"); + btnlaunch_clicked(NULL, dock); +} + +static void btnmedia_clicked(GtkWidget *widget, MyDock *dock) +{ + // When the window visible, control window state + if (gtk_widget_get_visible(GTK_WIDGET((dock->media_app)))) + { + window_ctrl(GTK_WINDOW(dock->media_app), dock->parent_win); + } + else + { + // Show the window + gtk_window_set_transient_for(GTK_WINDOW(dock->media_app), dock->parent_win); + gtk_window_present(GTK_WINDOW(dock->media_app)); + } + gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_media), "media-app-running"); +} + +static gboolean media_win_closed(GtkWidget *win, MyDock *dock) +{ + // Hide the window + gtk_widget_set_visible(win, FALSE); + gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_media), "media-app"); + return TRUE; +} + // Add-on Apps launch functions static void padvlc_clicked(GtkWidget *widget, MyDock *dock) { @@ -582,6 +626,8 @@ static void my_dock_get_widgets(MyDock *self) self->image_mine = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "image_mine")); self->btnset = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "btnset")); self->image_set = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "image_set")); + self->btnmedia = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "btnmedia")); + self->image_media = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "image_media")); self->launchpad_stack = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "launchpad_stack")); self->default_page = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "default_page")); self->launchpad_page = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "launchpad_page")); @@ -600,6 +646,7 @@ static void my_dock_get_widgets(MyDock *self) self->padgedit = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padgedit")); self->padimage = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padimage")); self->padmine = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padmine")); + self->padmedia = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padmedia")); self->padnote = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padnote")); self->padrun = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padrun")); self->padset = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padset")); @@ -698,6 +745,12 @@ static void my_dock_init(MyDock *self) g_signal_connect(self->padmine, "clicked", G_CALLBACK(padmine_clicked), self); g_signal_connect(self->mine_app, "close-request", G_CALLBACK(mine_win_closed), self); + // Media Player Window + self->media_app = my_media_player_new(); + g_signal_connect(self->btnmedia, "clicked", G_CALLBACK(btnmedia_clicked), self); + g_signal_connect(self->padmedia, "clicked", G_CALLBACK(padmedia_clicked), self); + g_signal_connect(self->media_app, "close-request", G_CALLBACK(media_win_closed), self); + // Signal for app runner g_signal_connect(self->padrun, "clicked", G_CALLBACK(padrun_clicked), self);