Skip to content

Commit

Permalink
Added 'display syncthing-notify output' option to menu. Ref #160
Browse files Browse the repository at this point in the history
  • Loading branch information
kozec committed Jun 1, 2015
1 parent 7e471f5 commit e8997b6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
19 changes: 19 additions & 0 deletions app.glade
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@
</object>
</child>

<child if="is_windows">
<object class="GtkImageMenuItem" id="menu-inotify-output">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Display Syncthing-Inotify Output</property>
<property name="use_underline">True</property>
<property name="always_show_image">True</property>
<property name="image">menu-inotify-image</property>
<property name="action-name">app.inotify_output</property>
</object>
</child>

<child>
<object class="GtkSeparatorMenuItem" id="menu-separator15">
<property name="visible">True</property>
Expand Down Expand Up @@ -852,6 +864,13 @@
<property name="icon_name">utilities-terminal</property>
</object>

<object class="GtkImage" id="menu-inotify-image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_size">1</property>
<property name="icon_name">utilities-terminal</property>
</object>

<object class="GtkImage" id="menu-exit-image">
<property name="visible">True</property>
<property name="can_focus">False</property>
Expand Down
17 changes: 17 additions & 0 deletions syncthing_gtk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def add_simple_action(name, callback):
return action
add_simple_action('webui', self.cb_menu_webui)
add_simple_action('daemon_output', self.cb_menu_daemon_output).set_enabled(False)
add_simple_action('inotify_output', self.cb_menu_inotify_output)
add_simple_action('preferences', self.cb_menu_ui_settings)
add_simple_action('about', self.cb_about)
add_simple_action('quit', self.cb_exit)
Expand Down Expand Up @@ -1736,6 +1737,22 @@ def cb_menu_daemon_output(self, *a):
d = DaemonOutputDialog(self, self.process)
d.show(self["window"])

def cb_menu_inotify_output(self, *a):
# Available & called only on Windows
if hasattr(self.watcher, "proc") and not self.watcher.proc is None:
d = DaemonOutputDialog(self, self.watcher.proc)
d.show(self["window"], _("Syncthing-Inotify Output"))
else:
d = Gtk.MessageDialog(
self["window"],
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE,
_("Syncthing-Inotify is unavailable or failed to start")
)
r = d.run()
d.hide()
d.destroy()

def cb_statusicon_click(self, *a):
""" Called when user clicks on status icon """
# Hide / show main window
Expand Down
4 changes: 3 additions & 1 deletion syncthing_gtk/daemonoutputdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ def show_with_lines(self, lines, parent=None):
self["dialog"].show_all()
self["tvOutput"].get_buffer().set_text("\n".join(lines))

def show(self, parent=None):
def show(self, parent=None, title=None):
if not parent is None:
self["dialog"].set_transient_for(parent)
if not title is None:
self["dialog"].set_title(title)
self["dialog"].show_all()
self["tvOutput"].get_buffer().set_text("\n".join(self.proc.get_output()))
self.handler = self.proc.connect('line', self.cb_line)
Expand Down
9 changes: 2 additions & 7 deletions syncthing_gtk/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ def __init__(self, app, daemon):
self.watched_ids = []
self.app = app
self.proc = None
self.log = logging.getLogger("Watcher")

def watch(self, id, path):
self.watched_ids += [id]
Expand All @@ -279,19 +278,15 @@ def start(self):
"-home", os.path.join(get_config_dir(), "syncthing"),
"-folders", ",".join(self.watched_ids)
])
self.proc.connect("line", self._on_output)
self.proc.connect("exit", self._on_exit)
self.proc.connect("failed", self._on_failed)
self.proc.start()

def _on_output(self, proc, message):
self.log.info(message)

def _on_exit(self, proc, code):
self.log.warning("syncthing-inotify exited with code %s" % (code,))
log.warning("syncthing-inotify exited with code %s" % (code,))

def _on_failed(self, proc, error):
self.log.error("Failed to start syncthing-inotify: %s" % (error,))
log.error("Failed to start syncthing-inotify: %s" % (error,))
self.proc = None

if os.path.exists(exe):
Expand Down

0 comments on commit e8997b6

Please sign in to comment.