Opened 14 years ago

Closed 5 years ago

#139 closed enhancement (fixed)

Enable drive icons

Reported by: rudi Owned by:
Priority: minor Milestone: Qt Enhanced
Component: QtGui Version: 4.5.1 GA
Severity: low Keywords:
Cc:

Description

Assign the proper icons to drives (i.e. Floppy, CD, HDD nad Network).

Change History (7)

comment:1 Changed 14 years ago by rudi

Possible solution:

in QFileIconProvider::icon(const QFileInfo &info)

#if defined (Q_WS_WIN) && !defined(Q_OS_WINCE)
    {
      ... windows stuff ...
    }
#elif defined(Q_WS_PM)
    {
      APIRET	arc;
      UCHAR	ioc_parm[2];
      BIOSPARAMETERBLOCK bpb;
      ioc_parm[0] = 0;
      ioc_parm[1] = info.absoluteFilePath().at(0).cell() - 'A';
      arc = DosDevIOCtl((HFILE)-1, IOCTL_DISK, DSK_GETDEVICEPARAMS,
		  ioc_parm, sizeof(ioc_parm), NULL, &bpb, sizeof(bpb), NULL);

      if( arc == ERROR_NOT_SUPPORTED )
	    return d->getIcon(QStyle::SP_DriveNetIcon);

      if( arc == NO_ERROR && bpb.bDeviceType != DEVTYPE_FIXED ) {

	 if (bpb.fsDeviceAttr & 0x10)		// floppy format
	     return d->getIcon(QStyle::SP_DriveFDIcon);

	 if ( !(bpb.fsDeviceAttr & 0x08) )	// partitionable removable
	     return d->getIcon(QStyle::SP_DriveCDIcon);
      }

      return d->getIcon(QStyle::SP_DriveHDIcon);
    }
#else
    return d->getIcon(QStyle::SP_DriveHDIcon);
#endif

...

needs:

#  define INCL_DOSERRORS
#  define INCL_DOSDEVICES
#  define INCL_DOSDEVIOCTL
#  include <os2.h>

comment:2 Changed 14 years ago by Dmitry A. Kuminov

Thank you, the icons look good. Committed in r607, with the one exception that we never do INCL_blabla or include <os2.h> directly in Qt, we #include <qt_os2.h> instead. Please also follow the Qt source code formatting guidelines which saves me from dummy work :)

Also, I was thinking of taking native icons from the PM which should not be difficult thanks to WinLoadFileIcon?(); your code will be used as a fallback in this case. Will leave the defect open till this is implemented.

Note that I had to update qt_os2.h (because INCL_DOS doesn't actually assume INCL_DOSDEVIOCTL for some reason), but the change does not affect anything but qfileiconprovider.cpp so you can save yourself from the full rebuild by setting the date of qt_os2.h back to the past.

comment:3 Changed 14 years ago by rudi

After looking again at the code:

Can we be sure that the drive letter returned by info.absoluteFilePath() is always upper case ?

Also, the check for "partitionable removable" is not neccessary, because they are reported as DEVTYPE_FIXED. Unfortunately, I don't have a computer with a 5.25" floppy ;-).

comment:4 Changed 14 years ago by Dmitry A. Kuminov

QFileInfo::absoluteFilePath() should always uppercase drive letters, but I added a small fix for the case in r619 if it ever stops doing so.

Your concern about DEVTYPE_FIXED is not fully clear to me: here, both floppies and CDs don't have this flag so everything works fine. Do you mean that there are cases when the drive is non-fixed but it has DEVTYPE_FIXED set?

I also wonder how the USB sticks are reported (can't check it here). Do they look like CDs in Qt applications on your system?

comment:5 Changed 14 years ago by rudi

USB sticks are reported as DEVTYPE_FIXED with bit 3 in the fsDeviceAttr set (i.e. partitionable removable). With the current code they are shown as harddrives. However the check for partitionable removable isn't neccessary. It also must be mentioned, that the bits 3 and 4 of fsDeviceAttr are not present in really ancient versions of OS/2 (Warp3, unfixed Warp4). But I'm not sure, if Qt will run at all on those systems...

comment:6 Changed 14 years ago by Dmitry A. Kuminov

In r642, I implemented support for displaying native file icons in QFileDialog.

Regarding DEVTYPE_FIXED. Thank you for the explanation, but I think that it's correct that USB sticks are shown as hard drives now (in fact, they are more like hard drives than like CDs) so I don't see a need to change the current code.

Another nice thing would be to take native icons for drives themselves (currently we use Qt icons for drives) as well as for "Computer" (Local System) and for other things like "Trash" (Shredder). This requires usage of RWS though (to call methods of WPS objects from another process) and I'm not sure I will be able to implement this for the 4.6.2 milestone. Will leave this defect open until this is done.

comment:7 Changed 5 years ago by Silvan Scherrer

Resolution: fixed
Status: newclosed

If one feels like we should add that in Qt5 please open a ticket at https://github.com/bitwiseworks/qtbase-os2

Note: See TracTickets for help on using tickets.