// get Date and time from this format : xx.xx.xx|xx:xx:xx:xxx TimeStamp* TimeStamp::DateTimeParse(string& tstamp) { stringstream cstream(tstamp); string date = "", time = ""; getline(cstream, date, '|'); getline(cstream, time); if (!CommandParser::getInstance()->checkDateFormat(date)) throw new EXCEPTION("Time format for date isn't correct. Valid format : xx.xx.xxxx"); if (time != "" && !CommandParser::getInstance()->checkTimeFormat(time)) throw new EXCEPTION("Time format for time isn't correct. Valid format : xx:xx:xx:xxx"); stringstream dstream(date), tstream(time); string day, month, year, hr , min, sec, ms; getline(dstream, day, '.'); getline(dstream, month, '.'); getline(dstream, year); /*podrazumevano vreme*/ if (time == "") { hr = min = sec = ms = "0"; } else { getline(tstream, hr, ':'); getline(tstream, min, ':'); getline(tstream, sec, ':'); getline(tstream, ms); } int Day = atoi(day.c_str()); int Month = atoi(month.c_str()); int Year = atoi(year.c_str()); int Hour = atoi(hr.c_str()); int Min = atoi(min.c_str()); int Sec = atoi(sec.c_str()); int Ms = atoi(ms.c_str()); return new TimeStamp(Hour, Min, Sec, Ms, Day, Month, Year); }
virtual bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url) { QByteArray data; QDataStream dstream(&data, QIODevice::ReadWrite); qint32 c = cookieList.count(); dstream << c; qDebug() << cookieList.count(); for (int i = 0; i < c; ++i) dstream << cookieList[i].toRawForm(); dstream.device()->close(); stream << QString("setCookiesFromUrl") << url << data;// << cookieList; bool set = NetworkCookieJar::setCookiesFromUrl(cookieList, url); file.flush(); return set; }
bool KIcoPlugin::readInfo( KFileMetaInfo& info, uint what) { QFile file(info.path()); if (!file.open(IO_ReadOnly)) { kdDebug(7034) << "Couldn't open " << QFile::encodeName(info.path()) << endl; return false; } QDataStream dstream(&file); // ICO files are little-endian dstream.setByteOrder(QDataStream::LittleEndian); // read the beginning of the file and make sure it looks ok uint16_t ico_reserved; uint16_t ico_type; uint16_t ico_count; dstream >> ico_reserved; dstream >> ico_type; dstream >> ico_count; if ((ico_reserved != 0) || (ico_type != 1) || (ico_count < 1)) return false; // now loop through each of the icon entries uint8_t icoe_width; uint8_t icoe_height; uint8_t icoe_colorcount; uint8_t icoe_reserved; uint16_t icoe_planes; uint16_t icoe_bitcount; uint32_t icoe_bytesinres; uint32_t icoe_imageoffset; // read the data on the 1st icon dstream >> icoe_width; dstream >> icoe_height; dstream >> icoe_colorcount; dstream >> icoe_reserved; dstream >> icoe_planes; dstream >> icoe_bitcount; dstream >> icoe_bytesinres; dstream >> icoe_imageoffset; // output the useful bits KFileMetaInfoGroup group = appendGroup(info, "Technical"); appendItem(group, "Number", ico_count); if (ico_count == 1) { appendItem(group, "Dimensions", QSize(icoe_width, icoe_height)); if (icoe_colorcount > 0) appendItem(group, "Colors", icoe_colorcount); else if (icoe_bitcount > 0) appendItem(group, "Colors", 2 ^ icoe_bitcount); } else { appendItem(group, "DimensionsM", QSize(icoe_width, icoe_height)); if (icoe_colorcount > 0) appendItem(group, "ColorsM", icoe_colorcount); else if (icoe_bitcount > 0) appendItem(group, "ColorsM", 2 ^ icoe_bitcount); } return true; }
bool KRpmPlugin::readInfo( KFileMetaInfo& info, uint what) { QFile file(info.path()); int pass; KFileMetaInfoGroup general, all; if (!file.open(QIODevice::ReadOnly)) { kDebug(7034) << "Couldn't open " << QFile::encodeName(info.path()); return false; } QDataStream dstream(&file); dstream.setByteOrder(QDataStream::BigEndian); general = appendGroup(info, "General"); if (what == KFileMetaInfo::Everything) all = appendGroup(info, "All tags"); file.seek(96); // Seek past old lead for (pass = 0; pass < 2; ++pass) { // RPMs have two headers uint32_t storepos, entries, size, reserved; unsigned char version; char magic[3]; dstream.readRawBytes(magic, 3); dstream >> version >> reserved >> entries >> size; if (memcmp(magic, RPM_HEADER_MAGIC, 3)) return false; if (version != 1) return false; // Only v1 headers supported storepos = file.pos() + entries * 16; if (pass == 0) { // Don't need the first batch of tags - pgp etc file.seek(storepos + size); file.seek(file.pos() + (8 - (file.pos() % 8)) % 8); // Skip padding continue; } if (entries < 500) while (entries--) { // Just in case something goes wrong, limit to 500 uint32_t tag, type, offset, count; QString tagname; dstream >> tag >> type >> offset >> count; offset += storepos; switch (tag) { case RPMTAG_NAME: tagname = "Name"; break; case RPMTAG_VERSION: tagname = "Version"; break; case RPMTAG_SUMMARY: tagname = "Summary"; break; case RPMTAG_GROUP: tagname = "Group"; break; case RPMTAG_SIZE: tagname = "Size"; break; case RPMTAG_RELEASE: tagname = "Release"; break; case RPMTAG_VENDOR: tagname = "Vendor"; break; case RPMTAG_PACKAGER: tagname = "Packager"; break; case RPMTAG_DESCRIPTION: tagname = "Comment"; break; } if ( !tagname.isEmpty() || all.isValid() ) { // kDebug(7034) << "Tag number: " << tag << " Type: " << type; int oldPos = file.pos(); file.seek(offset); // Set file position to correct place in store switch (type) { case RPM_INT32_TYPE: uint32_t int32tag; dstream >> int32tag; if ( !tagname.isEmpty() ) appendItem(general, tagname, int(int32tag)); if ( all.isValid() ) appendItem(all, QString("%1").arg( tag ), QString("%1").arg( int32tag )); break; case RPM_INT16_TYPE: uint16_t int16tag; dstream >> int16tag; if ( !tagname.isEmpty() ) appendItem(general, tagname, int(int16tag)); if ( all.isValid() ) appendItem(all, QString("%1").arg( tag ), QString("%1").arg( int16tag )); break; case RPM_I18NSTRING_TYPE: // Fallthru case RPM_STRING_TYPE: QString strtag; char in; while ( ( in = file.getch() ) != '\0' ) strtag += in; if ( !tagname.isEmpty() ) appendItem(general, tagname, strtag); if( all.isValid() ) appendItem(all, QString("%1").arg( tag ), strtag); break; } file.seek(oldPos); // Restore old position } } appendItem(general, "Archive Offset", (storepos + size) ); }
bool KAuPlugin::readInfo( KFileMetaInfo& info, uint what) { // the file signature, wants to be tidier... const char fsig[] = { 0x2e, 0x73, 0x6e, 0x64 }; // a dword buffer for input char inbuf[4]; // some vars for the file properties uint32_t datasize; uint32_t encoding; uint32_t samplerate; uint32_t channels; uint16_t bytespersample; if ( info.path().isEmpty() ) // remote file return false; QFile file(info.path()); if (!file.open(IO_ReadOnly)) { kdDebug(7034) << "Couldn't open " << QFile::encodeName(info.path()) << endl; return false; } QDataStream dstream(&file); // AU files are big-endian dstream.setByteOrder(QDataStream::BigEndian); // Read and verify the signature dstream.readRawBytes(inbuf, 4); if (memcmp(fsig, inbuf, 4)) return false; // skip unwanted bits file.at(8); // grab the bits we want dstream >> datasize; dstream >> encoding; dstream >> samplerate; dstream >> channels; // add the info KFileMetaInfoGroup group = appendGroup(info, "Technical"); appendItem(group, "Sample Rate", (uint) samplerate); appendItem(group, "Channels", (uint) channels); // work out the encoding switch (encoding) { case 1 : appendItem(group, "Encoding", i18n("8-bit ISDN u-law")); bytespersample = 1; break; case 2 : appendItem(group, "Encoding", i18n("8-bit linear PCM [REF-PCM]")); bytespersample = 1; break; case 3 : appendItem(group, "Encoding", i18n("16-bit linear PCM")); bytespersample = 2; break; case 4 : appendItem(group, "Encoding", i18n("24-bit linear PCM")); bytespersample = 3; break; case 5 : appendItem(group, "Encoding", i18n("32-bit linear PCM")); bytespersample = 4; break; case 6 : appendItem(group, "Encoding", i18n("32-bit IEEE floating point")); bytespersample = 4; break; case 7 : appendItem(group, "Encoding", i18n("64-bit IEEE floating point")); bytespersample = 8; break; case 23 : appendItem(group, "Encoding", i18n("8-bit ISDN u-law compressed")); bytespersample = 1; break; default : appendItem(group, "Encoding", i18n("Unknown")); bytespersample = 0; } // work out length from bytespersample + channels + size if ((channels > 0) && (datasize > 0) && (datasize != 0xFFFFFFFF) && (bytespersample > 0) && (samplerate > 0)) { uint32_t length = datasize / channels / bytespersample / samplerate; appendItem(group, "Length", (uint) length); } else { appendItem(group, "Length", "???"); } return true; }
bool KRgbPlugin::readInfo(KFileMetaInfo& info, uint /*what*/) { QFile file(info.path()); if (!file.open(QIODevice::ReadOnly)) { kDebug(7034) << "Couldn't open " << QFile::encodeName(info.path()); return false; } QDataStream dstream(&file); quint16 magic; quint8 storage; quint8 bpc; quint16 dimension; quint16 xsize; quint16 ysize; quint16 zsize; quint32 pixmin; quint32 pixmax; quint32 dummy; char imagename[80]; quint32 colormap; dstream >> magic; dstream >> storage; dstream >> bpc; dstream >> dimension; dstream >> xsize; dstream >> ysize; dstream >> zsize; dstream >> pixmin; dstream >> pixmax; dstream >> dummy; dstream.readRawBytes(imagename, 80); imagename[79] = '\0'; dstream >> colormap; quint8 u8; for (uint i = 0; i < 404; i++) dstream >> u8; if (magic != 474) return false; KFileMetaInfoGroup group; group = appendGroup(info, "Technical"); if (dimension == 1) ysize = 1; appendItem(group, "Dimensions", QSize(xsize, ysize)); appendItem(group, "BitDepth", zsize * 8 * bpc); if (zsize == 1) appendItem(group, "ColorMode", i18n("Grayscale")); else if (zsize == 2) appendItem(group, "ColorMode", i18n("Grayscale/Alpha")); else if (zsize == 3) appendItem(group, "ColorMode", i18n("RGB")); else if (zsize == 4) appendItem(group, "ColorMode", i18n("RGB/Alpha")); if (!storage) appendItem(group, "Compression", i18nc("Compression", "Uncompressed")); else if (storage == 1) { long compressed = file.size() - 512; long verbatim = xsize * ysize * zsize; appendItem(group, "Compression", i18nc("Compression", "Runlength Encoded") + QString(", %1%").arg(compressed * 100.0 / verbatim, 0, 'f', 1)); long k; quint32 offs; QMap<quint32, uint> map; QMap<quint32, uint>::Iterator it; QMap<quint32, uint>::Iterator end = map.end(); for (k = 0; k < (ysize * zsize); k++) { dstream >> offs; if ((it = map.find(offs)) != end) map.insert(offs, *it + 1); else map[offs] = 0; } for (k = 0, it = map.begin(); it != end; ++it) k += *it; if (k) appendItem(group, "SharedRows", QString("%1%").arg(k * 100.0 / (ysize * zsize), 0, 'f', 1)); else appendItem(group, "SharedRows", i18nc("SharedRows", "None")); } else