summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-08-16 17:26:20 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-08-16 17:26:20 +0000
commit63afce56f08e031e45a6a33f56af0f312c8bfc91 (patch)
tree0cca881dcd3b05a80879c97d33c6de9e7b4919cd
parent2e93497d5b19b4fc46f84cb18267bce357e48747 (diff)
Tox: added tox icon
git-svn-id: http://svn.miranda-ng.org/main/trunk@10204 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--protocols/Tox/Tox_12.vcxproj3
-rw-r--r--protocols/Tox/Tox_12.vcxproj.filters5
-rw-r--r--protocols/Tox/res/resource.rcbin7344 -> 7880 bytes
-rw-r--r--protocols/Tox/res/tox.icobin0 -> 1035 bytes
-rw-r--r--protocols/Tox/src/common.h4
-rw-r--r--protocols/Tox/src/resource.hbin1370 -> 1460 bytes
-rw-r--r--protocols/Tox/src/tox_contacts.cpp35
-rw-r--r--protocols/Tox/src/tox_proto.cpp44
-rw-r--r--protocols/Tox/src/tox_proto.h7
-rw-r--r--protocols/Tox/src/tox_utils.cpp25
10 files changed, 112 insertions, 11 deletions
diff --git a/protocols/Tox/Tox_12.vcxproj b/protocols/Tox/Tox_12.vcxproj
index 8b6b97a696..8b1d524b3b 100644
--- a/protocols/Tox/Tox_12.vcxproj
+++ b/protocols/Tox/Tox_12.vcxproj
@@ -225,6 +225,9 @@
<ResourceCompile Include="res\resource.rc" />
<ResourceCompile Include="res\version.rc" />
</ItemGroup>
+ <ItemGroup>
+ <Image Include="res\tox.ico" />
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
diff --git a/protocols/Tox/Tox_12.vcxproj.filters b/protocols/Tox/Tox_12.vcxproj.filters
index 1a0e0d6ad7..780d1db603 100644
--- a/protocols/Tox/Tox_12.vcxproj.filters
+++ b/protocols/Tox/Tox_12.vcxproj.filters
@@ -83,4 +83,9 @@
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
+ <ItemGroup>
+ <Image Include="res\tox.ico">
+ <Filter>Resource Files</Filter>
+ </Image>
+ </ItemGroup>
</Project> \ No newline at end of file
diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc
index 3d7a1fdb1d..88dc79e806 100644
--- a/protocols/Tox/res/resource.rc
+++ b/protocols/Tox/res/resource.rc
Binary files differ
diff --git a/protocols/Tox/res/tox.ico b/protocols/Tox/res/tox.ico
new file mode 100644
index 0000000000..f78a145590
--- /dev/null
+++ b/protocols/Tox/res/tox.ico
Binary files differ
diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h
index 71a16fb1ae..d47f2401bf 100644
--- a/protocols/Tox/src/common.h
+++ b/protocols/Tox/src/common.h
@@ -21,6 +21,8 @@
#include <m_clist.h>
#include <m_options.h>
#include <m_netlib.h>
+#include <m_popup.h>
+#include <m_icolib.h>
#include "tox\tox.h"
@@ -30,6 +32,8 @@
extern HINSTANCE g_hInstance;
+#define MODULE "Tox"
+
#define TOX_SETTINGS_ID "ToxID"
#define TOX_SETTINGS_ADDRES "ToxAddress"
#define TOX_SETTINGS_GROUP "DefaultGroup"
diff --git a/protocols/Tox/src/resource.h b/protocols/Tox/src/resource.h
index c50928e27f..dbd8559738 100644
--- a/protocols/Tox/src/resource.h
+++ b/protocols/Tox/src/resource.h
Binary files differ
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index 4bad40f78e..fe02760f78 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -1,8 +1,18 @@
#include "common.h"
+WORD CToxProto::GetContactStatus(MCONTACT hContact)
+{
+ return getWord(hContact, "Status", ID_STATUS_OFFLINE);
+}
+
+bool CToxProto::IsContactOnline(MCONTACT hContact)
+{
+ return GetContactStatus(hContact) == ID_STATUS_ONLINE;
+}
+
void CToxProto::SetContactStatus(MCONTACT hContact, WORD status)
{
- WORD oldStatus = getWord(hContact, "Status", ID_STATUS_OFFLINE);
+ WORD oldStatus = GetContactStatus(hContact);
if (oldStatus != status)
{
setWord(hContact, "Status", status);
@@ -13,7 +23,7 @@ void CToxProto::SetAllContactsStatus(WORD status)
{
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
{
- setWord(hContact, "Status", status);
+ SetContactStatus(hContact, status);
}
}
@@ -112,4 +122,25 @@ void CToxProto::LoadContactList()
//tox_get_last_online
}
}
+}
+
+void CToxProto::SearchByIdAsync(void* arg)
+{
+ std::string clientId = mir_utf8encodeT((TCHAR*)arg);
+ clientId.erase(clientId.begin() + TOX_CLIENT_ID_SIZE * 2, clientId.end());
+
+ MCONTACT hContact = FindContact(clientId.c_str());
+ if (hContact)
+ {
+ ShowNotification(TranslateT("Contact already in your contact list"), 0, hContact);
+ ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+ return;
+ }
+
+ PROTOSEARCHRESULT psr = { sizeof(PROTOSEARCHRESULT) };
+ psr.flags = PSR_TCHAR;
+ psr.id = (TCHAR*)arg;
+
+ ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
+ ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
} \ No newline at end of file
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index bdf58e51d0..d63ea49b7a 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -26,6 +26,26 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) :
SetAllContactsStatus(ID_STATUS_OFFLINE);
hMessageProcess = 1;
+
+ // icons
+ wchar_t filePath[MAX_PATH];
+ GetModuleFileName(g_hInstance, filePath, MAX_PATH);
+
+ wchar_t sectionName[100];
+ mir_sntprintf(sectionName, SIZEOF(sectionName), _T("%s/%s"), LPGENT("Protocols"), LPGENT(MODULE));
+
+ char settingName[100];
+ mir_snprintf(settingName, SIZEOF(settingName), "%s_%s", MODULE, "main");
+
+ SKINICONDESC sid = { 0 };
+ sid.cbSize = sizeof(SKINICONDESC);
+ sid.flags = SIDF_ALL_TCHAR;
+ sid.ptszDefaultFile = filePath;
+ sid.pszName = settingName;
+ sid.ptszSection = sectionName;
+ sid.ptszDescription = LPGENT("Protocol icon");
+ sid.iDefaultIndex = -IDI_TOX;
+ Skin_AddIcon(&sid);
}
CToxProto::~CToxProto()
@@ -46,7 +66,7 @@ DWORD_PTR __cdecl CToxProto::GetCaps(int type, MCONTACT hContact)
case PFLAGNUM_4:
return PF4_IMSENDUTF | PF4_NOAUTHDENYREASON | PF4_FORCEAUTH | PF4_FORCEADDED;
case PFLAG_UNIQUEIDTEXT:
- return (INT_PTR)"Tox ID";
+ return (INT_PTR)MODULE" ID";
case PFLAG_UNIQUEIDSETTING:
return (DWORD_PTR)TOX_SETTINGS_ID;
case PFLAG_MAXLENOFMESSAGE:
@@ -114,10 +134,6 @@ int __cdecl CToxProto::AuthRequest(MCONTACT hContact, const PROTOCHAR* szMessage
std::string nick(username.begin(), username.end());
setString(hContact, "Nick", nick.c_str());
- /*uint8_t userstatus = tox_get_user_status(tox, friends[i]);
- int status = ToxToMirandaStatus((TOX_USERSTATUS)userstatus);
- SetContactStatus(hContact, status);*/
-
return 0;
}
@@ -133,7 +149,17 @@ int __cdecl CToxProto::FileResume(HANDLE hTransfer, int* action, const PROTOCHAR
int __cdecl CToxProto::GetInfo(MCONTACT hContact, int infoType) { return 0; }
-HANDLE __cdecl CToxProto::SearchBasic(const PROTOCHAR* id) { return 0; }
+HANDLE __cdecl CToxProto::SearchBasic(const PROTOCHAR* id)
+{
+ if (!this->IsOnline())
+ {
+ return 0;
+ }
+
+ ForkThread(&CToxProto::SearchByIdAsync, mir_tstrdup(id));
+
+ return (HANDLE)1;
+}
HANDLE __cdecl CToxProto::SearchByEmail(const PROTOCHAR* email) { return 0; }
HANDLE __cdecl CToxProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName) { return 0; }
@@ -155,9 +181,9 @@ HANDLE __cdecl CToxProto::SendFile(MCONTACT hContact, const PROTOCHAR* szDescrip
int __cdecl CToxProto::SendMsg(MCONTACT hContact, int flags, const char* msg)
{
- if (!IsOnline())
+ if (!IsOnline() || !hContact || !IsContactOnline(hContact))
{
- return 1;
+ return 0;
}
std::string toxId(getStringA(hContact, TOX_SETTINGS_ID));
@@ -171,7 +197,7 @@ int __cdecl CToxProto::SendMsg(MCONTACT hContact, int flags, const char* msg)
if (result < 0)
{
debugLogA("CToxProto::SendMsg: error sending message %i", result);
- return 1;
+ return 0;
}
return messageId;
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index d7e566998c..0d185ac143 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -114,6 +114,8 @@ private:
static void OnReadReceipt(Tox *tox, int32_t friendnumber, uint32_t receipt, void *arg);
// contacts
+ WORD GetContactStatus(MCONTACT hContact);
+ bool IsContactOnline(MCONTACT hContact);
void SetContactStatus(MCONTACT hContact, WORD status);
void SetAllContactsStatus(WORD status);
bool IsProtoContact(MCONTACT hContact);
@@ -124,10 +126,15 @@ private:
void LoadContactList();
+ void __cdecl SearchByIdAsync(void* arg);
+
// utils
TOX_USERSTATUS MirandaToToxStatus(int status);
int ToxToMirandaStatus(TOX_USERSTATUS userstatus);
+ static void ShowNotification(const wchar_t *message, int flags = 0, MCONTACT hContact = NULL);
+ static void ShowNotification(const wchar_t *caption, const wchar_t *message, int flags = 0, MCONTACT hContact = NULL);
+
HANDLE AddDbEvent(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob);
void RaiseAuthRequestEvent(DWORD timestamp, const char* toxId, const char* reason);
diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp
index 4fb527df27..9f47d67de1 100644
--- a/protocols/Tox/src/tox_utils.cpp
+++ b/protocols/Tox/src/tox_utils.cpp
@@ -33,6 +33,31 @@ int CToxProto::ToxToMirandaStatus(TOX_USERSTATUS userstatus)
return status;
}
+void CToxProto::ShowNotification(const wchar_t *caption, const wchar_t *message, int flags, MCONTACT hContact)
+{
+ if (Miranda_Terminated())
+ return;
+
+ if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1))
+ {
+ POPUPDATAW ppd = { 0 };
+ ppd.lchContact = hContact;
+ wcsncpy(ppd.lpwzContactName, caption, MAX_CONTACTNAME);
+ wcsncpy(ppd.lpwzText, message, MAX_SECONDLINE);
+ ppd.lchIcon = Skin_GetIcon("Tox_main");
+
+ if (!PUAddPopupW(&ppd))
+ return;
+ }
+
+ MessageBoxW(NULL, message, caption, MB_OK | flags);
+}
+
+void CToxProto::ShowNotification(const wchar_t *message, int flags, MCONTACT hContact)
+{
+ ShowNotification(TranslateT(MODULE), message, flags, hContact);
+}
+
HANDLE CToxProto::AddDbEvent(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob)
{
DBEVENTINFO dbei = { sizeof(dbei) };