From 67845f83986e67f204bbc51d93d6ca1a1e7796ab Mon Sep 17 00:00:00 2001 From: Kostyantyn Ovechko Date: Tue, 27 Jul 2010 02:02:00 +0300 Subject: Add log and error_log windows to tuiclient --- segget/connection.cpp | 6 ++-- segget/distfile.cpp | 3 +- segget/log.cpp | 4 +-- segget/proxyfetcher.cpp | 2 +- segget/requestserver.cpp | 2 +- segget/tui.cpp | 47 ++++++++++++++++++++-------- segget/tui.h | 17 ++++++++++- segget/ui_server.cpp | 45 +++++++++++++++++++++------ segget/ui_server.h | 17 +++++------ tuiclient/helpwindow.cpp | 13 ++++---- tuiclient/mainwindow.cpp | 21 +++++++++++-- tuiclient/mainwindow.h | 5 +++ tuiclient/scrollwindow.cpp | 54 ++++++++++++++++++++++++++++++++ tuiclient/scrollwindow.h | 49 ++++++++++++++++++++++++++++++ tuiclient/tuiclient.cpp | 76 +++++++++++++++++++++++++++++++++------------- tuiclient/tuiclient.h | 11 +++++++ tuiclient/twindow.cpp | 19 +++++++++++- tuiclient/twindow.h | 6 +++- 18 files changed, 325 insertions(+), 72 deletions(-) create mode 100644 tuiclient/scrollwindow.cpp create mode 100644 tuiclient/scrollwindow.h diff --git a/segget/connection.cpp b/segget/connection.cpp index 5dec26a..a9d438e 100644 --- a/segget/connection.cpp +++ b/segget/connection.cpp @@ -92,9 +92,9 @@ void Tconnection::stop(CURLcode connection_result){ debug("Finished connection for distfile: "+segment->parent_distfile->name+" Segment#:"+toString(segment->segment_num)+" Network#"+toString(network_num)+" Status: "+toString(connection_result)); if (connection_result){ string error_str=curl_easy_strerror(connection_result); - debug(" ERROR "+toString(connection_result)+": "+error_str); + debug(" ERROR "+toString(connection_result)+": "+error_str); error_log("Finished connection for distfile: "+segment->parent_distfile->name+" Segment#:"+toString(segment->segment_num)+" Network#"+toString(network_num)+" Status: "+toString(connection_result)); - error_log(" ERROR "+toString(connection_result)+": "+error_str); + error_log(" ERROR "+toString(connection_result)+": "+error_str); } msg_clean_connection(connection_num); @@ -154,7 +154,7 @@ void Tconnection::stop(CURLcode connection_result){ } } // error -> start downloading again - msg_status2(segment->connection_num, toString(connection_result)+"]- Failed download "+segment->file_name); +// msg_status2(segment->connection_num, toString(connection_result)+"]- Failed download "+segment->file_name); debug(toString(connection_result)+"]- Failed download "+segment->url); Pcurr_mirror->stop(time_left_from(connection_array[connection_num].start_time),0); if (segment->try_num>=settings.max_tries){ diff --git a/segget/distfile.cpp b/segget/distfile.cpp index f3825a1..ba5778d 100644 --- a/segget/distfile.cpp +++ b/segget/distfile.cpp @@ -814,7 +814,7 @@ int Tdistfile::combine_segments(){ status=DFAILED; return 12; } -/* + if (! sha512_ok(settings.distfiles_dir+"/"+name,SHA512)){ status=DFAILED; return 13; @@ -834,7 +834,6 @@ int Tdistfile::combine_segments(){ status=DFAILED; return 16; } - */ status=DDOWNLOADED; if (settings.provide_mirror_dir!="none"){ symlink_distfile_to_provide_mirror_dir(); diff --git a/segget/log.cpp b/segget/log.cpp index 7916382..6af0ffa 100644 --- a/segget/log.cpp +++ b/segget/log.cpp @@ -54,7 +54,7 @@ void log_no_msg(string log_msg_text){ void log(string log_msg_text){ log_no_msg(log_msg_text); try{ - msg(LOG_LINE_NUM,0, "LOG:"+log_msg_text); + msg_log(log_msg_text); }catch(...){ error_log("Error in tui.cpp: log()"); } @@ -111,7 +111,7 @@ void error_log_no_msg(string error_msg_text){ void error_log(string error_msg_text){ error_log_no_msg(error_msg_text); try{ - msg(ERROR_LINE_NUM,0, "ERROR:"+error_msg_text); + msg_error_log(error_msg_text); }catch(...){ error_log_no_msg("Error in tui.cpp: error_log()"); } diff --git a/segget/proxyfetcher.cpp b/segget/proxyfetcher.cpp index 0895729..6f91680 100644 --- a/segget/proxyfetcher.cpp +++ b/segget/proxyfetcher.cpp @@ -101,7 +101,7 @@ void *run_proxy_fetcher_server(void * ){ // debug("serving client - read"); // debug("serving client on fd"+toString(fd)); string recv_msg=buffer; - error_log("Received a msg from the client:"+recv_msg); +// error_log("Received a msg from the client:"+recv_msg); string send_response; // char send_buffer[10]=""; diff --git a/segget/requestserver.cpp b/segget/requestserver.cpp index 74e214b..de365d2 100644 --- a/segget/requestserver.cpp +++ b/segget/requestserver.cpp @@ -101,7 +101,7 @@ void *run_request_server(void * ){ // debug("serving client - read"); // debug("serving client on fd"+toString(fd)); string recv_msg=buffer; - error_log("Received a msg from the client:"+recv_msg); +// error_log("Received a msg from the client:"+recv_msg); // char send_buffer[10]=""; json_object* json_obj_distfile=json_tokener_parse(buffer); string distfile_name=json_object_get_string(json_object_object_get(json_obj_distfile,"name")); diff --git a/segget/tui.cpp b/segget/tui.cpp index 5f4545b..423547a 100644 --- a/segget/tui.cpp +++ b/segget/tui.cpp @@ -27,7 +27,11 @@ #include "tui.h" extern Tsettings settings; -const uint CONNECTION_LINES=5; +const uint CONNECTION_LINES=3; +string screenlines[DEBUG_LINE_NUM+1]; +vector log_lines; +uint log_lines_counter=0; +uint max_published_screenline_num; //bool msg_idle=true; void msg(uint y, uint x, string msg_text){ @@ -36,7 +40,7 @@ void msg(uint y, uint x, string msg_text){ try{ if (max_published_screenline_numLOG_LINES_MAX_NUM){ + log_lines.erase(log_lines.begin(),log_lines.begin()+log_lines.size()-LOG_LINES_MAX_NUM); + } +// msg(20,0, error_text); + }catch(...){ + error_log_no_msg("Error in tui.cpp: msg_error()"); + } +} +void msg_error_log(string error_log_text){ try{ - msg(20,0, error_text); + ui_server.send_error_log_msg_to_all_clients(error_log_text); + log_lines.push_back(error_log_text); + if (log_lines.size()>LOG_LINES_MAX_NUM){ + log_lines.erase(log_lines.begin(),log_lines.begin()+log_lines.size()-LOG_LINES_MAX_NUM); + } +// msg(20,0, error_text); }catch(...){ error_log_no_msg("Error in tui.cpp: msg_error()"); } diff --git a/segget/tui.h b/segget/tui.h index 612ea5a..079c568 100644 --- a/segget/tui.h +++ b/segget/tui.h @@ -27,6 +27,7 @@ #ifndef __TUI_H__ #define __TUI_H__ #include +#include #include "settings.h" #include "ui_server.h" #include "utils.h" @@ -34,6 +35,19 @@ using namespace std; +const uint MAX_LINES=200; +const uint TOTAL_LINE_NUM=MAX_LINES; +const uint ERROR_LINE_NUM=MAX_LINES+1; +const uint LOG_LINE_NUM=MAX_LINES+2; +const uint DEBUG_LINE_NUM=MAX_LINES+3; +const uint LOG_LINES_MAX_NUM=200; + +extern string screenlines[DEBUG_LINE_NUM+1]; +extern uint max_published_screenline_num; + +extern vector log_lines; +extern uint log_lines_counter; + void msg_total(string msg_text); void msg(uint y, uint x, string msg_text); void msg_connecting(uint connection_num, uint distfile_num, uint segment_num, string msg_text); @@ -41,6 +55,7 @@ void msg_segment_progress(uint connection_num, uint network_num, uint segment_nu void msg_status1(uint connection_num, uint segment_num, string msg_text); void msg_status2(uint connection_num, string msg_text); void msg_clean_connection(uint connection_num); -void msg_error(string error_text); +void msg_log(string log_text); +void msg_error_log(string error_log_text); void msg_total(string msg_text); #endif \ No newline at end of file diff --git a/segget/ui_server.cpp b/segget/ui_server.cpp index 8e4f2cd..dd68330 100644 --- a/segget/ui_server.cpp +++ b/segget/ui_server.cpp @@ -26,9 +26,7 @@ #include "ui_server.h" -uint max_published_screenline_num; Tui_server ui_server; -string screenlines[DEBUG_LINE_NUM+1]; void Tui_server::init(){ socklen_t server_len; @@ -64,7 +62,25 @@ void Tui_server::init(){ send_to_fd_busy=false; } //prevent simultaneous writes -ulong Tui_server::send_to_fd(uint fd, uint y, string msg){ +string Tui_server::encode_connection_msg(uint y, string msg){ +// if (send_to_fd_idle) { + string message="c"+toString(y)+""+msg+"<.>"; + return message; +} + +string Tui_server::encode_log_msg(string msg){ +// if (send_to_fd_idle) { + string message="l"+msg+"<.>"; + return message; +} + +string Tui_server::encode_error_log_msg(string msg){ +// if (send_to_fd_idle) { + string message="e"+msg+"<.>"; + return message; +} + +ulong Tui_server::send_to_fd(uint fd, string msg){ // if (send_to_fd_idle) { while (send_to_fd_busy){ sleep(1); @@ -72,9 +88,8 @@ ulong Tui_server::send_to_fd(uint fd, uint y, string msg){ send_to_fd_busy=true; if (fd !=server_sockfd){ if(FD_ISSET(fd,&ui_server.readfds)) { - string message=""+toString(y)+""+msg+"<.>"; - ulong bytes_written=write(fd, message.c_str(), message.length()); - if (bytes_written!=message.length()){ + ulong bytes_written=write(fd, msg.c_str(), msg.length()); + if (bytes_written!=msg.length()){ debug("Error: Not all data has been sent to ui_client()"); } } @@ -83,9 +98,21 @@ ulong Tui_server::send_to_fd(uint fd, uint y, string msg){ return 0; } -void Tui_server::send_all_clients(uint y, string msg){ +void Tui_server::send_connection_msg_to_all_clients(uint y, string msg){ + for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){ + send_to_fd(fd, encode_connection_msg(y, msg)); + } +} + +void Tui_server::send_log_msg_to_all_clients(string msg){ + for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){ + send_to_fd(fd, encode_log_msg(msg)); + } +} + +void Tui_server::send_error_log_msg_to_all_clients(string msg){ for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){ - send_to_fd(fd, y, msg); + send_to_fd(fd, encode_error_log_msg(msg)); } } @@ -124,7 +151,7 @@ void *run_ui_server(void * ){ // Get this info to catch up! for (uint line_num=0; line_num<=max_published_screenline_num;line_num++){ - ui_server.send_to_fd(client_sockfd, line_num, screenlines[line_num]); + ui_server.send_to_fd(client_sockfd, ui_server.encode_connection_msg(line_num, screenlines[line_num])); debug_no_msg("Sending to client line:"+toString(line_num)+" "+screenlines[line_num]); // ui_server.send(line_num,screenlines[line_num]); } diff --git a/segget/ui_server.h b/segget/ui_server.h index 6723fc4..db67e13 100644 --- a/segget/ui_server.h +++ b/segget/ui_server.h @@ -38,19 +38,13 @@ #include #include #include "settings.h" +#include "tui.h" using namespace std; #define MAX_BIND_ATTEMPTS 5 -const uint MAX_LINES=200; -const uint TOTAL_LINE_NUM=MAX_LINES; -const uint ERROR_LINE_NUM=MAX_LINES+1; -const uint LOG_LINE_NUM=MAX_LINES+2; -const uint DEBUG_LINE_NUM=MAX_LINES+3; //const uint MAX_LINES=200; -extern string screenlines[DEBUG_LINE_NUM+1]; -extern uint max_published_screenline_num; class Tui_server{ public: @@ -59,8 +53,13 @@ class Tui_server{ uint max_fd_num; fd_set readfds, testfds; void init(); - ulong send_to_fd(uint fd, uint y, string msg); - void send_all_clients(uint y, string msg); + string encode_connection_msg(uint y, string msg); + string encode_log_msg(string msg); + string encode_error_log_msg(string msg); + ulong send_to_fd(uint fd, string msg); + void send_connection_msg_to_all_clients(uint y, string msg); + void send_log_msg_to_all_clients(string msg); + void send_error_log_msg_to_all_clients(string msg); }; extern Tui_server ui_server; diff --git a/tuiclient/helpwindow.cpp b/tuiclient/helpwindow.cpp index da51d75..f61bb84 100644 --- a/tuiclient/helpwindow.cpp +++ b/tuiclient/helpwindow.cpp @@ -29,14 +29,15 @@ void Thelp_window::compose(){ // msg_text=msg_text+" "; // - box(window, ACS_VLINE, ACS_HLINE); - mvwaddstr(window,0,12," HELP "); + make_frame(); 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"); + mvwaddstr(window,5,1,"e - show error log"); + mvwaddstr(window,6,1,"d - show distfiles queue"); + mvwaddstr(window,7,1,"Up - scroll 1 line up"); + mvwaddstr(window,8,1,"Down - scroll 1 line down"); + mvwaddstr(window,9,1,"PgUp - scroll 1 page up"); + mvwaddstr(window,10,1,"PgDown - scroll 1 page down"); wrefresh(window); } \ No newline at end of file diff --git a/tuiclient/mainwindow.cpp b/tuiclient/mainwindow.cpp index e1ba179..6a27022 100644 --- a/tuiclient/mainwindow.cpp +++ b/tuiclient/mainwindow.cpp @@ -50,7 +50,7 @@ void Tmainwindow::compose(){ //clear(); box(window, ACS_VLINE, ACS_HLINE); getmaxyx(window,height,width); - bottom_screenline_num=height-6; + bottom_screenline_num=height-3; color_status(); msg_status(); color_info(); @@ -58,12 +58,24 @@ void Tmainwindow::compose(){ msg_line(y+1,screen_info_lines[status_line_num]); } color_downloads(); - screenlines[26]="Max_num:"+toString(max_received_screenline_num); +// screenlines[26]="Max_num:"+toString(max_received_screenline_num); for (int y=0, line_num=top_position; y. +* +* 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 "scrollwindow.h" + +//Tscroll_window::~Tscroll_window(){}; + +void Tscroll_window::compose(){ +// msg_text=msg_text+" "; +// + make_frame(); + getmaxyx(window,height,width); + bottom_screenline_num=height-1; + color_downloads(); +// 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;}; + uint line_num=top_position; + for (int y=0; (ySCROLL_LINES_MAX_NUM){ + scroll_lines.erase(scroll_lines.begin(),scroll_lines.begin()+scroll_lines.size()-SCROLL_LINES_MAX_NUM); + } +} \ No newline at end of file diff --git a/tuiclient/scrollwindow.h b/tuiclient/scrollwindow.h new file mode 100644 index 0000000..19b1e0a --- /dev/null +++ b/tuiclient/scrollwindow.h @@ -0,0 +1,49 @@ +/* +* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn . +* +* 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 _SCROLLWINDOW_H_ +#define _SCROLLWINDOW_H_ + +const uint SCROLL_LINES_MAX_NUM=200; + +#include "twindow.h" +#include + +using namespace std; +class Tscroll_window: public Twindow{ + public: + vector scroll_lines; + uint scroll_lines_counter; + Tscroll_window(): + scroll_lines(), + scroll_lines_counter(0) + {}; + ~Tscroll_window(){}; + void add_line(string line); + void compose(); +}; + +#endif \ No newline at end of file diff --git a/tuiclient/tuiclient.cpp b/tuiclient/tuiclient.cpp index a9ce8d2..69531ca 100644 --- a/tuiclient/tuiclient.cpp +++ b/tuiclient/tuiclient.cpp @@ -64,14 +64,18 @@ void * watch_keyboard_thread_function(void *){ 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': case 'U':mainwindow.up(1);break; - case 'd':mainwindow.down(1);break; + case 'd': case 'D':mainwindow.down(1);break; - case 'q':quit();break; + case 'q': case 'Q':quit();break; - case 'h':mainwindow.help_win.toggle(); mainwindow.show();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: screenlines[25]=toString((int)key); } } @@ -89,6 +93,35 @@ void * refresh_screen_thread_function(void *){ return 0; } + +Tparts split(string splitter, string str){ + Tparts result; + int splitter_pos=str.find(splitter); + result.before=str.substr(0,splitter_pos); + result.after=str.substr(splitter_pos+splitter.length()); + return result; +} + +void decode_connection_msg(string msg_body){ + Tparts parts=split("",msg_body); + int line_num=atoi(parts.before.c_str()); + if (line_num<200){ + mainwindow.set_line(line_num, parts.after); +// set_line(line_num, "||"+toString(line_num)+"||("+first_part.substr(0,first_part.find("")+3)+")"+msg_text); +// set_line(line_num, "||"+toString(line_num)+"||("+original_msg); + }else{ + mainwindow.screen_info_lines[line_num-200]=parts.after; + } +} + +void decode_log_msg(string msg_body){ + mainwindow.log_win.add_line(msg_body); +} + +void decode_error_log_msg(string msg_body){ + mainwindow.error_log_win.add_line(msg_body); +} + int main() { try{ @@ -124,7 +157,7 @@ int main() int len; struct sockaddr_in address; - string recv_msg, first_part, msg_text; + string rest_of_the_msg, first_part, msg_text; //Create a socket for the client: int result=-1; @@ -134,8 +167,8 @@ int main() //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); + address.sin_addr.s_addr = inet_addr(settings.ui_ip.c_str()); + address.sin_port = htons(settings.ui_port); len = sizeof(address); //Connect your socket to the server’s socket: result = connect(sockfd, (struct sockaddr *)&address, len); @@ -175,20 +208,21 @@ int main() error_log("Error in tuiclient.cpp : main() read bytes count does NOT match declared count."); }; //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("")+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("")).c_str()); - msg_text=first_part.substr(first_part.find("")+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("")+3)+")"+msg_text); -// set_line(line_num, "||"+toString(line_num)+"||("+original_msg); - }else{ - mainwindow.screen_info_lines[line_num-200]=msg_text; + rest_of_the_msg=rest_of_the_msg+recv_buffer; + Tparts msg_parts; + while (rest_of_the_msg.find("<.>")!=rest_of_the_msg.npos){ + msg_parts=split("",rest_of_the_msg); + msg_parts=split("",msg_parts.after); + char msg_type=msg_parts.before[0]; + debug("msg_type="+msg_type); + msg_parts=split("<.>",msg_parts.after); + string msg_body=msg_parts.before; + debug("msg_body="+msg_body); + rest_of_the_msg=msg_parts.after; + switch (msg_type){ + case 'c': decode_connection_msg(msg_parts.before); break; + case 'l': decode_log_msg(msg_parts.before);break; + case 'e': decode_error_log_msg(msg_parts.before);break; } } }; diff --git a/tuiclient/tuiclient.h b/tuiclient/tuiclient.h index 6cb5fd9..ad7cdac 100644 --- a/tuiclient/tuiclient.h +++ b/tuiclient/tuiclient.h @@ -40,6 +40,7 @@ #include "twindow.cpp" #include "mainwindow.cpp" #include "helpwindow.cpp" +#include "scrollwindow.cpp" #include "colors.cpp" #include "config.cpp" #include "log.cpp" @@ -54,6 +55,16 @@ using namespace std; +class Tparts{ + public: + string before, after; + Tparts(): + before(""), + after("") + {}; +}; + + Tmainwindow mainwindow; int sockfd; diff --git a/tuiclient/twindow.cpp b/tuiclient/twindow.cpp index 233c499..e4ee2f7 100644 --- a/tuiclient/twindow.cpp +++ b/tuiclient/twindow.cpp @@ -26,7 +26,8 @@ #include "twindow.h" -void Twindow::init(int height_, int width_, int y_, int x_){ +void Twindow::init(string caption_, int height_, int width_, int y_, int x_){ + caption=caption_; height=height_; width=width_; y=y_; @@ -87,6 +88,22 @@ void Twindow::center(uint max_y, uint max_x){ mvwin(window,y,x); } +void Twindow::resize(uint new_height, uint new_width, uint new_y, uint new_x){ + y=new_y; + x=new_x; + height=new_height; + width=new_width; + mvwin(window,y,x); + wresize(window,height,width); +} + +void Twindow::make_frame(){ + wclear(window); + box(window, ACS_VLINE, ACS_HLINE); + mvwaddstr(window,0,(width-caption.length())/2,caption.c_str()); +} + + void Twindow::refresh(){ if (notfresh){ show(); diff --git a/tuiclient/twindow.h b/tuiclient/twindow.h index 32ab4b4..aa84214 100644 --- a/tuiclient/twindow.h +++ b/tuiclient/twindow.h @@ -36,6 +36,7 @@ using namespace std; class Twindow{ public: WINDOW * window; + string caption; uint width; uint height; uint y; @@ -49,6 +50,7 @@ class Twindow{ Twindow(): window(0), + caption(""), width(10), height(10), y(1), @@ -63,13 +65,15 @@ class Twindow{ virtual ~Twindow(){}; Twindow(const Twindow &L); // copy constructor Twindow & operator=(const Twindow &L); - void init(int height_, int width_, int y_, int x_); + void init(string caption_, 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 resize(uint new_height, uint new_width, uint new_y, uint new_x); + void make_frame(); void refresh(); void show(); virtual void compose(){}; -- cgit v1.2.3-65-gdbad