support bookmarks
This commit is contained in:
parent
f6c2edc64f
commit
f340ac485e
2 changed files with 70 additions and 7 deletions
|
|
@ -41,6 +41,7 @@ class MainWindow(QtMainWindow):
|
||||||
self.housing = None
|
self.housing = None
|
||||||
self.displayed_photo_idx = 0
|
self.displayed_photo_idx = 0
|
||||||
self.process_photo = {}
|
self.process_photo = {}
|
||||||
|
self.process_bookmarks = {}
|
||||||
|
|
||||||
self.ui.housingsList.setItemDelegate(HTMLDelegate())
|
self.ui.housingsList.setItemDelegate(HTMLDelegate())
|
||||||
self.ui.housingFrame.hide()
|
self.ui.housingFrame.hide()
|
||||||
|
|
@ -48,9 +49,11 @@ class MainWindow(QtMainWindow):
|
||||||
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
|
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
|
||||||
self.connect(self.ui.queriesList, SIGNAL('currentIndexChanged(int)'), self.queryChanged)
|
self.connect(self.ui.queriesList, SIGNAL('currentIndexChanged(int)'), self.queryChanged)
|
||||||
self.connect(self.ui.addQueryButton, SIGNAL('clicked()'), self.addQuery)
|
self.connect(self.ui.addQueryButton, SIGNAL('clicked()'), self.addQuery)
|
||||||
|
self.connect(self.ui.bookmarksButton, SIGNAL('clicked()'), self.displayBookmarks)
|
||||||
self.connect(self.ui.housingsList, SIGNAL('itemClicked(QListWidgetItem*)'), self.housingSelected)
|
self.connect(self.ui.housingsList, SIGNAL('itemClicked(QListWidgetItem*)'), self.housingSelected)
|
||||||
self.connect(self.ui.previousButton, SIGNAL('clicked()'), self.previousClicked)
|
self.connect(self.ui.previousButton, SIGNAL('clicked()'), self.previousClicked)
|
||||||
self.connect(self.ui.nextButton, SIGNAL('clicked()'), self.nextClicked)
|
self.connect(self.ui.nextButton, SIGNAL('clicked()'), self.nextClicked)
|
||||||
|
self.connect(self.ui.bookmark, SIGNAL('stateChanged(int)'), self.bookmarkChanged)
|
||||||
|
|
||||||
self.reloadQueriesList()
|
self.reloadQueriesList()
|
||||||
self.refreshHousingsList()
|
self.refreshHousingsList()
|
||||||
|
|
@ -107,6 +110,7 @@ class MainWindow(QtMainWindow):
|
||||||
|
|
||||||
self.ui.housingsList.clear()
|
self.ui.housingsList.clear()
|
||||||
self.ui.queriesList.setEnabled(False)
|
self.ui.queriesList.setEnabled(False)
|
||||||
|
self.ui.bookmarksButton.setEnabled(False)
|
||||||
|
|
||||||
query = Query()
|
query = Query()
|
||||||
query.cities = []
|
query.cities = []
|
||||||
|
|
@ -125,9 +129,22 @@ class MainWindow(QtMainWindow):
|
||||||
self.process = QtDo(self.weboob, self.addHousing)
|
self.process = QtDo(self.weboob, self.addHousing)
|
||||||
self.process.do('search_housings', query)
|
self.process.do('search_housings', query)
|
||||||
|
|
||||||
|
def displayBookmarks(self):
|
||||||
|
self.ui.housingsList.clear()
|
||||||
|
self.ui.queriesList.setEnabled(False)
|
||||||
|
self.ui.queriesList.setCurrentIndex(-1)
|
||||||
|
self.ui.bookmarksButton.setEnabled(False)
|
||||||
|
|
||||||
|
self.processes = {}
|
||||||
|
for id in self.storage.get('bookmarks'):
|
||||||
|
_id, backend_name = id.rsplit('@', 1)
|
||||||
|
self.process_bookmarks[id] = QtDo(self.weboob, self.addHousing)
|
||||||
|
self.process_bookmarks[id].do('get_housing', _id, backends=backend_name)
|
||||||
|
|
||||||
def addHousing(self, backend, housing):
|
def addHousing(self, backend, housing):
|
||||||
if not backend:
|
if not backend:
|
||||||
self.ui.queriesList.setEnabled(True)
|
self.ui.queriesList.setEnabled(True)
|
||||||
|
self.ui.bookmarksButton.setEnabled(True)
|
||||||
self.process = None
|
self.process = None
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -136,7 +153,9 @@ class MainWindow(QtMainWindow):
|
||||||
housing.area, housing.cost, housing.currency, housing.backend, housing.text))
|
housing.area, housing.cost, housing.currency, housing.backend, housing.text))
|
||||||
item.setData(Qt.UserRole, housing)
|
item.setData(Qt.UserRole, housing)
|
||||||
|
|
||||||
if not '%s@%s' % (housing.id, housing.backend) in self.storage.get('read'):
|
if housing.fullid in self.storage.get('bookmarks'):
|
||||||
|
item.setBackground(QBrush(QColor(255, 224, 219)))
|
||||||
|
elif not housing.fullid in self.storage.get('read'):
|
||||||
item.setBackground(QBrush(QColor(219, 224, 255)))
|
item.setBackground(QBrush(QColor(219, 224, 255)))
|
||||||
|
|
||||||
if housing.photos is NotLoaded:
|
if housing.photos is NotLoaded:
|
||||||
|
|
@ -152,13 +171,16 @@ class MainWindow(QtMainWindow):
|
||||||
|
|
||||||
self.ui.housingsList.addItem(item)
|
self.ui.housingsList.addItem(item)
|
||||||
|
|
||||||
|
if housing.fullid in self.process_bookmarks:
|
||||||
|
self.process_bookmarks.pop(housing.fullid)
|
||||||
|
|
||||||
def housingSelected(self, item):
|
def housingSelected(self, item):
|
||||||
housing = item.data(Qt.UserRole).toPyObject()
|
housing = item.data(Qt.UserRole).toPyObject()
|
||||||
self.ui.queriesFrame.setEnabled(False)
|
self.ui.queriesFrame.setEnabled(False)
|
||||||
|
|
||||||
item.setBackground(QBrush())
|
item.setBackground(QBrush())
|
||||||
read = set(self.storage.get('read'))
|
read = set(self.storage.get('read'))
|
||||||
read.add('%s@%s' % (housing.id, housing.backend))
|
read.add(housing.fullid)
|
||||||
self.storage.set('read', list(read))
|
self.storage.set('read', list(read))
|
||||||
self.storage.save()
|
self.storage.save()
|
||||||
|
|
||||||
|
|
@ -196,6 +218,8 @@ class MainWindow(QtMainWindow):
|
||||||
|
|
||||||
self.display_photo()
|
self.display_photo()
|
||||||
|
|
||||||
|
self.ui.bookmark.setChecked(housing.fullid in self.storage.get('bookmarks'))
|
||||||
|
|
||||||
self.ui.titleLabel.setText('<h1>%s</h1>' % housing.title)
|
self.ui.titleLabel.setText('<h1>%s</h1>' % housing.title)
|
||||||
self.ui.areaLabel.setText(u'%s m²' % housing.area)
|
self.ui.areaLabel.setText(u'%s m²' % housing.area)
|
||||||
self.ui.costLabel.setText(u'%s %s' % (housing.cost, housing.currency))
|
self.ui.costLabel.setText(u'%s %s' % (housing.cost, housing.currency))
|
||||||
|
|
@ -228,6 +252,15 @@ class MainWindow(QtMainWindow):
|
||||||
|
|
||||||
self.setHousing(housing, nottext='')
|
self.setHousing(housing, nottext='')
|
||||||
|
|
||||||
|
def bookmarkChanged(self, state):
|
||||||
|
bookmarks = set(self.storage.get('bookmarks'))
|
||||||
|
if state == Qt.Checked:
|
||||||
|
bookmarks.add(self.housing.fullid)
|
||||||
|
elif self.housing.fullid in bookmarks:
|
||||||
|
bookmarks.remove(self.housing.fullid)
|
||||||
|
self.storage.set('bookmarks', list(bookmarks))
|
||||||
|
self.storage.save()
|
||||||
|
|
||||||
def previousClicked(self):
|
def previousClicked(self):
|
||||||
if len(self.housing.photos) == 0:
|
if len(self.housing.photos) == 0:
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="bookmarksButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Bookmarks</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QSplitter" name="splitter">
|
<widget class="QSplitter" name="splitter">
|
||||||
|
|
@ -94,11 +101,34 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="titleLabel">
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
<property name="text">
|
<item>
|
||||||
<string><h1>Loading...</h1></string>
|
<widget class="QCheckBox" name="bookmark">
|
||||||
</property>
|
<property name="sizePolicy">
|
||||||
</widget>
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="titleLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string><h1>Loading...</h1></string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue