Skip to content

Commit

Permalink
Badge counter
Browse files Browse the repository at this point in the history
  • Loading branch information
muriloventuroso committed Jul 25, 2018
1 parent 4e65c90 commit 53f08ab
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
6 changes: 6 additions & 0 deletions data/com.github.muriloventuroso.easyssh.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<binary>com.github.muriloventuroso.easyssh</binary>
</provides>
​<releases>
<release version="1.2.8" date="2018-07-25">
<description>
<p>Bugfix</p>
<p>Badge counter for unread changes in terminal</p>
</description>
</release>
<release version="1.2.7" date="2018-07-16">
<description>
<p>Update for Juno</p>
Expand Down
7 changes: 4 additions & 3 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
com.github.muriloventuroso.easyssh (1.2.7) precise; urgency=low
com.github.muriloventuroso.easyssh (1.2.8) precise; urgency=low

* Release for Juno
* Bugfix
* Badge counter for unread changes in terminal

-- Murilo Venturoso <[email protected]> Mon, 16 Jul 2018 09:46:00 -0300
-- Murilo Venturoso <[email protected]> Wed, 25 Jul 2018 10:23:00 -0300
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ executable(
dependency('json-glib-1.0'),
dependency('vte-2.91', version: '>0.52'),
dependency('gee-0.8'),
dependency('unity'),
meson.get_compiler('c').find_library('m', required : false)
],
install: true
Expand Down
12 changes: 10 additions & 2 deletions src/Views/SourceListView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace EasySSH {
}
n.current = n_tab;
window.current_terminal = term.term;
term.set_selected();
term.term.grab_focus();
});

Expand Down Expand Up @@ -123,7 +124,8 @@ namespace EasySSH {
var box = (TerminalBox)notebook.current.page;
window.current_terminal = (TerminalWidget)box.term;
window.current_terminal.grab_focus();
box.tab.icon = null;
box.set_selected();
box.remove_badge ();
}
}
var all_read = true;
Expand Down Expand Up @@ -159,6 +161,7 @@ namespace EasySSH {
n.insert_tab (n_tab, next_tab);
n.current = n_tab;
window.current_terminal = term.term;
term.set_selected();
term.term.grab_focus();
}
}
Expand Down Expand Up @@ -203,6 +206,7 @@ namespace EasySSH {
n.insert_tab (n_tab, next_tab );
n.current = n_tab;
window.current_terminal = term.term;
term.set_selected();
});
n.tab_removed.connect(() => {
if(n.n_tabs == 0) {
Expand All @@ -219,14 +223,18 @@ namespace EasySSH {

private void on_tab_moved (Granite.Widgets.Tab tab, int x, int y) {
var t = get_term_widget (tab);
var box = (TerminalBox)tab.page;
window.current_terminal = t;
tab.icon = null;
box.set_selected();
box.remove_badge ();
}
private void on_tab_switched (Granite.Widgets.Tab? old_tab, Granite.Widgets.Tab new_tab) {
if(Type.from_instance(new_tab.page).name() == "EasySSHTerminalBox") {
var t = get_term_widget (new_tab);
window.current_terminal = t;
var box = (TerminalBox)new_tab.page;
box.set_selected();
box.remove_badge ();
box.dataHost.item.icon = null;
new_tab.icon = null;
var all_read = true;
Expand Down
32 changes: 29 additions & 3 deletions src/Widgets/TerminalBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace EasySSH {
public TerminalWidget term;
public MainWindow window { get; construct; }
public Granite.Widgets.Tab tab {get; set;}
private bool unread_changes;

public TerminalBox (Host host, Granite.Widgets.DynamicNotebook notebook, MainWindow window) {
Object (
Expand All @@ -40,6 +41,7 @@ namespace EasySSH {

construct {
open_dialog = false;
unread_changes = false;
var scroller = new Gtk.ScrolledWindow(null, null);
term = new TerminalWidget(window, dataHost);
term.set_scrollback_lines(-1);
Expand All @@ -54,6 +56,10 @@ namespace EasySSH {
set_vadjustment(term.get_vadjustment());
}

public void set_selected (){
unread_changes = false;
}

public void start_connection() {
var builder = new StringBuilder ();
builder.append("ssh " + dataHost.username + "@" + dataHost.host);
Expand All @@ -74,14 +80,34 @@ namespace EasySSH {
term.feed_child(cmd.to_utf8 ());
}

public void add_badge (){
var entry = Unity.LauncherEntry.get_for_desktop_id ("com.github.muriloventuroso.easyssh.desktop");
entry.count_visible = true;
entry.count = entry.count + 1;
unread_changes = true;
dataHost.item.icon = new GLib.ThemedIcon ("mail-mark-important");
tab.icon = new GLib.ThemedIcon ("mail-mark-important");
}
public void remove_badge (){
var entry = Unity.LauncherEntry.get_for_desktop_id ("com.github.muriloventuroso.easyssh.desktop");
if(entry.count_visible == true){
entry.count = entry.count - 1;
if(entry.count == 0){
entry.count_visible = false;
}
}
unread_changes = false;
dataHost.item.icon = new GLib.ThemedIcon ("mail-mark-important");
tab.icon = null;
}

public void on_change_terminal (Vte.Terminal terminal) {
string? res = terminal.get_text(null, null);
if(res != null) {
string[] lines = res.split("\n");
string[] ret = {};
if(term != window.current_terminal) {
dataHost.item.icon = new GLib.ThemedIcon ("mail-mark-important");
tab.icon = new GLib.ThemedIcon ("mail-mark-important");
if(term != window.current_terminal && unread_changes == false) {
add_badge ();
}
foreach (unowned string str in lines) {
if(str != "") {
Expand Down

0 comments on commit 53f08ab

Please sign in to comment.