eric6/WebBrowser/Session/SessionManager.py

Sat, 02 Jan 2021 15:18:36 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 02 Jan 2021 15:18:36 +0100
changeset 7937
181d1160f617
parent 7923
91e843545d9a
child 8143
2c730d5fd177
permissions
-rw-r--r--

Fixed some 'lambda' related issues by converting them to 'functools.partial'.

5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
3 # Copyright (c) 2017 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the session manager.
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import json
7937
181d1160f617 Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
12 import functools
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
14 from PyQt5.QtCore import (
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
15 pyqtSlot, pyqtSignal, Qt, QObject, QTimer, QDir, QFile, QFileInfo,
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
16 QFileSystemWatcher, QByteArray, QDateTime
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
17 )
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
18 from PyQt5.QtWidgets import (
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
19 QActionGroup, QApplication, QInputDialog, QLineEdit, QDialog,
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
20 QDialogButtonBox, QLabel, QComboBox, QVBoxLayout
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
21 )
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
22
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
23 from E5Gui import E5MessageBox
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
24 from E5Gui.E5OverrideCursor import E5OverrideCursor
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 import Utilities
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 import Preferences
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
30 class SessionMetaData(object):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
31 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
32 Class implementing a data structure to store meta data for a session.
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
33 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
34 def __init__(self):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
35 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
36 Constructor
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
37 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
38 self.name = ""
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
39 self.filePath = ""
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
40 self.isActive = False
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
41 self.isDefault = False
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
42 self.isBackup = False
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
43
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
44
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 class SessionManager(QObject):
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 Class implementing the session manager.
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
48
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
49 @signal sessionsMetaDataChanged() emitted to indicate a change of the
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
50 list of session meta data
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
52 sessionsMetaDataChanged = pyqtSignal()
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
53
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
54 SwitchSession = 1
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
55 CloneSession = 2
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
56 ReplaceSession = SwitchSession | 4
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
57 RestoreSession = 8
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
58
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 def __init__(self, parent=None):
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 Constructor
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 @param parent reference to the parent object
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 @type QObject
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 super(SessionManager, self).__init__(parent)
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
68 sessionsDirName = self.getSessionsDirectory()
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
69 sessionsDir = QDir(sessionsDirName)
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 if not sessionsDir.exists():
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
71 sessionsDir.mkpath(sessionsDirName)
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
72
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
73 self.__sessionMetaData = []
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
74 # list containing meta data about saved sessions
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
75
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
76 self.__sessionDefault = os.path.join(sessionsDirName, "session.json")
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
77 self.__sessionBackup1 = os.path.join(sessionsDirName,
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
78 "session.json.old")
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
79 self.__sessionBackup2 = os.path.join(sessionsDirName,
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
80 "session.json.old1")
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
81
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
82 self.__lastActiveSession = Preferences.getWebBrowser(
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
83 "SessionLastActivePath")
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
84 if not QFile.exists(self.__lastActiveSession):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
85 self.__lastActiveSession = self.__sessionDefault
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
86
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
87 self.__sessionsDirectoryWatcher = QFileSystemWatcher(
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
88 [self.getSessionsDirectory()], self)
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
89 self.__sessionsDirectoryWatcher.directoryChanged.connect(
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
90 self.__sessionDirectoryChanged)
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
91
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
92 self.__backupSavedSession()
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
94 self.__autoSaveTimer = None
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
95 self.__shutdown = False
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
96
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
97 def activateTimer(self):
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
98 """
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
99 Public method to activate the session save timer.
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
100 """
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
101 if self.__autoSaveTimer is None:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
102 self.__autoSaveTimer = QTimer()
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
103 self.__autoSaveTimer.setSingleShot(True)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
104 self.__autoSaveTimer.timeout.connect(self.__autoSaveSession)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
105 self.__initSessionSaveTimer()
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 def preferencesChanged(self):
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 Public slot to react upon changes of the settings.
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 self.__initSessionSaveTimer()
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 def getSessionsDirectory(self):
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 Public method to get the directory sessions are stored in.
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 @return name of the sessions directory
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @rtype str
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 return os.path.join(Utilities.getConfigDir(),
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 "web_browser", "sessions")
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 def defaultSessionFile(self):
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 Public method to get the name of the default session file.
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 @return name of the default session file
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 @rtype str
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 """
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
130 return self.__sessionDefault
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
131
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
132 def lastActiveSessionFile(self):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
133 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
134 Public method to get the name of the last active session file.
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
135
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
136 @return name of the last active session file
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
137 @rtype str
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
138 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
139 return self.__lastActiveSession
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
140
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
141 def shutdown(self):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
142 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
143 Public method to perform any shutdown actions.
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
144 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
145 self.__autoSaveTimer.stop()
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
146 if not self.__shutdown:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
147 self.__autoSaveSession(startTimer=False)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
148 self.__shutdown = True
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
149
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
150 def autoSaveSession(self):
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
151 """
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
152 Public method to save the current session state.
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
153 """
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
154 self.__autoSaveSession(startTimer=False)
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 def __initSessionSaveTimer(self):
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 Private slot to initialize the auto save timer.
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.__autoSaveInterval = Preferences.getWebBrowser(
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 "SessionAutoSaveInterval") * 1000
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 if Preferences.getWebBrowser("SessionAutoSave"):
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 if not self.__autoSaveTimer.isActive():
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 self.__autoSaveTimer.start(self.__autoSaveInterval)
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 else:
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 self.__autoSaveTimer.stop()
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 @pyqtSlot()
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
170 def __autoSaveSession(self, startTimer=True):
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 Private slot to save the current session state.
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
173
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
174 @param startTimer flag indicating to restart the timer
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
175 @type bool
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 from WebBrowser.WebBrowserWindow import WebBrowserWindow
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 if not WebBrowserWindow.isPrivate():
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
180 Preferences.setWebBrowser("SessionLastActivePath",
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
181 self.__lastActiveSession)
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
182 self.writeCurrentSession(self.__lastActiveSession)
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
184 if startTimer:
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
185 self.__autoSaveTimer.start(self.__autoSaveInterval)
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 def writeCurrentSession(self, sessionFileName):
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 Public method to write the current session to the given file name.
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 @param sessionFileName file name of the session
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 @type str
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 """
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 from WebBrowser.WebBrowserWindow import WebBrowserWindow
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 sessionData = {"Windows": []}
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
198 activeWindow = WebBrowserWindow.getWindow()
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 for window in WebBrowserWindow.mainWindows():
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 data = window.tabWidget().getSessionData()
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 # add window geometry
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 geometry = window.saveGeometry()
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 data["WindowGeometry"] = bytes(geometry.toBase64()).decode("ascii")
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 sessionData["Windows"].append(data)
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
207
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
208 if window is activeWindow:
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
209 sessionData["CurrentWindowIndex"] = (
5785
7c7c5f9e4fad Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5783
diff changeset
210 len(sessionData["Windows"]) - 1
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
211 )
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
212
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
213 if sessionData["Windows"]:
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
214 with open(sessionFileName, "w") as sessionFile:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
215 json.dump(sessionData, sessionFile, indent=2)
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
216
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
217 @classmethod
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
218 def readSessionFromFile(cls, sessionFileName):
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
219 """
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
220 Class method to read the session data from a file.
5777
2c4441d65ee3 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
222 @param sessionFileName file name of the session file
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
223 @type str
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
224 @return dictionary containing the session data
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
225 @rtype dict
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
226 """
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
227 try:
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
228 with open(sessionFileName, "r") as sessionFile:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
229 sessionData = json.load(sessionFile)
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
230 if not cls.isValidSession(sessionData):
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
231 sessionData = {}
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7785
diff changeset
232 except OSError:
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
233 sessionData = {}
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
234
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
235 return sessionData
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
236
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
237 @classmethod
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
238 def isValidSession(cls, session):
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
239 """
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
240 Class method to check the validity of a session.
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
241
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
242 @param session dictionary containing the session data
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
243 @type dict
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
244 @return flag indicating validity
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
245 @rtype bool
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
246 """
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
247 if not session:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
248 return False
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
249
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
250 if "Windows" not in session:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
251 return False
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
252
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
253 if not session["Windows"]:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
254 return False
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
255
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
256 return True
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
257
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
258 def __backupSavedSession(self):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
259 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
260 Private method to backup the most recently saved session.
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
261 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
262 if QFile.exists(self.__lastActiveSession):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
263
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
264 if QFile.exists(self.__sessionBackup1):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
265 QFile.remove(self.__sessionBackup2)
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
266 QFile.copy(self.__sessionBackup1, self.__sessionBackup2)
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
267
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
268 QFile.remove(self.__sessionBackup1)
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
269 QFile.copy(self.__lastActiveSession, self.__sessionBackup1)
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
270
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
271 def sessionMetaData(self, includeBackups=False):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
272 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
273 Public method to get the sessions meta data.
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
274
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
275 @param includeBackups flag indicating to include backup sessions
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
276 @type bool
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
277 @return list of session meta data
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
278 @rtype list of SessionMetaData
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
279 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
280 self.__fillMetaDataList()
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
281
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
282 metaDataList = self.__sessionMetaData[:]
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
283
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
284 if includeBackups and QFile.exists(self.__sessionBackup1):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
285 data = SessionMetaData()
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
286 data.name = self.tr("Backup 1")
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
287 data.filePath = self.__sessionBackup1
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
288 data.isBackup = True
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
289 metaDataList.append(data)
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
290
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
291 if includeBackups and QFile.exists(self.__sessionBackup2):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
292 data = SessionMetaData()
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
293 data.name = self.tr("Backup 2")
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
294 data.filePath = self.__sessionBackup2
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
295 data.isBackup = True
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
296 metaDataList.append(data)
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
297
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
298 return metaDataList
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
299
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
300 def __fillMetaDataList(self):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
301 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
302 Private method to fill the sessions meta data list.
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
303
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
304 The sessions meta data list is only populated, if the variable holding
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
305 it is empty (i.e. it is populated on demand).
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
306 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
307 if self.__sessionMetaData:
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
308 return
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
309
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
310 sessionFilesInfoList = QDir(self.getSessionsDirectory()).entryInfoList(
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
311 ["*.json"], QDir.Files, QDir.Time)
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
312
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
313 for sessionFileInfo in sessionFilesInfoList:
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
314 sessionData = self.readSessionFromFile(
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
315 sessionFileInfo.absoluteFilePath())
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
316 if not sessionData or not sessionData["Windows"]:
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
317 continue
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
318
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
319 data = SessionMetaData()
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
320 data.name = sessionFileInfo.baseName()
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
321 data.filePath = sessionFileInfo.canonicalFilePath()
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
322
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
323 if sessionFileInfo == QFileInfo(self.defaultSessionFile()):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
324 data.name = self.tr("Default Session")
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
325 data.isDefault = True
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
326
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
327 if self.__isActive(sessionFileInfo):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
328 data.isActive = True
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
329
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
330 if data.isDefault:
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
331 # default session is always first
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
332 self.__sessionMetaData.insert(0, data)
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
333 else:
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
334 self.__sessionMetaData.append(data)
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
335
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
336 def __isActive(self, filePath):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
337 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
338 Private method to check, if a given file is the active one.
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
339
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
340 @param filePath path of the session file to be checked
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
341 @type str or QFileInfo
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
342 @return flag indicating the active file
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
343 @rtype bool
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
344 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
345 return QFileInfo(filePath) == QFileInfo(self.__lastActiveSession)
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
346
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
347 @pyqtSlot()
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
348 def __sessionDirectoryChanged(self):
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
349 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
350 Private slot handling changes of the sessions directory.
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
351 """
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
352 self.__sessionMetaData = []
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
353
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
354 self.sessionsMetaDataChanged.emit()
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
355
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
356 @pyqtSlot()
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
357 def aboutToShowSessionsMenu(self, menu):
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
358 """
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
359 Public slot to populate the sessions selection menu.
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
360
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
361 @param menu reference to the menu about to be shown
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
362 @type QMenu
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
363 """
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
364 menu.clear()
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
365
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
366 actionGroup = QActionGroup(menu)
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
367 sessions = self.sessionMetaData(includeBackups=False)
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
368 for session in sessions:
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
369 act = menu.addAction(session.name)
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
370 act.setCheckable(True)
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
371 act.setChecked(session.isActive)
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
372 act.setData(session.filePath)
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
373 actionGroup.addAction(act)
7937
181d1160f617 Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
374 act.triggered.connect(
181d1160f617 Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
375 functools.partial(self.__sessionActTriggered, act))
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
376
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
377 @pyqtSlot()
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
378 def __sessionActTriggered(self, act):
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
379 """
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
380 Private slot to handle the menu selection of a session.
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
381
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
382 @param act reference to the action that triggered
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
383 @type QAction
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
384 """
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
385 path = act.data()
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
386 self.switchToSession(path)
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
387
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
388 def openSession(self, sessionFilePath, flags=0):
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
389 """
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
390 Public method to open a session from a given session file.
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
391
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
392 @param sessionFilePath name of the session file to get session from
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
393 @type str
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
394 @param flags flags determining the open mode
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
395 @type int
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
396 """
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
397 if self.__isActive(sessionFilePath):
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
398 return
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
399
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
400 sessionData = self.readSessionFromFile(sessionFilePath)
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
401 if not sessionData or not sessionData["Windows"]:
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
402 return
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
403
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
404 from WebBrowser.WebBrowserWindow import WebBrowserWindow
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
405 window = WebBrowserWindow.mainWindow()
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
406
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
407 if ((flags & SessionManager.SwitchSession) ==
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
408 SessionManager.SwitchSession):
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
409 # save the current session
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
410 self.writeCurrentSession(self.__lastActiveSession)
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
411
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
412 # create new window for the new session
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
413 window = window.newWindow(restoreSession=True)
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
414
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
415 # close all existing windows
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
416 for win in WebBrowserWindow.mainWindows()[:]:
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
417 if win is not window:
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
418 win.forceClose()
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
419
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
420 if not ((flags & SessionManager.ReplaceSession) ==
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
421 SessionManager.ReplaceSession):
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
422 self.__lastActiveSession = (
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
423 QFileInfo(sessionFilePath).canonicalFilePath()
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
424 )
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
425 self.__sessionMetaData = []
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
426
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
427 self.restoreSessionFromData(window, sessionData)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
428
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
429 @classmethod
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
430 def restoreSessionFromData(cls, window=None, sessionData=None):
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
431 """
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
432 Class method to restore a session from a session data dictionary.
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
433
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
434 @param window reference to main window to restore to
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
435 @type WebBrowserWindow
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
436 @param sessionData dictionary containing the session data
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
437 """
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
438 from WebBrowser.WebBrowserWindow import WebBrowserWindow
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
439 if window is None:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
440 window = WebBrowserWindow.mainWindow()
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
441
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
442 with E5OverrideCursor():
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
443 # restore session for first window
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
444 data = sessionData["Windows"].pop(0)
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
445 window.tabWidget().loadFromSessionData(data)
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
446 if "WindowGeometry" in data:
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
447 geometry = QByteArray.fromBase64(
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
448 data["WindowGeometry"].encode("ascii"))
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
449 window.restoreGeometry(geometry)
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
450 QApplication.processEvents()
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
451
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
452 # restore additional windows
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
453 for data in sessionData["Windows"]:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
454 window = (
7775
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7771
diff changeset
455 WebBrowserWindow.mainWindow().newWindow(
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7771
diff changeset
456 restoreSession=True)
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
457 )
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
458 window.tabWidget().loadFromSessionData(data)
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
459 if "WindowGeometry" in data:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
460 geometry = QByteArray.fromBase64(
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
461 data["WindowGeometry"].encode("ascii"))
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
462 window.restoreGeometry(geometry)
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
463 QApplication.processEvents()
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
464
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
465 if "CurrentWindowIndex" in sessionData:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
466 currentWindowIndex = sessionData["CurrentWindowIndex"]
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
467 try:
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
468 currentWindow = (
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
469 WebBrowserWindow.mainWindows()[currentWindowIndex]
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
470 )
5793
4ff73b969ab1 Some fixes and adjustments for the session support of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
471 QTimer.singleShot(0, lambda: currentWindow.raise_())
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
472 except IndexError:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
473 # ignore it
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
474 pass
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
475
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
476 def renameSession(self, sessionFilePath, flags=0):
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
477 """
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
478 Public method to rename or clone a session.
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
479
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
480 @param sessionFilePath name of the session file
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
481 @type str
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
482 @param flags flags determining a rename or clone operation
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
483 @type int
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
484 """
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
485 from WebBrowser.WebBrowserWindow import WebBrowserWindow
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
486
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
487 suggestedName = QFileInfo(sessionFilePath).baseName()
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
488 if flags & SessionManager.CloneSession:
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
489 suggestedName += "_cloned"
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
490 title = self.tr("Clone Session")
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
491 else:
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
492 suggestedName += "_renamed"
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
493 title = self.tr("Rename Session")
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
494 newName, ok = QInputDialog.getText(
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
495 WebBrowserWindow.getWindow(),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
496 title,
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
497 self.tr("Please enter a new name:"),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
498 QLineEdit.Normal,
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
499 suggestedName)
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
500
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
501 if not ok:
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
502 return
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
503
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
504 if not newName.endswith(".json"):
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
505 newName += ".json"
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
506
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
507 newSessionPath = os.path.join(self.getSessionsDirectory(), newName)
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
508 if os.path.exists(newSessionPath):
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
509 E5MessageBox.information(
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
510 WebBrowserWindow.getWindow(),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
511 title,
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
512 self.tr("""The session file "{0}" exists already. Please"""
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
513 """ enter another name.""").format(newName))
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
514 self.renameSession(sessionFilePath, flags)
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
515 return
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
516
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
517 if flags & SessionManager.CloneSession:
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
518 if not QFile.copy(sessionFilePath, newSessionPath):
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
519 E5MessageBox.critical(
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
520 WebBrowserWindow.getWindow(),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
521 title,
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
522 self.tr("""An error occurred while cloning the session"""
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
523 """ file."""))
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
524 return
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
525 else:
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
526 if not QFile.rename(sessionFilePath, newSessionPath):
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
527 E5MessageBox.critical(
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
528 WebBrowserWindow.getWindow(),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
529 title,
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
530 self.tr("""An error occurred while renaming the session"""
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
531 """ file."""))
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
532 return
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
533 if self.__isActive(sessionFilePath):
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
534 self.__lastActiveSession = newSessionPath
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
535 self.__sessionMetaData = []
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
536
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
537 def saveSession(self):
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
538 """
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
539 Public method to save the current session.
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
540 """
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
541 from WebBrowser.WebBrowserWindow import WebBrowserWindow
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
542 newName, ok = QInputDialog.getText(
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
543 WebBrowserWindow.getWindow(),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
544 self.tr("Save Session"),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
545 self.tr("Please enter a name for the session:"),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
546 QLineEdit.Normal,
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
547 self.tr("Saved Session ({0})").format(
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
548 QDateTime.currentDateTime().toString("yyyy-MM-dd HH-mm-ss")))
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
549
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
550 if not ok:
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
551 return
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
552
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
553 if not newName.endswith(".json"):
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
554 newName += ".json"
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
555
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
556 newSessionPath = os.path.join(self.getSessionsDirectory(), newName)
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
557 if os.path.exists(newSessionPath):
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
558 E5MessageBox.information(
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
559 WebBrowserWindow.getWindow(),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
560 self.tr("Save Session"),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
561 self.tr("""The session file "{0}" exists already. Please"""
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
562 """ enter another name.""").format(newName))
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
563 self.saveSession()
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
564 return
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
565
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
566 self.writeCurrentSession(newSessionPath)
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
567
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
568 def replaceSession(self, sessionFilePath):
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
569 """
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
570 Public method to replace the current session with the given one.
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
571
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
572 @param sessionFilePath file name of the session file to replace with
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
573 @type str
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
574 @return flag indicating success
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
575 @rtype bool
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
576 """
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
577 from WebBrowser.WebBrowserWindow import WebBrowserWindow
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
578 res = E5MessageBox.yesNo(
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
579 WebBrowserWindow.getWindow(),
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
580 self.tr("Restore Backup"),
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
581 self.tr("""Are you sure you want to replace the current"""
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
582 """ session?"""))
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
583 if res:
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
584 self.openSession(sessionFilePath, SessionManager.ReplaceSession)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
585 return True
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
586 else:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
587 return False
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
588
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
589 def switchToSession(self, sessionFilePath):
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
590 """
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
591 Public method to switch the current session to the given one.
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
592
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
593 @param sessionFilePath file name of the session file to switch to
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
594 @type str
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
595 @return flag indicating success
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
596 @rtype bool
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
597 """
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
598 self.openSession(sessionFilePath, SessionManager.SwitchSession)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
599 return True
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
600
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
601 def cloneSession(self, sessionFilePath):
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
602 """
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
603 Public method to clone a session.
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
604
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
605 @param sessionFilePath file name of the session file to be cloned
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
606 @type str
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
607 """
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
608 self.renameSession(sessionFilePath, SessionManager.CloneSession)
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
609
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
610 def deleteSession(self, sessionFilePath):
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
611 """
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
612 Public method to delete a session.
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
613
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
614 @param sessionFilePath file name of the session file to be deleted
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
615 @type str
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
616 """
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
617 from WebBrowser.WebBrowserWindow import WebBrowserWindow
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
618 res = E5MessageBox.yesNo(
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
619 WebBrowserWindow.getWindow(),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
620 self.tr("Delete Session"),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
621 self.tr("""Are you sure you want to delete session "{0}"?""")
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
622 .format(QFileInfo(sessionFilePath).baseName()))
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
623 if res:
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
624 QFile.remove(sessionFilePath)
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
625
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
626 def newSession(self):
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
627 """
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
628 Public method to start a new session.
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
629 """
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
630 from WebBrowser.WebBrowserWindow import WebBrowserWindow
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
631 newName, ok = QInputDialog.getText(
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
632 WebBrowserWindow.getWindow(),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
633 self.tr("New Session"),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
634 self.tr("Please enter a name for the new session:"),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
635 QLineEdit.Normal,
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
636 self.tr("New Session ({0})").format(
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
637 QDateTime.currentDateTime().toString("yyyy-MM-dd HH-mm-ss")))
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
638
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
639 if not ok:
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
640 return
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
641
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
642 if not newName.endswith(".json"):
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
643 newName += ".json"
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
644
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
645 newSessionPath = os.path.join(self.getSessionsDirectory(), newName)
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
646 if os.path.exists(newSessionPath):
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
647 E5MessageBox.information(
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
648 WebBrowserWindow.getWindow(),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
649 self.tr("New Session"),
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
650 self.tr("""The session file "{0}" exists already. Please"""
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
651 """ enter another name.""").format(newName))
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
652 self.newSession()
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
653 return
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
654
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
655 self.writeCurrentSession(self.__lastActiveSession)
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
656
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
657 # create new window for the new session and close all existing windows
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
658 window = WebBrowserWindow.mainWindow().newWindow()
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
659 for win in WebBrowserWindow.mainWindows():
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
660 if win is not window:
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
661 win.forceClose()
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
662
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
663 self.__lastActiveSession = newSessionPath
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
664 self.__autoSaveSession()
5779
b53fabc86f3c Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5777
diff changeset
665
5780
79d06c98c5c9 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5779
diff changeset
666 def showSessionManagerDialog(self):
5782
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
667 """
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
668 Public method to show the session manager dialog.
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
669 """
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
670 from WebBrowser.WebBrowserWindow import WebBrowserWindow
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
671 from .SessionManagerDialog import SessionManagerDialog
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
672
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
673 dlg = SessionManagerDialog(WebBrowserWindow.getWindow())
60874802161b Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5780
diff changeset
674 dlg.open()
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
675
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
676 def selectSession(self):
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
677 """
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
678 Public method to select a session to be restored.
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
679
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
680 @return name of the session file to be restored
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
681 @rtype str
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
682 """
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
683 from WebBrowser.WebBrowserWindow import WebBrowserWindow
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
684
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
685 self.__fillMetaDataList()
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
686
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
687 if self.__sessionMetaData:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
688 # skip, if no session file available
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
689 dlg = QDialog(WebBrowserWindow.getWindow(),
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
690 Qt.WindowStaysOnTopHint)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
691 lbl = QLabel(self.tr("Please select the startup session:"))
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
692 combo = QComboBox(dlg)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
693 buttonBox = QDialogButtonBox(
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
694 QDialogButtonBox.Ok | QDialogButtonBox.Cancel, dlg)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
695 buttonBox.accepted.connect(dlg.accept)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
696 buttonBox.rejected.connect(dlg.reject)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
697
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
698 layout = QVBoxLayout()
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
699 layout.addWidget(lbl)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
700 layout.addWidget(combo)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
701 layout.addWidget(buttonBox)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
702 dlg.setLayout(layout)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
703
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
704 lastActiveSessionFileInfo = QFileInfo(self.__lastActiveSession)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
705
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
706 for metaData in self.__sessionMetaData:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
707 if QFileInfo(metaData.filePath) != lastActiveSessionFileInfo:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
708 combo.addItem(metaData.name, metaData.filePath)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
709 else:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
710 combo.insertItem(
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
711 0,
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
712 self.tr("{0} (last session)").format(metaData.name),
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
713 metaData.filePath
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
714 )
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
715 combo.setCurrentIndex(0)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
716
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
717 if dlg.exec() == QDialog.Accepted:
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
718 session = combo.currentData()
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
719 if session is None:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
720 self.__lastActiveSession = self.__sessionDefault
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
721 else:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
722 self.__lastActiveSession = session
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
723
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5782
diff changeset
724 return self.__lastActiveSession

eric ide

mercurial