summaryrefslogtreecommitdiff
blob: 6a270228c4abcd7e865d80ac616074832f3eec52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* 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::connected(){
	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]");
}

void Tmainwindow::disconnected(){
	colors_disconnected();
	set_status("[Connecting... Attempt:"+toString(attempt_num)+". Waiting for 1 sec, before next reconnect.]");
}
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-3;
	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
	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();
}

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(" HELP ",14,31,5,5);
	log_win.init(" LOG ",12,50,5,5);
	error_log_win.init(" ERROR LOG ",12,50,5,5);

}