diff --git a/modules/aum/backend.py b/modules/aum/backend.py index be3a1c8a..3fb866f7 100644 --- a/modules/aum/backend.py +++ b/modules/aum/backend.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010-2011 Romain Bignon +# Copyright(C) 2010-2014 Romain Bignon # # This file is part of weboob. # @@ -127,6 +127,12 @@ class AuMBackend(BaseBackend, CapMessages, CapMessagesPost, CapDating, CapChat, e.message = message % e.contact.name 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 --------------------- def fill_thread(self, thread, fields): diff --git a/weboob/applications/qhavedate/contacts.py b/weboob/applications/qhavedate/contacts.py index ccc166fe..f4838984 100644 --- a/weboob/applications/qhavedate/contacts.py +++ b/weboob/applications/qhavedate/contacts.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010-2011 Romain Bignon +# Copyright(C) 2010-2014 Romain Bignon # # This file is part of weboob. # @@ -313,7 +313,7 @@ class ContactProfile(QWidget): self.display_photo() 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 if self.displayed_photo_idx < 0: self.ui.photoUrlLabel.setText('') diff --git a/weboob/applications/qhavedate/main_window.py b/weboob/applications/qhavedate/main_window.py index 55dc5557..c60e3417 100644 --- a/weboob/applications/qhavedate/main_window.py +++ b/weboob/applications/qhavedate/main_window.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010-2011 Romain Bignon +# Copyright(C) 2010-2014 Romain Bignon # # This file is part of weboob. # @@ -34,6 +34,7 @@ from .ui.main_window_ui import Ui_MainWindow from .status import AccountsStatus from .contacts import ContactsWidget from .events import EventsWidget +from .search import SearchWidget 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(ContactsWidget(self.weboob), self.tr('Contacts')) 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('Optimizations')) diff --git a/weboob/applications/qhavedate/search.py b/weboob/applications/qhavedate/search.py new file mode 100644 index 00000000..a1514bc7 --- /dev/null +++ b/weboob/applications/qhavedate/search.py @@ -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 . + +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'

%s

' % 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() diff --git a/weboob/applications/qhavedate/ui/search.ui b/weboob/applications/qhavedate/ui/search.ui new file mode 100644 index 00000000..63726d5f --- /dev/null +++ b/weboob/applications/qhavedate/ui/search.ui @@ -0,0 +1,122 @@ + + + Search + + + + 0 + 0 + 438 + 349 + + + + Form + + + + + + + 4 + 0 + + + + + 300 + 16777215 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + + + + + + + + + + <b>Profiles in queue:</b> + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Query + + + + + + + Next + + + + + + + + + + true + + + + + 0 + 0 + 178 + 235 + + + + + + + + + + + + diff --git a/weboob/capabilities/dating.py b/weboob/capabilities/dating.py index 7b3e2207..2ef27ad7 100644 --- a/weboob/capabilities/dating.py +++ b/weboob/capabilities/dating.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010-2011 Romain Bignon +# Copyright(C) 2010-2014 Romain Bignon # # This file is part of weboob. # @@ -147,3 +147,12 @@ class CapDating(CapBase): :rtype: iter[:class:`Event`] """ raise NotImplementedError() + + def iter_new_contacts(self): + """ + Iter new contacts. + + :rtype: iter[:class:`Contact`] + """ + raise NotImplementedError() +