Exemplo n.º 1
0
    def handle_cookiesSave_clicked(self):
        cookieJar = self.framework.get_global_cookie_jar()
        cookieList = cookieJar.allCookies()
        domain = str(self.mainWindow.cookiesCookieJarDomainEdit.text())
        name = str(self.mainWindow.cookiesCookieJarNameEdit.text())
        value = str(self.mainWindow.cookiesCookieJarValueEdit.text())
        if not (domain and name and value):
            return
        cookie = self.find_cookie_by_domain_and_name(cookieList, domain, name)
        if cookie is None:
            # new
            cookie = QNetworkCookie(name, value)
            index = -1
        else:
            index = cookieList.index(cookie)

        cookie.setName(name)
        cookie.setDomain(domain)
        cookie.setValue(value)
        cookie.setPath(str(self.mainWindow.cookiesCookieJarPathEdit.text()))
        if self.mainWindow.cookiesCookieJarSessionCookieCheckbox.isChecked():
            cookie.setExpirationDate(QDateTime())
        else:
            cookie.setExpirationDate(self.mainWindow.cookiesCookieJarExpiryEdit.dateTime())
        cookie.setSecure(self.mainWindow.cookiesCookieJarSecureCheckbox.isChecked())
        cookie.setHttpOnly(self.mainWindow.cookiesCookieJarHttpOnlyCheckbox.isChecked())

        if -1 == index:
            cookieList.append(cookie)
        else:
            cookieList[index] = cookie

        cookieJar.setAllCookies(cookieList)
        self.populate_cookie_jar_tree()
Exemplo n.º 2
0
 def get_cookie(line):
     fields = map(str.strip, line.split("\t"))
     if len(fields) != 7:
         return
     domain, domain_flag, path, is_secure, expiration, name, value = fields
     cookie = QNetworkCookie(name, value)
     cookie.setDomain(domain)
     cookie.setPath(path)
     cookie.setSecure(str2bool(is_secure))
     cookie.setExpirationDate(QDateTime.fromTime_t(int(expiration)))
     return cookie
Exemplo n.º 3
0
 def get_cookie(line):
     fields = map(str.strip, line.split("\t"))
     if len(fields) != 7:
         return
     domain, domain_flag, path, is_secure, expiration, name, value = fields
     cookie = QNetworkCookie(name, value)
     cookie.setDomain(domain)
     cookie.setPath(path)
     cookie.setSecure(str2bool(is_secure))
     cookie.setExpirationDate(QDateTime.fromTime_t(int(expiration)))
     return cookie
Exemplo n.º 4
0
class ShoutCastForm(PluginBase.PluginBase):
    '''Grab Shoutcast streams and save them as "bookmarks" - and play them on
       the currently selected server.

       General shoutcast information is not preserved between runs. Also, the
       shoutcast server/API is pretty lame so timeouts actually occur quite
       frequently.
    '''
    moduleName = '&Shoutcast'
    moduleIcon = "network-workgroup"

    def load(self):
        pass

    def event(self, event):
        if event.type() == QEvent.Paint:
            if not hasattr(self, 'webView'):
                self._load()
                self.event = super(ShoutCastForm, self).event
        return False

    def _load(self):
        self.cookie = QNetworkCookie('Settings', 'Player~others|Bandwidth~ALL|Codec~ALL')
        self.cookie.setDomain('.shoutcast.com')
        self.cookie.setExpirationDate(QDateTime())
        self.cookie.setPath('/')

        self.webView = QWebView(self)
        self.webPage = self.webView.page()
        self.cookiejar = QNetworkCookieJar()
        self.cookiejar.setAllCookies([self.cookie])
        self.webPage.networkAccessManager().setCookieJar(self.cookiejar)

        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.webView)
        self.webView.load(QUrl(HOMEURL))
        self.webPage.setLinkDelegationPolicy(QWebPage.DelegateExternalLinks)
        self.connect(self.webPage, SIGNAL('linkClicked(const QUrl&)'), self._processLink)

    def _processLink(self, url):
        if url.host() == TUNEIN:
            self._playStation(unicode(url.toString()))
        else:
            self.webView.load(url)
            self.webView.show()

    def _playStation(self, url):
        try:
            streamList = streamTools.getStreamList(url)
        except streamTools.ParseError:
            return
        if streamList:
            self.modelManager.playQueue.extend(streamList)
Exemplo n.º 5
0
 def toQtCookie(PyCookie):
     qc = QNetworkCookie( PyCookie.name, PyCookie.value )
     qc.setSecure(PyCookie.secure)
     if PyCookie.path_specified:
         qc.setPath(PyCookie.path)
     if PyCookie.domain != "" :
         qc.setDomain(PyCookie.domain)
     if PyCookie.expires != 0:
         t = QDateTime()
         t.setTime_t(PyCookie.expires)
         qc.setExpirationDate(t)
     # not yet handled(maybe less useful):
     #   py cookie.rest / QNetworkCookie.setHttpOnly()
     return qc
Exemplo n.º 6
0
 def toQtCookie(pyCookie):
     qc = QNetworkCookie(pyCookie.name, pyCookie.value)
     qc.setSecure(pyCookie.secure)
     if pyCookie.path_specified:
         qc.setPath(pyCookie.path)
     if pyCookie.domain != "":
         qc.setDomain(pyCookie.domain)
     if pyCookie.expires != 0:
         t = QDateTime()
         t.setTime_t(pyCookie.expires)
         qc.setExpirationDate(t)
     # not yet handled(maybe less useful):
     #   py cookie.rest / QNetworkCookie.setHttpOnly()
     return qc
Exemplo n.º 7
0
 def line2qcookie(line):
         domain,initial_dot,path,isSecure,expires,name,value=line.split()
         isSecure=(isSecure=="TRUE")
         dt=QDateTime()
         dt.setTime_t(int(expires))
         expires=dt
         c=QNetworkCookie()
         c.setDomain(domain)
         c.setPath(path)
         c.setSecure(isSecure)
         c.setExpirationDate(expires)
         c.setName(name)
         c.setValue(value)
         return c
Exemplo n.º 8
0
    def load(self):
      try:
        ds = pickle.load(open(self.m_cookiesFile, 'rb'))
      except:
        ds = []
      qs = []
      t = int(time.time())
      for d in ds:
        if d['expirationDate'] > t and not d['isSessionCookie']:
          c = QNetworkCookie(d['name'],d['value'])
          c.setDomain(d['domain'])
          c.setExpirationDate(QDateTime.fromTime_t(d['expirationDate']))
          c.setHttpOnly(d['isHttpOnly'])
          c.setSecure(d['isSecure'])
          c.setPath(d['path'])
          qs.append(c)

      #for c in cs
      self.setAllCookies(qs)
Exemplo n.º 9
0
    def har_cookie2qt(cls, cookie):
        qcookie = QNetworkCookie()
        qcookie.setName(cookie["name"])
        qcookie.setValue(cookie["value"])

        if 'domain' in cookie:
            qcookie.setDomain(cookie["domain"])

        if 'httpOnly' in cookie:
            qcookie.setHttpOnly(cookie["httpOnly"])

        if 'secure' in cookie:
            qcookie.setSecure(cookie["secure"])

        if 'path' in cookie:
            qcookie.setPath(cookie["path"])

        if cookie.get('expires'):
            expires = QDateTime.fromString(cookie["expires"], Qt.ISODate)
            qcookie.setExpirationDate(expires)

        return qcookie
Exemplo n.º 10
0
    def har_cookie2qt(cls, cookie):
        qcookie = QNetworkCookie()
        qcookie.setName(cookie["name"])
        qcookie.setValue(cookie["value"])

        if 'domain' in cookie:
            qcookie.setDomain(cookie["domain"])

        if 'httpOnly' in cookie:
            qcookie.setHttpOnly(cookie["httpOnly"])

        if 'secure' in cookie:
            qcookie.setSecure(cookie["secure"])

        if 'path' in cookie:
            qcookie.setPath(cookie["path"])

        if cookie.get('expires'):
            expires = QDateTime.fromString(cookie["expires"], Qt.ISODate)
            qcookie.setExpirationDate(expires)

        return qcookie
Exemplo n.º 11
0
    def handle_cookiesSave_clicked(self):
        cookieJar = self.framework.get_global_cookie_jar()
        cookieList = cookieJar.allCookies()
        domain = str(self.mainWindow.cookiesCookieJarDomainEdit.text())
        name = str(self.mainWindow.cookiesCookieJarNameEdit.text())
        value = str(self.mainWindow.cookiesCookieJarValueEdit.text())
        if not (domain and name and value):
            return
        cookie = self.find_cookie_by_domain_and_name(cookieList, domain, name)
        if cookie is None:
            # new
            cookie = QNetworkCookie(name, value)
            index = -1
        else:
            index = cookieList.index(cookie)

        cookie.setName(name)
        cookie.setDomain(domain)
        cookie.setValue(value)
        cookie.setPath(str(self.mainWindow.cookiesCookieJarPathEdit.text()))
        if self.mainWindow.cookiesCookieJarSessionCookieCheckbox.isChecked():
            cookie.setExpirationDate(QDateTime())
        else:
            cookie.setExpirationDate(
                self.mainWindow.cookiesCookieJarExpiryEdit.dateTime())
        cookie.setSecure(
            self.mainWindow.cookiesCookieJarSecureCheckbox.isChecked())
        cookie.setHttpOnly(
            self.mainWindow.cookiesCookieJarHttpOnlyCheckbox.isChecked())

        if -1 == index:
            cookieList.append(cookie)
        else:
            cookieList[index] = cookie

        cookieJar.setAllCookies(cookieList)
        self.populate_cookie_jar_tree()
Exemplo n.º 12
0
class ShoutCastForm(PluginBase.PluginBase):
    '''Grab Shoutcast streams and save them as "bookmarks" - and play them on
       the currently selected server.

       General shoutcast information is not preserved between runs. Also, the
       shoutcast server/API is pretty lame so timeouts actually occur quite
       frequently.
    '''
    moduleName = '&Shoutcast'
    moduleIcon = "network-workgroup"

    def load(self):
        pass

    def event(self, event):
        if event.type() == QEvent.Paint:
            if not hasattr(self, 'webView'):
                self._load()
                self.event = super(ShoutCastForm, self).event
        return False

    def _load(self):
        self.cookie = QNetworkCookie('Settings', 'Player~others|Bandwidth~ALL|Codec~ALL')
        self.cookie.setDomain('.shoutcast.com')
        self.cookie.setExpirationDate(QDateTime())
        self.cookie.setPath('/')

        self.webView = QWebView(self)
        self.webPage = self.webView.page()
        self.cookiejar = QNetworkCookieJar()
        self.cookiejar.setAllCookies([self.cookie])
        self.webPage.networkAccessManager().setCookieJar(self.cookiejar)

        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.webView)
        self.webView.load(QUrl(HOMEURL))
        self.webPage.setLinkDelegationPolicy(QWebPage.DelegateExternalLinks)
        self.connect(self.webPage, SIGNAL('linkClicked(const QUrl&)'), self._processLink)

    def _processLink(self, url):
        if url.host() == TUNEIN:
            self._playStation(url.toString())
        else:
            self.webView.load(url)
            self.webView.show()

    def _playStation(self, url):
        data = self._retreivePLS(url)
        adrlist = self._parsePLS(data)
        self.mpdclient.send('command_list_ok_begin')
        try:
            for address in adrlist:
                self.mpdclient.send('add', (address,))
        finally:
            self.mpdclient.send('command_list_end')

    def _retreivePLS(self, url):
        conn = httplib.HTTPConnection(TUNEIN)
        conn.request("GET", TUNEINFORMAT % url.split('=')[-1])
        resp = conn.getresponse()
        if resp.status == 200:
            return resp.read().split('\n')
        else:
            raise httplib.HTTPException('Got bad status code.')

    def _parsePLS(self, data):
        adrlist = []
        state = ''
        while data:
            line = data.pop(0)
            if state == '' and line == '[playlist]':
                state = 'playlist'
            elif state == 'playlist':
                if '=' in line:
                    key, value = line.split('=', 1)
                    if key.startswith('File'):
                        adrlist.append(value)
            else:
                raise httplib.HTTPException('Encountered error during parsing of the playlist.')
        return adrlist
Exemplo n.º 13
0
class ShoutCastForm(PluginBase.PluginBase):
    '''Grab Shoutcast streams and save them as "bookmarks" - and play them on
       the currently selected server.

       General shoutcast information is not preserved between runs. Also, the
       shoutcast server/API is pretty lame so timeouts actually occur quite
       frequently.
    '''
    moduleName = '&Shoutcast'
    moduleIcon = "network-workgroup"

    def load(self):
        pass

    def event(self, event):
        if event.type() == QEvent.Paint:
            if not hasattr(self, 'webView'):
                self._load()
                self.event = super(ShoutCastForm, self).event
        return False

    def _load(self):
        self.cookie = QNetworkCookie('Settings',
                                     'Player~others|Bandwidth~ALL|Codec~ALL')
        self.cookie.setDomain('.shoutcast.com')
        self.cookie.setExpirationDate(QDateTime())
        self.cookie.setPath('/')

        self.webView = QWebView(self)
        self.webPage = self.webView.page()
        self.cookiejar = QNetworkCookieJar()
        self.cookiejar.setAllCookies([self.cookie])
        self.webPage.networkAccessManager().setCookieJar(self.cookiejar)

        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.webView)
        self.webView.load(QUrl(HOMEURL))
        self.webPage.setLinkDelegationPolicy(QWebPage.DelegateExternalLinks)
        self.connect(self.webPage, SIGNAL('linkClicked(const QUrl&)'),
                     self._processLink)

    def _processLink(self, url):
        if url.host() == TUNEIN:
            self._playStation(url.toString())
        else:
            self.webView.load(url)
            self.webView.show()

    def _playStation(self, url):
        data = self._retreivePLS(url)
        adrlist = self._parsePLS(data)
        self.mpdclient.send('command_list_ok_begin')
        try:
            for address in adrlist:
                self.mpdclient.send('add', (address, ))
        finally:
            self.mpdclient.send('command_list_end')

    def _retreivePLS(self, url):
        conn = httplib.HTTPConnection(TUNEIN)
        conn.request("GET", TUNEINFORMAT % url.split('=')[-1])
        resp = conn.getresponse()
        if resp.status == 200:
            return resp.read().split('\n')
        else:
            raise httplib.HTTPException('Got bad status code.')

    def _parsePLS(self, data):
        adrlist = []
        state = ''
        while data:
            line = data.pop(0)
            if state == '' and line == '[playlist]':
                state = 'playlist'
            elif state == 'playlist':
                if '=' in line:
                    key, value = line.split('=', 1)
                    if key.startswith('File'):
                        adrlist.append(value)
            else:
                raise httplib.HTTPException(
                    'Encountered error during parsing of the playlist.')
        return adrlist