-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
203 lines (161 loc) · 5.11 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include <gtk/gtk.h>
#include <assert.h>
#include <time.h>
#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
#include "util.h"
#include "dv.h"
#include "global.h"
#include "config.h"
// Globals
struct _DVControl DVControl;
// Widgets
GtkWidget *framelabel;
GtkWidget *playbutton;
GtkWidget *frameentry;
GtkWidget *playbuttonimage;
GObject *frameadjustment;
/* Signal handlers */
void destroy (GtkWidget *widget, gpointer data)
{
playerstate = PLAYER_STATE_TERMINATE;
while(playerstate != PLAYER_STATE_TERMINATED);
gtk_main_quit();
}
int update_framedisp()
{
if (!GTK_IS_LABEL(framelabel)) return FALSE; // program closed
// Label
char labeltext[100];
strcpy(labeltext, long2string(DVControl.currentframe));
strcat(labeltext, " / ");
strcat(labeltext, long2string(DVControl.totalframes));
gtk_label_set_text(GTK_LABEL(framelabel), labeltext);
// Slider
if (DVControl.totalframes != 0 && playerstate != PLAYER_STATE_NEWPOS_PERCENT)
DVControl.pos_percent = DVControl.currentframe * 100. / DVControl.totalframes;
gtk_adjustment_set_value(GTK_ADJUSTMENT(frameadjustment), DVControl.pos_percent);
return TRUE;
}
gboolean button_play_toggle(GtkWidget *widget)
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget))) // State before switching
{
gtk_image_set_from_icon_name (GTK_IMAGE(playbuttonimage),
"media-playback-start", GTK_ICON_SIZE_DIALOG);
playerstate = PLAYER_STATE_PAUSE;
}
else
{
playerstate = PLAYER_STATE_CONTINUE;
gtk_image_set_from_icon_name (GTK_IMAGE(playbuttonimage),
"media-playback-pause", GTK_ICON_SIZE_DIALOG);
}
return FALSE;
}
void add_movie_to_list(GtkWidget *movlist, const gchar *name)
{
GtkListStore *store;
GtkTreeIter iter;
store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(movlist)));
gtk_list_store_append(store, &iter); // get iter at end
gtk_list_store_set(store, &iter, 0, name, -1);
}
// Change filename if different List item (=movie) is selected
void on_movlist_selection_changed(GtkWidget *selection)
{
GtkTreeModel *model;
GtkTreeIter iter;
char *value;
if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection), &model, &iter))
{
gtk_tree_model_get(model, &iter, 0, &value, -1);
static char *path;
path = movie_get_path_by_name(value);
DVControl.filename = path;
playerstate = PLAYER_STATE_PAUSE_NEWSOURCE;
// Start into the movie with a pause, wait for button press
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(playbutton), FALSE);
gtk_image_set_from_icon_name (GTK_IMAGE(playbuttonimage),
"media-playback-start", GTK_ICON_SIZE_DIALOG);
}
}
void setframe_activated(GtkWidget *widget)
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(playbutton), FALSE);
gtk_image_set_from_icon_name (GTK_IMAGE(playbuttonimage),
"media-playback-start", GTK_ICON_SIZE_DIALOG);
char *frametext = (char *)gtk_entry_get_text(GTK_ENTRY(frameentry));
long frame = string2long(frametext);
if (frame < 0) frame = 0;
DVControl.newpos = frame*BYTES_PER_FRAME;
playerstate = PLAYER_STATE_NEWPOS;
}
void on_frameadjustment_changed(GObject *frameadj)
{
double sliderpos = gtk_adjustment_get_value(GTK_ADJUSTMENT(frameadj));
// if slider was manually moved (not by playing the video)
if (sliderpos != DVControl.pos_percent)
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(playbutton), FALSE);
gtk_image_set_from_icon_name (GTK_IMAGE(playbuttonimage),
"media-playback-start", GTK_ICON_SIZE_DIALOG);
DVControl.pos_percent = sliderpos;
playerstate = PLAYER_STATE_NEWPOS_PERCENT;
}
}
/* Initializer */
static GtkWidget *create_window (void)
{
GtkWidget *window;
GtkWidget *movlist;
GError* error = NULL;
/* Load UI from file */
GtkBuilder *builder;
{
builder = gtk_builder_new ();
if (!gtk_builder_add_from_file (builder, UI_FILE, &error))
{
g_critical ("Couldn't load builder file: %s", error->message);
g_error_free (error);
}
/* Auto-connect signal handlers */
gtk_builder_connect_signals (builder, NULL);
/* Get the window object from the ui file */
window = GTK_WIDGET (gtk_builder_get_object (builder, "window" ));
movlist = GTK_WIDGET (gtk_builder_get_object (builder, "movlist" ));
framelabel = GTK_WIDGET (gtk_builder_get_object (builder, "framelabel" ));
playbutton = GTK_WIDGET (gtk_builder_get_object (builder, "playbutton" ));
frameentry = GTK_WIDGET (gtk_builder_get_object (builder, "frameentry" ));
playbuttonimage = GTK_WIDGET (gtk_builder_get_object (builder, "playbuttonimage"));
frameadjustment = G_OBJECT(gtk_builder_get_object (builder, "frameadjustment"));
gtk_widget_set_visible(movlist, TRUE);
/* Load Movies */
{
int mnum = 0;
char **movienames = get_movie_names();
while(movienames[mnum]) add_movie_to_list(movlist, movienames[mnum++]);
}
}
g_object_unref (builder);
return window;
}
int main (int argc, char *argv[])
{
// Read config
if (!readmovies())
{
fprintf(stderr, "ERROR: Config File not found!\n");
exit(EXIT_FAILURE);
}
// Start application
GtkWidget *window;
gtk_init (&argc, &argv);
window = create_window ();
gtk_widget_show (window);
init_dvsystem();
g_timeout_add(1000/25, update_framedisp, NULL);
gtk_main ();
exit(EXIT_SUCCESS);
}