[Zerofile-svn] SF.net SVN: zerofile: [39] trunk/src
Status: Pre-Alpha
Brought to you by:
karl-bengtsson
|
From: <kar...@us...> - 2007-11-07 15:57:11
|
Revision: 39
http://zerofile.svn.sourceforge.net/zerofile/?rev=39&view=rev
Author: karl-bengtsson
Date: 2007-11-07 07:57:15 -0800 (Wed, 07 Nov 2007)
Log Message:
-----------
Various changes in this commit. The contact list should now be almost fully operational. Yay!
*) In ZeroFileMainWindow: Completed the methods for adding and removing from the contact list, as well as checking if a certain host is already listed.
*) In ZeroconfBrowsing: Rewrote the browsing code to account for the above. Also added handling of unregistering of services.
*) In XMPPLinkLocalHost: Modified the class to include some more attributes.
*) In ZeroFile: removed the 20 second deregistration. Now the program stays registered until it exits.
Modified Paths:
--------------
trunk/src/XMPPLinkLocalHost.java
trunk/src/ZeroFile.java
trunk/src/ZeroFileMainWindow.java
trunk/src/ZeroconfBrowsing.java
Modified: trunk/src/XMPPLinkLocalHost.java
===================================================================
--- trunk/src/XMPPLinkLocalHost.java 2007-11-07 15:20:24 UTC (rev 38)
+++ trunk/src/XMPPLinkLocalHost.java 2007-11-07 15:57:15 UTC (rev 39)
@@ -1,5 +1,4 @@
import com.apple.dnssd.DNSSD;
-import com.apple.dnssd.DNSSDException;
import com.apple.dnssd.DNSSDService;
import com.apple.dnssd.ResolveListener;
import com.apple.dnssd.TXTRecord;
@@ -56,32 +55,38 @@
}
public void updateData()
- throws DNSSDException, InterruptedException
{
- _r = DNSSD.resolve(0, DNSSD.UNIQUE, _serviceName, "_presence._tcp", "local", new ResolveListener()
+ try
{
- public void operationFailed(DNSSDService service,int errorCode)
+ _r = DNSSD.resolve(0, DNSSD.ALL_INTERFACES, _serviceName, "_presence._tcp", "local", new ResolveListener()
{
- System.out.println("Resolved failed " + errorCode);
- System.exit(-1);
- }
- public void serviceResolved(DNSSDService resolver, int flags, int ifIndex,
- String fullName, String hostName, int port, TXTRecord txtRecord)
- {
- _host = hostName;
- _port = port;
- System.out.println("Host resolved: " + hostName + ":" + port);
- System.out.println("Flags: " + flags + ", ifIndex: " + ifIndex + ", FQDN: " + fullName);
- for (int i = 0; i < txtRecord.size(); i++)
+ public void operationFailed(DNSSDService service,int errorCode)
{
- String key = txtRecord.getKey(i);
- String value = txtRecord.getValueAsString(i);
- if (key.length() > 0)
- System.out.println("\t" + key + "=" + value);
+ System.out.println("Resolved failed " + errorCode);
+ System.exit(-1);
}
- _r.stop();
- }
- });
+ public void serviceResolved(DNSSDService resolver, int flags, int ifIndex,
+ String fullName, String hostName, int port, TXTRecord txtRecord)
+ {
+ _host = hostName;
+ _port = port;
+ if (txtRecord != null)
+ {
+ if (txtRecord.contains("1st"))
+ _firstName = txtRecord.getValueAsString("1st").toString();
+ if (txtRecord.contains("last"))
+ _lastName = txtRecord.getValueAsString("last").toString();
+ if (txtRecord.contains("nick"))
+ _nickName = txtRecord.getValueAsString("nick").toString();
+ }
+ _r.stop();
+ }
+ });
+ }
+ catch (Exception e)
+ {
+ System.out.println("Error: " + e.getStackTrace().toString());
+ }
}
}
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-07 15:20:24 UTC (rev 38)
+++ trunk/src/ZeroFile.java 2007-11-07 15:57:15 UTC (rev 39)
@@ -1,10 +1,8 @@
import java.io.IOException;
-//import java.net.ServerSocket;
-
public class ZeroFile {
/**
- * @param name - The service name used by the registration class. Deprecated. Don't use.
+ * Main class of the program.
* @throws IOException
*/
public static void main(String[] args) throws IOException {
@@ -14,25 +12,10 @@
ZeroFileSettings.loadSettings();
try
{
- // Let system allocate us an available port to listen on
- //ServerSocket s = new ServerSocket(0);
- //ZeroconfRegistration.registerService(s.getLocalPort());
ZeroconfRegistration.registerService();
ZeroconfRegistration.set1st("Testar");
ZeroconfRegistration.setLast("Nisse");
ZeroconfBrowsing.startBrowsing();
- /*
- ZeroFileMainWindow.addContact("Test 1");
- ZeroFileMainWindow.addContact("Test 2");
- ZeroFileMainWindow.addContact("Test 3");
- ZeroFileMainWindow.addContact("Test 4");
- ZeroFileMainWindow.removeContact("Test 3");
- */
- Thread.sleep(5000);
- ZeroconfRegistration.setStatus("away");
- Thread.sleep(15000);
- ZeroconfBrowsing.stopBrowsing();
- ZeroconfRegistration.unregisterService();
}
catch(Exception e)
{
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-07 15:20:24 UTC (rev 38)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-07 15:57:15 UTC (rev 39)
@@ -1,5 +1,6 @@
import java.awt.*;
import java.awt.event.*;
+
import javax.swing.*;
public class ZeroFileMainWindow
@@ -17,17 +18,30 @@
private static JComboBox _statusLista;
private static DefaultListModel _contactListModel;
private static JList _contactList;
- static void addContact(Object c)
+
+ static boolean containsHost(XMPPLinkLocalHost h)
{
- _contactListModel.addElement(c);
+ for (int i = 0; i<_contactListModel.size(); i++)
+ if (((XMPPLinkLocalHost)_contactListModel.getElementAt(i)).getServiceName().equals(h.getServiceName()))
+ return true;
+ return false;
}
- static void removeContact(Object c)
+
+ static void addHost(XMPPLinkLocalHost h)
{
- _contactListModel.removeElement(c);
+ _contactListModel.addElement(h);
}
+
+ static void removeHost(XMPPLinkLocalHost h)
+ {
+ for (int i = 0; i<_contactListModel.size(); i++)
+ if (((XMPPLinkLocalHost)_contactListModel.getElementAt(i)).getServiceName().equals(h.getServiceName()))
+ _contactListModel.remove(i);
+ }
+
static void startMainWindow()
{
- // Grundkittet, JFrame + JMenuBar
+ // Basics, JFrame + JMenuBar
_mainWindowFrame = new JFrame();
_mainWindowFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_mainMenuBar = new JMenuBar();
@@ -57,19 +71,19 @@
_aboutMenuItem = new JMenuItem("About..");
_helpMenu.add(_aboutMenuItem);
- // Layout, storlekar, samt koppling av JMenuBar
+ // Layout, sizes, and the connection of the JMenuBar
_mainWindowFrame.setLayout(new GridLayout(0,1,1,1));
_mainWindowFrame.setMinimumSize(new Dimension(120,300));
_mainWindowFrame.setSize(new Dimension(150,400));
_mainWindowFrame.setJMenuBar(_mainMenuBar);
- // Statuslista
+ // Status list
String[] statusModes = {"Available","Away","Do not disturb"};
_statusLista = new JComboBox(statusModes);
_statusLista.setMaximumSize(new Dimension(20,100));
_mainWindowFrame.add(_statusLista);
- // Kontaktlista
+ // Contact list
_contactListModel = new DefaultListModel();
_contactList = new JList(_contactListModel);
_contactList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
@@ -77,7 +91,7 @@
_contactList.setSize(500,700);
_mainWindowFrame.add(_contactList);
- // Sm\x8All upp f\x9Anstret
+ // Show the window
_mainWindowFrame.setVisible(true);
}
}
\ No newline at end of file
Modified: trunk/src/ZeroconfBrowsing.java
===================================================================
--- trunk/src/ZeroconfBrowsing.java 2007-11-07 15:20:24 UTC (rev 38)
+++ trunk/src/ZeroconfBrowsing.java 2007-11-07 15:57:15 UTC (rev 39)
@@ -15,22 +15,16 @@
String name, String regType, String domain)
{
XMPPLinkLocalHost newHost = new XMPPLinkLocalHost(name);
- ZeroFileMainWindow.addContact(newHost);
- /*System.out.println("Yay, found: " + name + " at interface: " + ifIndex);
- try
+ if (!ZeroFileMainWindow.containsHost(newHost))
{
- ZeroconfResolving.getHost(name);
+ newHost.updateData();
+ ZeroFileMainWindow.addHost(newHost);
}
- catch (Exception e)
- {
- System.out.println("Error: " + e.getStackTrace());
- }*/
}
public void serviceLost(DNSSDService browser, int flags, int ifIndex,
String name, String regType, String domain)
{
- ZeroFileMainWindow.removeContact("name");
- //System.out.println("Lost: " + name);
+ ZeroFileMainWindow.removeHost(new XMPPLinkLocalHost(name));
}
});
System.out.println("Starting browsing...");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|