diff options
Diffstat (limited to 'tuiclient')
-rw-r--r-- | tuiclient/colors.cpp | 48 | ||||
-rw-r--r-- | tuiclient/colors.h | 7 | ||||
-rw-r--r-- | tuiclient/distfilewindow.cpp | 37 | ||||
-rw-r--r-- | tuiclient/mainwindow.cpp | 46 | ||||
-rw-r--r-- | tuiclient/mainwindow.h | 10 | ||||
-rw-r--r-- | tuiclient/scrollwindow.cpp | 4 | ||||
-rw-r--r-- | tuiclient/settings.h | 4 | ||||
-rw-r--r-- | tuiclient/tuiclient.cpp | 266 | ||||
-rw-r--r-- | tuiclient/tuiclient.h | 9 | ||||
-rw-r--r-- | tuiclient/tuidistfile.cpp | 30 | ||||
-rw-r--r-- | tuiclient/tuidistfile.h | 17 | ||||
-rw-r--r-- | tuiclient/twindow.cpp | 2 | ||||
-rw-r--r-- | tuiclient/twindow.h | 6 |
13 files changed, 396 insertions, 90 deletions
diff --git a/tuiclient/colors.cpp b/tuiclient/colors.cpp index 0b1959d..a8b380c 100644 --- a/tuiclient/colors.cpp +++ b/tuiclient/colors.cpp @@ -26,10 +26,44 @@ #include "colors.h" -void color_default_window(WINDOW * window){ +void color_distfile_added(WINDOW * window){ + if(has_colors()){ + start_color(); /* Start color */ + wattron(window, COLOR_PAIR(4)); + } +} + +void color_distfile_waiting(WINDOW * window){ + if(has_colors()){ + start_color(); /* Start color */ + wattron(window, COLOR_PAIR(8)); + } +} + +void color_distfile_downloading(WINDOW * window){ + if(has_colors()){ + start_color(); /* Start color */ + wattron(window, COLOR_PAIR(6)); + } +} + +void color_distfile_downloaded(WINDOW * window){ + if(has_colors()){ + start_color(); /* Start color */ + wattron(window, COLOR_PAIR(5)); + } +} + +void color_distfile_failed(WINDOW * window){ + if(has_colors()){ + start_color(); /* Start color */ + wattron(window, COLOR_PAIR(7)); + } +} + +void color_distfiles_window(WINDOW * window){ if(has_colors()){ start_color(); /* Start color */ - wbkgd(window, COLOR_PAIR(4)); wattron(window, COLOR_PAIR(4)); } } @@ -73,8 +107,11 @@ void colors_connected(){ init_pair(1, COLOR_WHITE, COLOR_BLUE); init_pair(2, COLOR_BLACK, COLOR_CYAN); init_pair(3, COLOR_GREEN, COLOR_BLUE); - init_pair(4, COLOR_BLACK, COLOR_GREEN); + init_pair(4, COLOR_WHITE, COLOR_BLACK); init_pair(5, COLOR_GREEN, COLOR_BLACK); + init_pair(6, COLOR_BLUE, COLOR_BLACK); + init_pair(7, COLOR_RED, COLOR_BLACK); + init_pair(8, COLOR_YELLOW, COLOR_BLACK); // init_pair(4, COLOR_BLACK, COLOR_WHITE); // attrset(A_REVERSE); attrset(A_DIM); @@ -89,7 +126,10 @@ void colors_disconnected(){ init_pair(2, COLOR_WHITE, COLOR_BLACK); init_pair(3, COLOR_BLACK, COLOR_RED); init_pair(4, COLOR_WHITE, COLOR_BLACK); - init_pair(5, COLOR_RED, COLOR_BLACK); + init_pair(5, COLOR_WHITE, COLOR_BLACK); + init_pair(6, COLOR_WHITE, COLOR_BLACK); + init_pair(7, COLOR_WHITE, COLOR_BLACK); + init_pair(8, COLOR_WHITE, COLOR_BLACK); /// attrset(A_BOLD); // attrset(A_REVERSE); } diff --git a/tuiclient/colors.h b/tuiclient/colors.h index ea77f02..1e63bec 100644 --- a/tuiclient/colors.h +++ b/tuiclient/colors.h @@ -30,7 +30,12 @@ he terms of the GNU Lesser General Public #include <ncurses.h> -void color_default_window(WINDOW * window); +void color_distfile_added(WINDOW * window); +void color_distfile_waiting(WINDOW * window); +void color_distfile_downloading(WINDOW * window); +void color_distfile_downloaded(WINDOW * window); +void color_distfile_failed(WINDOW * window); +void color_distfiles_window(WINDOW * window); void color_scroll_window(WINDOW * window); void color_downloads(WINDOW * window); void color_info(WINDOW * window); diff --git a/tuiclient/distfilewindow.cpp b/tuiclient/distfilewindow.cpp index 22c7f49..718f9fe 100644 --- a/tuiclient/distfilewindow.cpp +++ b/tuiclient/distfilewindow.cpp @@ -27,7 +27,7 @@ #include "distfilewindow.h" void Tdistfile_window::compose(){ - color_default_window(window); +// color_distfiles_window(window); make_frame(); // box(window, ACS_VLINE, ACS_HLINE); // getmaxyx(window,height,width); @@ -41,15 +41,46 @@ void Tdistfile_window::compose(){ // color_downloads(window); // screenlines[26]="Max_num:"+toString(max_received_screenline_num); ulong distfile_num=top_position; - for (int y=0; y<bottom_screenline_num and distfile_num<tuidistfiles.size(); y++, distfile_num++){ + string percent; + for (uint y=0; y<bottom_screenline_num and distfile_num<tuidistfiles.size(); y++, distfile_num++){ + if (tuidistfiles[distfile_num].size>0) + percent="("+toString(tuidistfiles[distfile_num].dld_bytes*100/tuidistfiles[distfile_num].size)+"%) "; + else + percent="(n/a%)"; + + switch (tuidistfiles[distfile_num].status){ + case DNEW: + case D_NOT_PROXY_REQUESTED: + case DPROXY_REJECTED: + case DPROXY_QUEUED: + case DPROXY_DOWNLOADING: + case DPROXY_DOWNLOADED: + case DPROXY_FAILED: + color_distfile_added(window); + break; + case DWAITING: + color_distfile_waiting(window); + break; + case DDOWNLOADING: + color_distfile_downloading(window); + break; + case DDOWNLOADED: + color_distfile_downloaded(window); + break; + case DFAILED: + color_distfile_failed(window); + break; + } msg_line(y+1,field("",distfile_num+1,4)+") " - +"("+toString(tuidistfiles[distfile_num].dld_bytes*100/tuidistfiles[distfile_num].size)+"%) " + +percent +tuidistfiles[distfile_num].name + +" ["+tuidistfiles[distfile_num].statusToString()+"]" +" Segments: "+toString(tuidistfiles[distfile_num].dld_segments) +"/"+toString(tuidistfiles[distfile_num].segments_count) +" Bytes: "+toString(tuidistfiles[distfile_num].dld_bytes) +"/"+toString(tuidistfiles[distfile_num].size)); } +// color_distfiles_window(window); wrefresh(window); // mainwindow.distfiles_win.add_line(parts[0]+"("+toString(atol(parts[3].c_str())*100/)+"%)"+" "+parts[1]+"/"+parts[2]+" "+parts[3]+"/"+parts[4]); } diff --git a/tuiclient/mainwindow.cpp b/tuiclient/mainwindow.cpp index 55a16e7..1164c50 100644 --- a/tuiclient/mainwindow.cpp +++ b/tuiclient/mainwindow.cpp @@ -27,17 +27,20 @@ #include "mainwindow.h" void Tmainwindow::connected(){ - for (int line_num=0; line_num<=max_received_screenline_num; line_num++){ - screenlines[line_num]=""; - } + scroll_lines.clear(); +// for (int line_num=0; line_num<=max_received_screenline_num; line_num++){ +// screenlines[line_num]=""; +// } max_received_screenline_num=0; colors_connected(); set_status("[Connected]"); +// notfresh=true; } void Tmainwindow::disconnected(){ colors_disconnected(); set_status("[Connecting... Attempt:"+toString(attempt_num)+". Waiting for 1 sec, before next reconnect.]"); +// notfresh=true; } void Tmainwindow::msg_status(){ msg_short(0,2,"Tuiclient "+status_str); @@ -48,19 +51,28 @@ void Tmainwindow::msg_status(){ } void Tmainwindow::compose(){ - //clear(); - box(window, ACS_VLINE, ACS_HLINE); +// wclear(window); +// box(window, ACS_VLINE, ACS_HLINE); getmaxyx(window,height,width); - screenlines[27]=sms; +// resize(height,width,0,0); +// screenlines[27]=sms; bottom_screenline_num=height-2; color_status(window); + make_frame(); msg_status(); color_info(window); msg_short(height-1,2,screen_info_lines[0]); color_downloads(window); // 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]); +// for (int y=0, line_num=top_position; y<bottom_screenline_num; y++, line_num++){ +// msg_line(y+1,screenlines[line_num]); +// } + for (uint y=0, line_num=top_position; y<bottom_screenline_num; y++, line_num++){ + if (line_num<scroll_lines.size()){ + msg_line(y+1,scroll_lines[line_num]); + }else{ + msg_line(y+1,""); + } } wrefresh(window); //and show children @@ -91,8 +103,11 @@ void Tmainwindow::set_status(string str){ //show_lines(); } -void Tmainwindow::set_line(int y, string msg_text){ - screenlines[y]=msg_text; +void Tmainwindow::set_line(uint y, string msg_text){ + while (scroll_lines.size()<=y){ + scroll_lines.push_back(""); + }; + scroll_lines[y]=msg_text; notfresh=TRUE; if (max_received_screenline_num<y) max_received_screenline_num=y; } @@ -101,6 +116,7 @@ void Tmainwindow::init(){ top_position=0; max_received_screenline_num=0; window=initscr(); +// clear(); // help_win=Twindow(20,50,5,5); // box(help_window, ACS_VLINE, ACS_HLINE); // wrefresh(help_window); @@ -108,17 +124,23 @@ void Tmainwindow::init(){ //don't echo keyboard to the screen visible=TRUE; noecho(); +// nodelay(window,1); //don't wait for enter cbreak(); //enable arrow keys keypad(stdscr,TRUE); keypad(window,TRUE); - exit_flag=FALSE; +// exit_flag=FALSE; visible=TRUE; notfresh=TRUE; +// wclear(window); +// wrefresh(window); +// refresh(); help_win.init(" HELP ",14,31,5,5); log_win.init(" LOG ",12,50,5,5); distfiles_win.init(" DISTFILES ",12,50,5,5); error_log_win.init(" ERROR LOG ",12,50,5,5); - + disconnected(); + show(); +// sleep(1); } diff --git a/tuiclient/mainwindow.h b/tuiclient/mainwindow.h index 0c80c30..ca55343 100644 --- a/tuiclient/mainwindow.h +++ b/tuiclient/mainwindow.h @@ -39,16 +39,16 @@ using namespace std; const uint CONNECTION_LINES=5; const uint MAX_LINES=200; -class Tmainwindow: public Twindow{ +class Tmainwindow: public Tscroll_window{ public: Thelp_window help_win; Tscroll_window log_win; Tscroll_window error_log_win; Tdistfile_window distfiles_win; - bool exit_flag; +// bool exit_flag; bool connected_status; - string screenlines[200]; +// string screenlines[200]; string screen_info_lines[4]; ulong attempt_num; Tmainwindow(): @@ -56,7 +56,7 @@ class Tmainwindow: public Twindow{ log_win(), error_log_win(), distfiles_win(), - exit_flag(FALSE), +// exit_flag(FALSE), connected_status(FALSE), attempt_num(0) {}; @@ -66,7 +66,7 @@ class Tmainwindow: public Twindow{ void msg_status(); void compose(); void set_status(string str); - void set_line(int y, string msg_text); + void set_line(uint y, string msg_text); void init(); void connected(); void disconnected(); diff --git a/tuiclient/scrollwindow.cpp b/tuiclient/scrollwindow.cpp index cdfafad..f9cce9c 100644 --- a/tuiclient/scrollwindow.cpp +++ b/tuiclient/scrollwindow.cpp @@ -38,9 +38,9 @@ void Tscroll_window::compose(){ color_downloads(window); // screenlines[26]="Max_num:"+toString(max_received_screenline_num); top_position=scroll_lines.size()-height+2; // +2 for border lines - if (top_position<0) {top_position=0;}; +// if (top_position<0) {top_position=0;}; uint line_num=top_position; - for (int y=0; (y<bottom_screenline_num && line_num<scroll_lines.size()); y++, line_num++){ + for (uint y=0; (y<bottom_screenline_num && line_num<scroll_lines.size()); y++, line_num++){ msg_line(y+1,scroll_lines[line_num]); } wrefresh(window); diff --git a/tuiclient/settings.h b/tuiclient/settings.h index 90f60a1..3b1b938 100644 --- a/tuiclient/settings.h +++ b/tuiclient/settings.h @@ -36,6 +36,8 @@ using namespace std; class Tsettings{ private: public: + // cli arguments + string arg_wait_distfile; //ui_server string ui_ip; ulong ui_port; @@ -46,6 +48,8 @@ class Tsettings{ string debug_log_file; Tsettings(): + // cli arguments + arg_wait_distfile(""), //ui_server ui_ip("127.0.0.1"), ui_port(9999), diff --git a/tuiclient/tuiclient.cpp b/tuiclient/tuiclient.cpp index e8ac7b6..d5665d5 100644 --- a/tuiclient/tuiclient.cpp +++ b/tuiclient/tuiclient.cpp @@ -25,28 +25,8 @@ */ #include "tuiclient.h" +#include <iostream> -void quit(){ - mainwindow.exit_flag=TRUE; - try{ - close(sockfd); - } - catch(...) - { - //error while closing socket - } - try{ - close(sockfd); -// sleep(1); - nocbreak(); - endwin(); - exit(0); - } - catch(...) - { - //error while ending curses - } -} Twindow * next_window(){ cur_window_num++; if (cur_window_num>3) cur_window_num=0; @@ -75,22 +55,78 @@ Twindow * next_window(){ return &mainwindow; } +/* +void * watch_keyboard_thread_function(void *){ + Twindow * cur_window=&mainwindow.distfiles_win; + while (not exit_flag){ + int key=getch(); + if (key==ERR){ + 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 + }else{ + switch (key){ + //tab - move between windows + case (char)9:cur_window=next_window(); + //KEY_DOWN + case (char)2:cur_window->down(1);mainwindow.set_line(25,toString((int)key));break; + //KEY_RIGHT + case (char)5:cur_window->down(1);mainwindow.set_line(25,toString((int)key));break; + //KEY_UP + case (char)3:cur_window->up(1);mainwindow.set_line(25,toString((int)key));break; + //KEY_LEFT + case (char)4:cur_window->up(1);mainwindow.set_line(25,toString((int)key));break; + //KEY_PG_DOWN + case (char)82:cur_window->down(mainwindow.bottom_screenline_num);break; + //KEY_PG_UP + case (char)83:cur_window->up(mainwindow.bottom_screenline_num);break; + case 'd': + case 'D':mainwindow.distfiles_win.toggle(); + mainwindow.log_win.visible=false; + mainwindow.error_log_win.visible=false; + cur_window=&mainwindow.distfiles_win; + mainwindow.show(); + break; + case 'q': + case 'Q':quit(0,"Interrupted by user");break; + case 'h': + case 'H':mainwindow.help_win.toggle(); mainwindow.show();break; + case 'l': + case 'L':mainwindow.log_win.toggle(); mainwindow.show();break; + case 'e': + case 'E':mainwindow.error_log_win.toggle(); mainwindow.show();break; + default: mainwindow.set_line(25,toString((int)key)); + } + } + } +// pthread_exit((void*)watch_keyboard_thread_status); + exit_curses_and_show_msg(); + return (void*)0; + //watch_keyboard_thread_status; +} + +void * refresh_screen_thread_function(void *){ + return (void*)0; +} +*/ void * watch_keyboard_thread_function(void *){ Twindow * cur_window=&mainwindow.distfiles_win; - while (true){ + while (not exit_flag){ char key=getch(); switch (key){ //tab - move between windows case (char)9:cur_window=next_window(); //KEY_DOWN - case (char)2:cur_window->down(1);mainwindow.screenlines[25]=toString((int)key);break; + case (char)2:cur_window->down(1);mainwindow.set_line(25,toString((int)key));break; //KEY_RIGHT - case (char)5:cur_window->down(1);mainwindow.screenlines[25]=toString((int)key);break; + case (char)5:cur_window->down(1);mainwindow.set_line(25,toString((int)key));break; //KEY_UP - case (char)3:cur_window->up(1);mainwindow.screenlines[25]=toString((int)key);break; + case (char)3:cur_window->up(1);mainwindow.set_line(25,toString((int)key));break; //KEY_LEFT - case (char)4:cur_window->up(1);mainwindow.screenlines[25]=toString((int)key);break; + case (char)4:cur_window->up(1);mainwindow.set_line(25,toString((int)key));break; //KEY_PG_DOWN case (char)82:cur_window->down(mainwindow.bottom_screenline_num);break; //KEY_PG_UP @@ -103,27 +139,31 @@ void * watch_keyboard_thread_function(void *){ mainwindow.show(); break; case 'q': - case 'Q':quit();break; + case 'Q':quit(0,"Interrupted by user");break; case 'h': case 'H':mainwindow.help_win.toggle(); mainwindow.show();break; case 'l': case 'L':mainwindow.log_win.toggle(); mainwindow.show();break; case 'e': case 'E':mainwindow.error_log_win.toggle(); mainwindow.show();break; - default: mainwindow.screenlines[25]=toString((int)key); + default: mainwindow.set_line(25,toString((int)key)); } } - return 0; +// pthread_exit((void*)watch_keyboard_thread_status); + return (void*)watch_keyboard_thread_status; } void * refresh_screen_thread_function(void *){ - while (! mainwindow.exit_flag){ - mainwindow.refresh(); + while (! exit_flag){ + mainwindow.refresh(); + mainwindow.refresh(); +// sleep(1); 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 } + exit_curses_and_show_msg(); return 0; } @@ -138,11 +178,18 @@ void decode_connection_msg(string msg_body){ mainwindow.screen_info_lines[line_num-200]=parts.after; } } +/* void decode_downloaded_distfile_msg(string msg_body){ vector <string> parts; parts=split_to_vector(" ", msg_body); if (parts.size()>4){ +// if (settings.arg_wait_distfile!=""){ +// if (parts[0]==settings.arg_wait_distfile){ +// cant_find_distfile_exit_flag==false; +// if +// } +// } for (ulong cur_distfile=0;cur_distfile<tuidistfiles.size();cur_distfile++){ if (tuidistfiles[cur_distfile].name==parts[0]){ tuidistfiles[cur_distfile].dld_segments=atol(parts[1]); @@ -162,6 +209,33 @@ void decode_downloaded_distfile_msg(string msg_body){ mainwindow.distfiles_win.max_received_screenline_num=tuidistfiles.size(); } } +*/ + +void decode_downloaded_distfile_msg(string msg_body){ + vector <string> parts; + parts=split_to_vector("<>", msg_body); + if (parts.size()>5){ + for (ulong cur_distfile=0;cur_distfile<tuidistfiles.size();cur_distfile++){ + if (tuidistfiles[cur_distfile].name==parts[0]){ + tuidistfiles[cur_distfile].status=(Tdistfile_status)atoi(parts[1]); + tuidistfiles[cur_distfile].dld_segments=atol(parts[2]); + tuidistfiles[cur_distfile].segments_count=atol(parts[3]); + tuidistfiles[cur_distfile].dld_bytes=atol(parts[4]); + tuidistfiles[cur_distfile].size=atol(parts[5]); + return; + } + } + Ttuidistfile a_tuidistfile; + a_tuidistfile.name=parts[0]; + a_tuidistfile.status=(Tdistfile_status)atoi(parts[1]); + a_tuidistfile.dld_segments=atol(parts[2]); + a_tuidistfile.segments_count=atol(parts[3]); + a_tuidistfile.dld_bytes=atol(parts[4]); + a_tuidistfile.size=atol(parts[5]); + tuidistfiles.push_back(a_tuidistfile); + mainwindow.distfiles_win.max_received_screenline_num=tuidistfiles.size(); + } +} void decode_log_msg(string msg_body){ mainwindow.log_win.add_line(msg_body); @@ -170,39 +244,102 @@ void decode_log_msg(string msg_body){ void decode_error_log_msg(string msg_body){ mainwindow.error_log_win.add_line(msg_body); } +int parse_cli_arguments(int argc, char* argv[]){ + try{ + string option,name,value; + cout << "argc = " << argc << endl; + int posEqual; + for(int i = 0; i < argc; i++){ + cout << "argv[" << i << "] = " << argv[i] << endl; + option=argv[i]; + posEqual=option.find('='); + name = trim(option.substr(0,posEqual)); + value = trim(option.substr(posEqual+1)); + if (name=="--wait-distfile"){ + settings.arg_wait_distfile=value; + continue; + }; +// //f (name=="--pkglist-file") {settings.pkg_list_file=value; continue;}; + } + return 0; + }catch(...){ + perror("Error in segget.cpp: init_curses()"); + } + return 1; +} + +void no_curses_msg(string msg){ + cout << msg << endl; +} + +void exit_curses_and_show_msg(){ + try{ + nocbreak(); + endwin(); + try{ + close(sockfd); + }catch(...){ + no_curses_msg("error while closing socket"); + } + no_curses_msg(exit_msg); + exit(exit_code); + }catch(...){ + //error while ending curses + } +} -int main() +void quit(int exit_code_, string exit_msg_){ +// mainwindow.exit_flag=TRUE; + exit_code=exit_code_; + exit_msg=exit_msg_; + exit_flag=true; + //wait to exit + while (1){ + sleep(10); + } + // nodelay(mainwindow.window,0); +// sleep(1); // wait for thread to finish its job +// void *status; +// pthread_join(watch_keyboard_thread, &status); +// if ((int)status != watch_keyboard_thread_status) { +// printf("Secondary thread failed\n"); +// exit(1); +// } +// pthread_join(watch_keyboard_thread, 0); +} + +int main(int argc, char* argv[]) { try{ + parse_cli_arguments(argc, argv); + }catch(...){ + perror("error while parsing arguments"); + } + try{ try{ //init curses settings.init(); mainwindow.init(); // init_color(COLOR_BLUE, 0, 0, 0); - - }catch(...) - { + }catch(...){ //error while init curses } try{ - pthread_t watch_keyboard_thread; - int iret1; - iret1 = pthread_create( &watch_keyboard_thread, NULL, watch_keyboard_thread_function, (void*) NULL); - }catch(...) - { - //error while init curses watch_keyboard_thread; - } - try{ pthread_t refresh_screen_thread; int iret1; iret1 = pthread_create( &refresh_screen_thread, NULL, refresh_screen_thread_function, (void*) NULL); - }catch(...) - { + }catch(...){ //error while init refresh_screen_thread; } try{ + int iret1; + iret1 = pthread_create( &watch_keyboard_thread, NULL, watch_keyboard_thread_function, (void*) NULL); + }catch(...){ + //error while init curses watch_keyboard_thread; + } + try{ // struct timeval timeout; - while ( ! mainwindow.exit_flag ){ + while ( ! exit_flag ){ int len; struct sockaddr_in address; @@ -228,8 +365,17 @@ int main() } } - mainwindow.connected(); + if (settings.arg_wait_distfile.length()>999){ + quit(1,"Error in argument --wait-distfile="+settings.arg_wait_distfile+" : Distfile name is too long"); + }; + char send_buffer[10000]; + string send_msg="<d>"+settings.arg_wait_distfile+"<.>"; + strcpy(send_buffer,send_msg.c_str()); + if (write(sockfd, send_buffer, strlen(send_buffer))!=(int)send_msg.length()){ + perror("Error in request.cpp: request(): request msg size and sent data size are different."); + } + fd_set readfds, testfds; FD_ZERO(&readfds); @@ -273,6 +419,15 @@ int main() case 'l': decode_log_msg(msg_parts.before);break; case 'e': decode_error_log_msg(msg_parts.before);break; case 'd': decode_downloaded_distfile_msg(msg_parts.before);break; + // yes-distfile present in the queue + case 'y': break; // continue waiting for catchup info + // no distfile in the queue + case 'n': + quit(1,"Distfile: "+settings.arg_wait_distfile+" is not in the queue - quit"); + break; //shouldn't get to this point - but just in case + case 'N': + quit(0,"Distfile: "+settings.arg_wait_distfile+" is already downloaded - quit"); + break; //shouldn't get to this point - but just in case } } }; @@ -283,17 +438,12 @@ int main() }catch(...){ // error_log_no_msg("Error in segget.cpp launch_tui_theread() failed"); } + + }catch(...){ + perror("error during init and downloading process"); } - catch(...){ - //error during init and downloading process - } - try{ - nocbreak(); - endwin(); - } - catch(...) - { - //error while ending curses + while (1){ + sleep(10); } - return 0; + quit(0,""); }
\ No newline at end of file diff --git a/tuiclient/tuiclient.h b/tuiclient/tuiclient.h index cf1223c..708c843 100644 --- a/tuiclient/tuiclient.h +++ b/tuiclient/tuiclient.h @@ -57,10 +57,17 @@ using namespace std; +bool exit_flag=false; +bool thread_exited=false; +string exit_msg=""; +int exit_code=0; +int watch_keyboard_thread_status=10; +pthread_t watch_keyboard_thread; Tmainwindow mainwindow; int cur_window_num=0; int sockfd; -void quit(); +void exit_curses_and_show_msg(); +void quit(int exit_code, string error_msg); void * watch_keyboard_thread_function(void * ptr); void * refresh_screen_thread_function(void * ptr);
\ No newline at end of file diff --git a/tuiclient/tuidistfile.cpp b/tuiclient/tuidistfile.cpp index 09bd414..45d135d 100644 --- a/tuiclient/tuidistfile.cpp +++ b/tuiclient/tuidistfile.cpp @@ -27,5 +27,35 @@ #include "tuidistfile.h" +string Ttuidistfile::statusToString(){ + try{ + switch(status){ + case DNEW: return "Added"; + case D_NOT_PROXY_REQUESTED: return "Not proxy requested"; + case DPROXY_REJECTED: return "Proxy rejected"; + case DPROXY_QUEUED: return "Proxy queued"; + case DPROXY_DOWNLOADING: return "Downloading via proxy"; + case DPROXY_DOWNLOADED: return "Downloaded via proxy"; + case DPROXY_FAILED: return "Failed"; + case DWAITING: return "Waiting"; + case DDOWNLOADING: return "Downloading"; + case DDOWNLOADED: return "Downloaded"; + case DFAILED: return "Failed"; + } + }catch(...){ + error_log("Error: distfile.cpp: statusToString()"); + } + return "UNKNOWN status"; +} + +long find_distfile_by_name(string distfile_name){ + try{ + for (ulong cur_distfile=0;cur_distfile<tuidistfiles.size();cur_distfile++) + if (tuidistfiles[cur_distfile].name==distfile_name) return cur_distfile; + }catch(...){ + perror("Error in tuidistfile.cpp: find_distfile_by_name()"); + } + return -1; +} diff --git a/tuiclient/tuidistfile.h b/tuiclient/tuidistfile.h index fa857b8..f69d734 100644 --- a/tuiclient/tuidistfile.h +++ b/tuiclient/tuidistfile.h @@ -31,21 +31,38 @@ using namespace std; +enum Tdistfile_status{ + DNEW, + D_NOT_PROXY_REQUESTED, + DPROXY_REJECTED, + DPROXY_QUEUED, + DPROXY_DOWNLOADING, + DPROXY_DOWNLOADED, + DPROXY_FAILED, + DWAITING, + DDOWNLOADING, + DDOWNLOADED, + DFAILED +}; + class Ttuidistfile{ public: string name; ulong size; + Tdistfile_status status; ulong dld_bytes; ulong dld_segments; ulong segments_count; Ttuidistfile(): name(""), size(0), + status(DNEW), dld_bytes(0), dld_segments(0), segments_count(0) {}; ~Ttuidistfile(){}; + string statusToString(); }; vector <Ttuidistfile> tuidistfiles; diff --git a/tuiclient/twindow.cpp b/tuiclient/twindow.cpp index d451435..080506d 100644 --- a/tuiclient/twindow.cpp +++ b/tuiclient/twindow.cpp @@ -73,7 +73,7 @@ void Twindow::up(int inc){ } void Twindow::down(uint inc){ - int tmp_top_position=top_position+inc; + uint tmp_top_position=top_position+inc; // if we need to scroll down if (max_received_screenline_num>bottom_screenline_num){ notfresh=TRUE; diff --git a/tuiclient/twindow.h b/tuiclient/twindow.h index 89c5108..533b101 100644 --- a/tuiclient/twindow.h +++ b/tuiclient/twindow.h @@ -44,9 +44,9 @@ class Twindow{ uint x; bool notfresh; bool visible; - int top_position; - int bottom_screenline_num; - int max_received_screenline_num; + uint top_position; + uint bottom_screenline_num; + uint max_received_screenline_num; string status_str; Twindow(): |