Permalink
Browse files

import qt wrapper

  • Loading branch information...
1 parent f54b5a1 commit 150300806c42cadea7fd7bb6ba47e59380c3c08a @wengxt wengxt committed Sep 14, 2011
View
@@ -0,0 +1,18 @@
+cmake_minimum_required(VERSION 2.6)
+
+project(hotot-qt)
+
+find_package(Qt4 4.7 REQUIRED COMPONENTS QtCore QtGui QtWebkit QtSql)
+
+configure_file(config.h.in config.h)
+
+# uninstall target
+configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
+ IMMEDIATE @ONLY)
+
+add_custom_target(uninstall
+ COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
+
+add_subdirectory(qt)
@@ -0,0 +1,21 @@
+if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
+ message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
+endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
+
+file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
+string(REGEX REPLACE "\n" ";" files "${files}")
+foreach (file ${files})
+ message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
+ if (EXISTS "$ENV{DESTDIR}${file}" OR IS_SYMLINK "$ENV{DESTDIR}${file}")
+ execute_process(
+ COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}"
+ OUTPUT_VARIABLE rm_out
+ RESULT_VARIABLE rm_retval
+ )
+ if(NOT ${rm_retval} EQUAL 0)
+ message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
+ endif (NOT ${rm_retval} EQUAL 0)
+ else (EXISTS "$ENV{DESTDIR}${file}" OR IS_SYMLINK "$ENV{DESTDIR}${file}")
+ message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
+ endif (EXISTS "$ENV{DESTDIR}${file}" OR IS_SYMLINK "$ENV{DESTDIR}${file}")
+endforeach(file)
View
@@ -0,0 +1 @@
+#define PREFIX "@CMAKE_INSTALL_PREFIX@"
View
@@ -0,0 +1,2 @@
+add_subdirectory(src)
+add_subdirectory(data)
View
@@ -0,0 +1,5 @@
+install(DIRECTORY ${PROJECT_SOURCE_DIR}/data/ DESTINATION share/hotot-qt/html PATTERN .hg PATTERN *~ EXCLUDE)
+
+install(FILES ${PROJECT_SOURCE_DIR}/data/image/ic64_hotot_classics.png DESTINATION share/icons/hicolor/64x64/apps/ RENAME hotot-qt.png)
+install(FILES ${PROJECT_SOURCE_DIR}/data/image/ic32_hotot_classics.png DESTINATION share/icons/hicolor/32x32/apps/ RENAME hotot-qt.png)
+install(FILES hotot-qt.desktop DESTINATION share/applications/ )
View
@@ -0,0 +1,8 @@
+[Desktop Entry]
+Name=Hotot Qt
+GenericName=Twitter Client
+Type=Application
+Comment=Lightweight Twitter Client base on QtWebkit
+Exec=hotot-qt
+Icon=hotot-qt
+Categories=Qt;Network;
View
@@ -0,0 +1,29 @@
+include_directories(${QT_QTCORE_INCLUDE_DIR})
+include_directories(${QT_QTGUI_INCLUDE_DIR})
+include_directories(${QT_QTSQL_INCLUDE_DIR})
+include_directories(${QT_QTWEBKIT_INCLUDE_DIR})
+include_directories(${QT_QTNETWORK_INCLUDE_DIR})
+include_directories(${PROJECT_BINARY_DIR})
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+set(Hotot_QT_SRCS
+ formpost.cpp
+ hototrequest.cpp
+ main.cpp
+ mainwindow.cpp
+ hototwebpage.cpp
+)
+
+qt4_automoc(${Hotot_QT_SRCS})
+qt4_wrap_ui(Hotot_QT_SRCS mainwindow.ui)
+add_executable(hotot-qt ${Hotot_QT_SRCS})
+target_link_libraries(hotot-qt
+ ${QT_QTCORE_LIBRARY}
+ ${QT_QTGUI_LIBRARY}
+ ${QT_QTSQL_LIBRARY}
+ ${QT_QTWEBKIT_LIBRARY}
+ ${QT_QTNETWORK_LIBRARY}
+)
+
+install(TARGETS hotot-qt DESTINATION bin)
View
@@ -0,0 +1,141 @@
+/* from : http://code.google.com/p/bungeni-transcriber/ */
+
+#include "formpost.h"
+
+FormPost::FormPost(QNetworkAccessManager* manager)
+:QObject(0)
+{
+ userAgentS="";
+ encodingS="utf-8";
+ refererS="";
+ http= manager;
+}
+
+QString FormPost::userAgent() {
+ return userAgentS;
+}
+
+void FormPost::setUserAgent(QString agent) {
+ userAgentS=agent;
+}
+
+QString FormPost::referer() {
+ return refererS;
+}
+
+void FormPost::setReferer(QString ref) {
+ refererS=ref;
+}
+
+QString FormPost::encoding() {
+ return encodingS;
+}
+
+void FormPost::setEncoding(QString enc) {
+ if (enc=="utf-8" || enc=="ascii") {
+ encodingS=enc;
+ }
+}
+
+QByteArray FormPost::strToEnc(QString s) {
+ if (encodingS=="utf-8") {
+ return s.toUtf8();
+ } else {
+ return s.toAscii();
+ }
+}
+
+void FormPost::addField(QString name, QString value) {
+ fieldNames.append(name);
+ fieldValues.append(value);
+}
+
+void FormPost::addFile(QString fieldName, QByteArray file, QString name, QString mime) {
+ files.append(file);
+ fileFieldNames.append(fieldName);
+ fileNames.append(name);
+ fileMimes.append(mime);
+}
+
+void FormPost::addFile(QString fieldName, QString fileName, QString mime) {
+ QFile f(fileName);
+ f.open(QIODevice::ReadOnly);
+ QByteArray file=f.readAll();
+ f.close();
+ QString name;
+ if (fileName.contains("/")) {
+ int pos=fileName.lastIndexOf("/");
+ name=fileName.right(fileName.length()-pos-1);
+ } else if (fileName.contains("\\")) {
+ int pos=fileName.lastIndexOf("\\");
+ name=fileName.right(fileName.length()-pos-1);
+ } else {
+ name=fileName;
+ }
+ addFile(fieldName,file,name,mime);
+}
+
+QNetworkReply * FormPost::postData(QNetworkRequest& request) {
+ QString crlf="\r\n";
+ qsrand(QDateTime::currentDateTime().toTime_t());
+ QString b = QVariant(qrand()).toString()+QVariant(qrand()).toString()
+ +QVariant(qrand()).toString();
+ QString boundary="---------------------------"+b;
+ QString endBoundary=crlf+"--"+boundary+"--"+crlf;
+ QString contentType="multipart/form-data; boundary="+boundary;
+ boundary="--"+boundary+crlf;
+ QByteArray bond=boundary.toAscii();
+ QByteArray send;
+ bool first=true;
+
+ for (int i=0; i<fieldNames.size(); i++) {
+ send.append(bond);
+ if (first) {
+ boundary=crlf+boundary;
+ bond=boundary.toAscii();
+ first=false;
+ }
+ send.append(QString("Content-Disposition: form-data; name=\""
+ +fieldNames.at(i)+"\""+crlf).toAscii());
+ if (encodingS=="utf-8") send.append(QString("Content-Transfer-Encoding: 8bit"
+ +crlf).toAscii());
+ send.append(crlf.toAscii());
+ send.append(strToEnc(fieldValues.at(i)));
+ }
+ for (int i=0; i<files.size(); i++) {
+ send.append(bond);
+ send.append(QString("Content-Disposition: form-data; name=\""
+ +fileFieldNames.at(i)+"\"; filename=\""
+ +fileNames.at(i)+"\""+crlf).toAscii());
+ send.append(QString("Content-Type: "+fileMimes.at(i)+crlf+crlf).toAscii());
+ send.append(files.at(i));
+ }
+
+ send.append(endBoundary.toAscii());
+
+ fieldNames.clear();
+ fieldValues.clear();
+ fileFieldNames.clear();
+ fileNames.clear();
+ fileMimes.clear();
+ files.clear();
+
+
+ connect(http,SIGNAL(finished(QNetworkReply *)),this,SLOT(readData(QNetworkReply *)));
+ if (userAgentS!="") request.setRawHeader("User-Agent", userAgentS.toAscii());
+ if (refererS!="") request.setRawHeader("Referer", refererS.toAscii());
+ request.setHeader(QNetworkRequest::ContentTypeHeader, contentType.toAscii());
+ request.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(send.size()).toString());
+ QNetworkReply * reply=http->post(request,send);
+ return reply;
+}
+
+void FormPost::readData(QNetworkReply * r) {
+ this->data = r->readAll();
+}
+
+QByteArray FormPost::response() {
+ return this->data;
+}
+
+#include "formpost.moc"
View
@@ -0,0 +1,50 @@
+/* from : http://code.google.com/p/bungeni-transcriber/ */
+
+#ifndef __FORMPOST_H__
+#define __FORMPOST_H__
+#include <QtPlugin>
+#include <QString>
+#include <QByteArray>
+#include <QFile>
+#include <QProgressBar>
+#include <QDateTime>
+#include <QWidget>
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QDebug>
+
+class FormPost: public QObject
+{
+Q_OBJECT
+ public:
+ FormPost(QNetworkAccessManager* manager);
+ QString userAgent();
+ void setUserAgent(QString agent);
+ QString referer();
+ void setReferer(QString ref);
+ QString encoding();
+ void setEncoding(QString enc);
+ void addField(QString name, QString value);
+ void addFile(QString fieldName, QByteArray file, QString name, QString mime);
+ void addFile(QString fieldName, QString fileName, QString mime);
+ QNetworkReply * postData(QNetworkRequest& request);
+ QByteArray response();
+ QNetworkAccessManager * http;
+ private:
+ QByteArray data;
+ QByteArray strToEnc(QString s);
+ QString encodingS;
+ QString userAgentS;
+ QString refererS;
+ QStringList fieldNames;
+ QStringList fieldValues;
+ QStringList fileFieldNames;
+ QStringList fileNames;
+ QStringList fileMimes;
+ QList<QByteArray> files;
+ private slots:
+ void readData(QNetworkReply * r);
+};
+
+#endif
Oops, something went wrong.

0 comments on commit 1503008

Please sign in to comment.