Changeset 11497 in vbox for trunk/src/VBox
- Timestamp:
- Aug 19, 2008 6:16:55 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 34998
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxFilePathSelectorWidget.h
r11427 r11497 54 54 55 55 bool isModified() const; 56 bool isPathLineChosen() const; 57 58 QString path() const; 59 60 public slots: 56 61 57 62 void setPath (const QString &aPath); 58 QString path() const; 59 60 signals: 61 62 void selectPath(); 63 void setHomeDir (const QString &aHomeDir); 63 64 64 65 protected: 65 66 66 67 void resizeEvent (QResizeEvent *aEvent); 68 void focusInEvent (QFocusEvent *aEvent); 69 void focusOutEvent (QFocusEvent *aEvent); 67 70 void retranslateUi(); 68 71 … … 74 77 private: 75 78 79 void selectPath(); 76 80 QIcon defaultIcon() const; 77 81 QString fullPath (bool aAbsolute = true) const; … … 84 88 Mode mMode; 85 89 QString mPath; 90 QString mHomeDir; 86 91 QString mNoneStr; 87 92 QString mNoneTip; 93 bool mIsEditableMode; 88 94 }; 89 95 -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGLSettingsGeneral.h
r11427 r11497 46 46 47 47 void retranslateUi(); 48 49 private slots:50 51 void onSelectFolderClicked();52 48 }; 53 49 -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsGeneral.h
r11427 r11497 63 63 QTreeWidgetItem *aPrev = 0); 64 64 65 void selectSnapshotFolder();66 67 65 private: 68 66 -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsSFDetails.h
r10742 r11497 62 62 63 63 void retranslateUi(); 64 64 65 65 private slots: 66 66 67 void selectPath();67 void onSelectPath(); 68 68 void validate(); 69 69 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxFilePathSelectorWidget.cpp
r11427 r11497 30 30 #include <QDir> 31 31 #include <QFileIconProvider> 32 #include <QLineEdit> 32 33 33 34 enum … … 43 44 , mCopyAction (new QAction (this)) 44 45 , mMode (Mode_Folder) 46 , mHomeDir (QDir::current().absolutePath()) 47 , mIsEditableMode (false) 45 48 { 46 49 /* Populate items */ … … 58 61 mCopyAction->setShortcutContext (Qt::WidgetShortcut); 59 62 63 /* Initial Setup */ 64 setEditable (true); 65 Assert (lineEdit()); 66 setInsertPolicy (QComboBox::NoInsert); 67 setContextMenuPolicy (Qt::ActionsContextMenu); 68 setMinimumWidth (200); 69 60 70 /* Setup connections */ 71 connect (lineEdit(), SIGNAL (textEdited (const QString &)), 72 this, SLOT (setPath (const QString &))); 61 73 connect (this, SIGNAL (activated (int)), this, SLOT (onActivated (int))); 62 74 connect (mCopyAction, SIGNAL (triggered (bool)), this, SLOT (copyToClipboard())); … … 64 76 /* Applying language settings */ 65 77 retranslateUi(); 66 67 /* Initial Setup */68 setContextMenuPolicy (Qt::ActionsContextMenu);69 setMinimumWidth (200);70 78 } 71 79 … … 107 115 } 108 116 117 bool VBoxFilePathSelectorWidget::isPathLineChosen() const 118 { 119 return (currentIndex() == PathId); 120 } 121 122 QString VBoxFilePathSelectorWidget::path() const 123 { 124 return mPath; 125 } 126 109 127 void VBoxFilePathSelectorWidget::setPath (const QString &aPath) 110 128 { 111 mPath = aPath.isEmpty() ? QString::null : aPath; 129 mPath = aPath.isEmpty() ? QString::null : 130 QDir::toNativeSeparators (aPath); 112 131 refreshText(); 113 132 } 114 133 115 QString VBoxFilePathSelectorWidget::path() const 116 { 117 return mPath;134 void VBoxFilePathSelectorWidget::setHomeDir (const QString &aHomeDir) 135 { 136 mHomeDir = aHomeDir; 118 137 } 119 138 … … 122 141 QIWithRetranslateUI<QComboBox>::resizeEvent (aEvent); 123 142 refreshText(); 143 } 144 145 void VBoxFilePathSelectorWidget::focusInEvent (QFocusEvent *aEvent) 146 { 147 if (isPathLineChosen()) 148 { 149 mIsEditableMode = true; 150 refreshText(); 151 } 152 QIWithRetranslateUI<QComboBox>::focusInEvent (aEvent); 153 } 154 155 void VBoxFilePathSelectorWidget::focusOutEvent (QFocusEvent *aEvent) 156 { 157 if (isPathLineChosen()) 158 { 159 mIsEditableMode = false; 160 refreshText(); 161 } 162 QIWithRetranslateUI<QComboBox>::focusOutEvent (aEvent); 124 163 } 125 164 … … 188 227 case SelectId: 189 228 { 190 emitselectPath();229 selectPath(); 191 230 break; 192 231 } … … 200 239 } 201 240 setCurrentIndex (PathId); 241 setFocus(); 202 242 } 203 243 … … 211 251 } 212 252 253 void VBoxFilePathSelectorWidget::selectPath() 254 { 255 /* Preparing initial directory. */ 256 QString initDir = mPath.isNull() ? mHomeDir : 257 VBoxGlobal::getFirstExistingDir (mPath); 258 if (initDir.isNull()) 259 initDir = mHomeDir; 260 261 /* Open existing file or directory. */ 262 QString path = mMode == Mode_File ? 263 VBoxGlobal::getOpenFileName (initDir, QString::null, parentWidget(), QString::null) : 264 VBoxGlobal::getExistingDirectory (initDir, parentWidget()); 265 if (path.isNull()) 266 return; 267 268 path.remove (QRegExp ("[\\\\/]$")); 269 setPath (path); 270 } 271 213 272 QIcon VBoxFilePathSelectorWidget::defaultIcon() const 214 273 { … … 219 278 } 220 279 221 QString VBoxFilePathSelectorWidget::fullPath (bool aAbsolute) const 222 { 223 if (!mPath.isNull()) 224 { 225 switch (mMode) 226 { 227 case Mode_Folder: 228 return aAbsolute ? QDir (mPath).absolutePath() : 229 QDir (mPath).path(); 230 case Mode_File: 231 return aAbsolute ? QFileInfo (mPath).absoluteFilePath() : 232 QFileInfo (mPath).filePath(); 233 default: 234 AssertFailedBreak(); 235 } 236 } 237 return QString::null; 280 QString VBoxFilePathSelectorWidget::fullPath (bool aAbsolute /* = true */) const 281 { 282 if (mPath.isNull()) 283 return mPath; 284 285 QString result; 286 switch (mMode) 287 { 288 case Mode_Folder: 289 result = aAbsolute ? QDir (mPath).absolutePath() : 290 QDir (mPath).path(); 291 break; 292 case Mode_File: 293 result = aAbsolute ? QFileInfo (mPath).absoluteFilePath() : 294 QFileInfo (mPath).filePath(); 295 break; 296 default: 297 AssertFailedBreak(); 298 } 299 return QDir::toNativeSeparators (result); 238 300 } 239 301 … … 245 307 246 308 int oldSize = fontMetrics().width (fullText); 247 int indentSize = fontMetrics().width (" ...x");309 int indentSize = fontMetrics().width ("x...x"); 248 310 249 311 /* Compress text */ … … 281 343 void VBoxFilePathSelectorWidget::refreshText() 282 344 { 283 if (mPath.isNull()) 284 { 345 if (mIsEditableMode) 346 { 347 /* In editable mode there should be no any icon 348 * and text have be corresponding real stored path 349 * which can be absolute or relative. */ 350 setItemText (PathId, mPath); 351 setItemIcon (PathId, QIcon()); 352 } 353 else if (mPath.isNull()) 354 { 355 /* If we are not in editable mode and no path is 356 * stored here - show the translated 'none' string. */ 285 357 if (itemText (PathId) != mNoneStr) 286 358 { -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGLSettingsGeneral.cpp
r11427 r11497 31 31 Ui::VBoxGLSettingsGeneral::setupUi (this); 32 32 33 mPsVdi->setHomeDir (vboxGlobal().virtualBox().GetHomeFolder()); 34 mPsMach->setHomeDir (vboxGlobal().virtualBox().GetHomeFolder()); 35 mPsVRDP->setHomeDir (vboxGlobal().virtualBox().GetHomeFolder()); 33 36 mPsVRDP->setMode (VBoxFilePathSelectorWidget::Mode_File); 34 35 /* Setup connections */36 connect (mPsVdi, SIGNAL (selectPath()), this, SLOT (onSelectFolderClicked()));37 connect (mPsMach, SIGNAL (selectPath()), this, SLOT (onSelectFolderClicked()));38 connect (mPsVRDP, SIGNAL (selectPath()), this, SLOT (onSelectFolderClicked()));39 37 40 38 /* Applying language settings */ … … 86 84 } 87 85 88 void VBoxGLSettingsGeneral::onSelectFolderClicked()89 {90 VBoxFilePathSelectorWidget *ps = qobject_cast<VBoxFilePathSelectorWidget*> (sender());91 Assert (ps);92 93 QString initDir = VBoxGlobal::getFirstExistingDir (ps->path());94 if (initDir.isNull())95 initDir = vboxGlobal().virtualBox().GetHomeFolder();96 97 98 QString path = ps == mPsVRDP ?99 VBoxGlobal::getOpenFileName (initDir, QString::null, this, QString::null) :100 VBoxGlobal::getExistingDirectory (initDir, this);101 if (path.isNull())102 return;103 104 path = QDir::convertSeparators (path);105 /* remove trailing slash if any */106 path.remove (QRegExp ("[\\\\/]$"));107 108 ps->setPath (path);109 }110 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMSettingsGeneral.cpp
r11427 r11497 75 75 connect (mLeVideo, SIGNAL (textChanged (const QString&)), 76 76 this, SLOT (textChangedVRAM (const QString&))); 77 connect (mPsSnapshot, SIGNAL (selectPath()),78 this, SLOT (selectSnapshotFolder()));79 77 connect (mTbBootItemUp, SIGNAL (clicked()), 80 78 this, SLOT (moveBootItemUp())); … … 215 213 /* Snapshot folder */ 216 214 mPsSnapshot->setPath (aMachine.GetSnapshotFolder()); 215 mPsSnapshot->setHomeDir (QFileInfo (mMachine.GetSettingsFilePath()).absolutePath()); 217 216 218 217 /* Description */ … … 446 445 mTbBootItemUp->setEnabled (upEnabled); 447 446 mTbBootItemDown->setEnabled (downEnabled); 448 }449 450 void VBoxVMSettingsGeneral::selectSnapshotFolder()451 {452 QString settingsFolder = VBoxGlobal::getFirstExistingDir (mPsSnapshot->path());453 if (settingsFolder.isNull())454 settingsFolder = QFileInfo (mMachine.GetSettingsFilePath()).absolutePath();455 456 QString folder = vboxGlobal().getExistingDirectory (settingsFolder, this);457 if (folder.isNull())458 return;459 460 folder = QDir::convertSeparators (folder);461 /* Remove trailing slash if any */462 folder.remove (QRegExp ("[\\\\/]$"));463 464 mPsSnapshot->setPath (folder);465 447 } 466 448 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMSettingsSFDetails.cpp
r11361 r11497 44 44 /* No reset button */ 45 45 mPsPath->setResetEnabled (false); 46 connect (mPsPath, SIGNAL ( selectPath()),47 this, SLOT ( selectPath()));46 connect (mPsPath, SIGNAL (currentIndexChanged (int)), 47 this, SLOT (onSelectPath())); 48 48 49 49 connect (mLeName, SIGNAL (textChanged (const QString &)), … … 141 141 } 142 142 143 void VBoxVMSettingsSFDetails:: selectPath()143 void VBoxVMSettingsSFDetails::onSelectPath() 144 144 { 145 QString folderName = vboxGlobal() 146 .getExistingDirectory (mPsPath->path().isEmpty() ? QDir::homePath() : mPsPath->path(), 147 this, 148 tr ("Select a folder to share")); 149 if (folderName.isNull()) 145 if (!mPsPath->isPathLineChosen()) 150 146 return; 151 147 148 QString folderName (mPsPath->path()); 152 149 QDir folder (folderName); 153 mPsPath->setPath (QDir::toNativeSeparators (folder.absolutePath()));154 150 if (!folder.isRoot()) 155 /* processing non-root folder */151 /* Processing non-root folder */ 156 152 mLeName->setText (folder.dirName()); 157 153 else 158 154 { 159 /* processing root folder */155 /* Processing root folder */ 160 156 #if defined (Q_OS_WIN) || defined (Q_OS_OS2) 161 157 mLeName->setText (folderName.toUpper()[0] + "_DRIVE"); … … 166 162 /* Validate the fields */ 167 163 validate(); 168 169 164 } 170 165
Note:
See TracChangeset
for help on using the changeset viewer.