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
119
120
121
122
123
124
125
126
127
|
#include <stdlib.h>
#include <stdio.h>
#include "messageWind.h"
extern contact* contactList;
extern size_t nbContacts;
conversation* currentConv;
int x_WMessage = 1,y_WMessage = 1;
int w_WMessage,h_WMessage;
int contactListSelection;
int firstSMSIndex;
int canAugment = 1;
int nbLineSMS( sms* S );
void toTheEnd(void) {
if( !currentConv )
return;
int i = currentConv->nbSMS -1, size = h_WMessage ;
char lin[200] = "";
for(; i > 0 && size > 0 ; i--) {
size -= nbLineSMS(¤tConv->listSMS[i]) + 2;
}
if( size > 0 )
firstSMSIndex = 0;
else
firstSMSIndex = i+1 == currentConv->nbSMS ? i : i+1;
// Seriously ... It can happen only if a SMS is greater than
// the windows size ... We simply show the begin of the SMS without
// the end. (Yeah, fuck this ...)
}
int nbLineSMS( sms* S ) {
int w_WMessageSMS = w_WMessage-COLS/5;
int x = 0,y = 0, iS=0;
while( S->text[iS] ) {
x = 0;
while( x < w_WMessageSMS-1 && S->text[iS]) {
if( S->text[iS] == '\n' ) {
iS++;
break;
}
x++,iS++;
}
y++;
}
return y;
}
int show1SMS(sms* S, int y_base, int* hasFinish) {
int w_WMessageSMS = w_WMessage-COLS/5;
int x = 0,y = 0, iS=0;
int x_base = x_WMessage + (S->in_out == SMS_IN ? 0 : COLS/5) + 1;
char line[w_WMessageSMS];
memset(line, 0, w_WMessageSMS);
*hasFinish = 1;
attrset( COLOR_PAIR( (rand()%8) + 1) | A_BOLD);
while( S->text[iS] ) {
x = 0;
while( x < w_WMessageSMS-1 && S->text[iS]) {
if( S->text[iS] == '\n' ) {
iS++;
break;
}
line[x++] = S->text[iS++];
}
line[x] = 0;
if( y+1+y_base >= y_WMessage + h_WMessage -1 ) {
*hasFinish = 0;
break;
}
y++;
move(y+y_base, x_base);
printw("%s", line);
}
move(y+y_base+1, x_base);
attrset( COLOR_PAIR( 0 ) | A_NORMAL);
printw("\t\tOn %s", ctime(&S->outDate));
return y+1;
}
void clearWind(void) {
for(int i = 0; i < h_WMessage ; i++) {
move(y_WMessage+i,x_WMessage);
printw("%*s", w_WMessage, " ");
}
}
void showMessageWind(void) {
if( !currentConv )
return;
int y = 0;
int smsIndex = firstSMSIndex;
int hasFinish = 0;
while( y < h_WMessage && smsIndex < currentConv->nbSMS) {
// mvprintc(50, 50, "Hello", 30);
if( currentConv->listSMS[smsIndex].in_out == SMS_IN )
move(y+y_WMessage,x_WMessage);
else
move(y+y_WMessage,x_WMessage+COLS/5);
int ty = show1SMS(currentConv->listSMS + smsIndex, y, &hasFinish);
//mvprintc(x_WMessage, y + y_WMessage, currentConv->listSMS[0].text, w_WMessage);
y+=ty+1;
smsIndex++;
}
if( hasFinish && !(smsIndex < currentConv->nbSMS) )
canAugment = 0;
}
|