bool MediaImpl::realURL(const QString &name, const QString &path, KURL &url) { bool ok; Medium m = findMediumByName(name, ok); if(!ok) return false; ok = ensureMediumMounted(m); if(!ok) return false; url = m.prettyBaseURL(); url.addPath(path); return true; }
void MediaImpl::createMediumEntry(KIO::UDSEntry &entry, const Medium &medium) { kdDebug(1219) << "MediaProtocol::createMedium" << endl; QString url = "media:/" + medium.name(); kdDebug(1219) << "url = " << url << ", mime = " << medium.mimeType() << endl; entry.clear(); addAtom(entry, KIO::UDS_URL, 0, url); QString label = KIO::encodeFileName(medium.prettyLabel()); addAtom(entry, KIO::UDS_NAME, 0, label); addAtom(entry, KIO::UDS_FILE_TYPE, S_IFDIR); addAtom(entry, KIO::UDS_MIME_TYPE, 0, medium.mimeType()); addAtom(entry, KIO::UDS_GUESSED_MIME_TYPE, 0, "inode/directory"); if(!medium.iconName().isEmpty()) { addAtom(entry, KIO::UDS_ICON_NAME, 0, medium.iconName()); } else { QString mime = medium.mimeType(); QString icon = KMimeType::mimeType(mime)->icon(mime, false); addAtom(entry, KIO::UDS_ICON_NAME, 0, icon); } if(medium.needMounting()) { addAtom(entry, KIO::UDS_ACCESS, 0400); } else { KURL url = medium.prettyBaseURL(); entry += extractUrlInfos(url); } }
bool KFileMediaPlugin::readInfo(KFileMetaInfo &info, uint /*what*/) { const Medium medium = askMedium(info); kdDebug() << "KFileMediaPlugin::readInfo " << medium.id() << endl; if (medium.id().isNull()) return false; QString mount_point = medium.mountPoint(); KURL base_url = medium.prettyBaseURL(); QString device_node = medium.deviceNode(); KFileMetaInfoGroup group = appendGroup(info, "mediumInfo"); if (base_url.isValid()) { appendItem(group, "baseURL", base_url.prettyURL()); } if (!device_node.isEmpty()) { appendItem(group, "deviceNode", device_node); } if (!mount_point.isEmpty() && medium.isMounted()) { m_total = 0; m_used = 0; m_free = 0; struct statvfs vfs; memset(&vfs, 0, sizeof(vfs)); if ( ::statvfs(QFile::encodeName(mount_point), &vfs) != -1 ) { m_total = static_cast<KIO::filesize_t>(vfs.f_blocks) * static_cast<KIO::filesize_t>(vfs.f_frsize); m_free = static_cast<KIO::filesize_t>(vfs.f_bavail) * static_cast<KIO::filesize_t>(vfs.f_frsize); m_used = m_total - m_free; int percent = 0; int length = 0; if (m_total != 0) { percent = 100 * m_used / m_total; length = 150 * m_used / m_total; } appendItem(group, "free", m_free); appendItem(group, "used", m_used); appendItem(group, "total", m_total); group = appendGroup(info, "mediumSummary"); appendItem(group, "percent", QString("%1%").arg(percent)); QPixmap bar(150, 20); QPainter p(&bar); p.fillRect(0, 0, length, 20, Qt::red); p.fillRect(length, 0, 150-length, 20, Qt::green); QColorGroup cg = QApplication::palette().active(); QApplication::style().drawPrimitive(QStyle::PE_Panel, &p, QRect(0, 0, 150, 20), cg, QStyle::Style_Sunken); appendItem( group, "thumbnail", bar ); } } return true; }