VirtualBox

Ignore:
Timestamp:
Mar 6, 2009 2:43:38 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
43901
Message:

FE/Qt4: added support for GetSaveFileName

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxFilePathSelectorWidget.h

    r17047 r17475  
    4141    {
    4242        Mode_Folder = 0,
    43         Mode_File
     43        Mode_File_Open,
     44        Mode_File_Save
    4445    };
    4546
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h

    r17408 r17475  
    689689                                         bool resolveSymlinks = TRUE);
    690690
     691    static QString getSaveFileName (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
     692                                    const QString &aCaption, QString *aSelectedFilter = NULL,
     693                                    bool aResolveSymLinks = true);
     694
    691695    static QString getOpenFileName (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
    692696                                    const QString &aCaption, QString *aSelectedFilter = NULL,
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxProblemReporter.h

    r17450 r17475  
    183183    QWidget *mainWindowShown() const;
    184184
    185     // problem handlers
    186 
     185    /* Generic problem handlers */
     186    bool askForOverridingFileIfExists (const QString& path, QWidget *aParent = NULL) const;
     187
     188    /* Special problem handlers */
    187189#ifdef Q_WS_X11
    188190    void cannotFindLicenseFiles (const QString &aPath);
     
    375377    void cannotImportAppliance (const CProgress &aProgress, CAppliance *aAppliance, QWidget *aParent = NULL) const;
    376378
    377 
    378     bool askForOverridingAppliance (const QString& path, QWidget *aParent = NULL) const;
    379379    void cannotExportAppliance (CAppliance *aAppliance, QWidget *aParent = NULL) const;
    380380    void cannotExportAppliance (const CProgress &aProgress, CAppliance *aAppliance, QWidget *aParent = NULL) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxExportApplianceWzd.cpp

    r17457 r17475  
    7272
    7373    /* Configure the file selector */
    74     mFileSelector->setMode (VBoxFilePathSelectorWidget::Mode_File);
     74    mFileSelector->setMode (VBoxFilePathSelectorWidget::Mode_File_Save);
    7575    mFileSelector->setResetEnabled (false);
    7676    mFileSelector->setFileDialogTitle (tr ("Select a file to export into"));
     
    132132    /* Check if the file exists already, if yes get confirmation for
    133133     * overwriting from the user. */
    134     QFileInfo fi (mFileSelector->path());
    135     if (fi.exists())
    136         if (!vboxProblem().askForOverridingAppliance (mFileSelector->path(), this))
    137             return;
     134    if (!vboxProblem().askForOverridingFileIfExists (mFileSelector->path(), this))
     135        return;
    138136    /* Export the VMs, on success we are finished */
    139137    if (exportVMs())
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxFilePathSelectorWidget.cpp

    r17047 r17475  
    301301                         Qt::ToolTipRole);
    302302            break;
    303         case Mode_File:
     303        case Mode_File_Open:
     304        case Mode_File_Save:
    304305            setItemData (SelectId,
    305306                         tr ("Opens a dialog to select a different file."),
     
    370371        initDir = mHomeDir;
    371372
    372     /* Open existing file or directory. */
    373     QString path = mMode == Mode_File ?
    374         VBoxGlobal::getOpenFileName (initDir, mFileFilters, parentWidget(), mFileDialogTitle) :
    375         VBoxGlobal::getExistingDirectory (initDir, parentWidget(), mFileDialogTitle);
     373    QString path;
     374    switch (mMode)
     375    {
     376        case Mode_File_Open:
     377            path = VBoxGlobal::getOpenFileName (initDir, mFileFilters, parentWidget(), mFileDialogTitle); break;
     378        case Mode_File_Save:
     379            path = VBoxGlobal::getSaveFileName (initDir, mFileFilters, parentWidget(), mFileDialogTitle); break;
     380        case Mode_Folder:
     381            path = VBoxGlobal::getExistingDirectory (initDir, parentWidget(), mFileDialogTitle); break;
     382    }
     383
    376384    if (path.isNull())
    377385        return;
     
    401409                                 QDir (mPath).path();
    402410            break;
    403         case Mode_File:
     411        case Mode_File_Open:
     412        case Mode_File_Save:
    404413            result = aAbsolute ? QFileInfo (mPath).absoluteFilePath() :
    405414                                 QFileInfo (mPath).filePath();
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGLSettingsGeneral.cpp

    r15664 r17475  
    4141    mPsMach->setHomeDir (vboxGlobal().virtualBox().GetHomeFolder());
    4242    mPsVRDP->setHomeDir (vboxGlobal().virtualBox().GetHomeFolder());
    43     mPsVRDP->setMode (VBoxFilePathSelectorWidget::Mode_File);
     43    mPsVRDP->setMode (VBoxFilePathSelectorWidget::Mode_File_Open);
    4444
    4545    /* Applying language settings */
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r17408 r17475  
    41044104
    41054105/**
     4106 *  Reimplementation of QFileDialog::getSaveFileName() that removes some
     4107 *  oddities and limitations.
     4108 *
     4109 *  On Win32, this function makes sure a file filter is applied automatically
     4110 *  right after it is selected from the drop-down list, to conform to common
     4111 *  experience in other applications. Note that currently, @a selectedFilter
     4112 *  is always set to null on return.
     4113 *
     4114 *  On all other platforms, this function is equivalent to
     4115 *  QFileDialog::getSaveFileName().
     4116 */
     4117/* static */
     4118QString VBoxGlobal::getSaveFileName (const QString &aStartWith,
     4119                                     const QString &aFilters,
     4120                                     QWidget       *aParent,
     4121                                     const QString &aCaption,
     4122                                     QString       *aSelectedFilter /* = NULL */,
     4123                                     bool           aResolveSymlinks /* = true */)
     4124{
     4125#if defined Q_WS_WIN
     4126
     4127    /**
     4128     *  QEvent class reimplementation to carry Win32 API native dialog's
     4129     *  result folder information
     4130     */
     4131    class GetOpenFileNameEvent : public OpenNativeDialogEvent
     4132    {
     4133    public:
     4134
     4135        enum { TypeId = QEvent::User + 301 };
     4136
     4137        GetOpenFileNameEvent (const QString &aResult)
     4138            : OpenNativeDialogEvent (aResult, (QEvent::Type) TypeId) {}
     4139    };
     4140
     4141    /**
     4142     *  QThread class reimplementation to open Win32 API native file dialog
     4143     */
     4144    class Thread : public QThread
     4145    {
     4146    public:
     4147
     4148        Thread (QWidget *aParent, QObject *aTarget,
     4149                const QString &aStartWith, const QString &aFilters,
     4150                const QString &aCaption) :
     4151                mParent (aParent), mTarget (aTarget),
     4152                mStartWith (aStartWith), mFilters (aFilters),
     4153                mCaption (aCaption) {}
     4154
     4155        virtual void run()
     4156        {
     4157            QString result;
     4158
     4159            QString workDir;
     4160            QString initSel;
     4161            QFileInfo fi (mStartWith);
     4162
     4163            if (fi.isDir())
     4164                workDir = mStartWith;
     4165            else
     4166            {
     4167                workDir = fi.absolutePath();
     4168                initSel = fi.fileName();
     4169            }
     4170
     4171            workDir = QDir::toNativeSeparators (workDir);
     4172            if (!workDir.endsWith ("\\"))
     4173                workDir += "\\";
     4174
     4175            QString title = mCaption.isNull() ? tr ("Select a file") : mCaption;
     4176
     4177            QWidget *topParent = mParent ? mParent->window() : vboxGlobal().mainWindow();
     4178            QString winFilters = winFilter (mFilters);
     4179            AssertCompile (sizeof (TCHAR) == sizeof (QChar));
     4180            TCHAR buf [1024];
     4181            if (initSel.length() > 0 && initSel.length() < sizeof (buf))
     4182                memcpy (buf, initSel.isNull() ? 0 : initSel.utf16(),
     4183                        (initSel.length() + 1) * sizeof (TCHAR));
     4184            else
     4185                buf [0] = 0;
     4186
     4187            OPENFILENAME ofn;
     4188            memset (&ofn, 0, sizeof (OPENFILENAME));
     4189
     4190            ofn.lStructSize = sizeof (OPENFILENAME);
     4191            ofn.hwndOwner = topParent ? topParent->winId() : 0;
     4192            ofn.lpstrFilter = (TCHAR *) winFilters.isNull() ? 0 : winFilters.utf16();
     4193            ofn.lpstrFile = buf;
     4194            ofn.nMaxFile = sizeof (buf) - 1;
     4195            ofn.lpstrInitialDir = (TCHAR *) workDir.isNull() ? 0 : workDir.utf16();
     4196            ofn.lpstrTitle = (TCHAR *) title.isNull() ? 0 : title.utf16();
     4197            ofn.Flags = (OFN_NOCHANGEDIR | OFN_HIDEREADONLY |
     4198                         OFN_EXPLORER | OFN_ENABLEHOOK |
     4199                         OFN_NOTESTFILECREATE);
     4200            ofn.lpfnHook = OFNHookProc;
     4201
     4202            if (GetSaveFileName (&ofn))
     4203            {
     4204                result = QString::fromUtf16 ((ushort *) ofn.lpstrFile);
     4205            }
     4206
     4207            // qt_win_eatMouseMove();
     4208            MSG msg = {0, 0, 0, 0, 0, 0, 0};
     4209            while (PeekMessage (&msg, 0, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE));
     4210            if (msg.message == WM_MOUSEMOVE)
     4211                PostMessage (msg.hwnd, msg.message, 0, msg.lParam);
     4212
     4213            result = result.isEmpty() ? result : QFileInfo (result).absoluteFilePath();
     4214
     4215            QApplication::postEvent (mTarget, new GetOpenFileNameEvent (result));
     4216        }
     4217
     4218    private:
     4219
     4220        QWidget *mParent;
     4221        QObject *mTarget;
     4222        QString mStartWith;
     4223        QString mFilters;
     4224        QString mCaption;
     4225    };
     4226
     4227    if (aSelectedFilter)
     4228        *aSelectedFilter = QString::null;
     4229
     4230    /* Local event loop to run while waiting for the result from another
     4231     * thread */
     4232    QEventLoop loop;
     4233
     4234    QString startWith = QDir::toNativeSeparators (aStartWith);
     4235    LoopObject loopObject ((QEvent::Type) GetOpenFileNameEvent::TypeId, loop);
     4236
     4237//#warning check me!
     4238    if (aParent)
     4239        aParent->setWindowModality (Qt::WindowModal);
     4240
     4241    Thread openDirThread (aParent, &loopObject, startWith, aFilters, aCaption);
     4242    openDirThread.start();
     4243    loop.exec();
     4244    openDirThread.wait();
     4245
     4246//#warning check me!
     4247    if (aParent)
     4248        aParent->setWindowModality (Qt::NonModal);
     4249
     4250    return QStringList() << loopObject.result();
     4251
     4252#elif defined (Q_WS_X11) && (QT_VERSION < 0x040400)
     4253
     4254    /* Here is workaround for Qt4.3 bug with QFileDialog which crushes when
     4255     * gets initial path as hidden directory if no hidden files are shown.
     4256     * See http://trolltech.com/developer/task-tracker/index_html?method=entry&id=193483
     4257     * for details */
     4258    QFileDialog dlg (aParent);
     4259    dlg.setWindowTitle (aCaption);
     4260    dlg.setDirectory (aStartWith);
     4261    dlg.setFilter (aFilters);
     4262    dlg.setFileMode (QFileDialog::QFileDialog::AnyFile);
     4263    dlg.setAcceptMode (QFileDialog::AcceptSave);
     4264    if (aSelectedFilter)
     4265        dlg.selectFilter (*aSelectedFilter);
     4266    dlg.setResolveSymlinks (aResolveSymlinks);
     4267    dlg.setConfirmOverwrite (false);
     4268    QAction *hidden = dlg.findChild <QAction*> ("qt_show_hidden_action");
     4269    if (hidden)
     4270    {
     4271        hidden->trigger();
     4272        hidden->setVisible (false);
     4273    }
     4274    return dlg.exec() == QDialog::Accepted ? dlg.selectedFiles().value (0, "") : QString::null;
     4275
     4276#else
     4277
     4278    QFileDialog::Options o;
     4279    if (!aResolveSymlinks)
     4280        o |= QFileDialog::DontResolveSymlinks;
     4281    o |= QFileDialog::DontConfirmOverwrite;
     4282    return QFileDialog::getSaveFileName (aParent, aCaption, aStartWith,
     4283                                         aFilters, aSelectedFilter, o);
     4284#endif
     4285}
     4286
     4287/**
    41064288 *  Reimplementation of QFileDialog::getOpenFileName() that removes some
    41074289 *  oddities and limitations.
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxImportApplianceWzd.cpp

    r17450 r17475  
    4141
    4242    /* Configure the file selector */
    43     mFileSelector->setMode (VBoxFilePathSelectorWidget::Mode_File);
     43    mFileSelector->setMode (VBoxFilePathSelectorWidget::Mode_File_Open);
    4444    mFileSelector->setResetEnabled (false);
    4545    mFileSelector->setFileDialogTitle (tr ("Select an appliance to import"));
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxProblemReporter.cpp

    r17450 r17475  
    548548}
    549549
    550 // Problem handlers
     550// Generic Problem handlers
     551/////////////////////////////////////////////////////////////////////////////
     552
     553bool VBoxProblemReporter::askForOverridingFileIfExists (const QString& aPath, QWidget *aParent /* = NULL */) const
     554{
     555    QFileInfo fi (aPath);
     556    if (fi.exists())
     557        return messageYesNo (aParent, Question, tr ("A file named <b>%1</b> already exists. Are you sure you want to replace it?<br /><br />The file already exists in \"%2\". Replacing it will overwrite its contents.").arg (fi.fileName()). arg (fi.absolutePath()));
     558    else
     559        return true;
     560}
     561
     562// Special Problem handlers
    551563/////////////////////////////////////////////////////////////////////////////
    552564
     
    21442156}
    21452157
    2146 bool VBoxProblemReporter::askForOverridingAppliance (const QString& aPath, QWidget *aParent /* = NULL */) const
    2147 {
    2148     return messageYesNo (aParent, Question, tr ("The file <b>%1</b> exists already. Are you sure you want override it?").arg (aPath), NULL);
    2149 }
    2150 
    21512158void VBoxProblemReporter::cannotExportAppliance (CAppliance *aAppliance, QWidget *aParent /* = NULL */) const
    21522159{
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette