[gitg/wip/progress] Add ProgressBin widget
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/wip/progress] Add ProgressBin widget
- Date: Wed, 27 Mar 2013 21:22:29 +0000 (UTC)
commit 1d44db7d79ef07ca954316108c6a3d9efeb36fc6
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed Mar 27 15:55:46 2013 +0100
Add ProgressBin widget
gitg/resources/ui/style.css | 3 +
libgitg-gtk/Makefile.am | 3 +-
libgitg-gtk/gitg-gtk-dash-view.vala | 33 ++++++-----
libgitg-gtk/gitg-gtk-progress-bin.vala | 100 ++++++++++++++++++++++++++++++++
tests/Makefile.am | 6 ++-
tests/progress-bin.vala | 29 +++++++++
6 files changed, 158 insertions(+), 16 deletions(-)
---
diff --git a/gitg/resources/ui/style.css b/gitg/resources/ui/style.css
index fa12ed9..db91839 100644
--- a/gitg/resources/ui/style.css
+++ b/gitg/resources/ui/style.css
@@ -86,6 +86,9 @@ GtkLabel.grid_title {
background-color: @sidebar_bg_unfocused;
}
+.progress-grid {
+ background-color: shade (@theme_bg_color, 0.9);
+}
.branch, .remote, .tag, .stash {
border-radius: 6px;
diff --git a/libgitg-gtk/Makefile.am b/libgitg-gtk/Makefile.am
index 4d73d71..03c62ea 100644
--- a/libgitg-gtk/Makefile.am
+++ b/libgitg-gtk/Makefile.am
@@ -56,7 +56,8 @@ VALA_FILES = \
gitg-gtk-diff-view-request-resource.vala \
gitg-gtk-diff-view-request-diff.vala \
gitg-gtk-dash-view.vala \
- gitg-gtk-when-mapped.vala
+ gitg-gtk-when-mapped.vala \
+ gitg-gtk-progress-bin.vala
# Ignore all warnings for vala code...
libgitg_gtk_1_0_la_CFLAGS = \
diff --git a/libgitg-gtk/gitg-gtk-dash-view.vala b/libgitg-gtk/gitg-gtk-dash-view.vala
index d361b6d..0603fe6 100644
--- a/libgitg-gtk/gitg-gtk-dash-view.vala
+++ b/libgitg-gtk/gitg-gtk-dash-view.vala
@@ -31,7 +31,7 @@ namespace GitgGtk
{
public Repository? repository;
public DateTime time;
- public Grid grid;
+ public ProgressBin bin;
public Image image;
public Label repository_label;
public Label branch_label;
@@ -165,16 +165,18 @@ namespace GitgGtk
var data = new RepositoryData();
data.repository = null;
data.time = new DateTime.now_local();
- data.grid = new Grid();
- data.grid.margin = 12;
- data.grid.column_spacing = 10;
+ data.bin = new ProgressBin();
+ var grid = new Grid();
+ grid.margin = 12;
+ grid.column_spacing = 10;
+ data.bin.add(grid);
// FIXME: choose the folder image in relation to the next:
// - the repository is local
// - the repository has a remote
// - the repository uses github...
data.image = new Image.from_icon_name("folder", d_icon_size);
- data.grid.attach(data.image, 0, 0, 1, 2);
+ grid.attach(data.image, 0, 0, 1, 2);
data.repository_label = new Label(null);
data.repository_label.set_markup("<b>%s</b>".printf(name));
@@ -182,7 +184,7 @@ namespace GitgGtk
data.repository_label.halign = Align.START;
data.repository_label.valign = Align.END;
data.repository_label.hexpand = true;
- data.grid.attach(data.repository_label, 1, 0, 1, 1);
+ grid.attach(data.repository_label, 1, 0, 1, 1);
data.branch_label = new Label("");
data.branch_label.set_markup("<small>%s</small>".printf(branch_name));
@@ -190,20 +192,20 @@ namespace GitgGtk
data.branch_label.valign = Align.START;
data.branch_label.halign = Align.START;
data.branch_label.get_style_context().add_class("dim-label");
- data.grid.attach(data.branch_label, 1, 1, 1, 1);
+ grid.attach(data.branch_label, 1, 1, 1, 1);
data.arrow = new Arrow(ArrowType.RIGHT, ShadowType.NONE);
- data.grid.attach(data.arrow, 2, 0, 1, 2);
+ grid.attach(data.arrow, 2, 0, 1, 2);
- data.grid.set_data<RepositoryData>("data", data);
- data.grid.show_all();
- d_listbox.add(data.grid);
+ data.bin.set_data<RepositoryData>("data", data);
+ data.bin.show_all();
+ d_listbox.add(data.bin);
if (spin)
{
data.arrow.hide();
data.spinner = new Spinner();
- data.grid.attach(data.spinner, 3, 0, 1, 2);
+ grid.attach(data.spinner, 3, 0, 1, 2);
data.spinner.show();
data.spinner.start();
}
@@ -254,7 +256,7 @@ namespace GitgGtk
}
}
- private async Gitg.Repository? clone(string url, File location, bool is_bare)
+ private async Gitg.Repository? clone(RepositoryData data, string url, File location, bool
is_bare)
{
SourceFunc callback = clone.callback;
Gitg.Repository? repository = null;
@@ -264,6 +266,9 @@ namespace GitgGtk
{
var options = new Ggit.CloneOptions();
options.set_is_bare(is_bare);
+ /*options.set_fetch_progress_callback((stats) => {
+ data.bin.fraction = (100 * stats.received_objects) /
stats.total_objects;
+ });*/
repository = Ggit.Repository.clone(url, location, options) as
Gitg.Repository;
}
@@ -321,7 +326,7 @@ namespace GitgGtk
// Clone
RepositoryData? data = create_repository_data(subfolder_name, "Cloning...", true);
- clone.begin(url, subfolder, is_bare, (obj, res) => {
+ clone.begin(data, url, subfolder, is_bare, (obj, res) => {
Gitg.Repository? repository = clone.end(res);
string branch_name = "";
diff --git a/libgitg-gtk/gitg-gtk-progress-bin.vala b/libgitg-gtk/gitg-gtk-progress-bin.vala
new file mode 100644
index 0000000..d63f329
--- /dev/null
+++ b/libgitg-gtk/gitg-gtk-progress-bin.vala
@@ -0,0 +1,100 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2013 - Ignacio Casal Quinteiro
+ *
+ * gitg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gitg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace GitgGtk
+{
+ public class ProgressBin : Gtk.Bin
+ {
+ private double d_fraction;
+
+ public double fraction
+ {
+ get { return d_fraction; }
+ set
+ {
+ d_fraction = value;
+ queue_draw();
+ }
+ }
+
+ construct
+ {
+ set_has_window(true);
+ set_redraw_on_allocate(false);
+ }
+
+ public override void realize()
+ {
+ set_realized(true);
+
+ Gtk.Allocation allocation;
+ get_allocation(out allocation);
+
+ Gdk.WindowAttr attributes = {};
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
+ attributes.window_type = Gdk.WindowType.CHILD;
+ attributes.wclass = Gdk.WindowWindowClass.INPUT_OUTPUT;
+ attributes.event_mask = get_events() | Gdk.EventMask.EXPOSURE_MASK;
+
+ var attributes_mask = Gdk.WindowAttributesType.X | Gdk.WindowAttributesType.Y;
+ var window = new Gdk.Window(get_parent_window(),
+ attributes, attributes_mask);
+
+ var context = get_style_context();
+ context.set_background(window);
+
+ set_window(window);
+ window.set_user_data(this);
+ }
+
+ public override void size_allocate(Gtk.Allocation allocation)
+ {
+ base.size_allocate(allocation);
+
+ var window = get_window();
+ if (window != null)
+ {
+ window.move_resize(allocation.x, allocation.y, allocation.width,
allocation.height);
+ }
+ }
+
+ public override bool draw(Cairo.Context cr)
+ {
+ Gtk.Allocation allocation;
+ get_allocation(out allocation);
+
+ var context = get_style_context();
+ context.render_background(cr, 0, 0, allocation.width, allocation.height);
+
+ context.save();
+ context.add_class("progress-grid");
+
+ context.render_background(cr, 0, 0, allocation.width * d_fraction, allocation.height);
+ context.restore();
+
+ base.draw(cr);
+ return true;
+ }
+ }
+}
+
+// ex:ts=4 noet
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5dbe9be..3ef6d16 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,7 +4,7 @@ noinst_PROGRAMS = $(TEST_PROGS) $(DEMO_PROGS)
AM_VALAFLAGS = $(GITG_PLUGIN_VALAFLAGS)
-DEMO_PROGS = diff-view dash-view
+DEMO_PROGS = diff-view dash-view progress-bin
diff_view_SOURCES = diff-view.vala
diff_view_LDADD = $(GITG_PLUGIN_LIBS)
@@ -14,6 +14,10 @@ dash_view_SOURCES = dash-view.vala
dash_view_LDADD = $(GITG_PLUGIN_LIBS)
dash_view_CFLAGS = $(GITG_PLUGIN_CFLAGS) -w
+progress_bin_SOURCES = progress-bin.vala
+progress_bin_LDADD = $(GITG_PLUGIN_LIBS)
+progress_bin_CFLAGS = $(GITG_PLUGIN_CFLAGS) -w
+
TESTS = $(TEST_PROGS)
BUILT_SOURCES = \
diff --git a/tests/progress-bin.vala b/tests/progress-bin.vala
new file mode 100644
index 0000000..1f82130
--- /dev/null
+++ b/tests/progress-bin.vala
@@ -0,0 +1,29 @@
+using Gtk;
+using GitgGtk;
+
+class TestProgressGrid
+{
+ public static int main(string[] args)
+ {
+ Gtk.init(ref args);
+ Gitg.init();
+
+ var window = new Window();
+ window.set_default_size(300, 300);
+ var grid = new ProgressBin();
+ grid.fraction = 0.3;
+ window.add(grid);
+ window.show_all();
+
+ window.delete_event.connect((w, ev) => {
+ Gtk.main_quit();
+ return true;
+ });
+
+ Gtk.main();
+
+ return 0;
+ }
+}
+
+// vi:ts=4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]