libyui  3.0.5
 All Classes Functions Variables Enumerations Friends
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  { clearText(); appendLines( text ); }
124 
125  /**
126  * Return the last log line.
127  **/
128  std::string lastLine() const;
129 
130  /**
131  * Append one or more lines to the log text and trigger a display update.
132  **/
133  void appendLines( const std::string & text );
134 
135  /**
136  * Clear the log text and trigger a display update.
137  **/
138  void clearText();
139 
140  /**
141  * Return the current number of lines.
142  **/
143  int lines() const;
144 
145  /**
146  * Set a property.
147  * Reimplemented from YWidget.
148  *
149  * This function may throw YUIPropertyExceptions.
150  *
151  * This function returns 'true' if the value was successfully set and
152  * 'false' if that value requires special handling (not in error cases:
153  * those are covered by exceptions).
154  **/
155  virtual bool setProperty( const std::string & propertyName,
156  const YPropertyValue & val );
157 
158  /**
159  * Get a property.
160  * Reimplemented from YWidget.
161  *
162  * This method may throw YUIPropertyExceptions.
163  **/
164  virtual YPropertyValue getProperty( const std::string & propertyName );
165 
166  /**
167  * Return this class's property set.
168  * This also initializes the property upon the first call.
169  *
170  * Reimplemented from YWidget.
171  **/
172  virtual const YPropertySet & propertySet();
173 
174  /**
175  * Get the string of this widget that holds the keyboard shortcut.
176  *
177  * Reimplemented from YWidget.
178  **/
179  virtual std::string shortcutString() const { return label(); }
180 
181  /**
182  * Set the string of this widget that holds the keyboard shortcut.
183  *
184  * Reimplemented from YWidget.
185  **/
186  virtual void setShortcutString( const std::string & str )
187  { setLabel( str ); }
188 
189 
190 protected:
191 
192  /**
193  * Display the part of the log text that should be displayed.
194  * 'text' contains the last 'visibleLines()' lines.
195  * This is called whenever the log text changes. Note that the text might
196  * also be empty, in which case the displayed log text should be cleared.
197  *
198  * Derived classes are required to implement this.
199  **/
200  virtual void displayLogText( const std::string & text ) = 0;
201 
202 
203 private:
204 
205  /**
206  * Append one single line to the log text.
207  **/
208  void appendLine( const std::string & line );
209 
210  /**
211  * Trigger a re-display of the log text.
212  **/
213  void updateDisplay();
214 
215 
216  // Data members
217 
219 
220 };
221 
222 
223 #endif // YLogView_h