static void type_dir(mime_t *mime, /* I - MIME database */ const char *dirname) /* I - Directory */ { cups_dir_t *dir; /* Directory */ cups_dentry_t *dent; /* Directory entry */ char filename[1024]; /* File to type */ mime_type_t *filetype; /* File type */ int compression; /* Compressed file? */ mime_type_t *pstype; /* application/vnd.cups-postscript */ cups_array_t *filters; /* Filters to pstype */ mime_filter_t *filter; /* Current filter */ int cost; /* Filter cost */ dir = cupsDirOpen(dirname); if (!dir) return; pstype = mimeType(mime, "application", "vnd.cups-postscript"); while ((dent = cupsDirRead(dir)) != NULL) { if (dent->filename[0] == '.') continue; snprintf(filename, sizeof(filename), "%s/%s", dirname, dent->filename); if (S_ISDIR(dent->fileinfo.st_mode)) type_dir(mime, filename); if (!S_ISREG(dent->fileinfo.st_mode)) continue; filetype = mimeFileType(mime, filename, NULL, &compression); if (filetype) { printf("%s: %s/%s%s\n", filename, filetype->super, filetype->type, compression ? " (compressed)" : ""); filters = mimeFilter(mime, filetype, pstype, &cost); if (!filters) puts(" No filters to convert application/vnd.cups-postscript."); else { printf(" Filter cost = %d\n", cost); filter = (mime_filter_t *)cupsArrayFirst(filters); printf(" %s", filter->filter); for (filter = (mime_filter_t *)cupsArrayNext(filters); filter; filter = (mime_filter_t *)cupsArrayNext(filters)) printf(" | %s", filter->filter); putchar('\n'); cupsArrayDelete(filters); } } else printf("%s: unknown%s\n", filename, compression ? " (compressed)" : ""); } cupsDirClose(dir); }
static void mime_load_convs( mime_t *mime, /* I - MIME database */ const char *filename, /* I - Convs file to load */ const char *filterpath, /* I - Path for filters */ cups_array_t *filtercache) /* I - Filter program cache */ { cups_file_t *fp; /* Convs file */ char line[1024], /* Input line from file */ *lineptr, /* Current position in line */ super[MIME_MAX_SUPER], /* Super-type name */ type[MIME_MAX_TYPE], /* Type name */ *temp, /* Temporary pointer */ *filter; /* Filter program */ mime_type_t *temptype, /* MIME type looping var */ *dsttype; /* Destination MIME type */ int cost; /* Cost of filter */ DEBUG_printf(("2mime_load_convs(mime=%p, filename=\"%s\", filterpath=\"%s\", " "filtercache=%p)", mime, filename, filterpath, filtercache)); /* * First try to open the file... */ if ((fp = cupsFileOpen(filename, "r")) == NULL) { DEBUG_printf(("3mime_load_convs: Unable to open \"%s\": %s", filename, strerror(errno))); _mimeError(mime, "Unable to open \"%s\": %s", filename, strerror(errno)); return; } /* * Then read each line from the file, skipping any comments in the file... */ while (cupsFileGets(fp, line, sizeof(line)) != NULL) { /* * Skip blank lines and lines starting with a #... */ if (!line[0] || line[0] == '#') continue; /* * Strip trailing whitespace... */ for (lineptr = line + strlen(line) - 1; lineptr >= line && isspace(*lineptr & 255); lineptr --) *lineptr = '\0'; /* * Extract the destination super-type and type names from the middle of * the line. */ lineptr = line; while (*lineptr != ' ' && *lineptr != '\t' && *lineptr != '\0') lineptr ++; while (*lineptr == ' ' || *lineptr == '\t') lineptr ++; temp = super; while (*lineptr != '/' && *lineptr != '\n' && *lineptr != '\0' && (temp - super + 1) < MIME_MAX_SUPER) *temp++ = (char)tolower(*lineptr++ & 255); *temp = '\0'; if (*lineptr != '/') continue; lineptr ++; temp = type; while (*lineptr != ' ' && *lineptr != '\t' && *lineptr != '\n' && *lineptr != '\0' && (temp - type + 1) < MIME_MAX_TYPE) *temp++ = (char)tolower(*lineptr++ & 255); *temp = '\0'; if (*lineptr == '\0' || *lineptr == '\n') continue; if ((dsttype = mimeType(mime, super, type)) == NULL) { DEBUG_printf(("3mime_load_convs: Destination type %s/%s not found.", super, type)); continue; } /* * Then get the cost and filter program... */ while (*lineptr == ' ' || *lineptr == '\t') lineptr ++; if (*lineptr < '0' || *lineptr > '9') continue; cost = atoi(lineptr); while (*lineptr != ' ' && *lineptr != '\t' && *lineptr != '\0') lineptr ++; while (*lineptr == ' ' || *lineptr == '\t') lineptr ++; if (*lineptr == '\0' || *lineptr == '\n') continue; filter = lineptr; if (strcmp(filter, "-")) { /* * Verify that the filter exists and is executable... */ if (!mime_add_fcache(filtercache, filter, filterpath)) { DEBUG_printf(("mime_load_convs: Filter %s not found in %s.", filter, filterpath)); _mimeError(mime, "Filter \"%s\" not found.", filter); continue; } } /* * Finally, get the source super-type and type names from the beginning of * the line. We do it here so we can support wildcards... */ lineptr = line; temp = super; while (*lineptr != '/' && *lineptr != '\n' && *lineptr != '\0' && (temp - super + 1) < MIME_MAX_SUPER) *temp++ = (char)tolower(*lineptr++ & 255); *temp = '\0'; if (*lineptr != '/') continue; lineptr ++; temp = type; while (*lineptr != ' ' && *lineptr != '\t' && *lineptr != '\n' && *lineptr != '\0' && (temp - type + 1) < MIME_MAX_TYPE) *temp++ = (char)tolower(*lineptr++ & 255); *temp = '\0'; if (!strcmp(super, "*") && !strcmp(type, "*")) { /* * Force * / * to be "application/octet-stream"... */ strlcpy(super, "application", sizeof(super)); strlcpy(type, "octet-stream", sizeof(type)); } /* * Add the filter to the MIME database, supporting wildcards as needed... */ for (temptype = (mime_type_t *)cupsArrayFirst(mime->types); temptype; temptype = (mime_type_t *)cupsArrayNext(mime->types)) if ((super[0] == '*' || !strcmp(temptype->super, super)) && (type[0] == '*' || !strcmp(temptype->type, type))) mimeAddFilter(mime, temptype, dsttype, cost, filter); } cupsFileClose(fp); }
static void add_ppd_filter(mime_t *mime, /* I - MIME database */ mime_type_t *filtertype, /* I - Filter or prefilter MIME type */ const char *filter) /* I - Filter to add */ { char super[MIME_MAX_SUPER], /* Super-type for filter */ type[MIME_MAX_TYPE], /* Type for filter */ dsuper[MIME_MAX_SUPER], /* Destination super-type for filter */ dtype[MIME_MAX_TYPE], /* Destination type for filter */ dest[MIME_MAX_SUPER + MIME_MAX_TYPE + 2], /* Destination super/type */ program[1024]; /* Program/filter name */ int cost; /* Cost of filter */ size_t maxsize = 0; /* Maximum supported file size */ mime_type_t *temptype, /* MIME type looping var */ *desttype; /* Destination MIME type */ mime_filter_t *filterptr; /* MIME filter */ DEBUG_printf(("add_ppd_filter(mime=%p, filtertype=%p(%s/%s), filter=\"%s\")", mime, filtertype, filtertype->super, filtertype->type, filter)); /* * Parse the filter string; it should be in one of the following formats: * * source/type cost program * source/type cost maxsize(nnnn) program * source/type dest/type cost program * source/type dest/type cost maxsize(nnnn) program */ if (sscanf(filter, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]", super, type, dsuper, dtype, &cost, program) == 6) { snprintf(dest, sizeof(dest), "test/%s/%s", dsuper, dtype); if ((desttype = mimeType(mime, "printer", dest)) == NULL) desttype = mimeAddType(mime, "printer", dest); } else { if (sscanf(filter, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super, type, &cost, program) == 4) { desttype = filtertype; } else { printf("testmime: Invalid filter string \"%s\".\n", filter); return; } } if (!strncmp(program, "maxsize(", 8)) { char *ptr; /* Pointer into maxsize(nnnn) program */ maxsize = strtoll(program + 8, &ptr, 10); if (*ptr != ')') { printf("testmime: Invalid filter string \"%s\".\n", filter); return; } ptr ++; while (_cups_isspace(*ptr)) ptr ++; _cups_strcpy(program, ptr); } /* * Add the filter to the MIME database, supporting wildcards as needed... */ for (temptype = mimeFirstType(mime); temptype; temptype = mimeNextType(mime)) if (((super[0] == '*' && _cups_strcasecmp(temptype->super, "printer")) || !_cups_strcasecmp(temptype->super, super)) && (type[0] == '*' || !_cups_strcasecmp(temptype->type, type))) { if (desttype != filtertype) { DEBUG_printf(("add_ppd_filter: Adding filter %s/%s %s/%s %d %s", temptype->super, temptype->type, desttype->super, desttype->type, cost, program)); filterptr = mimeAddFilter(mime, temptype, desttype, cost, program); if (!mimeFilterLookup(mime, desttype, filtertype)) { DEBUG_printf(("add_printer_filter: Adding filter %s/%s %s/%s 0 -", desttype->super, desttype->type, filtertype->super, filtertype->type)); mimeAddFilter(mime, desttype, filtertype, 0, "-"); } } else { DEBUG_printf(("add_printer_filter: Adding filter %s/%s %s/%s %d %s", temptype->super, temptype->type, filtertype->super, filtertype->type, cost, program)); filterptr = mimeAddFilter(mime, temptype, filtertype, cost, program); } if (filterptr) filterptr->maxsize = maxsize; } }
bool CScraperUrl::Get(const SUrlEntry& scrURL, std::string& strHTML, XFILE::CCurlFile& http, const std::string& cacheContext) { CURL url(scrURL.m_url); http.SetReferer(scrURL.m_spoof); std::string strCachePath; if (scrURL.m_isgz) http.SetAcceptEncoding("gzip"); if (!scrURL.m_cache.empty()) { strCachePath = URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath, "scrapers", cacheContext, scrURL.m_cache); if (XFILE::CFile::Exists(strCachePath)) { XFILE::CFile file; XFILE::auto_buffer buffer; if (file.LoadFile(strCachePath, buffer) > 0) { strHTML.assign(buffer.get(), buffer.length()); return true; } } } std::string strHTML1(strHTML); if (scrURL.m_post) { std::string strOptions = url.GetOptions(); strOptions = strOptions.substr(1); url.SetOptions(""); if (!http.Post(url.Get(), strOptions, strHTML1)) return false; } else if (!http.Get(url.Get(), strHTML1)) return false; strHTML = strHTML1; std::string mimeType(http.GetMimeType()); CMime::EFileType ftype = CMime::GetFileTypeFromMime(mimeType); if (ftype == CMime::FileTypeUnknown) ftype = CMime::GetFileTypeFromContent(strHTML); if (ftype == CMime::FileTypeZip || ftype == CMime::FileTypeGZip) { XFILE::CZipFile file; std::string strBuffer; int iSize = file.UnpackFromMemory(strBuffer,strHTML,scrURL.m_isgz); // FIXME: use FileTypeGZip instead of scrURL.m_isgz? if (iSize > 0) { strHTML = strBuffer; CLog::Log(LOGDEBUG, "%s: Archive \"%s\" was unpacked in memory", __FUNCTION__, scrURL.m_url.c_str()); } else CLog::Log(LOGWARNING, "%s: \"%s\" looks like archive, but cannot be unpacked", __FUNCTION__, scrURL.m_url.c_str()); } std::string reportedCharset(http.GetServerReportedCharset()); if (ftype == CMime::FileTypeHtml) { std::string realHtmlCharset, converted; if (!CCharsetDetection::ConvertHtmlToUtf8(strHTML, converted, reportedCharset, realHtmlCharset)) CLog::Log(LOGWARNING, "%s: Can't find precise charset for HTML \"%s\", using \"%s\" as fallback", __FUNCTION__, scrURL.m_url.c_str(), realHtmlCharset.c_str()); else CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for HTML \"%s\"", __FUNCTION__, realHtmlCharset.c_str(), scrURL.m_url.c_str()); strHTML = converted; } else if (ftype == CMime::FileTypeXml) { CXBMCTinyXML xmlDoc; xmlDoc.Parse(strHTML, reportedCharset); std::string realXmlCharset(xmlDoc.GetUsedCharset()); if (!realXmlCharset.empty()) { CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for XML \"%s\"", __FUNCTION__, realXmlCharset.c_str(), scrURL.m_url.c_str()); std::string converted; g_charsetConverter.ToUtf8(realXmlCharset, strHTML, converted); strHTML = converted; } } else if (ftype == CMime::FileTypePlainText || StringUtils::CompareNoCase(mimeType.substr(0, 5), "text/") == 0) { std::string realTextCharset, converted; CCharsetDetection::ConvertPlainTextToUtf8(strHTML, converted, reportedCharset, realTextCharset); strHTML = converted; if (reportedCharset != realTextCharset) CLog::Log(LOGWARNING, "%s: Using \"%s\" charset for plain text \"%s\" instead of server reported \"%s\" charset", __FUNCTION__, realTextCharset.c_str(), scrURL.m_url.c_str(), reportedCharset.c_str()); else CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for plain text \"%s\"", __FUNCTION__, realTextCharset.c_str(), scrURL.m_url.c_str()); } else if (!reportedCharset.empty()) { CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for \"%s\"", __FUNCTION__, reportedCharset.c_str(), scrURL.m_url.c_str()); if (reportedCharset != "UTF-8") { std::string converted; g_charsetConverter.ToUtf8(reportedCharset, strHTML, converted); strHTML = converted; } } else CLog::Log(LOGDEBUG, "%s: Using content of \"%s\" as binary or text with \"UTF-8\" charset", __FUNCTION__, scrURL.m_url.c_str()); if (!scrURL.m_cache.empty()) { std::string strCachePath = URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath, "scrapers", cacheContext, scrURL.m_cache); XFILE::CFile file; if (!file.OpenForWrite(strCachePath, true) || file.Write(strHTML.data(), strHTML.size()) != static_cast<ssize_t>(strHTML.size())) return false; } return true; }
void TrashProtocol::slotMimetype( KIO::Job*, const QString& mt ) { mimeType( mt ); }
void Model::TrackIconSource(icon_size size) { PRINT(("tracking %s icon\n", size == B_LARGE_ICON ? "large" : "small")); BRect rect; if (size == B_MINI_ICON) rect.Set(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1); else rect.Set(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1); BBitmap bitmap(rect, B_CMAP8); BModelOpener opener(this); if (Node() == NULL) { PRINT(("track icon error - no node\n")); return; } if (IsSymLink()) { PRINT(("tracking symlink icon\n")); if (fLinkTo) { fLinkTo->TrackIconSource(size); return; } } if (fBaseType == kVolumeNode) { BVolume volume(NodeRef()->device); status_t result = volume.GetIcon(&bitmap, size); PRINT(("getting icon from volume %s\n", strerror(result))); } else { BNodeInfo nodeInfo(Node()); status_t err = nodeInfo.GetIcon(&bitmap, size); if (err == B_OK) { // file knew which icon to use, we are done PRINT(("track icon - got icon from file\n")); return; } char preferredApp[B_MIME_TYPE_LENGTH]; err = nodeInfo.GetPreferredApp(preferredApp); if (err == B_OK && preferredApp[0]) { BMimeType preferredAppType(preferredApp); err = preferredAppType.GetIconForType(MimeType(), &bitmap, size); if (err == B_OK) { PRINT( ("track icon - got icon for type %s from preferred " "app %s for file\n", MimeType(), preferredApp)); return; } } BMimeType mimeType(MimeType()); err = mimeType.GetIcon(&bitmap, size); if (err == B_OK) { // the system knew what icon to use for the type, we are done PRINT(("track icon - signature %s, got icon from system\n", MimeType())); return; } err = mimeType.GetPreferredApp(preferredApp); if (err != B_OK) { // no preferred App for document, give up PRINT(("track icon - signature %s, no prefered app, error %s\n", MimeType(), strerror(err))); return; } BMimeType preferredAppType(preferredApp); err = preferredAppType.GetIconForType(MimeType(), &bitmap, size); if (err == B_OK) { // the preferred app knew icon to use for the type, we are done PRINT( ("track icon - signature %s, got icon from preferred " "app %s\n", MimeType(), preferredApp)); return; } PRINT( ("track icon - signature %s, preferred app %s, no icon, " "error %s\n", MimeType(), preferredApp, strerror(err))); } }
int /* O - Exit status */ main(int argc, /* I - Number of command-line args */ char *argv[]) /* I - Command-line arguments */ { int i; /* Looping vars */ const char *command, /* Command name */ *opt, /* Current option */ *printer; /* Printer name */ mime_type_t *printer_type, /* Printer MIME type */ *prefilter_type; /* Printer prefilter MIME type */ char *srctype, /* Source type */ *dsttype, /* Destination type */ super[MIME_MAX_SUPER], /* Super-type name */ type[MIME_MAX_TYPE]; /* Type name */ int compression; /* Compression of file */ int cost; /* Cost of filters */ mime_t *mime; /* MIME database */ char mimedir[1024]; /* MIME directory */ char *infile, /* File to filter */ *outfile; /* File to create */ char cupsdconf[1024]; /* cupsd.conf file */ const char *server_root; /* CUPS_SERVERROOT environment variable */ mime_type_t *src, /* Source type */ *dst; /* Destination type */ cups_array_t *filters; /* Filters for the file */ int num_options; /* Number of options */ cups_option_t *options; /* Options */ const char *ppdfile; /* PPD file */ const char *title, /* Title string */ *user; /* Username */ int all_filters, /* Use all filters */ removeppd, /* Remove PPD file */ removeinfile; /* Remove input file */ int status; /* Execution status */ /* * Setup defaults... */ if ((command = strrchr(argv[0], '/')) != NULL) command ++; else command = argv[0]; printer = !strcmp(command, "convert") ? "tofile" : "cupsfilter"; mime = NULL; srctype = NULL; compression = 0; dsttype = "application/pdf"; infile = NULL; outfile = NULL; num_options = 0; options = NULL; ppdfile = NULL; title = NULL; user = cupsUser(); all_filters = 0; removeppd = 0; removeinfile = 0; if ((server_root = getenv("CUPS_SERVERROOT")) == NULL) server_root = CUPS_SERVERROOT; snprintf(cupsdconf, sizeof(cupsdconf), "%s/cupsd.conf", server_root); /* * Process command-line arguments... */ _cupsSetLocale(argv); for (i = 1; i < argc; i ++) if (argv[i][0] == '-') { for (opt = argv[i] + 1; *opt; opt ++) switch (*opt) { case '-' : /* Next argument is a filename... */ i ++; if (i < argc && !infile) infile = argv[i]; else usage(opt); break; case 'a' : /* Specify option... */ i ++; if (i < argc) num_options = cupsParseOptions(argv[i], num_options, &options); else usage(opt); break; case 'c' : /* Specify cupsd.conf file location... */ i ++; if (i < argc) { if (!strcmp(command, "convert")) num_options = cupsAddOption("copies", argv[i], num_options, &options); else strlcpy(cupsdconf, argv[i], sizeof(cupsdconf)); } else usage(opt); break; case 'd' : /* Specify the real printer name */ i ++; if (i < argc) printer = argv[i]; else usage(opt); break; case 'D' : /* Delete input file after conversion */ removeinfile = 1; break; case 'e' : /* Use every filter from the PPD file */ all_filters = 1; break; case 'f' : /* Specify input file... */ i ++; if (i < argc && !infile) infile = argv[i]; else usage(opt); break; case 'i' : /* Specify source MIME type... */ i ++; if (i < argc) { if (sscanf(argv[i], "%15[^/]/%255s", super, type) != 2) usage(opt); srctype = argv[i]; } else usage(opt); break; case 'j' : /* Get job file or specify destination MIME type... */ if (strcmp(command, "convert")) { i ++; if (i < argc) { get_job_file(argv[i]); infile = TempFile; } else usage(opt); break; } case 'm' : /* Specify destination MIME type... */ i ++; if (i < argc) { if (sscanf(argv[i], "%15[^/]/%255s", super, type) != 2) usage(opt); dsttype = argv[i]; } else usage(opt); break; case 'n' : /* Specify number of copies... */ i ++; if (i < argc) num_options = cupsAddOption("copies", argv[i], num_options, &options); else usage(opt); break; case 'o' : /* Specify option(s) or output filename */ i ++; if (i < argc) { if (!strcmp(command, "convert")) { if (outfile) usage(NULL); else outfile = argv[i]; } else num_options = cupsParseOptions(argv[i], num_options, &options); } else usage(opt); break; case 'p' : /* Specify PPD file... */ case 'P' : /* Specify PPD file... */ i ++; if (i < argc) ppdfile = argv[i]; else usage(opt); break; case 't' : /* Specify title... */ case 'J' : /* Specify title... */ i ++; if (i < argc) title = argv[i]; else usage(opt); break; case 'u' : /* Delete PPD file after conversion */ removeppd = 1; break; case 'U' : /* Specify username... */ i ++; if (i < argc) user = argv[i]; else usage(opt); break; default : /* Something we don't understand... */ usage(opt); break; } } else if (!infile) { if (strcmp(command, "convert")) infile = argv[i]; else usage(NULL); } else { _cupsLangPuts(stderr, _("cupsfilter: Only one filename can be specified.")); usage(NULL); } if (!infile && !srctype) usage(NULL); if (!title) { if (!infile) title = "(stdin)"; else if ((title = strrchr(infile, '/')) != NULL) title ++; else title = infile; } /* * Load the cupsd.conf file and create the MIME database... */ if (read_cupsd_conf(cupsdconf)) return (1); snprintf(mimedir, sizeof(mimedir), "%s/mime", DataDir); mime = mimeLoadTypes(NULL, mimedir); mime = mimeLoadTypes(mime, ServerRoot); mime = mimeLoadFilters(mime, mimedir, Path); mime = mimeLoadFilters(mime, ServerRoot, Path); if (!mime) { _cupsLangPrintf(stderr, _("%s: Unable to read MIME database from \"%s\" or " "\"%s\"."), command, mimedir, ServerRoot); return (1); } prefilter_type = NULL; if (all_filters) printer_type = add_printer_filters(command, mime, printer, ppdfile, &prefilter_type); else printer_type = mimeType(mime, "application", "vnd.cups-postscript"); /* * Get the source and destination types... */ if (srctype) { sscanf(srctype, "%15[^/]/%255s", super, type); if ((src = mimeType(mime, super, type)) == NULL) { _cupsLangPrintf(stderr, _("%s: Unknown source MIME type %s/%s."), command, super, type); return (1); } } else if ((src = mimeFileType(mime, infile, infile, &compression)) == NULL) { _cupsLangPrintf(stderr, _("%s: Unable to determine MIME type of \"%s\"."), command, infile); return (1); } sscanf(dsttype, "%15[^/]/%255s", super, type); if (!_cups_strcasecmp(super, "printer")) dst = printer_type; else if ((dst = mimeType(mime, super, type)) == NULL) { _cupsLangPrintf(stderr, _("%s: Unknown destination MIME type %s/%s."), command, super, type); return (1); } /* * Figure out how to filter the file... */ if (src == dst) { /* * Special case - no filtering needed... */ filters = cupsArrayNew(NULL, NULL); cupsArrayAdd(filters, &GZIPFilter); GZIPFilter.src = src; GZIPFilter.dst = dst; } else if ((filters = mimeFilter(mime, src, dst, &cost)) == NULL) { _cupsLangPrintf(stderr, _("%s: No filter to convert from %s/%s to %s/%s."), command, src->super, src->type, dst->super, dst->type); return (1); } else if (compression) cupsArrayInsert(filters, &GZIPFilter); if (prefilter_type) { /* * Add pre-filters... */ mime_filter_t *filter, /* Current filter */ *prefilter; /* Current pre-filter */ cups_array_t *prefilters = cupsArrayNew(NULL, NULL); /* New filters array */ for (filter = (mime_filter_t *)cupsArrayFirst(filters); filter; filter = (mime_filter_t *)cupsArrayNext(filters)) { if ((prefilter = mimeFilterLookup(mime, filter->src, prefilter_type)) != NULL) cupsArrayAdd(prefilters, prefilter); cupsArrayAdd(prefilters, filter); } cupsArrayDelete(filters); filters = prefilters; } /* * Do it! */ status = exec_filters(src, filters, infile, outfile, ppdfile, printer, user, title, num_options, options); /* * Remove files as needed, then exit... */ if (TempFile[0]) unlink(TempFile); if (removeppd && ppdfile) unlink(ppdfile); if (removeinfile && infile) unlink(infile); return (status); }
void RTSPSource::onConnected(bool isSeekable) { CHECK(mHandler != NULL); CHECK(mListener != NULL); // Clean up audio and video tracks. // In the case of RTSP reconnect, audio/video tracks might be created by // previous onConnected event. mAudioTrack = NULL; mVideoTrack = NULL; mTracks.clear(); size_t numTracks = mHandler->countTracks(); for (size_t i = 0; i < numTracks; ++i) { int32_t timeScale; sp<MetaData> format = mHandler->getTrackFormat(i, &timeScale); CHECK(format != NULL); const char *mime; CHECK(format->findCString(kKeyMIMEType, &mime)); nsAutoCString mimeType(mime, strlen(mime)); bool isAudio = !strncasecmp(mime, "audio/", 6); bool isVideo = !strncasecmp(mime, "video/", 6); TrackInfo info; info.mTimeScale = timeScale; info.mRTPTime = 0; info.mNormalPlaytimeUs = 0ll; info.mNPTMappingValid = false; info.mIsAudio = false; info.mLatestReceivedUnit = 0; info.mLatestPausedUnit = 0; if ((isAudio && mAudioTrack == NULL) || (isVideo && mVideoTrack == NULL)) { sp<AnotherPacketSource> source = new AnotherPacketSource(format); if (isAudio) { info.mIsAudio = true; mAudioTrack = source; } else { info.mIsAudio = false; mVideoTrack = source; } info.mSource = source; } nsRefPtr<nsIStreamingProtocolMetaData> meta; int32_t int32Value; int64_t int64Value; meta = new mozilla::net::RtspMetaData(); meta->SetTotalTracks(numTracks); meta->SetMimeType(mimeType); DebugOnly<bool> success; success = format->findInt64(kKeyDuration, &int64Value); MOZ_ASSERT(success); meta->SetDuration(int64Value); if (isAudio) { success = format->findInt32(kKeyChannelCount, &int32Value); MOZ_ASSERT(success); meta->SetChannelCount(int32Value); success = format->findInt32(kKeySampleRate, &int32Value); MOZ_ASSERT(success); meta->SetSampleRate(int32Value); } else { success = format->findInt32(kKeyWidth, &int32Value); MOZ_ASSERT(success); meta->SetWidth(int32Value); success = format->findInt32(kKeyHeight, &int32Value); MOZ_ASSERT(success); meta->SetHeight(int32Value); } // Optional meta data. const void *data; uint32_t type; size_t length = 0; if (format->findData(kKeyESDS, &type, &data, &length)) { nsCString esds; esds.Assign((const char *)data, length); meta->SetEsdsData(esds); } if (format->findData(kKeyAVCC, &type, &data, &length)) { nsCString avcc; avcc.Assign((const char *)data, length); meta->SetAvccData(avcc); } mListener->OnConnected(i, meta.get()); mTracks.push(info); } mState = CONNECTED; if (mPlayOnConnected) { mPlayOnConnected = false; play(); } }
bool CachedScript::mimeTypeAllowedByNosniff() const { return !parseContentTypeOptionsHeader(m_response.httpHeaderField(HTTPHeaderName::XContentTypeOptions)) == ContentTypeOptionsNosniff || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType()); }
status_t retrieve_preferred_app(BMessage* message, bool sameAs, const char* forType, BString& preferredApp) { entry_ref ref; if (message == NULL || message->FindRef("refs", &ref) != B_OK) return B_BAD_VALUE; BFile file(&ref, B_READ_ONLY); status_t status = file.InitCheck(); char preferred[B_MIME_TYPE_LENGTH]; if (status == B_OK) { if (sameAs) { // get preferred app from file BNodeInfo nodeInfo(&file); status = nodeInfo.InitCheck(); if (status == B_OK) { if (nodeInfo.GetPreferredApp(preferred) != B_OK) preferred[0] = '\0'; if (!preferred[0]) { // get MIME type from file char type[B_MIME_TYPE_LENGTH]; if (nodeInfo.GetType(type) == B_OK) { BMimeType mimeType(type); mimeType.GetPreferredApp(preferred); } } } } else { // get application signature BAppFileInfo appInfo(&file); status = appInfo.InitCheck(); if (status == B_OK && appInfo.GetSignature(preferred) != B_OK) preferred[0] = '\0'; } } if (status != B_OK) { error_alert(B_TRANSLATE("File could not be opened"), status, B_STOP_ALERT); return status; } if (!preferred[0]) { error_alert(sameAs ? B_TRANSLATE("Could not retrieve preferred application of this " "file") : B_TRANSLATE("Could not retrieve application signature")); return B_ERROR; } // Check if the application chosen supports this type BMimeType mimeType(forType); bool found = false; BMessage applications; if (mimeType.GetSupportingApps(&applications) == B_OK && is_application_in_message(applications, preferred)) found = true; applications.MakeEmpty(); if (!found && mimeType.GetWildcardApps(&applications) == B_OK && is_application_in_message(applications, preferred)) found = true; if (!found) { // warn user BMimeType appType(preferred); char description[B_MIME_TYPE_LENGTH]; if (appType.GetShortDescription(description) != B_OK) description[0] = '\0'; char warning[512]; snprintf(warning, sizeof(warning), B_TRANSLATE("The application " "\"%s\" does not support this file type.\n" "Are you sure you want to set it anyway?"), description[0] ? description : preferred); BAlert* alert = new BAlert(B_TRANSLATE("FileTypes request"), warning, B_TRANSLATE("Set Preferred Application"), B_TRANSLATE("Cancel"), NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); if (alert->Go() == 1) return B_ERROR; } preferredApp = preferred; return B_OK; }
void ImageshackTalker::uploadItemToGallery(QString path, const QString &/*gallery*/, QMap<QString, QString> opts) { if (m_job) { m_job->kill(); m_job = 0; } emit signalBusy(true); QMap<QString, QString> args; args["key"] = m_appKey; args["fileupload"] = KUrl(path).fileName(); MPForm form; for (QMap<QString, QString>::const_iterator it = opts.constBegin(); it != opts.constEnd(); ++it) { form.addPair(it.key(), it.value()); } for (QMap<QString, QString>::const_iterator it = args.constBegin(); it != args.constEnd(); ++it) { form.addPair(it.key(), it.value()); } if (!form.addFile(KUrl(path).fileName(), path)) { emit signalBusy(false); return; } form.finish(); // Check where to upload QString mime = mimeType(path); // TODO support for video uploads KUrl uploadUrl; if (mime.startsWith(QLatin1String("video/"))) { uploadUrl = KUrl(m_videoApiUrl); m_state = IMGHCK_ADDVIDEO; } else { // image file uploadUrl = KUrl(m_photoApiUrl); m_state = IMGHCK_ADDPHOTO; } KIO::Job* const job = KIO::http_post(uploadUrl, form.formData(), KIO::HideProgressInfo); job->addMetaData("UserAgent", m_userAgent); job->addMetaData("content-type", form.contentType()); m_job = job; // if (gallery.isEmpty()) // { // m_state = IMGHCK_ADDPHOTO; // } // else // { // kDebug() << "upload to gallery " << gallery; // m_state = IMGHCK_ADDPHOTOGALLERY; // job->setProperty("k_galleryName", gallery); // m_job->setProperty("k_step", STEP_UPLOADITEM); // } // TODO implement upload to galleries m_buffer.resize(0); connect(job, SIGNAL(data(KIO::Job*,QByteArray)), this, SLOT(data(KIO::Job*,QByteArray))); connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); }
nsresult nsIconChannel::MakeInputStream(nsIInputStream** _retval, PRBool nonBlocking) { nsXPIDLCString contentType; nsCAutoString filePath; nsCAutoString fileExtension; nsCOMPtr<nsIFile> localFile; // File we want an icon for PRUint32 desiredImageSize; nsresult rv = ExtractIconInfoFromUrl(getter_AddRefs(localFile), &desiredImageSize, contentType, fileExtension); NS_ENSURE_SUCCESS(rv, rv); PRUint32 iconSize = 16; if (desiredImageSize > 16) iconSize = 32; PRUint32 alphaBytesPerRow = (iconSize / 8); if (iconSize % 32 != 0) alphaBytesPerRow = ((iconSize / 32) + 1) * 4; PRBool fileExists = PR_FALSE; if (localFile) { localFile->GetNativePath(filePath); localFile->Exists(&fileExists); } // Get the native icon. // 1) If it is for an actual local file, BNodeInfo::GetTrackerIcon. // 2) If the local file does not exist, use the content type // and BMimeType::GetIcon BBitmap nativeIcon(BRect(0, 0, iconSize - 1, iconSize - 1), B_CMAP8); if (!nativeIcon.IsValid()) return NS_ERROR_OUT_OF_MEMORY; PRBool gotBitmap = PR_FALSE; if (fileExists) { BNode localNode(filePath.get()); // BeOS doesn't MIME type foreign files immediately - // If there is no type attribute then we can force an identify if (localNode.ReadAttr("BEOS:TYPE", B_STRING_TYPE, 0, NULL, 0) != B_OK) update_mime_info(filePath.get(), 0, 1, 1); BNodeInfo localNodeInfo(&localNode); if (iconSize == 16) { if (localNodeInfo.GetTrackerIcon(&nativeIcon, B_MINI_ICON) == B_OK) gotBitmap = PR_TRUE; } else { if (localNodeInfo.GetTrackerIcon(&nativeIcon, B_LARGE_ICON) == B_OK) gotBitmap = PR_TRUE; } } // If we haven't got a bitmap yet, use the content type if (!gotBitmap) { // If no content type specified, use mozilla's mime service to guess a mime type if (contentType.IsEmpty()) { nsCOMPtr<nsIMIMEService> mimeService (do_GetService("@mozilla.org/mime;1", &rv)); if (NS_SUCCEEDED(rv)) mimeService->GetTypeFromExtension(fileExtension, contentType); // If unrecognised extension - set to generic file if (contentType.IsEmpty()) contentType = "application/octet-stream"; } // Create BeOS-Native MIME type info - if unheard of, set to generic file BMimeType mimeType(contentType.get()); if (!mimeType.IsInstalled()) mimeType.SetTo("application/octet-stream"); if (iconSize == 16) { if (mimeType.GetIcon(&nativeIcon, B_MINI_ICON) == B_OK) gotBitmap = PR_TRUE; } else { if (mimeType.GetIcon(&nativeIcon, B_LARGE_ICON) == B_OK) gotBitmap = PR_TRUE; } } if (!gotBitmap) return NS_ERROR_NOT_AVAILABLE; BScreen mainScreen(B_MAIN_SCREEN_ID); if (!mainScreen.IsValid()) return NS_ERROR_NOT_AVAILABLE; // Got a bitmap and color space info - convert data to mozilla's icon format PRUint32 iconLength = 2 + iconSize * iconSize * 4; uint8 *buffer = new uint8[iconLength]; if (!buffer) return NS_ERROR_OUT_OF_MEMORY; uint8* destByte = buffer; *(destByte++) = iconSize; *(destByte++) = iconSize; // RGB data uint8* sourceByte = (uint8*)nativeIcon.Bits(); for(PRUint32 iconRow = 0; iconRow < iconSize; iconRow++) { sourceByte = (uint8*)nativeIcon.Bits() + nativeIcon.BytesPerRow() * iconRow; for(PRUint32 iconCol = 0; iconCol < iconSize; iconCol++) { if (*sourceByte != B_TRANSPARENT_MAGIC_CMAP8) { rgb_color colorVal = mainScreen.ColorForIndex(*sourceByte); #ifdef IS_LITTLE_ENDIAN *(destByte++) = colorVal.blue; *(destByte++) = colorVal.green; *(destByte++) = colorVal.red; *(destByte++) = uint8(255); #else *(destByte++) = uint8(255); *(destByte++) = colorVal.red; *(destByte++) = colorVal.green; *(destByte++) = colorVal.blue; #endif } else { *destByte++ = 0; *destByte++ = 0; *destByte++ = 0; *destByte++ = 0; } // original code had a conditional here: // if (iconCol < iconSize - 1) // Leaving this comment in case complications arise later sourceByte++; } } NS_ASSERTION(buffer + iconLength == destByte, "size miscalculation"); // Now, create a pipe and stuff our data into it nsCOMPtr<nsIInputStream> inStream; nsCOMPtr<nsIOutputStream> outStream; rv = NS_NewPipe(getter_AddRefs(inStream), getter_AddRefs(outStream), iconLength, iconLength, nonBlocking); if (NS_SUCCEEDED(rv)) { PRUint32 written; rv = outStream->Write((char*)buffer, iconLength, &written); if (NS_SUCCEEDED(rv)) NS_ADDREF(*_retval = inStream); } delete [] buffer; return rv; }
bool ScriptResource::mimeTypeAllowedByNosniff() const { return parseContentTypeOptionsHeader(m_response.httpHeaderField("X-Content-Type-Options")) != ContentTypeOptionsNosniff || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType()); }
static void add_printer_filter( const char *command, /* I - Command name */ mime_t *mime, /* I - MIME database */ mime_type_t *filtertype, /* I - Printer or prefilter MIME type */ const char *filter) /* I - Filter to add */ { char super[MIME_MAX_SUPER], /* Super-type for filter */ type[MIME_MAX_TYPE], /* Type for filter */ dsuper[MIME_MAX_SUPER], /* Destination super-type for filter */ dtype[MIME_MAX_TYPE], /* Destination type for filter */ dest[MIME_MAX_SUPER + MIME_MAX_TYPE + 2], /* Destination super/type */ program[1024]; /* Program/filter name */ int cost; /* Cost of filter */ size_t maxsize = 0; /* Maximum supported file size */ mime_type_t *temptype, /* MIME type looping var */ *desttype; /* Destination MIME type */ mime_filter_t *filterptr; /* MIME filter */ /* * Parse the filter string; it should be in one of the following formats: * * source/type cost program * source/type cost maxsize(nnnn) program * source/type dest/type cost program * source/type dest/type cost maxsize(nnnn) program */ if (sscanf(filter, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]", super, type, dsuper, dtype, &cost, program) == 6) { snprintf(dest, sizeof(dest), "%s/%s/%s", filtertype->type, dsuper, dtype); if ((desttype = mimeType(mime, "printer", dest)) == NULL) desttype = mimeAddType(mime, "printer", dest); } else { if (sscanf(filter, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super, type, &cost, program) == 4) { desttype = filtertype; } else { _cupsLangPrintf(stderr, _("%s: Invalid filter string \"%s\"."), command, filter); return; } } if (!strncmp(program, "maxsize(", 8)) { char *ptr; /* Pointer into maxsize(nnnn) program */ maxsize = strtoll(program + 8, &ptr, 10); if (*ptr != ')') { printf("testmime: Invalid filter string \"%s\".\n", filter); return; } ptr ++; while (_cups_isspace(*ptr)) ptr ++; _cups_strcpy(program, ptr); } /* * See if the filter program exists; if not, stop the printer and flag * the error! */ if (strcmp(program, "-")) { char filename[1024]; /* Full path to program */ if (program[0] == '/') strlcpy(filename, program, sizeof(filename)); else snprintf(filename, sizeof(filename), "%s/filter/%s", ServerBin, program); if (_cupsFileCheck(filename, _CUPS_FILE_CHECK_PROGRAM, !geteuid(), check_cb, (void *)command)) return; } /* * Add the filter to the MIME database, supporting wildcards as needed... */ for (temptype = mimeFirstType(mime); temptype; temptype = mimeNextType(mime)) if (((super[0] == '*' && _cups_strcasecmp(temptype->super, "printer")) || !_cups_strcasecmp(temptype->super, super)) && (type[0] == '*' || !_cups_strcasecmp(temptype->type, type))) { if (desttype != filtertype) { filterptr = mimeAddFilter(mime, temptype, desttype, cost, program); if (!mimeFilterLookup(mime, desttype, filtertype)) mimeAddFilter(mime, desttype, filtertype, 0, "-"); } else filterptr = mimeAddFilter(mime, temptype, filtertype, cost, program); if (filterptr) filterptr->maxsize = maxsize; } }
int /* O - Exit status */ main(int argc, /* I - Number of command-line args */ char *argv[]) /* I - Command-line arguments */ { int i; /* Looping vars */ const char *filter_path; /* Filter path */ char super[MIME_MAX_SUPER], /* Super-type name */ type[MIME_MAX_TYPE]; /* Type name */ int compression; /* Compression of file */ int cost; /* Cost of filters */ mime_t *mime; /* MIME database */ mime_type_t *src, /* Source type */ *dst; /* Destination type */ struct stat srcinfo; /* Source information */ ppd_file_t *ppd; /* PPD file */ cups_array_t *filters; /* Filters for the file */ mime_filter_t *filter; /* Current filter */ mime = NULL; src = NULL; dst = NULL; ppd = NULL; filter_path = "../filter:" CUPS_SERVERBIN "/filter"; srcinfo.st_size = 0; for (i = 1; i < argc; i ++) if (!strcmp(argv[i], "-d")) { i ++; if (i < argc) { mime = mimeLoad(argv[i], filter_path); if (ppd) add_ppd_filters(mime, ppd); } } else if (!strcmp(argv[i], "-f")) { i ++; if (i < argc) filter_path = argv[i]; } else if (!strcmp(argv[i], "-p")) { i ++; if (i < argc) { ppd = ppdOpenFile(argv[i]); if (mime) add_ppd_filters(mime, ppd); } } else if (!src) { if (!mime) mime = mimeLoad("../conf", filter_path); if (ppd) add_ppd_filters(mime, ppd); src = mimeFileType(mime, argv[i], NULL, &compression); stat(argv[i], &srcinfo); if (src) printf("%s: %s/%s%s\n", argv[i], src->super, src->type, compression ? " (gzipped)" : ""); else if ((src = mimeType(mime, "application", "octet-stream")) != NULL) printf("%s: application/octet-stream\n", argv[i]); else { printf("%s: unknown\n", argv[i]); if (mime) mimeDelete(mime); return (1); } } else { sscanf(argv[i], "%15[^/]/%31s", super, type); dst = mimeType(mime, super, type); filters = mimeFilter2(mime, src, srcinfo.st_size, dst, &cost); if (!filters) { printf("No filters to convert from %s/%s to %s.\n", src->super, src->type, argv[i]); } else { int first = 1; /* First filter shown? */ printf("Filter cost = %d\n", cost); for (filter = (mime_filter_t *)cupsArrayFirst(filters); filter; filter = (mime_filter_t *)cupsArrayNext(filters)) { if (!strcmp(filter->filter, "-")) continue; if (first) { first = 0; fputs(filter->filter, stdout); } else printf(" | %s", filter->filter); } putchar('\n'); cupsArrayDelete(filters); } } if (!mime) { mime = mimeLoad("../conf", filter_path); if (ppd) add_ppd_filters(mime, ppd); } if (!src) { puts("MIME database types:"); for (src = mimeFirstType(mime); src; src = mimeNextType(mime)) { printf("\t%s/%s (%d):\n", src->super, src->type, src->priority); print_rules(src->rules); puts(""); } puts(""); puts("MIME database filters:"); for (filter = mimeFirstFilter(mime); filter; filter = mimeNextFilter(mime)) printf("\t%s/%s to %s/%s: %s (%d)\n", filter->src->super, filter->src->type, filter->dst->super, filter->dst->type, filter->filter, filter->cost); type_dir(mime, "../doc"); } return (0); }
status_t IconsSaver::StartSaver(BView *view, bool /*preview*/) { if (fVectorIconsCount <= 0) { // Load the vector icons from the MIME types BMessage types; BMimeType::GetInstalledTypes(&types); for (int32 index = 0 ; ; index++) { const char* type; if (types.FindString("types", index, &type) != B_OK) break; BMimeType mimeType(type); uint8* vectorData = NULL; size_t size = 0; if (mimeType.GetIcon(&vectorData, &size) != B_OK || size == 0) continue; VectorIcon* icon = new VectorIcon; icon->data = vectorData; icon->size = size; fVectorIcons.AddItem(icon); } fVectorIconsCount = fVectorIcons.CountItems(); } srand(system_time() % INT_MAX); BRect screenRect(0, 0, view->Frame().Width(), view->Frame().Height()); fBackBitmap = new BBitmap(screenRect, B_RGBA32, true); if (!fBackBitmap->IsValid()) return B_NO_MEMORY; fBackView = new BView(screenRect, "back view", 0, 0); if (fBackView == NULL) return B_NO_MEMORY; fBackView->SetViewColor(kBackgroundColor); fBackView->SetHighColor(kBackgroundColor); fBackBitmap->AddChild(fBackView); if (fBackBitmap->Lock()) { fBackView->FillRect(fBackView->Frame()); fBackView->SetDrawingMode(B_OP_ALPHA); fBackView->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY); fBackView->Sync(); fBackBitmap->Unlock(); } fIcons = new IconDisplay[MAX_ICONS]; fMaxSize = (screenRect.IntegerWidth() * MAX_SIZE) / 100; fMinSize = (screenRect.IntegerWidth() * MIN_SIZE) / 100; if (fMaxSize > 255) fMaxSize = 255; if (fMaxSize > screenRect.IntegerHeight()) fMaxSize = screenRect.IntegerHeight(); if (fMinSize > fMaxSize) fMinSize = fMaxSize; return B_OK; }
//----------------------------------------------------------------- void MP3Worker::extract_cover(const TagLib::ID3v2::Tag *tags) { auto picture_frames = tags->frameList("APIC"); int i = 0; for(auto it = picture_frames.begin(); it != picture_frames.end(); ++it) { bool adquired = false; QString name = m_configuration.coverPictureName(); QString extension = "picture_unknown_format"; if(picture_frames.size() > 1) { name = "Image_" + QString::number(i); } auto picture = reinterpret_cast<TagLib::ID3v2::AttachedPictureFrame *>(*it); auto mime = QString::fromStdWString(picture->mimeType().toWString()); if(mime.contains("jpg") || mime.contains("jpeg")) { extension = ".jpg"; } if(mime.contains("png")) { extension = ".png"; } if(mime.contains("bmp")) { extension = ".bmp"; } if(mime.contains("tiff")) { extension = ".tif"; } auto cover_name = m_source_path + name + extension; { // if there are several files with the same cover I just need one of the workers to dump the cover, not all of them. QMutexLocker lock(&s_mutex); if (!QFile::exists(cover_name)) { QFile file(cover_name); if (!file.open(QIODevice::WriteOnly|QIODevice::Append)) { emit error_message(QString("Couldn't create cover picture file for '%1', check for file permissions.").arg(m_source_info.absoluteFilePath())); } else { file.close(); adquired = true; } } } if (adquired) { QFile file(cover_name); file.open(QIODevice::WriteOnly|QIODevice::Append); file.write(picture->picture().data(), picture->picture().size()); file.waitForBytesWritten(-1); file.flush(); file.close(); } } }
void ImageFilePanel::SelectionChanged() { entry_ref ref; Rewind(); if (GetNextSelectedRef(&ref) == B_OK) { BEntry entry(&ref); BNode node(&ref); fImageView->ClearViewBitmap(); if (node.IsFile()) { BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref); if (bitmap != NULL) { BRect dest(fImageView->Bounds()); if (bitmap->Bounds().Width() > bitmap->Bounds().Height()) { dest.InsetBy(0, (dest.Height() + 1 - ((bitmap->Bounds().Height() + 1) / (bitmap->Bounds().Width() + 1) * (dest.Width() + 1))) / 2); } else { dest.InsetBy((dest.Width() + 1 - ((bitmap->Bounds().Width() + 1) / (bitmap->Bounds().Height() + 1) * (dest.Height() + 1))) / 2, 0); } fImageView->SetViewBitmap(bitmap, bitmap->Bounds(), dest, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0); BString resolution; resolution << B_TRANSLATE("Resolution: ") << (int)(bitmap->Bounds().Width() + 1) << "x" << (int)(bitmap->Bounds().Height() + 1); fResolutionView->SetText(resolution.String()); delete bitmap; BNodeInfo nodeInfo(&node); char type[B_MIME_TYPE_LENGTH]; if (nodeInfo.GetType(type) == B_OK) { BMimeType mimeType(type); mimeType.GetShortDescription(type); // if this fails, the MIME type will be displayed fImageTypeView->SetText(type); } else { BMimeType refType; if (BMimeType::GuessMimeType(&ref, &refType) == B_OK) { refType.GetShortDescription(type); // if this fails, the MIME type will be displayed fImageTypeView->SetText(type); } else fImageTypeView->SetText(""); } } } else { fResolutionView->SetText(""); fImageTypeView->SetText(""); } fImageView->Invalidate(); fResolutionView->Invalidate(); } BFilePanel::SelectionChanged(); }
QString MeasureDragData::mimeType(openstudio::MeasureType type) { return mimeType() + openstudio::toQString(":" + type.valueName()); }
void MediaRoutingView::_checkDroppedFile( entry_ref *ref, BPoint dropPoint) { D_METHOD(("MediaRoutingView::_checkDroppedFile()\n")); // [cell 26apr00] traverse links BEntry entry(ref, true); entry.GetRef(ref); BNode node(ref); if (node.InitCheck() == B_OK) { BNodeInfo nodeInfo(&node); if (nodeInfo.InitCheck() == B_OK) { char mimeString[B_MIME_TYPE_LENGTH]; if (nodeInfo.GetType(mimeString) == B_OK) { BMimeType mimeType(mimeString); BMimeType superType; // [e.moon 22dec99] handle dropped node-set files if(mimeType == RouteApp::s_nodeSetType) { BMessage m(B_REFS_RECEIVED); m.AddRef("refs", ref); be_app_messenger.SendMessage(&m); } else if (mimeType.GetSupertype(&superType) == B_OK) { if (superType == "image") { _changeBackground(ref); } else if ((superType == "audio") || (superType == "video")) { NodeRef* droppedNode; status_t error; error = manager->instantiate(*ref, B_BUFFER_PRODUCER, &droppedNode); if (!error) { media_output encVideoOutput; if (droppedNode->findFreeOutput(&encVideoOutput, B_MEDIA_ENCODED_VIDEO) == B_OK) { droppedNode->setFlags(droppedNode->flags() | NodeRef::NO_POSITION_REPORTING); } m_lastDroppedNode = droppedNode->id(); m_lastDropPoint = Align(dropPoint); } else { char fileName[B_FILE_NAME_LENGTH]; BEntry entry(ref); entry.GetName(fileName); BString s; s << "Could not load '" << fileName << "'"; showErrorMessage(s, error); } } } } } } }