#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <mysql/mysql.h>
Go to the source code of this file.
Functions | |
void | daemon_init () |
popup.c pops up a notification onscreen | |
void | ret_any_day_more (char mod_date[15], char dat[15], int no) |
ret_any_day_more adds any number of days to a given date and returns the new date | |
void | conv_date_integer (char dt[15], int *dat, int *mnt, int *yr) |
conv_date_integer converts a given date into its corresponding integer parts | |
void | get_new_date (char dt[15], int d, int m, int y) |
create_new_date creates a date in the form of yyyy-mm-dd in a string format given the day, month and year | |
gint | delete_event (GtkWidget *widget, GdkEvent *event, gpointer data) |
delete_event is calles to restore control back to console when popup window is closed | |
int | main (int argc, char *argv[]) |
main function where the program starts working | |
Variables | |
MYSQL * | connection1 |
MYSQL_RES * | result |
MYSQL_ROW | sqlrow |
void conv_date_integer | ( | char | dt[15], | |
int * | dat, | |||
int * | mnt, | |||
int * | yr | |||
) |
conv_date_integer converts a given date into its corresponding integer parts
dt | The date to be converted into integer parts | |
dat | Pointer where day of dt will be returned as integer | |
dat | Pointer where month of dt will be returned as integer | |
dat | Pointer where year of dt will be returned as integer |
void daemon_init | ( | ) |
popup.c pops up a notification onscreen
void |
Definition at line 17 of file popup.c.
References pid.
00018 { 00019 int i; 00020 pid_t pid; 00021 char path[512]; 00022 if((pid=fork())!=0) 00023 { 00024 exit(0); 00025 } 00026 setsid(); 00027 signal(SIGHUP,SIG_IGN); 00028 if((pid=fork())!=0) 00029 { 00030 exit(0); 00031 } 00032 getcwd(path,512); 00033 chdir(path); 00034 umask(0); 00035 for(i=0;i<64;i++) 00036 { 00037 close(i); 00038 } 00039 }
gint delete_event | ( | GtkWidget * | widget, | |
GdkEvent * | event, | |||
gpointer | data | |||
) |
void get_new_date | ( | char | dt[15], | |
int | d, | |||
int | m, | |||
int | y | |||
) |
create_new_date creates a date in the form of yyyy-mm-dd in a string format given the day, month and year
dt | pointer where the newly created date will be returned | |
d | the day of the date | |
m | the month of the date | |
y | the year of the date |
Definition at line 98 of file popup.c.
Referenced by main().
int main | ( | int | argc, | |
char * | argv[] | |||
) |
main function where the program starts working
argc | number of command line arguments | |
argv | actual command line arguments |
Definition at line 125 of file popup.c.
References connection1, conv_date_integer(), daemon_init(), delete_event(), g_hour, g_min, get_new_date(), result, ret_any_day_more(), temp, and window.
00126 { 00127 daemon_init(); 00128 00129 GtkWidget *window; 00130 GtkWidget *table; 00131 GtkWidget *label_question; 00132 char server[30],dbuser[30],dbpassword[30],dbname[30],lbl[100],qry[300]; 00133 char g_dt[15],g_day[5],g_ed[15],g_ew[15],g_currdate[15],g_curday[5],temp[100],tm[15],tag[5],dat[15],t[10]; 00134 int i,result,g_hour,g_min,g_o,g_d,g_w,g_m,g_y,g_eo,g_em,g_ey,g_curmnth,g_curyr,type,dd,mm,yy; 00135 00136 strcpy(server,"localhost"); 00137 strcpy(dbuser,"alarm_user"); 00138 strcpy(dbpassword,"alarm_password"); 00139 strcpy(dbname,"alarm"); 00140 00141 connection1 = mysql_init (NULL); 00142 if (!connection1) 00143 { 00144 fprintf (stderr, "MySQL initialization failed\n"); 00145 exit(EXIT_FAILURE); 00146 } 00147 00148 connection1=mysql_real_connect (connection1, server,dbuser,dbpassword,dbname, 0, NULL, 0); 00149 00150 if (connection1) 00151 { 00152 printf ("Connection successful\n"); 00153 } 00154 else 00155 { 00156 printf ("Connection failed\n"); 00157 return -1; 00158 } 00159 00160 00161 gtk_init (&argc, &argv); 00162 window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 00163 00164 strcpy(g_dt,argv[1]); 00165 strcpy(g_day,argv[2]); 00166 g_hour=atoi(argv[3]); 00167 g_min=atoi(argv[4]); 00168 g_o=atoi(argv[5]); 00169 g_d=atoi(argv[6]); 00170 g_w=atoi(argv[7]); 00171 g_m=atoi(argv[8]); 00172 g_y=atoi(argv[9]); 00173 g_eo=atoi(argv[10]); 00174 strcpy(g_ed,argv[11]); 00175 strcpy(g_ew,argv[12]); 00176 g_em=atoi(argv[13]); 00177 g_ey=atoi(argv[14]); 00178 strcpy(g_currdate,argv[15]); 00179 g_curmnth=atoi(argv[16]); 00180 g_curyr=atoi(argv[17]); 00181 strcpy(g_curday,argv[18]); 00182 type=atoi(argv[19]); 00183 00184 strcpy(lbl,""); 00185 00186 for(i=20;i<argc;i++) 00187 { 00188 strcat(lbl,argv[i]); 00189 strcat(lbl," "); 00190 /*printf("<%s>",lbl);*/ 00191 } 00192 lbl[strlen(lbl)-1]='\0'; 00193 00194 00195 if(g_o==1) 00196 { 00197 sprintf(qry,"delete from ers where hour=%d and min=%d and event='%s' and dt='%s'",g_hour,g_min,lbl,g_dt); 00198 strcpy(t,"Once"); 00199 printf("The QUERY %s",qry); 00200 result=mysql_query(connection1,qry); 00201 if(result) 00202 printf("g_o failed\n"); 00203 } 00204 else if(g_d==1) 00205 { 00206 sprintf(qry,"update ers set ed='%s' where hour=%d and min=%d and event='%s' and dt='%s'",g_currdate,g_hour,g_min,lbl,g_dt); 00207 strcpy(t,"Daily"); 00208 printf("The QUERY %s",qry); 00209 result=mysql_query(connection1,qry); 00210 if(result) 00211 printf("g_d failed\n"); 00212 } 00213 else if(g_w==1) 00214 { 00215 ret_any_day_more(g_dt,dat,7); 00216 sprintf(qry,"update ers set dt='%s', ew='%s' where hour=%d and min=%d and event='%s' and day='%s' and dt='%s'",dat,g_currdate,g_hour,g_min,lbl,g_curday,g_dt); 00217 strcpy(t,"Weekly"); 00218 printf("The QUERY %s",qry); 00219 result=mysql_query(connection1,qry); 00220 if(result) 00221 printf("g_w failed\n"); 00222 } 00223 else if(g_m==1) 00224 { 00225 conv_date_integer(g_dt,&dd,&mm,&yy); 00226 if((g_curmnth+1)>12) 00227 get_new_date(dat,dd,1,yy+1); 00228 else 00229 get_new_date(dat,dd,g_curmnth+1,yy); 00230 00231 if(g_curmnth==12) 00232 g_curmnth=0; 00233 00234 sprintf(qry,"update ers set dt='%s', em=%d where hour=%d and min=%d and event='%s' and dt='%s'",dat,g_curmnth,g_hour,g_min,lbl,g_dt); 00235 strcpy(t,"Monthly"); 00236 printf("The QUERY %s",qry); 00237 result=mysql_query(connection1,qry); 00238 if(result) 00239 printf("g_m failed\n"); 00240 } 00241 else if(g_y==1) 00242 { 00243 conv_date_integer(g_dt,&dd,&mm,&yy); 00244 get_new_date(dat,dd,mm,g_curyr+1); 00245 00246 sprintf(qry,"update ers set dt='%s', ey=%d where hour=%d and min=%d and event='%s' and dt='%s'",dat,g_curyr,g_hour,g_min,lbl,g_dt); 00247 strcpy(t,"Yearly"); 00248 printf("The QUERY %s",qry); 00249 result=mysql_query(connection1,qry); 00250 if(result) 00251 printf("g_y failed\n"); 00252 } 00253 00254 strcpy(tag,"AM"); 00255 00256 if(g_hour>=13) 00257 { 00258 g_hour-=12; 00259 strcpy(tag,"PM"); 00260 } 00261 else if(g_hour==0) 00262 g_hour+=12; 00263 00264 if(g_hour<10 && g_min<10) 00265 sprintf(tm,"0%d:0%d %s",g_hour,g_min,tag); 00266 else if(g_hour<10 && g_min>9) 00267 sprintf(tm,"0%d:%d %s",g_hour,g_min,tag); 00268 else if(g_hour>9 && g_min<10) 00269 sprintf(tm,"%d:0%d %s",g_hour,g_min,tag); 00270 else 00271 sprintf(tm,"%d:%d %s",g_hour,g_min,tag); 00272 00273 00274 if(type==1) 00275 sprintf(temp,"You Have Missed Event: '%s' \nScheduled for: '%s' \nAt: %s\nEvent type: %s",lbl,g_dt,tm,t); 00276 else if(type==2) 00277 sprintf(temp,"You Have Event: '%s' \nScheduled for: '%s' \nAt: %s\nEvent type: %s",lbl,g_dt,tm,t); 00278 00279 label_question=gtk_label_new(temp); 00280 gtk_window_set_title (GTK_WINDOW (window), "Event Reminder"); 00281 gtk_window_set_default_size(GTK_WINDOW(window),120,80); 00282 gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS); 00283 gtk_signal_connect (GTK_OBJECT (window), "delete_event",GTK_SIGNAL_FUNC (delete_event), NULL); 00284 gtk_container_set_border_width (GTK_CONTAINER (window), 20); 00285 table = gtk_table_new (1, 1, TRUE); 00286 gtk_container_add (GTK_CONTAINER (window), table); 00287 gtk_table_attach_defaults (GTK_TABLE(table), label_question, 0, 1, 0, 1); 00288 gtk_widget_show (label_question); 00289 gtk_widget_show (table); 00290 gtk_widget_show (window); 00291 00292 00293 gtk_main (); 00294 mysql_close(connection1); 00295 00296 return 0; 00297 }
void ret_any_day_more | ( | char | mod_date[15], | |
char | dat[15], | |||
int | no | |||
) |
ret_any_day_more adds any number of days to a given date and returns the new date
mod_date | is the date to which any number of days is to be added | |
dat | pointer in which newly formed date will be returned | |
no | is the number of days to be added |
Definition at line 51 of file popup.c.
References connection1, result, and sqlrow.
Referenced by main().
00052 { 00053 int return_value; 00054 char qry[100]; 00055 sprintf(qry,"select DATE_ADD('%s',INTERVAL %d DAY)",mod_date,no); 00056 return_value = mysql_query (connection1,qry); 00057 00058 if (return_value) 00059 { 00060 printf ("select failed as : %s\n", mysql_error (connection1)); 00061 } 00062 else 00063 { 00064 result = mysql_use_result(connection1); 00065 if (result) 00066 { 00067 while ((sqlrow = mysql_fetch_row (result))) 00068 { 00069 strcpy(dat,sqlrow[0]); 00070 } 00071 } 00072 mysql_free_result(result); 00073 } 00074 }
MYSQL* connection1 |