Added translation using Weblate (Japanese)
[cygwin-setup.git] / confirm.cc
blob55ab1c13941e385644e54467d1bd0c3b35df4f02
1 /*
2 * Copyright (c) 2018
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
14 #include "confirm.h"
15 #include "threebar.h"
16 #include "resource.h"
17 #include "state.h"
18 #include "ControlAdjuster.h"
19 #include "package_db.h"
20 #include "package_meta.h"
22 #include <algorithm>
24 extern ThreeBarProgressPage Progress;
26 // Sizing information.
27 static ControlAdjuster::ControlInfo ConfirmControlsInfo[] = {
28 {IDC_CONFIRM_EDIT, CP_STRETCH, CP_STRETCH},
29 {0, CP_LEFT, CP_TOP}
32 // ---------------------------------------------------------------------------
33 // implements class ConfirmPage
34 // ---------------------------------------------------------------------------
36 ConfirmPage::ConfirmPage ()
38 sizeProcessor.AddControlInfo (ConfirmControlsInfo);
41 bool
42 ConfirmPage::Create ()
44 return PropertyPage::Create (IDD_CONFIRM);
47 void
48 ConfirmPage::OnInit ()
50 // set the edit-area to a larger font
51 SetDlgItemFont(IDC_CONFIRM_EDIT, "MS Shell Dlg", 10);
54 void
55 ConfirmPage::OnActivate()
57 // generate a report on actions we're going to take
58 std::wstring s = L"";
60 packagedb db;
61 const SolverTransactionList & trans = db.solution.transactions ();
63 // first list things we will erase
64 if (source != IDC_SOURCE_DOWNLOAD)
66 std::vector<std::wstring> erase;
67 for (SolverTransactionList::const_iterator i = trans.begin ();
68 i != trans.end (); i++)
70 if (i->type == SolverTransaction::transErase)
72 packageversion pv = i->version;
73 packagemeta *pkg = db.findBinary (PackageSpecification (pv.Name ()));
75 std::wstring action = LoadStringW(IDS_CONFIRM_UNINSTALL);
76 std::wstring line = format(L"%ls %s %s", action.c_str(),
77 i->version.Name().c_str(),
78 i->version.Canonical_version().c_str());
79 if (pkg && pkg->desired)
81 line += L" ";
82 line += LoadStringW(IDS_CONFIRM_AUTO_ADD);
84 line += L"\r\n";
85 erase.push_back (line);
88 sort (erase.begin(), erase.end());
89 for (std::vector<std::wstring>::const_iterator i = erase.begin ();
90 i != erase.end(); i++)
91 s += *i;
94 // then list things downloaded or installed
95 std::vector<std::wstring> install;
96 for (SolverTransactionList::const_iterator i = trans.begin ();
97 i != trans.end (); i++)
99 packageversion pv = i->version;
100 packagemeta *pkg = db.findBinary (PackageSpecification (pv.Name ()));
102 if (i->type == SolverTransaction::transInstall)
104 std::wstring action;
105 if (source != IDC_SOURCE_DOWNLOAD)
106 action = LoadStringW(IDS_CONFIRM_INSTALL);
107 else
108 action = LoadStringW(IDS_CONFIRM_DOWNLOAD);
110 std::wstring line = format(L"%ls %s %s", action.c_str(),
111 i->version.Name().c_str(),
112 i->version.Canonical_version().c_str());
114 if (i->version.Type() == package_source)
116 line += L" ";
117 line += LoadStringW(IDS_CONFIRM_SOURCE);
119 else if (pkg && pkg->desired != pv)
121 line += L" ";
122 line += LoadStringW(IDS_CONFIRM_AUTO_ADD);
124 line += L"\r\n";
125 install.push_back (line);
128 sort (install.begin(), install.end());
129 for (std::vector<std::wstring>::const_iterator i = install.begin ();
130 i != install.end(); i++)
131 s += *i;
133 // be explicit about doing nothing
134 if (s.empty())
135 s += LoadStringW(IDS_CONFIRM_NOTHING);
137 SetDlgItemTextW (GetHWND (), IDC_CONFIRM_EDIT, s.c_str ());
139 // move focus to 'next' button, so enter doesn't get eaten by edit control
140 HWND nextButton = ::GetDlgItem(::GetParent(GetHWND()), 0x3024 /* ID_WIZNEXT */);
141 PostMessage (GetHWND (), WM_NEXTDLGCTL, (WPARAM)nextButton, TRUE);
144 long
145 ConfirmPage::OnNext ()
147 return whatNext();
150 long
151 ConfirmPage::whatNext ()
153 if (source == IDC_SOURCE_LOCALDIR)
155 // Next, install
156 Progress.SetActivateTask (WM_APP_START_INSTALL);
158 else
160 // Next, start download from internet
161 Progress.SetActivateTask (WM_APP_START_DOWNLOAD);
163 return IDD_INSTATUS;
166 long
167 ConfirmPage::OnBack ()
169 return IDD_CHOOSE;
172 long
173 ConfirmPage::OnUnattended ()
175 return whatNext();