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 @@
</property>
<widget class="QMenu" name="menu_change_account">
<property name="title">
<string>Open account</string>
<string>Open</string>
</property>
</widget>
<addaction name="menu_change_account"/>
<addaction name="action_add_account"/>
<addaction name="menu_change_account"/>
<addaction name="action_configure_parameters"/>
<addaction name="action_set_as_default"/>
<addaction name="separator"/>
<addaction name="action_export"/>
<addaction name="action_import"/>
......@@ -127,7 +128,7 @@
</action>
<action name="action_add_account">
<property name="text">
<string>Add account</string>
<string>Add</string>
</property>
</action>
<action name="action_save">
......@@ -152,7 +153,7 @@
</action>
<action name="action_configure_parameters">
<property name="text">
<string>Configure account</string>
<string>Configure</string>
</property>
</action>
<action name="action_import">
......@@ -170,6 +171,11 @@
<string>Certification</string>
</property>
</action>
<action name="action_set_as_default">
<property name="text">
<string>Set as default</string>
</property>
</action>
</widget>
<resources/>
<connections>
......@@ -301,6 +307,22 @@
</hint>
</hints>
</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>
<slots>
<slot>open_add_account_dialog()</slot>
......@@ -312,5 +334,6 @@
<slot>refresh_wallet_content(QModelIndex)</slot>
<slot>export_account()</slot>
<slot>open_certification_dialog()</slot>
<slot>set_as_default_account()</slot>
</slots>
</ui>
......@@ -26,14 +26,20 @@ class Application(object):
Constructor
'''
self.accounts = {}
self.default_account = ""
self.current_account = None
config.parse_arguments(argv)
self.load()
if self.default_account != "":
self.current_account = self.get_account(self.default_account)
def get_account(self, name):
if not self.accounts[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):
for a in self.accounts:
......@@ -72,6 +78,8 @@ class Application(object):
with open(config.parameters['data'], 'r') as json_data:
data = json.load(json_data)
json_data.close()
if 'default_account' in data.keys():
self.default_account = data['default_account']
for account_name in data['local_accounts']:
self.accounts[account_name] = None
......@@ -141,10 +149,12 @@ class Application(object):
def jsonify_accounts(self):
data = []
logging.debug("{0}".format(self.accounts))
for account in self.accounts:
data.append(account.name)
data.append(account)
return data
def jsonify(self):
data = {'local_accounts': self.jsonify_accounts()}
data = {'default_account': self.default_account,
'local_accounts': self.jsonify_accounts()}
return data
......@@ -15,6 +15,7 @@ from .import_account import ImportAccountDialog
from .certification import CertificationDialog
from .password_asker import PasswordAskerDialog
import logging
class MainWindow(QMainWindow, Ui_MainWindow):
......@@ -69,6 +70,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
currency_tab = self.currencies_tabwidget.currentWidget()
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
When the selected account changes, all the widgets
......@@ -89,7 +96,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if self.app.current_account is None:
self.menu_contacts.setEnabled(False)
self.menu_actions.setEnabled(False)
self.action_set_as_default.setEnabled(False)
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.menu_contacts.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