class TimeLine

タイムラインのGtkウィジェット。

Public Class Methods

get_active_mumbles() click to toggle source

現在アクティブなTLで選択されているすべてのMessageオブジェクトを返す

# File core/mui/cairo_timeline.rb, line 27
def self.get_active_mumbles
  if Gtk::TimeLine::InnerTL.current_tl
    InnerTL.current_tl.get_active_messages
  else
    [] end end
new(imaginary=nil) click to toggle source
Calls superclass method Gtk::TimelineDarkMatterPurification.new
# File core/mui/cairo_timeline.rb, line 33
def initialize(imaginary=nil)
  super()
  @tl = InnerTL.new
  @tl.imaginary = imaginary
  closeup(postbox).pack_start(init_tl)
end

Public Instance Methods

active() click to toggle source

このタイムラインをアクティブにする

# File core/mui/cairo_timeline.rb, line 118
def active
  get_ancestor(Gtk::Window).set_focus(@tl)
end
add_retweets(messages) click to toggle source

リツイートを追加する。 messages には Message の配列を指定し、それらはretweetでなければならない

# File core/mui/cairo_timeline.rb, line 84
def add_retweets(messages)
  messages.reject{|message|
    include?(message.retweet_source)
  }.deach do |message|
    block_add(message.retweet_source) end end
block_add_all(messages) click to toggle source

新しいものから順番にpackしていく。

# File core/mui/cairo_timeline.rb, line 75
def block_add_all(messages)
  removes, appends = *messages.partition{ |m| m[:rule] == :destroy }
  remove_if_exists_all(removes)
  retweets, appends = *appends.partition{ |m| m[:retweet] }
  add_retweets(retweets)
  appends.sort_by{ |m| -get_order(m) }.deach(&method(:block_add))
end
clear() click to toggle source

TLのログを全て消去する

# File core/mui/cairo_timeline.rb, line 70
def clear
  @tl.clear
  self end
destroyed?() click to toggle source

このTLが既に削除されているなら真

# File core/mui/cairo_timeline.rb, line 123
def destroyed?
  @tl.destroyed? or @tl.model.destroyed? end
each(index=1) { |iter| ... } click to toggle source

TLに含まれているMessageを順番に走査する。最新のものから順番に。

# File core/mui/cairo_timeline.rb, line 62
def each(index=1)
  @tl.model.each{ |model,path,iter|
    yield(iter[index]) } end
favorite(user, message) click to toggle source

message が新たに user のお気に入りに追加された時に呼ばれる

# File core/mui/cairo_timeline.rb, line 98
def favorite(user, message)
  self
end
include?(message) click to toggle source
# File core/mui/cairo_timeline.rb, line 66
def include?(message)
  @tl.include? message end
init_tl() click to toggle source
# File core/mui/cairo_timeline.rb, line 40
def init_tl
  @tl.postbox = postbox
  scrollbar = Gtk::VScrollbar.new(@tl.vadjustment)
  @tl.model.set_sort_column_id(2, order = Gtk::SORT_DESCENDING)
  @tl.model.set_sort_func(2){ |a, b|
    order = a[2] <=> b[2]
    if order == 0
      a[0] <=> b[0]
    else
      order
    end
  }
  @tl.set_size_request(100, 100)
  @tl.get_column(0).sizing = Gtk::TreeViewColumn::FIXED
  @tl.ssc(:expose_event){
    emit_expose_miraclepainter
    false }

  init_remover
  @shell = Gtk::HBox.new.pack_start(@tl).closeup(scrollbar) end
method_missing(method_name, *args, &proc) click to toggle source
# File core/mui/cairo_timeline.rb, line 126
def method_missing(method_name, *args, &proc)
  @tl.__send__(method_name, *args, &proc) end
modified(message) click to toggle source

Messageオブジェクト message が更新されたときに呼ばれる

# File core/mui/cairo_timeline.rb, line 91
def modified(message)
  path = @tl.get_path_by_message(message)
  if(path)
    @tl.update!(message, 2, get_order(message)) end
  self end
remove_if_exists_all(messages) click to toggle source

つぶやきが削除されたときに呼ばれる

# File core/mui/cairo_timeline.rb, line 108
def remove_if_exists_all(messages)
  messages.each{ |message|
    path = @tl.get_path_by_message(message)
    tl_model_remove(@tl.model.get_iter(path)) if path } end
size() click to toggle source

TL上のつぶやきの数を返す

# File core/mui/cairo_timeline.rb, line 114
def size
  @tl.model.to_enum(:each).inject(0){ |i, r| i + 1 } end
unfavorite(user, message) click to toggle source

messageuser のお気に入りから削除された時に呼ばれる

# File core/mui/cairo_timeline.rb, line 103
def unfavorite(user, message)
  self
end

Protected Instance Methods

block_add(message) click to toggle source

message をTLに追加する

# File core/mui/cairo_timeline.rb, line 132
def block_add(message)
  if not @tl.destroyed?
    if(!any?{ |m| m == message })
      case
      when message[:rule] == :destroy
        remove_if_exists_all([message])
      when message.retweet?
        add_retweets([message])
      else
        _add(message) end end end
  self end
each_iter() { |iter| ... } click to toggle source

Gtk::TreeIterについて繰り返す

# File core/mui/cairo_timeline.rb, line 145
def each_iter
  @tl.model.each{ |model,path,iter|
    yield(iter) } end

Private Instance Methods

_add(message) click to toggle source
# File core/mui/cairo_timeline.rb, line 151
def _add(message)
  scroll_to_zero_lator! if @tl.realized? and @tl.vadjustment.value == 0.0
  miracle_painter = @tl.cell_renderer_message.create_miracle_painter(message)
  iter = @tl.model.append
  iter[Gtk::TimeLine::InnerTL::URI] = message.uri.to_s
  iter[Gtk::TimeLine::InnerTL::MESSAGE] = message
  iter[Gtk::TimeLine::InnerTL::ORDER] = get_order(message)
  iter[Gtk::TimeLine::InnerTL::MIRACLE_PAINTER] = miracle_painter
  @tl.set_iter_dict(iter)
  @remover_queue.push(message)
  self
end
emit_expose_miraclepainter() click to toggle source

スクロールなどの理由で新しくTLに現れたMiraclePainterにシグナルを送る

# File core/mui/cairo_timeline.rb, line 186
def emit_expose_miraclepainter
  @exposing_miraclepainter ||= []
  if @tl.visible_range
    current, last = @tl.visible_range.map{ |path| @tl.model.get_iter(path) }
    messages = Set.new
    while current[0].to_i >= last[0].to_i
      messages << current[1]
      break if not current.next! end
    (messages - @exposing_miraclepainter).each{ |exposed|
      @tl.cell_renderer_message.miracle_painter(exposed).signal_emit(:expose_event) if exposed.is_a? Message }
    @exposing_miraclepainter = messages end end
init_remover() click to toggle source

TLのMessageの数が上限を超えたときに削除するためのキューの初期化 オーバーしてもすぐには削除せず、1秒間更新がなければ削除するようになっている。

# File core/mui/cairo_timeline.rb, line 166
def init_remover
  @timeline_max = 200
  @remover_queue = TimeLimitedQueue.new(1024, 1){ |messages|
    Delayer.new{
      if not destroyed?
        remove_count = size - timeline_max
        if remove_count > 0
          to_enum(:each_iter).to_a[-remove_count, remove_count].each{ |iter|
            tl_model_remove(iter) } end end } } end
postbox() click to toggle source
# File core/mui/cairo_timeline.rb, line 198
def postbox
  @postbox ||= Gtk::VBox.new end
tl_model_remove(iter) click to toggle source

iter を削除する。このメソッドを通さないと、Gdk::MiraclePainterに destroyイベントが発生しない。

Args

iter

削除するレコード(Gtk::TreeIter)

# File core/mui/cairo_timeline.rb, line 181
def tl_model_remove(iter)
  iter[InnerTL::MIRACLE_PAINTER].destroy
  @tl.model.remove(iter) end