This repository has been archived by the owner on May 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainPage.cpp
364 lines (294 loc) · 11.1 KB
/
MainPage.cpp
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/*
* PROJECT: Nagisa
* FILE: MainPage.cpp
* PURPOSE: Implementation for the Main Window.
*
* LICENSE: The MIT License
*
* DEVELOPER: Mouri_Naruto (Mouri_Naruto AT Outlook.com)
*/
#include "pch.h"
#include "MainPage.h"
#include "MainPage.h"
#include "AboutDialog.h"
#include "NewTaskDialog.h"
#include "SettingsDialog.h"
using namespace winrt;
using namespace Windows::UI::Xaml;
namespace winrt::Nagisa::implementation
{
MainPage::MainPage() :
m_TransferManager(Assassin::TransferManager(true)),
m_UISettings(UISettings()),
m_CurrentApplication(Application::Current()),
m_ApplicationViewTitleBar(
ApplicationView::GetForCurrentView().TitleBar())
{
InitializeComponent();
}
TransferManager MainPage::TransferManager()
{
return this->m_TransferManager;
}
IAsyncOperation<ContentDialogResult> MainPage::ShowContentDialogAsync(
ContentDialog const& Dialog)
{
double PageActualWidth = this->ActualWidth();
if (Dialog.MaxWidth() > PageActualWidth)
Dialog.MaxWidth(PageActualWidth);
double PageActualHeight = this->ActualHeight();
if (Dialog.MaxHeight() > PageActualHeight)
Dialog.MaxHeight(PageActualHeight);
return Dialog.ShowAsync();
}
ITransferTask MainPage::GetTransferTaskFromEventSender(
IInspectable const& sender)
{
return sender.try_as<Windows::UI::Xaml::FrameworkElement>(
).DataContext().try_as<ITransferTask>();
}
void MainPage::UpdateTitleBarColor()
{
using Windows::UI::Color;
using Windows::UI::Colors;
Color ButtonForegroundColor =
(this->m_CurrentApplication.RequestedTheme()
!= Windows::UI::Xaml::ApplicationTheme::Dark)
? Colors::Black()
: Colors::White();
this->m_ApplicationViewTitleBar.ButtonForegroundColor(
ButtonForegroundColor);
this->m_ApplicationViewTitleBar.ButtonHoverForegroundColor(
ButtonForegroundColor);
this->m_ApplicationViewTitleBar.ButtonPressedForegroundColor(
ButtonForegroundColor);
}
void MainPage::InitializeCustomTitleBar()
{
using Windows::ApplicationModel::Core::CoreApplication;
using Windows::UI::Color;
using Windows::UI::Colors;
using Windows::UI::Xaml::Window;
// Extend main grid to titlebar
CoreApplication::GetCurrentView().TitleBar().ExtendViewIntoTitleBar(
true);
// Color settings.
Color DarkGray = Colors::DarkGray();
Color Transparent = Colors::Transparent();
this->m_ApplicationViewTitleBar.ButtonBackgroundColor(
Transparent);
this->m_ApplicationViewTitleBar.ButtonHoverBackgroundColor(
DarkGray);
this->m_ApplicationViewTitleBar.ButtonInactiveBackgroundColor(
Transparent);
this->m_ApplicationViewTitleBar.ButtonInactiveForegroundColor(
DarkGray);
this->m_ApplicationViewTitleBar.ButtonPressedBackgroundColor(
DarkGray);
this->UpdateTitleBarColor();
this->m_UISettings.ColorValuesChanged(
{ this, &MainPage::ColorValuesChanged });
// Set real titlebar area
Window::Current().SetTitleBar(this->realTitle());
}
void MainPage::ColorValuesChanged(
UISettings const& sender,
IInspectable const& e)
{
UNREFERENCED_PARAMETER(sender); // Unused parameter.
UNREFERENCED_PARAMETER(e); // Unused parameter.
using winrt::Windows::UI::Core::CoreDispatcherPriority;
this->Dispatcher().RunAsync(
CoreDispatcherPriority::Normal,
{ this, &MainPage::UpdateTitleBarColor });
}
void MainPage::Page_Loaded(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(sender); // Unused parameter.
UNREFERENCED_PARAMETER(e); // Unused parameter.
this->InitializeCustomTitleBar();
using Windows::UI::Xaml::Visibility;
this->SearchAutoSuggestBox().Visibility(Visibility::Collapsed);
}
void MainPage::TaskList_ContainerContentChanging(
ListViewBase const& sender,
ContainerContentChangingEventArgs const& e)
{
UNREFERENCED_PARAMETER(sender); // Unused parameter.
UNREFERENCED_PARAMETER(e); // Unused parameter.
this->TaskListNoItemsTextBlock().Visibility(
!sender.ItemsSource()
? Visibility::Visible
: Visibility::Collapsed);
}
fire_and_forget MainPage::AboutButton_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(sender); // Unused parameter.
UNREFERENCED_PARAMETER(e); // Unused parameter.
co_await this->ShowContentDialogAsync(
make<AboutDialog>(this->m_TransferManager));
}
fire_and_forget MainPage::NewTaskButton_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(sender); // Unused parameter.
UNREFERENCED_PARAMETER(e); // Unused parameter.
co_await this->ShowContentDialogAsync(
make<NewTaskDialog>(this->m_TransferManager));
}
void MainPage::CopyLinkMenuItem_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(e); // Unused parameter.
using Windows::ApplicationModel::DataTransfer::Clipboard;
using Windows::ApplicationModel::DataTransfer::DataPackage;
using Windows::Foundation::Uri;
ITransferTask Task = this->GetTransferTaskFromEventSender(sender);
Uri UriObject = Task.SourceUri();
if (UriObject)
{
DataPackage data = DataPackage();
data.SetText(UriObject.RawUri());
Clipboard::SetContent(data);
}
}
void MainPage::SearchAutoSuggestBox_LostFocus(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(sender); // Unused parameter.
UNREFERENCED_PARAMETER(e); // Unused parameter.
using Windows::UI::Xaml::Visibility;
this->SearchAutoSuggestBox().Visibility(Visibility::Collapsed);
this->SearchAppBarButton().Visibility(Visibility::Visible);
}
fire_and_forget MainPage::RetryButton_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(e); // Unused parameter.
ITransferTask Task = this->GetTransferTaskFromEventSender(sender);
auto SourceUri = Task.SourceUri();
auto FileName = Task.FileName();
auto SaveFolder = co_await Task.SaveFolder();
this->m_TransferManager.RemoveTask(Task);
co_await this->m_TransferManager.AddTaskAsync(
SourceUri,
FileName,
SaveFolder);
}
void MainPage::ResumeButton_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(e); // Unused parameter.
this->GetTransferTaskFromEventSender(sender).Resume();
}
void MainPage::PauseButton_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(e); // Unused parameter.
this->GetTransferTaskFromEventSender(sender).Pause();
}
void MainPage::CancelMenuItem_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(e); // Unused parameter.
this->GetTransferTaskFromEventSender(sender).Cancel();
}
void MainPage::RemoveMenuItem_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(e); // Unused parameter.
this->m_TransferManager.RemoveTask(
this->GetTransferTaskFromEventSender(sender));
}
fire_and_forget MainPage::OpenFolderMenuItem_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(e); // Unused parameter.
using Windows::Storage::IStorageFile;
using Windows::Storage::IStorageFolder;
using Windows::System::Launcher;
using Windows::System::FolderLauncherOptions;
ITransferTask Task = this->GetTransferTaskFromEventSender(sender);
IStorageFile FileObject = co_await Task.SaveFile();
IStorageFolder FolderObject = co_await Task.SaveFolder();
if (FileObject && FolderObject)
{
FolderLauncherOptions Options = FolderLauncherOptions();
Options.ItemsToSelect().Append(FileObject);
co_await Launcher::LaunchFolderAsync(FolderObject, Options);
}
}
void MainPage::StartAllAppBarButton_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(sender); // Unused parameter.
UNREFERENCED_PARAMETER(e); // Unused parameter.
this->m_TransferManager.ResumeAllTasks();
}
void MainPage::PauseAllAppBarButton_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(sender); // Unused parameter.
UNREFERENCED_PARAMETER(e); // Unused parameter.
this->m_TransferManager.PauseAllTasks();
}
void MainPage::ClearListAppBarButton_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(sender); // Unused parameter.
UNREFERENCED_PARAMETER(e); // Unused parameter.
this->m_TransferManager.ClearTaskList();
}
void MainPage::SearchAppBarButton_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(sender); // Unused parameter.
UNREFERENCED_PARAMETER(e); // Unused parameter.
using Windows::UI::Xaml::FocusState;
using Windows::UI::Xaml::Visibility;
this->SearchAppBarButton().Visibility(Visibility::Collapsed);
this->SearchAutoSuggestBox().Visibility(Visibility::Visible);
this->SearchAutoSuggestBox().Focus(FocusState::Programmatic);
}
fire_and_forget MainPage::OpenDownloadsFolderAppBarButton_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(sender); // Unused parameter.
UNREFERENCED_PARAMETER(e); // Unused parameter.
using Windows::Storage::IStorageFolder;
using Windows::System::Launcher;
IStorageFolder Folder =
co_await this->m_TransferManager.DefaultFolder();
if (!Folder) Folder =
co_await this->m_TransferManager.LastusedFolder();
if (Folder)
co_await Launcher::LaunchFolderAsync(Folder);
}
fire_and_forget MainPage::SettingsAppBarButton_Click(
IInspectable const& sender,
RoutedEventArgs const& e)
{
UNREFERENCED_PARAMETER(sender); // Unused parameter.
UNREFERENCED_PARAMETER(e); // Unused parameter.
co_await this->ShowContentDialogAsync(
winrt::make<SettingsDialog>(this->m_TransferManager));
}
}