root/branches/3.00/src/choose.cc

Revision 711, 6.8 kB (checked in by fujii, 3 years ago)

setup-ja.exe (Japanese version of setup.exe) is added.

* Makefile.in (setup-ja$(EXEEXT)): New target.

* Makefile.am (res-ja.o): New target.
(%.o): Add option '-DMEADOW_NETINSTALL'.

* res-ja.rc: New file.

* resource.h (IDS_CHOOSE_INSTALLATION_MSG): New ID.
(IDS_CHOOSE_DOWNLOAD_MSG): Ditto.

* res.rc: Add strings corresponding to IDs added to resource.h.

* choose.cc (OnInit?): Use messages in resource file.

Line 
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: choose.cc,v 2.136 2004/10/25 17:06:07 maxb Exp $\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 "threebar.h"
57 #include "Generic.h"
58 #include "ControlAdjuster.h"
59
60 using namespace std;
61
62 extern ThreeBarProgressPage Progress;
63
64 /*
65   Sizing information.
66  */
67 static ControlAdjuster::ControlInfo ChooserControlsInfo[] = {
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}
77 };
78
79 ChooserPage::ChooserPage ()
80 {
81   sizeProcessor.AddControlInfo (ChooserControlsInfo);
82 }
83
84 void
85 ChooserPage::createListview ()
86 {
87   packagedb db;
88   chooser = new PickView (*db.categories.find("All"));
89   RECT r = getDefaultListViewSize();
90   if (!chooser->Create(this, WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,&r))
91     // TODO throw exception
92     exit (11);
93   chooser->init(PickView::views::Category);
94   chooser->Show(SW_SHOW);
95
96   chooser->defaultTrust (TRUST_CURR);
97   chooser->setViewMode (PickView::views::Category);
98   if (!SetDlgItemText (GetHWND (), IDC_CHOOSE_VIEWCAPTION, chooser->mode_caption ()))
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 };
104   rbset (GetHWND (), ta, IDC_CHOOSE_CURR);
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
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
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 ();
155   db.fillMissingCategory ();
156
157 #ifdef MEADOW_NETINSTALL
158   {
159     char msg[1024];
160     UINT id;
161
162     if (source == IDC_SOURCE_DOWNLOAD)
163       id = IDS_CHOOSE_DOWNLOAD_MSG;
164     else
165       id = IDS_CHOOSE_INSTALLATION_MSG;
166
167     LoadString(GetModuleHandle(NULL), id, msg, sizeof (msg));
168
169     setPrompt(msg);
170   }
171 #else
172   if (source == IDC_SOURCE_DOWNLOAD)
173     setPrompt("Select packages to download ");
174   else
175     setPrompt("Select packages to install ");
176 #endif
177   createListview ();
178 }
179
180 void
181 ChooserPage::OnActivate()
182 {
183     chooser->refresh();;
184 }
185
186 void
187 ChooserPage::logResults()
188 {
189   log (LOG_BABBLE) << "Chooser results..." << endLog;
190   packagedb db;
191   for_each (db.packages.begin (), db.packages.end (), mem_fun(&packagemeta::logSelectionStatus));
192 }
193
194 long
195 ChooserPage::OnNext ()
196 {
197   logResults();
198
199   if (source == IDC_SOURCE_CWD)
200     {
201       // Next, install
202       Progress.SetActivateTask (WM_APP_START_INSTALL);
203     }
204   else
205     {
206       // Next, start download from internet
207       Progress.SetActivateTask (WM_APP_START_DOWNLOAD);
208     }
209   return IDD_INSTATUS;
210 }
211
212 long
213 ChooserPage::OnBack ()
214 {
215   if (source == IDC_SOURCE_CWD)
216     return IDD_LOCAL_DIR;
217   else
218     return IDD_SITE;
219 }
220
221 void
222 ChooserPage::keepClicked()
223 {
224   packagedb db;
225   for (vector <packagemeta *>::iterator i = db.packages.begin ();
226         i != db.packages.end (); ++i)
227     {
228       packagemeta & pkg = **i;
229       pkg.desired = pkg.installed;
230     }
231   chooser->refresh();
232 }
233
234 template <trusts aTrust>
235 void
236 ChooserPage::changeTrust()
237 {
238   chooser->defaultTrust (aTrust);
239   packagedb db;
240   for_each(db.packages.begin(), db.packages.end(), SetRequirement(aTrust));
241   chooser->refresh();
242 }
243
244 bool
245 ChooserPage::OnMessageCmd (int id, HWND hwndctl, UINT code)
246 {
247   if (code != BN_CLICKED)
248     {
249       // Not a click notification, we don't care.
250       return false;
251     }
252
253   switch (id)
254     {
255     case IDC_CHOOSE_KEEP:
256        return ifChecked(id, &ChooserPage::keepClicked);
257     case IDC_CHOOSE_PREV:
258        return ifChecked(id, &ChooserPage::changeTrust<TRUST_PREV>);
259     case IDC_CHOOSE_CURR:
260        return ifChecked(id, &ChooserPage::changeTrust<TRUST_CURR>);
261     case IDC_CHOOSE_EXP:
262        return ifChecked(id, &ChooserPage::changeTrust<TRUST_TEST>);
263     case IDC_CHOOSE_VIEW:
264       chooser->setViewMode (++chooser->get_view_mode ());
265       if (!SetDlgItemText
266         (GetHWND (), IDC_CHOOSE_VIEWCAPTION, chooser->mode_caption ()))
267       log (LOG_BABBLE) << "Failed to set View button caption " <<
268            GetLastError () << endLog;
269       break;
270      
271     default:
272       // Wasn't recognized or handled.
273       return false;
274     }
275
276   // Was handled since we never got to default above.
277   return true;
278 }
Note: See TracBrowser for help on using the browser.