/* * instance.c -- GTK+ 2 melted gui * Copyright (C) 2012 Maksym Veremeyenko * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include #include #include #include "instance.h" #include "ui.h" #include "opts.h" #include "timecode.h" #include "player.h" static gboolean on_main_window_delete_event( GtkWidget *widget, GdkEvent *event, gpointer user_data ) { g_print ("delete event occurred [start]\n"); gdk_threads_leave(); instance_release((instance_t*)user_data); gdk_threads_enter(); g_print ("delete event occurred [finish]\n"); return FALSE; } static void on_main_window_destroy( GtkWidget *widget, gpointer user_data ) { g_print ("destroy occurred\n"); gtk_main_quit(); } instance_t* instance_create(int argc, char** argv) { int i, c; instance_t* app; /* prepare application instance */ app = (instance_t*)malloc(sizeof(instance_t)); memset(app, 0, sizeof(instance_t)); /* load parameters from command line */ if(!instance_opt(argc, argv, app) && app->players.count) app->window = ui_create(app); else instance_usage(); return app; }; void instance_destroy(instance_t* app) { free(app); }; void instance_init(instance_t* app) { int i; pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); gtk_signal_connect( GTK_OBJECT( app->window ), "delete-event", GTK_SIGNAL_FUNC(on_main_window_delete_event), app); gtk_signal_connect( GTK_OBJECT( app->window ), "destroy", GTK_SIGNAL_FUNC(on_main_window_destroy), app); #if 0 gtk_widget_add_events(app->playlist_grid, GDK_BUTTON_PRESS_MASK); gtk_widget_add_events(app->playlist_grid, GDK_KEY_PRESS_MASK); gtk_signal_connect(GTK_OBJECT(app->playlist_grid), "key-press-event", GTK_SIGNAL_FUNC(on_playlist_grid_key), app); gtk_widget_add_events(app->library_grid, GDK_BUTTON_PRESS_MASK); gtk_widget_add_events(app->library_grid, GDK_KEY_PRESS_MASK); gtk_signal_connect(GTK_OBJECT(app->library_grid), "key-press-event", GTK_SIGNAL_FUNC(on_library_grid_key), app); gtk_signal_connect(GTK_OBJECT(app->playlist_grid), "button-press-event", GTK_SIGNAL_FUNC(on_playlist_grid_button), app); gtk_signal_connect(GTK_OBJECT(app->library_grid), "button-press-event", GTK_SIGNAL_FUNC(on_library_grid_button), app); #endif /* create lock */ pthread_mutex_init(&app->players.lock, &attr); pthread_mutex_init(&app->playlist.lock, &attr); pthread_mutex_init(&app->library.lock, &attr); pthread_mutexattr_destroy(&attr); /* run unit monitoring threads */ for(i = 0; i < app->players.count; i++) player_run(app, i); #if 0 /* attach buttons click */ for(i = 1; i < BUTTON_LAST; i++) gtk_signal_connect(GTK_OBJECT(app->buttons[i]), "clicked", GTK_SIGNAL_FUNC( on_button_click), app ); /* load library */ omnplay_library_load(app); #endif #if 0 /* setup drag n drop source/target */ static GtkTargetEntry drag_targets[] = { { (char*) "application/playlist_item_t", 0, 0 } }; gtk_drag_source_set(app->library_grid, GDK_BUTTON1_MASK, drag_targets, 1, (GdkDragAction)(GDK_ACTION_COPY)); gtk_drag_source_set(app->playlist_grid, GDK_BUTTON1_MASK, drag_targets, 1, (GdkDragAction)(GDK_ACTION_COPY | GDK_ACTION_MOVE)); gtk_drag_dest_set(app->playlist_grid, (GtkDestDefaults)(GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP), drag_targets, 1, (GdkDragAction)(GDK_ACTION_COPY | GDK_ACTION_MOVE)); g_signal_connect (app->library_grid, "drag_data_get", G_CALLBACK(library_grid_drag_data_get_cb), app); g_signal_connect (app->playlist_grid, "drag_data_get", G_CALLBACK(playlist_grid_drag_data_get_cb), app); g_signal_connect (app->library_grid, "drag_begin", G_CALLBACK(library_grid_drag_begin_cb), app); g_signal_connect (app->playlist_grid, "drag_begin", G_CALLBACK(playlist_grid_drag_begin_cb), app); g_signal_connect (app->playlist_grid, "drag_data_received", G_CALLBACK (playlist_grid_drag_data_received), app); g_signal_connect (app->playlist_grid, "drag_data_delete", G_CALLBACK (playlist_grid_drag_data_delete), app); g_signal_connect (app->playlist_grid, "drag_motion", G_CALLBACK (playlist_grid_drag_motion), app); #endif }; void instance_release(instance_t* app) { int i; app->f_exit = 1; /* stop unit monitoring threads */ for(i = 0; i < app->players.count; i++) player_stop(app, i); /* destroy lock */ pthread_mutex_destroy(&app->players.lock); /* destroy lock */ pthread_mutex_destroy(&app->playlist.lock); #if 0 /* load library */ omnplay_library_save(app); #endif /* destroy library lock */ pthread_mutex_destroy(&app->library.lock); };