diff --git a/Gtk4/gtk153_time_reminder/.vscode/settings.json b/Gtk4/gtk153_time_reminder/.vscode/settings.json
index b7960d1..3ef0924 100644
--- a/Gtk4/gtk153_time_reminder/.vscode/settings.json
+++ b/Gtk4/gtk153_time_reminder/.vscode/settings.json
@@ -1,6 +1,8 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"files.associations": {
- "*.xpm": "cpp"
- }
+ "*.xpm": "cpp",
+ "chrono": "cpp"
+ },
+ "cmake.configureOnOpen": true
}
\ No newline at end of file
diff --git a/Gtk4/gtk153_time_reminder/CMakeLists.txt b/Gtk4/gtk153_time_reminder/CMakeLists.txt
index 8900131..46b227e 100644
--- a/Gtk4/gtk153_time_reminder/CMakeLists.txt
+++ b/Gtk4/gtk153_time_reminder/CMakeLists.txt
@@ -26,7 +26,7 @@ link_directories (${GTK4_LIBRARY_DIRS})
# set(PO_DIR ${CMAKE_BINARY_DIR}/po/zh_CN/LC_MESSAGES)
#Source files
-set(SOURCE_FILE src/main.cpp src/MyReminder.cpp)
+set(SOURCE_FILE src/main.cpp src/MyReminder.cpp src/timer.cpp)
#Compile Resource
diff --git a/Gtk4/gtk153_time_reminder/src/MyReminder.cpp b/Gtk4/gtk153_time_reminder/src/MyReminder.cpp
index ca6096b..5cf40ff 100644
--- a/Gtk4/gtk153_time_reminder/src/MyReminder.cpp
+++ b/Gtk4/gtk153_time_reminder/src/MyReminder.cpp
@@ -1,16 +1,41 @@
#include "MyReminder.h"
+#include "timer.h"
struct _MyReminder
{
GtkApplicationWindow parent_instance;
- GtkLabel *label1;
+ GtkWidget *time_label;
};
G_DEFINE_TYPE(MyReminder, my_reminder, GTK_TYPE_APPLICATION_WINDOW)
static void my_reminder_init(MyReminder *self)
{
+ // Set properties of window
+ gtk_window_set_icon_name(GTK_WINDOW(self), "org.gtk.daleclack");
+ gtk_window_set_default_size(GTK_WINDOW(self), 240, 200);
+ gtk_window_set_title(GTK_WINDOW(self), "Reminder");
+
+ // Create and add a label
+ self->time_label = gtk_label_new(" ");
+
+ // Get time duration
+ char time_str[57];
+ int time = get_time_duration(2023, 12, 23);
+ if(time >= 0){
+ snprintf(time_str, sizeof(time_str), "%d\nDays Left", time);
+ }else{
+ strncpy(time_str, "Time is out!", 13);
+ }
+ // Text style of the label
+ gtk_label_set_markup(GTK_LABEL(self->time_label), time_str);
+ gtk_label_set_use_markup(GTK_LABEL(self->time_label), TRUE);
+
+ // // Set label
+ // gtk_label_set_label(GTK_LABEL(self->time_label), time_str);
+
+ gtk_window_set_child(GTK_WINDOW(self), self->time_label);
}
static void my_reminder_class_init(MyReminderClass *klass)
diff --git a/Gtk4/gtk153_time_reminder/src/MyReminder.h b/Gtk4/gtk153_time_reminder/src/MyReminder.h
index 627051f..a686ab0 100644
--- a/Gtk4/gtk153_time_reminder/src/MyReminder.h
+++ b/Gtk4/gtk153_time_reminder/src/MyReminder.h
@@ -1,7 +1,9 @@
#pragma once
#include
+#include "../json_nlohmann/json.hpp"
+using json = nlohmann::json;
G_DECLARE_FINAL_TYPE(MyReminder, my_reminder, MY, REMINDER, GtkApplicationWindow)
diff --git a/Gtk4/gtk153_time_reminder/src/timer.cpp b/Gtk4/gtk153_time_reminder/src/timer.cpp
new file mode 100644
index 0000000..f4c778f
--- /dev/null
+++ b/Gtk4/gtk153_time_reminder/src/timer.cpp
@@ -0,0 +1,89 @@
+#include
+#include
+#include
+#include
+#include "timer.h"
+
+// typedef void(*LP)(struct tm *local);//define a pointer function
+#define MAX_PATH 260
+
+int total_day(int year, int month, int day)
+{
+ // Calculate day of 1 year
+ int sum = 0;
+ switch (month)
+ {
+ case 1:
+ sum = day;
+ break;
+ case 2:
+ sum = day + 31;
+ break;
+ case 3:
+ sum = day + 59;
+ break;
+ case 4:
+ sum = day + 90;
+ break;
+ case 5:
+ sum = day + 120;
+ break;
+ case 6:
+ sum = day + 151;
+ break;
+ case 7:
+ sum = day + 181;
+ break;
+ case 8:
+ sum = day + 212;
+ break;
+ case 9:
+ sum = day + 243;
+ break;
+ case 10:
+ sum = day + 273;
+ break;
+ case 11:
+ sum = day + 304;
+ break;
+ case 12:
+ sum = day + 334;
+ break;
+ default:
+ printf("Date Wrong!");
+ }
+ if (year % 4 == 0 && year % 100 != 0)
+ sum = sum + 1;
+ return sum;
+}
+
+int total_year_day(int year1, int year2)
+{
+ // Calculate day of years
+ int sum = 0;
+ sum = (year2 - year1) * 365;
+ for (int i = year1; i < year2; i++)
+ {
+ if (i % 4 == 0 && i % 100 != 0)
+ {
+ sum = sum + 1;
+ }
+ }
+ return sum;
+}
+
+int get_time_duration(int year, int month, int day)
+{
+ // Get Current time
+ time_t t;
+ t = time(NULL);
+ struct tm *local;
+ local = localtime(&t);
+
+ // Calculate duration
+ int duration_day = total_year_day(year, local->tm_year + 1900)
+ + total_day(year, month, day)
+ - total_day(local->tm_year + 1900, local->tm_mon + 1, local->tm_mday);
+
+ return duration_day;
+}
diff --git a/Gtk4/gtk153_time_reminder/src/timer.h b/Gtk4/gtk153_time_reminder/src/timer.h
new file mode 100644
index 0000000..c6ca657
--- /dev/null
+++ b/Gtk4/gtk153_time_reminder/src/timer.h
@@ -0,0 +1,16 @@
+#pragma once
+// These code from xe release
+
+int total_day(int year,int month,int day);
+
+int total_year_day(int year1,int year2);
+
+int get_time_duration(int year, int month, int day);
+
+// static inline bool rel_unix_file_system_detected(){
+// #ifdef _WIN32
+// return false;
+// #else
+// return true;
+// #endif
+// }