diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 37518dc7..bf4acbb1 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -116,6 +116,7 @@ class Controller(object): # connect application events to GUI widgetUtils.connect_event(self.view, widgetUtils.CLOSE_EVENT, self.exit_) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.show_hide, menuitem=self.view.show_hide) + widgetUtils.connect_event(self.view, widgetUtils.MENU, self.update_profile, menuitem=self.view.updateProfile) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.search, menuitem=self.view.menuitem_search) # widgetUtils.connect_event(self.view, widgetUtils.MENU, self.list_manager, menuitem=self.view.lists) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.find, menuitem=self.view.find) @@ -1085,3 +1086,11 @@ class Controller(object): """Redirects the user to the issue page on github""" log.debug("Redirecting the user to report an error...") webbrowser.open_new_tab(application.report_bugs_url) + + def update_profile(self, *args): + """Updates the users profile""" + log.debug("Update profile") + buffer = self.get_best_buffer() + handler = self.get_handler(buffer.session.type) + if handler: + handler.update_profile(buffer.session) diff --git a/src/controller/mastodon/handler.py b/src/controller/mastodon/handler.py index 4a836f48..b4742448 100644 --- a/src/controller/mastodon/handler.py +++ b/src/controller/mastodon/handler.py @@ -4,10 +4,13 @@ import logging import output from pubsub import pub from mysc import restart +from mysc.thread_utils import call_threaded from wxUI.dialogs.mastodon import search as search_dialogs from wxUI.dialogs.mastodon import dialogs from wxUI.dialogs import userAliasDialogs from wxUI import commonMessageDialogs +from wxUI.dialogs.mastodon import updateProfile as update_profile_dialogs +from sessions.mastodon.utils import html_filter from . import userActions, settings log = logging.getLogger("controller.mastodon.handler") @@ -20,7 +23,7 @@ class Handler(object): # empty names mean the item will be Disabled. self.menus = dict( # In application menu. - updateProfile=None, + updateProfile=_("Update Profile"), menuitem_search=_("&Search"), lists=None, manageAliases=_("Manage user aliases"), @@ -254,4 +257,21 @@ class Handler(object): buffer.session.settings["user-aliases"][str(full_user.id)] = alias buffer.session.settings.write() output.speak(_("Alias has been set correctly for {}.").format(user)) - pub.sendMessage("alias-added") \ No newline at end of file + pub.sendMessage("alias-added") + + def update_profile(self, session): + """Updates the users dialog""" + profile = session.api.me() + data = { + 'display_name': profile.display_name, + 'note': html_filter(profile.note), + } + dialog = update_profile_dialogs.UpdateProfileDialog(**data) + if dialog.ShowModal() != wx.ID_OK: return + updated_data = dialog.data + # remove data that hasn't been updated + for key in data: + if data[key] == updated_data[key]: + del updated_data[key] + log.debug(f"Updating users profile with: {updated_data}") + call_threaded(session.api_call, "account_update_credentials", _("Update profile"), report_success=True, **updated_data) diff --git a/src/wxUI/dialogs/mastodon/updateProfile.py b/src/wxUI/dialogs/mastodon/updateProfile.py new file mode 100644 index 00000000..2e8f4426 --- /dev/null +++ b/src/wxUI/dialogs/mastodon/updateProfile.py @@ -0,0 +1,57 @@ +import wx + + +class UpdateProfileDialog(wx.Dialog): + """ + A dialog for user to update his / her profile details. + layout is: + ``` + header + avatar + name + bio + meta data + ``` + """ + + def __init__(self, display_name: str="", note: str=""): + """Initialize update profile dialog + Parameters: + - display_name: The user's display name to show in the display name field + - note: The users bio to show in the bio field + """ + super().__init__(parent=None) + self.SetTitle(_("Update Profile")) + panel = wx.Panel(self) + sizer = wx.BoxSizer(wx.VERTICAL) + + # create widgets + display_name_label = wx.StaticText(panel, label=_("Display Name")) + self.display_name = wx.TextCtrl(panel, value=display_name, style= + wx.TE_PROCESS_ENTER) + bio_label = wx.StaticText(panel, label=_("Bio")) + self.bio = wx.TextCtrl(panel, value=note, style=wx.TE_PROCESS_ENTER) + ok = wx.Button(panel, wx.ID_OK, _(u"&OK")) + ok.SetDefault() + cancel = wx.Button(panel, wx.ID_CANCEL, _("&Close")) + self.SetEscapeId(cancel.GetId()) + + # manage sizers + sizer.Add(display_name_label, wx.SizerFlags().Center()) + sizer.Add(self.display_name, wx.SizerFlags().Center()) + sizer.Add(cancel, wx.SizerFlags().Center()) + sizer.Add(ok, wx.SizerFlags().Center()) + sizer.Add(self.bio, wx.SizerFlags().Center()) + panel.SetSizer(sizer) + panel.Fit() + + # manage events + ok.Bind(wx.EVT_BUTTON, self.on_ok) + + def on_ok(self, *args): + """Method called when user clicks ok in dialog""" + self.data = { + 'display_name': self.display_name.GetValue(), + 'note': self.bio.GetValue() + } + self.EndModal(wx.ID_OK) diff --git a/src/wxUI/view.py b/src/wxUI/view.py index 08bb9079..c3e37a2a 100644 --- a/src/wxUI/view.py +++ b/src/wxUI/view.py @@ -15,7 +15,6 @@ class mainFrame(wx.Frame): self.menubar_application = wx.Menu() self.manage_accounts = self.menubar_application.Append(wx.ID_ANY, _(u"&Manage accounts")) self.updateProfile = self.menubar_application.Append(wx.ID_ANY, _("&Update profile")) - self.updateProfile.Enable(False) self.show_hide = self.menubar_application.Append(wx.ID_ANY, _(u"&Hide window")) self.menuitem_search = self.menubar_application.Append(wx.ID_ANY, _(u"&Search")) self.lists = self.menubar_application.Append(wx.ID_ANY, _(u"&Lists manager"))