project: Move all UI-related files to src/gui/

So we can have a nice separation.
This commit is contained in:
Georges Basile Stavracas Neto
2020-10-30 14:44:33 -03:00
parent 92863f578f
commit e67ebcfc50
39 changed files with 11 additions and 28 deletions
-3
View File
@@ -26,7 +26,6 @@
#include "gcal-context.h"
#include "gcal-debug.h"
#include "gcal-log.h"
#include "gcal-resources.h"
#include "gcal-shell-search-provider.h"
#include "gcal-window.h"
@@ -613,8 +612,6 @@ gcal_application_init (GcalApplication *self)
{
GcalManager *manager;
g_resources_register (calendar_get_resource ());
g_application_add_main_option_entries (G_APPLICATION (self), gcal_application_goptions);
self->context = gcal_context_new ();
+294
View File
@@ -0,0 +1,294 @@
/* gcal-search-button.c
*
* Copyright 2019 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#define G_LOG_DOMAIN "GcalSearchButton"
#include "gcal-context.h"
#include "gcal-search-button.h"
#include "gcal-search-hit.h"
#include <math.h>
#define MIN_WIDTH 450
struct _GcalSearchButton
{
DzlSuggestionButton parent;
GCancellable *cancellable;
GcalContext *context;
};
G_DEFINE_TYPE (GcalSearchButton, gcal_search_button, DZL_TYPE_SUGGESTION_BUTTON)
enum
{
PROP_0,
PROP_CONTEXT,
N_PROPS
};
static GParamSpec *properties [N_PROPS];
/*
* Callbacks
*/
static void
position_suggestion_popover_func (DzlSuggestionEntry *entry,
GdkRectangle *area,
gboolean *is_absolute,
gpointer user_data)
{
gint new_width;
#define RIGHT_MARGIN 6
dzl_suggestion_entry_window_position_func (entry, area, is_absolute, NULL);
new_width = MAX (area->width * 2 / 5, MIN_WIDTH);
area->x += area->width - new_width;
area->width = new_width - RIGHT_MARGIN;
area->y -= 3;
#undef RIGHT_MARGIN
}
static void
on_search_finished_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
g_autoptr (GListModel) model = NULL;
g_autoptr (GError) error = NULL;
DzlSuggestionEntry *entry;
GcalSearchButton *self;
self = GCAL_SEARCH_BUTTON (user_data);
model = gcal_search_engine_search_finish (GCAL_SEARCH_ENGINE (source_object), result, &error);
entry = dzl_suggestion_button_get_entry (DZL_SUGGESTION_BUTTON (self));
dzl_suggestion_entry_set_model (entry, model);
}
static void
on_search_entry_changed_cb (GcalSearchButton *self)
{
g_autofree gchar *sexp_query = NULL;
DzlSuggestionEntry *entry;
GcalSearchEngine *search_engine;
const gchar *typed_text;
entry = dzl_suggestion_button_get_entry (DZL_SUGGESTION_BUTTON (self));
typed_text = dzl_suggestion_entry_get_typed_text (entry);
g_cancellable_cancel (self->cancellable);
if (dzl_str_empty0 (typed_text))
{
dzl_suggestion_entry_set_model (entry, NULL);
return;
}
sexp_query = g_strdup_printf ("(contains? \"summary\" \"%s\")", typed_text);
search_engine = gcal_context_get_search_engine (self->context);
gcal_search_engine_search (search_engine,
sexp_query,
50,
self->cancellable,
on_search_finished_cb,
g_object_ref (self));
}
static void
on_search_entry_suggestion_activated_cb (DzlSuggestionEntry *entry,
GcalSearchHit *search_hit,
GcalSearchButton *self)
{
gcal_search_hit_activate (search_hit, GTK_WIDGET (self));
}
static void
on_unfocus_action_activated_cb (GSimpleAction *action,
GVariant *param,
gpointer user_data)
{
DzlSuggestionEntry *entry;
GcalSearchButton *self;
GtkWidget *toplevel;
g_assert (GCAL_IS_SEARCH_BUTTON (user_data));
g_assert (G_IS_SIMPLE_ACTION (action));
g_debug ("Unfocusing search button");
self = GCAL_SEARCH_BUTTON (user_data);
entry = dzl_suggestion_button_get_entry (DZL_SUGGESTION_BUTTON (self));
g_signal_emit_by_name (entry, "hide-suggestions");
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
gtk_widget_grab_focus (toplevel);
gtk_entry_set_text (GTK_ENTRY (entry), "");
}
static void
on_shortcut_grab_focus_cb (GtkWidget *widget,
gpointer user_data)
{
g_debug ("Focusing search button");
gtk_widget_grab_focus (GTK_WIDGET (user_data));
}
/*
* GObject overrides
*/
static void
gcal_search_button_finalize (GObject *object)
{
GcalSearchButton *self = (GcalSearchButton *)object;
g_cancellable_cancel (self->cancellable);
g_clear_object (&self->cancellable);
g_clear_object (&self->context);
G_OBJECT_CLASS (gcal_search_button_parent_class)->finalize (object);
}
static void
gcal_search_button_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GcalSearchButton *self = GCAL_SEARCH_BUTTON (object);
switch (prop_id)
{
case PROP_CONTEXT:
g_value_set_object (value, self->context);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gcal_search_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GcalSearchButton *self = GCAL_SEARCH_BUTTON (object);
switch (prop_id)
{
case PROP_CONTEXT:
g_assert (self->context == NULL);
self->context = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gcal_search_button_class_init (GcalSearchButtonClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gcal_search_button_finalize;
object_class->get_property = gcal_search_button_get_property;
object_class->set_property = gcal_search_button_set_property;
/**
* GcalSearchButton::context:
*
* The #GcalContext of the application.
*/
properties[PROP_CONTEXT] = g_param_spec_object ("context",
"Context of the application",
"The context of the application",
GCAL_TYPE_CONTEXT,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
gcal_search_button_init (GcalSearchButton *self)
{
g_autoptr (GSimpleActionGroup) group = NULL;
DzlShortcutController *controller;
DzlSuggestionEntry *entry;
static GActionEntry actions[] = {
{ "unfocus", on_unfocus_action_activated_cb },
};
group = g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP (group),
actions,
G_N_ELEMENTS (actions),
self);
gtk_widget_insert_action_group (GTK_WIDGET (self), "search", G_ACTION_GROUP (group));
entry = dzl_suggestion_button_get_entry (DZL_SUGGESTION_BUTTON (self));
g_signal_connect_object (entry,
"changed",
G_CALLBACK (on_search_entry_changed_cb),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (entry,
"suggestion-activated",
G_CALLBACK (on_search_entry_suggestion_activated_cb),
self,
0);
dzl_suggestion_entry_set_position_func (entry,
position_suggestion_popover_func,
self,
NULL);
controller = dzl_shortcut_controller_find (GTK_WIDGET (entry));
dzl_shortcut_controller_add_command_callback (controller,
"org.gnome.calendar.search",
"<Primary>f",
DZL_SHORTCUT_PHASE_CAPTURE | DZL_SHORTCUT_PHASE_GLOBAL,
on_shortcut_grab_focus_cb,
self,
NULL);
dzl_shortcut_controller_add_command_action (controller,
"org.gnome.calendar.search-button.unfocus",
"Escape",
DZL_SHORTCUT_PHASE_CAPTURE,
"search.unfocus");
}
+30
View File
@@ -0,0 +1,30 @@
/* gcal-search-button.h
*
* Copyright 2019 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include <dazzle.h>
G_BEGIN_DECLS
#define GCAL_TYPE_SEARCH_BUTTON (gcal_search_button_get_type())
G_DECLARE_FINAL_TYPE (GcalSearchButton, gcal_search_button, GCAL, SEARCH_BUTTON, DzlSuggestionButton)
G_END_DECLS
+362
View File
@@ -0,0 +1,362 @@
/* gcal-weather-settings.c
*
* Copyright © 2018 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define G_LOG_DOMAIN "GcalWeatherSettings"
#include "gcal-context.h"
#include "gcal-debug.h"
#include "gcal-manager.h"
#include "gcal-utils.h"
#include "gcal-weather-service.h"
#include "gcal-weather-settings.h"
struct _GcalWeatherSettings
{
GtkBox parent;
GtkSwitch *show_weather_switch;
GtkSwitch *weather_auto_location_switch;
GtkWidget *weather_location_entry;
GcalContext *context;
};
static void on_weather_location_searchbox_changed_cb (GWeatherLocationEntry *entry,
GcalWeatherSettings *self);
static void on_show_weather_changed_cb (GtkSwitch *wswitch,
GParamSpec *pspec,
GcalWeatherSettings *self);
static void on_weather_auto_location_changed_cb (GtkSwitch *lswitch,
GParamSpec *pspec,
GcalWeatherSettings *self);
G_DEFINE_TYPE (GcalWeatherSettings, gcal_weather_settings, GTK_TYPE_BOX)
enum
{
PROP_0,
PROP_CONTEXT,
N_PROPS
};
static GParamSpec *properties [N_PROPS] = { NULL, };
/*
* Auxiliary methods
*/
static void
load_weather_settings (GcalWeatherSettings *self)
{
g_autoptr (GVariant) location = NULL;
g_autoptr (GVariant) value = NULL;
g_autofree gchar *location_name = NULL;
GSettings *settings;
gboolean show_weather;
gboolean auto_location;
GCAL_ENTRY;
if (!self->context)
GCAL_RETURN ();
settings = gcal_context_get_settings (self->context);
value = g_settings_get_value (settings, "weather-settings");
g_variant_get (value, "(bbsmv)",
&show_weather,
&auto_location,
&location_name,
&location);
g_signal_handlers_block_by_func (self->show_weather_switch, on_show_weather_changed_cb, self);
g_signal_handlers_block_by_func (self->weather_auto_location_switch, on_weather_auto_location_changed_cb, self);
g_signal_handlers_block_by_func (self->weather_location_entry, on_weather_location_searchbox_changed_cb, self);
gtk_switch_set_active (self->show_weather_switch, show_weather);
gtk_switch_set_active (self->weather_auto_location_switch, auto_location);
if (!location && !auto_location)
{
GtkStyleContext *context;
context = gtk_widget_get_style_context (GTK_WIDGET (self->weather_location_entry));
gtk_entry_set_text (GTK_ENTRY (self->weather_location_entry), location_name);
gtk_style_context_add_class (context, "error");
}
else
{
g_autoptr (GWeatherLocation) weather_location;
GWeatherLocation *world;
world = gweather_location_get_world ();
weather_location = location ? gweather_location_deserialize (world, location) : NULL;
gweather_location_entry_set_location (GWEATHER_LOCATION_ENTRY (self->weather_location_entry), weather_location);
}
g_signal_handlers_unblock_by_func (self->show_weather_switch, on_show_weather_changed_cb, self);
g_signal_handlers_unblock_by_func (self->weather_auto_location_switch, on_weather_auto_location_changed_cb, self);
g_signal_handlers_unblock_by_func (self->weather_location_entry, on_weather_location_searchbox_changed_cb, self);
GCAL_EXIT;
}
static void
save_weather_settings (GcalWeatherSettings *self)
{
g_autoptr (GWeatherLocation) location = NULL;
GSettings *settings;
GVariant *value;
GVariant *vlocation;
gboolean res;
GCAL_ENTRY;
if (!self->context)
GCAL_RETURN ();
location = gweather_location_entry_get_location (GWEATHER_LOCATION_ENTRY (self->weather_location_entry));
vlocation = location ? gweather_location_serialize (location) : NULL;
settings = gcal_context_get_settings (self->context);
value = g_variant_new ("(bbsmv)",
gtk_switch_get_active (self->show_weather_switch),
gtk_switch_get_active (self->weather_auto_location_switch),
gtk_entry_get_text (GTK_ENTRY (self->weather_location_entry)),
vlocation);
res = g_settings_set_value (settings, "weather-settings", value);
if (!res)
g_warning ("Could not persist weather settings");
GCAL_EXIT;
}
static void
update_menu_weather_sensitivity (GcalWeatherSettings *self)
{
gboolean weather_enabled;
gboolean autoloc_enabled;
weather_enabled = gtk_switch_get_active (self->show_weather_switch);
autoloc_enabled = gtk_switch_get_active (self->weather_auto_location_switch);
gtk_widget_set_sensitive (GTK_WIDGET (self->weather_auto_location_switch), weather_enabled);
gtk_widget_set_sensitive (GTK_WIDGET (self->weather_location_entry), weather_enabled && !autoloc_enabled);
}
static GWeatherLocation*
get_checked_fixed_location (GcalWeatherSettings *self)
{
g_autoptr (GWeatherLocation) location;
location = gweather_location_entry_get_location (GWEATHER_LOCATION_ENTRY (self->weather_location_entry));
/*
* NOTE: This check feels shabby. However, I couldn't find a better
* one without iterating the model. has-custom-text does not work
* properly. Lets go with it for now.
*/
if (location && gweather_location_get_name (location))
return g_steal_pointer (&location);
return NULL;
}
static void
manage_weather_service (GcalWeatherSettings *self)
{
GcalWeatherService *weather_service;
GCAL_ENTRY;
weather_service = gcal_context_get_weather_service (self->context);
if (gtk_switch_get_active (self->show_weather_switch))
{
g_autoptr (GWeatherLocation) location = NULL;
if (!gtk_switch_get_active (self->weather_auto_location_switch))
{
location = get_checked_fixed_location (self);
if (!location)
g_warning ("Unknown location '%s' selected", gtk_entry_get_text (GTK_ENTRY (self->weather_location_entry)));
}
gcal_weather_service_run (weather_service, location);
}
else
{
gcal_weather_service_stop (weather_service);
}
GCAL_EXIT;
}
/*
* Callbacks
*/
static void
on_show_weather_changed_cb (GtkSwitch *wswitch,
GParamSpec *pspec,
GcalWeatherSettings *self)
{
save_weather_settings (self);
update_menu_weather_sensitivity (self);
manage_weather_service (self);
}
static void
on_weather_auto_location_changed_cb (GtkSwitch *lswitch,
GParamSpec *pspec,
GcalWeatherSettings *self)
{
save_weather_settings (self);
update_menu_weather_sensitivity (self);
manage_weather_service (self);
}
static void
on_weather_location_searchbox_changed_cb (GWeatherLocationEntry *entry,
GcalWeatherSettings *self)
{
GtkStyleContext *context;
GWeatherLocation *location;
gboolean auto_location;
save_weather_settings (self);
context = gtk_widget_get_style_context (self->weather_location_entry);
auto_location = gtk_switch_get_active (self->weather_auto_location_switch);
location = get_checked_fixed_location (self);
if (!location && !auto_location)
{
gtk_style_context_add_class (context, "error");
}
else
{
gtk_style_context_remove_class (context, "error");
manage_weather_service (self);
gweather_location_unref (location);
}
}
/*
* GObject overrides
*/
static void
gcal_weather_settings_finalize (GObject *object)
{
GcalWeatherSettings *self = (GcalWeatherSettings *)object;
g_clear_object (&self->context);
G_OBJECT_CLASS (gcal_weather_settings_parent_class)->finalize (object);
}
static void
gcal_weather_settings_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GcalWeatherSettings *self = GCAL_WEATHER_SETTINGS (object);
switch (prop_id)
{
case PROP_CONTEXT:
g_value_set_object (value, self->context);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gcal_weather_settings_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GcalWeatherSettings *self = GCAL_WEATHER_SETTINGS (object);
switch (prop_id)
{
case PROP_CONTEXT:
g_assert (self->context == NULL);
self->context = g_value_dup_object (value);
load_weather_settings (self);
update_menu_weather_sensitivity (self);
manage_weather_service (self);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gcal_weather_settings_class_init (GcalWeatherSettingsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = gcal_weather_settings_finalize;
object_class->get_property = gcal_weather_settings_get_property;
object_class->set_property = gcal_weather_settings_set_property;
properties[PROP_CONTEXT] = g_param_spec_object ("context",
"Context",
"Context",
GCAL_TYPE_CONTEXT,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/gui/gcal-weather-settings.ui");
gtk_widget_class_bind_template_child (widget_class, GcalWeatherSettings, show_weather_switch);
gtk_widget_class_bind_template_child (widget_class, GcalWeatherSettings, weather_auto_location_switch);
gtk_widget_class_bind_template_child (widget_class, GcalWeatherSettings, weather_location_entry);
gtk_widget_class_bind_template_callback (widget_class, on_show_weather_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, on_weather_auto_location_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, on_weather_location_searchbox_changed_cb);
}
static void
gcal_weather_settings_init (GcalWeatherSettings *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
+31
View File
@@ -0,0 +1,31 @@
/* gcal-weather-settings.h
*
* Copyright © 2018 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "gcal-weather-service.h"
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GCAL_TYPE_WEATHER_SETTINGS (gcal_weather_settings_get_type())
G_DECLARE_FINAL_TYPE (GcalWeatherSettings, gcal_weather_settings, GCAL, WEATHER_SETTINGS, GtkBox)
G_END_DECLS
+77
View File
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.14"/>
<template class="GcalWeatherSettings" parent="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="margin">12</property>
<property name="spacing">6</property>
<child>
<object class="GtkModelButton">
<property name="text" translatable="yes">_Weather</property>
<property name="menu-name">main</property>
<property name="inverted">True</property>
<property name="centered">True</property>
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">18</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="xalign">0.0</property>
<property name="label" translatable="yes">Show Weather</property>
</object>
</child>
<child>
<object class="GtkSwitch" id="show_weather_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<signal name="notify::active" handler="on_show_weather_changed_cb" object="GcalWeatherSettings" swapped="no" />
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox" id="weather_auto_location_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">18</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="xalign">0.0</property>
<property name="label" translatable="yes">Automatic Location</property>
</object>
</child>
<child>
<object class="GtkSwitch" id="weather_auto_location_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<signal name="notify::active" handler="on_weather_auto_location_changed_cb" object="GcalWeatherSettings" swapped="no" />
</object>
</child>
</object>
</child>
<child>
<object class="GWeatherLocationEntry" id="weather_location_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
<signal name="changed" handler="on_weather_location_searchbox_changed_cb" object="GcalWeatherSettings" swapped="no" />
<signal name="activate" handler="on_weather_location_searchbox_changed_cb" object="GcalWeatherSettings" swapped="no" />
</object>
</child>
</template>
</interface>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/calendar/gtk">
<file compressed="true">help-overlay.ui</file>
</gresource>
</gresources>
+122
View File
@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkShortcutsWindow" id="help_overlay">
<property name="modal">True</property>
<child>
<object class="GtkShortcutsSection">
<property name="visible">True</property>
<property name="section-name">shortcuts</property>
<property name="max-height">17</property>
<child>
<object class="GtkShortcutsGroup">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">General</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">New event</property>
<property name="accelerator">&lt;Primary&gt;N</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Close window</property>
<property name="accelerator">&lt;Primary&gt;Q</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Search</property>
<property name="accelerator">&lt;Primary&gt;F</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Show help</property>
<property name="accelerator">F1</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Shortcuts</property>
<property name="accelerator">&lt;Primary&gt;question &lt;Primary&gt;F1</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkShortcutsGroup">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Navigation</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Go back</property>
<property name="accelerator">&lt;alt&gt;Left Page_Up</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Go forward</property>
<property name="accelerator">&lt;alt&gt;Right Page_Down</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Show today</property>
<property name="accelerator">&lt;alt&gt;Down &lt;Primary&gt;T Home</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Next view</property>
<property name="accelerator">&lt;Primary&gt;Page_Down</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Previous view</property>
<property name="accelerator">&lt;Primary&gt;Page_Up</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkShortcutsGroup">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">View</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Week view</property>
<property name="accelerator">&lt;Primary&gt;1</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Month view</property>
<property name="accelerator">&lt;Primary&gt;2</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Year view</property>
<property name="accelerator">&lt;Primary&gt;3</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
+5
View File
@@ -0,0 +1,5 @@
built_sources += gnome.compile_resources(
'gtk-resources',
'gtk.gresource.xml',
c_name: 'gtk',
)
+1
View File
@@ -10,6 +10,7 @@
<file compressed="true">gcal-quick-add-popover.ui</file>
<file compressed="true">gcal-multi-choice.ui</file>
<file compressed="true">gcal-time-selector.ui</file>
<file compressed="true">gcal-weather-settings.ui</file>
<file compressed="true">gcal-window.ui</file>
</gresource>
</gresources>
+4
View File
@@ -1,4 +1,6 @@
subdir('calendar-management')
subdir('gtk')
subdir('views')
calendar_incs += include_directories('.')
@@ -19,6 +21,8 @@ sources += files(
'gcal-event-widget.c',
'gcal-multi-choice.c',
'gcal-quick-add-popover.c',
'gcal-search-button.c',
'gcal-time-selector.c',
'gcal-weather-settings.c',
'gcal-window.c',
)
+703
View File
@@ -0,0 +1,703 @@
/* gcal-month-cell.c
*
* Copyright (C) 2017 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define G_LOG_DOMAIN "GcalMonthCell"
#include "config.h"
#include "gcal-application.h"
#include "gcal-clock.h"
#include "gcal-debug.h"
#include "gcal-event-widget.h"
#include "gcal-utils.h"
#include "gcal-month-cell.h"
struct _GcalMonthCell
{
GtkEventBox parent;
GDateTime *date;
guint n_overflow;
GtkLabel *day_label;
GtkWidget *header_box;
GtkImage *weather_icon;
GtkLabel *temp_label;
GtkWidget *overflow_button;
GtkWidget *overflow_label;
GtkWidget *overlay;
gboolean different_month;
gboolean selected;
/* internal fields */
gboolean hovered : 1;
gboolean pressed : 1;
GcalContext *context;
GcalWeatherInfo *weather_info;
};
G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, GTK_TYPE_EVENT_BOX)
enum
{
SHOW_OVERFLOW,
N_SIGNALS
};
enum
{
PROP_0,
PROP_CONTEXT,
N_PROPS
};
static guint signals[N_SIGNALS] = { 0, };
static GParamSpec *properties[N_PROPS] = { 0, };
/*
* Auxiliary methods
*/
static void
update_style_flags (GcalMonthCell *self)
{
g_autoptr (GDateTime) today;
GtkStyleContext *context;
GtkStateFlags flags;
GtkWidget *widget;
widget = GTK_WIDGET (self);
flags = gtk_widget_get_state_flags (widget);
if (self->hovered)
flags |= GTK_STATE_FLAG_PRELIGHT;
else
flags &= ~GTK_STATE_FLAG_PRELIGHT;
gtk_widget_set_state_flags (widget, flags, TRUE);
/* Today */
today = g_date_time_new_now_local ();
context = gtk_widget_get_style_context (GTK_WIDGET (self));
if (gcal_date_time_compare_date (self->date, today) == 0)
gtk_style_context_add_class (context, "today");
else
gtk_style_context_remove_class (context, "today");
}
static gboolean
should_propagate_button_event (GtkWidget *widget,
GdkEventButton *event_button)
{
GcalMonthCell *self;
gdouble x, y;
gint button_height, height;
self = GCAL_MONTH_CELL (widget);
height = gtk_widget_get_allocated_height (widget);
button_height = gtk_widget_get_allocated_height (self->overflow_button);
x = event_button->x;
y = event_button->y;
if (!gcal_translate_child_window_position (widget, event_button->window, x, y, &x, &y))
return GDK_EVENT_PROPAGATE;
if (self->n_overflow > 0 && y > height - button_height)
return GDK_EVENT_STOP;
return GDK_EVENT_PROPAGATE;
}
/*
* Callbacks
*/
static void
day_changed_cb (GcalClock *clock,
GcalMonthCell *self)
{
update_style_flags (self);
}
static gboolean
enter_notify_event_cb (GtkWidget *widget,
GdkEventCrossing *event_crossing,
GcalMonthCell *self)
{
self->hovered = TRUE;
update_style_flags (self);
return GDK_EVENT_PROPAGATE;
}
static gboolean
leave_notify_event_cb (GtkWidget *widget,
GdkEventCrossing *event_crossing,
GcalMonthCell *self)
{
self->hovered = FALSE;
update_style_flags (self);
return GDK_EVENT_PROPAGATE;
}
static void
overflow_button_clicked_cb (GtkWidget *button,
GcalMonthCell *self)
{
g_signal_emit (self, signals[SHOW_OVERFLOW], 0, button);
}
/*
* GtkWidget overrides
*/
static gboolean
gcal_month_cell_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time)
{
GcalMonthCell *self;
self = GCAL_MONTH_CELL (widget);
if (self->different_month)
gtk_drag_unhighlight (widget);
else
gtk_drag_highlight (widget);
gdk_drag_status (context, self->different_month ? 0 : GDK_ACTION_MOVE, time);
return !self->different_month;
}
static gboolean
gcal_month_cell_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time)
{
g_autoptr (GcalEvent) changed_event = NULL;
GcalRecurrenceModType mod;
GcalMonthCell *self;
GcalCalendar *calendar;
GtkWidget *event_widget;
GDateTime *start_dt, *end_dt;
GcalEvent *event;
gint diff;
gint start_month, current_month;
gint start_year, current_year;
GTimeSpan timespan = 0;
self = GCAL_MONTH_CELL (widget);
event_widget = gtk_drag_get_source_widget (context);
mod = GCAL_RECURRENCE_MOD_THIS_ONLY;
GCAL_ENTRY;
if (!GCAL_IS_EVENT_WIDGET (event_widget))
GCAL_RETURN (FALSE);
if (self->different_month)
GCAL_RETURN (FALSE);
event = gcal_event_widget_get_event (GCAL_EVENT_WIDGET (event_widget));
changed_event = gcal_event_new_from_event (event);
calendar = gcal_event_get_calendar (changed_event);
if (gcal_event_has_recurrence (changed_event) &&
!ask_recurrence_modification_type (widget, &mod, calendar))
{
GCAL_GOTO (out);
}
/* Move the event's date */
start_dt = gcal_event_get_date_start (changed_event);
end_dt = gcal_event_get_date_end (changed_event);
start_month = g_date_time_get_month (start_dt);
start_year = g_date_time_get_year (start_dt);
current_month = g_date_time_get_month (self->date);
current_year = g_date_time_get_year (self->date);
timespan = g_date_time_difference (end_dt, start_dt);
start_dt = g_date_time_add_full (start_dt,
current_year - start_year,
current_month - start_month,
0, 0, 0, 0);
diff = g_date_time_get_day_of_month (self->date) - g_date_time_get_day_of_month (start_dt);
if (diff != 0 ||
current_month != start_month ||
current_year != start_year)
{
g_autoptr (GDateTime) new_start;
new_start = g_date_time_add_days (start_dt, diff);
gcal_event_set_date_start (changed_event, new_start);
/* The event may have a NULL end date, so we have to check it here */
if (end_dt)
{
GDateTime *new_end = g_date_time_add (new_start, timespan);
gcal_event_set_date_end (changed_event, new_end);
g_clear_pointer (&new_end, g_date_time_unref);
}
gcal_manager_update_event (gcal_context_get_manager (self->context), changed_event, mod);
}
g_clear_pointer (&start_dt, g_date_time_unref);
out:
/* Cancel the DnD */
gtk_drag_unhighlight (widget);
gtk_drag_finish (context, TRUE, FALSE, time);
GCAL_RETURN (TRUE);
}
static void
gcal_month_cell_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time)
{
gtk_drag_unhighlight (widget);
}
static gboolean
gcal_month_cell_button_press_event (GtkWidget *widget,
GdkEventButton *event_button)
{
GcalMonthCell *self = GCAL_MONTH_CELL (widget);
self->pressed = TRUE;
return should_propagate_button_event (widget, event_button);
}
static gboolean
gcal_month_cell_button_release_event (GtkWidget *widget,
GdkEventButton *event_button)
{
GcalMonthCell *self = GCAL_MONTH_CELL (widget);
if (!self->pressed)
return GDK_EVENT_STOP;
self->pressed = FALSE;
return should_propagate_button_event (widget, event_button);
}
static gboolean
gcal_month_cell_draw (GtkWidget *widget,
cairo_t *cr)
{
GtkStyleContext *context;
gint width, height;
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
context = gtk_widget_get_style_context (widget);
gtk_render_background (context, cr, 0, 0, width, height);
gtk_render_frame (context, cr, 0, 0, width, height);
if (gtk_widget_has_focus (widget))
gtk_render_focus (context, cr, 0, 0, width, height);
return GTK_WIDGET_CLASS (gcal_month_cell_parent_class)->draw (widget, cr);
}
/*
* GObject overrides
*/
static void
gcal_month_cell_finalize (GObject *object)
{
GcalMonthCell *self = (GcalMonthCell *)object;
gcal_clear_date_time (&self->date);
g_clear_object (&self->context);
G_OBJECT_CLASS (gcal_month_cell_parent_class)->finalize (object);
}
static void
gcal_month_cell_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GcalMonthCell *self = (GcalMonthCell *) object;
switch (property_id)
{
case PROP_CONTEXT:
gcal_month_cell_set_context (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gcal_month_cell_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GcalMonthCell *self = (GcalMonthCell *) object;
switch (property_id)
{
case PROP_CONTEXT:
g_value_set_object (value, self->context);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gcal_month_cell_class_init (GcalMonthCellClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = gcal_month_cell_finalize;
object_class->set_property = gcal_month_cell_set_property;
object_class->get_property = gcal_month_cell_get_property;
widget_class->button_press_event = gcal_month_cell_button_press_event;
widget_class->button_release_event = gcal_month_cell_button_release_event;
widget_class->drag_motion = gcal_month_cell_drag_motion;
widget_class->drag_drop = gcal_month_cell_drag_drop;
widget_class->drag_leave = gcal_month_cell_drag_leave;
widget_class->draw = gcal_month_cell_draw;
signals[SHOW_OVERFLOW] = g_signal_new ("show-overflow",
GCAL_TYPE_MONTH_CELL,
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE,
1,
GTK_TYPE_WIDGET);
properties[PROP_CONTEXT] = g_param_spec_object ("context",
"Context",
"The GcalContext of the application",
GCAL_TYPE_CONTEXT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/views/gcal-month-cell.ui");
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, day_label);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, header_box);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, overflow_button);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, overflow_label);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, overlay);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, temp_label);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, weather_icon);
gtk_widget_class_bind_template_callback (widget_class, enter_notify_event_cb);
gtk_widget_class_bind_template_callback (widget_class, leave_notify_event_cb);
gtk_widget_class_bind_template_callback (widget_class, overflow_button_clicked_cb);
gtk_widget_class_set_css_name (widget_class, "monthcell");
}
static void
gcal_month_cell_init (GcalMonthCell *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
/* Setup the month cell as a drag n' drop destination */
gtk_drag_dest_set (GTK_WIDGET (self),
0,
NULL,
0,
GDK_ACTION_MOVE);
}
GtkWidget*
gcal_month_cell_new (void)
{
return g_object_new (GCAL_TYPE_MONTH_CELL, NULL);
}
GDateTime*
gcal_month_cell_get_date (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), NULL);
return self->date;
}
void
gcal_month_cell_set_date (GcalMonthCell *self,
GDateTime *date)
{
g_autofree gchar *text = NULL;
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
if (self->date && date && gcal_date_time_compare_date (self->date, date) == 0)
return;
gcal_clear_date_time (&self->date);
self->date = g_date_time_ref (date);
/* Day label */
text = g_strdup_printf ("%d", g_date_time_get_day_of_month (date));
gtk_label_set_text (self->day_label, text);
update_style_flags (self);
}
/**
* gcal_month_cell_set_weather:
* @self: The #GcalMonthCell instance.
* @info: (nullable): The weather information to display.
*
* Sets the weather information to display for this day.
*
* Note that this function does not check dates nor
* manages weather information changes on its own.
*/
void
gcal_month_cell_set_weather (GcalMonthCell *self,
GcalWeatherInfo *info)
{
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
g_return_if_fail (!info || GCAL_IS_WEATHER_INFO (info));
if (self->weather_info == info)
return;
self->weather_info = info;
if (!info)
{
gtk_image_clear (self->weather_icon);
gtk_label_set_text (self->temp_label, "");
}
else
{
const gchar* icon_name; /* unowned */
const gchar* temp_str; /* unwoned */
icon_name = gcal_weather_info_get_icon_name (info);
temp_str = gcal_weather_info_get_temperature (info);
gtk_image_set_from_icon_name (self->weather_icon, icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
gtk_label_set_text (self->temp_label, temp_str);
}
}
gboolean
gcal_month_cell_get_different_month (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), FALSE);
return self->different_month;
}
void
gcal_month_cell_set_different_month (GcalMonthCell *self,
gboolean different)
{
GtkStyleContext *context;
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
if (self->different_month == different)
return;
self->different_month = different;
context = gtk_widget_get_style_context (GTK_WIDGET (self));
if (different)
gtk_style_context_add_class (context, "out-of-month");
else
gtk_style_context_remove_class (context, "out-of-month");
}
GcalContext*
gcal_month_cell_get_context (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), NULL);
return self->context;
}
void
gcal_month_cell_set_context (GcalMonthCell *self,
GcalContext *context)
{
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
if (!g_set_object (&self->context, context))
return;
g_signal_connect_object (gcal_context_get_clock (context),
"day-changed",
G_CALLBACK (day_changed_cb),
self,
0);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CONTEXT]);
}
guint
gcal_month_cell_get_overflow (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), 0);
return self->n_overflow;
}
void
gcal_month_cell_set_overflow (GcalMonthCell *self,
guint n_overflow)
{
g_autofree gchar *text = NULL;
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
gtk_widget_set_visible (self->overflow_label, n_overflow > 0);
gtk_widget_set_sensitive (self->overflow_button, n_overflow > 0);
if (self->n_overflow == n_overflow)
return;
self->n_overflow = n_overflow;
text = g_strdup_printf ("+%d", n_overflow);
gtk_label_set_text (GTK_LABEL (self->overflow_label), text);
}
gint
gcal_month_cell_get_content_space (GcalMonthCell *self)
{
GtkStyleContext *context;
GtkBorder padding;
GtkBorder border;
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), -1);
context = gtk_widget_get_style_context (GTK_WIDGET (self));
gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding);
gtk_style_context_get_border (context, gtk_style_context_get_state (context), &border);
return gtk_widget_get_allocated_height (GTK_WIDGET (self)) -
gcal_month_cell_get_header_height (self) -
padding.top - padding.bottom -
border.top - border.bottom;
}
gint
gcal_month_cell_get_header_height (GcalMonthCell *self)
{
GtkStyleContext *context;
GtkBorder padding;
GtkBorder border;
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), -1);
context = gtk_widget_get_style_context (GTK_WIDGET (self->header_box));
gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding);
gtk_style_context_get_border (context, gtk_style_context_get_state (context), &border);
return gtk_widget_get_allocated_height (self->header_box) +
gtk_widget_get_margin_top (self->header_box) +
gtk_widget_get_margin_bottom (self->header_box) +
padding.top + padding.bottom +
border.top + border.bottom;
}
gint
gcal_month_cell_get_overflow_height (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), -1);
return gtk_widget_get_allocated_height (self->overflow_button);
}
gboolean
gcal_month_cell_get_selected (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), FALSE);
return self->selected;
}
void
gcal_month_cell_set_selected (GcalMonthCell *self,
gboolean selected)
{
GtkStateFlags flags;
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
if (self->selected == selected)
return;
self->selected = selected;
/* Update style context state */
flags = gtk_widget_get_state_flags (GTK_WIDGET (self));
if (selected)
flags |= GTK_STATE_FLAG_SELECTED;
else
flags &= ~GTK_STATE_FLAG_SELECTED;
gtk_widget_set_state_flags (GTK_WIDGET (self), flags, TRUE);
gtk_widget_queue_resize (GTK_WIDGET (self));
}
+72
View File
@@ -0,0 +1,72 @@
/* gcal-month-cell.h
*
* Copyright (C) 2017 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GCAL_MONTH_CELL_H
#define GCAL_MONTH_CELL_H
#include "gcal-context.h"
#include "gcal-weather-info.h"
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GCAL_TYPE_MONTH_CELL (gcal_month_cell_get_type())
G_DECLARE_FINAL_TYPE (GcalMonthCell, gcal_month_cell, GCAL, MONTH_CELL, GtkEventBox)
GtkWidget* gcal_month_cell_new (void);
GDateTime* gcal_month_cell_get_date (GcalMonthCell *self);
void gcal_month_cell_set_date (GcalMonthCell *self,
GDateTime *date);
void gcal_month_cell_set_weather (GcalMonthCell *self,
GcalWeatherInfo *info);
gboolean gcal_month_cell_get_different_month (GcalMonthCell *self);
void gcal_month_cell_set_different_month (GcalMonthCell *self,
gboolean out);
GcalContext* gcal_month_cell_get_context (GcalMonthCell *self);
void gcal_month_cell_set_context (GcalMonthCell *self,
GcalContext *context);
guint gcal_month_cell_get_overflow (GcalMonthCell *self);
void gcal_month_cell_set_overflow (GcalMonthCell *self,
guint n_overflow);
gint gcal_month_cell_get_content_space (GcalMonthCell *self);
gint gcal_month_cell_get_header_height (GcalMonthCell *self);
gint gcal_month_cell_get_overflow_height (GcalMonthCell *self);
gboolean gcal_month_cell_get_selected (GcalMonthCell *self);
void gcal_month_cell_set_selected (GcalMonthCell *self,
gboolean selected);
G_END_DECLS
#endif /* GCAL_MONTH_VIEW_CELL_H */
+99
View File
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GcalMonthCell" parent="GtkEventBox">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="expand">True</property>
<signal name="enter-notify-event" handler="enter_notify_event_cb" object="GcalMonthCell" swapped="no" />
<signal name="leave-notify-event" handler="leave_notify_event_cb" object="GcalMonthCell" swapped="no" />
<child>
<object class="GtkOverlay" id="overlay">
<property name="visible">True</property>
<property name="can-focus">True</property>
<child type="overlay">
<object class="GtkBox" id="header_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="valign">start</property>
<property name="spacing">6</property>
<property name="margin">6</property>
<property name="margin-bottom">0</property>
<child>
<object class="GtkLabel" id="day_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<style>
<class name="day-label" />
</style>
</object>
</child>
<!-- Weather forecast -->
<child>
<object class="GtkImage" id="weather_icon">
<property name="can-focus">False</property>
<property name="visible">True</property>
<property name="pixel_size">16</property>
<property name="margin-start">12</property>
<style>
<class name="dim-label" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="temp_label">
<property name="visible">True</property>
<property name="can-focus">True</property>
<style>
<class name="dim-label" />
<class name="temp-label" />
</style>
</object>
</child>
</object>
</child>
<!-- HACK: in Gtk3, insensitive widgets receive no events. We "fix" this
limitation by adding an always-sensitive GtkEventBox above the event,
and when the event is insensitive, the event box's event window is
above it -->
<child type="overlay">
<object class="GtkEventBox" id="button_event_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="above-child" bind-source="overflow_button" bind-property="sensitive" bind-flags="default|invert-boolean|sync-create" />
<signal name="enter-notify-event" handler="enter_notify_event_cb" object="GcalMonthCell" swapped="no" />
<signal name="leave-notify-event" handler="leave_notify_event_cb" object="GcalMonthCell" swapped="no" />
<child>
<object class="GtkButton" id="overflow_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="valign">end</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="overflow_button_clicked_cb" object="GcalMonthCell" swapped="no" />
<style>
<class name="flat" />
</style>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel" id="overflow_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="ellipsize">end</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>
+893
View File
@@ -0,0 +1,893 @@
/* gcal-month-popover.c
*
* Copyright © 2017 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define G_LOG_DOMAIN "GcalMonthPopover"
#include "gcal-context.h"
#include "gcal-debug.h"
#include "gcal-event-widget.h"
#include "gcal-month-popover.h"
#include "gcal-utils.h"
#include <dazzle.h>
#define RATIO_TO_RELATIVE 1.25
#define MIN_WIDTH 250
struct _GcalMonthPopover
{
GtkWindow parent;
GtkLabel *day_label;
GtkWidget *listbox;
GtkRevealer *revealer;
GtkWidget *scrolled_window;
GtkWidget *relative_to;
GtkWindow *transient_for;
GcalContext *context;
DzlAnimation *opacity_animation;
DzlAnimation *position_animation;
DzlAnimation *size_animation;
gulong delete_event_handler;
gulong configure_event_handler;
gulong size_allocate_handler;
/* Positioning flags - range from [0, 1] */
gdouble x_ratio;
gdouble y_ratio;
GDateTime *date;
};
static void event_activated_cb (GcalEventWidget *event_widget,
GcalMonthPopover *self);
G_DEFINE_TYPE (GcalMonthPopover, gcal_month_popover, GTK_TYPE_WINDOW)
enum
{
PROP_0,
PROP_CONTEXT,
PROP_RELATIVE_TO,
PROP_X,
PROP_Y,
N_PROPS
};
enum
{
EVENT_ACTIVATED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0, };
static GParamSpec *properties [N_PROPS] = { NULL, };
/*
* Auxiliary functions
*/
static void
adjust_margin (GcalMonthPopover *self,
GdkRectangle *area)
{
GtkStyleContext *style_context;
GtkBorder margin;
style_context = gtk_widget_get_style_context (gtk_bin_get_child (GTK_BIN (self)));
gtk_style_context_get_margin (style_context,
gtk_style_context_get_state (style_context),
&margin);
area->x -= margin.right;
area->y -= margin.top;
area->width += margin.right + margin.left;
area->height += margin.top + margin.bottom;
}
static void
animate_opacity (GcalMonthPopover *self,
gdouble target)
{
DzlAnimation *animation;
if (self->opacity_animation)
dzl_animation_stop (self->opacity_animation);
/* Animate the opacity */
animation = dzl_object_animate (self,
DZL_ANIMATION_EASE_IN_OUT_CUBIC,
250,
gtk_widget_get_frame_clock (GTK_WIDGET (self)),
"opacity", target,
NULL);
dzl_set_weak_pointer (&self->opacity_animation, animation);
}
static void
animate_position (GcalMonthPopover *self,
gdouble x_ratio,
gdouble y_ratio)
{
DzlAnimation *animation;
if (self->position_animation)
dzl_animation_stop (self->position_animation);
/* Animate the opacity */
animation = dzl_object_animate (self,
DZL_ANIMATION_EASE_IN_OUT_CUBIC,
200,
gtk_widget_get_frame_clock (GTK_WIDGET (self)),
"x", x_ratio,
"y", y_ratio,
NULL);
dzl_set_weak_pointer (&self->position_animation, animation);
}
static void
animate_size (GcalMonthPopover *self,
gint target_width,
gint target_height)
{
DzlAnimation *animation;
if (self->size_animation)
dzl_animation_stop (self->size_animation);
/* Animate the size */
animation = dzl_object_animate (self,
DZL_ANIMATION_EASE_IN_OUT_CUBIC,
200,
gtk_widget_get_frame_clock (GTK_WIDGET (self)),
"width-request", target_width,
"height-request", target_height,
NULL);
dzl_set_weak_pointer (&self->size_animation, animation);
}
static void
update_maximum_height (GcalMonthPopover *self)
{
GdkWindow *window;
gint clip_height;
clip_height = 3000;
window = gtk_widget_get_window (GTK_WIDGET (self->relative_to));
if (window)
{
GdkDisplay *display;
GdkMonitor *monitor;
display = gtk_widget_get_display (GTK_WIDGET (self));
monitor = gdk_display_get_monitor_at_window (display, window);
if (monitor)
{
GdkRectangle workarea;
gdk_monitor_get_workarea (monitor, &workarea);
clip_height = workarea.height / 2;
}
}
g_object_set (self->scrolled_window,
"max-content-height", clip_height,
NULL);
}
static void
update_position (GcalMonthPopover *self)
{
GtkAllocation alloc;
GtkWidget *toplevel;
GdkWindow *window;
gint diff_w;
gint diff_h;
gint x;
gint y;
if (!gtk_widget_get_realized (GTK_WIDGET (self)))
return;
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self->relative_to));
window = gtk_widget_get_window (toplevel);
gtk_widget_get_allocation (GTK_WIDGET (self->relative_to), &alloc);
alloc.x = 0;
alloc.y = 0;
gtk_widget_translate_coordinates (GTK_WIDGET (self->relative_to), toplevel, 0, 0, &alloc.x, &alloc.y);
gdk_window_get_position (window, &x, &y);
alloc.x += x;
alloc.y += y;
adjust_margin (self, &alloc);
diff_w = (RATIO_TO_RELATIVE - 1) * alloc.width * (1.0 - self->x_ratio);
diff_h = (RATIO_TO_RELATIVE - 1) * alloc.height * (1.0 - self->y_ratio);
/* Animate the margins, not the (x, y) position) */
gtk_widget_set_margin_top (gtk_bin_get_child (GTK_BIN (self)), diff_h / 2);
if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL)
gtk_widget_set_margin_end (gtk_bin_get_child (GTK_BIN (self)), diff_w / 2);
else
gtk_widget_set_margin_start (gtk_bin_get_child (GTK_BIN (self)), diff_w / 2);
}
static void
reposition_popover (GcalMonthPopover *self,
gboolean animate)
{
GtkAllocation alloc;
GtkWidget *toplevel;
GdkWindow *window;
gint diff_w;
gint diff_h;
gint x;
gint y;
if (!gtk_widget_get_realized (GTK_WIDGET (self)))
return;
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self->relative_to));
window = gtk_widget_get_window (toplevel);
gtk_widget_get_allocation (GTK_WIDGET (self->relative_to), &alloc);
alloc.x = 0;
alloc.y = 0;
gtk_widget_translate_coordinates (GTK_WIDGET (self->relative_to), toplevel, 0, 0, &alloc.x, &alloc.y);
gdk_window_get_position (window, &x, &y);
alloc.x += x;
alloc.y += y;
adjust_margin (self, &alloc);
update_maximum_height (self);
diff_w = (RATIO_TO_RELATIVE - 1) * alloc.width;
diff_h = (RATIO_TO_RELATIVE - 1) * alloc.height;
gtk_window_move (GTK_WINDOW (self), alloc.x - diff_w / 2, alloc.y - diff_h / 2);
alloc.width = MAX (MIN_WIDTH, alloc.width);
if (animate)
{
gtk_widget_set_size_request (GTK_WIDGET (self), alloc.width, alloc.height);
animate_position (self, 1.0, 1.0);
animate_size (self, alloc.width * RATIO_TO_RELATIVE, alloc.height * RATIO_TO_RELATIVE);
}
else
{
gtk_widget_set_size_request (GTK_WIDGET (self), alloc.width * RATIO_TO_RELATIVE, alloc.height * RATIO_TO_RELATIVE);
}
}
static void
update_event_list (GcalMonthPopover *self)
{
g_autoptr (GDateTime) start_dt = NULL;
g_autoptr (GDateTime) end_dt = NULL;
g_autoptr (GPtrArray) events = NULL;
guint i;
gtk_container_foreach (GTK_CONTAINER (self->listbox), (GtkCallback) gtk_widget_destroy, NULL);
if (!gtk_widget_get_realized (GTK_WIDGET (self)) ||
!gtk_widget_get_visible (GTK_WIDGET (self)) ||
!self->date)
{
return;
}
start_dt = g_date_time_new_local (g_date_time_get_year (self->date),
g_date_time_get_month (self->date),
g_date_time_get_day_of_month (self->date),
0, 0, 0);
end_dt = g_date_time_add_days (start_dt, 1);
events = gcal_manager_get_events (gcal_context_get_manager (self->context), start_dt, end_dt);
for (i = 0; events && i < events->len; i++)
{
g_autoptr (GDateTime) event_start = NULL;
g_autoptr (GDateTime) event_end = NULL;
g_autoptr (GTimeZone) tz = NULL;
GtkWidget *event_widget;
GcalEvent *event;
event = g_ptr_array_index (events, i);
if (gcal_event_get_all_day (event))
tz = g_time_zone_new_utc ();
else
tz = g_time_zone_new_local ();
event_start = g_date_time_new (tz,
g_date_time_get_year (start_dt),
g_date_time_get_month (start_dt),
g_date_time_get_day_of_month (start_dt),
0, 0, 0);
event_end = g_date_time_add_days (event_start, 1);
event_widget = gcal_event_widget_new (self->context, event);
gcal_event_widget_set_date_start (GCAL_EVENT_WIDGET (event_widget), event_start);
gcal_event_widget_set_date_end (GCAL_EVENT_WIDGET (event_widget), event_end);
gtk_container_add (GTK_CONTAINER (self->listbox), event_widget);
g_signal_connect_object (event_widget,
"activate",
G_CALLBACK (event_activated_cb),
self,
0);
}
gtk_widget_show_all (self->listbox);
}
/*
* GtkListBox functions
*/
static gint
sort_func (GtkListBoxRow *a,
GtkListBoxRow *b,
gpointer user_data)
{
GcalEventWidget *event_a;
GcalEventWidget *event_b;
event_a = GCAL_EVENT_WIDGET (gtk_bin_get_child (GTK_BIN (a)));
event_b = GCAL_EVENT_WIDGET (gtk_bin_get_child (GTK_BIN (b)));
return gcal_event_widget_sort_events (event_a, event_b);
}
/*
* Callbacks
*/
static void
event_activated_cb (GcalEventWidget *event_widget,
GcalMonthPopover *self)
{
g_signal_emit (self, signals[EVENT_ACTIVATED], 0, event_widget);
}
static void
close_button_clicked_cb (GcalMonthPopover *self)
{
gcal_month_popover_popdown (self);
}
static void
new_event_button_clicked_cb (GtkWidget *button,
GcalMonthPopover *self)
{
GActionMap *map;
GAction *action;
GCAL_ENTRY;
map = G_ACTION_MAP (g_application_get_default ());
action = g_action_map_lookup_action (map, "new");
gcal_month_popover_popdown (self);
g_action_activate (action, NULL);
GCAL_EXIT;
}
static void
revealer_notify_child_revealed_cb (GcalMonthPopover *self,
GParamSpec *pspec,
GtkRevealer *revealer)
{
if (!gtk_revealer_get_reveal_child (self->revealer))
gtk_widget_hide (GTK_WIDGET (self));
}
static gboolean
transient_for_configure_event_cb (GcalMonthPopover *self,
GdkEvent *event,
GtkWindow *toplevel)
{
gtk_widget_hide (GTK_WIDGET (self));
return FALSE;
}
static gboolean
transient_for_delete_event_cb (GcalMonthPopover *self,
GdkEvent *event,
GtkWindow *toplevel)
{
gtk_widget_hide (GTK_WIDGET (self));
return FALSE;
}
static void
transient_for_size_allocate_cb (GcalMonthPopover *self,
GtkAllocation *allocation,
GtkWindow *toplevel)
{
reposition_popover (self, FALSE);
}
/*
* GtkWidget overrides
*/
static void
gcal_month_popover_destroy (GtkWidget *widget)
{
GcalMonthPopover *self = (GcalMonthPopover *)widget;
if (self->transient_for)
{
g_signal_handler_disconnect (self->transient_for, self->size_allocate_handler);
g_signal_handler_disconnect (self->transient_for, self->configure_event_handler);
g_signal_handler_disconnect (self->transient_for, self->delete_event_handler);
self->size_allocate_handler = 0;
self->configure_event_handler = 0;
self->delete_event_handler = 0;
self->transient_for = NULL;
}
if (self->opacity_animation)
{
dzl_animation_stop (self->opacity_animation);
dzl_clear_weak_pointer (&self->opacity_animation);
}
if (self->position_animation)
{
dzl_animation_stop (self->position_animation);
dzl_clear_weak_pointer (&self->position_animation);
}
if (self->size_animation)
{
dzl_animation_stop (self->size_animation);
dzl_clear_weak_pointer (&self->size_animation);
}
gcal_month_popover_set_relative_to (self, NULL);
GTK_WIDGET_CLASS (gcal_month_popover_parent_class)->destroy (widget);
}
static gboolean
gcal_month_popover_focus_out_event (GtkWidget *widget,
GdkEventFocus *event_focus)
{
gcal_month_popover_popdown (GCAL_MONTH_POPOVER (widget));
return GTK_WIDGET_CLASS (gcal_month_popover_parent_class)->focus_out_event (widget, event_focus);
}
static void
gcal_month_popover_hide (GtkWidget *widget)
{
GcalMonthPopover *self = (GcalMonthPopover *)widget;
if (self->transient_for)
gtk_window_group_remove_window (gtk_window_get_group (self->transient_for), GTK_WINDOW (self));
g_signal_handler_disconnect (self->transient_for, self->delete_event_handler);
g_signal_handler_disconnect (self->transient_for, self->size_allocate_handler);
g_signal_handler_disconnect (self->transient_for, self->configure_event_handler);
self->delete_event_handler = 0;
self->size_allocate_handler = 0;
self->configure_event_handler = 0;
self->transient_for = NULL;
gcal_month_popover_popdown (self);
GTK_WIDGET_CLASS (gcal_month_popover_parent_class)->hide (widget);
}
static void
gcal_month_popover_show (GtkWidget *widget)
{
GcalMonthPopover *self = (GcalMonthPopover *)widget;
if (self->relative_to)
{
GtkWidget *toplevel;
toplevel = gtk_widget_get_ancestor (GTK_WIDGET (self->relative_to), GTK_TYPE_WINDOW);
if (GTK_IS_WINDOW (toplevel))
{
self->transient_for = GTK_WINDOW (toplevel);
gtk_window_group_add_window (gtk_window_get_group (self->transient_for), GTK_WINDOW (self));
self->delete_event_handler =
g_signal_connect_object (toplevel,
"delete-event",
G_CALLBACK (transient_for_delete_event_cb),
self,
G_CONNECT_SWAPPED);
self->size_allocate_handler =
g_signal_connect_object (toplevel,
"size-allocate",
G_CALLBACK (transient_for_size_allocate_cb),
self,
G_CONNECT_SWAPPED | G_CONNECT_AFTER);
self->configure_event_handler =
g_signal_connect_object (toplevel,
"configure-event",
G_CALLBACK (transient_for_configure_event_cb),
self,
G_CONNECT_SWAPPED);
gtk_window_set_transient_for (GTK_WINDOW (self), self->transient_for);
reposition_popover (self, FALSE);
}
}
GTK_WIDGET_CLASS (gcal_month_popover_parent_class)->show (widget);
}
static void
gcal_month_popover_realize (GtkWidget *widget)
{
GcalMonthPopover *self = (GcalMonthPopover *)widget;
GdkScreen *screen;
GdkVisual *visual;
screen = gtk_widget_get_screen (widget);
visual = gdk_screen_get_rgba_visual (screen);
if (visual)
gtk_widget_set_visual (widget, visual);
GTK_WIDGET_CLASS (gcal_month_popover_parent_class)->realize (widget);
reposition_popover (self, TRUE);
}
/*
* GObject overrides
*/
static void
gcal_month_popover_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GcalMonthPopover *self = GCAL_MONTH_POPOVER (object);
switch (prop_id)
{
case PROP_CONTEXT:
g_value_set_object (value, self->context);
break;
case PROP_RELATIVE_TO:
g_value_set_object (value, self->relative_to);
break;
case PROP_X:
g_value_set_double (value, self->x_ratio);
break;
case PROP_Y:
g_value_set_double (value, self->y_ratio);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gcal_month_popover_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GcalMonthPopover *self = GCAL_MONTH_POPOVER (object);
switch (prop_id)
{
case PROP_CONTEXT:
self->context = g_value_dup_object (value);
break;
case PROP_RELATIVE_TO:
gcal_month_popover_set_relative_to (self, g_value_get_object (value));
break;
case PROP_X:
self->x_ratio = g_value_get_double (value);
update_position (self);
break;
case PROP_Y:
self->y_ratio = g_value_get_double (value);
update_position (self);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gcal_month_popover_class_init (GcalMonthPopoverClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->get_property = gcal_month_popover_get_property;
object_class->set_property = gcal_month_popover_set_property;
widget_class->destroy = gcal_month_popover_destroy;
widget_class->focus_out_event = gcal_month_popover_focus_out_event;
widget_class->hide = gcal_month_popover_hide;
widget_class->show = gcal_month_popover_show;
widget_class->realize = gcal_month_popover_realize;
properties [PROP_CONTEXT] = g_param_spec_object ("context",
"Context",
"Context",
GCAL_TYPE_CONTEXT,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
properties [PROP_RELATIVE_TO] = g_param_spec_object ("relative-to",
"Relative To",
"The widget to be relative to",
GTK_TYPE_WIDGET,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
properties [PROP_X] = g_param_spec_double ("x",
"X Percent position",
"X Percent position",
0.0,
1.0,
0.0,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
properties [PROP_Y] = g_param_spec_double ("y",
"Y Percent position",
"Y Percent position",
0.0,
1.0,
0.0,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
signals[EVENT_ACTIVATED] = g_signal_new ("event-activated",
GCAL_TYPE_MONTH_POPOVER,
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,
G_TYPE_NONE,
1,
GCAL_TYPE_EVENT_WIDGET);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/views/gcal-month-popover.ui");
gtk_widget_class_bind_template_callback (widget_class, close_button_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, new_event_button_clicked_cb);
gtk_widget_class_bind_template_child (widget_class, GcalMonthPopover, day_label);
gtk_widget_class_bind_template_child (widget_class, GcalMonthPopover, listbox);
gtk_widget_class_bind_template_child (widget_class, GcalMonthPopover, revealer);
gtk_widget_class_bind_template_child (widget_class, GcalMonthPopover, scrolled_window);
gtk_widget_class_set_css_name (widget_class, "monthpopover");
}
static void
gcal_month_popover_init (GcalMonthPopover *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
gtk_window_set_type_hint (GTK_WINDOW (self), GDK_WINDOW_TYPE_HINT_COMBO);
gtk_window_set_decorated (GTK_WINDOW (self), FALSE);
gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
gtk_window_set_skip_pager_hint (GTK_WINDOW (self), TRUE);
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (self), TRUE);
g_signal_connect_object (self->revealer,
"notify::child-revealed",
G_CALLBACK (revealer_notify_child_revealed_cb),
self,
G_CONNECT_SWAPPED);
gtk_list_box_set_sort_func (GTK_LIST_BOX (self->listbox), sort_func, NULL, NULL);
}
GtkWidget*
gcal_month_popover_new (void)
{
return g_object_new (GCAL_TYPE_MONTH_POPOVER,
"type", GTK_WINDOW_POPUP,
NULL);
}
void
gcal_month_popover_set_relative_to (GcalMonthPopover *self,
GtkWidget *relative_to)
{
g_return_if_fail (GCAL_MONTH_POPOVER (self));
g_return_if_fail (!relative_to || GTK_IS_WIDGET (relative_to));
if (self->relative_to == relative_to)
return;
if (self->relative_to)
{
g_signal_handlers_disconnect_by_func (self->relative_to, gtk_widget_destroyed, &self->relative_to);
self->relative_to = NULL;
}
if (relative_to)
{
self->relative_to = relative_to;
g_signal_connect (self->relative_to,
"destroy",
G_CALLBACK (gtk_widget_destroyed),
&self->relative_to);
}
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_RELATIVE_TO]);
}
void
gcal_month_popover_popup (GcalMonthPopover *self)
{
gint duration = 250;
g_return_if_fail (GCAL_IS_MONTH_POPOVER (self));
if (self->relative_to)
{
GtkAllocation alloc;
GdkDisplay *display;
GdkMonitor *monitor;
GdkWindow *window;
gint min_height;
gint nat_height;
display = gtk_widget_get_display (GTK_WIDGET (self->relative_to));
window = gtk_widget_get_window (GTK_WIDGET (self->relative_to));
monitor = gdk_display_get_monitor_at_window (display, window);
gtk_widget_get_preferred_height (GTK_WIDGET (self), &min_height, &nat_height);
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
duration = dzl_animation_calculate_duration (monitor, alloc.height, nat_height);
}
gtk_widget_show (GTK_WIDGET (self));
gtk_revealer_set_transition_duration (self->revealer, duration);
gtk_revealer_set_reveal_child (self->revealer, TRUE);
update_event_list (self);
gtk_widget_grab_focus (GTK_WIDGET (self));
/* Animations */
animate_opacity (self, 1.0);
reposition_popover (self, TRUE);
}
void
gcal_month_popover_popdown (GcalMonthPopover *self)
{
GtkAllocation alloc;
GdkDisplay *display;
GdkMonitor *monitor;
GdkWindow *window;
guint duration;
g_return_if_fail (GCAL_IS_MONTH_POPOVER (self));
if (!gtk_widget_get_realized (GTK_WIDGET (self)))
return;
display = gtk_widget_get_display (GTK_WIDGET (self->relative_to));
window = gtk_widget_get_window (GTK_WIDGET (self->relative_to));
monitor = gdk_display_get_monitor_at_window (display, window);
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
duration = dzl_animation_calculate_duration (monitor, alloc.height, 0);
gtk_revealer_set_transition_duration (self->revealer, duration);
gtk_revealer_set_reveal_child (self->revealer, FALSE);
/* Animations */
gtk_widget_get_allocation (GTK_WIDGET (self->relative_to), &alloc);
gtk_widget_translate_coordinates (self->relative_to,
gtk_widget_get_toplevel (self->relative_to), 0, 0, &alloc.x, &alloc.y);
adjust_margin (self, &alloc);
alloc.width = MAX (MIN_WIDTH, alloc.width);
animate_opacity (self, 0.0);
animate_position (self, 0.0, 0.0);
animate_size (self, alloc.width, alloc.height);
}
GDateTime*
gcal_month_popover_get_date (GcalMonthPopover *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_POPOVER (self), NULL);
return self->date;
}
void
gcal_month_popover_set_date (GcalMonthPopover *self,
GDateTime *date)
{
g_return_if_fail (GCAL_IS_MONTH_POPOVER (self));
if (date && self->date && gcal_date_time_compare_date (self->date, date) == 0)
return;
gcal_clear_date_time (&self->date);
if (date)
{
g_autofree gchar *label;
self->date = g_date_time_ref (date);
label = g_strdup_printf ("%d", g_date_time_get_day_of_month (date));
gtk_label_set_label (self->day_label, label);
}
update_event_list (self);
}
+50
View File
@@ -0,0 +1,50 @@
/* gcal-month-popover.h
*
* Copyright © 2017 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GCAL_MONTH_POPOVER_H
#define GCAL_MONTH_POPOVER_H
#include "gcal-manager.h"
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GCAL_TYPE_MONTH_POPOVER (gcal_month_popover_get_type())
G_DECLARE_FINAL_TYPE (GcalMonthPopover, gcal_month_popover, GCAL, MONTH_POPOVER, GtkWindow)
GtkWidget* gcal_month_popover_new (void);
void gcal_month_popover_set_relative_to (GcalMonthPopover *self,
GtkWidget *relative_to);
void gcal_month_popover_popup (GcalMonthPopover *self);
void gcal_month_popover_popdown (GcalMonthPopover *self);
GDateTime* gcal_month_popover_get_date (GcalMonthPopover *self);
void gcal_month_popover_set_date (GcalMonthPopover *self,
GDateTime *date);
G_END_DECLS
#endif /* GCAL_MONTH_POPOVER_H */
+99
View File
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GcalMonthPopover" parent="GtkWindow">
<property name="modal">false</property>
<property name="opacity">0.0</property>
<property name="destroy-with-parent">true</property>
<child>
<object class="GtkBox">
<property name="visible">true</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<!-- Day label & close button-->
<child>
<object class="GtkBox">
<property name="visible">true</property>
<child>
<object class="GtkLabel" id="day_label">
<property name="visible">true</property>
<property name="label">12</property>
<property name="xalign">0.0</property>
<property name="hexpand">true</property>
<attributes>
<attribute name="scale" value="2.25" />
</attributes>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">true</property>
<property name="halign">end</property>
<property name="valign">start</property>
<property name="relief">none</property>
<signal name="clicked" handler="close_button_clicked_cb" object="GcalMonthPopover" swapped="yes" />
<child>
<object class="GtkImage">
<property name="visible">true</property>
<property name="icon-name">window-close-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>
<!-- Event list revealer -->
<child>
<object class="GtkRevealer" id="revealer">
<property name="reveal-child">false</property>
<property name="transition-duration">200</property>
<property name="transition-type">slide-down</property>
<property name="visible">true</property>
<child>
<object class="GtkBox" id="top_box">
<property name="orientation">vertical</property>
<property name="visible">true</property>
<child>
<object class="DzlElasticBin" id="elastic">
<property name="visible">true</property>
<child>
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="hscrollbar-policy">never</property>
<property name="propagate-natural-height">true</property>
<property name="visible">true</property>
<child>
<object class="GtkListBox" id="listbox">
<property name="visible">true</property>
<property name="selection-mode">none</property>
<style>
<class name="background" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<!-- New Event button -->
<child>
<object class="GtkButton" id="new_event_button">
<property name="visible">true</property>
<property name="relief">none</property>
<property name="label" translatable="yes">New Event…</property>
<signal name="clicked" handler="new_event_button_clicked_cb" object="GcalMonthPopover" swapped="no" />
</object>
</child>
</object>
</child>
</template>
</interface>
File diff suppressed because it is too large Load Diff
+33
View File
@@ -0,0 +1,33 @@
/* gcal-month-view.h
*
* Copyright (C) 2012 - Erick Pérez Castellanos
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GCAL_MONTH_VIEW_H__
#define __GCAL_MONTH_VIEW_H__
#include "gcal-manager.h"
#include "gcal-weather-service.h"
G_BEGIN_DECLS
#define GCAL_TYPE_MONTH_VIEW (gcal_month_view_get_type ())
G_DECLARE_FINAL_TYPE (GcalMonthView, gcal_month_view, GCAL, MONTH_VIEW, GtkContainer)
G_END_DECLS
#endif /* __GCAL_MONTH_VIEW_H__ */
+145
View File
@@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GcalMonthView" parent="GtkContainer">
<!-- Header -->
<child type="header">
<object class="GtkBox">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">true</property>
<child>
<object class="GtkLabel" id="month_label">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="month-name" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="year_label">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">1.0</property>
<style>
<class name="secondary-label" />
</style>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">true</property>
<property name="spacing">6</property>
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="margin-bottom">6</property>
<child>
<object class="GtkLabel" id="label_0">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="label_1">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="label_2">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="label_3">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="label_4">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="label_5">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="label_6">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
<!-- Grid -->
<child type="grid">
<object class="GtkGrid" id="grid">
<property name="visible">true</property>
<property name="can-focus">false</property>
<property name="row-homogeneous">true</property>
<property name="column-homogeneous">true</property>
</object>
</child>
</template>
</interface>
+256
View File
@@ -0,0 +1,256 @@
/* gcal-view.c
*
* Copyright (C) 2015 - Erick Pérez Castellanos
* 2016 - Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define G_LOG_DOMAIN "GcalView"
#include "gcal-debug.h"
#include "gcal-event-widget.h"
#include "gcal-view.h"
#include "gcal-utils.h"
#include <glib.h>
G_DEFINE_INTERFACE (GcalView, gcal_view, GTK_TYPE_WIDGET)
static void
gcal_view_default_init (GcalViewInterface *iface)
{
/**
* GcalView::active-date:
*
* The active date of the view.
*/
g_object_interface_install_property (iface,
g_param_spec_boxed ("active-date",
"The active date",
"The active/selecetd date in the view",
G_TYPE_DATE_TIME,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GcalView::manager:
*
* The #GcalManager of the view.
*/
g_object_interface_install_property (iface,
g_param_spec_object ("context",
"The context",
"The context of the view",
GCAL_TYPE_CONTEXT,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
/**
* GcalView::create-event:
*
* Emitted when the view wants to create an event.
*/
g_signal_new ("create-event",
GCAL_TYPE_VIEW,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GcalViewInterface, create_event),
NULL, NULL, NULL,
G_TYPE_NONE,
4,
G_TYPE_DATE_TIME,
G_TYPE_DATE_TIME,
G_TYPE_DOUBLE,
G_TYPE_DOUBLE);
/**
* GcalView::create-event-detailed:
*
* Emitted when the view wants to create an event and immediately
* edit it.
*/
g_signal_new ("create-event-detailed",
GCAL_TYPE_VIEW,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GcalViewInterface, create_event_detailed),
NULL, NULL, NULL,
G_TYPE_NONE, 2,
G_TYPE_DATE_TIME,
G_TYPE_DATE_TIME);
/**
* GcalView::event-activated:
*
* Emitted when an event widget inside the view is activated.
*/
g_signal_new ("event-activated",
GCAL_TYPE_VIEW,
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE,
1,
GCAL_TYPE_EVENT_WIDGET);
}
/**
* gcal_view_set_date:
* @view: a #GcalView
* @date: an #GDateTime
*
* Sets the date of @view.
*/
void
gcal_view_set_date (GcalView *view,
GDateTime *date)
{
g_return_if_fail (GCAL_IS_VIEW (view));
g_return_if_fail (GCAL_VIEW_GET_IFACE (view)->set_date);
GCAL_VIEW_GET_IFACE (view)->set_date (view, date);
}
/**
* gcal_view_get_context:
* @self: a #GcalView
*
* Retrieves the #GcalContext instance from @self.
*
* Returns: (transfer none): a #GcalContext
*/
GcalContext*
gcal_view_get_context (GcalView *self)
{
GcalContext *context;
g_return_val_if_fail (GCAL_IS_VIEW (self), NULL);
g_object_get (self, "context", &context, NULL);
g_object_unref (context);
return context;
}
/**
* gcal_view_get_date:
* @view: a #GcalView
*
* Retrieves the date of @view.
*
* Returns: (transfer none): an #GDateTime.
*/
GDateTime*
gcal_view_get_date (GcalView *view)
{
g_return_val_if_fail (GCAL_IS_VIEW (view), NULL);
g_return_val_if_fail (GCAL_VIEW_GET_IFACE (view)->get_date, NULL);
return GCAL_VIEW_GET_IFACE (view)->get_date (view);
}
/**
* gcal_view_clear_marks:
* @view: a #GcalView
*
* Clear any marking the view had drawn
**/
void
gcal_view_clear_marks (GcalView *view)
{
g_return_if_fail (GCAL_IS_VIEW (view));
g_return_if_fail (GCAL_VIEW_GET_IFACE (view)->clear_marks);
GCAL_VIEW_GET_IFACE (view)->clear_marks (view);
}
/**
* gcal_view_get_children_by_uuid:
* @view: a #GcalView
* @uuid: The unique id of an event
*
* Returns a list with every event that has the passed uuid
*
* Returns: (transfer full): a {@link GList} instance
**/
GList*
gcal_view_get_children_by_uuid (GcalView *view,
GcalRecurrenceModType mod,
const gchar *uuid)
{
g_return_val_if_fail (GCAL_IS_VIEW (view), NULL);
g_return_val_if_fail (GCAL_VIEW_GET_IFACE (view)->get_children_by_uuid, NULL);
return GCAL_VIEW_GET_IFACE (view)->get_children_by_uuid (view, mod, uuid);
}
/**
* gcal_view_get_next_date:
* @self: a #GcalView
*
* Retrieves the next date from @self. Different views have
* different time ranges (e.g. day view ranges 1 day, week
* view ranges 1 week, etc) and pressing the next button
* of the main window may advance the time in different steps.
*
* Returns: (transfer full): a #GDateTime
*/
GDateTime*
gcal_view_get_next_date (GcalView *self)
{
g_autoptr (GDateTime) next_date = NULL;
g_return_val_if_fail (GCAL_IS_VIEW (self), NULL);
g_return_val_if_fail (GCAL_VIEW_GET_IFACE (self)->get_next_date, NULL);
next_date = GCAL_VIEW_GET_IFACE (self)->get_next_date (self);
#ifdef GCAL_ENABLE_TRACE
{
g_autofree gchar *str = NULL;
str = g_date_time_format (next_date, "%x %X %z");
g_debug ("%s's next date: %s", G_OBJECT_TYPE_NAME (self), str);
}
#endif
return g_steal_pointer (&next_date);
}
/**
* gcal_view_get_previous_date:
* @self: a #GcalView
*
* Retrieves the previous date from @self.
*
* Returns: (transfer full): a #GDateTime
*/
GDateTime*
gcal_view_get_previous_date (GcalView *self)
{
g_autoptr (GDateTime) previous_date = NULL;
g_return_val_if_fail (GCAL_IS_VIEW (self), NULL);
g_return_val_if_fail (GCAL_VIEW_GET_IFACE (self)->get_previous_date, NULL);
previous_date = GCAL_VIEW_GET_IFACE (self)->get_previous_date (self);
#ifdef GCAL_ENABLE_TRACE
{
g_autofree gchar *str = NULL;
str = g_date_time_format (previous_date, "%x %X %z");
g_debug ("%s's previous date: %s", G_OBJECT_TYPE_NAME (self), str);
}
#endif
return g_steal_pointer (&previous_date);
}
+82
View File
@@ -0,0 +1,82 @@
/* gcal-view.h
*
* Copyright (C) 2012 - Erick Pérez Castellanos
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GCAL_VIEW_H__
#define __GCAL_VIEW_H__
#include "gcal-context.h"
#include "gcal-event-widget.h"
G_BEGIN_DECLS
#define GCAL_TYPE_VIEW (gcal_view_get_type ())
G_DECLARE_INTERFACE (GcalView, gcal_view, GCAL, VIEW, GtkWidget)
struct _GcalViewInterface
{
GTypeInterface parent;
/* signals */
void (*create_event) (GcalView *view,
GDateTime *start_span,
GDateTime *end_span,
gdouble x,
gdouble y);
void (*create_event_detailed) (GcalView *view,
GDateTime *start_span,
GDateTime *end_span);
GDateTime* (*get_date) (GcalView *view);
void (*set_date) (GcalView *view,
GDateTime *date);
GDateTime* (*get_next_date) (GcalView *self);
GDateTime* (*get_previous_date) (GcalView *self);
/* Marks related API */
void (*clear_marks) (GcalView *view);
GList* (*get_children_by_uuid) (GcalView *view,
GcalRecurrenceModType mod,
const gchar *uuid);
};
void gcal_view_set_date (GcalView *view,
GDateTime *date);
GDateTime* gcal_view_get_date (GcalView *view);
GcalContext* gcal_view_get_context (GcalView *self);
void gcal_view_clear_marks (GcalView *view);
GList* gcal_view_get_children_by_uuid (GcalView *view,
GcalRecurrenceModType mod,
const gchar *uuid);
GDateTime* gcal_view_get_next_date (GcalView *self);
GDateTime* gcal_view_get_previous_date (GcalView *self);
G_END_DECLS
#endif /* __GCAL_MONTH_VIEW_H__ */
File diff suppressed because it is too large Load Diff
+56
View File
@@ -0,0 +1,56 @@
/* gcal-week-grid.h
*
* Copyright (C) 2016 Vamsi Krishna Gollapudi <pandu.sonu@yahoo.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GCAL_WEEK_GRID_H
#define GCAL_WEEK_GRID_H
#include "gcal-context.h"
#include "gcal-event-widget.h"
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GCAL_TYPE_WEEK_GRID (gcal_week_grid_get_type())
G_DECLARE_FINAL_TYPE (GcalWeekGrid, gcal_week_grid, GCAL, WEEK_GRID, GtkContainer)
void gcal_week_grid_set_context (GcalWeekGrid *week_grid,
GcalContext *context);
void gcal_week_grid_set_first_weekday (GcalWeekGrid *week_grid,
gint nr_day);
void gcal_week_grid_add_event (GcalWeekGrid *self,
GcalEvent *event);
void gcal_week_grid_remove_event (GcalWeekGrid *self,
const gchar *uid);
GList* gcal_week_grid_get_children_by_uuid (GcalWeekGrid *self,
GcalRecurrenceModType mod,
const gchar *uid);
void gcal_week_grid_clear_marks (GcalWeekGrid *self);
void gcal_week_grid_set_date (GcalWeekGrid *self,
GDateTime *date);
G_END_DECLS
#endif /* GCAL_WEEK_GRID_H */
File diff suppressed because it is too large Load Diff
+57
View File
@@ -0,0 +1,57 @@
/* gcal-week-header.h
*
* Copyright (C) 2016 Vamsi Krishna Gollapudi <pandu.sonu@yahoo.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GCAL_WEEK_HEADER_H
#define GCAL_WEEK_HEADER_H
#include "gcal-context.h"
#include "gcal-event-widget.h"
#include "gcal-weather-service.h"
#include "gcal-weather-info.h"
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GCAL_TYPE_WEEK_HEADER (gcal_week_header_get_type())
G_DECLARE_FINAL_TYPE (GcalWeekHeader, gcal_week_header, GCAL, WEEK_HEADER, GtkGrid)
void gcal_week_header_set_context (GcalWeekHeader *self,
GcalContext *context);
void gcal_week_header_add_event (GcalWeekHeader *self,
GcalEvent *event);
void gcal_week_header_remove_event (GcalWeekHeader *self,
const gchar *uuid);
GList* gcal_week_header_get_children_by_uuid (GcalWeekHeader *self,
GcalRecurrenceModType mod,
const gchar *uuid);
GtkSizeGroup* gcal_week_header_get_sidebar_size_group (GcalWeekHeader *self);
void gcal_week_header_clear_marks (GcalWeekHeader *self);
void gcal_week_header_set_date (GcalWeekHeader *self,
GDateTime *date);
G_END_DECLS
#endif /* GCAL_WEEK_HEADER_H */
+208
View File
@@ -0,0 +1,208 @@
<?xml version="1.0"?>
<interface>
<template class="GcalWeekHeader" parent="GtkGrid">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="vexpand">False</property>
<style>
<class name="week-header" />
</style>
<child>
<object class="GtkBox" id="header_labels_box">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<child>
<object class="GtkLabel" id="month_label">
<property name="visible">True</property>
<property name="label">Month</property>
<property name="yalign">0</property>
<style>
<class name="primary-label" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="week_label">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="label">Week</property>
<style>
<class name="secondary-label" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="year_label">
<property name="visible">True</property>
<property name="label">Year</property>
<property name="yalign">0</property>
<style>
<class name="secondary-label" />
</style>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<child>
<object class="GtkBox" id="expand_button_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">False</property>
<child>
<object class="GtkButton" id="expand_button">
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="halign">center</property>
<property name="valign">end</property>
<property name="margin-bottom">6</property>
<signal name="clicked" handler="on_expand_action_activated" object="GcalWeekHeader" swapped="yes"/>
<style>
<class name="flat" />
<class name="circular" />
</style>
<child>
<object class="GtkImage" id="expand_button_image">
<property name="visible">True</property>
<property name="icon_name">go-down-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkEventBox">
<property name="visible">True</property>
<signal name="button-press-event" handler="on_button_pressed" object="GcalWeekHeader" swapped="yes" />
<signal name="motion-notify-event" handler="on_motion_notify" object="GcalWeekHeader" swapped="yes" />
<signal name="button-release-event" handler="on_button_released" object="GcalWeekHeader" swapped="yes" />
<child>
<object class="GtkScrolledWindow" id="scrolledwindow">
<property name="visible">True</property>
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">never</property>
<property name="propagate-natural-height">True</property>
<property name="margin-bottom">2</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="column-homogeneous">True</property>
<property name="hexpand">True</property>
<property name="column-spacing">6</property>
<property name="row-spacing">2</property>
<property name="margin-start">6</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">4</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">5</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">6</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</template>
<object class="GtkSizeGroup" id="sizegroup">
<property name="mode">horizontal</property>
<widgets>
<widget name="expand_button_box"/>
</widgets>
</object>
</interface>
+610
View File
@@ -0,0 +1,610 @@
/* gcal-week-view.c
*
* Copyright (C) 2015 - Erick Pérez Castellanos
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define G_LOG_DOMAIN "GcalWeekView"
#include "gcal-debug.h"
#include "gcal-enums.h"
#include "gcal-event-widget.h"
#include "gcal-timeline-subscriber.h"
#include "gcal-utils.h"
#include "gcal-view.h"
#include "gcal-week-header.h"
#include "gcal-week-grid.h"
#include "gcal-week-view.h"
#include <glib/gi18n.h>
#include <math.h>
#define ALL_DAY_CELLS_HEIGHT 40
static const double dashed [] =
{
5.0,
6.0
};
struct _GcalWeekView
{
GtkBox parent;
GtkWidget *header;
GtkWidget *hours_bar;
GtkWidget *scrolled_window;
GtkWidget *week_grid;
/* property */
GDateTime *date;
GcalContext *context;
guint scroll_grid_timeout_id;
gint clicked_cell;
};
static void schedule_position_scroll (GcalWeekView *self);
static void gcal_view_interface_init (GcalViewInterface *iface);
static void gcal_timeline_subscriber_interface_init (GcalTimelineSubscriberInterface *iface);
enum
{
PROP_0,
PROP_DATE,
PROP_CONTEXT,
NUM_PROPS
};
G_DEFINE_TYPE_WITH_CODE (GcalWeekView, gcal_week_view, GTK_TYPE_BOX,
G_IMPLEMENT_INTERFACE (GCAL_TYPE_VIEW, gcal_view_interface_init)
G_IMPLEMENT_INTERFACE (GCAL_TYPE_TIMELINE_SUBSCRIBER,
gcal_timeline_subscriber_interface_init));
/* Callbacks */
static void
on_event_activated (GcalWeekView *self,
GtkWidget *widget)
{
g_signal_emit_by_name (self, "event-activated", widget);
}
static void
stack_visible_child_changed_cb (GtkStack *stack,
GParamSpec *pspec,
GcalWeekView *self)
{
if (gtk_stack_get_visible_child (stack) != (GtkWidget*) self)
return;
schedule_position_scroll (self);
g_signal_handlers_disconnect_by_func (stack, stack_visible_child_changed_cb, self);
}
/* Auxiliary methods */
static gboolean
update_grid_scroll_position (GcalWeekView *self)
{
g_autoptr(GDateTime) week_start = NULL;
g_autoptr(GDateTime) week_end = NULL;
g_autoptr(GDateTime) now = NULL;
GtkAdjustment *vadjustment;
gdouble minutes, real_value;
gdouble max, page, page_increment, value;
gboolean dummy;
/* While the scrolled window is not mapped, we keep waiting */
if (!gtk_widget_get_realized (self->scrolled_window) ||
!gtk_widget_get_mapped (self->scrolled_window))
{
GtkWidget *stack;
stack = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_STACK);
g_signal_connect_object (stack,
"notify::visible-child",
G_CALLBACK (stack_visible_child_changed_cb),
self,
0);
self->scroll_grid_timeout_id = 0;
GCAL_RETURN (G_SOURCE_REMOVE);
}
now = g_date_time_new_now_local ();
week_start = gcal_date_time_get_start_of_week (self->date);
week_end = gcal_date_time_get_end_of_week (self->date);
/* Don't animate when not today */
if (gcal_date_time_compare_date (now, week_start) < 0 || gcal_date_time_compare_date (now, week_end) >= 0)
GCAL_GOTO (out);
vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->scrolled_window));
minutes = g_date_time_get_hour (now) * 60 + g_date_time_get_minute (now);
page = gtk_adjustment_get_page_size (vadjustment);
max = gtk_adjustment_get_upper (vadjustment);
real_value = max / MINUTES_PER_DAY * minutes - (page / 2.0);
page_increment = gtk_adjustment_get_page_increment (vadjustment);
value = gtk_adjustment_get_value (vadjustment);
gtk_adjustment_set_page_increment (vadjustment, real_value - value);
g_signal_emit_by_name (self->scrolled_window,
"scroll-child",
GTK_SCROLL_PAGE_FORWARD,
FALSE,
&dummy);
gtk_adjustment_set_page_increment (vadjustment, page_increment);
out:
self->scroll_grid_timeout_id = 0;
GCAL_RETURN (G_SOURCE_REMOVE);
}
static void
schedule_position_scroll (GcalWeekView *self)
{
/* Nothing is scheduled, we should do it now */
if (self->scroll_grid_timeout_id > 0)
g_source_remove (self->scroll_grid_timeout_id);
self->scroll_grid_timeout_id = g_timeout_add (200,
(GSourceFunc) update_grid_scroll_position,
self);
}
/* GcalView implementation */
static GDateTime*
gcal_week_view_get_date (GcalView *view)
{
GcalWeekView *self = GCAL_WEEK_VIEW (view);
return self->date;
}
static void
gcal_week_view_set_date (GcalView *view,
GDateTime *date)
{
GcalWeekView *self = GCAL_WEEK_VIEW (view);
GCAL_ENTRY;
gcal_set_date_time (&self->date, date);
/* Propagate the new date */
gcal_week_grid_set_date (GCAL_WEEK_GRID (self->week_grid), date);
gcal_week_header_set_date (GCAL_WEEK_HEADER (self->header), date);
schedule_position_scroll (self);
gcal_timeline_subscriber_range_changed (GCAL_TIMELINE_SUBSCRIBER (view));
GCAL_EXIT;
}
static GList*
gcal_week_view_get_children_by_uuid (GcalView *view,
GcalRecurrenceModType mod,
const gchar *uuid)
{
GcalWeekView *self;
GList *grid, *header;
GCAL_ENTRY;
self = GCAL_WEEK_VIEW (view);
grid = gcal_week_grid_get_children_by_uuid (GCAL_WEEK_GRID (self->week_grid), mod, uuid);
header = gcal_week_header_get_children_by_uuid (GCAL_WEEK_HEADER (self->header), mod, uuid);
GCAL_RETURN (g_list_concat (grid, header));
}
static void
gcal_week_view_clear_marks (GcalView *view)
{
GcalWeekView *self = GCAL_WEEK_VIEW (view);
gcal_week_header_clear_marks (GCAL_WEEK_HEADER (self->header));
gcal_week_grid_clear_marks (GCAL_WEEK_GRID (self->week_grid));
}
static GDateTime*
gcal_week_view_get_next_date (GcalView *view)
{
GcalWeekView *self = GCAL_WEEK_VIEW (view);
g_assert (self->date != NULL);
return g_date_time_add_weeks (self->date, 1);
}
static GDateTime*
gcal_week_view_get_previous_date (GcalView *view)
{
GcalWeekView *self = GCAL_WEEK_VIEW (view);
g_assert (self->date != NULL);
return g_date_time_add_weeks (self->date, -1);
}
static void
gcal_view_interface_init (GcalViewInterface *iface)
{
iface->get_date = gcal_week_view_get_date;
iface->set_date = gcal_week_view_set_date;
iface->get_children_by_uuid = gcal_week_view_get_children_by_uuid;
iface->clear_marks = gcal_week_view_clear_marks;
iface->get_next_date = gcal_week_view_get_next_date;
iface->get_previous_date = gcal_week_view_get_previous_date;
}
static void
update_hours_sidebar_size (GcalWeekView *self)
{
GtkStyleContext *context;
GtkStateFlags state;
GtkSizeGroup *sidebar_sizegroup;
GtkWidget *widget;
GtkBorder padding;
PangoLayout *layout;
PangoFontDescription *font_desc;
gint hours_12_width, hours_24_width, sidebar_width;
gint hours_12_height, hours_24_height, cell_height;
widget = GTK_WIDGET (self);
context = gtk_widget_get_style_context (widget);
state = gtk_style_context_get_state (context);
gtk_style_context_save (context);
gtk_style_context_add_class (context, "hours");
gtk_style_context_get (context, state,
"font", &font_desc,
NULL);
gtk_style_context_get_padding (context, state, &padding);
layout = pango_layout_new (gtk_widget_get_pango_context (widget));
pango_layout_set_font_description (layout, font_desc);
pango_layout_set_text (layout, _("00 AM"), -1);
pango_layout_get_pixel_size (layout, &hours_12_width, &hours_12_height);
pango_layout_set_text (layout, _("00:00"), -1);
pango_layout_get_pixel_size (layout, &hours_24_width, &hours_24_height);
sidebar_width = MAX (hours_12_width, hours_24_width) + padding.left + padding.right;
cell_height = MAX (hours_12_height, hours_24_height) + padding.top + padding.bottom + 1;
gtk_style_context_restore (context);
/* Update the size requests */
gtk_widget_set_size_request (self->hours_bar,
sidebar_width,
48 * cell_height);
/* Sync with the week header sidebar */
sidebar_sizegroup = gcal_week_header_get_sidebar_size_group (GCAL_WEEK_HEADER (self->header));
gtk_size_group_add_widget (sidebar_sizegroup, self->hours_bar);
pango_font_description_free (font_desc);
g_object_unref (layout);
}
/*
* GcalTimelineSubscriber iface
*/
static GcalRange*
gcal_week_view_get_range (GcalTimelineSubscriber *subscriber)
{
GcalWeekView *self = GCAL_WEEK_VIEW (subscriber);
return gcal_range_new_take (gcal_date_time_get_start_of_week (self->date),
gcal_date_time_get_end_of_week (self->date),
GCAL_RANGE_DEFAULT);
}
static void
gcal_week_view_add_event (GcalTimelineSubscriber *subscriber,
GcalEvent *event)
{
GcalWeekView *self = GCAL_WEEK_VIEW (subscriber);
GCAL_ENTRY;
if (gcal_event_is_multiday (event) || gcal_event_get_all_day (event))
gcal_week_header_add_event (GCAL_WEEK_HEADER (self->header), event);
else
gcal_week_grid_add_event (GCAL_WEEK_GRID (self->week_grid), event);
GCAL_EXIT;
}
static void
gcal_week_view_update_event (GcalTimelineSubscriber *subscriber,
GcalEvent *event)
{
GcalWeekView *self = GCAL_WEEK_VIEW (subscriber);
const gchar *event_id;
GCAL_ENTRY;
event_id = gcal_event_get_uid (event);
gcal_week_header_remove_event (GCAL_WEEK_HEADER (self->header), event_id);
gcal_week_grid_remove_event (GCAL_WEEK_GRID (self->week_grid), event_id);
gcal_week_view_add_event (subscriber, event);
GCAL_EXIT;
}
static void
gcal_week_view_remove_event (GcalTimelineSubscriber *subscriber,
GcalEvent *event)
{
GcalWeekView *self = GCAL_WEEK_VIEW (subscriber);
const gchar *uuid = gcal_event_get_uid (event);
GCAL_ENTRY;
gcal_week_header_remove_event (GCAL_WEEK_HEADER (self->header), uuid);
gcal_week_grid_remove_event (GCAL_WEEK_GRID (self->week_grid), uuid);
GCAL_EXIT;
}
static void
gcal_timeline_subscriber_interface_init (GcalTimelineSubscriberInterface *iface)
{
iface->get_range = gcal_week_view_get_range;
iface->add_event = gcal_week_view_add_event;
iface->update_event = gcal_week_view_update_event;
iface->remove_event = gcal_week_view_remove_event;
}
static gboolean
gcal_week_view_draw_hours (GcalWeekView *self,
cairo_t *cr,
GtkWidget *widget)
{
GtkStyleContext *context;
GcalTimeFormat time_format;
GtkStateFlags state;
GtkBorder padding;
GdkRGBA color;
gboolean ltr;
gint i, width, height;
gint font_width;
PangoLayout *layout;
PangoFontDescription *font_desc;
time_format = gcal_context_get_time_format (self->context);
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL;
gtk_style_context_save (context);
gtk_style_context_add_class (context, "hours");
gtk_style_context_get_color (context, state, &color);
gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_get (context, state, "font", &font_desc, NULL);
layout = pango_cairo_create_layout (cr);
pango_layout_set_font_description (layout, font_desc);
gdk_cairo_set_source_rgba (cr, &color);
/* Gets the size of the widget */
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
/* Draws the hours in the sidebar */
for (i = 0; i < 24; i++)
{
gchar *hours;
if (time_format == GCAL_TIME_FORMAT_24H)
{
hours = g_strdup_printf ("%02d:00", i);
}
else
{
hours = g_strdup_printf ("%d %s",
i % 12 == 0 ? 12 : i % 12,
i >= 12 ? _("PM") : _("AM"));
}
pango_layout_set_text (layout, hours, -1);
pango_layout_get_pixel_size (layout, &font_width, NULL);
gtk_render_layout (context,
cr,
ltr ? padding.left : width - font_width - padding.right,
(height / 24) * i + padding.top,
layout);
g_free (hours);
}
gtk_style_context_restore (context);
gtk_style_context_save (context);
gtk_style_context_add_class (context, "lines");
gtk_style_context_get_color (context, state, &color);
gdk_cairo_set_source_rgba (cr, &color);
cairo_set_line_width (cr, 0.65);
if (!ltr)
{
cairo_move_to (cr, 0.5, 0);
cairo_rel_line_to (cr, 0, height);
}
/* Draws the horizontal complete lines */
for (i = 1; i < 24; i++)
{
cairo_move_to (cr, 0, (height / 24) * i + 0.4);
cairo_rel_line_to (cr, width, 0);
}
cairo_stroke (cr);
cairo_set_dash (cr, dashed, 2, 0);
/* Draws the horizontal dashed lines */
for (i = 0; i < 24; i++)
{
cairo_move_to (cr, 0, (height / 24) * i + (height / 48) + 0.4);
cairo_rel_line_to (cr, width, 0);
}
cairo_stroke (cr);
gtk_style_context_restore (context);
pango_font_description_free (font_desc);
g_object_unref (layout);
return FALSE;
}
static void
gcal_week_view_finalize (GObject *object)
{
GcalWeekView *self;
self = GCAL_WEEK_VIEW (object);
g_clear_pointer (&self->date, g_date_time_unref);
g_clear_object (&self->context);
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (gcal_week_view_parent_class)->finalize (object);
}
static void
gcal_week_view_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GcalWeekView *self = (GcalWeekView *) object;
switch (property_id)
{
case PROP_DATE:
gcal_view_set_date (GCAL_VIEW (object), g_value_get_boxed (value));
break;
case PROP_CONTEXT:
g_assert (self->context == NULL);
self->context = g_value_dup_object (value);
gcal_week_grid_set_context (GCAL_WEEK_GRID (self->week_grid), self->context);
gcal_week_header_set_context (GCAL_WEEK_HEADER (self->header), self->context);
g_signal_connect_object (self->context,
"notify::time-format",
G_CALLBACK (gtk_widget_queue_draw),
self->hours_bar,
G_CONNECT_SWAPPED);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gcal_week_view_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GcalWeekView *self;
g_return_if_fail (GCAL_IS_WEEK_VIEW (object));
self = GCAL_WEEK_VIEW (object);
switch (property_id)
{
case PROP_DATE:
g_value_set_boxed (value, self->date);
break;
case PROP_CONTEXT:
g_value_set_object (value, self->context);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gcal_week_view_class_init (GcalWeekViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
g_type_ensure (GCAL_TYPE_WEEK_GRID);
g_type_ensure (GCAL_TYPE_WEEK_HEADER);
object_class->finalize = gcal_week_view_finalize;
object_class->set_property = gcal_week_view_set_property;
object_class->get_property = gcal_week_view_get_property;
g_object_class_override_property (object_class, PROP_DATE, "active-date");
g_object_class_override_property (object_class, PROP_CONTEXT, "context");
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/views/gcal-week-view.ui");
gtk_widget_class_bind_template_child (widget_class, GcalWeekView, header);
gtk_widget_class_bind_template_child (widget_class, GcalWeekView, hours_bar);
gtk_widget_class_bind_template_child (widget_class, GcalWeekView, scrolled_window);
gtk_widget_class_bind_template_child (widget_class, GcalWeekView, week_grid);
gtk_widget_class_bind_template_callback (widget_class, gcal_week_view_draw_hours);
gtk_widget_class_bind_template_callback (widget_class, on_event_activated);
gtk_widget_class_set_css_name (widget_class, "calendar-view");
}
static void
gcal_week_view_init (GcalWeekView *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
update_hours_sidebar_size (self);
}
+33
View File
@@ -0,0 +1,33 @@
/* gcal-week-view.h
*
* Copyright (C) 2012 - Erick Pérez Castellanos
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GCAL_WEEK_VIEW_H__
#define __GCAL_WEEK_VIEW_H__
#include "gcal-manager.h"
#include "gcal-view.h"
G_BEGIN_DECLS
#define GCAL_TYPE_WEEK_VIEW (gcal_week_view_get_type ())
G_DECLARE_FINAL_TYPE (GcalWeekView, gcal_week_view, GCAL, WEEK_VIEW, GtkBox)
G_END_DECLS
#endif /* __GCAL_WEEK_VIEW_H__ */
+49
View File
@@ -0,0 +1,49 @@
<?xml version="1.0"?>
<interface>
<template class="GcalWeekView" parent="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<style>
<class name="week-view" />
</style>
<child>
<object class="GcalWeekHeader" id="header">
<property name="visible">True</property>
<signal name="event-activated" handler="on_event_activated" object="GcalWeekView" swapped="yes" />
</object>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<child>
<object class="GtkDrawingArea" id="hours_bar">
<property name="visible">True</property>
<property name="height-request">2568</property>
<signal name="draw" handler="gcal_week_view_draw_hours" object="GcalWeekView" swapped="yes" />
</object>
</child>
<child>
<object class="GcalWeekGrid" id="week_grid">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<signal name="event-activated" handler="on_event_activated" object="GcalWeekView" swapped="yes" />
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>
File diff suppressed because it is too large Load Diff
+31
View File
@@ -0,0 +1,31 @@
/* gcal-year-view.h
*
* Copyright (C) 2015 Erick Pérez Castellanos <erick.red@gmail.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GCAL_YEAR_VIEW_H
#define GCAL_YEAR_VIEW_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GCAL_TYPE_YEAR_VIEW (gcal_year_view_get_type())
G_DECLARE_FINAL_TYPE (GcalYearView, gcal_year_view, GCAL, YEAR_VIEW, GtkBox)
G_END_DECLS
#endif /* GCAL_YEAR_VIEW_H */
+172
View File
@@ -0,0 +1,172 @@
<?xml version="1.0"?>
<interface>
<!-- interface-requires gtk+ 3.10 -->
<template class="GcalYearView" parent="GtkBox">
<style>
<class name="year-view"/>
</style>
<child>
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="visible">True</property>
<property name="shadow_type">none</property>
<property name="vexpand">True</property>
<signal name="edge-overshot" handler="navigator_edge_overshot_cb" object="GcalYearView" swapped="yes"/>
<signal name="scroll-event" handler="navigator_scroll_event_cb" object="GcalYearView" swapped="yes"/>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="shadow_type">none</property>
<property name="vexpand">True</property>
<child>
<object class="GtkDrawingArea" id="navigator">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="events">GDK_POINTER_MOTION_MASK|GDK_BUTTON_MOTION_MASK|GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_STRUCTURE_MASK</property>
<signal name="draw" handler="draw_navigator" object="GcalYearView" swapped="yes"/>
<signal name="button-press-event" handler="navigator_button_press_cb" object="GcalYearView" swapped="yes"/>
<signal name="button-release-event" handler="navigator_button_release_cb" object="GcalYearView" swapped="yes"/>
<signal name="motion-notify-event" handler="navigator_motion_notify_cb" object="GcalYearView" swapped="yes"/>
<signal name="drag-motion" handler="navigator_drag_motion_cb" object="GcalYearView" swapped="yes"/>
<signal name="drag-drop" handler="navigator_drag_drop_cb" object="GcalYearView" swapped="yes"/>
<signal name="drag-leave" handler="navigator_drag_leave_cb" object="GcalYearView" swapped="yes"/>
<style>
<class name="year-navigator"/>
</style>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="position">0</property>
<property name="pack_type">start</property>
</packing>
</child>
<child>
<object class="GtkBox" id="sidebar">
<property name="visible">True</property>
<property name="width_request">200</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkStack" id="navigator_stack">
<property name="visible">True</property>
<child>
<object class="GtkScrolledWindow" id="navigator_sidebar">
<property name="visible">True</property>
<property name="shadow_type">none</property>
<property name="vexpand">True</property>
<child>
<object class="GtkListBox" id="events_sidebar">
<property name="visible">True</property>
<property name="selection-mode">none</property>
<style>
<class name="sidebar"/>
</style>
</object>
</child>
</object>
<packing>
<property name="name">events-list</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<style>
<class name="sidebar"/>
</style>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="no_events_title">
<property name="visible">True</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Today</property>
<style>
<class name="sidebar-header"/>
</style>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="temp_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">temp</property>
<property name="label">foo</property>
<style>
<class name="temp-label" />
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkImage" id="weather_icon">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="halign">start</property>
<property name="margin_start">6</property>
<property name="label" translatable="yes">No events</property>
<style>
<class name="dim-label"/>
<class name="italic-label"/>
</style>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
<property name="name">no-events</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="valign">end</property>
<property name="label" translatable="yes">Add Event…</property>
<signal name="clicked" handler="add_event_clicked_cb" object="GcalYearView" swapped="yes"/>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</template>
<object class="GtkPopover" id="popover">
<property name="relative_to">navigator</property>
<style>
<class name="events"/>
</style>
<signal name="closed" handler="popover_closed_cb" object="GcalYearView" swapped="yes"/>
</object>
</interface>
+18
View File
@@ -0,0 +1,18 @@
calendar_incs += include_directories('.')
built_sources += gnome.compile_resources(
'views-resources',
'views.gresource.xml',
c_name: 'views',
)
sources += files(
'gcal-month-cell.c',
'gcal-month-popover.c',
'gcal-month-view.c',
'gcal-view.c',
'gcal-week-grid.c',
'gcal-week-header.c',
'gcal-week-view.c',
'gcal-year-view.c',
)
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/calendar/ui/views">
<file compressed="true">gcal-month-cell.ui</file>
<file compressed="true">gcal-month-popover.ui</file>
<file compressed="true">gcal-month-view.ui</file>
<file compressed="true">gcal-week-header.ui</file>
<file compressed="true">gcal-week-view.ui</file>
<file compressed="true">gcal-year-view.ui</file>
</gresource>
</gresources>