Mercurial > hg
comparison mcabber/src/screen.c @ 991:ef10906691bb
Chatstates: add composing timeout
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Wed, 01 Nov 2006 11:56:58 +0100 |
parents | 35e7913affb7 |
children | b37348c2aa79 |
comparison
equal
deleted
inserted
replaced
990:35e7913affb7 | 991:ef10906691bb |
---|---|
93 static int completion_started; | 93 static int completion_started; |
94 static GList *cmdhisto; | 94 static GList *cmdhisto; |
95 static GList *cmdhisto_cur; | 95 static GList *cmdhisto_cur; |
96 static char cmdhisto_backup[INPUTLINE_LENGTH+1]; | 96 static char cmdhisto_backup[INPUTLINE_LENGTH+1]; |
97 | 97 |
98 static int chatstate; | 98 static int chatstate; /* (0=active, 1=composing, 2=paused) */ |
99 static bool lock_chatstate; | 99 static bool lock_chatstate; |
100 static time_t chatstate_timestamp; | |
100 | 101 |
101 #define MAX_KEYSEQ_LENGTH 8 | 102 #define MAX_KEYSEQ_LENGTH 8 |
102 | 103 |
103 typedef struct { | 104 typedef struct { |
104 char *seqstr; | 105 char *seqstr; |
1367 oldmsg = NULL; | 1368 oldmsg = NULL; |
1368 } | 1369 } |
1369 } | 1370 } |
1370 } | 1371 } |
1371 | 1372 |
1372 unsigned int scr_GetAutoAwayTimeout(time_t now) | 1373 long int scr_GetAutoAwayTimeout(time_t now) |
1373 { | 1374 { |
1374 enum imstatus cur_st; | 1375 enum imstatus cur_st; |
1375 unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); | 1376 unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); |
1376 | 1377 |
1377 if (Autoaway || !autoaway_timeout) | 1378 if (Autoaway || !autoaway_timeout) |
1386 return 0; | 1387 return 0; |
1387 else | 1388 else |
1388 return LastActivity + (time_t)autoaway_timeout - now; | 1389 return LastActivity + (time_t)autoaway_timeout - now; |
1389 } | 1390 } |
1390 | 1391 |
1391 // Check if we should enter/leave automatic away status | |
1392 void scr_CheckAutoAway(int activity) | |
1393 { | |
1394 enum imstatus cur_st; | |
1395 unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); | |
1396 | |
1397 if (Autoaway && activity) set_autoaway(FALSE); | |
1398 if (!autoaway_timeout) return; | |
1399 if (!LastActivity || activity) time(&LastActivity); | |
1400 | |
1401 cur_st = jb_getstatus(); | |
1402 // Auto-away is disabled for the following states | |
1403 if ((cur_st != available) && (cur_st != freeforchat)) | |
1404 return; | |
1405 | |
1406 if (!activity) { | |
1407 time_t now; | |
1408 time(&now); | |
1409 if (!Autoaway && (now > LastActivity + (time_t)autoaway_timeout)) | |
1410 set_autoaway(TRUE); | |
1411 } | |
1412 } | |
1413 | |
1414 // set_chatstate(state) | 1392 // set_chatstate(state) |
1415 // Set the current chat state (0=active, 1=composing, 2=paused) | 1393 // Set the current chat state (0=active, 1=composing, 2=paused) |
1394 // If the chat state has changed, call jb_send_chatstate() | |
1416 static inline void set_chatstate(int state) | 1395 static inline void set_chatstate(int state) |
1417 { | 1396 { |
1418 #if defined JEP0022 || defined JEP0085 | 1397 #if defined JEP0022 || defined JEP0085 |
1419 if (!chatmode) | 1398 if (!chatmode) |
1420 state = 0; | 1399 state = 0; |
1429 jep_state = ROSTER_EVENT_PAUSED; | 1408 jep_state = ROSTER_EVENT_PAUSED; |
1430 else | 1409 else |
1431 jep_state = ROSTER_EVENT_ACTIVE; | 1410 jep_state = ROSTER_EVENT_ACTIVE; |
1432 jb_send_chatstate(BUDDATA(current_buddy), jep_state); | 1411 jb_send_chatstate(BUDDATA(current_buddy), jep_state); |
1433 } | 1412 } |
1413 if (!chatstate) | |
1414 chatstate_timestamp = 0; | |
1434 } | 1415 } |
1435 #endif | 1416 #endif |
1417 } | |
1418 | |
1419 #if defined JEP0022 || defined JEP0085 | |
1420 inline long int scr_GetChatStatesTimeout(time_t now) | |
1421 { | |
1422 // Check if we're currently composing... | |
1423 if (chatstate != 1 || !chatstate_timestamp) | |
1424 return 86400; | |
1425 | |
1426 // If the timeout is reached, let's change the state right now. | |
1427 if (now >= chatstate_timestamp + COMPOSING_TIMEOUT) { | |
1428 chatstate_timestamp = now; | |
1429 set_chatstate(2); | |
1430 return 86400; | |
1431 } | |
1432 | |
1433 return chatstate_timestamp + COMPOSING_TIMEOUT - now; | |
1434 } | |
1435 #endif | |
1436 | |
1437 // Check if we should enter/leave automatic away status | |
1438 void scr_CheckAutoAway(int activity) | |
1439 { | |
1440 enum imstatus cur_st; | |
1441 unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); | |
1442 | |
1443 if (Autoaway && activity) set_autoaway(FALSE); | |
1444 if (!autoaway_timeout) return; | |
1445 if (!LastActivity || activity) time(&LastActivity); | |
1446 | |
1447 cur_st = jb_getstatus(); | |
1448 // Auto-away is disabled for the following states | |
1449 if ((cur_st != available) && (cur_st != freeforchat)) | |
1450 return; | |
1451 | |
1452 if (!activity) { | |
1453 time_t now; | |
1454 time(&now); | |
1455 if (!Autoaway && (now > LastActivity + (time_t)autoaway_timeout)) | |
1456 set_autoaway(TRUE); | |
1457 } | |
1436 } | 1458 } |
1437 | 1459 |
1438 // set_current_buddy(newbuddy) | 1460 // set_current_buddy(newbuddy) |
1439 // Set the current_buddy to newbuddy (if not NULL) | 1461 // Set the current_buddy to newbuddy (if not NULL) |
1440 // Lock the newbuddy, and unlock the previous current_buddy | 1462 // Lock the newbuddy, and unlock the previous current_buddy |
2791 if (!lock_chatstate) { | 2813 if (!lock_chatstate) { |
2792 if (inputLine[0] == 0 || inputLine[0] == COMMAND_CHAR) | 2814 if (inputLine[0] == 0 || inputLine[0] == COMMAND_CHAR) |
2793 set_chatstate(0); | 2815 set_chatstate(0); |
2794 else | 2816 else |
2795 set_chatstate(1); | 2817 set_chatstate(1); |
2818 if (chatstate) | |
2819 time(&chatstate_timestamp); | |
2796 } | 2820 } |
2797 return 0; | 2821 return 0; |
2798 } | 2822 } |
2799 | 2823 |
2800 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ | 2824 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |