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

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

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

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

# 

# Copyright (C) 2007, 2008 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. 

# 

 

from __future__ import print_function 

 

import warnings 

 

import gobject 

import gtk 

 

import deluge.common as common 

import deluge.component as component 

 

# Status icons.. Create them from file only once to avoid constantly 

# re-creating them. 

icon_downloading = gtk.gdk.pixbuf_new_from_file(common.get_pixmap("downloading16.png")) 

icon_seeding = gtk.gdk.pixbuf_new_from_file(common.get_pixmap("seeding16.png")) 

icon_inactive = gtk.gdk.pixbuf_new_from_file(common.get_pixmap("inactive16.png")) 

icon_alert = gtk.gdk.pixbuf_new_from_file(common.get_pixmap("alert16.png")) 

icon_queued = gtk.gdk.pixbuf_new_from_file(common.get_pixmap("queued16.png")) 

icon_checking = gtk.gdk.pixbuf_new_from_file(common.get_pixmap("checking16.png")) 

 

# Holds the info for which status icon to display based on TORRENT_STATE 

ICON_STATE = { 

    "Allocating": icon_checking, 

    "Checking": icon_checking, 

    "Downloading": icon_downloading, 

    "Seeding": icon_seeding, 

    "Paused": icon_inactive, 

    "Error": icon_alert, 

    "Queued": icon_queued, 

    "Moving": icon_checking 

} 

 

# Cache the key used to calculate the current value set for the specific cell 

# renderer. This is much cheaper than fetch the current value and test if 

# it's equal. 

func_last_value = {"cell_data_speed_down": None, 

                   "cell_data_speed_up": None, 

                   "cell_data_time": None, 

                   "cell_data_ratio_seeds_peers": None, 

                   "cell_data_ratio_ratio": None, 

                   "cell_data_ratio_avail": None, 

                   "cell_data_date": None, 

                   "cell_data_date_or_never": None, 

                   "cell_data_speed_limit_down": None, 

                   "cell_data_speed_limit_up": None, 

                   "cell_data_trackericon": None, 

                   "cell_data_statusicon": None, 

                   "cell_data_queue": None, 

                   "cell_data_progress": [None, None], 

                   } 

 

 

def cell_data_statusicon(column, cell, model, row, data): 

    """Display text with an icon""" 

    try: 

        state = model.get_value(row, data) 

 

        if func_last_value["cell_data_statusicon"] == state: 

            return 

        func_last_value["cell_data_statusicon"] = state 

 

        icon = ICON_STATE[state] 

 

        # Supress Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed 

        original_filters = warnings.filters[:] 

        warnings.simplefilter("ignore") 

        try: 

            cell.set_property("pixbuf", icon) 

        finally: 

            warnings.filters = original_filters 

 

    except KeyError: 

        pass 

 

 

def create_blank_pixbuf(): 

    i = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 16, 16) 

    i.fill(0x00000000) 

    return i 

 

 

def set_icon(icon, cell): 

    if icon: 

        pixbuf = icon.get_cached_icon() 

        if pixbuf is None: 

            try: 

                pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon.get_filename(), 16, 16) 

            except gobject.GError: 

                # Failed to load the pixbuf (Bad image file), so set a blank pixbuf 

                pixbuf = create_blank_pixbuf() 

            finally: 

                icon.set_cached_icon(pixbuf) 

    else: 

        pixbuf = create_blank_pixbuf() 

 

    # Suppress Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed 

    with warnings.catch_warnings(): 

        warnings.simplefilter("ignore") 

        cell.set_property("pixbuf", pixbuf) 

 

 

def cell_data_trackericon(column, cell, model, row, data): 

    host = model[row][data] 

 

    if func_last_value["cell_data_trackericon"] == host: 

        return 

    if host: 

        if not component.get("TrackerIcons").has(host): 

            # Set blank icon while waiting for the icon to be loaded 

            set_icon(None, cell) 

            component.get("TrackerIcons").fetch(host) 

            func_last_value["cell_data_trackericon"] = None 

        else: 

            set_icon(component.get("TrackerIcons").get(host), cell) 

            # Only set the last value when we have found the icon 

            func_last_value["cell_data_trackericon"] = host 

    else: 

        set_icon(None, cell) 

        func_last_value["cell_data_trackericon"] = None 

 

 

def cell_data_progress(column, cell, model, row, data): 

    """Display progress bar with text""" 

    (value, state_str) = model.get(row, *data) 

    if func_last_value["cell_data_progress"][0] != value: 

        func_last_value["cell_data_progress"][0] = value 

        cell.set_property("value", value) 

 

    # Marked for translate states text are in filtertreeview 

    textstr = _(state_str) 

    if state_str != "Seeding" and value < 100: 

        textstr = "%s %.2f%%" % (textstr, value) 

 

    if func_last_value["cell_data_progress"][1] != textstr: 

        func_last_value["cell_data_progress"][1] = textstr 

        cell.set_property("text", textstr) 

 

 

def cell_data_queue(column, cell, model, row, data): 

    value = model.get_value(row, data) 

 

    if func_last_value["cell_data_queue"] == value: 

        return 

    func_last_value["cell_data_queue"] = value 

 

    if value < 0: 

        cell.set_property("text", "") 

    else: 

        cell.set_property("text", str(value + 1)) 

 

 

def cell_data_speed(cell, model, row, data, cache_key): 

    """Display value as a speed, eg. 2 KiB/s""" 

    try: 

        speed = model.get_value(row, data) 

    except AttributeError: 

        print("AttributeError") 

        import traceback 

        traceback.print_exc() 

    if func_last_value[cache_key] == speed: 

        return 

    func_last_value[cache_key] = speed 

 

    speed_str = "" 

    if speed > 0: 

        speed_str = common.fspeed(speed) 

    cell.set_property('text', speed_str) 

 

 

def cell_data_speed_down(column, cell, model, row, data): 

    """Display value as a speed, eg. 2 KiB/s""" 

    cell_data_speed(cell, model, row, data, "cell_data_speed_down") 

 

 

def cell_data_speed_up(column, cell, model, row, data): 

    """Display value as a speed, eg. 2 KiB/s""" 

    cell_data_speed(cell, model, row, data, "cell_data_speed_up") 

 

 

def cell_data_speed_limit(cell, model, row, data, cache_key): 

    """Display value as a speed, eg. 2 KiB/s""" 

    speed = model.get_value(row, data) 

 

    if func_last_value[cache_key] == speed: 

        return 

    func_last_value[cache_key] = speed 

 

    speed_str = "" 

    if speed > 0: 

        speed_str = common.fspeed(speed * 1024) 

    cell.set_property('text', speed_str) 

 

 

def cell_data_speed_limit_down(column, cell, model, row, data): 

    cell_data_speed_limit(cell, model, row, data, "cell_data_speed_limit_down") 

 

 

def cell_data_speed_limit_up(column, cell, model, row, data): 

    cell_data_speed_limit(cell, model, row, data, "cell_data_speed_limit_up") 

 

 

def cell_data_size(column, cell, model, row, data): 

    """Display value in terms of size, eg. 2 MB""" 

    size = model.get_value(row, data) 

    cell.set_property('text', common.fsize(size)) 

 

 

def cell_data_peer(column, cell, model, row, data): 

    """Display values as 'value1 (value2)'""" 

    (first, second) = model.get(row, *data) 

    # Only display a (total) if second is greater than -1 

    if second > -1: 

        cell.set_property('text', '%d (%d)' % (first, second)) 

    else: 

        cell.set_property('text', '%d' % first) 

 

 

def cell_data_time(column, cell, model, row, data): 

    """Display value as time, eg 1m10s""" 

    time = model.get_value(row, data) 

    if func_last_value["cell_data_time"] == time: 

        return 

    func_last_value["cell_data_time"] = time 

 

    if time <= 0: 

        time_str = "" 

    else: 

        time_str = common.ftime(time) 

    cell.set_property('text', time_str) 

 

 

def cell_data_ratio(cell, model, row, data, cache_key): 

    """Display value as a ratio with a precision of 3.""" 

    ratio = model.get_value(row, data) 

    # Previous value in cell is the same as for this value, so ignore 

    if func_last_value[cache_key] == ratio: 

        return 

    func_last_value[cache_key] = ratio 

    cell.set_property('text', "∞" if ratio < 0 else "%.3f" % ratio) 

 

 

def cell_data_ratio_seeds_peers(column, cell, model, row, data): 

    cell_data_ratio(cell, model, row, data, "cell_data_ratio_seeds_peers") 

 

 

def cell_data_ratio_ratio(column, cell, model, row, data): 

    cell_data_ratio(cell, model, row, data, "cell_data_ratio_ratio") 

 

 

def cell_data_ratio_avail(column, cell, model, row, data): 

    cell_data_ratio(cell, model, row, data, "cell_data_ratio_avail") 

 

 

def cell_data_date(column, cell, model, row, data): 

    """Display value as date, eg 05/05/08""" 

    date = model.get_value(row, data) 

 

    if func_last_value["cell_data_date"] == date: 

        return 

    func_last_value["cell_data_date"] = date 

 

    date_str = common.fdate(date) if date > 0.0 else "" 

    cell.set_property('text', date_str) 

 

 

def cell_data_date_or_never(column, cell, model, row, data): 

    """Display value as date, eg 05/05/08 or Never""" 

    value = model.get_value(row, data) 

 

    if func_last_value["cell_data_date_or_never"] == value: 

        return 

    func_last_value["cell_data_date_or_never"] = value 

 

    date_str = common.fdate(value) if value > 0.0 else _("Never") 

    cell.set_property('text', date_str)