libyui  3.4.2
YLogView.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YLogView.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YLogView_h
26 #define YLogView_h
27 
28 #include "YWidget.h"
29 
30 class YLogViewPrivate;
31 
32 
33 /**
34  * LogView: A scrollable (output-only) text to display a growing log,
35  * very much like the "tail -f" shell command.
36  **/
37 class YLogView : public YWidget
38 {
39 protected:
40  /**
41  * Constructor.
42  *
43  * 'label' is the caption above the log. 'visibleLines' indicates how many
44  * lines should be visible by default (unless changed by other layout
45  * constraints), 'maxLines' specifies how many lines (always the last ones)
46  * to keep in the log. 0 for 'maxLines' means "keep all lines".
47  **/
49  const std::string & label,
50  int visibleLines,
51  int maxLines );
52 
53 public:
54 
55  /**
56  * Destructor.
57  **/
58  virtual ~YLogView();
59 
60  /**
61  * Returns a descriptive name of this widget class for logging,
62  * debugging etc.
63  **/
64  virtual const char * widgetClass() const { return "YLogView"; }
65 
66  /**
67  * Return the label (the caption above the log text).
68  **/
69  std::string label() const;
70 
71  /**
72  * Set the label (the caption above the log text).
73  *
74  * Derived classes are free to reimplement this, but they should call this
75  * base class method at the end of the overloaded function.
76  **/
77  virtual void setLabel( const std::string & label );
78 
79  /**
80  * Return the number of visible lines.
81  **/
82  int visibleLines() const;
83 
84  /**
85  * Set the number of visible lines. Changing this has only effect upon the
86  * next geometry call, so applications calling this function might want to
87  * trigger a re-layout afterwards.
88  *
89  * This method is intentionally not virtual: visibleLines() should be
90  * queried in the preferredHeight() implementation.
91  **/
92  void setVisibleLines( int newVisibleLines );
93 
94  /**
95  * Return the maximum number of lines to store. The last maxLines() lines
96  * of the log text will be kept.
97  **/
98  int maxLines() const;
99 
100  /**
101  * Set the maximum number of lines to store. "0" means "keep all lines"
102  * (beware of memory overflow!).
103  *
104  * If the new value is lower than the old value, any (now) excess lines
105  * before the last 'newMaxLines' lines of the log text is cut off and a
106  * display update is triggered.
107  *
108  * This method is intentionally not virtual since a display update is
109  * triggered when appropriate.
110  **/
111  void setMaxLines( int newMaxLines );
112 
113  /**
114  * Return the entire log text as one large string of concatenated lines
115  * delimited with newlines.
116  **/
117  std::string logText() const;
118 
119  /**
120  * Set (replace) the entire log text and trigger a display update.
121  **/
122  void setLogText( const std::string & text );
123 
124  /**
125  * Return the last log line.
126  **/
127  std::string lastLine() const;
128 
129  /**
130  * Append one or more lines to the log text and trigger a display update.
131  **/
132  void appendLines( const std::string & text );
133 
134  /**
135  * Clear the log text and trigger a display update.
136  **/
137  void clearText();
138 
139  /**
140  * Return the current number of lines.
141  **/
142  int lines() const;
143 
144  /**
145  * Set a property.
146  * Reimplemented from YWidget.
147  *
148  * This function may throw YUIPropertyExceptions.
149  *
150  * This function returns 'true' if the value was successfully set and
151  * 'false' if that value requires special handling (not in error cases:
152  * those are covered by exceptions).
153  **/
154  virtual bool setProperty( const std::string & propertyName,
155  const YPropertyValue & val );
156 
157  /**
158  * Get a property.
159  * Reimplemented from YWidget.
160  *
161  * This method may throw YUIPropertyExceptions.
162  **/
163  virtual YPropertyValue getProperty( const std::string & propertyName );
164 
165  /**
166  * Return this class's property set.
167  * This also initializes the property upon the first call.
168  *
169  * Reimplemented from YWidget.
170  **/
171  virtual const YPropertySet & propertySet();
172 
173  /**
174  * Get the string of this widget that holds the keyboard shortcut.
175  *
176  * Reimplemented from YWidget.
177  **/
178  virtual std::string shortcutString() const { return label(); }
179 
180  /**
181  * Set the string of this widget that holds the keyboard shortcut.
182  *
183  * Reimplemented from YWidget.
184  **/
185  virtual void setShortcutString( const std::string & str )
186  { setLabel( str ); }
187 
188 
189 protected:
190 
191  /**
192  * Display the part of the log text that should be displayed.
193  * 'text' contains the last 'visibleLines()' lines.
194  * This is called whenever the log text changes. Note that the text might
195  * also be empty, in which case the displayed log text should be cleared.
196  *
197  * Derived classes are required to implement this.
198  **/
199  virtual void displayLogText( const std::string & text ) = 0;
200 
201 
202 private:
203 
204  /**
205  * Append one single line to the log text.
206  **/
207  void appendLine( const std::string & line );
208 
209  /**
210  * Trigger a re-display of the log text.
211  **/
212  void updateDisplay();
213 
214 
215  // Data members
216 
218 
219 };
220 
221 
222 #endif // YLogView_h
std::string logText() const
Return the entire log text as one large string of concatenated lines delimited with newlines...
Definition: YLogView.cc:125
void appendLines(const std::string &text)
Append one or more lines to the log text and trigger a display update.
Definition: YLogView.cc:161
YLogView(YWidget *parent, const std::string &label, int visibleLines, int maxLines)
Constructor.
Definition: YLogView.cc:58
virtual std::string shortcutString() const
Get the string of this widget that holds the keyboard shortcut.
Definition: YLogView.h:178
Transport class for the value of simple properties.
Definition: YProperty.h:104
void setVisibleLines(int newVisibleLines)
Set the number of visible lines.
Definition: YLogView.cc:97
A set of properties to check names and types against.
Definition: YProperty.h:197
int lines() const
Return the current number of lines.
Definition: YLogView.cc:225
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YLogView.cc:240
YWidget * parent() const
Return this widget&#39;s parent or 0 if it doesn&#39;t have a parent.
Definition: YWidget.cc:269
virtual void setLabel(const std::string &label)
Set the label (the caption above the log text).
Definition: YLogView.cc:83
virtual void setShortcutString(const std::string &str)
Set the string of this widget that holds the keyboard shortcut.
Definition: YLogView.h:185
void setLogText(const std::string &text)
Set (replace) the entire log text and trigger a display update.
Definition: YLogView.cc:205
virtual void displayLogText(const std::string &text)=0
Display the part of the log text that should be displayed.
virtual ~YLogView()
Destructor.
Definition: YLogView.cc:69
std::string lastLine() const
Return the last log line.
Definition: YLogView.cc:151
LogView: A scrollable (output-only) text to display a growing log, very much like the "tail -f" shell...
Definition: YLogView.h:37
int visibleLines() const
Return the number of visible lines.
Definition: YLogView.cc:90
int maxLines() const
Return the maximum number of lines to store.
Definition: YLogView.cc:104
void clearText()
Clear the log text and trigger a display update.
Definition: YLogView.cc:218
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YLogView.cc:266
virtual const char * widgetClass() const
Returns a descriptive name of this widget class for logging, debugging etc.
Definition: YLogView.h:64
std::string label() const
Return the label (the caption above the log text).
Definition: YLogView.cc:76
Abstract base class of all UI widgets.
Definition: YWidget.h:54
void setMaxLines(int newMaxLines)
Set the maximum number of lines to store.
Definition: YLogView.cc:111
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YLogView.cc:285