From cbc67557917f4e4bbd3404c8f542f4a5b062fbb4 Mon Sep 17 00:00:00 2001 From: jeena Date: Mon, 25 Mar 2013 19:13:09 +0100 Subject: [PATCH] fixed many things and added search --- Linux/Bungloo.py | 10 ++-- Linux/Helper.py | 4 ++ WebKit/css/default.css | 11 ++++ WebKit/scripts/controller/Conversation.js | 8 +++ WebKit/scripts/controller/Mentions.js | 13 ++++- WebKit/scripts/controller/Profile.js | 68 +++++++++++++---------- WebKit/scripts/controller/Sidebar.js | 14 ++--- WebKit/scripts/controller/Timeline.js | 10 +++- WebKit/scripts/helper/Core.js | 31 ++++++++--- WebKit/scripts/main.js | 34 ++++-------- 10 files changed, 128 insertions(+), 75 deletions(-) diff --git a/Linux/Bungloo.py b/Linux/Bungloo.py index 2f849ab..60a2d82 100755 --- a/Linux/Bungloo.py +++ b/Linux/Bungloo.py @@ -233,23 +233,23 @@ class Console(QtCore.QObject): @QtCore.pyqtSlot(str) def log(self, string): - print ": " + string + print ": " + unicode(string) @QtCore.pyqtSlot(str) def error(self, string): - print ": " + string + print ": " + unicode(string) @QtCore.pyqtSlot(str) def warn(self, string): - print ": " + string + print ": " + unicode(string) @QtCore.pyqtSlot(str) def notice(self, string): - print ": " + string + print ": " + unicode(string) @QtCore.pyqtSlot(str) def debug(self, string): - print ": " + string + print ": " + unicode(string) if __name__ == "__main__": diff --git a/Linux/Helper.py b/Linux/Helper.py index baa31b8..f3733ac 100644 --- a/Linux/Helper.py +++ b/Linux/Helper.py @@ -44,6 +44,10 @@ class WebViewCreator(QtWebKit.QWebView): self.actions = [] QtWebKit.QWebSettings.globalSettings().setAttribute(QtWebKit.QWebSettings.DeveloperExtrasEnabled, True) + def copy_link(): + self.page().triggerAction(QtWebKit.QWebPage.CopyLinkToClipboard) + self.action_copy_link = QtGui.QAction('Copy Lin&k', self, triggered=copy_link) + def context_menu_requested(self, point): context_menu = QtGui.QMenu() diff --git a/WebKit/css/default.css b/WebKit/css/default.css index 17527bd..afb1159 100644 --- a/WebKit/css/default.css +++ b/WebKit/css/default.css @@ -396,4 +396,15 @@ a.youtube:before { iframe { max-width: 500px; +} + +form.search { + text-align: center; + padding: 5px 10%; +} + +form.search input { + width: 100%; + padding: 10px; + font-size: 1.2em; } \ No newline at end of file diff --git a/WebKit/scripts/controller/Conversation.js b/WebKit/scripts/controller/Conversation.js index a92897e..b488d32 100644 --- a/WebKit/scripts/controller/Conversation.js +++ b/WebKit/scripts/controller/Conversation.js @@ -22,6 +22,14 @@ function(HostApp, Core, Paths, URI) { } Conversation.prototype = Object.create(Core.prototype); + + Conversation.prototype.show = function() { + Core.prototype.show.call(this, this.body); + } + + Conversation.prototype.hide = function() { + Core.prototype.hide.call(this, this.body); + } Conversation.addStatus = function(status) { diff --git a/WebKit/scripts/controller/Mentions.js b/WebKit/scripts/controller/Mentions.js index 1909aa5..b60de05 100644 --- a/WebKit/scripts/controller/Mentions.js +++ b/WebKit/scripts/controller/Mentions.js @@ -2,10 +2,11 @@ define([ "helper/HostApp", "controller/Timeline", "lib/URI", - "helper/Paths" + "helper/Paths", + "helper/Core" ], -function(HostApp, Timeline, URI, Paths) { +function(HostApp, Timeline, URI, Paths, Core) { function Mentions() { @@ -23,6 +24,14 @@ function(HostApp, Timeline, URI, Paths) { Mentions.prototype = Object.create(Timeline.prototype); + Mentions.prototype.show = function() { + Core.prototype.show.call(this, this.body); + } + + Mentions.prototype.hide = function() { + Core.prototype.hide.call(this, this.body); + } + Mentions.prototype.newStatus = function(statuses) { diff --git a/WebKit/scripts/controller/Profile.js b/WebKit/scripts/controller/Profile.js index f9b39e3..43d07aa 100644 --- a/WebKit/scripts/controller/Profile.js +++ b/WebKit/scripts/controller/Profile.js @@ -20,19 +20,20 @@ function(HostApp, Core, Paths, URI) { this.initProfileTemplate(); this.hide(); - this.showProfileForEntity(); // Load users profile on start + var _this = this; + setTimeout(function() { _this.showProfileForEntity() }, 5000); // Load users profile on start } Profile.prototype = Object.create(Core.prototype); Profile.prototype.show = function() { - $(this.container).show(); + Core.prototype.show.call(this, this.container); } Profile.prototype.hide = function() { - $(this.container).hide(); - }; + Core.prototype.hide.call(this, this.container); + } Profile.prototype.showList = function(list) { $(this.body).hide(); @@ -247,18 +248,23 @@ function(HostApp, Core, Paths, URI) { } Profile.prototype.getFollowing = function() { - var url = Paths.mkApiRootPath("/followings") + "/" + encodeURIComponent(this.entity); - var _this = this; - Paths.getURL(url, "GET", function(resp) { - if (resp.status >= 200 && resp.status < 400) { - var following = JSON.parse(resp.responseText); - _this.following_id = following.id - _this.setFollowingButton(true); - } else { - _this.setFollowingButton(false); - _this.following_id = null; - } - }) + if(this.entity != HostApp.stringForKey("entity")) { + var url = Paths.mkApiRootPath("/followings") + "/" + encodeURIComponent(this.entity); + var _this = this; + Paths.getURL(url, "GET", function(resp) { + if (resp.status >= 200 && resp.status < 400) { + var following = JSON.parse(resp.responseText); + _this.following_id = following.id + _this.setFollowingButton(true); + } else { + _this.setFollowingButton(false); + _this.following_id = null; + } + }) + } else { + this.setFollowingButton(false); + this.following_id = null; + } } Profile.prototype.showProfile = function(profile) { @@ -320,21 +326,25 @@ function(HostApp, Core, Paths, URI) { _this.populate(_this.profile_template.followed, resp.responseText); }, null, false); - Paths.getURL(URI(root_url + "/followers/" + encodeURIComponent(HostApp.stringForKey("entity"))).toString(), "GET", function(resp) { - if (resp.status == 200) { - _this.relationships.following_you = true; - } - _this.setRelationships(); + if (this.entity != HostApp.stringForKey("entity")) { + Paths.getURL(URI(root_url + "/followers/" + encodeURIComponent(HostApp.stringForKey("entity"))).toString(), "GET", function(resp) { + if (resp.status == 200) { + _this.relationships.following_you = true; + } + _this.setRelationships(); - }, null, false); + }, null, false); - Paths.getURL(URI(Paths.mkApiRootPath("/followings/" + encodeURIComponent(this.entity))), "GET", function(resp) { - if (resp.status == 200) { - _this.relationships.followed_by_you = true; - } - _this.setRelationships(); - - }); + Paths.getURL(URI(Paths.mkApiRootPath("/followings/" + encodeURIComponent(this.entity))), "GET", function(resp) { + if (resp.status == 200) { + _this.relationships.followed_by_you = true; + } + _this.setRelationships(); + }); + + } else { + this.setRelationships(); + } var url = URI(root_url + "/posts/count"); var post_types = [ diff --git a/WebKit/scripts/controller/Sidebar.js b/WebKit/scripts/controller/Sidebar.js index fd43d49..4a4bc8d 100644 --- a/WebKit/scripts/controller/Sidebar.js +++ b/WebKit/scripts/controller/Sidebar.js @@ -18,13 +18,13 @@ function(HostApp, Paths, Cache) { this.menu = {}; - this.menu.user = this.createItem("User", function() { _this.onEntity() }, "img/sidebar/user.png", "img/sidebar/user.png"); - this.menu.timeline = this.createItem("Timeline", function() { _this.onTimeline() }, "img/sidebar/timeline.png", "img/sidebar/timeline_active.png", true); - this.menu.mentions = this.createItem("Mentions", function() { _this.onMentions() }, "img/sidebar/mentions.png", "img/sidebar/mentions_active.png"); + this.menu.user = this.createItem("User", function() { _this.onEntity(); return false; }, "img/sidebar/user.png", "img/sidebar/user.png"); + this.menu.timeline = this.createItem("Timeline", function() { _this.onTimeline(); return false; }, "img/sidebar/timeline.png", "img/sidebar/timeline_active.png", true); + this.menu.mentions = this.createItem("Mentions", function() { _this.onMentions(); return false; }, "img/sidebar/mentions.png", "img/sidebar/mentions_active.png"); - this.menu.conversation = this.createItem("Conversation", function() { _this.onConversation() }, "img/sidebar/conversation.png", "img/sidebar/conversation_active.png"); - this.menu.entityProfile = this.createItem("Profile", function() { _this.onEntityProfile() }, "img/sidebar/profile.png", "img/sidebar/profile_active.png"); - this.menu.search = this.createItem("Search", function() { _this.onSearch() }, "img/sidebar/search.png", "img/sidebar/search_active.png") + this.menu.conversation = this.createItem("Conversation", function() { _this.onConversation(); return false; }, "img/sidebar/conversation.png", "img/sidebar/conversation_active.png"); + this.menu.entityProfile = this.createItem("Profile", function() { _this.onEntityProfile(); return false; }, "img/sidebar/profile.png", "img/sidebar/profile_active.png"); + this.menu.search = this.createItem("Search", function() { _this.onSearch(); return false; }, "img/sidebar/search.png", "img/sidebar/search_active.png") this.body.appendChild(this.menu.user); this.body.appendChild(this.menu.timeline); @@ -174,7 +174,7 @@ function(HostApp, Paths, Cache) { } Sidebar.prototype.onSearch = function() { - debug("Search not implemented yet") + this.showContentFor(bungloo.search, this.menu.search); } return Sidebar; diff --git a/WebKit/scripts/controller/Timeline.js b/WebKit/scripts/controller/Timeline.js index e287635..4888ee4 100644 --- a/WebKit/scripts/controller/Timeline.js +++ b/WebKit/scripts/controller/Timeline.js @@ -14,7 +14,7 @@ function(Core, Paths, HostApp, URI) { this.action = "timeline"; this.reload_blocked = false; - this.max_length = 20; + this.max_length = 200; this.timeout = 10 * 1000; // every 10 seconds this.since_id = null; this.since_id_entity = null; @@ -31,6 +31,14 @@ function(Core, Paths, HostApp, URI) { } Timeline.prototype = Object.create(Core.prototype); + + Timeline.prototype.show = function() { + Core.prototype.show.call(this, this.body); + } + + Timeline.prototype.hide = function() { + Core.prototype.hide.call(this, this.body); + } Timeline.prototype.newStatus = function(statuses) { diff --git a/WebKit/scripts/helper/Core.js b/WebKit/scripts/helper/Core.js index 9632ba7..207d873 100644 --- a/WebKit/scripts/helper/Core.js +++ b/WebKit/scripts/helper/Core.js @@ -11,15 +11,22 @@ function(jQuery, Paths, URI, HostApp, Cache) { function Core() { this.cache = new Cache(); + this.saveScrollTop = 0; } - Core.prototype.show = function() { - if (this.body) $(this.body).show(); + Core.prototype.show = function(container) { + if (container) { + $(container).show(); + document.body.scrollTop = this.saveScrollTop; + } } - Core.prototype.hide = function() { - if (this.body) $(this.body).hide(); + Core.prototype.hide = function(container) { + if (container && $(container).is(":visible")) { + this.saveScrollTop = document.body.scrollTop; + $(container).hide(); + } } Core.prototype.getTemplate = function() { @@ -270,11 +277,19 @@ function(jQuery, Paths, URI, HostApp, Cache) { text = text.escapeHTML().replace(/\n/g, "
"); var entities = [status.entity]; - status.mentions.map(function (mention) { - entities.push(mention.entity) - }); + if (status.mentions) { + status.mentions.map(function (mention) { + entities.push(mention.entity) + }); + } template.message.innerHTML = this.replaceURLWithHTMLLinks(text, entities, template.message); + + // adding show search on click hash + $(template.message).find("a.hash").click(function(e) { + bungloo.search.searchFor("#" + e.target.innerHTML); + return false; + }); if (status.type == "https://tent.io/types/post/photo/v0.1.0") { @@ -802,7 +817,7 @@ function(jQuery, Paths, URI, HostApp, Cache) { var hash = /(^|\s)(#)(\w+)/ig; - return URI.withinString(text, callback).replace(hash, "$1$2$3"); + return URI.withinString(text, callback).replace(hash, "$1$2$3"); } Core.prototype.parseForMedia = function(text, images) { diff --git a/WebKit/scripts/main.js b/WebKit/scripts/main.js index 3bea0cb..7d28999 100644 --- a/WebKit/scripts/main.js +++ b/WebKit/scripts/main.js @@ -6,6 +6,7 @@ var bungloo = { mentions: null, entityProfile: null, conversation: null, + search: null, cache: {} }; @@ -21,37 +22,24 @@ function start() { });*/ - require(["controller/Sidebar"], function(Sidebar) { + require([ + "controller/Sidebar", + "controller/Timeline", + "controller/Mentions", + "controller/Profile", + "controller/Conversation", + "controller/Search" + + ], function(Sidebar, Timeline, Mentions, Profile, Conversation, Search) { bungloo.sidebar = new Sidebar(); - - }); - - require(["controller/Timeline"], function(Timeline) { - bungloo.timeline = new Timeline(); - - }); - - require(["controller/Mentions"], function(Mentions) { - bungloo.mentions = new Mentions(); - - }); - - - require(["controller/Profile"], function(Profile) { - bungloo.entityProfile = new Profile(); - - }); - - require(["controller/Conversation"], function(Conversation) { - bungloo.conversation = new Conversation(); + bungloo.search = new Search(); }); - }