← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3008: add filtering settings to the dev plugin

 

------------------------------------------------------------
revno: 3008
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2012-07-20 15:49:53 +0200
message:
  add filtering settings to the dev plugin
modified:
  plugins/Dev/Dialog.cpp
  plugins/Dev/Dialog.h
  plugins/Dev/Plugin.cpp
  plugins/Dev/resource.h
  plugins/Dev/resource.rc


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'plugins/Dev/Dialog.cpp'
--- plugins/Dev/Dialog.cpp	2012-07-20 13:04:43 +0000
+++ plugins/Dev/Dialog.cpp	2012-07-20 13:49:53 +0000
@@ -21,13 +21,16 @@
 #include "resource.h"
 #include "Util.h"
 
+#include <unordered_set>
 #include <vector>
 
 #include <CriticalSection.h>
 
 #include <commctrl.h>
+#include <windowsx.h>
 
 using std::move;
+using std::unordered_set;
 using std::vector;
 
 using dcpp::CriticalSection;
@@ -38,12 +41,16 @@
 namespace {
 
 // store the messages to be displayed here; process them with a timer.
-struct Message { bool sending; string ip; string peer; string message; };
+struct Message { bool hubOrUser; bool sending; string ip; string peer; string message; };
 vector<Message> messages;
 
 CriticalSection mutex;
 uint16_t counter = 0;
 bool scroll = true;
+bool hubMessages = true;
+bool userMessages = true;
+unordered_set<tstring> filter;
+tstring filterSel;
 
 struct Item {
 	tstring index;
@@ -53,6 +60,12 @@
 	tstring message;
 };
 
+void initFilter(HWND hwnd) {
+#define noFilter _T("0 - No filtering")
+	auto control = GetDlgItem(hwnd, IDC_FILTER);
+	ComboBox_SetCurSel(control, ComboBox_AddString(control, noFilter));
+}
+
 BOOL init(HWND hwnd) {
 	auto control = GetDlgItem(hwnd, IDC_MESSAGES);
 
@@ -80,6 +93,10 @@
 	ListView_InsertColumn(control, 4, &col);
 
 	SendMessage(GetDlgItem(hwnd, IDC_SCROLL), BM_SETCHECK, BST_CHECKED, 0);
+	SendMessage(GetDlgItem(hwnd, IDC_HUB_MESSAGES), BM_SETCHECK, BST_CHECKED, 0);
+	SendMessage(GetDlgItem(hwnd, IDC_USER_MESSAGES), BM_SETCHECK, BST_CHECKED, 0);
+
+	initFilter(hwnd);
 
 	SetTimer(hwnd, 1, 500, 0);
 
@@ -101,10 +118,19 @@
 	LVITEM lvi = { 0 };
 
 	for(auto& message: messages_) {
+		if(!(message.hubOrUser ? hubMessages : userMessages)) {
+			continue;
+		}
+
+		auto ip = Util::toT(message.ip);
+		if(!filterSel.empty() && ip != filterSel) {
+			continue;
+		}
+
 		auto item = new Item;
 		item->index = Util::toT(Util::toString(counter));
 		item->dir = message.sending ? _T("Out") : _T("In");
-		item->ip = Util::toT(message.ip);
+		item->ip = move(ip);
 		item->peer = Util::toT(message.peer);
 		item->message = Util::toT(message.message);
 
@@ -136,9 +162,13 @@
 		ListView_SetItem(control, &lvi);
 
 		++counter;
+
+		if(filter.find(item->ip) == filter.end()) {
+			ComboBox_AddString(GetDlgItem(hwnd, IDC_FILTER), filter.insert(item->ip).first->c_str());
+		}
 	}
 
-	if(scroll) {
+	if(scroll && lvi.lParam) { // make sure something was added
 		ListView_EnsureVisible(control, lvi.iItem, FALSE);
 	}
 }
@@ -184,8 +214,19 @@
 	CloseClipboard();
 }
 
-void switchScroll(HWND hwnd) {
-	scroll = SendMessage(GetDlgItem(hwnd, IDC_SCROLL), BM_GETCHECK, 0, 0) == BST_CHECKED;
+void filterSelChanged(HWND hwnd) {
+	auto control = GetDlgItem(hwnd, IDC_FILTER);
+
+	auto sel = ComboBox_GetCurSel(hwnd);
+
+	tstring str(ComboBox_GetLBTextLen(control, sel), '\0');
+	ComboBox_GetLBText(control, sel, &str[0]);
+
+	if(str == noFilter) {
+		filterSel.clear();
+	} else {
+		filterSel = move(str);
+	}
 }
 
 void clear(HWND hwnd) {
@@ -201,10 +242,15 @@
 
 	ListView_DeleteAllItems(control);
 	counter = 0;
+
+	ComboBox_ResetContent(GetDlgItem(hwnd, IDC_FILTER));
+	filter.clear();
+	filterSel.clear();
+	initFilter(hwnd);
 }
 
-void command(HWND hwnd, UINT id) {
-	switch(id) {
+void command(HWND hwnd, WPARAM wParam) {
+	switch(LOWORD(wParam)) {
 	case IDOK:
 	case IDCANCEL:
 		{
@@ -220,7 +266,27 @@
 
 	case IDC_SCROLL:
 		{
-			switchScroll(hwnd);
+			scroll = SendMessage(GetDlgItem(hwnd, IDC_SCROLL), BM_GETCHECK, 0, 0) == BST_CHECKED;
+			break;
+		}
+
+	case IDC_HUB_MESSAGES:
+		{
+			hubMessages = SendMessage(GetDlgItem(hwnd, IDC_HUB_MESSAGES), BM_GETCHECK, 0, 0) == BST_CHECKED;
+			break;
+		}
+
+	case IDC_USER_MESSAGES:
+		{
+			userMessages = SendMessage(GetDlgItem(hwnd, IDC_USER_MESSAGES), BM_GETCHECK, 0, 0) == BST_CHECKED;
+			break;
+		}
+
+	case IDC_FILTER:
+		{
+			if(HIWORD(wParam) == CBN_SELENDOK) {
+				filterSelChanged(hwnd);
+			}
 			break;
 		}
 
@@ -245,7 +311,7 @@
 		}
 	case WM_COMMAND:
 		{
-			command(hwnd, LOWORD(wParam));
+			command(hwnd, wParam);
 			break;
 		}
 	case WM_CLOSE:
@@ -286,8 +352,8 @@
 #endif
 }
 
-void Dialog::write(bool sending, string ip, string peer, string message) {
-	Message msg = { sending, move(ip), move(peer), move(message) };
+void Dialog::write(bool hubOrUser, bool sending, string ip, string peer, string message) {
+	Message msg = { hubOrUser, sending, move(ip), move(peer), move(message) };
 	Lock l(mutex);
 	messages.push_back(move(msg));
 }

=== modified file 'plugins/Dev/Dialog.h'
--- plugins/Dev/Dialog.h	2012-07-20 13:04:43 +0000
+++ plugins/Dev/Dialog.h	2012-07-20 13:49:53 +0000
@@ -28,7 +28,7 @@
 	~Dialog();
 
 	void create(HWND parent);
-	void write(bool sending, string ip, string peer, string message);
+	void write(bool hubOrUser, bool sending, string ip, string peer, string message);
 
 	static HINSTANCE instance;
 

=== modified file 'plugins/Dev/Plugin.cpp'
--- plugins/Dev/Plugin.cpp	2012-07-20 13:04:43 +0000
+++ plugins/Dev/Plugin.cpp	2012-07-20 13:49:53 +0000
@@ -98,22 +98,22 @@
 }
 
 Bool Plugin::onHubDataIn(HubDataPtr hHub, const char* message) {
-	dialog.write(false, hHub->ip, "Hub " + string(hHub->url), message);
+	dialog.write(true, false, hHub->ip, "Hub " + string(hHub->url), message);
 	return False;
 }
 
 Bool Plugin::onHubDataOut(HubDataPtr hHub, const char* message, Bool* bBreak) {
-	dialog.write(true, hHub->ip, "Hub " + string(hHub->url), message);
+	dialog.write(true, true, hHub->ip, "Hub " + string(hHub->url), message);
 	return False;
 }
 
 Bool Plugin::onConnectionDataIn(ConnectionDataPtr hConn, const char* message) {
-	dialog.write(false, hConn->ip, "User " + string(reinterpret_cast<UserDataPtr>(hConn->object)->nick), message);
+	dialog.write(false, false, hConn->ip, "User " + string(reinterpret_cast<UserDataPtr>(hConn->object)->nick), message);
 	return False;
 }
 
 Bool Plugin::onConnectionDataOut(ConnectionDataPtr hConn, const char* message) {
-	dialog.write(true, hConn->ip, "User " + string(reinterpret_cast<UserDataPtr>(hConn->object)->nick), message);
+	dialog.write(false, true, hConn->ip, "User " + string(reinterpret_cast<UserDataPtr>(hConn->object)->nick), message);
 	return False;
 }
 

=== modified file 'plugins/Dev/resource.h'
--- plugins/Dev/resource.h	2012-07-20 13:04:43 +0000
+++ plugins/Dev/resource.h	2012-07-20 13:49:53 +0000
@@ -8,6 +8,9 @@
 #define IDC_COPY                        1002
 #define IDC_CLEAR                       1003
 #define IDC_SCROLL                      1004
+#define IDC_HUB_MESSAGES                1005
+#define IDC_USER_MESSAGES               1006
+#define IDC_FILTER                      1007
 
 // Next default values for new objects
 // 
@@ -15,7 +18,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        102
 #define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1005
+#define _APS_NEXT_CONTROL_VALUE         1008
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif

=== modified file 'plugins/Dev/resource.rc'
--- plugins/Dev/resource.rc	2012-07-20 13:04:43 +0000
+++ plugins/Dev/resource.rc	2012-07-20 13:49:53 +0000
@@ -98,8 +98,11 @@
     PUSHBUTTON      "Cancel",IDCANCEL,615,458,50,14,NOT WS_VISIBLE | WS_DISABLED
     CONTROL         "",IDC_MESSAGES,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP,7,7,709,441
     PUSHBUTTON      "Copy selected messages",IDC_COPY,7,458,129,14
-    PUSHBUTTON      "Clear the list",IDC_CLEAR,282,458,88,14
-    CONTROL         "Auto-scroll",IDC_SCROLL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,181,462,58,10
+    PUSHBUTTON      "Clear the list",IDC_CLEAR,563,458,88,14
+    CONTROL         "Auto-scroll",IDC_SCROLL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,150,462,50,10
+    CONTROL         "Add hub messages",IDC_HUB_MESSAGES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,213,462,76,10
+    CONTROL         "Add user messages",IDC_USER_MESSAGES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,305,462,78,10
+    COMBOBOX        IDC_FILTER,404,460,140,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
 END