30 #include <QtGui/QClipboard>
31 #include <QtDBus/QtDBus>
40 class KPasteTextActionPrivate
48 ~KPasteTextActionPrivate()
53 void _k_menuAboutToShow();
54 void _k_slotTriggered(
QAction*);
64 :
KAction(parent), d(new KPasteTextActionPrivate(this))
70 :
KAction(parent), d(new KPasteTextActionPrivate(this))
77 :
KAction(icon, text, parent), d(new KPasteTextActionPrivate(this))
82 void KPasteTextActionPrivate::init()
85 q->connect(m_popup, SIGNAL(aboutToShow()), q, SLOT(_k_menuAboutToShow()));
86 q->connect(m_popup, SIGNAL(triggered(
QAction*)), q, SLOT(_k_slotTriggered(
QAction*)));
97 d->m_mixedMode = mode;
100 void KPasteTextActionPrivate::_k_menuAboutToShow()
104 QDBusInterface klipper(
"org.kde.klipper",
"/klipper",
"org.kde.klipper.klipper");
105 if (klipper.isValid()) {
106 QDBusReply<QStringList> reply = klipper.call(
"getClipboardHistoryMenu");
110 QString clipboardText = qApp->clipboard()->text(QClipboard::Clipboard);
112 list << clipboardText;
114 const QFontMetrics fm = m_popup->fontMetrics();
115 foreach (
const QString&
string, list)
117 QString text = fm.elidedText(
string.simplified(), Qt::ElideMiddle, fm.maxWidth() * 20);
118 text.replace(
'&',
"&&");
119 QAction* action = m_popup->addAction(text);
120 if (!found &&
string == clipboardText)
122 action->setChecked(
true);
128 void KPasteTextActionPrivate::_k_slotTriggered(
QAction* action)
130 QDBusInterface klipper(
"org.kde.klipper",
"/klipper",
"org.kde.klipper.klipper");
131 if (klipper.isValid()) {
132 QDBusReply<QString> reply = klipper.call(
"getClipboardHistoryItem",
133 m_popup->actions().indexOf(action));
134 if (!reply.isValid())
137 reply = klipper.call(
"setClipboardContents", clipboardText);
139 kDebug(129) <<
"Clipboard: " << qApp->clipboard()->text(QClipboard::Clipboard);
146 #include "kpastetextaction.moc"
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
void setMixedMode(bool mode)
Controls the behavior of the clipboard history menu popup.
A wrapper around QIcon that provides KDE icon features.
virtual ~KPasteTextAction()
An action for pasting text from the clipboard.
Class to encapsulate user-driven action or event.
KPasteTextAction(QObject *parent)
Constructs an action with the specified parent.