diff options
author | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-07-13 02:24:36 +0300 |
---|---|---|
committer | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-07-13 02:24:36 +0300 |
commit | 7fbfb61101735082287e65abced1fc02425932b1 (patch) | |
tree | d4ae3d5d665cca32bfad26408b3938321549aa1d | |
parent | Add scrolling to tuiclient (diff) | |
download | idfetch-7fbfb61101735082287e65abced1fc02425932b1.tar.gz idfetch-7fbfb61101735082287e65abced1fc02425932b1.tar.bz2 idfetch-7fbfb61101735082287e65abced1fc02425932b1.zip |
Add help window to tuiclient
-rw-r--r-- | segget/network0.conf | 4 | ||||
-rw-r--r-- | segget/segget.conf | 60 | ||||
-rw-r--r-- | segget/stats.cpp | 2 | ||||
-rw-r--r-- | segget/tui.cpp | 2 | ||||
-rw-r--r-- | tuiclient/colors.cpp | 51 | ||||
-rw-r--r-- | tuiclient/colors.h | 35 | ||||
-rw-r--r-- | tuiclient/helpwindow.cpp | 42 | ||||
-rw-r--r-- | tuiclient/helpwindow.h | 41 | ||||
-rw-r--r-- | tuiclient/mainwindow.cpp | 90 | ||||
-rw-r--r-- | tuiclient/mainwindow.h | 61 | ||||
-rw-r--r-- | tuiclient/tuiclient.cpp | 375 | ||||
-rw-r--r-- | tuiclient/tuiclient.h | 59 | ||||
-rw-r--r-- | tuiclient/twindow.cpp | 100 | ||||
-rw-r--r-- | tuiclient/twindow.h | 77 |
14 files changed, 725 insertions, 274 deletions
diff --git a/segget/network0.conf b/segget/network0.conf index d816e29..6b80614 100644 --- a/segget/network0.conf +++ b/segget/network0.conf @@ -63,7 +63,7 @@ bind_interface=none # Maximum value: 20 # Default: # max_connections=10 -max_connections=2 +max_connections=20 # CONNECTION_TIMEOUT # Set the number of seconds to wait while trying to connect. Use 0 to wait @@ -249,4 +249,4 @@ use_own_mirror_list_only_on=0 # in network0.conf file has been reached. # Default: # only_local_when_possible=1 -only_local_when_possible=1
\ No newline at end of file +only_local_when_possible=0
\ No newline at end of file diff --git a/segget/segget.conf b/segget/segget.conf index 8b8217b..489acf9 100644 --- a/segget/segget.conf +++ b/segget/segget.conf @@ -76,7 +76,7 @@ max_tries=10 # Maximum value: 20 # Default: # max_connections=10 -max_connections=6 +max_connections=10 # CURRENT_SPEED_TIME_INTERVAL_MSECS # segget transfers may have bursty nature of their traffic. Therefore, while @@ -99,7 +99,7 @@ current_speed_time_interval_msecs=1000 # Maximum value: 10 # Default: # max_connections_num_per_mirror=1 -max_connections_num_per_mirror=2 +max_connections_num_per_mirror=10 # SYNOPSIS: collect_benchmark_stats_on=0 | 1 # - If set to 1, stats on mirrors performance will be collected. @@ -189,68 +189,14 @@ provide_mirror_files_restrict_list_on=1 # Default: # network0_priority=10 network0_priority=10 - -# NETWORK1_PRIORITY -# Description: same as for NETWORK0_PRIORITY -# Define network specific settings in network1.conf -# Default: -# network1_priority=0 -network1_priority=9 - -# NETWORK2_PRIORITY -# Description: same as for NETWORK0_PRIORITY -# Define network specific settings in network2.conf -# Default: -# network2_priority=0 +network1_priority=0 network2_priority=8 - -# NETWORK3_PRIORITY -# Description: same as for NETWORK0_PRIORITY -# Define network specific settings in network3.conf -# Default: -# network3_priority=0 network3_priority=0 - -# NETWORK4_PRIORITY -# Description: same as for NETWORK0_PRIORITY -# Define network specific settings in network4.conf -# Default: -# network4_priority=0 network4_priority=0 - -# NETWORK5_PRIORITY -# Description: same as for NETWORK0_PRIORITY -# Define network specific settings in network5.conf -# Default: -# network5_priority=0 network5_priority=0 - -# NETWORK6_PRIORITY -# Description: same as for NETWORK0_PRIORITY -# Define network specific settings in network6.conf -# Default: -# network6_priority=0 network6_priority=0 - -# NETWORK7_PRIORITY -# Description: same as for NETWORK0_PRIORITY -# Define network specific settings in network7.conf -# Default: -# network7_priority=0 network7_priority=0 - -# NETWORK8_PRIORITY -# Description: same as for NETWORK0_PRIORITY -# Define network specific settings in network8.conf -# Default: -# network8_priority=0 network8_priority=0 - -# NETWORK9_PRIORITY -# Description: same as for NETWORK0_PRIORITY -# Define network specific settings in network9.conf -# Default: -# network9_priority=0 network9_priority=0 [schedule] diff --git a/segget/stats.cpp b/segget/stats.cpp index cfbe66c..bd782ca 100644 --- a/segget/stats.cpp +++ b/segget/stats.cpp @@ -57,7 +57,7 @@ void Tstats::show_totals(){ +field(" / ", distfiles_count,4) +field(" = Size:", dld_size/1000,7) +field(" / ", total_size/1000,7)+" Kb " - +field(" = ", dld_size*100/(1+show_total_size),3)+"%%" + +field(" = ", dld_size*100/(1+show_total_size),3)+"%" +field(" Total speed: ", (total_bytes_per_last_interval/(show_last_time_interval)),7) +" Kb/s" // +" Secs:"+toString(now_timee.tv_sec) diff --git a/segget/tui.cpp b/segget/tui.cpp index ade8e68..d84e17e 100644 --- a/segget/tui.cpp +++ b/segget/tui.cpp @@ -76,7 +76,7 @@ void msg_segment_progress(uint connection_num, uint network_num, uint segment_nu +field(" Try:",try_num,4) +field(" Bytes:",dld_bytes,7) +field(" / ",total_bytes,7) - +field(" = ",percent,3)+"%%" + +field(" = ",percent,3)+"%" +speed_str +avg_speed_str); }catch(...){ diff --git a/tuiclient/colors.cpp b/tuiclient/colors.cpp new file mode 100644 index 0000000..53871e5 --- /dev/null +++ b/tuiclient/colors.cpp @@ -0,0 +1,51 @@ +/* +* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>. +* +* Project: IDFetch. +* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine). +* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead). +* Mentoring organization: Gentoo Linux. +* Sponsored by GSOC 2010. +* +* This file is part of Segget. +* +* Segget is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* Segget 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with Segget; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "colors.h" + +void color_downloads(){ + if(has_colors()){ + start_color(); /* Start color */ + init_pair(1, COLOR_WHITE, COLOR_BLUE); + attron(COLOR_PAIR(1)); + } +} + +void color_info(){ + if(has_colors()){ + start_color(); /* Start color */ + init_pair(2, COLOR_BLACK, COLOR_CYAN); + attron(COLOR_PAIR(2)); + } +} + +void color_status(){ + if(has_colors()){ + start_color(); /* Start color */ + init_pair(3, COLOR_RED, COLOR_BLUE); + attron(COLOR_PAIR(3)); + } +} diff --git a/tuiclient/colors.h b/tuiclient/colors.h new file mode 100644 index 0000000..904c150 --- /dev/null +++ b/tuiclient/colors.h @@ -0,0 +1,35 @@ +/* +* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>. +* +* Project: IDFetch. +* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine). +* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead). +* Mentoring organization: Gentoo Linux. +* Sponsored by GSOC 2010. +* +* This file is part of Segget. +* +* Segget is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* Segget 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with Segget; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _COLORS_H_ +#define _COLORS_H_ + +#include <ncurses.h> + +void color_downloads(); +void color_info(); +void color_status(); +#endif
\ No newline at end of file diff --git a/tuiclient/helpwindow.cpp b/tuiclient/helpwindow.cpp new file mode 100644 index 0000000..da51d75 --- /dev/null +++ b/tuiclient/helpwindow.cpp @@ -0,0 +1,42 @@ +/* +* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>. +* +* Project: IDFetch. +* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine). +* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead). +* Mentoring organization: Gentoo Linux. +* Sponsored by GSOC 2010. +* +* This file is part of Segget. +* +* Segget is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* Segget 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with Segget; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "helpwindow.h" + +void Thelp_window::compose(){ +// msg_text=msg_text+" "; +// + box(window, ACS_VLINE, ACS_HLINE); + mvwaddstr(window,0,12," HELP "); + mvwaddstr(window,2,1,"q - quit"); + mvwaddstr(window,3,1,"h - show this help"); + mvwaddstr(window,4,1,"l - show log"); + mvwaddstr(window,5,1,"Up - scroll 1 line up"); + mvwaddstr(window,6,1,"Down - scroll 1 line down"); + mvwaddstr(window,7,1,"PgUp - scroll 1 page up"); + mvwaddstr(window,8,1,"PgDown - scroll 1 page down"); + wrefresh(window); +}
\ No newline at end of file diff --git a/tuiclient/helpwindow.h b/tuiclient/helpwindow.h new file mode 100644 index 0000000..883b586 --- /dev/null +++ b/tuiclient/helpwindow.h @@ -0,0 +1,41 @@ +/* +* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>. +* +* Project: IDFetch. +* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine). +* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead). +* Mentoring organization: Gentoo Linux. +* Sponsored by GSOC 2010. +* +* This file is part of Segget. +* +* Segget is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* Segget 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with Segget; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _HELPWINDOW_H_ +#define _HELPWINDOW_H_ + +#include "twindow.h" + +using namespace std; +class Thelp_window: public Twindow{ + public: +// Thelp_window(int height_, int width_, int y_, int x_); +// Thelp_window(); + ~Thelp_window(){}; + void compose(); +}; + +#endif
\ No newline at end of file diff --git a/tuiclient/mainwindow.cpp b/tuiclient/mainwindow.cpp new file mode 100644 index 0000000..b649832 --- /dev/null +++ b/tuiclient/mainwindow.cpp @@ -0,0 +1,90 @@ +/* +* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>. +* +* Project: IDFetch. +* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine). +* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead). +* Mentoring organization: Gentoo Linux. +* Sponsored by GSOC 2010. +* +* This file is part of Segget. +* +* Segget is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* Segget 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with Segget; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "mainwindow.h" + +void Tmainwindow::msg_status(){ + msg_short(0,width/2-13,"tuiclient to segget daemon"); + msg_short(0,width-20,"[Lines:"+toString(top_position+1)+"-"+toString(top_position+1+bottom_screenline_num)+"/"+toString(max_received_screenline_num+1)+"]"); + msg_short(height-1,2,status_str); + msg_short(height-1,width-18,"[h-Help] [q-Quit]"); +} + +void Tmainwindow::compose(){ + //clear(); + box(window, ACS_VLINE, ACS_HLINE); + getmaxyx(window,height,width); + bottom_screenline_num=height-6; + color_status(); + msg_status(); + color_info(); + for (uint y=bottom_screenline_num,status_line_num=0; y<height-2; y++,status_line_num++){ + msg_line(y+1,screen_info_lines[status_line_num]); + } + color_downloads(); + screenlines[26]="Max_num:"+toString(max_received_screenline_num); + for (int y=0, line_num=top_position; y<bottom_screenline_num; y++, line_num++){ + msg_line(y+1,screenlines[line_num]); + } + wrefresh(window); + //and show children + help_win.center(height,width); + help_win.show(); +} + +void Tmainwindow::set_status(string str){ + status_str=str; + notfresh=TRUE; + //show_lines(); +} + +void Tmainwindow::set_line(int y, string msg_text){ + screenlines[y]=msg_text; + notfresh=TRUE; + if (max_received_screenline_num<y) max_received_screenline_num=y; +} + +void Tmainwindow::init(){ + top_position=0; + max_received_screenline_num=0; + window=initscr(); +// help_win=Twindow(20,50,5,5); +// box(help_window, ACS_VLINE, ACS_HLINE); +// wrefresh(help_window); + curs_set(0); + //don't echo keyboard to the screen visible=TRUE; + + noecho(); + //don't wait for enter + cbreak(); + //enable arrow keys + keypad(stdscr,TRUE); + keypad(window,TRUE); + exit_flag=FALSE; + visible=TRUE; + notfresh=TRUE; + help_win.init(12,30,5,5); +} diff --git a/tuiclient/mainwindow.h b/tuiclient/mainwindow.h new file mode 100644 index 0000000..64184ca --- /dev/null +++ b/tuiclient/mainwindow.h @@ -0,0 +1,61 @@ +/* +* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>. +* +* Project: IDFetch. +* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine). +* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead). +* Mentoring organization: Gentoo Linux. +* Sponsored by GSOC 2010. +* +* This file is part of Segget. +* +* Segget is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* Segget 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with Segget; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _MAINWINDOW_H_ +#define _MAINWINDOW_H_ + +#include <ncurses.h> +#include <sys/types.h> + +using namespace std; + +#include "twindow.h" +#include "helpwindow.h" + +const uint CONNECTION_LINES=5; +const uint MAX_LINES=200; + +class Tmainwindow: public Twindow{ + public: + + Thelp_window help_win; + bool exit_flag; + string screenlines[200]; + string screen_info_lines[4]; + Tmainwindow(): + help_win(), + exit_flag(FALSE) + {}; + ~Tmainwindow(){}; + Tmainwindow(const Twindow &L); // copy constructor + Tmainwindow & operator=(const Twindow &L); + void msg_status(); + void compose(); + void set_status(string str); + void set_line(int y, string msg_text); + void init(); +}; +#endif
\ No newline at end of file diff --git a/tuiclient/tuiclient.cpp b/tuiclient/tuiclient.cpp index 85f5baf..6214964 100644 --- a/tuiclient/tuiclient.cpp +++ b/tuiclient/tuiclient.cpp @@ -1,144 +1,92 @@ -//Make the necessary includes and set up the variables: -#include <sys/types.h> -#include <sys/socket.h> -#include <stdio.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <sys/ioctl.h> -#include <unistd.h> -#include <stdlib.h> -#include <string> -#include <string.h> -#include <ncurses.h> -#include <pthread.h> -#include "str.cpp" - -#define BUFFER_SIZE 2000 - -#define TOTAL_LINE_NUM 200 -#define ERROR_LINE_NUM 201 -#define LOG_LINE_NUM 202 -#define DEBUG_LINE_NUM 203 - -using namespace std; - -WINDOW * screen; -int max_x, max_y; -int max_received_screenline_num; -int last_screenline_num; - - -void show_lines(); - -const uint CONNECTION_LINES=5; -const uint MAX_LINES=200; -int top_position; -string screenlines[200]; -string screen_info_lines[4]; -string status_str; -void msg_line(uint y, string msg_text){ +/* +* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>. +* +* Project: IDFetch. +* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine). +* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead). +* Mentoring organization: Gentoo Linux. +* Sponsored by GSOC 2010. +* +* This file is part of Segget. +* +* Segget is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* Segget 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with Segget; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "tuiclient.h" + +void quit(){ + mainwindow.exit_flag=TRUE; try{ -// cout << msg_text; - msg_text=msg_text+" "; - mvaddstr(y,1,msg_text.substr(0,max_x-2).c_str()); -// mvwprintw(screen,y,1,ready_msg_text.c_str()); -// mvwprintw(screen,y,1,msg_text.substr(0,max_x-2).c_str()); -// mvaddstr(); - }catch(...){ -// error_log_no_msg("Error in tui.cpp: msg()"); + close(sockfd); } -} -void msg_short(uint y, uint x, string msg_text){ - try{ - mvaddstr(y,x,msg_text.c_str()); - }catch(...){ -// error_log_no_msg("Error in tui.cpp: msg()"); - } -} -void set_status(string str){ - status_str=str; - show_lines(); -} - -void color_downloads(){ - if(has_colors()){ - start_color(); /* Start color */ - init_pair(1, COLOR_WHITE, COLOR_BLUE); - attron(COLOR_PAIR(1)); + catch(...) + { + //error while closing socket } -} - -void color_info(){ - if(has_colors()){ - start_color(); /* Start color */ - init_pair(2, COLOR_BLACK, COLOR_CYAN); - attron(COLOR_PAIR(2)); + try{ + close(sockfd); +// sleep(1); + nocbreak(); + endwin(); + exit(0); } -} - -void color_status(){ - if(has_colors()){ - start_color(); /* Start color */ - init_pair(3, COLOR_RED, COLOR_BLUE); - attron(COLOR_PAIR(3)); + catch(...) + { + //error while ending curses } } - -void msg_status(){ - msg_short(0,max_x/2-13,"tuiclient to segget daemon"); - msg_short(max_y-1,2,status_str); - msg_short(max_y-1,max_x-10,"[q-Quit]"); -} - -void show_lines(){ - //clear(); - box(screen, ACS_VLINE, ACS_HLINE); - getmaxyx(screen,max_y,max_x); - last_screenline_num=max_y-6; - color_status(); - msg_status(); - color_info(); - for (int y=max_y-6,status_line_num=0; y<max_y-2; y++,status_line_num++){ - msg_line(y+1,screen_info_lines[status_line_num]); - } - color_downloads(); - screenlines[26]="Max_num:"+toString(max_received_screenline_num); - for (int y=0, line_num=top_position; y<max_y-6; y++, line_num++){ - msg_line(y+1,screenlines[line_num]); +void * watch_keyboard_thread_function(void * ptr){ + char * args = (char *) ptr; + while (true){ + char key=getch(); + switch (key){ + //KEY_DOWN + case (char)2:mainwindow.down(1);break; + //KEY_RIGHT + case (char)5:mainwindow.down(1);break; + //KEY_UP + case (char)3:mainwindow.up(1);break; + //KEY_LEFT + case (char)4:mainwindow.up(1);break; + //KEY_PG_DOWN + case (char)82:mainwindow.down(mainwindow.bottom_screenline_num);break; + //KEY_PG_UP + case (char)83:mainwindow.up(mainwindow.bottom_screenline_num);break; + case 'u':mainwindow.up(1);break; + case 'U':mainwindow.up(1);break; + case 'd':mainwindow.down(1);break; + case 'D':mainwindow.down(1);break; + case 'q':quit();break; + case 'Q':quit();break; + case 'h':mainwindow.help_win.toggle(); mainwindow.show();break; + case 'H':mainwindow.help_win.toggle(); mainwindow.show();break; +// default: screenlines[25]=toString((int)key); + } } - wrefresh(screen); - refresh(); -} - -void set_line(uint y, string msg_text){ - screenlines[y]=msg_text; - if (max_received_screenline_num<y) max_received_screenline_num=y; -} -void updown(int inc){ - int tmp_top_position=top_position+inc; - if (tmp_top_position>=0 && tmp_top_position<(max_received_screenline_num-last_screenline_num)){ - top_position=tmp_top_position; - } + return 0; } -void * watch_keyboard_thread_function(void * ptr){ +void * refresh_screen_thread_function(void * ptr){ char * args = (char *) ptr; - while (true){ - char key=getch(); - switch (key){ - //KEY_DOWN - case (char)2:updown(1);break; - //KEY_RIGHT - case (char)5:updown(1);break; - //KEY_UP - case (char)3:updown(-1);break; - //KEY_LEFT - case (char)4:updown(-1);break; - case 'u':updown(1);break; - case 'd':updown(-1);break; -// default: screenlines[25]=toString((int)key); - } + while (! mainwindow.exit_flag){ + mainwindow.refresh(); + struct timeval delay; + delay.tv_sec=0; + delay.tv_usec=300000; + select(FD_SETSIZE, (fd_set *)0, (fd_set *)0,(fd_set *)0, (struct timeval *) &delay);//&timeout } return 0; } @@ -148,16 +96,7 @@ int main() try{ try{ //init curses - screen=initscr(); - curs_set(0); - //don't echo keyboard to the screen - noecho(); - //don't wait for enter - cbreak(); - //enable arrow keys - keypad(screen,true); - top_position=0; - max_received_screenline_num=0; + mainwindow.init(); }catch(...) { //error while init curses @@ -168,91 +107,101 @@ int main() iret1 = pthread_create( &watch_keyboard_thread, NULL, watch_keyboard_thread_function, (void*) NULL); }catch(...) { - //error while init curses + //error while init curses watch_keyboard_thread; } try{ - while (true){ - int sockfd; - int len; - struct sockaddr_in address; - string recv_msg, first_part, msg_text; - - //Create a socket for the client: - int result=-1; - ulong attempt_num=1; - while (result==-1){ - sockfd = socket(AF_INET, SOCK_STREAM, 0); - - //Name the socket, as agreed with the server: - address.sin_family = AF_INET; - address.sin_addr.s_addr = inet_addr("127.0.0.1"); - address.sin_port = htons(9999); - len = sizeof(address); - //Connect your socket to the server’s socket: - result = connect(sockfd, (struct sockaddr *)&address, len); - if(result == -1) { - set_status("[Connecting... Attempt:"+toString(attempt_num)+". Waiting for 1 sec, before next reconnect.]"); - close(sockfd); - attempt_num++; - sleep(1); + pthread_t refresh_screen_thread; + int iret1; + iret1 = pthread_create( &refresh_screen_thread, NULL, refresh_screen_thread_function, (void*) NULL); + }catch(...) + { + //error while init refresh_screen_thread; + } + try{ +// struct timeval timeout; + while ( ! mainwindow.exit_flag ){ + int len; + + struct sockaddr_in address; + string recv_msg, first_part, msg_text; + + //Create a socket for the client: + int result=-1; + ulong attempt_num=1; + while (result==-1){ + sockfd = socket(AF_INET, SOCK_STREAM, 0); + + //Name the socket, as agreed with the server: + address.sin_family = AF_INET; + address.sin_addr.s_addr = inet_addr("127.0.0.1"); + address.sin_port = htons(9999); + len = sizeof(address); + //Connect your socket to the server’s socket: + result = connect(sockfd, (struct sockaddr *)&address, len); + if(result == -1) { + mainwindow.set_status("[Connecting... Attempt:"+toString(attempt_num)+". Waiting for 1 sec, before next reconnect.]"); + close(sockfd); + attempt_num++; + sleep(1); + } } - } - - set_status("[Connected]"); - fd_set readfds, testfds; - FD_ZERO(&readfds); - FD_SET(sockfd, &readfds); - testfds = readfds; - bool run_flag=true; - while (run_flag){ - result = select(FD_SETSIZE, &testfds, (fd_set *)0, - (fd_set *)0, (struct timeval *) 0); - - int nread; - ioctl(sockfd, FIONREAD, &nread); - if(nread == 0) { - close(sockfd); - // FD_CLR(sockfd, &readfds); -// printf("removing client on fd %d\n", sockfd); - run_flag=false; - }else { - char recv_buffer[BUFFER_SIZE+1]=""; - read(sockfd, recv_buffer, BUFFER_SIZE); - //recv_msg=recv_msg+recv_buffer; - recv_msg="MMM"; - recv_msg=recv_msg+recv_buffer; -// cout<<recv_buffer; - while (recv_msg.find("<.>")!=recv_msg.npos){ - string original_msg=recv_msg; - recv_msg=recv_msg.substr(recv_msg.find("<y>")+3,recv_msg.npos); - first_part=recv_msg.substr(0,recv_msg.find("<.>")); - - recv_msg=recv_msg.substr(recv_msg.find("<.>")+3); - uint line_num=atoi(first_part.substr(0,first_part.find("<s>")).c_str()); - msg_text=first_part.substr(first_part.find("<s>")+3,first_part.npos); - if (line_num<200){ - set_line(line_num, msg_text); -// set_line(line_num, "||"+toString(line_num)+"||("+first_part.substr(0,first_part.find("<s>")+3)+")"+msg_text); -// set_line(line_num, "||"+toString(line_num)+"||("+original_msg); - }else{ - screen_info_lines[line_num-200]=msg_text; - } - show_lines(); - } - }; - } - close(sockfd); + mainwindow.set_status("[Connected]"); + fd_set readfds, testfds; + + FD_ZERO(&readfds); + FD_SET(sockfd, &readfds); + testfds = readfds; + bool run_flag=true; + while (run_flag){ + //init each time ! +// timeout.tv_sec=1; +// timeout.tv_usec=0; + result = select(FD_SETSIZE, &testfds, (fd_set *)0, + (fd_set *)0, (struct timeval *) 0);//&timeout + // if fd is set - it's not because of timeout - read data + if (FD_ISSET(sockfd, &testfds)){ + int nread; + ioctl(sockfd, FIONREAD, &nread); + if(nread == 0) { + close(sockfd); +// FD_CLR(sockfd, &readfds); +// printf("removing client on fd %d\n", sockfd); + run_flag=false; + }else { + char recv_buffer[BUFFER_SIZE+1]=""; + read(sockfd, recv_buffer, BUFFER_SIZE); + //recv_msg=recv_msg+recv_buffer; + recv_msg=recv_msg+recv_buffer; + while (recv_msg.find("<.>")!=recv_msg.npos){ + string original_msg=recv_msg; + recv_msg=recv_msg.substr(recv_msg.find("<y>")+3,recv_msg.npos); + first_part=recv_msg.substr(0,recv_msg.find("<.>")); + recv_msg=recv_msg.substr(recv_msg.find("<.>")+3); + uint line_num=atoi(first_part.substr(0,first_part.find("<s>")).c_str()); + msg_text=first_part.substr(first_part.find("<s>")+3,first_part.npos); + if (line_num<200){ + mainwindow.set_line(line_num, msg_text); +// set_line(line_num, "||"+toString(line_num)+"||("+first_part.substr(0,first_part.find("<s>")+3)+")"+msg_text); +// set_line(line_num, "||"+toString(line_num)+"||("+original_msg); + }else{ + mainwindow.screen_info_lines[line_num-200]=msg_text; + } + } + }; + } + } + close(sockfd); } }catch(...){ // error_log_no_msg("Error in segget.cpp launch_tui_theread() failed"); } - getch(); } catch(...){ //error during init and downloading process } try{ + nocbreak(); endwin(); } catch(...) @@ -260,4 +209,4 @@ int main() //error while ending curses } return 0; -} +}
\ No newline at end of file diff --git a/tuiclient/tuiclient.h b/tuiclient/tuiclient.h new file mode 100644 index 0000000..1d4b1cd --- /dev/null +++ b/tuiclient/tuiclient.h @@ -0,0 +1,59 @@ +/* +* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>. +* +* Project: IDFetch. +* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine). +* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead). +* Mentoring organization: Gentoo Linux. +* Sponsored by GSOC 2010. +* +* This file is part of Segget. +* +* Segget is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* Segget 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with Segget; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include <sys/types.h> +#include <sys/socket.h> +#include <stdio.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <stdlib.h> +#include <string> +#include <string.h> +#include <ncurses.h> +#include <pthread.h> +#include "str.cpp" +#include "twindow.cpp" +#include "mainwindow.cpp" +#include "helpwindow.cpp" +#include "colors.cpp" + +#define BUFFER_SIZE 2000 + +#define TOTAL_LINE_NUM 200 +#define ERROR_LINE_NUM 201 +#define LOG_LINE_NUM 202 +#define DEBUG_LINE_NUM 203 + +using namespace std; + +Tmainwindow mainwindow; + +int sockfd; +void quit(); +void * watch_keyboard_thread_function(void * ptr); +void * refresh_screen_thread_function(void * ptr);
\ No newline at end of file diff --git a/tuiclient/twindow.cpp b/tuiclient/twindow.cpp new file mode 100644 index 0000000..233c499 --- /dev/null +++ b/tuiclient/twindow.cpp @@ -0,0 +1,100 @@ +/* +* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>. +* +* Project: IDFetch. +* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine). +* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead). +* Mentoring organization: Gentoo Linux. +* Sponsored by GSOC 2010. +* +* This file is part of Segget. +* +* Segget is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* Segget 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with Segget; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "twindow.h" + +void Twindow::init(int height_, int width_, int y_, int x_){ + height=height_; + width=width_; + y=y_; + x=x_; + window=newwin(height,width,y,x); +} + +void Twindow::toggle(){ + visible=not(visible); +} + +void Twindow::msg_line(uint y, string msg_text){ + try{ +// cout << msg_text; + msg_text=msg_text+" "; + mvwaddstr(window,y,1,msg_text.substr(0,width-2).c_str()); +// mvwprintw(screen,y,1,ready_msg_text.c_str()); +// mvwprintw(screen,y,1,msg_text.substr(0,max_x-2).c_str()); +// mvaddstr(); + }catch(...){ +// error_log_no_msg("Error in tui.cpp: msg()"); + } +} + +void Twindow::msg_short(uint y, uint x, string msg_text){ + try{ + mvwaddstr(window,y,x,msg_text.c_str()); + }catch(...){ +// error_log_no_msg("Error in tui.cpp: msg()"); + } +} +void Twindow::up(int inc){ + int tmp_top_position=top_position-inc; + notfresh=TRUE; + if (tmp_top_position<0){ + top_position=0; + }else{ + top_position=tmp_top_position; + } +} +void Twindow::down(uint inc){ + int tmp_top_position=top_position+inc; + // if we need to scroll down + if (max_received_screenline_num>bottom_screenline_num){ + notfresh=TRUE; + if (tmp_top_position>(max_received_screenline_num-bottom_screenline_num)){ + //set to max if it's over the limit + top_position=max_received_screenline_num-bottom_screenline_num; + }else{ + top_position=tmp_top_position; + } + } +} + +void Twindow::center(uint max_y, uint max_x){ + y=(max_y-height)/2; + x=(max_x-width)/2; + mvwin(window,y,x); +} + +void Twindow::refresh(){ + if (notfresh){ + show(); + } +} + +void Twindow::show(){ + if (visible){ + compose(); + } +}
\ No newline at end of file diff --git a/tuiclient/twindow.h b/tuiclient/twindow.h new file mode 100644 index 0000000..32ab4b4 --- /dev/null +++ b/tuiclient/twindow.h @@ -0,0 +1,77 @@ +/* +* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>. +* +* Project: IDFetch. +* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine). +* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead). +* Mentoring organization: Gentoo Linux. +* Sponsored by GSOC 2010. +* +* This file is part of Segget. +* +* Segget is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* Segget 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with Segget; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _TWINDOW_H_ +#define _TWINDOW_H_ + +#include <ncurses.h> +#include <sys/types.h> +#include "colors.h" + +using namespace std; + +class Twindow{ + public: + WINDOW * window; + uint width; + uint height; + uint y; + uint x; + bool notfresh; + bool visible; + int top_position; + int bottom_screenline_num; + int max_received_screenline_num; + string status_str; + + Twindow(): + window(0), + width(10), + height(10), + y(1), + x(1), + notfresh(FALSE), + visible(FALSE), + top_position(0), + bottom_screenline_num(0), + max_received_screenline_num(0), + status_str("") + {}; + virtual ~Twindow(){}; + Twindow(const Twindow &L); // copy constructor + Twindow & operator=(const Twindow &L); + void init(int height_, int width_, int y_, int x_); + void toggle(); + void msg_line(uint y, string msg_text); + void msg_short(uint y, uint x, string msg_text); + void up(int inc); + void down(uint inc); + void center(uint max_y, uint max_x); + void refresh(); + void show(); + virtual void compose(){}; +}; +#endif
\ No newline at end of file |