From 9499b6e66b779ce7924d45219909da24d43b6eec Mon Sep 17 00:00:00 2001
From: Vincent Texier <vit@free.fr>
Date: Wed, 3 Jun 2015 10:40:27 +0200
Subject: [PATCH] fix account not opened if preferences default account is
 empty

---
 src/cutecoin/gui/mainwindow.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py
index a2f75946..e3c314ea 100644
--- a/src/cutecoin/gui/mainwindow.py
+++ b/src/cutecoin/gui/mainwindow.py
@@ -404,7 +404,22 @@ class MainWindow(QMainWindow, Ui_MainWindow):
     def showEvent(self, event):
         super().showEvent(event)
         if not self.initialized:
+            # if default account in preferences...
             if self.app.preferences['account'] != "":
                 logging.debug("Loading default account")
                 self.action_change_account(self.app.preferences['account'])
+            # no default account...
+            else:
+                # if at least one account exists, set it as default...
+                if len(self.app.accounts) > 0:
+                    # capture names sorted alphabetically
+                    names = list(self.app.accounts.keys())
+                    names.sort()
+                    # set first name in list as default in preferences
+                    self.app.preferences['account'] = names[0]
+                    self.app.save_preferences(self.app.preferences)
+                    # open it
+                    logging.debug("No default account in preferences. Set %s as default account." % names[0])
+                    self.action_change_account(self.app.preferences['account'])
+
             self.initialized = True
-- 
GitLab