diff options
| author | Neil Jagdish Patel <neil.patel@canonical.com> | 2010-01-19 16:10:14 +0000 |
|---|---|---|
| committer | Neil Jagdish Patel <neil.patel@canonical.com> | 2010-01-19 16:10:14 +0000 |
| commit | b782b961ab6c2f7cb55594bfd470dc6fd6ff23a6 (patch) | |
| tree | 3d1d92f849e94896196173222a8e3c3be67b7f04 /src | |
| parent | 1edbb6b9cfd24b3ad34281424d26df84aefdb48b (diff) | |
[places] Some bits-and-pieces to make it more MVC
added: src/places/places-controller.vala src/places/places-model.vala src/places/places-place.vala renamed: src/places/view.vala => src/places/places-view.vala modified: src/Makefile.am src/quicklauncher/quicklist-view.vala src/window.vala src/places/places-view.vala unknown: src/places/places-controller.c src/places/places-model.c src/places/places-place.c src/places/places-view.c src/quicklauncher/quicklist-controller.c src/quicklauncher/quicklist-view.c (bzr r61.2.1)
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 5 | ||||
| -rw-r--r-- | src/places/places-controller.vala | 71 | ||||
| -rw-r--r-- | src/places/places-model.vala | 64 | ||||
| -rw-r--r-- | src/places/places-place.vala | 56 | ||||
| -rw-r--r-- | src/places/places-view.vala (renamed from src/places/view.vala) | 35 | ||||
| -rw-r--r-- | src/quicklauncher/quicklist-view.vala | 13 | ||||
| -rw-r--r-- | src/window.vala | 48 |
7 files changed, 246 insertions, 46 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index de815ce7c..a61a9640e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -69,7 +69,10 @@ places_sources = \ places/bar-view.vala \ places/default-model.vala \ places/default-view.vala \ - places/view.vala + places/places-controller.vala \ + places/places-model.vala \ + places/places-place.vala \ + places/places-view.vala quicklauncher_sources = \ quicklauncher/application-model.vala \ diff --git a/src/places/places-controller.vala b/src/places/places-controller.vala new file mode 100644 index 000000000..885a588f0 --- /dev/null +++ b/src/places/places-controller.vala @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2009 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by Neil Jagdish Patel <neil.patel@canonical.com> + * + */ + +using Gee; + +namespace Unity.Places +{ + public class Controller : Object + { + /** + * This class takes care of reading in the places, creating the view and + * keeping it up-to-date + **/ + private Model model; + private View view; + + public Controller () + { + + } + + construct + { + this.model = new Model (); + this.view = new View (this.model); + + Idle.add (this.load_places); + } + + private bool load_places () + { + /* Currently we have a static list, in the future we'll be using the + * utility functions in libunity-places to load in the actual places + * information from the drive + */ + var place = new Place ("Home", PKGDATADIR + "/home.png"); + this.model.add (place); + + place = new Place ("Applications", PKGDATADIR + "/applications.png"); + this.model.add (place); + + place = new Place ("Files & Folders", PKGDATADIR + "/files.png"); + this.model.add (place); + + return false; + } + + /* Public Methods */ + public View get_view () + { + return this.view; + } + } +} + diff --git a/src/places/places-model.vala b/src/places/places-model.vala new file mode 100644 index 000000000..0d8502a68 --- /dev/null +++ b/src/places/places-model.vala @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2009 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by Neil Jagdish Patel <neil.patel@canonical.com> + * + */ + +using Gee; + +namespace Unity.Places +{ + public class Model : Object + { + /** + * Contains a list of places + **/ + + /* Properties */ + public ArrayList<Place> list; + + /* Signals */ + public signal void place_added (Place place); + public signal void place_removed (Place place); + public signal void place_changed (Place place); + + public Model () + { + Object (); + } + + construct + { + list = new ArrayList<Place> (); + } + + public void add (Place place) + { + this.list.add (place); + + this.place_added (place); + } + + public void remove (Place place) + { + this.list.remove (place); + + this.place_removed (place); + } + + } +} + diff --git a/src/places/places-place.vala b/src/places/places-place.vala new file mode 100644 index 000000000..2a3aaa673 --- /dev/null +++ b/src/places/places-place.vala @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2009 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by Neil Jagdish Patel <neil.patel@canonical.com> + * + */ + +namespace Unity.Places +{ + public class Place : Object + { + /** + * Represents a Place (icon, view etc). Will eventually be able to be + * constructed from a Unity.Place.Proxy as well as sub-classed + **/ + + /* Properties */ + public string name { get; construct; } + public string icon_name { get; construct; } + public Gdk.Pixbuf icon { get; construct; } + public string comment { get; construct; } + + /* Signals */ + public signal void activated (); + + public Place (string name, string icon_name) + { + Object (name:name, icon_name:icon_name); + } + + construct + { + try + { + this.icon = new Gdk.Pixbuf.from_file (this.icon_name); + } + catch (Error e) + { + warning (@"Unable to load '$icon_name' for '$name': %s", e.message); + } + } + } +} + diff --git a/src/places/view.vala b/src/places/places-view.vala index 6941259af..45ecdee09 100644 --- a/src/places/view.vala +++ b/src/places/places-view.vala @@ -20,7 +20,7 @@ namespace Unity.Places { /* Margin outside of the cairo texture. We draw outside to complete the line loop - * and we don't want the line loop to be visible in some parts of the screen. + * and we don't want the line loop to be visible in some parts of the screen. * */ private int Margin = 5; @@ -31,7 +31,7 @@ namespace Unity.Places private Ctk.EffectGlow effect_glow; /* (X, Y) origine of Places Bar: The top-left corner of the screen */ - private int PlaceX = 0; + private int PlaceX = 0; private int PlaceY = 0; /* Places Bar width and height. The width is set the the width of the window. */ @@ -61,18 +61,18 @@ namespace Unity.Places int top; int bottom; } - + public int PlaceWidth; void DrawAroundMenu (Cairo.Context cairoctx) { cairoctx.line_to (PlaceX + PlaceW + Margin, PlaceY + MenuH); cairoctx.line_to (PlaceX + PlaceW - MenuW + Rounding, PlaceY + MenuH); - cairoctx.curve_to ( + cairoctx.curve_to ( PlaceX + PlaceW - MenuW, PlaceY + MenuH, PlaceX + PlaceW - MenuW, PlaceY + MenuH, PlaceX + PlaceW - MenuW, PlaceY + MenuH + Rounding); - cairoctx.line_to (PlaceX + PlaceW - MenuW, PlaceY + PlaceH - Rounding); + cairoctx.line_to (PlaceX + PlaceW - MenuW, PlaceY + PlaceH - Rounding); cairoctx.curve_to ( PlaceX + PlaceW - MenuW, PlaceY + PlaceH, PlaceX + PlaceW - MenuW, PlaceY + PlaceH, @@ -82,7 +82,7 @@ namespace Unity.Places void DrawTab(Cairo.Context cairoctx, TabRect tab) { cairoctx.line_to (tab.right + RoundingSmall, PlaceBottom ); - cairoctx.curve_to ( + cairoctx.curve_to ( tab.right, PlaceBottom, tab.right, PlaceBottom, tab.right, PlaceBottom - RoundingSmall); @@ -198,9 +198,12 @@ namespace Unity.Places private int current_tab_index; - /* These parameters are temporary until we get the right metrics for the places bar */ + public Model model { get; construct; } - public override void allocate (Clutter.ActorBox box, + /* These parameters are temporary until we get the right metrics for + * the places bar + */ + public override void allocate (Clutter.ActorBox box, Clutter.AllocationFlags flags) { base.allocate (box, flags); @@ -213,7 +216,7 @@ namespace Unity.Places this.bar_view.IconSize = bar_icon_size; this.bar_view.FirstPlaceIconPosition = 100; /* HARDCODED: Offset from the left of the Places bar to the first Icon */ this.bar_view.PlaceIconSpacing = 24; - + child_box.x1 = PlacesPosition; child_box.x2 = box.x2 - box.x1; child_box.y1 = this.padding.top + 8; @@ -258,15 +261,17 @@ namespace Unity.Places 2*icon_margin + bar_icon_size); } this.TrashBackground.allocate (child_box, flags); - + } - public View () + public View (Model model) { int i; int NunItems; PlacesBackground background; + Object (model:model); + this.PlacesBackgroundArray = new Gee.ArrayList<PlacesBackground> (); this.DevicesBackgroundArray = new Gee.ArrayList<PlacesBackground> (); @@ -279,7 +284,7 @@ namespace Unity.Places this.default_view = new Unity.Places.Default.View (); - NunItems = this.bar_view.get_number_of_places (); + NunItems = this.bar_view.get_number_of_places (); for (i = 0; i < NunItems; i++) { background = new PlacesBackground (); @@ -289,7 +294,7 @@ namespace Unity.Places } this.PlacesBackgroundArray[0].show (); - NunItems = this.bar_view.get_number_of_devices (); + NunItems = this.bar_view.get_number_of_devices (); for (i = 0; i < NunItems; i++) { background = new PlacesBackground (); @@ -344,7 +349,7 @@ namespace Unity.Places { this.DevicesBackgroundArray[j].hide (); } - TrashBackground.hide (); + TrashBackground.hide (); this.PlacesBackgroundArray[this.current_tab_index].hide (); this.current_tab_index = i; @@ -361,7 +366,7 @@ namespace Unity.Places { this.PlacesBackgroundArray[j].hide (); } - TrashBackground.hide (); + TrashBackground.hide (); this.DevicesBackgroundArray[this.current_tab_index].hide (); this.current_tab_index = i; diff --git a/src/quicklauncher/quicklist-view.vala b/src/quicklauncher/quicklist-view.vala index 712a647ba..fc3e9e940 100644 --- a/src/quicklauncher/quicklist-view.vala +++ b/src/quicklauncher/quicklist-view.vala @@ -17,16 +17,15 @@ * Authored by Gordon Allott <gord.allott@canonical.com> * */ - + namespace Unity.Quicklauncher { /* we call this instead of Ctk.Menu so you can alter this to look right */ public class QuicklistMenu : Ctk.Menu { - Ctk.EffectDropShadow drop_shadow; Clutter.Rectangle ql_background; - construct + construct { Clutter.Color color = Clutter.Color () { red = 0x20, @@ -35,7 +34,7 @@ namespace Unity.Quicklauncher alpha = 0xff }; this.ql_background = new Clutter.Rectangle.with_color (color); - + this.set_background (this.ql_background); Ctk.Padding padding = Ctk.Padding () { left = 6, @@ -44,9 +43,9 @@ namespace Unity.Quicklauncher bottom = 6 }; this.set_padding (padding); - + // triggers a bug in the effects framework, only first frame is cached. - // can't do the work-around of waiting for the menu to have all its + // can't do the work-around of waiting for the menu to have all its // elements before attaching the effects anymore as we need to account // for the menu being a small label. //removed for now - broken on mutter - makes gord's brain bleed. @@ -55,5 +54,5 @@ namespace Unity.Quicklauncher add_effect(this.drop_shadow); */ } - } + } } diff --git a/src/window.vala b/src/window.vala index f6d06e62e..4eea6ca6b 100644 --- a/src/window.vala +++ b/src/window.vala @@ -26,7 +26,7 @@ namespace Unity public bool is_popup { get; construct; } public int popup_width { get; construct; } public int popup_height { get; construct; } - + private Wnck.Screen wnck_screen; private Workarea workarea_size; @@ -36,26 +36,28 @@ namespace Unity private Background background; private Quicklauncher.View quicklauncher; + + private Places.Controller controller; private Unity.Places.View places; public UnderlayWindow (bool popup, int width, int height) { Object(is_popup: popup, popup_width: width, popup_height: height); } - + construct { START_FUNCTION (); this.workarea_size = new Workarea (); this.workarea_size.update_net_workarea (); - + if (this.is_popup) { this.type_hint = Gdk.WindowTypeHint.NORMAL; this.decorated = true; this.skip_taskbar_hint = false; this.skip_pager_hint = false; - this.delete_event.connect (() => + this.delete_event.connect (() => { Gtk.main_quit (); return false; @@ -72,7 +74,7 @@ namespace Unity this.accept_focus = false; this.can_focus = false; this.delete_event.connect (() => { return true; }); - this.screen.size_changed.connect ((s) => + this.screen.size_changed.connect ((s) => { this.relayout (); }); this.screen.monitors_changed.connect ((s) => { this.relayout (); }); @@ -80,7 +82,7 @@ namespace Unity this.title = "Unity"; this.icon_name = "distributor-logo"; this.is_showing = false; - + /* Gtk.ClutterEmbed */ LOGGER_START_PROCESS ("unity_underlay_window_realize"); this.realize (); @@ -104,14 +106,14 @@ namespace Unity LOGGER_START_PROCESS ("ctk_dnd_init"); Ctk.dnd_init (this.gtk_clutter, target_list); LOGGER_END_PROCESS ("ctk_dnd_init"); - + this.stage = (Clutter.Stage)this.gtk_clutter.get_stage (); - - Clutter.Color stage_bg = Clutter.Color () { + + Clutter.Color stage_bg = Clutter.Color () { red = 0x00, green = 0x00, blue = 0x00, - alpha = 0xff + alpha = 0xff }; this.stage.set_color (stage_bg); this.stage.button_press_event.connect (this.on_stage_button_press); @@ -122,10 +124,12 @@ namespace Unity this.background.show (); this.quicklauncher = new Quicklauncher.View (this); - this.places = new Unity.Places.View (); + + this.controller = new Places.Controller (); + this.places = this.controller.get_view (); this.stage.add_actor (this.quicklauncher); this.stage.add_actor (this.places); - + /* Layout everything */ this.move (0, 0); this.relayout (); @@ -164,8 +168,6 @@ namespace Unity height = size.height; } - debug ("relayout: %dx%d - %dx%d", x, y, width, height); - this.resize (width, height); this.stage.set_size (width, height); @@ -175,7 +177,7 @@ namespace Unity /* Update component layouts */ this.background.set_position (0, 0); this.background.set_size (width, height); - + this.quicklauncher.set_size (58, height); this.quicklauncher.set_position (this.workarea_size.left, this.workarea_size.top); @@ -204,9 +206,9 @@ namespace Unity Wnck.Window new_window = this.wnck_screen.get_active_window (); if (new_window == null) return; - + /* FIXME: We want the second check to be a class_name or pid check */ - if (new_window is Wnck.Window + if (new_window is Wnck.Window && new_window.get_type () != Wnck.WindowType.DESKTOP && new_window.get_name () == "Unity") { @@ -258,26 +260,26 @@ namespace Unity } } - - public class Workarea + + public class Workarea { public signal void workarea_changed (); public int left; public int top; public int right; public int bottom; - + public Workarea () { left = 0; right = 0; top = 0; bottom = 0; - + update_net_workarea (); } - public void update_net_workarea () + public void update_net_workarea () { /* FIXME - steal code from the old liblauncher to do this * (launcher-session.c) this is just fake code to get it running @@ -287,5 +289,5 @@ namespace Unity top = 24; bottom = 0; } - } + } } |
