Skip to content
Snippets Groups Projects
Commit 5a49a318 authored by inso's avatar inso
Browse files

Added default account feature

Added the possibility to define a default account
parent cf7d3423
No related branches found
No related tags found
No related merge requests found
...@@ -42,12 +42,13 @@ ...@@ -42,12 +42,13 @@
</property> </property>
<widget class="QMenu" name="menu_change_account"> <widget class="QMenu" name="menu_change_account">
<property name="title"> <property name="title">
<string>Open account</string> <string>Open</string>
</property> </property>
</widget> </widget>
<addaction name="menu_change_account"/>
<addaction name="action_add_account"/> <addaction name="action_add_account"/>
<addaction name="menu_change_account"/>
<addaction name="action_configure_parameters"/> <addaction name="action_configure_parameters"/>
<addaction name="action_set_as_default"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="action_export"/> <addaction name="action_export"/>
<addaction name="action_import"/> <addaction name="action_import"/>
...@@ -127,7 +128,7 @@ ...@@ -127,7 +128,7 @@
</action> </action>
<action name="action_add_account"> <action name="action_add_account">
<property name="text"> <property name="text">
<string>Add account</string> <string>Add</string>
</property> </property>
</action> </action>
<action name="action_save"> <action name="action_save">
...@@ -152,7 +153,7 @@ ...@@ -152,7 +153,7 @@
</action> </action>
<action name="action_configure_parameters"> <action name="action_configure_parameters">
<property name="text"> <property name="text">
<string>Configure account</string> <string>Configure</string>
</property> </property>
</action> </action>
<action name="action_import"> <action name="action_import">
...@@ -170,6 +171,11 @@ ...@@ -170,6 +171,11 @@
<string>Certification</string> <string>Certification</string>
</property> </property>
</action> </action>
<action name="action_set_as_default">
<property name="text">
<string>Set as default</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections> <connections>
...@@ -301,6 +307,22 @@ ...@@ -301,6 +307,22 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>action_set_as_default</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>set_as_default_account()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>340</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots> <slots>
<slot>open_add_account_dialog()</slot> <slot>open_add_account_dialog()</slot>
...@@ -312,5 +334,6 @@ ...@@ -312,5 +334,6 @@
<slot>refresh_wallet_content(QModelIndex)</slot> <slot>refresh_wallet_content(QModelIndex)</slot>
<slot>export_account()</slot> <slot>export_account()</slot>
<slot>open_certification_dialog()</slot> <slot>open_certification_dialog()</slot>
<slot>set_as_default_account()</slot>
</slots> </slots>
</ui> </ui>
...@@ -26,14 +26,20 @@ class Application(object): ...@@ -26,14 +26,20 @@ class Application(object):
Constructor Constructor
''' '''
self.accounts = {} self.accounts = {}
self.default_account = ""
self.current_account = None self.current_account = None
config.parse_arguments(argv) config.parse_arguments(argv)
self.load() self.load()
if self.default_account != "":
self.current_account = self.get_account(self.default_account)
def get_account(self, name): def get_account(self, name):
if not self.accounts[name]: if not self.accounts[name]:
self.load_account(name) self.load_account(name)
return self.accounts[name] if name in self.accounts.keys():
return self.accounts[name]
else:
return None
def create_account(self, name): def create_account(self, name):
for a in self.accounts: for a in self.accounts:
...@@ -72,6 +78,8 @@ class Application(object): ...@@ -72,6 +78,8 @@ class Application(object):
with open(config.parameters['data'], 'r') as json_data: with open(config.parameters['data'], 'r') as json_data:
data = json.load(json_data) data = json.load(json_data)
json_data.close() json_data.close()
if 'default_account' in data.keys():
self.default_account = data['default_account']
for account_name in data['local_accounts']: for account_name in data['local_accounts']:
self.accounts[account_name] = None self.accounts[account_name] = None
...@@ -141,10 +149,12 @@ class Application(object): ...@@ -141,10 +149,12 @@ class Application(object):
def jsonify_accounts(self): def jsonify_accounts(self):
data = [] data = []
logging.debug("{0}".format(self.accounts))
for account in self.accounts: for account in self.accounts:
data.append(account.name) data.append(account)
return data return data
def jsonify(self): def jsonify(self):
data = {'local_accounts': self.jsonify_accounts()} data = {'default_account': self.default_account,
'local_accounts': self.jsonify_accounts()}
return data return data
...@@ -15,6 +15,7 @@ from .import_account import ImportAccountDialog ...@@ -15,6 +15,7 @@ from .import_account import ImportAccountDialog
from .certification import CertificationDialog from .certification import CertificationDialog
from .password_asker import PasswordAskerDialog from .password_asker import PasswordAskerDialog
import logging
class MainWindow(QMainWindow, Ui_MainWindow): class MainWindow(QMainWindow, Ui_MainWindow):
...@@ -69,6 +70,12 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -69,6 +70,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
currency_tab = self.currencies_tabwidget.currentWidget() currency_tab = self.currencies_tabwidget.currentWidget()
currency_tab.refresh_wallets() currency_tab.refresh_wallets()
def set_as_default_account(self):
self.app.default_account = self.app.current_account.name
logging.debug(self.app.current_account)
self.app.save(self.app.current_account)
self.action_set_as_default.setEnabled(False)
''' '''
Refresh main window Refresh main window
When the selected account changes, all the widgets When the selected account changes, all the widgets
...@@ -89,7 +96,9 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -89,7 +96,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if self.app.current_account is None: if self.app.current_account is None:
self.menu_contacts.setEnabled(False) self.menu_contacts.setEnabled(False)
self.menu_actions.setEnabled(False) self.menu_actions.setEnabled(False)
self.action_set_as_default.setEnabled(False)
else: else:
self.action_set_as_default.setEnabled(self.app.current_account.name != self.app.default_account)
self.password_asker = PasswordAskerDialog(self.app.current_account) self.password_asker = PasswordAskerDialog(self.app.current_account)
self.menu_contacts.setEnabled(True) self.menu_contacts.setEnabled(True)
self.menu_actions.setEnabled(True) self.menu_actions.setEnabled(True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment