Exemple #1
0
// Show the events details
void event_details(int z_index) {
	erase();
	titlebar();
	refresh();
	resize_term(25, 80);

	attron(COLOR_PAIR(3));
	mvprintw(2, 1, "View Details");
	mvprintw(3, 1, "------------");

	mvprintw(5, 1, "Event Name\t: %s", myVector[z_index].name);
	mvprintw(7, 1, "Date\t\t: %i %s %i", myVector[z_index].day, mon_name(myVector[z_index].nmon), myVector[z_index].year);
	mvprintw(9, 1, "Time\t\t: ");
	formatted_time(9, 18, myVector[z_index].hour, myVector[z_index].min);
	mvprintw(11, 1, "Location\t: %s", myVector[z_index].loc);
	//mvprintw(13, 1, "Description\t: ");
	attron(COLOR_PAIR(6));
	mvprintw(17, 1, "Press ESC to go back...");
	refresh();

	/*WINDOW *wdesc;
	wdesc = newwin(3, 60, 13, 18);
	wattron(wdesc, COLOR_PAIR(3));
	mvwprintw(wdesc, 0, 0, "%s", myVector[z_index].desc);
	wrefresh(wdesc);*/

	int key;
	do {
		key = getch();
	} while (key != 27);
	list_events();
}
Exemple #2
0
/* Unconditionally redraw the entire screen, and then refresh it using
 * the current file. */
void total_refresh(void)
{
	total_redraw();
	titlebar(NULL);
	edit_refresh();
	bottombars(currmenu);
}
Exemple #3
0
// Show the data saved at the "create new event" page
// It will only show the data saved in the data class of myevent
void view_event() {
	erase();
	titlebar();
	refresh();

	attron(COLOR_PAIR(3));
	mvprintw(2, 1, "View saved event");
	mvprintw(3, 1, "----------------");
	mvprintw(5, 1, "Date\t\t: %i %s %i", myVector[0].day, mon_name(myVector[0].nmon), myVector[0].year);
	mvprintw(6, 1, "Event name\t: %s", myVector[0].name);
	mvprintw(7, 1, "Location\t: %s", myVector[0].loc);
	mvprintw(8, 1, "Description\t:");

	mvprintw(12, 1, "Press ESC to go back.");
	refresh();

	// Create a small window for placing description
	/*WINDOW *wdesc_2;
	wdesc_2 = newwin(3, 60, 8, 18);
	wattron(wdesc_2, COLOR_PAIR(3));
	mvwprintw(wdesc_2, 0, 0, "%s", myVector[0].desc);
	wrefresh(wdesc_2);*/
	
	int key;
	while (1) {
		key = getch();
		if (key == 27) menu();
	}
}
Exemple #4
0
MainWindow::MainWindow(QWidget *parent)
    : DMainWindow(parent)
{
    mainWidget = new QWidget();
    layout = new QStackedLayout();
    tabbar = new TabBar();
    homePage = new HomePage();
    cleanerPage = new CleanerPage();

    titlebar()->setCustomWidget(tabbar, Qt::AlignVCenter, false);
    titlebar()->setSeparatorVisible(true);

    layout->addWidget(homePage);
    layout->addWidget(cleanerPage);

    mainWidget->setLayout(layout);
    setCentralWidget(mainWidget);

    connect(tabbar, &TabBar::currentChanged, this, &MainWindow::tabbarCurrentChanged);
}
Exemple #5
0
// A function that handles the changes of month and year that suit the page
void change_mon() {
	// Routine to clear and add draw the titlebar
	erase();
	titlebar();
	refresh();

	attron(COLOR_PAIR(3));
	mvprintw(2, 1, "Change month / year");
	mvprintw(3, 1, "-------------------");

	mvprintw(5, 1, "Press key LEFT or RIGHT to change and ENTER to select.");
	mvprintw(6, 1, "To quit this program, press Q.");

	show_calendar(true, 14, 10);
}
Exemple #6
0
/* Mark the current file as modified if it isn't already, and then
 * update the titlebar to display the file's new status. */
void set_modified(void)
{
	if (!openfile->modified) {
		openfile->modified = true;
		titlebar(NULL);
		if (ISSET(LOCKING)) {
			if (openfile->filename == "") {
				/* Don't bother with a lockfile if there isn't an actual file open */
				return;
			} else if (openfile->lock_filename == "") {
				/* Translators: Try to keep this at most 80 characters. */
				statusbar(_("Warning: Modifying a file which is not locked, check directory permission?"));
			} else {
				write_lockfile(openfile->lock_filename, get_full_path(openfile->filename), true);
			}
		}
	}
}
Exemple #7
0
/* Set width to the number of files that we can display per line, if
 * necessary, and display the list of files. */
void browser_refresh(void)
{
    size_t i;
    int line = 0, col = 0;
	/* The current line and column while the list is getting displayed. */
    char *foo;
	/* The additional information that we'll display about a file. */

    /* Perhaps window dimensions have changed; reinitialize the browser. */
    browser_init(path_save, opendir(path_save));
    qsort(filelist, filelist_len, sizeof(char *), diralphasort);

    /* Make sure the selected file is within range. */
    if (selected >= filelist_len)
	selected = filelist_len - 1;

    titlebar(path_save);
    blank_edit();

    wmove(edit, 0, 0);

    i = width * editwinrows * ((selected / width) / editwinrows);

    for (; i < filelist_len && line < editwinrows; i++) {
	struct stat st;
	const char *filetail = tail(filelist[i]);
		/* The filename we display, minus the path. */
	size_t filetaillen = strlenpt(filetail);
		/* The length of the filename in columns. */
	size_t foolen;
		/* The length of the file information in columns. */
	int foomaxlen = 7;
		/* The maximum length of the file information in
		 * columns: seven for "--", "(dir)", or the file size,
		 * and 12 for "(parent dir)". */
	bool dots = (COLS >= 15 && filetaillen >= longest - foomaxlen);
		/* Do we put an ellipsis before the filename?  Don't set
		 * this to TRUE if we have fewer than 15 columns (i.e.
		 * one column for padding, plus seven columns for a
		 * filename other than ".."). */
	char *disp = display_string(filetail, dots ? filetaillen -
		longest + foomaxlen + 4 : 0, longest, FALSE);
		/* If we put an ellipsis before the filename, reserve
		 * one column for padding, plus seven columns for "--",
		 * "(dir)", or the file size, plus three columns for the
		 * ellipsis. */

	/* Start highlighting the currently selected file or directory. */
	if (i == selected)
	    wattron(edit, hilite_attribute);

	blank_line(edit, line, col, longest);

	/* If dots is TRUE, we will display something like "...ename". */
	if (dots)
	    mvwaddstr(edit, line, col, "...");
	mvwaddstr(edit, line, dots ? col + 3 : col, disp);

	free(disp);

	col += longest;

	/* Show information about the file.  We don't want to report
	 * file sizes for links, so we use lstat(). */
	if (lstat(filelist[i], &st) == -1 || S_ISLNK(st.st_mode)) {
	    /* If the file doesn't exist (i.e. it's been deleted while
	     * the file browser is open), or it's a symlink that doesn't
	     * point to a directory, display "--". */
	    if (stat(filelist[i], &st) == -1 || !S_ISDIR(st.st_mode))
		foo = mallocstrcpy(NULL, "--");
	    /* If the file is a symlink that points to a directory,
	     * display it as a directory. */
	    else
		/* TRANSLATORS: Try to keep this at most 7 characters. */
		foo = mallocstrcpy(NULL, _("(dir)"));
	} else if (S_ISDIR(st.st_mode)) {
	    /* If the file is a directory, display it as such. */
	    if (strcmp(filetail, "..") == 0) {
		/* TRANSLATORS: Try to keep this at most 12 characters. */
		foo = mallocstrcpy(NULL, _("(parent dir)"));
		foomaxlen = 12;
	    } else
		foo = mallocstrcpy(NULL, _("(dir)"));
	} else {
	    unsigned long result = st.st_size;
	    char modifier;

	    foo = charalloc(foomaxlen + 1);

	    if (st.st_size < (1 << 10))
		modifier = ' ';  /* bytes */
	    else if (st.st_size < (1 << 20)) {
		result >>= 10;
		modifier = 'K';  /* kilobytes */
	    } else if (st.st_size < (1 << 30)) {
		result >>= 20;
		modifier = 'M';  /* megabytes */
	    } else {
Exemple #8
0
/* Our main file browser function.  path is the tilde-expanded path we
 * start browsing from. */
char *do_browser(char *path, DIR *dir)
{
    char *retval = NULL;
    int kbinput;
    bool old_const_update = ISSET(CONST_UPDATE);
    char *prev_dir = NULL;
	/* The directory we were in before backing up to "..". */
    char *ans = NULL;
	/* The last answer the user typed at the statusbar prompt. */
    size_t old_selected;
	/* The selected file we had before the current selected file. */
    functionptrtype func;
	/* The function of the key the user typed in. */

    curs_set(0);
    blank_statusbar();
    bottombars(MBROWSER);
    wnoutrefresh(bottomwin);

    UNSET(CONST_UPDATE);

    ans = mallocstrcpy(NULL, "");

  change_browser_directory:
	/* We go here after we select a new directory. */

    /* Start with no key pressed. */
    kbinput = ERR;

    path = mallocstrassn(path, get_full_path(path));

    /* Save the current path in order to be used later. */
    path_save = path;

    assert(path != NULL && path[strlen(path) - 1] == '/');

    /* Get the file list, and set longest and width in the process. */
    browser_init(path, dir);

    assert(filelist != NULL);

    /* Sort the file list. */
    qsort(filelist, filelist_len, sizeof(char *), diralphasort);

    /* If prev_dir isn't NULL, select the directory saved in it, and
     * then blow it away. */
    if (prev_dir != NULL) {
	browser_select_dirname(prev_dir);

	free(prev_dir);
	prev_dir = NULL;
    /* Otherwise, select the first file or directory in the list. */
    } else
	selected = 0;

    old_selected = (size_t)-1;

    titlebar(path);

    while (TRUE) {
	struct stat st;
	int i;
	size_t fileline = selected / width;
		/* The line number the selected file is on. */
	char *new_path;
		/* The path we switch to at the "Go to Directory"
		 * prompt. */

	/* Display the file list if we don't have a key, or if the
	 * selected file has changed, and set width in the process. */
	if (kbinput == ERR || old_selected != selected)
	    browser_refresh();

	old_selected = selected;

	kbinput = get_kbinput(edit);

#ifndef NANO_TINY
	if (kbinput == KEY_WINCH) {
	    kbinput = ERR;
	    curs_set(0);
	    continue;
	}
#endif

#ifndef DISABLE_MOUSE
	if (kbinput == KEY_MOUSE) {
	    int mouse_x, mouse_y;

	    /* We can click on the edit window to select a
	     * filename. */
	    if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == 0 &&
		wmouse_trafo(edit, &mouse_y, &mouse_x, FALSE)) {
		/* longest is the width of each column.  There
		 * are two spaces between each column. */
		selected = (fileline / editwinrows) *
				(editwinrows * width) + (mouse_y *
				width) + (mouse_x / (longest + 2));

		/* If they clicked beyond the end of a row,
		 * select the last filename in that row. */
		if (mouse_x > width * (longest + 2))
		    selected--;

		/* If we're off the screen, select the last filename. */
		if (selected > filelist_len - 1)
		    selected = filelist_len - 1;

		/* If we selected the same filename as last time,
		 * put back the Enter key so that it's read in. */
		if (old_selected == selected)
		    unget_kbinput(sc_seq_or(do_enter_void, 0), FALSE, FALSE);
	    }
	}
#endif /* !DISABLE_MOUSE */

	func = parse_browser_input(&kbinput);

	if (func == total_refresh) {
	    total_redraw();
	} else if (func == do_help_void) {
#ifndef DISABLE_HELP
	    do_help_void();
	    /* Perhaps the window dimensions have changed. */
	    browser_refresh();
	    curs_set(0);
#else
	    nano_disabled_msg();
#endif
	} else if (func == do_search) {
	    /* Search for a filename. */
	    curs_set(1);
	    do_filesearch();
	    curs_set(0);
	} else if (func == do_research) {
	    /* Search for another filename. */
	    do_fileresearch();
	} else if (func == do_page_up) {
	    if (selected >= (editwinrows + fileline % editwinrows) * width)
		selected -= (editwinrows + fileline % editwinrows) * width;
	    else
		selected = 0;
	} else if (func == do_page_down) {
	    selected += (editwinrows - fileline % editwinrows) * width;
	    if (selected > filelist_len - 1)
		selected = filelist_len - 1;
	} else if (func == do_first_file) {
	    selected = 0;
	} else if (func == do_last_file) {
	    selected = filelist_len - 1;
	} else if (func == goto_dir_void) {
	    /* Go to a specific directory. */
	    curs_set(1);
	    i = do_prompt(TRUE,
#ifndef DISABLE_TABCOMP
			FALSE,
#endif
			MGOTODIR, ans,
#ifndef DISABLE_HISTORIES
			NULL,
#endif
			/* TRANSLATORS: This is a prompt. */
			browser_refresh, _("Go To Directory"));

	    curs_set(0);
	    bottombars(MBROWSER);

	    /* If the directory begins with a newline (i.e. an
	     * encoded null), treat it as though it's blank. */
	    if (i < 0 || *answer == '\n') {
		/* We canceled.  Indicate that on the statusbar, and
		* blank out ans, since we're done with it. */
		statusbar(_("Cancelled"));
		ans = mallocstrcpy(ans, "");
		continue;
	    } else if (i != 0) {
		/* Put back the "Go to Directory" key and save
		 * answer in ans, so that the file list is displayed
		 * again, the prompt is displayed again, and what we
		 * typed before at the prompt is displayed again. */
		unget_kbinput(sc_seq_or(do_gotolinecolumn_void, 0), FALSE, FALSE);
		ans = mallocstrcpy(ans, answer);
		continue;
	    }

	    /* We have a directory.  Blank out ans, since we're done
	     * with it. */
	    ans = mallocstrcpy(ans, "");

	    /* Convert newlines to nulls, just before we go to the
	     * directory. */
	    sunder(answer);
	    align(&answer);

	    new_path = real_dir_from_tilde(answer);

	    if (new_path[0] != '/') {
		new_path = charealloc(new_path, strlen(path) +
				strlen(answer) + 1);
		sprintf(new_path, "%s%s", path, answer);
	    }

#ifndef DISABLE_OPERATINGDIR
	    if (check_operating_dir(new_path, FALSE)) {
		statusbar(_("Can't go outside of %s in restricted mode"),
				operating_dir);
		free(new_path);
		continue;
	    }
#endif

	    dir = opendir(new_path);
	    if (dir == NULL) {
		/* We can't open this directory for some reason.
		* Complain. */
		statusbar(_("Error reading %s: %s"), answer,
				strerror(errno));
		beep();
		free(new_path);
		continue;
	    }

	    /* Start over again with the new path value. */
	    free(path);
	    path = new_path;
	    goto change_browser_directory;
	} else if (func == do_up_void) {
	    if (selected >= width)
		selected -= width;
	} else if (func == do_down_void) {
	    if (selected + width <= filelist_len - 1)
		selected += width;
	} else if (func == do_left) {
	    if (selected > 0)
		selected--;
	} else if (func == do_right) {
	    if (selected < filelist_len - 1)
		selected++;
	} else if (func == do_enter_void) {
	    /* We can't move up from "/". */
	    if (strcmp(filelist[selected], "/..") == 0) {
		statusbar(_("Can't move up a directory"));
		beep();
		continue;
	    }

#ifndef DISABLE_OPERATINGDIR
	    /* Note: The selected file can be outside the operating
	     * directory if it's ".." or if it's a symlink to a
	     * directory outside the operating directory. */
	    if (check_operating_dir(filelist[selected], FALSE)) {
		statusbar(_("Can't go outside of %s in restricted mode"),
				operating_dir);
		beep();
		continue;
	    }
#endif

	    if (stat(filelist[selected], &st) == -1) {
		/* We can't open this file for some reason.
		 * Complain. */
		 statusbar(_("Error reading %s: %s"),
				filelist[selected], strerror(errno));
		 beep();
		 continue;
	    }

	    if (!S_ISDIR(st.st_mode)) {
		/* We've successfully opened a file, we're done, so
		 * get out. */
		retval = mallocstrcpy(NULL, filelist[selected]);
		break;
	    } else if (strcmp(tail(filelist[selected]), "..") == 0)
		/* We've successfully opened the parent directory,
		 * save the current directory in prev_dir, so that
		 * we can easily return to it by hitting Enter. */
		prev_dir = mallocstrcpy(NULL, striponedir(filelist[selected]));

	    dir = opendir(filelist[selected]);
	    if (dir == NULL) {
		/* We can't open this directory for some reason.
		 * Complain. */
		statusbar(_("Error reading %s: %s"),
				filelist[selected], strerror(errno));
		beep();
		continue;
	    }

	    path = mallocstrcpy(path, filelist[selected]);

	    /* Start over again with the new path value. */
	    goto change_browser_directory;
	} else if (func == do_exit) {
	    /* Exit from the file browser. */
	    break;
	}
    }
    titlebar(NULL);
    edit_refresh();
    curs_set(1);
    if (old_const_update)
	SET(CONST_UPDATE);

    free(path);
    free(ans);

    free_chararray(filelist, filelist_len);
    filelist = NULL;
    filelist_len = 0;

    return retval;
}
Exemple #9
0
int init_buffer(int buf, btype type, const char *bname, int nlines)
{
	bufs[buf].type=type;
	bufs[buf].bname=strdup(bname);
	if(type==SERVER)
		bufs[buf].serverloc=strdup(bname);
	else
		bufs[buf].serverloc=NULL;
	bufs[buf].realsname=NULL;
	bufs[buf].nlist=NULL;
	bufs[buf].us=NULL;
	bufs[buf].ilist=NULL;
	bufs[buf].handle=0;
	bufs[buf].server=0;
	bufs[buf].nick=NULL;
	bufs[buf].topic=NULL;
	bufs[buf].logf=NULL;
	bufs[buf].nlines=nlines;
	bufs[buf].ptr=0;
	bufs[buf].scroll=0;
	bufs[buf].ascroll=0;
	bufs[buf].lm=malloc(nlines*sizeof(mtype));
	bufs[buf].lq=malloc(nlines*sizeof(prio));
	bufs[buf].lp=malloc(nlines);
	bufs[buf].ls=malloc(nlines*sizeof(bool));
	bufs[buf].lt=malloc(nlines*sizeof(char *));
	int i;
	for(i=0;i<bufs[buf].nlines;i++)
	{
		bufs[buf].lt[i]=NULL;
	}
	bufs[buf].ltag=malloc(nlines*sizeof(char *));
	for(i=0;i<bufs[buf].nlines;i++)
	{
		bufs[buf].ltag[i]=NULL;
	}
	bufs[buf].lpl=malloc(nlines*sizeof(int));
	bufs[buf].lpc=malloc(nlines*sizeof(colour));
	bufs[buf].lpt=malloc(nlines*sizeof(char **));
	for(i=0;i<nlines;i++)
	{
		bufs[buf].lpl[i]=0;
		bufs[buf].lpc[i]=(colour){.fore=7, .back=0, .hi=false, .ul=false};
		bufs[buf].lpt[i]=NULL;
	}
	bufs[buf].dirty=false;
	bufs[buf].ts=malloc(nlines*sizeof(time_t));
	bufs[buf].filled=false;
	bufs[buf].alert=false;
	bufs[buf].hi_alert=0;
	bufs[buf].ping=0;
	bufs[buf].last=time(NULL);
	bufs[buf].namreply=false;
	bufs[buf].live=false;
	bufs[buf].conninpr=false;
	initibuf(&bufs[buf].input);
	bufs[buf].casemapping=RFC1459;
	if(type==SERVER)
	{
		bufs[buf].npfx=2;
		bufs[buf].prefixes=malloc(2*sizeof(prefix));
		bufs[buf].prefixes[0]=(prefix){.letter='o', .pfx='@'};
		bufs[buf].prefixes[1]=(prefix){.letter='v', .pfx='+'};
	}
	else
	{
		bufs[buf].npfx=0;
		bufs[buf].prefixes=NULL;
	}
	bufs[buf].autoent=NULL;
	bufs[buf].conf=conf;
	bufs[buf].key=NULL;
	bufs[buf].lastkey=NULL;
	return(0);
}

int free_buffer(int buf)
{
	if(bufs[buf].live)
	{
		add_to_buffer(buf, ERR, NORMAL, 0, false, "Buffer is still live!", "free_buffer:");
		return(1);
	}
	else
	{
		free(bufs[buf].bname);
		free(bufs[buf].serverloc);
		free(bufs[buf].realsname);
		n_free(bufs[buf].nlist);
		bufs[buf].nlist=NULL;
		n_free(bufs[buf].ilist);
		bufs[buf].ilist=NULL;
		free(bufs[buf].nick);
		free(bufs[buf].topic);
		if(bufs[buf].logf)
			fclose(bufs[buf].logf);
		free(bufs[buf].lm);
		free(bufs[buf].lq);
		free(bufs[buf].lp);
		free(bufs[buf].ls);
		int l;
		if(bufs[buf].lt)
		{
			for(l=0;l<bufs[buf].nlines;l++)
				free(bufs[buf].lt[l]);
			free(bufs[buf].lt);
		}
		if(bufs[buf].ltag)
		{
			for(l=0;l<bufs[buf].nlines;l++)
				free(bufs[buf].ltag[l]);
			free(bufs[buf].ltag);
		}
		if(bufs[buf].lpt)
		{
			for(l=0;l<bufs[buf].nlines;l++)
			{
				if(bufs[buf].lpt[l])
				{
					if(bufs[buf].lpl)
					{
						int p;
						for(p=0;p<bufs[buf].lpl[l];p++)
						{
							free(bufs[buf].lpt[l][p]);
						}
					}
					free(bufs[buf].lpt[l]);
				}
			}
			free(bufs[buf].lpt);
		}
		free(bufs[buf].lpl);
		free(bufs[buf].lpc);
		free(bufs[buf].ts);
		freeibuf(&bufs[buf].input);
		free(bufs[buf].prefixes);
		free(bufs[buf].key);
		free(bufs[buf].lastkey);
		if(cbuf>=buf)
			cbuf--;
		nbufs--;
		int b;
		for(b=buf;b<nbufs;b++)
		{
			bufs[b]=bufs[b+1];
		}
		for(b=0;b<nbufs;b++)
		{
			if(bufs[b].server==buf)
			{
				bufs[b].server=0; // orphaned; should not happen
				bufs[b].live=false;
				bufs[b].handle=0; // just in case
			}
			else if(bufs[b].server>buf)
			{
				bufs[b].server--;
			}
		}
		if(nbufs) redraw_buffer();
		return(0);
	}
}

int add_to_buffer(int buf, mtype lm, prio lq, char lp, bool ls, const char *lt, const char *ltag)
{
	if(buf>=nbufs)
	{
		if(bufs&&buf)
		{
			add_to_buffer(0, ERR, NORMAL, 0, false, "Line was written to bad buffer!  Contents below.", "add_to_buffer(): ");
			add_to_buffer(0, lm, NORMAL, lp, ls, lt, ltag);
		}
		return(1);
	}
	if(!debug&&(lq==DEBUG))
	{
		if(!d_buf.nlines)
		{
			init_ring(&d_buf);
			d_buf.loop=true;
		}
		return(add_to_ring(&d_buf, lm, lt, ltag));
	}
	int optr=bufs[buf].ptr;
	bool scrollisptr=(bufs[buf].scroll==bufs[buf].ptr)&&(bufs[buf].ascroll==0);
	bufs[buf].lm[bufs[buf].ptr]=lm;
	bufs[buf].lq[bufs[buf].ptr]=lq;
	bufs[buf].lp[bufs[buf].ptr]=lp;
	bufs[buf].ls[bufs[buf].ptr]=ls;
	free(bufs[buf].lt[bufs[buf].ptr]);
	bufs[buf].lt[bufs[buf].ptr]=strdup(lt);
	free(bufs[buf].ltag[bufs[buf].ptr]);
	bufs[buf].ltag[bufs[buf].ptr]=strdup(ltag);
	time_t ts=bufs[buf].ts[bufs[buf].ptr]=time(NULL);
	bufs[buf].ptr=(bufs[buf].ptr+1)%bufs[buf].nlines;
	if(scrollisptr)
	{
		bufs[buf].scroll=bufs[buf].ptr;
		bufs[buf].ascroll=0;
	}
	if(bufs[buf].ptr==0)
		bufs[buf].filled=true;
	render_line(buf, optr);
	if(buf==cbuf)
	{
		int e=redraw_buffer();
		if(e) return(e);
	}
	else
	{
		if(!(
			(bufs[buf].conf&&((lm==JOIN)||(lm==PART)||(lm==NICK)||(lm==MODE)||(lm==QUIT)))
			||
				(quiet&&(lq==QUIET))
			||
				(!debug&&(lq==DEBUG))
			))
		bufs[buf].alert=true;
	}
	if(bufs[buf].logf)
	{
		int e=log_add(bufs[buf].logf, bufs[buf].logt, lm, lq, lp, ls, lt, ltag, ts);
		if(e) return(e);
	}
	return(0);
}

int redraw_buffer(void)
{
	if(bufs[cbuf].dirty)
	{
		int e=render_buffer(cbuf);
		if(e) return(e);
		if(bufs[cbuf].dirty) return(1);
	}
	int uline=bufs[cbuf].scroll;
	int pline=bufs[cbuf].ascroll;
	while(pline<0)
	{
		uline--;
		if((bufs[cbuf].filled)&&(uline==bufs[cbuf].ptr))
		{
			uline++;
			pline=0;
			break;
		}
		if(uline<0)
		{
			if(bufs[cbuf].filled)
				uline+=bufs[cbuf].nlines;
			else
			{
				uline=0;
				pline=0;
				break;
			}
		}
		pline+=bufs[cbuf].lpl[uline];
	}
	if(uline==bufs[cbuf].ptr)
	{
		pline=0;
	}
	while(pline>=bufs[cbuf].lpl[uline])
	{
		pline-=bufs[cbuf].lpl[uline];
		if(bufs[cbuf].filled)
		{
			if(uline==bufs[cbuf].ptr)
			{
				pline=0;
				break;
			}
			uline=(uline+1)%bufs[cbuf].nlines;
		}
		else
		{
			if(uline>=bufs[cbuf].ptr)
			{
				uline=bufs[cbuf].ptr;
				pline=0;
				break;
			}
			uline++;
		}
	}
	bufs[cbuf].scroll=uline;
	bufs[cbuf].ascroll=pline;
	int row=height-2;
	//setcolour(bufs[cbuf].lpc[uline]);
	while(row>(tsb?1:0))
	{
		bool breakit=false;
		pline--;
		while(pline<0)
		{
			uline--;
			if(uline<0)
			{
				if(bufs[cbuf].filled)
					uline+=bufs[cbuf].nlines;
				else
				{
					breakit=true;
					pline=0;
					break;
				}
			}
			if(uline==bufs[cbuf].ptr)
			{
				breakit=true;
				break;
			}
			pline+=bufs[cbuf].lpl[uline];
		}
		if(breakit) break;
		locate(row, 0);
		fputs(bufs[cbuf].lpt[uline][pline], stdout);
		if(!full_width_colour) resetcol();
		clr();
		row--;
	}
	resetcol();
	while(row>(tsb?1:0))
	{
		locate(row--, 0);
		clr();
	}
	switch(bufs[cbuf].type)
	{
		case STATUS:
			settitle("quIRC - status");
		break;
		case SERVER: // have to scope it for the cstr 'variably modified type'
			{
				char cstr[16+strlen(bufs[cbuf].bname)];
				sprintf(cstr, "quIRC - %s", bufs[cbuf].bname);
				settitle(cstr);
			}
		break;
		case CHANNEL: // have to scope it for the cstr 'variably modified type'
			{
				char cstr[16+strlen(bufs[cbuf].bname)+strlen(SERVER(cbuf).bname)];
				sprintf(cstr, "quIRC - %s on %s", bufs[cbuf].bname, SERVER(cbuf).bname);
				settitle(cstr);
			}
		break;
		case PRIVATE: // have to scope it for the cstr 'variably modified type'
			{
				char cstr[16+strlen(bufs[cbuf].bname)+strlen(SERVER(cbuf).bname)];
				sprintf(cstr, "quIRC - <%s> on %s", bufs[cbuf].bname, SERVER(cbuf).bname);
				settitle(cstr);
			}
		break;
		default:
			settitle("quIRC");
		break;
	}
	if(tsb)
		titlebar();
	bufs[cbuf].alert=false;
	return(0);
}

int mark_buffer_dirty(int buf)
{
	bufs[buf].dirty=true;
	return(0);
}
Exemple #10
0
/* Our main file browser function.  path is the tilde-expanded path we
 * start browsing from. */
std::string do_browser(std::string path, DIR *dir)
{
	std::string retval;
	bool old_const_update = ISSET(CONST_UPDATE);
	std::string prev_dir;
	/* The directory we were in before backing up to "..". */
	std::string ans;
	/* The last answer the user typed at the statusbar prompt. */
	size_t old_selected;
	/* The selected file we had before the current selected file. */

	curs_set(0);
	blank_statusbar();
	bottombars(MBROWSER);
	wnoutrefresh(bottomwin);

	UNSET(CONST_UPDATE);

change_browser_directory:
	/* We go here after we select a new directory. */

	path = get_full_path(path);

	assert(path.length() > 0 && path.back() == '/');

	/* Get the file list, and set longest and width in the process. */
	browser_init(path, dir);

	/* Sort the file list. */
	std::sort(filelist.begin(), filelist.end(), sort_directories);

	/* If prev_dir isn't empty, select the directory saved in it, and then blow it away. */
	if (prev_dir != "") {
		browser_select_filename(prev_dir);

		prev_dir = "";
		/* Otherwise, select the first file or directory in the list. */
	} else {
		selected = 0;
	}

	old_selected = (size_t)-1;

	titlebar(path);

	Key *kbinput = nullptr;

	while (true) {
		struct stat st;
		size_t fileline = selected / width;
		/* The line number the selected file is on. */
		std::string new_path;
		/* The path we switch to at the "Go to Directory" prompt. */

		if (kbinput) {
			delete kbinput;
			kbinput = nullptr;
		}

		/* Display the file list if we don't have a key, or if the
		 * selected file has changed, and set width in the process. */
		if (old_selected != selected) {
			browser_refresh();
		}

		old_selected = selected;

		// Deal with the keyboard input
		kbinput = new Key(get_kbinput(edit));

		auto func = func_from_key(*kbinput);

		if (func == total_refresh) {
			total_redraw();
		} else if (func == do_help_void) {
			do_help_void();
			curs_set(0);
			/* Search for a filename. */
		} else if (func == do_search) {
			curs_set(1);
			do_filesearch();
			curs_set(0);
			/* Search for another filename. */
		} else if (func == do_research) {
			do_fileresearch();
		} else if (func == do_page_up) {
			if (selected >= (editwinrows + fileline % editwinrows) * width) {
				selected -= (editwinrows + fileline % editwinrows) * width;
			} else {
				selected = 0;
			}
		} else if (func == do_page_down) {
			selected += (editwinrows - fileline % editwinrows) * width;
			if (selected > filelist.size() - 1) {
				selected = filelist.size() - 1;
			}
		} else if (func == do_first_file) {
			selected = 0;
		} else if (func == do_last_file) {
			selected = filelist.size() - 1;
		} else if (func == goto_dir_void) {
			/* Go to a specific directory. */
			curs_set(1);

			std::shared_ptr<Key> key;
			PromptResult i = do_prompt(true,
			              false,
			              MGOTODIR, key, ans.c_str(),
			              NULL,
			              browser_refresh, _("Go To Directory"));

			curs_set(0);
			bottombars(MBROWSER);

			/* If the directory begins with a newline (i.e. an
			 * encoded null), treat it as though it's blank. */
			if (i == PROMPT_ABORTED || i == PROMPT_BLANK_STRING || answer.front() == '\n') {
				/* We canceled.  Indicate that on the statusbar, and
				 * blank out ans, since we're done with it. */
				statusbar(_("Cancelled"));
				ans = "";
				func = nullptr;
				continue;
			} else if (i != PROMPT_ENTER_PRESSED) {
				/* Put back the "Go to Directory" key and save
				 * answer in ans, so that the file list is displayed
				 * again, the prompt is displayed again, and what we
				 * typed before at the prompt is displayed again. */
				ans = answer;
				func = goto_dir_void;
				continue;
			}

			/* We have a directory.  Blank out ans, since we're done with it. */
			ans = "";

			/* Convert newlines to nulls, just before we go to the directory. */
			sunder(answer);

			new_path = real_dir_from_tilde(answer);

			if (new_path == "") {
				new_path = path + answer;
			}

			dir = opendir(new_path);
			if (dir == NULL) {
				/* We can't open this directory for some reason. Complain. */
				statusbar(_("Error reading %s: %s"), answer.c_str(), strerror(errno));
				beep();
				func = nullptr;
				continue;
			}

			/* Start over again with the new path value. */
			path = new_path;
			goto change_browser_directory;
		} else if (func == do_up_void) {
			if (selected >= width) {
				selected -= width;
			}
		} else if (func == do_left) {
			if (selected > 0) {
				selected--;
			}
		} else if (func == do_down_void) {
			if (selected + width <= filelist.size() - 1) {
				selected += width;
			}
		} else if (func == do_right) {
			if (selected < filelist.size() - 1) {
				selected++;
			}
		} else if (func == do_enter_void) {
			/* We can't move up from "/". */
			if (filelist[selected] == "/..") {
				statusbar(_("Can't move up a directory"));
				beep();
				func = nullptr;
				continue;
			}

			if (stat(filelist[selected], &st) == -1) {
				/* We can't open this file for some reason. Complain. */
				statusbar(_("Error reading %s: %s"), filelist[selected].c_str(), strerror(errno));
				beep();
				func = nullptr;
				continue;
			}

			if (!S_ISDIR(st.st_mode)) {
				/* We've successfully opened a file, we're done, so get out. */
				retval = filelist[selected];
				func = nullptr;
				break;
			} else if (tail(filelist[selected]) == "..") {
				/* We've successfully opened the parent directory,
				 * save the current directory in prev_dir, so that
				  * we can easily return to it by hitting Enter. */
				prev_dir = striponedir(filelist[selected]);
			}

			dir = opendir(filelist[selected].c_str());
			if (dir == NULL) {
				/* We can't open this directory for some reason. Complain. */
				statusbar(_("Error reading %s: %s"), filelist[selected].c_str(), strerror(errno));
				beep();
				func = nullptr;
				continue;
			}

			path = filelist[selected];

			/* Start over again with the new path value. */
			goto change_browser_directory;
		} else if (func == do_exit) {
			/* Exit from the file browser. */
			break;
		}
		func = nullptr;
	}
	if (kbinput) {
		delete kbinput;
	}
	titlebar(NULL);
	edit_refresh();
	curs_set(1);
	if (old_const_update) {
		SET(CONST_UPDATE);
	}

	filelist.clear();

	return retval;
}
Exemple #11
0
void list_events(int day_filter, int mon_filter, int year_filter) {
	unsigned int current_page = 1, max_page, index_page = 0;
	unsigned int mod = myVector.size() % 12;
	int key, n_keys = 0, selected_event_index;
	char type_keys[66];

	erase();
	titlebar();
	refresh();
	resize_term(40, 80);

	attron(COLOR_PAIR(3));
	mvprintw(2, 1, "List Event(s)");
	mvprintw(3, 1, "-------------");

	// Draw table
	mvvline(5, 1, 0, 29);
	mvvline(5, 6, 0, 29);
	mvvline(5, 51, 0, 29);
	mvvline(5, 70, 0, 29);
	mvvline(5, 78, 0, 29);
	mvhline(5, 1, 0, 78);
	mvhline(7, 1, 0, 78);
	mvhline(33, 1, 0, 78);

	// Print out some text
	mvprintw(6, 3, "No");
	mvprintw(6, 8, "Event Name");
	mvprintw(6, 53, "Date");
	mvprintw(6, 72, "Time");

	refresh();

	WINDOW *wID, *wNAME, *wDATE, *wTIME, *wDET, *wSTAT;

	wID = newwin(25, 4, 8, 2);
	wrefresh(wID);

	wNAME = newwin(25, 42, 8, 8);
	wrefresh(wNAME);

	wDATE = newwin(25, 18, 8, 52);
	wrefresh(wDATE);

	wTIME = newwin(25, 7, 8, 71);
	wrefresh(wTIME);

	wDET = newwin(4, 78, 36, 1);
	wattron(wDET, COLOR_PAIR(6));
	mvwprintw(wDET, 0, 0, "Press LEFT or RIGHT to change the page. Type any event number and press E to \nedit, D to delete, R to swap two events or ENTER for more details.\nOr you can press S to sort all the events. To go back, press ESC.");
	wrefresh(wDET);

	wSTAT = newwin(1, 78, 39, 1);
	wrefresh(wSTAT);

	// Declare variable for filter purpose
	std::vector<my_event> filter;
	std::vector<my_event> *list;
	my_event temp;

	// Apply filter for saved events. Copy data to the temporary local vector and print to the list.
	// Optional function. Maybe not implemented for now.
	// Since the code is identical, only the logical expression different. So it can be simpified but not for now.
	if (day_filter != 0 || mon_filter != 0 || year_filter != 0) {
		for (unsigned int z = 0; z < myVector.size(); z++) {
			if (year_filter != 0) {
				if (myVector[z].year == year_filter) {
					temp.hour = myVector[z].hour;
					temp.min = myVector[z].min;
					temp.day = myVector[z].day;
					temp.nmon = myVector[z].nmon;
					temp.year = myVector[z].year;
					temp.save_name(myVector[z].name);
					temp.save_loc(myVector[z].loc);
					//temp.save_desc(myVector[z].desc);
					filter.push_back(temp);
				}
			}
			if (mon_filter != 0) {
				if (myVector[z].nmon == mon_filter) {
					temp.hour = myVector[z].hour;
					temp.min = myVector[z].min;
					temp.day = myVector[z].day;
					temp.nmon = myVector[z].nmon;
					temp.year = myVector[z].year;
					temp.save_name(myVector[z].name);
					temp.save_loc(myVector[z].loc);
					//temp.save_desc(myVector[z].desc);
					filter.push_back(temp);
				}
			}
			if (day_filter != 0) {
				if (myVector[z].day == day_filter) {
					temp.hour = myVector[z].hour;
					temp.min = myVector[z].min;
					temp.day = myVector[z].day;
					temp.nmon = myVector[z].nmon;
					temp.year = myVector[z].year;
					temp.save_name(myVector[z].name);
					temp.save_loc(myVector[z].loc);
					//temp.save_desc(myVector[z].desc);
					filter.push_back(temp);
				}
			}
			if (day_filter != 0 && mon_filter != 0) {
				if (myVector[z].day == day_filter && myVector[z].nmon == mon_filter) {
					temp.hour = myVector[z].hour;
					temp.min = myVector[z].min;
					temp.day = myVector[z].day;
					temp.nmon = myVector[z].nmon;
					temp.year = myVector[z].year;
					temp.save_name(myVector[z].name);
					temp.save_loc(myVector[z].loc);
					//temp.save_desc(myVector[z].desc);
					filter.push_back(temp);
				}
			}
			if (year_filter != 0 && mon_filter != 0) {
				if (myVector[z].year == year_filter && myVector[z].nmon == mon_filter) {
					temp.hour = myVector[z].hour;
					temp.min = myVector[z].min;
					temp.day = myVector[z].day;
					temp.nmon = myVector[z].nmon;
					temp.year = myVector[z].year;
					temp.save_name(myVector[z].name);
					temp.save_loc(myVector[z].loc);
					//temp.save_desc(myVector[z].desc);
					filter.push_back(temp);
				}
			}
			if (day_filter != 0 && mon_filter != 0 && year_filter != 0) {
				if (myVector[z].day == day_filter && myVector[z].nmon == mon_filter && myVector[z].year == year_filter) {
					temp.hour = myVector[z].hour;
					temp.min = myVector[z].min;
					temp.day = myVector[z].day;
					temp.nmon = myVector[z].nmon;
					temp.year = myVector[z].year;
					temp.save_name(myVector[z].name);
					temp.save_loc(myVector[z].loc);
					//temp.save_desc(myVector[z].desc);
					filter.push_back(temp);
				}
			}
		}
		list = &filter;
	}
	else list = &myVector;

	if (mod != 0) max_page = (int)(ceil((*list).size() / 12)) + 1;
	else max_page = (*list).size() / 12;

	while (1) {

		werase(wID);
		werase(wNAME);
		werase(wDATE);
		werase(wTIME);
		mvprintw(34, 1, "Page: %i/%i", current_page, max_page);

		int n_line = 1;
		for (unsigned int i = index_page; i < index_page + 12; i++) {
			if (i < (*list).size()) {
				mvwprintw(wID, n_line, 1, "%i", i + 1);
				mvwprintw(wNAME, n_line, 0, "%s", (*list)[i].name);
				mvwprintw(wDATE, n_line, 1, "%i %s %i", (*list)[i].day, mon_name((*list)[i].nmon), (*list)[i].year);
				wformatted_time(wTIME, n_line, 1, (*list)[i].hour, (*list)[i].min);
				wrefresh(wID);
				wrefresh(wNAME);
				wrefresh(wDATE);
				wrefresh(wTIME);
				n_line += 2;
			}
		}

		key = getch();
		//mvprintw(39, 1, "%i", key);

		if (key == 115 || key == 83) {
			werase(wDET);
			wattron(wDET, COLOR_PAIR(6));
			mvwprintw(wDET, 0, 0, "Press 1 to sort by Day, 2 to sort by Month or 3 to sort by Year.\nPress ESC to go back.");
			wattroff(wDET, COLOR_PAIR(6));
			wrefresh(wDET);
			werase(wSTAT);
			while (1) {
				key = getch();
				if (!(key >= 49 && key <= 51) || key != 27) {
					werase(wDET);
					wattron(wDET, COLOR_PAIR(5));
					mvwprintw(wDET, 0, 0, "Invalid selection...");
					wattroff(wDET, COLOR_PAIR(5));
					wrefresh(wDET);
				}
				if (key == 49) {
					std::sort(myVector.begin(), myVector.end(), SortDay());
					break;
				}
				if (key == 50) {
					std::sort(myVector.begin(), myVector.end(), SortMonth());
					break;
				}
				if (key == 51) {
					std::sort(myVector.begin(), myVector.end(), SortYear());
					break;
				}
				if (key == 27) break;
			}
			break;
		}

		if ((key >= 48 && key <= 57) || key == 8) {
			if (key >= 48 && key <= 57) {
				if (n_keys <= 66) {
					werase(wSTAT);
					type_keys[n_keys] = char(key);
					n_keys++;

					wattron(wSTAT, COLOR_PAIR(3));
					mvwprintw(wSTAT, 0, 0, "Event No: ");
					wattroff(wSTAT, COLOR_PAIR(3));

					wattron(wSTAT, COLOR_PAIR(7));
					for (int o = 0; o < n_keys; o++) wprintw(wSTAT, "%c", type_keys[o]);		// Show the user for any typed numbers
					wrefresh(wSTAT);
					wattroff(wSTAT, COLOR_PAIR(7));
				}
			}
			if (key == 8) {
				if (n_keys > 1) {
					werase(wSTAT);
					type_keys[n_keys] = ' ';
					type_keys[n_keys - 1] = ' ';
					n_keys--;

					wattron(wSTAT, COLOR_PAIR(3));
					mvwprintw(wSTAT, 0, 0, "Event No: ");
					wattroff(wSTAT, COLOR_PAIR(3));

					wattron(wSTAT, COLOR_PAIR(7));
					for (int o = 0; o < n_keys; o++) wprintw(wSTAT, "%c", type_keys[o]);
					wrefresh(wSTAT);
					wattroff(wSTAT, COLOR_PAIR(7));
				}
				else {
					werase(wSTAT);
					wrefresh(wSTAT);
					n_keys = 0;
				}
			}
		}

		// User pressed enter/E/D (all caps)
		if (key == 13 || key == 100 || key == 68 || key == 69 || key == 101 || key == 82 || key == 114) {
			if (n_keys > 0) {
				selected_event_index = atol(&type_keys[0]);
				if (selected_event_index >= 1 && selected_event_index <= int((*list).size())) break;
				else {
					werase(wSTAT);
					wrefresh(wSTAT);
					werase(wDET);
					wattron(wDET, COLOR_PAIR(5));
					mvwprintw(wDET, 0, 0, "Invalid number or out of range.\nPlease try again...");
					wattroff(wDET, COLOR_PAIR(5));
					wrefresh(wDET);
					for (int o = 0; o <= 66; o++) type_keys[o] = ' ';						// Clear the array
					n_keys = 0;																// Reset the number of key typed
				}
			}
		}

		if (key == 27) menu();

		if (key == KEY_RIGHT) {
			if (current_page < max_page) {
				index_page += 12;
				current_page++;
				continue;
			}
		}

		if (key == KEY_LEFT) {
			if (current_page > 1) {
				index_page -= 12;
				current_page--;
				continue;
			}
		}

		if (key == KEY_F(2)) {
			mvprintw(5, 1, "%i", myVector.size());
			//refresh();
		}

		if (key == KEY_F(1)) exit(0);
	}

	if (key == 13) data.show_details(selected_event_index - 1);
	if (key == 100 || key == 68) data.delete_event(selected_event_index - 1);
	if (key == 101 || key == 69) data.edit_event(selected_event_index - 1);

	// Sorting Lab 4
//	if (key == 82 || key == 114) {
		
	//}

	// Swapping Lab 3
	if (key == 82 || key == 114) {
		werase(wDET);
		wattron(wDET, COLOR_PAIR(6));
		mvwprintw(wDET, 0, 0, "Now enter the second event number to replace.\nPress ESC to cancel.");
		wattroff(wDET, COLOR_PAIR(6));
		wrefresh(wDET);
		werase(wSTAT);
		mvwprintw(wSTAT, 0, 0, "Event No To Replace: ");
		wrefresh(wSTAT);
		for (int o = 0; o <= 66; o++) type_keys[o] = ' ';						// Clear the array
		n_keys = 0;
		while (1) {
			key = getch();
			if (key == 27) break;
			if (key >= 48 && key <= 57) {
				if (n_keys <= 66) {
					werase(wSTAT);
					type_keys[n_keys] = char(key);
					n_keys++;

					wattron(wSTAT, COLOR_PAIR(3));
					mvwprintw(wSTAT, 0, 0, "Event No To Replace: ");
					wattroff(wSTAT, COLOR_PAIR(3));

					wattron(wSTAT, COLOR_PAIR(7));
					for (int o = 0; o < n_keys; o++) wprintw(wSTAT, "%c", type_keys[o]);		// Show the user for any typed numbers
					wrefresh(wSTAT);
					wattroff(wSTAT, COLOR_PAIR(7));
				}
			}
			if (key == 8) {
				if (n_keys > 1) {
					werase(wSTAT);
					type_keys[n_keys] = ' ';
					type_keys[n_keys - 1] = ' ';
					n_keys--;

					wattron(wSTAT, COLOR_PAIR(3));
					mvwprintw(wSTAT, 0, 0, "Event No To Replace: ");
					wattroff(wSTAT, COLOR_PAIR(3));

					wattron(wSTAT, COLOR_PAIR(7));
					for (int o = 0; o < n_keys; o++) wprintw(wSTAT, "%c", type_keys[o]);
					wrefresh(wSTAT);
					wattroff(wSTAT, COLOR_PAIR(7));
				}
				else {
					werase(wSTAT);
					wrefresh(wSTAT);
					n_keys = 0;
				}
			}

			if (key == 13 || key == 100) {
				if (n_keys > 0) {
					int sec_selected_event_index;
					sec_selected_event_index = atol(&type_keys[0]);
					if (sec_selected_event_index >= 1 && sec_selected_event_index <= int((*list).size()) && selected_event_index != sec_selected_event_index) {
						/*mvwprintw(wSTAT, 0, 0, "selected: %i, second: %i",selected_event_index,sec_selected_event_index);
						wrefresh(wSTAT);
						getch();*/
						swap(selected_event_index - 1, sec_selected_event_index - 1);
						break;
					}
					else {
						werase(wSTAT);
						wrefresh(wSTAT);
						werase(wDET);
						wattron(wDET, COLOR_PAIR(5));
						mvwprintw(wDET, 0, 0, "Invalid number or out of range.\nPlease try again...");
						wattroff(wDET, COLOR_PAIR(5));
						wrefresh(wDET);
						for (int o = 0; o <= 66; o++) type_keys[o] = ' ';						// Clear the array
						n_keys = 0;																// Reset the number of key typed
						werase(wSTAT);
						mvwprintw(wSTAT, 0, 0, "Event No To Replace: ");
						wrefresh(wSTAT);
					}
				}
			}
		}

	}

	list_events();
}
Exemple #12
0
void show_calendar(bool input, int x_axis = 14, int y_axis = 10) {
	// Calendar
	wcal = newwin(12, 52, y_axis, x_axis);
	wbkgd(wcal, COLOR_PAIR(4));

	// Get current date and print the calendar
	time_t rawtime = time(NULL);
	tm now;
	localtime_s(&now, &rawtime);

	// Applies the changes if the user select to change the month / year
	if (selected_mon != 0 && selected_year != 0) {
		now.tm_year = selected_year - 1900;
		now.tm_mon = selected_mon - 1;
	}

	// Variables
	int nmon = 1, nyear = 1900;

	// Print out the calendar
	printCar(nyear + now.tm_year, now.tm_mon + nmon);

	// Window border
	box(wcal, 0, 0);

	// Draw the window and its contents
	wrefresh(wcal);

	// Loop to manage user inputs
	if (input == true) {
		int key;
		while (1) {
			key = getch();

			// Pressed enter
			if (key == 13) {
				selected_mon = now.tm_mon + nmon;
				selected_year = nyear + now.tm_year;
				erase();
				titlebar();
				refresh();
				menu();
			}

			// Pressed q to exit
			if (key == 113 || key == 81) {
				exit(0);
			}

			// Pressed left key and change to a month before current month
			if (key == 260) {
				nmon--;
				if (now.tm_mon + nmon == 0) {
					nmon = 12 - now.tm_mon;
					nyear--;
				}
				werase(wcal);
				printCar(nyear + now.tm_year, now.tm_mon + nmon);
				box(wcal, 0, 0);
				wrefresh(wcal);
			}

			// Pressed right key and change the month next after current month
			if (key == 261) {
				nmon++;
				if (now.tm_mon + nmon >= 13) {
					nmon = 1 - now.tm_mon;
					nyear++;
				}
				werase(wcal);
				printCar(nyear + now.tm_year, now.tm_mon + nmon);
				box(wcal, 0, 0);
				wrefresh(wcal);
			}
		}
	}
}
Exemple #13
0
// Menu function
void menu() {
	int key;

	resize_term(25, 80);
	erase();
	titlebar();
	noecho();

	attron(COLOR_PAIR(3));
	mvprintw(2, 1, "Menu");
	mvprintw(3, 1, "----");
	mvprintw(5, 1, "1) Create a new event");
	mvprintw(6, 1, "2) View or edit event");
	mvprintw(7, 1, "3) Change month / year (Selected: %s %i)", mon_name(selected_mon), selected_year);
	mvprintw(8, 1, "4) Save all events to file");
	mvprintw(9, 1, "Q) Quit program");
	//mvprintw(23, 1, "Created by Ijat (172205)");
	attron(COLOR_PAIR(8));
	mvprintw(23, 1, "(c) 2014 Ijat.my");
	attron(COLOR_PAIR(3));
	mvprintw(11, 1, "Your selection: ");
	refresh();

	// Check user input
	while (1) {
		key = getch();
		//mvprintw(23, 1, "%i", key);

		// Pressed 1
		if (key == 49) { create_new_event(false); }

		// Pressed 2
		if (key == 50) {
			if (event_saved == false) {
				attron(COLOR_PAIR(5));
				mvhline(23, 1, ' ', 78);
				mvprintw(23, 1, "No event(s) saved. Nothing to view. Please create a new event first!");
				refresh();
				attroff(COLOR_PAIR(5));
			}
			else if (event_saved == true) { //view_event(); 
				list_events();
			}
		}

		// Pressed 3
		if (key == 51) change_mon(); 

		if (key == 52) {
			if (event_saved == true) {
				attron(COLOR_PAIR(6));
				mvprintw(23, 1, "Saved to \"My Events.txt\"");
				data.print_details();
				attroff(COLOR_PAIR(6));
			}
			else {
				attron(COLOR_PAIR(5));
				mvhline(23, 1, ' ', 78);
				mvprintw(23, 1, "No event(s) to save. Please create a event first!");
				attroff(COLOR_PAIR(5));
			}
		}

		// Pressed Q
		if (key == 113 || key == 81) exit(0);
	}
}
Exemple #14
0
// A function to create the "create new event" page.
// This function is the most crucial part in the program which is handling user inputs/data
void create_new_event(bool edit, int z_index ) {
	// This will enable the input to be shown to the user when type.
	resize_term(40, 80);
	echo();

	// Variables
	char rawday, rawname, rawloc, rawhour, rawminute;	// Raw variables used for pdcurses function
	int confirmation;
	bool eventloop = false;									// Indicator for the loop
	int n_day, n_hour, n_minute;							// Day variable which is to be selected by the user

	// Loop until get a data to be saved in data object
	while (eventloop == false) {
		// Empty the console, add titlebar and redraw all.
		erase();
		titlebar();
		refresh();
		raw();

		attron(COLOR_PAIR(3));
		if (edit == true) {
			mvprintw(2, 1, "Edit Event");
			mvprintw(3, 1, "----------");
		}
		else {
			mvprintw(2, 1, "Create New Event");
			mvprintw(3, 1, "----------------");
		}

		mvprintw(20, 1, "Date\t\t:");
		mvprintw(22, 1, "Time\t\t:");
		mvprintw(24, 1, "Event name\t:");
		mvprintw(26, 1, "Location\t:");
		//mvprintw(28, 1, "Description\t:");
		
		// Disabled due to BUG002
		// A small window for description to fit in the text in nice allignment.
		/*WINDOW *wdesc;
		wdesc = newwin(3, 60, 28, 18);
		wattron(wdesc, COLOR_PAIR(3));*/

		// Show calendar, without any inputs
		mvprintw(4, 36, "Calendar");
		show_calendar(false, 14, 6);

		// Show status window (used to deliver message to the user about error, etc.)
		statuswin();

		// Update text in status window
		update_status("Please select the day for the event...\n\nTo go back, press ESC and ENTER",6);
		//refresh();

		// Do this loop until the program obtained a valid day

		do {
			mvhline(20, 18, ' ', 3);											// Clear a small portion of the console
			mvprintw(20, 21, "%s %i", mon_name(selected_mon), selected_year);	// Print the month and year
			mvgetnstr(20, 18, &rawday, 2);										// User input of the day
			if (rawday == 27) menu();												// If user pressed esc and enter, the program will go back to main menu
			n_day = atoi(&rawday);
			//n_day = day;														// A C-function to convert char * to int
			if (n_day == 0 || n_day > max_day_in_month) { update_status("Invalid day. Please enter a valid DAY in the selected month.\n\nTo go back, press ESC and ENTER.",5); }			// Inform user if the day not valid
			refresh();															// Redraw
		} while (n_day == 0 || n_day > max_day_in_month);						// Check if the day valid or not

		// Got a nice and valid n_day and print again to the screen.
		mvhline(20, 18, ' ', 60);												// Refresh the line
		mvprintw(20, 18, "%i %s %i", n_day, mon_name(selected_mon), selected_year);

		// Update to the current status.
		update_status("Please enter the hour in 24 hours...\nIf you enter some string, the result will be 0.", 6);

		// A loop that handle the time input. Runs loop until it gets the valid time.
		do {

			mvhline(22, 18, ' ', 6);											// Clear the line
			mvgetnstr(22, 18, &rawhour, 2);										// Get hour from user
			if (rawhour == 27) menu();											// If user input is ESC then go back to menu
			n_hour = atoi(&rawhour);											// Convert from char to int
			if ( !(n_hour >= 0 && n_hour < 24) ) {								// Check for valid hour
				update_status("Invalid hour. Enter a number in between 0-23. Please try again...", 5);
				continue;
			}
			else {
				mvprintw(22, 20, ":");
				update_status("Please enter the minute...\nIf you enter some string, the result will be 0.", 6);
				do {
					mvhline(22, 21, ' ', 3);
					mvgetnstr(22, 21, &rawminute, 2);
					if (rawminute == 27) menu();
					n_minute = atoi(&rawminute);								// Convert from char to int
					if (!(n_minute >= 0 && n_minute < 60)) {					// Check for valid minutes
						update_status("Invalid minute. Type a number in between 0-59. Please try again...", 5);
						continue;
					}
					else break;
				} while (1);
				break;
			}
		} while (1);

		// Print the time nicely.
		mvhline(22, 18, ' ', 6);
		formatted_time(22, 18, n_hour, n_minute);		// Print time in formatted form xx:yy

		// Update the status
		update_status("Now fill the name, location and description of the event.");

		// Get event name, location and description		// BUG001
		mvgetnstr(24, 18, &rawname, 28);				// First program bug detected here (Read below for more)
		data.save_name(&rawname);						// This function is used to copy rawname char * to another variable in normal char type. It copy the data to a more reliable variable.
														// This is because to prevent memory leak or maybe something else that causes the data in other the pointer (this is bad due to it affect other variable as well) overwritten by the typed data. Approximate more than 11 characters will cause the memory leak -- TESTED)
		mvgetnstr(26, 18, &rawloc, 28);					// Also, to prevent this bug, this function data.save_*** is called right after the user input the data.
		data.save_loc(&rawloc);							// This problem maybe related to the pdcurses library bug that cause the memory leak which affect other variables too.

		//mvwgetnstr(wdesc, 0, 0, &rawdesc, 28);		// BUG002
		//data.save_desc(&rawdesc);						// The program will crash when number of characters more than 28 chars. The cause still unknown. To fix whether to create another custom function to handle input (which is long) or decrease the numbers of characters (which is the quickest way to solve).

		refresh();

		// Clear status
		werase(wstatus);
		wrefresh(wstatus);

		// User confirmation
		mvprintw(32, 1, "Are you sure? (Y/N): ");
		refresh();

		// A loop to check only y/Y/n/N are allowed as a user input
		while (1) {
			mvhline(32, 22, ' ', 1);
			confirmation = getch();
			if (confirmation == 780 || confirmation == 110 || confirmation == 121 || confirmation == 891) { break; }
		}

		// If user type y/Y, the the loop ends
		if (confirmation == 121 || confirmation == 891){
			eventloop = true;								// To ensure that this will break the loop and will not continue anymore
			data.day = n_day;								// Save user inputs
			data.year = selected_year;
			data.nmon = selected_mon;

			// LAB-2
			data.hour = n_hour;
			data.min = n_minute;

			if (edit == true) {
				myVector.erase(myVector.begin() + z_index);
				myVector.insert(myVector.begin() + z_index, data);
				list_events();
			}
			else {
				myVector.push_back(data);
				event_saved = true;								// Tells the program about the saved data
				break;
			}
		}
	}

	if (edit == false) menu();
}
Exemple #15
0
int main(int argc, char *argv[]) {
	// Set the tiltle of the window
	system("title ");

	// Pdcurses initiation functions
	initscr();
	scrollok(stdscr, TRUE);
	raw();
	noecho();
	clear();
	keypad(stdscr, TRUE);

	// Get max height and width of the console. 
	getmaxyx(stdscr, max_y, max_x);

	// Color functions/declarations
	start_color();
	init_color(COLOR_RED, 1000, 500, 500);
	init_pair(1, 15, 9);
	init_pair(2, 0, 7);
	init_pair(3, 15, 0);
	init_pair(4, 15, 1);
	init_pair(5, 12, 0);
	init_pair(6, 10, 0);
	init_pair(7, 13, 0);
	init_pair(8, 11, 0);

	// Title of the app (with blue background)
	titlebar();

	attron(COLOR_PAIR(3));		// Function to enable coloured text based on color pair (init_pair) declared before.
	mvprintw(2, 1, "Welcome to rF3.Calendar!");
	mvprintw(3, 1, "------------------------");
	mvprintw(5, 1, "Please select the month / year...");
	mvprintw(6, 1, "Press key LEFT or RIGHT to change and ENTER to select.");
	mvprintw(7, 1, "To quit this program, press Q.");
	refresh();

	// Adding example events to the vector
	event_saved = true;
	data.save_name("Example Event");
	data.save_loc("Engineering Faculty");
	data.min = 20;
	data.hour = 11;
	srand(time_t(NULL));
	for (int o = 1; o < 31; o++) {
		data.day = rand() % (10 - 1 + 1) + 1;
		data.nmon = rand() % (12 - 1 + 1) + 1;
		data.year = rand() % (2014 - 1990 + 1) + 1990;
		myVector.push_back(data);
	}

	// Old code
	// Show the calendar and user must select one
	//show_calendar(true,14,10);

	set_month();
	menu();

	return 0;
}
Exemple #16
0
/* If path is NULL, we're in normal editing mode, so display the current
 * version of pinot, the current filename, and whether the current file
 * has been modified on the titlebar.  If path isn't NULL, we're in the
 * file browser, and path contains the directory to start the file
 * browser in, so display the current version of pinot and the contents
 * of path on the titlebar. */
void titlebar(const std::string& path)
{
	titlebar(path.c_str());
}