Regenerate Japanese resources
[cygwin-setup.git] / PickPackageLine.cc
blobd380965d585e06931bf4ede869bebd419b4f9936
1 /*
2 * Copyright (c) 2002 Robert Collins.
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/
12 * Written by Robert Collins <robertc@hotmail.com>
16 #include "PickPackageLine.h"
17 #include "PickView.h"
18 #include "package_db.h"
20 const std::wstring
21 PickPackageLine::get_text(int col_num) const
23 if (col_num == pkgname_col)
25 return string_to_wstring(pkg.name);
27 else if (col_num == current_col)
29 return string_to_wstring(pkg.installed.Canonical_version());
31 else if (col_num == new_col)
33 return pkg.action_caption ();
35 else if (col_num == srctick_col)
37 const char *srctick = "?";
38 if ( /* uninstall */ !pkg.desired ||
39 /* when no source mirror available */
40 !pkg.desired.sourcePackage().accessible())
41 srctick = "n/a";
42 else if (pkg.srcpicked())
43 srctick = "yes";
44 else
45 srctick = "no";
47 return string_to_wstring(srctick);
49 else if (col_num == cat_col)
51 return string_to_wstring(pkg.getReadableCategoryList());
53 else if (col_num == size_col)
55 int sz = 0;
56 packageversion picked;
58 /* Find the size of the package. If user has chosen to upgrade/downgrade
59 the package, use that version. Otherwise use the currently installed
60 version, or if not installed then use the version that would be chosen
61 based on the current trust level (curr/prev/test). */
62 if (pkg.desired)
63 picked = pkg.desired;
64 else if (pkg.installed)
65 picked = pkg.installed;
66 else
67 picked = pkg.trustp (false, theView.deftrust);
69 /* Include the size of the binary package, and if selected, the source
70 package as well. */
71 sz += picked.source()->size;
72 if (pkg.srcpicked())
73 sz += picked.sourcePackage().source()->size;
75 /* If size still 0, size must be unknown. */
76 std::string size = (sz == 0) ? "?" : format_1000s((sz+1023)/1024) + "k";
78 return string_to_wstring(size);
80 else if (col_num == pkg_col)
82 return string_to_wstring(pkg.SDesc());
85 return L"unknown";
88 const std::string
89 PickPackageLine::get_tooltip(int col_num) const
91 if (col_num == pkg_col)
93 return pkg.LDesc();
96 return "";
99 int
100 PickPackageLine::do_action(int col_num, int action_id)
102 if (col_num == new_col)
104 pkg.select_action(action_id, theView.deftrust);
105 return 1;
108 if (col_num == srctick_col)
110 if (pkg.desired.sourcePackage ().accessible ())
111 pkg.srcpick (!pkg.srcpicked ());
113 return 1;
116 return 0;
120 PickPackageLine::do_default_action(int col_num)
122 if (col_num == new_col)
124 pkg.toggle_action();
125 return 1;
127 return 0;
130 ActionList *
131 PickPackageLine::get_actions(int col_num) const
133 if (col_num == new_col)
135 return pkg.list_actions (theView.deftrust);
138 return NULL;
142 PickPackageLine::get_indent() const
144 return indent;
148 PickPackageLine::map_key_to_action(WORD vkey, int modkeys, int & col_num,
149 int & action_id) const
151 switch (vkey)
153 case VK_SPACE: // install/reinstall/uninstall context menu for package
154 case VK_APPS:
155 col_num = new_col;
156 return Action::PopUp;
157 case 'I': // Ctrl+I: select install default version and move to next row
158 case 'K': // Ctrl+K: select keep or skip package and move to next row
159 case 'R': // Ctrl+R: select reinstall and move to next row
160 case 'U': // Ctrl+U: select uninstall and move to next row
161 if (modkeys != ModifierKeys::Control)
162 break;
163 col_num = new_col;
164 switch (vkey)
166 case 'I': action_id = packagemeta::Install_action; break;
167 default: action_id = packagemeta::NoChange_action; break;
168 case 'R': action_id = packagemeta::Reinstall_action; break;
169 case 'U': action_id = packagemeta::Uninstall_action; break;
171 return Action::Direct | Action::NextRow;
174 return Action::None;