Update gtk154
This commit is contained in:
parent
24ef0ddd28
commit
141c341102
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
cmake_minimum_required(VERSION 3.5.0)
|
||||||
|
project(gtk154_mediaplayer3 VERSION 1.0.0)
|
||||||
|
|
||||||
|
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../GCR_CMake/macros)
|
||||||
|
include(GlibCompileResourcesSupport)
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||||
|
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||||
|
|
||||||
|
include(CPack)
|
||||||
|
include_directories(.)
|
||||||
|
include_directories(..)
|
||||||
|
|
||||||
|
#Find PkgConfig to use gtkmm3
|
||||||
|
find_package (PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules (GTK4 REQUIRED gtk4)
|
||||||
|
include_directories (${GTK4_INCLUDE_DIRS})
|
||||||
|
link_directories (${GTK4_LIBRARY_DIRS})
|
||||||
|
|
||||||
|
#Find Gettext
|
||||||
|
# find_package (Gettext REQUIRED)
|
||||||
|
# set(PO_DIR ${CMAKE_BINARY_DIR}/po/zh_CN/LC_MESSAGES)
|
||||||
|
|
||||||
|
#Source files
|
||||||
|
set(SOURCE_FILE src/main.cpp src/MyMediaPlayer.cpp src/MyItem.cpp)
|
||||||
|
|
||||||
|
#Compile Resource
|
||||||
|
|
||||||
|
# set(RESOURCE_LIST
|
||||||
|
# icons/16x16/actions/folder-images.svg
|
||||||
|
# icons/16x16/actions/list-add.svg
|
||||||
|
# icons/16x16/actions/list-remove.svg
|
||||||
|
# icons/16x16/actions/My_GtkUI.png
|
||||||
|
# icons/16x16/actions/prefs_folder.svg
|
||||||
|
# icons/48x48/actions/dialog-error.png
|
||||||
|
# icons/48x48/actions/My_GtkUI.png
|
||||||
|
# icons/scalable/status/display_prefs.svg
|
||||||
|
# prefs_stack.ui
|
||||||
|
# )
|
||||||
|
|
||||||
|
# compile_gresources(RESOURCE_FILE
|
||||||
|
# XML_OUT
|
||||||
|
# TYPE EMBED_C
|
||||||
|
# RESOURCES ${RESOURCE_LIST}
|
||||||
|
# PREFIX "/org/gtk/daleclack"
|
||||||
|
# SOURCE_DIR ${PROJECT_SOURCE_DIR}/res)
|
||||||
|
|
||||||
|
# Add a custom target to the makefile. Now make builds our resource file.
|
||||||
|
# It depends on the output RESOURCE_FILE.
|
||||||
|
|
||||||
|
# add_custom_target(resource ALL DEPENDS ${RESOURCE_FILE})
|
||||||
|
|
||||||
|
#For win32 platform,use rc resource and .ico icon
|
||||||
|
if(WIN32)
|
||||||
|
SET(CMAKE_RC_COMPILER windres)
|
||||||
|
set(app_WINRC ../icon.rc)
|
||||||
|
set_property(SOURCE ../icon.rc APPEND PROPERTY
|
||||||
|
OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/../icon.ico
|
||||||
|
)
|
||||||
|
add_executable(${PROJECT_NAME} WIN32 ${app_WINRC} ${SOURCE_FILE})
|
||||||
|
add_custom_command( TARGET ${PROJECT_NAME}
|
||||||
|
COMMAND echo * > ${CMAKE_BINARY_DIR}/.gitignore
|
||||||
|
COMMAND echo **/* > ${CMAKE_BINARY_DIR}/.hgignore)
|
||||||
|
else()
|
||||||
|
add_executable(${PROJECT_NAME} ${SOURCE_FILE})
|
||||||
|
add_custom_command( TARGET ${PROJECT_NAME}
|
||||||
|
COMMAND echo \"*\" > ${CMAKE_BINARY_DIR}/.gitignore
|
||||||
|
COMMAND echo \"**/*\" > ${CMAKE_BINARY_DIR}/.hgignore)
|
||||||
|
endif(WIN32)
|
||||||
|
|
||||||
|
#Add command to generate .gitignore and .mo files
|
||||||
|
# add_custom_command( TARGET ${PROJECT_NAME}
|
||||||
|
# COMMAND mkdir -p ${PO_DIR}
|
||||||
|
# COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} ${CMAKE_SOURCE_DIR}/po/zh_CN.po -o ${PO_DIR}/${PROJECT_NAME}.mo)
|
||||||
|
|
||||||
|
SET (CMAKE_EXTRA_CXX_FLAGS ${GTK4_CFLAGS_OTHER})
|
||||||
|
target_link_libraries (${PROJECT_NAME} ${GTK4_LIBRARIES} -lpthread)
|
|
@ -0,0 +1,5 @@
|
||||||
|
# README of My Reminder
|
||||||
|
This simple application is a reminder for the date,
|
||||||
|
and the window show the days left for the deadline set by user
|
||||||
|
|
||||||
|
The reminded date and color of text can be changed by preferences dialog.
|
|
@ -0,0 +1,43 @@
|
||||||
|
#include "MyItem.h"
|
||||||
|
#include <cstring>
|
||||||
|
// File name and path limits
|
||||||
|
#define name_max_length 256
|
||||||
|
#define path_max_length 4096
|
||||||
|
|
||||||
|
struct _MyItem
|
||||||
|
{
|
||||||
|
GObject parent_instance;
|
||||||
|
char disp_name[name_max_length];
|
||||||
|
char file_name[path_max_length];
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE(MyItem, my_item, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
const char *my_item_get_filename(MyItem *item)
|
||||||
|
{
|
||||||
|
// Get true file name
|
||||||
|
return item->file_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *my_item_get_dispname(MyItem *item)
|
||||||
|
{
|
||||||
|
// Get Base name
|
||||||
|
return item->disp_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void my_item_init(MyItem *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void my_item_class_init(MyItemClass *klass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MyItem *my_item_new(const char *dispname, const char *filename)
|
||||||
|
{
|
||||||
|
// Create a new item
|
||||||
|
MyItem *item = MY_ITEM(g_object_new(my_item_get_type(), NULL));
|
||||||
|
strncpy(item->disp_name, dispname, name_max_length);
|
||||||
|
strncpy(item->file_name, filename, path_max_length);
|
||||||
|
return item;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
#define MY_ITEM_TYPE (my_item_get_type())
|
||||||
|
G_DECLARE_FINAL_TYPE(MyItem, my_item, MY, ITEM, GObject)
|
||||||
|
|
||||||
|
const char *my_item_get_filename(MyItem *item);
|
||||||
|
|
||||||
|
const char *my_item_get_dispname(MyItem *item);
|
||||||
|
|
||||||
|
MyItem *my_item_new(const char *dispname, const char *filename);
|
|
@ -0,0 +1,146 @@
|
||||||
|
#include "MyMediaPlayer.h"
|
||||||
|
#include "MyItem.h"
|
||||||
|
|
||||||
|
struct _MyMediaPlayer
|
||||||
|
{
|
||||||
|
GtkApplicationWindow parent_instance;
|
||||||
|
GtkWidget *video;
|
||||||
|
GtkWidget *main_box, *btn_box;
|
||||||
|
GtkWidget *btn_add, *btn_remove;
|
||||||
|
GtkWidget *btn_load, *btn_save;
|
||||||
|
GtkWidget *column_view;
|
||||||
|
GListStore *music_store;
|
||||||
|
GtkSingleSelection *music_selection;
|
||||||
|
GtkListItemFactory *filename_factory;
|
||||||
|
GtkColumnViewColumn *filename_column;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE(MyMediaPlayer, my_media_player, GTK_TYPE_APPLICATION_WINDOW)
|
||||||
|
|
||||||
|
void file_dialog_response(GObject *dialog, GAsyncResult *res, gpointer data)
|
||||||
|
{
|
||||||
|
GFile *file;
|
||||||
|
MyMediaPlayer *player = MYMEDIA_PLAYER(data);
|
||||||
|
|
||||||
|
// Get file
|
||||||
|
file = gtk_file_dialog_open_finish(GTK_FILE_DIALOG(dialog), res, NULL);
|
||||||
|
if (file != NULL)
|
||||||
|
{
|
||||||
|
// Get file name
|
||||||
|
char *path = g_file_get_path(file);
|
||||||
|
char *name = g_file_get_basename(file);
|
||||||
|
g_list_store_append(player->music_store,
|
||||||
|
my_item_new(name, path));
|
||||||
|
g_object_unref(file);
|
||||||
|
g_free(path);
|
||||||
|
g_free(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void btnadd_clicked(GtkWidget *widget, MyMediaPlayer *player)
|
||||||
|
{
|
||||||
|
// Create a file dialog window
|
||||||
|
GtkFileDialog *dialog = gtk_file_dialog_new();
|
||||||
|
|
||||||
|
// Open the file dialog
|
||||||
|
gtk_file_dialog_open(dialog, GTK_WINDOW(player), NULL, file_dialog_response, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void btnremove_clicked(GtkWidget *widget, MyMediaPlayer *player)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void btnload_clicked(GtkWidget *widget, MyMediaPlayer *player)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void btnsave_clicked(GtkWidget *widget, MyMediaPlayer *player)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void filename_factory_setup(GtkListItemFactory *factory,
|
||||||
|
GtkListItem *item)
|
||||||
|
{
|
||||||
|
// Create a label
|
||||||
|
GtkWidget *label;
|
||||||
|
label = gtk_label_new(" ");
|
||||||
|
|
||||||
|
// Add the label to the item
|
||||||
|
gtk_widget_set_halign(label, GTK_ALIGN_START);
|
||||||
|
gtk_list_item_set_child(item, label);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void filename_factory_bind(GtkListItemFactory *factory,
|
||||||
|
GtkListItem *item)
|
||||||
|
{
|
||||||
|
// Get child
|
||||||
|
GtkWidget *label;
|
||||||
|
label = gtk_list_item_get_child(item);
|
||||||
|
|
||||||
|
// Get item
|
||||||
|
MyItem *file_item = MY_ITEM(gtk_list_item_get_item(item));
|
||||||
|
gtk_label_set_label(GTK_LABEL(label),
|
||||||
|
my_item_get_dispname(file_item));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void my_media_player_init(MyMediaPlayer *self)
|
||||||
|
{
|
||||||
|
// Initalize window
|
||||||
|
gtk_window_set_icon_name(GTK_WINDOW(self), "org.gtk.daleclack");
|
||||||
|
gtk_window_set_title(GTK_WINDOW(self), "Gtk4 Media Player 3");
|
||||||
|
gtk_window_set_default_size(GTK_WINDOW(self), 300, 400);
|
||||||
|
|
||||||
|
// Create widgets
|
||||||
|
self->main_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
|
||||||
|
self->video = gtk_video_new();
|
||||||
|
self->btn_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
|
||||||
|
self->btn_add = gtk_button_new_from_icon_name("list-add");
|
||||||
|
self->btn_remove = gtk_button_new_from_icon_name("list-remove");
|
||||||
|
self->btn_load = gtk_button_new_from_icon_name("go-up");
|
||||||
|
self->btn_save = gtk_button_new_from_icon_name("document-save");
|
||||||
|
gtk_widget_set_size_request(self->video, 300, 50);
|
||||||
|
|
||||||
|
// Link signals for buttons
|
||||||
|
g_signal_connect(self->btn_add, "clicked", G_CALLBACK(btnadd_clicked), self);
|
||||||
|
g_signal_connect(self->btn_remove, "clicked", G_CALLBACK(btnremove_clicked), self);
|
||||||
|
g_signal_connect(self->btn_load, "clicked", G_CALLBACK(btnload_clicked), self);
|
||||||
|
g_signal_connect(self->btn_save, "clicked", G_CALLBACK(btnsave_clicked), self);
|
||||||
|
|
||||||
|
// Create store and list view
|
||||||
|
self->music_store = g_list_store_new(MY_ITEM_TYPE);
|
||||||
|
self->music_selection = gtk_single_selection_new(G_LIST_MODEL(self->music_store));
|
||||||
|
self->column_view = gtk_column_view_new(GTK_SELECTION_MODEL(self->music_selection));
|
||||||
|
gtk_widget_set_vexpand(self->column_view, TRUE);
|
||||||
|
|
||||||
|
// Create factory for renderer
|
||||||
|
self->filename_factory = gtk_signal_list_item_factory_new();
|
||||||
|
self->filename_column = gtk_column_view_column_new("File Name",
|
||||||
|
self->filename_factory);
|
||||||
|
g_signal_connect(self->filename_factory, "setup",
|
||||||
|
G_CALLBACK(filename_factory_setup), NULL);
|
||||||
|
g_signal_connect(self->filename_factory, "bind",
|
||||||
|
G_CALLBACK(filename_factory_bind), NULL);
|
||||||
|
gtk_column_view_append_column(GTK_COLUMN_VIEW(self->column_view),
|
||||||
|
self->filename_column);
|
||||||
|
|
||||||
|
// Add widgets
|
||||||
|
gtk_box_append(GTK_BOX(self->main_box), self->video);
|
||||||
|
gtk_box_append(GTK_BOX(self->btn_box), self->btn_add);
|
||||||
|
gtk_box_append(GTK_BOX(self->btn_box), self->btn_remove);
|
||||||
|
gtk_box_append(GTK_BOX(self->btn_box), self->btn_load);
|
||||||
|
gtk_box_append(GTK_BOX(self->btn_box), self->btn_save);
|
||||||
|
gtk_box_append(GTK_BOX(self->main_box), self->btn_box);
|
||||||
|
gtk_box_append(GTK_BOX(self->main_box), self->column_view);
|
||||||
|
gtk_window_set_child(GTK_WINDOW(self), self->main_box);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void my_media_player_class_init(MyMediaPlayerClass *klass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MyMediaPlayer *my_media_player_new(GtkApplication *app)
|
||||||
|
{
|
||||||
|
// Create a window for media player
|
||||||
|
return MYMEDIA_PLAYER(g_object_new(my_media_player_get_type(),
|
||||||
|
"application", app, NULL));
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE(MyMediaPlayer, my_media_player, MYMEDIA, PLAYER, GtkApplicationWindow)
|
||||||
|
|
||||||
|
MyMediaPlayer *my_media_player_new(GtkApplication *app);
|
|
@ -0,0 +1,17 @@
|
||||||
|
#include "MyMediaPlayer.h"
|
||||||
|
|
||||||
|
static void gtkmain(GtkApplication *app, gpointer user_data)
|
||||||
|
{
|
||||||
|
// Create a media player window and run
|
||||||
|
MyMediaPlayer *media_player = my_media_player_new(app);
|
||||||
|
gtk_window_present(GTK_WINDOW(media_player));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
// Create a application and run
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Reference in New Issue