80-column limit for cdplayer

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39837 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues
2010-12-13 21:37:20 +00:00
parent 9e124835e2
commit 26c424b68f
5 changed files with 73 additions and 54 deletions
+4 -2
View File
@@ -46,7 +46,8 @@ cddb_sum(int n)
// #pragma mark - // #pragma mark -
CDAudioData::CDAudioData(const int32 &id, const int32 &count, const int32 &discLength) CDAudioData::CDAudioData(const int32 &id, const int32 &count,
const int32 &discLength)
: :
fDiscId(id), fDiscId(id),
fTrackCount(count), fTrackCount(count),
@@ -124,7 +125,8 @@ CDAudioTime::operator-(const CDAudioTime &from)
{ {
CDAudioTime time; CDAudioTime time;
int32 tsec = ((fMinutes * 60) + fSeconds) - ((from.fMinutes * 60) + from.fSeconds); int32 tsec = ((fMinutes * 60) + fSeconds) - ((from.fMinutes * 60)
+ from.fSeconds);
if (tsec < 0) { if (tsec < 0) {
time.fMinutes = 0; time.fMinutes = 0;
time.fSeconds = 0; time.fSeconds = 0;
+59 -41
View File
@@ -577,8 +577,8 @@ CDDBQuery::GetSites(bool (*eachFunc)(const char *site, int port, const char *lat
scanner = _GetToken(scanner, longitude); scanner = _GetToken(scanner, longitude);
description = scanner; description = scanner;
if (eachFunc(site.String(), sitePort, latitude.String(), longitude.String(), if (eachFunc(site.String(), sitePort, latitude.String(),
description.String(), passThru)) longitude.String(), description.String(), passThru))
break; break;
} }
_Disconnect(); _Disconnect();
@@ -686,8 +686,8 @@ CDDBQuery::GetTrackTimes(const scsi_toc *toc, vector<CDAudioTime> &times)
status_t status_t
CDDBQuery::_ReadFromServer(BString &data) CDDBQuery::_ReadFromServer(BString &data)
{ {
// This function queries the given CDDB server for the existence of the disc's data and // This function queries the given CDDB server for the existence of the
// saves the data to file once obtained. // disc's data and saves the data to file once obtained.
// Query for the existence of the disc in the database // Query for the existence of the disc in the database
char idString[10]; char idString[10];
@@ -696,7 +696,8 @@ CDDBQuery::_ReadFromServer(BString &data)
int32 trackCount = GetTrackCount(&fSCSIData); int32 trackCount = GetTrackCount(&fSCSIData);
BString offsetString = OffsetsToString(&fSCSIData); BString offsetString = OffsetsToString(&fSCSIData);
int32 discLength = (fCDData.DiscTime()->GetMinutes() * 60) + fCDData.DiscTime()->GetSeconds(); int32 discLength = (fCDData.DiscTime()->GetMinutes() * 60)
+ fCDData.DiscTime()->GetSeconds();
query << "cddb query " << idString << ' ' << trackCount << ' ' query << "cddb query " << idString << ' ' << trackCount << ' '
<< offsetString << ' ' << discLength << '\n'; << offsetString << ' ' << discLength << '\n';
@@ -717,29 +718,32 @@ CDDBQuery::_ReadFromServer(BString &data)
if (tmp.FindFirst("200") != 0) { if (tmp.FindFirst("200") != 0) {
if (tmp.FindFirst("211") == 0) { if (tmp.FindFirst("211") == 0) {
// A 211 means that the query was not exact. To make sure that we don't // A 211 means that the query was not exact. To make sure that we
// have a problem with this in the future, we will choose the first entry that // don't have a problem with this in the future, we will choose the
// the server returns. This may or may not be wise, but in my experience, the first // first entry that the server returns. This may or may not be wise,
// one has been the right one. // but in my experience, the first one has been the right one.
_ReadLine(tmp); _ReadLine(tmp);
// Get the category from the what the server returned // Get the category from the what the server returned
_GetToken(tmp.String(), category); _GetToken(tmp.String(), category);
// Now we will get the disc ID for the CD. We will need this when we query for // Now we will get the disc ID for the CD. We will need this when we
// the track name list. If we send the track name query with the real discID, nothing // query for the track name list. If we send the track name query
// will be returned. However, if we send the one from the entry, we'll get the names // with the real discID, nothing will be returned. However, if we
// and we can take these names attach them to the disc that we have. // send the one from the entry, we'll get the names and we can take
// these names attach them to the disc that we have.
_GetToken(tmp.String() + category.CountChars(), queryDiscID); _GetToken(tmp.String() + category.CountChars(), queryDiscID);
// This is to suck up any more search results that the server sends us. // This is to suck up any more search results that the server sends
// us.
BString throwaway; BString throwaway;
_ReadLine(throwaway); _ReadLine(throwaway);
while (throwaway.ByteAt(0) != '.') while (throwaway.ByteAt(0) != '.')
_ReadLine(throwaway); _ReadLine(throwaway);
} else { } else {
// We get here for any time the CDDB server does not recognize the CD, amongst other things // We get here for any time the CDDB server does not recognize the
// CD, amongst other things
STRACE(("CDDB lookup error: %s\n", tmp.String())); STRACE(("CDDB lookup error: %s\n", tmp.String()));
fCDData.SetGenre("misc"); fCDData.SetGenre("misc");
return B_NAME_NOT_FOUND; return B_NAME_NOT_FOUND;
@@ -828,12 +832,15 @@ CDDBQuery::_ReadLine(BString &buffer)
break; break;
// This function is more work than it should have to be. FreeDB lookups can sometimes // This function is more work than it should have to be. FreeDB lookups
// be in a non-ASCII encoding, such as Latin-1 or UTF8. The problem lies in Be's implementation // can sometimes be in a non-ASCII encoding, such as Latin-1 or UTF8.
// of BString, which does not support UTF8 string assignments. The Be Book says we have to // The problem lies in Be's implementation of BString, which does not
// flatten the string and adjust the character counts manually. Man, this *really* sucks. // support UTF8 string assignments. The Be Book says we have to flatten
// the string and adjust the character counts manually. Man, this
// *really* sucks.
if (ch > 0x7f) { if (ch > 0x7f) {
// Obviously non-ASCII character detected. Let's see if it's Latin-1 or UTF8. // Obviously non-ASCII character detected. Let's see if it's Latin-1
// or UTF8.
unsigned char *string, *stringindex; unsigned char *string, *stringindex;
int32 length = buffer.Length(); int32 length = buffer.Length();
@@ -869,8 +876,10 @@ CDDBQuery::_ReadLine(BString &buffer)
destlen = 5; destlen = 5;
memset(deststr, 0, 5); memset(deststr, 0, 5);
if (convert_to_utf8(B_ISO1_CONVERSION, srcstr, &srclen, deststr, &destlen, &state) == B_OK) { if (convert_to_utf8(B_ISO1_CONVERSION, srcstr, &srclen, deststr,
// We succeeded. Amazing. Now we hack the string into having the character &destlen, &state) == B_OK) {
// We succeeded. Amazing. Now we hack the string into having the
// character
length = buffer.Length(); length = buffer.Length();
string = (unsigned char *)buffer.LockBuffer(length + 10); string = (unsigned char *)buffer.LockBuffer(length + 10);
@@ -884,7 +893,8 @@ CDDBQuery::_ReadLine(BString &buffer)
buffer.UnlockBuffer(); buffer.UnlockBuffer();
} else { } else {
// well, we tried. Append the character to the string and live with it // well, we tried. Append the character to the string and live
// with it
buffer += ch; buffer += ch;
} }
} else } else
@@ -914,7 +924,8 @@ CDDBQuery::_IdentifySelf()
hostname = "haiku"; hostname = "haiku";
BString tmp; BString tmp;
tmp << "cddb hello " << username << " " << hostname << " HaikuCDPlayer 1.0\n"; tmp << "cddb hello " << username << " " << hostname
<< " HaikuCDPlayer 1.0\n";
STRACE((">%s", tmp.String())); STRACE((">%s", tmp.String()));
if (fSocket.Send(tmp.String(), tmp.Length())==-1) { if (fSocket.Send(tmp.String(), tmp.Length())==-1) {
@@ -931,8 +942,9 @@ CDDBQuery::_IdentifySelf()
status_t status_t
CDDBQuery::_OpenContentFile(const int32 &discID) CDDBQuery::_OpenContentFile(const int32 &discID)
{ {
// Makes sure that the lookup has a valid file to work with for the CD content. // Makes sure that the lookup has a valid file to work with for the CD
// Returns true if there is an existing file, false if a lookup is required. // content. Returns true if there is an existing file, false if a lookup is
// required.
BFile file; BFile file;
BString predicate; BString predicate;
@@ -962,8 +974,9 @@ CDDBQuery::_OpenContentFile(const int32 &discID)
status_t status = fCDData.Load(ref); status_t status = fCDData.Load(ref);
if (status == B_NO_INIT) { if (status == B_NO_INIT) {
// We receive this error when the Load() function couldn't load the track times // We receive this error when the Load() function couldn't load the
// This just means that we get it from the SCSI data given to us in SetToCD // track times This just means that we get it from the SCSI data given
// to us in SetToCD
vector<CDAudioTime> times; vector<CDAudioTime> times;
GetTrackTimes(&fSCSIData,times); GetTrackTimes(&fSCSIData,times);
@@ -995,9 +1008,9 @@ CDDBQuery::_QueryThread(void *owner)
query->_ParseData(data); query->_ParseData(data);
query->_WriteFile(); query->_WriteFile();
} else { } else {
// We apparently couldn't connect to the server, so we'll need to handle // We apparently couldn't connect to the server, so we'll need to
// creating tracknames. Note that we do not save to disk. This is because it should // handle creating tracknames. Note that we do not save to disk.
// be up to the user what to do. // This is because it should be up to the user what to do.
query->_SetDefaultInfo(); query->_SetDefaultInfo();
} }
} }
@@ -1061,9 +1074,10 @@ CDDBQuery::_SetDefaultInfo()
void void
CDDBQuery::_ParseData(const BString &data) CDDBQuery::_ParseData(const BString &data)
{ {
// Can't simply call MakeEmpty() because the thread is spawned when the discID kept in fCDData // Can't simply call MakeEmpty() because the thread is spawned when the
// is not the same as what's in the drive and MakeEmpty invalidates *everything* in the object. // discID kept in fCDData is not the same as what's in the drive and
// Considering that we reassign everything here, simply emptying the track list should be sufficient // MakeEmpty invalidates *everything* in the object. Considering that we
// reassign everything here, simply emptying the track list should be sufficient
for (int16 i = fCDData.CountTracks(); i >= 0; i--) for (int16 i = fCDData.CountTracks(); i >= 0; i--)
fCDData.RemoveTrack(i); fCDData.RemoveTrack(i);
@@ -1072,8 +1086,8 @@ CDDBQuery::_ParseData(const BString &data)
int32 trackCount = GetTrackCount(&fSCSIData); int32 trackCount = GetTrackCount(&fSCSIData);
if (data.CountChars() < 1) { if (data.CountChars() < 1) {
// This case occurs when the CDDB lookup fails. On these occasions, we need to generate // This case occurs when the CDDB lookup fails. On these occasions, we
// the file ourselves. This is actually pretty easy. // need to generate the file ourselves. This is actually pretty easy.
fCDData.SetArtist("Artist"); fCDData.SetArtist("Artist");
fCDData.SetAlbum("Audio CD"); fCDData.SetAlbum("Audio CD");
fCDData.SetGenre("Misc"); fCDData.SetGenre("Misc");
@@ -1093,15 +1107,17 @@ CDDBQuery::_ParseData(const BString &data)
// TODO: This function is dog slow, but it works. Optimize. // TODO: This function is dog slow, but it works. Optimize.
// Ideally, the search should be done sequentially using GetLineFromString() and strchr(). // Ideally, the search should be done sequentially using GetLineFromString()
// Order: genre(category), frame offsets, disc length, artist/album, track titles // and strchr(). Order: genre(category), frame offsets, disc length,
// artist/album, track titles
int32 pos; int32 pos;
pos = data.FindFirst("DYEAR="); pos = data.FindFirst("DYEAR=");
if (pos > 0) { if (pos > 0) {
BString artist,album; BString artist,album;
artist = album = GetLineFromString(data.String() + sizeof("DYEAR") + pos); artist = album = GetLineFromString(data.String() + sizeof("DYEAR")
+ pos);
// TODO: finish, once I find an entry which actually has a year in it // TODO: finish, once I find an entry which actually has a year in it
BAlert *alert = new BAlert("SimplyVorbis", "DYEAR entry found\n", "OK"); BAlert *alert = new BAlert("SimplyVorbis", "DYEAR entry found\n", "OK");
@@ -1112,7 +1128,8 @@ CDDBQuery::_ParseData(const BString &data)
pos = data.FindFirst("DTITLE="); pos = data.FindFirst("DTITLE=");
if (pos > 0) { if (pos > 0) {
BString artist,album; BString artist,album;
artist = album = GetLineFromString(data.String() + sizeof("DTITLE") + pos); artist = album = GetLineFromString(data.String() + sizeof("DTITLE")
+ pos);
pos = artist.FindFirst(" / "); pos = artist.FindFirst(" / ");
if (pos > 0) if (pos > 0)
@@ -1138,7 +1155,8 @@ CDDBQuery::_ParseData(const BString &data)
BString trackName = data.String() + pos + searchString.Length(); BString trackName = data.String() + pos + searchString.Length();
trackName.Truncate(trackName.FindFirst("\n")); trackName.Truncate(trackName.FindFirst("\n"));
CDAudioTime tracktime = trackTimes[trackCount + 1] - trackTimes[trackCount]; CDAudioTime tracktime = trackTimes[trackCount + 1]
- trackTimes[trackCount];
fCDData.AddTrack(trackName.String(),tracktime); fCDData.AddTrack(trackName.String(),tracktime);
trackCount++; trackCount++;
+5 -6
View File
@@ -8,13 +8,12 @@
#include "DoubleShotDrawButton.h" #include "DoubleShotDrawButton.h"
#include <stdio.h> #include <stdio.h>
// The only difference between this class and DrawButton is the fact that it is invoked // The only difference between this class and DrawButton is the fact that it is
// twice during a mousedown-mouseup cycle. It fires when pushed, and then again when // invoked twice during a mousedown-mouseup cycle. It fires when pushed, and
// released. // then again when released.
DoubleShotDrawButton::DoubleShotDrawButton(BRect frame, const char *name, BBitmap *up, DoubleShotDrawButton::DoubleShotDrawButton(BRect frame, const char *name,
BBitmap *down,BMessage *msg, int32 resize, BBitmap *up, BBitmap *down,BMessage *msg, int32 resize, int32 flags)
int32 flags)
: DrawButton(frame, name, up,down, msg, resize, flags) : DrawButton(frame, name, up,down, msg, resize, flags)
{ {
} }
+2 -2
View File
@@ -12,8 +12,8 @@ Application CDPlayer :
TwoStateDrawButton.cpp TwoStateDrawButton.cpp
VolumeSlider.cpp VolumeSlider.cpp
: be $(TARGET_SELECT_UNAME_ETC_LIB) $(TARGET_NETAPI_LIB) $(TARGET_LIBSTDC++) $(HAIKU_LOCALE_LIBS) : be $(TARGET_SELECT_UNAME_ETC_LIB) $(TARGET_NETAPI_LIB) $(TARGET_LIBSTDC++)
translation textencoding $(HAIKU_LOCALE_LIBS) translation textencoding
: CDPlayer.rdef : CDPlayer.rdef
; ;
+3 -3
View File
@@ -10,9 +10,9 @@
#include "TwoStateDrawButton.h" #include "TwoStateDrawButton.h"
TwoStateDrawButton::TwoStateDrawButton(BRect frame, const char *name, BBitmap *upone, TwoStateDrawButton::TwoStateDrawButton(BRect frame, const char *name,
BBitmap *downone, BBitmap *uptwo, BBitmap *downtwo, BMessage *msg, BBitmap *upone, BBitmap *downone, BBitmap *uptwo, BBitmap *downtwo,
const int32 &resize, const int32 &flags) BMessage *msg, const int32 &resize, const int32 &flags)
: BButton(frame, name, "", msg, resize, flags), : BButton(frame, name, "", msg, resize, flags),
fUpOne(upone), fUpOne(upone),
fDownOne(downone), fDownOne(downone),