comparison mcabber/src/screen.c @ 1598:a087125d8fc8

Replace libjabber with loudmouth
author franky
date Sun, 11 Oct 2009 15:38:32 +0200
parents 8d1bcc83ae32
children dcd5d4c75199
comparison
equal deleted inserted replaced
1597:4f59a414217e 1598:a087125d8fc8
56 #include "compl.h" 56 #include "compl.h"
57 #include "roster.h" 57 #include "roster.h"
58 #include "histolog.h" 58 #include "histolog.h"
59 #include "settings.h" 59 #include "settings.h"
60 #include "utils.h" 60 #include "utils.h"
61 #include "xmpp.h"
61 62
62 #define get_color(col) (COLOR_PAIR(col)|COLOR_ATTRIB[col]) 63 #define get_color(col) (COLOR_PAIR(col)|COLOR_ATTRIB[col])
63 #define compose_color(col) (COLOR_PAIR(col->color_pair)|col->color_attrib) 64 #define compose_color(col) (COLOR_PAIR(col->color_pair)|col->color_attrib)
64 65
65 #define DEFAULT_LOG_WIN_HEIGHT (5+2) 66 #define DEFAULT_LOG_WIN_HEIGHT (5+2)
136 static char cmdhisto_backup[INPUTLINE_LENGTH+1]; 137 static char cmdhisto_backup[INPUTLINE_LENGTH+1];
137 138
138 static int chatstate; /* (0=active, 1=composing, 2=paused) */ 139 static int chatstate; /* (0=active, 1=composing, 2=paused) */
139 static bool lock_chatstate; 140 static bool lock_chatstate;
140 static time_t chatstate_timestamp; 141 static time_t chatstate_timestamp;
142 static guint chatstate_timeout_id = 0;
141 int chatstates_disabled; 143 int chatstates_disabled;
142 144
143 #define MAX_KEYSEQ_LENGTH 8 145 #define MAX_KEYSEQ_LENGTH 8
144 146
145 typedef struct { 147 typedef struct {
157 159
158 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp, 160 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp,
159 unsigned int prefix_flags, int force_show, 161 unsigned int prefix_flags, int force_show,
160 unsigned mucnicklen); 162 unsigned mucnicklen);
161 163
162 inline void scr_WriteMessage(const char *bjid, const char *text, 164 void scr_WriteMessage(const char *bjid, const char *text,
163 time_t timestamp, guint prefix_flags, 165 time_t timestamp, guint prefix_flags,
164 unsigned mucnicklen); 166 unsigned mucnicklen, gpointer xep184);
165 inline void scr_UpdateBuddyWindow(void); 167 inline void scr_UpdateBuddyWindow(void);
166 inline void scr_set_chatmode(int enable); 168 inline void scr_set_chatmode(int enable);
167 169
168 #define SPELLBADCHAR 5 170 #define SPELLBADCHAR 5
169 171
182 int color_attrib; 184 int color_attrib;
183 } ccolor; 185 } ccolor;
184 186
185 typedef struct { 187 typedef struct {
186 char *status, *wildcard; 188 char *status, *wildcard;
187 ccolor * color; 189 ccolor *color;
188 GPatternSpec *compiled; 190 GPatternSpec *compiled;
189 } rostercolor; 191 } rostercolor;
190 192
191 static GSList *rostercolrules = NULL; 193 static GSList *rostercolrules = NULL;
192 194
193 static GHashTable *muccolors = NULL, *nickcolors = NULL; 195 static GHashTable *muccolors = NULL, *nickcolors = NULL;
194 196
195 typedef struct { 197 typedef struct {
196 bool manual; // Manually set? 198 bool manual; // Manually set?
197 ccolor * color; 199 ccolor *color;
198 } nickcolor; 200 } nickcolor;
199 201
200 static int nickcolcount = 0; 202 static int nickcolcount = 0;
201 static ccolor ** nickcols = NULL; 203 static ccolor ** nickcols = NULL;
202 static muccoltype glob_muccol = MC_OFF; 204 static muccoltype glob_muccol = MC_OFF;
233 235
234 scr_LogPrint(LPRINT_LOGNORM, "ERROR: Wrong color: %s", name); 236 scr_LogPrint(LPRINT_LOGNORM, "ERROR: Wrong color: %s", name);
235 return -1; 237 return -1;
236 } 238 }
237 239
238 static ccolor * get_user_color(const char *color) 240 static ccolor *get_user_color(const char *color)
239 { 241 {
240 bool isbright = FALSE; 242 bool isbright = FALSE;
241 int cl; 243 int cl;
242 ccolor * ccol; 244 ccolor *ccol;
243 if (!strncmp(color, "bright", 6)) { 245 if (!strncmp(color, "bright", 6)) {
244 isbright = TRUE; 246 isbright = TRUE;
245 color += 6; 247 color += 6;
246 } 248 }
247 cl = FindColor(color); 249 cl = FindColor(color);
315 } 317 }
316 g_free(snick);//They are not saved in the hash 318 g_free(snick);//They are not saved in the hash
317 g_free(mnick); 319 g_free(mnick);
318 need_update = TRUE; 320 need_update = TRUE;
319 } else { 321 } else {
320 ccolor * cl = get_user_color(color); 322 ccolor *cl = get_user_color(color);
321 if (!cl) { 323 if (!cl) {
322 scr_LogPrint(LPRINT_NORMAL, "No such color name"); 324 scr_LogPrint(LPRINT_NORMAL, "No such color name");
323 g_free(snick); 325 g_free(snick);
324 g_free(mnick); 326 g_free(mnick);
325 } else { 327 } else {
387 } else { 389 } else {
388 scr_LogPrint(LPRINT_NORMAL, "No such color rule, nothing removed"); 390 scr_LogPrint(LPRINT_NORMAL, "No such color rule, nothing removed");
389 return FALSE; 391 return FALSE;
390 } 392 }
391 } else { 393 } else {
392 ccolor * cl = get_user_color(color); 394 ccolor *cl = get_user_color(color);
393 if (!cl) { 395 if (!cl) {
394 scr_LogPrint(LPRINT_NORMAL, "No such color name"); 396 scr_LogPrint(LPRINT_NORMAL, "No such color name");
395 return FALSE; 397 return FALSE;
396 } 398 }
397 if (found) { 399 if (found) {
518 while (ncolors < ncolor_end && *ncolors) { 520 while (ncolors < ncolor_end && *ncolors) {
519 if ((*ncolors == ' ') || (*ncolors == '\t')) { 521 if ((*ncolors == ' ') || (*ncolors == '\t')) {
520 ncolors++; 522 ncolors++;
521 } else { 523 } else {
522 char *end = ncolors; 524 char *end = ncolors;
523 ccolor * cl; 525 ccolor *cl;
524 while (*end && (*end != ' ') && (*end != '\t')) 526 while (*end && (*end != ' ') && (*end != '\t'))
525 end++; 527 end++;
526 *end = '\0'; 528 *end = '\0';
527 cl = get_user_color(ncolors); 529 cl = get_user_color(ncolors);
528 if (!cl) { 530 if (!cl) {
1379 1381
1380 // scr_UpdateMainStatus() 1382 // scr_UpdateMainStatus()
1381 // Redraw the main (bottom) status line. 1383 // Redraw the main (bottom) status line.
1382 void scr_UpdateMainStatus(int forceupdate) 1384 void scr_UpdateMainStatus(int forceupdate)
1383 { 1385 {
1384 char *sm = from_utf8(jb_getstatusmsg()); 1386 char *sm = from_utf8(xmpp_getstatusmsg());
1385 const char *info = settings_opt_get("info"); 1387 const char *info = settings_opt_get("info");
1386 1388
1387 werase(mainstatusWnd); 1389 werase(mainstatusWnd);
1388 if (info) { 1390 if (info) {
1389 char *info_locale = from_utf8(info); 1391 char *info_locale = from_utf8(info);
1390 mvwprintw(mainstatusWnd, 0, 0, "%c[%c] %s: %s", 1392 mvwprintw(mainstatusWnd, 0, 0, "%c[%c] %s: %s",
1391 (unread_msg(NULL) ? '#' : ' '), 1393 (unread_msg(NULL) ? '#' : ' '),
1392 imstatus2char[jb_getstatus()], 1394 imstatus2char[xmpp_getstatus()],
1393 info_locale, (sm ? sm : "")); 1395 info_locale, (sm ? sm : ""));
1394 g_free(info_locale); 1396 g_free(info_locale);
1395 } else 1397 } else
1396 mvwprintw(mainstatusWnd, 0, 0, "%c[%c] %s", 1398 mvwprintw(mainstatusWnd, 0, 0, "%c[%c] %s",
1397 (unread_msg(NULL) ? '#' : ' '), 1399 (unread_msg(NULL) ? '#' : ' '),
1398 imstatus2char[jb_getstatus()], (sm ? sm : "")); 1400 imstatus2char[xmpp_getstatus()], (sm ? sm : ""));
1399 if (forceupdate) { 1401 if (forceupdate) {
1400 top_panel(inputPanel); 1402 top_panel(inputPanel);
1401 update_panels(); 1403 update_panels();
1402 } 1404 }
1403 g_free(sm); 1405 g_free(sm);
1728 if (ismuc) { 1730 if (ismuc) {
1729 if (buddy_getinsideroom(BUDDATA(current_buddy))) 1731 if (buddy_getinsideroom(BUDDATA(current_buddy)))
1730 status = 'C'; 1732 status = 'C';
1731 else 1733 else
1732 status = 'x'; 1734 status = 'x';
1733 } else if (jb_getstatus() != offline) { 1735 } else if (xmpp_getstatus() != offline) {
1734 enum imstatus budstate; 1736 enum imstatus budstate;
1735 budstate = buddy_getstatus(BUDDATA(current_buddy), NULL); 1737 budstate = buddy_getstatus(BUDDATA(current_buddy), NULL);
1736 if (budstate < imstatus_size) 1738 if (budstate < imstatus_size)
1737 status = imstatus2char[budstate]; 1739 status = imstatus2char[budstate];
1738 } 1740 }
1811 GList *buddy; 1813 GList *buddy;
1812 int i, n; 1814 int i, n;
1813 int rOffset; 1815 int rOffset;
1814 int cursor_backup; 1816 int cursor_backup;
1815 char status, pending; 1817 char status, pending;
1816 enum imstatus currentstatus = jb_getstatus(); 1818 enum imstatus currentstatus = xmpp_getstatus();
1817 int x_pos; 1819 int x_pos;
1818 1820
1819 // We can reset update_roster 1821 // We can reset update_roster
1820 update_roster = FALSE; 1822 update_roster = FALSE;
1821 1823
1962 g_utf8_strncpy(name, buddy_getname(BUDDATA(buddy)), Roster_Width-7); 1964 g_utf8_strncpy(name, buddy_getname(BUDDATA(buddy)), Roster_Width-7);
1963 else 1965 else
1964 name[0] = 0; 1966 name[0] = 0;
1965 1967
1966 if (isgrp) { 1968 if (isgrp) {
1967 if (ishid){ 1969 if (ishid) {
1968 int group_count = 0; 1970 int group_count = 0;
1969 foreach_group_member(BUDDATA(buddy), increment_if_buddy_not_filtered, 1971 foreach_group_member(BUDDATA(buddy), increment_if_buddy_not_filtered,
1970 &group_count); 1972 &group_count);
1971 snprintf(rline, 4*Roster_Width, " %c+++ %s (%i)", pending, name, 1973 snprintf(rline, 4*Roster_Width, " %c+++ %s (%i)", pending, name,
1972 group_count); 1974 group_count);
2100 static char *oldmsg; 2102 static char *oldmsg;
2101 Autoaway = setaway; 2103 Autoaway = setaway;
2102 2104
2103 if (setaway) { 2105 if (setaway) {
2104 const char *msg, *prevmsg; 2106 const char *msg, *prevmsg;
2105 oldstatus = jb_getstatus(); 2107 oldstatus = xmpp_getstatus();
2106 if (oldmsg) { 2108 if (oldmsg) {
2107 g_free(oldmsg); 2109 g_free(oldmsg);
2108 oldmsg = NULL; 2110 oldmsg = NULL;
2109 } 2111 }
2110 prevmsg = jb_getstatusmsg(); 2112 prevmsg = xmpp_getstatusmsg();
2111 msg = settings_opt_get("message_autoaway"); 2113 msg = settings_opt_get("message_autoaway");
2112 if (!msg) 2114 if (!msg)
2113 msg = prevmsg; 2115 msg = prevmsg;
2114 if (prevmsg) 2116 if (prevmsg)
2115 oldmsg = g_strdup(prevmsg); 2117 oldmsg = g_strdup(prevmsg);
2116 jb_setstatus(away, NULL, msg, FALSE); 2118 xmpp_setstatus(away, NULL, msg, FALSE);
2117 } else { 2119 } else {
2118 // Back 2120 // Back
2119 jb_setstatus(oldstatus, NULL, (oldmsg ? oldmsg : ""), FALSE); 2121 xmpp_setstatus(oldstatus, NULL, (oldmsg ? oldmsg : ""), FALSE);
2120 if (oldmsg) { 2122 if (oldmsg) {
2121 g_free(oldmsg); 2123 g_free(oldmsg);
2122 oldmsg = NULL; 2124 oldmsg = NULL;
2123 } 2125 }
2124 } 2126 }
2125 } 2127 }
2126 2128
2127 long int scr_GetAutoAwayTimeout(time_t now)
2128 {
2129 enum imstatus cur_st;
2130 unsigned int autoaway_timeout = settings_opt_get_int("autoaway");
2131
2132 if (Autoaway || !autoaway_timeout)
2133 return 86400;
2134
2135 cur_st = jb_getstatus();
2136 // Auto-away is disabled for the following states
2137 if ((cur_st != available) && (cur_st != freeforchat))
2138 return 86400;
2139
2140 if (now >= LastActivity + (time_t)autoaway_timeout)
2141 return 0;
2142 else
2143 return LastActivity + (time_t)autoaway_timeout - now;
2144 }
2145
2146 // set_chatstate(state) 2129 // set_chatstate(state)
2147 // Set the current chat state (0=active, 1=composing, 2=paused) 2130 // Set the current chat state (0=active, 1=composing, 2=paused)
2148 // If the chat state has changed, call jb_send_chatstate() 2131 // If the chat state has changed, call xmpp_send_chatstate()
2149 static inline void set_chatstate(int state) 2132 static inline void set_chatstate(int state)
2150 { 2133 {
2151 #if defined JEP0022 || defined JEP0085 2134 #if defined JEP0022 || defined JEP0085
2152 if (chatstates_disabled) 2135 if (chatstates_disabled)
2153 return; 2136 return;
2156 if (state != chatstate) { 2139 if (state != chatstate) {
2157 chatstate = state; 2140 chatstate = state;
2158 if (current_buddy && 2141 if (current_buddy &&
2159 buddy_gettype(BUDDATA(current_buddy)) == ROSTER_TYPE_USER) { 2142 buddy_gettype(BUDDATA(current_buddy)) == ROSTER_TYPE_USER) {
2160 guint jep_state; 2143 guint jep_state;
2161 if (chatstate == 1) 2144 if (chatstate == 1) {
2145 if (chatstate_timeout_id == 0)
2146 chatstate_timeout_id = g_timeout_add_seconds(1,
2147 scr_ChatStatesTimeout,
2148 NULL);
2162 jep_state = ROSTER_EVENT_COMPOSING; 2149 jep_state = ROSTER_EVENT_COMPOSING;
2150 }
2163 else if (chatstate == 2) 2151 else if (chatstate == 2)
2164 jep_state = ROSTER_EVENT_PAUSED; 2152 jep_state = ROSTER_EVENT_PAUSED;
2165 else 2153 else
2166 jep_state = ROSTER_EVENT_ACTIVE; 2154 jep_state = ROSTER_EVENT_ACTIVE;
2167 jb_send_chatstate(BUDDATA(current_buddy), jep_state); 2155 xmpp_send_chatstate(BUDDATA(current_buddy), jep_state);
2168 } 2156 }
2169 if (!chatstate) 2157 if (!chatstate)
2170 chatstate_timestamp = 0; 2158 chatstate_timestamp = 0;
2171 } 2159 }
2172 #endif 2160 #endif
2173 } 2161 }
2174 2162
2175 #if defined JEP0022 || defined JEP0085 2163 #if defined JEP0022 || defined JEP0085
2176 long int scr_GetChatStatesTimeout(time_t now) 2164 gboolean scr_ChatStatesTimeout(void)
2177 { 2165 {
2166 time_t now;
2167 time(&now);
2178 // Check if we're currently composing... 2168 // Check if we're currently composing...
2179 if (chatstate != 1 || !chatstate_timestamp) 2169 if (chatstate != 1 || !chatstate_timestamp) {
2180 return 86400; 2170 chatstate_timeout_id = 0;
2171 return FALSE;
2172 }
2181 2173
2182 // If the timeout is reached, let's change the state right now. 2174 // If the timeout is reached, let's change the state right now.
2183 if (now >= chatstate_timestamp + COMPOSING_TIMEOUT) { 2175 if (now >= chatstate_timestamp + COMPOSING_TIMEOUT) {
2184 chatstate_timestamp = now; 2176 chatstate_timestamp = now;
2185 set_chatstate(2); 2177 set_chatstate(2);
2186 return 86400; 2178 chatstate_timeout_id = 0;
2187 } 2179 return FALSE;
2188 2180 }
2189 return chatstate_timestamp + COMPOSING_TIMEOUT - now; 2181 return TRUE;
2190 } 2182 }
2191 #endif 2183 #endif
2192 2184
2193 // Check if we should enter/leave automatic away status 2185 // Check if we should enter/leave automatic away status
2194 void scr_CheckAutoAway(int activity) 2186 void scr_CheckAutoAway(int activity)
2198 2190
2199 if (Autoaway && activity) set_autoaway(FALSE); 2191 if (Autoaway && activity) set_autoaway(FALSE);
2200 if (!autoaway_timeout) return; 2192 if (!autoaway_timeout) return;
2201 if (!LastActivity || activity) time(&LastActivity); 2193 if (!LastActivity || activity) time(&LastActivity);
2202 2194
2203 cur_st = jb_getstatus(); 2195 cur_st = xmpp_getstatus();
2204 // Auto-away is disabled for the following states 2196 // Auto-away is disabled for the following states
2205 if ((cur_st != available) && (cur_st != freeforchat)) 2197 if ((cur_st != available) && (cur_st != freeforchat))
2206 return; 2198 return;
2207 2199
2208 if (!activity) { 2200 if (!activity) {