Beispiel #1
0
int EventList::GetContactMessageNumber(MCONTACT hContact)
{
	int count = db_event_count(hContact);

	mir_cslock lck(csEventList);
	std::map<MCONTACT, EventList::ImportDiscData>::iterator it = contactFileMap.find(hContact);
	if (it != contactFileMap.end())
		++count;
	return count;
}
Beispiel #2
0
int EventList::GetContactMessageNumber(HANDLE hContact)
{
	int count = db_event_count(hContact);
	EnterCriticalSection(&criticalSection);
	std::map<HANDLE, EventList::ImportDiscData>::iterator it = contactFileMap.find(hContact);
	if (it != contactFileMap.end())
		++count;

	LeaveCriticalSection(&criticalSection);
	return count;
}
Beispiel #3
0
void CMsnProto::MSN_CleanupLists(void)
{
	for (int i=contList.getCount(); i--;) {
		MsnContact& p = contList[i];
		if (p.list & LIST_FL)
			MSN_SetContactDb(p.hContact, p.email);

		if (p.list & LIST_PL) {
			if (p.list & (LIST_AL | LIST_BL))
				MSN_AddUser(NULL, p.email, p.netId, LIST_PL + LIST_REMOVE);
			else
				MSN_AddAuthRequest(p.email, p.nick, p.invite);
		}

		if (p.hContact && !(p.list & (LIST_LL | LIST_FL | LIST_PL)) && p.list != LIST_RL) {
			int count = db_event_count(p.hContact);
			if (count) {
				TCHAR text[256];
				TCHAR *sze = mir_a2t(p.email);
				mir_sntprintf(text, SIZEOF(text), TranslateT("Contact %s has been removed from the server.\nWould you like to keep it as \"Local Only\" contact to preserve history?"), sze);
				mir_free(sze);

				TCHAR title[128];
				mir_sntprintf(title, SIZEOF(title), TranslateT("%s protocol"), m_tszUserName);

				if (MessageBox(NULL, text, title, MB_YESNO | MB_ICONQUESTION | MB_SETFOREGROUND) == IDYES) {
					MSN_AddUser(p.hContact, p.email, 0, LIST_LL);
					setByte(p.hContact, "LocalList", 1);
					continue;
				}
			}

			if (!(p.list & (LIST_LL | LIST_FL))) {
				CallService(MS_DB_CONTACT_DELETE, (WPARAM)p.hContact, 0);
				p.hContact = NULL;
			}
		}

		if (p.list & (LIST_LL | LIST_FL) && p.hContact) {
			TCHAR path[MAX_PATH];
			MSN_GetCustomSmileyFileName(p.hContact, path, SIZEOF(path), "", 0);
			if (path[0]) {
				SMADD_CONT cont;
				cont.cbSize = sizeof(SMADD_CONT);
				cont.hContact = p.hContact;
				cont.type = 0;
				cont.path = path;

				CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont);
			}
		}
	}
}
Beispiel #4
0
int PrebuildContactMenu(WPARAM hContact, LPARAM lParam)
{
    bool remove = db_get_b(hContact, MODULE, DBSETTING_REMOVE, 0) != 0;
    char *proto = GetContactProto(hContact);
    bool chat_room = (proto && db_get_b(hContact, proto, "ChatRoom", 0) != 0);

    if (chat_room)
        Menu_ShowItem(hMenuToggle, false);
    else {
        if (remove)
            Menu_ModifyItem(hMenuToggle, LPGENT("Enable History"), hIconKeep);
        else
            Menu_ModifyItem(hMenuToggle, LPGENT("Disable History"), hIconRemove);
    }

    Menu_ShowItem(hMenuClear, !chat_room && db_event_count(hContact) > 0);
    return 0;
}
Beispiel #5
0
static void FillHistoryThread(void* param)
{
	Thread_SetName("HistoryWindow::FillHistoryThread");

	THistoryThread *hInfo = (THistoryThread*)param;
	HWND hwndList = GetDlgItem(hInfo->hwnd, IDC_LIST);

	SendDlgItemMessage(hInfo->hwnd, IDC_LIST, LB_RESETCONTENT, 0, 0);
	int i = db_event_count(hInfo->hContact);
	SendDlgItemMessage(hInfo->hwnd, IDC_LIST, LB_INITSTORAGE, i, i * 40);

	DBEVENTINFO dbei = { sizeof(dbei) };
	int oldBlobSize = 0;
	MEVENT hDbEvent = db_event_last(hInfo->hContact);

	while (hDbEvent != NULL) {
		if (!IsWindow(hInfo->hwnd))
			break;
		int newBlobSize = db_event_getBlobSize(hDbEvent);
		if (newBlobSize > oldBlobSize) {
			dbei.pBlob = (PBYTE)mir_realloc(dbei.pBlob, newBlobSize);
			oldBlobSize = newBlobSize;
		}
		dbei.cbBlob = oldBlobSize;
		db_event_get(hDbEvent, &dbei);

		TCHAR str[200], eventText[256], strdatetime[64];
		GetObjectSummary(&dbei, str, _countof(str));
		if (str[0]) {
			TimeZone_PrintTimeStamp(NULL, dbei.timestamp, _T("d t"), strdatetime, _countof(strdatetime), 0);
			mir_sntprintf(eventText, _T("%s: %s"), strdatetime, str);
			i = SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)eventText);
			SendMessage(hwndList, LB_SETITEMDATA, i, (LPARAM)hDbEvent);
		}
		hDbEvent = db_event_prev(hInfo->hContact, hDbEvent);
	}
	mir_free(dbei.pBlob);

	SendDlgItemMessage(hInfo->hwnd, IDC_LIST, LB_SETCURSEL, 0, 0);
	SendMessage(hInfo->hwnd, WM_COMMAND, MAKEWPARAM(IDC_LIST, LBN_SELCHANGE), 0);
	EnableWindow(GetDlgItem(hInfo->hwnd, IDC_LIST), TRUE);
	mir_free(hInfo);
}
//Sweep history from specified contact
void SweepHistoryFromContact(MCONTACT hContact, CriteriaStruct Criteria, BOOL keepUnread)
{
    int lPolicy;
    if (hContact == NULL)			// for system history
        lPolicy = db_get_b(NULL, ModuleName, "SweepSHistory", 0);
    else							// for contact history (or "SweepHistory" - default action)
        lPolicy = db_get_b(hContact, ModuleName, "SweepHistory", db_get_b(NULL, ModuleName, "SweepHistory", 0));

    if (lPolicy == 0) return;		// nothing to do

    int eventsCnt = db_event_count(hContact);
    if (eventsCnt == 0)
        return;

    BOOL doDelete, unsafe = db_get_b(NULL, ModuleName, "UnsafeMode", 0);
    BEventData *books, *item, ev = { 0 };
    size_t bookcnt, btshift;

    SetCursor(LoadCursor(0, IDC_WAIT));

    // switch off SAFETYMODE if necessary
    if (unsafe)
        CallService(MS_DB_SETSAFETYMODE, 0, 0);

    GetBookmarks(hContact, &books, &bookcnt);

    // Get first event
    for (MEVENT hDBEvent = db_event_first(hContact); hDBEvent != NULL; ) {
        DBEVENTINFO dbei = { sizeof(dbei) };
        db_event_get(hDBEvent, &dbei);

        // should we stop processing?
        // lPolicy == 1 - for time criterion, lPolicy == 2 - keep N last events, lPolicy == 3 - delete all events
        if ((lPolicy == 1 && (unsigned)Criteria.time < dbei.timestamp) || (lPolicy == 2 && Criteria.keep > --eventsCnt)) break;

        doDelete = TRUE;

        if (!(dbei.flags & (DBEF_SENT | DBEF_READ)) && keepUnread) doDelete = FALSE;	// keep unread events

        if (bookcnt != 0) { // keep bookmarks
            ev.hDBEvent = hDBEvent;
            item = (BEventData*)bsearch(&ev, books, bookcnt, sizeof(BEventData), CompareBookmarks);
            if (item != NULL && item->Timestamp == dbei.timestamp) {
                doDelete = FALSE;
                btshift = (--bookcnt - (item - books))*sizeof(BEventData);
                if (btshift)
                    memmove(item, item + 1, btshift);
            }
        }

        // find next event
        MEVENT hDBEventNext = db_event_next(hContact, hDBEvent);
        if (doDelete)
            db_event_delete(hContact, hDBEvent);

        hDBEvent = hDBEventNext;
    }

    mir_free(books);

    // switch ON safety mode as fast as we can to avoid  DB corruption
    if (unsafe)
        CallService(MS_DB_SETSAFETYMODE, 1, 0);

    SetCursor(LoadCursor(0, IDC_ARROW));
}
Beispiel #7
0
static INT_PTR LinkList_Main(WPARAM wParam, LPARAM)
{
	HANDLE hContact = (HANDLE)wParam;
	HWND hWnd = WindowList_Find(hWindowList, hContact);
	if ( hWnd != NULL ) {
		int len;
		SetForegroundWindow(hWnd);
		SetFocus(hWnd);
		len = GetWindowTextLength(GetDlgItem(hWnd, IDC_MAIN));
		PostMessage(GetDlgItem(hWnd, IDC_MAIN), EM_SETSEL, (WPARAM)len, (LPARAM)len);
		return 0;
	}	
	
	HANDLE hEvent = db_event_first(hContact);
	if (hEvent == NULL) {
		MessageBox(NULL, TXT_EMPTYHISTORY, TXT_PLUGINNAME, MB_OK | MB_ICONINFORMATION );
		return 0;
	}

	int histCount = db_event_count(hContact), actCount = 0;

	DBEVENTINFO dbe = { sizeof(dbe) };
	dbe.cbBlob = db_event_getBlobSize(hEvent);
	dbe.pBlob  = (PBYTE)malloc(dbe.cbBlob+1);
	db_event_get(hEvent, &dbe);
	dbe.pBlob[dbe.cbBlob] = 0;

	RECT DesktopRect;
	GetWindowRect(GetDesktopWindow(), &DesktopRect);
	HWND hWndProgress = CreateWindow(_T("Progressbar"), TranslateT("Processing history..."), WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, 350, 45, NULL, NULL, hInst, NULL);
	if ( hWndProgress == 0 ) {
		free(dbe.pBlob);
		MessageBox(NULL, TranslateT("Could not create window!"), TranslateT("Error"), MB_OK | MB_ICONEXCLAMATION );
		return -1;
	}
	SetWindowPos(hWndProgress, HWND_TOP, (int)(DesktopRect.right*0.5)-175, (int)(DesktopRect.bottom*0.5)-22, 0, 0, SWP_NOSIZE);
	ShowWindow(hWndProgress, SW_SHOW);
	SetForegroundWindow(hWndProgress);

	LISTELEMENT *listStart = (LISTELEMENT*)malloc(sizeof(LISTELEMENT));
	ZeroMemory(listStart, sizeof(LISTELEMENT));

	while( 1 ) {
		if ( dbe.eventType == EVENTTYPE_URL || dbe.eventType == EVENTTYPE_MESSAGE ) {
			// Call function to find URIs
			if ( ExtractURI(&dbe, hEvent, listStart) < 0 ) {
				free(dbe.pBlob);
				RemoveList(listStart);
				MessageBox(NULL, TranslateT("Could not allocate memory!"), TranslateT("Error"), MB_OK | MB_ICONEXCLAMATION);
				return -1;
			}
		}
		actCount++;
		if ( ((int)(((float)actCount/histCount)*100.00)) % 10 == 0 )
			SendMessage(hWndProgress, WM_COMMAND, 100, ((int)(((float)actCount/histCount)*100.00)));
		
		hEvent = db_event_next(hEvent);
		if ( hEvent == NULL )
			break;

		free(dbe.pBlob);
		dbe.cbBlob = db_event_getBlobSize(hEvent);
		dbe.pBlob = (PBYTE)malloc(dbe.cbBlob+1);
		db_event_get(hEvent, &dbe);
		dbe.pBlob[dbe.cbBlob] = 0;
	}
	free(dbe.pBlob);
	SendMessage(hWndProgress, WM_CLOSE, 0, 0);
	if ( ListCount(listStart) <= 0 ) {	
		RemoveList(listStart);
		MessageBox(NULL, TXT_NOLINKINHISTORY, TXT_PLUGINNAME, MB_OK | MB_ICONINFORMATION);
		return 0;
	}

	DIALOGPARAM *DlgParam = (DIALOGPARAM*)malloc(sizeof(DIALOGPARAM));
	DlgParam->hContact    = hContact;
	DlgParam->listStart   = listStart;
	DlgParam->findMessage = 0;
	DlgParam->chrg.cpMax  = -1;
	DlgParam->chrg.cpMin  = -1;

	HWND hWndMain = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, MainDlgProc, (LPARAM)DlgParam);
	if (hWndMain == 0) {
		RemoveList(listStart);
		MessageBox(NULL, TranslateT("Could not create window!"), TranslateT("Error"), MB_OK | MB_ICONEXCLAMATION );
		return -1;
	}

	ShowWindow(hWndMain, SW_SHOW);	
	return 0;
}