From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.213.13.12 with SMTP id z12cs1183596ebz; Sun, 3 Jan 2010 22:25:42 -0800 (PST) Received: by 10.224.31.78 with SMTP id x14mr10967429qac.196.1262586341788; Sun, 03 Jan 2010 22:25:41 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id 37si30530345qyk.20.2010.01.03.22.25.41; Sun, 03 Jan 2010 22:25:41 -0800 (PST) Received-SPF: pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-devel-bounces@rubyforge.org; dkim=neutral (body hash did not verify) header.i=@gmail.com Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 442411D7887C; Mon, 4 Jan 2010 01:25:41 -0500 (EST) Received: from mail-qy0-f192.google.com (mail-qy0-f192.google.com [209.85.221.192]) by rubyforge.org (Postfix) with ESMTP id CB72D1858291 for ; Mon, 4 Jan 2010 01:20:36 -0500 (EST) Received: by qyk30 with SMTP id 30so6871644qyk.33 for ; Sun, 03 Jan 2010 22:20:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:content-type:subject:from:to :date:message-id:user-agent:content-transfer-encoding; bh=9u7J+4Fw8zqtzaSEW7hRrMt537sOPwRyJ8jgZpWxNXA=; b=hrl5yv9JQhvMr84353F1E/TEymuwNehhBdeKiAj2p/+5mUnuwRpLixvWd4iPvCMulL thczfWvx0Sjfo6BgQCmn09FT6YxzgnfDmwdKve4jfjn8tTycUcJxwaDMMDnhzifrpKjK 3eIpzG+Gd0Rkj12SfsL9j/gVUR/ctdcZIGLRk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=content-type:subject:from:to:date:message-id:user-agent :content-transfer-encoding; b=srLwNJzPjzb2yuzeCZUnhN0Fe2KCUx/EGMX9y+Hx6ZvFtAw+s8VQPIXmWr8Zwpo93q TuEtYtA2w0OImeauFTXLex44sW7axdNgpEvuOrf9/QRSC8ljpB0UrPF1gQdhLdnmtLq4 lntihczS6Mp4fiShuorhEnsBQWCBOwkxdcPz4= Received: by 10.224.72.23 with SMTP id k23mr10981946qaj.120.1262586036520; Sun, 03 Jan 2010 22:20:36 -0800 (PST) Received: from localhost (c-76-98-110-216.hsd1.nj.comcast.net [76.98.110.216]) by mx.google.com with ESMTPS id 5sm47995303qwg.48.2010.01.03.22.20.35 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 03 Jan 2010 22:20:36 -0800 (PST) From: Eric Sherman To: sup-devel Date: Mon, 04 Jan 2010 01:20:34 -0500 Message-Id: <1262585888-sup-7490@changeling.local> User-Agent: Sup/git Subject: [sup-devel] [PATCH] [issue14] poll updates accumulate while idle X-BeenThere: sup-devel@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Sup developer discussion List-Id: Sup developer discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-devel-bounces@rubyforge.org Errors-To: sup-devel-bounces@rubyforge.org If you were to leave sup running for a long time, this patch would enable you to get a glance summary of new mail activity since sup was last touched, by letting the poll update message accumulate its tally while idle. On keystrokes, BufferManager sends an :unidle update if the last keystroke occurred more than :idle_threshold seconds ago. PollManager listens for :unidle updates to clear PollTally, which will otherwise accumulate. * :idle_threshold defaults to 60 seconds if not defined in config.yaml * presently no :idle update is sent when becoming idle * after-poll behavior is unaffected --- lib/sup.rb | 3 ++- lib/sup/buffer.rb | 5 +++++ lib/sup/poll.rb | 23 +++++++++++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/sup.rb b/lib/sup.rb index 840b3fc..a6de0ab 100644 --- a/lib/sup.rb +++ b/lib/sup.rb @@ -229,7 +229,8 @@ else :confirm_top_posting => true, :discard_snippets_from_encrypted_messages => false, :default_attachment_save_dir => "", - :sent_source => "sup://sent" + :sent_source => "sup://sent", + :idle_threshold => 60 } begin FileUtils.mkdir_p Redwood::BASE_DIR diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb index c826ab9..c34917d 100644 --- a/lib/sup/buffer.rb +++ b/lib/sup/buffer.rb @@ -212,6 +212,7 @@ EOS @in_x = ENV["TERM"] =~ /(xterm|rxvt|screen)/ @sigwinch_happened = false @sigwinch_mutex = Mutex.new + @idle_since = Time.now end def sigwinch_happened!; @sigwinch_mutex.synchronize { @sigwinch_happened = true } end @@ -269,6 +270,8 @@ EOS @focus_buf.mode.cancel_search! @focus_buf.mark_dirty end + UpdateManager.relay self, :unidle, Time.at(@idle_since) if idle? + @idle_since = Time.now @focus_buf.mode.handle_input c end end @@ -797,5 +800,7 @@ private end @users end + + def idle?; Time.now.to_i - @idle_since.to_i >= ($config[:idle_threshold] || 60); end end end diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb index 4f30505..fb684df 100644 --- a/lib/sup/poll.rb +++ b/lib/sup/poll.rb @@ -37,6 +37,8 @@ EOS @polling = false @poll_sources = nil @mode = nil + PollTally.init + UpdateManager.register self end def poll_with_sources @@ -45,8 +47,9 @@ EOS BufferManager.flash "Polling for new messages..." num, numi, from_and_subj, from_and_subj_inbox, loaded_labels = @mode.poll - if num > 0 - BufferManager.flash "Loaded #{num.pluralize 'new message'}, #{numi} to inbox. Labels: #{loaded_labels.map{|l| l.to_s}.join(', ')}" + PollTally.add :num => num, :num_inbox => numi, :loaded_labels => loaded_labels + if PollTally.num > 0 + BufferManager.flash "Loaded #{PollTally.num.pluralize 'new message'}, #{PollTally.num_inbox} to inbox. Labels: #{PollTally.loaded_labels.map{|l| l.to_s}.join(', ')}" else BufferManager.flash "No new messages." end @@ -183,6 +186,22 @@ EOS Index.add_message m UpdateManager.relay self, :added, m end + + def handle_unidle_update sender, idle_since; PollTally.clear; end +end + +class PollTally + include Singleton + attr_reader :num, :num_inbox, :loaded_labels + + def initialize; @num = 0; @num_inbox = 0; @loaded_labels = Set.new; end + def clear; @num = 0; @num_inbox = 0; @loaded_labels.clear; end + + def add opts={} + @num += opts[:num]||0 + @num_inbox += opts[:num_inbox]||0 + @loaded_labels = Set.new(opts[:loaded_labels] || []) + @loaded_labels + end end end -- 1.6.5.7 _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel