From a332acad4f5b991b9d7a8af1e76d49a9e8577190 Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Wed, 26 Dec 2012 19:28:25 +0100 Subject: [PATCH] fixed posting --- Linux/Helper.py | 17 +++++++++-- Linux/Tentia.py | 46 +++++++++++++++++++++++++--- Linux/Windows.py | 79 ++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 123 insertions(+), 19 deletions(-) diff --git a/Linux/Helper.py b/Linux/Helper.py index 0f031ed..d2a4d64 100644 --- a/Linux/Helper.py +++ b/Linux/Helper.py @@ -18,8 +18,11 @@ class WebPage(QtWebKit.QWebPage): class WebViewCreator(QtWebKit.QWebView): - def __init__(self, app, local=True): - QtGui.QWidget.__init__(self) + def __init__(self, app, local=True, parent=None): + if parent != None: + QtGui.QWidget.__init__(self) + else: + QtGui.QWidget.__init__(self) self.app = app self.is_local = local @@ -68,4 +71,12 @@ class NetworkAccessManager(QNetworkAccessManager): self.tentia_callback(request.url()) return QNetworkAccessManager.createRequest(self, QNetworkAccessManager.GetOperation, QNetworkRequest(QtCore.QUrl())) - \ No newline at end of file +class PostModel: + + def __init__(self): + self.text = None + self.inReplyTostatusId = None + self.inReplyToEntity = None + self.location = None + self.imageFilePath = None + self.isPrivate = False \ No newline at end of file diff --git a/Linux/Tentia.py b/Linux/Tentia.py index 2b1b074..e36f6c4 100755 --- a/Linux/Tentia.py +++ b/Linux/Tentia.py @@ -89,7 +89,7 @@ class Controller(QtCore.QObject): def unreadMentions(self, count): i = int(count) if i > 0: - self.app.timeline.set_window_title("Tentia (^" + count + ")") + self.app.timeline.set_window_title("Tentia (^" + str(i) + ")") else: self.app.timeline.set_window_title("Tentia") @@ -97,19 +97,57 @@ class Controller(QtCore.QObject): def notificateUserAboutMention(self, text, name, post_id, entity): print "notificateUserAboutMention is not implemented yet" - @QtCore.pyqtSlot(str, str, str) + @QtCore.pyqtSlot(str) def openNewMessageWidow(self, string): - print "openNewMessageWidow is not implemented yet" + new_message_window = Windows.NewPost(self.app) + new_message_window.show() + new_message_window.setAttribute(QtCore.Qt.WA_DeleteOnClose) + self.app.new_message_windows.append(new_message_window) @QtCore.pyqtSlot(str, str, str, bool) def openNewMessageWindowInReplyTostatusIdwithStringIsPrivate(self, entity, status_id, string, is_private): - new_message_window = Windows.NewPost() + new_message_window = Windows.NewPost(self.app) new_message_window.inReplyToStatusIdWithString(entity, status_id, string) new_message_window.setIsPrivate(is_private) new_message_window.show() new_message_window.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.app.new_message_windows.append(new_message_window) + def sendMessage(self, message): + text = str.replace(str(message.text), "\\", "\\\\") + text = str.replace(text, "\"", "\\\"") + text = str.replace(text, "\n", "\\n") + + in_reply_to_status_id = "" + if message.inReplyTostatusId is not None: + in_reply_to_status_id = message.inReplyTostatusId + + in_reply_to_entity = "" + if message.inReplyToEntity is not None: + in_reply_to_entity = message.inReplyToEntity + + locationObject = "null" + #if (post.location) { + # locationObject = [NSString stringWithFormat:@"[%f, %f]", post.location.coordinate.latitude, post.location.coordinate.longitude]; + #} + + imageFilePath = "null" + #if (post.imageFilePath) { + # NSError *error; + # NSString *mimeType = [MimeType mimeTypeForFileAtPath:post.imageFilePath error:&error]; + # NSData *data = [[NSData alloc] initWithContentsOfFile:post.imageFilePath]; + # NSString *base64 = [data base64Encoding_xcd]; + # [data release]; + # imageFilePath = [NSString stringWithFormat:@"\"data:%@;base64,%@\"", mimeType, base64]; + #} + + isPrivate = "false"; + if message.isPrivate: + isPrivate = "true" + + func = "tentia_instance.sendNewMessage(\"{}\", \"{}\", \"{}\", {}, {}, {});".format(text, in_reply_to_status_id, in_reply_to_entity, locationObject, imageFilePath, isPrivate) + self.app.timeline.webView.page().mainFrame().evaluateJavaScript(func) + @QtCore.pyqtSlot(str, str) def showConversation(self, id, entity): print "showConversation is not implemented yet" diff --git a/Linux/Windows.py b/Linux/Windows.py index 30b949f..4036176 100644 --- a/Linux/Windows.py +++ b/Linux/Windows.py @@ -72,7 +72,6 @@ class Preferences: else: self.activity_indicator.hide() - class Timeline: def __init__(self, app, action="timeline", title="Tentia"): @@ -80,13 +79,30 @@ class Timeline: self.action = action self.title = title - self.window = Helper.WebViewCreator(self.app) + self.window = QtGui.QMainWindow() + self.window.setWindowTitle(title) - self.window.load_local(self.load_finished) self.window.resize(380, 600) self.window.setMinimumSize(200, 200) + self.webView = Helper.WebViewCreator(self.app, True, self.window) + self.webView.load_local(self.load_finished) + self.window.setCentralWidget(self.webView) + + # self.window.addWidget(self.webView) + self.initUI() + + def initUI(self): + newPostAction = QtGui.QAction("&New Post", self.window) + newPostAction.setShortcut("Ctrl+N") + newPostAction.setStatusTip("Open new post window") + newPostAction.triggered.connect(self.app.controller.openNewMessageWidow) + + menubar = self.window.menuBar() + fileMenu = menubar.addMenu("&File") + fileMenu.addAction(newPostAction) + def show(self): self.window.show() @@ -95,7 +111,7 @@ class Timeline: def load_finished(self, widget): script = "function HostAppGo() { start('" + self.action + "'); }" - self.window.page().mainFrame().evaluateJavaScript(script) + self.webView.page().mainFrame().evaluateJavaScript(script) def set_window_title(self, title): self.window.setWindowTitle(title) @@ -174,17 +190,41 @@ class Login(QtGui.QDialog): #self.buttonLogin.clicked.connect(callback) #self.label.setText("The server " + url.host() + " requires a username and password.") -class NewPost(QtGui.QPlainTextEdit): - def __init__(self): +class NewPost(QtGui.QMainWindow): + def __init__(self, app): + self.app = app QtGui.QPlainTextEdit.__init__(self) + + self.textInput = QtGui.QPlainTextEdit(self) + self.setCentralWidget(self.textInput) + self.textInput.textChanged.connect(self.onChanged) + self.setWindowTitle("New Post") self.resize(300, 150) self.setMinimumSize(100, 100) - - self.statusBar = QtGui.QStatusBar(self) - self.statusBar.showMessage("256") + self.initUI() self.isPrivate = False + self.status_id = None + self.reply_to_entity = None + + def initUI(self): + newPostAction = QtGui.QAction("&New Post", self) + newPostAction.setShortcut("Ctrl+N") + newPostAction.setStatusTip("Open new post window") + newPostAction.triggered.connect(self.app.controller.openNewMessageWidow) + + sendPostAction = QtGui.QAction("&Send Post", self) + sendPostAction.setShortcut("Ctrl+Return") + sendPostAction.setStatusTip("Send post") + sendPostAction.triggered.connect(self.sendMessage) + + self.statusBar().showMessage('256') + + menubar = self.menuBar() + fileMenu = menubar.addMenu("&File") + fileMenu.addAction(newPostAction) + fileMenu.addAction(sendPostAction) def setIsPrivate(self, is_private): self.isPrivate = is_private @@ -195,8 +235,23 @@ class NewPost(QtGui.QPlainTextEdit): def inReplyToStatusIdWithString(self, reply_to, status_id, string): self.reply_to_entity = reply_to self.status_id = status_id - self.setPlainText(string) + self.textInput.setPlainText(string) - cursor = self.textCursor() + cursor = self.textInput.textCursor() cursor.movePosition(QtGui.QTextCursor.End, QtGui.QTextCursor.MoveAnchor) - self.setTextCursor(cursor) \ No newline at end of file + self.textInput.setTextCursor(cursor) + + def onChanged(self): + count = 256 - len(self.textInput.toPlainText()) + self.statusBar().showMessage(str(count)) + + def sendMessage(self): + message = Helper.PostModel() + message.text = self.textInput.toPlainText() + message.inReplyTostatusId = self.status_id + message.inReplyToEntity = self.reply_to_entity + message.location = None + message.imageFilePath = None + message.isPrivate = self.isPrivate + self.app.controller.sendMessage(message) + self.close() \ No newline at end of file