[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/network/ktorrent
From:       Joris Guisson <joris.guisson () gmail ! com>
Date:       2010-10-12 16:27:55
Message-ID: 20101012162755.A03E4AC894 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1185220 by guisson:

Fix bug causing KT to use invalid dbus paths in group paths

 M  +1 -0      ChangeLog  
 M  +23 -16    libktcore/dbus/dbusgroup.cpp  


--- trunk/extragear/network/ktorrent/ChangeLog #1185219:1185220
@@ -31,6 +31,7 @@
 - Improve performance of ViewModel when there are many torrents (216501)
 - Backport several improvements for IP filter auto update from trunk
 - Fix bug causing two instances of ktorrent to be started when missing files dialog \
is shown at startup (252099) +- Fix bug causing KT to use invalid dbus paths in group \
paths  
 Changes in 4.0.3:
 - Fix bug causing wrong encoding to be used when the default save location of a \
                group is read (244873)
--- trunk/extragear/network/ktorrent/libktcore/dbus/dbusgroup.cpp #1185219:1185220
@@ -25,40 +25,47 @@
 
 namespace kt
 {
-	static QString ValidDBusName(const QString & s,int extra_digit)
+	static bool ValidCharacter(const QChar &c)
 	{
+		ushort u = c.unicode();
+		return (u >= 'a' && u <= 'z')
+			|| (u >= 'A' && u <= 'Z')
+			|| (u >= '0' && u <= '9')
+			|| (u == '_');
+	}
+	
+	
+	static bool ValidDBusName(const QString & s)
+	{
 		if (s.isEmpty())
-			return s;
+			return false;
 		
 		QString ret = s;
 		if (ret[0].isDigit())
-			ret[0] = '_';
+			return false;
 		
 		for (int i = 0;i < s.length();i++)
 		{
 			QChar c = ret[i];
-			if (!c.isLetterOrNumber() && c != '_')
-				ret[i] = '_';
+			if (!ValidCharacter(c))
+				return false;
 		}
 		
-		if (extra_digit > 0)
-			return ret + QString::number(extra_digit);
-		else
-			return ret;
+		return true;
 	}
 
 	DBusGroup::DBusGroup(Group* g,GroupManager* gman,QObject* parent)
 			: QObject(parent),group(g),gman(gman)
 	{
-		QString name = ValidDBusName(g->groupName(),0);
-		if (name != g->groupName())
+		QString name = g->groupName();
+		if (!ValidDBusName(name))
 		{
-			// check for dupes if the name has been changed
-			int i = 2;
-			while (gman->find(name) != 0)
+			static int invalid_groups = 0;
+			while (true)
 			{
-				name = ValidDBusName(g->groupName(),i);
-				i++;
+				name = "group_" + QString::number(invalid_groups++);
+				if (!gman->find(name))
+					break;
 			}
 		}
 		QString path = "/group/" + name;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic