libyui
3.0.10
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: YLogView.h 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 #ifndef YLogView_h 00026 #define YLogView_h 00027 00028 #include "YWidget.h" 00029 00030 class YLogViewPrivate; 00031 00032 00033 /** 00034 * LogView: A scrollable (output-only) text to display a growing log, 00035 * very much like the "tail -f" shell command. 00036 **/ 00037 class YLogView : public YWidget 00038 { 00039 protected: 00040 /** 00041 * Constructor. 00042 * 00043 * 'label' is the caption above the log. 'visibleLines' indicates how many 00044 * lines should be visible by default (unless changed by other layout 00045 * constraints), 'maxLines' specifies how many lines (always the last ones) 00046 * to keep in the log. 0 for 'maxLines' means "keep all lines". 00047 **/ 00048 YLogView( YWidget * parent, 00049 const std::string & label, 00050 int visibleLines, 00051 int maxLines ); 00052 00053 public: 00054 00055 /** 00056 * Destructor. 00057 **/ 00058 virtual ~YLogView(); 00059 00060 /** 00061 * Returns a descriptive name of this widget class for logging, 00062 * debugging etc. 00063 **/ 00064 virtual const char * widgetClass() const { return "YLogView"; } 00065 00066 /** 00067 * Return the label (the caption above the log text). 00068 **/ 00069 std::string label() const; 00070 00071 /** 00072 * Set the label (the caption above the log text). 00073 * 00074 * Derived classes are free to reimplement this, but they should call this 00075 * base class method at the end of the overloaded function. 00076 **/ 00077 virtual void setLabel( const std::string & label ); 00078 00079 /** 00080 * Return the number of visible lines. 00081 **/ 00082 int visibleLines() const; 00083 00084 /** 00085 * Set the number of visible lines. Changing this has only effect upon the 00086 * next geometry call, so applications calling this function might want to 00087 * trigger a re-layout afterwards. 00088 * 00089 * This method is intentionally not virtual: visibleLines() should be 00090 * queried in the preferredHeight() implementation. 00091 **/ 00092 void setVisibleLines( int newVisibleLines ); 00093 00094 /** 00095 * Return the maximum number of lines to store. The last maxLines() lines 00096 * of the log text will be kept. 00097 **/ 00098 int maxLines() const; 00099 00100 /** 00101 * Set the maximum number of lines to store. "0" means "keep all lines" 00102 * (beware of memory overflow!). 00103 * 00104 * If the new value is lower than the old value, any (now) excess lines 00105 * before the last 'newMaxLines' lines of the log text is cut off and a 00106 * display update is triggered. 00107 * 00108 * This method is intentionally not virtual since a display update is 00109 * triggered when appropriate. 00110 **/ 00111 void setMaxLines( int newMaxLines ); 00112 00113 /** 00114 * Return the entire log text as one large string of concatenated lines 00115 * delimited with newlines. 00116 **/ 00117 std::string logText() const; 00118 00119 /** 00120 * Set (replace) the entire log text and trigger a display update. 00121 **/ 00122 void setLogText( const std::string & text ) 00123 { clearText(); appendLines( text ); } 00124 00125 /** 00126 * Return the last log line. 00127 **/ 00128 std::string lastLine() const; 00129 00130 /** 00131 * Append one or more lines to the log text and trigger a display update. 00132 **/ 00133 void appendLines( const std::string & text ); 00134 00135 /** 00136 * Clear the log text and trigger a display update. 00137 **/ 00138 void clearText(); 00139 00140 /** 00141 * Return the current number of lines. 00142 **/ 00143 int lines() const; 00144 00145 /** 00146 * Set a property. 00147 * Reimplemented from YWidget. 00148 * 00149 * This function may throw YUIPropertyExceptions. 00150 * 00151 * This function returns 'true' if the value was successfully set and 00152 * 'false' if that value requires special handling (not in error cases: 00153 * those are covered by exceptions). 00154 **/ 00155 virtual bool setProperty( const std::string & propertyName, 00156 const YPropertyValue & val ); 00157 00158 /** 00159 * Get a property. 00160 * Reimplemented from YWidget. 00161 * 00162 * This method may throw YUIPropertyExceptions. 00163 **/ 00164 virtual YPropertyValue getProperty( const std::string & propertyName ); 00165 00166 /** 00167 * Return this class's property set. 00168 * This also initializes the property upon the first call. 00169 * 00170 * Reimplemented from YWidget. 00171 **/ 00172 virtual const YPropertySet & propertySet(); 00173 00174 /** 00175 * Get the string of this widget that holds the keyboard shortcut. 00176 * 00177 * Reimplemented from YWidget. 00178 **/ 00179 virtual std::string shortcutString() const { return label(); } 00180 00181 /** 00182 * Set the string of this widget that holds the keyboard shortcut. 00183 * 00184 * Reimplemented from YWidget. 00185 **/ 00186 virtual void setShortcutString( const std::string & str ) 00187 { setLabel( str ); } 00188 00189 00190 protected: 00191 00192 /** 00193 * Display the part of the log text that should be displayed. 00194 * 'text' contains the last 'visibleLines()' lines. 00195 * This is called whenever the log text changes. Note that the text might 00196 * also be empty, in which case the displayed log text should be cleared. 00197 * 00198 * Derived classes are required to implement this. 00199 **/ 00200 virtual void displayLogText( const std::string & text ) = 0; 00201 00202 00203 private: 00204 00205 /** 00206 * Append one single line to the log text. 00207 **/ 00208 void appendLine( const std::string & line ); 00209 00210 /** 00211 * Trigger a re-display of the log text. 00212 **/ 00213 void updateDisplay(); 00214 00215 00216 // Data members 00217 00218 ImplPtr<YLogViewPrivate> priv; 00219 00220 }; 00221 00222 00223 #endif // YLogView_h