예제 #1
0
int FillList(WPARAM, LPARAM)
{

	if (options.logging)
		CallService(PLUG "/Log", (WPARAM)_T("ping address list reload"), 0);

	PINGLIST pl;
	CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);

	SendMessage(list_hwnd, WM_SETREDRAW, FALSE, 0);
	{
		mir_cslock lck(data_list_cs);
		data_list = pl;
		SendMessage(list_hwnd, LB_RESETCONTENT, 0, 0);

		int index = 0;
		for (pinglist_it j = data_list.begin(); j != data_list.end(); ++j, index++) {
			SendMessage(list_hwnd, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)&(*j));
		}
		set_list_changed(true);

		list_size = data_list.size();
	}
	SendMessage(list_hwnd, WM_SETREDRAW, TRUE, 0);

	InvalidateRect(list_hwnd, 0, FALSE);

	SetEvent(hWakeEvent);

	if (!ServiceExists(MS_CLIST_FRAMES_ADDFRAME) && options.attach_to_clist)
		UpdateFrame();

	return 0;
}
예제 #2
0
// call with list_cs locked
void write_ping_addresses() {
	int index = 0;
	for(PINGLIST::iterator i = list_items.begin(); i != list_items.end(); i++, index++) {
		i->index = index;
		write_ping_address(&(*i));
	}
}
예제 #3
0
void reset_myhandle() {
	EnterCriticalSection(&list_cs);
	set_changing_clist_handle(true);
	for(PINGLIST::iterator i = list_items.begin(); i != list_items.end(); i++) {
		DBWriteContactSettingString(i->hContact, "CList", "MyHandle", i->pszLabel);
	}
	set_changing_clist_handle(false);
	LeaveCriticalSection(&list_cs);
}
예제 #4
0
INT_PTR PingDisableAll(WPARAM wParam, LPARAM lParam) {
	PINGLIST pl;
	CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
	for(PINGLIST::Iterator i = pl.start(); i.has_val(); i.next()) {
		i.val().status = PS_DISABLED;
		i.val().miss_count = 0;
	}
	CallService(PLUG "/SetPingList", (WPARAM)&pl, 0);
	return 0;
}
예제 #5
0
파일: utils.cpp 프로젝트: Seldom/miranda-ng
INT_PTR PingDisableAll(WPARAM, LPARAM) {
	PINGLIST pl;
	CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
	for (pinglist_it i = pl.begin(); i != pl.end(); ++i) {
		i->status = PS_DISABLED;
		i->miss_count = 0;
	}
	CallService(PLUG "/SetPingList", (WPARAM)&pl, 0);
	return 0;
}
예제 #6
0
INT_PTR PingEnableAll(WPARAM wParam, LPARAM lParam) {
	PINGLIST pl;
	CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
	for(PINGLIST::Iterator i = pl.start(); i.has_val(); i.next()) {
		if(i.val().status == PS_DISABLED) {
			i.val().status = PS_NOTRESPONDING;
		}
	}
	CallService(PLUG "/SetPingList", (WPARAM)&pl, 0);
	return 0;
}
예제 #7
0
파일: utils.cpp 프로젝트: Seldom/miranda-ng
INT_PTR PingEnableAll(WPARAM, LPARAM) {
	PINGLIST pl;
	CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
	for (pinglist_it i = pl.begin(); i != pl.end(); ++i) {
		if (i->status == PS_DISABLED) {
			i->status = PS_NOTRESPONDING;
		}
	}
	CallService(PLUG "/SetPingList", (WPARAM)&pl, 0);
	return 0;
}
예제 #8
0
// call with list_cs locked
void read_ping_addresses()
{
	PINGADDRESS pa;
	pa.index = 0;

	list_items.clear();
	while (read_ping_address(pa))
	{
		list_items.push_back(pa);
		++pa.index;
	}
}
예제 #9
0
int PingEnableAll(WPARAM wParam, LPARAM lParam) {
	PINGLIST pl;
	CallService(PROTO "/GetPingList", 0, (LPARAM)&pl);
	for(PINGLIST::iterator i = pl.begin(); i != pl.end(); i++) {
		if(i->status == options.off_status) {
			i->status = options.nrstatus;
			DBWriteContactSettingWord(i->hContact, PROTO, "Status", i->status);
		}
	}
	CallService(PROTO "/SetPingList", (WPARAM)&pl, 0);
	return 0;
}
예제 #10
0
int PingDisableAll(WPARAM wParam, LPARAM lParam) {
	PINGLIST pl;
	CallService(PROTO "/GetPingList", 0, (LPARAM)&pl);
	for(PINGLIST::iterator i = pl.begin(); i != pl.end(); i++) {
		i->status = options.off_status;
		DBWriteContactSettingWord(i->hContact, PROTO, "Status", i->status);
		set_changing_clist_handle(TRUE);
		DBWriteContactSettingString(i->hContact, "CList", "MyHandle", i->pszLabel);
		set_changing_clist_handle(FALSE);
	}
	CallService(PROTO "/SetPingList", (WPARAM)&pl, 0);
	return 0;
}
예제 #11
0
int ContactDblClick(WPARAM wParam, LPARAM lParam) {
	PINGLIST pl;
	CallService(PROTO "/GetPingList", 0, (LPARAM)&pl);
	for(PINGLIST::iterator i = pl.begin(); i != pl.end(); i++) {
		if(i->hContact == (HANDLE)wParam) {
			if(strlen(i->pszCommand)) {
				ShellExecute(0, "open", i->pszCommand, i->pszParams, 0, SW_SHOW);
			} else {
				CallService(PROTO "/ToggleEnabled", wParam, 0);
			}
		}
	}
	return 0;
}
예제 #12
0
INT_PTR DblClick(WPARAM wParam, LPARAM lParam) {
	PINGLIST pl;
	CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
	for(PINGLIST::Iterator i = pl.start(); i.has_val(); i.next()) {
		if(i.val().item_id == (DWORD)wParam) {
			if(strlen(i.val().pszCommand)) {
				ShellExecute(0, "open", i.val().pszCommand, i.val().pszParams, 0, SW_SHOW);
			} else {
				return CallService(PLUG "/ToggleEnabled", wParam, 0);
			}
		}
	}
	return 0;
}
예제 #13
0
파일: utils.cpp 프로젝트: Seldom/miranda-ng
INT_PTR DblClick(WPARAM wParam, LPARAM) {
	PINGLIST pl;
	CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
	for (pinglist_it i = pl.begin(); i != pl.end(); ++i) {
		if (i->item_id == (DWORD)wParam) {
			if (mir_tstrlen(i->pszCommand)) {
				ShellExecute(0, _T("open"), i->pszCommand, i->pszParams, 0, SW_SHOW);
			}
			else {
				return CallService(PLUG "/ToggleEnabled", wParam, 0);
			}
		}
	}
	return 0;
}
예제 #14
0
INT_PTR GetListSize(WPARAM, LPARAM)
{
	INT_PTR ret = 0;
	mir_cslock lck(list_cs);
	ret = list_items.size();
	return ret;
}
예제 #15
0
INT_PTR ClearPingList(WPARAM wParam, LPARAM lParam)
{
	mir_cslock lck(list_cs);
	list_items.clear();

	NotifyEventHooks(reload_event_handle, 0, 0);
	return 0;
}
예제 #16
0
int ClearPingList(WPARAM wParam, LPARAM lParam) {
	EnterCriticalSection(&list_cs);
	list_items.clear();
	LeaveCriticalSection(&list_cs);
	
	NotifyEventHooks(reload_event_handle, 0, 0);
	return 0;
}
예제 #17
0
// call with list_cs locked
void read_ping_addresses() {
	HANDLE hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDFIRST, 0, 0 );
	PINGADDRESS pa;

	list_items.clear();
	while ( hContact != NULL ) {
		char *proto = ( char* )CallService( MS_PROTO_GETCONTACTBASEPROTO, ( WPARAM )hContact,0 );
		if ( proto && lstrcmp( PROTO, proto) == 0) {
			pa.hContact = hContact;
			read_ping_address(pa);
			list_items.push_back(pa);
		}

		hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDNEXT,( WPARAM )hContact, 0 );
	}	
	std::sort(list_items.begin(), list_items.end(), SAscendingSort());
}
예제 #18
0
INT_PTR ToggleEnabled(WPARAM wParam, LPARAM lParam) {
	int retval = 0;
	PINGLIST pl;
	CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
	for(PINGLIST::Iterator i = pl.start(); i.has_val(); i.next()) {
		if(i.val().item_id == (DWORD)wParam) {

			if(i.val().status == PS_DISABLED)
				i.val().status = PS_NOTRESPONDING;
			else {
				i.val().status = PS_DISABLED;
				i.val().miss_count = 0;
				retval = 1;
			}
		}
	}
	CallService(PLUG "/SetPingList", (WPARAM)&pl, 0);
	return 0;
}
예제 #19
0
파일: utils.cpp 프로젝트: Seldom/miranda-ng
INT_PTR ToggleEnabled(WPARAM wParam, LPARAM) {
	int retval = 0;
	PINGLIST pl;
	CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
	for (pinglist_it i = pl.begin(); i != pl.end(); ++i) {
		if (i->item_id == (DWORD)wParam) {

			if (i->status == PS_DISABLED)
				i->status = PS_NOTRESPONDING;
			else {
				i->status = PS_DISABLED;
				i->miss_count = 0;
				retval = 1;
			}
		}
	}
	CallService(PLUG "/SetPingList", (WPARAM)&pl, 0);
	return 0;
}
예제 #20
0
int EditContact(WPARAM wParam, LPARAM lParam) {
	PINGLIST pl;
	HWND hwndList = (HWND)CallService(MS_CLUI_GETHWND, 0, 0);

	CallService(PROTO "/GetPingList", 0, (LPARAM)&pl);
	for(PINGLIST::iterator i = pl.begin(); i != pl.end(); i++) {
		if(i->hContact == (HANDLE)wParam) {

			add_edit_addr = *i;
	
			if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndList, DlgProcDestEdit) == IDOK) {
	
				*i = add_edit_addr;
				CallService(PROTO "/SetAndSavePingList", (WPARAM)&pl, 0);
				return 0;
			}
		}
	}
	return 1;
}
예제 #21
0
INT_PTR EditContact(WPARAM wParam, LPARAM lParam) {
	PINGLIST pl;
	HWND hwndList = (HWND)CallService(MS_CLUI_GETHWND, 0, 0);

	CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
	for(PINGLIST::Iterator i = pl.start(); i.has_val(); i.next()) {
		if(i.val().item_id == (DWORD)wParam) {

			add_edit_addr = i.val();
	
			if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndList, DlgProcDestEdit) == IDOK) {
	
				i.val() = add_edit_addr;
				CallService(PLUG "/SetAndSavePingList", (WPARAM)&pl, 0);
				return 0;
			}
		}
	}
	return 1;
}
예제 #22
0
파일: utils.cpp 프로젝트: Seldom/miranda-ng
INT_PTR EditContact(WPARAM wParam, LPARAM)
{
	PINGLIST pl;
	HWND hwndList = pcli->hwndContactList;

	CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
	for (pinglist_it i = pl.begin(); i != pl.end(); ++i) {
		if (i->item_id == (DWORD)wParam) {

			add_edit_addr = *i;

			if (DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndList, DlgProcDestEdit) == IDOK) {

				*i = add_edit_addr;
				CallService(PLUG "/SetAndSavePingList", (WPARAM)&pl, 0);
				return 0;
			}
		}
	}
	return 1;
}
예제 #23
0
// call with list_cs locked
void write_ping_addresses()
{
	int index = 0;
	for (pinglist_it i = list_items.begin(); i != list_items.end(); ++i, index++)
	{
		i->index = index;
		write_ping_address(*i);
	}

	// mark further destinations in the DB as invalid
	char buff[16];
	bool found;

	do {
		found = false;
		mir_snprintf(buff, "PING_DEST_%d", index++);
		if (db_get_dw(0, buff, "Id", 0) != 0) {
			found = true;
			db_set_dw(0, buff, "Id", 0);
		}
	} while (found);
}
예제 #24
0
// wParam is address of a PINGLIST structure to replace the current one
// lParam is zero
int SetAndSavePingList(WPARAM wParam, LPARAM lParam) {
	PINGLIST *pli = (PINGLIST *)wParam;
	
	EnterCriticalSection(&list_cs);
	// delete items that aren't in the new list
	bool found;
	for(PINGLIST::iterator i = list_items.begin(); i != list_items.end(); i++) {
		found = false;
		for(PINGLIST::iterator j = pli->begin(); j != pli->end(); j++) {
			if(i->hContact == j->hContact) {
				found = true;
				break;
			}

		}
		if(!found) {
			//MessageBox(0, "Deleting contact", "Ping", MB_OK);
			// remove prot first, so that our contact deleted event handler isn't activated
			CallService(MS_PROTO_REMOVEFROMCONTACT, (WPARAM)i->hContact, (LPARAM)PROTO);
			CallService(MS_DB_CONTACT_DELETE, (WPARAM)i->hContact, 0);
		}
	}

	// set new list
	if(pli->size())
		list_items = *pli;
	else 
		list_items.clear();

	write_ping_addresses();
	LeaveCriticalSection(&list_cs);
	
	NotifyEventHooks(reload_event_handle, 0, 0);
	
	return 0;
}
예제 #25
0
// ping hosts list window
static INT_PTR CALLBACK DlgProcOpts2(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch ( msg ) {
	case WM_INITDIALOG: 
			TranslateDialogDefault( hwndDlg );

			Lock(&data_list_cs, "init options dialog");
			temp_list = data_list;
			Unlock(&data_list_cs);

			for (pinglist_it i = temp_list.begin(); i != temp_list.end(); ++i)
			{
				int index = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)i->pszLabel);
				SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, index, (LPARAM)&(*i));
			}
		return TRUE;

	case WM_COMMAND:
		if (HIWORD( wParam ) == LBN_SELCHANGE && LOWORD(wParam) == IDC_LST_DEST)
		{
			int sel = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
			if(sel != LB_ERR)
			{
				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), TRUE);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), TRUE);

				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), (sel > 0));
				int count = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCOUNT, 0, 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel < count - 1));
			}
		}

		if ( HIWORD( wParam ) == BN_CLICKED )
		{
			switch( LOWORD( wParam ))
			{
			case IDC_BTN_DESTEDIT:
			{
				int sel = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
				if (sel != LB_ERR)
				{
					PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel, 0);
					PINGADDRESS temp = *item;
					if (Edit(hwndDlg, temp))
					{
						*item = temp;
						SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel, 0);
						SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)sel, (LPARAM)item->pszLabel);
						SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)sel, (LPARAM)item);
						SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)sel, 0);

						EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), TRUE);
						EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), TRUE);
						EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), sel > 0);
						int count = SendDlgItemMessage(hwndDlg, IDC_BTN_DESTDOWN, LB_GETCOUNT, 0, 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel < count - 1));

						SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
					}
				}
			}
				break;
			case IDC_BTN_DESTADD:

				memset(&add_edit_addr,0,sizeof(add_edit_addr));
				add_edit_addr.cbSize = sizeof(add_edit_addr);
				add_edit_addr.port = -1;
				add_edit_addr.set_status = ID_STATUS_ONLINE;
				add_edit_addr.get_status = ID_STATUS_OFFLINE;
				add_edit_addr.status = PS_NOTRESPONDING;
				add_edit_addr.item_id = 0;
				add_edit_addr.index = (int)temp_list.size();

				if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndDlg, DlgProcDestEdit) == IDOK)
				{
					temp_list.push_back(add_edit_addr);

					int index = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)add_edit_addr.pszLabel);
					SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)index, 0);
					SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)index, (LPARAM)&(temp_list.back()));

					EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), TRUE);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), TRUE);

					int sel = (int)temp_list.size() - 1;
					EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), (sel > 0));
					int count = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCOUNT, 0, 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel < count - 1));

					SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
				}

				break;
			case IDC_BTN_DESTREM:
			{
				int sel = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
				if(sel != LB_ERR) {
					PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel, 0);
					SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel, 0);
					temp_list.remove(*item);
				}

				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), FALSE);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), FALSE);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), FALSE);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), FALSE);

				SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
				RefreshWindow(0, 0);
				break;
			}
			case IDC_BTN_DESTDOWN:
				{
					int sel2 = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
					if(sel2 != LB_ERR) {
						PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2, 0),
							*item2 = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2 + 1, 0);
						if(item && item2)
						{
							add_edit_addr = *item;
							*item = *item2;
							*item2 = add_edit_addr;

							// keep indexes the same, as they're used for sorting the binary tree
							int index = item->index, index2 = item2->index;						
							item->index = index2;
							item2->index = index;

							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel2, (LPARAM)0);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)item->pszLabel);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)sel2, (LPARAM)item);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)(sel2 + 1), (LPARAM)0);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)(sel2 + 1), (LPARAM)item2->pszLabel);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)(sel2 + 1), (LPARAM)item2);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)(sel2 + 1), 0);

							EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), (sel2 + 1 > 0));
							int count = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCOUNT, 0, 0);
							EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel2 + 1 < count - 1));

							SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
						}
					}
				}
				break;
			case IDC_BTN_DESTUP:
				{
					int sel2 = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
					if(sel2 != LB_ERR) {
						PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2, 0),
							*item2 = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2 - 1, 0);

						if (item && item2)
						{
							add_edit_addr = *item;
							*item = *item2;
							*item2 = add_edit_addr;

							// keep indexes the same, as they're used for sorting the binary tree
							int index = item->index, index2 = item2->index;						
							item->index = index2;
							item2->index = index;

							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel2, (LPARAM)0);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)item->pszLabel);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)sel2, (LPARAM)item);

							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)(sel2 - 1), (LPARAM)0);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)(sel2 - 1), (LPARAM)item2->pszLabel);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)(sel2 - 1), (LPARAM)item2);

							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)(sel2 - 1), 0);

							EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), (sel2 - 1 > 0));
							int count = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCOUNT, 0, 0);
							EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel2 - 1 < count - 1));

							SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
						}
					}
				}

				break;
			}
		}
		if(LOWORD(wParam) == IDC_BGCOL
			|| LOWORD(wParam) == IDC_SP_INDENT || LOWORD(wParam) == IDC_SP_ROWHEIGHT)
		{
			SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
		}
		break;

	case WM_NOTIFY:
		if (((LPNMHDR)lParam)->code == PSN_APPLY )
		{
			CallService(PLUG "/SetAndSavePingList", (WPARAM)&temp_list, 0);
			CallService(PLUG "/GetPingList", 0, (LPARAM)&temp_list);
			// the following will be affected due to list rebuild event
			//if(hWakeEvent) SetEvent(hWakeEvent);
			return TRUE;
		}
		break;

	}
	return FALSE;
}
예제 #26
0
void __cdecl sttCheckStatusThreadProc(void*)
{
	clock_t start_t = clock(), end_t;
	while (!get_thread_finished()) {
		end_t = clock();

		int wait = (int)((options.ping_period - ((end_t - start_t) / (double)CLOCKS_PER_SEC)) * 1000);
		if (wait > 0)
			WaitForSingleObjectEx(hWakeEvent, wait, TRUE);

		if (get_thread_finished()) break;

		start_t = clock();

		bool timeout = false;
		bool reply = false;
		int count = 0;

		PINGADDRESS pa = { 0 };
		HistPair history_entry;
		size_t size;
		{
			mir_cslock lck(data_list_cs);
			set_list_changed(false);
			size = data_list.size();
		}

		size_t index = 0;
		for (; index < size; index++) {
			{
				mir_cslock lck(data_list_cs);
				size_t c = 0;
				for (pinglist_it i = data_list.begin(); i != data_list.end() && c <= index; ++i, c++) {
					if (c == index) {
						// copy just what we need - i.e. not history, not command
						pa.get_status = i->get_status;
						pa.item_id = i->item_id;
						pa.miss_count = i->miss_count;
						pa.port = i->port;
						mir_tstrncpy(pa.pszLabel, i->pszLabel, _countof(pa.pszLabel));
						mir_tstrncpy(pa.pszName, i->pszName, _countof(pa.pszName));
						mir_strncpy(pa.pszProto, i->pszProto, _countof(pa.pszProto));
						pa.set_status = i->set_status;
						pa.status = i->status;
						break;
					}
				}
			}

			if (get_thread_finished()) break;
			if (get_list_changed()) break;

			if (pa.status != PS_DISABLED) {
				if (!options.no_test_icon) {
					mir_cslock lck(data_list_cs);
					for (pinglist_it i = data_list.begin(); i != data_list.end(); ++i)
						if (i->item_id == pa.item_id)
							i->status = PS_TESTING;

					InvalidateRect(list_hwnd, 0, FALSE);
				}

				CallService(PLUG "/Ping", 0, (LPARAM)&pa);

				if (get_thread_finished()) break;
				if (get_list_changed()) break;

				{	mir_cslock lck(data_list_cs);
				
					for (pinglist_it i = data_list.begin(); i != data_list.end(); ++i) {
						if (i->item_id == pa.item_id) {
							i->responding = pa.responding;
							i->round_trip_time = pa.round_trip_time;
							history_entry.first = i->round_trip_time;
							history_entry.second = time(0);
							history_map[i->item_id].push_back(history_entry);
							// maintain history (-1 represents no response)
							while (history_map[i->item_id].size() >= MAX_HISTORY)
								//history_map[i->item_id].pop_front();
								history_map[i->item_id].remove(history_map[i->item_id].begin().val());

							if (pa.responding) {
								if (pa.miss_count > 0)
									pa.miss_count = -1;
								else
									pa.miss_count--;
								pa.status = PS_RESPONDING;
							}
							else {
								if (pa.miss_count < 0)
									pa.miss_count = 1;
								else
									pa.miss_count++;
								pa.status = PS_NOTRESPONDING;
							}

							i->miss_count = pa.miss_count;
							i->status = pa.status;

							break;
						}
					}
				}

				if (pa.responding) {
					count++;

					if (pa.miss_count == -1 - options.retries ||
						(((-pa.miss_count) % (options.retries + 1)) == 0 && !options.block_reps)) {
						reply = true;
						if (options.show_popup2 && ServiceExists(MS_POPUP_SHOWMESSAGE)) {
							ShowPopup(TranslateT("Ping Reply"), pa.pszLabel, 1);
						}
					}
					if (pa.miss_count == -1 - options.retries && options.logging) {
						TCHAR buf[512];
						mir_sntprintf(buf, TranslateT("%s - reply, %d"), pa.pszLabel, pa.round_trip_time);
						CallService(PLUG "/Log", (WPARAM)buf, 0);
					}
					SetProtoStatus(pa.pszLabel, pa.pszProto, pa.get_status, pa.set_status);
				}
				else {
					if (pa.miss_count == 1 + options.retries ||
						((pa.miss_count % (options.retries + 1)) == 0 && !options.block_reps)) {
						timeout = true;
						if (options.show_popup)
							ShowPopup(TranslateT("Ping Timeout"), pa.pszLabel, 0);
					}
					if (pa.miss_count == 1 + options.retries && options.logging) {
						TCHAR buf[512];
						mir_sntprintf(buf, TranslateT("%s - timeout"), pa.pszLabel);
						CallService(PLUG "/Log", (WPARAM)buf, 0);
					}
				}

				InvalidateRect(list_hwnd, 0, FALSE);
			}
		}

		if (timeout) SkinPlaySound("PingTimeout");
		if (reply) SkinPlaySound("PingReply");

		if (!get_list_changed()) {
			upCount = count;
			total = (int)index;
		}
		else total = 0;
	}
}
예제 #27
0
// ping destinations list window
static BOOL CALLBACK DlgProcOpts2(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND hw;
	int sel;

	switch ( msg ) {
	case WM_INITDIALOG: 
		{
			TranslateDialogDefault( hwndDlg );

			Lock(&data_list_cs, "init options dialog");
			temp_list = data_list;
			Unlock(&data_list_cs);

			hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
			for(PINGLIST::iterator i = temp_list.begin(); i != temp_list.end(); i++) {
				//int index = 
					SendMessage(hw, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)i->pszLabel);
			}

		}
		return TRUE;

	case WM_COMMAND:
		if (HIWORD( wParam ) == LBN_SELCHANGE && LOWORD(wParam) == IDC_LST_DEST) {
			hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
			sel = SendMessage(hw, LB_GETCURSEL, 0, 0);
			if(sel != LB_ERR) {
				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTREM);
				EnableWindow(hw, TRUE);
				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT);
				EnableWindow(hw, TRUE);

				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTUP);
				EnableWindow(hw, (sel > 0));
				hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
				int count = SendMessage(hw, LB_GETCOUNT, 0, 0);
				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN);
				EnableWindow(hw, (sel < count - 1));
			}
		}

		if ( HIWORD( wParam ) == BN_CLICKED ) {
			switch( LOWORD( wParam )) {
			case IDC_BTN_DESTEDIT:
				hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
				sel = SendMessage(hw, LB_GETCURSEL, 0, 0);
				if(sel != LB_ERR) {
					add_edit_addr = temp_list[sel];
					
					if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndDlg, DlgProcDestEdit) == IDOK) {

						temp_list[sel] = add_edit_addr;
						SendMessage(hw, LB_DELETESTRING, (WPARAM)sel, (LPARAM)0);
						SendMessage(hw, LB_INSERTSTRING, (WPARAM)sel, (LPARAM)temp_list[sel].pszLabel);
						SendMessage(hw, LB_SETCURSEL, (WPARAM)sel, 0);
						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTREM);
						EnableWindow(hw, TRUE);
						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT);
						EnableWindow(hw, TRUE);
						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTUP);
						EnableWindow(hw, TRUE);
						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN);
						EnableWindow(hw, TRUE);
	
						SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
					}
				}
				break;
			case IDC_BTN_DESTADD:

				memset(&add_edit_addr,0,sizeof(add_edit_addr));
				add_edit_addr.cbSize = sizeof(add_edit_addr);
				add_edit_addr.port = -1;
				add_edit_addr.set_status = ID_STATUS_ONLINE;
				add_edit_addr.get_status = ID_STATUS_OFFLINE;
				add_edit_addr.status = options.nrstatus;

				if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndDlg, DlgProcDestEdit) == IDOK) {

					temp_list.push_back(add_edit_addr);

					hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
					int index = SendMessage(hw, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)add_edit_addr.pszLabel);
					hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
					SendMessage(hw, LB_SETCURSEL, (WPARAM)index, 0);

					hw = GetDlgItem(hwndDlg, IDC_BTN_DESTREM);
					EnableWindow(hw, TRUE);
					hw = GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT);
					EnableWindow(hw, TRUE);

					sel = temp_list.size() - 1;
					hw = GetDlgItem(hwndDlg, IDC_BTN_DESTUP);
					EnableWindow(hw, (sel > 0));
					hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
					int count = SendMessage(hw, LB_GETCOUNT, 0, 0);
					hw = GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN);
					EnableWindow(hw, (sel < count - 1));
					
					SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
				}

				break;
			case IDC_BTN_DESTREM:
				hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
				sel = SendMessage(hw, LB_GETCURSEL, 0, 0);
				if(sel != LB_ERR) {
					SendMessage(hw, LB_DELETESTRING, (WPARAM)sel, 0);
					PINGLIST::iterator i = temp_list.begin();
					while(sel > 0 && i != temp_list.end()) {
						sel--;
						i++;
					}
					if(i != temp_list.end())
						temp_list.erase(i);
				}

				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTREM);
				EnableWindow(hw, FALSE);
				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT);
				EnableWindow(hw, FALSE);
				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTUP);
				EnableWindow(hw, FALSE);
				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN);
				EnableWindow(hw, FALSE);

				SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
				break;
			case IDC_BTN_DESTDOWN:
				{
					hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
					int sel2 = SendMessage(hw, LB_GETCURSEL, 0, 0);
					if(sel2 != LB_ERR) {
						add_edit_addr = temp_list[sel2];					
						temp_list[sel2] = temp_list[sel2 + 1];					
						temp_list[sel2 + 1] = add_edit_addr;

						SendMessage(hw, LB_DELETESTRING, (WPARAM)sel2, (LPARAM)0);
						SendMessage(hw, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)temp_list[sel2].pszLabel);
						SendMessage(hw, LB_DELETESTRING, (WPARAM)(sel2 + 1), (LPARAM)0);
						SendMessage(hw, LB_INSERTSTRING, (WPARAM)(sel2 + 1), (LPARAM)temp_list[sel2 + 1].pszLabel);
						SendMessage(hw, LB_SETCURSEL, (WPARAM)(sel2 + 1), 0);

						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTUP);
						EnableWindow(hw, (sel2 + 1 > 0));
						hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
						int count = SendMessage(hw, LB_GETCOUNT, 0, 0);
						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN);
						EnableWindow(hw, (sel2 + 1 < count - 1));

						SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
					}				
				}
				break;
			case IDC_BTN_DESTUP:
				{
					hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
					int sel2 = SendMessage(hw, LB_GETCURSEL, 0, 0);
					if(sel2 != LB_ERR) {
						add_edit_addr = temp_list[sel2 - 1];					
						temp_list[sel2 - 1] = temp_list[sel2];					
						temp_list[sel2] = add_edit_addr;

						SendMessage(hw, LB_DELETESTRING, (WPARAM)sel2, (LPARAM)0);
						SendMessage(hw, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)temp_list[sel2].pszLabel);

						SendMessage(hw, LB_DELETESTRING, (WPARAM)(sel2 - 1), (LPARAM)0);
						SendMessage(hw, LB_INSERTSTRING, (WPARAM)(sel2 - 1), (LPARAM)temp_list[sel2 - 1].pszLabel);

						SendMessage(hw, LB_SETCURSEL, (WPARAM)(sel2 - 1), 0);

						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTUP);
						EnableWindow(hw, (sel2 - 1 > 0));
						hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
						int count = SendMessage(hw, LB_GETCOUNT, 0, 0);
						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN);
						EnableWindow(hw, (sel2 - 1 < count - 1));
		
						SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
					}				
				}

				break;
			}
		}
		break;

	case WM_NOTIFY:
		if (((LPNMHDR)lParam)->code == (unsigned)PSN_APPLY ) {
			CallService(PROTO "/SetAndSavePingList", (WPARAM)&temp_list, 0);
			CallService(PROTO "/GetPingList", 0, (LPARAM)&temp_list);
			// the following will be affected due to list rebuild event
			//if(hWakeEvent) SetEvent(hWakeEvent);
			return TRUE;
		}
		break;

	}
	return FALSE;
}