Changeset 1889 in vbox
- Timestamp:
- Apr 3, 2007 3:42:03 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 20134
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/VBoxDefs.h
r1863 r1889 137 137 #if defined (Q_WS_WIN) 138 138 ShellExecuteEventType, 139 GetExistDirectoryEventType,140 139 #endif 141 140 ActivateMenuEventType, -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h
r1863 r1889 396 396 static QString highlight (const QString &aStr, bool aToolTip = false); 397 397 398 voidgetExistingDirectory (const QString &aDir, QWidget *aParent,399 const char *aName = 0,400 const QString &aCaption = QString::null,401 bool aDirOnly = TRUE,402 bool resolveSymlinks = TRUE);398 static QString getExistingDirectory (const QString &aDir, QWidget *aParent, 399 const char *aName = 0, 400 const QString &aCaption = QString::null, 401 bool aDirOnly = TRUE, 402 bool resolveSymlinks = TRUE); 403 403 404 404 static QString getOpenFileName (const QString &, const QString &, QWidget*, … … 406 406 QString *defaultFilter = 0, 407 407 bool resolveSymLinks = true); 408 409 static QString getStartingDir (const QString &); 408 410 409 411 signals: … … 446 448 void sessionStateChanged (const VBoxSessionStateChangeEvent &e); 447 449 void snapshotChanged (const VBoxSnapshotEvent &e); 448 449 /* Emitted upon getExistingDirectory dialog accepting */450 void existingDirectoryResult (const QString &);451 450 452 451 protected: -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp
r1863 r1889 48 48 #ifdef Q_WS_WIN 49 49 #include "shlobj.h" 50 #include <qeventloop.h> 50 51 #endif 51 52 … … 95 96 QString mURL; 96 97 bool mOk; 97 };98 99 class VBoxGetExistDirectoryEvent : public QEvent100 {101 public:102 103 /** Constructs a regular enum event */104 VBoxGetExistDirectoryEvent (QThread *aThread, const QString &aName)105 : QEvent ((QEvent::Type) VBoxDefs::GetExistDirectoryEventType)106 , mThread (aThread), mName (aName)107 {}108 109 QThread *mThread;110 QString mName;111 98 }; 112 99 #endif … … 418 405 { 419 406 SendMessage (hwnd, BFFM_SETSELECTION, TRUE, Q_ULONG (initDir->ucs2())); 420 SendMessage (hwnd, BFFM_SETEXPANDED, TRUE, Q_ULONG (initDir->ucs2()));407 //SendMessage (hwnd, BFFM_SETEXPANDED, TRUE, Q_ULONG (initDir->ucs2())); 421 408 } 422 409 } … … 2222 2209 * QFileDialog::getExistingDirectory(). 2223 2210 */ 2224 voidVBoxGlobal::getExistingDirectory (const QString &aDir,2225 QWidget *aParent, const char *aName,2226 const QString &aCaption,2227 bool aDirOnly,2228 bool aResolveSymlinks)2211 QString VBoxGlobal::getExistingDirectory (const QString &aDir, 2212 QWidget *aParent, const char *aName, 2213 const QString &aCaption, 2214 bool aDirOnly, 2215 bool aResolveSymlinks) 2229 2216 { 2230 2217 #if defined Q_WS_WIN 2231 2218 2232 /* open existing directory thread class */ 2219 /** 2220 * QEvent type for VBoxGetExistDirectoryEvent event 2221 */ 2222 enum { GetExistDirectoryEventType = QEvent::User + 300 }; 2223 2224 /** 2225 * QEvent class reimplementation to carry Win32 API native dialog's 2226 * result folder information 2227 */ 2228 class VBoxGetExistDirectoryEvent : public QEvent 2229 { 2230 public: 2231 2232 VBoxGetExistDirectoryEvent (const QString &aName) 2233 : QEvent ((QEvent::Type) GetExistDirectoryEventType) 2234 , mName (aName) 2235 {} 2236 2237 QString mName; 2238 }; 2239 2240 /** 2241 * QThread class reimplementation to open Win32 API native folder's dialog 2242 */ 2233 2243 class Thread : public QThread 2234 2244 { … … 2277 2287 else 2278 2288 result = QString::null; 2279 QApplication::postEvent (mTarget, 2280 new VBoxGetExistDirectoryEvent (this, result)); 2289 QApplication::postEvent (mTarget, new VBoxGetExistDirectoryEvent (result)); 2281 2290 if (parent) parent->setEnabled (true); 2282 2291 } … … 2290 2299 }; 2291 2300 2301 class LoopObject : public QObject 2302 { 2303 public: 2304 2305 LoopObject() : mFolder (QString::null) {} 2306 const QString& folder() { return mFolder; } 2307 2308 private: 2309 2310 bool event (QEvent *e) 2311 { 2312 switch (e->type()) 2313 { 2314 case GetExistDirectoryEventType: 2315 { 2316 VBoxGetExistDirectoryEvent *ev = (VBoxGetExistDirectoryEvent *) e; 2317 mFolder = ev->mName; 2318 qApp->eventLoop()->exitLoop(); 2319 return true; 2320 } 2321 default: 2322 break; 2323 } 2324 return QObject::event (e); 2325 } 2326 2327 QString mFolder; 2328 }; 2329 2292 2330 /* this dialog is proposed to be a modal */ 2293 if (!aParent) return ;2331 if (!aParent) return QString::null; 2294 2332 QString dir = QDir::convertSeparators (aDir); 2295 Thread *openDirThread = new Thread (aParent->winId(), this, dir, aCaption); 2296 openDirThread->start(); 2297 /* thread will be deleted in the VBoxGetExistDirectoryEvent handler */ 2333 LoopObject loopObject; 2334 Thread openDirThread (aParent->winId(), &loopObject, dir, aCaption); 2335 openDirThread.start(); 2336 qApp->eventLoop()->enterLoop(); 2337 openDirThread.wait(); 2338 return loopObject.folder(); 2298 2339 2299 2340 #else 2300 2341 2301 QString result = QFileDialog::getExistingDirectory (aDir, aParent, 2302 aName, aCaption, aDirOnly, aResolveSymlinks); 2303 emit existingDirectoryResult (result); 2342 return QFileDialog::getExistingDirectory (aDir, aParent, aName, aCaption, 2343 aDirOnly, aResolveSymlinks); 2304 2344 2305 2345 #endif … … 2412 2452 } 2413 2453 2454 /** 2455 * Search for the first directory that exists starting from the passed one. 2456 * In case of there is no directory (and all of its parent except root) exist 2457 * the function returns QString::null. 2458 */ 2459 /* static */ 2460 QString VBoxGlobal::getStartingDir (const QString &aStartDir) 2461 { 2462 QString result = QString::null; 2463 QDir dir (aStartDir); 2464 while (!dir.exists() && !dir.isRoot()) 2465 { 2466 QFileInfo dirInfo (dir.absPath()); 2467 dir = dirInfo.dirPath (true); 2468 } 2469 if (dir.exists() && !dir.isRoot()) 2470 result = dir.absPath(); 2471 return result; 2472 } 2473 2474 2414 2475 // Protected members 2415 2476 //////////////////////////////////////////////////////////////////////////////// … … 2428 2489 ev->mThread->wait(); 2429 2490 delete ev->mThread; 2430 return true;2431 }2432 2433 case VBoxDefs::GetExistDirectoryEventType:2434 {2435 VBoxGetExistDirectoryEvent *ev = (VBoxGetExistDirectoryEvent *) e;2436 /* wait for the thread and free resources */2437 ev->mThread->wait();2438 delete ev->mThread;2439 emit existingDirectoryResult (ev->mName);2440 2491 return true; 2441 2492 } -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui
r1863 r1889 1041 1041 <variable access="private">bool mUSBFilterListModified;</variable> 1042 1042 <variable access="private">VBoxUSBMenu *usbDevicesMenu;</variable> 1043 <variable access="private">QLineEdit *mLastAccessedField;</variable>1044 1043 </variables> 1045 1044 <slots> … … 1050 1049 <slot>tbResetFolder_clicked()</slot> 1051 1050 <slot>tbSelectFolder_clicked()</slot> 1052 <slot>folderSelected( const QString & )</slot>1053 1051 <slot>addUSBFilter( const CUSBDeviceFilter &, bool )</slot> 1054 1052 <slot>lvUSBFilters_currentChanged( QListViewItem * )</slot> -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui.h
r1863 r1889 148 148 149 149 /* General page */ 150 151 mLastAccessedField = 0;152 connect (&vboxGlobal(), SIGNAL (existingDirectoryResult (const QString&)),153 this, SLOT (folderSelected (const QString&)));154 150 155 151 /// @todo (dmik) remove … … 503 499 if (tb == tbSelectVDIFolder) le = leVDIFolder; 504 500 else if (tb == tbSelectMachineFolder) le = leMachineFolder; 505 mLastAccessedField = le;506 501 Assert (le); 507 502 508 QString initDir = vboxGlobal().virtualBox().GetHomeFolder(); 509 510 if (!le->text().isEmpty()) 511 { 512 /* set the first parent directory that exists as the current */ 513 const QDir _dir (initDir); 514 QFileInfo fld (_dir, le->text()); 515 do 516 { 517 QString dp = fld.dirPath (false); 518 fld = QFileInfo (dp); 519 } 520 while (!fld.exists() && !QDir (fld.absFilePath()).isRoot()); 521 522 if (fld.exists()) 523 initDir = fld.absFilePath(); 524 } 525 526 vboxGlobal().getExistingDirectory (initDir, this); 527 } 528 529 void VBoxGlobalSettingsDlg::folderSelected (const QString &aFolder) 530 { 531 if (aFolder.isNull()) 503 QString initDir = VBoxGlobal::getStartingDir (le->text()); 504 if (initDir.isNull()) 505 initDir = vboxGlobal().virtualBox().GetHomeFolder(); 506 QString folder = VBoxGlobal::getExistingDirectory (initDir, this); 507 if (folder.isNull()) 532 508 return; 533 509 534 QString folder = QDir::convertSeparators (aFolder);510 folder = QDir::convertSeparators (folder); 535 511 /* remove trailing slash if any */ 536 512 folder.remove (QRegExp ("[\\\\/]$")); … … 540 516 * isModified() return true 541 517 */ 542 if (mLastAccessedField) 543 { 544 mLastAccessedField->selectAll(); 545 mLastAccessedField->insert (folder); 546 mLastAccessedField = 0; 547 } 518 le->selectAll(); 519 le->insert (folder); 548 520 } 549 521 -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui.h
r1863 r1889 188 188 this, SLOT (validate())); 189 189 connect (tbPath, SIGNAL (clicked()), this, SLOT (showFileDialog())); 190 connect (&vboxGlobal(), SIGNAL (existingDirectoryResult (const QString&)),191 this, SLOT (folderSelected (const QString&)));192 190 QWhatsThis::add (mLePath, tr ("Enter existing path for the shared folder here")); 193 191 QWhatsThis::add (mLeName, tr ("Enter name for the shared folder to be created")); … … 233 231 void showFileDialog() 234 232 { 235 vboxGlobal().getExistingDirectory (QDir::convertSeparators ( 236 QDir::rootDirPath()), 237 this, "addSharedFolderDialog", 238 tr ("Select a folder to share")); 239 } 240 241 void folderSelected (const QString &aFolder) 242 { 243 if (aFolder.isNull()) 233 QString folder = vboxGlobal().getExistingDirectory (QDir::rootDirPath(), 234 this, "addSharedFolderDialog", 235 tr ("Select a folder to share")); 236 if (folder.isNull()) 244 237 return; 245 238 246 QString folderName = QDir::convertSeparators ( aFolder);239 QString folderName = QDir::convertSeparators (folder); 247 240 QRegExp commonRule ("[\\\\/]([^\\\\^/]+)[\\\\/]?$"); 248 241 QRegExp rootRule ("(([a-zA-Z])[^\\\\^/])?[\\\\/]$"); -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui
r1863 r1889 2698 2698 <slot>tbResetSavedStateFolder_clicked()</slot> 2699 2699 <slot>tbSelectSavedStateFolder_clicked()</slot> 2700 <slot>folderSelected( const QString & )</slot>2701 2700 <slot>addUSBFilter( const CUSBDeviceFilter & aFilter, bool isNew )</slot> 2702 2701 <slot>lvUSBFilters_currentChanged( QListViewItem * item )</slot> -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h
r1863 r1889 1847 1847 void VBoxVMSettingsDlg::tbSelectSavedStateFolder_clicked() 1848 1848 { 1849 QString settingsFolder = 1850 QFileInfo (cmachine.GetSettingsFilePath()).dirPath (true); 1851 1852 if (!leSnapshotFolder->text().isEmpty()) 1853 { 1854 /* set the first parent directory that exists as the current */ 1855 const QDir dir (settingsFolder); 1856 QFileInfo fld (dir, leSnapshotFolder->text()); 1857 do 1858 { 1859 QString dp = fld.dirPath (false); 1860 fld = QFileInfo (dp); 1861 } 1862 while (!fld.exists() && !QDir (fld.absFilePath()).isRoot()); 1863 1864 if (fld.exists()) 1865 settingsFolder = fld.absFilePath(); 1866 } 1867 1868 vboxGlobal().getExistingDirectory (settingsFolder, this); 1869 } 1870 1871 void VBoxVMSettingsDlg::folderSelected (const QString &aFolder) 1872 { 1873 if (aFolder.isNull()) 1849 QString settingsFolder = VBoxGlobal::getStartingDir (leSnapshotFolder->text()); 1850 if (settingsFolder.isNull()) 1851 settingsFolder = QFileInfo (cmachine.GetSettingsFilePath()).dirPath (true); 1852 1853 QString folder = vboxGlobal().getExistingDirectory (settingsFolder, this); 1854 if (folder.isNull()) 1874 1855 return; 1875 1856 1876 QString folder = QDir::convertSeparators (aFolder);1857 folder = QDir::convertSeparators (folder); 1877 1858 /* remove trailing slash if any */ 1878 1859 folder.remove (QRegExp ("[\\\\/]$"));
Note:
See TracChangeset
for help on using the changeset viewer.