Skip to content

Commit

Permalink
Split widgets into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilprusko committed Jan 2, 2015
1 parent 6eb936d commit c69fef3
Show file tree
Hide file tree
Showing 12 changed files with 805 additions and 648 deletions.
9 changes: 8 additions & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ libgnome_pomodoro_la_SOURCES = \
sounds.vala \
timer.vala \
utils.vala \
widgets.vala
widgets/calendar-button.vala \
widgets/enum-combo-box.vala \
widgets/keybinding-chooser-button.vala \
widgets/log-scale.vala \
widgets/mode-button.vala \
widgets/sound-chooser-button.vala \
widgets/symbolic-button.vala \
widgets/toolbar.vala

libgnome_pomodoro_la_VALAFLAGS = \
--library=gnome-pomodoro \
Expand Down
2 changes: 1 addition & 1 deletion lib/main-window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private class Pomodoro.AddTaskDialog : Gtk.Dialog
child.hexpand = false;
}

var due_date_button = new CalendarButton ();
var due_date_button = new Widgets.CalendarButton ();
due_date_button.halign = Gtk.Align.START;

// var completed/done checkbox
Expand Down
16 changes: 8 additions & 8 deletions lib/preferences-dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ namespace Pomodoro
var value_label = new Gtk.Label (null);
value_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);

var scale = new LogScale (adjustment, 2.0);
var scale = new Widgets.LogScale (adjustment, 2.0);
var widget = list_box_create_field (text, value_label, scale);

adjustment.value_changed.connect (() => {
Expand Down Expand Up @@ -510,7 +510,7 @@ public class Pomodoro.PreferencesDialog : Gtk.ApplicationWindow
_("Pomodoros to a long break"),
long_break_interval_entry);

var toggle_key_button = new Pomodoro.KeybindingButton (keybinding);
var toggle_key_button = new Pomodoro.Widgets.KeybindingChooserButton (keybinding);
var toggle_key_field = list_box_create_field (
_("Shortcut to toggle the timer"),
toggle_key_button);
Expand Down Expand Up @@ -542,9 +542,9 @@ public class Pomodoro.PreferencesDialog : Gtk.ApplicationWindow

if (Pomodoro.Player.is_supported ())
{
var ticking_sound_button = new Pomodoro.SoundChooserButton ();
var ticking_sound_button = new Widgets.SoundChooserButton ();
ticking_sound_button.title = _("Select ticking sound");
ticking_sound_button.backend = Pomodoro.SoundBackend.GSTREAMER;
ticking_sound_button.backend = SoundBackend.GSTREAMER;
ticking_sound_button.has_volume_button = true;

foreach (var sound_info in this.timer_sounds)
Expand Down Expand Up @@ -607,7 +607,7 @@ public class Pomodoro.PreferencesDialog : Gtk.ApplicationWindow
_("Wake up screen"),
screen_wake_up_toggle);

var pomodoro_end_sound = new Pomodoro.SoundChooserButton ();
var pomodoro_end_sound = new Widgets.SoundChooserButton ();
pomodoro_end_sound.title = _("Select sound for start of break");

foreach (var sound_info in this.notification_sounds)
Expand All @@ -621,7 +621,7 @@ public class Pomodoro.PreferencesDialog : Gtk.ApplicationWindow
_("Start of break sound"),
pomodoro_end_sound);

var pomodoro_start_sound = new Pomodoro.SoundChooserButton ();
var pomodoro_start_sound = new Widgets.SoundChooserButton ();
pomodoro_start_sound.title = _("Select sound for end of break");

foreach (var sound_info in this.notification_sounds)
Expand Down Expand Up @@ -698,7 +698,7 @@ public class Pomodoro.PreferencesDialog : Gtk.ApplicationWindow

private Gtk.ComboBox create_indicator_type_combo_box ()
{
var combo_box = new Pomodoro.EnumComboBox ();
var combo_box = new Widgets.EnumComboBox ();
combo_box.add_option (IndicatorType.TEXT, _("Text"));
combo_box.add_option (IndicatorType.TEXT_SMALL, _("Short Text"));
combo_box.add_option (IndicatorType.ICON, _("Icon"));
Expand All @@ -710,7 +710,7 @@ public class Pomodoro.PreferencesDialog : Gtk.ApplicationWindow

private Gtk.ComboBox create_presence_status_combo_box ()
{
var combo_box = new Pomodoro.EnumComboBox ();
var combo_box = new Widgets.EnumComboBox ();
combo_box.add_option (PresenceStatus.DEFAULT, "");
combo_box.add_option (PresenceStatus.AVAILABLE, _("Available"));
combo_box.add_option (PresenceStatus.BUSY, _("Busy"));
Expand Down
5 changes: 5 additions & 0 deletions lib/sounds.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ namespace Pomodoro
POMODORO_END = 2
}

public enum SoundBackend {
CANBERRA,
GSTREAMER
}

private const uint PLAYER_FADE_IN_TIME = 25000;
private const uint PLAYER_FADE_OUT_TIME = 15000;

Expand Down
106 changes: 106 additions & 0 deletions lib/widgets/calendar-button.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2013 gnome-pomodoro contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* Authors: Kamil Prusko <kamilprusko@gmail.com>
*
*/

using GLib;


public class Pomodoro.Widgets.CalendarButton : Gtk.Button
{
private static string DATE_TIME_FORMAT = "%a, %e %B %Y";

public int day { get; set; default = 0; }
public int month { get; set; default = 0; }
public int year { get; set; default = 0; }

construct
{
this.label = "24 July 2014";
// this.image = new Gtk.Image.from_icon_name ("x-office-calendar-symbolic",
// Gtk.IconSize.MENU);
// this.image_position = Gtk.PositionType.LEFT;
// this.always_show_image = true;
}

private void show_popover ()
{
var calendar = new Gtk.Calendar ();
calendar.halign = Gtk.Align.FILL;
calendar.valign = Gtk.Align.FILL;
calendar.margin = 4;
calendar.show_week_numbers = false;
calendar.show_heading = true;
calendar.show_details = true;
calendar.show_day_names = true;
calendar.set_size_request (300, -1);

if (this.day > 0) {
calendar.day = this.day;
calendar.mark_day (this.day);
}

if (this.month > 0) {
calendar.month = this.month;
}

if (this.year > 0) {
calendar.year = this.year;
}

var popover = new Gtk.Popover (this);
popover.set_position (Gtk.PositionType.BOTTOM);
popover.add (calendar);

calendar.day_selected.connect (() => {
// TODO: block notify event
this.day = calendar.day;
this.month = calendar.month;
this.year = calendar.year;

calendar.clear_marks ();
calendar.mark_day (this.day);

this.date_selected ();
});

calendar.day_selected_double_click.connect (() => {
popover.destroy ();
});

popover.show_all ();
}

public override void clicked ()
{
this.show_popover ();
}

public virtual signal void date_selected ()
{
var datetime = new DateTime.local (this.year,
this.month + 1,
this.day,
0,
0,
0.0);

this.label = datetime.format (DATE_TIME_FORMAT);
}
}

92 changes: 92 additions & 0 deletions lib/widgets/enum-combo-box.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2013 gnome-pomodoro contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* Authors: Kamil Prusko <kamilprusko@gmail.com>
*
*/

using GLib;


public class Pomodoro.Widgets.EnumComboBox : Gtk.ComboBox
{
enum Column {
VALUE,
DISPLAY_NAME
}

construct {
var model = new Gtk.ListStore (2,
typeof (int),
typeof (string));
this.model = model;

var cell = new Gtk.CellRendererText ();
cell.width = 120; /* TODO: make it adjustable */

this.pack_start (cell, false);
this.set_attributes (cell, "text", Column.DISPLAY_NAME);

this.changed.connect (() => {
this.notify_property ("value");
});
}

public int value {
get {
Gtk.TreeIter iter;
int iter_value = 0;

if (this.get_active_iter (out iter))
{
this.model.get (iter,
Column.VALUE, out iter_value);
}

return iter_value;
}
set {
Gtk.TreeIter iter;
int iter_value = 0;

if (this.model.get_iter_first (out iter))
{
do {
this.model.get (iter,
Column.VALUE, out iter_value);

if (iter_value == value) {
this.set_active_iter (iter);
break;
}
}
while (this.model.iter_next (ref iter));
}
}
}

public void add_option (int value, string display_name)
{
Gtk.TreeIter iter;

var model = this.model as Gtk.ListStore;

model.append (out iter);
model.set (iter,
Column.VALUE, value,
Column.DISPLAY_NAME, display_name);
}
}
Loading

0 comments on commit c69fef3

Please sign in to comment.