Skip to content

Commit

Permalink
#45 show total message count
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-mausch committed Nov 4, 2017
1 parent b94ffc4 commit 84f92fa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
10 changes: 6 additions & 4 deletions resources/Resources.rc
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ CAPTION "WhatsApp Viewer"
MENU IDR_MENU_MAIN
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_MAIN_CHATS,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,28,175,355
CONTROL "",IDC_MAIN_CHATS,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,52,175,331
CONTROL "Messages",IDC_MAIN_MESSAGES,"ChatControl",WS_VSCROLL | WS_TABSTOP,190,7,425,354,WS_EX_CLIENTEDGE
PUSHBUTTON "Export .txt ..",IDC_MAIN_EXPORT_TXT,190,369,50,14,WS_DISABLED
PUSHBUTTON ".txt ..",IDC_MAIN_EXPORT_TXT,190,369,50,14,WS_DISABLED
CONTROL "Benutzerdefiniert1",IDC_MAIN_SEARCH_CHATS,"SearchControl",WS_TABSTOP,7,8,175,14,WS_EX_CLIENTEDGE
PUSHBUTTON "Export .html ..",IDC_MAIN_EXPORT_HTML,245,369,50,14,WS_DISABLED
PUSHBUTTON "Export .json ..",IDC_MAIN_EXPORT_JSON,301,369,50,14,WS_DISABLED
PUSHBUTTON ".html ..",IDC_MAIN_EXPORT_HTML,245,369,50,14,WS_DISABLED
PUSHBUTTON ".json ..",IDC_MAIN_EXPORT_JSON,301,369,50,14,WS_DISABLED
LTEXT "Total message count",IDC_MAIN_MESSAGES_COUNT_LABEL,440,372,67,8
EDITTEXT IDC_MAIN_MESSAGES_COUNT,511,369,104,14,ES_AUTOHSCROLL | ES_READONLY
END

IDD_DECRYPT DIALOGEX 0, 0, 325, 135
Expand Down
4 changes: 3 additions & 1 deletion resources/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,9 @@
#define IDC_DECRYPT_CRYPT7_SELECT_DATABASE 1017
#define IDC_DECRYPT_CRYPT7_KEYFILE 1018
#define IDC_DECRYPT_CRYPT7_SELECT_KEY 1019
#define IDC_MAIN_MESSAGES_COUNT 1019
#define IDR_CHAT_EXPORT_HTML_TEMPLATE 1020
#define IDC_MAIN_MESSAGES_COUNT_LABEL 1020
#define ID_FILE_OPEN40001 40001
#define ID_MENU_MAIN_FILE_OPEN 40002
#define ID_FILE_DECRYPT 40003
Expand All @@ -917,7 +919,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 972
#define _APS_NEXT_COMMAND_VALUE 40022
#define _APS_NEXT_CONTROL_VALUE 1019
#define _APS_NEXT_CONTROL_VALUE 1021
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
40 changes: 31 additions & 9 deletions source/Platforms/Win32/GUI/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,7 @@ void MainWindow::addChat(WhatsappChat &chat)
{
std::wstring text = strtowstr(chat.getDisplayName());
std::wstring lastMessageText = strtowstr(formatTimestamp(chat.getLastMessage()));

std::stringstream messagesText;
messagesText.imbue(std::locale(""));
messagesText << std::fixed << chat.getMessagesSent() + chat.getMessagesReceived() << " (" << chat.getMessagesSent() << " / " << chat.getMessagesReceived() << ")";
std::wstring messagesTextW = strtowstr(messagesText.str());
std::wstring messagesText = strtowstr(formatMessageCount(chat.getMessagesSent(), chat.getMessagesReceived()));

LVITEM item;
ZeroMemory(&item, sizeof(LVITEM));
Expand All @@ -227,7 +223,7 @@ void MainWindow::addChat(WhatsappChat &chat)
ListView_InsertItem(GetDlgItem(dialog, IDC_MAIN_CHATS), &item);

ListView_SetItemText(GetDlgItem(dialog, IDC_MAIN_CHATS), item.iItem, 1, const_cast<WCHAR *>(lastMessageText.c_str()));
ListView_SetItemText(GetDlgItem(dialog, IDC_MAIN_CHATS), item.iItem, 2, const_cast<WCHAR *>(messagesTextW.c_str()));
ListView_SetItemText(GetDlgItem(dialog, IDC_MAIN_CHATS), item.iItem, 2, const_cast<WCHAR *>(messagesText.c_str()));
}

void MainWindow::selectChat(WhatsappChat *chat)
Expand All @@ -253,9 +249,11 @@ void MainWindow::resizeChildWindows(int width, int height)
SetWindowPos(GetDlgItem(dialog, IDC_MAIN_SEARCH_CHATS), NULL, border, border, chatsWidth, searchBoxHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
SetWindowPos(GetDlgItem(dialog, IDC_MAIN_CHATS), NULL, border, border + searchBoxHeight + 5, chatsWidth, height - border * 2 - searchBoxHeight - 5, SWP_NOZORDER | SWP_SHOWWINDOW);
SetWindowPos(GetDlgItem(dialog, IDC_MAIN_MESSAGES), NULL, chatsWidth + border * 2, border, width - chatsWidth - border * 3, height - border * 3 - buttonRowHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
SetWindowPos(GetDlgItem(dialog, IDC_MAIN_EXPORT_TXT), NULL, chatsWidth + border * 2, height - border - buttonRowHeight, 120, buttonRowHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
SetWindowPos(GetDlgItem(dialog, IDC_MAIN_EXPORT_HTML), NULL, chatsWidth + border * 3 + 120, height - border - buttonRowHeight, 120, buttonRowHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
SetWindowPos(GetDlgItem(dialog, IDC_MAIN_EXPORT_JSON), NULL, chatsWidth + border * 4 + 240, height - border - buttonRowHeight, 120, buttonRowHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
SetWindowPos(GetDlgItem(dialog, IDC_MAIN_EXPORT_TXT), NULL, chatsWidth + border * 2, height - border - buttonRowHeight, 70, buttonRowHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
SetWindowPos(GetDlgItem(dialog, IDC_MAIN_EXPORT_HTML), NULL, chatsWidth + border * 2 + 75, height - border - buttonRowHeight, 70, buttonRowHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
SetWindowPos(GetDlgItem(dialog, IDC_MAIN_EXPORT_JSON), NULL, chatsWidth + border * 2 + 150, height - border - buttonRowHeight, 70, buttonRowHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
SetWindowPos(GetDlgItem(dialog, IDC_MAIN_MESSAGES_COUNT_LABEL), NULL, width - 260 - border, height - border - buttonRowHeight + 5, 105, buttonRowHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
SetWindowPos(GetDlgItem(dialog, IDC_MAIN_MESSAGES_COUNT), NULL, width - 150 - border, height - border - buttonRowHeight, 150, buttonRowHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
}

void MainWindow::sortChats()
Expand Down Expand Up @@ -441,6 +439,30 @@ void MainWindow::openPlainDatabase(const std::string &filename)
database->getChats(settings, chats);

addChats();
setMessagesCount();
}

void MainWindow::setMessagesCount()
{
int sent = 0;
int received = 0;
for (std::vector<WhatsappChat *>::iterator it = chats.begin(); it != chats.end(); ++it)
{
WhatsappChat *chat = *it;
sent += chat->getMessagesSent();
received += chat->getMessagesReceived();
}

std::wstring text = strtowstr(formatMessageCount(sent, received));
SetDlgItemText(dialog, IDC_MAIN_MESSAGES_COUNT, const_cast<WCHAR *>(text.c_str()));
}

std::string MainWindow::formatMessageCount(int sent, int received)
{
std::stringstream text;
text.imbue(std::locale(""));
text << std::fixed << sent + received << " (" << sent << " / " << received << ")";
return text.str();
}

void MainWindow::closeDatabase()
Expand Down
2 changes: 2 additions & 0 deletions source/Platforms/Win32/GUI/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class MainWindow
void setIcon();
void resizeChildWindows(int width, int height);
void addChats();
void setMessagesCount();
std::string formatMessageCount(int sent, int received);
void addChat(WhatsappChat &chat);
void selectChat(WhatsappChat *chat);
void sortChats();
Expand Down

0 comments on commit 84f92fa

Please sign in to comment.