summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-12-15 22:23:26 +0300
committerAndrei Karas <akaras@inbox.ru>2013-12-15 22:23:26 +0300
commitf03edb38328aa5ddb48e10198621bf2353096440 (patch)
treea7fe17c3e7ceee0f646663d115273852c632e0dd /src
parentd0cdad7bf81a07ba4b2f13c73a65fe1c68bb702f (diff)
downloadplus-f03edb38328aa5ddb48e10198621bf2353096440.tar.gz
plus-f03edb38328aa5ddb48e10198621bf2353096440.tar.bz2
plus-f03edb38328aa5ddb48e10198621bf2353096440.tar.xz
plus-f03edb38328aa5ddb48e10198621bf2353096440.zip
in updater window cut news to 50 lines and show link to full news.
Diffstat (limited to 'src')
-rw-r--r--src/being/being.cpp3
-rw-r--r--src/gui/windows/updaterwindow.cpp34
-rw-r--r--src/gui/windows/updaterwindow.h2
-rw-r--r--src/resources/resourcemanager.cpp9
-rw-r--r--src/resources/resourcemanager.h4
-rw-r--r--src/utils/paths.cpp3
6 files changed, 44 insertions, 11 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 8990ec339..98b83bcf7 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -2848,7 +2848,8 @@ std::string Being::loadComment(const std::string &name, const int type)
const ResourceManager *const resman = ResourceManager::getInstance();
if (resman->existsLocal(str))
{
- lines = resman->loadTextFileLocal(str);
+ StringVect lines;
+ resman->loadTextFileLocal(str, lines);
if (lines.size() >= 2)
return lines[1];
}
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
index 9c9a3adab..36cdba6dd 100644
--- a/src/gui/windows/updaterwindow.cpp
+++ b/src/gui/windows/updaterwindow.cpp
@@ -329,8 +329,11 @@ void UpdaterWindow::loadNews()
std::stringstream ss(mMemoryBuffer);
std::string line;
file.open(newsName.c_str(), std::ios::out);
+ int cnt = 0;
+ const int maxNews = 50;
while (std::getline(ss, line, '\n'))
{
+ cnt ++;
if (firstLine)
{
firstLine = false;
@@ -340,17 +343,25 @@ void UpdaterWindow::loadNews()
if (file.is_open())
file << line << std::endl;
- mBrowserBox->addRow(line);
+ if (cnt < maxNews)
+ mBrowserBox->addRow(line);
}
else
{
if (file.is_open())
file << line << std::endl;
- mBrowserBox->addRow(line);
+ if (cnt < maxNews)
+ mBrowserBox->addRow(line);
}
}
file.close();
+ if (cnt > maxNews)
+ {
+ mBrowserBox->addRow("");
+ mBrowserBox->addRow("news", _("Show all news (can be slow)"));
+ mBrowserBox->addRow("");
+ }
// Free the memory buffer now that we don't need it anymore
free(mMemoryBuffer);
mMemoryBuffer = nullptr;
@@ -944,5 +955,24 @@ void UpdaterWindow::handleLink(const std::string &link,
gcn::MouseEvent *event A_UNUSED)
{
if (strStartWith(link, "http://") || strStartWith(link, "https://"))
+ {
openBrowser(link);
+ }
+ else if (link == "news")
+ {
+ loadFile("news");
+ }
+}
+
+void UpdaterWindow::loadFile(std::string file)
+{
+ mBrowserBox->clearRows();
+ trim(file);
+
+ StringVect lines;
+ ResourceManager::getInstance()->loadTextFileLocal(
+ mUpdatesDir + "/local/help/news.txt", lines);
+
+ for (size_t i = 0, sz = lines.size(); i < sz; ++i)
+ mBrowserBox->addRow(lines[i]);
}
diff --git a/src/gui/windows/updaterwindow.h b/src/gui/windows/updaterwindow.h
index 1f9328908..6003cf976 100644
--- a/src/gui/windows/updaterwindow.h
+++ b/src/gui/windows/updaterwindow.h
@@ -126,6 +126,8 @@ class UpdaterWindow final : public Window,
void handleLink(const std::string &link,
gcn::MouseEvent *event A_UNUSED) override final;
+ void loadFile(std::string file);
+
static void loadLocalUpdates(const std::string &dir);
static void unloadUpdates(const std::string &dir);
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 193647a6e..143cf467e 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -1001,25 +1001,24 @@ bool ResourceManager::loadTextFile(const std::string &fileName,
return true;
}
-StringVect ResourceManager::loadTextFileLocal(
- const std::string &fileName)
+bool ResourceManager::loadTextFileLocal(const std::string &fileName,
+ StringVect &lines)
{
std::ifstream file;
char line[501];
- StringVect lines;
file.open(fileName.c_str(), std::ios::in);
if (!file.is_open())
{
logger->log("Couldn't load text file: %s", fileName.c_str());
- return lines;
+ return false;
}
while (file.getline(line, 500))
lines.push_back(line);
- return lines;
+ return true;
}
void ResourceManager::saveTextFile(std::string path, const std::string &name,
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 88e958245..9fa612e7c 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -268,8 +268,8 @@ class ResourceManager final
/**
* Retrieves the contents of a text file.
*/
- static StringVect loadTextFileLocal(const std::string &fileName)
- A_WARN_UNUSED;
+ static bool loadTextFileLocal(const std::string &fileName,
+ StringVect &lines);
void saveTextFile(std::string path, const std::string &name,
const std::string &text) const;
diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp
index e1a4ee03c..e02fcc23c 100644
--- a/src/utils/paths.cpp
+++ b/src/utils/paths.cpp
@@ -171,7 +171,8 @@ std::string getDesktopDir()
file = std::string(xdg).append("/user-dirs.dirs");
}
- const StringVect arr = ResourceManager::loadTextFileLocal(file);
+ StringVect arr;
+ ResourceManager::loadTextFileLocal(file, arr);
FOR_EACH (StringVectCIter, it, arr)
{
std::string str = *it;