[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdeplasma-addons/applets/pastebin
From: Danilo Cesar <danilo.eu () gmail ! com>
Date: 2009-03-31 20:06:28
Message-ID: 1238529988.280739.20379.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 947581 by danilocesar:
Adding history support to pastebin plasmoid
M +45 -9 pastebin.cpp
M +12 -0 pastebin.h
--- trunk/KDE/kdeplasma-addons/applets/pastebin/pastebin.cpp #947580:947581
@@ -32,6 +32,7 @@
#include <QBuffer>
#include <QPainter>
#include <QPaintEngine>
+#include <QSignalMapper>
#include <KAction>
#include <KDebug>
@@ -51,7 +52,9 @@
Pastebin::Pastebin(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args), m_graphicsWidget(0), m_textServer(0),
- m_imageServer(0), m_textBackend(0), m_imageBackend(0)
+ m_imageServer(0), m_textBackend(0), m_imageBackend(0),
+ m_paste(0), m_topSeparator(0), m_bottomSeparator(0),
+ m_signalMapper(new QSignalMapper())
{
setAcceptDrops(true);
setHasConfigurationInterface(true);
@@ -60,6 +63,9 @@
resize(150, 150);
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showErrors()));
+
+ connect(m_signalMapper, SIGNAL(mapped(const QString &)),
+ this, SLOT(copyToClipboard(const QString &)));
}
Pastebin::~Pastebin()
@@ -467,6 +473,8 @@
m_url = url;
setActionState(IdleSuccess);
copyToClipboard(url);
+
+ addToHistory(url);
}
void Pastebin::copyToClipboard(const QString &url)
@@ -564,18 +572,46 @@
}
}
+void Pastebin::addToHistory(const QString &url)
+{
+ if (m_actionHistory.size() >= MAX_HISTORY) {
+ delete m_actionHistory.takeFirst();
+ }
+
+ QAction *ac = new QAction(url, this);
+ m_actionHistory.append(ac);
+ m_signalMapper->setMapping(ac, url);
+ connect(ac, SIGNAL(triggered(bool)), m_signalMapper, SLOT(map()));
+}
+
QList<QAction*> Pastebin::contextualActions()
{
- if (m_contextualActions.isEmpty()){
- KAction *paste = KStandardAction::paste(this);
- connect(paste, SIGNAL(triggered(bool)), this, SLOT(postClipboard()));
- m_contextualActions.append(paste);
-
- QAction *separator = new QAction(this);
- separator->setSeparator(true);
- m_contextualActions.append(separator);
+ if (!m_paste) {
+ m_paste = KStandardAction::paste(this);
+ connect(m_paste, SIGNAL(triggered(bool)), this, SLOT(postClipboard()));
}
+ if (!m_topSeparator) {
+ m_topSeparator = new QAction(this);
+ m_topSeparator->setSeparator(true);
+ }
+ if (!m_bottomSeparator) {
+ m_bottomSeparator = new QAction(this);
+ m_bottomSeparator->setSeparator(true);
+ }
+ m_contextualActions.clear();
+
+ m_contextualActions.append(m_paste);
+ m_contextualActions.append(m_topSeparator);
+
+ foreach(QAction *ac, m_actionHistory) {
+ m_contextualActions.append(ac);
+ }
+
+ if (!m_actionHistory.isEmpty()) {
+ m_contextualActions.append(m_bottomSeparator);
+ }
+
return m_contextualActions;
}
--- trunk/KDE/kdeplasma-addons/applets/pastebin/pastebin.h #947580:947581
@@ -20,6 +20,9 @@
#ifndef PASTEBIN_H
#define PASTEBIN_H
+//XXX It would be better to replace this by a KConfig
+#define MAX_HISTORY 3
+
#include "backends/backends.h"
#include "ui_pastebinConfig.h"
#include "ui_pastebinServersConfig.h"
@@ -34,6 +37,8 @@
#include <QTimer>
#include <QPen>
+class QSignalMapper;
+class KAction;
class Pastebin : public Plasma::Applet
{
@@ -105,6 +110,8 @@
void showOverlay(bool show);
void postContent(QString text, QImage imageData);
+ void addToHistory(const QString &url);
+
void setInteractionState(InteractionState state);
void setActionState(ActionState state);
@@ -134,7 +141,12 @@
QTimer *timer;
+ QSignalMapper *m_signalMapper;
QList<QAction *> m_contextualActions;
+ QList<QAction *> m_actionHistory;
+ KAction *m_paste;
+ QAction *m_topSeparator;
+ QAction *m_bottomSeparator;
Ui::pastebinConfig uiConfig;
Ui::pastebinServersConfig uiServers;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic