e40de503b4ec779ee85e0aa9f582073d55554d09
[scilab.git] / scilab / modules / atoms / macros / atoms_internals / atomsGetLeftListboxElts.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2010 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
3 //
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution. The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10 // Internal function
11 // GUI function
12
13 // Returns a struct that contains the followings fields:
14 //  - elements("items_str")
15 //  - elements("items_mat")
16 //  - elements("title")
17 //
18
19 function elements = atomsGetLeftListboxElts(category)
20
21     rhs = argn(2);
22
23     // Check number of input arguments
24     // =========================================================================
25
26     if rhs <> 1 then
27         error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"getLeftListboxElements",1));
28     end
29
30     // Check input argument types
31     // =========================================================================
32
33     if category<>[] & type(category) <> 10 then
34         error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"),"getLeftListboxElements",1));
35     end
36
37     if category<>[] & type(category) <> 10 then
38         error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"),"getLeftListboxElements",1));
39     end
40
41     if size(category(1,:),"*") > 2 then
42         error(msprintf(gettext("%s: Wrong size for input argument #%d: mx1 or mx2 string matrix expected.\n"),"atomsIsCategory",1));
43     end
44
45     // Build lists
46     // =========================================================================
47
48     items_str  = [];
49     items_mat  = [];
50
51     atomsfig   = findobj("tag","atomsFigure");
52     allModules = atomsfig("UserData");
53
54     background = "#ffffff";
55
56     // 1st case, All main categories
57     // -------------------------------------------------------------------------
58
59     if category=="filter:main" then
60
61         categories = atomsCategoryGet("filter:main");
62
63         thisItem  =            "<html>";
64         thisItem  = thisItem + "<table style=""background-color:#ffffff;color:#000000;""><tr>";
65         thisItem  = thisItem + "<td><img src=""file:///"+SCI+"/modules/gui/images/icons/16x16/places/user-home.png"" /></td>";
66         thisItem  = thisItem + "<td style=""width:132px;""><div style=""width:118px;text-align:left;font-weight:bold;"">"+gettext("All modules")+"</div></td>";
67         thisItem  = thisItem + "</tr></table>";
68         thisItem  = thisItem + "</html>";
69
70         items_str = [items_str ; thisItem ];
71         items_mat = [items_mat ; "category" "filter:all"];
72
73          for i=1:size(categories, "*")
74
75             if background == "#eeeeee" then
76                 background = "#ffffff";
77             else
78                 background = "#eeeeee";
79             end
80
81             thisItem  =            "<html>";
82             thisItem  = thisItem + "<table style=""background-color:"+background+";color:#000000;"" ><tr>";
83             thisItem  = thisItem + "<td><img src=""file:///"+SCI+"/modules/gui/images/icons/16x16/places/folder.png"" /></td>";
84             thisItem  = thisItem + "<td style=""width:132px;""><div style=""width:118px;text-align:left;"">"+categories(i)+"</div></td>";
85             thisItem  = thisItem + "</tr></table>";
86             thisItem  = thisItem + "</html>";
87
88             items_str = [items_str ; thisItem ];
89             items_mat = [items_mat ; "category" categories(i)];
90         end
91
92     // 2nd case: Sub categories + modules
93     // -------------------------------------------------------------------------
94
95     else
96
97         // Categories
98         // ---------------------------------------------------------------------
99
100         index_start = regexp(category,"/ - /");
101         // if index_start == [], category is a main category
102         // otherwise, category is a subcategory
103
104         if category=="filter:all" then
105             categories = [];
106             top_str    = gettext("Main categories");
107             top_mat    = ["category" "filter:main"];
108
109         elseif index_start==[] then
110             categories = atomsCategoryGet(category);
111             top_str    = gettext("Main categories");
112             top_mat    = ["category" "filter:main"];
113
114         else
115             categories = [];
116             parent     = part(category,1:index_start-1);
117             top_str    = parent;
118             top_mat    = ["category" parent];
119
120         end
121
122         thisItem  =            "<html>";
123         thisItem  = thisItem + "<table style=""background-color:#ffffff;color:#000000;"" ><tr>";
124         thisItem  = thisItem + "<td><img src=""file:///"+SCI+"/modules/gui/images/icons/16x16/places/user-home.png"" /></td>";
125         thisItem  = thisItem + "<td style=""width:132px;""><div style=""width:118px;text-align:left;font-weight:bold;"">"+top_str+"</div></td>";
126
127         thisItem  = thisItem + "</tr></table>";
128         thisItem  = thisItem + "</html>";
129
130         items_str = [items_str ; thisItem ];
131         items_mat = [items_mat ; top_mat  ];
132
133         for i=1:size(categories, "*")
134
135             if background == "#eeeeee" then
136                 background = "#ffffff";
137             else
138                 background = "#eeeeee";
139             end
140
141             thisItem  =            "<html>";
142             thisItem  = thisItem + "<table style=""background-color:"+background+";color:#000000;"" ><tr>";
143             thisItem  = thisItem + "<td><img src=""file:///"+SCI+"/modules/gui/images/icons/16x16/places/folder.png"" /></td>";
144             thisItem  = thisItem + "<td style=""width:132px;""><div style=""width:118px;text-align:left;"">"+categories(i)+"</div></td>";
145             thisItem  = thisItem + "</tr></table>";
146             thisItem  = thisItem + "</html>";
147
148             items_str = [items_str ; thisItem ];
149             items_mat = [items_mat ; "category" category+" - "+categories(i) ];
150         end
151
152         // Modules
153         // ---------------------------------------------------------------------
154
155         if category=="filter:all" then
156             modulesNames = atomsGetAvailable([],%T);
157         else
158             modulesNames = atomsGetAvailable(category,%T);
159         end
160
161         for i=1:size(modulesNames, "*")
162
163             MRVersionAvailable = atomsGetMRVersion(modulesNames(i));
164             thisModuleTitle    = allModules(modulesNames(i))(MRVersionAvailable).Title;
165
166             if atomsIsInstalled(modulesNames(i)) then
167
168                 MRVersionInstalled = atomsVersionSort(atomsGetInstalledVers(modulesNames(i)),"DESC");
169                 MRVersionInstalled = MRVersionInstalled(1);
170                 thisModuleTitle    = allModules(modulesNames(i))(MRVersionInstalled).Title;
171
172                 if atomsVersionCompare(MRVersionInstalled,MRVersionAvailable) == -1 then
173                     // Not up-to-date
174                     icon = "software-update-notuptodate.png";
175                 else
176                     // The Most Recent Version is already installed
177                     icon = "software-update-installed.png";
178                 end
179
180             else
181                 icon = "software-update-notinstalled.png";
182             end
183
184             if background == "#eeeeee" then
185                 background = "#ffffff";
186             else
187                 background = "#eeeeee";
188             end
189
190             thisItem =            "<html>";
191             thisItem = thisItem + "<table style=""background-color:"+background+";color:#000000;"" ><tr>";
192             thisItem = thisItem + "<td><img src=""file:///"+SCI+"/modules/atoms/images/icons/16x16/status/"+icon+""" /></td>";
193             thisItem = thisItem + "<td style=""width:132px;""><div style=""width:118px;text-align:left;"">"+thisModuleTitle+"</div></td>";
194             thisItem = thisItem + "</tr></table>";
195             thisItem = thisItem + "</html>";
196
197             items_str = [items_str ; thisItem     ];
198             items_mat = [items_mat ; "module" modulesNames(i)];
199
200         end
201     end
202
203     if items_str==[] then
204         elements("items_str") = "";
205     else
206         elements("items_str") = items_str;
207     end
208
209     elements("items_mat") = items_mat;
210
211     if category=="filter:main" then
212         elements("title") = gettext("Main categories");
213     elseif category=="filter:all" then
214         elements("title") = gettext("All modules");
215     else
216         elements("title") = category;
217     end
218
219 endfunction