about summary refs log tree commit diff stats
Commit message (Expand)AuthorAgeFilesLines
...
* travis: Build libgcrypt by handMichael Vetter2019-04-131-1/+9
* Use xenial on travisMichael Vetter2019-04-131-1/+1
* Merge pull request #1056 from paulfariello/feature/omemo_travisMichael Vetter2019-04-132-14/+15
|\
| * Add libgcrypt minimum version in configure error logPaul Fariello2019-04-131-2/+2
| * Look for gcry_md_extract (libgcrypt >= 1.7.0)Paul Fariello2019-04-131-1/+1
| * testPaul Fariello2019-04-131-0/+1
| * Build with libcmocka from packagesPaul Fariello2019-04-121-11/+1
| * Add manual build of libsignal in travisPaul Fariello2019-04-121-1/+11
|/
* Update travis from Ubuntu trusty to bionicMichael Vetter2019-04-121-1/+1
* Update travisMichael Vetter2019-04-122-5/+21
* Merge pull request #1053 from paulfariello/feature/random_resourceMichael Vetter2019-04-124-3/+27
|\
| * Add random string at the end of the default resourcePaul Fariello2019-04-124-3/+27
|/
* Revert "Set C99 standard in configure"Michael Vetter2019-04-121-1/+1
* Set C99 standard in configureMichael Vetter2019-04-121-1/+1
* Merge pull request #1039 from paulfariello/feature/omemoMichael Vetter2019-04-1148-103/+5084
|\
| * Support contact name in /omemo fingerprint commandPaul Fariello2019-04-101-4/+9
| * Fix issue with first encrypted messagePaul Fariello2019-04-101-1/+5
| * Try to start sessions with every jid in rosterPaul Fariello2019-04-103-0/+22
| * OMEMO should be written uppercasePaul Fariello2019-04-102-15/+15
| * Fix build on travisPaul Fariello2019-04-101-0/+2
| * Add /omemo char commandPaul Fariello2019-04-103-1/+25
| * Automatically starts OMEMO if one identity is trustedPaul Fariello2019-04-104-6/+80
| * Rework trusted fingerprint storagePaul Fariello2019-04-104-29/+90
| * Wait for discovery end to publish omemo devicelist and bundlePaul Fariello2019-04-1010-10/+59
| * Don't build OMEMO by defaultPaul Fariello2019-04-101-1/+2
| * Prefix static function with _Paul Fariello2019-04-101-41/+41
| * Ensure pre keys are generated if missing from long term storagePaul Fariello2019-04-101-24/+51
| * Rework MUC reflected message filteringPaul Fariello2019-04-1014-25/+64
| * Add OMEMO in prefs commandPaul Fariello2019-04-106-2/+34
| * Fix devicelist notification handlerPaul Fariello2019-04-102-6/+5
| * Add clear_device_list commandPaul Fariello2019-04-104-4/+28
| * Permanently store pre keysPaul Fariello2019-04-103-22/+119
| * Add support for missing from in bundle iqPaul Fariello2019-04-101-3/+9
| * Handle bundle publication error on publish-optionsPaul Fariello2019-04-105-23/+166
| * Ensure signal context is built on connectionPaul Fariello2019-04-101-20/+23
| * Don't use glib 2.58 funcPaul Fariello2019-04-101-3/+1
| * Ensure encrypted carbon of own message are marked as encryptedPaul Fariello2019-04-104-4/+42
| * Add required OMEMO stub for unit-testPaul Fariello2019-04-104-3/+73
| * Show all device fingerprint for current accountPaul Fariello2019-04-101-1/+1
| * Print fingerprint after trust and untrust commandPaul Fariello2019-04-101-0/+34
| * Temporarly disable check for publish-options supportPaul Fariello2019-04-101-6/+2
| * Add fingerprint autocompletionPaul Fariello2019-04-103-1/+49
| * Use /omemo fingerprint to show contact fingerprintsPaul Fariello2019-04-105-32/+96
| * Use connection_support to check for publish-options supportPaul Fariello2019-04-101-6/+2
| * Add OMEMO log commandPaul Fariello2019-04-104-0/+49
| * Add missing preferences for OMEMO logsPaul Fariello2019-04-101-0/+6
| * Add support for disconnect in OMEMOPaul Fariello2019-04-107-40/+140
| * Add OMEMO end commandPaul Fariello2019-04-104-0/+46
| * Handle absent muc memberPaul Fariello2019-04-101-0/+4
| * Revert "Ensure room isn't anonymous"Paul Fariello2019-04-102-5/+0
d6b4d301fcaccbc37a13746610a10149f0a1'>^
cfdbb9d6 ^
9cce9fab ^


8db3c4b1 ^

30b25795 ^
5599636d ^
30b25795 ^
cfdbb9d6 ^
9cce9fab ^
cfdbb9d6 ^
30b25795 ^
9cce9fab ^
30b25795 ^
cfdbb9d6 ^
9cce9fab ^










30b25795 ^
9cce9fab ^

30b25795 ^
9cce9fab ^

cfdbb9d6 ^
























9cce9fab ^

8db3c4b1 ^
9cce9fab ^
3201b163 ^
8db3c4b1 ^
cfdbb9d6 ^
0115ab10 ^
9cce9fab ^
2b82ef62 ^
3201b163 ^
8db3c4b1 ^
9cce9fab ^
3201b163 ^

9cce9fab ^


3201b163 ^

9cce9fab ^
3201b163 ^
9cce9fab ^
cfdbb9d6 ^
9cce9fab ^

3201b163 ^
9cce9fab ^
cfdbb9d6 ^


d3eff0a9 ^
cfdbb9d6 ^
9cce9fab ^


6f43de0a ^













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













                                                                          





                                                                        


                    




                                    

                              




                                     

                   
 

                        
                       

                     
                                             
                                          
                                    
        


                                                       
                       

                                        




                                                            

                              





                                                   





                                                       

















                                                         
 
                                        
                                                       
        






                                                
        
                                
                                

                                                                 



                                                           


                                       
                                                    






                                                                               
                                                                                   





                                                      
 


                                      

                                                               
                     
                                                                 
 
                                  
                              
 
                                              
                              
 
                                                      










                                                                        
                                 

                                                                      
                     

                                                                                  
























                                                                   

                                       
                                       
                              
 
                                           
 
                                                                      
                              
 
                                         
                                                       
                               

                                       


                                                                                    

                                    
                                                             
                                            
                                                             
                             

                                                                                     
                     
                                                     


                                        
                                   
                                   


                                                













                                                
# Copyright (c) 2009, 2010 hut <hut@lavabit.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

"""
The statusbar displays information about the current file and directory.

On the left side, there is a display similar to what "ls -l" would
print for the current file.  The right side shows directory information
such as the space used by all the files in this directory.
"""

from . import Widget
from pwd import getpwuid
from grp import getgrgid
from os import getuid
from time import strftime, localtime

from ranger.gui.bar import Bar

class StatusBar(Widget):
	__doc__ = __doc__
	owners = {}
	groups = {}
	timeformat = '%Y-%m-%d %H:%M'
	hint = None
	msg = None

	old_cf = None
	old_mtime = None
	old_hint = None
	result = None

	def __init__(self, win, column=None):
		Widget.__init__(self, win)
		self.column = column
	
	def notify(self, text, duration=4, bad=False):
		self.msg = Message(text, duration, bad)
	
	def draw(self):
		"""Draw the statusbar"""

		if self.hint and isinstance(self.hint, str):
			if self.old_hint != self.hint:
				self.need_redraw = True
			if self.need_redraw:
				self._draw_hint()
			return

		if self.old_hint and not self.hint:
			self.old_hint = None
			self.need_redraw = True

		if self.msg:
			if self.msg.is_alive():
				self._draw_message()
				return
			else:
				self.msg = None
				self.need_redraw = True

		try:
			mtime = self.env.cf.stat.st_mtime
		except:
			mtime = -1

		if not self.result:
			self.need_redraw = True

		if self.old_cf != self.env.cf:
			self.old_cf = self.env.cf
			self.need_redraw = True

		if self.old_mtime != mtime:
			self.old_mtime = mtime
			self.need_redraw = True

		if self.need_redraw:
			self.need_redraw = False

			self._calc_bar()
			self._print_result(self.result)
	
	def _calc_bar(self):
		bar = Bar('in_statusbar')
		self._get_left_part(bar)
		self._get_right_part(bar)
		bar.shrink_by_removing(self.wid)

		self.result = bar.combine()
	
	def _draw_message(self):
		self.win.erase()
		self.color('in_statusbar', 'message',
				self.msg.bad and 'bad' or 'good')
		self.addnstr(0, 0, self.msg.text, self.wid)

	def _draw_hint(self):
		self.win.erase()
		highlight = True
		space_left = self.wid
		starting_point = self.x
		for string in self.hint.split('//'):
			highlight = not highlight
			if highlight:
				self.color('in_statusbar', 'text', 'highlight')
			else:
				self.color('in_statusbar', 'text')

			try:
				self.addnstr(0, starting_point, string, space_left)
			except:
				break
			space_left -= len(string)
			starting_point += len(string)
#			if starting_point >= self.wid:
#				break

	def _get_left_part(self, bar):
		left = bar.left
		
		if self.column is not None:
			target = self.column.target.pointed_obj
		else:
			target = self.env.at_level(0).pointed_obj

		if target is None:
			return

		if target.accessible is False:
			return

		perms = target.get_permission_string()
		how = getuid() == target.stat.st_uid and 'good' or 'bad'
		left.add(perms, 'permissions', how)

		left.add_space()
		left.add(str(target.stat.st_nlink), 'nlink')
		left.add_space()
		left.add(self._get_owner(target), 'owner')
		left.add_space()
		left.add(self._get_group(target), 'group')
		left.add_space()

		if target.islink:
			how = target.exists and 'good' or 'bad'
			left.add('-> ' + target.readlink, 'link', how)
		else:
			left.add(strftime(self.timeformat,
					localtime(target.stat.st_mtime)), 'mtime')
	
	def _get_owner(self, target):
		uid = target.stat.st_uid

		try:
			return self.owners[uid]
		except KeyError:
			try:
				self.owners[uid] = getpwuid(uid)[0]
				return self.owners[uid]
			except KeyError:
				return str(uid)

	def _get_group(self, target):
		gid = target.stat.st_gid

		try:
			return self.groups[gid]
		except KeyError:
			try:
				self.groups[gid] = getgrgid(gid)[0]
				return self.groups[gid]
			except KeyError:
				return str(gid)

	def _get_right_part(self, bar):
		right = bar.right
		if self.column is None:
			return

		target = self.column.target

		if not target.content_loaded or not target.accessible:
			return

		pos = target.scroll_begin
		max_pos = len(target) - self.column.hei
		base = 'scroll'

		if target.marked_items:
			# Indicate that there are marked files. Useful if you scroll
			# away and don't see them anymore.
			right.add('Mrk', base, 'marked')
		elif max_pos > 0:
			if pos == 0:
				right.add('Top', base, 'top')
			elif pos >= max_pos:
				right.add('Bot', base, 'bot')
			else:
				right.add('{0:0>.0f}%'.format(100.0 * pos / max_pos),
						base, 'percentage')
		else:
			right.add('All', base, 'all')

	def _print_result(self, result):
		import _curses
		self.win.move(0, 0)
		for part in result:
			self.color(*part.lst)
			self.addstr(part.string)
		self.color_reset()

from time import time
class Message(object):
	elapse = None
	text = None
	bad = False

	def __init__(self, text, duration, bad):
		self.text = text
		self.bad = bad
		self.elapse = time() + duration
	
	def is_alive(self):
		return time() <= self.elapse