from PySide import QtGui

import cbpos

from cbpos.mod.currency.models.currency import Currency

class CurrencyConfigPage(QtGui.QWidget):
    label = 'Currency'
    
    def __init__(self):
        super(CurrencyConfigPage, self).__init__()
        
        self.default = QtGui.QComboBox()
        
        form = QtGui.QFormLayout()
        form.setSpacing(10)
        
        form.addRow('Default Currency', self.default)
        
        self.setLayout(form)

    def populate(self):
        session = cbpos.database.session()
        
        default_id = cbpos.config['mod.currency', 'default']
        
        selected_index = -1
        self.default.clear()
        
        for i, c in enumerate(session.query(Currency)):
            self.default.addItem(c.display, c)
            if default_id == c.id:
                selected_index = i
        
        self.default.setCurrentIndex(selected_index)
    
    def update(self):
        default = self.default.itemData(self.default.currentIndex())
        cbpos.config['mod.currency', 'default'] = unicode(default.id)

@@ -37,16 +37,67 @@
 bpos%0D%0A%0D%0A
+import cbpos.mod.currency.controllers as currency%0D%0A
 from cbp
@@ -634,34 +634,16 @@
 d = 
-cbpos.config%5B'mod.
 currency
 ', '
@@ -638,29 +638,27 @@
 currency
-', '
+.
 default
-'%5D
+.id
 %0D%0A      

Handle unset default currency better