返回介绍

Biff (UNIX only)

发布于 2019-10-04 14:57:36 字数 3909 浏览 1067 评论 0 收藏 0

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.0.5   edited Oct 12 2001 $
**
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#ifndef BIFF_H
#define BIFF_H

#include <qwidget.h>
#include <qdatetime.h>
#include <qpixmap.h>


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

protected:
    void        timerEvent( QTimerEvent * );
    void        paintEvent( QPaintEvent * );
    void        mousePressEvent( QMouseEvent * );

private:
    QDateTime   lastModified;
    QPixmap     hasNewMail;
    QPixmap     noNewMail;
    QString     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.0.5   edited Oct 12 2001 $
**
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include "biff.h"
#include <qstring.h>
#include <qfileinfo.h>
#include <qpainter.h>

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

#include "bmp.cpp"


Biff::Biff( QWidget *parent, const char *name )
    : QWidget( parent, name, WType_Modal )
{
    QFileInfo fi = QString(getenv( "MAIL" ));
    if ( !fi.exists() ) {
        QString 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( QTimerEvent * )
{
    QFileInfo 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( QPaintEvent * )
{
    if ( gotMail )
        bitBlt( this, 0, 0, &hasNewMail );
    else
        bitBlt( this, 0, 0, &noNewMail );
}


void Biff::mousePressEvent( QMouseEvent * )
{
    QFileInfo fi( mailbox );
    lastModified = fi.lastModified();
}


Main:

/****************************************************************************
** $Id:  qt/main.cpp   3.0.5   edited Oct 12 2001 $
**
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

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


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

See also Examples.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文