def __load_addressbook_cb(self,dlg=None):
     self._addressbook_controller = MSDAddressBook.get_addressbook_controller(self.MSDConf,self.preferences)
     dlg.destroy()
     self._addressbook_controller.show()
    def __init__(self):
	MSD.init_i18n()
        self.xml = gtk.glade.XML(MSD.glade_files_dir + "mainwindow.glade")
        self.main_window = self.xml.get_widget("main_window")
        self.main_window.set_icon_from_file(MSD.icons_files_dir + "main_window_icon.png")
        self.main_vbox = self.xml.get_widget("main_vbox")
        #FIXED : Controller
        self.mcontroller = MSD.MobileManagerControllerClient()
        self.main_toolbar = MSD.MSDMainToolbar()
        #FIXED : Controller
        self.main_stats = MSD.MSDMainStatsWidget(self.mcontroller)
        self.rss = MSD.MSDRSSFeeder()
        self.main_vbox.pack_start(self.main_toolbar)
        self.main_vbox.reorder_child(self.main_toolbar, 0)
        self.main_vbox.pack_start(self.main_stats)
        self.main_vbox.reorder_child(self.main_stats, 3)
        self.actions_scrolled_window = self.xml.get_widget("actions_scrolled_window")
        self.main_actions_view = self.xml.get_widget("main_actions_view")
        self.bookmarks_button = self.main_toolbar.bookmarks_button
        self.preferences_button = self.main_toolbar.preferences_button
        self.addressbook_button = self.main_toolbar.addressbook_button
        self.help_button = self.main_toolbar.help_button
        self.expander_eventbox = self.xml.get_widget("expander_eventbox")
        self.expander_eventbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ecf1fb"))
        self.main_separator = self.xml.get_widget("main_separator")
        self.mini_banner_eventbox = self.xml.get_widget("mini_banner_eventbox")
        self.mini_banner_eventbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#525774"))
        self.mini_banner_image =  self.xml.get_widget("mini_banner_image")
        self.mini_banner_image.set_from_file(MSD.icons_files_dir + "mini_banner.png")
        self.device_eventbox = self.xml.get_widget("device_eventbox")
        self.device_eventbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#515774"))
        self.main_statusbar = self.xml.get_widget("main_statusbar")
        self.connect_statusbar_im = gtk.Image()
        self.connect_statusbar_im.set_from_file(MSD.icons_files_dir + "conectado.png")
        self.disconnect_statusbar_im = gtk.Image()
        self.disconnect_statusbar_im.set_from_file(MSD.icons_files_dir + "no-conectado.png")
        self.main_statusbar.pack_start(self.connect_statusbar_im, expand=False)
        self.main_statusbar.pack_start(self.disconnect_statusbar_im, expand=False)
        self.connect_statusbar_im.hide()
        self.disconnect_statusbar_im.hide()
        self.main_statusbar.reorder_child(self.connect_statusbar_im, 0)
        self.main_statusbar.reorder_child(self.disconnect_statusbar_im, 1)
        self.card_statusbar = gtk.Statusbar()
        self.card_statusbar.set_has_resize_grip(False)
        self.main_statusbar.pack_end(self.card_statusbar, expand=True)
        self.card_statusbar.hide()
        
        self.consum_button = self.main_stats.consum_button
        self.connect_button = self.main_stats.connect_button
        self.disconnect_button = self.main_stats.disconnect_button
        self.expander_on_button = self.xml.get_widget("expander_on_button")
        self.expander_off_button = self.xml.get_widget("expander_off_button")
        self.device_selected_button = self.xml.get_widget("device_selected_button")
        self.device_selected_label = self.xml.get_widget("device_selected_label")
        self.device_selected_button.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse("#717aa6"))
        self.device_selected_button.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse("#717aa6"))
        self.device_selected_button.modify_bg(gtk.STATE_SELECTED, gtk.gdk.color_parse("#717aa6"))
        #FIXED : UI
        self.at_options_button = MobileManager.ui.MobileATOptionsButton()

        #FIXED : Controller
        dev = self.mcontroller.get_active_device()
        #FIXED : Controller (esto puede dar None?)
        if dev == None :
            self.device_selected_label.set_markup(_(u'<span foreground="white">Ningún dispositivo disponible</span>'))
        else:
            #FIXED : Set
            odev = self.mcontroller.get_device_obj_from_path(dev)
            self.device_selected_label.set_markup ('<span foreground="white">%s</span>' % odev.get_prettyname())
            self.mcontroller.set_active_device(dev)
        
        self.can_show_main_pcmcia_menu = False

        self.MSDConf = MSD.MSDConf()

        self.MSDConnManager = MSD.MSDConnectionsManager(self.MSDConf, self)

        self.main_actions_menu_item_mail = gtk.MenuItem(_(u"Nuevo correo"))
        
        self.MSDActManager = MSD.MSDActionsManager(self.MSDConf, self.MSDConnManager)

        liststore = self.MSDActManager.get_actions_model()
        cellrenderpixbuf = gtk.CellRendererPixbuf()
        cellrenderpixbuf.set_property('cell-background', '#DEDEDE')
        cellrendertext = gtk.CellRendererText()
        cellrendertext.set_property('cell-background', '#DEDEDE')
        
        column = gtk.TreeViewColumn('MAV_icon', cellrenderpixbuf,
                                    pixbuf=0, cell_background_set=3)
        self.main_actions_view.append_column(column)
        column = gtk.TreeViewColumn('MAV_name', cellrendertext,
                                    markup=1, cell_background_set=3)
        self.main_actions_view.append_column(column)

        # assign the tooltip
        tips = gtk.Tooltips()
        tips.set_tip(self.main_actions_view, "")

        self.main_actions_view.set_model(liststore)
        
        self.preferences = MSD.MSDPreferencesDialog(self)

        self.MSDActManager.set_connections_model(self.preferences.get_connections_model())


        # Consum
        emtraffic.set_db_file(get_user_traffic_db_path())
        emtraffic.set_version(
        	MSD.msd_version_major,
        	MSD.msd_version_minor,
        	MSD.msd_version_update,
        	MSD.msd_version_string)        
        self.consum = MSD.MSDConsumWindow(self.MSDConf)
        #FIXED: mcontroller
        self.consum_manager = MSD.MSDConsumManager(self.mcontroller, self.main_stats, self.consum,self.MSDConf)

        # Help stuff

        self.progress_dialog = MSD.MSDProgressWindow()
        self.progress_dialog.set_show_buttons(False)
        self.timer_id = 0

        self.help_dialog = self.xml.get_widget("help_window")
        self.help_dialog.set_icon_from_file(MSD.icons_files_dir + "ayuda_16x16.png")
        self.hd_help_button = self.xml.get_widget("help_button")
        self.hd_help_online_button = self.xml.get_widget("help_online_button")
        self.hd_help_close_button = self.xml.get_widget("help_close_button")
        self.hd_help_info_treeview = self.xml.get_widget("help_info_treeview")
        self.help_liststore = gtk.ListStore(str, str)
        column = gtk.TreeViewColumn('Option_key', gtk.CellRendererText(),
                                    markup=0)
        self.hd_help_info_treeview.append_column(column)
        column = gtk.TreeViewColumn('Option_value', gtk.CellRendererText(),
                                    markup=1)
        self.hd_help_info_treeview.append_column(column)
        self.hd_help_info_treeview.set_model(self.help_liststore)

        # Bookmarks
        self.bookmarks_menu = gtk.Menu()
        for bookmark in self.MSDConf.get_bookmarks_list():
            self.bookmarks_menu.append(gtk.MenuItem(gobject.markup_escape_text(bookmark[0]), False))
        
        #Warning
        self.warning_dialog = MSD.MSDWarningDialog(self.xml, self.main_window, self.MSDConf)

        # Main actions menu
        self.main_actions_menu = gtk.Menu()
        self.main_actions_menu_item_open = gtk.ImageMenuItem(_(u"Abrir"))
        self.main_actions_menu_item_config = gtk.MenuItem(_(u"Configuración"))
        self.main_actions_menu_item_install = gtk.MenuItem(_(u"Instalar"))
        self.main_actions_menu_item_help = gtk.ImageMenuItem(gtk.STOCK_HELP)
        self.main_actions_menu.append (self.main_actions_menu_item_mail)
        self.main_actions_menu.append (self.main_actions_menu_item_open)
        self.main_actions_menu.append (self.main_actions_menu_item_config)
        self.main_actions_menu.append (self.main_actions_menu_item_install)
        self.main_actions_menu.append (self.main_actions_menu_item_help)

        #Signals !
        self.MSDActManager.connect_signals()
        self.main_window.connect("delete-event", self.__closeapp_cb, None)
        self.bookmarks_button.connect("clicked", self.__show_bookmarks_cb, None)
        self.addressbook_button.connect("clicked",self.__show_addressbook_cb,None)
        self.preferences_button.connect("clicked", self.__show_preferences_cb, None)
        self.help_button.connect("clicked", self.__show_help_cb, None)
        self.hd_help_button.connect("clicked", self.__open_help_button_cb, None)
        self.hd_help_online_button.connect("clicked", self.__open_help_online_button_cb, None)
        self.hd_help_close_button.connect("clicked", self.__close_help_dialog_cb, None)
        self.help_dialog.connect("delete_event", self.__close_help_dialog_cb)
        self.expander_on_button.connect("clicked", self.__expander_on_button_cb, None)
        self.expander_off_button.connect("clicked", self.__expander_off_button_cb, None)
        self.consum_button.connect("clicked", self.__consum_button_cb)
        self.device_selected_button.connect("clicked", self.__device_selected_button_cb, None)
        self.main_actions_view.connect("row-activated", self.__action_activated_cb, None)
        self.main_actions_view.connect("event", self.__roll_over_main_actions_treeview_cb, None)
        self.main_actions_view.connect("motion-notify-event", self.__main_actions_view_tooltip, tips, 4)
        self.main_actions_view.set_events(gtk.gdk.POINTER_MOTION_MASK)
        self.main_actions_menu_item_mail.connect("activate", self.__main_actions_menu_item_mail_cb, None)
        self.main_actions_menu_item_open.connect("activate", self.__main_actions_menu_item_open_cb, None)
        self.main_actions_menu_item_config.connect("activate", self.__main_actions_menu_item_config_cb, None)
        self.main_actions_menu_item_install.connect("activate", self.__main_actions_menu_item_install_cb, None)
        self.main_actions_menu_item_help.connect("activate", self.__main_actions_menu_item_help_cb, None)

        #Rss stopper delegate
        self.mcontroller.dialer.add_stop_delegate(self.rss.kill_downloader)
                                                  
        #FIXED : Controller
        self.mcontroller.connect ("active-device-changed", self.__active_device_changed_cb)
        self.mcontroller.connect ("active-dev-card-status-changed", self.__active_device_card_status_changed)
        #FIXME : Politica nueva?
        self.mcontroller.connect ("added-device", self.__device_added_cb)
        self.mcontroller.connect ("removed-device", self.__device_removed_cb)
        self.mcontroller.dialer.connect("connected", self.__connected_cb)
        self.mcontroller.dialer.connect("disconnected", self.__disconnected_cb)
        self.mcontroller.dialer.connect("connecting", self.__connecting_cb)
        self.mcontroller.dialer.connect("disconnecting", self.__disconnecting_cb)

        if self.MSDConnManager.ppp_manager.status() == MobileManager.PPP_STATUS_CONNECTED:
            self.mcontroller.dialer.emit("connected")
        
        self.pcmcia_manager = None

        # Systray
        #FIXED : Controller
        self.systray = MSD.MSDSystray(self.MSDConf, self.main_window, self.MSDConnManager, self.MSDActManager, self.mcontroller)
        self.MSDActManager.set_systray(self.systray)

        if self.MSDConf.get_ui_general_key_value ("systray_showing_mw"):
            self.main_window.show()
        else:
            self.main_window.hide()

        self.main_stats.show()
        self.main_toolbar.show()
        
        if self.MSDConf.get_ui_general_key_value("main_expander_on") == True:
            self.__expander_on_button_cb(None, None)
        else:
            self.__expander_off_button_cb(None, None)
        
        # pongo un timeout para ejecutar las acciones que deben se ejecutadas de manera autonoma (sin intervencion del usuario)
        # al cargarse la aplicacion
        gobject.timeout_add(1,self.__initial_actions_cb)


        if len(sys.argv) == 3 :
            if os.path.exists(sys.argv[2]):
                 self.preferences.importer.import_from_file(sys.argv[2])

        gobject.timeout_add(3000, self.__import_while_app_working_cb)
        
        # Addressbook
        self._addressbook_controller = None
        self._user_book = MSDAddressBook.get_user_addressbook()
        self._select_contact_window = self.xml.get_widget("select_contact_window")
        self._select_contact_window.set_icon_from_file(MSD.icons_files_dir + "mail_16x16.png")
        self._sc_send_mail_button = self.xml.get_widget("sc_send_mail_button")
        self._sc_cancel_button = self.xml.get_widget("sc_cancel_button")
        ## treeview
        self._sc_treeview = self.xml.get_widget("sc_contacts_treeview")
        base_id = 1
        for field in [_(u"Nombre"),_(u"Correo electrónico")]:
            col = gtk.TreeViewColumn(field)
            self._sc_treeview.append_column(col)
            cell = gtk.CellRendererText()
            col.pack_start(cell, True)
            col.add_attribute(cell, 'text', base_id)
            col.set_resizable(True)
            cell.set_property("ellipsize", pango.ELLIPSIZE_END)
            base_id = base_id + 1
            
        model = gtk.ListStore(gobject.TYPE_INT,
                               gobject.TYPE_STRING,
                               gobject.TYPE_STRING)
        self._sc_treeview.set_model(model)
        #signals
        self._select_contact_window.connect("delete-event", self.__sl_delete_cb, None)
        self._sc_send_mail_button.connect("clicked", self.__sl_send_mail_cb, None)
        self._sc_cancel_button.connect("clicked", self.__sl_delete_cb, None)

        # Select active device if available
        # FIXED: Controller
        self.__select_active_device_on_init()

        # Feed updater
        #FIXED: Controller
        self.update_checker = MSD.MSDUpdateChecker (self.MSDConf, self.mcontroller)