Esempio n. 1
0
class PySideReconnectionStrategy(ReconnectionStrategy):

    can_reconnect = True

    def __init__(self):
        self.manager = QNetworkConfigurationManager()
        self.session = self._session()
        self.manager.onlineStateChanged.connect(self._connect)

    def _session(self):
        return QNetworkSession(self.manager.defaultConfiguration())

    def _connect(self, is_connected):
        if is_connected is False:
            # create a new session
            self.session = self._session()
            # start session if required
            caps = self.manager.capabilities()
            if caps & QNetworkConfigurationManager.CanStartAndStopInterfaces:
                self.session.open()
                self.session.waitForOpened(-1)

    def on_connect_attempt(self, conn):
        self._connect(self.manager.isOnline())

    def on_connection_open(self, conn):
        caps = self.manager.capabilities()
        if caps & QNetworkConfigurationManager.ForcedRoaming:
            reconnect = conn.force_reconnect
            self.session.newConfigurationActivated.connect(reconnect)

    def on_connection_closed(self, conn):
        conn._reconnect() if not self.is_active else None
Esempio n. 2
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.serviceProvider = 0
        self.popupMenu = None
        self.mapControlButtons = []
        self.mapControlTypes = []
        self.markerObjects = []
        self.setWindowTitle(self.tr('Map Viewer Demo'))

        self.routingManager = None
        self.mapManager = None
        self.mapWidget = None
        self.markerIcon = None
        self.slider = None

        manager = QNetworkConfigurationManager()

        canStartIAP = manager.capabilities() & QNetworkConfigurationManager.CanStartAndStopInterfaces

        configuration = manager.defaultConfiguration()

        if not configuration.isValid or (not canStartIAP and configuration.starte() != QNetworkConfiguration.Active):
            QMessageBox.information(self, self.tr('Map Viewer Demo'),
                                    self.tr('Available Access Points not found.'))
            return

        self.session = QNetworkSession(configuration, self)
        self.session.opened.connect(self.networkSessionOpened)
        self.session.error.connect(self.error)

        self.session.open()
        self.session.waitForOpened()

        self.setProvider('nokia')
        self.setupUi()
Esempio n. 3
0
class ConnMonitor(QObject):

	connectionSwitched = QtCore.Signal();
	connected = QtCore.Signal()
	disconnected = QtCore.Signal()
	
	def __init__(self):
		super(ConnMonitor,self).__init__();
		
		self.session = None
		self.online = False
		self.manager = QNetworkConfigurationManager()
		self.config = self.manager.defaultConfiguration() if self.manager.isOnline() else None
		
		self.manager.onlineStateChanged.connect(self.onOnlineStateChanged)
		self.manager.configurationChanged.connect(self.onConfigurationChanged)
		
		self.connected.connect(self.onOnline)
		self.disconnected.connect(self.onOffline)
		self.session =  QNetworkSession(self.manager.defaultConfiguration());
		self.session.stateChanged.connect(self.sessionStateChanged)
		self.session.closed.connect(self.disconnected);
		#self.session.opened.connect(self.connected);
		#self.createSession();
		#self.session.waitForOpened(-1)
	
	
	def sessionStateChanged(self,state):
		print "state changed "+str(state);
	
	def createSession(self):
		
		#self.session.setSessionProperty("ConnectInBackground", True);
		self.session.open();
	
	def isOnline(self):
		return self.manager.isOnline()
	
	def onConfigurationChanged(self,config):
		if self.manager.isOnline() and config.state() == PySide.QtNetwork.QNetworkConfiguration.StateFlag.Active:
			if self.config is None:
				self.config = config
			else:
				self.connected.emit()
				self.createSession();
		
	def onOnlineStateChanged(self,state):
		self.online = state
		if state:
			self.connected.emit()
		else:
			self.config = None
			self.disconnected.emit()
	
	def onOnline(self):
		print "ONLINE"
		#self.session = QNetworkSession(self.config)
	
	def onOffline(self):
		print "OFFLINE";
Esempio n. 4
0
	def __init__(self):
		super(ConnMonitor,self).__init__();
		
		self.session = None
		self.online = False
		self.manager = QNetworkConfigurationManager()
		self.config = self.manager.defaultConfiguration() if self.manager.isOnline() else None
		
		self.manager.onlineStateChanged.connect(self.onOnlineStateChanged)
		self.manager.configurationChanged.connect(self.onConfigurationChanged)
		
		self.connected.connect(self.onOnline)
		self.disconnected.connect(self.onOffline)
		self.session =  QNetworkSession(self.manager.defaultConfiguration());
		self.session.stateChanged.connect(self.sessionStateChanged)
		self.session.closed.connect(self.disconnected);
  def __init__(self):
    QObject.__init__(self)
    self._httpd = None
    self._thread = None
    self._port = 8000
    self._alive = False

    #For starting and stopping the server based on network connectiviy changes
    self._nm = QNetworkConfigurationManager()
    self._nm.onlineStateChanged.connect(self._onlineStateChanged)
Esempio n. 6
0
def qncm():
  from PySide.QtNetwork import QNetworkConfigurationManager
  return QNetworkConfigurationManager()
Esempio n. 7
0
 def get_network_configuration(self):
     network_manager = QNetworkConfigurationManager()
     network_configuration = network_manager.defaultConfiguration()
     return network_configuration
Esempio n. 8
0
 def get_network_configuration(self):
     network_manager = QNetworkConfigurationManager()
     network_configuration = network_manager.defaultConfiguration()
     return network_configuration
Esempio n. 9
0
 def __init__(self):
     self.manager = QNetworkConfigurationManager()
     self.session = self._session()
     self.manager.onlineStateChanged.connect(self._connect)
Esempio n. 10
0
 def check_online_status(self):
     mgr = QNetworkConfigurationManager()
     activeConfigs = mgr.allConfigurations(QNetworkConfiguration.Active)
     return mgr.isOnline()
class ElServer(QObject):
  '''This is the class to start and manage a http server
    in a separate thread.It also contains the necessary '''
  CONNECTIONS = ConnectionsModel()
  def __init__(self):
    QObject.__init__(self)
    self._httpd = None
    self._thread = None
    self._port = 8000
    self._alive = False

    #For starting and stopping the server based on network connectiviy changes
    self._nm = QNetworkConfigurationManager()
    self._nm.onlineStateChanged.connect(self._onlineStateChanged)

  def _onlineStateChanged(self, isOnline):
    if isOnline:
      #Restart the server to get the new IPs, if any
      self.stop()
      self.start()
    else:
      self.stop()

  @Slot()
  def start(self):
    # Allow only 1 instance of the server per object.
    # Also create the server only when we are connected.
    if self._httpd is None and self._nm.isOnline():
      self._thread = threading.Thread(target=self._thread_proc)
      self._thread.setDaemon(True)
      self._thread.start()
      print "Started HTTP server on port: ", self._port

  def _thread_proc(self):
    ''' The HTTP Server Thread'''
    while self._port < 10000:
      try:
        self._httpd = ThreadedHTTPServer(("", self._port),ElRequestHandler)
        break
      except:
        self._port += 1
    self._setAlive(True)
    self._httpd.serve_forever()
    self._thread = None

  def _isAlive(self):
    return self._alive

  def _setAlive(self,value):
    if value != self._alive:
      self._alive = value
      self.statusChanged.emit()

  statusChanged = Signal()
  isAlive = Property(bool, _isAlive, _setAlive, notify = statusChanged)

  @Slot()
  def stop(self):
    if self._httpd is not None:
      self._httpd.shutdown()
      self._httpd = None
      self._setAlive(False)
      print "Stopping Server..."

  def get_ips(self):
    ''' Gets a list of ip addresses the current device is using. '''
    ifconfig = subprocess.Popen('/sbin/ifconfig', stdout=subprocess.PIPE)
    stdout, stderr = ifconfig.communicate()

    ips = re.findall('addr:([^ ]+)', stdout)
    ips = filter(lambda ip: not ip.startswith('127.'), ips) or None
    return ips

  @Slot(result=unicode)
  def statusString(self):
    ips = self.get_ips()
    if ips is None:
      return ""
    return u'<center>Visit:<br>' + u'<br>or '.join(u'http://%s:%d/' % (ip, self._port) for ip in ips) + '<br/>on your computer, to access your files.</center>'

  @Slot(result=QObject)
  def connections(self):
    return self.CONNECTIONS

  @classmethod
  def isAcceptable(self, address):
    return ElServer.CONNECTIONS.status(address)