File: gtk_listlist.rb

package info (click to toggle)
mikutter 3.0.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,396 kB
  • ctags: 1,916
  • sloc: ruby: 16,619; sh: 117; makefile: 27
file content (48 lines) | stat: -rw-r--r-- 1,860 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
# ユーザグループリスト用リストビュー
#

miquire :mui, 'extension'

class Gtk::ListList < Gtk::CRUD

  def column_schemer
    [{:kind => :active, :widget => :boolean, :type => TrueClass, :label => '表示'},
     {:kind => :text, :type => String, :label => 'リスト名'},
     {:type => UserList},
    ].freeze
  end

  # 「自分」のアカウントが関係するTwitterリストでこのリストビューを埋める。
  # ==== Args
  # [own]
  #   真なら自分が作成したTwitterリストのみをこのリストビューに入れる
  #   偽なら自分が作成したものと自分がフォローしているTwitterリストも入れる
  # ==== Return
  # self
  def set_auto_getter(plugin, own = false, &proc)
    type_strict plugin => Plugin, proc => Proc
    add_hook(Service.primary, own, UserLists.new(Plugin.filtering(:following_lists, UserLists.new).first), &proc)
    create = plugin.add_event(:list_created) { |service, lists|
      add_hook(service, own, UserLists.new(lists), &proc) }
    destroy = plugin.add_event(:list_destroy){ |service, list_ids|
      unless destroyed?
        each{ |model, path, iter|
          remove(iter) if list_ids.include?(iter[2][:id]) } end }
    signal_connect('destroy-event'){ |w, event|
      plugin.detach(create).detach(destroy) }
    self end

  private

  # リスト郡 _lists_ の中で、まだリストビューの中にないリストを追加する
  # ==== Args
  # [service] Service
  # [own] 真なら自分の作成したリストのみを追加する
  # [lists] リストの配列(UserLists)
  def add_hook(service, own, lists, &proc)
    type_strict service => Service, lists => UserLists, proc => Proc
    (own ? lists.select{ |list| list[:user].is_me? } : lists).each{ |list|
      proc.call(service, list, model.append) } end

end