Logo Search packages:      
Sourcecode: kbiff version File versions

status.cpp

/*
 * status.cpp
 * Copyright (C) 1999-2002 Kurt Granroth <granroth@kde.org>
 *
 * This file contains the implementation of the KBiffStatus
 * widget
 *
 * $Id: status.cpp,v 1.8 2002/11/08 02:27:03 gran Exp $
 */
#include "status.h"

#include <kapp.h>
#include <klocale.h>

#include <qheader.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlistview.h>
#include <qpoint.h>

KBiffStatus::KBiffStatus(QWidget *parent, const QString& profile, const KBiffStatusList& list)
    : QFrame(parent, 0, WType_Popup),
      _listView(new QListView(this))
{
    setFrameStyle(WinPanel|Raised);
    QLabel *profile_label = new QLabel(profile, this);
    profile_label->setFrameStyle(QFrame::Box | QFrame::Raised);
    profile_label->setAlignment(AlignCenter);

    _listView->addColumn(i18n("Mailbox"));
    _listView->addColumn(i18n("New"));
    _listView->addColumn(i18n("Old"));
    _listView->setColumnAlignment(1, AlignRight);
    _listView->setColumnAlignment(2, AlignRight);
    _listView->setSorting(1, FALSE);
    _listView->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
    _listView->setVScrollBarMode(QScrollView::AlwaysOff);
    _listView->setHScrollBarMode(QScrollView::AlwaysOff);
    _listView->header()->hide();

    updateListView(list);

    int list_height = (_listView->firstChild()->height() * list.count()) + 10;
    _listView->setFixedSize(_listView->sizeHint().width() + 5, list_height);
    resize(_listView->size());

    QVBoxLayout *layout = new QVBoxLayout(this, 0, 0);
    layout->addWidget(profile_label);
    layout->addWidget(_listView);
}

KBiffStatus::~KBiffStatus()
{
}

void KBiffStatus::updateListView(const KBiffStatusList& list)
{
    _listView->clear();
    KBiffStatusListIterator it(list);
    for(it.toFirst(); it.current(); ++it)
    {
        if (it.current()->newMessages() == "-1")
        {
            new QListViewItem(_listView, it.current()->mailbox(),
                              i18n("Disabled"));
        }
        else
        {
             new QListViewItem(_listView, it.current()->mailbox(),
                               it.current()->newMessages(),it.current()->curMessages());
        }
    }
}

void KBiffStatus::popup(const QPoint& pos)
{
    QWidget *desktop = KApplication::desktop();
    int x = pos.x(), y = pos.y();

    // for some reason, the width and height are incorrect until
    // we do the show.  so we show first (after hiding) and move later
    move(-100, -100);
    show();

    // verify that the width is within the desktop
    if ((pos.x() + width()) > desktop->width())
    {
        x = pos.x() - width();
        x = (x < 0) ? 0 : x;
    }

    // verify that that height is within tolerances
    if ((pos.y() + height()) > desktop->height())
    {
        y = pos.y() - height();
        y = (y < 0) ? 0 : y;
    }

    // now that we have *real* co-ordinates, we move to them
    move(x, y);
}

KBiffStatusItem::KBiffStatusItem(const QString& mailbox, const int num_new,const int num_cur)
    : QObject(),
      _mailbox(mailbox),
      _newMessages(QString().setNum(num_new)),
      _curMessages((num_cur==-1)?QString("?"):QString().setNum(num_cur))
{
}
KBiffStatusItem::KBiffStatusItem(const QString& mailbox, const int num_new)
    : QObject(),
      _mailbox(mailbox),
      _newMessages(QString().setNum(num_new)),
      _curMessages(QString("?"))
{
}

KBiffStatusItem::~KBiffStatusItem()
{
}

Generated by  Doxygen 1.6.0   Back to index