bf8e26fdc221 — cedricbonhomme 11 years ago
Added the possibility to save the conversation. Added messages for the status bar. And other improvements.
M source/authenticationAgent.py +25 -7
@@ 64,47 64,66 @@ class AuthenticationAgent(spade.Agent.Ag
 
         def _process(self):
             """
+            Process the request of client.
             """
             self.msg = None
 
             # Blocking receive indefinitely
             self.msg = self._receive(True)
 
-            # Check wether the message arrived
+            # Check wether the message arrived (incoming request from a client)
             if self.msg:
                 self.myAgent.outgoing_message = None
                 command = self.msg.getContent().split(':')
 
+                # REGISTRATION
                 if command[0] == "signin":
+                    print "Incomming signin request from", self.msg.getSender().getName()
                     xml = xmlParser.add_client(command[1], command[2], \
                                         command[3], command[4])
                     if xml == 'already_registered':
                         self.myAgent.outgoing_message = xml
+                        print "Request of", self.msg.getSender().getName(), "rejected:"
+                        print xml
                     else:
                         xmlParser.write(xml)
+                        print "Request of", self.msg.getSender().getName(), "accepted."
 
                 elif command[0] == "signout":
                     pass
 
+                # AUTHENTICATION
                 elif command[0] == "login":
+                    print "Incomming authentication request from", self.msg.getSender().getName()
                     if command[2] == xmlParser.get_password(command[1]):
                         ontology = xmlParser.get_ontology(command[1])
-                        self.myAgent.outgoing_message = "authentication_success:" +\
+                        # Provides the ontology to the client for the bevaviour
+                        # in charge of receiving incoming messages from other clients.
+                        self.myAgent.outgoing_message = "authentication_success:" + \
                                                             ontology
+                        print "Request of", self.msg.getSender().getName(), "accepted."
                     else:
                         self.myAgent.outgoing_message = "authentication_failed"
+                        print "Request of", self.msg.getSender().getName(), "rejected."
 
+                # ADDITION OF INTERLOCUTOR
                 elif command[0] == "addinterlocutor":
+                    print self.msg.getSender().getName(), "asked informations about", command[1]
                     pubkey = str(xmlParser.get_pub_key(command[1]))
                     ontology = str(xmlParser.get_ontology(command[1]))
 
+                    # Provides to the client (Bob) the ontology and RSA public key
+                    # of the new interlocutor (Alice).
                     self.myAgent.outgoing_message = "newinterlocutor:" + command[1] + \
                                             ":" + ontology + ":" + pubkey
 
+                print ""
+                # SEND the reply to the client.
                 if self.myAgent.outgoing_message != None:
-                    self.myAgent.receiver = self.msg.getSender().getName().split('@')[0]
+                    # Prepare the receiver AID
+                    self.myAgent.receiver = self.msg.getSender()
 
-                    # send the message with a OneShotBehaviour
+                    # Send the message with a OneShotBehaviour
                     self.myAgent.addBehaviour(self.myAgent.SendMessage(), None)
 
 

          
@@ 112,7 131,7 @@ class AuthenticationAgent(spade.Agent.Ag
 
     class SendMessage(spade.Behaviour.OneShotBehaviour):
         """
-        This behaviour is in charge of sending message (answers)
+        This behaviour is in charge of sending messages (answers)
         to the client.
         """
         def onStart(self):

          
@@ 123,8 142,7 @@ class AuthenticationAgent(spade.Agent.Ag
             Send a message.
             """
             # First, form the receiver AID
-            receiver = self.myAgent.search_agent_into_df( \
-                                service_name = self.myAgent.receiver)[0].getAID()
+            receiver = self.myAgent.receiver
 
             # Second, build the message
             self.msg = spade.ACLMessage.ACLMessage()          # Instantiate the message

          
M source/clientAgent.py +1 -1
@@ 79,7 79,7 @@ class ClientAgent(spade.Agent.Agent):
                 elif command[0] == "authentication_success":
                     self.myAgent.ontology = command[1]
                     self.myAgent.launch_behaviour_client()
-                    self.myAgent.gui.show_info("Authentication success")
+                    self.myAgent.gui.authentication_success()
 
                 elif command[0] == "authentication_failed":
                     self.myAgent.gui.show_info("Authentication failed")

          
R source/configurations/clients_informations.xml +0 -1
@@ 1,1 0,0 @@ 
-<?xml version="1.0" ?><clients><client><name>bob</name><password>5ed25af7b1ed23fb00122e13d7f74c4d8262acd8</password><ontology>ontoBOB1</ontology><pubkey>26132083131104328772915520935906375741258270791954907144762536711849699668443-39405459139698945953820799021932797301078095534722266488704157617712445066389</pubkey></client><client><name>alice</name><password>92ef57ba40706594b46425705e989cbc256d9724</password><ontology>ChatTout</ontology><pubkey>54454921728377717257547813832479245729136087241850165130075873362087690308127-65531769888088421015639757020470536864719945014583667952974249971550025211857</pubkey></client></clients>
  No newline at end of file

          
M source/simpleGui.py +33 -3
@@ 32,11 32,13 @@ under certain conditions; type `show c' 
 __copyright__ = "Copyright (c) 2010 Cedric Bonhomme"
 __license__ = "GPLv3"
 
+import os
 import time
 import pickle
 import hashlib
 import threading
 import tkMessageBox
+import tkFileDialog
 
 from Tkinter import *
 

          
@@ 133,7 135,7 @@ class SimpleGui(object):
         # Status bar
         self.status = Label(self.master, \
                 text = "You are not connected to the SPADE platform. " + \
-                "Connect to the platform via the File menu.", \
+                "Connect to the platform via the 'File' menu.", \
                 bd = 1, relief = SUNKEN, anchor = W)
         self.status.grid(row = 4, columnspan = 5, sticky = W+E+N+S, pady = 5)
 

          
@@ 168,14 170,13 @@ class SimpleGui(object):
         niveau.add_command(label = "Free to chat")
         niveau.add_command(label = "Not here")
         filemenu.add_separator()
-        filemenu.add_command(label = "Save conversation")
-        filemenu.add_separator()
         filemenu.add_command(label = "Quit", command = self.onClose)
 
         # Edit menu
         editmenu = Menu(self.menu, tearoff = 0)
         self.menu.add_cascade(label = "Edit", menu = editmenu)
         editmenu.add_command(label = "Clear conversation zone", command = self.clear_window)
+        editmenu.add_command(label = "Save conversation", command = self.save_conversation)
 
         # Management of interlocutors menu
         managementmenu = Menu(self.menu, tearoff = 0)

          
@@ 437,6 438,14 @@ class SimpleGui(object):
         ## displays the window and waits for its closure
         msg.wait_window(msg)
 
+    def authentication_success(self):
+        """
+        """
+        self.status.config(text = "You are now ready to chat. " + \
+                            "Select interlocutors via the" + \
+                            " 'Management of interlocutors' menu.")
+        self.show_info("Authentication success")
+
     def display_client_list(self):
         """Display the list of client in a new window.
         """

          
@@ 674,6 683,27 @@ class SimpleGui(object):
         """
         self.conversation_zone.delete(1.0, END)
 
+    def save_conversation(self):
+        """
+        Save the conversation in a file.
+        """
+        formats = [ \
+        ('Format', '*.txt'), \
+        ('All', '*.*') \
+        ]
+
+        text_file = tkFileDialog.asksaveasfile(parent = self.master, \
+            filetypes = formats, title = "Save the conversation", mode='w')
+        if text_file != None:
+            text = str(self.message_to_send.get(1.0, END).encode('utf-8'))
+            try:
+                text_file.write('%s' % text)
+                text_file.close()
+            except :
+                print "Writing error"
+            (filepath, filename) = os.path.split(text_file.name)
+            print text_file.name, "saved."
+
     def show_info(self, message):
         """
         Display an information message.