VirtualBox

Changeset 79212 in vbox


Ignore:
Timestamp:
Jun 18, 2019 2:06:54 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131389
Message:

FE/Qt: bugref:6143. Saving and loading layouts tofrom a default folder

Location:
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp

    r79206 r79212  
    2121#include <QFile>
    2222#include <QGroupBox>
     23#include <QInputDialog>
    2324#include <QLabel>
    2425#include <QLineEdit>
     
    4041#include "UIExtraDataManager.h"
    4142#include "UIIconPool.h"
     43#include "UIModalWindowManager.h"
    4244#include "UISession.h"
    4345#include "UISoftKeyboard.h"
     
    5355class UISoftKeyboardLayout;
    5456class UISoftKeyboardRow;
     57
     58const int iMessageTimeout = 3000;
     59const QString strSubDirectorName("keyboardLayouts");
    5560
    5661enum UIKeyState
     
    407412signals:
    408413
     414    void sigStatusBarMessage(const QString &strMessage);
    409415    void sigPutKeyboardSequence(QVector<LONG> sequence);
    410416    void sigCurrentLayoutChange();
     
    432438    void updateKeyCaptionsInLayout(UISoftKeyboardKey *pKey);
    433439    void addLayout(const UISoftKeyboardLayout &newLayout);
     440    void saveCurentLayoutToFile();
    434441
    435442protected:
     
    444451
    445452    void sltContextMenuRequest(const QPoint &point);
    446     void sltSaveLayout();
    447453    void sltPhysicalLayoutForLayoutChanged(int iIndex);
    448454
     
    465471    void               setCurrentLayout(UISoftKeyboardLayout *pLayout);
    466472    UISoftKeyboardLayout *findLayoutByName(const QString &strName);
    467 
     473    /** Looks under the default keyboard layout folder and add the file names to the fileList. */
     474    void               lookAtDefaultLayoutFolder(QStringList &fileList);
    468475    UISoftKeyboardKey *m_pKeyUnderMouse;
    469476    UISoftKeyboardKey *m_pKeyBeingEdited;
     
    476483    QColor m_keyEditColor;
    477484    QVector<UISoftKeyboardKey*> m_pressedModifiers;
    478     //QVector<UISoftKeyboardRow>  m_rows;
    479485    QVector<UISoftKeyboardPhysicalLayout> m_physicalLayouts;
    480486    QVector<UISoftKeyboardLayout>         m_layouts;
     
    12911297{
    12921298    return QSize(0.5 * m_minimumSize.width(), 0.5 * m_minimumSize.height());
    1293     //return m_minimumSize;
    12941299}
    12951300
     
    14141419}
    14151420
    1416 // bool UISoftKeyboardWidget::eventFilter(QObject *pWatched, QEvent *pEvent)
    1417 // {
    1418 //     if (pWatched != m_pLayoutEditor)
    1419 //         return QIWithRetranslateUI<QWidget>::eventFilter(pWatched, pEvent);
    1420 
    1421 //     switch (pEvent->type())
    1422 //     {
    1423 //         case QEvent::KeyPress:
    1424 //         {
    1425 //             QKeyEvent *pKeyEvent = dynamic_cast<QKeyEvent*>(pEvent);
    1426 //             if (pKeyEvent && pKeyEvent->key() == Qt::Key_Escape)
    1427 //             {
    1428 //                 setKeyBeingEdited(0);
    1429 //                 update();
    1430 //                 return true;
    1431 //             }
    1432 //             else if (pKeyEvent && (pKeyEvent->key() == Qt::Key_Enter || pKeyEvent->key() == Qt::Key_Return))
    1433 //             {
    1434 //                 // if (m_pKeyBeingEdited)
    1435 //                 //     m_pKeyBeingEdited->setStaticKeyCap(m_pLayoutEditor->text());
    1436 //                 setKeyBeingEdited(0);
    1437 //                 update();
    1438 //                 return true;
    1439 //             }
    1440 //             break;
    1441 //         }
    1442 //         default:
    1443 //             break;
    1444 //     }
    1445 
    1446 //     return QIWithRetranslateUI<QWidget>::eventFilter(pWatched, pEvent);
    1447 // }
    1448 
    1449 
    14501421void UISoftKeyboardWidget::retranslateUi()
    14511422{
     
    14571428}
    14581429
    1459 // void UISoftKeyboardWidget::sltLoadLayout(QAction *pSenderAction)
    1460 // {
    1461 //     if (!pSenderAction)
    1462 //         return;
    1463 //     if (pSenderAction == m_pLoadLayoutFileAction)
    1464 //     {
    1465 //         const QString strFileName = QIFileDialog::getOpenFileName(QString(), UISoftKeyboard::tr("XML files (*.xml)"), this,
    1466 //                                                                   UISoftKeyboard::tr("Choose file to load physical keyboard layout.."));
    1467 //         if (!strFileName.isEmpty() && loadPhysicalLayout(strFileName))
    1468 //         {
    1469 //             m_pLastSelectedLayout = pSenderAction;
    1470 //             m_pLoadLayoutFileAction->setData(strFileName);
    1471 //
    1472 //             return;
    1473 //         }
    1474 //     }
    1475 //     else
    1476 //     {
    1477 //         QString strLayout = pSenderAction->data().toString();
    1478 //         if (!strLayout.isEmpty() && loadPhysicalLayout(strLayout))
    1479 //         {
    1480 //             m_pLastSelectedLayout = pSenderAction;
    1481 //             emit sigCurrentLayoutChange(strLayout);
    1482 //             return;
    1483 //         }
    1484 //     }
    1485 //     /* In case something went wrong try to restore the previous layout: */
    1486 //     if (m_pLastSelectedLayout)
    1487 //     {
    1488 //         QString strLayout = m_pLastSelectedLayout->data().toString();
    1489 //         loadPhysicalLayout(strLayout);
    1490 //         emit sigCurrentLayoutChange(strLayout);
    1491 //         m_pLastSelectedLayout->setChecked(true);
    1492 //     }
    1493 // }
    1494 
    1495 void UISoftKeyboardWidget::sltSaveLayout()
    1496 {
    1497     QString strFileName = QIFileDialog::getSaveFileName(vboxGlobal().documentsPath(), UISoftKeyboard::tr("XML files (*.xml)"),
    1498                                                         this, tr("Save layout to a file..."));
    1499     if (strFileName.isEmpty())
    1500         return;
     1430void UISoftKeyboardWidget::saveCurentLayoutToFile()
     1431{
     1432    QString strHomeFolder = vboxGlobal().homeFolder();
     1433    QDir dir(strHomeFolder);
     1434    if (!dir.exists(strSubDirectorName))
     1435    {
     1436        if (!dir.mkdir(strSubDirectorName))
     1437        {
     1438            sigStatusBarMessage(QString("%1 %2").arg(UISoftKeyboard::tr("Error! Could not create folder under").arg(strHomeFolder)));
     1439            return;
     1440        }
     1441    }
     1442
     1443    strHomeFolder += QString(QDir::separator()) + strSubDirectorName;
     1444    QInputDialog dialog(this);
     1445    dialog.setInputMode(QInputDialog::TextInput);
     1446    dialog.setWindowModality(Qt::WindowModal);
     1447    dialog.setWindowTitle(UISoftKeyboard::tr("Provide a file name"));
     1448    dialog.setLabelText(QString("%1 %2").arg(UISoftKeyboard::tr("The File will be saved under:\n")).arg(strHomeFolder));
     1449    if (dialog.exec() == QDialog::Rejected)
     1450        return;
     1451    QString strFileName(dialog.textValue());
     1452    if (strFileName.isEmpty() || strFileName.contains("..") || strFileName.contains(QDir::separator()))
     1453    {
     1454        sigStatusBarMessage(QString("%1 %2").arg(strFileName).arg(UISoftKeyboard::tr(" is an invalid file name")));
     1455        return;
     1456    }
     1457
    15011458    if (!m_pCurrentKeyboardLayout)
    15021459        return;
     
    15041461    UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(m_pCurrentKeyboardLayout->m_physicalLayoutUuid);
    15051462    if (!pPhysicalLayout)
    1506         return;
     1463    {
     1464        sigStatusBarMessage("The layout file could not be saved");
     1465        return;
     1466    }
    15071467
    15081468    QFileInfo fileInfo(strFileName);
    15091469    if (fileInfo.suffix().compare("xml", Qt::CaseInsensitive) != 0)
    15101470        strFileName += ".xml";
    1511 
     1471    strFileName = strHomeFolder + QString(QDir::separator()) + strFileName;
    15121472    QFile xmlFile(strFileName);
    15131473    if (!xmlFile.open(QIODevice::WriteOnly))
    1514         return;
     1474    {
     1475        sigStatusBarMessage("The layout file could not be saved");
     1476        return;
     1477    }
     1478
    15151479    QXmlStreamWriter xmlWriter;
    15161480    xmlWriter.setDevice(&xmlFile);
     
    15361500           xmlWriter.writeTextElement("shiftcaption", key.shiftCaption());
    15371501           xmlWriter.writeTextElement("altgrcaption", key.altGrCaption());
    1538 
    1539            // if (!key.keyCap().isEmpty())
    1540            //     xmlWriter.writeTextElement("keycap", key.keyCap());
    1541            // else
    1542            //     xmlWriter.writeTextElement("keycap", key.staticKeyCap());
    15431502           xmlWriter.writeEndElement();
    15441503       }
     
    15481507
    15491508   xmlFile.close();
    1550 }
    1551 
    1552 // void UISoftKeyboardWidget::sltLoadKeyCapFile()
    1553 // {
    1554 //     const QString strFileName = QIFileDialog::getOpenFileName(QString(), UISoftKeyboard::tr("XML files (*.xml)"), this,
    1555 //                                                               UISoftKeyboard::tr("Choose file to load key captions.."));
    1556 //     if (strFileName.isEmpty())
    1557 //         return;
    1558 //     UIKeyboardLayoutReader keyCapReader(strFileName);
    1559 //     //const QMap<int, QString> &keyCapMap = keyCapReader.keyCapMap();
    1560 
    1561 //     //for (int i = 0; i < m_rows.size(); ++i)
    1562 //     {
    1563 //         //QVector<UISoftKeyboardKey> &keys = m_rows[i].keys();
    1564 //         // for (int j = 0; j < keys.size(); ++j)
    1565 //         // {
    1566 //         //     UISoftKeyboardKey &key = keys[j];
    1567 //         //     if (keyCapMap.contains(key.position()))
    1568 //         //         key.setKeyCap(keyCapMap[key.position()]);
    1569 //         // }
    1570 //     }
    1571 //     emit sigKeyCapChange(strFileName);
    1572 // }
     1509
     1510   sigStatusBarMessage(QString("%1 %2").arg(strFileName).arg(UISoftKeyboard::tr(" is saved")));
     1511}
    15731512
    15741513void UISoftKeyboardWidget::toggleEditMode(bool fIsEditMode)
     
    18341773{
    18351774    m_pressedModifiers.clear();
    1836     //m_rows.clear();
    18371775}
    18381776
     
    18451783        loadPhysicalLayout(strName);
    18461784
    1847     /* Load keyboard layouts from resources: */
     1785    /* Add keyboard layouts from resources: */
    18481786    QStringList keyboardLayoutNames;
    18491787    keyboardLayoutNames << ":/us_international.xml"
    18501788                        <<":/german.xml";
     1789    /* Add keyboard layouts from the defalt keyboard layout folder: */
     1790    lookAtDefaultLayoutFolder(keyboardLayoutNames);
    18511791    foreach (const QString &strName, keyboardLayoutNames)
    18521792        loadKeyboardLayout(strName);
     
    19261866    }
    19271867    return 0;
     1868}
     1869
     1870void UISoftKeyboardWidget::lookAtDefaultLayoutFolder(QStringList &fileList)
     1871{
     1872    QString strFolder = QString("%1%2%3").arg(vboxGlobal().homeFolder()).arg(QDir::separator()).arg(strSubDirectorName);
     1873    QDir dir(strFolder);
     1874    if (!dir.exists())
     1875        return;
     1876    QStringList filters;
     1877    filters << "*.xml";
     1878    dir.setNameFilters(filters);
     1879    QFileInfoList fileInfoList = dir.entryInfoList();
     1880    foreach (const QFileInfo &fileInfo, fileInfoList)
     1881        fileList << fileInfo.absoluteFilePath();
    19281882}
    19291883
     
    23192273}
    23202274
    2321 bool UISoftKeyboard::eventFilter(QObject *pWatched, QEvent *pEvent)
    2322 {
    2323     Q_UNUSED(pWatched);
    2324     Q_UNUSED(pEvent);
    2325     // if (pWatched != m_pLayoutListButton)
    2326     //     return QIWithRetranslateUI<QMainWindow>::eventFilter(pWatched, pEvent);
    2327 
    2328     // if (pEvent->type() == QEvent::MouseButtonPress)
    2329     // {
    2330     //     QMouseEvent *pMouseEvent = dynamic_cast<QMouseEvent*>(pEvent);
    2331     //     if (pMouseEvent && pMouseEvent->button() == Qt::LeftButton)
    2332     //     {
    2333     //         if (m_pKeyboardWidget)
    2334     //             m_pKeyboardWidget->showContextMenu(m_pLayoutListButton->mapToGlobal(pMouseEvent->pos()));
    2335     //         return true;
    2336     //     }
    2337     // }
    2338 
    2339     return QIWithRetranslateUI<QMainWindow>::eventFilter(pWatched, pEvent);
    2340 }
    2341 
    23422275void UISoftKeyboard::sltKeyboardLedsChange()
    23432276{
     
    24372370void UISoftKeyboard::sltSaveLayout()
    24382371{
     2372    if (m_pKeyboardWidget)
     2373        m_pKeyboardWidget->saveCurentLayoutToFile();
     2374}
     2375
     2376void UISoftKeyboard::sltStatusBarMessage(const QString &strMessage)
     2377{
     2378    statusBar()->showMessage(strMessage, iMessageTimeout);
    24392379}
    24402380
     
    24522392    m_pSidePanelWidget->hide();
    24532393
    2454     m_pSplitter->addWidget(m_pSidePanelWidget);
    2455     m_pSplitter->setCollapsible(0, false);
    2456 
    24572394    m_pLayoutSelector = new UILayoutSelector;
    24582395    if (m_pLayoutSelector)
     
    24692406    m_pKeyboardWidget->updateGeometry();
    24702407    m_pSplitter->addWidget(m_pKeyboardWidget);
     2408    m_pSplitter->addWidget(m_pSidePanelWidget);
     2409    m_pSplitter->setCollapsible(0, false);
     2410    m_pSplitter->setCollapsible(1, false);
    24712411
    24722412    statusBar()->setStyleSheet( "QStatusBar::item { border: 0px}" );
    24732413    m_pStatusBarWidget = new UISoftKeyboardStatusBarWidget;
    2474     statusBar()->addWidget(m_pStatusBarWidget);
     2414    statusBar()->addPermanentWidget(m_pStatusBarWidget);
    24752415
    24762416    retranslateUi();
     
    24832423    connect(m_pKeyboardWidget, &UISoftKeyboardWidget::sigCurrentLayoutChange, this, &UISoftKeyboard::sltCurentLayoutChanged);
    24842424    connect(m_pKeyboardWidget, &UISoftKeyboardWidget::sigKeyToEdit, this, &UISoftKeyboard::sltKeyToEditChanged);
     2425    connect(m_pKeyboardWidget, &UISoftKeyboardWidget::sigStatusBarMessage, this, &UISoftKeyboard::sltStatusBarMessage);
    24852426
    24862427    connect(m_pLayoutSelector, &UILayoutSelector::sigLayoutSelectionChanged, this, &UISoftKeyboard::sltLayoutSelectionChanged);
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h

    r79206 r79212  
    6161
    6262    virtual void retranslateUi() /* override */;
    63     bool eventFilter(QObject *pWatched, QEvent *pEvent)/* override */;
    6463
    6564private slots:
     
    8281    void sltCopyLayout();
    8382    void sltSaveLayout();
     83    void sltStatusBarMessage(const QString &strMessage);
    8484
    8585private:
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