From a1e5a601845a81a5ce45bb0bf6b224447a99cac7 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sat, 19 Oct 2013 01:11:02 +0200 Subject: [PATCH] CComponentsText: use separated function to get text fro a file --- src/gui/components/cc_item_text.cpp | 18 ++++++++++++++---- src/gui/components/cc_item_text.h | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/gui/components/cc_item_text.cpp b/src/gui/components/cc_item_text.cpp index c0dbd024a..1b5aba9a1 100644 --- a/src/gui/components/cc_item_text.cpp +++ b/src/gui/components/cc_item_text.cpp @@ -199,8 +199,7 @@ void CComponentsText::setText(const int digit, const int mode, Font* font_text) setText(s_digit, mode, font_text); } -//set text lines directly from a file, returns true on succsess -bool CComponentsText::setTextFromFile(const string& path_to_textfile, const int mode, Font* font_text) +string CComponentsText::getTextFromFile(const string& path_to_textfile) { string file = path_to_textfile; string txt = ""; @@ -208,7 +207,7 @@ bool CComponentsText::setTextFromFile(const string& path_to_textfile, const int ifstream in (file.c_str(), ios::in); if (!in){ printf("[CComponentsText] [%s - %d] error while open %s -> %s\n", __FUNCTION__, __LINE__, file.c_str(), strerror(errno)); - return false; + return ""; } string line; @@ -217,8 +216,19 @@ bool CComponentsText::setTextFromFile(const string& path_to_textfile, const int } in.close(); - setText(txt, mode, font_text); + return txt; +} +//set text lines directly from a file, returns true on succsess +bool CComponentsText::setTextFromFile(const string& path_to_textfile, const int mode, Font* font_text) +{ + string txt = getTextFromFile(path_to_textfile); + + if (txt.empty()) + return false; + + setText(txt, mode, font_text); + return true; } diff --git a/src/gui/components/cc_item_text.h b/src/gui/components/cc_item_text.h index 194bd2dfb..e6bf1365e 100644 --- a/src/gui/components/cc_item_text.h +++ b/src/gui/components/cc_item_text.h @@ -118,6 +118,8 @@ class CComponentsText : public CComponentsItem, public CBox virtual void setText(const int digit, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); ///set text directly from a textfile, path as string is required virtual bool setTextFromFile(const std::string& path_to_textfile, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); + ///get text directly from a textfile, path as string is required + virtual std::string getTextFromFile(const std::string& path_to_textfile); ///helper to remove linebreak chars from a string if needed virtual void removeLineBreaks(std::string& str);