Class: ProgressBar::KDE

Inherits:
Base
  • Object
show all
Defined in:
lib/progress-bar.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#i, #max, #startts, #text

Instance Method Summary collapse

Methods inherited from Base

#done_dur, #done_rel, #increment!, #total_dur

Constructor Details

#initialize(max, text = nil, title: nil, app_name: nil, app_icon_name: nil, unit: nil, is_cancable: nil, is_suspendable: nil, **_options) ⇒ KDE

Returns a new instance of KDE.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/progress-bar.rb', line 113

def initialize max, text = nil, title: nil,
			app_name: nil,
			app_icon_name: nil,
			unit: nil,
			is_cancable: nil,
			is_suspendable: nil,
			**_options

	super max, text
	text = @text
	text = nil   if text.nil?  or text.empty?
	title = nil  if title.nil? or title.empty?
	unit = ''    if unit.nil?  or unit.empty?
	@title, @text, @unit, @app_name, @app_icon_name, @is_cancable, @is_suspendable =
		title, text, unit, app_name || $0, app_icon_name || '', is_cancable, is_suspendable
	@errors = []
end

Instance Attribute Details

#busObject (readonly)

Returns the value of attribute bus.



111
112
113
# File 'lib/progress-bar.rb', line 111

def bus
  @bus
end

#serviceObject (readonly)

Returns the value of attribute service.



111
112
113
# File 'lib/progress-bar.rb', line 111

def service
  @service
end

#viewObject (readonly)

Returns the value of attribute view.



111
112
113
# File 'lib/progress-bar.rb', line 111

def view
  @view
end

Instance Method Details

#change_progressObject



154
155
156
157
# File 'lib/progress-bar.rb', line 154

def change_progress
	@view.setProcessedAmount i, @unit
	@view.setPercent done_rel
end

#change_textObject



150
151
152
# File 'lib/progress-bar.rb', line 150

def change_text
	@view.setInfoMessage text
end

#error(text) ⇒ Object



159
160
161
162
163
164
# File 'lib/progress-bar.rb', line 159

def error text
	#STDERR.puts @view.object.introspect
	#@view.setError text
	@view.setDescriptionField 0, "Error", text
	#@view.setInfoMessage "#{text}\nError: #{error}"
end

#finishObject



166
167
168
169
170
# File 'lib/progress-bar.rb', line 166

def finish
	return  if @finished
	@view.terminate ''
	@finished = true
end

#max=(value) ⇒ Object



172
173
174
175
# File 'lib/progress-bar.rb', line 172

def max= value
	super value
	@view.setTotalAmount value, @unit
end

#possible?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/progress-bar.rb', line 131

def possible?
	'KDE' == ENV['XDG_CURRENT_DESKTOP']
end

#startObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/progress-bar.rb', line 135

def start
	@finished = false
	@bus = DBus::SessionBus.instance
	@service = @bus['org.kde.JobViewServer']
	jvs = @service['/JobViewServer']['org.kde.JobViewServer']
	jvs.introspect
	flags = (@is_cancable ? 0x1 : 0) | (@is_suspendable ? 0x2 : 0)
	view_path = jvs.requestView @app_name, @app_icon_name, flags
	@view = @service[view_path] #['org.kde.JobViewV2']
	@view.introspect
	super
	@view.setTotalAmount @max, @unit
	self
end