File: SyncFailedDialog.cpp

package info (click to toggle)
audacity 3.7.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 125,252 kB
  • sloc: cpp: 358,238; ansic: 75,458; lisp: 7,761; sh: 3,410; python: 1,503; xml: 1,385; perl: 854; makefile: 122
file content (143 lines) | stat: -rw-r--r-- 4,191 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*  SPDX-License-Identifier: GPL-2.0-or-later */
/*!********************************************************************

  Audacity: A Digital Audio Editor

  SyncFailedDialog.cpp

  Dmitry Vedenko

**********************************************************************/
#include "SyncFailedDialog.h"

#include "CodeConversions.h"

namespace audacity::cloud::audiocom::sync
{
namespace
{
const auto MessageAuthorizationFailed =
   XO("You are not authorized to access this project.");
const auto MessageExpired =
   XO("You tried to access a project that has expired.");
const auto MessageConnectionFailed =
   XO("Audacity had trouble connecting to the server.");
const auto MessageTooLarge = XO(
   "The project is too large to upload. Please save it to your computer instead.");
const auto MessageForbidden = XO("You don't have access to this project.");
const auto MessageNotFound  = XO("The project could not be found.");
const auto MessageUnexpectedResponse =
   XO("The server responded with something Audacity could not understand.");
const auto MessageInternalClientError =
   XO("Audacity encountered an internal error.");
const auto MessageInternalServerError =
   XO("Audio.com encountered an internal error.");
const auto MessageUnknownError = XO("Audacity encountered an unknown error.");

TranslatableString GetMessage(const CloudSyncError& error)
{
   switch (error.Type)
   {
   case CloudSyncError::Authorization:
      return MessageAuthorizationFailed;
   case CloudSyncError::Network:
      return MessageConnectionFailed;
   case CloudSyncError::Server:
      return MessageInternalServerError;
   case CloudSyncError::ClientFailure:
      return MessageInternalClientError;
   default:
      return MessageUnknownError;
   }
}

TranslatableString GetMessage(const ResponseResult& error)
{
   switch (error.Code)
   {
   case SyncResultCode::Unauthorized:
      return MessageAuthorizationFailed;
   case SyncResultCode::Expired:
      return MessageExpired;
   case SyncResultCode::ConnectionFailed:
      return MessageConnectionFailed;
   case SyncResultCode::TooLarge:
      return MessageTooLarge;
   case SyncResultCode::Forbidden:
      return MessageForbidden;
   case SyncResultCode::NotFound:
      return MessageNotFound;
   case SyncResultCode::UnexpectedResponse:
      return MessageUnexpectedResponse;
   case SyncResultCode::InternalServerError:
      return MessageInternalServerError;
   default:
      return MessageUnknownError;
   }
}
} // namespace

void SyncFailedDialog::OnOpen(const CloudSyncError& error)
{
   if (error.Type == CloudSyncError::None)
      return;

   auto message = GetMessage(error);

   SyncFailedDialog dialog { nullptr, message, error.ErrorMessage,
                             DialogMode::Opening };
   dialog.ShowDialog();
}

void SyncFailedDialog::OnSave(const CloudSyncError& error)
{
   if (error.Type == CloudSyncError::None)
      return;

   auto message = GetMessage(error);

   SyncFailedDialog dialog { nullptr, message, error.ErrorMessage,
                             DialogMode::Saving };
   dialog.ShowDialog();
}

void SyncFailedDialog::OnOpen(const ResponseResult& error)
{
   if (error.Code == SyncResultCode::Success)
      return;

   auto message = GetMessage(error);

   SyncFailedDialog dialog { nullptr, message, error.Content,
                             DialogMode::Opening };
   dialog.ShowDialog();
}

void SyncFailedDialog::OnSave(const ResponseResult& error)
{
   if (error.Code == SyncResultCode::Success)
      return;

   auto message = GetMessage(error);

   SyncFailedDialog dialog { nullptr, message, error.Content,
                             DialogMode::Saving };
   dialog.ShowDialog();
}

SyncFailedDialog::SyncFailedDialog(
   const AudacityProject* project, const TranslatableString& message,
   const std::string& log, DialogMode dialogMode)
    : AudioComDialogBase { project, {}, dialogMode }
{
   AddTitle(XO("Sync failed"));

   AddParagraph(message);

   if (!log.empty())
      AddParagraph(XO("Error details:\n%s").Format(ToWXString(log)));

   AddButton(CancelButtonIdentifier(), XO("OK"), DefaultButton | EscButton);
}

} // namespace audacity::cloud::audiocom::sync