comparison mcabber/src/screen.c @ 990:35e7913affb7

Send events/chatstates notifications (JEP-22/JEP-85)
author Mikael Berthe <mikael@lilotux.net>
date Wed, 01 Nov 2006 00:57:56 +0100
parents f47e312560af
children ef10906691bb
comparison
equal deleted inserted replaced
989:859ab76e5093 990:35e7913affb7
92 static short int inputline_offset; 92 static short int inputline_offset;
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
98 static int chatstate;
99 static bool lock_chatstate;
97 100
98 #define MAX_KEYSEQ_LENGTH 8 101 #define MAX_KEYSEQ_LENGTH 8
99 102
100 typedef struct { 103 typedef struct {
101 char *seqstr; 104 char *seqstr;
1406 if (!Autoaway && (now > LastActivity + (time_t)autoaway_timeout)) 1409 if (!Autoaway && (now > LastActivity + (time_t)autoaway_timeout))
1407 set_autoaway(TRUE); 1410 set_autoaway(TRUE);
1408 } 1411 }
1409 } 1412 }
1410 1413
1414 // set_chatstate(state)
1415 // Set the current chat state (0=active, 1=composing, 2=paused)
1416 static inline void set_chatstate(int state)
1417 {
1418 #if defined JEP0022 || defined JEP0085
1419 if (!chatmode)
1420 state = 0;
1421 if (state != chatstate) {
1422 chatstate = state;
1423 if (current_buddy &&
1424 buddy_gettype(BUDDATA(current_buddy)) == ROSTER_TYPE_USER) {
1425 guint jep_state;
1426 if (chatstate == 1)
1427 jep_state = ROSTER_EVENT_COMPOSING;
1428 else if (chatstate == 2)
1429 jep_state = ROSTER_EVENT_PAUSED;
1430 else
1431 jep_state = ROSTER_EVENT_ACTIVE;
1432 jb_send_chatstate(BUDDATA(current_buddy), jep_state);
1433 }
1434 }
1435 #endif
1436 }
1437
1411 // set_current_buddy(newbuddy) 1438 // set_current_buddy(newbuddy)
1412 // Set the current_buddy to newbuddy (if not NULL) 1439 // Set the current_buddy to newbuddy (if not NULL)
1413 // Lock the newbuddy, and unlock the previous current_buddy 1440 // Lock the newbuddy, and unlock the previous current_buddy
1414 static void set_current_buddy(GList *newbuddy) 1441 static void set_current_buddy(GList *newbuddy)
1415 { 1442 {
1419 * buddy_getstatus() call. 1446 * buddy_getstatus() call.
1420 */ 1447 */
1421 1448
1422 if (!current_buddy || !newbuddy) return; 1449 if (!current_buddy || !newbuddy) return;
1423 if (newbuddy == current_buddy) return; 1450 if (newbuddy == current_buddy) return;
1451
1452 // We're moving to another buddy. We're thus inactive wrt current_buddy.
1453 set_chatstate(0);
1454 // We don't want the chatstate to be changed again right now.
1455 lock_chatstate = true;
1424 1456
1425 prev_st = buddy_getstatus(BUDDATA(current_buddy), NULL); 1457 prev_st = buddy_getstatus(BUDDATA(current_buddy), NULL);
1426 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); 1458 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
1427 if (chatmode) 1459 if (chatmode)
1428 alternate_buddy = current_buddy; 1460 alternate_buddy = current_buddy;
2528 int process_key(keycode kcode) 2560 int process_key(keycode kcode)
2529 { 2561 {
2530 int key = kcode.value; 2562 int key = kcode.value;
2531 int display_char = FALSE; 2563 int display_char = FALSE;
2532 2564
2565 lock_chatstate = false;
2566
2533 switch (kcode.mcode) { 2567 switch (kcode.mcode) {
2534 case 0: 2568 case 0:
2535 break; 2569 break;
2536 case MKEY_EQUIV: 2570 case MKEY_EQUIV:
2537 key = kcode.value; 2571 key = kcode.value;
2751 } 2785 }
2752 2786
2753 if (completion_started && key != 9 && key != KEY_RESIZE) 2787 if (completion_started && key != 9 && key != KEY_RESIZE)
2754 scr_end_current_completion(); 2788 scr_end_current_completion();
2755 refresh_inputline(); 2789 refresh_inputline();
2790
2791 if (!lock_chatstate) {
2792 if (inputLine[0] == 0 || inputLine[0] == COMMAND_CHAR)
2793 set_chatstate(0);
2794 else
2795 set_chatstate(1);
2796 }
2756 return 0; 2797 return 0;
2757 } 2798 }
2758 2799
2759 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ 2800 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */