diff --git a/src/controller/buffers.py b/src/controller/buffers.py index c644a30..c6454e1 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -83,6 +83,16 @@ class baseBuffer(object): if post.has_key("type") and post["type"] == "audio": pub.sendMessage("play-audio", audio_object=post["audio"][1]["url"]) + def open_post(self): + post = self.session.db[self.name]["items"][self.tab.list.get_selected()] + if post.has_key("type") and post["type"] == "audio": + a = posts.audio(self.session, post["audio"][1]) + a.dialog.get_response() + elif post.has_key("type") and post["type"] == "friend": + pub.sendMessage("open-post", post_object=post, controller_="friendship") + else: + pub.sendMessage("open-post", post_object=post, controller_="postController") + class feedBuffer(baseBuffer): def get_items(self, no_next=True): diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 743f8d5..b21ffde 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -4,6 +4,7 @@ import widgetUtils import messages import buffers import player +import posts from pubsub import pub from mysc.repeating_timer import RepeatingTimer from mysc.thread_utils import call_threaded @@ -45,6 +46,7 @@ class Controller(object): pub.subscribe(self.in_post, "posted") pub.subscribe(self.download, "download-file") pub.subscribe(self.play_audio, "play-audio") + pub.subscribe(self.view_post, "open-post") def login(self): self.window.change_status(_(u"Logging in VK")) @@ -73,3 +75,8 @@ class Controller(object): def play_audio(self, audio_object): call_threaded(player.player.play, audio_object) + + def view_post(self, post_object, controller_): + print controller_ + p = getattr(posts, controller_)(self.session, post_object) + p.dialog.get_response() \ No newline at end of file diff --git a/src/controller/posts.py b/src/controller/posts.py index cf82d4f..6a5a37e 100644 --- a/src/controller/posts.py +++ b/src/controller/posts.py @@ -8,6 +8,7 @@ import output import wx import webbrowser import utils +from sessionmanager import session # We'll use some functions from there from pubsub import pub from wxUI.dialogs import postDialogs, urlList from extra import SpellChecker, translator @@ -21,34 +22,29 @@ class postController(object): self.post = postObject self.dialog = postDialogs.post() self.dialog.comments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.show_comment) - from_ = self.session.get_user_name(self.post["from_id"]) -# if self.post.has_key("owner_id"): -# to_ = [i["name"] for i in self.post["to"]["data"]] -# title = _(u"Post from {0} in {1}").format(from_, "".join(to_)) -# else: - title = _(u"Post from {0}").format(from_,) - self.dialog.set_title(title) - message = story = u"" - if self.post.has_key("message"): - message = self.post["message"] - if self.post.has_key("story"): - story = self.post["story"] - if self.post.has_key("name") and self.post.has_key("link"): - message += u". {0}, {1}".format(self.post["name"], self.post["link"]) - if story != "": - final_msg = u"{0} \n\n{1}".format(story, message) - else: - final_msg = message - self.dialog.set_post(final_msg) # widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck) # widgetUtils.connect_event(self.message.translateButton, widgetUtils.BUTTON_PRESSED, self.translate) -# self.text_processor() widgetUtils.connect_event(self.dialog.like, widgetUtils.BUTTON_PRESSED, self.post_like) widgetUtils.connect_event(self.dialog.comment, widgetUtils.BUTTON_PRESSED, self.add_comment) widgetUtils.connect_event(self.dialog.tools, widgetUtils.BUTTON_PRESSED, self.show_tools_menu) self.dialog.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.show_menu, self.dialog.comments.list) self.dialog.Bind(wx.EVT_LIST_KEY_DOWN, self.show_menu_by_key, self.dialog.comments.list) - call_threaded(self.load_all_components) +# call_threaded(self.load_all_components) + self.get_post_information() + + def get_post_information(self): + if self.post.has_key("type"): + if self.post["type"] == "post": + from_ = self.session.get_user_name(self.post["source_id"]) + title = _(u"Post from {0}").format(from_,) + self.dialog.set_title(title) + message = u"" + if self.post.has_key("text"): + message = self.post["text"] + if self.post.has_key("attachment"): + print self.post["attachment"].keys() + message = message+session.add_attachment(self.post["attachment"]) + self.dialog.set_post(message) def load_all_components(self): self.get_likes() @@ -220,3 +216,23 @@ class audio(postController): def play(self, *args, **kwargs): pub.sendMessage("play-audio", audio_object=self.post["url"]) + +class friendship(object): + + def __init__(self, session, post): + self.session = session + self.post = post + self.dialog = postDialogs.friendship() + list_of_friends = self.get_friend_names() + from_ = self.session.get_user_name(self.post["source_id"]) + title = _(u"{0} added the following friends").format(from_,) + self.dialog.set_title(title) + self.set_friends_list(list_of_friends) + + def get_friend_names(self): + self.friends = self.post["friends"][1:] + return [self.session.get_user_name(i["uid"]) for i in self.friends] + + def set_friends_list(self, friendslist): + for i in friendslist: + self.dialog.friends.insert_item(False, *[i]) diff --git a/src/wxUI/dialogs/postDialogs.py b/src/wxUI/dialogs/postDialogs.py index 707187e..ddd3644 100644 --- a/src/wxUI/dialogs/postDialogs.py +++ b/src/wxUI/dialogs/postDialogs.py @@ -144,4 +144,18 @@ class audio(widgetUtils.BaseDialog): saveFileDialog = wx.FileDialog(self, _(u"Save this file"), "", filename, _(u"Audio Files(*.mp3)|*.mp3"), wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) if saveFileDialog.ShowModal() == wx.ID_OK: return saveFileDialog.GetPath() - saveFileDialog.Destroy() \ No newline at end of file + saveFileDialog.Destroy() + +class friendship(widgetUtils.BaseDialog): + def __init__(self): + super(friendship, self).__init__(parent=None) + panel = wx.Panel(self) + sizer = wx.BoxSizer(wx.VERTICAL) + self.friends = widgetUtils.list(panel, [_(u"Friend")], style=wx.LC_REPORT) + sizer.Add(self.friends.list, 0, wx.ALL, 5) + close = wx.Button(panel, wx.ID_CANCEL) + btnbox = wx.BoxSizer(wx.HORIZONTAL) + btnbox.Add(close, 0, wx.ALL, 5) + sizer.Add(btnbox, 0, wx.ALL, 5) + panel.SetSizer(sizer) + self.SetClientSize(sizer.CalcMin()) \ No newline at end of file