aboutsummaryrefslogtreecommitdiffstats
path: root/scudcloud-1.0/lib/cookiejar.py
blob: bd355f24e72ad98b3189a7d85084d58e423f4c72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
from PyQt4 import QtCore, QtNetwork

class PersistentCookieJar(QtNetwork.QNetworkCookieJar):

    def __init__(self, parent):
        super(PersistentCookieJar, self).__init__(parent)
        self.mainWindow = parent
        self.load()
        self.save()

    def save(self):
        listCookies = self.allCookies()
        data = QtCore.QByteArray()
        for cookie in  listCookies:
            if not cookie.isSessionCookie():
                data.append(cookie.toRawForm()+ "\n")
        self.mainWindow.settings.setValue("Cookies",data)

    def load(self):
        data = self.mainWindow.settings.value("Cookies")
        if data is not None:
            self.setAllCookies(QtNetwork.QNetworkCookie.parseCookies(data))