📄 main.c
字号:
/* Voice Reader version 0.1 (Very Alpha) This is my very first attempt at using the qt library. I decided to write a little application that I can use to listen to voice mail messages recieved with vgetty. Since I have a USR voice modem which uses GSM as its audio format it is relatively easy to translate that into au format and send to /dev/audio. Since other voice modems use other formats besides GSM, more work will need to be done on those to convert the format to be /dev/audio playable. This version is extremely simple (written in <1 hour) but it gives something to work on. This package was compiled using gtk+-0.99.9 and the gsm library. I use untoast in a system call specifically to translate the GSM formated voice file into au format and then push it's output into /dev/audio. I am not including the gsm library as part of this package, it will need to be downloaded seperately. And it is only useful if you have a newer USR voice modem. This program works well with vgetty, but could be modified easily to work with other programs as well. This code is licenced under the terms of the GPL. If you make changes to this code (as I hope many will) all I ask is that you send a copy to me so that I can incorporate it into the next release. And if it works well for you I would also like to hear about it. If you have any suggestions I am always open to them. Since this is a first attempt and many things need to be changed I would appreciate input. Please send questions or suggestions to jer@xmission.com. Thanks.*/#include <gtk/gtk.h>#include <sys/types.h>#include <dirent.h>#include <sys/stat.h>#include <unistd.h>#include <time.h>#include "main.h"const gchar *list_item_filename_key="list_item_filename";GtkWidget *gtklist;/* Quit the program */void destroy(GtkWidget *widget, gpointer data){ gtk_main_quit();}/* Put all of the messages in the listbox by date*/void listmessages(GtkWidget *widget){ GtkWidget *list_item; GList *dlist; gchar *date; DIR *directory; struct dirent *entry; struct stat filestatus; gtk_list_clear_items(GTK_LIST(gtklist),0,0); dlist=NULL; if((directory=opendir(VOICE_DIRECTORY))){ while((entry=readdir(directory))){ if((strcmp(entry->d_name,"."))&&(strcmp(entry->d_name,".."))){ if(!stat(entry->d_name,&filestatus)){ date=ctime(&filestatus.st_atime); date[strlen(date)-1]=0; } else date="No Time Stamp"; list_item=gtk_list_item_new_with_label(date); dlist=g_list_append(dlist,list_item); gtk_widget_show(list_item); gtk_object_set_data(GTK_OBJECT(list_item), list_item_filename_key, entry->d_name); } } gtk_list_append_items(GTK_LIST(gtklist),dlist); }}/* The listen button was pressed, check to see if a file has been selected and then pipe it to the untoast command*/void listen(GtkWidget *widget, gpointer data){ GList *dlist; GtkObject *list_item; gchar *item_filename_string; char filename[256], buffer[1024]; FILE *fvar,*prog; dlist=GTK_LIST(gtklist)->selection; if(dlist){ list_item=GTK_OBJECT(dlist->data); item_filename_string=gtk_object_get_data(list_item, list_item_filename_key); } sprintf(filename,"%s/%s",VOICE_DIRECTORY,item_filename_string); if((prog=popen(UNTOAST_COMMAND,"w"))) if((fvar=fopen(filename,"r"))){ while(fread(buffer,1,1024,fvar)) fwrite(buffer,1,1024,prog); fclose(fvar); fclose(prog); }}/* The delete command has been pressed, go ahead and unlink the file*/void delete(GtkWidget *widget, GdkEvent *event, gpointer data){ GList *dlist; GtkObject *list_item; gchar *item_filename_string; char filename[256]; dlist=GTK_LIST(gtklist)->selection; if(dlist){ list_item=GTK_OBJECT(dlist->data); item_filename_string=gtk_object_get_data(list_item, list_item_filename_key); sprintf(filename,"%s/%s",VOICE_DIRECTORY,item_filename_string); unlink(filename); gtk_list_remove_items(GTK_LIST(gtklist),dlist); gtk_widget_show(gtklist); }}/* The appliation should be closed */gint delete_event(GtkWidget *widget, GdkEvent *event, gpointer data){ gtk_main_quit(); return(FALSE);}/* Setup the screens and the widgets and call gtk_main() and wait for input*/int main(int argc, char **argv){ GtkWidget *window; GtkWidget *button; GtkWidget *box1,*box2; GtkWidget *label; GtkWidget *scrollwindow; gtk_init(&argc, &argv); window=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window),"Voice Mail"); gtk_signal_connect(GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (delete_event), NULL); gtk_container_border_width(GTK_CONTAINER (window),10); box2=gtk_vbox_new(FALSE,10); gtk_widget_show(box2); gtk_container_add(GTK_CONTAINER(window),box2); box1=gtk_hbox_new(FALSE,10); label=gtk_label_new("Voice Mail Messages"); gtk_widget_show(label); gtk_box_pack_start(GTK_BOX(box2),label,TRUE,TRUE,0); scrollwindow=gtk_scrolled_window_new(NULL,NULL); gtk_widget_set_usize(scrollwindow,250,250); gtk_container_add(GTK_CONTAINER(box2),scrollwindow); gtk_widget_show(scrollwindow); gtklist=gtk_list_new(); gtk_container_add(GTK_CONTAINER(scrollwindow),gtklist); gtk_widget_show(gtklist); listmessages(gtklist); gtk_container_add(GTK_CONTAINER(box2),box1); button=gtk_button_new_with_label("Listen"); gtk_signal_connect(GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (listen), (gpointer) "Listen"); gtk_box_pack_start(GTK_BOX(box1),button,TRUE,TRUE,0); gtk_widget_show(button); button=gtk_button_new_with_label("Delete"); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC (delete), (gpointer) "Delete"); gtk_box_pack_start(GTK_BOX(box1),button,TRUE,TRUE,0); gtk_widget_show(button); button=gtk_button_new_with_label("Quit"); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(delete_event), (gpointer) "Quit"); gtk_box_pack_start(GTK_BOX(box1),button,TRUE,TRUE,0); gtk_widget_show(button); gtk_widget_show(box1); gtk_widget_show(window); gtk_main(); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -