Permalink
Browse files

Improved handling of events loading.

Updated TODO.
BUgfix here and there.
  • Loading branch information...
1 parent e2eb6e4 commit 05b351a78a7f14f8e5ac8a7b68abfcad796508df @cando committed May 17, 2012
Showing with 197 additions and 115 deletions.
  1. +1 −1 data/gtk-style.css
  2. +11 −2 src/activities.vala
  3. +2 −2 src/dayview.vala
  4. +14 −7 src/loading.vala
  5. +95 −71 src/timelineview.vala
  6. +8 −0 src/utils.vala
  7. +66 −32 src/zg-backend.vala
View
@@ -101,7 +101,7 @@ GtkScale.mark {
border-radius: 10px;
}
-.osd GtkButton GtkLabel {
+.osd GtkLabel {
font-size: 11;
font-weight: bold;
color: white;
View
@@ -90,8 +90,17 @@ private class Journal.GenericActivity : Object {
private string create_display_uri () {
string home = Environment.get_home_dir ();
- string uri = this.subject.get_origin ().split ("://")[1];
- return uri.replace (home, "~");
+ string origin = this.subject.get_origin ();
+ string uri, display_uri;
+ if (origin != null) {
+ uri = origin.split ("://")[1];
+ display_uri = uri.replace (home, "~");
+ }
+ else {
+ uri = this.uri.split ("://")[1];
+ display_uri = uri;
+ }
+ return display_uri;
}
//The code related to this function is extracted, ported and adapted
View
@@ -79,7 +79,7 @@ private class Journal.DayView: Box{
setup_ui ();
- app.backend.events_loaded.connect (() => {
+ app.backend.events_loaded.connect ((tr) => {
load_events ();
});
}
@@ -101,7 +101,7 @@ private class Journal.DayView: Box{
public void load_events () {
for (int i = 0; i < num_days; i++) {
var key = day_views[i].get_day_string ();
- day_views[i].load_events (app.backend.get_events_for_day (key));
+ day_views[i].load_events (app.backend.get_events_for_date (key));
}
}
View
@@ -49,40 +49,47 @@ private class Journal.LoadingActor: GLib.Object {
}
}
-public class Journal.OSDLabel: GLib.Object {
+public class Journal.OSDLabel: Object{
public GtkClutter.Actor actor;
private Clutter.Stage stage;
private Button button;
+ private uint timeout_id;
public OSDLabel (Clutter.Stage stage) {
this.stage = stage;
+ timeout_id = 0;
button = new Button ();
button.sensitive = false;
-
+
actor = new GtkClutter.Actor.with_contents (button);
actor.get_widget ().get_style_context ().add_class ("osd");
actor.add_constraint (new Clutter.AlignConstraint (stage, Clutter.AlignAxis.X_AXIS, 0.5f));
actor.add_constraint (new Clutter.AlignConstraint (stage, Clutter.AlignAxis.Y_AXIS, 0.8f));
- button.show ();
+ button.show();
actor.hide ();
}
public void set_message_and_show (string message) {
button.label = message;
- actor.show ();
- actor.animate (Clutter.AnimationMode.EASE_OUT_CUBIC,
+ if (timeout_id != 0)
+ Source.remove (timeout_id);
+ else {
+ actor.show ();
+ actor.animate (Clutter.AnimationMode.EASE_OUT_CUBIC,
500,
"opacity", 255);
- Timeout.add_seconds (3, () => {
+ }
+
+ timeout_id = Timeout.add_seconds (3, () => {
var animation = actor.animate (Clutter.AnimationMode.EASE_OUT_CUBIC,
500,
"opacity", 0);
- animation.completed.connect (()=> {actor.hide ();});
+ animation.completed.connect (()=> {actor.hide (); timeout_id = 0;});
return false;
});
}
View
@@ -36,8 +36,8 @@ private class Journal.ClutterVTL : Box {
this.activity_factory = new ActivityFactory ();
y_positions = new Gee.HashMap<string, int> ();
- app.backend.events_loaded.connect (() => {
- load_events ();
+ app.backend.events_loaded.connect ((tr) => {
+ load_events (tr);
});
viewport = new Clutter.Actor ();
@@ -91,10 +91,13 @@ private class Journal.ClutterVTL : Box {
scrollbar = new Scrollbar (Orientation.VERTICAL, adj);
viewport.queue_relayout.connect (() => {
scrollbar.adjustment.upper = viewport.height;
- scrollbar.adjustment.step_increment = viewport.height/200;
+ scrollbar.adjustment.step_increment = viewport.height/500; //TODO Divide by number of bubble?
scrollbar.adjustment.page_increment = viewport.height/10;
});
- adj.value_changed.connect (() => { this.on_scrollbar_scroll ();});
+ scrollbar.change_value.connect ((st, v) => {
+ this.on_scrollbar_scroll ();
+ return false;
+ });
vnav = new TimelineNavigator (Orientation.VERTICAL);
vnav.go_to_date.connect ((date) => {this.jump_to_day(date);});
@@ -110,83 +113,101 @@ private class Journal.ClutterVTL : Box {
loading.start ();
}
- public void load_events () {
- Gee.ArrayList<Zeitgeist.Event> all_activities= app.backend.all_activities;
+ public void load_events (Zeitgeist.TimeRange tr) {
+ int64 start = tr.get_start () / 1000;
+ int64 end = tr.get_end () / 1000;
+ DateTime start_date = new DateTime.from_unix_utc (start).to_local ();
+ DateTime end_date = new DateTime.from_unix_utc (end).to_local ();
+
+ Gee.ArrayList<string> date_to_load = new Gee.ArrayList<string> ();
+ DateTime next_date = end_date;
+ date_to_load.add (next_date.format("%Y-%m-%d"));
+ while (next_date.compare (start_date) != 0) {
+ next_date = next_date.add_days (-1);
+ date_to_load.add (next_date.format("%Y-%m-%d"));
+ }
int i = 50;
int type = 0;
Side side;
float offset = 0;
- foreach (Zeitgeist.Event e in all_activities)
+ foreach (string d in date_to_load)
{
- GenericActivity activity = activity_factory.get_activity_for_event (e);
- model.add_activity (activity);
- if (type % 2 == 0)
- side = Side.RIGHT;
- else
- side = Side.LEFT;
+ var event_list = app.backend.get_events_for_date (d);
+ if (event_list == null)
+ continue;
+ foreach (Zeitgeist.Event e in event_list) {
+ GenericActivity activity = activity_factory.get_activity_for_event (e);
+ model.add_activity (activity);
+ if (type % 2 == 0)
+ side = Side.RIGHT;
+ else
+ side = Side.LEFT;
- RoundBox r = new RoundBox (side);
- RoundBoxContent rc = new RoundBoxContent (activity, null);
- r.add (rc);
- r.show_all ();
+ RoundBox r = new RoundBox (side);
+ RoundBoxContent rc = new RoundBoxContent (activity, null);
+ r.add (rc);
+ r.show_all ();
- string date = Utils.get_start_of_the_day_string (activity.time);
- if(y_positions.has_key (date) == false)
- y_positions.set (date, i);
-
- GtkClutter.Actor actor = new GtkClutter.Actor.with_contents (r);
- /****TODO MOVE THIS WHOLE CODE IN A CLASS WRAPPING THE RoundBoxContent***/
- actor.reactive = true;
- if (type % 2 == 0)
- actor.scale_center_x = actor.width;
- actor.enter_event.connect ((e) => {
- double scale_x;
- double scale_y;
-
- actor.get_scale (out scale_x, out scale_y);
-
- actor.animate (Clutter.AnimationMode.EASE_OUT_QUAD, 200,
- "scale-x", scale_x * 1.05,
- "scale-y", scale_y * 1.05);
+ string date = Utils.get_start_of_the_day_string (activity.time);
+ if(y_positions.has_key (date) == false)
+ y_positions.set (date, i);
+
+ GtkClutter.Actor actor = new GtkClutter.Actor.with_contents (r);
+ /****TODO MOVE THIS WHOLE CODE IN A CLASS WRAPPING THE RoundBoxContent***/
+ actor.reactive = true;
+ if (type % 2 == 0)
+ actor.scale_center_x = actor.width;
+ actor.enter_event.connect ((e) => {
+ double scale_x;
+ double scale_y;
+
+ actor.get_scale (out scale_x, out scale_y);
+
+ actor.animate (Clutter.AnimationMode.EASE_OUT_QUAD, 200,
+ "scale-x", scale_x * 1.05,
+ "scale-y", scale_y * 1.05);
- return false;
- });
- actor.leave_event.connect ((e) => {
- actor.animate (Clutter.AnimationMode.EASE_OUT_QUAD, 200,
- "scale-x", 1.0,
- "scale-y", 1.0);
- return false;
- });
+ return false;
+ });
+ actor.leave_event.connect ((e) => {
+ actor.animate (Clutter.AnimationMode.EASE_OUT_QUAD, 200,
+ "scale-x", 1.0,
+ "scale-y", 1.0);
+ return false;
+ });
- actor.button_release_event.connect ((e) => {
- //TODO Improve here?
- actor.animate (Clutter.AnimationMode.EASE_OUT_QUAD, 200,
- "scale-x", 1.0,
- "scale-y", 1.0);
- try {
- AppInfo.launch_default_for_uri (activity.uri, null);
- } catch (Error e) {
- warning ("Error in launching: "+ activity.uri);
- }
- return false;
- });
- /****************************************************/
- viewport.add_actor (actor);
- if (type % 2 == 0)
- offset = -(5 + actor.get_width());
- else
- offset = 5 + timeline.get_width ();
- actor.add_constraint (new Clutter.BindConstraint (timeline, Clutter.BindCoordinate.X, offset)); // timeline!
- actor.set_y (i);
- timeline.add_circle (i);
- //i += (int)actor.get_height() + 20; // padding TODO FIXME better algorithm here
- if (type % 2 == 1) i += 20;
- else i += (int)actor.get_height();
-
- type ++;
+ actor.button_release_event.connect ((e) => {
+ //TODO Improve here?
+ actor.animate (Clutter.AnimationMode.EASE_OUT_QUAD, 200,
+ "scale-x", 1.0,
+ "scale-y", 1.0);
+ try {
+ AppInfo.launch_default_for_uri (activity.uri, null);
+ } catch (Error e) {
+ warning ("Error in launching: "+ activity.uri);
+ }
+ return false;
+ });
+ /****************************************************/
+ viewport.add_actor (actor);
+ if (type % 2 == 0)
+ offset = -(5 + actor.get_width());
+ else
+ offset = 5 + timeline.get_width ();
+ actor.add_constraint (new Clutter.BindConstraint (timeline, Clutter.BindCoordinate.X, offset)); // timeline!
+ actor.set_y (i);
+ timeline.add_circle (i);
+ //i += (int)actor.get_height() + 20; // padding TODO FIXME better algorithm here
+ if (type % 2 == 1) i += 20;
+ else i += (int)actor.get_height();
+ type ++;
+ }
}
timeline.invalidate ();
+
+ if (viewport.height <= stage.height)
+ scrollbar.hide ();
}
public void jump_to_day (string date) {
@@ -195,12 +216,15 @@ private class Journal.ClutterVTL : Box {
y = this.y_positions.get (date);
else {
//jump to TODAY (y == 0)
- osd_label.set_message_and_show (_("Impossible to jump to this data! Jumping to Today"));
+ osd_label.set_message_and_show (_("Loading Activities..."));
+ //TODO load activities!
+ //app.backend.load_events_
}
viewport.animate (Clutter.AnimationMode.EASE_OUT_CUBIC,
350,
"y", (float)(-y));
+ scrollbar.adjustment.value = y;
}
public void on_scrollbar_scroll () {
@@ -230,7 +254,7 @@ private class Journal.ClutterHTL : Object {
x_positions = new Gee.HashMap<string, int> ();
- app.backend.events_loaded.connect (() => {
+ app.backend.events_loaded.connect ((tr) => {
load_events ();
});
View
@@ -112,6 +112,14 @@ private class Journal.Utils : Object{
}
//DATE UTILS
+ public static string get_date_for_event (Zeitgeist.Event e) {
+ int64 timestamp = e.get_timestamp () / 1000;
+ //TODO To localtime here? Zeitgeist uses UTC timestamp, right?
+ DateTime date = new DateTime.from_unix_utc (timestamp).to_local ();
+ //TODO efficiency here? Use String? Int? Quark?
+ return date.format("%Y-%m-%d");
+ }
+
public static string get_start_of_the_day_string (int64 time) {
var start_of_day = get_start_of_the_day (time);
return start_of_day.format("%Y-%m-%d");
Oops, something went wrong.

0 comments on commit 05b351a

Please sign in to comment.