Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

elementary code style #60

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/Config.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
*/

namespace Constants {
public const string DATADIR = "/usr/share";
public const string PKG_DATADIR = "/usr/share/com.github.tomatoers.tomato";
public const string GETTEXT_PACKAGE = "com.github.tomatoers.tomato";
public const string RELEASE_NAME = "Stupice";
public const string VERSION = "2.0.2";
public const string VERSION_INFO = "Release";
public const string INSTALL_PREFIX = "/usr";
public const string DATADIR = "/usr/share";
public const string PKG_DATADIR = "/usr/share/com.github.tomatoers.tomato";
public const string GETTEXT_PACKAGE = "com.github.tomatoers.tomato";
public const string RELEASE_NAME = "Stupice";
public const string VERSION = "2.0.2";
public const string VERSION_INFO = "Release";
public const string INSTALL_PREFIX = "/usr";
public const string APP_NAME = "Tomato";
public const string EXEC_NAME = "com.github.tomatoers.tomato";
public const string ICON_NAME = "com.github.tomatoers.tomato";
public const string EXEC_NAME = "com.github.tomatoers.tomato";
public const string ICON_NAME = "com.github.tomatoers.tomato";
}

namespace Default {
public const int POMODORO_DURATION = 25;
public const int POMODORO_DURATION = 25;
public const int SHORT_BREAK_DURATION = 5;
public const int LONG_BREAK_DURATION = 15;
public const int LONG_BREAK_DELAY = 4;
Expand Down
9 changes: 6 additions & 3 deletions src/Tomato.vala
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ namespace Tomato {
if (stop_countdown == -1) {
on_stop_clicked ();
stop_countdown = 14;
notification.show (_("Pomodoro was interrupted"), _("Tomato was paused for a long time. You might have lost focus. Try a new pomodoro!"));
notification.show (
_("Pomodoro was interrupted"),
_("Tomato was paused for a long time. You might have lost focus. Try a new pomodoro!")
);
}
} return paused;
}
Expand Down Expand Up @@ -308,8 +311,8 @@ namespace Tomato {
}
}

public static void main(string[] args) {
Gtk.init(ref args);
public static void main (string[] args) {
Gtk.init (ref args);

TomatoApp app = new TomatoApp ();
app.run (args);
Expand Down
4 changes: 2 additions & 2 deletions src/Widgets/Screen.vala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace Tomato.Widget {

public void add_controls (Gtk.Widget[] controls) {
foreach (Gtk.Widget control in controls) {
add_control (control);
add_control (control);
}
}

Expand All @@ -78,7 +78,7 @@ namespace Tomato.Widget {
private void setup_control_box () {
control_box.set_layout (Gtk.ButtonBoxStyle.CENTER);
control_box.set_spacing (6);
control_box.set_valign (Gtk.Align.END);
control_box.set_valign (Gtk.Align.END);
control_box.set_margin_bottom (15);
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/Widgets/Slide.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,26 @@ namespace Tomato.Widget {

private List<Screen> screens;

public signal void changed (Screen s);
public signal void changed (Screen s);

public Slide () {
screens = new List<Screen> ();
set_transition_duration (500);
this.expand = true;
this.expand = true;
}

public void add_screen (Screen screen) {
add_named (screen, screen.get_name ());
screens.append (screen);
}

public void set_visible_screen (string name, Gtk.StackTransitionType transition = Gtk.StackTransitionType.SLIDE_LEFT) {
public void set_visible_screen (
string name,
Gtk.StackTransitionType transition = Gtk.StackTransitionType.SLIDE_LEFT
) {
set_visible_child_full (name, transition);
message (name);
changed (find_screen (name));
message (name);
changed (find_screen (name));
}

public Screen? get_visible_screen () {
Expand Down
137 changes: 72 additions & 65 deletions src/Windows/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace Tomato.Window {

public class MainWindow : Gtk.Dialog {
private const string COLOR_PRIMARY = """
private const string COLOR_PRIMARY = """
@define-color colorPrimary %s;

.main-window.background,
Expand All @@ -40,11 +40,11 @@ namespace Tomato.Window {

private TomatoApp app;

private Gtk.HeaderBar headerbar;
private Gtk.HeaderBar headerbar;
private Gtk.MenuButton appmenu;
private Gtk.MenuItem preferences;
private Widget.Slide slide;
private Gtk.Box content;
private Gtk.Box content;

private Gtk.Label countdown_label;
private Gtk.Label total_time_label;
Expand All @@ -56,7 +56,7 @@ namespace Tomato.Window {

// constructor
public MainWindow (TomatoApp app) {
Object (use_header_bar: 1);
Object (use_header_bar: 1);

this.app = app;
this.title = Constants.APP_NAME;
Expand All @@ -75,8 +75,8 @@ namespace Tomato.Window {
stop = new Gtk.Button.with_label (_("Stop"));
skip = new Gtk.Button.with_label (_("Skip"));

content = this.get_content_area ();
headerbar = this.get_header_bar () as Gtk.HeaderBar;
content = this.get_content_area ();
headerbar = this.get_header_bar () as Gtk.HeaderBar;

setup_layout ();
setup_style ();
Expand All @@ -87,16 +87,16 @@ namespace Tomato.Window {

next_status (Gtk.StackTransitionType.NONE);

/**
* Allow moving the window
*/
this.button_press_event.connect ((e) => {
if (e.button == Gdk.BUTTON_PRIMARY) {
this.begin_move_drag ((int) e.button, (int) e.x_root, (int) e.y_root, e.time);
return true;
}
return false;
});
/**
* Allow moving the window
*/
this.button_press_event.connect ((e) => {
if (e.button == Gdk.BUTTON_PRIMARY) {
this.begin_move_drag ((int) e.button, (int) e.x_root, (int) e.y_root, e.time);
return true;
}
return false;
});
}

public void set_pause (bool topause = true) {
Expand All @@ -115,7 +115,7 @@ namespace Tomato.Window {

if (saved.status == Status.START) {
slide.set_visible_screen ("start", transition);
this.set_title ("Pomodoro %d".printf(saved.pomodoro_count+1));
this.set_title ("Pomodoro %d".printf (saved.pomodoro_count + 1));
appmenu.set_sensitive (true);
} else if (saved.status == Status.SHORT_BREAK) {
slide.set_visible_screen ("break", transition);
Expand All @@ -127,7 +127,7 @@ namespace Tomato.Window {
appmenu.set_sensitive (true);
} else {
slide.set_visible_screen ("pomodoro", transition);
this.set_title ("Pomodoro %d".printf(saved.pomodoro_count+1));
this.set_title ("Pomodoro %d".printf (saved.pomodoro_count + 1));
appmenu.set_sensitive (false);
}

Expand Down Expand Up @@ -156,7 +156,10 @@ namespace Tomato.Window {
}

public void update_total_time () {
if ((saved.status == Status.START || saved.status == Status.SHORT_BREAK || saved.status == Status.LONG_BREAK || paused) && saved.total_time != 0) {
if ((saved.status == Status.START || saved.status == Status.SHORT_BREAK
|| saved.status == Status.LONG_BREAK || paused)
&& saved.total_time != 0
) {
total_time_label.set_label (work.formatted_total_time () + _(" of work"));
} else {
total_time_label.set_label ("");
Expand All @@ -176,13 +179,13 @@ namespace Tomato.Window {
appmenu.set_image (menu_icon);
appmenu.popup = menu;

appmenu.valign = Gtk.Align.CENTER;
appmenu.valign = Gtk.Align.CENTER;

appmenu.get_style_context ().add_class ("close");
appmenu.get_style_context ().add_class ("titlebutton");
appmenu.get_style_context ().remove_class ("image-button");
appmenu.get_style_context ().add_class ("close");
appmenu.get_style_context ().add_class ("titlebutton");
appmenu.get_style_context ().remove_class ("image-button");

headerbar.pack_end (appmenu);
headerbar.pack_end (appmenu);
}

private void setup_stack () {
Expand All @@ -203,7 +206,7 @@ namespace Tomato.Window {
private void setup_layout () {
setup_headerbar ();
setup_stack ();
content.add (slide);
content.add (slide);
}

private void setup_style () {
Expand All @@ -227,12 +230,12 @@ namespace Tomato.Window {
resume.get_style_context ().add_class ("pomodoro-button");
pause.get_style_context ().add_class ("pomodoro-button");
stop.get_style_context ().add_class ("pomodoro-button");
start.get_style_context ().add_class ("pomodoro-button");
start.get_style_context ().add_class ("pomodoro-button");

headerbar.get_style_context ().add_class ("compact");
headerbar.get_style_context ().add_class ("main-window");
headerbar.get_style_context ().add_class ("compact");
headerbar.get_style_context ().add_class ("main-window");

this.get_style_context ().add_class ("main-window");
this.get_style_context ().add_class ("main-window");
}

private void connect_signals () {
Expand All @@ -243,45 +246,49 @@ namespace Tomato.Window {
skip.clicked.connect (() => {skip_clicked ();});
preferences.activate.connect (() => {preferences_clicked ();});

this.slide.changed.connect ((s) => {
string color_primary;

switch (s.get_name ()) {
case "start":
color_primary = "#8ea5af";
break;
case "pomodoro":
color_primary = "#df4b4b";
break;
case "break":
color_primary = "#05B560";
break;
default:
color_primary = "#8ea5af";
break;
}

var provider = new Gtk.CssProvider ();
try {
var colored_css = COLOR_PRIMARY.printf (color_primary);
provider.load_from_data (colored_css, colored_css.length);

Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (GLib.Error e) {
critical (e.message);
}
});
this.slide.changed.connect ((s) => {
string color_primary;

switch (s.get_name ()) {
case "start":
color_primary = "#8ea5af";
break;
case "pomodoro":
color_primary = "#df4b4b";
break;
case "break":
color_primary = "#05B560";
break;
default:
color_primary = "#8ea5af";
break;
}

var provider = new Gtk.CssProvider ();
try {
var colored_css = COLOR_PRIMARY.printf (color_primary);
provider.load_from_data (colored_css, colored_css.length);

Gtk.StyleContext.add_provider_for_screen (
Gdk.Screen.get_default (),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);
} catch (GLib.Error e) {
critical (e.message);
}
});

this.delete_event.connect (quit);
}

private bool quit () {
if (!paused) {
hide ();
return true;
}
Gtk.main_quit ();
return false;
}
private bool quit () {
if (!paused) {
hide ();
return true;
}
Gtk.main_quit ();
return false;
}
}
}
Loading