public static Account ShowAccountSelectMenu(QWidget attachWidget) { AccountService accountService = ServiceManager.Get <AccountService>(); if (accountService.ConnectedAccounts.Count == 0) { var widget = (attachWidget != null) ? attachWidget.TopLevelWidget() : Gui.MainWindow; QMessageBox.Critical(widget, "Synapse", "You are not connected."); return(null); } Account selectedAccount = null; if (accountService.ConnectedAccounts.Count > 1) { QMenu menu = new QMenu(); menu.AddAction("Select Account:").SetDisabled(true); foreach (Account account in accountService.ConnectedAccounts) { QAction action = menu.AddAction(account.Jid.ToString()); if (menu.ActiveAction() == null) { menu.SetActiveAction(action); } } var pos = (attachWidget != null) ? attachWidget.MapToGlobal(new QPoint(0, attachWidget.Height())) : QCursor.Pos(); QAction selectedAction = menu.Exec(pos); if (selectedAction != null) { selectedAccount = accountService.GetAccount(new jabber.JID(selectedAction.Text)); } } else { selectedAccount = accountService.ConnectedAccounts[0]; } return(selectedAccount); }