From 5283014b9e745c66618324d5fb3919b68200fc43 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sat, 23 Jan 2016 14:06:16 +0100
Subject: [PATCH] Search user in transfer dialog
---
res/ui/transfer.ui | 227 ++++++++++++++++++------------------
src/sakia/gui/mainwindow.py | 2 +-
src/sakia/gui/transfer.py | 127 ++++++++++++--------
3 files changed, 191 insertions(+), 165 deletions(-)
diff --git a/res/ui/transfer.ui b/res/ui/transfer.ui
index d258290a..64837315 100644
--- a/res/ui/transfer.ui
+++ b/res/ui/transfer.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>496</width>
- <height>440</height>
+ <height>485</height>
</rect>
</property>
<property name="windowTitle">
@@ -36,6 +36,12 @@
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="radio_contact">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="text">
<string>Con&tact</string>
</property>
@@ -44,11 +50,33 @@
</property>
</widget>
</item>
+ <item>
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Maximum</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
<item>
<widget class="QComboBox" name="combo_contact">
<property name="enabled">
<bool>true</bool>
</property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
</widget>
</item>
</layout>
@@ -57,6 +85,12 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="radio_pubkey">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="text">
<string>&Recipient public key</string>
</property>
@@ -65,11 +99,33 @@
</property>
</widget>
</item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Maximum</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
<item>
<widget class="QLineEdit" name="edit_pubkey">
<property name="enabled">
<bool>false</bool>
</property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="inputMask">
<string/>
</property>
@@ -83,6 +139,52 @@
</item>
</layout>
</item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_5">
+ <property name="topMargin">
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QRadioButton" name="radio_search">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>S&earch user</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Maximum</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="SearchUserWidget" name="search_user" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
</layout>
</widget>
</item>
@@ -188,121 +290,16 @@
</item>
</layout>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>SearchUserWidget</class>
+ <extends>QWidget</extends>
+ <header>sakia.gui.widgets.search_user</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
<resources/>
- <connections>
- <connection>
- <sender>button_box</sender>
- <signal>accepted()</signal>
- <receiver>TransferMoneyDialog</receiver>
- <slot>accept()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>248</x>
- <y>254</y>
- </hint>
- <hint type="destinationlabel">
- <x>157</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>button_box</sender>
- <signal>rejected()</signal>
- <receiver>TransferMoneyDialog</receiver>
- <slot>reject()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>316</x>
- <y>260</y>
- </hint>
- <hint type="destinationlabel">
- <x>286</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>combo_wallets</sender>
- <signal>currentIndexChanged(int)</signal>
- <receiver>TransferMoneyDialog</receiver>
- <slot>change_displayed_wallet(int)</slot>
- <hints>
- <hint type="sourcelabel">
- <x>82</x>
- <y>264</y>
- </hint>
- <hint type="destinationlabel">
- <x>199</x>
- <y>244</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>radio_pubkey</sender>
- <signal>toggled(bool)</signal>
- <receiver>TransferMoneyDialog</receiver>
- <slot>recipient_mode_changed(bool)</slot>
- <hints>
- <hint type="sourcelabel">
- <x>87</x>
- <y>51</y>
- </hint>
- <hint type="destinationlabel">
- <x>199</x>
- <y>244</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>combo_community</sender>
- <signal>currentIndexChanged(int)</signal>
- <receiver>TransferMoneyDialog</receiver>
- <slot>change_current_community(int)</slot>
- <hints>
- <hint type="sourcelabel">
- <x>199</x>
- <y>50</y>
- </hint>
- <hint type="destinationlabel">
- <x>199</x>
- <y>165</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>spinbox_relative</sender>
- <signal>valueChanged(double)</signal>
- <receiver>TransferMoneyDialog</receiver>
- <slot>relative_amount_changed()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>320</x>
- <y>269</y>
- </hint>
- <hint type="destinationlabel">
- <x>199</x>
- <y>165</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>spinbox_amount</sender>
- <signal>valueChanged(double)</signal>
- <receiver>TransferMoneyDialog</receiver>
- <slot>amount_changed()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>209</x>
- <y>292</y>
- </hint>
- <hint type="destinationlabel">
- <x>247</x>
- <y>219</y>
- </hint>
- </hints>
- </connection>
- </connections>
+ <connections/>
<slots>
<slot>open_manage_wallet_coins()</slot>
<slot>change_displayed_wallet(int)</slot>
diff --git a/src/sakia/gui/mainwindow.py b/src/sakia/gui/mainwindow.py
index 1538cd59..3c0b0181 100644
--- a/src/sakia/gui/mainwindow.py
+++ b/src/sakia/gui/mainwindow.py
@@ -173,7 +173,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.password_asker,
self.community_view.community,
None)
- if dialog.exec_() == QDialog.Accepted:
+ if dialog.exec() == QDialog.Accepted:
self.community_view.tab_history.table_history.model().sourceModel().refresh_transfers()
def open_certification_dialog(self):
diff --git a/src/sakia/gui/transfer.py b/src/sakia/gui/transfer.py
index e0dae0fa..72afc7b4 100644
--- a/src/sakia/gui/transfer.py
+++ b/src/sakia/gui/transfer.py
@@ -6,7 +6,7 @@ Created on 2 févr. 2014
import asyncio
from PyQt5.QtWidgets import QDialog, QApplication
-from PyQt5.QtCore import QRegExp, Qt
+from PyQt5.QtCore import QRegExp, Qt, QObject
from PyQt5.QtGui import QRegExpValidator
@@ -16,24 +16,31 @@ from sakia.gui.widgets.dialogs import QAsyncMessageBox, QMessageBox
from ..tools.decorators import asyncify
-class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
+class TransferMoneyDialog(QObject):
"""
classdocs
"""
- def __init__(self, app, sender, password_asker, community, transfer):
+ def __init__(self, app, account, password_asker, community, transfer, widget=QDialog, view=Ui_TransferMoneyDialog):
"""
Constructor
:param sakia.core.Application app: The application
- :param sakia.core.Account sender: The sender
+ :param sakia.core.Account account: The account
:param sakia.gui.password_asker.Password_Asker password_asker: The password asker
+ :param sakia.core.Community community:
+ :param sakia.core.Transfer transfer:
+ :param class widget:
+ :param class view:
:return:
"""
super().__init__()
- self.setupUi(self)
+ self.widget = widget()
+ self.ui = view()
+ self.ui.setupUi(self.widget)
+
self.app = app
- self.account = sender
+ self.account = account
self.password_asker = password_asker
self.recipient_trusts = []
self.transfer = transfer
@@ -41,41 +48,54 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
self.community = community if community else self.account.communities[0]
self.wallet = self.account.wallets[0]
+ self.ui.radio_contact.toggled.connect(lambda c, radio="contact": self.recipient_mode_changed(radio))
+ self.ui.radio_pubkey.toggled.connect(lambda c, radio="pubkey": self.recipient_mode_changed(radio))
+ self.ui.radio_search.toggled.connect(lambda c, radio="search": self.recipient_mode_changed(radio))
+ self.ui.button_box.accepted.connect(self.accept)
+ self.ui.button_box.rejected.connect(self.widget.reject)
+ self.ui.combo_wallets.currentIndexChanged.connect(self.change_displayed_wallet)
+ self.ui.combo_community.currentIndexChanged.connect(self.change_current_community)
+ self.ui.spinbox_relative.valueChanged.connect(self.relative_amount_changed)
+ self.ui.spinbox_amount.valueChanged.connect(self.amount_changed)
+ self.ui.search_user.button_reset.hide()
+ self.ui.search_user.init(self.app)
+ self.ui.search_user.change_account(self.account)
+ self.ui.search_user.change_community(self.community)
+
regexp = QRegExp('^([ a-zA-Z0-9-_:/;*?\[\]\(\)\\\?!^+=@&~#{}|<>%.]{0,255})$')
validator = QRegExpValidator(regexp)
- self.edit_message.setValidator(validator)
+ self.ui.edit_message.setValidator(validator)
for community in self.account.communities:
- self.combo_community.addItem(community.currency)
+ self.ui.combo_community.addItem(community.currency)
for wallet in self.account.wallets:
- self.combo_wallets.addItem(wallet.name)
+ self.ui.combo_wallets.addItem(wallet.name)
- for contact_name in sorted([c['name'] for c in sender.contacts], key=str.lower):
- self.combo_contact.addItem(contact_name)
+ for contact_name in sorted([c['name'] for c in account.contacts], key=str.lower):
+ self.ui.combo_contact.addItem(contact_name)
if len(self.account.contacts) == 0:
- self.combo_contact.setEnabled(False)
- self.radio_contact.setEnabled(False)
- self.radio_pubkey.setChecked(True)
+ self.ui.combo_contact.setEnabled(False)
+ self.ui.radio_contact.setEnabled(False)
+ self.ui.radio_pubkey.setChecked(True)
- self.combo_community.setCurrentText(self.community.name)
+ self.ui.combo_community.setCurrentText(self.community.name)
if self.transfer:
- sender = self.transfer.metadata['issuer']
- wallet_index = [w.pubkey for w in app.current_account.wallets].index(sender)
- self.combo_wallets.setCurrentIndex(wallet_index)
- self.edit_pubkey.setText(transfer.metadata['receiver'])
- self.radio_pubkey.setChecked(True)
- self.edit_message.setText(transfer.metadata['comment'])
-
+ account = self.transfer.metadata['issuer']
+ wallet_index = [w.pubkey for w in app.current_account.wallets].index(account)
+ self.ui.combo_wallets.setCurrentIndex(wallet_index)
+ self.ui.edit_pubkey.setText(transfer.metadata['receiver'])
+ self.ui.radio_pubkey.setChecked(True)
+ self.ui.edit_message.setText(transfer.metadata['comment'])
@classmethod
async def send_money_to_identity(cls, app, account, password_asker, community, identity):
dialog = cls(app, account, password_asker, community, None)
dialog.edit_pubkey.setText(identity.pubkey)
dialog.radio_pubkey.setChecked(True)
- return (await dialog.async_exec())
+ return await dialog.async_exec()
@classmethod
async def send_transfer_again(cls, app, account, password_asker, community, transfer):
@@ -86,27 +106,32 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
dialog.spinbox_relative.setMaximum(relative)
dialog.spinbox_amount.setValue(transfer.metadata['amount'])
- return (await dialog.async_exec())
+ return await dialog.async_exec()
@asyncify
async def accept(self):
- self.button_box.setEnabled(False)
- comment = self.edit_message.text()
+ self.ui.button_box.setEnabled(False)
+ comment = self.ui.edit_message.text()
- if self.radio_contact.isChecked():
+ if self.ui.radio_contact.isChecked():
for contact in self.account.contacts:
- if contact['name'] == self.combo_contact.currentText():
+ if contact['name'] == self.ui.combo_contact.currentText():
recipient = contact['pubkey']
break
+ elif self.ui.radio_search.isChecked():
+ if self.ui.search_user.current_identity():
+ recipient = self.ui.search_user.current_identity().pubkey
+ else:
+ return
else:
- recipient = self.edit_pubkey.text()
- amount = self.spinbox_amount.value()
+ recipient = self.ui.edit_pubkey.text()
+ amount = self.ui.spinbox_amount.value()
if not amount:
await QAsyncMessageBox.critical(self, self.tr("Money transfer"),
self.tr("No amount. Please give the transfert amount"),
QMessageBox.Ok)
- self.button_box.setEnabled(True)
+ self.ui.button_box.setEnabled(True)
return
password = await self.password_asker.async_exec()
@@ -130,7 +155,7 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
if self.transfer:
self.transfer.cancel()
- super().accept()
+ self.widget.accept()
else:
if self.app.preferences['notifications']:
toast.display(self.tr("Transfer"), "Error : {0}".format(result[1]))
@@ -138,23 +163,23 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
await QAsyncMessageBox.critical(self, self.tr("Transfer"), result[1])
QApplication.restoreOverrideCursor()
- self.button_box.setEnabled(True)
+ self.ui.button_box.setEnabled(True)
@asyncify
async def amount_changed(self, value):
dividend = await self.community.dividend()
relative = value / dividend
- self.spinbox_relative.blockSignals(True)
- self.spinbox_relative.setValue(relative)
- self.spinbox_relative.blockSignals(False)
+ self.ui.spinbox_relative.blockSignals(True)
+ self.ui.spinbox_relative.setValue(relative)
+ self.ui.spinbox_relative.blockSignals(False)
@asyncify
async def relative_amount_changed(self, value):
dividend = await self.community.dividend()
amount = value * dividend
- self.spinbox_amount.blockSignals(True)
- self.spinbox_amount.setValue(amount)
- self.spinbox_amount.blockSignals(False)
+ self.ui.spinbox_amount.blockSignals(True)
+ self.ui.spinbox_amount.setValue(amount)
+ self.ui.spinbox_amount.blockSignals(False)
@asyncify
async def change_current_community(self, index):
@@ -164,13 +189,13 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
ref_text = await self.account.current_ref(amount, self.community, self.app)\
.diff_localized(units=True,
international_system=self.app.preferences['international_system_of_units'])
- self.label_total.setText("{0}".format(ref_text))
- self.spinbox_amount.setSuffix(" " + self.community.currency)
+ self.ui.label_total.setText("{0}".format(ref_text))
+ self.ui.spinbox_amount.setSuffix(" " + self.community.currency)
amount = await self.wallet.value(self.community)
dividend = await self.community.dividend()
relative = amount / dividend
- self.spinbox_amount.setMaximum(amount)
- self.spinbox_relative.setMaximum(relative)
+ self.ui.spinbox_amount.setMaximum(amount)
+ self.ui.spinbox_relative.setMaximum(relative)
@asyncify
async def change_displayed_wallet(self, index):
@@ -179,19 +204,23 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
ref_text = await self.account.current_ref(amount, self.community, self.app)\
.diff_localized(units=True,
international_system=self.app.preferences['international_system_of_units'])
- self.label_total.setText("{0}".format(ref_text))
+ self.ui.label_total.setText("{0}".format(ref_text))
amount = await self.wallet.value(self.community)
dividend = await self.community.dividend()
relative = amount / dividend
- self.spinbox_amount.setMaximum(amount)
- self.spinbox_relative.setMaximum(relative)
+ self.ui.spinbox_amount.setMaximum(amount)
+ self.ui.spinbox_relative.setMaximum(relative)
- def recipient_mode_changed(self, pubkey_toggled):
- self.edit_pubkey.setEnabled(pubkey_toggled)
- self.combo_contact.setEnabled(not pubkey_toggled)
+ def recipient_mode_changed(self, radio):
+ self.ui.edit_pubkey.setEnabled(radio == "pubkey")
+ self.ui.combo_contact.setEnabled(radio == "contact")
+ self.ui.search_user.setEnabled(radio == "search")
def async_exec(self):
future = asyncio.Future()
self.finished.connect(lambda r: future.set_result(r))
self.open()
return future
+
+ def exec(self):
+ self.widget.exec()
\ No newline at end of file
--
GitLab