| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | 
|---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/biff/biff.doc:4 --> | 
|---|
| 3 | <html> | 
|---|
| 4 | <head> | 
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | 
|---|
| 6 | <title>Biff (UNIX only)</title> | 
|---|
| 7 | <style type="text/css"><!-- | 
|---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; } | 
|---|
| 9 | a:link { color: #004faf; text-decoration: none } | 
|---|
| 10 | a:visited { color: #672967; text-decoration: none } | 
|---|
| 11 | body { background: #ffffff; color: black; } | 
|---|
| 12 | --></style> | 
|---|
| 13 | </head> | 
|---|
| 14 | <body> | 
|---|
| 15 |  | 
|---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%"> | 
|---|
| 17 | <tr bgcolor="#E5E5E5"> | 
|---|
| 18 | <td valign=center> | 
|---|
| 19 | <a href="index.html"> | 
|---|
| 20 | <font color="#004faf">Home</font></a> | 
|---|
| 21 | | <a href="classes.html"> | 
|---|
| 22 | <font color="#004faf">All Classes</font></a> | 
|---|
| 23 | | <a href="mainclasses.html"> | 
|---|
| 24 | <font color="#004faf">Main Classes</font></a> | 
|---|
| 25 | | <a href="annotated.html"> | 
|---|
| 26 | <font color="#004faf">Annotated</font></a> | 
|---|
| 27 | | <a href="groups.html"> | 
|---|
| 28 | <font color="#004faf">Grouped Classes</font></a> | 
|---|
| 29 | | <a href="functions.html"> | 
|---|
| 30 | <font color="#004faf">Functions</font></a> | 
|---|
| 31 | </td> | 
|---|
| 32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Biff (UNIX only)</h1> | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | <p> | 
|---|
| 36 | Biff is a simple graphical program to indicate whether there is new | 
|---|
| 37 | mail; it looks exactly like xbiff but is much shorter. | 
|---|
| 38 | <p> <hr> | 
|---|
| 39 | <p> Header file: | 
|---|
| 40 | <p> <pre>/**************************************************************************** | 
|---|
| 41 | ** $Id: biff-example.html 2051 2007-02-21 10:04:20Z chehrlic $ | 
|---|
| 42 | ** | 
|---|
| 43 | ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved. | 
|---|
| 44 | ** | 
|---|
| 45 | ** This file is part of an example program for Qt.  This example | 
|---|
| 46 | ** program may be used, distributed and modified without limitation. | 
|---|
| 47 | ** | 
|---|
| 48 | *****************************************************************************/ | 
|---|
| 49 |  | 
|---|
| 50 | #ifndef BIFF_H | 
|---|
| 51 | #define BIFF_H | 
|---|
| 52 |  | 
|---|
| 53 | #include <<a href="qwidget-h.html">qwidget.h</a>> | 
|---|
| 54 | #include <<a href="qdatetime-h.html">qdatetime.h</a>> | 
|---|
| 55 | #include <<a href="qpixmap-h.html">qpixmap.h</a>> | 
|---|
| 56 |  | 
|---|
| 57 |  | 
|---|
| 58 | class Biff : public <a href="qwidget.html">QWidget</a> | 
|---|
| 59 | { | 
|---|
| 60 | <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a> | 
|---|
| 61 | public: | 
|---|
| 62 | Biff( <a href="qwidget.html">QWidget</a> *parent=0, const char *name=0 ); | 
|---|
| 63 |  | 
|---|
| 64 | protected: | 
|---|
| 65 | void        timerEvent( <a href="qtimerevent.html">QTimerEvent</a> * ); | 
|---|
| 66 | void        paintEvent( <a href="qpaintevent.html">QPaintEvent</a> * ); | 
|---|
| 67 | void        mousePressEvent( <a href="qmouseevent.html">QMouseEvent</a> * ); | 
|---|
| 68 |  | 
|---|
| 69 | private: | 
|---|
| 70 | <a href="qdatetime.html">QDateTime</a>   lastModified; | 
|---|
| 71 | <a href="qpixmap.html">QPixmap</a>     hasNewMail; | 
|---|
| 72 | <a href="qpixmap.html">QPixmap</a>     noNewMail; | 
|---|
| 73 | <a href="qstring.html">QString</a>     mailbox; | 
|---|
| 74 | bool        gotMail; | 
|---|
| 75 | }; | 
|---|
| 76 |  | 
|---|
| 77 |  | 
|---|
| 78 | #endif // BIFF_H | 
|---|
| 79 | </pre> | 
|---|
| 80 |  | 
|---|
| 81 | <p> <hr> | 
|---|
| 82 | <p> <em>biff.cpp</em> implements this custom widget.  Note in particular | 
|---|
| 83 | how two images (<em>hasmail_bmp_data</em> and <em>nomail_bmp_data</em>, both from | 
|---|
| 84 | <em>bmp.cpp</em>) are included into the executable. | 
|---|
| 85 | <p> <pre>/**************************************************************************** | 
|---|
| 86 | ** $Id: biff-example.html 2051 2007-02-21 10:04:20Z chehrlic $ | 
|---|
| 87 | ** | 
|---|
| 88 | ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved. | 
|---|
| 89 | ** | 
|---|
| 90 | ** This file is part of an example program for Qt.  This example | 
|---|
| 91 | ** program may be used, distributed and modified without limitation. | 
|---|
| 92 | ** | 
|---|
| 93 | *****************************************************************************/ | 
|---|
| 94 |  | 
|---|
| 95 | #include "biff.h" | 
|---|
| 96 | #include <<a href="qstring-h.html">qstring.h</a>> | 
|---|
| 97 | #include <<a href="qfileinfo-h.html">qfileinfo.h</a>> | 
|---|
| 98 | #include <<a href="qpainter-h.html">qpainter.h</a>> | 
|---|
| 99 |  | 
|---|
| 100 | #include <unistd.h> | 
|---|
| 101 | #include <stdlib.h> | 
|---|
| 102 |  | 
|---|
| 103 | #include "bmp.cpp" | 
|---|
| 104 |  | 
|---|
| 105 |  | 
|---|
| 106 | <a name="f527"></a>Biff::Biff( <a href="qwidget.html">QWidget</a> *parent, const char *name ) | 
|---|
| 107 | : <a href="qwidget.html">QWidget</a>( parent, name, WShowModal | WType_Dialog ) | 
|---|
| 108 | { | 
|---|
| 109 | <a href="qfileinfo.html">QFileInfo</a> fi = QString(getenv( "MAIL" )); | 
|---|
| 110 | <a name="x1955"></a>    if ( !fi.<a href="qfileinfo.html#exists">exists</a>() ) { | 
|---|
| 111 | <a href="qstring.html">QString</a> s( "/var/spool/mail/" ); | 
|---|
| 112 | s += getlogin(); | 
|---|
| 113 | <a name="x1958"></a>        fi.<a href="qfileinfo.html#setFile">setFile</a>( s ); | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 | if ( fi.<a href="qfileinfo.html#exists">exists</a>() ) { | 
|---|
| 117 | <a name="x1954"></a>        mailbox = fi.<a href="qfileinfo.html#absFilePath">absFilePath</a>(); | 
|---|
| 118 | <a href="qobject.html#startTimer">startTimer</a>( 1000 ); | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | <a href="qwidget.html#setMinimumSize">setMinimumSize</a>( 48, 48 ); | 
|---|
| 122 | <a href="qwidget.html#setMaximumSize">setMaximumSize</a>( 48, 48 ); | 
|---|
| 123 | <a href="qwidget.html#resize">resize</a>( 48, 48 ); | 
|---|
| 124 |  | 
|---|
| 125 | hasNewMail.loadFromData( hasmail_bmp_data, hasmail_bmp_len ); | 
|---|
| 126 | noNewMail.loadFromData( nomail_bmp_data, nomail_bmp_len ); | 
|---|
| 127 |  | 
|---|
| 128 | gotMail = FALSE; | 
|---|
| 129 | <a name="x1956"></a>    lastModified = fi.<a href="qfileinfo.html#lastModified">lastModified</a>(); | 
|---|
| 130 | } | 
|---|
| 131 |  | 
|---|
| 132 |  | 
|---|
| 133 | <a name="x1959"></a>void Biff::<a href="qobject.html#timerEvent">timerEvent</a>( <a href="qtimerevent.html">QTimerEvent</a> * ) | 
|---|
| 134 | { | 
|---|
| 135 | <a href="qfileinfo.html">QFileInfo</a> fi( mailbox ); | 
|---|
| 136 | bool newState = ( fi.<a href="qfileinfo.html#lastModified">lastModified</a>() != lastModified && | 
|---|
| 137 | <a name="x1957"></a>                      fi.<a href="qfileinfo.html#lastModified">lastModified</a>() > fi.<a href="qfileinfo.html#lastRead">lastRead</a>() ); | 
|---|
| 138 | if ( newState != gotMail ) { | 
|---|
| 139 | if ( gotMail ) | 
|---|
| 140 | lastModified = fi.<a href="qfileinfo.html#lastModified">lastModified</a>(); | 
|---|
| 141 | gotMail = newState; | 
|---|
| 142 | <a href="qwidget.html#repaint">repaint</a>( FALSE ); | 
|---|
| 143 | } | 
|---|
| 144 | } | 
|---|
| 145 |  | 
|---|
| 146 |  | 
|---|
| 147 | void Biff::<a href="qwidget.html#paintEvent">paintEvent</a>( <a href="qpaintevent.html">QPaintEvent</a> * ) | 
|---|
| 148 | { | 
|---|
| 149 | if ( gotMail ) | 
|---|
| 150 | <a href="qimage.html#bitBlt">bitBlt</a>( this, 0, 0, &hasNewMail ); | 
|---|
| 151 | else | 
|---|
| 152 | <a href="qimage.html#bitBlt">bitBlt</a>( this, 0, 0, &noNewMail ); | 
|---|
| 153 | } | 
|---|
| 154 |  | 
|---|
| 155 |  | 
|---|
| 156 | <a name="x1960"></a>void Biff::<a href="qwidget.html#mousePressEvent">mousePressEvent</a>( <a href="qmouseevent.html">QMouseEvent</a> * ) | 
|---|
| 157 | { | 
|---|
| 158 | <a href="qfileinfo.html">QFileInfo</a> fi( mailbox ); | 
|---|
| 159 | lastModified = fi.<a href="qfileinfo.html#lastModified">lastModified</a>(); | 
|---|
| 160 | } | 
|---|
| 161 | </pre> | 
|---|
| 162 |  | 
|---|
| 163 | <p> <hr> | 
|---|
| 164 | <p> Main: | 
|---|
| 165 | <p> <pre>/**************************************************************************** | 
|---|
| 166 | ** $Id: biff-example.html 2051 2007-02-21 10:04:20Z chehrlic $ | 
|---|
| 167 | ** | 
|---|
| 168 | ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved. | 
|---|
| 169 | ** | 
|---|
| 170 | ** This file is part of an example program for Qt.  This example | 
|---|
| 171 | ** program may be used, distributed and modified without limitation. | 
|---|
| 172 | ** | 
|---|
| 173 | *****************************************************************************/ | 
|---|
| 174 |  | 
|---|
| 175 | #include <<a href="qapplication-h.html">qapplication.h</a>> | 
|---|
| 176 | #include "biff.h" | 
|---|
| 177 |  | 
|---|
| 178 |  | 
|---|
| 179 | int main( int argc, char ** argv ) | 
|---|
| 180 | { | 
|---|
| 181 | <a href="qapplication.html">QApplication</a> a( argc, argv ); | 
|---|
| 182 | Biff b; | 
|---|
| 183 | a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &b ); | 
|---|
| 184 | b.<a href="qwidget.html#show">show</a>(); | 
|---|
| 185 | return a.<a href="qapplication.html#exec">exec</a>(); | 
|---|
| 186 | } | 
|---|
| 187 | </pre> | 
|---|
| 188 |  | 
|---|
| 189 | <p>See also <a href="examples.html">Examples</a>. | 
|---|
| 190 |  | 
|---|
| 191 | <!-- eof --> | 
|---|
| 192 | <p><address><hr><div align=center> | 
|---|
| 193 | <table width=100% cellspacing=0 border=0><tr> | 
|---|
| 194 | <td>Copyright © 2007 | 
|---|
| 195 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a> | 
|---|
| 196 | <td align=right><div align=right>Qt 3.3.8</div> | 
|---|
| 197 | </table></div></address></body> | 
|---|
| 198 | </html> | 
|---|