Skip to content

Commit

Permalink
1.0.6 - Add sorting by name/time
Browse files Browse the repository at this point in the history
  • Loading branch information
Lains committed Mar 5, 2020
1 parent dfca497 commit cd39afd
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 17 deletions.
8 changes: 8 additions & 0 deletions data/com.github.lainsce.khronos.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
<content_attribute id="money-gambling">none</content_attribute>
</content_rating>
<releases>
<release version="1.0.6" date="2020-03-06">
<description>
<p>Release: Start Sorting</p>
<ul>
<li>Added: Sorting Options on Settings Menu</li>
</ul>
</description>
</release>
<release version="1.0.3" date="2020-02-21">
<description>
<p>Release: Start Building Up</p>
Expand Down
5 changes: 5 additions & 0 deletions data/com.github.lainsce.khronos.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@
<summary>Use notifications</summary>
<description>Whether to alert the user via notifications, default is false.</description>
</key>
<key name="sort-type" type="s">
<default>'time'</default>
<summary>Sorting type for the task list</summary>
<description>The user-preferred sorting of tasks to use in Khronos, default is time</description>
</key>
</schema>
</schemalist>
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Name our project
project('com.github.lainsce.khronos', ['vala', 'c'],
version: '1.0.2'
version: '1.0.6'
)

# Import main lib files
Expand Down
25 changes: 25 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Khronos {
// Widgets
public DayColumn column;
public Gtk.Grid grid;
public Gtk.Grid sort_type_grid;

public TaskManager tm;
public Gtk.Application app { get; construct; }
Expand Down Expand Up @@ -119,11 +120,15 @@ namespace Khronos {
notification_box.add (notification_sb);
notification_box.show_all ();

sort_type_menu_item ();

var menu_grid = new Gtk.Grid ();
menu_grid.margin = 6;
menu_grid.row_spacing = 6;
menu_grid.column_spacing = 12;
menu_grid.orientation = Gtk.Orientation.VERTICAL;
menu_grid.add (sort_type_grid);
menu_grid.add (separator);
menu_grid.add (notification_box);
menu_grid.show_all ();

Expand Down Expand Up @@ -190,6 +195,26 @@ namespace Khronos {
return false;
}

public void sort_type_menu_item () {
var sort_time = new Gtk.RadioButton.with_label_from_widget (null, _("Sort By Time"));
sort_time.toggled.connect (() => {
Khronos.Application.gsettings.set_string("sort-type", "time");
});

var sort_name = new Gtk.RadioButton.with_label_from_widget (sort_time, _("Sort By Name"));
sort_name.toggled.connect (() => {
Khronos.Application.gsettings.set_string("sort-type", "name");
});
sort_name.set_active (true);

sort_type_grid = new Gtk.Grid ();
sort_type_grid.row_spacing = 12;
sort_type_grid.orientation = Gtk.Orientation.VERTICAL;
sort_type_grid.add (sort_time);
sort_type_grid.add (sort_name);
sort_type_grid.show_all ();
}

public void set_timeouts () {
if (column.start) {
id1 = Timeout.add_seconds (Khronos.Application.gsettings.get_int("notification-delay"), () => {
Expand Down
52 changes: 36 additions & 16 deletions src/Widgets/ColumnListBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,42 @@ namespace Khronos {
this.activate_on_single_click = false;
this.selection_mode = Gtk.SelectionMode.SINGLE;
this.set_sort_func ((row1, row2) => {
string task1 = ((TaskBox) row1).time;
string task2 = ((TaskBox) row2).time;

int int1 = int.parse(task1);
int int2 = int.parse(task2);

unichar str1 = task1.get_char (task1.index_of_nth_char (0));
unichar str2 = task2.get_char (task2.index_of_nth_char (0));

if (str1.tolower () != 'a' || str2.tolower () != 'a') {
return strcmp (task1.ascii_down (), task2.ascii_down ());
} else if (int1 > int2) {
return task1.ascii_down ().collate (task2.ascii_down ());
} else {
return 0;
if (Khronos.Application.gsettings.get_string ("sort-type") == "time") {
string task1 = ((TaskBox) row1).time;
string task2 = ((TaskBox) row2).time;

int int1 = int.parse(task1);
int int2 = int.parse(task2);

unichar str1 = task1.get_char (task1.index_of_nth_char (0));
unichar str2 = task2.get_char (task2.index_of_nth_char (0));

if (str1.tolower () != '0' || str2.tolower () != '0') {
return strcmp (task1.ascii_down (), task2.ascii_down ());
} else if (int1 > int2) {
return task1.ascii_down ().collate (task2.ascii_down ());
} else {
return 0;
}
} else if (Khronos.Application.gsettings.get_string ("sort-type") == "name") {
string task1 = ((TaskBox) row1).name;
string task2 = ((TaskBox) row2).name;

int int1 = int.parse(task1);
int int2 = int.parse(task2);

unichar str1 = task1.get_char (task1.index_of_nth_char (0));
unichar str2 = task2.get_char (task2.index_of_nth_char (0));

if (str1.tolower () != 'a' || str2.tolower () != 'a') {
return strcmp (task1.ascii_down (), task2.ascii_down ());
} else if (int1 > int2) {
return task1.ascii_down ().collate (task2.ascii_down ());
} else {
return 0;
}
}
return 0;
});

this.build_drag_and_drop ();
Expand Down Expand Up @@ -79,4 +99,4 @@ namespace Khronos {
win.tm.save_notes ();
}
}
}
}

0 comments on commit cd39afd

Please sign in to comment.