[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/base/plasma/applets
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2008-09-30 22:42:20
Message-ID: 1222814540.361689.8432.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 866458 by aseigo:

pastebin works again.. woo! =)


 M  +1 -1      CMakeLists.txt  
 M  +40 -67    pastebin/pastebin.cpp  
 M  +9 -30     pastebin/pastebin.h  


--- trunk/playground/base/plasma/applets/CMakeLists.txt #866457:866458
@@ -39,7 +39,7 @@
 add_subdirectory(timetracker)
 
 add_subdirectory(moodbar)
-#add_subdirectory(pastebin)
+add_subdirectory(pastebin)
 add_subdirectory(life)
 add_subdirectory(bball)
 add_subdirectory(spacer)
--- trunk/playground/base/plasma/applets/pastebin/pastebin.cpp #866457:866458
@@ -20,107 +20,84 @@
 #include "pastebin.h"
 
 #include <math.h>
+#include <iostream>
 
 #include <QApplication>
-#include <QGraphicsScene>
-#include <QStyleOptionGraphicsItem>
 #include <QCheckBox>
-#include <QPushButton>
-#include <iostream>
+#include <QClipboard>
+#include <QDrag>
+#include <QGraphicsLinearLayout>
+#include <QGraphicsScene>
 #include <QGraphicsSceneDragDropEvent>
 #include <QMimeData>
-#include <QDrag>
+#include <QUrl>
 
 #include <KDebug>
 #include <KLocale>
-#include <KIcon>
-#include <KSharedConfig>
-#include <KTimeZoneWidget>
-#include <KDialog>
-#include <QTime>
-#include <plasma/svg.h>
-#include <plasma/animator.h>
-#include <plasma/theme.h>
+#include <KToolInvocation>
 
 #include <kio/global.h>
 #include <kio/job.h>
-#include <QUrl>
-#include <QClipboard>
 
+#include <plasma/widgets/flash.h>
+#include <plasma/widgets/label.h>
+
 using namespace Plasma;
 
 Pastebin::Pastebin(QObject *parent, const QVariantList &args)
-    : Plasma::Applet(parent, args)
+    : Plasma::Applet(parent, args),
+      m_text(i18n("Drag text here to post to pastebin.ca")),
+      m_apikey("AnGWmLlrReJCCJOUMOMpHViBTFkFZxre")
 {
-    apikey = QByteArray("AnGWmLlrReJCCJOUMOMpHViBTFkFZxre");
     setAcceptDrops(true);
-    m_displayEdit = new Plasma::LineEdit(this);
-    m_displayEdit->setStyled(false);
-    m_displayEdit->setDefaultTextColor(Plasma::Theme::self()->textColor());
-    m_displayEdit->setTextInteractionFlags(Qt::NoTextInteraction);
-    m_text = i18n("Drag text here to post to pastebin.ca");
-    setHandlesChildEvents(true);
-    setContentSize(200,200);
-    QColor textColor = Plasma::Theme::self()->textColor();
-    textColor.setAlpha(200);
-    m_displayEdit->setDefaultTextColor(textColor);
-    m_displayEdit->setHtml(m_text);
-    m_displayEdit->setTextWidth(contentSize().width());
-    m_flash = new Plasma::Flash(this);
-    QColor flashColor = Plasma::Theme::self()->textColor();
-    flashColor.setAlpha(128);
-    m_flash->setColor(flashColor);
-    QFont fnt = qApp->font();
-    fnt.setBold(true);
-    m_flash->setFont(fnt);
-    m_layout = new Plasma::VBoxLayout(this);
-    m_layout->addItem(m_flash);
-    m_layout->addItem(m_displayEdit);
+    m_displayEdit = new Plasma::Label(this);
+    m_displayEdit->setText(m_text);
+    m_displayEdit->setAcceptDrops(false);
+    connect(m_displayEdit, SIGNAL(linkActivated(QString)), this, \
SLOT(openLink(QString))); +    QGraphicsLinearLayout *layout = new \
QGraphicsLinearLayout(Qt::Vertical, this); +    layout->addItem(m_displayEdit);
+    resize(200,200);
 }
 
-QSizeF Pastebin::contentSizeHint() const
+Pastebin::~Pastebin()
 {
-    return QSizeF(contentSize().width(),m_layout->sizeHint().height());
 }
 
-void Pastebin::constraintsEvent(Plasma::Constraints constraints)
-{
-    if (constraints & Plasma::SizeConstraint) {
-        m_displayEdit->setTextWidth(contentSize().width());
-        updateGeometry();
-    }
-}
-
 void Pastebin::readKIOData(KIO::Job *job, const QByteArray &data)
 {
-    Q_UNUSED( job );
-    m_flash->kill();
-    if (data.length() == 0)
+    Q_UNUSED(job);
+
+    if (data.length() == 0) {
         return;
-    kDebug() << data.data();
-    kDebug() << data.data();
+    }
+
+    //kDebug() << data.data();
     QString url(data);
     url.replace("SUCCESS:","");
     url.prepend("http://pastebin.ca/");
-    kDebug() << url;
-    m_text = url;
-    m_displayEdit->setPlainText(m_text);
+    //kDebug() << url;
+    m_text = i18n("Successfully posted to: <a href=\"%1\">%2</a><p>Drag text here to \
post to pastebin.ca", url, url); +    m_displayEdit->setText(m_text);
     QApplication::clipboard()->setText(m_text);
 }
 
+void Pastebin::openLink(const QString &link)
+{
+    KToolInvocation::invokeBrowser(link);
+}
+
 void Pastebin::post(QString content)
 {
-    m_flash->flash(QString("Pasting..."));
+    m_displayEdit->setText("Sending content...");
     QByteArray bytearray = "content=";
     bytearray.append(QUrl::toPercentEncoding(content,"/"));
     bytearray.append("&api=");
-    bytearray.append(apikey);
+    bytearray.append(m_apikey);
     bytearray.append("&description=&type=1&expiry=1%20day&name=");
 
     KIO::TransferJob *a = \
KIO::http_post(KUrl("http://pastebin.ca/quiet-paste.php"),bytearray,KIO::HideProgressInfo);
                
     a->addMetaData("content-type","Content-Type: \
                application/x-www-form-urlencoded");
     connect(a, SIGNAL(data(KIO::Job*, const QByteArray&)), this, \
                SLOT(readKIOData(KIO::Job*, const QByteArray&)));
-    
 }
 
 void Pastebin::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
@@ -137,8 +114,7 @@
 
 void Pastebin::dropEvent(QGraphicsSceneDragDropEvent *event)
 {
-    if (event->mimeData()->objectName()!=QString("Pastebin-applet"))
-    {
+    if (event->mimeData()->objectName() != QString("Pastebin-applet")) {
         m_text = event->mimeData()->text();
         post(m_text);
         event->acceptProposedAction();
@@ -150,14 +126,11 @@
     QMimeData *data = new QMimeData;
     data->setText(m_text);
     data->setObjectName("Pastebin-applet");
-    
+
     QDrag *drag = new QDrag(event->widget());
     drag->setMimeData(data);
     drag->start();
 }
 
-Pastebin::~Pastebin()
-{
-}
-
 #include "pastebin.moc"
+
--- trunk/playground/base/plasma/applets/pastebin/pastebin.h #866457:866458
@@ -20,31 +20,14 @@
 #ifndef PASTEBIN_H
 #define PASTEBIN_H
 
-#include <QTimer>
-#include <QTime>
-#include <QGraphicsItem>
-#include <QTextEdit>
-#include <QHttp>
-
 #include <KDE/KIO/TransferJob>
 #include <KDE/KIO/Job>
 
 #include <plasma/applet.h>
-#include <plasma/dataengine.h>
-#include <plasma/layouts/vboxlayout.h>
-#include <plasma/widgets/lineedit.h>
-#include <plasma/widgets/flash.h>
-#include <plasma/widgets/pushbutton.h>
 
-class QTimer;
-class QLineEdit;
-
-
-class KDialog;
-
 namespace Plasma
 {
-    class Svg;
+    class Label;
 }
 
 class Pastebin : public Plasma::Applet
@@ -55,29 +38,25 @@
         ~Pastebin();
 
         void setPath(const QString&);
-        QSizeF contentSizeHint() const;
-        
-        void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
-        void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
-        void dropEvent(QGraphicsSceneDragDropEvent *event);
-        void mousePressEvent(QGraphicsSceneMouseEvent *event);
 
     public slots:
 
     protected slots:
         void readKIOData(KIO::Job *job, const QByteArray &data);
+        void openLink(const QString &link);
 
     protected:
-        void constraintsEvent(Plasma::Constraints);
+        void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
+        void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
+        void dropEvent(QGraphicsSceneDragDropEvent *event);
+        void mousePressEvent(QGraphicsSceneMouseEvent *event);
 
     private:
         void post(QString content);
-        
-        Plasma::LineEdit *m_displayEdit;
-        Plasma::Flash *m_flash;
+
+        Plasma::Label *m_displayEdit;
         QString m_text;
-        QByteArray apikey;
-        Plasma::VBoxLayout *m_layout;
+        const QByteArray m_apikey;
 };
 
 K_EXPORT_PLASMA_APPLET(pastebin, Pastebin)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic