~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to klipper/tray.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

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