Skip to content

Commit

Permalink
Merge 4ef4596 into e9fcae0
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Jan 30, 2024
2 parents e9fcae0 + 4ef4596 commit cd62d17
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ Changelog

- Add the ability to change the last entry using Ctrl+Shift+BackSpace (GH: #247).

- There's a new hidden setting to override the text editor (GH: #113).
You can use ``gsettings set org.gtimelog editor gvim`` (or dconf-editor).
More complicated settings like ``'gnome-terminal -e "vim %s"'`` also work
(``%s`` is replaced with the file name).


0.11.3 (2019-04-23)
~~~~~~~~~~~~~~~~~~~
Expand Down
Binary file modified src/gtimelog/data/gschemas.compiled
Binary file not shown.
8 changes: 7 additions & 1 deletion src/gtimelog/data/org.gtimelog.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

<key name="log-order" enum="org.gtimelog.LogOrder">
<default>"start-time"</default>
<summary>Log Tasks/Groups order</summary>
<summary>Log Tasks/Groups order</summary>
<description>Order of tasks and groups in Log view</description>
</key>

Expand Down Expand Up @@ -163,6 +163,12 @@
<description>If true, the task entry will use the standard GTK+ completion. If false, it'll only use the custom prefix completion on PageUp/PageDown.</description>
</key>

<key name="editor" type="s">
<default>""</default>
<summary>Text editor to use for editing timelog.txt or tasks.txt</summary>
<description>If blank, gtimelog will use your system default editor. If the value contains '%s', it will be replaced with the filename, otherwise the filename will be appended as an extra argument.</description>
</key>

</schema>

</schemalist>
60 changes: 45 additions & 15 deletions src/gtimelog/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""An application for keeping track of your time."""
import shlex
import subprocess
import sys
import time

Expand Down Expand Up @@ -309,9 +311,36 @@ def do_startup(self):
def on_quit(self, action, parameter):
self.quit()

@staticmethod
def prepare_args(program, filename):
args = shlex.split(program)
had_percent_s = False
for i, arg in enumerate(args):
if '%s' in arg:
args[i] = arg.replace('%s', filename)
had_percent_s = True
if not had_percent_s:
args.append(filename)
return args

def run_in_background(self, program, filename):
args = self.prepare_args(program, filename)
try:
subprocess.Popen(args)
except OSError as e:
log.error(_("Couldn't execute %s: %s"), args, e)
window = self.get_active_window()
if window is not None:
# XXX: info_bar is only visible in reporting mode!!!
window.show_info_bar(_("Couldn't execute {}: {}").format(args, e))

def open_in_editor(self, filename):
self.create_if_missing(filename)
if os.name == 'nt':
gsettings = Gio.Settings.new("org.gtimelog")
editor = gsettings.get_string('editor')
if editor:
self.run_in_background(editor, filename)
elif os.name == 'nt':
os.startfile(filename)
else:
uri = GLib.filename_to_uri(filename, None)
Expand All @@ -325,8 +354,9 @@ def on_edit_tasks(self, action, parameter):
gsettings = Gio.Settings.new("org.gtimelog")
if gsettings.get_boolean('remote-task-list'):
uri = gsettings.get_string('task-list-edit-url')
if self.get_active_window() is not None:
self.get_active_window().editing_remote_tasks = True
window = self.get_active_window()
if window is not None:
window.editing_remote_tasks = True
Gtk.show_uri(None, uri, Gdk.CURRENT_TIME)
else:
filename = Settings().get_task_list_file()
Expand All @@ -335,8 +365,9 @@ def on_edit_tasks(self, action, parameter):
def on_refresh_tasks(self, action, parameter):
gsettings = Gio.Settings.new("org.gtimelog")
if gsettings.get_boolean('remote-task-list'):
if self.get_active_window() is not None:
self.get_active_window().download_tasks()
window = self.get_active_window()
if window is not None:
window.download_tasks()

def create_if_missing(self, filename):
if not os.path.exists(filename):
Expand Down Expand Up @@ -747,20 +778,20 @@ def update_send_report_availability(self, *args):

def update_already_sent_indication(self, *args):
if self.report_view.report_status == 'sent':
self.infobar_label.set_text(_("Report already sent"))
self.infobar.show()
# https://github.com/gtimelog/gtimelog/issues/89
self.infobar.queue_resize()
self.show_info_bar(_("Report already sent"))
elif self.report_view.report_status == 'sent-elsewhere':
self.infobar_label.set_text(
self.show_info_bar(
_("Report already sent (to {})").format(
self.report_view.report_sent_to))
self.infobar.show()
# https://github.com/gtimelog/gtimelog/issues/89
self.infobar.queue_resize()
else:
self.infobar.hide()

def show_info_bar(self, text):
self.infobar_label.set_text(text)
self.infobar.show()
# https://github.com/gtimelog/gtimelog/issues/89
self.infobar.queue_resize()

def cancel_tasks_download(self, hide=True):
if self._download:
self.cancellable.cancel()
Expand Down Expand Up @@ -1080,9 +1111,8 @@ def on_send_report(self, action, parameter):
try:
self.send_email(sender, recipient, subject, body)
except EmailError as e:
self.infobar_label.set_text(
self.show_info_bar(
_("Couldn't send email to {}: {}.").format(recipient, e))
self.infobar.show()
else:
self.record_sent_email(self.report_view.time_range,
self.report_view.date,
Expand Down

0 comments on commit cd62d17

Please sign in to comment.