Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/services/console/lib/purk/scripts/ui_script.py
blob: 459de96aa743261b93da933cf8275807792f876e (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import irc
import ui
import windows
import irc_script
from conf import conf

# FIXME: meh still might want rid of these, I'm not sure yet

def onActive(e):
    e.window.activity = None

    ui.register_idle(windows.manager.set_title)

def setupNick(e):
    if e.source == e.network.me:
        for w in windows.get_with(core.manager, network=e.network):
            try:
                w.nick_label.update(e.target)
            except AttributeError:
                pass    

def onExit(e):
    for n in set(w.network for w in windows.manager):
        if n:
            n.quit()

def setupJoin(e):
    if e.source == e.network.me:
        window = windows.get(windows.StatusWindow, e.network, 'status', core)
        
        if window and not conf.get('status'):
            window.mutate(windows.ChannelWindow, e.network, e.target)
        else:
            window = windows.new(windows.ChannelWindow, e.network, e.target, core)
        
        if e.requested:
            window.activate()

    e.window = windows.get(windows.ChannelWindow, e.network, e.target, core) or e.window

def setupText(e):
    if e.target == e.network.me:
        e.window = windows.new(windows.QueryWindow, e.network, e.source, core)
    else:
        e.window = \
            windows.get(windows.ChannelWindow, e.network, e.target, core) or \
            windows.get(windows.QueryWindow, e.network, e.source, core) or \
            e.window

setupAction = setupText

def setupNotice(e):
    if e.target != e.network.me:
        e.window = \
            windows.get(windows.ChannelWindow, e.network, e.target, core) or e.window

def setupOwnText(e):
    e.window = \
        windows.get(windows.ChannelWindow, e.network, e.target, core) or \
        windows.get(windows.QueryWindow, e.network, e.target, core) or \
        e.window

setupOwnAction = setupOwnText

def setdownPart(e):
    if e.source == e.network.me:
        window = windows.get(windows.ChannelWindow, e.network, e.target, core)        
        
        if window:
            cwindows = list(windows.get_with(
                                network=window.network,
                                wclass=windows.ChannelWindow
                                ))
                            
            if len(cwindows) == 1 and not list(windows.get_with(network=window.network, wclass=windows.StatusWindow)):
                window.mutate(windows.StatusWindow, e.network, 'status')
                if e.requested:
                    window.activate()
            elif e.requested:
                window.close()

def onClose(e):
    nwindows = list(windows.get_with(core.manager, network=e.window.network))
    
    if isinstance(e.window, windows.ChannelWindow): 
        cwindows = list(windows.get_with(core.manager,
                            network=e.window.network,
                            wclass=windows.ChannelWindow
                            ))
        
        #if we only have one window for the network, don't bother to part as
        # we'll soon be quitting anyway
        if len(nwindows) != 1 and irc_script.ischan(e.window.network, e.window.id):
            e.window.network.part(e.window.id) 
    
    if len(nwindows) == 1:
        core.events.trigger("CloseNetwork", window=e.window, network=e.window.network)
    
    elif isinstance(e.window, windows.StatusWindow) and conf.get('status'):
        core.events.trigger("CloseNetwork", window=e.window, network=e.window.network)
        for window in nwindows:
            if window != e.window:
                window.close()
        
    if len(core.manager) == 1:
        windows.new(windows.StatusWindow, irc.Network(), "status", core)

def onConnecting(e):
    return
    window = windows.get_default(e.network)
    if window:
        window.update()

onDisconnect = onConnecting

def setupPart(e):
    e.window = windows.get(windows.ChannelWindow, e.network, e.target, core) or e.window

setupTopic = setupPart

def setupKick(e):
    e.window = windows.get(windows.ChannelWindow, e.network, e.channel, core) or e.window

def setupMode(e):
    if e.target != e.network.me:
        e.window = windows.get(windows.ChannelWindow, e.network, e.target, core) or e.window

def onWindowMenu(e):
    if isinstance(e.window, windows.ChannelWindow):
        e.channel = e.window.id
        e.network = e.window.network
        core.events.trigger('ChannelMenu', e)