diff options
author | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-07-27 02:02:00 +0300 |
---|---|---|
committer | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-07-27 02:02:00 +0300 |
commit | 67845f83986e67f204bbc51d93d6ca1a1e7796ab (patch) | |
tree | 8d82d6ce4b978b577396f9e3d17a5a9fc609d30e /tuiclient | |
parent | Add command line option --pkglist-file to request application (diff) | |
download | idfetch-67845f83986e67f204bbc51d93d6ca1a1e7796ab.tar.gz idfetch-67845f83986e67f204bbc51d93d6ca1a1e7796ab.tar.bz2 idfetch-67845f83986e67f204bbc51d93d6ca1a1e7796ab.zip |
Add log and error_log windows to tuiclient
Diffstat (limited to 'tuiclient')
-rw-r--r-- | tuiclient/helpwindow.cpp | 13 | ||||
-rw-r--r-- | tuiclient/mainwindow.cpp | 21 | ||||
-rw-r--r-- | tuiclient/mainwindow.h | 5 | ||||
-rw-r--r-- | tuiclient/scrollwindow.cpp | 54 | ||||
-rw-r--r-- | tuiclient/scrollwindow.h | 49 | ||||
-rw-r--r-- | tuiclient/tuiclient.cpp | 76 | ||||
-rw-r--r-- | tuiclient/tuiclient.h | 11 | ||||
-rw-r--r-- | tuiclient/twindow.cpp | 19 | ||||
-rw-r--r-- | tuiclient/twindow.h | 6 |
9 files changed, 222 insertions, 32 deletions
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<bottom_screenline_num; y++, line_num++){ msg_line(y+1,screenlines[line_num]); } wrefresh(window); //and show children + if (log_win.visible && error_log_win.visible){ + int modd = (height-3)%4; + log_win.resize((height-3)/4+modd, width, 1+(height-3)/4*2, 0); + error_log_win.resize((height-3)/4, width, 1+(height-3)/4*3+modd, 0); + }else{ + int modd = (height-3)%2; + log_win.resize((height-3)/2+modd, width, 1+(height-3)/2, 0); + error_log_win.resize((height-3)/2+modd, width, 1+(height-3)/2, 0); + } + log_win.show(); + error_log_win.show(); + help_win.center(height,width); help_win.show(); } @@ -99,5 +111,8 @@ void Tmainwindow::init(){ exit_flag=FALSE; visible=TRUE; notfresh=TRUE; - help_win.init(12,30,5,5); + help_win.init(" HELP ",14,31,5,5); + log_win.init(" LOG ",12,50,5,5); + error_log_win.init(" ERROR LOG ",12,50,5,5); + } diff --git a/tuiclient/mainwindow.h b/tuiclient/mainwindow.h index 5a81e2f..cff1c75 100644 --- a/tuiclient/mainwindow.h +++ b/tuiclient/mainwindow.h @@ -34,6 +34,7 @@ using namespace std; #include "twindow.h" #include "helpwindow.h" +#include "scrollwindow.h" const uint CONNECTION_LINES=5; const uint MAX_LINES=200; @@ -42,6 +43,8 @@ class Tmainwindow: public Twindow{ public: Thelp_window help_win; + Tscroll_window log_win; + Tscroll_window error_log_win; bool exit_flag; bool connected_status; string screenlines[200]; @@ -49,6 +52,8 @@ class Tmainwindow: public Twindow{ ulong attempt_num; Tmainwindow(): help_win(), + log_win(), + error_log_win(), exit_flag(FALSE), connected_status(FALSE), attempt_num(0) diff --git a/tuiclient/scrollwindow.cpp b/tuiclient/scrollwindow.cpp new file mode 100644 index 0000000..6e7354c --- /dev/null +++ b/tuiclient/scrollwindow.cpp @@ -0,0 +1,54 @@ +/* +* 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 "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; (y<bottom_screenline_num && line_num<scroll_lines.size()); y++, line_num++){ + msg_line(y+1,scroll_lines[line_num]); + } + wrefresh(window); +} + + +void Tscroll_window::add_line(string line){ + scroll_lines.push_back(line); + if (scroll_lines.size()>SCROLL_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 <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 _SCROLLWINDOW_H_ +#define _SCROLLWINDOW_H_ + +const uint SCROLL_LINES_MAX_NUM=200; + +#include "twindow.h" +#include <vector> + +using namespace std; +class Tscroll_window: public Twindow{ + public: + vector<string> 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("<y>",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("<s>")+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("<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; + 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("<m>",rest_of_the_msg); + msg_parts=split("<t>",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(){}; |