1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2009 - DIGITEO - Vincent COUVERT <vincent.couvert@scilab.org>
3 // Copyright (C) 2009-2010 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
5 // This file must be used under the terms of the CeCILL.
6 // This source file is licensed as described in the file COPYING, which
7 // you should have received as part of this distribution. The terms
8 // are also available at
9 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
15 // Load Atoms Internals lib if it's not already loaded
16 if ~ exists("atomsinternalslib") then
17 load("SCI/modules/atoms/macros/atoms_internals/lib");
20 UItag = get(gcbo,"Tag");
22 // Get the description frame object
23 DescFrame = findobj("tag","DescFrame");
25 // Display selected module informations
26 // =========================================================================
28 if or(UItag == ["LeftListbox";"HomeListbox"]) then
30 // Get the selected module
31 module = getSelected(UItag);
33 // Save the module name
34 set(DescFrame,"userdata",module);
36 // Update the description frame
39 // Show the description frame
43 // A button has been pressed
44 // =========================================================================
46 if or(UItag == ["installButton";"removeButton";"updateButton"]) then
47 // Get the module name
48 module = get(DescFrame,"userdata");
54 // Install selected module
55 // =========================================================================
57 if UItag == "installButton" then
58 if execstr("atomsInstall("""+module+""")","errcatch")<>0 then
59 messagebox(gettext("Installation failed!"),gettext("Atoms error"),"error");
61 messagebox(gettext("Installation done! Please restart Scilab to take changes into account."),gettext("Atoms"),"info");
64 // Remove selected module
65 // =========================================================================
67 elseif UItag == "removeButton" then // Remove selected module
68 if execstr("atomsRemove("""+module+""")", "errcatch")<>0 then
69 messagebox(gettext("Remove failed!"),gettext("Atoms error"),"error");
71 messagebox(gettext("Remove done! Please restart Scilab to take changes into account. "),gettext("Atoms"),"info");
74 // Update selected module
75 // =========================================================================
77 elseif UItag == "updateButton" then // Update selected module
78 if execstr("atomsUpdate("""+module+""")","errcatch")<>0 then
79 messagebox(gettext("Update failed!"),gettext("Atoms error"),"error");
81 messagebox(gettext("Update done! Please restart Scilab to take changes into account."),gettext("Atoms"),"info");
85 // End of the button action
86 // =========================================================================
88 if or(UItag == ["installButton";"removeButton";"updateButton"]) then
95 // =========================================================================
98 if UItag == "homeMenu" then
102 elseif UItag == "closeMenu" then
103 delete(findobj("Tag", "atomsFigure"));
106 elseif UItag == "helpMenu" then
114 // =============================================================================
116 // + Return the module name selected from a listbox.
117 // + Accepted listboxes:
120 // =============================================================================
122 function name = getSelected(listbox)
124 selected = get(findobj("Tag",listbox),"Value");
126 if listbox == "HomeListbox" then
127 modulesNames = atomsGetInstalled();
128 modulesNames = modulesNames(:,1);
129 elseif listbox == "LeftListbox" then
130 allModules = get(findobj("Tag", "atomsFigure"), "userdata");
131 modulesNames = getfield(1, allModules);
132 modulesNames (1:2) = [];
134 error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"),"getSelected",1,"HomeListbox","LeftListbox"));
137 name = modulesNames(selected);
142 // =============================================================================
144 // + Disable all callback
145 // =============================================================================
148 function disableAtomsGui()
150 set(findobj("tag", "installButton"), "Enable", "off");
151 set(findobj("tag", "updateButton") , "Enable", "off");
152 set(findobj("tag", "removeButton") , "Enable", "off");
156 function disableLeftListbox()
157 set(findobj("tag", "LeftListbox"),"Callback", "");
158 set(findobj("tag", "LeftListbox"),"ForegroundColor",[0.5 0.5 0.5]);
161 function enableLeftListbox()
162 set(findobj("tag", "LeftListbox"),"Callback", "cbAtomsGui");
163 set(findobj("tag", "LeftListbox"),"ForegroundColor",[0 0 0]);
167 // =============================================================================
169 // + Update the description frame with the selected module
170 // + does not change the description frame visibility
171 // =============================================================================
173 function updateDescFrame()
175 // Operating system detection + Architecture detection
176 // =========================================================================
177 [OSNAME,ARCH,LINUX,MACOSX,SOLARIS,BSD] = atomsGetPlatform();
179 // Get the modules list and the selected module
180 // =========================================================================
182 thisFigure = findobj("tag","atomsFigure");
184 Desc = findobj("tag","Desc");
185 DescFrame = findobj("tag","DescFrame");
186 DescTitle = findobj("tag","DescTitle");
188 allModules = get(thisFigure,"userdata");
189 thisModuleName = get(DescFrame ,"userdata");
191 // Reset the message frame
192 // =========================================================================
193 set(findobj("tag","msgText"),"String","");
195 // Get the module details
196 // =========================================================================
198 modulesNames = getfield(1, allModules);
199 modulesNames (1:2) = [];
200 thisModuleStruct = allModules(thisModuleName);
202 MRVersionAvailable = atomsGetMRVersion(thisModuleName);
203 MRVersionInstalled = "";
205 if atomsIsInstalled(thisModuleName) then
206 MRVersionInstalled = atomsVersionSort(atomsGetInstalledVers(thisModuleName),"DESC");
207 MRVersionInstalled = MRVersionInstalled(1);
208 thisModuleDetails = thisModuleStruct(MRVersionInstalled);
210 thisModuleDetails = thisModuleStruct(MRVersionAvailable);
214 // =========================================================================
216 if isfield(thisModuleDetails,OSNAME+ARCH+"Size") then
218 "<div style=""font-weight:bold;margin-top:10px;margin-bottom:5px;"">" + ..
219 gettext("Download size") + ..
222 atomsSize2human(thisModuleDetails(OSNAME+ARCH+"Size")) + ..
229 // =========================================================================
231 authorMat = thisModuleDetails.Author;
233 authorHTML = "<div style=""font-weight:bold;margin-top:10px;margin-bottom:5px;"">" + ..
234 gettext("Author(s)") + ..
238 for i=1:size(authorMat,"*")
239 authorHTML = authorHTML + authorMat(i)+"<br>";
242 authorHTML = authorHTML + "</div>";
244 // Build and Set the HTML code
245 // =========================================================================
248 htmlcode = "<html>" + ..
250 "<div style=""font-weight:bold;margin-top:10px;margin-bottom:5px;"">" + ..
251 gettext("Version") + ..
253 "<div>" + thisModuleDetails.Version + "</div>" + ..
255 "<div style=""font-weight:bold;margin-top:10px;margin-bottom:5px;"">" + ..
256 gettext("Description") + ..
259 strcat(thisModuleDetails.Description,"<br>") + ..
265 // Process URLs and Emails
266 htmlcode = processHTMLLinks(htmlcode);
268 // Update the main description
269 set(Desc,"String",htmlcode);
271 // Description title management
272 // =========================================================================
274 descFrameHTML = thisModuleDetails.Title;
276 descFramePos = get(DescTitle,"Position");
277 descFramePos(3) = 300;
279 set(DescTitle, "String" , descFrameHTML );
280 set(DescTitle, "Position" , descFramePos );
283 // =========================================================================
285 // Tests for update available
286 // --------------------------
290 if atomsIsInstalled(thisModuleName) & atomsVersionCompare(MRVersionInstalled,MRVersionAvailable) == -1 then
293 showWarning(sprintf(gettext("A new version (''%s'') of ''%s'' is available"),MRVersionAvailable,thisModuleDetails.Title));
297 // --------------------------
299 if atomsIsInstalled(thisModuleName) then
306 // --------------------------
308 if ~ atomsIsInstalled(thisModuleName) then
314 // Update the buttons
315 // --------------------------
317 set(findobj("tag", "installButton"), "Enable", canInstall);
318 set(findobj("tag", "updateButton") , "Enable", canUpdate );
319 set(findobj("tag", "removeButton") , "Enable", canRemove );
323 // =============================================================================
325 // =============================================================================
327 function human_str = atomsSize2human(size_str)
329 size_int = strtod(size_str);
331 if size_int < 1024 then
332 human_str = string(size_int) + " " + gettext("Bytes");
334 elseif size_int < 1024*1024 then
335 human_str = string(round(size_int/1024)) + " " + gettext("KB");
338 human_str = string( round((size_int*10)/(1024*1024)) / 10 ) + " " + gettext("MB");
344 // =============================================================================
346 // =============================================================================
349 obj = findobj("tag",tag);
350 set(obj,"Visible","On");
353 // =============================================================================
355 // =============================================================================
358 obj = findobj("tag",tag);
359 set(obj,"Visible","Off");
362 // =============================================================================
364 // + Hide the detailed description of a module
365 // + Show the home page
366 // =============================================================================
370 // Reset the message frame
371 set(findobj("tag","msgText"),"String","");
373 // Hide the Desc frame
377 hide("removeButton");
378 hide("installButton");
379 hide("updateButton");
381 // Show the Home page
388 // =============================================================================
390 // + Hide the home page
391 // + Show the detailed description of a module
392 // =============================================================================
396 // Show the Home page
401 // Hide the Desc frame
405 show("removeButton");
406 show("installButton");
407 show("updateButton");
412 // =============================================================================
414 // + Update the string in the msg Frame
415 // =============================================================================
417 function showWarning(msg)
420 str = str + "<table><tr>";
421 str = str + "<td><img src=""file:///"+SCI+"/modules/atoms/images/icons/software-update-available.png"" /></td>";
422 str = str + "<td><div style=""color:red;font-style:italic;"">"+msg+"</div></td>";
423 str = str + "</tr></table>";
424 str = str + "</html>";
426 msgText = findobj("tag","msgText");
428 set(msgText,"String",str);
432 // =============================================================================
434 // + Find URLs and emails
435 // + Convert them in HTML
436 // =============================================================================
438 function txtout = processHTMLLinks(txtin)
440 regexUrl = "/((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\:\/\/)(www|[a-zA-Z0-9])[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]{1,5})*(\/($|[a-zA-Z0-9\.\,\;\?\''\\\+&%\$#\=~_\-\/]+))*/";
441 regexEmail = "/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/";
446 [mat_start,mat_end,mat_match] = regexp(txtin,regexUrl);
448 if ~isempty(mat_match) then
449 mat_end = [ 0 mat_end ];
450 for i=1:size(mat_match,"*")
451 txtout = txtout + part(txtin,[mat_end(i)+1:mat_start(i)-1]) ..
452 + "<a href="""+mat_match(i)+""" target=""_blank"">" ..
456 txtout = txtout + part(txtin,mat_end(size(mat_end,"*"))+1:length(txtin));
463 [mat_start,mat_end,mat_match] = regexp(txtin,regexEmail);
465 if ~isempty(mat_match) then
466 mat_end = [ 0 mat_end ];
467 for i=1:size(mat_match,"*")
468 txtout = txtout + part(txtin,[mat_end(i)+1:mat_start(i)-1]) ..
469 + "<a href=""mailto:"+mat_match(i)+""" target=""_blank"">" ..
473 txtout = txtout + part(txtin,mat_end(size(mat_end,"*"))+1:length(txtin));