eric6/WebBrowser/History/HistoryManager.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7781
607a6098cb44
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the history manager.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
1621
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
10 import os
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
11
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
12 from PyQt5.QtCore import (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
13 pyqtSignal, pyqtSlot, QFileInfo, QDateTime, QDate, QTime, QUrl, QTimer,
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
14 QFile, QIODevice, QByteArray, QDataStream, QTemporaryFile, QObject
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
15 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
539
87f9bce38a44 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
17 from E5Gui import E5MessageBox
87f9bce38a44 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
18
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from Utilities.AutoSaver import AutoSaver
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 import Utilities
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 import Preferences
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
23 HISTORY_VERSION_42 = 42
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
24 HISTORY_VERSION_60 = 60
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
25 HISTORY_VERSIONS = [HISTORY_VERSION_60, HISTORY_VERSION_42]
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
27
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 class HistoryEntry(object):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 Class implementing a history entry.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
32 def __init__(self, url=None, dateTime=None, title=None, visitCount=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @param url URL of the history entry (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @param dateTime date and time this entry was created (QDateTime)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @param title title string for the history entry (string)
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
39 @param visitCount number of visits of this URL (int)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.url = url and url or ""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.dateTime = dateTime and dateTime or QDateTime()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.title = title and title or ""
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
44 self.visitCount = visitCount and visitCount or 0
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 def __eq__(self, other):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 Special method determining equality.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
50 @param other reference to the history entry to compare against
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
51 (HistoryEntry)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 @return flag indicating equality (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
54 return (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
55 other.title == self.title and
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
56 other.url == self.url and
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 other.dateTime == self.dateTime
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
58 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 def __lt__(self, other):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 Special method determining less relation.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 Note: History is sorted in reverse order by date and time
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
66 @param other reference to the history entry to compare against
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
67 (HistoryEntry)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 @return flag indicating less (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 return self.dateTime > other.dateTime
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 def userTitle(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 Public method to get the title of the history entry.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 @return title of the entry (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 if not self.title:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 page = QFileInfo(QUrl(self.url).path()).fileName()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 if page:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 return page
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 return self.url
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 return self.title
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
84
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
85 def isValid(self):
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
86 """
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
87 Public method to determine validity.
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
88
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
89 @return flag indicating validity
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
90 @rtype bool
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
91 """
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
92 return bool(self.url) and self.dateTime.isValid()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
94
4734
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
95 class HistoryManager(QObject):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 Class implementing the history manager.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 @signal historyCleared() emitted after the history has been cleared
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 @signal historyReset() emitted after the history has been reset
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
101 @signal entryAdded(HistoryEntry) emitted after a history entry has been
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
102 added
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
103 @signal entryRemoved(HistoryEntry) emitted after a history entry has been
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
104 removed
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 @signal entryUpdated(int) emitted after a history entry has been updated
1623
6b9654035a7c Added signals to indicate, that the managed data was saved, to some web browser managers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1621
diff changeset
106 @signal historySaved() emitted after the history was saved
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 """
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
108 historyCleared = pyqtSignal()
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
109 historyReset = pyqtSignal()
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
110 entryAdded = pyqtSignal(HistoryEntry)
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
111 entryRemoved = pyqtSignal(HistoryEntry)
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
112 entryUpdated = pyqtSignal(int)
1623
6b9654035a7c Added signals to indicate, that the managed data was saved, to some web browser managers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1621
diff changeset
113 historySaved = pyqtSignal()
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
114
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
115 def __init__(self, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 @param parent reference to the parent object (QObject)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
121 super(HistoryManager, self).__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 self.__saveTimer = AutoSaver(self, self.save)
4734
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
124 self.__daysToExpire = Preferences.getWebBrowser("HistoryLimit")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 self.__history = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 self.__lastSavedUrl = ""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
323
75182cd9b2c5 Some small tweaks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 257
diff changeset
128 self.__expiredTimer = QTimer(self)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 self.__expiredTimer.setSingleShot(True)
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
130 self.__expiredTimer.timeout.connect(self.__checkForExpired)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
323
75182cd9b2c5 Some small tweaks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 257
diff changeset
132 self.__frequencyTimer = QTimer(self)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 self.__frequencyTimer.setSingleShot(True)
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
134 self.__frequencyTimer.timeout.connect(self.__refreshFrequencies)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
136 self.entryAdded.connect(self.__saveTimer.changeOccurred)
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
137 self.entryRemoved.connect(self.__saveTimer.changeOccurred)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 self.__load()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
141 from .HistoryModel import HistoryModel
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
142 from .HistoryFilterModel import HistoryFilterModel
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
143 from .HistoryTreeModel import HistoryTreeModel
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
144
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 self.__historyModel = HistoryModel(self, self)
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
146 self.__historyFilterModel = HistoryFilterModel(
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
147 self.__historyModel, self)
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
148 self.__historyTreeModel = HistoryTreeModel(
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
149 self.__historyFilterModel, self)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 self.__startFrequencyTimer()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 def close(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 Public method to close the history manager.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 # remove history items on application exit
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 if self.__daysToExpire == -2:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 self.clear()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.__saveTimer.saveIfNeccessary()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 def history(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 Public method to return the history.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 @return reference to the list of history entries (list of HistoryEntry)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
38
5fe2b7deab15 Fixed a few issues of the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
168 return self.__history[:]
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
170 def setHistory(self, history, loadedAndSorted=False):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 Public method to set a new history.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 @param history reference to the list of history entries to be set
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 (list of HistoryEntry)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
176 @param loadedAndSorted flag indicating that the list is sorted
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
177 (boolean)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 self.__history = history[:]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 if not loadedAndSorted:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 self.__history.sort()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 self.__checkForExpired()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 if loadedAndSorted:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 try:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 self.__lastSavedUrl = self.__history[0].url
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 except IndexError:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 self.__lastSavedUrl = ""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 self.__lastSavedUrl = ""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 self.__saveTimer.changeOccurred()
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
193 self.historyReset.emit()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
195 def __findFirstHistoryEntry(self, url):
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
196 """
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
197 Private method to find the first entry for the given URL.
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
198
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
199 @param url URL to search for
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
200 @type str
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
201 @return first entry for the given URL
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
202 @rtype HistoryEntry
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
203 """
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
204 for index in range(len(self.__history)):
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
205 if url == self.__history[index].url:
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
206 return self.__history[index]
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
207
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
208 # not found, return an empty entry
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
209 return HistoryEntry()
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
210
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
211 def __updateVisitCount(self, url, count):
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
212 """
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
213 Private method to update the visit count for all entries of the
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
214 given URL.
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
215
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
216 @param url URL to be updated
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
217 @type str
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
218 @param count new visit count
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
219 @type int
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
220 """
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
221 for index in range(len(self.__history)):
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
222 if url == self.__history[index].url:
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
223 self.__history[index].visitCount = count
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
224
4734
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
225 def addHistoryEntry(self, view):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 Public method to add a history entry.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228
4734
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
229 @param view reference to the view to add an entry for
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
230 @type WebBrowserView
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 """
4734
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
232 import WebBrowser.WebBrowserWindow
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
233 if WebBrowser.WebBrowserWindow.WebBrowserWindow.isPrivate():
4734
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
234 return
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
235
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
236 url = view.url()
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
237 title = view.title()
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
238
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
239 if url.scheme() not in ["eric", "about", "data", "chrome"]:
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
240 cleanUrlStr = self.__cleanUrlStr(url)
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
241 firstEntry = self.__findFirstHistoryEntry(cleanUrlStr)
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
242 if firstEntry.isValid():
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
243 visitCount = firstEntry.visitCount + 1
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
244 self.__updateVisitCount(cleanUrlStr, visitCount)
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
245 else:
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
246 visitCount = 1
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
247 itm = HistoryEntry(cleanUrlStr,
4734
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
248 QDateTime.currentDateTime(),
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
249 title,
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
250 visitCount)
4734
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
251 self.__history.insert(0, itm)
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
252 self.entryAdded.emit(itm)
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
253 if len(self.__history) == 1:
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
254 self.__checkForExpired()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 def updateHistoryEntry(self, url, title):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 Public method to update a history entry.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 @param url URL of the entry to update (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 @param title title of the entry to update (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 """
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
263 if QUrl(url).scheme() not in ["eric", "about", "data", "chrome"]:
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
264 cleanUrlStr = self.__cleanUrlStr(QUrl(url))
1693
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1670
diff changeset
265 for index in range(len(self.__history)):
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
266 if cleanUrlStr == self.__history[index].url:
1693
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1670
diff changeset
267 self.__history[index].title = title
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1670
diff changeset
268 self.__saveTimer.changeOccurred()
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1670
diff changeset
269 if not self.__lastSavedUrl:
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1670
diff changeset
270 self.__lastSavedUrl = self.__history[index].url
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1670
diff changeset
271 self.entryUpdated.emit(index)
9bb872e26a33 Added a history sub-menu showing the most visited sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1670
diff changeset
272 break
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
274 def removeHistoryEntry(self, url, title=""):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 Public method to remove a history entry.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 @param url URL of the entry to remove (QUrl)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 @param title title of the entry to remove (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 """
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
281 if url.scheme() not in ["eric", "about", "data", "chrome"]:
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
282 cleanUrlStr = self.__cleanUrlStr(url)
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
283 for index in range(len(self.__history)):
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
284 if (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
285 cleanUrlStr == self.__history[index].url and
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
286 (not title or title == self.__history[index].title)
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
287 ):
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
288 itm = self.__history[index]
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
289 self.__lastSavedUrl = ""
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
290 self.__history.remove(itm)
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
291 self.entryRemoved.emit(itm)
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
292 break
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
293
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
294 def __cleanUrl(self, url):
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
295 """
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
296 Private method to generate a clean URL usable for the history entry.
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
297
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
298 @param url original URL
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
299 @type QUrl
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
300 @return cleaned URL
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
301 @rtype QUrl
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
302 """
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
303 cleanurl = QUrl(url)
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
304 if cleanurl.password():
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
305 # don't save the password in the history
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
306 cleanurl.setPassword("")
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
307 if cleanurl.host():
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
308 # convert host to lower case
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
309 cleanurl.setHost(url.host().lower())
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
310
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
311 return cleanurl
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
312
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
313 def __cleanUrlStr(self, url):
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
314 """
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
315 Private method to generate a clean URL usable for the history entry.
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
316
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
317 @param url original URL
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
318 @type QUrl
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
319 @return cleaned URL
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
320 @rtype str
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
321 """
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
322 cleanurl = self.__cleanUrl(url)
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
323 return cleanurl.toString()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 def historyModel(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 Public method to get a reference to the history model.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 @return reference to the history model (HistoryModel)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 return self.__historyModel
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 def historyFilterModel(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 Public method to get a reference to the history filter model.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 @return reference to the history filter model (HistoryFilterModel)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 return self.__historyFilterModel
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 def historyTreeModel(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 Public method to get a reference to the history tree model.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 @return reference to the history tree model (HistoryTreeModel)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 return self.__historyTreeModel
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 def __checkForExpired(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 Private slot to check entries for expiration.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 if self.__daysToExpire < 0 or len(self.__history) == 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 now = QDateTime.currentDateTime()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 nextTimeout = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 while self.__history:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 checkForExpired = QDateTime(self.__history[-1].dateTime)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
361 checkForExpired.setDate(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
362 checkForExpired.date().addDays(self.__daysToExpire))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 if now.daysTo(checkForExpired) > 7:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 nextTimeout = 7 * 86400
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 nextTimeout = now.secsTo(checkForExpired)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 if nextTimeout > 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 break
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 itm = self.__history.pop(-1)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 self.__lastSavedUrl = ""
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
372 self.entryRemoved.emit(itm)
9
911a9f7aef1e Fixed a bug in the web-browser history manager, that caused the history file to grow without limits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
373 self.__saveTimer.saveIfNeccessary()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 if nextTimeout > 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 self.__expiredTimer.start(nextTimeout * 1000)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 def daysToExpire(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 Public method to get the days for entry expiration.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 @return days for entry expiration (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 return self.__daysToExpire
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 def setDaysToExpire(self, limit):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 Public method to set the days for entry expiration.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 @param limit days for entry expiration (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 if self.__daysToExpire == limit:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 self.__daysToExpire = limit
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 self.__checkForExpired()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 self.__saveTimer.changeOccurred()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 def preferencesChanged(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 Public method to indicate a change of preferences.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 """
4734
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
403 self.setDaysToExpire(Preferences.getWebBrowser("HistoryLimit"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
405 @pyqtSlot()
1853
01812b281a1e Extended the "Clear Private Data" dialog of the web browser to clear flash cookies and to select a browsing history period to clear.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
406 def clear(self, period=0):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 Public slot to clear the complete history.
1853
01812b281a1e Extended the "Clear Private Data" dialog of the web browser to clear flash cookies and to select a browsing history period to clear.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
409
01812b281a1e Extended the "Clear Private Data" dialog of the web browser to clear flash cookies and to select a browsing history period to clear.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
410 @param period history period in milliseconds to be cleared (integer)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 """
1853
01812b281a1e Extended the "Clear Private Data" dialog of the web browser to clear flash cookies and to select a browsing history period to clear.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
412 if period == 0:
01812b281a1e Extended the "Clear Private Data" dialog of the web browser to clear flash cookies and to select a browsing history period to clear.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
413 self.__history = []
01812b281a1e Extended the "Clear Private Data" dialog of the web browser to clear flash cookies and to select a browsing history period to clear.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
414 self.historyReset.emit()
01812b281a1e Extended the "Clear Private Data" dialog of the web browser to clear flash cookies and to select a browsing history period to clear.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
415 else:
01812b281a1e Extended the "Clear Private Data" dialog of the web browser to clear flash cookies and to select a browsing history period to clear.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
416 breakMS = QDateTime.currentMSecsSinceEpoch() - period
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
417 while (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
418 self.__history and
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
419 (QDateTime(self.__history[0].dateTime).toMSecsSinceEpoch() >
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
420 breakMS)
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
421 ):
1853
01812b281a1e Extended the "Clear Private Data" dialog of the web browser to clear flash cookies and to select a browsing history period to clear.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
422 itm = self.__history.pop(0)
01812b281a1e Extended the "Clear Private Data" dialog of the web browser to clear flash cookies and to select a browsing history period to clear.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1693
diff changeset
423 self.entryRemoved.emit(itm)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 self.__lastSavedUrl = ""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 self.__saveTimer.changeOccurred()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 self.__saveTimer.saveIfNeccessary()
488
4174c2707dba Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 323
diff changeset
427 self.historyCleared.emit()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428
1621
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
429 def getFileName(self):
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
430 """
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
431 Public method to get the file name of the history file.
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
432
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
433 @return name of the history file (string)
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
434 """
4734
ce0b1f024da9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
435 return os.path.join(Utilities.getConfigDir(), "web_browser", "history")
1621
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
436
1626
a77c8ea8582c Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1623
diff changeset
437 def reload(self):
a77c8ea8582c Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1623
diff changeset
438 """
a77c8ea8582c Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1623
diff changeset
439 Public method to reload the history.
a77c8ea8582c Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1623
diff changeset
440 """
a77c8ea8582c Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1623
diff changeset
441 self.__load()
a77c8ea8582c Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1623
diff changeset
442
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 def __load(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 Private method to load the saved history entries from disk.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 """
1621
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
447 historyFile = QFile(self.getFileName())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448 if not historyFile.exists():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 if not historyFile.open(QIODevice.ReadOnly):
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
451 E5MessageBox.warning(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
452 None,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
453 self.tr("Loading History"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
454 self.tr(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
455 """<p>Unable to open history file <b>{0}</b>.<br/>"""
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
456 """Reason: {1}</p>""")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
457 .format(historyFile.fileName, historyFile.errorString()))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
458 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
460 history = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
462 # double check, that the history file is sorted as it is read
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 needToSort = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
464 lastInsertedItem = HistoryEntry()
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
465 data = QByteArray(historyFile.readAll())
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
466 stream = QDataStream(data, QIODevice.ReadOnly)
2095
5bf2d8a73173 Set the format of the data stream used to save information explicitly to ensure compatibility of the resulting file with Qt 5.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
467 stream.setVersion(QDataStream.Qt_4_6)
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
468 while not stream.atEnd():
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
469 ver = stream.readUInt32()
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
470 if ver not in HISTORY_VERSIONS:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471 continue
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472 itm = HistoryEntry()
2084
d3f083dd0222 Made the fiveth set of Qt5 compatibility changes (some of the previous changes are backed out due to changes in PyQt4).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1853
diff changeset
473 itm.url = Utilities.readStringFromStream(stream)
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
474 stream >> itm.dateTime
2084
d3f083dd0222 Made the fiveth set of Qt5 compatibility changes (some of the previous changes are backed out due to changes in PyQt4).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1853
diff changeset
475 itm.title = Utilities.readStringFromStream(stream)
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
476 if ver == HISTORY_VERSION_60:
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
477 itm.visitCount = stream.readUInt32()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
478
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
479 if not itm.dateTime.isValid():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
480 continue
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
481
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
482 if itm == lastInsertedItem:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
483 if not lastInsertedItem.title and len(history) > 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
484 history[0].title = itm.title
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485 continue
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
486
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
487 if ver == HISTORY_VERSION_42:
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
488 firstEntry = self.__findFirstHistoryEntry(itm.url)
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
489 if firstEntry.isValid():
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
490 visitCount = firstEntry.visitCount + 1
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
491 self.__updateVisitCount(itm.url, visitCount)
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
492 else:
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
493 visitCount = 1
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
494 itm.visitCount = visitCount
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
495
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
496 if not needToSort and history and lastInsertedItem < itm:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497 needToSort = True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
499 history.insert(0, itm)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
500 lastInsertedItem = itm
644
7c1c3abedf1c Fixed a little issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
501 historyFile.close()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
502
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
503 if needToSort:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
504 history.sort()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
506 self.setHistory(history, True)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
507
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
508 # if the history had to be sorted, rewrite the history sorted
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
509 if needToSort:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
510 self.__lastSavedUrl = ""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
511 self.__saveTimer.changeOccurred()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
512
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
513 def save(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
514 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
515 Public slot to save the history entries to disk.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
516 """
1621
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
517 historyFile = QFile(self.getFileName())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
518 if not historyFile.exists():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
519 self.__lastSavedUrl = ""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
520
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
521 saveAll = self.__lastSavedUrl == ""
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
522 first = len(self.__history) - 1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
523 if not saveAll:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
524 # find the first one to save
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
525 for index in range(len(self.__history)):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
526 if self.__history[index].url == self.__lastSavedUrl:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
527 first = index - 1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
528 break
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
529 if first == len(self.__history) - 1:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
530 saveAll = True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
531
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
532 if saveAll:
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
533 # use a temporary file when saving everything
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
534 f = QTemporaryFile()
9
911a9f7aef1e Fixed a bug in the web-browser history manager, that caused the history file to grow without limits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
535 f.setAutoRemove(False)
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
536 opened = f.open()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
537 else:
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
538 f = historyFile
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
539 opened = f.open(QIODevice.Append)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
540
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
541 if not opened:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
542 E5MessageBox.warning(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
543 None,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
544 self.tr("Saving History"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
545 self.tr(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
546 """<p>Unable to open history file <b>{0}</b>.<br/>"""
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
547 """Reason: {1}</p>""")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
548 .format(f.fileName(), f.errorString()))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
549 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
550
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
551 for index in range(first, -1, -1):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
552 data = QByteArray()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
553 stream = QDataStream(data, QIODevice.WriteOnly)
2095
5bf2d8a73173 Set the format of the data stream used to save information explicitly to ensure compatibility of the resulting file with Qt 5.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
554 stream.setVersion(QDataStream.Qt_4_6)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
555 itm = self.__history[index]
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
556 stream.writeUInt32(HISTORY_VERSION_60)
4331
711e7c35a49b Changed code to make eric compatible to PyQt 5.5 (QByteArry issue).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
557 stream.writeString(itm.url.encode("utf-8"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 stream << itm.dateTime
2599
2373006616da Fixes for the webbrowser.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2525
diff changeset
559 stream.writeString(itm.title.encode('utf-8'))
5707
1273cd92a8f4 Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
560 stream.writeUInt32(itm.visitCount)
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
561 f.write(data)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
562
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
563 f.close()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
564 if saveAll:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
565 if historyFile.exists() and not historyFile.remove():
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
566 E5MessageBox.warning(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
567 None,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
568 self.tr("Saving History"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
569 self.tr(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
570 """<p>Error removing old history file <b>{0}</b>."""
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
571 """<br/>Reason: {1}</p>""")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
572 .format(historyFile.fileName(),
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
573 historyFile.errorString()))
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
574 if not f.copy(historyFile.fileName()):
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
575 E5MessageBox.warning(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
576 None,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
577 self.tr("Saving History"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
578 self.tr(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
579 """<p>Error moving new history file over old one """
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
580 """(<b>{0}</b>).<br/>Reason: {1}</p>""")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
581 .format(historyFile.fileName(), f.errorString()))
5189
8fa3e3d379d1 Fixed an issue causing the temporary file created while the web browser history is saved to be left in the temporary area.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4910
diff changeset
582 f.remove() # get rid of the temporary file
1623
6b9654035a7c Added signals to indicate, that the managed data was saved, to some web browser managers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1621
diff changeset
583 self.historySaved.emit()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
584 try:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
585 self.__lastSavedUrl = self.__history[0].url
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
586 except IndexError:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
587 self.__lastSavedUrl = ""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
588
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
589 def __refreshFrequencies(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
590 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
591 Private slot to recalculate the refresh frequencies.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
592 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
593 self.__historyFilterModel.recalculateFrequencies()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
594 self.__startFrequencyTimer()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
595
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
596 def __startFrequencyTimer(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
597 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
598 Private method to start the timer to recalculate the frequencies.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
599 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
600 tomorrow = QDateTime(QDate.currentDate().addDays(1), QTime(3, 0))
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
601 self.__frequencyTimer.start(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
602 QDateTime.currentDateTime().secsTo(tomorrow) * 1000)
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
603
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
604 def siteVisitsCount(self, scheme, host):
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
605 """
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
606 Public method to get the visit count for a web site using the given
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
607 scheme.
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
608
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
609 @param scheme scheme to look for
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
610 @type str
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
611 @param host host to look for
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
612 @type str
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
613 @return number of visits to this site
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
614 @rtype int
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
615 """
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
616 count = 0
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
617 url = "{0}://{1}".format(scheme.lower(), host.lower())
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
618
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
619 seenUrls = []
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
620
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
621 for index in range(len(self.__history)):
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
622 historyUrl = self.__history[index].url
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
623 if historyUrl.startswith(url) and historyUrl not in seenUrls:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
624 count += self.__history[index].visitCount
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
625 seenUrls.append(historyUrl)
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
626
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
627 return count

eric ide

mercurial