TrackSupplier* FilePlaylistItem::CreateTrackSupplier() const { MediaFileTrackSupplier* supplier = new(std::nothrow) MediaFileTrackSupplier(); if (supplier == NULL) return NULL; for (vector<entry_ref>::size_type i = 0; i < fRefs.size(); i++) { BMediaFile* mediaFile = new(std::nothrow) BMediaFile(&fRefs[i]); if (mediaFile == NULL) { delete supplier; return NULL; } if (supplier->AddMediaFile(mediaFile) != B_OK) delete mediaFile; } for (vector<entry_ref>::size_type i = 0; i < fImageRefs.size(); i++) { BBitmap* bitmap = BTranslationUtils::GetBitmap(&fImageRefs[i]); if (bitmap == NULL) continue; if (supplier->AddBitmap(bitmap) != B_OK) delete bitmap; } // Search for subtitle files in the same folder // TODO: Error checking BEntry entry(&fRefs[0], true); char originalName[B_FILE_NAME_LENGTH]; entry.GetName(originalName); BString nameWithoutExtension(originalName); int32 extension = nameWithoutExtension.FindLast('.'); if (extension > 0) nameWithoutExtension.Truncate(extension); BPath path; entry.GetPath(&path); path.GetParent(&path); BDirectory directory(path.Path()); while (directory.GetNextEntry(&entry) == B_OK) { char name[B_FILE_NAME_LENGTH]; if (entry.GetName(name) != B_OK) continue; BString nameString(name); if (nameString == originalName) continue; if (nameString.IFindFirst(nameWithoutExtension) < 0) continue; BFile file(&entry, B_READ_ONLY); if (file.InitCheck() != B_OK) continue; int32 pos = nameString.FindLast('.'); if (pos < 0) continue; BString extensionString(nameString.String() + pos + 1); extensionString.ToLower(); BString language = "default"; if (pos > 1) { int32 end = pos; while (pos > 0 && *(nameString.String() + pos - 1) != '.') pos--; language.SetTo(nameString.String() + pos, end - pos); } if (extensionString == "srt") { SubTitles* subTitles = new(std::nothrow) SubTitlesSRT(&file, language.String()); if (subTitles != NULL && !supplier->AddSubTitles(subTitles)) delete subTitles; } } return supplier; }
QVariant KrVfsModel::data(const QModelIndex& index, int role) const { if (!index.isValid() || index.row() >= rowCount()) return QVariant(); vfile *vf = _vfiles.at(index.row()); if (vf == 0) return QVariant(); switch (role) { case Qt::FontRole: return _defaultFont; case Qt::EditRole: { if (index.column() == 0) { return vf->vfile_getName(); } return QVariant(); } case Qt::UserRole: { if (index.column() == 0) { return nameWithoutExtension(vf, false); } return QVariant(); } case Qt::ToolTipRole: case Qt::DisplayRole: { switch (index.column()) { case KrViewProperties::Name: { return nameWithoutExtension(vf); } case KrViewProperties::Ext: { QString nameOnly = nameWithoutExtension(vf); const QString& vfName = vf->vfile_getName(); return vfName.mid(nameOnly.length() + 1); } case KrViewProperties::Size: { if (vf->vfile_isDir() && vf->vfile_getSize() <= 0) { //HACK add <> brackets AFTER translating - otherwise KUIT thinks it's a tag static QString label = QString("<") + i18nc("Show the string 'DIR' instead of file size in detailed view (for folders)", "DIR") + ">"; return label; } else return (properties()->humanReadableSize) ? KIO::convertSize(vf->vfile_getSize()) + " " : KRpermHandler::parseSize(vf->vfile_getSize()) + ' '; } case KrViewProperties::Type: { if (vf == _dummyVfile) return QVariant(); QMimeDatabase db; QMimeType mt = db.mimeTypeForName(vf->vfile_getMime()); if (mt.isValid()) return mt.comment(); return QVariant(); } case KrViewProperties::Modified: { if (vf == _dummyVfile) return QVariant(); time_t time = vf->vfile_getTime_t(); struct tm* t = localtime((time_t *) & time); QDateTime tmp(QDate(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday), QTime(t->tm_hour, t->tm_min)); return QLocale().toString(tmp, QLocale::ShortFormat); } case KrViewProperties::Permissions: { if (vf == _dummyVfile) return QVariant(); if (properties()->numericPermissions) { QString perm; return perm.sprintf("%.4o", vf->vfile_getMode() & PERM_BITMASK); } return vf->vfile_getPerm(); } case KrViewProperties::KrPermissions: { if (vf == _dummyVfile) return QVariant(); return KrView::krPermissionString(vf); } case KrViewProperties::Owner: { if (vf == _dummyVfile) return QVariant(); return vf->vfile_getOwner(); } case KrViewProperties::Group: { if (vf == _dummyVfile) return QVariant(); return vf->vfile_getGroup(); } default: return QString(); } return QVariant(); } case Qt::DecorationRole: { switch (index.column()) { case KrViewProperties::Name: { if (properties()->displayIcons) { if (_justForSizeHint) return QPixmap(_view->fileIconSize(), _view->fileIconSize()); return _view->getIcon(vf); } break; } default: break; } return QVariant(); } case Qt::TextAlignmentRole: { switch (index.column()) { case KrViewProperties::Size: return QVariant(Qt::AlignRight | Qt::AlignVCenter); default: return QVariant(Qt::AlignLeft | Qt::AlignVCenter); } return QVariant(); } case Qt::BackgroundRole: case Qt::ForegroundRole: { KrColorItemType colorItemType; colorItemType.m_activePanel = _view->isFocused(); int actRow = index.row(); if (_alternatingTable) { int itemNum = _view->itemsPerPage(); if (itemNum == 0) itemNum++; if ((itemNum & 1) == 0) actRow += (actRow / itemNum); } colorItemType.m_alternateBackgroundColor = (actRow & 1); colorItemType.m_currentItem = _view->getCurrentIndex().row() == index.row(); colorItemType.m_selectedItem = _view->isSelected(index); if (vf->vfile_isSymLink()) { if (vf->vfile_isBrokenLink()) colorItemType.m_fileType = KrColorItemType::InvalidSymlink; else colorItemType.m_fileType = KrColorItemType::Symlink; } else if (vf->vfile_isDir()) colorItemType.m_fileType = KrColorItemType::Directory; else if (vf->vfile_isExecutable()) colorItemType.m_fileType = KrColorItemType::Executable; else colorItemType.m_fileType = KrColorItemType::File; KrColorGroup cols; KrColorCache::getColorCache().getColors(cols, colorItemType); if (colorItemType.m_selectedItem) { if (role == Qt::ForegroundRole) return cols.highlightedText(); else return cols.highlight(); } if (role == Qt::ForegroundRole) return cols.text(); else return cols.background(); } default: return QVariant(); } }