diff options
author | Frederic Culot <calcurse@culot.org> | 2006-09-09 20:15:06 +0000 |
---|---|---|
committer | Frederic Culot <calcurse@culot.org> | 2006-09-09 20:15:06 +0000 |
commit | be24cf8b950163cb20e41675fa0c92ad5a63d775 (patch) | |
tree | 12f511b636008eda8191c859e2330cd697d8f35d /src | |
parent | ece0f2d24849cc87b061d26b0e47d746f542e267 (diff) | |
download | calcurse-be24cf8b950163cb20e41675fa0c92ad5a63d775.zip |
implementation of notifying functions
Diffstat (limited to 'src')
-rwxr-xr-x | src/notify.c | 116 | ||||
-rwxr-xr-x | src/notify.h | 49 |
2 files changed, 165 insertions, 0 deletions
diff --git a/src/notify.c b/src/notify.c new file mode 100755 index 0000000..3d973d1 --- /dev/null +++ b/src/notify.c @@ -0,0 +1,116 @@ +/* $calcurse: notify.c,v 1.1 2006/09/09 20:15:34 culot Exp $ */ + +/* + * Calcurse - text-based organizer + * Copyright (c) 2004-2006 Frederic Culot + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Send your feedback or comments to : calcurse@culot.org + * Calcurse home page : http://culot.org/calcurse + * + */ + +#include <ncurses.h> +#include <pthread.h> +#include <time.h> + +#include "custom.h" +#include "vars.h" +#include "notify.h" + +static struct notify_vars_s *notify = NULL; + +/* + * Create the notification bar, by initializing all the variables and + * creating the notification window (l is the number of lines, c the + * number of columns, y and x are its coordinates). + */ +void notify_init_bar(int l, int c, int y, int x) +{ + pthread_t notify_thread; + + notify = (struct notify_vars_s *) malloc(sizeof(struct notify_vars_s)); + pthread_mutex_init(¬ify->mut, NULL); + notify->win = newwin(l, c, y, x); + notify_extract_aptsfile(); + pthread_create(¬ify_thread, NULL, notify_thread_sub, NULL); +} + +/* + * The calcurse window geometry as changed so we need to reset the + * notification window. + */ +void notify_reinit_bar(int l, int c, int y, int x) +{ + delwin(notify->win); + notify->win = newwin(l, c, y, x); +} + +/* + * Update the notification bar. This is useful when changing color theme + * for example. + */ +void notify_update_bar(void) +{ + int file_pos, date_pos; + + date_pos = 3; + file_pos = date_pos + 2*NOTIFY_FIELD_LENGTH; + + pthread_mutex_lock(¬ify->mut); + + custom_apply_attr(notify->win, ATTR_HIGHEST); + wattron(notify->win, A_UNDERLINE | A_REVERSE); + mvwhline(notify->win, 0, 0, ACS_HLINE, col); + mvwprintw(notify->win, 0, date_pos, "[ %s | %s ]", + notify->date, notify->time); + mvwprintw(notify->win, 0, file_pos, "(%s)", notify->apts_file); + wattroff(notify->win, A_UNDERLINE | A_REVERSE); + custom_remove_attr(notify->win, ATTR_HIGHEST); + wrefresh(notify->win); + + pthread_mutex_unlock(¬ify->mut); +} + +/* Extract the appointment file name from the complete file path. */ +void notify_extract_aptsfile(void) +{ + notify->apts_file = strrchr(path_apts, '/'); + notify->apts_file++; +} + +/* Update the notication bar content */ +void *notify_thread_sub(void *arg) +{ + unsigned thread_sleep = 1; + struct tm *ntime; + time_t ntimer; + char *time_format = "%T"; + char *date_format = "%a %F"; + + for (;;) { + ntimer = time(NULL); + ntime = localtime(&ntimer); + pthread_mutex_lock(¬ify->mut); + strftime(notify->time, NOTIFY_FIELD_LENGTH, time_format, ntime); + strftime(notify->date, NOTIFY_FIELD_LENGTH, date_format, ntime); + notify_update_bar(); + pthread_mutex_unlock(¬ify->mut); + sleep(thread_sleep); + } + pthread_exit((void*) 0); +} diff --git a/src/notify.h b/src/notify.h new file mode 100755 index 0000000..8f64365 --- /dev/null +++ b/src/notify.h @@ -0,0 +1,49 @@ +/* $calcurse: notify.h,v 1.1 2006/09/09 20:15:06 culot Exp $ */ + +/* + * Calcurse - text-based organizer + * Copyright (c) 2004-2006 Frederic Culot + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Send your feedback or comments to : calcurse@culot.org + * Calcurse home page : http://culot.org/calcurse + * + */ + +#ifndef CALCURSE_NOTIFY_H +#define CALCURSE_NOTIFY_H + +#include <ncurses.h> +#include <pthread.h> + +#define NOTIFY_FIELD_LENGTH 20 + +struct notify_vars_s { + WINDOW *win; + char *apts_file; + char time[NOTIFY_FIELD_LENGTH]; + char date[NOTIFY_FIELD_LENGTH]; + pthread_mutex_t mut; +}; + +void notify_init_bar(int l, int c, int y, int x); +void notify_reinit_bar(int l, int c, int y, int x); +void notify_update_bar(void); +void notify_extract_aptsfile(void); +void *notify_thread_sub(void *arg); + +#endif /* CALCURSE_NOTIFY_H */ |