Line data Source code
1 : import 'package:cwtch/cwtch_icons_icons.dart';
2 : import 'package:cwtch/main.dart';
3 : import 'package:cwtch/models/contact.dart';
4 : import 'package:cwtch/models/profile.dart';
5 : import 'package:cwtch/settings.dart';
6 : import 'package:cwtch/themes/opaque.dart';
7 : import 'package:flutter/material.dart';
8 : import 'package:cwtch/l10n/app_localizations.dart';
9 : import 'package:provider/provider.dart';
10 :
11 : enum ConversationOptionsMenu { settings, disconnect, manage_shares, membership, edit_group, rebuildConnection }
12 :
13 : class ConversationOptions extends StatefulWidget {
14 : final void Function() SelectSettings;
15 : final void Function() ManageFiles;
16 : final void Function() Membership;
17 : final void Function() EditGroup;
18 :
19 0 : ConversationOptions(this.SelectSettings, this.ManageFiles, this.Membership, this.EditGroup);
20 0 : @override
21 0 : _ConversationOptionsState createState() => _ConversationOptionsState();
22 : }
23 :
24 : class _ConversationOptionsState extends State<ConversationOptions> {
25 0 : @override
26 : Widget build(BuildContext context) {
27 0 : return PopupMenuButton<ConversationOptionsMenu>(
28 0 : icon: Provider.of<ContactInfoState>(context, listen: false).isGroup == true ? Icon(CwtchIcons.group_settings_24px) : Icon(CwtchIcons.peer_settings_24px),
29 : iconSize: 24,
30 0 : tooltip: AppLocalizations.of(context)!.conversationSettings,
31 0 : splashRadius: Material.defaultSplashRadius / 2,
32 0 : onSelected: (ConversationOptionsMenu item) {
33 : switch (item) {
34 0 : case ConversationOptionsMenu.settings:
35 0 : widget.SelectSettings();
36 : break;
37 0 : case ConversationOptionsMenu.rebuildConnection:
38 0 : if (Provider.of<ContactInfoState>(context, listen: false).isGroup) {
39 0 : Provider.of<FlwtchState>(
40 : context,
41 : listen: false,
42 0 : ).cwtch.DisconnectFromServer(Provider.of<ProfileInfoState>(context, listen: false).onion, Provider.of<ContactInfoState>(context, listen: false).server!);
43 0 : Provider.of<FlwtchState>(
44 : context,
45 : listen: false,
46 0 : ).cwtch.AttemptReconnectionServer(Provider.of<ProfileInfoState>(context, listen: false).onion, Provider.of<ContactInfoState>(context, listen: false).server!);
47 : } else {
48 0 : Provider.of<FlwtchState>(
49 : context,
50 : listen: false,
51 0 : ).cwtch.DisconnectFromPeer(Provider.of<ProfileInfoState>(context, listen: false).onion, Provider.of<ContactInfoState>(context, listen: false).onion);
52 0 : Provider.of<FlwtchState>(
53 : context,
54 : listen: false,
55 0 : ).cwtch.AttemptReconnection(Provider.of<ProfileInfoState>(context, listen: false).onion, Provider.of<ContactInfoState>(context, listen: false).server!);
56 : }
57 :
58 0 : Provider.of<ContactInfoState>(context, listen: false).lastRetryTime = DateTime.now();
59 0 : Provider.of<ContactInfoState>(context, listen: false).contactEvents.add(ContactEvent("Actively Retried Connection"));
60 0 : setState(() {
61 : // force update of this view...otherwise the button won't be removed fast enough...
62 : });
63 :
64 : break;
65 0 : case ConversationOptionsMenu.disconnect:
66 0 : if (Provider.of<ContactInfoState>(context, listen: false).isGroup) {
67 0 : Provider.of<FlwtchState>(
68 : context,
69 : listen: false,
70 0 : ).cwtch.DisconnectFromServer(Provider.of<ProfileInfoState>(context, listen: false).onion, Provider.of<ContactInfoState>(context, listen: false).server!);
71 : } else {
72 0 : Provider.of<FlwtchState>(
73 : context,
74 : listen: false,
75 0 : ).cwtch.DisconnectFromPeer(Provider.of<ProfileInfoState>(context, listen: false).onion, Provider.of<ContactInfoState>(context, listen: false).onion);
76 : }
77 : // reset the disconnect button to allow for immediate connection...
78 0 : Provider.of<ContactInfoState>(context, listen: false).lastRetryTime = DateTime.now().subtract(Duration(minutes: 2));
79 0 : Provider.of<ContactInfoState>(context, listen: false).contactEvents.add(ContactEvent("Disconnect from Peer"));
80 : break;
81 0 : case ConversationOptionsMenu.manage_shares:
82 0 : widget.ManageFiles();
83 : break;
84 0 : case ConversationOptionsMenu.membership:
85 0 : widget.Membership();
86 : break;
87 0 : case ConversationOptionsMenu.edit_group:
88 0 : widget.EditGroup();
89 : break;
90 : }
91 : },
92 0 : itemBuilder: (context) {
93 0 : var items = <PopupMenuEntry<ConversationOptionsMenu>>[
94 0 : PopupMenuItem<ConversationOptionsMenu>(
95 : value: ConversationOptionsMenu.settings,
96 : enabled: true,
97 0 : child: Row(
98 0 : children: [
99 0 : Icon(CwtchIcons.account_circle_24px),
100 0 : Expanded(
101 0 : child: Text(AppLocalizations.of(context)!.conversationSettings, textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
102 : ),
103 : ],
104 : ),
105 : ),
106 0 : PopupMenuItem<ConversationOptionsMenu>(
107 : value: ConversationOptionsMenu.rebuildConnection,
108 0 : enabled: Provider.of<ContactInfoState>(context, listen: false).isOnline(),
109 0 : child: Tooltip(
110 0 : message: AppLocalizations.of(context)!.restartConnection,
111 0 : child: Row(
112 0 : children: [
113 0 : Icon(Icons.cached),
114 0 : Expanded(
115 0 : child: Text(AppLocalizations.of(context)!.restartConnection, textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
116 : ),
117 : ],
118 : ),
119 : ),
120 : ),
121 0 : PopupMenuItem<ConversationOptionsMenu>(
122 : value: ConversationOptionsMenu.disconnect,
123 0 : enabled: Provider.of<ContactInfoState>(context, listen: false).isOnline(),
124 0 : child: Tooltip(
125 0 : message: AppLocalizations.of(context)!.contactDisconnect,
126 0 : child: Row(
127 0 : children: [
128 0 : Icon(CwtchIcons.disconnect_from_contact),
129 0 : Expanded(
130 0 : child: Text(
131 0 : AppLocalizations.of(context)!.contactDisconnectSummary,
132 : textAlign: TextAlign.right,
133 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
134 : ),
135 : ),
136 : ],
137 : ),
138 : ),
139 : ),
140 : ];
141 0 : if (Provider.of<ContactInfoState>(context, listen: false).isManaged) {
142 0 : items.add(
143 0 : PopupMenuItem<ConversationOptionsMenu>(
144 : value: ConversationOptionsMenu.membership,
145 : enabled: true,
146 0 : child: Row(
147 0 : children: [
148 0 : Icon(CwtchIcons.create_group),
149 0 : Expanded(
150 0 : child: Text(AppLocalizations.of(context)!.editMembershipTitle, textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
151 : ),
152 : ],
153 : ),
154 : ),
155 : );
156 0 : items.add(
157 0 : PopupMenuItem<ConversationOptionsMenu>(
158 : value: ConversationOptionsMenu.edit_group,
159 : enabled: true,
160 0 : child: Row(
161 0 : children: [
162 0 : Icon(CwtchIcons.anti_spam_1),
163 0 : Expanded(
164 0 : child: Text(AppLocalizations.of(context)!.editGroupTitle, textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
165 : ),
166 : ],
167 : ),
168 : ),
169 : );
170 : }
171 : return items;
172 : },
173 : );
174 : }
175 : }
|