class Ui_ChatMainWindow
Public Class Methods
new(parent = nil)
click to toggle source
Calls superclass method
# File examples/qdbus/chat/chat.rb, line 42 def initialize(parent = nil) super @m_nickname = "nickname" require 'ui_chatmainwindow.rb' setupUi(self) @sendButton.enabled = false connect(@messageLineEdit, SIGNAL('textChanged(QString)'), self, SLOT('textChangedSlot(QString)')) connect(@sendButton, SIGNAL('clicked(bool)'), self, SLOT('sendClickedSlot()')) connect(@actionChangeNickname, SIGNAL('triggered(bool)'), self, SLOT('changeNickname()')) connect(@actionAboutQt, SIGNAL('triggered(bool)'), self, SLOT('aboutQt()')) connect($qApp, SIGNAL('lastWindowClosed()'), self, SLOT('exiting()')) # add our D-Bus interface and connect to D-Bus ChatAdaptor.new(self) Qt::DBusConnection.sessionBus.registerObject("/", self) iface = ComTrolltechChatInterface.new(nil, nil, Qt::DBusConnection.sessionBus(), self) # connect(self, SIGNAL('message(QString,QString)'), self, SLOT('messageSlot(QString,QString)')) Qt::DBusConnection.sessionBus.connect(nil, nil, "com.trolltech.chat", "message", self, SLOT('messageSlot(QString,QString)')) connect(iface, SIGNAL('action(QString,QString)'), self, SLOT('actionSlot(QString,QString)')) require 'ui_chatsetnickname.rb' dialog = Ui_NicknameDialog.new dialog.cancelButton.visible = false dialog.exec @m_messages = [] @m_nickname = dialog.nickname.text.strip emit action(@m_nickname, "joins the chat") end
Public Instance Methods
aboutQt()
click to toggle source
# File examples/qdbus/chat/chat.rb, line 119 def aboutQt() Qt::MessageBox.aboutQt(self) end
actionSlot(nickname, text)
click to toggle source
# File examples/qdbus/chat/chat.rb, line 88 def actionSlot(nickname, text) msg = "* %s %s" % [nickname, text] @m_messages.push(msg) if @m_messages.length > 100 @m_messages.shift end rebuildHistory() end
changeNickname()
click to toggle source
# File examples/qdbus/chat/chat.rb, line 110 def changeNickname() dialog = Ui_NicknameDialog.new(self) if dialog.exec == Qt::Dialog::Accepted old = @m_nickname @m_nickname = dialog.nickname.text.strip emit action(old, "is now known as %s" % @m_nickname) end end
exiting()
click to toggle source
# File examples/qdbus/chat/chat.rb, line 123 def exiting() emit action(@m_nickname, "leaves the chat") end
messageSlot(nickname, text)
click to toggle source
# File examples/qdbus/chat/chat.rb, line 78 def messageSlot(nickname, text) msg = "<%s> %s" % [nickname, text] @m_messages.push(msg) if @m_messages.length > 100 @m_messages.shift end rebuildHistory() end
rebuildHistory()
click to toggle source
# File examples/qdbus/chat/chat.rb, line 73 def rebuildHistory() history = @m_messages.join("\n") @chatHistory.plainText = history end
sendClickedSlot()
click to toggle source
# File examples/qdbus/chat/chat.rb, line 102 def sendClickedSlot() # emit message(@m_nickname, messageLineEdit.text()) msg = Qt::DBusMessage.createSignal("/", "com.trolltech.chat", "message") msg << @m_nickname << @messageLineEdit.text() Qt::DBusConnection.sessionBus().send(msg) @messageLineEdit.text = "" end
textChangedSlot(newText)
click to toggle source
# File examples/qdbus/chat/chat.rb, line 98 def textChangedSlot(newText) @sendButton.enabled = !newText.empty? end