Class: Skype::MenuItem

Inherits:
AbstractObject show all
Defined in:
lib/skype/menuitem.rb

Constant Summary collapse

OBJECT_NAME =
'MENU_ITEM'

Instance Attribute Summary

Attributes included from AbstractObject::Get

#property2callback, #property2symbol

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractObject

inherited, #initialize, new, #to_s

Methods included from AbstractObject::Notify

#delNotify, #notify

Methods included from AbstractObject::Get

#def_parser, #notice

Methods included from AbstractObject::Invokers

#invoke_alter, #invoke_echo, #invoke_get, #invoke_one, #invoke_set

Constructor Details

This class inherits a constructor from Skype::AbstractObject

Class Method Details

.create(h, block = Proc.new) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
# File 'lib/skype/menuitem.rb', line 6

def create h, block=Proc.new
  raise ArgumentError unless h[:id] and h[:context] and h[:caption]
  #id, context, caption, hint=nil, icon=nil, enabled=nil, enableMultipleContacts=nil, &block
  res = Skype.invoke "CREATE MENU_ITEM #{h[:id]} CONTEXT #{h[:context]} CAPTION #{h[:caption]}#{h[:hint].nil? ? '' : " HINT #{h[:hint]}"}#{h[:icon].nil? ? '' : " ICON #{h[:icon]}"}#{h[:enable].nil? ? '' : " ENABLED #{h[:enabled]}"}#{h[:enableMultipleContacts].nil? ? '' : " ENABLE_MULTIPLE_CONTACTS #{h[:enableMultipleContacts]}"}"
  res == "MENU_ITEM #{h[:id]} CREATED"
  instance = new h[:id]
  instance.setNotify block if block
  instance
end

.delete(id) ⇒ Object



31
32
33
# File 'lib/skype/menuitem.rb', line 31

def delete id
  new(id).delete
end

.notified(msg) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/skype/menuitem.rb', line 20

def notified msg
  if msg =~ /^([^ ]+) CLICKED( ([^ ]+))? CONTEXT ([^ ]+)( CONTEXT_ID (.+))?$/m
    id = $1; context = $4; userID = $3; contextID = $6
    user = userID ? Skype.user(userID) : nil
    instance = new $1
    @notify[nil].call instance, context, user, contextID if @notify[nil]
    @notify[id].call instance, context, user, contextID if @notify[id]
    @@instance[self][id].notified instance, context, user, contextID if @@instance[self][id]
  end
end

.set_notify(sym = nil, block = Proc.new) ⇒ Object



16
17
18
# File 'lib/skype/menuitem.rb', line 16

def set_notify sym=nil, block=Proc.new
  @notify[sym] = block
end

Instance Method Details

#deleteObject



46
47
48
49
# File 'lib/skype/menuitem.rb', line 46

def delete
  res = Skype.invoke "DELETE MENU_ITEM #{@id}"
  res == "DELETE MENU_ITEM #{@id}"
end

#notified(instance, context, user, contextID) ⇒ Object



37
38
39
# File 'lib/skype/menuitem.rb', line 37

def notified instance, context, user, contextID
  @notify.call instance, context, user, contextID if @notify
end

#set_caption(caption) ⇒ Object Also known as: setCaption



51
52
53
54
# File 'lib/skype/menuitem.rb', line 51

def set_caption caption
  res = invoke "SET MENU_ITEM #{@id} CAPTION #{caption}"
  res == "MENU_ITEM #{@id} CAPTION \"#{caption}\""
end

#set_enabled(flag) ⇒ Object Also known as: setEnabled



63
64
65
66
# File 'lib/skype/menuitem.rb', line 63

def set_enabled flag
  res = invoke "SET MENU_ITEM #{@id} ENABLED #{flag._str}"
  res == "MENU_ITEM #{@id} ENABLED #{flag._str}"
end

#set_hint(hint) ⇒ Object Also known as: setHint



57
58
59
60
# File 'lib/skype/menuitem.rb', line 57

def set_hint hint
  res = invoke "SET MENU_ITEM #{@id} HINT #{hint}"
  res == "MENU_ITEM #{@id} HINT \"#{hint}\""
end

#set_notify(block = Proc.new) ⇒ Object Also known as: setNotify



41
42
43
# File 'lib/skype/menuitem.rb', line 41

def set_notify block=Proc.new
  @notify = block
end