예제 #1
0
    class SavedWindow(object):
        def __init__(self, window=None):
            '''
            @param: window BrowserWindow
            '''
            self.windowState = QByteArray()
            self.windowGeometry = QByteArray()
            self.windowUiState = {}  # QString -> QVariant
            self.virtualDesktop = -1
            self.currentTab = -1
            self.tabs = []  # WebTab.SavedTab
            if window:
                self.init(window)

        def init(self, window):
            if window.isFullScreen():
                self.windowState = QByteArray()
            else:
                self.windowState = window.saveState()
            self.windowGeometry = window.saveGeometry()
            self.windowUiState = window._saveUiState()

            tabsCount = window.tabCount()
            for idx in range(tabsCount):
                # TabbedWebView
                webView = window.weView(idx)
                if not webView:
                    continue
                webTab = webView.webTab()
                if not webTab:
                    continue
                tab = WebTab.SavedTab(webTab)
                if not tab.isValid():
                    continue
                if webTab.isCurrentTab():
                    self.currentTab = len(self.tabs)
                self.tabs.append(tab)

        def isValid(self):
            for tab in self.tabs:
                if not tab.isValid():
                    return False
            return self.currentTab > -1

        def clear(self):
            self.windowState.clear()
            self.windowGeometry.clear()
            self.virtualDesktop = -1
            self.currentTab = -1
            self.tabs.clear()
예제 #2
0
class RestoreData(object):
    _s_restoreDataVersion = 2

    def __init__(self):
        self.windows = []  # BrowserWindow.SavedWindow
        self.crashedSession = QByteArray()
        self.closedWindows = QByteArray()

    def isValid(self):
        for window in self.windows:
            if not window.isValid():
                return False
        return len(self.windows) > 0

    def clear(self):
        self.windows.clear()
        self.crashedSession.clear()
        self.closedWindows.clear()

    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

    def __setstate__(self, state):
        stream = QDataStream(state)
        self.windows = stream.readQVariant()
        assert (type(self.windows) == list)

        version = stream.readInt()
        if version >= 1:
            self.crashedSession = stream.readQVariant()
        if version >= 2:
            self.closedWindows = stream.readQVariant()