Exemplo n.º 1
0
 def add (self, User):
     if self.IDs.count(User.ID) == 0:
         if int(User.ID) >= 1000:
             self.IDs.append(User.ID)
             name = self.treestore.append(None, ["  " + User.name])
             self.treestore.append(name, [_(" ID: ") + User.ID])
             self.treestore.append(name, [_(" Known Since: ") + str(User.knownsince)])
Exemplo n.º 2
0
 def makeLabels(self):
     labels = [_("Server:"), _("Port:"), _("Alias:")]
     a = 1
     for label in labels:
         l = gtk.Label(label)
         self.table.attach(l, 0, 1, a, a + 1)
         l.show()
         a = a + 1
Exemplo n.º 3
0
 def startService(self, widget):
     host = self.hostText.get_text()
     port = int(self.portText.get_text())
     alias = self.aliasText.get_text()
     self.log.log(_("******** PRE-CONNECTION INFO *********"))
     self.log.log(_("%s is trying to connect to %s at port %s") % (APP_NAME, host, port))
     self.log.log(_("You are logging in under the name %s\n") % (alias,))
     self.log.log(_("********** CONNECTION INFO ***********"), LOG_CONN)
     runReactor(host, port, self.log, alias, self.messages, self.userPanel)
 def makeLabels(self):
     labels = [_("To:"), _("Chat:"), _("Message:")]
     a = 0
     for label in labels:
         l = gtk.Label(label)
         self.table.attach(l, 0, 1, a, a + 1)
         l.show()
         a = a + 1
         if a == 2:
             a = 4
Exemplo n.º 5
0
    def treeviewCallback(self, treeview, event, data=None):
        if event.type == gtk.gdk._2BUTTON_PRESS:
            x = int(event.x)
            y = int(event.y)

            treeselection = self.treeview.get_selection()
            (model, treeiter) = treeselection.get_selected()
            treeiter = self.tm.convert_iter_to_child_iter(None, treeiter)
            name = self.treestore.get_value(treeiter, 0)
            if name[0:5] != _(" ID: ") and name[0:14] != _(" Known Since: "):
                pm = privateMessage(str(name[2:]), self.messages, self.log)
 def connectionMade(self):
     self.factory.log.log(_("You are connected to the server!\n"), LOG_CONN)
     self.init = True
     self.message = 0
     self.pm = 0
     d = self.sendMessages()
     d.addCallback(self.sendMessages)
Exemplo n.º 7
0
    def makeTreeViews(self):
        self.treestore = gtk.TreeStore(str)
        self.tm = gtk.TreeModelSort(self.treestore)
        self.tm.set_sort_column_id(0, gtk.SORT_ASCENDING)

        self.treeview = gtk.TreeView(self.tm);
        self.tvcolumn = gtk.TreeViewColumn(_('Online Users'))
        self.treeview.append_column(self.tvcolumn)

        self.cell = gtk.CellRendererText()
        self.treeview.set_headers_clickable(True)
        self.treeview.connect("button_press_event", self.treeviewCallback, None)
        self.cellpb = gtk.CellRendererPixbuf()
        self.tvcolumn.pack_start(self.cellpb, True)
        self.tvcolumn.pack_start(self.cell, False)
        self.tvcolumn.add_attribute(self.cell, 'text', 0)
        self.tvcolumn.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
        self.tvcolumn.set_cell_data_func(self.cellpb, self.userImage)
        self.tvcolumn.set_sort_column_id(0)

        scrolled = gtk.ScrolledWindow()
        scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scrolled.set_shadow_type(gtk.SHADOW_IN)
        scrolled.add(self.treeview)

        self.table.attach(scrolled, 4, 6, 1, 14, gtk.FILL, gtk.FILL, 20)
        self.table.show_all()

        self.userPanel = userPanel(self.treestore)
Exemplo n.º 8
0
    def makeFrames(self):
        f = gtk.Frame(_("Client options"))
        f.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
        f.set_label_align(0.0, 0.0)
        self.table.attach(f, 0, 4, 0, 5)
        f.show()

        f = gtk.Frame(_("Chat"))
        f.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
        f.set_label_align(0.0, 0.0)
        self.table.attach(f, 0, 4, 5, 18)
        f.show()

        f = gtk.Frame(_("Users"))
        f.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
        f.set_label_align(0.0, 0.0)
        self.table.attach(f, 4, 6, 0, 18)
        f.show()
Exemplo n.º 9
0
    def makeButtons(self):
        b = gtk.Button(_("Connect"))
        b.connect("clicked", self.startService)
        self.table.attach(b, 2, 3, 2, 3)
        b.show()
        self.connectButton = b

        b = gtk.Button(_("Disconnect"))
        b.connect("clicked", self.stopService)
        self.table.attach(b, 3, 4, 2, 3)
        b.show()
        self.connectButton = b

        b = gtk.Button(_("Send"))
        b.connect("clicked", self.sendMessage)
        self.table.attach(b, 3, 4, 17, 18)
        b.show()
        self.sendButton = b
    def __init__(self, name, msgObject, log):
        self.to = name
        self.log = log
        self.messages = msgObject

        #initiate the container window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_icon(gtk.gdk.pixbuf_new_from_file_at_size("user_icon.gif", 14, 16))
        self.window.set_resizable(True)
        self.window.connect("destroy", self.closeWindow)
        self.window.set_title(_("Private conversation with %s") % (name,))
        self.window.set_border_width(20)
        self.window.show()

        #adding widgets
        self.table = gtk.Table(5, 5, True)
        self.makeLabels()
        self.makeEntries()
        self.makeTextArea()
        self.makeFrames()
        self.makeButtons()

        self.window.add(self.table)
        self.table.show()
 def makeButtons(self):
     b = gtk.Button(_("Send"))
     b.connect("clicked", self.sendMessage)
     self.table.attach(b, 4, 5, 4, 5)
     b.show()
    def dataReceived(self, data):
        if self.init:
            self.factory.log.log(_("********** SERVER MESSAGE **********"), LOG_SERVER)
            block = data.split("\r\n\r\n")
            welcome = block[0]
            self.factory.log.log(welcome, LOG_SERVER)

            connData = block[1]
            connData = connData.split("\r\n")
            for lines in connData:
                if lines[0:3] == "UID":
                    params = lines.split(" ")
                    self.factory.Users.usersEver = params[2]
                    self.factory.Users.usersOnline = params[3]
                    self.factory.Users.addUser(params[1], self.factory.alias)
            self.factory.log.log(_("There are currently %s users online. This server had %s logins\n") % (params[3], params[2]), LOG_SERVER)
            self.factory.log.log(_("********** JOINING CHAT **********"), LOG_INFO)
            self.sendMsg("USER "  + self.factory.alias)
            self.init = False
        else:
            if data[0:7] == "USER OK":
                self.factory.log.log(_("You've succesfully authenticated yourself on the server\n"), LOG_INFO)
                self.sendMsg("JOIN CHAT")
            elif data[0:9] == "JOIN CHAT":
                block = data.split("\r\n\r\n")
                params = block[0].split(" ")
                try:
                    ID = params[3]
                except:
                    self.factory.log.log("You've joined the chat as " + self.factory.alias + "\n", LOG_INFO)
                    return
                try:
                    name = params[4]
                    name = name.split("\n")
                    self.factory.log.log(_("%s joined the chat!") % (name[0],), LOG_RECV)
                    if name[0] == self.factory.alias:
                        self.sendMsg("USERLIST")
                except:
                    name[0] = "NameNotSet"
                self.factory.Users.addUser(ID, name[0], True)
            elif data[0:8] == "USERLIST":
                lines = data.split("\r\n")
                for block in lines:
                    params = block.split("\t")
                    try:
                        ID = params[1]
                    except:
                        ID = -1
                    try:
                        name = params[2]
                    except:
                        name = "NameNotSet"
                    self.factory.Users.addUser(ID, name, True)
            elif data[0:8] == "CONN UID":
                params = data.split(" ")
            elif data[0:8] == "EXIT UID":
                data = data.split("\n")
                data = data[0]
                params = data.split(" ")
                try:
                    ID = params[2]
                    name = self.factory.Users.getName(ID)
                    if name != "Unknown User":
                        self.factory.log.log(_("%s left the premises") % (name,), LOG_RECV)
                        self.factory.Users.removeUser(ID)
                except:
                    params = ""
            elif data[0:6] == "MSG PM":
                block = data.split("\n")
                params = block[0].split(" ")
                fromUser = params[2]
                toUser = params[3]
                msg = unquote_plus(params[4])
                if self.factory.alias != fromUser:
                    self.factory.log.plog(fromUser, msg, LOG_PM_RECV)
                else:
                    self.factory.log.plog(toUser, msg, LOG_PM_SENT)

            elif data[0:13] == "MSG CHAT UID ":
                block = data.split("\r\n\r\n")
                params = block[0].split(" ")
                msg = params[4].split("\r\n")
                msg = msg[0]
                msg = unquote_plus(msg)
                if msg[0:3] == "/me":
                    self.factory.log.log(self.factory.Users.getName(params[3]) + msg[3:], LOG_MSG)
                else:
                    self.factory.log.log(self.factory.Users.getName(params[3]) + " >>> " + msg, LOG_MSG)

            else:
                self.factory.log.log("[" + str(self.factory.pid) + "] " +data, LOG_ERR)
 def clientConnectionFailed(self, reason, bla):
     self.log.log(_("Couldn't connect...\n"), LOG_ERR)
Exemplo n.º 14
0
 def stopService(self, widget):
     self.log.log(_("****** DISCONNECTED FROM SERVER ******"))
     stopReactor()
 def closeWindow(self, widget):
     print _("Exiting private message")
 def connectionLost(self, reason):
     self.factory.log.log(_("\n\n===Lost connection to the server ==="), LOG_CONN)
     self.factory.Users.clear()
Exemplo n.º 17
0
 def getName(self, ID):
     for user in self.users:
         if user.ID == ID:
             return user.name
     return _("Unknown User (%s)") % (ID,)