Update gtk153
This commit is contained in:
parent
784fb5a94f
commit
1c87d0e365
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"*.xpm": "cpp"
|
"*.xpm": "cpp",
|
||||||
}
|
"chrono": "cpp"
|
||||||
|
},
|
||||||
|
"cmake.configureOnOpen": true
|
||||||
}
|
}
|
|
@ -26,7 +26,7 @@ link_directories (${GTK4_LIBRARY_DIRS})
|
||||||
# set(PO_DIR ${CMAKE_BINARY_DIR}/po/zh_CN/LC_MESSAGES)
|
# set(PO_DIR ${CMAKE_BINARY_DIR}/po/zh_CN/LC_MESSAGES)
|
||||||
|
|
||||||
#Source files
|
#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
|
#Compile Resource
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,41 @@
|
||||||
#include "MyReminder.h"
|
#include "MyReminder.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
struct _MyReminder
|
struct _MyReminder
|
||||||
{
|
{
|
||||||
GtkApplicationWindow parent_instance;
|
GtkApplicationWindow parent_instance;
|
||||||
GtkLabel *label1;
|
GtkWidget *time_label;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE(MyReminder, my_reminder, GTK_TYPE_APPLICATION_WINDOW)
|
G_DEFINE_TYPE(MyReminder, my_reminder, GTK_TYPE_APPLICATION_WINDOW)
|
||||||
|
|
||||||
static void my_reminder_init(MyReminder *self)
|
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), "<span foreground=\"blue\" size='16pt'>%d</span>\nDays Left", time);
|
||||||
|
}else{
|
||||||
|
strncpy(time_str, "<span foreground=\"blue\" size='16pt'>Time is out!</span>", 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)
|
static void my_reminder_class_init(MyReminderClass *klass)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
#include "../json_nlohmann/json.hpp"
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
G_DECLARE_FINAL_TYPE(MyReminder, my_reminder, MY, REMINDER, GtkApplicationWindow)
|
G_DECLARE_FINAL_TYPE(MyReminder, my_reminder, MY, REMINDER, GtkApplicationWindow)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
#include <cstdio>
|
||||||
|
#include <ctime>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cstdlib>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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
|
||||||
|
// }
|
Loading…
Reference in New Issue