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

List:       kde-commits
Subject:    branches/kopete/0.12/kopete/protocols/msn
From:       Guillaume Laurent <glaurent () telegraph-road ! org>
Date:       2006-04-04 23:13:08
Message-ID: 1144192388.879918.14125.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 526579 by glaurent:

multiple webcam connection support

 M  +3 -3      ui/msneditaccountui.ui  
 M  +36 -6     webcam.cpp  
 M  +1 -0      webcam.h  


--- branches/kopete/0.12/kopete/protocols/msn/ui/msneditaccountui.ui #526578:526579
@@ -1247,10 +1247,10 @@
                                             <cstring>m_useWebcamPort</cstring>
                                         </property>
                                         <property name="text">
-                                            <string>S&amp;pecify a port for incoming \
webcam connection:</string> +                                            \
<string>S&amp;pecify a base port for incoming webcam connections:</string>  \
                </property>
                                         <property name="whatsThis" stdset="0">
-                                            <string>If you are behind a firewall, \
you may specify a port to use for the incoming connection, and configure your \
firewall to accept connections on this port. Incoming connections are used for the \
webcam. If you don't specify a port yourself, the operating system will choose an \
available port for you. It is recommended to leave the checkbox unchecked.</string> + \
<string>If you are behind a firewall, you may specify a base port to use for the \
incoming connection, and configure your firewall to accept connections on a range of \
10 ports, starting at this one. Incoming connections are used for the webcam. If you \
don't specify a port yourself, the operating system will choose an available port for \
you. It is recommended to leave the checkbox unchecked.</string>  </property>
                                     </widget>
                                     <widget class="QSpinBox">
@@ -1270,7 +1270,7 @@
                                             <number>6891</number>
                                         </property>
                                         <property name="whatsThis" stdset="0">
-                                            <string>If you are behind a firewall, \
you may specify a port to use for the incoming connection, and configure your \
firewall to accept connections on this port. Incoming connections are used for the \
webcam. If you don't specify a port yourself, the operating system will choose an \
available port for you. It is recommended to leave the checkbox unchecked.</string> + \
<string>If you are behind a firewall, you may specify a base port to use for the \
incoming connection, and configure your firewall to accept connections on a range of \
10 ports, starting at this one. Incoming connections are used for the webcam. If you \
don't specify a port yourself, the operating system will choose an available port for \
you. It is recommended to leave the checkbox unchecked.</string>  </property>
                                     </widget>
                                 </hbox>
--- branches/kopete/0.12/kopete/protocols/msn/webcam.cpp #526578:526579
@@ -499,13 +499,9 @@
 		ip+=QString("<tcpipaddress%1>%2</tcpipaddress%3>").arg(ip_number).arg(*it).arg(ip_number);
  ++ip_number;
 	}
+
+        QString port = QString::number(getAvailablePort());
 	
-	KConfig *config = KGlobal::config();
-	config->setGroup( "MSN" );
-	QString port=config->readEntry("WebcamPort" );
-	if(port.isEmpty() || port == "0" )
-		port="6891";
-	
 	m_listener = new KServerSocket(port, this) ;
 	
 	return "<" + who + \
"><version>2.0</version><rid>"+QString::number(rid)+"</rid><udprid>"+QString::number(r \
id+1)+"</udprid><session>"+QString::number(session)+"</session><ctypes>0</ctypes><cpu>2931</cpu>" \
+ @@ -514,6 +510,40 @@
 			"<codec></codec><channelmode>1</channelmode></"+who+">\r\n\r\n";
 }
 
+int Webcam::getAvailablePort()
+{
+    KConfig *config = KGlobal::config();
+    config->setGroup( "MSN" );
+    QString basePort=config->readEntry("WebcamPort");
+    if(basePort.isEmpty() || basePort == "0" )
+		basePort="6891";
+	
+    uint firstport = basePort.toInt();
+    uint maxOffset=config->readUnsignedNumEntry("WebcamMaxPortOffset", 10);
+    uint lastport = firstport + maxOffset;
+
+	// try to find an available port
+	//
+    KServerSocket *ss = new KServerSocket();
+    ss->setFamily(KResolver::InetFamily);
+    bool found = false;
+	unsigned int port = firstport;
+    for( ; port <= lastport; ++port) {
+		ss->setAddress( QString::number( port ) );
+		bool success = ss->listen();
+		if( found = ( success && ss->error() == KSocketBase::NoError ) )
+			break;
+		ss->close();
+    }
+	delete ss;
+	
+
+    kdDebug(14140) << k_funcinfo<< "found available port : " << port << endl;
+
+	return port;
+}
+
+
 /* ---------- Now functions about the dirrect connection  --------- */
 
 void Webcam::slotSocketConnected()
--- branches/kopete/0.12/kopete/protocols/msn/webcam.h #526578:526579
@@ -50,6 +50,7 @@
 		QString m_content;
 		
 		QString xml(uint session , uint rid);
+    int getAvailablePort();
 
 		
 		KNetwork::KServerSocket   *m_listener;


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

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