Changeset 34543 in vbox for trunk/src/VBox
- Timestamp:
- Dec 1, 2010 12:32:54 AM (14 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 6 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r34479 r34543 301 301 src/settings/global/UIGlobalSettingsNetwork.h \ 302 302 src/settings/global/UIGlobalSettingsNetworkDetails.h \ 303 src/settings/global/UIGlobalSettingsExtension.h \ 303 304 src/settings/machine/UIMachineSettingsGeneral.h \ 304 305 src/settings/machine/UIMachineSettingsSystem.h \ … … 464 465 src/settings/global/UIGlobalSettingsNetwork.cpp \ 465 466 src/settings/global/UIGlobalSettingsNetworkDetails.cpp \ 467 src/settings/global/UIGlobalSettingsExtension.cpp \ 466 468 src/settings/machine/UIMachineSettingsGeneral.cpp \ 467 469 src/settings/machine/UIMachineSettingsSystem.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/VBoxUI.pro
r33882 r34543 35 35 src/settings/global/UIGlobalSettingsNetwork.ui \ 36 36 src/settings/global/UIGlobalSettingsNetworkDetails.ui \ 37 src/settings/global/UIGlobalSettingsExtension.ui \ 37 38 src/settings/machine/UIMachineSettingsGeneral.ui \ 38 39 src/settings/machine/UIMachineSettingsSystem.ui \ -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxProblemReporter.cpp
r34519 r34543 2418 2418 } 2419 2419 2420 void VBoxProblemReporter::cannotUninstallExtPack(const QString &strPackName, const CExtPackManager &extPackManager, QWidget *pParent /* = 0 */) 2421 { 2422 message (pParent ? pParent : mainWindowShown(), 2423 Error, 2424 tr("Failed to uninstall the Extension Pack <b>%1</b>.").arg(strPackName), 2425 formatErrorInfo(extPackManager)); 2426 } 2427 2428 bool VBoxProblemReporter::confirmRemovingPackage(const QString &strPackName, QWidget *pParent /* = 0 */) 2429 { 2430 return messageOkCancel (pParent ? pParent : mainWindowShown(), 2431 Question, 2432 tr("You are about to remove the Extension Pack <b>%1</b>. Are you sure you want to do that?").arg(strPackName), 2433 0, 2434 tr("&Remove")); 2435 } 2436 2420 2437 void VBoxProblemReporter::warnAboutIncorrectPort (QWidget *pParent) const 2421 2438 { -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxProblemReporter.h
r34519 r34543 384 384 385 385 void cannotInstallExtPack(const QString &strFilename, const CExtPackManager &extPackManager, QWidget *pParent = 0); 386 void cannotUninstallExtPack(const QString &strPackName, const CExtPackManager &extPackManager, QWidget *pParent = 0); 387 bool confirmRemovingPackage(const QString &strPackName, QWidget *pParent = 0); 386 388 387 389 void warnAboutIncorrectPort(QWidget *pParent) const; -
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp
r33932 r34543 37 37 #include "UIGlobalSettingsLanguage.h" 38 38 #include "UIGlobalSettingsNetwork.h" 39 #include "UIGlobalSettingsExtension.h" 39 40 40 41 #include "UIMachineSettingsGeneral.h" … … 360 361 break; 361 362 } 363 /* Extension page: */ 364 case GLSettingsPage_Extension: 365 { 366 UISettingsPage *pSettingsPage = new UIGlobalSettingsExtension; 367 pSettingsPage->setId(i); 368 addItem(":/shared_folder_32px.png", ":/shared_folder_disabled_32px.png", 369 ":/shared_folder_16px.png", ":/shared_folder_disabled_16px.png", 370 i, "#extension", pSettingsPage); 371 break; 372 } 362 373 default: 363 374 break; … … 441 452 m_pSelector->setItemText(GLSettingsPage_Network, tr("Network")); 442 453 454 /* Extension page: */ 455 m_pSelector->setItemText(GLSettingsPage_Extension, tr("Extensions")); 456 443 457 /* Translate the selector: */ 444 458 m_pSelector->polish(); -
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.h
r33631 r34543 39 39 GLSettingsPage_USB, 40 40 GLSettingsPage_Network, 41 GLSettingsPage_Extension, 41 42 GLSettingsPage_MAX 42 43 }; -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsExtension.cpp
r34512 r34543 3 3 * 4 4 * VBox frontends: Qt4 GUI ("VirtualBox"): 5 * UIGlobalSettings Languageclass implementation5 * UIGlobalSettingsExtension class implementation 6 6 */ 7 7 8 8 /* 9 * Copyright (C) 20 06-2010 Oracle Corporation9 * Copyright (C) 2010 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 19 19 20 20 /* Global includes */ 21 #include <QDir>22 21 #include <QHeaderView> 23 #include <QPainter>24 #include <QTranslator>25 26 #include <iprt/err.h>27 #include <iprt/param.h>28 #include <iprt/path.h>29 #include <VBox/version.h>30 22 31 23 /* Local includes */ 32 #include "UIGlobalSettingsLanguage.h" 33 #include "VBoxGlobalSettings.h" 24 #include "UIGlobalSettingsExtension.h" 25 #include "UIIconPool.h" 26 #include "QIFileDialog.h" 34 27 #include "VBoxGlobal.h" 35 36 extern const char *gVBoxLangSubDir; 37 extern const char *gVBoxLangFileBase; 38 extern const char *gVBoxLangFileExt; 39 extern const char *gVBoxLangIDRegExp; 40 extern const char *gVBoxBuiltInLangName; 41 42 /* Language item: */ 43 class UILanguageItem : public QTreeWidgetItem 28 #include "VBoxProblemReporter.h" 29 30 /* Extension package item: */ 31 class UIExtensionPackageItem : public QTreeWidgetItem 44 32 { 45 33 public: 46 34 47 /* Language item type: */ 48 enum { UILanguageItemType = QTreeWidgetItem::UserType + 1 }; 49 50 /* Language item constructor: */ 51 UILanguageItem(QTreeWidget *pParent, const QTranslator &translator, 52 const QString &strId, bool fBuiltIn = false) 53 : QTreeWidgetItem(pParent, UILanguageItemType), m_fBuiltIn(fBuiltIn) 54 { 55 Assert (!strId.isEmpty()); 56 57 /* Note: context/source/comment arguments below must match strings 58 * used in VBoxGlobal::languageName() and friends (the latter are the 59 * source of information for the lupdate tool that generates 60 * translation files) */ 61 62 QString strNativeLanguage = tratra(translator, "@@@", "English", "Native language name"); 63 QString strNativeCountry = tratra(translator, "@@@", "--", "Native language country name " 64 "(empty if this language is for all countries)"); 65 66 QString strEnglishLanguage = tratra(translator, "@@@", "English", "Language name, in English"); 67 QString strEnglishCountry = tratra(translator, "@@@", "--", "Language country name, in English " 68 "(empty if native country name is empty)"); 69 70 QString strTranslatorsName = tratra(translator, "@@@", "Oracle Corporation", "Comma-separated list of translators"); 71 72 QString strItemName = strNativeLanguage; 73 QString strLanguageName = strEnglishLanguage; 74 75 if (!m_fBuiltIn) 35 /* Extension package item type: */ 36 enum { UIItemType = QTreeWidgetItem::UserType + 1 }; 37 38 /* Extension package item constructor: */ 39 UIExtensionPackageItem(QTreeWidget *pParent, const UISettingsCacheGlobalExtensionItem &data) 40 : QTreeWidgetItem(pParent, UIItemType) 41 , m_data(data) 42 { 43 /* Icon: */ 44 setIcon(0, UIIconPool::iconSet(m_data.m_fIsUsable ? 45 ":/shared_folder_16px.png" : 46 ":/shared_folder_disabled_16px.png")); 47 48 /* Name: */ 49 setText(1, m_data.m_strName); 50 51 /* Version: */ 52 setText(2, m_data.m_strVersion); 53 54 /* Tool-tip: */ 55 QString strTip = m_data.m_strDescription; 56 if (!m_data.m_fIsUsable) 76 57 { 77 if (strNativeCountry != "--") 78 strItemName += " (" + strNativeCountry + ")"; 79 80 if (strEnglishCountry != "--") 81 strLanguageName += " (" + strEnglishCountry + ")"; 82 83 if (strItemName != strLanguageName) 84 strLanguageName = strItemName + " / " + strLanguageName; 58 strTip += QString("<hr>"); 59 strTip += m_data.m_strWhyUnusable; 85 60 } 86 else 87 { 88 strItemName += UIGlobalSettingsLanguage::tr(" (built-in)", "Language"); 89 strLanguageName += UIGlobalSettingsLanguage::tr(" (built-in)", "Language"); 90 } 91 92 setText(0, strItemName); 93 setText(1, strId); 94 setText(2, strLanguageName); 95 setText(3, strTranslatorsName); 96 97 /* Current language appears in bold: */ 98 if (text(1) == VBoxGlobal::languageId()) 99 { 100 QFont fnt = font(0); 101 fnt.setBold(true); 102 setFont(0, fnt); 103 } 104 } 105 106 /* Constructs an item for an invalid language ID 107 * (i.e. when a language file is missing or corrupt): */ 108 UILanguageItem(QTreeWidget *pParent, const QString &strId) 109 : QTreeWidgetItem(pParent, UILanguageItemType), m_fBuiltIn(false) 110 { 111 Assert(!strId.isEmpty()); 112 113 setText(0, QString("<%1>").arg(strId)); 114 setText(1, strId); 115 setText(2, UIGlobalSettingsLanguage::tr("<unavailable>", "Language")); 116 setText(3, UIGlobalSettingsLanguage::tr("<unknown>", "Author(s)")); 117 118 /* Invalid language appears in italic: */ 119 QFont fnt = font(0); 120 fnt.setItalic(true); 121 setFont(0, fnt); 122 } 123 124 /* Constructs an item for the default language ID 125 * (column 1 will be set to QString::null): */ 126 UILanguageItem(QTreeWidget *pParent) 127 : QTreeWidgetItem(pParent, UILanguageItemType), m_fBuiltIn(false) 128 { 129 setText(0, UIGlobalSettingsLanguage::tr("Default", "Language")); 130 setText(1, QString::null); 131 /* Empty strings of some reasonable length to prevent the info part 132 * from being shrinked too much when the list wants to be wider */ 133 setText(2, " "); 134 setText(3, " "); 135 } 136 137 bool isBuiltIn() const { return m_fBuiltIn; } 138 139 bool operator<(const QTreeWidgetItem &other) const 140 { 141 QString thisId = text(1); 142 QString thatId = other.text(1); 143 if (thisId.isNull()) 144 return true; 145 if (thatId.isNull()) 146 return false; 147 if (m_fBuiltIn) 148 return true; 149 if (other.type() == UILanguageItemType && ((UILanguageItem*)&other)->m_fBuiltIn) 150 return false; 151 return QTreeWidgetItem::operator<(other); 152 } 61 setToolTip(0, strTip); 62 setToolTip(1, strTip); 63 setToolTip(2, strTip); 64 } 65 66 QString name() const { return m_data.m_strName; } 153 67 154 68 private: 155 69 156 QString tratra(const QTranslator &translator, const char *pCtxt, 157 const char *pSrc, const char *pCmnt) 158 { 159 QString strMsg = translator.translate(pCtxt, pSrc, pCmnt); 160 /* Return the source text if no translation is found: */ 161 if (strMsg.isEmpty()) 162 strMsg = QString(pSrc); 163 return strMsg; 164 } 165 166 bool m_fBuiltIn : 1; 70 UISettingsCacheGlobalExtensionItem m_data; 167 71 }; 168 72 169 /* Languagepage constructor: */170 UIGlobalSettings Language::UIGlobalSettingsLanguage()171 : m_ fIsLanguageChanged(false)73 /* Extension page constructor: */ 74 UIGlobalSettingsExtension::UIGlobalSettingsExtension() 75 : m_pActionAdd(0), m_pActionRemove(0) 172 76 { 173 77 /* Apply UI decorations: */ 174 Ui::UIGlobalSettingsLanguage::setupUi(this); 175 176 /* Setup widgets: */ 177 m_pLanguageTree->header()->hide(); 178 m_pLanguageTree->hideColumn(1); 179 m_pLanguageTree->hideColumn(2); 180 m_pLanguageTree->hideColumn(3); 181 182 /* Setup connections: */ 183 connect(m_pLanguageTree, SIGNAL(painted(QTreeWidgetItem*, QPainter*)), 184 this, SLOT(sltLanguageItemPainted(QTreeWidgetItem*, QPainter*))); 185 connect(m_pLanguageTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), 186 this, SLOT(sltCurrentLanguageChanged(QTreeWidgetItem*))); 78 Ui::UIGlobalSettingsExtension::setupUi(this); 79 80 /* Setup tree-widget: */ 81 //m_pPackagesTree->header()->hide(); 82 m_pPackagesTree->header()->setStretchLastSection(false); 83 m_pPackagesTree->header()->setResizeMode(0, QHeaderView::ResizeToContents); 84 m_pPackagesTree->header()->setResizeMode(1, QHeaderView::Stretch); 85 m_pPackagesTree->header()->setResizeMode(2, QHeaderView::ResizeToContents); 86 m_pPackagesTree->setContextMenuPolicy(Qt::CustomContextMenu); 87 connect(m_pPackagesTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), 88 this, SLOT(sltHandleCurrentItemChange(QTreeWidgetItem*))); 89 connect(m_pPackagesTree, SIGNAL(customContextMenuRequested(const QPoint&)), 90 this, SLOT(sltShowContextMenu(const QPoint&))); 91 92 /* Setup tool-bar: */ 93 m_pPackagesToolbar->setUsesTextLabel(false); 94 m_pPackagesToolbar->setIconSize(QSize(16, 16)); 95 m_pActionAdd = m_pPackagesToolbar->addAction(UIIconPool::iconSet(":/controller_add_16px.png", 96 ":/controller_add_disabled_16px.png"), 97 QString(), this, SLOT(sltInstallPackage())); 98 m_pActionRemove = m_pPackagesToolbar->addAction(UIIconPool::iconSet(":/controller_remove_16px.png", 99 ":/controller_remove_disabled_16px.png"), 100 QString(), this, SLOT(sltRemovePackage())); 187 101 188 102 /* Apply language settings: */ … … 192 106 /* Load data to cashe from corresponding external object(s), 193 107 * this task COULD be performed in other than GUI thread: */ 194 void UIGlobalSettings Language::loadToCacheFrom(QVariant &data)108 void UIGlobalSettingsExtension::loadToCacheFrom(QVariant &data) 195 109 { 196 110 /* Fetch data to properties & settings: */ … … 198 112 199 113 /* Load to cache: */ 200 m_cache.m_strLanguageId = m_settings.languageId(); 114 const CExtPackManager &manager = vboxGlobal().virtualBox().GetExtensionPackManager(); 115 const CExtPackVector &packages = manager.GetInstalledExtPacks(); 116 for (int i = 0; i < packages.size(); ++i) 117 m_cache.m_items << fetchData(packages[i]); 201 118 202 119 /* Upload properties & settings to data: */ … … 206 123 /* Load data to corresponding widgets from cache, 207 124 * this task SHOULD be performed in GUI thread only: */ 208 void UIGlobalSettings Language::getFromCache()125 void UIGlobalSettingsExtension::getFromCache() 209 126 { 210 127 /* Fetch from cache: */ 211 reload(m_cache.m_strLanguageId); 212 m_pLanguageInfo->setFixedHeight(fontMetrics().height() * 4); 128 for (int i = 0; i < m_cache.m_items.size(); ++i) 129 new UIExtensionPackageItem(m_pPackagesTree, m_cache.m_items[i]); 130 /* If at least one item present: */ 131 if (m_pPackagesTree->topLevelItemCount()) 132 m_pPackagesTree->setCurrentItem(m_pPackagesTree->topLevelItem(0)); 133 /* Update action's availability: */ 134 sltHandleCurrentItemChange(m_pPackagesTree->currentItem()); 213 135 } 214 136 215 137 /* Save data from corresponding widgets to cache, 216 138 * this task SHOULD be performed in GUI thread only: */ 217 void UIGlobalSettingsLanguage::putToCache() 218 { 219 /* Upload to cache: */ 220 QTreeWidgetItem *pCurrentItem = m_pLanguageTree->currentItem(); 221 Assert(pCurrentItem); 222 if (pCurrentItem) 223 m_cache.m_strLanguageId = pCurrentItem->text(1); 139 void UIGlobalSettingsExtension::putToCache() 140 { 141 /* Nothing to put to cache... */ 224 142 } 225 143 226 144 /* Save data from cache to corresponding external object(s), 227 145 * this task COULD be performed in other than GUI thread: */ 228 void UIGlobalSettings Language::saveFromCacheTo(QVariant &data)146 void UIGlobalSettingsExtension::saveFromCacheTo(QVariant &data) 229 147 { 230 148 /* Fetch data to properties & settings: */ 231 149 UISettingsPageGlobal::fetchData(data); 232 150 233 /* Save from cache: */ 234 if (m_fIsLanguageChanged) 235 { 236 m_settings.setLanguageId(m_cache.m_strLanguageId); 237 VBoxGlobal::loadLanguage(m_cache.m_strLanguageId); 238 } 151 /* Nothing to save from cache... */ 239 152 240 153 /* Upload properties & settings to data: */ … … 243 156 244 157 /* Navigation stuff: */ 245 void UIGlobalSettingsLanguage::setOrderAfter(QWidget *pWidget) 246 { 247 setTabOrder(pWidget, m_pLanguageTree); 158 void UIGlobalSettingsExtension::setOrderAfter(QWidget *pWidget) 159 { 160 /* Setup tab-order: */ 161 setTabOrder(pWidget, m_pPackagesTree); 248 162 } 249 163 250 164 /* Translation stuff: */ 251 void UIGlobalSettings Language::retranslateUi()165 void UIGlobalSettingsExtension::retranslateUi() 252 166 { 253 167 /* Translate uic generated strings: */ 254 Ui::UIGlobalSettingsLanguage::retranslateUi(this); 255 256 /* Reload language tree: */ 257 reload(VBoxGlobal::languageId()); 258 } 259 260 /* Reload language tree: */ 261 void UIGlobalSettingsLanguage::reload(const QString &strLangId) 262 { 263 /* Clear languages tree: */ 264 m_pLanguageTree->clear(); 265 266 /* Load languages tree: */ 267 char szNlsPath[RTPATH_MAX]; 268 int rc = RTPathAppPrivateNoArch(szNlsPath, sizeof(szNlsPath)); 269 AssertRC(rc); 270 QString strNlsPath = QString(szNlsPath) + gVBoxLangSubDir; 271 QDir nlsDir(strNlsPath); 272 QStringList files = nlsDir.entryList(QStringList(QString("%1*%2").arg(gVBoxLangFileBase, gVBoxLangFileExt)), QDir::Files); 273 274 QTranslator translator; 275 /* Add the default language: */ 276 new UILanguageItem(m_pLanguageTree); 277 /* Add the built-in language: */ 278 new UILanguageItem(m_pLanguageTree, translator, gVBoxBuiltInLangName, true /* built-in */); 279 /* Add all existing languages */ 280 for (QStringList::Iterator it = files.begin(); it != files.end(); ++it) 281 { 282 QString strFileName = *it; 283 QRegExp regExp(QString(gVBoxLangFileBase) + gVBoxLangIDRegExp); 284 int iPos = regExp.indexIn(strFileName); 285 if (iPos == -1) 286 continue; 287 288 /* Skip any English version, cause this is extra handled: */ 289 QString strLanguage = regExp.cap(2); 290 if (strLanguage.toLower() == "en") 291 continue; 292 293 bool fLoadOk = translator.load(strFileName, strNlsPath); 294 if (!fLoadOk) 295 continue; 296 297 new UILanguageItem(m_pLanguageTree, translator, regExp.cap(1)); 298 } 299 300 /* Adjust selector list: */ 301 #ifdef Q_WS_MAC 302 int width = qMax(static_cast<QAbstractItemView*>(m_pLanguageTree)->sizeHintForColumn(0) + 303 2 * m_pLanguageTree->frameWidth() + QApplication::style()->pixelMetric(QStyle::PM_ScrollBarExtent), 304 220); 305 m_pLanguageTree->setFixedWidth(width); 306 #else /* Q_WS_MAC */ 307 m_pLanguageTree->setMinimumWidth(static_cast<QAbstractItemView*>(m_pLanguageTree)->sizeHintForColumn(0) + 308 2 * m_pLanguageTree->frameWidth() + QApplication::style()->pixelMetric(QStyle::PM_ScrollBarExtent)); 309 #endif /* Q_WS_MAC */ 310 m_pLanguageTree->resizeColumnToContents(0); 311 312 /* Search for necessary language: */ 313 QList<QTreeWidgetItem*> itemsList = m_pLanguageTree->findItems(strLangId, Qt::MatchExactly, 1); 314 QTreeWidgetItem *pItem = itemsList.isEmpty() ? 0 : itemsList[0]; 315 if (!pItem) 316 { 317 /* Add an pItem for an invalid language to represent it in the list: */ 318 pItem = new UILanguageItem(m_pLanguageTree, strLangId); 319 m_pLanguageTree->resizeColumnToContents(0); 320 } 321 Assert(pItem); 168 Ui::UIGlobalSettingsExtension::retranslateUi(this); 169 170 /* Translate actions: */ 171 m_pActionAdd->setText(tr("Add package")); 172 m_pActionRemove->setText(tr("Remove package")); 173 } 174 175 /* Handle current-item change fact: */ 176 void UIGlobalSettingsExtension::sltHandleCurrentItemChange(QTreeWidgetItem *pCurrentItem) 177 { 178 /* Check action's availability: */ 179 //m_pActionAdd->setEnabled(true); 180 m_pActionRemove->setEnabled(pCurrentItem); 181 } 182 183 /* Invoke context menu: */ 184 void UIGlobalSettingsExtension::sltShowContextMenu(const QPoint &position) 185 { 186 QMenu menu; 187 if (m_pPackagesTree->itemAt(position)) 188 { 189 menu.addAction(m_pActionAdd); 190 menu.addAction(m_pActionRemove); 191 } 192 else 193 { 194 menu.addAction(m_pActionAdd); 195 } 196 menu.exec(m_pPackagesTree->viewport()->mapToGlobal(position)); 197 } 198 199 /* Package add procedure: */ 200 void UIGlobalSettingsExtension::sltInstallPackage() 201 { 202 /* Open file-open window to let user to choose package file: */ 203 QString strFilePath; 204 QString strBaseFolder = vboxGlobal().virtualBox().GetHomeFolder(); 205 QString strTitle = tr("Select an extension package file"); 206 QStringList extensions; 207 for (int i = 0; i < VBoxDefs::VBoxExtPackFileExts.size(); ++i) 208 extensions << QString("*.%1").arg(VBoxDefs::VBoxExtPackFileExts[i]); 209 QString strFilter = tr("Extension package files (%1)").arg(extensions.join(" ")); 210 /* Create open file dialog: */ 211 QStringList fileNames = QIFileDialog::getOpenFileNames(strBaseFolder, strFilter, this, strTitle, 0, true, true); 212 if (!fileNames.isEmpty()) 213 strFilePath = fileNames.at(0); 214 215 /* Install chosen package: */ 216 if (!strFilePath.isEmpty()) 217 { 218 /* Get package manager: */ 219 CExtPackManager manager = vboxGlobal().virtualBox().GetExtensionPackManager(); 220 /* Install package & get the name of newly installed package: */ 221 QString strAddedPackageName = manager.Install(strFilePath); 222 if (manager.isOk()) 223 { 224 /* Get the newly added package: */ 225 const CExtPack &package = manager.Find(strAddedPackageName); 226 /* Add newly added package into cache: */ 227 m_cache.m_items << fetchData(package); 228 /* Add newly added package into tree: */ 229 UIExtensionPackageItem *pItem = new UIExtensionPackageItem(m_pPackagesTree, m_cache.m_items.last()); 230 /* Set the newly created item as current: */ 231 m_pPackagesTree->setCurrentItem(pItem); 232 /* Sort the tree by <name> column: */ 233 m_pPackagesTree->sortByColumn(1, Qt::AscendingOrder); 234 } 235 else vboxProblem().cannotInstallExtPack(strFilePath, manager, this); 236 } 237 } 238 239 /* Package remove procedure: */ 240 void UIGlobalSettingsExtension::sltRemovePackage() 241 { 242 /* Get current item: */ 243 UIExtensionPackageItem *pItem = m_pPackagesTree && 244 m_pPackagesTree->currentItem() && 245 m_pPackagesTree->currentItem()->type() == UIExtensionPackageItem::UIItemType ? 246 static_cast<UIExtensionPackageItem*>(m_pPackagesTree->currentItem()) : 0; 247 248 /* Uninstall chosen package: */ 322 249 if (pItem) 323 m_pLanguageTree->setCurrentItem(pItem); 324 325 m_pLanguageTree->sortItems(0, Qt::AscendingOrder); 326 m_pLanguageTree->scrollToItem(pItem); 327 m_fIsLanguageChanged = false; 328 } 329 330 /* Routine to paint language items: */ 331 void UIGlobalSettingsLanguage::sltLanguageItemPainted(QTreeWidgetItem *pItem, QPainter *pPainter) 332 { 333 if (pItem && pItem->type() == UILanguageItem::UILanguageItemType) 334 { 335 UILanguageItem *pLanguageItem = static_cast<UILanguageItem*>(pItem); 336 if (pLanguageItem->isBuiltIn()) 250 { 251 /* Get name of current package: */ 252 QString strSelectedPackageName = pItem->name(); 253 /* Ask the user about package removing: */ 254 if (vboxProblem().confirmRemovingPackage(strSelectedPackageName, this)) 337 255 { 338 QRect rect = m_pLanguageTree->visualItemRect(pLanguageItem); 339 pPainter->setPen(m_pLanguageTree->palette().color(QPalette::Mid)); 340 pPainter->drawLine(rect.x(), rect.y() + rect.height() - 1, 341 rect.x() + rect.width(), rect.y() + rect.height() - 1); 256 /* Get package manager: */ 257 CExtPackManager manager = vboxGlobal().virtualBox().GetExtensionPackManager(); 258 /* Uninstall package: */ 259 manager.Uninstall(strSelectedPackageName, false /* forced removal? */); 260 if (manager.isOk()) 261 { 262 /* Remove selected package from cache: */ 263 for (int i = 0; i < m_cache.m_items.size(); ++i) 264 { 265 if (m_cache.m_items[i].m_strName == strSelectedPackageName) 266 { 267 m_cache.m_items.removeAt(i); 268 break; 269 } 270 } 271 /* Remove selected package from tree: */ 272 delete pItem; 273 } 274 else vboxProblem().cannotUninstallExtPack(strSelectedPackageName, manager, this); 342 275 } 343 276 } 344 277 } 345 278 346 /* Slot to handle currentl language change fact: */ 347 void UIGlobalSettingsLanguage::sltCurrentLanguageChanged(QTreeWidgetItem *pItem) 348 { 349 if (!pItem) return; 350 351 /* Disable labels for the Default language item: */ 352 bool fEnabled = !pItem->text (1).isNull(); 353 354 m_pLanguageInfo->setEnabled(fEnabled); 355 m_pLanguageInfo->setText(QString("<table>" 356 "<tr><td>%1 </td><td>%2</td></tr>" 357 "<tr><td>%3 </td><td>%4</td></tr>" 358 "</table>") 359 .arg(tr("Language:")) 360 .arg(pItem->text(2)) 361 .arg(tr("Author(s):")) 362 .arg(pItem->text(3))); 363 364 m_fIsLanguageChanged = true; 365 } 366 279 UISettingsCacheGlobalExtensionItem UIGlobalSettingsExtension::fetchData(const CExtPack &package) const 280 { 281 UISettingsCacheGlobalExtensionItem item; 282 item.m_strName = package.GetName(); 283 item.m_strDescription = package.GetDescription(); 284 item.m_strVersion = package.GetVersion(); 285 item.m_strRevision = package.GetRevision(); 286 item.m_fIsUsable = package.GetUsable(); 287 if (!item.m_fIsUsable) 288 item.m_strWhyUnusable = package.GetWhyUnusable(); 289 return item; 290 } 291 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsExtension.h
r34512 r34543 2 2 * 3 3 * VBox frontends: Qt4 GUI ("VirtualBox"): 4 * UIGlobalSettings Languageclass declaration4 * UIGlobalSettingsExtension class declaration 5 5 */ 6 6 7 7 /* 8 * Copyright (C) 20 06-2010 Oracle Corporation8 * Copyright (C) 2010 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 17 17 */ 18 18 19 #ifndef __UIGlobalSettings Language_h__20 #define __UIGlobalSettings Language_h__19 #ifndef __UIGlobalSettingsExtension_h__ 20 #define __UIGlobalSettingsExtension_h__ 21 21 22 22 /* Local includes */ 23 23 #include "UISettingsPage.h" 24 #include "UIGlobalSettings Language.gen.h"24 #include "UIGlobalSettingsExtension.gen.h" 25 25 26 /* Global settings / Language page / Cache: */27 struct UISettingsCacheGlobal Language26 /* Global settings / Extension page / Cache Item: */ 27 struct UISettingsCacheGlobalExtensionItem 28 28 { 29 QString m_strLanguageId; 29 QString m_strName; 30 QString m_strDescription; 31 QString m_strVersion; 32 ULONG m_strRevision; 33 bool m_fIsUsable; 34 QString m_strWhyUnusable; 30 35 }; 31 36 32 /* Global settings / Language page: */ 33 class UIGlobalSettingsLanguage : public UISettingsPageGlobal, public Ui::UIGlobalSettingsLanguage 37 /* Global settings / Extension page / Cache: */ 38 struct UISettingsCacheGlobalExtension 39 { 40 QList<UISettingsCacheGlobalExtensionItem> m_items; 41 }; 42 43 /* Global settings / Extension page: */ 44 class UIGlobalSettingsExtension : public UISettingsPageGlobal, public Ui::UIGlobalSettingsExtension 34 45 { 35 46 Q_OBJECT; … … 38 49 39 50 /* Constructor: */ 40 UIGlobalSettings Language();51 UIGlobalSettingsExtension(); 41 52 42 53 protected: … … 62 73 void retranslateUi(); 63 74 64 /* Reload language tree: */65 void reload(const QString &strLangId);66 67 75 private slots: 68 76 69 /* Routine to paint language items: */ 70 void sltLanguageItemPainted(QTreeWidgetItem *pItem, QPainter *pPainter); 77 /* Tree-widget slots: */ 78 void sltHandleCurrentItemChange(QTreeWidgetItem *pCurrentItem); 79 void sltShowContextMenu(const QPoint &position); 71 80 72 /* Slot to handle current language change signal: */ 73 void sltCurrentLanguageChanged(QTreeWidgetItem *pItem); 81 /* Package add/remove procedures: */ 82 void sltInstallPackage(); 83 void sltRemovePackage(); 74 84 75 85 private: 76 86 77 /* Edited flag: */ 78 bool m_fIsLanguageChanged; 87 /* Prepare UISettingsCacheGlobalExtensionItem basing on CExtPack: */ 88 UISettingsCacheGlobalExtensionItem fetchData(const CExtPack &package) const; 89 90 /* Actions: */ 91 QAction *m_pActionAdd; 92 QAction *m_pActionRemove; 79 93 80 94 /* Cache: */ 81 UISettingsCacheGlobal Languagem_cache;95 UISettingsCacheGlobalExtension m_cache; 82 96 }; 83 97 84 #endif // __UIGlobalSettings Language_h__98 #endif // __UIGlobalSettingsExtension_h__ 85 99 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsExtension.ui
r34512 r34543 3 3 VBox frontends: Qt4 GUI ("VirtualBox"): 4 4 5 Copyright (C) 20 08-2010 Oracle Corporation5 Copyright (C) 2010 Oracle Corporation 6 6 7 7 This file is part of VirtualBox Open Source Edition (OSE), as … … 13 13 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 14 14 </comment> 15 <class>UIGlobalSettings Language</class>16 <widget class="QWidget" name="UIGlobalSettings Language">15 <class>UIGlobalSettingsExtension</class> 16 <widget class="QWidget" name="UIGlobalSettingsExtension"> 17 17 <property name="geometry"> 18 18 <rect> … … 46 46 <widget class="QLabel" name="m_pLanguageLabel"> 47 47 <property name="text"> 48 <string>& Interface Language:</string>48 <string>&Extension Packages:</string> 49 49 </property> 50 50 <property name="buddy"> 51 <cstring>m_p LanguageTree</cstring>51 <cstring>m_pPackagesTree</cstring> 52 52 </property> 53 53 </widget> … … 70 70 </item> 71 71 <item row="1" column="2"> 72 <widget class="QITreeWidget" name="m_pLanguageTree"> 73 <property name="sizePolicy"> 74 <sizepolicy vsizetype="Expanding" hsizetype="Expanding"> 75 <horstretch>0</horstretch> 76 <verstretch>0</verstretch> 77 </sizepolicy> 72 <layout class="QHBoxLayout" name="m_pLayout1"> 73 <property name="spacing"> 74 <number>1</number> 78 75 </property> 79 <property name="minimumSize"> 80 <size> 81 <width>0</width> 82 <height>150</height> 83 </size> 76 <property name="margin"> 77 <number>0</number> 84 78 </property> 85 <property name="whatsThis"> 86 <string>Lists all available user interface languages. The effective language is written in <b>bold</b>. Select <i>Default</i> to reset to the system default language.</string> 87 </property> 88 <property name="rootIsDecorated"> 89 <bool>false</bool> 90 </property> 91 <column> 92 <property name="text"> 93 <string>Name</string> 94 </property> 95 </column> 96 <column> 97 <property name="text"> 98 <string>Id</string> 99 </property> 100 </column> 101 <column> 102 <property name="text"> 103 <string>Language</string> 104 </property> 105 </column> 106 <column> 107 <property name="text"> 108 <string>Author</string> 109 </property> 110 </column> 111 </widget> 112 </item> 113 <item row="2" column="2"> 114 <widget class="QILabel" name="m_pLanguageInfo"> 115 <property name="sizePolicy"> 116 <sizepolicy vsizetype="Minimum" hsizetype="Expanding"> 117 <horstretch>0</horstretch> 118 <verstretch>0</verstretch> 119 </sizepolicy> 120 </property> 121 <property name="alignment"> 122 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> 123 </property> 124 <property name="wordWrap"> 125 <bool>true</bool> 126 </property> 127 </widget> 79 <item> 80 <widget class="QTreeWidget" name="m_pPackagesTree"> 81 <property name="sizePolicy"> 82 <sizepolicy vsizetype="Expanding" hsizetype="Expanding"> 83 <horstretch>0</horstretch> 84 <verstretch>0</verstretch> 85 </sizepolicy> 86 </property> 87 <property name="minimumSize"> 88 <size> 89 <width>0</width> 90 <height>150</height> 91 </size> 92 </property> 93 <property name="whatsThis"> 94 <string>Lists all installed packages.</string> 95 </property> 96 <property name="rootIsDecorated"> 97 <bool>false</bool> 98 </property> 99 <column> 100 <property name="text"> 101 <string>Active</string> 102 </property> 103 </column> 104 <column> 105 <property name="text"> 106 <string>Name</string> 107 </property> 108 </column> 109 <column> 110 <property name="text"> 111 <string>Version</string> 112 </property> 113 </column> 114 </widget> 115 </item> 116 <item> 117 <widget class="UIToolBar" name="m_pPackagesToolbar"> 118 <property name="orientation"> 119 <enum>Qt::Vertical</enum> 120 </property> 121 </widget> 122 </item> 123 </layout> 128 124 </item> 129 125 </layout> … … 131 127 <customwidgets> 132 128 <customwidget> 133 <class>QITreeWidget</class> 134 <extends>QTreeWidget</extends> 135 <header>QITreeWidget.h</header> 136 </customwidget> 137 <customwidget> 138 <class>QILabel</class> 139 <extends>QLabel</extends> 140 <header>QILabel.h</header> 129 <class>UIToolBar</class> 130 <extends>QToolBar</extends> 131 <header>UIToolBar.h</header> 141 132 </customwidget> 142 133 </customwidgets>
Note:
See TracChangeset
for help on using the changeset viewer.