LCOV - code coverage report
Current view: top level - malcontent-control - cc-time-editor.c (source / functions) Coverage Total Hit
Test: 2 coverage DB files Lines: 0.0 % 35 0
Test Date: 2025-09-15 13:55:46 Functions: 0.0 % 11 0
Branches: 0.0 % 6 0

             Branch data     Line data    Source code
       1                 :             : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
       2                 :             : /*
       3                 :             :  * Copyright 2024 GNOME Foundation, Inc.
       4                 :             :  *
       5                 :             :  * This library is free software; you can redistribute it and/or
       6                 :             :  * modify it under the terms of the GNU Lesser General Public
       7                 :             :  * License as published by the Free Software Foundation; either
       8                 :             :  * version 2 of the License, or (at your option) any later version.
       9                 :             :  *
      10                 :             :  * This library is distributed in the hope that it will be useful,
      11                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13                 :             :  * Lesser General Public License for more details.
      14                 :             :  *
      15                 :             :  * You should have received a copy of the GNU Lesser General
      16                 :             :  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      17                 :             :  *
      18                 :             :  * Authors:
      19                 :             :  *  - Philip Withnall <pwithnall@gnome.org>
      20                 :             :  *
      21                 :             :  * SPDX-License-Identifier: GPL-3.0-or-later
      22                 :             :  */
      23                 :             : 
      24                 :             : #include <glib-object.h>
      25                 :             : #include <gtk/gtk.h>
      26                 :             : 
      27                 :             : #include "cc-time-editor.h"
      28                 :             : #include "cc-timelike-editor.h"
      29                 :             : 
      30                 :             : /**
      31                 :             :  * CcTimeEditor:
      32                 :             :  *
      33                 :             :  * A widget for displaying and editing a clock time in hours and minutes, from
      34                 :             :  * 00:00 to 23:59.
      35                 :             :  *
      36                 :             :  * It also supports a 12-hour mode, which is used automatically if requested via
      37                 :             :  * the user’s `org.gnome.desktop.interface.clock-format` GSetting.
      38                 :             :  */
      39                 :             : struct _CcTimeEditor {
      40                 :             :   GtkWidget parent_instance;
      41                 :             : 
      42                 :             :   CcTimelikeEditor *editor;
      43                 :             : };
      44                 :             : 
      45   [ #  #  #  #  :           0 : G_DEFINE_TYPE (CcTimeEditor, cc_time_editor, GTK_TYPE_WIDGET)
                   #  # ]
      46                 :             : 
      47                 :             : static void cc_time_editor_dispose (GObject *object);
      48                 :             : 
      49                 :             : static void editor_time_changed_cb (CcTimelikeEditor *editor,
      50                 :             :                                     gpointer          user_data);
      51                 :             : 
      52                 :             : typedef enum {
      53                 :             :   SIGNAL_TIME_CHANGED,
      54                 :             : } CcTimeEditorSignal;
      55                 :             : 
      56                 :             : static guint signals[SIGNAL_TIME_CHANGED + 1];
      57                 :             : 
      58                 :             : static void
      59                 :           0 : cc_time_editor_class_init (CcTimeEditorClass *klass)
      60                 :             : {
      61                 :           0 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
      62                 :           0 :   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
      63                 :             : 
      64                 :           0 :   object_class->dispose = cc_time_editor_dispose;
      65                 :             : 
      66                 :             :   /**
      67                 :             :    * CcTimeEditor::time-changed:
      68                 :             :    *
      69                 :             :    * Emitted when the time in the widget is edited.
      70                 :             :    *
      71                 :             :    * Use this rather than #GObject::notify because that would be emitted
      72                 :             :    * separately for hours and minutes. (It’s currently not implemented.)
      73                 :             :    */
      74                 :           0 :   signals[SIGNAL_TIME_CHANGED] =
      75                 :           0 :     g_signal_new ("time-changed",
      76                 :             :                   G_TYPE_FROM_CLASS (klass),
      77                 :             :                   G_SIGNAL_RUN_FIRST,
      78                 :             :                   0, NULL, NULL,
      79                 :             :                   NULL,
      80                 :             :                   G_TYPE_NONE, 0);
      81                 :             : 
      82                 :           0 :   gtk_widget_class_set_template_from_resource (widget_class, "/org/freedesktop/MalcontentControl/ui/cc-time-editor.ui");
      83                 :             : 
      84                 :           0 :   gtk_widget_class_bind_template_child (widget_class, CcTimeEditor, editor);
      85                 :             : 
      86                 :           0 :   gtk_widget_class_bind_template_callback (widget_class, editor_time_changed_cb);
      87                 :             : 
      88                 :           0 :   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
      89                 :           0 : }
      90                 :             : 
      91                 :             : static void
      92                 :           0 : cc_time_editor_init (CcTimeEditor *self)
      93                 :             : {
      94                 :           0 :   gtk_widget_init_template (GTK_WIDGET (self));
      95                 :             : 
      96                 :           0 :   g_signal_connect_object (self->editor, "time-changed",
      97                 :             :                            G_CALLBACK (editor_time_changed_cb), self, G_CONNECT_DEFAULT);
      98                 :           0 : }
      99                 :             : 
     100                 :             : static void
     101                 :           0 : cc_time_editor_dispose (GObject *object)
     102                 :             : {
     103                 :           0 :   gtk_widget_dispose_template (GTK_WIDGET (object), CC_TYPE_TIME_EDITOR);
     104                 :             : 
     105                 :           0 :   G_OBJECT_CLASS (cc_time_editor_parent_class)->dispose (object);
     106                 :           0 : }
     107                 :             : 
     108                 :             : static void
     109                 :           0 : editor_time_changed_cb (CcTimelikeEditor *editor,
     110                 :             :                         gpointer          user_data)
     111                 :             : {
     112                 :           0 :   CcTimeEditor *self = CC_TIME_EDITOR (user_data);
     113                 :             : 
     114                 :           0 :   g_signal_emit (self, signals[SIGNAL_TIME_CHANGED], 0);
     115                 :           0 : }
     116                 :             : 
     117                 :             : /**
     118                 :             :  * cc_time_editor_new:
     119                 :             :  *
     120                 :             :  * Create a new #CcTimeEditor.
     121                 :             :  *
     122                 :             :  * Returns: (transfer full): a new #CcTimeEditor
     123                 :             :  */
     124                 :             : CcTimeEditor *
     125                 :           0 : cc_time_editor_new (void)
     126                 :             : {
     127                 :           0 :   return g_object_new (CC_TYPE_TIME_EDITOR, NULL);
     128                 :             : }
     129                 :             : 
     130                 :             : /**
     131                 :             :  * cc_time_editor_set_time:
     132                 :             :  * @self: a #CcTimeEditor
     133                 :             :  * @hour: the new hour ([0, 23])
     134                 :             :  * @minute: the new minute ([0, 59])
     135                 :             :  *
     136                 :             :  * Set the time in the editor.
     137                 :             :  *
     138                 :             :  * This is always in 24-hour time, regardless of whether the editor is
     139                 :             :  * displaying in 12-hour mode.
     140                 :             :  */
     141                 :             : void
     142                 :           0 : cc_time_editor_set_time (CcTimeEditor *self,
     143                 :             :                          guint         hour,
     144                 :             :                          guint         minute)
     145                 :             : {
     146                 :           0 :   g_return_if_fail (CC_IS_TIME_EDITOR (self));
     147                 :             : 
     148                 :           0 :   cc_timelike_editor_set_time (self->editor, hour, minute);
     149                 :             : }
     150                 :             : 
     151                 :             : /**
     152                 :             :  * cc_time_editor_get_hour:
     153                 :             :  * @self: a #CcTimeEditor
     154                 :             :  *
     155                 :             :  * Get the hours from the editor.
     156                 :             :  *
     157                 :             :  * These are always in 24-hour time, regardless of whether the editor is
     158                 :             :  * displaying in 12-hour mode.
     159                 :             :  *
     160                 :             :  * Returns: current hours value from the editor ([0, 23])
     161                 :             :  */
     162                 :             : guint
     163                 :           0 : cc_time_editor_get_hour (CcTimeEditor *self)
     164                 :             : {
     165                 :           0 :   g_return_val_if_fail (CC_IS_TIME_EDITOR (self), 0);
     166                 :             : 
     167                 :           0 :   return cc_timelike_editor_get_hour (self->editor);
     168                 :             : }
     169                 :             : 
     170                 :             : /**
     171                 :             :  * cc_time_editor_get_minute:
     172                 :             :  * @self: a #CcTimeEditor
     173                 :             :  *
     174                 :             :  * Get the minutes from the editor.
     175                 :             :  *
     176                 :             :  * Returns: current minutes value from the editor ([0, 59])
     177                 :             :  */
     178                 :             : guint
     179                 :           0 : cc_time_editor_get_minute (CcTimeEditor *self)
     180                 :             : {
     181                 :           0 :   g_return_val_if_fail (CC_IS_TIME_EDITOR (self), 0);
     182                 :             : 
     183                 :           0 :   return cc_timelike_editor_get_minute (self->editor);
     184                 :             : }
     185                 :             : 
        

Generated by: LCOV version 2.0-1