NCLoginWeb+Menu.swift 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // NCLoginWeb+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 03/03/2021.
  6. // Copyright © 2021 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import UIKit
  24. import FloatingPanel
  25. extension NCLoginWeb {
  26. func toggleMenu() {
  27. var actions = [NCMenuAction]()
  28. let accounts = NCManageDatabase.shared.getAllAccount()
  29. var avatar = NCUtility.shared.loadImage(named: "person.crop.circle")
  30. for account in accounts {
  31. let title = account.user + " " + (URL(string: account.urlBase)?.host ?? "")
  32. avatar = NCUtility.shared.loadUserImage(for: account.user, displayName: account.displayName, urlBase: account.urlBase)
  33. actions.append(
  34. NCMenuAction(
  35. title: title,
  36. icon: avatar,
  37. onTitle: title,
  38. onIcon: avatar,
  39. selected: account.active == true,
  40. on: account.active == true,
  41. action: { menuAction in
  42. if self.appDelegate.account != account.account {
  43. NCManageDatabase.shared.setAccountActive(account.account)
  44. self.dismiss(animated: true) {
  45. self.appDelegate.settingAccount(account.account, urlBase: account.urlBase, user: account.user, userId: account.userId, password: CCUtility.getPassword(account.account))
  46. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize)
  47. }
  48. }
  49. }
  50. )
  51. )
  52. }
  53. actions.append(
  54. NCMenuAction(
  55. title: NSLocalizedString("_delete_active_account_", comment: ""),
  56. icon: NCUtility.shared.loadImage(named: "trash", color: NCBrandColor.shared.gray),
  57. onTitle: NSLocalizedString("_delete_active_account_", comment: ""),
  58. onIcon: avatar,
  59. selected: false,
  60. on: false,
  61. action: { menuAction in
  62. self.appDelegate.deleteAccount(self.appDelegate.account, wipe: false)
  63. self.dismiss(animated: true) {
  64. let accounts = NCManageDatabase.shared.getAllAccount()
  65. if accounts.count > 0 {
  66. self.appDelegate.changeAccount(accounts.first!.account)
  67. } else {
  68. self.appDelegate.openLogin(viewController: nil, selector: NCGlobal.shared.introLogin, openLoginWeb: false)
  69. }
  70. }
  71. }
  72. )
  73. )
  74. presentMenu(with: actions)
  75. }
  76. }