diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-01 23:15:51 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-01 23:15:51 +0000 |
commit | 6b1b516f42036cf9eff691dba3fd6e9eab82a7e1 (patch) | |
tree | 6830f75fd57d0fac7e33c097ee98b210e90c5239 /src/cddb.cpp | |
parent | 6318b8bb3ef964cfa99ba454a2630779cc9ac3ec (diff) | |
download | soundkonverter-6b1b516f42036cf9eff691dba3fd6e9eab82a7e1.tar.gz soundkonverter-6b1b516f42036cf9eff691dba3fd6e9eab82a7e1.zip |
TQt4 port soundkonverter
This enables compilation under both Qt3 and Qt4
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/soundkonverter@1239038 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/cddb.cpp')
-rwxr-xr-x | src/cddb.cpp | 162 |
1 files changed, 81 insertions, 81 deletions
diff --git a/src/cddb.cpp b/src/cddb.cpp index 58ebde7..5129987 100755 --- a/src/cddb.cpp +++ b/src/cddb.cpp @@ -29,12 +29,12 @@ #endif #include <errno.h> #include <unistd.h> -#include <qdir.h> -#include <qtextstream.h> -#include <qregexp.h> -//#include <qapp.h> -#include <qstring.h> -// #include <qcursor.h> +#include <tqdir.h> +#include <tqtextstream.h> +#include <tqregexp.h> +//#include <tqapp.h> +#include <tqstring.h> +// #include <tqcursor.h> //#include <kdebug.h> #include <ksock.h> #include <kextsock.h> @@ -49,7 +49,7 @@ CDDB::CDDB() : ks(0), port(80), remote(false), save_local(false) { - QString s = QDir::homeDirPath()+"/.cddb"; + TQString s = TQDir::homeDirPath()+"/.cddb"; cddb_dirs +=s; } @@ -86,7 +86,7 @@ CDDB::set_server(const char *hostname, unsigned short int _port) h_name = hostname; port = _port; - QCString r; + TQCString r; readLine(r); // the server greeting writeLine("cddb hello kde-user blubb kio_audiocd 0.4"); readLine(r); @@ -102,7 +102,7 @@ CDDB::deinit() if (ks) { writeLine("quit"); - QCString r; + TQCString r; readLine(r); ks->close(); } @@ -116,7 +116,7 @@ CDDB::deinit() bool -CDDB::readLine(QCString& ret) +CDDB::readLine(TQCString& ret) { int read_length = 0; char small_b[128]; @@ -126,7 +126,7 @@ CDDB::readLine(QCString& ret) while (read_length < 40000) { // Look for a \n in buf - int ni = buf.find('\n'); + int ni = buf.tqfind('\n'); if (ni >= 0) { // Nice, so return this substring (without the \n), @@ -157,7 +157,7 @@ CDDB::readLine(QCString& ret) bool -CDDB::writeLine(const QCString& line) +CDDB::writeLine(const TQCString& line) { const char *b = line.data(); int l = line.length(); @@ -189,7 +189,7 @@ CDDB::writeLine(const QCString& line) unsigned int -CDDB::get_discid(QValueList<int>& track_ofs) +CDDB::get_discid(TQValueList<int>& track_ofs) { unsigned int id = 0; int num_tracks = track_ofs.count() - 2; @@ -216,7 +216,7 @@ CDDB::get_discid(QValueList<int>& track_ofs) static int -get_code (const QCString &s) +get_code (const TQCString &s) { bool ok; int code = s.left(3).toInt(&ok); @@ -228,17 +228,17 @@ get_code (const QCString &s) static void -parse_query_resp (const QCString& _r, QCString& catg, QCString& d_id, QCString& title) +parse_query_resp (const TQCString& _r, TQCString& catg, TQCString& d_id, TQCString& title) { - QCString r = _r.stripWhiteSpace(); - int i = r.find(' '); + TQCString r = _r.stripWhiteSpace(); + int i = r.tqfind(' '); if (i) { catg = r.left(i).stripWhiteSpace(); r.remove(0, i+1); r = r.stripWhiteSpace(); } - i = r.find(' '); + i = r.tqfind(' '); if (i) { d_id = r.left(i).stripWhiteSpace(); @@ -250,32 +250,32 @@ parse_query_resp (const QCString& _r, QCString& catg, QCString& d_id, QCString& -QString +TQString CDDB::track(int i) const { if (i < 0 || i >= int(m_names.count())) - return QString(); + return TQString(); return m_names[i].utf8(); } -QString +TQString CDDB::artist(int i) const { if (i < 0 || i >= int(m_artists.count())) - return QString(); + return TQString(); return m_artists[i].utf8(); } bool -CDDB::parse_read_resp(QTextStream *stream, QTextStream *write_stream) +CDDB::parse_read_resp(TQTextStream *stream, TQTextStream *write_stream) { /* Note, that m_names and m_title should be empty */ - QCString end = "."; + TQCString end = "."; m_disc = 0; m_year = 0; @@ -289,7 +289,7 @@ CDDB::parse_read_resp(QTextStream *stream, QTextStream *write_stream) } while (1) { - QCString r; + TQCString r; if (stream) { if (stream->atEnd()) @@ -313,12 +313,12 @@ CDDB::parse_read_resp(QTextStream *stream, QTextStream *write_stream) if (r.left(7) == "DTITLE=") { r.remove(0, 7); - m_title += QString::fromLocal8Bit(r.stripWhiteSpace()); + m_title += TQString::fromLocal8Bit(r.stripWhiteSpace()); } else if (r.left(6) == "TTITLE") { r.remove(0, 6); - int e = r.find('='); + int e = r.tqfind('='); if (e) { bool ok; @@ -326,28 +326,28 @@ CDDB::parse_read_resp(QTextStream *stream, QTextStream *write_stream) if (ok && i >= 0 && i < m_tracks) { r.remove(0, e+1); - m_names[i] += QString::fromLocal8Bit(r); + m_names[i] += TQString::fromLocal8Bit(r); } } } else if (r.left(6) == "DYEAR=") { r.remove(0, 6); - QString year = QString::fromLocal8Bit(r.stripWhiteSpace()); + TQString year = TQString::fromLocal8Bit(r.stripWhiteSpace()); m_year = year.toInt(); - //kdDebug(7101) << "CDDB: found Year: " << QString().sprintf("%04i",m_year) << endl; + //kdDebug(7101) << "CDDB: found Year: " << TQString().sprintf("%04i",m_year) << endl; } else if (r.left(7) == "DGENRE=") { r.remove(0, 7); - m_genre = QString::fromLocal8Bit(r.stripWhiteSpace()); + m_genre = TQString::fromLocal8Bit(r.stripWhiteSpace()); //kdDebug(7101) << "CDDB: found Genre: " << m_genre << endl; } } /* XXX We should canonicalize the strings ("\n" --> '\n' e.g.) */ - int si = m_title.find(" / "); + int si = m_title.tqfind(" / "); if (si > 0) { m_artist = m_title.left(si).stripWhiteSpace(); @@ -355,10 +355,10 @@ CDDB::parse_read_resp(QTextStream *stream, QTextStream *write_stream) m_title = m_title.stripWhiteSpace(); } - si = m_title.find(" - CD"); + si = m_title.tqfind(" - CD"); if (si > 0) { - QString disc = m_title.right(m_title.length()-(si+5)).stripWhiteSpace(); + TQString disc = m_title.right(m_title.length()-(si+5)).stripWhiteSpace(); m_disc = disc.toInt(); //kdDebug(7101) << "CDDB: found Disc: " << disc << endl; m_title = m_title.left(si).stripWhiteSpace(); @@ -367,22 +367,22 @@ CDDB::parse_read_resp(QTextStream *stream, QTextStream *write_stream) if (m_title.isEmpty()) m_title = i18n("No Title"); /*else - m_title.replace(QRegExp("/"), "%2f");*/ + m_title.tqreplace(TQRegExp("/"), "%2f");*/ if (m_artist.isEmpty()) m_artist = i18n("Unknown"); /*else - m_artist.replace(QRegExp("/"), "%2f");*/ + m_artist.tqreplace(TQRegExp("/"), "%2f");*/ //kdDebug(7101) << "CDDB: found Title: `" << m_title << "'" << endl; for (int i = 0; i < m_tracks; i++) { if (m_names[i].isEmpty()) - m_names[i] += i18n("Track %1").arg(i); - //m_names[i].replace(QRegExp("/"), "%2f"); - si = m_names[i].find(" - "); + m_names[i] += i18n("Track %1").tqarg(i); + //m_names[i].tqreplace(TQRegExp("/"), "%2f"); + si = m_names[i].tqfind(" - "); if (si < 0) { - si = m_names[i].find(" / "); + si = m_names[i].tqfind(" / "); } if (si > 0) { @@ -402,9 +402,9 @@ CDDB::parse_read_resp(QTextStream *stream, QTextStream *write_stream) void -CDDB::add_cddb_dirs(const QStringList& list) +CDDB::add_cddb_dirs(const TQStringList& list) { - QString s = QDir::homeDirPath()+"/.cddb"; + TQString s = TQDir::homeDirPath()+"/.cddb"; cddb_dirs = list; if (cddb_dirs.isEmpty()) @@ -416,15 +416,15 @@ CDDB::add_cddb_dirs(const QStringList& list) /* Locates and opens the local file corresponding to that discid. Returns TRUE, if file is found and ready for reading. Returns FALSE, if file isn't found. In this case ret_file is initialized - with a QFile which resides in the first cddb_dir, and has a temp name + with a TQFile which resides in the first cddb_dir, and has a temp name (the ID + getpid()). You can open it for writing. */ bool -CDDB::searchLocal(unsigned int id, QFile *ret_file) +CDDB::searchLocal(unsigned int id, TQFile *ret_file) { - QDir dir; - QString filename; - filename = QString("%1").arg(id, 0, 16).rightJustify(8, '0'); - QStringList::ConstIterator it; + TQDir dir; + TQString filename; + filename = TQString("%1").tqarg(id, 0, 16).rightJustify(8, '0'); + TQStringList::ConstIterator it; for (it = cddb_dirs.begin(); it != cddb_dirs.end(); ++it) { dir.setPath(*it); @@ -436,9 +436,9 @@ CDDB::searchLocal(unsigned int id, QFile *ret_file) return true; /* And then in the subdirs of dir (representing the categories normally). */ - const QFileInfoList *subdirs = dir.entryInfoList (QDir::Dirs); - QFileInfoListIterator fiit(*subdirs); - QFileInfo *fi; + const TQFileInfoList *subdirs = dir.entryInfoList (TQDir::Dirs); + TQFileInfoListIterator fiit(*subdirs); + TQFileInfo *fi; while ((fi = fiit.current()) != 0) { ret_file->setName (*it + "/" + fi->fileName() + "/" + filename); @@ -447,14 +447,14 @@ CDDB::searchLocal(unsigned int id, QFile *ret_file) ++fiit; } } - QString pid; + TQString pid; pid.setNum(::getpid()); ret_file->setName (cddb_dirs[0] + "/" + filename + "." + pid); /* Try to create the save location. */ dir.setPath(cddb_dirs[0]); if (save_local && !dir.exists()) { - //dir = QDir::current(); + //dir = TQDir::current(); dir.mkdir(cddb_dirs[0]); } return false; @@ -463,13 +463,13 @@ CDDB::searchLocal(unsigned int id, QFile *ret_file) bool -CDDB::queryCD(QValueList<int>& track_ofs) +CDDB::queryCD(TQValueList<int>& track_ofs) { int num_tracks = track_ofs.count() - 2; if (num_tracks < 1) return false; unsigned int id = get_discid(track_ofs); - QFile file; + TQFile file; bool local; /* Already read this ID. */ @@ -477,7 +477,7 @@ CDDB::queryCD(QValueList<int>& track_ofs) return true; emit cddbMessage(i18n("Searching local cddb entry ...")); - qApp->processEvents(); + tqApp->processEvents(); /* First look for a local file. */ local = searchLocal (id, &file); @@ -492,41 +492,41 @@ CDDB::queryCD(QValueList<int>& track_ofs) m_discid = id; if (local) { - QTextStream stream(&file); + TQTextStream stream(&file); /* XXX Hmm, what encoding is used by CDDB files? local? Unicode? Nothing? */ - //stream.setEncoding(QTextStream::Locale); + //stream.setEncoding(TQTextStream::Locale); parse_read_resp(&stream, 0); file.close(); return true; } emit cddbMessage(i18n("Searching remote cddb entry ...")); - qApp->processEvents(); + tqApp->processEvents(); /* Remote CDDB query. */ unsigned int length = track_ofs[num_tracks+1] - track_ofs[num_tracks]; - QCString q; + TQCString q; q.sprintf("cddb query %08x %d", id, num_tracks); - QCString num; + TQCString num; for (int i = 0; i < num_tracks; i++) q += " " + num.setNum(track_ofs[i]); q += " " + num.setNum(length / 75); if (!writeLine(q)) return false; - QCString r; + TQCString r; if (!readLine(r)) return false; r = r.stripWhiteSpace(); int code = get_code(r); if (code == 200) { - QCString catg, d_id, title; - QDir dir; - QCString s, pid; + TQCString catg, d_id, title; + TQDir dir; + TQCString s, pid; emit cddbMessage(i18n("Found exact match cddb entry ...")); - qApp->processEvents(); + tqApp->processEvents(); /* an exact match */ r.remove(0, 3); @@ -553,16 +553,16 @@ CDDB::queryCD(QValueList<int>& track_ofs) if (save_local && file.open(IO_WriteOnly)) { //kdDebug(7101) << "CDDB: file name to save =" << file.name() << endl; - QTextStream stream(&file); + TQTextStream stream(&file); if (!parse_read_resp(0, &stream)) { file.remove(); return false; } file.close(); - /*QString newname (file.name()); - newname.truncate(newname.findRev('.')); - if (QDir::current().rename(file.name(), newname)) { + /*TQString newname (file.name()); + newname.truncate(newname.tqfindRev('.')); + if (TQDir::current().rename(file.name(), newname)) { //kdDebug(7101) << "CDDB: rename failed" << endl; file.remove(); } */ @@ -574,16 +574,16 @@ CDDB::queryCD(QValueList<int>& track_ofs) { // Found some close matches. We'll read the query response and ask the user // which one should be fetched from the server. - QCString end = "."; - QCString catg, d_id, title; - QDir dir; - QCString s, pid, first_match; - QStringList disc_ids; + TQCString end = "."; + TQCString catg, d_id, title; + TQDir dir; + TQCString s, pid, first_match; + TQStringList disc_ids; /* some close matches */ //XXX may be try to find marker based on r emit cddbMessage(i18n("Found close cddb entry ...")); - qApp->processEvents(); + tqApp->processEvents(); int i=0; while (1) @@ -602,12 +602,12 @@ CDDB::queryCD(QValueList<int>& track_ofs) bool ok = false; // We don't want to be thinking too much, do we? -// QApplication::restoreOverrideCursor(); +// TQApplication::restoreOverrideCursor(); // Oh, mylord, which match should I serve you? - QString _answer = KInputDialog::getItem(i18n("CDDB Matches"), i18n("Several close CDDB entries found. Choose one:"), + TQString _answer = KInputDialog::getItem(i18n("CDDB Matches"), i18n("Several close CDDB entries found. Choose one:"), disc_ids, 0, false, &ok ); - QCString answer = _answer.utf8(); + TQCString answer = _answer.utf8(); if (ok){ // Get user selected match parse_query_resp(answer, catg, d_id, title); @@ -617,7 +617,7 @@ CDDB::queryCD(QValueList<int>& track_ofs) } // Now we can continue thinking... -// QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); +// TQApplication::setOverrideCursor( TQCursor(TQt::WaitCursor) ); /*kdDebug(7101) << "CDDB: found close CD: category=" << catg << " DiscId=" << d_id << " Title=`" << title << "'" << endl;*/ @@ -644,7 +644,7 @@ CDDB::queryCD(QValueList<int>& track_ofs) if (save_local && file.open(IO_WriteOnly)) { //kdDebug(7101) << "CDDB: file name to save =" << file.name() << endl; - QTextStream stream(&file); + TQTextStream stream(&file); if (!parse_read_resp(0, &stream)) { file.remove(); |