aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscudcloud-1.0/lib/scudcloud.py11
-rw-r--r--scudcloud-1.0/lib/wrapper.py41
-rw-r--r--scudcloud-1.0/resources/scudcloud.js2
-rw-r--r--scudcloud-1.0/scudcloud-src.js106
4 files changed, 88 insertions, 72 deletions
diff --git a/scudcloud-1.0/lib/scudcloud.py b/scudcloud-1.0/lib/scudcloud.py
index 3fb3b2c..abcc8ca 100755
--- a/scudcloud-1.0/lib/scudcloud.py
+++ b/scudcloud-1.0/lib/scudcloud.py
@@ -61,8 +61,6 @@ class ScudCloud(QtGui.QMainWindow):
self.systray(ScudCloud.minimized)
self.installEventFilter(self)
self.statusBar().showMessage('Loading Slack...')
- # Starting unread msgs counter
- self.setupTimer()
def addWrapper(self, url):
webView = Wrapper(self)
@@ -73,12 +71,6 @@ class ScudCloud(QtGui.QMainWindow):
self.stackedWidget.addWidget(webView)
self.stackedWidget.setCurrentWidget(webView)
- def setupTimer(self):
- self.timer = QTimer(self)
- self.timer.timeout.connect(self.count)
- self.timer.setInterval(2000)
- self.timer.start()
-
def webSettings(self):
self.cookiesjar = PersistentCookieJar(self)
self.zoom = self.readZoom()
@@ -281,7 +273,6 @@ class ScudCloud(QtGui.QMainWindow):
break
if not exists:
self.addWrapper(url)
- self.enableMenus(self.current().isConnected())
self.updateEditMenu()
def eventFilter(self, obj, event):
@@ -367,7 +358,7 @@ class ScudCloud(QtGui.QMainWindow):
total = 0
for i in range(0, self.stackedWidget.count()):
widget = self.stackedWidget.widget(i)
- messages = widget.count()
+ messages = widget.highlights
if messages == 0:
self.leftPane.stopAlert(widget.team())
else:
diff --git a/scudcloud-1.0/lib/wrapper.py b/scudcloud-1.0/lib/wrapper.py
index 084c631..9d1c348 100644
--- a/scudcloud-1.0/lib/wrapper.py
+++ b/scudcloud-1.0/lib/wrapper.py
@@ -10,7 +10,9 @@ from PyQt4.QtNetwork import QNetworkProxy
class Wrapper(QWebView):
+ highlights = 0
icon = None
+ name = ''
def __init__(self, window):
self.configure_proxy()
@@ -26,18 +28,6 @@ class Wrapper(QWebView):
self.linkClicked.connect(self._linkClicked)
self.page().featurePermissionRequested.connect(self.permissionRequested)
self.addActions()
- self.setupTimer()
-
- # Starting a timer that will check by server side reloads (which drops ScudCloud notification)
- def setupTimer(self):
- timer = QTimer(self)
- timer.timeout.connect(self.overrideNotifications)
- # Hope each 10 minutes will not be produce high CPU usage
- timer.setInterval(600000)
- timer.start()
-
- def overrideNotifications(self):
- self.call("overrideNotifications")
def permissionRequested(self, frame, feature):
self.page().setFeaturePermission(frame, feature, QWebPage.PermissionGrantedByUser)
@@ -102,9 +92,10 @@ class Wrapper(QWebView):
self.load(QUrl("https://"+qUrl.host()+"/messages/general"))
def _loadFinished(self, ok=True):
+ # Starting the webkit-JS bridge
self.page().currentFrame().addToJavaScriptWindowObject("desktop", self)
+ # Loading ScudCloud JS client
self.page().currentFrame().evaluateJavaScript(self.js)
- self.window.enableMenus(self.isConnected())
self.window.statusBar().hide()
def systemOpen(self, url):
@@ -127,9 +118,6 @@ class Wrapper(QWebView):
self.window.show()
self.call("preferences")
- def isConnected(self):
- return self.call("isConnected")
-
def createSnippet(self):
self.call("createSnippet")
@@ -148,9 +136,6 @@ class Wrapper(QWebView):
def about(self):
subprocess.call(('xdg-open', "https://github.com/raelgc/scudcloud"))
- def isConnected(self):
- return self.call("isConnected")
-
def listChannels(self):
return self.call("listChannels")
@@ -158,11 +143,10 @@ class Wrapper(QWebView):
self.call("join", menuitem.property_get("id"))
self.window.show()
- def count(self):
- try:
- return self.call("count")
- except:
- return 0
+ @QtCore.pyqtSlot(int, int)
+ def count(self, highlight, unread):
+ self.highlights = highlight
+ self.window.count()
@QtCore.pyqtSlot(str)
def populate(self, serialized):
@@ -170,8 +154,8 @@ class Wrapper(QWebView):
self.window.teams(data['teams'])
if self.window.current() == self:
self.window.quicklist(data['channels'])
- iconFile = data['teams'][0]['team_name']+'.png'
- filename, headers = request.urlretrieve(data['icon'], tempfile.gettempdir()+'/'+iconFile)
+ self.name = data['teams'][0]['team_name']
+ filename, headers = request.urlretrieve(data['icon'], tempfile.gettempdir()+'/'+self.name+'.png')
self.icon = filename
@QtCore.pyqtSlot(bool)
@@ -191,6 +175,9 @@ class Wrapper(QWebView):
@QtCore.pyqtSlot(str, str)
def sendMessage(self, title, message):
- self.window.notify(str(title).replace("New message from ", "").replace("New message in ", ""), str(message), self.icon)
+ erase = ['['+self.name.lower()+'] in ', '['+self.name.lower()+'] from ']
+ for s in erase:
+ title = str(title).replace(s, '', 1)
+ self.window.notify(title, str(message), self.icon)
diff --git a/scudcloud-1.0/resources/scudcloud.js b/scudcloud-1.0/resources/scudcloud.js
index 5e121c6..82a7621 100644
--- a/scudcloud-1.0/resources/scudcloud.js
+++ b/scudcloud-1.0/resources/scudcloud.js
@@ -1 +1 @@
-var ScudCloud={overrideNotifications:function(){TS.ui.growls.no_notifications=!1,TS.ui.growls.checkPermission=function(){return!0},TS.ui.growls.getPermissionLevel=function(){return"granted"},TS.ui.growls.show=function(n,e){desktop.sendMessage(n,e)},TS.ui.banner.close()},overrideConnect:function(){TS.ms.connected_sig.add(function(){ScudCloud.connect(!0)}),TS.ms.disconnected_sig.add(function(){ScudCloud.connect(!1)})},overrideBanner:function(){ScudCloud.showBanner=TS.ui.banner.show,TS.ui.banner.show=function(){ScudCloud.showBanner(),ScudCloud.overrideNotifications()}},connect:function(n){desktop.enableMenus(n),n&&(ScudCloud.overrideNotifications(),desktop.populate(JSON.stringify({channels:ScudCloud.listChannels(),teams:ScudCloud.listTeams(),icon:TS.model.team.icon.image_44})))},count:function(){var n=0;return $("span.unread_highlight").not(".hidden").each(function(){n+=new Number($(this).text().replace("+",""))}),n},createSnippet:function(){return TS.ui.snippet_dialog.start()},listChannels:function(){return TS.channels.getUnarchivedChannelsForUser()},listTeams:function(){var n=TS.getAllTeams();return n[0].team_icon={image_44:TS.model.team.icon.image_44},n},quicklist:function(){desktop.quicklist(ScudCloud.listChannels())},join:function(n){return TS.channels.join(n)},setClipboard:function(n){TS.client.ui.file_pasted_sig.dispatch(n,TS.model.shift_key_pressed)},preferences:function(){return TS.ui.prefs_dialog.start()},addTeam:function(){document.location=TS.boot_data.signin_url},getCurrentTeam:function(){var n=TS.getAllTeams();if(null!=n)for(var e=0;n.length;e++)if(n[e].team_url==TS.boot_data.team_url)return n[e].id;return""},logout:function(){document.location=TS.boot_data.logout_url},help:function(){return TS.help_dialog.start()},isConnected:function(){return"undefined"!=typeof TS&&"undefined"!=typeof TS.model&&TS.model.ms_connected}};"undefined"!=typeof TS&&(document.onpaste=function(){desktop.pasted(!1)},ScudCloud.overrideNotifications(),ScudCloud.overrideConnect(),ScudCloud.overrideBanner());
+ScudCloud={unloaded:!0,hasPreference:function(n){return!1},getPreference:function(n){return!1},setPreference:function(n,e){return!1},canShowHtmlNotifications:function(){return!1},call:function(n,e){switch(ScudCloud.log(n),n){case"reload":return ScudCloud.reload();case"didStartLoading":return ScudCloud.didStartLoading();case"didFinishLoading":return ScudCloud.didFinishLoading();case"setConnectionStatus":return ScudCloud.setConnectionStatus(e);case"notify":return ScudCloud.notify(e);case"setBadgeCount":return ScudCloud.setBadgeCount(e);case"displayTeam":return ScudCloud.displayTeam(e)}return!1},reload:function(){window.location.reload()},didStartLoading:function(){},didFinishLoading:function(){TS.ui.banner.close(),ScudCloud.populate(),ScudCloud.unloaded=!1},setConnectionStatus:function(n){switch(n){case"online":desktop.enableMenus(!0);break;default:desktop.enableMenus(!1)}},notify:function(n){desktop.sendMessage(n.title,n.content)},setBadgeCount:function(n){desktop.count(n.all_unread_highlights_cnt,n.all_unread_cnt)},displayTeam:function(n){},log:function(n){console.log("ScudCloud."+n)},populate:function(){desktop.populate(JSON.stringify({channels:ScudCloud.listChannels(),teams:ScudCloud.listTeams(),icon:TS.model.team.icon.image_44}))},createSnippet:function(){return TS.ui.snippet_dialog.start()},listChannels:function(){return TS.channels.getUnarchivedChannelsForUser()},listTeams:function(){var n=TS.getAllTeams();return n[0].team_icon={image_44:TS.model.team.icon.image_44},n},quicklist:function(){desktop.quicklist(ScudCloud.listChannels())},join:function(n){return TS.channels.join(n)},setClipboard:function(n){TS.client.ui.file_pasted_sig.dispatch(n,TS.model.shift_key_pressed)},preferences:function(){return TS.ui.prefs_dialog.start()},addTeam:function(){document.location=TS.boot_data.signin_url},getCurrentTeam:function(){var n=TS.getAllTeams();if(null!=n)for(var e=0;n.length;e++)if(n[e].team_url==TS.boot_data.team_url)return n[e].id;return""},logout:function(){document.location=TS.boot_data.logout_url},help:function(){return TS.help_dialog.start()}},document.onpaste=function(n){desktop.pasted(!1)},window.winssb=TSSSB=ScudCloud,ScudCloud.unloaded&&ScudCloud.didFinishLoading();
diff --git a/scudcloud-1.0/scudcloud-src.js b/scudcloud-1.0/scudcloud-src.js
index c16a0b9..3bb9beb 100644
--- a/scudcloud-1.0/scudcloud-src.js
+++ b/scudcloud-1.0/scudcloud-src.js
@@ -1,33 +1,74 @@
-var ScudCloud = {
- overrideNotifications: function(){
- TS.ui.growls.no_notifications = false;
- TS.ui.growls.checkPermission = function() { return true; };
- TS.ui.growls.getPermissionLevel = function() { return 'granted'; };
- TS.ui.growls.show = function(j,f,o,p){ desktop.sendMessage(j,f); };
- TS.ui.banner.close();
+
+ScudCloud = {
+ unloaded: true,
+ // App functions
+ hasPreference: function(name){
+ return false;
+ },
+ getPreference: function(name){
+ return false;
+ },
+ setPreference: function(name, value){
+ return false;
+ },
+ canShowHtmlNotifications: function(){
+ // Ubuntu cannot display HTML notifications
+ return false;
+ },
+ // TSSSB.call
+ call: function(name, args){
+ ScudCloud.log(name);
+ switch(name){
+ case "reload":
+ return ScudCloud.reload();
+ case "didStartLoading":
+ return ScudCloud.didStartLoading();
+ case "didFinishLoading":
+ return ScudCloud.didFinishLoading();
+ case "setConnectionStatus":
+ return ScudCloud.setConnectionStatus(args);
+ case "notify":
+ return ScudCloud.notify(args);
+ case "setBadgeCount":
+ return ScudCloud.setBadgeCount(args);
+ case "displayTeam":
+ return ScudCloud.displayTeam(args);
+ }
+ return false;
+ },
+ // TSSSB.call implementations
+ reload: function(){
+ window.location.reload();
},
- overrideConnect: function(){
- TS.ms.connected_sig.add(function(){ScudCloud.connect(true);});
- TS.ms.disconnected_sig.add(function(){ScudCloud.connect(false);});
+ didStartLoading: function(){
},
- overrideBanner: function(){
- ScudCloud.showBanner = TS.ui.banner.show;
- TS.ui.banner.show = function(){ ScudCloud.showBanner(); ScudCloud.overrideNotifications(); };
+ didFinishLoading: function(){
+ TS.ui.banner.close();
+ ScudCloud.populate();
+ ScudCloud.unloaded = false;
},
- connect: function(b){
- desktop.enableMenus(b);
- if(b){
- ScudCloud.overrideNotifications();
- desktop.populate(JSON.stringify({'channels': ScudCloud.listChannels(), 'teams': ScudCloud.listTeams(), 'icon': TS.model.team.icon.image_44}));
+ setConnectionStatus: function(status){
+ // "online", "connecting", "offline"
+ switch(status){
+ case "online": desktop.enableMenus(true); break;
+ default: desktop.enableMenus(false);
}
},
- count: function(){
- var total=0;
- $('span.unread_highlight').not('.hidden').each(function(i){
- total+= new Number($(this).text().replace('+','')); }
- );
- return total;
- },
+ notify: function(args){
+ desktop.sendMessage(args.title, args.content);
+ },
+ setBadgeCount: function(args){
+ desktop.count(args.all_unread_highlights_cnt, args.all_unread_cnt);
+ },
+ displayTeam: function(id){
+ },
+ // ScudCloud internal functions
+ log: function(name){
+ console.log("ScudCloud."+name);
+ },
+ populate: function(){
+ desktop.populate(JSON.stringify({'channels': ScudCloud.listChannels(), 'teams': ScudCloud.listTeams(), 'icon': TS.model.team.icon.image_44}));
+ },
createSnippet: function(){
return TS.ui.snippet_dialog.start();
},
@@ -69,14 +110,11 @@ var ScudCloud = {
},
help: function(){
return TS.help_dialog.start();
- },
- isConnected: function(){
- return "undefined" != typeof TS && "undefined" != typeof TS.model && TS.model.ms_connected;
- }
+ }
};
-if("undefined" != typeof TS){
- document.onpaste = function(e){desktop.pasted(false);};
- ScudCloud.overrideNotifications();
- ScudCloud.overrideConnect();
- ScudCloud.overrideBanner();
+document.onpaste = function(e){desktop.pasted(false);};
+window.winssb = TSSSB = ScudCloud;
+// Sometimes didFinishLoading is not loaded
+if(ScudCloud.unloaded){
+ ScudCloud.didFinishLoading();
}