Progress notification for connect and disconnect.

This commit is contained in:
plfiorini 2010-05-30 12:17:59 +00:00
parent 225957b2f6
commit 7757c0b64c
3 changed files with 40 additions and 5 deletions

View File

@ -27,6 +27,7 @@ void
GoogleTalkProtocol::OverrideSettings() GoogleTalkProtocol::OverrideSettings()
{ {
fServer = "talk.google.com"; fServer = "talk.google.com";
fPort = 0;
} }

View File

@ -155,16 +155,20 @@ JabberHandler::UpdateSettings(BMessage* msg)
fPassword = password; fPassword = password;
fServer = server; fServer = server;
fResource = resource; fResource = resource;
fPort = 5222;
// Give the add-on a change to override settings // Give the add-on a change to override settings
OverrideSettings(); OverrideSettings();
// Compose JID // Compose JID
BString jid = ComposeJID(); BString jid = ComposeJID();
fJid.setJID(jid.String());
// Register our client // Register our client
fClient = new gloox::Client(gloox::JID(jid.String()), fPassword.String()); fClient = new gloox::Client(fJid, fPassword.String());
fClient->setServer(fServer.String()); fClient->setServer(fServer.String());
if (fPort > 0)
fClient->setPort(fPort);
fClient->registerConnectionListener(this); fClient->registerConnectionListener(this);
fClient->registerMessageHandler(this); fClient->registerMessageHandler(this);
fClient->rosterManager()->registerRosterListener(this); fClient->rosterManager()->registerRosterListener(this);
@ -276,7 +280,7 @@ JabberHandler::_CacheAvatar(const char* id, const char* binimage, size_t length)
sha1.SetTo(hash, 256); sha1.SetTo(hash, 256);
BString oldSha1; BString oldSha1;
if (fAvatarCache.FindString("id", &oldSha1) != B_OK || oldSha1 == "" || sha1 != oldSha1) { if (fAvatarCache.FindString(id, &oldSha1) != B_OK || oldSha1 == "" || sha1 != oldSha1) {
// Replace old hash and save cache // Replace old hash and save cache
fAvatarCache.RemoveName(id); fAvatarCache.RemoveName(id);
fAvatarCache.AddString(id, sha1); fAvatarCache.AddString(id, sha1);
@ -340,14 +344,31 @@ JabberHandler::_AvatarChanged(const char* id, const char* filename)
return; return;
BMessage msg(IM_MESSAGE); BMessage msg(IM_MESSAGE);
if (fJid.bare() == id)
msg.AddInt32("im_what", IM_OWN_AVATAR_SET);
else {
msg.AddInt32("im_what", IM_AVATAR_SET); msg.AddInt32("im_what", IM_AVATAR_SET);
msg.AddString("protocol", kProtocolSignature);
msg.AddString("id", id); msg.AddString("id", id);
}
msg.AddString("protocol", kProtocolSignature);
msg.AddRef("ref", &ref); msg.AddRef("ref", &ref);
fServerMessenger->SendMessage(&msg); fServerMessenger->SendMessage(&msg);
} }
void
JabberHandler::_Progress(const char* title, const char* message, float progress)
{
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_PROGRESS);
msg.AddString("protocol", kProtocolSignature);
msg.AddString("title", title);
msg.AddString("message", message);
msg.AddFloat("progress", progress);
fServerMessenger->SendMessage(&msg);
}
CayaStatus CayaStatus
JabberHandler::_GlooxStatusToCaya(gloox::Presence::PresenceType type) JabberHandler::_GlooxStatusToCaya(gloox::Presence::PresenceType type)
{ {
@ -384,6 +405,12 @@ JabberHandler::onConnect()
msg.AddString("protocol", kProtocolSignature); msg.AddString("protocol", kProtocolSignature);
msg.AddInt32("status", CAYA_ONLINE); msg.AddInt32("status", CAYA_ONLINE);
fServerMessenger->SendMessage(&msg); fServerMessenger->SendMessage(&msg);
BString content(fUsername);
content << " has logged in!";
_Progress("Connected", content.String(), 1.0f);
fVCardManager->fetchVCard(fJid, this);
} }
@ -395,6 +422,10 @@ JabberHandler::onDisconnect(gloox::ConnectionError e)
msg.AddString("protocol", kProtocolSignature); msg.AddString("protocol", kProtocolSignature);
msg.AddInt32("status", CAYA_OFFLINE); msg.AddInt32("status", CAYA_OFFLINE);
fServerMessenger->SendMessage(&msg); fServerMessenger->SendMessage(&msg);
BString content(fUsername);
content << " has logged out!";
_Progress("Disconnected", content.String(), 1.0f);
} }
@ -618,7 +649,7 @@ JabberHandler::handleVCard(const gloox::JID& jid, const gloox::VCard* card)
return; return;
if (_SetupAvatarCache() == B_OK) if (_SetupAvatarCache() == B_OK)
// Cache avatar icon // Cache avatar icon and notify the change
_CacheAvatar(jid.bare().c_str(), photo.binval.c_str(), _CacheAvatar(jid.bare().c_str(), photo.binval.c_str(),
photo.binval.length()); photo.binval.length());
} }

View File

@ -57,6 +57,7 @@ protected:
BString fPassword; BString fPassword;
BString fServer; BString fServer;
BString fResource; BString fResource;
uint16 fPort;
private: private:
CayaProtocolMessengerInterface* CayaProtocolMessengerInterface*
@ -67,6 +68,7 @@ private:
fConnection; fConnection;
gloox::VCardManager* fVCardManager; gloox::VCardManager* fVCardManager;
gloox::JID fJid;
thread_id fRecvThread; thread_id fRecvThread;
BPath fCachePath; BPath fCachePath;
@ -82,6 +84,7 @@ private:
status_t _SaveAvatarCache(); status_t _SaveAvatarCache();
void _CacheAvatar(const char* id, const char* binval, size_t length); void _CacheAvatar(const char* id, const char* binval, size_t length);
void _AvatarChanged(const char*id, const char* filename); void _AvatarChanged(const char*id, const char* filename);
void _Progress(const char* title, const char* message, float progress);
virtual void onConnect(); virtual void onConnect();
virtual void onDisconnect(gloox::ConnectionError); virtual void onDisconnect(gloox::ConnectionError);