Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed icons drawing in webkit chat
  • Loading branch information
Ri0n committed Dec 19, 2011
1 parent 1be19cd commit 2b7d1ca
Showing 1 changed file with 58 additions and 83 deletions.
141 changes: 58 additions & 83 deletions patches/0030-psi-webkit.diff
Expand Up @@ -28,7 +28,7 @@
<border type="QColor">#5297f9</border>
--- psi.orig/psi.qc
+++ psi/psi.qc
@@ -26,6 +26,9 @@
@@ -29,6 +29,9 @@
<required/>
</dep>
<dep type='qdbus'/>
Expand Down Expand Up @@ -81,7 +81,7 @@
+};
--- psi.orig/src/bytearrayreply.cpp
+++ psi/src/bytearrayreply.cpp
@@ -0,0 +1,89 @@
@@ -0,0 +1,77 @@
+/*
+ * bytearrayreply.cpp - Base class for QNetworReply'es returning QByteArray
+ * Copyright (C) 2010 senu, Rion
Expand All @@ -106,58 +106,51 @@
+
+#include <QTimer>
+
+ByteArrayReply::ByteArrayReply(const QByteArray& ba, QObject * parent) : QNetworkReply(parent) {
+ setOpenMode(QIODevice::ReadOnly | QIODevice::Unbuffered);
+
+ dataBuffer_.setData(ba);
+ dataBuffer_.open(QIODevice::ReadOnly);
+
+ QTimer::singleShot(0, this, SLOT(dataReady()));
+}
+
+void ByteArrayReply::abort() {
+}
+
+
+void ByteArrayReply::close() {
+}
+
+ByteArrayReply::ByteArrayReply(const QNetworkRequest &request,
+ const QByteArray &ba, const QString& mimeType,
+ QObject *parent) :
+ QNetworkReply(parent),
+ origLen(ba.size()),
+ data(ba)
+{
+ setRequest(request);
+ setOpenMode(QIODevice::ReadOnly);
+
+qint64 ByteArrayReply::bytesAvailable() const {
+ return dataBuffer_.bytesAvailable();
+ if (mimeType.isEmpty()) {
+ setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
+ } else {
+ setHeader(QNetworkRequest::ContentTypeHeader, mimeType);
+ }
+ setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(origLen));
+ QTimer::singleShot(0, this, SIGNAL(metaDataChanged()));
+ QTimer::singleShot(0, this, SIGNAL(readyRead()));
+}
+
+ByteArrayReply::~ByteArrayReply() {
+
+qint64 ByteArrayReply::readData(char *data, qint64 len) {
+ return dataBuffer_.read(data, len);
+}
+
+
+void ByteArrayReply::setReadBufferSize(qint64 size) {
+ Q_UNUSED(size);
+ Q_ASSERT(0); //should never happened
+void ByteArrayReply::abort() {
+ qDebug("ByteArrayReply abort O_o");
+}
+
+
+ByteArrayReply::~ByteArrayReply() {
+qint64 ByteArrayReply::bytesAvailable() const
+{
+ return data.length() + QNetworkReply::bytesAvailable();
+}
+
+
+void ByteArrayReply::dataReady() {
+
+ qint64 totalSize = dataBuffer_.bytesAvailable();
+
+ if (!totalSize) { //not in IconServer or (internet) access denied
+ setError(QNetworkReply::ContentAccessDenied, "Access Denied");
+ emit error(QNetworkReply::ContentAccessDenied);
+ emit finished();
+ return;
+qint64 ByteArrayReply::readData(char *buffer, qint64 maxlen)
+{
+ qint64 len = qMin(qint64(data.length()), maxlen);
+ if (len) {
+ memcpy(buffer, data.constData(), len);
+ data.remove(0, len);
+ }
+ if (!data.length())
+ QTimer::singleShot(0, this, SIGNAL(finished()));
+ return len;
+
+ emit downloadProgress(0, totalSize);
+ emit downloadProgress(totalSize, totalSize);
+ emit readyRead();
+ emit finished();
+}
+
+
Expand All @@ -166,14 +159,9 @@
+ Q_ASSERT(0); //should never happened
+ return true;
+}
+
+
+qint64 ByteArrayReply::size() const {
+ return bytesAvailable(); //well, should never happended too
+}
--- psi.orig/src/bytearrayreply.h
+++ psi/src/bytearrayreply.h
@@ -0,0 +1,67 @@
@@ -0,0 +1,53 @@
+/*
+ * bytearrayreply.h - Base class for QNetworReply'es returning QByteArray
+ * Copyright (C) 2010 senu, Rion
Expand Down Expand Up @@ -206,38 +194,24 @@
+ Q_OBJECT
+
+public:
+ ByteArrayReply(const QByteArray& ba = QByteArray(), QObject * parent = 0);
+ ByteArrayReply(const QNetworkRequest &request,
+ const QByteArray &ba = QByteArray(),
+ const QString &mimeType = QString(),
+ QObject * parent = 0);
+
+ /** Construct IconReply that fails with ContentAccessDenied error */
+ //ByteArrayReply();
+ ~ByteArrayReply();
+
+ //reimplemented
+ void abort();
+ void close();
+ qint64 readData(char *data, qint64 len);
+ void setReadBufferSize(qint64 size);
+ qint64 readData(char *buffer, qint64 maxlen);
+ qint64 bytesAvailable() const;
+ bool open(OpenMode mode);
+ qint64 size() const;
+
+
+ private
+slots:
+
+ /**
+ * Emits finished().
+ *
+ * We cannot emit finished() in constructor.
+ *
+ * To be precise QNetworkAccessManager::createRequest() must return before we emit finished()
+ * It's Qt bug.
+ */
+ void dataReady();
+
+private:
+ /** Icon data */
+ QBuffer dataBuffer_;
+ int origLen;
+ QByteArray data;
+};
+
+#endif
Expand Down Expand Up @@ -2286,11 +2260,11 @@
+ MessageView mv = MessageView::fromPlainText(str, MessageView::System);
+ if (!PsiOptions::instance()->getOption("options.ui.muc.use-highlighting").toBool()) {
+ alert = false;
+ }
}
+ mv.setAlert(alert);
+ if(!ts.isNull()) {
+ mv.setDateTime(ts);
}
+ }
+ appendSysMsg(mv);
}

Expand All @@ -2312,8 +2286,7 @@

- if (!PsiOptions::instance()->getOption("options.ui.muc.use-highlighting").toBool())
- alert=false;
+ ui_.log->dispatchMessage(mv);

-
- QDateTime time = QDateTime::currentDateTime();
- if(!ts.isNull())
- time = ts;
Expand All @@ -2323,7 +2296,8 @@
- QString color = ColorOpt::instance()->color("options.ui.look.colors.messages.informational").name();
- ui_.log->appendText(QString("<font color=\"%1\">[%2]").arg(color, timestr) +
- QString(" *** %1</font>").arg(prepareAsChatMessage ? TextUtil::prepareMessageText(str) : Qt::escape(str)));
-
+ ui_.log->dispatchMessage(mv);

- if(alert)
+ if(mv.isAlert())
doAlert();
Expand Down Expand Up @@ -2490,7 +2464,7 @@
</widget>
<widget class="GCUserView" name="lv_users" >
<property name="minimumSize" >
@@ -289,8 +286,8 @@
@@ -292,8 +289,8 @@
</customwidget>
<customwidget>
<class>ChatView</class>
Expand Down Expand Up @@ -3177,7 +3151,7 @@
{
--- psi.orig/src/networkaccessmanager.cpp
+++ psi/src/networkaccessmanager.cpp
@@ -0,0 +1,115 @@
@@ -0,0 +1,116 @@
+/*
+ * networkaccessmanager.cpp - Network Manager for WebView able to process
+ * custom url schemas
Expand Down Expand Up @@ -3223,7 +3197,11 @@
+ }
+
+ if (schemeHandlers_.contains(req.url().scheme())) {
+ ByteArrayReply *repl = new ByteArrayReply(schemeHandlers_.value(req.url().scheme())->data(req.url()), this);
+ ByteArrayReply *repl = new ByteArrayReply(
+ req,
+ schemeHandlers_.value(req.url().scheme())->data(req.url()),
+ QString(),
+ this);
+ connect(repl, SIGNAL(finished()), SLOT(callFinished()));
+ return repl;
+ }
Expand All @@ -3239,10 +3217,7 @@
+ return QNetworkAccessManager::createRequest(op, req, outgoingData);
+ }
+
+ //deny all other access
+ QNetworkRequest req2(req);
+
+ QNetworkReply * reply = new ByteArrayReply(); //finishes with error
+ QNetworkReply * reply = new ByteArrayReply(req); //finishes with error
+ connect(reply, SIGNAL(finished()), SLOT(callFinished()));
+
+ return reply;
Expand Down Expand Up @@ -4323,7 +4298,7 @@
//----------------------------------------------------------------------------
// PsiCon::Private
//----------------------------------------------------------------------------
@@ -475,6 +481,16 @@ bool PsiCon::init()
@@ -473,6 +479,16 @@ bool PsiCon::init()
//}
}

Expand All @@ -4340,7 +4315,7 @@
if ( !d->actionList )
d->actionList = new PsiActionList( this );

@@ -621,7 +637,6 @@ bool PsiCon::init()
@@ -619,7 +635,6 @@ bool PsiCon::init()
}

checkAccountsEmpty();
Expand Down Expand Up @@ -5325,7 +5300,7 @@
-}
--- psi.orig/src/textutil.h
+++ psi/src/textutil.h
@@ -15,6 +15,7 @@ namespace TextUtil
@@ -15,6 +15,7 @@ namespace TextUtil
QString linkify(const QString &);
QString legacyFormat(const QString &);
QString emoticonify(const QString &in);
Expand Down

2 comments on commit 2b7d1ca

@zet
Copy link
Member

@zet zet commented on 2b7d1ca Dec 19, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

думаешь поможет?

@Ri0n
Copy link
Member Author

@Ri0n Ri0n commented on 2b7d1ca Dec 19, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ну я не то чтобы думаю, я уже проверил. работает.

Please sign in to comment.