-
Notifications
You must be signed in to change notification settings - Fork 2
/
TelegramConfig.py
109 lines (93 loc) · 3.92 KB
/
TelegramConfig.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# rhythmbox-telegram
# Copyright (C) 2023-2024 Andrey Izman <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import gi
gi.require_version('Gtk', '3.0')
import rb
from gi.repository import GObject, Gtk, Gdk, GLib
from gi.repository import Peas, PeasGtk # noqa
from PrefsConnectPage import PrefsConnectPage
from PrefsChannelsPage import PrefsChannelsPage
from PrefsSettingsPage import PrefsSettingsPage
from PrefsTempPage import PrefsTempPage
from TelegramAccount import TelegramAccount
class TelegramConfig(GObject.GObject, PeasGtk.Configurable):
__gtype_name__ = 'TelegramConfig'
object = GObject.property(type=GObject.GObject)
loading = None
spinner = None
parent = None
api = None
removed_help = False
_changes = {}
__gsignals__ = {
'channels-clear' : (GObject.SignalFlags.RUN_FIRST, None, ()),
'channels-reload' : (GObject.SignalFlags.RUN_FIRST, None, ()),
'channels-fetch' : (GObject.SignalFlags.RUN_FIRST, None, ()),
}
def __init__(self):
GObject.GObject.__init__(self)
self.shell = self.object
self.account = None
self.plugin = None
self.settings = None
def find_plugin_file(self, file):
return rb.find_plugin_file(self, file)
def do_create_configure_widget(self):
self.account = TelegramAccount()
self.account.init()
self.plugin = self.account.plugin
self.settings = self.account.settings
main_box = Gtk.Box()
self.main_box = main_box
main_box.set_border_width(5)
notebook = Gtk.Notebook(vexpand=True, hexpand=True)
main_box.add(notebook)
self.page1 = PrefsConnectPage(self)
self.page2 = PrefsChannelsPage(self)
self.page3 = PrefsSettingsPage(self)
self.page4 = PrefsTempPage(self)
self.page1.register_signals()
self.page2.register_signals()
self.page3.register_signals()
self.page4.register_signals()
self.page1.create_widget().append_to(notebook)
self.page2.create_widget().append_to(notebook)
self.page3.create_widget().append_to(notebook)
self.page4.create_widget().append_to(notebook)
GLib.timeout_add(600, self.update_window)
return main_box
def get_center(self):
self.parent = self.main_box.get_toplevel().get_property('window')
position = self.parent.get_position()
geometry = self.parent.get_geometry()
left_center = round(position.x + (geometry.width - geometry.x) / 2)
top_center = round(position.y + (geometry.height - geometry.y) / 2)
return {"x": left_center, "y": top_center}
def update_window(self):
gtk_win = self.main_box.get_toplevel()
gtk_win.set_default_size(500, 600)
gtk_win.set_resizable(False)
donate_btn = gtk_win.add_button("Donate", Gtk.ResponseType.HELP)
donate_btn.connect("pressed", self.on_donate_clicked)
style_context = donate_btn.get_style_context()
style_context.add_class('suggested-action')
gtk_win.set_border_width(5)
box = gtk_win.get_content_area()
box.set_spacing(2)
def on_donate_clicked(self, button):
screen = self.plugin.shell.props.window.get_screen()
Gtk.show_uri(screen, 'https://github.com/mervick/rhythmbox-telegram', Gdk.CURRENT_TIME)
GObject.type_register(TelegramConfig)