Commit be42c888 authored by Alexander Mikhaylenko's avatar Alexander Mikhaylenko Committed by Zander Brown
Browse files

world: Split standalone view, add a back swipe

Introduce World.Standalone, put it into a HdyDeck inside the main window.

This breaks window title when viewing a location, it will be fixed in
subsequent commits.
parent 8a47a82c
......@@ -8,6 +8,7 @@
<file preprocess="xml-stripblanks">ui/headerbar.ui</file>
<file preprocess="xml-stripblanks">ui/worldlocationdialog.ui</file>
<file preprocess="xml-stripblanks">ui/world.ui</file>
<file preprocess="xml-stripblanks">ui/worldstandalone.ui</file>
<file preprocess="xml-stripblanks">ui/worldtile.ui</file>
<file preprocess="xml-stripblanks">ui/alarmringing.ui</file>
<file preprocess="xml-stripblanks">ui/alarmrow.ui</file>
......
......@@ -6,76 +6,86 @@
<template class="ClocksWindow" parent="HdyApplicationWindow">
<property name="title" bind-source="header_bar" bind-property="title" bind-flags="sync-create" />
<child>
<object class="GtkBox">
<object class="HdyDeck" id="world_deck">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="can-swipe-back">True</property>
<child>
<object class="ClocksHeaderBar" id="header_bar">
<property name="visible">True</property>
<property name="stack">stack</property>
<property name="switcher_bar">switcher_bar</property>
<style>
<class name="titlebar"/>
</style>
</object>
</child>
<child>
<object class="GtkStack" id="stack">
<object class="GtkBox" id="main_view">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="homogeneous">True</property>
<signal name="notify::visible-child" handler="pane_changed" swapped="no"/>
<property name="orientation">vertical</property>
<child>
<object class="ClocksWorldFace" id="world">
<object class="ClocksHeaderBar" id="header_bar">
<property name="visible">True</property>
<property name="stack">stack</property>
<property name="switcher_bar">switcher_bar</property>
<style>
<class name="titlebar"/>
</style>
</object>
<packing>
<property name="name">world</property>
<property name="title" translatable="yes">World</property>
<property name="icon-name">globe-symbolic</property>
</packing>
</child>
<child>
<object class="ClocksAlarmFace" id="alarm">
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="homogeneous">True</property>
<signal name="notify::visible-child" handler="pane_changed" swapped="no"/>
<child>
<object class="ClocksWorldFace" id="world">
<property name="visible">True</property>
</object>
<packing>
<property name="name">world</property>
<property name="title" translatable="yes">World</property>
<property name="icon-name">globe-symbolic</property>
</packing>
</child>
<child>
<object class="ClocksAlarmFace" id="alarm">
<property name="visible">True</property>
</object>
<packing>
<property name="name">alarm</property>
<property name="title" translatable="yes">Alarms</property>
<property name="icon-name">alarm-symbolic</property>
</packing>
</child>
<child>
<object class="ClocksStopwatchFace" id="stopwatch">
<property name="visible">True</property>
</object>
<packing>
<property name="name">stopwatch</property>
<property name="title" translatable="yes">Stopwatch</property>
<property name="icon-name">stopwatch-symbolic</property>
</packing>
</child>
<child>
<object class="ClocksTimerFace" id="timer">
<property name="visible">True</property>
</object>
<packing>
<property name="name">timer</property>
<property name="title" translatable="yes">Timer</property>
<property name="icon-name">timer-symbolic</property>
</packing>
</child>
</object>
<packing>
<property name="name">alarm</property>
<property name="title" translatable="yes">Alarms</property>
<property name="icon-name">alarm-symbolic</property>
</packing>
</child>
<child>
<object class="ClocksStopwatchFace" id="stopwatch">
<object class="HdyViewSwitcherBar" id="switcher_bar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stack">stack</property>
</object>
<packing>
<property name="name">stopwatch</property>
<property name="title" translatable="yes">Stopwatch</property>
<property name="icon-name">stopwatch-symbolic</property>
</packing>
</child>
<child>
<object class="ClocksTimerFace" id="timer">
<property name="visible">True</property>
</object>
<packing>
<property name="name">timer</property>
<property name="title" translatable="yes">Timer</property>
<property name="icon-name">timer-symbolic</property>
</packing>
</child>
</object>
</child>
<child>
<object class="HdyViewSwitcherBar" id="switcher_bar">
<object class="ClocksWorldStandalone" id="world_standalone">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stack">stack</property>
<property name="reveal">True</property>
</object>
</child>
</object>
......
......@@ -5,7 +5,6 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">False</property>
<signal name="notify::visible-child" handler="visible_child_changed" swapped="no"/>
<child>
<object class="GtkGrid" id="empty_view">
<property name="visible">True</property>
......@@ -67,141 +66,5 @@
</child>
</object>
</child>
<child>
<object class="GtkGrid" id="standalone">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkGrid" id="grid2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin_start">34</property>
<property name="margin_end">34</property>
<property name="margin_bottom">12</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child>
<object class="GtkLabel" id="dummy_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label"> </property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="standalone_time_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="justify">center</property>
<property name="wrap">True</property>
<attributes>
<attribute name="font-features" value="tnum=1"/>
</attributes>
<style>
<class name="clocks-standalone-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="standalone_day_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<style>
<class name="clocks-secondary-standalone-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="margin_bottom">24</property>
<property name="column_spacing">12</property>
<style>
<class name="clocks-secondary-standalone-label"/>
</style>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Sunrise</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Sunset</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="standalone_sunrise_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">label</property>
<attributes>
<attribute name="font-features" value="tnum=1"/>
</attributes>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="standalone_sunset_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<attributes>
<attribute name="font-features" value="tnum=1"/>
</attributes>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
</child>
</template>
</interface>
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.18"/>
<template class="ClocksWorldStandalone" parent="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<signal name="notify::location" handler="location_changed"/>
<child>
<object class="HdyHeaderBar">
<property name="visible">True</property>
<property name="show-close-button">True</property>
<property name="title" bind-source="ClocksWorldStandalone" bind-property="title" bind-flags="sync-create" />
<property name="subtitle" bind-source="ClocksWorldStandalone" bind-property="subtitle" bind-flags="sync-create" />
<style>
<class name="titlebar"/>
</style>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">win.back</property>
<property name="tooltip-text" translatable="yes">Back</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-previous-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin_start">34</property>
<property name="margin_end">34</property>
<property name="margin_bottom">12</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child>
<object class="GtkLabel" id="dummy_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label"> </property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="time_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="justify">center</property>
<property name="wrap">True</property>
<attributes>
<attribute name="font-features" value="tnum=1"/>
</attributes>
<style>
<class name="clocks-standalone-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="day_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<style>
<class name="clocks-secondary-standalone-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="margin_bottom">24</property>
<property name="column_spacing">12</property>
<style>
<class name="clocks-secondary-standalone-label"/>
</style>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Sunrise</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Sunset</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="sunrise_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">label</property>
<attributes>
<attribute name="font-features" value="tnum=1"/>
</attributes>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="sunset_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<attributes>
<attribute name="font-features" value="tnum=1"/>
</attributes>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
</child>
</template>
</interface>
......@@ -15,7 +15,8 @@ clocks_vala_sources = [
'utils.vala',
'widgets.vala',
'window.vala',
'world.vala'
'world.vala',
'world-standalone.vala'
]
clocks_c_sources = [
......
......@@ -32,12 +32,18 @@ public class Window : Hdy.ApplicationWindow {
[GtkChild]
private HeaderBar header_bar;
[GtkChild]
private Hdy.Deck world_deck;
[GtkChild]
private Gtk.Box main_view;
[GtkChild]
private Gtk.Stack stack;
[GtkChild]
private World.Face world;
[GtkChild]
private Alarm.Face alarm;
[GtkChild]
private World.Standalone world_standalone;
[GtkChild]
private Stopwatch.Face stopwatch;
[GtkChild]
private Timer.Face timer;
......@@ -84,8 +90,14 @@ public class Window : Hdy.ApplicationWindow {
settings.get ("size", "(ii)", out width, out height);
resize (width, height);
world.show_standalone.connect ((w, l) => {
stack.visible_child = w;
world_standalone.location = l;
world_deck.navigate (Hdy.NavigationDirection.FORWARD);
});
alarm.ring.connect ((w) => {
world.reset_view ();
close_standalone ();
stack.visible_child = w;
});
......@@ -94,7 +106,7 @@ public class Window : Hdy.ApplicationWindow {
});
timer.ring.connect ((w) => {
world.reset_view ();
close_standalone ();
stack.visible_child = w;
});
......@@ -180,11 +192,15 @@ public class Window : Hdy.ApplicationWindow {
}
private void on_back_activate () {
((Clock) stack.visible_child).activate_back ();
if (world_deck.visible_child == main_view) {
((Clock) stack.visible_child).activate_back ();
} else {
world_deck.navigate (Hdy.NavigationDirection.BACK);
}
}
public void show_world () {
world.reset_view ();
close_standalone ();
stack.visible_child = world;
}
......@@ -197,7 +213,11 @@ public class Window : Hdy.ApplicationWindow {
bool handled = false;
if (((Gdk.Event)(event)).get_keyval (out keyval) && keyval == Gdk.Key.Escape) {
handled = ((Clock) stack.visible_child).escape_pressed ();
if (world_deck.visible_child == main_view) {
handled = ((Clock) stack.visible_child).escape_pressed ();
} else {
world_deck.navigate (Hdy.NavigationDirection.BACK);
}
}
if (handled) {
......@@ -212,7 +232,7 @@ public class Window : Hdy.ApplicationWindow {
uint button;
if (((Gdk.Event) (event)).get_button (out button) && button == BUTTON_BACK) {
((Clock) stack.visible_child).activate_back ();
on_back_activate ();
return true;
}
......@@ -339,6 +359,10 @@ public class Window : Hdy.ApplicationWindow {
stack.visible_child.grab_focus ();
}
private void close_standalone () {
world_deck.visible_child = main_view;
}
}
} // namespace Clocks
/*
* Copyright (C) 2013 Paolo Borelli <pborelli@gnome.org>
*
* This program 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.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
namespace Clocks {
namespace World {
[GtkTemplate (ui = "/org/gnome/clocks/ui/worldstandalone.ui")]
public class Standalone : Gtk.Box {
public string title { get; set; default = _("Clocks"); }
public string subtitle { get; set; }
public Item? location { get; set; }
[GtkChild]
private Gtk.Label time_label;
[GtkChild]
private Gtk.Label day_label;
[GtkChild]
private Gtk.Label sunrise_label;
[GtkChild]
private Gtk.Label sunset_label;
construct {
// Start ticking...
Utils.WallClock.get_default ().tick.connect (update);
}
private void update () {
if (location != null) {
time_label.label = ((Item) location).time_label;
day_label.label = (string) ((Item) location).day_label;
sunrise_label.label = ((Item) location).sunrise_label;
sunset_label.label = ((Item) location).sunset_label;
}
}
[GtkCallback]
private void location_changed () {
if (location == null) {
return;
}
update ();
var item = (Item) location;
if (item.state_name != null) {
title = "%s, %s".printf (item.city_name, (string) item.state_name);
} else {