fixed posting
This commit is contained in:
parent
a861de4eb4
commit
a332acad4f
3 changed files with 123 additions and 19 deletions
|
@ -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()))
|
||||
|
||||
class PostModel:
|
||||
|
||||
def __init__(self):
|
||||
self.text = None
|
||||
self.inReplyTostatusId = None
|
||||
self.inReplyToEntity = None
|
||||
self.location = None
|
||||
self.imageFilePath = None
|
||||
self.isPrivate = False
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
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()
|
Reference in a new issue