/** * @fileOverview Common classes and objects used * @author Ian Moore (imoore76 at yahoo dot com) * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com) */ /** * Host details sections used on details tab * * @namespace vboxHostDetailsSections */ var vboxHostDetailsSections = { /* * General */ hostgeneral: { icon: 'machine_16px.png', title: 'General', settingsLink: 'General', rows: [ { title: 'Name', callback: function() { return $('#vboxPane').data('vboxConfig').name; }, condition: function() { return $('#vboxPane').data('vboxConfig').servers.length; } },{ title: 'OS Type', callback: function(d) { return d['operatingSystem'] + ' (' + d['OSVersion'] +')'; } },{ title: 'VirtualBox', callback: function() { return $('#vboxPane').data('vboxConfig').version.string+' ('+$('#vboxPane').data('vboxConfig').version.revision+')'; } },{ title: 'Base Memory', callback: function(d) { return trans('%1 MB').replace('%1',d['memorySize']); } },{ title: '', data: '
' },{ title: "Processor(s)", callback: function(d) { return d['cpus'][0] + ' (' + d['cpus'].length +')'; } },{ title: '', callback: function(d) { // Processor features? var cpuFeatures = new Array(); for(var f in d.cpuFeatures) { if(!d.cpuFeatures[f]) continue; cpuFeatures[cpuFeatures.length] = trans(f); } return cpuFeatures.join(', '); }, condition: function(d) { if(!d.cpuFeatures) return false; for(var f in d.cpuFeatures) { if(!d.cpuFeatures[f]) continue; return true; } return false; } }], onRender: function(d) { // See if timer is already set var eTimer = $('#vboxVMDetails').data('vboxHostMemInfoTimer'); if(eTimer != null) { $('#vboxVMDetails').data('vboxHostMemInfoTimer',null); window.clearInterval(eTimer); } var showFree = $('#vboxPane').data('vboxConfig').hostMemInfoShowFreePct; var memRes = $('#vboxPane').data('vboxConfig').vmMemoryOffset; if(!memRes || parseInt(memRes) < 1) memRes = 0; // Memory used function var vboxHostShowMemInfo = function(avail) { // If target div no longer exists, stop updating if($('#vboxHostMemFreeLbl')[0] == null) { var eTimer = $('#vboxVMDetails').data('vboxHostMemInfoTimer'); $('#vboxVMDetails').data('vboxHostMemInfoTimer',null); window.clearInterval(eTimer); return; } // Subtract reserved memory? avail -= memRes; avail = Math.max(0,avail); var mUsed = d['memorySize'] - (avail + memRes); var mUsedPct = Math.round(parseInt((mUsed / d['memorySize']) * 100)); var memResPct = 0; if(memRes > 0) { memResPct = Math.round(parseInt((memRes / d['memorySize']) * 100)); } // Add tooltip with info var tip = trans('%1 MB').replace('%1',mUsed); if(memResPct) tip += ' | ' + trans('%1 MB').replace('%1',memRes); tip += ' | ' + trans('%1 MB').replace('%1',avail); $('#vboxHostMemUsed').tipped({'source':tip,'position':'mouse'}); // Update tooltip content in case tooltip is already showing var cid = $($('#tipped').data('original')).attr('id'); if(cid && cid == 'vboxHostMemUsed') $('#tipped-content').html(tip); // Width(s) $('#vboxHostMemUsedPct').css({'width':((mUsedPct+memResPct)*2)+'px'}); if(memRes > 0) { $('#vboxHostMemResPct').css({'width':''+(memResPct*2)+'px'}); } else { $('#vboxHostMemResPct').hide(); } // Labels if(!showFree) { $('#vboxHostMemUsedLblPct').html(trans('%1 MB').replace('%1',(mUsed)) + ' ('+trans('%1%').replace('%1',mUsedPct)+')'); $('#vboxHostMemFreeLbl').html(trans('%1 MB').replace('%1',avail)); } else { $('#vboxHostMemUsedLblPct').html(trans('%1 MB').replace('%1',mUsed)); $('#vboxHostMemFreeLbl').html('('+trans('%1%').replace('%1',Math.round(parseInt((avail / d['memorySize']) * 100)))+') ' + trans('%1 MB').replace('%1',avail)); } }; // Refresh at configured intervals var interval = 5; try { interval = Math.max(3,parseInt($('#vboxPane').data('vboxConfig').hostMemInfoRefreshInterval)); } catch (e) { interval = 5; } var vboxHostUpdateMeminfo = function() { $.when(vboxAjaxRequest('hostGetMeminfo')).done(function(d){ vboxHostShowMemInfo(d.responseData); }); }; vboxHostUpdateMeminfo(); // Failsafe if(isNaN(interval) || interval < 3) interval = 5; $('#vboxVMDetails').data('vboxHostMemInfoTimer',window.setInterval(vboxHostUpdateMeminfo,interval*1000)); } }, hostnetwork: { title: 'Network', icon: 'nw_16px.png', rows: function(d) { var netRows = []; d['networkInterfaces'].sort(function(a,b){ return strnatcasecmp(a.name, b.name); }); for(var i = 0; i < d['networkInterfaces'].length; i++) { /* Interface Name */ netRows[netRows.length] = { title: d['networkInterfaces'][i].name + ' (' + trans(d['networkInterfaces'][i].status) + ')', data: '' }; /* IPv4 Addr */ if(d['networkInterfaces'][i].IPAddress){ netRows[netRows.length] = { title: trans('IPv4 Address','UIGlobalSettingsNetwork'), data: d['networkInterfaces'][i].IPAddress + ' / ' + d['networkInterfaces'][i].networkMask, indented: true }; } /* IPv6 Address */ if(d['networkInterfaces'][i].IPV6Supported && d['networkInterfaces'][i].IPV6Address) { netRows[netRows.length] = { title: trans('IPv6 Address','UIGlobalSettingsNetwork'), data: d['networkInterfaces'][i].IPV6Address + ' / ' + d['networkInterfaces'][i].IPV6NetworkMaskPrefixLength, indented: true }; } /* Physical info */ netRows[netRows.length] = { title: '', data: trans(d['networkInterfaces'][i].mediumType) + (d['networkInterfaces'][i].hardwareAddress ? ' (' + d['networkInterfaces'][i].hardwareAddress + ')': ''), indented: true }; } return netRows; } }, hostdvddrives: { title: 'DVD', icon: 'cd_16px.png', language_context: 'UIApplianceEditorWidget', condition: function(d) { return d['DVDDrives'].length; }, rows: function(d) { var dvdRows = []; for(var i = 0; i < d['DVDDrives'].length; i++) { dvdRows[dvdRows.length] = { title: vboxMedia.getName(vboxMedia.getMediumById(d['DVDDrives'][i].id)), data: '' }; } return dvdRows; } }, hostfloppydrives: { title: 'Floppy', language_context: 'UIApplianceEditorWidget', icon: "fd_16px.png", condition: function(d) { return d['floppyDrives'].length; }, rows: function(d) { var fRows = []; for(var i = 0; i < d['floppyDrives'].length; i++) { fRows[fRows.length] = { title: vboxMedia.getName(vboxMedia.getMediumById(d['floppyDrives'][i].id)), data: '' }; } return fRows; } } }; /** * VM details sections used on details tab and snapshot pages * * @namespace vboxVMDetailsInfo */ var vboxVMDetailsSections = { /* * General */ general: { title: 'General', icon: 'machine_16px.png', settingsLink: 'General', multiSelectDetailsTable: true, rows: [ { title: 'Name', attrib: 'name' },{ title: 'OS Type', attrib: 'OSTypeDesc' },{ title: 'Guest Additions Version', attrib: 'guestAdditionsVersion' },{ title: 'Groups', language_context: 'UIGDetails', condition: function(d){ return (d.groups.length > 1 || (d.groups.length == 1 && d.groups[0] != '/')); }, callback: function(d) { if(d.groups && d.groups.length > 0) return jQuery.map(d.groups,function(elm) { if(elm.length > 1) return elm.substring(1); return elm; }).join(', '); } } ] }, /* * System */ system: { title: 'System', icon: 'chipset_16px.png', settingsLink: 'System', redrawMachineEvents: ['OnCPUExecutionCapChanged'], multiSelectDetailsTable: true, rows: [ { title: 'Base Memory', callback: function(d) { return trans('%1 MB').replace('%1',d['memorySize']); } },{ title: "Processor(s)", attrib: 'CPUCount', condition: function(d) { return d.CPUCount > 1; } },{ title: "Execution Cap", callback: function(d) { return trans('%1%').replace('%1',parseInt(d['CPUExecutionCap'])); }, condition: function(d) { return d.CPUExecutionCap < 100; } },{ title: "Boot Order", callback: function(d) { var bo = new Array(); for(var i = 0; i < d['bootOrder'].length; i++) { bo[i] = trans(vboxDevice(d['bootOrder'][i])); } return bo.join(', '); } },{ title: "Acceleration", language_context: 'UIGDetails', callback: function(d) { var acList = []; if(d['HWVirtExProperties'].Enabled) acList[acList.length] = trans('VT-x/AMD-V'); if(d['HWVirtExProperties'].NestedPaging) acList[acList.length] = trans('Nested Paging'); if(d['CpuProperties']['PAE']) acList[acList.length] = trans('PAE/NX'); if(d['EffectiveParavirtProvider'] != 'None') acList[acList.length] = trans(d['EffectiveParavirtProvider'] + ' Paravirtualization'); if($('#vboxPane').data('vboxConfig').enableAdvancedConfig) { if(d['HWVirtExProperties'].LargePages) acList[acList.length] = trans('Large Pages'); if(d['HWVirtExProperties'].UnrestrictedExecution) acList[acList.length] = trans('VT-x unrestricted execution'); if(d['HWVirtExProperties'].VPID) acList[acList.length] = trans('VT-x VPID'); } return acList.join(', '); }, condition: function(d) { return (d['HWVirtExProperties'].Enabled || d['CpuProperties']['PAE']); } } ] }, /* * Preview box */ preview: { title: 'Preview', icon: 'fullscreen_16px.png', _resolutionCache: {}, settingsLink: 'Display', multiSelectDetailsTable: true, noSnapshot: true, noFooter: true, _updateInterval: undefined, _screenPadding: 17, // padding around actual screenshot in px condition: function() { // Update our default updateInterval here if(vboxVMDetailsSections.preview._updateInterval === undefined) { // Try local data first var updateInterval = vboxGetLocalDataItem('previewUpdateInterval'); if(updateInterval === null || updateInterval === undefined) { updateInterval = $('#vboxPane').data('vboxConfig').previewUpdateInterval; if(updateInterval === null || updateInterval === undefined) { updateInterval = 3; } vboxSetLocalDataItem('previewUpdateInterval', parseInt(updateInterval)); } vboxVMDetailsSections.preview._updateInterval = parseInt(updateInterval); } return !($('#vboxPane').data('vboxConfig').noPreview); }, /** * Function triggered on VM state change * */ vboxEventOnMachineStateChanged: function(eventData) { var timer = $('#vboxPane').data('vboxPreviewTimer-'+eventData.machineId); if(timer) { $('#vboxPane').data('vboxPreviewTimer-'+eventData.machineId, null); window.clearInterval(timer); } vboxVMDetailsSections.preview._drawPreview(eventData.machineId); // Kick off timer if VM is running if(vboxVMStates.isRunning(eventData)) { window.setTimeout(function(){ $('#vboxPane').data('vboxPreviewTimer-'+eventData.machineId, window.setInterval('vboxVMDetailsSections.preview._drawPreview("'+eventData.machineId+'")',vboxVMDetailsSections.preview._updateInterval*1000)); },vboxVMDetailsSections.preview._updateInterval*1000); } }, /* * * Preivew Update Menu * */ contextMenu: function() { var menu = $('#vboxDetailsPreviewMenu'); if(menu[0]) return menu; /* Menu List */ var ul = $('