- Timestamp:
- Mar 19, 2012 10:39:18 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp
r40202 r40527 762 762 /* Get selected items: */ 763 763 QList<UIVMItem*> items = m_pVMListView->currentItems(); 764 AssertMsgReturnVoid(pItem, ("Current item should be selected!\n")); 765 764 /* Enable/disable 'Machine/Close' menu according logic: */ 766 765 m_pMachineCloseMenuAction->setEnabled(isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, pItem, items)); 767 766 } … … 1791 1790 bool UISelectorWindow::isActionEnabled(int iActionIndex, UIVMItem *pItem, const QList<UIVMItem*> &items) 1792 1791 { 1793 switch (iActionIndex) 1794 { 1795 case UIActionIndexSelector_Simple_Machine_SettingsDialog: 1796 { 1797 /* Check that there is only one item, its accessible 1798 * and machine is not in 'stuck' or 'saved' state. 1799 * Modifying VM settings in 'saved' state will be available later. */ 1800 return items.size() == 1 && 1801 pItem && pItem->accessible() && 1802 pItem->machineState() != KMachineState_Stuck && 1803 pItem->machineState() != KMachineState_Saved; 1804 } 1805 case UIActionIndexSelector_Simple_Machine_CloneWizard: 1806 { 1807 /* Check that there is only one item, its accessible 1808 * and session state is unlocked. */ 1809 return items.size() == 1 && 1810 pItem && pItem->accessible() && 1811 pItem->sessionState() == KSessionState_Unlocked; 1812 } 1813 case UIActionIndexSelector_Simple_Machine_RemoveDialog: 1814 { 1815 /* Check that item is present and 1816 * machine is not accessible or session state is unlocked. */ 1817 return pItem && 1818 (!pItem->accessible() || pItem->sessionState() == KSessionState_Unlocked); 1819 } 1820 case UIActionIndexSelector_State_Machine_StartOrShow: 1821 { 1822 /* Check that item present and accessible: */ 1823 if (!pItem || !pItem->accessible()) 1824 return false; 1825 1826 /* Check if we are in powered off mode which unifies next possible states. 1827 * Then if session state is unlocked we can allow to start VM. */ 1828 if (pItem->machineState() == KMachineState_PoweredOff || 1829 pItem->machineState() == KMachineState_Saved || 1830 pItem->machineState() == KMachineState_Teleported || 1831 pItem->machineState() == KMachineState_Aborted) 1832 return pItem->sessionState() == KSessionState_Unlocked; 1833 1834 /* Otherwise we are in running mode and 1835 * should allow to switch to VM if its possible: */ 1836 return pItem->canSwitchTo(); 1837 } 1838 case UIActionIndexSelector_Simple_Machine_Discard: 1839 { 1840 /* Check that there is only one item, its accessible 1841 * and machine is in 'saved' state and session state is unlocked. */ 1842 return items.size() == 1 && 1843 pItem && pItem->accessible() && 1844 pItem->machineState() == KMachineState_Saved && 1845 pItem->sessionState() == KSessionState_Unlocked; 1846 } 1847 case UIActionIndexSelector_Toggle_Machine_PauseAndResume: 1848 { 1849 /* Check that item present and accessible 1850 * and machine is in 'running' or 'paused' mode which unifies next possible states. */ 1851 return pItem && pItem->accessible() && 1852 (pItem->machineState() == KMachineState_Running || 1853 pItem->machineState() == KMachineState_Teleporting || 1854 pItem->machineState() == KMachineState_LiveSnapshotting || 1855 pItem->machineState() == KMachineState_Paused || 1856 pItem->machineState() == KMachineState_TeleportingPausedVM); 1857 } 1858 case UIActionIndexSelector_Simple_Machine_Reset: 1859 { 1860 /* Check that item present and accessible 1861 * and machine is in 'running' mode which unifies next possible states. */ 1862 return pItem && pItem->accessible() && 1863 (pItem->machineState() == KMachineState_Running || 1864 pItem->machineState() == KMachineState_Teleporting || 1865 pItem->machineState() == KMachineState_LiveSnapshotting); 1866 } 1867 case UIActionIndexSelector_Menu_Machine_Close: 1868 { 1869 /* Check that item present and accessible 1870 * and machine is in 'running' or 'paused' state. */ 1871 return pItem && pItem->accessible() && 1872 (pItem->machineState() == KMachineState_Running || 1873 pItem->machineState() == KMachineState_Paused); 1874 } 1875 case UIActionIndexSelector_Simple_Machine_Close_ACPIShutdown: 1876 { 1877 /* Check that 'Machine/Close' menu is enabled: */ 1878 if (!isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, pItem, items)) 1879 return false; 1880 1881 /* Check if we are entered ACPI mode already. 1882 * Only then it make sense to send the ACPI shutdown sequence: */ 1883 bool fEnteredACPIMode = false; 1884 CSession session = vboxGlobal().openExistingSession(pItem->id()); 1885 if (!session.isNull()) 1792 if (pItem) 1793 { 1794 switch (iActionIndex) 1795 { 1796 case UIActionIndexSelector_Simple_Machine_SettingsDialog: 1886 1797 { 1887 CConsole console = session.GetConsole(); 1888 if (!console.isNull()) 1889 fEnteredACPIMode = console.GetGuestEnteredACPIMode(); 1890 session.UnlockMachine(); 1798 /* Check that there is only one item, its accessible 1799 * and machine is not in 'stuck' or 'saved' state. 1800 * Modifying VM settings in 'saved' state will be available later. */ 1801 return items.size() == 1 && 1802 pItem && pItem->accessible() && 1803 pItem->machineState() != KMachineState_Stuck && 1804 pItem->machineState() != KMachineState_Saved; 1891 1805 } 1892 else 1893 msgCenter().cannotOpenSession(session); 1894 1895 return fEnteredACPIMode; 1896 } 1897 case UIActionIndexSelector_Simple_Machine_Close_PowerOff: 1898 { 1899 /* The same as 'Machine/Close' menu is enabled: */ 1900 return isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, pItem, items); 1901 } 1902 case UIActionIndexSelector_Simple_Machine_Refresh: 1903 { 1904 /* Check if item present and NOT accessible: */ 1905 return pItem && !pItem->accessible(); 1906 } 1907 case UIActionIndexSelector_Simple_Machine_LogDialog: 1908 case UIActionIndexSelector_Simple_Machine_ShowInFileManager: 1909 case UIActionIndexSelector_Simple_Machine_Sort: 1910 { 1911 /* Check if item present and accessible: */ 1912 return pItem && pItem->accessible(); 1913 } 1914 case UIActionIndexSelector_Simple_Machine_CreateShortcut: 1915 { 1806 case UIActionIndexSelector_Simple_Machine_CloneWizard: 1807 { 1808 /* Check that there is only one item, its accessible 1809 * and session state is unlocked. */ 1810 return items.size() == 1 && 1811 pItem && pItem->accessible() && 1812 pItem->sessionState() == KSessionState_Unlocked; 1813 } 1814 case UIActionIndexSelector_Simple_Machine_RemoveDialog: 1815 { 1816 /* Check that item is present and 1817 * machine is not accessible or session state is unlocked. */ 1818 return pItem && 1819 (!pItem->accessible() || pItem->sessionState() == KSessionState_Unlocked); 1820 } 1821 case UIActionIndexSelector_State_Machine_StartOrShow: 1822 { 1823 /* Check that item present and accessible: */ 1824 if (!pItem || !pItem->accessible()) 1825 return false; 1826 1827 /* Check if we are in powered off mode which unifies next possible states. 1828 * Then if session state is unlocked we can allow to start VM. */ 1829 if (pItem->machineState() == KMachineState_PoweredOff || 1830 pItem->machineState() == KMachineState_Saved || 1831 pItem->machineState() == KMachineState_Teleported || 1832 pItem->machineState() == KMachineState_Aborted) 1833 return pItem->sessionState() == KSessionState_Unlocked; 1834 1835 /* Otherwise we are in running mode and 1836 * should allow to switch to VM if its possible: */ 1837 return pItem->canSwitchTo(); 1838 } 1839 case UIActionIndexSelector_Simple_Machine_Discard: 1840 { 1841 /* Check that there is only one item, its accessible 1842 * and machine is in 'saved' state and session state is unlocked. */ 1843 return items.size() == 1 && 1844 pItem && pItem->accessible() && 1845 pItem->machineState() == KMachineState_Saved && 1846 pItem->sessionState() == KSessionState_Unlocked; 1847 } 1848 case UIActionIndexSelector_Toggle_Machine_PauseAndResume: 1849 { 1850 /* Check that item present and accessible 1851 * and machine is in 'running' or 'paused' mode which unifies next possible states. */ 1852 return pItem && pItem->accessible() && 1853 (pItem->machineState() == KMachineState_Running || 1854 pItem->machineState() == KMachineState_Teleporting || 1855 pItem->machineState() == KMachineState_LiveSnapshotting || 1856 pItem->machineState() == KMachineState_Paused || 1857 pItem->machineState() == KMachineState_TeleportingPausedVM); 1858 } 1859 case UIActionIndexSelector_Simple_Machine_Reset: 1860 { 1861 /* Check that item present and accessible 1862 * and machine is in 'running' mode which unifies next possible states. */ 1863 return pItem && pItem->accessible() && 1864 (pItem->machineState() == KMachineState_Running || 1865 pItem->machineState() == KMachineState_Teleporting || 1866 pItem->machineState() == KMachineState_LiveSnapshotting); 1867 } 1868 case UIActionIndexSelector_Menu_Machine_Close: 1869 { 1870 /* Check that item present and accessible 1871 * and machine is in 'running' or 'paused' state. */ 1872 return pItem && pItem->accessible() && 1873 (pItem->machineState() == KMachineState_Running || 1874 pItem->machineState() == KMachineState_Paused); 1875 } 1876 case UIActionIndexSelector_Simple_Machine_Close_ACPIShutdown: 1877 { 1878 /* Check that 'Machine/Close' menu is enabled: */ 1879 if (!isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, pItem, items)) 1880 return false; 1881 1882 /* Check if we are entered ACPI mode already. 1883 * Only then it make sense to send the ACPI shutdown sequence: */ 1884 bool fEnteredACPIMode = false; 1885 CSession session = vboxGlobal().openExistingSession(pItem->id()); 1886 if (!session.isNull()) 1887 { 1888 CConsole console = session.GetConsole(); 1889 if (!console.isNull()) 1890 fEnteredACPIMode = console.GetGuestEnteredACPIMode(); 1891 session.UnlockMachine(); 1892 } 1893 else 1894 msgCenter().cannotOpenSession(session); 1895 1896 return fEnteredACPIMode; 1897 } 1898 case UIActionIndexSelector_Simple_Machine_Close_PowerOff: 1899 { 1900 /* The same as 'Machine/Close' menu is enabled: */ 1901 return isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, pItem, items); 1902 } 1903 case UIActionIndexSelector_Simple_Machine_Refresh: 1904 { 1905 /* Check if item present and NOT accessible: */ 1906 return pItem && !pItem->accessible(); 1907 } 1908 case UIActionIndexSelector_Simple_Machine_LogDialog: 1909 case UIActionIndexSelector_Simple_Machine_ShowInFileManager: 1910 case UIActionIndexSelector_Simple_Machine_Sort: 1911 { 1912 /* Check if item present and accessible: */ 1913 return pItem && pItem->accessible(); 1914 } 1915 case UIActionIndexSelector_Simple_Machine_CreateShortcut: 1916 { 1916 1917 #ifdef Q_WS_MAC 1917 /* On Mac OS X this are real alias files, which don't work with the old1918 * legacy xml files. On the other OS's some kind of start up script is used. */1919 return pItem && pItem->accessible() &&1920 pItem->settingsFile().endsWith(".vbox", Qt::CaseInsensitive);1918 /* On Mac OS X this are real alias files, which don't work with the old 1919 * legacy xml files. On the other OS's some kind of start up script is used. */ 1920 return pItem && pItem->accessible() && 1921 pItem->settingsFile().endsWith(".vbox", Qt::CaseInsensitive); 1921 1922 #else /* Q_WS_MAC */ 1922 return pItem && pItem->accessible();1923 return pItem && pItem->accessible(); 1923 1924 #endif /* Q_WS_MAC */ 1924 } 1925 default: 1926 break; 1925 } 1926 default: 1927 break; 1928 } 1927 1929 } 1928 1930 return false;
Note:
See TracChangeset
for help on using the changeset viewer.