- int diff;
-
- if (paste_state == 0) {
- /* gone already */
- return FALSE;
- }
-
- g_get_current_time(&now);
- diff = (now.tv_sec - last_keypress.tv_sec) * 1000 +
- (now.tv_usec - last_keypress.tv_usec)/1000;
-
- if (diff < paste_detect_time) {
- /* still pasting */
- return TRUE;
- }
-
- if (paste_line_count < paste_verify_line_count ||
- active_win->active == NULL) {
- /* paste without asking */
- paste_flush(TRUE);
- } else if (!paste_prompt) {
- paste_prompt = TRUE;
- paste_old_prompt = g_strdup(active_entry->prompt);
- printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
- TXT_PASTE_WARNING,
- paste_line_count,
- active_win->active == NULL ? "window" :
- active_win->active->visible_name);
-
- str = format_get_text(MODULE_NAME, active_win, NULL, NULL,
- TXT_PASTE_PROMPT, 0, 0);
- gui_entry_set_prompt(active_entry, str);
- gui_entry_set_text(active_entry, "");
- g_free(str);
- }
- return TRUE;
-}
-
-static int check_pasting(unichar key, int diff)
-{
- if (paste_state < 0)
- return FALSE;
-
- if (paste_state == 0) {
- /* two keys hit together quick. possibly pasting */
- if (diff > paste_detect_time)
- return FALSE;
-
- g_free(paste_entry);
- paste_entry = g_strdup(prev_entry);
- paste_entry_pos = prev_entry_pos;
-
- paste_state++;
- paste_line_count = 0;
- paste_keycount = 0;
- g_array_set_size(paste_buffer, 0);
- if (prev_key != '\r' && prev_key != '\n')
- g_array_append_val(paste_buffer, prev_key);
- } else if (paste_state > 0 && diff > paste_detect_time &&
- paste_line_count == 0) {
- /* reset paste state */
- paste_state = 0;
- paste_keycount = 0;
- return FALSE;
- }
-
- /* continuing quick hits */
- if ((key == 11 || key == 3) && paste_prompt) {
- paste_flush(key == 11);
- return TRUE;
- }
-
- g_array_append_val(paste_buffer, key);
- if (key == '\r' || key == '\n') {
- if (paste_state == 1 &&
- paste_keycount < paste_detect_keycount) {
- /* not enough keypresses to determine if this is
- pasting or not. don't reset paste keycount, but
- send this line as non-pasted */
- g_array_set_size(paste_buffer, 0);
- return FALSE;
- }
-
- /* newline - assume this line was pasted */
- if (paste_state == 1) {
- paste_state = 2;
- gui_entry_set_text(active_entry, paste_entry);
- gui_entry_set_pos(active_entry, paste_entry_pos);
- if (paste_verify_line_count > 0)
- g_timeout_add(100, paste_timeout, NULL);
- }
-
- if (paste_verify_line_count <= 0) {
- /* paste previous line */
- paste_send();
- g_array_set_size(paste_buffer, 0);
- } else {
- paste_line_count++;
- }
- }