VirtualBox

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


Ignore:
Timestamp:
Mar 19, 2018 7:55:18 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699 Adding a properties dialog to display file objects' properties

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl
Files:
2 edited

Legend:

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

    r71363 r71380  
    2727# include <QItemDelegate>
    2828# include <QGridLayout>
     29# include <QMenu>
     30# include <QTextEdit>
    2931# include <QPushButton>
    30 # include <QMenu>
    3132
    3233/* GUI includes: */
     
    3536# include "QILabel.h"
    3637# include "QILineEdit.h"
     38# include "QIMessageBox.h"
    3739# include "UIErrorString.h"
    3840# include "UIIconPool.h"
     
    8688class UIGuestControlFileView : public QTableView
    8789{
     90
    8891    Q_OBJECT;
     92
    8993signals:
    9094
     
    98102    void sigCopy();
    99103    void sigPaste();
     104    void sigShowProperties();
     105
     106    void sigSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
    100107
    101108public:
     
    105112
    106113protected:
     114    virtual void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected) /*override */;
    107115    void contextMenuEvent(QContextMenuEvent *pEvent);
    108116};
     
    145153
    146154/*********************************************************************************************************************************
    147 *   UIPathOperations implementation.                                                                                      *
     155*   UIPropertiesDialog definition.                                                                                          *
     156*********************************************************************************************************************************/
     157
     158/** A QIDialog child to display properties of a file object */
     159class UIPropertiesDialog : public QIDialog
     160{
     161
     162    Q_OBJECT;
     163
     164public:
     165
     166    UIPropertiesDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0);
     167    void setPropertyText(const QString &strProperty);
     168
     169private:
     170
     171    QVBoxLayout    *m_pMainLayout;
     172    QTextEdit *m_pInfoEdit;
     173
     174};
     175
     176
     177/*********************************************************************************************************************************
     178*   UIPathOperations implementation.                                                                                             *
    148179*********************************************************************************************************************************/
    149180
     
    318349        pActionPaste->setIcon(UIIconPool::iconSet(QString(":/shared_clipboard_16px.png")));
    319350        connect(pActionPaste, &QAction::triggered, this, &UIGuestControlFileView::sigPaste);
     351    }
     352
     353    menu->addSeparator();
     354    QAction *pActionShowProperties = menu->addAction(UIVMInformationDialog::tr("Properties"));
     355    if (pActionShowProperties)
     356    {
     357        pActionShowProperties->setIcon(UIIconPool::iconSet(QString(":/session_info_32px.png")));
     358        pActionShowProperties->setEnabled(selectionAvaible);
     359        connect(pActionShowProperties, &QAction::triggered, this, &UIGuestControlFileView::sigShowProperties);
    320360    }
    321361
     
    340380    if (pActionPaste)
    341381        disconnect(pActionPaste, &QAction::triggered, this, &UIGuestControlFileView::sigPaste);
     382    if (pActionShowProperties)
     383        disconnect(pActionShowProperties, &QAction::triggered, this, &UIGuestControlFileView::sigShowProperties);
    342384
    343385    delete menu;
     
    350392        return false;
    351393    return pSelectionModel->hasSelection();
     394}
     395
     396void UIGuestControlFileView::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
     397{
     398    emit sigSelectionChanged(selected, deselected);
     399    QTableView::selectionChanged(selected, deselected);
    352400}
    353401
     
    379427        return QString();
    380428    return m_pLineEdit->text();
     429}
     430
     431
     432/*********************************************************************************************************************************
     433*   UIPropertiesDialog implementation.                                                                                           *
     434*********************************************************************************************************************************/
     435
     436UIPropertiesDialog::UIPropertiesDialog(QWidget *pParent, Qt::WindowFlags flags)
     437    :QIDialog(pParent, flags)
     438    , m_pMainLayout(new QVBoxLayout)
     439    , m_pInfoEdit(new QTextEdit)
     440{
     441    setLayout(m_pMainLayout);
     442
     443    if (m_pMainLayout)
     444        m_pMainLayout->addWidget(m_pInfoEdit);
     445    if (m_pInfoEdit)
     446    {
     447        // m_pInfoEdit->setTextFormat(Qt::RichText);
     448        m_pInfoEdit->setReadOnly(true);
     449        m_pInfoEdit->setFrameStyle(QFrame::NoFrame);
     450        //  m_pInfoEdit->setText("Line 1\nLine 2\n\nLine 4");
     451        //  m_pInfoEdit->setWordWrap(true);
     452    }
     453    QIDialogButtonBox *pButtonBox =
     454        new QIDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, this);
     455    m_pMainLayout->addWidget(pButtonBox);
     456    connect(pButtonBox, &QIDialogButtonBox::accepted, this, &UIStringInputDialog::accept);
     457}
     458
     459void UIPropertiesDialog::setPropertyText(const QString &strProperty)
     460{
     461    if (!m_pInfoEdit)
     462        return;
     463
     464    m_pInfoEdit->setText(strProperty);
    381465}
    382466
     
    559643    , m_pCut(0)
    560644    , m_pPaste(0)
     645    , m_pShowProperties(0)
    561646
    562647{
     
    649734        connect(m_pView, &UIGuestControlFileView::sigRename,
    650735                this, &UIGuestControlFileTable::sltRename);
    651 
    652736        connect(m_pView, &UIGuestControlFileView::sigCreateNewDirectory,
    653737                this, &UIGuestControlFileTable::sltCreateNewDirectory);
    654 
    655738        connect(m_pView, &UIGuestControlFileView::sigCopy,
    656739                this, &UIGuestControlFileTable::sltCopy);
     
    659742        connect(m_pView, &UIGuestControlFileView::sigPaste,
    660743                this, &UIGuestControlFileTable::sltPaste);
     744        connect(m_pView, &UIGuestControlFileView::sigShowProperties,
     745                this, &UIGuestControlFileTable::sltShowProperties);
     746        connect(m_pView, &UIGuestControlFileView::sigSelectionChanged,
     747                this, &UIGuestControlFileTable::sltSelectionChanged);
    661748
    662749    }
     
    700787        m_pDelete->setIcon(UIIconPool::iconSet(QString(":/vm_delete_32px.png")));
    701788        m_pToolBar->addAction(m_pDelete);
     789        m_selectionDependentActions.push_back(m_pDelete);
    702790    }
    703791
     
    708796        m_pRename->setIcon(UIIconPool::iconSet(QString(":/name_16px_x2.png")));
    709797        m_pToolBar->addAction(m_pRename);
     798        m_selectionDependentActions.push_back(m_pRename);
    710799    }
    711800
     
    724813        m_pToolBar->addAction(m_pCopy);
    725814        connect(m_pCopy, &QAction::triggered, this, &UIGuestControlFileTable::sltCopy);
     815        m_selectionDependentActions.push_back(m_pCopy);
    726816    }
    727817
     
    732822        m_pToolBar->addAction(m_pCut);
    733823        connect(m_pCut, &QAction::triggered, this, &UIGuestControlFileTable::sltCut);
     824        m_selectionDependentActions.push_back(m_pCut);
    734825    }
    735826
     
    740831        m_pToolBar->addAction(m_pPaste);
    741832        connect(m_pPaste, &QAction::triggered, this, &UIGuestControlFileTable::sltPaste);
    742     }
     833        m_pPaste->setEnabled(false);
     834    }
     835
     836    m_pToolBar->addSeparator();
     837
     838    m_pShowProperties = new QAction(this);
     839    {
     840        m_pShowProperties->setIcon(UIIconPool::iconSet(QString(":/session_info_32px.png")));
     841        m_pToolBar->addAction(m_pShowProperties);
     842        connect(m_pShowProperties, &QAction::triggered, this, &UIGuestControlFileTable::sltShowProperties);
     843        m_selectionDependentActions.push_back(m_pShowProperties);
     844    }
     845
     846    disableSelectionDependentActions();
    743847}
    744848
     
    9901094void UIGuestControlFileTable::sltCopy()
    9911095{
     1096
     1097    m_copyCutBuffer = selectedItemPathList();
     1098    if (!m_copyCutBuffer.isEmpty())
     1099        m_pPaste->setEnabled(true);
     1100    else
     1101        m_pPaste->setEnabled(false);
    9921102}
    9931103
    9941104void UIGuestControlFileTable::sltCut()
    9951105{
     1106    m_copyCutBuffer = selectedItemPathList();
     1107    if (!m_copyCutBuffer.isEmpty())
     1108        m_pPaste->setEnabled(true);
     1109    else
     1110        m_pPaste->setEnabled(false);
    9961111}
    9971112
    9981113void UIGuestControlFileTable::sltPaste()
    9991114{
     1115    // paste them
     1116    m_copyCutBuffer.clear();
     1117    m_pPaste->setEnabled(false);
     1118}
     1119
     1120void UIGuestControlFileTable::sltShowProperties()
     1121{
     1122    QString fsPropertyString = fsObjectPropertyString();
     1123    if (fsPropertyString.isEmpty())
     1124        return;
     1125
     1126    UIPropertiesDialog *dialog = new UIPropertiesDialog();
     1127    dialog->setPropertyText(fsPropertyString);
     1128    dialog->execute();
     1129
     1130
     1131
     1132    // QIMessageBox *pFsObjectPropertiesBox = new QIMessageBox("Properties",
     1133    //                                                         fsPropertyString,
     1134    //                                                         AlertIconType_Information,
     1135    //                                                         AlertButton_Ok| AlertButtonOption_Escape, 0, 0, this);
     1136    // pFsObjectPropertiesBox->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
     1137
     1138
     1139    //     //pFsObjectPropertiesBox->setFixedWidth(300);
     1140    // pFsObjectPropertiesBox->exec();
     1141
     1142    // delete pFsObjectPropertiesBox;
     1143}
     1144
     1145void UIGuestControlFileTable::sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
     1146{
     1147    /* Disable all the action that operate on some selection: */
     1148    if (!deselected.isEmpty() && selected.isEmpty())
     1149        disableSelectionDependentActions();
     1150
     1151    /* Enable all the action that operate on some selection: */
     1152    if (deselected.isEmpty() && !selected.isEmpty())
     1153        enableSelectionDependentActions();
    10001154}
    10011155
     
    10721226        m_pPaste->setToolTip(UIVMInformationDialog::tr("Paste the copied item(s)"));
    10731227        m_pPaste->setStatusTip(UIVMInformationDialog::tr("Paste the copied item(s)"));
     1228    }
     1229
     1230    if (m_pShowProperties)
     1231    {
     1232        m_pShowProperties->setText(UIVMInformationDialog::tr("Show the properties of the selected item(s)"));
     1233        m_pShowProperties->setToolTip(UIVMInformationDialog::tr("Show the properties of the selected item(s)"));
     1234        m_pShowProperties->setStatusTip(UIVMInformationDialog::tr("Show the properties of the selected item(s)"));
    10741235    }
    10751236}
     
    11671328}
    11681329
     1330void UIGuestControlFileTable::enableSelectionDependentActions()
     1331{
     1332    for (int i = 0; i < m_selectionDependentActions.size(); ++i)
     1333    {
     1334        if (m_selectionDependentActions[i])
     1335            m_selectionDependentActions[i]->setEnabled(true);
     1336    }
     1337}
     1338
     1339void UIGuestControlFileTable::disableSelectionDependentActions()
     1340{
     1341    /* Disable all the action that operate on some selection: */
     1342    for (int i = 0; i < m_selectionDependentActions.size(); ++i)
     1343    {
     1344        if (m_selectionDependentActions[i])
     1345            m_selectionDependentActions[i]->setEnabled(false);
     1346    }
     1347}
     1348
     1349QString UIGuestControlFileTable::fileTypeString(FileObjectType type)
     1350{
     1351    QString strType("Unknown");
     1352    switch(type)
     1353    {
     1354        case FileObjectType_File:
     1355            strType = "File";
     1356            break;
     1357        case FileObjectType_Directory:
     1358            strType = "Directory";
     1359            break;
     1360        case FileObjectType_SymLink:
     1361            strType = "Symbolic Link";
     1362            break;
     1363        case FileObjectType_Other:
     1364            strType = "Other";
     1365            break;
     1366
     1367        case FileObjectType_Unknown:
     1368        default:
     1369            break;
     1370    }
     1371    return strType;
     1372}
     1373
    11691374
    11701375/*********************************************************************************************************************************
     
    12221427
    12231428            data << fsInfo.GetName() << static_cast<qulonglong>(fsInfo.GetObjectSize()) << changeTime;
    1224             FileObjectType fileType = getFileType(fsInfo);
    1225             UIFileTableItem *item = new UIFileTableItem(data, parent, fileType);
     1429            FileObjectType fsObjectType = fileType(fsInfo);
     1430            UIFileTableItem *item = new UIFileTableItem(data, parent, fsObjectType);
    12261431            item->setPath(UIPathOperations::mergePaths(strPath, fsInfo.GetName()));
    1227             if (fileType == FileObjectType_Directory)
     1432            if (fsObjectType == FileObjectType_Directory)
    12281433            {
    12291434                directories.insert(fsInfo.GetName(), item);
    12301435                item->setIsOpened(false);
    12311436            }
    1232             else if(fileType == FileObjectType_File)
     1437            else if(fsObjectType == FileObjectType_File)
    12331438            {
    12341439                files.insert(fsInfo.GetName(), item);
     
    12361441            }
    12371442            /** @todo Seems like our API is not able to detect symlinks: */
    1238             else if(fileType == FileObjectType_SymLink)
     1443            else if(fsObjectType == FileObjectType_SymLink)
    12391444            {
    12401445                files.insert(fsInfo.GetName(), item);
     
    13901595}
    13911596
    1392 FileObjectType UIGuestFileTable::getFileType(const CFsObjInfo &fsInfo)
     1597FileObjectType UIGuestFileTable::fileType(const CFsObjInfo &fsInfo)
    13931598{
    13941599    if (fsInfo.isNull() || !fsInfo.isOk())
     
    14041609}
    14051610
     1611QString UIGuestFileTable::fsObjectPropertyString()
     1612{
     1613    return QString();
     1614}
     1615
    14061616
    14071617/*********************************************************************************************************************************
     
    14431653        QList<QVariant> data;
    14441654        data << fileInfo.fileName() << fileInfo.size() << fileInfo.lastModified();
    1445         UIFileTableItem *item = new UIFileTableItem(data, parent, getFileType(fileInfo));
     1655        UIFileTableItem *item = new UIFileTableItem(data, parent, fileType(fileInfo));
    14461656        item->setPath(fileInfo.absoluteFilePath());
    14471657        /* if the item is a symlink set the target path and
     
    15361746}
    15371747
    1538 FileObjectType UIHostFileTable::getFileType(const QFileInfo &fsInfo)
     1748FileObjectType UIHostFileTable::fileType(const QFileInfo &fsInfo)
    15391749{
    15401750    if (!fsInfo.exists())
     
    15521762}
    15531763
     1764QString UIHostFileTable::fsObjectPropertyString()
     1765{
     1766    QStringList selectedObjects = selectedItemPathList();
     1767    if (selectedObjects.isEmpty())
     1768        return QString();
     1769    if (selectedObjects.size() == 1)
     1770    {
     1771        if (selectedObjects.at(0).isNull())
     1772            return QString();
     1773        QFileInfo fileInfo(selectedObjects.at(0));
     1774        if (!fileInfo.exists())
     1775            return QString();
     1776        QString propertyString;
     1777        /* Name: */
     1778        propertyString += "<b>Name:</b> " + fileInfo.fileName() + "\n";
     1779        if (!fileInfo.suffix().isEmpty())
     1780            propertyString += "." + fileInfo.suffix();
     1781        propertyString += "<br/>";
     1782        /* Size: */
     1783        propertyString += "<b>Size:</b> " + QString::number(fileInfo.size()) + QString(" bytes");
     1784        propertyString += "<br/>";
     1785        /* Type: */
     1786        propertyString += "<b>Type:</b> " + fileTypeString(fileType(fileInfo));
     1787        propertyString += "<br/>";
     1788        /* Creation Date: */
     1789        propertyString += "<b>Created:</b> " + fileInfo.created().toString();
     1790        propertyString += "<br/>";
     1791        /* Last Modification Date: */
     1792        propertyString += "<b>Modified:</b> " + fileInfo.lastModified().toString();
     1793        propertyString += "<br/>";
     1794        /* Owner: */
     1795        propertyString += "<b>Owner:</b> " + fileInfo.owner();
     1796
     1797
     1798        return propertyString;
     1799    }
     1800    return QString();
     1801}
     1802
    15541803#include "UIGuestControlFileTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h

    r71362 r71380  
    154154    virtual bool renameItem(UIFileTableItem *item, QString newBaseName) = 0;
    155155    virtual bool createDirectory(const QString &path, const QString &directoryName) = 0;
     156    virtual QString fsObjectPropertyString() = 0;
     157    static QString fileTypeString(FileObjectType type);
    156158    void             goIntoDirectory(const QModelIndex &itemIndex);
    157159    /** Follow the path trail, open directories as we go and descend */
     
    170172    QILabel                 *m_pLocationLabel;
    171173
    172 protected slots:
     174private slots:
    173175
    174176    void sltItemDoubleClicked(const QModelIndex &index);
     
    181183    void sltCut();
    182184    void sltPaste();
     185    void sltShowProperties();
    183186    void sltCreateNewDirectory();
     187    void sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
    184188
    185189private:
     
    192196    /** Shows a modal dialog with a line edit for user to enter a new directory name and return the entered string*/
    193197    QString         getNewDirectoryName();
     198    void            enableSelectionDependentActions();
     199    void            disableSelectionDependentActions();
    194200    QGridLayout     *m_pMainLayout;
    195201    QILineEdit      *m_pCurrentLocationEdit;
     
    201207    QAction         *m_pRename;
    202208    QAction         *m_pCreateNewDirectory;
    203 
    204 
    205209    QAction         *m_pCopy;
    206210    QAction         *m_pCut;
    207211    QAction         *m_pPaste;
    208 
     212    QAction         *m_pShowProperties;
     213    /** The vector of action which need some selection to work on like cut, copy etc. */
     214    QVector<QAction*> m_selectionDependentActions;
     215    /** The absolue path list of the file objects which user has chosen to cut/copy. this
     216        list will be cleaned after a paste operation or overwritten by a subsequent cut/copy */
     217    QStringList       m_copyCutBuffer;
    209218    friend class UIGuestControlFileModel;
    210219};
     
    231240    virtual bool renameItem(UIFileTableItem *item, QString newBaseName);
    232241    virtual bool createDirectory(const QString &path, const QString &directoryName);
     242    virtual QString fsObjectPropertyString() /* override */;
    233243
    234244private:
    235245
    236     static FileObjectType getFileType(const CFsObjInfo &fsInfo);
     246    static FileObjectType fileType(const CFsObjInfo &fsInfo);
    237247    bool copyGuestToHost(const QString &guestSourcePath, const QString& hostDestinationPath);
    238248    bool copyHostToGuest(const QString& hostSourcePath, const QString &guestDestinationPath);
     
    254264protected:
    255265
    256     static FileObjectType getFileType(const QFileInfo &fsInfo);
     266    static FileObjectType fileType(const QFileInfo &fsInfo);
    257267    void retranslateUi() /* override */;
    258268    virtual void readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) /* override */;
     
    261271    virtual bool renameItem(UIFileTableItem *item, QString newBaseName);
    262272    virtual bool createDirectory(const QString &path, const QString &directoryName);
     273    virtual QString fsObjectPropertyString() /* override */;
     274
    263275};
    264276
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