summaryrefslogtreecommitdiffstats
path: root/src/daemon/NotifyWidget.cpp
blob: 482fe8444b7eef897307fb99271fd6d44a27322c (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
/*
 * NotifyWidget.cpp
 *
 * Copyright (C) 2021  Emanoil Kotsev <[email protected]>
 *
 *
 *  This file is part of kdbusnotification.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <kdebug.h>
#include <tdeapplication.h>
#include <tqtimer.h>
#include <tqpixmap.h>

#include "NotifyWidget.h"
#include "NotificationsService.h"

#define FADE_SPEED 5

NotifyWidget::NotifyWidget(TQWidget *parent, const char *name, NotificationsService *ns, TQ_INT32 id )
: TQLabel( parent, name, WStyle_Customize | TQt::WStyle_StaysOnTop | TQt::WStyle_NoBorder),
  mName(TQString(name)), notificationService(ns), mId(id)
{
    // TODO Auto-generated constructor stub
    TQDesktopWidget *d = TQApplication::desktop();
    mPosition=TQPoint(d->width()-50, d->height()-20);
    move(mPosition);
// TODO: give the user an option to configure if he/she wants to have
//    the notification fading away from down to top
//    TQTimer::singleShot(100, this, TQ_SLOT(fadeAway()));
}

NotifyWidget::~NotifyWidget()
{
    if(notificationService)
        delete notificationService;
}

void NotifyWidget::mousePressEvent( TQMouseEvent *e )
{
    if (e->button() == TQMouseEvent::LeftButton)
    {
        // The notification was dismissed by the user.
        notificationService->closeNotifyWidget(mId, 2);
    }
}

void NotifyWidget::timeout()
{
    notificationService->closeNotifyWidget(mId, 1); // The notification expired.
}

void NotifyWidget::fadeAway()
{
    mPosition.setY(mPosition.y()-1);
    move(mPosition);
    TQTimer::singleShot(FADE_SPEED, this, TQ_SLOT(fadeAway()));
}

void NotifyWidget::setAutoMask(bool b)
{
    if (b)
        setBackgroundMode( PaletteForeground );
    else
        setBackgroundMode( PaletteBackground );
    TQWidget::setAutoMask(b);
}

bool NotifyWidget::setIcon(const TQString& icon) {
    mIcon = icon;
    TQPixmap pixmap;
    if ( pixmap.load(mIcon) ) {
        this->setPixmap(pixmap);
    } else {
        tqDebug("Could not load notification icon");
        return false;
    }
    return true;
}

void NotifyWidget::setActions(const TQStringList& actions) {
    mActions = actions;
    // TODO handle actions
}

void NotifyWidget::setHints(const TQMap< TQString, TQT_DBusVariant >& hints) {
    mHints = hints;
    // TODO handle hints
}

void NotifyWidget::setTimeout(TQ_INT32 t) {
    TDEApplication::kApplication()->setTopWidget(this);
    TQTimer::singleShot(t, this, TQ_SLOT(timeout()));
}

#include "NotifyWidget.moc"