# HG changeset patch # User Goffi # Date 1267078158 -39600 # Node ID 9b842086d915ec5a26130022a987d960e4e672db # Parent 0e50dd3a234a7011936d06e30b9463826f886aa5 multiple profiles update - Wix: new profile managed, it appear at launch in place of the contact list, and disappear once the profile is choosen - SàT: default profile is now saved, first one is choosed is no default profile - Bridge: new delete profile method diff -r 0e50dd3a234a -r 9b842086d915 frontends/quick_frontend/quick_app.py --- a/frontends/quick_frontend/quick_app.py Thu Feb 04 01:06:36 2010 +1100 +++ b/frontends/quick_frontend/quick_app.py Thu Feb 25 17:09:18 2010 +1100 @@ -62,6 +62,7 @@ profile = self.bridge.getProfileName(profile_key) if not profile: error("The profile asked doesn't exist") + return if self.profiles.has_key(profile): warning("The profile is already plugged") return diff -r 0e50dd3a234a -r 9b842086d915 frontends/sat_bridge_frontend/DBus.py --- a/frontends/sat_bridge_frontend/DBus.py Thu Feb 04 01:06:36 2010 +1100 +++ b/frontends/sat_bridge_frontend/DBus.py Thu Feb 25 17:09:18 2010 +1100 @@ -46,8 +46,11 @@ def getProfilesList(self): return self.db_req_iface.getProfilesList() - def createProfile(self, profile): - return self.db_req_iface.getProfileName(profile) + def createProfile(self, name): + return self.db_req_iface.createProfile(name) + + def deleteProfile(self, name): + return self.db_req_iface.deleteProfile(name) def connect(self, profile_key='@DEFAULT@'): return self.db_comm_iface.connect(profile_key) diff -r 0e50dd3a234a -r 9b842086d915 frontends/wix/main_window.py --- a/frontends/wix/main_window.py Thu Feb 04 01:06:36 2010 +1100 +++ b/frontends/wix/main_window.py Thu Feb 25 17:09:18 2010 +1100 @@ -26,6 +26,7 @@ from form import Form from gateways import GatewaysManager from profile import Profile +from profile_manager import ProfileManager import gobject import os.path import pdb @@ -219,17 +220,24 @@ """main app window""" def __init__(self): - wx.Frame.__init__(self,None, title="SAT Wix", size=(300,500)) + wx.Frame.__init__(self,None, title="SàT Wix", size=(300,500)) self.CM = QuickContactManagement() #FIXME: not the best place - - + #sizer + self.sizer = wx.BoxSizer(wx.VERTICAL) + self.SetSizer(self.sizer) + #Frame elements self.contactList = ContactList(self, self.CM) self.contactList.registerActivatedCB(self.onContactActivated) + self.contactList.Hide() + self.sizer.Add(self.contactList, 1, flag=wx.EXPAND) + self.chat_wins=ChatList(self) self.CreateStatusBar() self.createMenus() + for i in range(self.menuBar.GetMenuCount()): + self.menuBar.EnableTop(i, False) #ToolBar self.tools=self.CreateToolBar() @@ -254,10 +262,26 @@ self.Bind(wx.EVT_CLOSE, self.onClose, self) QuickApp.__init__(self) - self.plug_profile() + #self.plug_profile() #gof: + + #profile panel + self.profile_pan = ProfileManager(self) + #self.profile_pan.Hide() #gof: + self.sizer.Add(self.profile_pan, 1, flag=wx.EXPAND) self.Show() + def plug_profile(self, profile_key='@DEFAULT@'): + """Hide profile panel then plug profile""" + self.profile_pan.Hide() + self.contactList.Show() + self.sizer.Layout() + for i in range(self.menuBar.GetMenuCount()): + self.menuBar.EnableTop(i, True) + super(MainWindow, self).plug_profile(profile_key) + if not self.bridge.isConnected(profile_key): + self.bridge.connect(profile_key) + def createMenus(self): info("Creating menus") connectMenu = wx.Menu() @@ -273,11 +297,11 @@ contactMenu.Append(idSHOW_PROFILE, "&Show profile", " Show contact's profile") communicationMenu = wx.Menu() communicationMenu.Append(idFIND_GATEWAYS, "&Find Gateways"," Find gateways to legacy IM") - menuBar = wx.MenuBar() - menuBar.Append(connectMenu,"&General") - menuBar.Append(contactMenu,"&Contacts") - menuBar.Append(communicationMenu,"&Communication") - self.SetMenuBar(menuBar) + self.menuBar = wx.MenuBar() + self.menuBar.Append(connectMenu,"&General") + self.menuBar.Append(contactMenu,"&Contacts") + self.menuBar.Append(communicationMenu,"&Communication") + self.SetMenuBar(self.menuBar) #events wx.EVT_MENU(self, idCONNECT, self.onConnectRequest) @@ -448,10 +472,10 @@ self.chat_wins[jid.short].Show() def onConnectRequest(self, e): - self.bridge.connect() + self.bridge.connect(self.profile) def onDisconnectRequest(self, e): - self.bridge.disconnect() + self.bridge.disconnect(self.profile) def __updateStatus(self): show = filter(lambda x:x[1] == self.statusBox.GetValue(), const_STATUS)[0][0] diff -r 0e50dd3a234a -r 9b842086d915 frontends/wix/profile_manager.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frontends/wix/profile_manager.py Thu Feb 25 17:09:18 2010 +1100 @@ -0,0 +1,150 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +""" +wix: a SAT frontend +Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" + + + +import wx +import pdb +from logging import debug, info, error +from tools.jid import JID +import pdb + + +class ProfileManager(wx.Panel): + def __init__(self, host): + super(ProfileManager, self).__init__(host) + self.host = host + + #self.sizer = wx.FlexGridSizer(cols=2) + self.sizer = wx.BoxSizer(wx.VERTICAL) + self.SetSizer(self.sizer) + + profiles = self.host.bridge.getProfilesList() + self.profile_name = wx.ComboBox(self, -1, style=wx.CB_READONLY|wx.CB_SORT) + self.__refillProfiles() + self.Bind(wx.EVT_COMBOBOX, self.onProfileChange) + self.panel_id = wx + + self.sizer.Add(wx.Window(self, -1), 1) + self.sizer.Add(wx.StaticText(self, -1, "Profile:"), 0, flag=wx.ALIGN_CENTER) + self.sizer.Add(self.profile_name, 0, flag=wx.ALIGN_CENTER) + button_panel = wx.Panel(self) + button_panel.sizer = wx.BoxSizer(wx.HORIZONTAL) + button_panel.SetSizer(button_panel.sizer) + button_new = wx.Button(button_panel, -1, "New") + button_del = wx.Button(button_panel, -1, "Delete") + button_panel.sizer.Add(button_new) + button_panel.sizer.Add(button_del) + self.sizer.Add(button_panel, flag=wx.CENTER) + self.Bind(wx.EVT_BUTTON, self.onNewProfile, button_new) + self.Bind(wx.EVT_BUTTON, self.onDeleteProfile, button_del) + + login_box = wx.StaticBox(self, -1, "Login") + self.login_sizer = wx.StaticBoxSizer(login_box, wx.VERTICAL) + self.sizer.Add(self.login_sizer, 1, wx.EXPAND | wx.ALL) + self.login_jid = wx.TextCtrl(self, -1) + self.login_sizer.Add(wx.StaticText(self, -1, "JID:"), 0, flag=wx.ALIGN_CENTER) + self.login_sizer.Add(self.login_jid, flag=wx.EXPAND) + self.login_pass = wx.TextCtrl(self, -1, style = wx.TE_PASSWORD) + self.login_sizer.Add(wx.StaticText(self, -1, "Password:"), 0, flag=wx.ALIGN_CENTER) + self.login_sizer.Add(self.login_pass, flag=wx.EXPAND) + + loggin_button = wx.Button(self, -1, "Connect") + self.Bind(wx.EVT_BUTTON, self.onConnectButton, loggin_button) + self.login_sizer.Add(loggin_button, flag=wx.ALIGN_CENTER) + + self.sizer.Add(wx.Window(self, -1), 1) + + #Now we can set the default value + self.__setDefault() + + + def __setDefault(self): + profile_default = self.host.bridge.getProfileName("@DEFAULT@") + if profile_default: + self.profile_name.SetValue(profile_default) + self.onProfileChange(None) + + def __refillProfiles(self): + """Update profiles with current names. Must be called after a profile change""" + self.profile_name.Clear() + profiles = self.host.bridge.getProfilesList() + profiles.sort() + for profile in profiles: + self.profile_name.Append(profile) + + + def onNewProfile(self, event): + dlg = wx.TextEntryDialog(self, "Please enter the new profile name", "New profile", style = wx.OK | wx.CANCEL) + if dlg.ShowModal() == wx.ID_OK: + name = dlg.GetValue() + if name: + if name[0]=='@': + wx.MessageDialog(self, "A profile name can't start with a @", "Bad profile name", wx.ICON_ERROR).ShowModal() + else: + profile = self.host.bridge.createProfile(name) + self.__refillProfiles() + self.profile_name.SetValue(name) + dlg.Destroy() + + def onDeleteProfile(self, event): + name = self.profile_name.GetValue() + if not name: + return + dlg = wx.MessageDialog(self, "Are you sure to delete the profile [%s]" % name, "Confirmation", wx.ICON_QUESTION | wx.YES_NO) + if dlg.ShowModal() == wx.ID_YES: + self.host.bridge.deleteProfile(name) + self.__refillProfiles() + self.__setDefault() + dlg.Destroy() + + def onProfileChange(self, event): + """Called when a profile is choosen in the combo box""" + jabberID = self.host.bridge.getParamA("JabberID", "Connection", profile_key=self.profile_name.GetValue()) + password = self.host.bridge.getParamA("Password", "Connection", profile_key=self.profile_name.GetValue()) + self.login_jid.SetValue(jabberID) + self.login_pass.SetValue(password) + + def onConnectButton(self, event): + """Called when the Connect button is pressed""" + name = self.profile_name.GetValue() + if not name: + wx.MessageDialog(self, "You must select a profile a create a new one before connecting", "No profile selected", wx.ICON_ERROR).ShowModal() + return + if name[0]=='@': + wx.MessageDialog(self, "A profile name can't start with a @", "Bad profile name", wx.ICON_ERROR).ShowModal() + return + profile = None # gof + profile = self.host.bridge.getProfileName(name) + if not profile: + debug("The profile is new, we create it") + old_jid = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile) + old_pass = self.host.bridge.getParamA("Password", "Connection", profile_key=profile) + new_jid = self.login_jid.GetValue() + new_pass = self.login_pass.GetValue() + if old_jid != new_jid: + debug('Saving new JID') + self.host.bridge.setParam("JabberID", new_jid, "Connection", profile) + if old_pass != new_pass: + debug('Saving new password') + self.host.bridge.setParam("JabberID", new_pass, "Connection", profile) + self.host.plug_profile(name) + diff -r 0e50dd3a234a -r 9b842086d915 sat.tac --- a/sat.tac Thu Feb 04 01:06:36 2010 +1100 +++ b/sat.tac Thu Feb 25 17:09:18 2010 +1100 @@ -330,6 +330,7 @@ self.bridge.register("getProfileName", self.memory.getProfileName) self.bridge.register("getProfilesList", self.memory.getProfilesList) self.bridge.register("createProfile", self.memory.createProfile) + self.bridge.register("deleteProfile", self.memory.deleteProfile) self.bridge.register("registerNewAccount", self.registerNewAccount) self.bridge.register("connect", self.connect) self.bridge.register("disconnect", self.disconnect) diff -r 0e50dd3a234a -r 9b842086d915 sat_bridge/DBus.py --- a/sat_bridge/DBus.py Thu Feb 04 01:06:36 2010 +1100 +++ b/sat_bridge/DBus.py Thu Feb 25 17:09:18 2010 +1100 @@ -117,10 +117,16 @@ return self.cb["getProfilesList"]() @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, - in_signature='s', out_signature='') + in_signature='s', out_signature='i') def createProfile(self, name): info ('Profile creation asked') - return self.cb["createProfile"](name, default) + return self.cb["createProfile"](str(name)) + + @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, + in_signature='s', out_signature='i') + def deleteProfile(self, name): + info ('Profile deletion asked') + return self.cb["deleteProfile"](str(name)) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, in_signature='sssi', out_signature='s') diff -r 0e50dd3a234a -r 9b842086d915 tools/memory.py --- a/tools/memory.py Thu Feb 04 01:06:36 2010 +1100 +++ b/tools/memory.py Thu Feb 25 17:09:18 2010 +1100 @@ -119,14 +119,22 @@ def createProfile(self, name): """Create a new profile - @param name: Name of the profile - @param default: True if default value""" + @param name: Name of the profile""" if self.params.has_key(name): info ('The profile name already exists') return 1 self.params[name]={} return 0 + def deleteProfile(self, name): + """Delete an existing profile + @param name: Name of the profile""" + if not self.params.has_key(name): + error ('Trying to delete an unknown profile') + return 1 + del self.params[name] + return 0 + def getProfileName(self, profile_key): """return profile according to profile_key @param profile_key: profile name or key which can be @@ -136,10 +144,14 @@ if profile_key=='@DEFAULT@': if not self.params: return "" - info('No default profile, returning first one') #TODO: manage real default profile - return self.params.keys()[0] #FIXME: gof: temporary, must use real default value, and fallback to first one if it doesn't exists + default = self.host.memory.getPrivate('Profile_default') + if not default or not default in self.params: + info('No default profile, returning first one') #TODO: manage real default profile + default = self.params.keys()[0] + self.host.memory.setPrivate('Profile_default', default) + return default #FIXME: gof: temporary, must use real default value, and fallback to first one if it doesn't exists if not self.params.has_key(profile_key): - error ('Trying to access an unknown profile') + info ('Trying to access an unknown profile') return "" return profile_key @@ -451,12 +463,16 @@ @return: profile name or None if it doesn't exist""" return self.params.getProfileName(profile_key) - def createProfile(self, name, default=False): + def createProfile(self, name): """Create a new profile @param name: Profile name - @param default: True if default profile (replace previous default) """ - return self.params.createProfile(name, default) + return self.params.createProfile(name) + + def deleteProfile(self, name): + """Delete an existing profile + @param name: Name of the profile""" + return self.params.deleteProfile(name) def addToHistory(self, me_jid, from_jid, to_jid, type, message): me_short=me_jid.userhost()