Debian Codegraph @

plugin/mastodon_setting/mastodon_setting.rb

raw symbols SCIP
1 require_relative 'instance_setting_list'
2
3 Plugin.create :mastodon_setting do
4 # 設定の初期化
5 defaults = {
6 mastodon_enable_streaming: true,
7 mastodon_rest_interval: 1,
8 mastodon_show_subparts_visibility: true,
9 mastodon_show_subparts_bot: true,
10 mastodon_show_subparts_pin: true,
11 mastodon_instances: {}
12 }
13 defaults.each do |key, value|
14 UserConfig[key] ||= value
15 end
16
17 # 追加
18 on_mastodon_instances_open_create_dialog do
19 dialog _('サーバー設定の追加') do
20 error_msg = nil
21 while true
22 if error_msg
23 label error_msg
24 end
25 input _('サーバーのドメイン'), :domain
26 result = await_input
27 if result[:domain].empty?
28 error_msg = _('ドメイン名を入力してください。')
29 next
30 end
31 if UserConfig[:mastodon_instances].has_key?(result[:domain])
32 error_msg = _('既に登録済みのドメインです。入力し直してください。')
33 next
34 end
35 instance = await(Plugin::Mastodon::Instance.add(result[:domain]).trap { nil })
36 unless instance
37 error_msg = _('接続に失敗しました。もう一度確認してください。')
38 next
39 end
40
41 break
42 end
43 domain = result[:domain]
44 label _('%{domain} サーバーを追加しました') % { domain: }
45 Plugin.call(:mastodon_instance_created, domain)
46 end
47 end
48
49 # 編集
50 on_mastodon_instances_open_edit_dialog do |domain|
51 dialog _('サーバー設定の編集') {
52 label _('サーバーのドメイン: %{domain}') % { domain: }
53 }.next do |result|
54 Plugin.call(:mastodon_update_instance, result.domain)
55 end
56 end
57
58 # 削除
59 on_mastodon_instances_delete_with_confirm do |domain|
60 next unless UserConfig[:mastodon_instances][domain]
61 dialog _('サーバー設定の削除') {
62 label _('サーバー %{domain} を削除しますか?') % { domain: }
63 }.next do
64 Plugin.call(:mastodon_delete_instance, domain)
65 end
66 end
67
68 # 設定
69 settings _('Mastodon') do
70 settings _('表示') do
71 boolean _('botアカウントにアイコンを表示する'), :mastodon_show_subparts_bot
72 boolean _('ピン留めトゥートにアイコンを表示する'), :mastodon_show_subparts_pin
73 boolean _('トゥートに公開範囲を表示する'), :mastodon_show_subparts_visibility
74 end
75
76 settings _('接続') do
77 boolean _('ストリーミング接続する'), :mastodon_enable_streaming
78 adjustment _('接続間隔(分)'), :mastodon_rest_interval, 1, 60 * 24
79 end
80
81 settings _('公開タイムライン') do
82 treeview = Plugin::MastodonSetting::InstanceSettingList.new
83 treeview.hexpand = true
84 add_tab_observer = on_mastodon_instance_created(&treeview.method(:add_record))
85 delete_tab_observer = on_mastodon_delete_instance(&treeview.method(:remove_record))
86 treeview.ssc(:destroy) do
87 detach add_tab_observer
88 detach delete_tab_observer
89 end
90
91 btn_add = Gtk::Button.new stock_id: Gtk::Stock::ADD
92 btn_delete = Gtk::Button.new stock_id: Gtk::Stock::DELETE
93 btn_add.ssc(:clicked) do
94 Plugin.call(:mastodon_instances_open_create_dialog)
95 true
96 end
97 btn_delete.ssc(:clicked) do
98 domain = treeview.selected_domain
99 if domain
100 Plugin.call(:mastodon_instances_delete_with_confirm, domain) end
101 true
102 end
103
104 box = Gtk::ButtonBox.new :vertical
105 box.layout_style = :start
106 box.spacing = 6
107 box << btn_add << btn_delete
108
109 grid = Gtk::Grid.new
110 grid.column_spacing = 6
111 grid << treeview << box
112
113 attach_next_to grid, nil, :bottom, 2, 1
114 end
115 end
116 end