1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
#include <iostream>
#include <ctime>
#include <cstring>
#include <sstream>
#include <time.h>
#include <cstdlib>
// Ncurses
#include <ncurses.h>
#include <menu.h>
#include <panel.h>
using namespace std;
int y = 10, x = 25;
static time_t start;
static time_t timer_diff;
static int timer_diff_m;
static int timer_diff_h;
int status = 0;
WINDOW *my_wins[0];
PANEL *my_panels[0];
char input[100];
char c_name[100];
char c_company[100];
char c_details[1000];
void basics()
{
clear();
mvprintw( 0, 0, "(Type 'quit' to exit)" );
mvprintw( 5, 0, "start) (Re)Start Timer" );
mvprintw( 6, 0, "stop) Check Timer" );
mvprintw( 7, 0, "n) New Ticket" );
if ( start != 0 ) { mvprintw( 5, x, "Timer started" ); }
if ( timer_diff_m != 0 ) { mvprintw( 6, 25, "Time: %d hours : %d minutes", timer_diff_h, timer_diff_m ); }
mvprintw( y, x, "Enter option: " ); // ncurses print (uses y, x for coordinates)
update_panels();
doupdate();
}
void basics2()
{
clear();
mvprintw( 0, 0, "(Type 'quit' to exit)" );
mvprintw( 5, 0, "start) (Re)Start Timer" );
mvprintw( 6, 0, "stop) Check Timer" );
if ( start != 0 ) { mvprintw( 5, x, "Timer started" ); }
if ( timer_diff_m != 0 ) { mvprintw( 6, 25, "Time: %d hours : %d minutes", timer_diff_h, timer_diff_m ); }
if (c_name != 0) { mvwprintw( my_wins[0], 1, 1, "Client Name: %s", c_name ); } // ncurses print (uses y, x for coordinates)
update_panels();
doupdate();
}
void exec_option( char option[100] )
{
int yy = y, xx = x;
// Start timer
if ( strcmp( option, "start" ) == 0 ) {
start = time(0);
basics();
if ( status == 1 ) { basics2();}
}
// Stop timer
if ( strcmp( option, "stop" ) == 0 ) {
time_t end = time(0);
timer_diff = end - start;
if ( timer_diff >= 60 ) {
timer_diff_m = ((int)timer_diff / 60) % 60; // convert to minutes
timer_diff_h = ((int)timer_diff / 60 / 60) % 24; // convert to hours
} else if ( (timer_diff > 0) && (timer_diff < 60) ) { timer_diff_h = (int)0; timer_diff_m = (int)1; }
basics();
if ( status == 1 ) { basics2();}
}
// Change to the Ticket panel
if ( strcmp( option, "n" ) == 0 ) {
status = 1;
int lines = 30, cols = 60, yy = 12, xx = 20, i;
/* Create windows for the panels */
my_wins[0] = newwin(lines, cols, yy, xx);
/* Create borders around the windows so that you can see the effect of panels */
box(my_wins[0], 0, 0);
/* Attach a panel to each window */ /* Order is bottom up */
my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */
/* Update the stacking order. 2nd panel will be on top */
update_panels();
/* Show it on the screen */
doupdate();
mvwprintw( my_wins[0], 1, 1, "Client Name: " );
wgetstr( my_wins[0], c_name);
mvwprintw( my_wins[0], 3, 1, "Company Name: " );
wgetstr( my_wins[0], c_company);
mvwprintw( my_wins[0], 5, 1, "Details: " );
wgetstr( my_wins[0], c_details);
}
}
int main ()
{
initscr(); // creates stdscr
cbreak(); // debug
keypad(stdscr, TRUE);
basics();
while ( strcmp( input, "quit" ) != 0 ) // ESC (27) to exit
{
// Option List
if (status == 1) {
wgetstr( my_wins[0], input );
} else { getstr( input ); }
exec_option( input );
}
endwin(); // ncurses end
return 0;
}
| |