Subject: just posting my first (yet not functional) jabber client
Yup, it's not functional at all. It only can login to given server with and without SSL encryption with given resource and priority. I wrote it using Gtk interface (gtk-sharp-2.0), Here it is:
jabber.cs:
jabber.cs:
using System;
using agsXMPP;
class Connection : XmppClientConnection
{
public Connection(string jid, string pass, bool ssl, int pri)
{
Jid j = new Jid(jid);
this.OnLogin += new ObjectHandler(Login);
this.OnReadXml += new XmlHandler(ReadXML);
this.OnWriteXml += new XmlHandler(WriteXML);
this.OnError += new ErrorHandler(Error);
try
{
this.Server = j.Server;
this.Username = j.User;
this.Password = pass;
this.Priority = pri;
this.AutoAgents = false;
this.AutoRoster = false;
if(j.Resource != null)
{
this.Resource = j.Resource;
}
else
{
this.Resource = "no to pajechali!:P";
}
if(ssl)
{
Console.WriteLine("Connection is encrypted!:D");
this.Port = 5223;
this.UseSSL = ssl;
}
this.Open();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
this.Close();
}
}
private static void Error(object o, Exception ex)
{
Console.WriteLine(ex.Message);
}
public static void ReadXML(object o, string xml)
{
if(xml!="")
Console.WriteLine("RECV XML: " + xml );
}
public static void WriteXML(object o, string xml)
{
if(xml!="")
Console.WriteLine("SEND XML: " + xml );
}
private void Login(object o)
{
Console.WriteLine("logged in, sending presence");
this.SendMyPresence();
}
}
and gui.cs:using agsXMPP;
class Connection : XmppClientConnection
{
public Connection(string jid, string pass, bool ssl, int pri)
{
Jid j = new Jid(jid);
this.OnLogin += new ObjectHandler(Login);
this.OnReadXml += new XmlHandler(ReadXML);
this.OnWriteXml += new XmlHandler(WriteXML);
this.OnError += new ErrorHandler(Error);
try
{
this.Server = j.Server;
this.Username = j.User;
this.Password = pass;
this.Priority = pri;
this.AutoAgents = false;
this.AutoRoster = false;
if(j.Resource != null)
{
this.Resource = j.Resource;
}
else
{
this.Resource = "no to pajechali!:P";
}
if(ssl)
{
Console.WriteLine("Connection is encrypted!:D");
this.Port = 5223;
this.UseSSL = ssl;
}
this.Open();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
this.Close();
}
}
private static void Error(object o, Exception ex)
{
Console.WriteLine(ex.Message);
}
public static void ReadXML(object o, string xml)
{
if(xml!="")
Console.WriteLine("RECV XML: " + xml );
}
public static void WriteXML(object o, string xml)
{
if(xml!="")
Console.WriteLine("SEND XML: " + xml );
}
private void Login(object o)
{
Console.WriteLine("logged in, sending presence");
this.SendMyPresence();
}
}
using System;
using Gtk;
class Sharper
{
static bool ssltoggle = false;
static int priority;
static Entry jabberid;
static Entry password;
static CheckButton cb;
static SpinButton spinner;
static Button btn;
static Connection c;
static void Main()
{
Application.Init();
Window win = new Window("Sharper");
win.DeleteEvent += new DeleteEventHandler(Close);
HBox hb1 = new HBox(true, 2);
win.Add(hb1);
VBox vb1 = new VBox(true, 2);
hb1.Add(vb1);
jabberid = new Entry();
jabberid.Editable = true;
vb1.Add(jabberid);
jabberid.Show();
password = new Entry();
password.Editable = true;
password.Visibility = false;
password.InvisibleChar = '*';
vb1.Add(password);
password.Show();
spinner = new SpinButton(0, 9999, 1);
spinner.ValueChanged += new EventHandler(OnSpinnerValueChanged);
vb1.Add(spinner);
spinner.Show();
cb = new CheckButton("Encrypted connection");
cb.Toggled += new EventHandler(OnCheckToggled);
vb1.Add(cb);
cb.Show();
btn = new Button("ok");
btn.Clicked += new EventHandler(OnButtonClicked);
hb1.Add(btn);
btn.Show();
win.ShowAll();
Application.Run();
}
static private void Close(object obj, DeleteEventArgs args)
{
try
{
c.Close();
}
catch(Exception ex){}
Application.Quit();
}
static private void OnButtonClicked(object obj, EventArgs args)
{
if(jabberid.Text != "" && password.Text != "")
{
btn.Sensitive = false;
c = new Connection(jabberid.Text, password.Text, ssltoggle, priority);
}
}
static private void OnCheckToggled(object obj, EventArgs args)
{
if (cb.Active)
{
ssltoggle = true;
}
else
{
ssltoggle = false;
}
}
static private void OnSpinnerValueChanged(object obj, EventArgs args)
{
priority = spinner.ValueAsInt;
}
}
BTW, I had noticed that your library is badly documented (i use online documentation b'cause *chm documentation is quite unusable on Linux), please, fix it if you can
using Gtk;
class Sharper
{
static bool ssltoggle = false;
static int priority;
static Entry jabberid;
static Entry password;
static CheckButton cb;
static SpinButton spinner;
static Button btn;
static Connection c;
static void Main()
{
Application.Init();
Window win = new Window("Sharper");
win.DeleteEvent += new DeleteEventHandler(Close);
HBox hb1 = new HBox(true, 2);
win.Add(hb1);
VBox vb1 = new VBox(true, 2);
hb1.Add(vb1);
jabberid = new Entry();
jabberid.Editable = true;
vb1.Add(jabberid);
jabberid.Show();
password = new Entry();
password.Editable = true;
password.Visibility = false;
password.InvisibleChar = '*';
vb1.Add(password);
password.Show();
spinner = new SpinButton(0, 9999, 1);
spinner.ValueChanged += new EventHandler(OnSpinnerValueChanged);
vb1.Add(spinner);
spinner.Show();
cb = new CheckButton("Encrypted connection");
cb.Toggled += new EventHandler(OnCheckToggled);
vb1.Add(cb);
cb.Show();
btn = new Button("ok");
btn.Clicked += new EventHandler(OnButtonClicked);
hb1.Add(btn);
btn.Show();
win.ShowAll();
Application.Run();
}
static private void Close(object obj, DeleteEventArgs args)
{
try
{
c.Close();
}
catch(Exception ex){}
Application.Quit();
}
static private void OnButtonClicked(object obj, EventArgs args)
{
if(jabberid.Text != "" && password.Text != "")
{
btn.Sensitive = false;
c = new Connection(jabberid.Text, password.Text, ssltoggle, priority);
}
}
static private void OnCheckToggled(object obj, EventArgs args)
{
if (cb.Active)
{
ssltoggle = true;
}
else
{
ssltoggle = false;
}
}
static private void OnSpinnerValueChanged(object obj, EventArgs args)
{
priority = spinner.ValueAsInt;
}
}