VirtualBox

Changeset 57688 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Sep 10, 2015 12:08:52 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: 7837: Runtime UI: Taking immediate screenshot of VM, before asking for filename to save.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r57591 r57688  
    16461646        return;
    16471647
     1648    /* Formatting default and temporary filenames for screenshot accroding to current time: */
     1649    const QFileInfo fi(machine().GetSettingsFilePath());
     1650    const QString strCurrentTime = QDateTime::currentDateTime().toString("dd_MM_yyyy_hh_mm_ss");
     1651    const QString strFormatDefaultFileName = QString("VirtualBox").append("_").append(machine().GetName()).append("_").
     1652            append(strCurrentTime);
     1653    const QString strDefaultFileName = QDir(fi.absolutePath()).absoluteFilePath(strFormatDefaultFileName);
     1654    const QString strTempFile = QDir(fi.absolutePath()).absoluteFilePath("temp").append(strCurrentTime).append(".png");
     1655
     1656    /* Do the screenshot: */
     1657    takeScreenshot(strTempFile, "png");
     1658
    16481659    /* Which image formats for writing does this Qt version know of? */
    16491660    QList<QByteArray> formats = QImageWriter::supportedImageFormats();
    16501661    QStringList filters;
    1651     /* Build a filters list out of it. */
     1662    /* Build a filters list out of it: */
    16521663    for (int i = 0; i < formats.size(); ++i)
    16531664    {
     
    16571668            filters << s;
    16581669    }
    1659     /* Try to select some common defaults. */
     1670    /* Try to select some common defaults: */
    16601671    QString strFilter;
    16611672    int i = filters.indexOf(QRegExp(".*png.*", Qt::CaseInsensitive));
     
    16811692#endif /* Q_WS_WIN */
    16821693
    1683     /* Request the filename from the user. */
    1684     QFileInfo fi(machine().GetSettingsFilePath());
    1685     QString strAbsolutePath(fi.absolutePath());
    1686     QString strCompleteBaseName(fi.completeBaseName());
    1687     QString strStart = QDir(strAbsolutePath).absoluteFilePath(strCompleteBaseName);
    1688     QString strFilename = QIFileDialog::getSaveFileName(strStart,
     1694    /* Request the filename from the user: */
     1695    const QString strFilename = QIFileDialog::getSaveFileName(strDefaultFileName,
    16891696                                                        filters.join(";;"),
    16901697                                                        activeMachineWindow(),
     
    17041711#endif /* Q_WS_WIN */
    17051712
    1706     /* Do the screenshot. */
    17071713    if (!strFilename.isEmpty())
    1708         takeScreenshot(strFilename, strFilter.split(" ").value(0, "png"));
     1714    {
     1715        const QString strFormat = strFilter.split(" ").value(0, "png");
     1716        const QImage tmpImage(strTempFile);
     1717
     1718    /* On X11 Qt Filedialog returns the filepath without the filetype suffix,
     1719     * so adding it ourselves: */
     1720    #ifdef Q_WS_X11
     1721        tmpImage.save(QDir::toNativeSeparators(QFile::encodeName(QString("%1.%2").arg(strFilename, strFormat))),
     1722                    strFormat.toAscii().constData());
     1723    #else /* !Q_WS_X11 */
     1724        tmpImage.save(QDir::toNativeSeparators(QFile::encodeName(strFilename)),
     1725                    strFormat.toAscii().constData());
     1726    #endif /* !Q_WS_X11 */
     1727    }
     1728    QFile::remove(strTempFile);
    17091729}
    17101730
Note: See TracChangeset for help on using the changeset viewer.

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