summaryrefslogtreecommitdiff
path: root/protocols/Tox
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-08-14 19:56:42 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-08-14 19:56:42 +0000
commit29fcbd4c970c7b2aba1539519b8ec68f0370a1e2 (patch)
treeed4139f9b0ab7eb9d41ae2416a5cfd562ccea22f /protocols/Tox
parent14001c799e72b8eefa523f8ff7ce44c443c78db8 (diff)
Tox: more point to save tox data
git-svn-id: http://svn.miranda-ng.org/main/trunk@10184 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox')
-rw-r--r--protocols/Tox/res/resource.rcbin7240 -> 7344 bytes
-rw-r--r--protocols/Tox/src/tox_contacts.cpp4
-rw-r--r--protocols/Tox/src/tox_events.cpp10
-rw-r--r--protocols/Tox/src/tox_options.cpp5
-rw-r--r--protocols/Tox/src/tox_proto.cpp28
-rw-r--r--protocols/Tox/src/tox_proto.h4
-rw-r--r--protocols/Tox/src/tox_utils.cpp20
7 files changed, 49 insertions, 22 deletions
diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc
index 8bbfd29f4b..3d7a1fdb1d 100644
--- a/protocols/Tox/res/resource.rc
+++ b/protocols/Tox/res/resource.rc
Binary files differ
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index c0c9335d63..6cf642cca6 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -108,9 +108,9 @@ void CToxProto::LoadContactList()
std::string nick(username.begin(), username.end());
setString(hContact, "Nick", nick.c_str());
- uint8_t userstatus = tox_get_user_status(tox, friends[i]);
+ /*uint8_t userstatus = tox_get_user_status(tox, friends[i]);
int status = ToxToMirandaStatus((TOX_USERSTATUS)userstatus);
- SetContactStatus(hContact, status);
+ SetContactStatus(hContact, status);*/
}
}
}
diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp
index 8283e80c6a..d10e146aee 100644
--- a/protocols/Tox/src/tox_events.cpp
+++ b/protocols/Tox/src/tox_events.cpp
@@ -49,13 +49,15 @@ INT_PTR CToxProto::OnContactDeleted(WPARAM wParam, LPARAM)
std::vector<uint8_t> clientId = HexStringToData(toxId);
uint32_t number = tox_get_friend_number(tox, clientId.data());
- if (tox_del_friend(tox, number) == -1)
+ if (tox_del_friend(tox, number) == 0)
{
- return 1;
+ SaveToxData();
+
+ return 0;
}
}
- return 0;
+ return 1;
}
void CToxProto::OnFriendRequest(Tox *tox, const uint8_t *userId, const uint8_t *message, const uint16_t messageSize, void *arg)
@@ -66,6 +68,8 @@ void CToxProto::OnFriendRequest(Tox *tox, const uint8_t *userId, const uint8_t *
std::string toxId = proto->DataToHexString(clientId);
proto->RaiseAuthRequestEvent(time(NULL), toxId.c_str(), (char*)message);
+
+ proto->SaveToxData();
}
void CToxProto::OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t *message, const uint16_t messageSize, void *arg)
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp
index f4eb2e6e5d..74463dc454 100644
--- a/protocols/Tox/src/tox_options.cpp
+++ b/protocols/Tox/src/tox_options.cpp
@@ -107,6 +107,11 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,
GetDlgItemTextA(hwnd, IDC_USERNAME, username, SIZEOF(username));
proto->setString("Username", username);
+ if (tox_set_name(proto->tox, (uint8_t*)&username[0], strlen(username)) == 0)
+ {
+ proto->SaveToxData();
+ }
+
char dataPath[128];
GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
proto->setString("DataPath", dataPath);
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index a5e32c810f..11fea96f73 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -5,11 +5,12 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) :
{
tox = tox_new(TOX_ENABLE_IPV6_DEFAULT);
- ptrA dataPath(getStringA("DataPath"));
- if (dataPath)
- {
- LoadToxData(dataPath);
- }
+ LoadToxData();
+
+ std::vector<uint8_t> username(TOX_MAX_NAME_LENGTH);
+ tox_get_self_name(tox, &username[0]);
+ std::string nick(username.begin(), username.end());
+ setString("Nick", nick.c_str());
tox_callback_friend_request(tox, OnFriendRequest, this);
tox_callback_friend_message(tox, OnFriendMessage, this);
@@ -29,11 +30,7 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) :
CToxProto::~CToxProto()
{
- ptrA dataPath(getStringA("DataPath"));
- if (dataPath)
- {
- SaveToxData(dataPath);
- }
+ SaveToxData();
tox_kill(tox);
}
@@ -79,6 +76,8 @@ int __cdecl CToxProto::Authorize(HANDLE hDbEvent)
if (tox_add_friend_norequest(tox, &clientId[0]) >= 0)
{
+ SaveToxData();
+
return 0;
}
}
@@ -99,6 +98,8 @@ int __cdecl CToxProto::AuthRequest(MCONTACT hContact, const PROTOCHAR* szMessage
int32_t friendnumber = tox_add_friend(tox, &clientId[0], (uint8_t*)(char*)reason, strlen(reason));
if (friendnumber >= 0)
{
+ SaveToxData();
+
clientId.resize(TOX_CLIENT_ID_SIZE);
tox_get_client_id(tox, friendnumber, &clientId[0]);
std::string toxId = DataToHexString(clientId);
@@ -132,10 +133,12 @@ HWND __cdecl CToxProto::CreateExtendedSearchUI(HWND owner) { return 0; }
int __cdecl CToxProto::RecvContacts(MCONTACT hContact, PROTORECVEVENT*) { return 0; }
int __cdecl CToxProto::RecvFile(MCONTACT hContact, PROTOFILEEVENT*) { return 0; }
+
int __cdecl CToxProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre)
{
return (INT_PTR)AddDbEvent(hContact, EVENTTYPE_MESSAGE, pre->timestamp, DBEF_UTF, lstrlenA(pre->szMessage), (BYTE*)pre->szMessage);
}
+
int __cdecl CToxProto::RecvUrl(MCONTACT hContact, PROTORECVEVENT*) { return 0; }
int __cdecl CToxProto::SendContacts(MCONTACT hContact, int flags, int nContacts, MCONTACT* hContactsList) { return 0; }
@@ -198,7 +201,10 @@ int __cdecl CToxProto::SetStatus(int iNewStatus)
else
{
// set tox status
- tox_set_user_status(tox, MirandaToToxStatus(iNewStatus));
+ if (tox_set_user_status(tox, MirandaToToxStatus(iNewStatus)) == 0)
+ {
+ SaveToxData();
+ }
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index c61555c408..f3c258a22e 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -131,8 +131,8 @@ private:
std::vector<uint8_t> HexStringToData(std::string hex);
std::string DataToHexString(std::vector<uint8_t>);
- int LoadToxData(const char *path);
- int SaveToxData(const char *path);
+ int LoadToxData();
+ int SaveToxData();
// dialogs
static INT_PTR CALLBACK MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp
index 95743b9412..f9e315c9d3 100644
--- a/protocols/Tox/src/tox_utils.cpp
+++ b/protocols/Tox/src/tox_utils.cpp
@@ -13,7 +13,7 @@ TOX_USERSTATUS CToxProto::MirandaToToxStatus(int status)
break;
case ID_STATUS_OCCUPIED:
userstatus = TOX_USERSTATUS_BUSY;
- break;
+break;
default:
userstatus = TOX_USERSTATUS_INVALID;
break;
@@ -61,7 +61,7 @@ void CToxProto::RaiseAuthRequestEvent(DWORD timestamp, const char* toxId, const
/*blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), sid(ASCIIZ), reason(ASCIIZ)*/
DWORD cbBlob = (DWORD)
- (sizeof(DWORD) * 2 +
+ (sizeof(DWORD)* 2 +
strlen(toxId) +
strlen(reason) +
5);
@@ -109,8 +109,14 @@ std::string CToxProto::DataToHexString(std::vector<uint8_t> data)
return ss.str();
}
-int CToxProto::LoadToxData(const char *path)
+int CToxProto::LoadToxData()
{
+ ptrA path(getStringA("DataPath"));
+ if (!path)
+ {
+ return 0;
+ }
+
FILE *hFile = fopen(path, "rb");
if (hFile)
@@ -146,8 +152,14 @@ int CToxProto::LoadToxData(const char *path)
return 0;
}
-int CToxProto::SaveToxData(const char *path)
+int CToxProto::SaveToxData()
{
+ ptrA path(getStringA("DataPath"));
+ if (!path)
+ {
+ return 0;
+ }
+
FILE *hFile = fopen(path, "wb");
if (!hFile)