Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

# -*- coding: utf-8 -*- 

# 

# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com> 

# 

# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with 

# the additional special exception to link portions of this program with the OpenSSL library. 

# See LICENSE for more details. 

# 

 

import deluge.common 

import deluge.component as component 

from deluge.core.preferencesmanager import DEFAULT_PREFS 

from deluge.ui.client import client 

 

 

class StatusBars(component.Component): 

    def __init__(self): 

        component.Component.__init__(self, "StatusBars", 2, depend=["CoreConfig"]) 

        self.config = component.get("CoreConfig") 

 

        # Hold some values we get from the core 

        self.connections = 0 

        self.download = "" 

        self.upload = "" 

        self.dht = 0 

 

        # Default values 

        self.topbar = "{!status!}Deluge %s Console - " % deluge.common.get_version() 

        self.bottombar = "{!status!}C: %s" % self.connections 

 

    def start(self): 

        self.update() 

 

    def update(self): 

        def on_get_session_status(status): 

            self.upload = deluge.common.fsize(status["payload_upload_rate"]) 

            self.download = deluge.common.fsize(status["payload_download_rate"]) 

            self.connections = status["num_peers"] 

            if "dht_nodes" in status: 

                self.dht = status["dht_nodes"] 

 

            self.update_statusbars() 

 

        keys = ["num_peers", "payload_upload_rate", "payload_download_rate"] 

 

        if self.config["dht"]: 

            keys.append("dht_nodes") 

 

        client.core.get_session_status(keys).addCallback(on_get_session_status) 

 

    def update_statusbars(self): 

        # Update the topbar string 

        self.topbar = "{!status!}Deluge %s Console - " % deluge.common.get_version() 

 

        if client.connected(): 

            info = client.connection_info() 

            connection_info = "" 

 

            # Client name 

            if info[2] == "localclient": 

                connection_info += "{!white,blue!}%s" 

            else: 

                connection_info += "{!green,blue,bold!}%s" 

 

            # Hostname 

            if info[0] == "127.0.0.1": 

                connection_info += "{!white,blue,bold!}@{!white,blue!}%s" 

            else: 

                connection_info += "{!white,blue,bold!}@{!red,blue,bold!}%s" 

 

            # Port 

            if info[1] == DEFAULT_PREFS["daemon_port"]: 

                connection_info += "{!white,blue!}:%s" 

            else: 

                connection_info += "{!status!}:%s" 

 

            # Change color back to normal, just in case 

            connection_info += "{!status!}" 

 

            self.topbar += connection_info % (info[2], info[0], info[1]) 

        else: 

            self.topbar += "Not Connected" 

 

        # Update the bottombar string 

        self.bottombar = "{!status!}C: {!white,blue!}%s{!status!}" % self.connections 

 

        if self.config["max_connections_global"] > -1: 

            self.bottombar += " (%s)" % self.config["max_connections_global"] 

 

        if self.download != "0.0 KiB": 

            self.bottombar += " D: {!magenta,blue,bold!}%s{!status!}" % self.download 

        else: 

            self.bottombar += " D: {!white,blue!}%s{!status!}" % self.download 

 

        if self.config["max_download_speed"] > -1: 

            self.bottombar += " (%s " % self.config["max_download_speed"] + _("KiB/s") + ")" 

 

        if self.upload != "0.0 KiB": 

            self.bottombar += " U: {!green,blue,bold!}%s{!status!}" % self.upload 

        else: 

            self.bottombar += " U: {!white,blue!}%s{!status!}" % self.upload 

 

        if self.config["max_upload_speed"] > -1: 

            self.bottombar += " (%s " % self.config["max_upload_speed"] + _("KiB/s") + ")" 

 

        if self.config["dht"]: 

            self.bottombar += " " + _("DHT") + ": {!white,blue!}%s{!status!}" % self.dht