summaryrefslogtreecommitdiffstats
path: root/kbiff/status.cpp
blob: f7528989f7be4c1c4472ad431d4a90c22774177b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * status.cpp
 * Copyright (C) 1999-2008 Kurt Granroth <granroth@kde.org>
 *
 * This file contains the implementation of the KBiffStatus
 * widget
 */
#include "status.h"
#include "status.moc"

#include <kapp.h>
#include <tdelocale.h>

#include <ntqdesktopwidget.h>
#include <ntqpoint.h>
#include <ntqrect.h>

#include <ntqheader.h>
#include <ntqlabel.h>
#include <ntqlayout.h>
#include <ntqlistview.h>
#include <ntqpoint.h>

KBiffStatus::KBiffStatus(TQWidget *parent_, const TQString& profile, const KBiffStatusList& list)
    : TQFrame(parent_, 0, WType_Popup),
      _listView(new TQListView(this))
{
    setFrameStyle(WinPanel|Raised);
    TQLabel *profile_label = new TQLabel(profile, this);
    profile_label->setFrameStyle(TQFrame::Box | TQFrame::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(TQFrame::WinPanel | TQFrame::Raised);
    _listView->setVScrollBarMode(TQScrollView::AlwaysOff);
    _listView->setHScrollBarMode(TQScrollView::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());

    TQVBoxLayout *blayout = new TQVBoxLayout(this, 0, 0);
    blayout->addWidget(profile_label);
    blayout->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 TQListViewItem(_listView, it.current()->mailbox(),
                              i18n("Disabled"));
        }
        else
        {
             new TQListViewItem(_listView, it.current()->mailbox(),
                               it.current()->newMessages(),it.current()->curMessages());
        }
    }
}

void KBiffStatus::popup(const TQPoint& pos_)
{
    TQDesktopWidget *desktop = TDEApplication::desktop();
    int cx = pos_.x(), cy = 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 (desktop->isVirtualDesktop())
    {
	TQRect scn = desktop->screenGeometry(TQPoint(cx, cy));
	
	if ((pos_.x() + width()) > (scn.x() + scn.width()))
        {
	    cx = (scn.x() + scn.width()) - width();
            cx = (cx < 0) ? 0 : cx;
        }
    }   
    else
    {
        if ((pos_.x() + width()) > desktop->width())
	{
	    cx = pos_.x() - width();
	    cx = (cx < 0) ? 0 : cx;
        }
    }

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

    // now that we have *real* co-ordinates, we move to them
    move(cx, cy+1);
}

KBiffStatusItem::KBiffStatusItem(const TQString& mailbox_, const int num_new,const int num_cur)
    : TQObject(),
      _mailbox(mailbox_),
      _newMessages(TQString().setNum(num_new)),
      _curMessages((num_cur==-1)?TQString("?"):TQString().setNum(num_cur))
{
}
KBiffStatusItem::KBiffStatusItem(const TQString& mailbox_, const int num_new)
    : TQObject(),
      _mailbox(mailbox_),
      _newMessages(TQString().setNum(num_new)),
      _curMessages(TQString("?"))
{
}

KBiffStatusItem::~KBiffStatusItem()
{
}