diff --git a/src/kits/storage/Mime.cpp b/src/kits/storage/Mime.cpp index 80d33290db..acf0d44d89 100644 --- a/src/kits/storage/Mime.cpp +++ b/src/kits/storage/Mime.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -161,26 +162,45 @@ get_device_icon(const char *dev, void *icon, int32 size) return err; } - - - - - - - - - - - - - - - - - - - - - - +// get_device_icon +/*! Retrieves an icon associated with a given device. + \param dev The path to the device. + \param icon A pointer to a pre-allocated BBitmap of the correct dimension + to store the requested icon (16x16 for the mini and 32x32 for the + large icon). + \param which Specifies the size of the icon to be retrieved: + \c B_MINI_ICON for the mini and \c B_LARGE_ICON for the large icon. + + \todo The mounted directories for volumes can also have META:X:STD_ICON + attributes. Should those attributes override the icon returned + by ioctl(,B_GET_ICON,)? + + \return + - \c B_OK: Everything went fine. + - An error code otherwise. +*/ +status_t +get_device_icon(const char *dev, BBitmap *icon, icon_size which) +{ + // check parameters + status_t error = (dev && icon ? B_OK : B_BAD_VALUE); + BRect rect; + if (error == B_OK) { + if (which == B_MINI_ICON) + rect.Set(0, 0, 15, 15); + else if (which == B_LARGE_ICON) + rect.Set(0, 0, 31, 31); + else + error = B_BAD_VALUE; + } + // check whether icon size and bitmap dimensions do match + if (error == B_OK + && (icon->Bounds() != rect || icon->ColorSpace() != B_CMAP8)) { + error = B_BAD_VALUE; + } + // get the icon + if (error == B_OK) + error = get_device_icon(dev, icon->Bits(), which); + return error; +} diff --git a/src/kits/storage/Volume.cpp b/src/kits/storage/Volume.cpp index a275b8022e..fbdcc7ff33 100644 --- a/src/kits/storage/Volume.cpp +++ b/src/kits/storage/Volume.cpp @@ -289,29 +289,15 @@ BVolume::SetName(const char *name) status_t BVolume::GetIcon(BBitmap *icon, icon_size which) const { - // check parameter and initialization - status_t error = (icon && InitCheck() == B_OK ? B_OK : B_BAD_VALUE); - BRect rect; - if (error == B_OK) { - if (which == B_MINI_ICON) - rect.Set(0, 0, 15, 15); - else if (which == B_LARGE_ICON) - rect.Set(0, 0, 31, 31); - else - error = B_BAD_VALUE; - } - // check whether icon size and bitmap dimensions do match - if (error == B_OK - && (icon->Bounds() != rect || icon->ColorSpace() != B_CMAP8)) { - error = B_BAD_VALUE; - } + // check initialization + status_t error = (InitCheck() == B_OK ? B_OK : B_BAD_VALUE); // get FS stat fs_info info; if (error == B_OK && fs_stat_dev(fDevice, &info) != 0) error = errno; // get the icon if (error == B_OK) - error = get_device_icon(info.device_name, icon->Bits(), which); + error = get_device_icon(info.device_name, icon, which); return error; }