Advertisement
Guest User

notes.c

a guest
Feb 23rd, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.67 KB | None | 0 0
  1. #include <gtk/gtk.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. void create_window(int , char **);
  7. int load_file(void);
  8. void usage(char *);
  9. void rm_file(char *);
  10. void save_note(gchar *);
  11. struct date_t carga_fecha(void);
  12.  
  13. struct date_t {
  14.     int day, mon, year, hor, min;
  15. };
  16.  
  17. int main(int argc, char **argv) {
  18.  
  19.     if(argc < 2) {
  20.         usage(argv[0]);
  21.         exit(1);
  22.     } else {
  23.         //If there are at least one argument, continue, else, close the app.
  24.         if(strcmp(argv[1],"-d") == 0) {
  25.            
  26.         } else if(strcmp(argv[1],"-n") == 0) {
  27.             //If there's chossen the new note option, create a GTK dialog to create it.
  28.             create_window(argc, argv);
  29.         } else if(strcmp(argv[1], "-r") == 0) {
  30.            
  31.         } else {
  32.             usage(argv[0]);
  33.             exit(1);
  34.         }
  35.     }
  36.     return 0;
  37. }
  38.  
  39. void usage(char *s) {
  40.     /**
  41.      * Shows the app usage
  42.      */
  43.     printf("[USAGE] %s [-d|-n|-r] <note> <-g --user=Username --pass=Password --note=note>\n\t-d: Display the most recent notes by the stdout\n\t-n: Create a GTK+ dialog for create the note\n\t-r: If provided remove the notes, else display the notes for chosing which note are going to be removed",s);
  44. }
  45.  
  46. void save_note(gchar *note) {
  47.     /**
  48.      * Saves the note in the file descriptor provided by load_file()
  49.      */
  50.     int file;
  51. }
  52.  
  53. int load_file(void) {
  54.     /**
  55.      * Returns a file descriptor of the file, if the file doesn't exist create it. The file name is: dd-mm-yyyy-hh-mm.note.
  56.      */
  57.     char *file_name;
  58.     struct date_t current_date;
  59. }
  60.  
  61. struct date_t load_date(void) {
  62.     /**
  63.      * Returns a struct with all the information about current date (day, month, year, hour and minute).
  64.      */
  65.     struct date_t current_date;
  66.     long int time_ms = time(0); // Takes the time in miliseconds since 1970.
  67. }
  68.  
  69. void create_window(int argc, char **argv) {
  70.     /**
  71.      * Creates a GTK+ dialog for editing the note      
  72.      */
  73.     GtkWidget *window, *save_button, *text_box, *container;
  74.    
  75.     gtk_init(&argc, &argv);
  76.  
  77.     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  78.     gtk_window_set_title((GtkWindow *) window, "Notes");
  79.     gtk_window_set_default_size((GtkWindow *) window, 300,160);
  80.     g_signal_connect((GObject *) window, "delete-event", (GCallback) gtk_main_quit, NULL);
  81.  
  82.     save_button = gtk_button_new_with_label("Save");
  83.     g_signal_connect((GObject *) save_button, "clicked", (GCallback) save_note, NULL /*By the way*/);
  84.  
  85.     container = gtk_vbox_new(FALSE, 1);
  86.  
  87.     text_box = gtk_text_new(NULL, NULL);
  88.     gtk_text_set_editable((GtkText *) text_box, TRUE);
  89.  
  90.     gtk_box_pack_start((GtkBox *) container, text_box, FALSE, FALSE, 0);
  91.     gtk_box_pack_start((GtkBox *) container, save_button, FALSE, FALSE, 0);
  92.  
  93.     gtk_container_add((GtkContainer *) window, container);
  94.  
  95.     gtk_widget_show_all(window);
  96.     gtk_main();
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement