Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Dwyer committed Dec 14, 2013
2 parents 22d4a08 + 05026f9 commit 5286689
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 62 deletions.
11 changes: 9 additions & 2 deletions TODO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ TODO

* exceptions to recurrent events
* use a writable calendar for as a default calendar
* make read-only calendars static

* khal default ui:
* show which calendar/resource an events belongs to

* ikhal:
* new weeks should be loaded into the walker
* make it look prettier
* edit recurrence rules
* show which resource an event belongs to and make it editable
* edit recurrence rules
* do not loose chosen day highlight when focussing on Event Column
* warning on pressing 'esc' in event editor when event has changed (including
options to save and discard edit)



DONE
Expand All @@ -32,6 +38,7 @@ DONE
* help text
* new event on pressing n in calendar
* reload EventList after editing or adding an event
* show which resource/calendar an event belongs to and make it editable
* prevent user from leaving EventEditor by pressing left or top (at least when event has been modified)

* layout should probably be::
Expand Down
12 changes: 12 additions & 0 deletions doc/webpage/src/30c3.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pycarddav and khal at 30c3
==========================
:date: 13.12.2013
:category: News
:tags: announcement

If you will be 30C3_ and would like to discuss the faults and merits of khal or
pycarddav, commandline calendaring/addressbooking in general, your ideas or just
have a beer or mate, I'd love to meet up. You can find my contact details under
*Feedback*.

.. _30C3: https://events.ccc.de/congress/2013/wiki/Main_Page
8 changes: 8 additions & 0 deletions khal.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,12 @@ longdateformat: %d.%m.%Y
datetimeformat: %d.%m. %H:%M
longdatetimeformat: %d.%m.%Y %H:%M

# the encoding of your terminal emulator
# encoding: utf-8

# by default, khal uses unicode symbols to display certain event properties set
# to False if you do not want this (e.g. your character set does not support
# these symbols
# unicode_symbols: True

DEBUG: 0
5 changes: 3 additions & 2 deletions khal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ def __init__(self, parser):
('dateformat', '', None),
('longdateformat', '', None),
('datetimeformat', '', None),
('longdatetimeformat', '', None)
('longdatetimeformat', '', None),
('encoding', 'utf-8', None),
('unicode_symbols', 'True', self._parse_bool_string)
]


Expand Down Expand Up @@ -346,7 +348,6 @@ def check(self, ns):
else:
ns.sync.accounts = accounts


for account in ns.accounts:
if account.type == 'caldav':
account.readonly = False
Expand Down
7 changes: 5 additions & 2 deletions khal/aux.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ def generate_random_uid():

def construct_event(date_list, timeformat, dateformat, longdateformat,
datetimeformat, longdatetimeformat, defaulttz,
defaulttimelen=60, defaultdatelen=1):
defaulttimelen=60, defaultdatelen=1, encoding='utf-8'):
"""takes a list of strings and constructs a vevent from it,
:param encoding: the encoding of your terminal, should be a valid encoding
:type encoding: str
can be either of this:
* datetime datetime description
start and end datetime specified, if no year is given, this year
Expand Down Expand Up @@ -197,7 +200,7 @@ def construct_event(date_list, timeformat, dateformat, longdateformat,
event = icalendar.Event()
event.add('dtstart', dtstart)
event.add('dtend', dtend)
event.add('summary', ' '.join(date_list))
event.add('summary', ' '.join(date_list).decode(encoding))
event.add('uid', generate_random_uid())
return event

Expand Down
36 changes: 21 additions & 15 deletions khal/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@
import xdg.BaseDirectory

from .model import Event
from .status import OK, NEW, CHANGED, DELETED, NEWDELETE, CALCHANGED

OK = 0 # not touched since last sync
NEW = 1 # new card, needs to be created on the server
CHANGED = 2 # properties edited or added (news to be pushed to server)
DELETED = 9 # marked for deletion (needs to be deleted on server)
NEWDELETE = 11 # card should be deleted on exit (not yet on the server)

# TODO fix that event/vevent mess


class UpdateFailed(Exception):
Expand Down Expand Up @@ -245,6 +243,7 @@ def update(self, vevent, account_name, href='', etag='', status=OK):
:type status: one of backend.OK, backend.NEW, backend.CHANGED,
backend.DELETED
"""
if not isinstance(vevent, icalendar.cal.Event):
ical = icalendar.Event.from_ical(vevent)
Expand Down Expand Up @@ -372,11 +371,10 @@ def delete(self, href, account_name):
removes the event from the db,
returns nothing
"""
stuple = (href, )
logging.debug("locally deleting " + str(href))
for dbname in [account_name + '_d', account_name + '_dt', account_name]:
sql_s = 'DELETE FROM {0} WHERE href = ? ;'.format(dbname)
self.sql_ex(sql_s, (href ,))
self.sql_ex(sql_s, (href, ))

def get_all_href_from_db(self, accounts):
"""returns a list with all hrefs
Expand All @@ -397,10 +395,12 @@ def get_all_href_from_db_not_new(self, accounts):
result = result + [(href[0], account) for href in hrefs]
return result

def get_time_range(self, start, end, account_name, color='', readonly=False):
def get_time_range(self, start, end, account_name, color='', readonly=False,
unicode_symbols=True, show_deleted=True):
"""returns
:type start: datetime.datetime
:type end: datetime.datetime
:param deleted: include deleted events in returned lsit
"""
start = time.mktime(start.timetuple())
end = time.mktime(end.timetuple())
Expand All @@ -417,13 +417,15 @@ def get_time_range(self, start, end, account_name, color='', readonly=False):
event = self.get_vevent_from_db(href, account_name,
start=start, end=end,
color=color,
readonly=readonly)
event_list.append(event)
readonly=readonly,
unicode_symbols=unicode_symbols)
if show_deleted or event.status not in [DELETED, CALCHANGED, NEWDELETE]:
event_list.append(event)

return event_list

def get_allday_range(self, start, end=None, account_name=None,
color='', readonly=False):
color='', readonly=False, unicode_symbols=True, show_deleted=True):
if account_name is None:
raise Exception('need to specify an account_name')
strstart = start.strftime('%Y%m%d')
Expand All @@ -445,8 +447,10 @@ def get_allday_range(self, start, end=None, account_name=None,
vevent = self.get_vevent_from_db(href, account_name,
start=start, end=end,
color=color,
readonly=readonly)
event_list.append(vevent)
readonly=readonly,
unicode_symbols=unicode_symbols)
if show_deleted or vevent.status not in [DELETED, CALCHANGED, NEWDELETE]:
event_list.append(vevent)
return event_list

def hrefs_by_time_range_datetime(self, start, end, account_name, color=''):
Expand Down Expand Up @@ -484,7 +488,8 @@ def hrefs_by_time_range(self, start, end, account_name):
self.hrefs_by_time_range_datetime(start, end, account_name)))

def get_vevent_from_db(self, href, account_name, start=None, end=None,
readonly=False, color=lambda x: x):
readonly=False, color=lambda x: x,
unicode_symbols=True):
"""returns the Event matching href, if start and end are given, a
specific Event from a Recursion set is returned, the Event as saved in
the db
Expand All @@ -500,7 +505,8 @@ def get_vevent_from_db(self, href, account_name, start=None, end=None,
href=href,
account=account_name,
status=result[0][1],
readonly=readonly)
readonly=readonly,
unicode_symbols=unicode_symbols)

def get_changed(self, account_name):
"""returns list of hrefs of locally edited vcards
Expand Down
26 changes: 18 additions & 8 deletions khal/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ def __init__(self, conf, sync_account_name):
self.dbtool.delete(href, sync_account.name)




class Display(Controller):
def __init__(self, conf):
super(Display, self).__init__(conf)
Expand All @@ -161,6 +159,7 @@ def __init__(self, conf):
daylist = [(today, 'Today:'), (tomorrow, 'Tomorrow:')]
event_column = list()
for day, dayname in daylist:
# TODO unify allday and datetime events
start = datetime.datetime.combine(day, datetime.time.min)
end = datetime.datetime.combine(day, datetime.time.max)

Expand All @@ -171,10 +170,20 @@ def __init__(self, conf):
readonly = conf.accounts[account]['readonly']
color = conf.accounts[account]['color']
all_day_events += self.dbtool.get_allday_range(
day, account_name=account, color=color, readonly=readonly)
events += self.dbtool.get_time_range(start, end, account,
color=color,
readonly=readonly)
day,
account_name=account,
color=color,
readonly=readonly,
unicode_symbols=conf.default.unicode_symbols,
show_deleted=False)
events += self.dbtool.get_time_range(
start,
end,
account,
color=color,
readonly=readonly,
unicode_symbols=conf.default.unicode_symbols,
show_deleted=False)
for event in all_day_events:
event_column.append(aux.colored(event.compact(day), event.color))
events.sort(key=lambda e: e.start)
Expand All @@ -188,7 +197,7 @@ def __init__(self, conf):
calendar_column = calendar_column + missing * [25 * ' ']

rows = [' '.join(one) for one in izip_longest(calendar_column, event_column, fillvalue='')]
print('\n'.join(rows))
print('\n'.join(rows).encode(conf.default.encoding))


class NewFromString(Controller):
Expand All @@ -201,7 +210,8 @@ def __init__(self, conf):
conf.default.longdateformat,
conf.default.datetimeformat,
conf.default.longdatetimeformat,
conf.default.local_timezone)
conf.default.local_timezone,
encoding=conf.default.encoding)
self.dbtool.update(event, conf.sync.accounts.pop(), status=backend.NEW)


Expand Down
33 changes: 25 additions & 8 deletions khal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@

import icalendar

from .status import OK, NEW, CHANGED, DELETED, NEWDELETE, CALCHANGED


class Event(object):
def __init__(self, ical, status=0, href=None, account=None, local_tz=None,
default_tz=None, start=None, end=None, color=None,
readonly=False):
readonly=False, unicode_symbols=True, dbtool=None):
self.vevent = icalendar.Event.from_ical(ical)
if account is None:
raise TypeError('account must not be None')
Expand All @@ -40,6 +43,20 @@ def __init__(self, ical, status=0, href=None, account=None, local_tz=None,
self.href = href
self.account = account
self.readonly = readonly
self.unicode_symbols = unicode_symbols
self.dbtool = dbtool

if unicode_symbols:
self.recurstr = u' ⟳'
self.rangestr = u'↔ '
self.rangestopstr = u'⇥ '
self.rangestartstr = u'↦ '
else:
self.recurstr = u' R'
self.rangestr = u' <->'
self.rangestopstr = u' ->|'
self.rangestartstr = u' |->'

if start is not None:
if isinstance(self.vevent['dtstart'].dt, datetime.datetime):
self.allday = False # TODO detect allday even if start is None
Expand Down Expand Up @@ -84,11 +101,11 @@ def recur(self):
return 'RRULE' in self.vevent.keys()

def compact(self, day, timeformat='%H:%M'):
if self.status == 9:
if self.status == DELETED:
status = 'D '
elif self.status == 11:
elif self.status == NEWDELETE:
status = 'X '
elif self.status == 1:
elif self.status == NEW:
status = 'N '
else:
status = ''
Expand All @@ -100,21 +117,21 @@ def compact(self, day, timeformat='%H:%M'):

def _compact_allday(self, day):
if 'RRULE' in self.vevent.keys():
recurstr = u' ⟳'
recurstr = self.recurstr
else:
recurstr = ''
if self.start < day and self.end > day + datetime.timedelta(days=1):
# event started in the past and goes on longer than today:
rangestr = u'↔ '
rangestr = self.rangestr
pass
elif self.start < day:
# event started in past
rangestr = u'⇥ '
rangestr = self.rangestopstr
pass

elif self.end > day + datetime.timedelta(days=1):
# event goes on longer than today
rangestr = u'↦ '
rangestr = self.rangestartstr
else:
rangestr = ''
return rangestr + self.summary + recurstr
Expand Down
7 changes: 7 additions & 0 deletions khal/status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

OK = 0 # not touched since last sync
NEW = 1 # new card, needs to be created on the server
CHANGED = 2 # properties edited or added (news to be pushed to server)
CALCHANGED = 8 # copied to another account, should be deleted in this account
DELETED = 9 # marked for deletion (needs to be deleted on server)
NEWDELETE = 11 # card should be deleted on exit (not yet on the server)
Loading

0 comments on commit 5286689

Please sign in to comment.