diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Tox/Tox_12.vcxproj | 2 | ||||
-rw-r--r-- | protocols/Tox/Tox_12.vcxproj.filters | 4 | ||||
-rw-r--r-- | protocols/Tox/res/resource.rc | bin | 4956 -> 7240 bytes | |||
-rw-r--r-- | protocols/Tox/src/common.h | 2 | ||||
-rw-r--r-- | protocols/Tox/src/resource.h | bin | 992 -> 1370 bytes | |||
-rw-r--r-- | protocols/Tox/src/tox_account.cpp | 19 | ||||
-rw-r--r-- | protocols/Tox/src/tox_events.cpp | 40 | ||||
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 130 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.cpp | 41 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 9 | ||||
-rw-r--r-- | protocols/Tox/src/tox_services.cpp | 14 | ||||
-rw-r--r-- | protocols/Tox/src/version.h | 2 |
12 files changed, 214 insertions, 49 deletions
diff --git a/protocols/Tox/Tox_12.vcxproj b/protocols/Tox/Tox_12.vcxproj index f633883d94..2f8f1bf09c 100644 --- a/protocols/Tox/Tox_12.vcxproj +++ b/protocols/Tox/Tox_12.vcxproj @@ -197,6 +197,7 @@ </PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClInclude Include="res\resource.h" />
<ClInclude Include="src\common.h" />
<ClInclude Include="src\resource.h" />
<ClInclude Include="src\tox\tox.h" />
@@ -214,6 +215,7 @@ <ClCompile Include="src\tox_account.cpp" />
<ClCompile Include="src\tox_events.cpp" />
<ClCompile Include="src\tox_instances.cpp" />
+ <ClCompile Include="src\tox_options.cpp" />
<ClCompile Include="src\tox_proto.cpp" />
<ClCompile Include="src\tox_services.cpp" />
<ClCompile Include="src\tox_contacts.cpp" />
diff --git a/protocols/Tox/Tox_12.vcxproj.filters b/protocols/Tox/Tox_12.vcxproj.filters index c47ae00fad..70da2bf03d 100644 --- a/protocols/Tox/Tox_12.vcxproj.filters +++ b/protocols/Tox/Tox_12.vcxproj.filters @@ -39,6 +39,7 @@ <ClInclude Include="src\tox_bootstrap.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="res\resource.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\tox_proto.cpp">
@@ -68,6 +69,9 @@ <ClCompile Include="src\tox_account.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\tox_options.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\resource.rc">
diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc Binary files differindex 54fa3d6340..8bbfd29f4b 100644 --- a/protocols/Tox/res/resource.rc +++ b/protocols/Tox/res/resource.rc diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h index 479bf8fbef..7aaddd04b4 100644 --- a/protocols/Tox/src/common.h +++ b/protocols/Tox/src/common.h @@ -13,6 +13,8 @@ #include <m_database.h>
#include <m_langpack.h>
+#include <m_clist.h>
+#include <m_options.h>
#include "tox\tox.h"
diff --git a/protocols/Tox/src/resource.h b/protocols/Tox/src/resource.h Binary files differindex 161dc416c0..c50928e27f 100644 --- a/protocols/Tox/src/resource.h +++ b/protocols/Tox/src/resource.h diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp index a406d8d55c..33b1f4a8ed 100644 --- a/protocols/Tox/src/tox_account.cpp +++ b/protocols/Tox/src/tox_account.cpp @@ -45,21 +45,12 @@ void CToxProto::ConnectionThread(void*) {
DoBootstrap();
- uint8_t name[TOX_MAX_NAME_LENGTH + 1];
- uint16_t namelen = tox_get_self_name(tox, name);
- name[namelen] = 0;
-
if (tox_isconnected(tox))
{
isConnected = true;
-
- char dataPath[MAX_PATH];
- mir_snprintf(dataPath, MAX_PATH, "%s\\%s.tox", VARS("%miranda_profile%\\%miranda_profilename%"), _T2A(m_tszUserName));
-
- SaveToxData(dataPath);
-
- char idstring3[200] = { 0 };
- get_id(tox, idstring3);
+
+ m_iStatus = m_iDesiredStatus = ID_STATUS_ONLINE;
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus);
break;
}
@@ -67,10 +58,10 @@ void CToxProto::ConnectionThread(void*) DoTox();
}
+ debugLogA("CToxProto::ConnectionThread: leaving");
+
if (!isTerminated && isConnected)
{
poolingThread = ForkThreadEx(&CToxProto::PollingThread, 0, NULL);
}
-
- debugLogA("CToxProto::ConnectionThread: leaving");
}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index 550cdd2999..d4ab8a8960 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -1,5 +1,45 @@ #include "common.h"
+int CToxProto::OnModulesLoaded(WPARAM, LPARAM)
+{
+ HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, this);
+
+ return 0;
+}
+
+INT_PTR CToxProto::OnAccountManagerInit(WPARAM, LPARAM lParam)
+{
+ return (INT_PTR)CreateDialogParam(
+ g_hInstance,
+ MAKEINTRESOURCE(IDD_ACCMGR),
+ (HWND)lParam,
+ &CToxProto::MainOptionsProc,
+ (LPARAM)this);
+}
+
+int CToxProto::OnOptionsInit(void *obj, WPARAM wParam, LPARAM lParam)
+{
+ CToxProto *proto = (CToxProto*)obj;
+
+ char *title = mir_t2a(proto->m_tszUserName);
+
+ OPTIONSDIALOGPAGE odp = { sizeof(odp) };
+ odp.hInstance = g_hInstance;
+ odp.pszTitle = title;
+ odp.dwInitParam = LPARAM(obj);
+ odp.flags = ODPF_BOLDGROUPS;
+ odp.pszGroup = LPGEN("Network");
+
+ odp.pszTab = LPGEN("Account");
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_MAIN);
+ odp.pfnDlgProc = MainOptionsProc;
+ Options_AddPage(wParam, &odp);
+
+ mir_free(title);
+
+ return 0;
+}
+
void CToxProto::OnFriendRequest(Tox *tox, const uint8_t *userId, 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 new file mode 100644 index 0000000000..f6e41bff31 --- /dev/null +++ b/protocols/Tox/src/tox_options.cpp @@ -0,0 +1,130 @@ +#include "common.h"
+
+INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+
+ switch (uMsg)
+ {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwnd);
+ {
+ proto = (CToxProto*)lParam;
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
+
+ ptrA username(proto->getStringA("Username"));
+ SetDlgItemTextA(hwnd, IDC_USERNAME, username);
+
+ ptrA dataPath(proto->getStringA("DataPath"));
+ if (!dataPath)
+ {
+ char defaultPath[MAX_PATH];
+ mir_snprintf(defaultPath, MAX_PATH, "%s\\Tox\\%s.dat", VARS("%miranda_userdata%"), _T2A(proto->m_tszUserName));
+ dataPath = mir_strdup(defaultPath);
+ }
+ SetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath);
+
+ ptrW groupName(proto->getWStringA(NULL, "DefaultGroup"));
+ SetDlgItemText(hwnd, IDC_GROUP, groupName);
+ SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, 64, 0);
+
+ /*if (proto->IsOnline())
+ {
+ EnableWindow(GetDlgItem(hwnd, IDC_USERNAME), FALSE);
+ EnableWindow(GetDlgItem(hwnd, IDC_DATAPATH), FALSE);
+ }*/
+ }
+ return TRUE;
+
+ case WM_COMMAND:
+ {
+ switch (LOWORD(wParam))
+ {
+ case IDC_USERNAME:
+ if ((HWND)lParam == GetFocus())
+ {
+ //EnableWindow(GetDlgItem(hwnd, IDC_USERNAME), !proto->IsOnline());
+ if (HIWORD(wParam) != EN_CHANGE) return 0;
+ char username[128];
+ GetDlgItemTextA(hwnd, IDC_USERNAME, username, SIZEOF(username));
+ SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
+ }
+ break;
+
+ case IDC_DATAPATH:
+ if ((HWND)lParam == GetFocus())
+ {
+ //EnableWindow(GetDlgItem(hwnd, IDC_DATAPATH), !proto->IsOnline());
+ if (HIWORD(wParam) != EN_CHANGE) return 0;
+ char dataPath[128];
+ GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
+ SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
+ }
+ break;
+
+ case IDC_BROWSE:
+ {
+ char dataPath[MAX_PATH];
+ GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
+
+ char filter[MAX_PATH] = "";
+ mir_snprintf(filter, MAX_PATH, "%s\0*.*\0", Translate("All Files (*.*)"));
+
+ OPENFILENAMEA ofn = { 0 };
+ ofn.lStructSize = sizeof(ofn);
+ ofn.hwndOwner = 0;
+ ofn.lpstrFilter = filter;
+ ofn.nFilterIndex = 1;
+ ofn.lpstrFile = dataPath;
+ ofn.lpstrTitle = Translate("Select data file");
+ ofn.nMaxFile = SIZEOF(dataPath);
+ ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR;
+ if (GetOpenFileNameA(&ofn) && dataPath[0])
+ {
+ SetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath);
+ }
+ }
+ break;
+
+ case IDC_GROUP:
+ {
+ if ((HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
+ return 0;
+ SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
+ }
+ break;
+ }
+ }
+ break;
+
+ case WM_NOTIFY:
+ if (reinterpret_cast<NMHDR*>(lParam)->code == PSN_APPLY)
+ {
+ //if (!proto->IsOnline())
+ {
+ char username[128];
+ GetDlgItemTextA(hwnd, IDC_USERNAME, username, SIZEOF(username));
+ proto->setString("Username", username);
+
+ char dataPath[128];
+ GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
+ proto->setString("DataPath", dataPath);
+ }
+
+ wchar_t groupName[128];
+ GetDlgItemText(hwnd, IDC_GROUP, groupName, SIZEOF(groupName));
+ if (lstrlen(groupName) > 0)
+ {
+ proto->setWString(NULL, "DefaultGroup", groupName);
+ Clist_CreateGroup(0, groupName);
+ }
+ else
+ proto->delSetting(NULL, "DefaultGroup");
+
+ return TRUE;
+ }
+ break;
+ }
+
+ return FALSE;
+}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 0af9bd0cc3..c20d1aa7e4 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -5,16 +5,11 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) : {
tox = tox_new(TOX_ENABLE_IPV6_DEFAULT);
- char idstring[200] = { 0 };
- get_id(tox, idstring);
-
- char dataPath[MAX_PATH];
- mir_snprintf(dataPath, MAX_PATH, "%s\\%s.tox", VARS("%miranda_profile%\\%miranda_profilename%"), _T2A(m_tszUserName));
-
- LoadToxData(dataPath);
-
- char idstring2[200] = { 0 };
- get_id(tox, idstring2);
+ ptrA dataPath(getStringA("DataPath"));
+ if (dataPath)
+ {
+ LoadToxData(dataPath);
+ }
tox_callback_friend_request(tox, OnFriendRequest, this);
tox_callback_friend_message(tox, OnFriendMessage, this);
@@ -24,15 +19,16 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) : tox_callback_user_status(tox, OnUserStatusChanged, this);
tox_callback_connection_status(tox, OnConnectionStatusChanged, this);
- CreateProtoService(PS_CREATEACCMGRUI, &CToxProto::CreateAccMgrUI);
+ CreateProtoService(PS_CREATEACCMGRUI, &CToxProto::OnAccountManagerInit);
}
CToxProto::~CToxProto()
{
- char dataPath[MAX_PATH];
- mir_snprintf(dataPath, MAX_PATH, "%s\\%s.tox", VARS("%miranda_profile%\\%miranda_profilename%"), _T2A(m_tszUserName));
-
- SaveToxData(dataPath);
+ ptrA dataPath(getStringA("DataPath"));
+ if (dataPath)
+ {
+ SaveToxData(dataPath);
+ }
tox_kill(tox);
}
@@ -69,9 +65,9 @@ DWORD_PTR __cdecl CToxProto::GetCaps(int type, MCONTACT hContact) case PFLAGNUM_4:
return PF4_SUPPORTTYPING;
case PFLAG_UNIQUEIDTEXT:
- return (INT_PTR)"User Id";
+ return (INT_PTR)"Tox ID";
case PFLAG_UNIQUEIDSETTING:
- return (DWORD_PTR)"UserId";
+ return (DWORD_PTR)"ToxID";
case PFLAG_MAXLENOFMESSAGE:
return TOX_MAX_MESSAGE_LENGTH;
}
@@ -154,4 +150,13 @@ int __cdecl CToxProto::SetAwayMsg(int iStatus, const PROTOCHAR* msg) { return 0; int __cdecl CToxProto::UserIsTyping(MCONTACT hContact, int type) { return 0; }
-int __cdecl CToxProto::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam) { return 0; }
\ No newline at end of file +int __cdecl CToxProto::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam)
+{
+ switch (iEventType)
+ {
+ case EV_PROTO_ONLOAD:
+ return OnModulesLoaded(wParam, lParam);
+ }
+
+ return 1;
+}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 3ebd7fe88b..502928419b 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -90,6 +90,10 @@ private: void __cdecl PollingThread(void*);
//events
+ int OnModulesLoaded(WPARAM, LPARAM);
+ INT_PTR __cdecl OnAccountManagerInit(WPARAM, LPARAM);
+ static int __cdecl OnOptionsInit(void *obj, WPARAM wParam, LPARAM lParam);
+
static void OnFriendRequest(Tox *tox, const uint8_t *userId, const uint8_t *message, const uint16_t messageSize, void *arg);
static void OnFriendMessage(Tox *tox, const int friendId, const uint8_t *message, const uint16_t messageSize, void *arg);
static void OnFriendNameChange(Tox *tox, const int friendId, const uint8_t *name, const uint16_t nameSize, void *arg);
@@ -106,7 +110,8 @@ private: void __cdecl SearchByUidAsync(void* arg);
//services
- INT_PTR __cdecl CreateAccMgrUI(WPARAM, LPARAM);
+
+
// utils
TOX_USERSTATUS MirandaToToxStatus(int status);
@@ -120,7 +125,7 @@ private: static void get_id(Tox *m, char *data);
// dialogs
- static INT_PTR CALLBACK AccountManagerProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ static INT_PTR CALLBACK MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
};
#endif //_TOX_PROTO_H_
\ No newline at end of file diff --git a/protocols/Tox/src/tox_services.cpp b/protocols/Tox/src/tox_services.cpp index dfd4907737..e74c41ff98 100644 --- a/protocols/Tox/src/tox_services.cpp +++ b/protocols/Tox/src/tox_services.cpp @@ -1,16 +1,2 @@ #include "common.h"
-INT_PTR CALLBACK CToxProto::AccountManagerProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- return FALSE;
-}
-
-INT_PTR CToxProto::CreateAccMgrUI(WPARAM, LPARAM lParam)
-{
- return (INT_PTR)CreateDialogParam(
- g_hInstance,
- MAKEINTRESOURCE(IDD_ACCMGR),
- (HWND)lParam,
- &CToxProto::AccountManagerProc,
- (LPARAM)this);
-}
\ No newline at end of file diff --git a/protocols/Tox/src/version.h b/protocols/Tox/src/version.h index d08f40b256..116da36745 100644 --- a/protocols/Tox/src/version.h +++ b/protocols/Tox/src/version.h @@ -8,7 +8,7 @@ #define __PLUGIN_NAME "Tox Protocol"
#define __FILENAME "Tox.dll"
#define __DESCRIPTION "Tox protocol support for Miranda NG."
-#define __AUTHOR "ForNeVeR, unsane"
+#define __AUTHOR "ForNeVeR, Mataes, unsane"
#define __AUTHOREMAIL ""
#define __AUTHORWEB "http://miranda-ng.org/p/Tox/"
#define __COPYRIGHT "© 2014 Miranda NG Team"
|