class ListModel
this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)
Attributes
archive_key[R]
background_legend[R]
base[R]
column_of_background[R]
column_of_child_key[R]
column_of_child_key2[R]
column_of_foreground[R]
column_of_gantt_duration[R]
column_of_gantt_group[R]
column_of_gantt_group_color[R]
column_of_gantt_partial[R]
column_of_gantt_percentage[R]
column_of_gantt_start[R]
column_of_gantt_successors[R]
column_of_id[R]
column_of_parent_key[R]
column_of_parent_key2[R]
column_of_sensitive[R]
column_of_visible[R]
data[RW]
filter[RW]
filtered_rowcount[RW]
foreground_legend[R]
headers[R]
headertypes[R]
key_child[R]
key_child2[R]
key_parent[R]
key_parent2[R]
list[RW]
list_key[R]
moditem[RW]
parentM[RW]
parentselected[RW]
rowcount[R]
rows_loaded[R]
show_archive[R]
sorter[R]
thread[R]
Public Class Methods
new(list)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 10 def initialize(list) @filter=nil @data=nil @id_index=Hash.new @sorter=nil @parentselected=nil @filtered_rowcount=0 @rowcount=0 @rows_loaded=nil @show_archive=false @list=list @remote_model=nil @key_parent=nil @key_parent2=nil @moditem=nil @base=nil @thread=nil @headers=Hash.new @headertypes=Array.new end
Public Instance Methods
add_iter()
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 631 def add_iter if table=guess_table(@querysql,'id') sql="insert into #{table}"; if @key_child sql="#{sql} set #{@key_child}=" if @key_parent=="id" sql="#{sql}'#{parentselected}'" else if parent_header=parentM.headers[@key_parent] and parent_iter=parentM.iter_at_cursor sql="#{sql}'#{parent_iter[parent_header["model_col"]]}'" end end sql="#{sql},#{moditem['additional_on_insert']}" if moditem['additional_on_insert'].length>0 else if lastt=@querysql.index('{parentselected}') last=@querysql.rindex('=',lastt)-1 temp1=@querysql[1 .. last] first=temp1.rindex(' ')+1 sql="#{sql} set "+@querysql[first .. last]+"='#{parentselected}'" sql=sql+", "+moditem['additional_on_insert'] if moditem['additional_on_insert'].length>0 else if moditem['additional_on_insert'].length>0 sql="#{sql} set #{moditem['additional_on_insert']}" else sql="#{sql} () VALUES()"; end end end end query(eeval("\"#{sql}\"")) inserted_id=qrow("select id from #{table} order by id desc limit 1")["id"].to_i row_modified(inserted_id) inserted_id end
alive?()
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 820 def alive? true end
change_value_of_id(iter_id, column_data, new_value)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 673 def change_value_of_id(iter_id, column_data, new_value) sql="update #{@base} set #{column_data}='#{new_value}' where #{@list_key}='#{iter_id}' limit 1" einfo("changing #{column_data.inspect} to #{new_value.inspect} updatesql: #{sql.inspect}","list") query(eeval("\"#{sql}\"")) row_modified(iter_id) end
change_value_of_iter(iter, column_data, new_value)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 666 def change_value_of_iter(iter, column_data, new_value) sql="update #{@base} set #{column_data}='#{new_value}' where #{@list_key}='#{iter[column_of_id]}' limit 1" einfo("changing #{column_data.inspect} to #{new_value.inspect} updatesql: #{sql.inspect}","list") query(eeval("\"#{sql}\"")) row_modified(iter[column_of_id]) end
change_value_of_path(path, column_data, new_value)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 680 def change_value_of_path(path, column_data, new_value) change_value_of_iter(@sorter.get_iter(path), column_data, new_value) end
create_skeleton()
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 170 def create_skeleton unless get_id edebug("can't update, no list_id set","list","error") return end # list.progress.pulse(list.get_id) # @thread=Thread.new{ begin drbmodel.unsubscribe(ManqodRPC.instance.to_s) unless @remote_model.nil? rescue => err ewarn("server model is gone") end begin @remote_model=manqod_db.moditem(get_id) rescue =>err eerror(backtrace_to_debug(err),'list') if reconnect_manqod_db retry else tell_exception("server is gone") end end @moditem=cache.get("#{get_id}moditem") @headers=cache.get("#{get_id}headers") @headertypes=cache.get("#{get_id}headertypes") moditem_attributes=cache.get("#{get_id}attributes") @querysql=moditem_attributes[:querySQL] @base=moditem_attributes[:base] @list_key=moditem_attributes[:list_key] @key_child=moditem_attributes[:child_key] @key_parent=moditem_attributes[:parent_key] @key_child2=moditem_attributes[:child_key2] @key_parent2=moditem_attributes[:parent_key2] @tree_key=moditem_attributes[:tree_key] @column_of_id=moditem_attributes[:column_of_id] @column_of_visible=moditem_attributes[:column_of_visible] @column_of_sensitive=moditem_attributes[:column_of_sensitive] @column_of_background=moditem_attributes[:column_of_background] @column_of_foreground=moditem_attributes[:column_of_foreground] @column_of_archive=moditem_attributes[:column_of_archive] @column_of_tree_parent=moditem_attributes[:column_of_tree_parent] @column_of_tree=moditem_attributes[:column_of_tree] @fetch_filter_key=moditem_attributes[:fetch_filter_key] @fetch_filter_value=moditem_attributes[:fetch_filter_value] @fetch_filter_negate=moditem_attributes[:fetch_filter_negate] @column_of_fetch_filter=moditem_attributes[:column_of_fetch_filter] @archive_key=moditem_attributes[:archive_key] drbmodel.subscribe(ManqodRPC.instance.to_s,self) @parentM=list.parentM.get_model if list.parentM if @tree_key @data = Gtk::TreeStore.new(*headertypes) else @data = Gtk::ListStore.new(*headertypes) end hdebug="#{hdebug}\nheadertypes: #{headertypes.inspect}\nheaders:[result]order<[editable]>[rgrp_id]\n" headers.delete_if{|key,val| hdebug="#{hdebug}[#{val['data']}]#{val['model_col']}#{val['editable'] == 'true' ? '[ed]' : ''}[#{val['rgrp_id']}]\n" val['rgrp_id'].to_i>0 && !Nick.instance.ingroup_id?(val['rgrp_id'].to_i) } edebug("#{hdebug}","list") @column_of_child_key=nil if @key_child && headers.has_key?(@key_child) @column_of_child_key=headers[@key_child]["model_col"] end @column_of_child_key2=nil if @key_child2 && headers.has_key?(@key_child2) @column_of_child_key2=headers[@key_child2]["model_col"] end #if child_key defined, but parent_key is not, we set parent_key=parentM.list_key @key_parent=parentM.list_key if @key_child && @key_parent.nil? #if child_key2 defined, but parent_key2 is not, we set parent_key2='id' @key_parent2=parentM.list_key if @key_child2 && @key_parent2.nil? @column_of_parent_key=nil if @key_parent && parentM && parentM.headers.has_key?(@key_parent) @column_of_parent_key=parentM.headers[@key_parent]["model_col"] end @column_of_parent_key2=nil if @key_parent2 && parentM && parentM.headers.has_key?(@key_parent2) @column_of_parent_key2=parentM.headers[@key_parent2]["model_col"] end @filter=Gtk::TreeModelFilter.new(@data) @filter.set_visible_column(column_of_visible) @sorter=Gtk::TreeModelSort.new(@filter) if sortcolumn=get_conf(get_id,0,"sortcolumn") and sortorder=get_conf(get_id,0,"sortorder") @sorter.set_sort_column_id(sortcolumn.to_i,sortorder=="asc" ? Gtk::SORT_ASCENDING : Gtk::SORT_DESCENDING) end if gantt_start=list.gtk_attribute('gantt_start') @column_of_gantt_start=headers[gantt_start] end if gantt_duration=list.gtk_attribute('gantt_duration') @column_of_gantt_duration=headers[gantt_duration] end if gantt_successors=list.gtk_attribute('gantt_successors') @column_of_gantt_successors=headers[gantt_successors] end if gantt_group=list.gtk_attribute('gantt_group') @column_of_gantt_group=headers[gantt_group] end if gantt_group=list.gtk_attribute('gantt_group') @column_of_gantt_group=headers[gantt_group] end if gantt_group_color=list.gtk_attribute('gantt_group_color') @column_of_gantt_group_color=headers[gantt_group_color] end if gantt_partial=list.gtk_attribute('gantt_partial') @column_of_gantt_partial=headers[gantt_partial] end if gantt_percentage=list.gtk_attribute('gantt_percentage') @column_of_gantt_percentage=headers[gantt_percentage] end @foreground_legend=cache.get("#{get_id}foreground") @background_legend=cache.get("#{get_id}background") list.set_info("created") # } # @thread.join end
data_iter_of_col_num(col_num,col_num_data)
click to toggle source
finds iter by col_num, col_num=colnum number to search for, col_num_data=the data we're looking for
# File lib/ListHolder/EditableList/DrbListModel.rb, line 138 def data_iter_of_col_num(col_num,col_num_data) found_iter=nil @data.each{|model,path,iter| if iter[col_num]==col_num_data found_iter=iter break end } found_iter end
data_of_column(colname,lid=list.get_cursor_id)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 163 def data_of_column(colname,lid=list.get_cursor_id) ret=nil if di=iter_of_id(lid) and col=headers[colname] ret=di[col["model_col"]] end end
display_lock(locked_id)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 121 def display_lock(locked_id) einfo("display lock called for: #{locked_id}") if iter=@id_index[locked_id] iter[@column_of_sensitive]=drbmodel.data[locked_id][@column_of_sensitive] list.changed list.notify_observers(list) end end
drbmodel()
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 45 def drbmodel begin @remote_model rescue =>err edebug("error: #{err}\n#{err.backtrace.joint("\n")}\n","list","error") end end
duplicate_iter(iter_to_dup)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 623 def duplicate_iter(iter_to_dup) drbmodel.duplicate_iter(iter_to_dup) end
filter_one_iter(iter)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 393 def filter_one_iter(iter) if @key_child.nil? || (@key_child && iter[@column_of_child_key] == @current_parent_key) || (@key_child2 && iter[@column_of_child_key2] == @current_parent_key2) filter_count=0 filter_hits=0 list.columns.each{|column| fl=get_conf(get_id,column.header["id"],"filter").to_s.upcase case column.header['type'] when 'gtk_combo', 'gtk_const_combo' then fl = (fl=="-1" or fl=="") ? "" : "=#{fl}" end #if timestamp, then we convert the comparision data to the timestamp format specified by attributes comp=case column.header['type'] when 'gtk_timestamp' then Time.at(iter[column.header["model_col"]]).strftime(column.timestamp_format).upcase else iter[column.header["model_col"]].to_s.upcase end if fl.length>0 filter_count=filter_count+1 filter_hits=filter_hits+ case column.header['type'] when 'gtk_int','Integer','gtk_float','gtk_progress','gtk_duration' then case fl[0].chr when "<" then comp.to_f < fl[1 .. fl.length].to_f ? 1: 0 when ">" then comp.to_f > fl[1 .. fl.length].to_f ? 1: 0 when "!" then comp.to_f != fl[1 .. fl.length].to_f ? 1: 0 when "=" then comp.to_f == fl[1 .. fl.length].to_f ? 1: 0 else comp.to_f == fl[0 .. fl.length].to_f ? 1: 0 end else case fl[0].chr when "=" then comp == fl[1 .. fl.length] ? 1: 0 when "<" then comp < fl[1 .. fl.length] ? 1: 0 when ">" then comp > fl[1 .. fl.length] ? 1: 0 when "!" then comp != fl[1 .. fl.length] ? 1: 0 else comp.index(fl) ? 1: 0 end end end } unless list.destroyed? iter[column_of_visible]=filter_hits == filter_count #make sure parent iters are visible, only when we're tree unhide_tree_parent_iters(iter) if @column_of_tree && iter[@column_of_visible] else iter[@column_of_visible]=false end iter[@column_of_visible] end
from_csv(filename)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 729 def from_csv(filename) separator=(list.gtk_attribute("csv_field_separator") ? list.gtk_attribute("csv_field_separator") : ',') skip_header_lines=(list.gtk_attribute("csv_skip_header_lines") ? list.gtk_attribute("csv_skip_header_lines").to_i : 1) row_counter=0 ids=Array.new IO.foreach(filename){|line| row=line.chomp.split(separator) row_counter+=1 if row_counter > skip_header_lines && row.size>0 sql="insert into #{base} set" comma=false #child key auto adding if @key_child comma=true sql="#{sql} #{@key_child}=" if @key_parent=="id" sql="#{sql}'#{parentselected}'" else if parent_header=parentM.headers[@key_parent] and parent_iter=parentM.iter_at_cursor sql="#{sql}'#{parent_iter[parent_header["model_col"]]}'" end end end #values list.columns.each{|col| if c=col.gtk_attribute("csv_column_number") sql="#{sql}#{comma ? ",": ""} #{col.header['data']}=\"#{row[c.to_i-1]}\"" comma=true end } sql="#{sql};" #unless sql.nil? sql="#{sql} #{moditem['additional_on_insert']}" if moditem['additional_on_insert'].length>0 query(sql) inserted_id=qrow("select id from #{base} order by id desc limit 1")["id"].to_i ids.push(inserted_id) end } drbmodel.rows_changed(ids,nick) if ids.size>0 edebug("csv loaded","list") end
get_id()
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 87 def get_id list.get_id end
iter2csv(iter)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 691 def iter2csv(iter) separator=(list.gtk_attribute("csv_field_separator") ? list.gtk_attribute("csv_field_separator") : ',') row="" list.columns.each{|col| case col.header["type"] when "gtk_const_text" then ct=col.renderer.get_display(iter[col.colnum].to_s) when "gtk_const_combo","gtk_combo" then ct=col.renderer.get_text_from_value(iter[col.colnum].to_s) else ct=case col.data_type.to_s when "Integer" then number_format(iter[col.colnum],0) when "Float" then number_format(iter[col.colnum],2) else iter[col.colnum].to_s end end row="#{row}#{ct.to_s}#{separator}" } row="#{row[0..row.length]}\n" end
iter_at_cursor()
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 159 def iter_at_cursor iter_of_id(list.get_cursor_id) if list.get_cursor_id end
iter_of_id(id_of_iter)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 148 def iter_of_id(id_of_iter) found_iter=nil @sorter.each{|model,path,iter| if iter[@column_of_id] == id_of_iter.to_i found_iter=iter break end } if @sorter found_iter end
load_data(notifier,ids=nil)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 446 def load_data(notifier,ids=nil) # @thread=Thread.new{ ids=[ids] if !ids.nil? and ids.class != Array ids.uniq! if ids.class == Array edebug("called for data_load for #{ids.inspect} by #{notifier}","list","info") begin we_have_server=drbmodel.alive? rescue => err if reconnect_manqod_db retry else tell_exception("server is gone") end end return unless we_have_server before=Time.now @rows_loaded=0 @rowcount=drbmodel.rowcount ffv=if @fetch_filter_value then eeval(@fetch_filter_value) else nil end edebug("fetch-filter: key:#{@fetch_filter_key}, value:#{@fetch_filter_value}=#{ffv}","list") if ids.nil? list.set_model(nil) list.set_info("0") @data.clear @id_index.clear parent_iter=parentM.iter_at_cursor if parentM @current_parent_key=if @column_of_parent_key and parent_iter parent_iter[@column_of_parent_key] end @current_parent_key2=if @column_of_parent_key2 and parent_iter parent_iter[@column_of_parent_key2] end list.progress.zero(list.object_id,0,@moditem["display"]) prep_time=Time.now.to_f-before.to_f before=Time.now ff=nil pkeys=Array.new # @thread=Thread.new{ keys=cache.get("#{@moditem["id"]}[ids]") keys.each{|v| pkeys.push("#{@moditem["id"]}[#{v}]")} ff=cache.get(pkeys) @rowcount=ff ? ff.size : 0 # } # @thread.join # ff=drbmodel.filtered_fetch2(ffv,@show_archive) fetch_time=Time.now.to_f-before.to_f list.progress.zero(list.object_id,@rowcount,@moditem["display"]) before=Time.now pkeys.each{|idx| row=ff[idx] eerror("row #{idx} is nil!","list") if row.nil? # next if !@show_archive && !@column_of_archive.nil? && row[@column_of_archive] next unless (@column_of_fetch_filter.nil? || ffv.nil? || (!@fetch_filter_negate && row[@column_of_fetch_filter].to_s == ffv.to_s ) || (@fetch_filter_negate && row[@column_of_fetch_filter].to_s != ffv.to_s) ) && row && (@column_of_archive.nil? || (@show_archive || !row[@column_of_archive])) #we recieve a row iter=if @tree_key then @data.append(@id_index[row[@column_of_tree].to_i]) else @data.append end begin row.each_pair{|key,val| iter[key]=val} rescue =>err # eerror("filling row: #{err}\n#{key.inspect}=>#{val}\niter:#{iter.inspect}, row:#{row.inspect}","list") end @id_index[row[@column_of_id].to_i]=iter @rows_loaded+=1 Thread.new{list.progress.step(list.object_id,@rows_loaded)} # Thread.pass } unless ff.nil? #nil if no keys found, the list is empty load_time=Time.now.to_f-before.to_f t=Time.new refilter filtert=Time.new.to_f-t.to_f update_time=Time.now.to_f-before.to_f enormal("total: #{@filtered_rowcount}/#{@rows_loaded}/#{@rowcount} (prep:"+sprintf("%.2fs",prep_time)+",fetch:"+sprintf("%.2fs",fetch_time)+",load:"+sprintf("%.2fs",load_time)+",refilter:"+sprintf("%.2fs",filtert)+")"+sprintf("%.2fs",update_time),"time") einfo("data loaded #{ids or 'all rows'}","list") else ids.each{|row_id| begin row=cache.get("#{@moditem["id"]}[#{row_id}]") # eerror("row #{row_id} is nil!","list") if row.nil? #row=drbmodel.data[row_id] if row && (@column_of_fetch_filter.nil? || ffv.nil? || (!@fetch_filter_negate && row[@column_of_fetch_filter].to_s == ffv.to_s ) || (@fetch_filter_negate && row[@column_of_fetch_filter].to_s != ff_value.to_s) ) && (@column_of_archive.nil? || (@show_archive || !row[@column_of_archive])) piter=@id_index[row[@column_of_tree].to_i] if iter=@id_index[row_id] #iter is found if iter && iter.parent!=piter edebug("current parent:#{iter.parent.inspect}!=new parent:#{piter.inspect} -> we remove iter, so we readd it later, thus reparenting it","list") parent_iter=iter.parent rec_save_childs(iter) iter=nil need_to_reload=true end end unless iter=@id_index[row_id] edebug("new iter, id:#{row_id.inspect}","list") if @tree_key then list.set_model(nil) if !piter.nil? and !piter.has_child? iter=@data.append(piter) else iter=@data.append end end begin row.each_pair{|key,val| iter[key]=val} rescue =>err edebug("filling one row: #{err}\n iter:#{iter}, row:#{row.inspect}, id:#{row_id}","list","error") end @id_index[row[@column_of_id].to_i]=iter @data.row_changed(iter.path,iter) reload_saved_childs if need_to_reload refilter(iter) else edebug("we were called to load_data of a non existing id:#{row_id}, which means it's archive and we don't show archive","list") if iter_to_remove=@id_index[row_id] data.remove(iter_to_remove) @id_index.delete(row_id) end end rescue Memcached::NotFound eerror("cache not found: id:[#{row_id}]") data.remove(iter_to_remove) @id_index.delete(row_id) rescue => err eerror("#{err}\n\t#{err.backtrace.join("\n\t")}") #we were called to load_data of a non existing id, which means it's deleted end } gstart=Time.new list.set_model(@sorter) if list.model.nil? gtime=Time.new.to_f-gstart.to_f Gtk.thread_protect{list.scroll_to_cursor} update_time=Time.now.to_f-before.to_f # edebug("total: #{@filtered_rowcount}/#{@rowcount} "+sprintf("%.2fs",update_time) + +sprintf("%.2fs",gtime),"time","normal") edebug("data loaded #{ids.inspect or 'all rows'}","list","info") end # } end
lock_iter(locked_id)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 91 def lock_iter(locked_id) counter=0 begin counter+=1 manqod_db.lock_id_of_base(@base,locked_id) rescue =>err resubscribe if counter==3 warn("server is gone",err.to_s,"list",ERROR,false,false) else retry end end end
locked?(locked_id)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 129 def locked?(locked_id) locked=nil if iter=@id_index[locked_id] locked=!iter[@column_of_sensitive] end locked end
move_down_id(uid)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 804 def move_down_id(uid) ordering=@list.gtk_attribute("ordering") if ordering && (ocolh=headers[ordering]) && (iter=iter_of_id(uid)) ocol=ocolh["model_col"] if next_iter=next_sorted_iter(iter) #only if we have next if nnext_iter=next_sorted_iter(next_iter) #middle of next and nnext change_value_of_iter(iter,ordering,(nnext_iter[ocol]+next_iter[ocol])/2.0) else #next +1 change_value_of_iter(iter,ordering,next_iter[ocol]+1) end end end end
move_up_id(uid)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 788 def move_up_id(uid) ordering=@list.gtk_attribute("ordering") if ordering && (ocolh=headers[ordering]) && (iter=iter_of_id(uid)) ocol=ocolh["model_col"] if prev_iter=prev_sorted_iter(iter) #only if we have previous if pprev_iter=prev_sorted_iter(prev_iter) #middle of prev and pprev change_value_of_iter(iter,ordering,(prev_iter[ocol]+pprev_iter[ocol])/2.0) else #prev -1 change_value_of_iter(iter,ordering,prev_iter[ocol]-1) end end end end
next_sorted_iter(iter)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 781 def next_sorted_iter(iter) pp=iter.path if pp.next! @sorter.get_iter(pp) end end
prev_sorted_iter(iter)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 774 def prev_sorted_iter(iter) pp=iter.path if pp.prev! @sorter.get_iter(pp) end end
print_iter(iter)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 52 def print_iter(iter) if iter headers.each_value{|h| print h['data'],":",iter[h['model_col']]," "} print "\n" end end
print_iter_of_id(id_to_print)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 66 def print_iter_of_id(id_to_print) print_iter(iter_of_id(id_to_print)) end
rec_save_childs(root_iter)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 604 def rec_save_childs(root_iter) @childs_to_readd=Array.new if @childs_to_readd.nil? if iter=root_iter.first_child loop{ @childs_to_readd.push(iter[column_of_id]) prev_iter=iter.clone finished=!iter.next! rec_save_childs(prev_iter) break if finished } end @id_index.delete(root_iter[@column_of_id].to_i) @data.remove(root_iter) end
refilter(one=nil)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 359 def refilter(one=nil) edebug("refiltering #{one}") if one.nil? list.set_model(nil) list.progress.zero(list.object_id,@rows_loaded,@moditem["display"]) @thread=Thread.new{ r=0 @data.each{|model, path, iter| filter_one_iter(iter) r+=1 list.progress.step(list.object_id,r) } } @thread.join einfo("refiltered","list") list.set_model(@sorter) list.progress.done(list.object_id) unless list.destroyed? list.scroll_to_cursor list.update_tip list.caller.list_panel.list_sum.calculate end else filter_one_iter(one) end #update filtered count @filtered_rowcount=0 @data.each{|model, path, iter| @filtered_rowcount+=1 if iter[column_of_visible]} list.set_info("#{@filtered_rowcount}/#{@rows_loaded}") self end
reload_saved_childs()
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 619 def reload_saved_childs load_data(self,@childs_to_readd) if @childs_to_readd.class == Array && @childs_to_readd.size>0 end
remove_iters(iters_to_remove)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 627 def remove_iters(iters_to_remove) drbmodel.remove_iters(iters_to_remove,nick) end
resubscribe()
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 58 def resubscribe begin @remote_model=manqod_db.moditem(get_id) drbmodel.subscribe(ManqodRPC.instance.to_s,self) rescue =>err retry if warn("can't reconnect to server",err.to_s,"list",ERROR,false,true) end end
row_modified(modified_id=list.get_cursor_id)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 684 def row_modified(modified_id=list.get_cursor_id) edebug("row modified #{modified_id.inspect}","list","info") drbmodel.rows_changed(modified_id,nick) list.set_model(@sorter) if list.model.nil? list.scroll_to_cursor end
set_show_archive(ns)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 770 def set_show_archive(ns) @show_archive=ns.to_s == 'true' end
to_csv(filename,ids=nil)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 710 def to_csv(filename,ids=nil) file = File.new(filename, "wb+") ids=Array.new separator=(list.gtk_attribute("csv_field_separator") ? list.gtk_attribute("csv_field_separator") : ',') row="" list.columns.each{|col| row="#{row}#{col.header['header']}#{separator}" } file.write("#{row[0..row.length]}\n") if @list.selection.count_selected_rows > 1 @list.selection.selected_each{|model, path, iter| file.write(iter2csv(iter))} else @filter.each{|model,path,iter| file.write(iter2csv(iter))} end file.close edebug("saved","list") end
to_s()
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 70 def to_s "model of #{list}" end
unhide_tree_parent_iters(iter)
click to toggle source
recursive show parent iters
# File lib/ListHolder/EditableList/DrbListModel.rb, line 441 def unhide_tree_parent_iters(iter) iter[@column_of_visible]=true; unhide_tree_parent_iters(iter.parent) if iter.parent end
unlock_iter(unlocked_id)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 106 def unlock_iter(unlocked_id) counter=0 begin counter+=1 manqod_db.unlock_id_of_base(@base,unlocked_id) rescue =>err resubscribe if counter==3 warn("server is gone",err.to_s,"list",ERROR,false,false) else retry end end end
update(notifier,ids=nil,notification_subect=nil)
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 300 def update(notifier,ids=nil,notification_subect=nil) =begin notifier is the notifier object ids is the array of ids which should be reloaded/deleted notification_subject: @column_of: lock/unlock the ids "structure": for create_skeleton "buttons" : reload the list buttons else : load ids =end before=Time.now case notifier.class.name when 'BarMenuItem' #we're main list, menu is notifying load_data(notifier) when 'MyEditableList' #we're sublist unless(@parentselected == notifier.get_cursor_id) @parentselected=notifier.get_cursor_id @current_parent_key=if @column_of_parent_key and parent_iter=parentM.iter_at_cursor parent_iter[@column_of_parent_key] end @current_parent_key2=if @column_of_parent_key2 and parent_iter parent_iter[@column_of_parent_key2] end if @key_child.nil? and !parentM.nil? tell_exception("[#{self}] add child_key attribute!","list","warning") load_data(notifier) end refilter end when 'String' case notification_subect when @column_of_sensitive einfo("lock change recieved: #{ids}","list") Gtk.thread_protect{display_lock(ids)} when "structure" einfo("structure change recieved","list") Gtk.thread_protect{@list.create_skeleton} Gtk.thread_protect{@list.update(self)} when "buttons" einfo("button change recieved","list") Gtk.thread_protect{list.caller.buttonholder.update(list,true)} else #no subject, we recieved just ids, so reload them einfo("load #{ids.inspect} recieved","list") Gtk.thread_protect{load_data(notifier,ids)} end when 'ListModel','ArchiveButton' #it's self load_data(self) else ewarn("unknown notifier #{notifier}[#{notifier.class.name}] for list update","list") end update_time=Time.now.to_f-before.to_f edebug("updateed in "+sprintf("%.2fs",update_time),"time","debug") end
wipe()
click to toggle source
# File lib/ListHolder/EditableList/DrbListModel.rb, line 74 def wipe begin drbmodel.unsubscribe(ManqodRPC.instance.to_s) if @remote_model && @remote_model.alive? rescue =>err eerror("unsubscribing: #{err}","main") end if @sorter and @sorter.sort_column_id edebug("saving model's sortcolumn: #{@sorter.sort_column_id}","config","info") set_conf(get_id,0,"sortcolumn",@sorter.sort_column_id[0]) set_conf(get_id,0,"sortorder",if @sorter.sort_column_id[1]==Gtk::SORT_ASCENDING then "asc" else "desc";end) end end