40 changes: 22 additions & 18 deletions mythtv/programs/mythbackend/mainserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4385,36 +4385,40 @@ void MainServer::GetFilesystemInfos(QList<FileSystemInfo> &fsInfos)
fsInfos.push_back(fsInfo);
}

VERBOSE(VB_SCHEDULE+VB_FILE+VB_EXTRA, "Determining unique filesystems");
VERBOSE(VB_SCHEDULE|VB_FILE|VB_EXTRA, "Determining unique filesystems");
size_t maxWriteFiveSec = GetCurrentMaxBitrate()/12 /*5 seconds*/;
maxWriteFiveSec = max((size_t)2048, maxWriteFiveSec); // safety for NFS mounted dirs
// safety for NFS mounted dirs
maxWriteFiveSec = max((size_t)2048, maxWriteFiveSec);

FileSystemInfo::Consolidate(fsInfos, false, maxWriteFiveSec);

QList<FileSystemInfo>::iterator it1;
if (VERBOSE_LEVEL_CHECK(VB_FILE|VB_SCHEDULE))
{
cout << "--- GetFilesystemInfos directory list start ---" << endl;
VERBOSE(VB_FILE|VB_SCHEDULE, "--- GetFilesystemInfos directory list "
"start ---");
for (it1 = fsInfos.begin(); it1 != fsInfos.end(); ++it1)
{
QString msg = QString("Dir: %1:%2")
.arg(it1->getHostname()).arg(it1->getPath());
cout << msg.toLocal8Bit().constData() << endl;
cout << " Location: ";
if (it1->isLocal())
cout << "Local";
else
cout << "Remote";
cout << endl;
cout << " fsID : " << it1->getFSysID() << endl;
cout << " dirID : " << it1->getGroupID() << endl;
cout << " BlkSize : " << it1->getBlockSize() << endl;
cout << " TotalKB : " << it1->getTotalSpace() << endl;
cout << " UsedKB : " << it1->getUsedSpace() << endl;
cout << " FreeKB : " << it1->getFreeSpace() << endl;
cout << endl;
VERBOSE(VB_FILE|VB_SCHEDULE, msg) ;
VERBOSE(VB_FILE|VB_SCHEDULE, QString(" Location: %1")
.arg(it1->isLocal() ? "Local" : "Remote"));
VERBOSE(VB_FILE|VB_SCHEDULE, QString(" fsID : %1")
.arg(it1->getFSysID()));
VERBOSE(VB_FILE|VB_SCHEDULE, QString(" dirID : %1")
.arg(it1->getGroupID()));
VERBOSE(VB_FILE|VB_SCHEDULE, QString(" BlkSize : %1")
.arg(it1->getBlockSize()));
VERBOSE(VB_FILE|VB_SCHEDULE, QString(" TotalKB : %1")
.arg(it1->getTotalSpace()));
VERBOSE(VB_FILE|VB_SCHEDULE, QString(" UsedKB : %1")
.arg(it1->getUsedSpace()));
VERBOSE(VB_FILE|VB_SCHEDULE, QString(" FreeKB : %1")
.arg(it1->getFreeSpace()));
}
cout << "--- GetFilesystemInfos directory list end ---" << endl;
VERBOSE(VB_FILE|VB_SCHEDULE, "--- GetFilesystemInfos directory list "
"end ---");
}
}

Expand Down
160 changes: 83 additions & 77 deletions mythtv/programs/mythbackend/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ using namespace std;
#define LOC_WARN QString("Scheduler, Warning: ")
#define LOC_ERR QString("Scheduler, Error: ")

bool debugConflicts = false;

Scheduler::Scheduler(bool runthread, QMap<int, EncoderLink *> *tvList,
QString tmptable, Scheduler *master_sched) :
recordTable(tmptable),
Expand All @@ -69,6 +71,9 @@ Scheduler::Scheduler(bool runthread, QMap<int, EncoderLink *> *tvList,
livetvpriority(0),
prefinputpri(0)
{
char *debug = getenv("DEBUG_CONFLICTS");
debugConflicts = (debug != NULL);

if (master_sched)
master_sched->getAllPending(&reclist);

Expand Down Expand Up @@ -470,9 +475,9 @@ void Scheduler::PrintList(RecList &list, bool onlyFutureRecordings)

QDateTime now = QDateTime::currentDateTime();

cout << "--- print list start ---\n";
cout << "Title - Subtitle Ch Station "
"Day Start End S C I T N Pri" << endl;
VERBOSE(VB_SCHEDULE, "--- print list start ---");
VERBOSE(VB_SCHEDULE, "Title - Subtitle Ch Station "
"Day Start End S C I T N Pri");

RecIter i = list.begin();
for ( ; i != list.end(); ++i)
Expand All @@ -488,22 +493,24 @@ void Scheduler::PrintList(RecList &list, bool onlyFutureRecordings)
PrintRec(first);
}

cout << "--- print list end ---\n";
VERBOSE(VB_SCHEDULE, "--- print list end ---");
}

void Scheduler::PrintRec(const RecordingInfo *p, const char *prefix)
{
if (!VERBOSE_LEVEL_CHECK(VB_SCHEDULE))
return;

QString outstr;

if (prefix)
cout << prefix;
outstr = QString(prefix);

QString episode = p->toString(ProgramInfo::kTitleSubtitle, " - ", "");
episode = episode.leftJustified(34 - (prefix ? strlen(prefix) : 0),
' ', true);

QString outstr = QString("%1 %2 %3 %4-%5 %6 %7 %8 ")
outstr += QString("%1 %2 %3 %4-%5 %6 %7 %8 ")
.arg(episode)
.arg(p->GetChanNum().rightJustified(4, ' '))
.arg(p->GetChannelSchedulingID().leftJustified(7, ' ', true))
Expand All @@ -519,9 +526,7 @@ void Scheduler::PrintRec(const RecordingInfo *p, const char *prefix)
if (p->GetRecordingPriority2())
outstr += QString("/%1").arg(p->GetRecordingPriority2());

QByteArray out = outstr.toLocal8Bit();

cout << out.constData() << endl;
VERBOSE(VB_SCHEDULE, outstr);
}

void Scheduler::UpdateRecStatus(RecordingInfo *pginfo)
Expand All @@ -536,15 +541,15 @@ void Scheduler::UpdateRecStatus(RecordingInfo *pginfo)
{
if (p->GetRecordingStatus() != pginfo->GetRecordingStatus())
{
VERBOSE(VB_IMPORTANT,
VERBOSE(VB_IMPORTANT,
QString("Updating status for %1 on cardid %2 (%3 => %4)")
.arg(p->toString(ProgramInfo::kTitleSubtitle))
.arg(p->GetCardID())
.arg(toString(p->GetRecordingStatus(),
.arg(toString(p->GetRecordingStatus(),
p->GetRecordingRuleType()))
.arg(toString(pginfo->GetRecordingStatus(),
.arg(toString(pginfo->GetRecordingStatus(),
p->GetRecordingRuleType())));
bool resched =
bool resched =
((p->GetRecordingStatus() != rsRecording &&
p->GetRecordingStatus() != rsTuning) ||
(pginfo->GetRecordingStatus() != rsRecording &&
Expand Down Expand Up @@ -586,15 +591,15 @@ void Scheduler::UpdateRecStatus(uint cardid, uint chanid,

if (p->GetRecordingStatus() != recstatus)
{
VERBOSE(VB_IMPORTANT,
VERBOSE(VB_IMPORTANT,
QString("Updating status for %1 on cardid %2 (%3 => %4)")
.arg(p->toString(ProgramInfo::kTitleSubtitle))
.arg(p->GetCardID())
.arg(toString(p->GetRecordingStatus(),
.arg(toString(p->GetRecordingStatus(),
p->GetRecordingRuleType()))
.arg(toString(recstatus,
.arg(toString(recstatus,
p->GetRecordingRuleType())));
bool resched =
bool resched =
((p->GetRecordingStatus() != rsRecording &&
p->GetRecordingStatus() != rsTuning) ||
(recstatus != rsRecording &&
Expand Down Expand Up @@ -900,27 +905,25 @@ bool Scheduler::FindNextConflict(
RecConstIter &j,
int openEnd) const
{
bool is_conflict_dbg = false;

for ( ; j != cardlist.end(); ++j)
{
const RecordingInfo *q = *j;
QString msg;

if (p == q)
continue;

if (!Recording(q))
continue;

if (is_conflict_dbg)
cout << QString("\n comparing with '%1' ").arg(q->GetTitle())
.toLocal8Bit().constData();
if (debugConflicts)
msg = QString("comparing with '%1' ").arg(q->GetTitle());

if (p->GetCardID() != 0 && (p->GetCardID() != q->GetCardID()) &&
!igrp.GetSharedInputGroup(p->GetInputID(), q->GetInputID()))
{
if (is_conflict_dbg)
cout << " cardid== ";
if (debugConflicts)
msg += " cardid== ";
continue;
}

Expand All @@ -929,8 +932,8 @@ bool Scheduler::FindNextConflict(
if (p->GetRecordingEndTime() < q->GetRecordingStartTime() ||
p->GetRecordingStartTime() > q->GetRecordingEndTime())
{
if (is_conflict_dbg)
cout << " no-overlap ";
if (debugConflicts)
msg += " no-overlap ";
continue;
}
}
Expand All @@ -939,22 +942,23 @@ bool Scheduler::FindNextConflict(
if (p->GetRecordingEndTime() <= q->GetRecordingStartTime() ||
p->GetRecordingStartTime() >= q->GetRecordingEndTime())
{
if (is_conflict_dbg)
cout << " no-overlap ";
if (debugConflicts)
msg += " no-overlap ";
continue;
}
}

if (is_conflict_dbg)
cout << "\n" <<
(QString(" cardid's: %1, %2 ")
.arg(p->GetCardID()).arg(q->GetCardID()) +
QString("Shared input group: %1 ")
.arg(igrp.GetSharedInputGroup(
p->GetInputID(), q->GetInputID())) +
QString("mplexid's: %1, %2")
.arg(p->QueryMplexID()).arg(q->QueryMplexID()))
.toLocal8Bit().constData();
if (debugConflicts)
{
VERBOSE(VB_SCHEDULE, msg);
VERBOSE(VB_SCHEDULE, QString(" cardid's: %1, %2 "
"Shared input group: %3 "
"mplexid's: %4, %5")
.arg(p->GetCardID()).arg(q->GetCardID())
.arg(igrp.GetSharedInputGroup(
p->GetInputID(), q->GetInputID()))
.arg(p->QueryMplexID()).arg(q->QueryMplexID()));
}

// if two inputs are in the same input group we have a conflict
// unless the programs are on the same multiplex.
Expand All @@ -966,14 +970,14 @@ bool Scheduler::FindNextConflict(
continue;
}

if (is_conflict_dbg)
cout << "\n Found conflict" << endl;
if (debugConflicts)
VERBOSE(VB_SCHEDULE, "Found conflict");

return true;
}

if (is_conflict_dbg)
cout << "\n No conflict" << endl;
if (debugConflicts)
VERBOSE(VB_SCHEDULE, "No conflict");

return false;
}
Expand All @@ -983,16 +987,13 @@ const RecordingInfo *Scheduler::FindConflict(
const RecordingInfo *p,
int openend) const
{
bool is_conflict_dbg = false;

QMap<int, RecList>::const_iterator it = reclists.begin();
for (; it != reclists.end(); ++it)
{
if (is_conflict_dbg)
{
cout << QString("Checking '%1' for conflicts on cardid %2")
.arg(p->GetTitle()).arg(it.key()).toLocal8Bit().constData();
}
if (debugConflicts)
VERBOSE(VB_SCHEDULE, QString("Checking '%1' for conflicts on "
"cardid %2")
.arg(p->GetTitle()).arg(it.key()));

const RecList &cardlist = *it;
RecConstIter k = cardlist.begin();
Expand Down Expand Up @@ -1376,7 +1377,7 @@ void Scheduler::PruneRedundants(void)

// Restore the old status for some selected cases.
if (p->GetRecordingStatus() == rsMissedFuture ||
(p->GetRecordingStatus() == rsMissed &&
(p->GetRecordingStatus() == rsMissed &&
p->oldrecstatus != rsUnknown) ||
(p->GetRecordingStatus() == rsCurrentRecording &&
p->oldrecstatus == rsPreviousRecording && !p->future) ||
Expand Down Expand Up @@ -1682,7 +1683,7 @@ bool Scheduler::IsBusyRecording(const RecordingInfo *rcinfo)
rctv = (*m_tvList)[cardids[i]];
if (!rctv)
{
// VERBOSE(VB_SCHEDULE,
// VERBOSE(VB_SCHEDULE,
// QString(LOC_ERR + "IsBusyRecording() -> true, "
// "rctv(NULL) for card %2").arg(cardids[i]));

Expand Down Expand Up @@ -2244,7 +2245,7 @@ bool Scheduler::HandleRecording(
if (!recPendingList.contains(schedid))
{
recPendingList[schedid] = false;

livetvTime = (livetvTime < nextrectime) ?
nextrectime : livetvTime;

Expand Down Expand Up @@ -3273,9 +3274,9 @@ void Scheduler::UpdateMatches(int recordid) {
{
for (clause = 0; clause < fromclauses.count(); ++clause)
{
QString msg = QString("Query %1: %2/%3")
.arg(clause).arg(fromclauses[clause]).arg(whereclauses[clause]);
cout << msg.toLocal8Bit().constData() << endl;
VERBOSE(VB_SCHEDULE, QString("Query %1: %2/%3")
.arg(clause).arg(fromclauses[clause]).
arg(whereclauses[clause]));
}
}

Expand Down Expand Up @@ -4190,7 +4191,7 @@ static bool comp_storage_perc_free_space(FileSystemInfo *a, FileSystemInfo *b)
if (b->getTotalSpace() == 0)
return true;

if ((a->getFreeSpace() * 100.0) / a->getTotalSpace() >
if ((a->getFreeSpace() * 100.0) / a->getTotalSpace() >
(b->getFreeSpace() * 100.0) / b->getTotalSpace())
return true;

Expand Down Expand Up @@ -4511,23 +4512,23 @@ int Scheduler::FillRecordingDir(

if (VERBOSE_LEVEL_CHECK(VB_FILE|VB_SCHEDULE))
{
cout << "--- FillRecordingDir Sorted fsInfoList start ---\n";
VERBOSE(VB_FILE|VB_SCHEDULE, "--- FillRecordingDir Sorted fsInfoList "
"start ---");
for (fslistit = fsInfoList.begin();fslistit != fsInfoList.end();
++fslistit)
{
FileSystemInfo *fs = *fslistit;
QString msg = QString(
"%1:%2\n"
" Location : %3\n"
" weight : %4\n"
" free space : %5")
.arg(fs->getHostname()).arg(fs->getPath())
.arg((fs->isLocal()) ? "local" : "remote")
.arg(fs->getWeight())
.arg(fs->getFreeSpace());
cout << msg.toLocal8Bit().constData() << endl;
VERBOSE(VB_FILE|VB_SCHEDULE, QString("%1:%2")
.arg(fs->getHostname()) .arg(fs->getPath()));
VERBOSE(VB_FILE|VB_SCHEDULE, QString(" Location : %1")
.arg((fs->isLocal()) ? "local" : "remote"));
VERBOSE(VB_FILE|VB_SCHEDULE, QString(" weight : %1")
.arg(fs->getWeight()));
VERBOSE(VB_FILE|VB_SCHEDULE, QString(" free space : %5")
.arg(fs->getFreeSpace()));
}
cout << "--- FillRecordingDir Sorted fsInfoList end ---\n";
VERBOSE(VB_FILE|VB_SCHEDULE, "--- FillRecordingDir Sorted fsInfoList "
"end ---");
}

// This code could probably be expanded to check the actual bitrate the
Expand All @@ -4540,9 +4541,9 @@ int Scheduler::FillRecordingDir(
recstartts.secsTo(recendts) / 1024;

bool simulateAutoExpire =
((gCoreContext->GetSetting("StorageScheduler") == "BalancedFreeSpace") &&
(m_expirer) &&
(fsInfoList.size() > 1));
((gCoreContext->GetSetting("StorageScheduler") == "BalancedFreeSpace") &&
(m_expirer) &&
(fsInfoList.size() > 1));

// Loop though looking for a directory to put the file in. The first time
// through we look for directories with enough free space in them. If we
Expand All @@ -4567,7 +4568,8 @@ int Scheduler::FillRecordingDir(
for (fslistit = fsInfoList.begin();
fslistit != fsInfoList.end(); ++fslistit)
{
remainingSpaceKB[(*fslistit)->getFSysID()] = (*fslistit)->getFreeSpace();
remainingSpaceKB[(*fslistit)->getFSysID()] =
(*fslistit)->getFreeSpace();
}

// get list of expirable programs
Expand All @@ -4578,7 +4580,7 @@ int Scheduler::FillRecordingDir(
it != expiring.end(); ++it)
{
// find the filesystem its on
FileSystemInfo *fs=NULL;
FileSystemInfo *fs = NULL;
for (fslistit = fsInfoList.begin();
fslistit != fsInfoList.end(); ++fslistit)
{
Expand Down Expand Up @@ -4622,7 +4624,8 @@ int Scheduler::FillRecordingDir(
break;
}
}
if (foundSlave && programinfo->GetPathname() == filename)
if (foundSlave &&
programinfo->GetPathname() == filename)
{
fs = *fslistit;
programinfo->SetPathname(backuppath);
Expand All @@ -4641,12 +4644,15 @@ int Scheduler::FillRecordingDir(
}

// add this files size to the remaining free space
remainingSpaceKB[fs->getFSysID()] += (*it)->GetFilesize() / 1024;
remainingSpaceKB[fs->getFSysID()] +=
(*it)->GetFilesize() / 1024;

// check if we have enough space for new file
long long desiredSpaceKB = m_expirer->GetDesiredSpace(fs->getFSysID());
long long desiredSpaceKB =
m_expirer->GetDesiredSpace(fs->getFSysID());

if (remainingSpaceKB[fs->getFSysID()] > (desiredSpaceKB + maxSizeKB))
if (remainingSpaceKB[fs->getFSysID()] >
(desiredSpaceKB + maxSizeKB))
{
recording_dir = fs->getPath();
fsID = fs->getFSysID();
Expand Down
42 changes: 20 additions & 22 deletions mythtv/programs/mythbackend/upnpcdsmusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ UPnpCDSRootInfo UPnpCDSMusic::g_RootNodes[] =
"ORDER BY name",
"", "name" },

/*
This is currently broken... need to handle list of items with single parent (like 'All Music')
#if 0
// This is currently broken... need to handle list of items with single parent
// (like 'All Music')

{ "Recently Added",
"*",
Expand All @@ -67,7 +68,8 @@ This is currently broken... need to handle list of items with single parent (lik
"%1 "
"ORDER BY name",
"WHERE (DATEDIFF( CURDATE(), date_modified ) <= 30 ) ", "" },
*/
#endif

{ "By Album",
"song.album_id",
"SELECT a.album_id as id, "
Expand All @@ -78,8 +80,8 @@ This is currently broken... need to handle list of items with single parent (lik
"GROUP BY a.album_id "
"ORDER BY a.album_name",
"WHERE song.album_id=:KEY", "album.album_name" },
/*

#if 0
{ "By Artist",
"artist_id",
"SELECT a.artist_id as id, "
Expand All @@ -90,8 +92,7 @@ This is currently broken... need to handle list of items with single parent (lik
"GROUP BY a.artist_id "
"ORDER BY a.artist_name",
"WHERE song.artist_id=:KEY", "" },
*/
/*

{ "By Genre",
"genre_id",
"SELECT g.genre_id as id, "
Expand All @@ -102,8 +103,8 @@ This is currently broken... need to handle list of items with single parent (lik
"GROUP BY g.genre_id "
"ORDER BY g.genre",
"WHERE song.genre_id=:KEY", "" },
#endif

*/
};

int UPnpCDSMusic::g_nRootCount = sizeof( g_RootNodes ) / sizeof( UPnpCDSRootInfo );
Expand Down Expand Up @@ -268,7 +269,7 @@ void UPnpCDSMusic::AddItem( const UPnpCDSRequest *pRequest,
QString sFileName = query.value( 8).toString();
uint nLength = query.value( 9).toInt();

/*
#if 0
if ((nNodeIdx == 0) || (nNodeIdx == 1))
{
sName = QString( "%1-%2:%3" )
Expand All @@ -277,21 +278,21 @@ void UPnpCDSMusic::AddItem( const UPnpCDSRequest *pRequest,
.arg( sTitle );
}
else
*/
#endif
sName = sTitle;

//cout << nId << " " << sName << endl;


// ----------------------------------------------------------------------
// Cache Host ip Address & Port
// ----------------------------------------------------------------------

// if (!m_mapBackendIp.contains( sHostName ))
// m_mapBackendIp[ sHostName ] = gCoreContext->GetSettingOnHost( "BackendServerIp", sHostName);
//
// if (!m_mapBackendPort.contains( sHostName ))
// m_mapBackendPort[ sHostName ] = gCoreContext->GetSettingOnHost("BackendStatusPort", sHostName);
#if 0
if (!m_mapBackendIp.contains( sHostName ))
m_mapBackendIp[ sHostName ] = gCoreContext->GetSettingOnHost( "BackendServerIp", sHostName);

if (!m_mapBackendPort.contains( sHostName ))
m_mapBackendPort[ sHostName ] = gCoreContext->GetSettingOnHost("BackendStatusPort", sHostName);
#endif

QString sServerIp = gCoreContext->GetSetting( "BackendServerIp" );
QString sPort = gCoreContext->GetSetting( "BackendStatusPort" );
Expand Down Expand Up @@ -333,10 +334,9 @@ void UPnpCDSMusic::AddItem( const UPnpCDSRequest *pRequest,

pItem->SetPropValue( "artist" , sArtist );
pItem->SetPropValue( "album" , sAlbum );
pItem->SetPropValue( "originalTrackNumber" , QString::number( nTrackNum ));

/*
pItem->SetPropValue( "originalTrackNumber" , QString::number(nTrackNum));

#if 0
pObject->AddProperty( new Property( "publisher" , "dc" ));
pObject->AddProperty( new Property( "language" , "dc" ));
pObject->AddProperty( new Property( "relation" , "dc" ));
Expand All @@ -347,9 +347,7 @@ void UPnpCDSMusic::AddItem( const UPnpCDSRequest *pRequest,
pObject->AddProperty( new Property( "storageMedium" , "upnp" ));
pObject->AddProperty( new Property( "contributor" , "dc" ));
pObject->AddProperty( new Property( "date" , "dc" ));
*/

#endif

pResults->Add( pItem );

Expand Down
11 changes: 5 additions & 6 deletions mythtv/programs/mythshutdown/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,18 +817,17 @@ int main(int argc, char **argv)
bWantRecStatus = (bool)(cmdline.toInt("status") == 1);
}

QString logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet, facility, dblog);

gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(false))
{
cout << "mythshutdown: Could not initialize MythContext. "
"Exiting." << endl;
VERBOSE(VB_IMPORTANT, "mythshutdown: Could not initialize MythContext. "
"Exiting.");
return GENERIC_EXIT_NO_MYTHCONTEXT;
}


QString logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet, facility, dblog);

int res = 0;

if (bLockShutdown)
Expand Down
13 changes: 8 additions & 5 deletions mythtv/programs/mythtranscode/transcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,11 +885,14 @@ int Transcode::TranscodeFile(
wait_recover = 0;
}

// int buflen = (int)(arb->audiobuffer_len / rateTimeConv);
// cout << curFrameNum << ": video time: " << frame.timecode
// << " audio time: " << arb->last_audiotime << " buf: "
// << buflen << " exp: "
// << audbufTime << " delta: " << delta << endl;
#if 0
int buflen = (int)(arb->audiobuffer_len / rateTimeConv);
VERBOSE(VB_GENERAL, QString("%1: video time: %2 audio time: %3 "
"buf: %4 exp: %5 delta: %6")
.arg(curFrameNum) .arg(frame.timecode)
.arg(arb->last_audiotime) .arg(buflen) .arg(audbufTime)
.arg(delta));
#endif
if (arb->audiobuffer_len)
fifow->FIFOWrite(1, arb->audiobuffer, arb->audiobuffer_len);
if (dropvideo < 0)
Expand Down
96 changes: 50 additions & 46 deletions themestringstool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void parseElement(QDomElement &element)
laststring = lines.join(" ");

laststring.replace(QString("<newline>"), QString("\\n"));

if (!strings.contains(laststring))
strings << laststring;
++stringCount;
Expand All @@ -100,10 +100,10 @@ void parseDirectory(QString dir)
QDir themeDir(dir);

cout << "Searching directory: " << qPrintable(themeDir.path()) << endl;

themeDir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
themeDir.setSorting(QDir::DirsFirst);

QDomDocument doc;
QFileInfoList themeFiles = themeDir.entryInfoList();
QFileInfoList::const_iterator it;
Expand All @@ -119,7 +119,7 @@ void parseDirectory(QString dir)
continue;

cout << " Found: " << qPrintable((*it).filePath()) << endl;

QFile fin((*it).absoluteFilePath());

if (!fin.open(QIODevice::ReadOnly))
Expand All @@ -145,7 +145,7 @@ void parseDirectory(QString dir)
fin.close();

stringCount = 0;

QDomElement docElem = doc.documentElement();
QDomNode n = docElem.firstChild();
while (!n.isNull())
Expand All @@ -157,7 +157,7 @@ void parseDirectory(QString dir)
}
n = n.nextSibling();
}

cout << " Contains " << stringCount << " total strings" << endl;
}

Expand Down Expand Up @@ -220,51 +220,55 @@ int main(int argc, char *argv[])
fdataout << QString(" ThemeUI::tr(\"%1\");\n")
.arg((*strit).toUtf8().data());

// if (translatedStrings.contains(*strit))
// {
// QStringList prevSeenLanguages;
// QList<QString> values = translatedStrings.values(*strit);
// for (int i = 0; i < values.size(); ++i)
// {
// QString language = values.at(i).section("{}", 0, 0);
// if (prevSeenLanguages.contains(language))
// continue;
// prevSeenLanguages << language;
//
// QString translation = values.at(i).section("{}", 1, 1);
// if (!transFiles.contains(language))
// {
// QFile *tmp = new QFile(outfile + '_' + language + ".ts");
// if (!tmp->open(QIODevice::WriteOnly))
// {
// cerr << "couldn't open language file\n";
// exit(-1);
// }
//
// transFiles[language] = tmp;
// }
//
// QTextStream dstream(transFiles[language]);
// dstream.setCodec("UTF-8");
//
// dstream << " <message>\n"
// << " <location filename=\"" << qPrintable(outfile) << "\" line=\"" << lineCount << "\"/>\n"
// << " <source>" << Qt::escape(*strit).replace("\"", "&quot;") << "<source>\n"
// << " <translation>" << Qt::escape(translation).replace("\"", "&quot;") << "<translation>\n"
// << " <message>\n";
// }
// }
#if 0
if (translatedStrings.contains(*strit))
{
QStringList prevSeenLanguages;
QList<QString> values = translatedStrings.values(*strit);
for (int i = 0; i < values.size(); ++i)
{
QString language = values.at(i).section("{}", 0, 0);
if (prevSeenLanguages.contains(language))
continue;
prevSeenLanguages << language;

QString translation = values.at(i).section("{}", 1, 1);
if (!transFiles.contains(language))
{
QFile *tmp = new QFile(outfile + '_' + language + ".ts");
if (!tmp->open(QIODevice::WriteOnly))
{
cerr << "couldn't open language file\n";
exit(-1);
}

transFiles[language] = tmp;
}

QTextStream dstream(transFiles[language]);
dstream.setCodec("UTF-8");

dstream << " <message>\n"
<< " <location filename=\"" << qPrintable(outfile) << "\" line=\"" << lineCount << "\"/>\n"
<< " <source>" << Qt::escape(*strit).replace("\"", "&quot;") << "<source>\n"
<< " <translation>" << Qt::escape(translation).replace("\"", "&quot;") << "<translation>\n"
<< " <message>\n";
}
}
#endif
++lineCount;
}

fdataout << QString("}\n");
fstringout.close();

// QMap<QString, QFile *>::Iterator it;
// for (it = transFiles.begin(); it != transFiles.end(); ++it)
// {
// it.value()->close();
// }
#if 0
QMap<QString, QFile *>::Iterator it;
for (it = transFiles.begin(); it != transFiles.end(); ++it)
{
it.value()->close();
}
#endif

cout << endl;
cout << "---------------------------------------" << endl;
Expand Down