VirtualBox

Ignore:
Timestamp:
Jan 16, 2007 12:49:17 PM (18 years ago)
Author:
vboxsync
Message:

FE/Qt [dsen]:

  • Replaced the "enumeration in progress" indication in the VDM list-views with progress bar list view items. Single media enumretaion events for individual media are handled again to make progress bars run.
  • Added static methods to VBoxDiskImageManagerDlg to compose tool tips for media. These methods are used in the VM settings dialog for media shortcut comboboxes.
  • Fixed: The Remove button is now disabled for hard disks with children.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxDiskImageManagerDlg.ui.h

    r1 r59  
    106106    int compare (QListViewItem *aItem, int aColumn, bool aAscending) const
    107107    {
     108        if (aItem->rtti() == 1002)
     109            return aAscending ? 1 : -1;
     110
    108111        ULONG64 thisValue = vboxGlobal().parseSize (       text (aColumn));
    109112        ULONG64 thatValue = vboxGlobal().parseSize (aItem->text (aColumn));
    110113        if (thisValue && thatValue)
    111             return thisValue > thatValue ? 1 : -1;
     114        {
     115            if (thisValue == thatValue)
     116                return 0;
     117            else
     118                return thisValue > thatValue ? 1 : -1;
     119        }
    112120        else
    113121            return QListViewItem::compare (aItem, aColumn, aAscending);
     
    136144
    137145    QString mToolTip;
     146};
     147
     148
     149class ProgressBarItem : public QListViewItem, public QProgressBar
     150{
     151public:
     152
     153    ProgressBarItem (QListView *aParent, ULONG aTotalSteps) :
     154        QListViewItem (aParent)
     155    {
     156        setFrameShadow (Sunken);
     157        setFrameShape (Panel);
     158        setSelectable (false);
     159        setProgress (0, aTotalSteps);
     160        setPercentageVisible (false);
     161    }
     162
     163    void paintCell (QPainter *p, const QColorGroup &cg,
     164                    int column, int width, int align)
     165    {
     166        setMaximumWidth (100);
     167        setFixedHeight (QListViewItem::height());
     168        QListViewItem::paintCell (p, cg, column, width, align);
     169        if (column == 0)
     170        {
     171            drawContents (p);
     172            drawFrame (p);
     173        }
     174    }
     175
     176    void increaseProgress() { setProgress (progress() + 1); }
     177
     178    int rtti() const { return 1002; }
     179
     180    int compare (QListViewItem *aItem, int aColumn, bool aAscending) const
     181    {
     182        if (aItem->rtti() == 1001)
     183            return aAscending ? -1 : 1;
     184        else
     185            return 0;
     186    }
    138187};
    139188
     
    163212        connect (&vboxGlobal(), SIGNAL (snapshotChanged (const VBoxSnapshotEvent &)),
    164213                 mModelessDialog, SLOT (refreshAll()));
    165        
     214
    166215        /* listen also to the machine state change because hard disks of running
    167216         * VMs are inaccessible by the current design */
     
    184233    mToBeRefreshed = false;
    185234    mInLoop = false;
     235
     236    mHdsProgress = 0;
     237    mCdsProgress = 0;
     238    mFdsProgress = 0;
    186239
    187240    defaultButton = searchDefaultButton();
     
    221274    /* setup image list views */
    222275
     276    hdsView->setShowSortIndicator (true);
     277    cdsView->setShowSortIndicator (true);
     278    fdsView->setShowSortIndicator (true);
     279
    223280    hdsView->setColumnAlignment (1, Qt::AlignRight);
    224281    hdsView->setColumnAlignment (2, Qt::AlignRight);
     
    234291    cdsView->header()->setStretchEnabled (true, 0);
    235292
     293    /* setup list-view's item tooltip */
     294    hdsView->setShowToolTips (false);
     295    cdsView->setShowToolTips (false);
     296    fdsView->setShowToolTips (false);
    236297    connect (hdsView, SIGNAL (onItem (QListViewItem*)),
    237298             this, SLOT (mouseOnItem(QListViewItem*)));
     
    240301    connect (fdsView, SIGNAL (onItem (QListViewItem*)),
    241302             this, SLOT (mouseOnItem(QListViewItem*)));
    242     hdsView->setShowToolTips (false);
    243     cdsView->setShowToolTips (false);
    244     fdsView->setShowToolTips (false);
     303
     304    /* setup dnd handlers */
     305    hdsView->viewport()->setAcceptDrops (true);
     306    cdsView->viewport()->setAcceptDrops (true);
     307    fdsView->viewport()->setAcceptDrops (true);
     308    connect (hdsView, SIGNAL (dropped (QDropEvent *)),
     309             this, SLOT (addDroppedImages (QDropEvent*)));
     310    connect (cdsView, SIGNAL (dropped (QDropEvent*)),
     311             this, SLOT (addDroppedImages (QDropEvent*)));
     312    connect (fdsView, SIGNAL (dropped (QDropEvent*)),
     313             this, SLOT (addDroppedImages (QDropEvent*)));
    245314
    246315    /* status-bar currently disabled */
     
    424493
    425494    VBoxGlobal::centerWidget (this, parentWidget());
    426 
    427     updateNotice (getCurrentListView());
    428495}
    429496
     
    432499{
    433500    QListView *currentList = getCurrentListView();
    434     DiskImageItem *item = 0;
    435     if (aItem->rtti() == 1001)
    436         item = static_cast<DiskImageItem*> (aItem);
    437     Assert (item);
    438 
    439     QToolTip::add (currentList->viewport(), currentList->itemRect(item), item->getToolTip());
     501    QString tip;
     502    switch (aItem->rtti())
     503    {
     504        case 1001:
     505            tip = static_cast<DiskImageItem*> (aItem)->getToolTip();
     506            break;
     507        case 1002:
     508            tip = tr ("Enumeration in progress...", "Media accessibility check");
     509            break;
     510        default:
     511            Assert (0);
     512    }
     513    QToolTip::add (currentList->viewport(), currentList->itemRect (aItem), tip);
    440514}
    441515
     
    445519    sizeGrip->move (centralWidget()->rect().bottomRight() -
    446520                    QPoint(sizeGrip->rect().width() - 1, sizeGrip->rect().height() - 1));
    447 
    448     updateNotice (getCurrentListView());
    449521}
    450522
     
    546618    switch (aEvent->type())
    547619    {
    548         /* Dragged object(s) has entered list-view area */
    549620        case QEvent::DragEnter:
    550621        {
     
    557628            break;
    558629        }
    559         /* Dragged object(s) was dropped on list-view area */
    560         case QEvent::Drop:
    561         {
    562             if (aObject == currentList)
    563             {
    564                 QDropEvent *dropEvent = static_cast<QDropEvent*>(aEvent);
    565 
    566                 QStringList droppedList;
    567                 QUriDrag::decodeLocalFiles (dropEvent, droppedList);
    568 
    569                 for (QStringList::Iterator it = droppedList.begin();
    570                      it != droppedList.end(); ++it)
    571                 {
    572                     /* Checking dropped media type */
    573                     VBoxDefs::DiskType type = VBoxDefs::InvalidType;
    574                     if      ((*it).endsWith ("iso", false))
    575                     {
    576                         if (currentList == cdsView) type = VBoxDefs::CD;
    577                     }
    578                     else if ((*it).endsWith ("img", false))
    579                     {
    580                         if (currentList == fdsView) type = VBoxDefs::FD;
    581                     }
    582                     else if ((*it).endsWith ("vdi", false))
    583                     {
    584                         if (currentList == hdsView) type = VBoxDefs::HD;
    585                     }
    586                     /* If media type has been determined - attach this device */
    587                     if (type)
    588                         addDroppedImage(*it, type);
    589                 }
    590                 dropEvent->accept();
    591                 refreshAll();
    592             }
    593             break;
    594         }
    595630        case QEvent::FocusIn:
    596631        {
     
    617652    }
    618653    return QMainWindow::eventFilter (aObject, aEvent);
     654}
     655
     656
     657void VBoxDiskImageManagerDlg::addDroppedImages (QDropEvent *aEvent)
     658{
     659    QListView *currentList = getCurrentListView();
     660
     661    QStringList droppedList;
     662    QUriDrag::decodeLocalFiles (aEvent, droppedList);
     663
     664    for (QStringList::Iterator it = droppedList.begin();
     665         it != droppedList.end(); ++it)
     666    {
     667        // Checking dropped media type
     668        VBoxDefs::DiskType type = VBoxDefs::InvalidType;
     669        if      ((*it).endsWith ("iso", false))
     670        {
     671            if (currentList == cdsView) type = VBoxDefs::CD;
     672        }
     673        else if ((*it).endsWith ("img", false))
     674        {
     675            if (currentList == fdsView) type = VBoxDefs::FD;
     676        }
     677        else if ((*it).endsWith ("vdi", false))
     678        {
     679            if (currentList == hdsView) type = VBoxDefs::HD;
     680        }
     681        // If media type has been determined - attach this device
     682        if (type)
     683            addDroppedImage (*it, type);
     684    }
     685
     686    refreshAll();
    619687}
    620688
     
    695763QString VBoxDiskImageManagerDlg::getDVDImageUsage (const QUuid &aId)
    696764{
     765    CVirtualBox vbox = vboxGlobal().virtualBox();
     766
    697767    QStringList permMachines =
    698768        QStringList::split (' ', vbox.GetDVDImageUsage (aId, CEnums::PermanentUsage));
     
    731801QString VBoxDiskImageManagerDlg::getFloppyImageUsage (const QUuid &aId)
    732802{
     803    CVirtualBox vbox = vboxGlobal().virtualBox();
     804
    733805    QStringList permMachines =
    734806        QStringList::split (' ', vbox.GetFloppyImageUsage (aId, CEnums::PermanentUsage));
     
    763835
    764836    return usage;
     837}
     838
     839
     840QString VBoxDiskImageManagerDlg::composeHdToolTip (CHardDisk &aHd)
     841{
     842    CVirtualBox vbox = vboxGlobal().virtualBox();
     843    bool accessible = aHd.GetAccessible();
     844    QUuid machineId = aHd.GetMachineId();
     845
     846    QString src = aHd.GetLocation();
     847    QFileInfo fi (src);
     848    QString location = aHd.GetStorageType() == CEnums::ISCSIHardDisk ? src :
     849                       QDir::convertSeparators (fi.absFilePath());
     850
     851    QString storageType = vboxGlobal().toString (aHd.GetStorageType());
     852    QString hardDiskType = vboxGlobal().hardDiskTypeString (aHd);
     853
     854    QString usage;
     855    if (!machineId.isNull())
     856        usage = vbox.GetMachine (machineId).GetName();
     857
     858    QString snapshotName;
     859    if (!machineId.isNull() && !aHd.GetSnapshotId().isNull())
     860    {
     861        CSnapshot snapshot = vbox.GetMachine (machineId).
     862                                  GetSnapshot (aHd.GetSnapshotId());
     863        if (!snapshot.isNull())
     864            snapshotName = snapshot.GetName();
     865    }
     866
     867    /* compose tool-tip information */
     868    QString tip;
     869    if (!accessible)
     870    {
     871        tip = tr ("<nobr><b>%1</b></nobr><br>%2")
     872                  .arg (location)
     873                  .arg (aHd.GetLastAccessError());
     874    }
     875    else
     876    {
     877        tip = tr ("<nobr><b>%1</b></nobr><br>"
     878                  "<nobr>Disk type:&nbsp;&nbsp;%2</nobr><br>"
     879                  "<nobr>Storage type:&nbsp;&nbsp;%3</nobr>")
     880                  .arg (location)
     881                  .arg (hardDiskType)
     882                  .arg (storageType);
     883
     884        if (!usage.isNull())
     885            tip += tr ("<br><nobr>Attached to:&nbsp;&nbsp;%1</nobr>").arg (usage);
     886        if (!snapshotName.isNull())
     887            tip += tr ("<br><nobr>Snapshot:&nbsp;&nbsp;%5</nobr>").arg (snapshotName);
     888    }
     889    return tip;
     890}
     891
     892QString VBoxDiskImageManagerDlg::composeCdToolTip (CDVDImage &aCd)
     893{
     894    bool accessible = aCd.GetAccessible();
     895    QString src = aCd.GetFilePath();
     896    QFileInfo fi (src);
     897    QString location = QDir::convertSeparators (fi.absFilePath ());
     898    QUuid uuid = aCd.GetId();
     899    QString usage = getDVDImageUsage (uuid);
     900
     901    /* compose tool-tip information */
     902    QString tip;
     903    if (!accessible)
     904    {
     905        /// @todo (r=dmik) correct this when GetLastAccessError() is
     906        //  implemented for IFloppyImage/IDVDImage
     907        tip = tr ("<nobr><b>%1</b></nobr><br>%2")
     908                  .arg (location)
     909                  .arg (tr ("The image file is not accessible",
     910                            "CD/DVD/Floppy"));
     911    }
     912    else
     913    {
     914        tip = tr ("<nobr><b>%1</b></nobr>")
     915                  .arg (location);
     916
     917        if (!usage.isNull())
     918            tip += tr ("<br><nobr>Attached to:&nbsp;&nbsp;%1</nobr>").arg (usage);
     919    }
     920    return tip;
     921}
     922
     923QString VBoxDiskImageManagerDlg::composeFdToolTip (CFloppyImage &aFd)
     924{
     925    bool accessible = aFd.GetAccessible();
     926    QString src = aFd.GetFilePath();
     927    QFileInfo fi (src);
     928    QString location = QDir::convertSeparators (fi.absFilePath ());
     929    QUuid uuid = aFd.GetId();
     930    QString usage = getFloppyImageUsage (uuid);
     931
     932    /* compose tool-tip information */
     933    QString tip;
     934    if (!accessible)
     935    {
     936        /// @todo (r=dmik) correct this when GetLastAccessError() is
     937        //  implemented for IFloppyImage/IDVDImage
     938        tip = tr ("<nobr><b>%1</b></nobr><br>%2")
     939                  .arg (location)
     940                  .arg (tr ("The image file is not accessible",
     941                            "CD/DVD/Floppy"));
     942    }
     943    else
     944    {
     945        tip = tr ("<nobr><b>%1</b></nobr>")
     946                      .arg (location);
     947
     948        if (!usage.isNull())
     949            tip += tr ("<br><nobr>Attached to:&nbsp;&nbsp;%1</nobr>").arg (usage);
     950    }
     951    return tip;
    765952}
    766953
     
    812999    item->setUuid (uuid);
    8131000    item->setMachineId (machineId);
    814 
    815     /* compose tool-tip information */
    816     if (!accessible)
    817     {
    818         item->setToolTip (tr ("<nobr><b>%1</b></nobr><br>%2")
    819                           .arg (item->getPath())
    820                           .arg (aHd.GetLastAccessError()));
    821     }
    822     else
    823     {
    824         QString tip = tr ("<nobr><b>%1</b></nobr><br>"
    825                           "<nobr>Disk type:&nbsp;&nbsp;%2</nobr><br>"
    826                           "<nobr>Storage type:&nbsp;&nbsp;%3</nobr>")
    827                       .arg (item->getPath())
    828                       .arg (item->getDiskType())
    829                       .arg (item->getStorageType());
    830 
    831         QString str = item->getUsage();
    832         if (!str.isNull())
    833             tip += tr ("<br><nobr>Attached to:&nbsp;&nbsp;%1</nobr>").arg (str);
    834 
    835         str = item->getSnapshotName();
    836         if (!str.isNull())
    837             tip += tr ("<br><nobr>Snapshot:&nbsp;&nbsp;%5</nobr>").arg (str);
    838 
    839         item->setToolTip (tip);
    840     }
     1001    item->setToolTip (composeHdToolTip (aHd));
    8411002
    8421003    return item;
     
    8661027    item->setActualSize (size);
    8671028    item->setUuid (uuid);
    868 
    869     /* compose tool-tip information */
    870     if (!accessible)
    871     {
    872         /// @todo (r=dmik) correct this when GetLastAccessError() is
    873         //  implemented for IFloppyImage/IDVDImage
    874         item->setToolTip (tr ("<nobr><b>%1</b></nobr><br>%2")
    875                           .arg (item->getPath())
    876                           .arg (tr ("The image file is not accessible",
    877                                     "CD/DVD/Floppy")));
    878     }
    879     else
    880     {
    881         QString tip = tr ("<nobr><b>%1</b></nobr>")
    882                       .arg (item->getPath());
    883 
    884         QString str = item->getUsage();
    885         if (!str.isNull())
    886             tip += tr ("<br><nobr>Attached to:&nbsp;&nbsp;%1</nobr>").arg (str);
    887 
    888         item->setToolTip (tip);
    889     }
     1029    item->setToolTip (composeCdToolTip (aCd));
    8901030
    8911031    return item;
     
    9151055    item->setActualSize (size);
    9161056    item->setUuid (uuid);
    917 
    918     /* compose tool-tip information */
    919     if (!accessible)
    920     {
    921         /// @todo (r=dmik) correct this when GetLastAccessError() is
    922         //  implemented for IFloppyImage/IDVDImage
    923         item->setToolTip (tr ("<nobr><b>%1</b></nobr><br>%2")
    924                           .arg (item->getPath())
    925                           .arg (tr ("The image file is not accessible",
    926                                     "CD/DVD/Floppy")));
    927     }
    928     else
    929     {
    930         QString tip = tr ("<nobr><b>%1</b></nobr>")
    931                       .arg (item->getPath());
    932 
    933         QString str = item->getUsage();
    934         if (!str.isNull())
    935             tip += tr ("<br><nobr>Attached to:&nbsp;&nbsp;%1</nobr>").arg (str);
    936 
    937         item->setToolTip (tip);
    938     }
     1057    item->setToolTip (composeFdToolTip (aFd));
    9391058
    9401059    return item;
     
    9671086        case VBoxDefs::HD:
    9681087        {
     1088            refreshList (hdsView, mHdsProgress);
    9691089            CHardDisk hd = aMedia.disk;
    9701090            item = createHdItem (hdsView, 0, hd);
     
    9761096        case VBoxDefs::CD:
    9771097        {
     1098            refreshList (cdsView, mCdsProgress);
    9781099            CDVDImage cd = aMedia.disk;
    9791100            item = createCdItem (cdsView, 0, cd);
     
    9831104        case VBoxDefs::FD:
    9841105        {
     1106            refreshList (fdsView, mFdsProgress);
    9851107            CFloppyImage fd = aMedia.disk;
    9861108            item = createFdItem (fdsView, 0, fd);
     
    10511173
    10521174
    1053 void VBoxDiskImageManagerDlg::mediaEnumerated (const VBoxMedia &)
    1054 {
    1055     /* This function is unnecessary since media devices enumeration
    1056        performs on full VBoxMediaList completion */
     1175void VBoxDiskImageManagerDlg::mediaEnumerated (const VBoxMedia &aMedia)
     1176{
     1177    if (!mToBeRefreshed) return;
     1178
     1179    insertMedia (aMedia);
    10571180}
    10581181
     
    10621185    if (!mToBeRefreshed) return;
    10631186
    1064     hdsView->clear();
    1065     cdsView->clear();
    1066     fdsView->clear();
    1067 
    1068     VBoxMediaList::const_iterator it;
    1069     for (it = aList.begin(); it != aList.end(); ++ it)
    1070         insertMedia (*it);
    1071 
    1072     removeNotice (hdsView), removeNotice (cdsView), removeNotice (fdsView);
     1187    delete mHdsProgress, delete mCdsProgress, delete mFdsProgress;
     1188    mHdsProgress = 0, mCdsProgress = 0, mFdsProgress = 0;
    10731189
    10741190    cdsView->setCurrentItem (cdsView->firstChild());
    10751191    fdsView->setCurrentItem (fdsView->firstChild());
    10761192    hdsView->setCurrentItem (hdsView->firstChild());
    1077     cdsView->setSelected (cdsView->firstChild(), true);
    1078     fdsView->setSelected (fdsView->firstChild(), true);
    1079     hdsView->setSelected (hdsView->firstChild(), true);
     1193    cdsView->setSelected (cdsView->currentItem(), true);
     1194    fdsView->setSelected (fdsView->currentItem(), true);
     1195    hdsView->setSelected (hdsView->currentItem(), true);
    10801196    processCurrentChanged();
    10811197
     
    11101226
    11111227
    1112 void VBoxDiskImageManagerDlg::createNotice (QListView *aListView)
    1113 {
    1114     QString warning = tr ("...enumerating media...");
    1115     QLabel *notice = new QLabel (warning, aListView->viewport(), "notice");
    1116     notice->setFrameShape (QFrame::Box);
    1117     notice->setMargin (10);
    1118     notice->adjustSize();
    1119     aListView->setEnabled (false);
    1120 }
    1121 
    1122 
    1123 void VBoxDiskImageManagerDlg::updateNotice (QListView *aListView)
    1124 {
    1125     QLabel *notice = (QLabel*)aListView->child ("notice");
    1126     if (notice)
    1127         notice->move ((((QListView*)notice->parent())->width() - notice->width())/2,
    1128                       (((QListView*)notice->parent())->height() - notice->height())/2);
    1129 }
    1130 
    1131 
    1132 void VBoxDiskImageManagerDlg::removeNotice (QListView *aListView)
    1133 {
    1134     QLabel *notice = (QLabel*)aListView->child ("notice");
    1135     if (notice) delete notice;
    1136     aListView->setEnabled (true);
    1137 }
    1138 
    1139 
    11401228void VBoxDiskImageManagerDlg::refreshAll()
    11411229{
     
    11431231    mToBeRefreshed = true;
    11441232
    1145     hdsView->clear(), cdsView->clear(), fdsView->clear();
    1146     createNotice (hdsView), createNotice (cdsView), createNotice (fdsView);
     1233    /* info panel clearing */
     1234    hdsPane1->clear();
     1235    hdsPane2->clear(), hdsPane3->clear();
     1236    hdsPane4->clear(), hdsPane5->clear();
     1237    cdsPane1->clear(), cdsPane2->clear();
     1238    fdsPane1->clear(), fdsPane2->clear();
     1239
    11471240    imRefreshAction->setEnabled (false);
    11481241    setCursor (QCursor (BusyCursor));
     
    11501243    /* start enumerating media */
    11511244    vboxGlobal().startEnumeratingMedia();
     1245}
     1246
     1247void VBoxDiskImageManagerDlg::refreshList (QListView *aView, ProgressBarItem *&aItem)
     1248{
     1249    if (!aItem)
     1250    {
     1251        aView->clear();
     1252        ULONG iCount = 0;
     1253        if (aView == hdsView)
     1254            iCount = vbox.GetHardDisks().GetCount();
     1255        else if (aView == cdsView)
     1256            iCount = vbox.GetDVDImages().GetCount();
     1257        else if (aView == fdsView)
     1258            iCount = vbox.GetFloppyImages().GetCount();
     1259        aItem = new ProgressBarItem (aView, iCount);
     1260    }
     1261    aItem->increaseProgress();
    11521262}
    11531263
     
    12311341    QListView *currentList = getCurrentListView();
    12321342    currentList->setFocus();
    1233     updateNotice (currentList);
    12341343
    12351344    /* tab stop setup */
     
    12601369        static_cast<DiskImageItem*> (aItem) : 0;
    12611370
    1262     bool modifyEnabled  = item &&  item->getUsage().isNull();
     1371    bool modifyEnabled  = item &&  item->getUsage().isNull() &&
     1372                          !item->firstChild() && !item->getPath().isNull();
    12631373    bool releaseEnabled = item && !item->getUsage().isNull() &&
    12641374                          checkImage (item) &&
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