📄 interface.c
字号:
/* Nemesis * Copyright (C) 1999 John Ferlito <johnf@inodes.org> * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. * */#include <gtk/gtk.h>#include <gdk_imlib.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/time.h>#include "config.h"#include "menus.h"#include "interface.h"#include "show_image.h"#include "parse.h"int currentdir = 0;char currentfile[ZEROS] = "00000";char dirs[24][DIRSIZE];int num_dirs;int fps = FRAMES;long long delay;int idle_func;int playing = FALSE;int hour, min, sec, tenth;int fpsth=0;long long oldtime;GtkWidget *pixmap;GdkPixmap *image; GdkBitmap *mask;GtkWidget *spin_hour, *spin_min, *spin_sec, *spin_tenth;GtkObject *adj_h, *adj_m, *adj_s, *adj_t;int main(int argc, char *argv[]){ GtkWidget *window; GtkWidget *menu_bar; GtkWidget *main_vbox, *video_vbox, *spin_hbox, *buttons_hbox; GtkWidget *play_button, *stop_button, *snap_button, *save_button; gtk_init(&argc, &argv); /* let gtk get display etc */ gdk_init(&argc, &argv); /* let gdk get display etc */ gdk_imlib_init(); parse_rc(RC_FILE); /* Create Window */ window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW (window), "Glengarry Security System"); gtk_widget_set_usize(GTK_WIDGET(window), 340, 400); gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(gtk_exit), NULL); /* Create main box for packing */ main_vbox = gtk_vbox_new(FALSE, 1); gtk_container_border_width(GTK_CONTAINER(main_vbox), 4); gtk_container_add(GTK_CONTAINER(window), main_vbox); menu_bar = create_menus(); gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar, FALSE, TRUE, 0); /*Create box for image */ video_vbox = gtk_vbox_new(TRUE,0); gtk_container_border_width(GTK_CONTAINER(video_vbox), 10); gtk_box_pack_start(GTK_BOX(main_vbox), video_vbox, TRUE, TRUE, 0); /* Create pixmap widget put in box and put our logo in there */ gdk_imlib_load_file_to_pixmap(LOGO, &image, &mask); pixmap = gtk_pixmap_new(image, mask); gtk_box_pack_start(GTK_BOX(video_vbox), pixmap, TRUE, TRUE, 0); gtk_widget_show(pixmap); /*Create box for buttons */ buttons_hbox = gtk_hbox_new(FALSE,0); gtk_container_border_width(GTK_CONTAINER(buttons_hbox), 4); gtk_box_pack_end(GTK_BOX(main_vbox), buttons_hbox, FALSE, TRUE, 0); /* Stop */ stop_button = gtk_button_new_with_label("Stop"); gtk_box_pack_start(GTK_BOX(buttons_hbox), stop_button, FALSE, TRUE, 2); gtk_signal_connect (GTK_OBJECT (stop_button), "clicked", GTK_SIGNAL_FUNC (stop), NULL); gtk_widget_show(stop_button); /* Play */ play_button = gtk_button_new_with_label("Play"); gtk_box_pack_start(GTK_BOX(buttons_hbox), play_button, FALSE, TRUE, 2); gtk_signal_connect (GTK_OBJECT (play_button), "clicked", GTK_SIGNAL_FUNC (play), NULL); gtk_widget_show(play_button); /* Snapshot */ snap_button = gtk_button_new_with_label("Floppy"); gtk_box_pack_start(GTK_BOX(buttons_hbox), snap_button, FALSE, TRUE, 2); gtk_signal_connect (GTK_OBJECT (snap_button), "clicked", GTK_SIGNAL_FUNC (snapshot_window), NULL); gtk_widget_show(snap_button); /* Save */ save_button = gtk_button_new_with_label("Hard Drive"); gtk_box_pack_start(GTK_BOX(buttons_hbox), save_button, FALSE, TRUE, 2); gtk_signal_connect(GTK_OBJECT(save_button), "clicked", GTK_SIGNAL_FUNC(save_window), NULL); gtk_widget_show(save_button); /* A time thingy is nice */ hour = 0; min = 0; sec = 0, tenth = 0; fpsth=0; adj_h = gtk_adjustment_new(hour, -1, 24, 1, 1, 24); spin_hour = gtk_spin_button_new(GTK_ADJUSTMENT(adj_h), 5, 0); gtk_signal_connect_object(GTK_OBJECT(adj_h), "value_changed", GTK_SIGNAL_FUNC(hour_change), GTK_OBJECT(spin_hour)); adj_m = gtk_adjustment_new(min, -1, 60, 1, 1, 60); spin_min = gtk_spin_button_new(GTK_ADJUSTMENT(adj_m), 5, 0); gtk_signal_connect_object(GTK_OBJECT(adj_m), "value_changed", GTK_SIGNAL_FUNC(min_change), GTK_OBJECT(spin_min)); adj_s = gtk_adjustment_new(sec, -1, 60, 1, 1, 60); spin_sec = gtk_spin_button_new(GTK_ADJUSTMENT(adj_s), 5, 0); gtk_signal_connect_object(GTK_OBJECT(adj_s), "value_changed", GTK_SIGNAL_FUNC(sec_change), GTK_OBJECT(spin_sec)); adj_t = gtk_adjustment_new(tenth, -50, 100, 100/fps, 1, 100); spin_tenth = gtk_spin_button_new(GTK_ADJUSTMENT(adj_t), 5, 0); gtk_signal_connect_object(GTK_OBJECT(adj_t), "value_changed", GTK_SIGNAL_FUNC(tenth_change), GTK_OBJECT(spin_tenth)); spin_hbox = gtk_hbox_new(TRUE,0); gtk_box_pack_end(GTK_BOX(main_vbox), spin_hbox, FALSE, TRUE, 2); gtk_box_pack_start(GTK_BOX(spin_hbox), spin_hour, FALSE, TRUE, 2); gtk_box_pack_start(GTK_BOX(spin_hbox), spin_min, FALSE, TRUE, 2); gtk_box_pack_start(GTK_BOX(spin_hbox), spin_sec, FALSE, TRUE, 2); gtk_box_pack_start(GTK_BOX(spin_hbox), spin_tenth, FALSE, TRUE, 2); /* Show all our main widgets */ gtk_widget_show(video_vbox); gtk_widget_show(buttons_hbox); gtk_widget_show(spin_hbox); gtk_widget_show(spin_hour); gtk_widget_show(spin_min); gtk_widget_show(spin_sec); gtk_widget_show(spin_tenth); gtk_widget_show(menu_bar); gtk_widget_show(main_vbox); gtk_widget_show(window); /* Lets move into main image dir */ chdir(dirs[currentdir]); gtk_main(); return 0; }void snapshot_window(void){ char *message = "Put a floppy in the disk drive.\n W A R N I N G\n The disk will be formatted.\n\n ";GtkWidget *dialog, *label, *button; dialog = gtk_dialog_new (); gtk_grab_add(dialog); gtk_window_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); gtk_container_border_width (GTK_CONTAINER (dialog), 5); label = gtk_label_new (message); gtk_misc_set_padding (GTK_MISC (label), 20, 20); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), label, TRUE, TRUE, 0); gtk_widget_show (label); button = gtk_button_new_with_label ("OK"); gtk_widget_set_usize (button, 80, -1); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), button, FALSE, FALSE, 14); GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); gtk_widget_grab_default (button); gtk_widget_show (button); gtk_signal_connect_object (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (snapshot_work), GTK_OBJECT (dialog)); gtk_widget_show (dialog); }void save_window(void){ GtkWidget *file_select; chdir("/"); file_select = gtk_file_selection_new("Image"); gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_select), "/crims/crim.jpg"); gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(file_select)->cancel_button), "clicked", (GtkSignalFunc)gtk_widget_destroy, GTK_OBJECT(file_select)); gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(file_select)->cancel_button), "destroy", (GtkSignalFunc)gtk_widget_destroy, GTK_OBJECT(file_select)); gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(file_select)->ok_button), "clicked", GTK_SIGNAL_FUNC(save_image), file_select); gtk_widget_show(file_select); gtk_grab_add(file_select); chdir(dirs[currentdir]); }void save_image(GtkWidget *w, GtkFileSelection *fs){ gchar *filename; char command[BUFSIZ]; filename = gtk_file_selection_get_filename(fs); strcpy(command, "cp "); strcat(command, dirs[currentdir]); strcat(command, "/"); strcat(command, currentfile); strcat(command, ".jpg "); strcat(command, filename); system(command); gtk_grab_remove((GtkWidget *)fs); gtk_widget_destroy((GtkWidget *)fs);}void snapshot_work(GtkWidget *dialog){ char buf[BUFSIZ]; system("mformat a:"); strcat(buf, "mcopy "); strcat(buf, dirs[currentdir]); strcat(buf, "/"); strcat(buf, currentfile); strcat(buf, ".jpg a:\\crim.jpg"); system(buf); gtk_grab_remove(dialog); gtk_widget_destroy(dialog); }void hour_change(GtkWidget *spin_hour){ char file[25]; hour = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin_hour)); if(hour == 24) { gtk_signal_handler_block_by_func(adj_h, hour_change, spin_hour); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_h), 0); gtk_signal_handler_unblock_by_func(adj_h, hour_change, spin_hour); hour = 0; } if(hour == -1) { gtk_signal_handler_block_by_func(adj_h, hour_change, spin_hour); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_h), 23); gtk_signal_handler_unblock_by_func(adj_h, hour_change, spin_hour); hour = 23; } chdir(dirs[hour]); currentdir = hour; strcpy(file, currentfile); strcat(file, ".jpg"); show(file, pixmap);} void min_change(GtkWidget *spin_min, gpointer data){ int num; char file[25]; min = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin_min)); if(min == 60) { gtk_signal_handler_block_by_func(adj_m, min_change, spin_min); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_m), 0); gtk_signal_handler_unblock_by_func(adj_m, min_change, spin_min); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_h), ++hour); } else if(min == -1) { gtk_signal_handler_block_by_func(adj_m, min_change, spin_min); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_m), 59); gtk_signal_handler_unblock_by_func(adj_m, min_change, spin_min); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_h), --hour); } else { num = (min*60 + sec)*fps + fpsth; snprintf(currentfile, MAX_FILE, "%05d", num); strcpy(file, currentfile); strcat(file, ".jpg"); show(file, pixmap); }}void sec_change(GtkWidget *spin_sec, gpointer data){ int num; char file[25]; sec = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin_sec)); if(sec == 60) { gtk_signal_handler_block_by_func(adj_s, sec_change, spin_sec); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_s), 0); gtk_signal_handler_unblock_by_func(adj_s, sec_change, spin_sec); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_m), ++min); } else if(sec == -1) { gtk_signal_handler_block_by_func(adj_s, sec_change, spin_sec); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_s), 59); gtk_signal_handler_unblock_by_func(adj_s, sec_change, spin_sec); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_m), --min); } else { num = (min*60 + sec)*fps + fpsth; snprintf(currentfile, MAX_FILE, "%05d", num); strcpy(file, currentfile); strcat(file, ".jpg"); show(file, pixmap); }}void tenth_change(GtkWidget *spin_tenth, gpointer data){ int num; char file[25]; tenth = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin_tenth)); fpsth = tenth*fps/100; if(tenth == 100) { gtk_signal_handler_block_by_func(adj_t, tenth_change, spin_tenth); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_t), 0); gtk_signal_handler_unblock_by_func(adj_t, tenth_change, spin_tenth); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_s), ++sec); } else if(tenth < 0) { gtk_signal_handler_block_by_func(adj_t, tenth_change, spin_tenth); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_t), 80); gtk_signal_handler_unblock_by_func(adj_t, tenth_change, spin_tenth); gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_s), --sec); } else { num = (min*60 + sec)*fps + fpsth; snprintf(currentfile, MAX_FILE, "%05d", num); strcpy(file, currentfile); strcat(file, ".jpg"); show(file, pixmap); }} void play(void){ if(!playing) { playing = TRUE; idle_func = gtk_timeout_add(200, (GtkFunction)update_clock, NULL); } return;}void stop(void){ playing = FALSE; gtk_timeout_remove(idle_func); return;}int update_clock(gpointer data){ fpsth++; tenth += 100/fps; gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_t), (tenth == 100) ? 0 : tenth ); if(fpsth == fps) { fpsth = 0; sec++; gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_s), (sec == 60) ? 0 : sec ); } if(sec == 60) { sec = 0; min++; gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_m), (min == 60) ? 0 : min ); } if(min == 60) { min = 0; hour++; gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_h), (hour == 24) ? 0 : hour ); } if(hour == 24) { hour = 11; } return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -