1/* This file is part of the KDE project
2
3 Copyright (C) by Andrew Stanley-Jones <asj@cban.com>
4 Copyright (C) 2000 by Carsten Pfeiffer <pfeiffer@kde.org>
5 Copyright (C) 2004 Esben Mose Hansen <kde@mosehansen.dk>
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22
23#include "tray.h"
24
25#include <KGlobal>
26#include <KLocale>
27#include <KNotification>
28#include <KIcon>
29
30#include "klipper.h"
31#include "history.h"
32#include "klipperpopup.h"
33
34KlipperTray::KlipperTray()
35 : KStatusNotifierItem()
36{
37 setTitle( i18n( "Klipper" ) );
38 setIconByName( "klipper" );
39 setToolTip( "klipper", i18n( "Clipboard Contents" ), i18n( "Clipboard is empty" ) );
40 setCategory( SystemServices );
41 setStatus( Active );
42 setStandardActionsEnabled( false );
43
44 m_klipper = new Klipper( this, KGlobal::config());
45 setContextMenu( m_klipper->history()->popup() );
46 setAssociatedWidget( m_klipper->history()->popup() );
47 connect( m_klipper->history(), SIGNAL(changed()), SLOT(slotSetToolTipFromHistory()));
48 slotSetToolTipFromHistory();
49 connect( m_klipper, SIGNAL(passivePopup(QString,QString)), SLOT(slotPassivePopup(QString,QString)));
50}
51
52void KlipperTray::slotSetToolTipFromHistory()
53{
54 const int TOOLTIP_LENGTH_LIMIT = 200;
55 if (m_klipper->history()->empty()) {
56 setToolTipSubTitle( i18n("Clipboard is empty"));
57 } else {
58 const HistoryItem* top = m_klipper->history()->first();
59 if (top->text().length() <= TOOLTIP_LENGTH_LIMIT) {
60 setToolTipSubTitle(top->text());
61 } else {
62 setToolTipSubTitle(top->text().left(TOOLTIP_LENGTH_LIMIT - 3) + "..." );
63 }
64 }
65}
66
67void KlipperTray::slotPassivePopup(const QString& caption, const QString& text)
68{
69 if (m_notification) {
70 m_notification->setTitle(caption);
71 m_notification->setText(text);
72 } else {
73 m_notification = KNotification::event(KNotification::Notification, caption, text,
74 KIcon("klipper").pixmap(QSize(16, 16)));
75 }
76}
77
78#include "tray.moc"
79