[smuxi/experiments/tag_messages: 1/41] Engine(-Tests), Frontend-GNOME: support matching filters against NetworkID (closes: #838)
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi/experiments/tag_messages: 1/41] Engine(-Tests), Frontend-GNOME: support matching filters against NetworkID (closes: #838)
- Date: Sun, 3 Apr 2016 10:57:15 +0000 (UTC)
commit cf887e3e78e07d40f8bb8ecd388e93f120a3b353
Author: Mirco Bauer <meebey meebey net>
Date: Fri Nov 27 16:26:32 2015 +0100
Engine(-Tests), Frontend-GNOME: support matching filters against NetworkID (closes: #838)
src/Engine-Tests/Engine-Tests.csproj | 1 +
src/Engine-Tests/SessionTests.cs | 65 ++++++++++++++++++++++++++
src/Engine/Config/Config.cs | 1 +
src/Engine/Config/FilterListController.cs | 5 ++-
src/Engine/Config/FilterModel.cs | 3 +-
src/Engine/Session.cs | 17 ++++++-
src/Frontend-GNOME/Views/FilterListWidget.cs | 30 +++++++++++-
7 files changed, 118 insertions(+), 4 deletions(-)
---
diff --git a/src/Engine-Tests/Engine-Tests.csproj b/src/Engine-Tests/Engine-Tests.csproj
index 1c30005..c0c7765 100644
--- a/src/Engine-Tests/Engine-Tests.csproj
+++ b/src/Engine-Tests/Engine-Tests.csproj
@@ -45,6 +45,7 @@
<Compile Include="JsonMessageBufferTests.cs" />
<Compile Include="MessageDtoModelV1Tests.cs" />
<Compile Include="SqliteMessageBufferTests.cs" />
+ <Compile Include="SessionTests.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
diff --git a/src/Engine-Tests/SessionTests.cs b/src/Engine-Tests/SessionTests.cs
new file mode 100644
index 0000000..9673656
--- /dev/null
+++ b/src/Engine-Tests/SessionTests.cs
@@ -0,0 +1,65 @@
+// Smuxi - Smart MUltipleXed Irc
+//
+// Copyright (c) 2015 Mirco Bauer <meebey meebey net>
+//
+// Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+
+namespace Smuxi.Engine
+{
+ [TestFixture]
+ public class SessionTests
+ {
+ Session Session { get; set; }
+ TestProtocolManager Protocol { get; set; }
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp()
+ {
+ Engine.Init();
+ Session = new Session(Engine.Config,
+ Engine.ProtocolManagerFactory,
+ "local");
+ Protocol = new TestProtocolManager(Session);
+ }
+
+ [Test]
+ public void IsFilteredMessage()
+ {
+ var chat = new GroupChatModel("testchat", "Test Chat", Protocol);
+ Assert.IsFalse(Session.IsFilteredMessage(chat, "foobar", MessageType.Normal));
+
+ var filters = new List<FilterModel>(Session.Filters);
+ filters.Add(
+ new FilterModel() {
+ NetworkID = "TESTnet",
+ MessagePattern = "/^filter me$/"
+ }
+ );
+ filters.Add(
+ new FilterModel() {
+ NetworkID = "OTHERnet"
+ }
+ );
+ Session.Filters = filters;
+ Assert.IsTrue(Session.IsFilteredMessage(chat, "filter me", MessageType.Normal));
+ Assert.IsFalse(Session.IsFilteredMessage(chat, "do not filter me", MessageType.Normal));
+ }
+ }
+}
diff --git a/src/Engine/Config/Config.cs b/src/Engine/Config/Config.cs
index 6509d30..58b9d52 100644
--- a/src/Engine/Config/Config.cs
+++ b/src/Engine/Config/Config.cs
@@ -644,6 +644,7 @@ namespace Smuxi.Engine
foreach (string filter in filters) {
cprefix = "Filters/" + filter + "/";
LoadUserEntry(user, cprefix + "Protocol", null);
+ LoadUserEntry(user, cprefix + "NetworkID", null);
LoadUserEntry(user, cprefix + "ChatType", null);
LoadUserEntry(user, cprefix + "ChatID", null);
LoadUserEntry(user, cprefix + "MessageType", null);
diff --git a/src/Engine/Config/FilterListController.cs b/src/Engine/Config/FilterListController.cs
index e5b7a34..ccf5a3a 100644
--- a/src/Engine/Config/FilterListController.cs
+++ b/src/Engine/Config/FilterListController.cs
@@ -1,7 +1,7 @@
/*
* Smuxi - Smart MUltipleXed Irc
*
- * Copyright (c) 2005-2006, 2010 Mirco Bauer <meebey meebey net>
+ * Copyright (c) 2005-2006, 2010, 2015 Mirco Bauer <meebey meebey net>
*
* Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
*
@@ -69,6 +69,7 @@ namespace Smuxi.Engine
}
FilterModel filter = new FilterModel();
filter.Protocol = (string) f_UserConfig[prefix + "Protocol"];
+ filter.NetworkID = (string) f_UserConfig[prefix + "NetworkID"];
var chatType = (string) f_UserConfig[prefix + "ChatType"];
if (!String.IsNullOrEmpty(chatType)) {
filter.ChatType = (ChatType) Enum.Parse(
@@ -111,6 +112,7 @@ namespace Smuxi.Engine
string prefix = "Filters/" + newKey + "/";
f_UserConfig[prefix + "Protocol"] = filter.Protocol;
+ f_UserConfig[prefix + "NetworkID"] = filter.NetworkID;
if (filter.ChatType == null) {
f_UserConfig[prefix + "ChatType"] = String.Empty;
} else {
@@ -140,6 +142,7 @@ namespace Smuxi.Engine
string prefix = "Filters/" + key + "/";
f_UserConfig[prefix + "Protocol"] = filter.Protocol;
+ f_UserConfig[prefix + "NetworkID"] = filter.NetworkID;
if (filter.ChatType == null) {
f_UserConfig[prefix + "ChatType"] = String.Empty;
} else {
diff --git a/src/Engine/Config/FilterModel.cs b/src/Engine/Config/FilterModel.cs
index 99fdcc1..cb57cad 100644
--- a/src/Engine/Config/FilterModel.cs
+++ b/src/Engine/Config/FilterModel.cs
@@ -1,7 +1,7 @@
/*
* Smuxi - Smart MUltipleXed Irc
*
- * Copyright (c) 2005-2006, 2010 Mirco Bauer <meebey meebey net>
+ * Copyright (c) 2005-2006, 2010, 2015 Mirco Bauer <meebey meebey net>
*
* Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
*
@@ -28,6 +28,7 @@ namespace Smuxi.Engine
public class FilterModel
{
public string Protocol { get; set; }
+ public string NetworkID { get; set; }
public string ChatID { get; set; }
public ChatType? ChatType { get; set; }
public MessageType? MessageType { get; set; }
diff --git a/src/Engine/Session.cs b/src/Engine/Session.cs
index 2cbbf8d..31417d6 100644
--- a/src/Engine/Session.cs
+++ b/src/Engine/Session.cs
@@ -1,7 +1,7 @@
/*
* Smuxi - Smart MUltipleXed Irc
*
- * Copyright (c) 2005-2014 Mirco Bauer <meebey meebey net>
+ * Copyright (c) 2005-2015 Mirco Bauer <meebey meebey net>
*
* Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
*
@@ -125,6 +125,14 @@ namespace Smuxi.Engine
}
}
+ internal ICollection<FilterModel> Filters {
+ get {
+ return _Filters;
+ }
+ set {
+ _Filters = value;
+ }
+ }
static Session()
{
@@ -1658,6 +1666,13 @@ namespace Smuxi.Engine
filter.Protocol != chat.ProtocolManager.Protocol) {
continue;
}
+ if (!String.IsNullOrEmpty(filter.NetworkID) &&
+ chat.ProtocolManager != null &&
+ String.Compare(filter.NetworkID,
+ chat.ProtocolManager.NetworkID,
+ StringComparison.OrdinalIgnoreCase) != 0) {
+ continue;
+ }
if (filter.ChatType.HasValue &&
filter.ChatType != chat.ChatType) {
continue;
diff --git a/src/Frontend-GNOME/Views/FilterListWidget.cs b/src/Frontend-GNOME/Views/FilterListWidget.cs
index e0dec63..cd9ccd3 100644
--- a/src/Frontend-GNOME/Views/FilterListWidget.cs
+++ b/src/Frontend-GNOME/Views/FilterListWidget.cs
@@ -1,6 +1,6 @@
// Smuxi - Smart MUltipleXed Irc
//
-// Copyright (c) 2010 Mirco Bauer <meebey meebey net>
+// Copyright (c) 2010, 2015 Mirco Bauer <meebey meebey net>
//
// Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
//
@@ -136,6 +136,7 @@ namespace Smuxi.Frontend.Gnome
if (key == -1) {
// new filter
if (String.IsNullOrEmpty(filter.Protocol) &&
+ String.IsNullOrEmpty(filter.NetworkID) &&
filter.ChatType == null &&
String.IsNullOrEmpty(filter.ChatID) &&
filter.MessageType == null &&
@@ -168,6 +169,7 @@ namespace Smuxi.Frontend.Gnome
try {
var filter = new FilterModel();
filter.Protocol = String.Empty;
+ filter.NetworkID = String.Empty;
filter.ChatID = String.Empty;
filter.MessagePattern = String.Empty;
Gtk.TreeIter iter = f_ListStore.AppendValues(filter, -1);
@@ -233,6 +235,32 @@ namespace Smuxi.Frontend.Gnome
column = f_TreeView.AppendColumn(_("Protocol"), comboCellr);
column.SetCellDataFunc(comboCellr, RenderProtocol);
+ // NetworkID
+ textCellr = new Gtk.CellRendererText();
+ textCellr.Editable = true;
+ textCellr.Edited += delegate(object sender, Gtk.EditedArgs e) {
+ Gtk.TreeIter iter;
+ if (!f_ListStore.GetIterFromString(out iter, e.Path)) {
+ return;
+ }
+ var filter = (FilterModel) f_ListStore.GetValue(iter, 0);
+ filter.NetworkID = e.NewText;
+ f_ListStore.EmitRowChanged(new Gtk.TreePath(e.Path), iter);
+ OnChanged(EventArgs.Empty);
+ };
+ column = f_TreeView.AppendColumn(_("Network"), textCellr);
+ column.Resizable = true;
+ column.MinWidth = 80;
+ column.Sizing = Gtk.TreeViewColumnSizing.GrowOnly;
+ column.SetCellDataFunc(textCellr,
+ delegate(Gtk.TreeViewColumn col,
+ Gtk.CellRenderer cellr,
+ Gtk.TreeModel model, Gtk.TreeIter iter) {
+ var filter = (FilterModel) model.GetValue(iter, 0);
+ (cellr as Gtk.CellRendererText).Text = filter.NetworkID;
+ }
+ );
+
f_ChatTypeListStore = new Gtk.ListStore(typeof(string),
typeof(ChatType?));
f_ChatTypeListStore.AppendValues(String.Empty, null);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]