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 }
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.disconnect:
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 : } else {
44 0 : Provider.of<FlwtchState>(
45 : context,
46 : listen: false,
47 0 : ).cwtch.DisconnectFromPeer(Provider.of<ProfileInfoState>(context, listen: false).onion, Provider.of<ContactInfoState>(context, listen: false).onion);
48 : }
49 : // reset the disconnect button to allow for immediate connection...
50 0 : Provider.of<ContactInfoState>(context, listen: false).lastRetryTime = DateTime.now().subtract(Duration(minutes: 2));
51 0 : Provider.of<ContactInfoState>(context, listen: false).contactEvents.add(ContactEvent("Disconnect from Peer"));
52 : break;
53 0 : case ConversationOptionsMenu.manage_shares:
54 0 : widget.ManageFiles();
55 : break;
56 0 : case ConversationOptionsMenu.membership:
57 0 : widget.Membership();
58 : break;
59 0 : case ConversationOptionsMenu.edit_group:
60 0 : widget.EditGroup();
61 : break;
62 : }
63 : },
64 0 : itemBuilder: (context) {
65 0 : var items = <PopupMenuEntry<ConversationOptionsMenu>>[
66 0 : PopupMenuItem<ConversationOptionsMenu>(
67 : value: ConversationOptionsMenu.settings,
68 : enabled: true,
69 0 : child: Row(
70 0 : children: [
71 0 : Icon(CwtchIcons.account_circle_24px),
72 0 : Expanded(
73 0 : child: Text(AppLocalizations.of(context)!.conversationSettings, textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
74 : ),
75 : ],
76 : ),
77 : ),
78 0 : PopupMenuItem<ConversationOptionsMenu>(
79 : value: ConversationOptionsMenu.disconnect,
80 0 : enabled: Provider.of<ContactInfoState>(context, listen: false).isOnline(),
81 0 : child: Tooltip(
82 0 : message: AppLocalizations.of(context)!.contactDisconnect,
83 0 : child: Row(
84 0 : children: [
85 0 : Icon(CwtchIcons.disconnect_from_contact),
86 0 : Expanded(
87 0 : child: Text(
88 0 : AppLocalizations.of(context)!.contactDisconnectSummary,
89 : textAlign: TextAlign.right,
90 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
91 : ),
92 : ),
93 : ],
94 : ),
95 : ),
96 : ),
97 : ];
98 0 : if (Provider.of<ContactInfoState>(context, listen: false).isManaged) {
99 0 : items.add(
100 0 : PopupMenuItem<ConversationOptionsMenu>(
101 : value: ConversationOptionsMenu.membership,
102 : enabled: true,
103 0 : child: Row(
104 0 : children: [
105 0 : Icon(CwtchIcons.create_group),
106 0 : Expanded(
107 0 : child: Text(AppLocalizations.of(context)!.editMembershipTitle, textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
108 : ),
109 : ],
110 : ),
111 : ),
112 : );
113 0 : items.add(
114 0 : PopupMenuItem<ConversationOptionsMenu>(
115 : value: ConversationOptionsMenu.edit_group,
116 : enabled: true,
117 0 : child: Row(
118 0 : children: [
119 0 : Icon(CwtchIcons.anti_spam_1),
120 0 : Expanded(
121 0 : child: Text(AppLocalizations.of(context)!.editGroupTitle, textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
122 : ),
123 : ],
124 : ),
125 : ),
126 : );
127 : }
128 : return items;
129 : },
130 : );
131 : }
132 : }
|