new 'Events' tab
This commit is contained in:
parent
05a5ca0fe1
commit
cde5bff35a
4 changed files with 250 additions and 9 deletions
|
|
@ -474,6 +474,9 @@ class ContactsWidget(QWidget):
|
|||
if not contact or contact == self.contact:
|
||||
return
|
||||
|
||||
if not isinstance(contact, Contact):
|
||||
return self.retrieveContact(contact)
|
||||
|
||||
self.ui.tabWidget.clear()
|
||||
self.contact = contact
|
||||
backend = self.weboob.get_backend(self.contact.backend)
|
||||
|
|
@ -491,12 +494,15 @@ class ContactsWidget(QWidget):
|
|||
if not url:
|
||||
return
|
||||
|
||||
self.retrieveContact(url)
|
||||
|
||||
def retrieveContact(self, url):
|
||||
backend_name = unicode(self.ui.backendsList.currentText())
|
||||
self.ui.urlButton.setEnabled(False)
|
||||
self.url_process = QtDo(self.weboob, self.urlClicked_cb, self.urlClicked_eb)
|
||||
self.url_process = QtDo(self.weboob, self.retrieveContact_cb, self.retrieveContact_eb)
|
||||
self.url_process.do('get_contact', url, backends=backend_name)
|
||||
|
||||
def urlClicked_cb(self, backend, contact):
|
||||
def retrieveContact_cb(self, backend, contact):
|
||||
if not backend:
|
||||
self.url_process = None
|
||||
self.ui.urlButton.setEnabled(True)
|
||||
|
|
@ -505,7 +511,7 @@ class ContactsWidget(QWidget):
|
|||
self.ui.urlEdit.clear()
|
||||
self.setContact(contact)
|
||||
|
||||
def urlClicked_eb(self, backend, error, backtrace):
|
||||
def retrieveContact_eb(self, backend, error, backtrace):
|
||||
content = unicode(self.tr('Unable to get contact:\n%s\n')) % to_unicode(error)
|
||||
if logging.root.level == logging.DEBUG:
|
||||
content += u'\n%s\n' % to_unicode(backtrace)
|
||||
|
|
|
|||
137
weboob/applications/qhavesex/events.py
Normal file
137
weboob/applications/qhavesex/events.py
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Romain Bignon
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
# weboob is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# weboob is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from PyQt4.QtGui import QWidget, QTreeWidgetItem, QImage, QIcon, QPixmap
|
||||
from PyQt4.QtCore import SIGNAL, Qt
|
||||
|
||||
from weboob.capabilities.base import NotLoaded
|
||||
from weboob.tools.application.qt import QtDo
|
||||
|
||||
from .ui.events_ui import Ui_Events
|
||||
|
||||
class EventsWidget(QWidget):
|
||||
def __init__(self, weboob, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
self.ui = Ui_Events()
|
||||
self.ui.setupUi(self)
|
||||
|
||||
self.weboob = weboob
|
||||
self.photo_processes = {}
|
||||
self.event_filter = None
|
||||
|
||||
self.connect(self.ui.eventsList, SIGNAL('itemDoubleClicked(QTreeWidgetItem*, int)'), self.eventDoubleClicked)
|
||||
self.connect(self.ui.typeBox, SIGNAL('currentIndexChanged(int)'), self.typeChanged)
|
||||
self.connect(self.ui.refreshButton, SIGNAL('clicked()'), self.refreshEventsList)
|
||||
|
||||
self.ui.eventsList.sortByColumn(1, Qt.DescendingOrder)
|
||||
|
||||
def load(self):
|
||||
self.refreshEventsList()
|
||||
|
||||
def typeChanged(self, i):
|
||||
if self.ui.refreshButton.isEnabled():
|
||||
self.refreshEventsList()
|
||||
|
||||
def refreshEventsList(self):
|
||||
self.ui.eventsList.clear()
|
||||
self.ui.refreshButton.setEnabled(False)
|
||||
if self.ui.typeBox.currentIndex() >= 0:
|
||||
# XXX strangely, in gotEvent() in the loop to check if there is already the
|
||||
# event type to try to introduce it in list, itemData() returns the right value.
|
||||
# But, I don't know why, here, it will ALWAYS return None...
|
||||
# So the filter does not work currently.
|
||||
self.events_filter = self.ui.typeBox.itemData(self.ui.typeBox.currentIndex())
|
||||
else:
|
||||
self.event_filter = None
|
||||
self.ui.typeBox.setEnabled(False)
|
||||
self.ui.typeBox.clear()
|
||||
self.ui.typeBox.addItem('All', None)
|
||||
self.process = QtDo(self.weboob, self.gotEvent)
|
||||
self.process.do('iter_events')
|
||||
|
||||
def setPhoto(self, contact, item):
|
||||
if not contact:
|
||||
return False
|
||||
|
||||
try:
|
||||
self.photo_processes.pop(contact.id, None)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
img = None
|
||||
for photo in contact.photos.itervalues():
|
||||
if photo.thumbnail_data:
|
||||
img = QImage.fromData(photo.thumbnail_data)
|
||||
break
|
||||
|
||||
if img:
|
||||
item.setIcon(0, QIcon(QPixmap.fromImage(img)))
|
||||
self.ui.eventsList.resizeColumnToContents(0)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def gotEvent(self, backend, event):
|
||||
if not backend:
|
||||
self.ui.refreshButton.setEnabled(True)
|
||||
self.ui.typeBox.setEnabled(True)
|
||||
return
|
||||
|
||||
found = False
|
||||
for i in xrange(self.ui.typeBox.count()):
|
||||
s = self.ui.typeBox.itemData(i)
|
||||
if s == event.type:
|
||||
found = True
|
||||
if not found:
|
||||
print event.type
|
||||
self.ui.typeBox.addItem(event.type.capitalize(), event.type)
|
||||
if event.type == self.event_filter:
|
||||
self.ui.typeBox.setCurrentIndex(self.ui.typeBox.count()-1)
|
||||
|
||||
if self.event_filter and self.event_filter != event.type:
|
||||
return
|
||||
|
||||
date = event.date.strftime('%Y-%m-%d %H:%M')
|
||||
type = event.type
|
||||
name = event.contact.name if event.contact else ''
|
||||
message = event.message
|
||||
|
||||
item = QTreeWidgetItem(None, [name, date, type, message])
|
||||
item.setData(0, Qt.UserRole, event)
|
||||
|
||||
contact = event.contact
|
||||
contact.backend = event.backend
|
||||
if contact.photos is NotLoaded:
|
||||
process = QtDo(self.weboob, lambda b, c: self.setPhoto(c, item))
|
||||
process.do('fillobj', contact, ['photos'], backends=contact.backend)
|
||||
self.photo_processes[contact.id] = process
|
||||
elif len(contact.photos) > 0:
|
||||
if not self.setPhoto(contact, item):
|
||||
photo = contact.photos.values()[0]
|
||||
process = QtDo(self.weboob, lambda b, p: self.setPhoto(contact, item))
|
||||
process.do('fillobj', photo, ['thumbnail_data'], backends=contact.backend)
|
||||
self.photo_processes[contact.id] = process
|
||||
|
||||
self.ui.eventsList.addTopLevelItem(item)
|
||||
self.ui.eventsList.resizeColumnToContents(0)
|
||||
self.ui.eventsList.resizeColumnToContents(1)
|
||||
|
||||
def eventDoubleClicked(self, item, col):
|
||||
event = item.data(0, Qt.UserRole).toPyObject()
|
||||
self.emit(SIGNAL('display_contact'), event.contact)
|
||||
|
|
@ -33,6 +33,7 @@ except ImportError:
|
|||
from .ui.main_window_ui import Ui_MainWindow
|
||||
from .status import AccountsStatus
|
||||
from .contacts import ContactsWidget
|
||||
from .events import EventsWidget
|
||||
|
||||
class MainWindow(QtMainWindow):
|
||||
def __init__(self, config, weboob, parent=None):
|
||||
|
|
@ -48,12 +49,12 @@ class MainWindow(QtMainWindow):
|
|||
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
|
||||
self.connect(self.ui.tabWidget, SIGNAL('currentChanged(int)'), self.tabChanged)
|
||||
|
||||
self.ui.tabWidget.addTab(AccountsStatus(self.weboob), self.tr('Status'))
|
||||
if HAVE_BOOBMSG:
|
||||
self.ui.tabWidget.addTab(MessagesManager(self.weboob), self.tr('Messages'))
|
||||
self.ui.tabWidget.addTab(ContactsWidget(self.weboob), self.tr('Contacts'))
|
||||
self.ui.tabWidget.addTab(QWidget(), self.tr('Calendar'))
|
||||
self.ui.tabWidget.addTab(QWidget(), self.tr('Optimizations'))
|
||||
self.addTab(AccountsStatus(self.weboob), self.tr('Status'))
|
||||
self.addTab(MessagesManager(self.weboob) if HAVE_BOOBMSG else None, self.tr('Messages'))
|
||||
self.addTab(ContactsWidget(self.weboob), self.tr('Contacts'))
|
||||
self.addTab(EventsWidget(self.weboob), self.tr('Events'))
|
||||
self.addTab(None, self.tr('Calendar'))
|
||||
self.addTab(None, self.tr('Optimizations'))
|
||||
|
||||
if self.weboob.count_backends() == 0:
|
||||
self.backendsConfig()
|
||||
|
|
@ -65,9 +66,22 @@ class MainWindow(QtMainWindow):
|
|||
widget = self.ui.tabWidget.widget(self.ui.tabWidget.currentIndex())
|
||||
widget.load()
|
||||
|
||||
def addTab(self, widget, title):
|
||||
if widget:
|
||||
self.connect(widget, SIGNAL('display_contact'), self.display_contact)
|
||||
self.ui.tabWidget.addTab(widget, title)
|
||||
else:
|
||||
index = self.ui.tabWidget.addTab(QWidget(), title)
|
||||
self.ui.tabWidget.setTabEnabled(index, False)
|
||||
|
||||
def tabChanged(self, i):
|
||||
widget = self.ui.tabWidget.currentWidget()
|
||||
|
||||
if hasattr(widget, 'load') and not i in self.loaded_tabs:
|
||||
widget.load()
|
||||
self.loaded_tabs[i] = True
|
||||
|
||||
def display_contact(self, contact):
|
||||
self.ui.tabWidget.setCurrentIndex(2)
|
||||
widget = self.ui.tabWidget.currentWidget()
|
||||
widget.setContact(contact)
|
||||
|
|
|
|||
84
weboob/applications/qhavesex/ui/events.ui
Normal file
84
weboob/applications/qhavesex/ui/events.ui
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Events</class>
|
||||
<widget class="QWidget" name="Events">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>497</width>
|
||||
<height>318</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QComboBox" name="typeBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="refreshButton">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../usr/share/icons/oxygen/16x16/actions/view-refresh.png</normaloff>../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../usr/share/icons/oxygen/16x16/actions/view-refresh.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="eventsList">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="animated">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Contact</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Date</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Message</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Loading…
Add table
Add a link
Reference in a new issue