Пример #1
0
    def __getstate__(self):
        data = QByteArray()
        stream = QDataStream(data, QIODevice.WriteOnly)
        stream.writeQVariant(self.windows)

        stream.writeInt(self._s_restoreDataVersion)
        stream.writeQVariant(self.crashedSession)
        stream.writeQVariant(self.closedWindows)

        return data
Пример #2
0
    def saveState(self):
        restoreData = RestoreData()
        for window in self._windows:
            restoreData.windows.append(BrowserWindow.SavedWindow(window))
        if self._restoreManager and self._restoreManager.isValid():
            stream = QDataStream(restoreData.crashedSession,
                                 QIODevice.WriteOnly)
            stream.writeQVariant(self._restoreManager.restoreData())
        restoreData.closedWindows = self._closedWindowsManager.saveState()
        data = QByteArray()
        stream = QDataStream(data, QIODevice.WriteOnly)

        stream.writeInt(const.sessionVersion)
        stream.writeBytes(pickle.dumps(restoreData))
        return data
    def saveState(self):
        '''
        @return: QByteArray
        '''
        data = QByteArray()
        stream = QDataStream(data, QIODevice.WriteOnly)

        stream.writeInt(self._s_closedWindowsVersion)

        # Only save last 3 windows
        windowCount = min(max(0, len(self._closedWindows)), 3)
        stream.writeInt(windowCount)

        for window in self._closedWindows[:windowCount]:
            stream.writeQVariant(window.windowState)

        return data
Пример #4
0
    def _saveState(self):
        '''
        @return: QByteArray
        '''
        # history - web database - local storage - cache - icons
        data = QByteArray()
        stream = QDataStream(data, QIODevice.WriteOnly)

        stream.writeInt(self._s_stateDataVersoin)

        if not self._ui.history.isChecked():
            stream.writeInt(-1)
        else:
            stream.writeInt(self._ui.historyLength.currentIndex())

        stream.writeBool(self._ui.databases.isChecked())
        stream.writeBool(self._ui.localStorage.isChecked())
        stream.writeBool(self._ui.cache.isChecked())
        stream.writeBool(self._ui.cookies.isChecked())

        return data
Пример #5
0
        result['test1'] = result['test1'].toEncoded()
        return result

    def __setstate__(self, state):
        print('__setstate__')
        for key, val in state.items():
            if key == 'test1':
                self.test1 = QUrl.fromEncoded(val)
            else:
                setattr(self, key, val)


if argv[1] == 'dump':
    data = QByteArray()
    ds = QDataStream(data, QIODevice.WriteOnly)
    ds.writeInt(1)
    obj = ObjType()
    ds.writeQVariant([obj, obj])
    print(data)
    with open('test.dat', 'wb') as fp:
        fp.write(data)
elif argv[1] == 'load':
    with open('test.dat', 'rb') as fp:
        data = fp.read()
    dsOut = QDataStream(QByteArray(data))
    ver = dsOut.readInt()
    lst = dsOut.readQVariant()
    print(lst[0].test1)
    print(lst)
else:
    raise RuntimeError('action should be dump or load')