add tab to send queries

This commit is contained in:
Romain Bignon 2013-05-24 09:34:31 +02:00
commit 0f1ce1d4b1
6 changed files with 248 additions and 5 deletions

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Romain Bignon # Copyright(C) 2010-2014 Romain Bignon
# #
# This file is part of weboob. # This file is part of weboob.
# #
@ -127,6 +127,12 @@ class AuMBackend(BaseBackend, CapMessages, CapMessagesPost, CapDating, CapChat,
e.message = message % e.contact.name e.message = message % e.contact.name
yield e yield e
def iter_new_contacts(self):
with self.browser:
for _id in self.browser.search_profiles():#.difference(self.OPTIM_PROFILE_WALKER.visited_profiles):
contact = Contact(_id, '', 0)
yield contact
# ---- CapMessages methods --------------------- # ---- CapMessages methods ---------------------
def fill_thread(self, thread, fields): def fill_thread(self, thread, fields):

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Romain Bignon # Copyright(C) 2010-2014 Romain Bignon
# #
# This file is part of weboob. # This file is part of weboob.
# #
@ -313,7 +313,7 @@ class ContactProfile(QWidget):
self.display_photo() self.display_photo()
def display_photo(self): def display_photo(self):
if self.displayed_photo_idx >= len(self.contact.photos): if self.displayed_photo_idx >= len(self.contact.photos) or self.displayed_photo_idx < 0:
self.displayed_photo_idx = len(self.contact.photos) - 1 self.displayed_photo_idx = len(self.contact.photos) - 1
if self.displayed_photo_idx < 0: if self.displayed_photo_idx < 0:
self.ui.photoUrlLabel.setText('') self.ui.photoUrlLabel.setText('')

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Romain Bignon # Copyright(C) 2010-2014 Romain Bignon
# #
# This file is part of weboob. # This file is part of weboob.
# #
@ -34,6 +34,7 @@ from .ui.main_window_ui import Ui_MainWindow
from .status import AccountsStatus from .status import AccountsStatus
from .contacts import ContactsWidget from .contacts import ContactsWidget
from .events import EventsWidget from .events import EventsWidget
from .search import SearchWidget
class MainWindow(QtMainWindow): class MainWindow(QtMainWindow):
@ -54,6 +55,7 @@ class MainWindow(QtMainWindow):
self.addTab(MessagesManager(self.weboob) if HAVE_BOOBMSG else None, self.tr('Messages')) self.addTab(MessagesManager(self.weboob) if HAVE_BOOBMSG else None, self.tr('Messages'))
self.addTab(ContactsWidget(self.weboob), self.tr('Contacts')) self.addTab(ContactsWidget(self.weboob), self.tr('Contacts'))
self.addTab(EventsWidget(self.weboob), self.tr('Events')) self.addTab(EventsWidget(self.weboob), self.tr('Events'))
self.addTab(SearchWidget(self.weboob), self.tr('Search'))
self.addTab(None, self.tr('Calendar')) self.addTab(None, self.tr('Calendar'))
self.addTab(None, self.tr('Optimizations')) self.addTab(None, self.tr('Optimizations'))

View file

@ -0,0 +1,104 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2014 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
from PyQt4.QtCore import SIGNAL
from weboob.tools.application.qt import QtDo
from .ui.search_ui import Ui_Search
from .contacts import ContactProfile
from .status import Account
class SearchWidget(QWidget):
def __init__(self, weboob, parent=None):
QWidget.__init__(self, parent)
self.ui = Ui_Search()
self.ui.setupUi(self)
self.weboob = weboob
self.contacts = []
self.accounts = []
self.current = None
self.connect(self.ui.nextButton, SIGNAL('clicked()'), self.next)
self.connect(self.ui.queryButton, SIGNAL('clicked()'), self.sendQuery)
def load(self):
while self.ui.statusFrame.layout().count() > 0:
item = self.ui.statusFrame.layout().takeAt(0)
if item.widget():
item.widget().deinit()
item.widget().hide()
item.widget().deleteLater()
self.accounts = []
for backend in self.weboob.iter_backends():
account = Account(self.weboob, backend)
account.title.setText(u'<h2>%s</h2>' % backend.name)
self.accounts.append(account)
self.ui.statusFrame.layout().addWidget(account)
self.ui.statusFrame.layout().addStretch()
self.getNewProfiles()
def updateStats(self):
for account in self.accounts:
account.updateStats()
def getNewProfiles(self):
self.newprofiles_process = QtDo(self.weboob, self.retrieveNewContacts_cb)
self.newprofiles_process.do('iter_new_contacts')
def retrieveNewContacts_cb(self, backend, contact):
if not backend:
return
self.contacts.insert(0, contact)
self.ui.queueLabel.setText('%d' % len(self.contacts))
if self.current is None:
self.next()
def next(self):
try:
contact = self.contacts.pop()
except IndexError:
contact = None
self.ui.queueLabel.setText('%d' % len(self.contacts))
self.setContact(contact)
self.updateStats()
def setContact(self, contact):
self.current = contact
if contact is not None:
widget = ContactProfile(self.weboob, contact)
self.ui.scrollArea.setWidget(widget)
else:
self.ui.scrollArea.setWidget(None)
def sendQuery(self):
self.newprofiles_process = QtDo(self.weboob, self.querySent)
self.newprofiles_process.do('send_query', self.current.id, backends=[self.current.backend])
def querySent(self, backend, query):
if backend is None:
self.next()

View file

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Search</class>
<widget class="QWidget" name="Search">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>438</width>
<height>349</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QFrame" name="statusFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLabel" name="queueLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;b&gt;Profiles in queue:&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="queryButton">
<property name="text">
<string>Query</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="nextButton">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>178</width>
<height>235</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Romain Bignon # Copyright(C) 2010-2014 Romain Bignon
# #
# This file is part of weboob. # This file is part of weboob.
# #
@ -147,3 +147,12 @@ class CapDating(CapBase):
:rtype: iter[:class:`Event`] :rtype: iter[:class:`Event`]
""" """
raise NotImplementedError() raise NotImplementedError()
def iter_new_contacts(self):
"""
Iter new contacts.
:rtype: iter[:class:`Contact`]
"""
raise NotImplementedError()