Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# Biff (UNIX only)

Biff is a simple graphical program to indicate whether there is new mail; it looks exactly like xbiff but is much shorter.

Header file:

    /****************************************************************************
    ** $Id: qt/biff.h   3.3.8   edited Jan 11 14:37 $
    **
    ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
    **
    ** This file is part of an example program for TQt.  This example
    ** program may be used, distributed and modified without limitation.
    **
    *****************************************************************************/

    #ifndef BIFF_H
    #define BIFF_H

    #include <tqwidget.h>
    #include <tqdatetime.h>
    #include <tqpixmap.h>

    class Biff : public TQWidget
    {
        TQ_OBJECT
    public:
        Biff( TQWidget *parent=0, const char *name=0 );

    protected:
        void        timerEvent( TQTimerEvent * );
        void        paintEvent( TQPaintEvent * );
        void        mousePressEvent( TQMouseEvent * );

    private:
        TQDateTime   lastModified;
        TQPixmap     hasNewMail;
        TQPixmap     noNewMail;
        TQString     mailbox;
        bool        gotMail;
    };

    #endif // BIFF_H

biff.cpp implements this custom widget. Note in particular how two images (hasmail_bmp_data and nomail_bmp_data, both from bmp.cpp) are included into the executable.

    /****************************************************************************
    ** $Id: qt/biff.cpp   3.3.8   edited Jan 11 14:37 $
    **
    ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
    **
    ** This file is part of an example program for TQt.  This example
    ** program may be used, distributed and modified without limitation.
    **
    *****************************************************************************/

    #include "biff.h"
    #include <tqstring.h>
    #include <tqfileinfo.h>
    #include <tqpainter.h>

    #include <unistd.h>
    #include <stdlib.h>

    #include "bmp.cpp"

    Biff::Biff( TQWidget *parent, const char *name )
        : TQWidget( parent, name, WShowModal | WType_Dialog )
    {
        TQFileInfo fi = TQString(getenv( "MAIL" ));
        if ( !fi.exists() ) {
            TQString s( "/var/spool/mail/" );
            s += getlogin();
            fi.setFile( s );
        }

        if ( fi.exists() ) {
            mailbox = fi.absFilePath();
            startTimer( 1000 );
        }

        setMinimumSize( 48, 48 );
        setMaximumSize( 48, 48 );
        resize( 48, 48 );

        hasNewMail.loadFromData( hasmail_bmp_data, hasmail_bmp_len );
        noNewMail.loadFromData( nomail_bmp_data, nomail_bmp_len );

        gotMail = false;
        lastModified = fi.lastModified();
    }

    void Biff::timerEvent( TQTimerEvent * )
    {
        TQFileInfo fi( mailbox );
        bool newState = ( fi.lastModified() != lastModified &&
                          fi.lastModified() > fi.lastRead() );
        if ( newState != gotMail ) {
            if ( gotMail )
                lastModified = fi.lastModified();
            gotMail = newState;
            repaint( false );
        }
    }

    void Biff::paintEvent( TQPaintEvent * )
    {
        if ( gotMail )
            bitBlt( this, 0, 0, &hasNewMail );
        else
            bitBlt( this, 0, 0, &noNewMail );
    }

    void Biff::mousePressEvent( TQMouseEvent * )
    {
        TQFileInfo fi( mailbox );
        lastModified = fi.lastModified();
    }

Main:

    /****************************************************************************
    ** $Id: qt/main.cpp   3.3.8   edited Jan 11 14:37 $
    **
    ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
    **
    ** This file is part of an example program for TQt.  This example
    ** program may be used, distributed and modified without limitation.
    **
    *****************************************************************************/

    #include <tqapplication.h>
    #include "biff.h"

    int main( int argc, char ** argv )
    {
        TQApplication a( argc, argv );
        Biff b;
        a.setMainWidget( &b );
        b.show();
        return a.exec();
    }

See also Examples.