2 * instance.c -- GTK+ 2 melted gui
3 * Copyright (C) 2012 Maksym Veremeyenko <verem@m1stereo.tv>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <gdk/gdkkeysyms.h>
43 GtkTargetEntry drag_targets
[] = { { (char*) "application/playlist_item_t", 0, 0 } };
45 gboolean
instance_button_click(instance_t
* app
, control_buttons_t button
)
50 case BUTTON_PLAYLIST_ITEM_ADD
:
51 omnplay_playlist_item_add(app
, 0);
53 case BUTTON_PLAYLIST_ITEM_DEL
:
54 omnplay_playlist_item_del(app
);
56 case BUTTON_PLAYLIST_ITEM_EDIT
:
57 omnplay_playlist_item_edit(app
);
59 case BUTTON_PLAYLIST_LOAD
:
60 omnplay_playlist_load(app
);
62 case BUTTON_PLAYLIST_SAVE
:
63 omnplay_playlist_save(app
);
65 case BUTTON_PLAYLIST_BLOCK_SINGLE
:
66 case BUTTON_PLAYLIST_BLOCK_LOOP
:
67 omnplay_playlist_block(app
, button
);
69 case BUTTON_PLAYLIST_ITEM_UP
:
70 omnplay_playlist_item_swap(app
, -1);
72 case BUTTON_PLAYLIST_ITEM_DOWN
:
73 omnplay_playlist_item_swap(app
, +1);
75 case BUTTON_PLAYER_CUE
:
76 case BUTTON_PLAYER_PLAY
:
77 case BUTTON_PLAYER_PAUSE
:
78 case BUTTON_PLAYER_STOP
:
79 omnplay_ctl(app
, button
);
81 case BUTTON_LIBRARY_ADD
:
82 omnplay_library_add(app
, 0);
84 case BUTTON_LIBRARY_REFRESH
:
85 omnplay_library_refresh(app
);
87 case BUTTON_LIBRARY_FIND
:
88 omnplay_library_search(app
, 0);
90 case BUTTON_LIBRARY_FIND_NEXT
:
91 omnplay_library_search(app
, 1);
93 case BUTTON_PLAYLIST_RELINK
:
94 omnplay_playlist_relink(app
);
101 static gboolean
on_button_click(GtkWidget
*button
, gpointer user_data
)
104 instance_t
* app
= (instance_t
*)user_data
;
106 for(i
= 1; i
< BUTTON_LAST
; i
++)
107 if(app
->buttons
[i
] == button
)
108 return instance_button_click(app
, (control_buttons_t
)i
);
113 static gboolean
on_main_window_delete_event( GtkWidget
*widget
, GdkEvent
*event
, gpointer user_data
)
115 g_print ("delete event occurred [start]\n");
117 instance_release((instance_t
*)user_data
);
119 g_print ("delete event occurred [finish]\n");
124 static void on_main_window_destroy( GtkWidget
*widget
, gpointer user_data
)
126 g_print ("destroy occurred\n");
130 instance_t
* instance_create(int argc
, char** argv
)
135 /* prepare application instance */
136 app
= (instance_t
*)malloc(sizeof(instance_t
));
137 memset(app
, 0, sizeof(instance_t
));
139 /* load parameters from command line */
140 if(!instance_opt(argc
, argv
, app
) && app
->players
.count
)
141 app
->window
= ui_create(app
);
148 void instance_destroy(instance_t
* app
)
153 void instance_init(instance_t
* app
)
156 pthread_mutexattr_t attr
;
158 gtk_signal_connect( GTK_OBJECT( app
->window
), "delete-event",
159 GTK_SIGNAL_FUNC(on_main_window_delete_event
), app
);
161 gtk_signal_connect( GTK_OBJECT( app
->window
), "destroy",
162 GTK_SIGNAL_FUNC(on_main_window_destroy
), app
);
165 gtk_widget_add_events(app
->playlist_grid
, GDK_BUTTON_PRESS_MASK
);
166 gtk_widget_add_events(app
->playlist_grid
, GDK_KEY_PRESS_MASK
);
167 gtk_signal_connect(GTK_OBJECT(app
->playlist_grid
), "key-press-event",
168 GTK_SIGNAL_FUNC(on_playlist_grid_key
), app
);
170 gtk_widget_add_events(app
->library_grid
, GDK_BUTTON_PRESS_MASK
);
171 gtk_widget_add_events(app
->library_grid
, GDK_KEY_PRESS_MASK
);
172 gtk_signal_connect(GTK_OBJECT(app
->library_grid
), "key-press-event",
173 GTK_SIGNAL_FUNC(on_library_grid_key
), app
);
175 gtk_signal_connect(GTK_OBJECT(app
->playlist_grid
), "button-press-event",
176 GTK_SIGNAL_FUNC(on_playlist_grid_button
), app
);
178 gtk_signal_connect(GTK_OBJECT(app
->library_grid
), "button-press-event",
179 GTK_SIGNAL_FUNC(on_library_grid_button
), app
);
183 pthread_mutexattr_init(&attr
);
184 pthread_mutexattr_settype(&attr
, PTHREAD_MUTEX_RECURSIVE
);
185 pthread_mutex_init(&app
->players
.lock
, &attr
);
186 pthread_mutex_init(&app
->playlist
.lock
, &attr
);
187 pthread_mutex_init(&app
->library
.lock
, &attr
);
188 pthread_mutexattr_destroy(&attr
);
190 /* run unit monitoring threads */
191 for(i
= 0; i
< app
->players
.count
; i
++)
194 /* attach buttons click */
195 for(i
= 1; i
< BUTTON_LAST
; i
++)
196 gtk_signal_connect(GTK_OBJECT(app
->buttons
[i
]), "clicked",
197 GTK_SIGNAL_FUNC( on_button_click
), app
);
206 void instance_release(instance_t
* app
)
212 /* stop unit monitoring threads */
213 for(i
= 0; i
< app
->players
.count
; i
++)
216 /* release laylist */
217 playlist_release(app
);
219 /* release library */
220 library_release(app
);
223 pthread_mutex_destroy(&app
->players
.lock
);
226 pthread_mutex_destroy(&app
->playlist
.lock
);
228 /* destroy library lock */
229 pthread_mutex_destroy(&app
->library
.lock
);