summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-07-15 23:43:22 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-07-15 23:43:22 +0000
commit9cea91975451a7abb6f15e08f7fb6c20efed152c (patch)
treeddf2aaf22597d8fa63a33dd62a57cb50e083f7e3 /src/gui
parent97cac06ae12026f4be3765f68b0aea3caf02d8f0 (diff)
downloadmana-9cea91975451a7abb6f15e08f7fb6c20efed152c.tar.gz
mana-9cea91975451a7abb6f15e08f7fb6c20efed152c.tar.bz2
mana-9cea91975451a7abb6f15e08f7fb6c20efed152c.tar.xz
mana-9cea91975451a7abb6f15e08f7fb6c20efed152c.zip
Fixed compiler warnings and added plain text file loading to resource manager.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/help.cpp24
-rw-r--r--src/gui/updatewindow.cpp21
2 files changed, 10 insertions, 35 deletions
diff --git a/src/gui/help.cpp b/src/gui/help.cpp
index cff36da8..3ff8f0f4 100644
--- a/src/gui/help.cpp
+++ b/src/gui/help.cpp
@@ -87,27 +87,11 @@ void HelpWindow::loadHelp(const std::string &helpFile)
void HelpWindow::loadFile(const std::string &file)
{
ResourceManager *resman = ResourceManager::getInstance();
- const std::string filePath = "help/" + file + ".txt";
- int contentsLength;
- char *fileContents = (char*)resman->loadFile(filePath, contentsLength);
+ std::vector<std::string> lines =
+ resman->loadTextFile("help/" + file + ".txt");
- if (!fileContents)
+ for (unsigned int i = 0; i < lines.size(); ++i)
{
- logger->log("Couldn't load help file: %s", filePath.c_str());
- return;
+ browserBox->addRow(lines[i]);
}
-
- // Reallocate and include terminating 0 character
- fileContents = (char*)realloc(fileContents, contentsLength + 1);
- fileContents[contentsLength] = '\0';
-
- // Tokenize and add each line separately
- char *line = strtok(fileContents, "\n");
- while (line != NULL)
- {
- browserBox->addRow(line);
- line = strtok(NULL, "\n");
- }
-
- free(fileContents);
}
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 75f94b4b..473cc171 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -127,25 +127,16 @@ void UpdaterWindow::action(const std::string& eventId)
void UpdaterWindow::loadNews()
{
- browserBox->clearRows();
ResourceManager *resman = ResourceManager::getInstance();
- int contentsLength;
- std::ifstream newsFile(TMW_DATADIR "data/news.txt");
- if (!newsFile.is_open())
- {
- logger->log("Couldn't load news.txt");
- browserBox->addRow("Error");
- return;
- }
+ std::vector<std::string> lines = resman->loadTextFile("news.txt");
- // Tokenize and add each line separately
- std::string line("");
- while (!newsFile.eof())
+ browserBox->clearRows();
+
+ for (unsigned int i = 0; i < lines.size(); ++i)
{
- getline(newsFile, line);
- browserBox->addRow(line);
+ browserBox->addRow(lines[i]);
}
- newsFile.close();
+
scrollArea->setVerticalScrollAmount(0);
setVisible(true);
}