]>
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 | ||
56 | #include "port.h" | |
57 | #include "threebar.h" | |
58 | #include "Generic.h" | |
59 | ||
60 | using namespace std; | |
61 | ||
62 | extern ThreeBarProgressPage Progress; | |
63 | ||
0f0a6b63 | 64 | void |
bc16bb7d | 65 | ChooserPage::createListview () |
0f0a6b63 MB |
66 | { |
67 | packagedb db; | |
68 | chooser = new PickView (*db.categories.find("All")); | |
bc16bb7d RC |
69 | RECT r = getDefaultListViewSize(); |
70 | if (!chooser->Create(this, WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,&r)) | |
0f0a6b63 MB |
71 | // TODO throw exception |
72 | exit (11); | |
73 | chooser->init(PickView::views::Category); | |
74 | chooser->Show(SW_SHOW); | |
75 | ||
76 | chooser->defaultTrust (TRUST_CURR); | |
525531ca | 77 | chooser->setViewMode (PickView::views::Category); |
952ea3fe | 78 | if (!SetDlgItemText (GetHWND (), IDC_CHOOSE_VIEWCAPTION, chooser->mode_caption ())) |
0f0a6b63 MB |
79 | log (LOG_BABBLE) << "Failed to set View button caption %ld" << |
80 | GetLastError () << endLog; | |
81 | for_each (db.packages.begin(), db.packages.end(), bind2nd(mem_fun(&packagemeta::set_requirements), chooser->deftrust)); | |
82 | /* FIXME: do we need to init the desired fields ? */ | |
83 | static int ta[] = { IDC_CHOOSE_KEEP, IDC_CHOOSE_PREV, IDC_CHOOSE_CURR, IDC_CHOOSE_EXP, 0 }; | |
952ea3fe | 84 | rbset (GetHWND (), ta, IDC_CHOOSE_CURR); |
0f0a6b63 MB |
85 | } |
86 | ||
87 | /* TODO: review ::overrides for possible consolidation */ | |
88 | void | |
89 | ChooserPage::getParentRect (HWND parent, HWND child, RECT * r) | |
90 | { | |
91 | POINT p; | |
92 | ::GetWindowRect (child, r); | |
93 | p.x = r->left; | |
94 | p.y = r->top; | |
95 | ::ScreenToClient (parent, &p); | |
96 | r->left = p.x; | |
97 | r->top = p.y; | |
98 | p.x = r->right; | |
99 | p.y = r->bottom; | |
100 | ::ScreenToClient (parent, &p); | |
101 | r->right = p.x; | |
102 | r->bottom = p.y; | |
103 | } | |
104 | ||
105 | bool | |
106 | ChooserPage::Create () | |
107 | { | |
108 | return PropertyPage::Create (IDD_CHOOSE); | |
109 | } | |
110 | ||
111 | void | |
112 | ChooserPage::setPrompt(char const *aString) | |
113 | { | |
114 | ::SetWindowText (GetDlgItem (IDC_CHOOSE_INST_TEXT), aString); | |
115 | } | |
116 | ||
bc16bb7d RC |
117 | RECT |
118 | ChooserPage::getDefaultListViewSize() | |
119 | { | |
120 | RECT result; | |
121 | getParentRect (GetHWND (), GetDlgItem (IDC_LISTVIEW_POS), &result); | |
122 | result.top += 2; | |
123 | result.bottom -= 2; | |
124 | return result; | |
125 | } | |
126 | ||
0f0a6b63 MB |
127 | void |
128 | ChooserPage::OnInit () | |
129 | { | |
130 | if (source == IDC_SOURCE_DOWNLOAD || source == IDC_SOURCE_CWD) | |
131 | packagemeta::ScanDownloadedFiles (); | |
132 | ||
133 | packagedb db; | |
134 | db.setExistence (); | |
2f18f94d | 135 | db.fillMissingCategory (); |
0f0a6b63 MB |
136 | |
137 | if (source == IDC_SOURCE_DOWNLOAD) | |
138 | setPrompt("Select packages to download "); | |
139 | else | |
140 | setPrompt("Select packages to install "); | |
bc16bb7d | 141 | createListview (); |
0f0a6b63 MB |
142 | } |
143 | ||
144 | void | |
145 | ChooserPage::OnActivate() | |
146 | { | |
ec2dbbf0 | 147 | chooser->refresh();; |
0f0a6b63 MB |
148 | } |
149 | ||
150 | void | |
151 | ChooserPage::logResults() | |
152 | { | |
153 | log (LOG_BABBLE) << "Chooser results..." << endLog; | |
154 | packagedb db; | |
155 | for_each (db.packages.begin (), db.packages.end (), mem_fun(&packagemeta::logSelectionStatus)); | |
156 | } | |
157 | ||
158 | long | |
159 | ChooserPage::OnNext () | |
160 | { | |
161 | logResults(); | |
162 | ||
163 | if (source == IDC_SOURCE_CWD) | |
164 | { | |
165 | // Next, install | |
166 | Progress.SetActivateTask (WM_APP_START_INSTALL); | |
167 | } | |
168 | else | |
169 | { | |
170 | // Next, start download from internet | |
171 | Progress.SetActivateTask (WM_APP_START_DOWNLOAD); | |
172 | } | |
173 | return IDD_INSTATUS; | |
174 | } | |
175 | ||
176 | long | |
177 | ChooserPage::OnBack () | |
178 | { | |
179 | if (source == IDC_SOURCE_CWD) | |
180 | return IDD_LOCAL_DIR; | |
181 | else | |
182 | return IDD_SITE; | |
183 | } | |
184 | ||
185 | void | |
186 | ChooserPage::keepClicked() | |
187 | { | |
188 | packagedb db; | |
189 | for (vector <packagemeta *>::iterator i = db.packages.begin (); | |
190 | i != db.packages.end (); ++i) | |
191 | { | |
192 | packagemeta & pkg = **i; | |
193 | pkg.desired = pkg.installed; | |
194 | } | |
bb8e2353 | 195 | chooser->refresh(); |
0f0a6b63 MB |
196 | } |
197 | ||
198 | template <trusts aTrust> | |
199 | void | |
200 | ChooserPage::changeTrust() | |
201 | { | |
202 | chooser->defaultTrust (aTrust); | |
203 | packagedb db; | |
204 | for_each(db.packages.begin(), db.packages.end(), SetRequirement(aTrust)); | |
bb8e2353 | 205 | chooser->refresh(); |
0f0a6b63 MB |
206 | } |
207 | ||
208 | bool | |
209 | ChooserPage::OnMessageCmd (int id, HWND hwndctl, UINT code) | |
210 | { | |
211 | if (code != BN_CLICKED) | |
212 | { | |
213 | // Not a click notification, we don't care. | |
214 | return false; | |
215 | } | |
216 | ||
217 | switch (id) | |
218 | { | |
219 | case IDC_CHOOSE_KEEP: | |
220 | return ifChecked(id, &ChooserPage::keepClicked); | |
221 | case IDC_CHOOSE_PREV: | |
222 | return ifChecked(id, &ChooserPage::changeTrust<TRUST_PREV>); | |
223 | case IDC_CHOOSE_CURR: | |
224 | return ifChecked(id, &ChooserPage::changeTrust<TRUST_CURR>); | |
225 | case IDC_CHOOSE_EXP: | |
226 | return ifChecked(id, &ChooserPage::changeTrust<TRUST_TEST>); | |
227 | case IDC_CHOOSE_VIEW: | |
525531ca | 228 | chooser->setViewMode (++chooser->get_view_mode ()); |
0f0a6b63 MB |
229 | if (!SetDlgItemText |
230 | (GetHWND (), IDC_CHOOSE_VIEWCAPTION, chooser->mode_caption ())) | |
231 | log (LOG_BABBLE) << "Failed to set View button caption " << | |
232 | GetLastError () << endLog; | |
233 | break; | |
234 | ||
235 | default: | |
236 | // Wasn't recognized or handled. | |
237 | return false; | |
238 | } | |
239 | ||
240 | // Was handled since we never got to default above. | |
241 | return true; | |
242 | } |