Source Code (Use browser search to find items of interest.)
Class Index
amor'AmorTips (./kdetoys/amor/amortips.h:22)
class AmorTips
{
public:
AmorTips();
bool setFile(const char *file);
void reset();
const char *tip();
protected:
bool read(const char *file);
bool readTip(QFile &file);
protected:
QStrList mTips;
};
amor'AmorTips::AmorTips() (./kdetoys/amor/amortips.cpp:20)
AmorTips::AmorTips()
{
}
//---------------------------------------------------------------------------
//
// Set the file containing tips. This reads all tips into memory at the
// moment - need to make more efficient.
//
amor'AmorTips::setFile() (./kdetoys/amor/amortips.cpp:29)
bool AmorTips::setFile(const char *file)
{
#if QT_VERSION >= 199
QStringList list = KGlobal::locale()->languageList();
list.append("default");
QStringList::ConstIterator it = list.begin();
for (it = list.begin(); it != list.end(); it++)
{
QString path( locate("appdata", QString(file) + "-" + *it) );
if (path.length() && read(path.ascii()))
{
return true;
}
}
#else
QStrList list = klocale->languageList();
list.append("default");
QStrListIterator it(list);
for (; it.current(); ++it)
{
QString path = KApplication::localkdedir().copy();
path += "/share/apps/amor/";
path += file + QString("-") + it.current();
if (read(path))
{
return true;
}
path = KApplication::kde_datadir().copy();
path += "/amor/";
path += file + QString("-") + it.current();
if (read(path))
{
return true;
}
}
#endif
return false;
}
//---------------------------------------------------------------------------
//
// Clear all tips from memory
//
amor'AmorTips::reset() (./kdetoys/amor/amortips.cpp:76)
void AmorTips::reset()
{
mTips.clear();
}
//---------------------------------------------------------------------------
//
// Get a tip randomly from the list
//
amor'AmorTips::tip() (./kdetoys/amor/amortips.cpp:85)
const char *AmorTips::tip()
{
if (mTips.count())
{
return mTips.at(kapp->random()%mTips.count());
}
return "No tip";
}
//---------------------------------------------------------------------------
//
// Read all tips from the specified file.
//
amor'AmorTips::read() (./kdetoys/amor/amortips.cpp:99)
bool AmorTips::read(const char *path)
{
QFile file(path);
if (file.open(IO_ReadOnly))
{
while (!file.atEnd())
{
readTip(file);
}
}
return false;
}
//---------------------------------------------------------------------------
//
// Read a single tip.
//
amor'AmorTips::readTip() (./kdetoys/amor/amortips.cpp:118)
bool AmorTips::readTip(QFile &file)
{
char buffer[1024] = "";
QString tip;
while (!file.atEnd() && buffer[0] != '%')
{
file.readLine(buffer, 1024);
if (buffer[0] != '%')
{
tip += buffer;
}
}
if (!tip.isEmpty())
{
if (tip[tip.length()-1] == '\n')
{
tip.truncate(tip.length()-1);
}
mTips.append(tip);
return true;
}
return false;
}