Revision
14616
Author
jmesquita
Date
2009-08-24 02:03:42 -0500 (Mon, 24 Aug 2009)

Log Message

Add the ability to pastebin logs directly to pastebin.freeswitch.org

Modified Paths

Added Paths

Diff

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/centralWidget.ui (14615 => 14616)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/centralWidget.ui	2009-08-24 06:02:56 UTC (rev 14615)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/centralWidget.ui	2009-08-24 07:03:42 UTC (rev 14616)
@@ -79,6 +79,7 @@
      <string>&amp;Console</string>
     </property>
     <addaction name="actionRealtime_Statistics"/>
+    <addaction name="action_Pastebin_Log"/>
    </widget>
    <addaction name="menu_File"/>
    <addaction name="menu_Edit"/>
@@ -93,6 +94,9 @@
    <property name="text">
     <string>&amp;Connect</string>
    </property>
+   <property name="shortcut">
+    <string>Ctrl+C</string>
+   </property>
   </action>
   <action name="action_Disconnect">
    <property name="enabled">
@@ -101,6 +105,9 @@
    <property name="text">
     <string>&amp;Disconnect</string>
    </property>
+   <property name="shortcut">
+    <string>Ctrl+D</string>
+   </property>
   </action>
   <action name="action_Close">
    <property name="text">
@@ -114,33 +121,36 @@
    <property name="text">
     <string>&amp;Server Manager</string>
    </property>
+   <property name="shortcut">
+    <string>F4</string>
+   </property>
   </action>
   <action name="action_Clear">
    <property name="text">
     <string>&amp;Clear</string>
    </property>
   </action>
-  <action name="actionAutomatic_Scroll">
-   <property name="checkable">
-    <bool>true</bool>
-   </property>
-   <property name="checked">
-    <bool>true</bool>
-   </property>
-   <property name="text">
-    <string>&amp;Automatic Scroll</string>
-   </property>
-  </action>
   <action name="actionRealtime_Statistics">
    <property name="text">
     <string>Realtime &amp;Statistics</string>
    </property>
+   <property name="shortcut">
+    <string>F5</string>
+   </property>
   </action>
   <action name="action_Save_log">
    <property name="text">
     <string>&amp;Save log</string>
    </property>
+   <property name="shortcut">
+    <string>Ctrl+S</string>
+   </property>
   </action>
+  <action name="action_Pastebin_Log">
+   <property name="text">
+    <string>&amp;Pastebin Log</string>
+   </property>
+  </action>
  </widget>
  <resources>
   <include location="../../resources/resources.qrc"/>

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.cpp (14615 => 14616)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.cpp	2009-08-24 06:02:56 UTC (rev 14615)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.cpp	2009-08-24 07:03:42 UTC (rev 14616)
@@ -31,6 +31,8 @@
                      this, SLOT(saveLogToFile()));
     QObject::connect(consoleWindow->actionRealtime_Statistics, SIGNAL(triggered()),
                      this, SLOT(showRealtimeStats()));
+    QObject::connect(consoleWindow->action_Pastebin_Log, SIGNAL(triggered()),
+                     this, SLOT(pastebinLog()));
 }
 
 ConsolePlugin::~ConsolePlugin(){}
@@ -174,6 +176,13 @@
         tab->saveLogToFile();
 }
 
+void ConsolePlugin::pastebinLog()
+{
+    ConsoleTabWidget *tab = qobject_cast<ConsoleTabWidget*>(consoleWindow->tabConsole->currentWidget());
+    if (tab)
+        tab->pastebinLog();
+}
+
 void ConsolePlugin::showRealtimeStats()
 {
     ConsoleTabWidget *tab = qobject_cast<ConsoleTabWidget*>(consoleWindow->tabConsole->currentWidget());

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.h (14615 => 14616)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.h	2009-08-24 06:02:56 UTC (rev 14615)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.h	2009-08-24 07:03:42 UTC (rev 14616)
@@ -76,6 +76,7 @@
     void newConnection();
     void clearLogContents();
     void saveLogToFile();
+    void pastebinLog();
     void showRealtimeStats();
     void changeConsoleBackgroundColor();
     void changeAlertBackgroundColor();

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.pro (14615 => 14616)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.pro	2009-08-24 06:02:56 UTC (rev 14615)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.pro	2009-08-24 07:03:42 UTC (rev 14616)
@@ -19,6 +19,7 @@
 win32:INCLUDEPATH += ../../../../../src/include/
 
 # #####################################
+QT += network
 TEMPLATE = lib
 TARGET = consoleplugin
 DESTDIR = ../../../bin/plugins/
@@ -30,16 +31,19 @@
     sortfilterproxymodel.h \
     consoletabwidget.h \
     realtimestatisticsdialog.h \
-    realtimemodels.h
+    realtimemodels.h \
+    pastebindialog.h
 SOURCES = consoleplugin.cpp \
     sortfilterproxymodel.cpp \
     consoletabwidget.cpp \
     realtimestatisticsdialog.cpp \
-    realtimemodels.cpp
+    realtimemodels.cpp \
+    pastebindialog.cpp
 FORMS += centralWidget.ui \
     console_settings.ui \
     consoletabwidget.ui \
-    realtimestatisticsdialog.ui
+    realtimestatisticsdialog.ui \
+    pastebindialog.ui
 LIBS += -L../../interfaces \
     -linterfaces \
     -L../../../../../../libs/esl/ \

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.cpp (14615 => 14616)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.cpp	2009-08-24 06:02:56 UTC (rev 14615)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.cpp	2009-08-24 07:03:42 UTC (rev 14616)
@@ -3,12 +3,14 @@
 #include "eslconnection.h"
 #include "monitorstatemachine.h"
 #include "realtimestatisticsdialog.h"
+#include "pastebindialog.h"
 
 ConsoleTabWidget::ConsoleTabWidget(QWidget *parent, ESLconnection *eslconnection) :
     QWidget(parent),
     m_ui(new Ui::ConsoleTabWidget),
     esl(eslconnection),
     _rtStatsDlg(NULL),
+    _pastebinDlg(NULL),
     findNext(false)
 {
     m_ui->setupUi(this);
@@ -354,3 +356,19 @@
     }
     QApplication::restoreOverrideCursor();
 }
+
+void ConsoleTabWidget::pastebinLog()
+{
+    QString text;
+    foreach(QStandardItem *item, sourceModel->modelData())
+    {
+        text.append(item->data(Qt::DisplayRole).toString());
+        text.append("\n");
+    }
+    if (!_pastebinDlg)
+        _pastebinDlg = new pastebinDialog;
+    _pastebinDlg->setText(text);
+    _pastebinDlg->show();
+    _pastebinDlg->raise();
+    _pastebinDlg->activateWindow();
+}

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.h (14615 => 14616)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.h	2009-08-24 06:02:56 UTC (rev 14615)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.h	2009-08-24 07:03:42 UTC (rev 14616)
@@ -52,6 +52,7 @@
 class ESLconnection;
 class MonitorStateMachine;
 class RealtimeStatisticsDialog;
+class pastebinDialog;
 
 class ConsoleTabWidget : public QWidget {
     Q_OBJECT
@@ -63,6 +64,7 @@
     void clearConsoleContents();
     void showRealtimeStats();
     void saveLogToFile();
+    void pastebinLog();
     void filterLogUUID(QString);
 
 protected:
@@ -97,6 +99,7 @@
     ESLconnection *esl;
     MonitorStateMachine *msm;
     RealtimeStatisticsDialog *_rtStatsDlg;
+    pastebinDialog *_pastebinDlg;
     bool findNext;
     bool autoScroll;
     int currentLogLevel;

Added: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/pastebindialog.cpp (0 => 14616)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/pastebindialog.cpp	                        (rev 0)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/pastebindialog.cpp	2009-08-24 07:03:42 UTC (rev 14616)
@@ -0,0 +1,127 @@
+#include <QtGui>
+#include <QtNetwork>
+#include "pastebindialog.h"
+#include "ui_pastebindialog.h"
+
+pastebinDialog::pastebinDialog(QWidget *parent) :
+    QDialog(parent),
+    m_ui(new Ui::pastebinDialog),
+    progressDialog(new QProgressDialog(this))
+{
+    m_ui->setupUi(this);
+
+    connect(this, SIGNAL(accepted()),
+            this, SLOT(pasteIt()));
+}
+
+pastebinDialog::~pastebinDialog()
+{
+    delete m_ui;
+}
+
+void pastebinDialog::changeEvent(QEvent *e)
+{
+    QDialog::changeEvent(e);
+    switch (e->type()) {
+    case QEvent::LanguageChange:
+        m_ui->retranslateUi(this);
+        break;
+    default:
+        break;
+    }
+}
+void pastebinDialog::pasteIt()
+{
+
+    pastebinHttp = new QHttp(this);
+
+    /* TODO: Make a progress thing? */
+    connect(pastebinHttp, SIGNAL(requestFinished(int,bool)),
+            this, SLOT(pastebinFinished(int,bool)));
+     connect(pastebinHttp, SIGNAL(dataSendProgress(int, int)),
+             this, SLOT(updateDataSendProgress(int, int)));
+     connect(pastebinHttp, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
+             this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
+
+    QHttpRequestHeader header( "POST",  "/pastebin.php") ;
+    header.setValue( "Host", "pastebin.freeswitch.org" ) ;
+    header.setContentType( "application/x-www-form-urlencoded" ) ;
+
+    pastebinHttp->setHost(m_ui->lineURL->text(), QHttp::ConnectionModeHttp, m_ui->linePort->text().toInt());
+    pastebinHttp->setUser(m_ui->lineUsername->text(), m_ui->linePassword->text());
+    header.setValue( "User-Agent", "FsGUI");
+    QString params = QString("parent_pid=&format=fslog&code2=%1").arg(QString(QUrl::toPercentEncoding(text)));
+
+    /* Set the paste user identification */
+    if (m_ui->lineName->text().trimmed().isEmpty())
+    {
+        params += QString("&poster=%1&paste=Send&remember=0").arg(QString(QUrl::toPercentEncoding(tr("Anonymous"))));
+    }
+    else
+    {
+        params += QString("&poster=%1&paste=Send&remember=0").arg(QString(QUrl::toPercentEncoding(m_ui->lineName->text())));
+    }
+
+    /* Set the duration of the paste */
+    if (m_ui->radioDay->isChecked())
+    {
+        params += QString("&expiry=%1").arg("d");
+    }
+    if (m_ui->radioMonth->isChecked())
+    {
+        params += QString("&expiry=%1").arg("m");
+    }
+    if (m_ui->radioForever->isChecked())
+    {
+        params += QString("&expiry=%1").arg("f");
+    }
+    /* Paste it! */
+    postId = pastebinHttp->request(header, params.toAscii());
+    progressDialog->setWindowTitle(tr("Pastebin"));
+    progressDialog->setLabelText(tr("Pasting..."));
+}
+void pastebinDialog::setText(QString consoleText)
+{
+    text = consoleText;
+}
+void pastebinDialog::pastebinFinished(int req, bool /*isError*/)
+{
+    if (req == postId)
+    {
+        progressDialog->hide();
+        QMessageBox::information(this, tr("Sucess"),
+                                 tr("You pastebin was successful"
+                                " and copied to clipboard: %1.")
+                                 .arg(pasteURL));
+        QApplication::clipboard()->setText(pasteURL);
+    }
+
+}
+void pastebinDialog::updateDataSendProgress(int bytesRead, int totalBytes)
+{
+    progressDialog->setMaximum(totalBytes);
+    progressDialog->setValue(bytesRead);
+}
+void pastebinDialog::readResponseHeader(const QHttpResponseHeader &responseHeader)
+{
+    switch (responseHeader.statusCode())
+    {
+    case 200:                   // Ok
+    case 301:                   // Moved Permanently
+    case 303:                   // See Other
+    case 307:                   // Temporary Redirect
+        // these are not error conditions
+        break;
+
+    case 302:                   // Found
+        pasteURL = responseHeader.value("Location");
+        break;
+
+    default:
+        QMessageBox::information(this, tr("HTTP"),
+                                 tr("Pastebin Failed: %1.")
+                                 .arg(responseHeader.reasonPhrase()));
+        progressDialog->hide();
+        pastebinHttp->abort();
+    }
+}

Added: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/pastebindialog.h (0 => 14616)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/pastebindialog.h	                        (rev 0)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/pastebindialog.h	2009-08-24 07:03:42 UTC (rev 14616)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2007, Anthony Minessale II
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of the original author; nor the names of any contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contributor(s):
+ *
+ * Joao Mesquita <jmesquita (at) freeswitch.org>
+ *
+ */
+#ifndef PASTEBINDIALOG_H
+#define PASTEBINDIALOG_H
+
+#include <QtGui/QDialog>
+
+namespace Ui {
+    class pastebinDialog;
+}
+
+class QHttp;
+class QString;
+class QProgressDialog;
+class QHttpResponseHeader;
+class QStandardItem;
+
+class pastebinDialog : public QDialog {
+    Q_OBJECT
+    Q_DISABLE_COPY(pastebinDialog)
+public:
+    explicit pastebinDialog(QWidget *parent = 0);
+    virtual ~pastebinDialog();
+    void setText(QString);
+
+protected:
+    virtual void changeEvent(QEvent *e);
+
+private:
+    Ui::pastebinDialog *m_ui;
+    QString text;
+    QString pasteURL;
+    QHttp * pastebinHttp;
+    int postId;
+    QProgressDialog *progressDialog;
+
+private slots:
+    void pastebinFinished(int, bool);
+    void pasteIt();
+    void readResponseHeader(const QHttpResponseHeader &);
+    void updateDataSendProgress(int, int);
+};
+
+#endif // PASTEBINDIALOG_H

Added: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/pastebindialog.ui (0 => 14616)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/pastebindialog.ui	                        (rev 0)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/pastebindialog.ui	2009-08-24 07:03:42 UTC (rev 14616)
@@ -0,0 +1,234 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>pastebinDialog</class>
+ <widget class="QDialog" name="pastebinDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>352</width>
+    <height>310</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_3">
+   <item>
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string>Pastebin</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout">
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout_4">
+        <item>
+         <widget class="QLabel" name="label">
+          <property name="minimumSize">
+           <size>
+            <width>80</width>
+            <height>0</height>
+           </size>
+          </property>
+          <property name="text">
+           <string>Url</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="lineURL">
+          <property name="text">
+           <string>pastebin.freeswitch.org</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout_3">
+        <item>
+         <widget class="QLabel" name="label_2">
+          <property name="minimumSize">
+           <size>
+            <width>80</width>
+            <height>0</height>
+           </size>
+          </property>
+          <property name="text">
+           <string>Port</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="linePort">
+          <property name="text">
+           <string>80</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout">
+        <item>
+         <widget class="QLabel" name="label_3">
+          <property name="minimumSize">
+           <size>
+            <width>80</width>
+            <height>0</height>
+           </size>
+          </property>
+          <property name="text">
+           <string>Username</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="lineUsername">
+          <property name="text">
+           <string>pastebin</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout_2">
+        <item>
+         <widget class="QLabel" name="label_4">
+          <property name="minimumSize">
+           <size>
+            <width>80</width>
+            <height>0</height>
+           </size>
+          </property>
+          <property name="text">
+           <string>Password</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="linePassword">
+          <property name="text">
+           <string>freeswitch</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox_2">
+     <property name="title">
+      <string>Options</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_2">
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout_5">
+        <item>
+         <widget class="QLabel" name="label_5">
+          <property name="minimumSize">
+           <size>
+            <width>80</width>
+            <height>0</height>
+           </size>
+          </property>
+          <property name="text">
+           <string>Your name</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="lineName"/>
+        </item>
+       </layout>
+      </item>
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout_6">
+        <item>
+         <widget class="QLabel" name="label_6">
+          <property name="text">
+           <string>Paste duration</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QRadioButton" name="radioDay">
+          <property name="text">
+           <string>A day</string>
+          </property>
+          <property name="checked">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QRadioButton" name="radioMonth">
+          <property name="text">
+           <string>A month</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QRadioButton" name="radioForever">
+          <property name="text">
+           <string>Forever</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>pastebinDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>pastebinDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
+