diff --git a/CMakeLists.txt b/CMakeLists.txt index 2252ce7a..9eca2791 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,8 +140,10 @@ OPTIONS ${GLOBAL_VALAC_OPTIONS} ) -add_executable(com.github.philip-scott.notes-up ${VALA_C} ${generated_resources}) +include (gresource) +glib_compile_resources(GLIB_RESOURCES_ICONS SOURCE /data/assets.gresource.xml) +add_executable(com.github.philip-scott.notes-up ${VALA_C} ${GLIB_RESOURCES_ICONS}) install(TARGETS com.github.philip-scott.notes-up RUNTIME DESTINATION bin) diff --git a/cmake/gresource.cmake b/cmake/gresource.cmake index fd9c76b8..1f47b059 100644 --- a/cmake/gresource.cmake +++ b/cmake/gresource.cmake @@ -1,37 +1,69 @@ -# Used for GResource. # -# resource_dir: Directory where the .gresource.xml is located. -# resource_file: Filename of the .gresource.xml file (just the -# filename, not the complete path). -# output_dir: Directory where the C output file is written. -# output_file: This variable will be set with the complete path of the -# output C file. +# Copyright (C) 2013 Venom authors and contributors +# +# This file is part of Venom. +# +# Venom 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. +# +# Venom 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 Venom. If not, see . +# + +FIND_PROGRAM(GLIB_COMPILE_RESOURCES_EXECUTABLE NAMES glib-compile-resources) +MARK_AS_ADVANCED(GLIB_COMPILE_RESOURCES_EXECUTABLE) + +INCLUDE(CMakeParseArguments) -function (gresource resource_dir resource_file output_dir output_file) - # Get the output file path - get_filename_component (resource_name ${resource_file} NAME_WE) - set (output "${output_dir}/${resource_name}-resources.c") - set (${output_file} ${output} PARENT_SCOPE) +FUNCTION(GLIB_COMPILE_RESOURCES output) + CMAKE_PARSE_ARGUMENTS(ARGS "" "" "SOURCE" ${ARGN}) + SET(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + SET(out_files "") - # Get the dependencies of the gresource - execute_process ( - OUTPUT_VARIABLE _files - WORKING_DIRECTORY ${resource_dir} - COMMAND ${gresources_executable} --generate-dependencies ${resource_file} - ) + FOREACH(src ${ARGS_SOURCE} ${ARGS_UNPARSED_ARGUMENTS}) + SET(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${src}") + GET_FILENAME_COMPONENT(WORKING_DIR ${in_file} PATH) + STRING(REPLACE ".xml" ".c" src ${src}) + SET(out_file "${DIRECTORY}/${src}") + GET_FILENAME_COMPONENT(OUPUT_DIR ${out_file} PATH) + FILE(MAKE_DIRECTORY ${OUPUT_DIR}) + LIST(APPEND out_files "${DIRECTORY}/${src}") - string (REPLACE "\n" ";" files ${_files}) + #FIXME implicit depends currently not working + EXECUTE_PROCESS( + COMMAND + ${GLIB_COMPILE_RESOURCES_EXECUTABLE} + "--generate-dependencies" + ${in_file} + WORKING_DIRECTORY ${WORKING_DIR} + OUTPUT_VARIABLE in_file_dep + ) + STRING(REGEX REPLACE "(\r?\n)" ";" in_file_dep "${in_file_dep}") + SET(in_file_dep_path "") + FOREACH(dep ${in_file_dep}) + LIST(APPEND in_file_dep_path "${WORKING_DIR}/${dep}") + ENDFOREACH(dep ${in_file_dep}) + ADD_CUSTOM_COMMAND( + OUTPUT ${out_file} + WORKING_DIRECTORY ${WORKING_DIR} + COMMAND + ${GLIB_COMPILE_RESOURCES_EXECUTABLE} + ARGS + "--generate-source" + "--target=${out_file}" + ${in_file} + DEPENDS + ${in_file};${in_file_dep_path} + ) + ENDFOREACH(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS}) + SET(${output} ${out_files} PARENT_SCOPE) +ENDFUNCTION(GLIB_COMPILE_RESOURCES) - set (depends "") - foreach (cur_file ${files}) - list (APPEND depends "${resource_dir}/${cur_file}") - endforeach () - # Command to compile the resources - add_custom_command ( - OUTPUT ${output} - DEPENDS "${resource_dir}/${resource_file}" ${depends} - WORKING_DIRECTORY ${resource_dir} - COMMAND ${gresources_executable} --generate-source --target=${output} ${resource_file} - ) -endfunction () diff --git a/data/assets.gresource.xml b/data/assets.gresource.xml new file mode 100644 index 00000000..9a7ebba2 --- /dev/null +++ b/data/assets.gresource.xml @@ -0,0 +1,6 @@ + + + + stylesheet.css + + diff --git a/data/stylesheet.css b/data/stylesheet.css new file mode 100644 index 00000000..911ac7a9 --- /dev/null +++ b/data/stylesheet.css @@ -0,0 +1,13 @@ +.title-label { + font-size: 1.2em; + font-weight: 700; +} + +.preview-label { + opacity:1; +} + +.date-time-label { + opacity:0.6; + font-size:0.9em; +} diff --git a/schemas/org.notes.gschema.xml b/schemas/org.notes.gschema.xml index 4584ece7..d874b047 100644 --- a/schemas/org.notes.gschema.xml +++ b/schemas/org.notes.gschema.xml @@ -91,7 +91,7 @@ - "Open Sans 12" + "Open Sans 10" Editor font The editor's font family and size diff --git a/src/Application.vala b/src/Application.vala index 9f3a03f4..06cf3677 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -62,6 +62,8 @@ public class ENotes.Application : Granite.Application { public const string PROGRAM_NAME = N_("Notes-Up"); public const string COMMENT = N_("Your Markdown Notebook."); public const string ABOUT_STOCK = N_("About Notes"); + private Settings interface_settings; + public string clock_format { get; set; } public bool running = false; @@ -88,6 +90,18 @@ public class ENotes.Application : Granite.Application { if (!running) { settings = ENotes.Services.Settings.get_instance (); + var interface_settings_schema = SettingsSchemaSource.get_default ().lookup ("org.gnome.desktop.interface", true); + if (interface_settings_schema == null || !interface_settings_schema.has_key ("clock_format")) { + info ("No clock settings schema found, using 12 hours as a fallback"); + } else { + interface_settings = new GLib.Settings ("org.gnome.desktop.interface"); + interface_settings.bind ("clock_format", this, "clock_format", GLib.SettingsBindFlags.GET); + + // I'm not sure how to actually get access to the above or if I'm even doing it right + + info (clock_format); + } + if (settings.notes_database == "") { // Init databases var notes_dir = GLib.Environment.get_home_dir () + "/.local/share/notes-up/"; DirUtils.create_with_parents (notes_dir, 0766); diff --git a/src/Services/Page.vala b/src/Services/Page.vala index 18730726..122ee46d 100644 --- a/src/Services/Page.vala +++ b/src/Services/Page.vala @@ -161,19 +161,19 @@ public class ENotes.PageTable : DatabaseTable { } public Page new_page (int64 notebook_id) { - var stmt = create_stmt ("INSERT INTO Page (notebook_id, name, creation_date, modification_date) " + var stmt = create_stmt ("INSERT INTO Page (notebook_id, name, creation_date, modification_date) " + "VALUES (?, ?, CAST(strftime('%s', 'now') AS INT), CAST(strftime('%s', 'now') AS INT))"); - bind_int (stmt, 1, notebook_id); - bind_text (stmt, 2, _("New Page")); + bind_int (stmt, 1, notebook_id); + bind_text (stmt, 2, _("New Page")); - stmt.step (); + stmt.step (); - return get_page (last_insert_row ()); + return get_page (last_insert_row ()); } public Gee.ArrayList get_pages (int64 notebook_id) { - var stmt = create_stmt ("SELECT id, name, subtitle, data FROM Page Where notebook_id = ?"); + var stmt = create_stmt ("SELECT id, name, subtitle, data, creation_date, modification_date FROM Page Where notebook_id = ?"); bind_int (stmt, 1, notebook_id); var pages = new Gee.ArrayList(); @@ -193,6 +193,8 @@ public class ENotes.PageTable : DatabaseTable { row.name = stmt.column_text (1); row.subtitle = stmt.column_text (2); row.data = stmt.column_text (3); + row.creation_date = stmt.column_int64 (4); + row.modification_date = stmt.column_int64 (5); pages.add (row); } diff --git a/src/Widgets/PageItem.vala b/src/Widgets/PageItem.vala index 9ba19fd9..abc4d513 100644 --- a/src/Widgets/PageItem.vala +++ b/src/Widgets/PageItem.vala @@ -23,8 +23,12 @@ public class ENotes.PageItem : Gtk.ListBoxRow { public ENotes.Page page; private Gtk.Grid grid; - private Gtk.Label line1; - private Gtk.Label line2; + private Gtk.Label name_label; + private Gtk.Label preview_label; + private Gtk.Label date_label; + private DateTime time; + private string date_formatted; + private const int HORIZONTAL_MARGIN = 12; public PageItem (ENotes.Page page) { this.page = page; @@ -37,35 +41,49 @@ public class ENotes.PageItem : Gtk.ListBoxRow { grid = new Gtk.Grid (); grid.orientation = Gtk.Orientation.VERTICAL; - line1 = new Gtk.Label (""); - line1.use_markup = true; - line1.halign = Gtk.Align.START; - line1.get_style_context ().add_class ("h3"); - line1.ellipsize = Pango.EllipsizeMode.END; - ((Gtk.Misc) line1).xalign = 0; - line1.margin_top = 4; - line1.margin_left = 8; - line1.margin_right = 8; - line1.margin_bottom = 4; + name_label = new Gtk.Label (""); + name_label.ellipsize = Pango.EllipsizeMode.END; + name_label.get_style_context ().add_class ("title-label"); + name_label.halign = Gtk.Align.START; + name_label.margin_left = HORIZONTAL_MARGIN; + name_label.margin_right = HORIZONTAL_MARGIN; + name_label.margin_top = 8; + name_label.margin_bottom = 0; // Because the gap between name_label and the below is otherwise uneven compared to the gap between the preview_label and the labe, due to the smaller font-size of the date_label + name_label.use_markup = true; + ((Gtk.Misc) name_label).xalign = 0; - line2 = new Gtk.Label (""); - line2.halign = Gtk.Align.START; - line2.margin_left = 8; - line2.margin_right = 8; - line2.margin_bottom = 4; - line2.use_markup = true; - line2.set_line_wrap (true); - line2.ellipsize = Pango.EllipsizeMode.END; - ((Gtk.Misc) line2).xalign = 0; - line2.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); - line2.lines = 3; + preview_label = new Gtk.Label (""); + preview_label.ellipsize = Pango.EllipsizeMode.END; + preview_label.get_style_context ().add_class ("preview-label"); + preview_label.halign = Gtk.Align.START; + preview_label.lines = 2; + preview_label.margin_left = HORIZONTAL_MARGIN; + preview_label.margin_right = HORIZONTAL_MARGIN; + preview_label.margin_top = 3; + preview_label.margin_bottom = 2; + preview_label.set_line_wrap (true); + preview_label.use_markup = true; + ((Gtk.Misc) preview_label).xalign = 0; + + date_label = new Gtk.Label (""); + date_label.ellipsize = Pango.EllipsizeMode.END; + date_label.get_style_context ().add_class ("date-time-label"); + date_label.halign = Gtk.Align.START; + date_label.lines = 1; + date_label.margin_left = HORIZONTAL_MARGIN; + date_label.margin_right = HORIZONTAL_MARGIN; + date_label.margin_top = 3; + date_label.margin_bottom = 10; + date_label.set_line_wrap (true); + ((Gtk.Misc) date_label).xalign = 0; var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL); separator.hexpand = true; this.add (grid); - grid.add (line1); - grid.add (line2); + grid.add (name_label); + grid.add (preview_label); + grid.add (date_label); grid.add (separator); load_data (); @@ -77,8 +95,17 @@ public class ENotes.PageItem : Gtk.ListBoxRow { } public void load_data () { - this.line2.label = page.subtitle; - this.line1.label = "" + page.name + ""; + time = new DateTime.from_unix_utc (page.modification_date); + //if (ENotes.Application.clock_format == "24h") { + // date_formatted = time.format (_("%a, %e %b %y, %H:%M")).strip (); + //} else { + // date_formatted = time.format (_("%a, %e %b %y, %l:%M %p")).strip (); + //} + + date_formatted = "Sat, 18 Mar 2018, 10:40 PM"; + this.date_label.label = date_formatted; + this.preview_label.label = page.subtitle; + this.name_label.label = page.name; } } diff --git a/src/Widgets/Window.vala b/src/Widgets/Window.vala index d12bbf2a..3a6daec4 100644 --- a/src/Widgets/Window.vala +++ b/src/Widgets/Window.vala @@ -41,6 +41,11 @@ public class ENotes.Window : Gtk.ApplicationWindow { } private void build_ui () { + + var provider = new Gtk.CssProvider (); + provider.load_from_resource ("/com/github/philip-scott/notes-up/stylesheet.css"); + Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + headerbar = ENotes.Headerbar.get_instance (); set_titlebar (headerbar);