Add features to the mini window
This commit is contained in:
+67
-25
@@ -35,11 +35,6 @@ struct _TimerMainWindow {
|
||||
/* time in seconds */
|
||||
gint64 currentTime;
|
||||
GDateTime *startTime;
|
||||
|
||||
int widthBuff;
|
||||
int heightBuff;
|
||||
int xBuff;
|
||||
int yBuff;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(TimerMainWindow, timer_main_window, GTK_TYPE_APPLICATION_WINDOW);
|
||||
@@ -131,6 +126,7 @@ static void timer_main_window_interpret_settings(TimerMainWindow *self) {
|
||||
self, "Settings", "Always on Top", FALSE));
|
||||
|
||||
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(self->nameBox));
|
||||
gtk_combo_box_text_remove_all(timer_mini_window_get_name_box(self->miniWindow));
|
||||
gsize len;
|
||||
GError *err = NULL;
|
||||
char **data = g_key_file_get_string_list(self->keyFile, "Settings", "Tasks",
|
||||
@@ -142,6 +138,8 @@ static void timer_main_window_interpret_settings(TimerMainWindow *self) {
|
||||
for (i = 0; i < len; ++i) {
|
||||
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(self->nameBox),
|
||||
data[i]);
|
||||
gtk_combo_box_text_append_text(timer_mini_window_get_name_box(self->miniWindow),
|
||||
data[i]);
|
||||
g_free(data[i]);
|
||||
}
|
||||
g_free(data);
|
||||
@@ -154,6 +152,8 @@ static void timer_main_window_interpret_settings(TimerMainWindow *self) {
|
||||
self, "Cache", "Current Name", "");
|
||||
gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(self->nameBox))),
|
||||
taskName);
|
||||
gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(
|
||||
timer_mini_window_get_name_box(self->miniWindow)))), taskName);
|
||||
g_free(taskName);
|
||||
int x = g_key_file_get_integer(self->keyFile, "Cache", "x", NULL);
|
||||
int y = g_key_file_get_integer(self->keyFile, "Cache", "y", NULL);
|
||||
@@ -253,8 +253,8 @@ static void start_stop_button_callback(GtkButton *btn, TimerMainWindow *win) {
|
||||
gtk_button_set_label(GTK_BUTTON(win->startStopButton), "Stop");
|
||||
gtk_button_set_label(timer_mini_window_get_start_stop_button(win->miniWindow), "Stop");
|
||||
gtk_widget_set_sensitive(win->resetButton, TRUE);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(timer_mini_window_get_reset_button(win->miniWindow)), TRUE);
|
||||
gtk_widget_set_sensitive(win->saveButton, TRUE);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(timer_mini_window_get_save_button(win->miniWindow)), TRUE);
|
||||
win->startTime = g_date_time_new_now_local();
|
||||
timer_main_window_update_time(win);
|
||||
}
|
||||
@@ -269,8 +269,8 @@ static void reset_button_callback(GtkButton *btn, TimerMainWindow *win) {
|
||||
gtk_button_set_label(GTK_BUTTON(win->startStopButton), "Start");
|
||||
gtk_button_set_label(timer_mini_window_get_start_stop_button(win->miniWindow), "Start");
|
||||
gtk_widget_set_sensitive(win->resetButton, FALSE);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(timer_mini_window_get_reset_button(win->miniWindow)), FALSE);
|
||||
gtk_widget_set_sensitive(win->saveButton, FALSE);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(timer_mini_window_get_save_button(win->miniWindow)), FALSE);
|
||||
g_date_time_unref(win->startTime);
|
||||
win->startTime = NULL;
|
||||
}
|
||||
@@ -279,8 +279,12 @@ static void save_button_callback(GtkButton *btn, TimerMainWindow *win) {
|
||||
if (timer_clock_is_running(win->timerClock)) {
|
||||
timer_clock_stop(win->timerClock);
|
||||
}
|
||||
const char *text =
|
||||
gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(win->nameBox));
|
||||
const char *text;
|
||||
if (win->miniWindowMode) {
|
||||
text = gtk_combo_box_text_get_active_text(timer_mini_window_get_name_box(win->miniWindow));
|
||||
} else {
|
||||
text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(win->nameBox));
|
||||
}
|
||||
timer_task_tree_add_task(TIMER_TASK_TREE(win->taskTree), win->startTime,
|
||||
strcmp(text, "") == 0 ? "Untitled" : text,
|
||||
win->currentTime);
|
||||
@@ -289,8 +293,10 @@ static void save_button_callback(GtkButton *btn, TimerMainWindow *win) {
|
||||
win->startTime = NULL;
|
||||
timer_main_window_update_time(win);
|
||||
gtk_button_set_label(GTK_BUTTON(win->startStopButton), "Start");
|
||||
gtk_button_set_label(timer_mini_window_get_start_stop_button(win->miniWindow), "Start");
|
||||
gtk_widget_set_sensitive(win->resetButton, FALSE);
|
||||
gtk_widget_set_sensitive(win->saveButton, FALSE);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(timer_mini_window_get_save_button(win->miniWindow)), FALSE);
|
||||
}
|
||||
|
||||
static void timer_button_callback(GtkButton *btn, TimerMainWindow *win) {
|
||||
@@ -298,6 +304,7 @@ static void timer_button_callback(GtkButton *btn, TimerMainWindow *win) {
|
||||
timer_clock_stop(win->timerClock);
|
||||
timer_main_window_update_time(win);
|
||||
gtk_button_set_label(GTK_BUTTON(win->startStopButton), "Start");
|
||||
gtk_button_set_label(timer_mini_window_get_start_stop_button(win->miniWindow), "Start");
|
||||
}
|
||||
gsize optLen;
|
||||
const char **names =
|
||||
@@ -323,6 +330,7 @@ static void timer_button_callback(GtkButton *btn, TimerMainWindow *win) {
|
||||
timer_main_window_update_time(win);
|
||||
gtk_widget_set_sensitive(win->resetButton, TRUE);
|
||||
gtk_widget_set_sensitive(win->saveButton, TRUE);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(timer_mini_window_get_save_button(win->miniWindow)), TRUE);
|
||||
}
|
||||
gtk_widget_destroy(GTK_WIDGET(diag));
|
||||
}
|
||||
@@ -357,17 +365,21 @@ static void timer_main_window_get_defualt_label_color(TimerMainWindow *self) {
|
||||
(int)round(color.blue * 255));
|
||||
}
|
||||
|
||||
void timer_main_window_save_mini_window_pos(TimerMainWindow *self, int x, int y) {
|
||||
static void timer_main_window_save_mini_window_specs(TimerMainWindow *self, int x, int y, int w, int h) {
|
||||
g_key_file_set_integer(self->keyFile, "Cache", "smallX", x);
|
||||
g_key_file_set_integer(self->keyFile, "Cache", "smallY", y);
|
||||
g_key_file_set_integer(self->keyFile, "Cache", "smallW", w);
|
||||
g_key_file_set_integer(self->keyFile, "Cache", "smallH", h);
|
||||
}
|
||||
|
||||
void timer_main_window_read_mini_window_pos(TimerMainWindow *self, int *x, int *y) {
|
||||
static void timer_main_window_read_mini_window_specs(TimerMainWindow *self, int *x, int *y, int *w, int *h) {
|
||||
*x = g_key_file_get_integer(self->keyFile, "Cache", "smallX", NULL);
|
||||
*y = g_key_file_get_integer(self->keyFile, "Cache", "smallY", NULL);
|
||||
*w = g_key_file_get_integer(self->keyFile, "Cache", "smallW", NULL);
|
||||
*h = g_key_file_get_integer(self->keyFile, "Cache", "smallH", NULL);
|
||||
}
|
||||
|
||||
static gboolean window_configure_callback(TimerMainWindow *win, GdkEventConfigure event, gpointer ptr) {
|
||||
static gboolean window_configure_callback(TimerMainWindow *win, GdkEvent *event, gpointer ptr) {
|
||||
int x, y, w, h;
|
||||
gtk_window_get_size(GTK_WINDOW(win), &w, &h);
|
||||
gtk_window_get_position(GTK_WINDOW(win), &x, &y);
|
||||
@@ -408,53 +420,83 @@ static gboolean window_delete_event(TimerMainWindow *win, GdkEvent *evt, gpointe
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean mini_window_configure_callback(TimerMiniWindow *win, GdkEventConfigure event, TimerMainWindow *main) {
|
||||
static gboolean mini_window_configure_callback(TimerMiniWindow *win, GdkEvent *event, TimerMainWindow *main) {
|
||||
if (main->miniWindowMode) {
|
||||
int x, y;
|
||||
int x, y, w, h;
|
||||
gtk_window_get_position(GTK_WINDOW(win), &x, &y);
|
||||
timer_main_window_save_mini_window_pos(main, x, y);
|
||||
gtk_window_get_size(GTK_WINDOW(win), &w, &h);
|
||||
timer_main_window_save_mini_window_specs(main, x, y, w, h);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean mini_window_delete_event(TimerMiniWindow *win, GdkEvent *evt, TimerMainWindow *main) {
|
||||
if (main->startTime != NULL) {
|
||||
GtkWidget *diag = gtk_message_dialog_new(GTK_WINDOW(win), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Are you sure you would like to exit?");
|
||||
gtk_window_set_position(GTK_WINDOW(diag), GTK_WIN_POS_MOUSE);
|
||||
int resp = gtk_dialog_run(GTK_DIALOG(diag));
|
||||
gtk_widget_destroy(diag);
|
||||
if (resp != GTK_RESPONSE_NO) {
|
||||
main->miniWindowMode = FALSE;
|
||||
gtk_widget_destroy(GTK_WIDGET(main));
|
||||
}
|
||||
}
|
||||
main->miniWindowMode = FALSE;
|
||||
gtk_widget_hide(GTK_WIDGET(win));
|
||||
gtk_widget_show_all(GTK_WIDGET(main));
|
||||
return FALSE;
|
||||
gtk_widget_destroy(GTK_WIDGET(main));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void mini_window_expand_callback(GtkButton *btn, TimerMainWindow *win) {
|
||||
win->miniWindowMode = FALSE;
|
||||
gtk_widget_hide(GTK_WIDGET(win->miniWindow));
|
||||
const char *text = gtk_combo_box_text_get_active_text(timer_mini_window_get_name_box(win->miniWindow));
|
||||
gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(win->nameBox))), text);
|
||||
if (timer_main_window_is_always_on_top(win)) {
|
||||
gtk_window_set_keep_above(GTK_WINDOW(win), TRUE);
|
||||
}
|
||||
gtk_widget_show_all(GTK_WIDGET(win));
|
||||
g_key_file_set_boolean(win->keyFile, "Cache", "isMini", FALSE);
|
||||
}
|
||||
|
||||
static void init_mini_window(TimerMainWindow *self) {
|
||||
self->miniWindowFirstOpen = TRUE;
|
||||
self->miniWindowMode = FALSE;
|
||||
self->miniWindowFirstOpen = TRUE;
|
||||
self->miniWindow = timer_mini_window_new();
|
||||
g_signal_connect(self->miniWindow, "configure-event", G_CALLBACK(mini_window_configure_callback), self);
|
||||
g_signal_connect(self->miniWindow, "delete-event", G_CALLBACK(mini_window_delete_event), self);
|
||||
g_signal_connect(timer_mini_window_get_start_stop_button(self->miniWindow),
|
||||
"clicked", G_CALLBACK(start_stop_button_callback), self);
|
||||
g_signal_connect(timer_mini_window_get_reset_button(self->miniWindow),
|
||||
"clicked", G_CALLBACK(reset_button_callback), self);
|
||||
g_signal_connect(timer_mini_window_get_save_button(self->miniWindow),
|
||||
"clicked", G_CALLBACK(save_button_callback), self);
|
||||
g_signal_connect(timer_mini_window_get_expand_button(self->miniWindow),
|
||||
"clicked", G_CALLBACK(mini_window_expand_callback), self);
|
||||
g_signal_connect(timer_mini_window_get_timer_button(self->miniWindow),
|
||||
"clicked", G_CALLBACK(timer_button_callback), self);
|
||||
}
|
||||
|
||||
static void main_window_collapse_callback(GtkButton *btn, TimerMainWindow *win) {
|
||||
gtk_widget_hide(GTK_WIDGET(win));
|
||||
const char *text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(win->nameBox));
|
||||
gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(timer_mini_window_get_name_box(win->miniWindow)))), text);
|
||||
gtk_window_set_keep_above(GTK_WINDOW(win->miniWindow), TRUE);
|
||||
gtk_widget_show_all(GTK_WIDGET(win->miniWindow));
|
||||
win->miniWindowMode = TRUE;
|
||||
if (win->miniWindowFirstOpen) {
|
||||
gtk_window_set_keep_above(GTK_WINDOW(win->miniWindow), TRUE);
|
||||
int x, y;
|
||||
timer_main_window_read_mini_window_pos(win, &x, &y);
|
||||
int x, y, w, h;
|
||||
timer_main_window_read_mini_window_specs(win, &x, &y, &w, &h);
|
||||
gtk_window_move(GTK_WINDOW(win->miniWindow), x, y);
|
||||
gtk_window_resize(GTK_WINDOW(win->miniWindow), w, h);
|
||||
win->miniWindowFirstOpen = FALSE;
|
||||
}
|
||||
win->miniWindowMode = TRUE;
|
||||
g_key_file_set_boolean(win->keyFile, "Cache", "isMini", TRUE);
|
||||
}
|
||||
|
||||
void timer_main_window_show_for_mode(TimerMainWindow *self) {
|
||||
if (g_key_file_get_boolean(self->keyFile, "Cache", "isMini", NULL)) {
|
||||
main_window_collapse_callback(NULL, self);
|
||||
} else {
|
||||
mini_window_expand_callback(NULL, self);
|
||||
}
|
||||
}
|
||||
|
||||
static void timer_main_window_finalize(GObject *self) {
|
||||
|
||||
Reference in New Issue
Block a user