diff options
Diffstat (limited to 'protocols/VKontakte/src')
-rw-r--r-- | protocols/VKontakte/src/vk.h | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 9 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 24 |
4 files changed, 28 insertions, 9 deletions
diff --git a/protocols/VKontakte/src/vk.h b/protocols/VKontakte/src/vk.h index a61ba05cb1..20a5fec2e8 100644 --- a/protocols/VKontakte/src/vk.h +++ b/protocols/VKontakte/src/vk.h @@ -46,6 +46,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define VK_NODUMPHEADERS NLHRF_NODUMPHEADERS
#endif
+struct CVkProto;
+extern LIST<CVkProto> vk_Instances;
extern HINSTANCE hInst;
LPCSTR findHeader(NETLIBHTTPREQUEST *hdr, LPCSTR szField);
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index d2191bc4b2..e12e19ae5e 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -17,6 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h"
+static int sttCompareProtocols(const CVkProto *p1, const CVkProto *p2)
+{
+ return lstrcmp(p1->m_tszUserName, p2->m_tszUserName);
+}
+
+LIST<CVkProto> vk_Instances(1, sttCompareProtocols);
+
static COLORREF sttColors[] = { 0, 1, 2, 3, 4, 5, 6 };
CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) :
@@ -61,12 +68,14 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) : // Set all contacts offline -- in case we crashed
SetAllContactStatuses(ID_STATUS_OFFLINE);
+ vk_Instances.insert(this);
}
CVkProto::~CVkProto()
{
Netlib_CloseHandle(m_hNetlibUser); m_hNetlibUser = NULL;
UninitQueue();
+ vk_Instances.remove(this);
}
int CVkProto::OnModulesLoaded(WPARAM wParam, LPARAM lParam)
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 46c153491d..99398339e8 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -229,7 +229,7 @@ struct CVkProto : public PROTO<CVkProto> __forceinline LPCTSTR getGroup() const { return m_defaultGroup; }
__forceinline void setGroup(LPCTSTR grp) { m_defaultGroup = mir_tstrdup(grp); }
- UINT_PTR m_timer;
+ static UINT_PTR m_timer;
private:
friend struct AsyncHttpRequest;
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 028a7b585b..c8b5642ce9 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -17,6 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h"
+UINT_PTR CVkProto::m_timer;
+
char szBlankUrl[] = "http://api.vk.com/blank.html";
void CVkProto::ShutdownSession()
@@ -38,22 +40,23 @@ void CVkProto::ConnectionFailed(int iReason) ShutdownSession();
}
-static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR pObject, DWORD)
+static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD)
{
- CVkProto *ppro = (CVkProto*)pObject;
- ppro->SetServerStatus(ppro->m_iStatus);
+ for (int i=0; i < vk_Instances.getCount(); i++)
+ vk_Instances[i]->SetServerStatus(vk_Instances[i]->m_iStatus);
}
static void CALLBACK VKSetTimer(void *pObject)
{
- CVkProto *ppro = (CVkProto*)pObject;
- ppro->m_timer = SetTimer(NULL, (UINT_PTR)ppro, 870000, TimerProc);
+ CVkProto::m_timer = SetTimer(NULL, 0, 60000, TimerProc);
}
static void CALLBACK VKUnsetTimer(void *pObject)
{
CVkProto *ppro = (CVkProto*)pObject;
- KillTimer(NULL, ppro->m_timer);
+ if (CVkProto::m_timer)
+ KillTimer(NULL, CVkProto::m_timer);
+ CVkProto::m_timer = 0;
}
void CVkProto::OnLoggedIn()
@@ -62,7 +65,8 @@ void CVkProto::OnLoggedIn() SetServerStatus(m_iDesiredStatus);
// initialize online timer
- CallFunctionAsync(VKSetTimer, this);
+ if (!m_timer)
+ CallFunctionAsync(VKSetTimer, this);
}
void CVkProto::OnLoggedOut()
@@ -75,7 +79,11 @@ void CVkProto::OnLoggedOut() ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, ID_STATUS_OFFLINE);
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
- CallFunctionAsync(VKUnsetTimer, this);
+ bool bOnline = false;
+ for (int i=0; i < vk_Instances.getCount(); i++)
+ bOnline = bOnline&&vk_Instances[i]->IsOnline();
+ if(!bOnline)
+ CallFunctionAsync(VKUnsetTimer, this);
SetAllContactStatuses(ID_STATUS_OFFLINE);
m_chats.destroy();
}
|