]>
Commit | Line | Data |
---|---|---|
0f0a6b63 MB |
1 | /* |
2 | * Copyright (c) 2000, 2001 Red Hat, Inc. | |
3 | * Copyright (c) 2003 Robert Collins <rbtcollins@hotmail.com> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * A copy of the GNU General Public License can be found at | |
11 | * http://www.gnu.org/ | |
12 | * | |
13 | * Written by DJ Delorie <dj@cygnus.com> | |
14 | * | |
15 | */ | |
16 | ||
17 | /* The purpose of this file is to let the user choose which packages | |
18 | to install, and which versions of the package when more than one | |
19 | version is provided. The "trust" level serves as an indication as | |
20 | to which version should be the default choice. At the moment, all | |
21 | we do is compare with previously installed packages to skip any | |
22 | that are already installed (by setting the action to ACTION_SAME). | |
23 | While the "trust" stuff is supported, it's not really implemented | |
24 | yet. We always prefer the "current" option. In the future, this | |
25 | file might have a user dialog added to let the user choose to not | |
26 | install packages, or to install packages that aren't installed by | |
27 | default. */ | |
28 | ||
29 | #if 0 | |
30 | static const char *cvsid = | |
31 | "\n%%% $Id$\n"; | |
32 | #endif | |
33 | ||
34 | #include "win32.h" | |
35 | #include <commctrl.h> | |
36 | #include <stdio.h> | |
37 | #include <io.h> | |
38 | #include <ctype.h> | |
39 | #include <process.h> | |
40 | ||
41 | #include "dialog.h" | |
42 | #include "resource.h" | |
43 | #include "state.h" | |
44 | #include "msg.h" | |
45 | #include "LogSingleton.h" | |
46 | #include "filemanip.h" | |
47 | #include "io_stream.h" | |
48 | #include "propsheet.h" | |
49 | #include "choose.h" | |
50 | #include "category.h" | |
51 | ||
52 | #include "package_db.h" | |
53 | #include "package_meta.h" | |
54 | #include "package_version.h" | |
55 | ||
0f0a6b63 MB |
56 | #include "threebar.h" |
57 | #include "Generic.h" | |
ee91d9be | 58 | #include "ControlAdjuster.h" |
0f0a6b63 MB |
59 | |
60 | using namespace std; | |
61 | ||
62 | extern ThreeBarProgressPage Progress; | |
63 | ||
ee91d9be RC |
64 | /* |
65 | Sizing information. | |
66 | */ | |
67 | static ControlAdjuster::ControlInfo ChooserControlsInfo[] = { | |
a8d753b6 RC |
68 | {IDC_CHOOSE_KEEP, CP_RIGHT, CP_TOP}, |
69 | {IDC_CHOOSE_PREV, CP_RIGHT, CP_TOP}, | |
70 | {IDC_CHOOSE_CURR, CP_RIGHT, CP_TOP}, | |
71 | {IDC_CHOOSE_EXP, CP_RIGHT, CP_TOP}, | |
72 | {IDC_CHOOSE_VIEW, CP_RIGHT, CP_TOP}, | |
73 | {IDC_LISTVIEW_POS, CP_RIGHT, CP_TOP}, | |
74 | {IDC_CHOOSE_VIEWCAPTION, CP_RIGHT, CP_TOP}, | |
75 | {IDC_CHOOSE_LIST, CP_STRETCH, CP_STRETCH}, | |
76 | {0, CP_LEFT, CP_TOP} | |
ee91d9be RC |
77 | }; |
78 | ||
79 | ChooserPage::ChooserPage () | |
80 | { | |
81 | sizeProcessor.AddControlInfo (ChooserControlsInfo); | |
82 | } | |
83 | ||
0f0a6b63 | 84 | void |
bc16bb7d | 85 | ChooserPage::createListview () |
0f0a6b63 MB |
86 | { |
87 | packagedb db; | |
88 | chooser = new PickView (*db.categories.find("All")); | |
bc16bb7d RC |
89 | RECT r = getDefaultListViewSize(); |
90 | if (!chooser->Create(this, WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,&r)) | |
0f0a6b63 MB |
91 | // TODO throw exception |
92 | exit (11); | |
93 | chooser->init(PickView::views::Category); | |
94 | chooser->Show(SW_SHOW); | |
95 | ||
96 | chooser->defaultTrust (TRUST_CURR); | |
525531ca | 97 | chooser->setViewMode (PickView::views::Category); |
952ea3fe | 98 | if (!SetDlgItemText (GetHWND (), IDC_CHOOSE_VIEWCAPTION, chooser->mode_caption ())) |
0f0a6b63 MB |
99 | log (LOG_BABBLE) << "Failed to set View button caption %ld" << |
100 | GetLastError () << endLog; | |
101 | for_each (db.packages.begin(), db.packages.end(), bind2nd(mem_fun(&packagemeta::set_requirements), chooser->deftrust)); | |
102 | /* FIXME: do we need to init the desired fields ? */ | |
103 | static int ta[] = { IDC_CHOOSE_KEEP, IDC_CHOOSE_PREV, IDC_CHOOSE_CURR, IDC_CHOOSE_EXP, 0 }; | |
952ea3fe | 104 | rbset (GetHWND (), ta, IDC_CHOOSE_CURR); |
0f0a6b63 MB |
105 | } |
106 | ||
107 | /* TODO: review ::overrides for possible consolidation */ | |
108 | void | |
109 | ChooserPage::getParentRect (HWND parent, HWND child, RECT * r) | |
110 | { | |
111 | POINT p; | |
112 | ::GetWindowRect (child, r); | |
113 | p.x = r->left; | |
114 | p.y = r->top; | |
115 | ::ScreenToClient (parent, &p); | |
116 | r->left = p.x; | |
117 | r->top = p.y; | |
118 | p.x = r->right; | |
119 | p.y = r->bottom; | |
120 | ::ScreenToClient (parent, &p); | |
121 | r->right = p.x; | |
122 | r->bottom = p.y; | |
123 | } | |
124 | ||
125 | bool | |
126 | ChooserPage::Create () | |
127 | { | |
128 | return PropertyPage::Create (IDD_CHOOSE); | |
129 | } | |
130 | ||
131 | void | |
132 | ChooserPage::setPrompt(char const *aString) | |
133 | { | |
134 | ::SetWindowText (GetDlgItem (IDC_CHOOSE_INST_TEXT), aString); | |
135 | } | |
136 | ||
bc16bb7d RC |
137 | RECT |
138 | ChooserPage::getDefaultListViewSize() | |
139 | { | |
140 | RECT result; | |
141 | getParentRect (GetHWND (), GetDlgItem (IDC_LISTVIEW_POS), &result); | |
142 | result.top += 2; | |
143 | result.bottom -= 2; | |
144 | return result; | |
145 | } | |
146 | ||
0f0a6b63 MB |
147 | void |
148 | ChooserPage::OnInit () | |
149 | { | |
150 | if (source == IDC_SOURCE_DOWNLOAD || source == IDC_SOURCE_CWD) | |
151 | packagemeta::ScanDownloadedFiles (); | |
152 | ||
153 | packagedb db; | |
154 | db.setExistence (); | |
2f18f94d | 155 | db.fillMissingCategory (); |
0f0a6b63 MB |
156 | |
157 | if (source == IDC_SOURCE_DOWNLOAD) | |
158 | setPrompt("Select packages to download "); | |
159 | else | |
160 | setPrompt("Select packages to install "); | |
bc16bb7d | 161 | createListview (); |
0f0a6b63 MB |
162 | } |
163 | ||
164 | void | |
165 | ChooserPage::OnActivate() | |
166 | { | |
ec2dbbf0 | 167 | chooser->refresh();; |
0f0a6b63 MB |
168 | } |
169 | ||
170 | void | |
171 | ChooserPage::logResults() | |
172 | { | |
173 | log (LOG_BABBLE) << "Chooser results..." << endLog; | |
174 | packagedb db; | |
175 | for_each (db.packages.begin (), db.packages.end (), mem_fun(&packagemeta::logSelectionStatus)); | |
176 | } | |
177 | ||
178 | long | |
179 | ChooserPage::OnNext () | |
180 | { | |
db165a9a | 181 | #ifdef DEBUG |
0f0a6b63 | 182 | logResults(); |
db165a9a | 183 | #endif |
0f0a6b63 MB |
184 | |
185 | if (source == IDC_SOURCE_CWD) | |
186 | { | |
187 | // Next, install | |
188 | Progress.SetActivateTask (WM_APP_START_INSTALL); | |
189 | } | |
190 | else | |
191 | { | |
192 | // Next, start download from internet | |
193 | Progress.SetActivateTask (WM_APP_START_DOWNLOAD); | |
194 | } | |
195 | return IDD_INSTATUS; | |
196 | } | |
197 | ||
198 | long | |
199 | ChooserPage::OnBack () | |
200 | { | |
201 | if (source == IDC_SOURCE_CWD) | |
202 | return IDD_LOCAL_DIR; | |
203 | else | |
204 | return IDD_SITE; | |
205 | } | |
206 | ||
207 | void | |
208 | ChooserPage::keepClicked() | |
209 | { | |
210 | packagedb db; | |
211 | for (vector <packagemeta *>::iterator i = db.packages.begin (); | |
212 | i != db.packages.end (); ++i) | |
213 | { | |
214 | packagemeta & pkg = **i; | |
215 | pkg.desired = pkg.installed; | |
216 | } | |
bb8e2353 | 217 | chooser->refresh(); |
0f0a6b63 MB |
218 | } |
219 | ||
220 | template <trusts aTrust> | |
221 | void | |
222 | ChooserPage::changeTrust() | |
223 | { | |
224 | chooser->defaultTrust (aTrust); | |
225 | packagedb db; | |
226 | for_each(db.packages.begin(), db.packages.end(), SetRequirement(aTrust)); | |
bb8e2353 | 227 | chooser->refresh(); |
0f0a6b63 MB |
228 | } |
229 | ||
230 | bool | |
231 | ChooserPage::OnMessageCmd (int id, HWND hwndctl, UINT code) | |
232 | { | |
233 | if (code != BN_CLICKED) | |
234 | { | |
235 | // Not a click notification, we don't care. | |
236 | return false; | |
237 | } | |
238 | ||
239 | switch (id) | |
240 | { | |
241 | case IDC_CHOOSE_KEEP: | |
242 | return ifChecked(id, &ChooserPage::keepClicked); | |
243 | case IDC_CHOOSE_PREV: | |
244 | return ifChecked(id, &ChooserPage::changeTrust<TRUST_PREV>); | |
245 | case IDC_CHOOSE_CURR: | |
246 | return ifChecked(id, &ChooserPage::changeTrust<TRUST_CURR>); | |
247 | case IDC_CHOOSE_EXP: | |
248 | return ifChecked(id, &ChooserPage::changeTrust<TRUST_TEST>); | |
249 | case IDC_CHOOSE_VIEW: | |
525531ca | 250 | chooser->setViewMode (++chooser->get_view_mode ()); |
0f0a6b63 MB |
251 | if (!SetDlgItemText |
252 | (GetHWND (), IDC_CHOOSE_VIEWCAPTION, chooser->mode_caption ())) | |
253 | log (LOG_BABBLE) << "Failed to set View button caption " << | |
254 | GetLastError () << endLog; | |
255 | break; | |
256 | ||
257 | default: | |
258 | // Wasn't recognized or handled. | |
259 | return false; | |
260 | } | |
261 | ||
262 | // Was handled since we never got to default above. | |
263 | return true; | |
264 | } |