Use slight gradient for background
[conv-inbox] / src / el-home-applet.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2 /*
3  *  Copyright (C) 2009 Artem Garmash. All rights reserved.
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program 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
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * Contact: Artem Garmash <artemgarmash@gmail.com>
20  *
21  */
22
23 #include "config.h"
24 #include "el-home-applet.h"
25
26 #include <hildon/hildon.h>
27 #include <rtcom-eventlogger/eventlogger.h>
28 #include <sqlite3.h>
29 #include <string.h>
30
31 #define EL_HOME_APPLET_GET_PRIVATE(obj) ( \
32         G_TYPE_INSTANCE_GET_PRIVATE (obj, \
33                 EL_TYPE_HOME_APPLET, ELHomeAppletPrivate))
34
35 #define BOX_WIDTH 352
36 #define BOX_HEIGHT 266
37
38 #define C_WIDTH (BOX_WIDTH - 2*HILDON_MARGIN_HALF)
39 #define C_HEIGHT (BOX_HEIGHT - 2*HILDON_MARGIN_HALF)
40 #define C_X HILDON_MARGIN_HALF
41 #define C_Y HILDON_MARGIN_HALF
42
43 #define HEADER_HEIGHT 48
44 #define MESSAGE_HEIGHT (C_HEIGHT - HEADER_HEIGHT)
45 #define MESSAGE_WIDTH (C_WIDTH - 2*HILDON_MARGIN_DEFAULT)
46
47 #define BOX_RADIOUS 10
48
49 struct _ELHomeAppletPrivate
50 {
51         RTComEl *eventlogger;
52
53         GtkWidget *sender;
54         GtkWidget *message;
55         GtkWidget *icon;
56         GtkWidget *unread;
57         GtkWidget *received;
58
59         gint       event_id;
60
61         gboolean   active;
62
63         guint unread_count;
64
65         const gchar *current_font;
66
67         guint idle_id;
68         /* new or updated event id */
69         gint  new_event_id;
70 };
71
72 HD_DEFINE_PLUGIN_MODULE (ELHomeApplet, el_home_applet, HD_TYPE_HOME_PLUGIN_ITEM);
73
74 const gchar* g_module_check_init(GModule *module);
75 const gchar*
76 g_module_check_init(GModule *module)
77 {
78         g_module_make_resident (module);
79         return NULL;
80 }
81
82 static void
83 el_home_applet_class_finalize (ELHomeAppletClass *klass)
84 {
85 }
86
87 static void
88 el_home_applet_realize (GtkWidget *widget)
89 {
90         GdkScreen *screen;
91
92         screen = gtk_widget_get_screen (widget);
93         gtk_widget_set_colormap (widget,
94                                  gdk_screen_get_rgba_colormap (screen));
95
96         gtk_widget_set_app_paintable (widget,
97                                       TRUE);
98
99         GTK_WIDGET_CLASS (el_home_applet_parent_class)->realize (widget);
100 }
101
102 /*
103  * Thanks http://cairographics.org/cookbook/roundedrectangles/
104  */
105 static void
106 rounded_rectangle (cairo_t *cr,
107                    double   x,
108                    double   y,
109                    double   w,
110                    double   h,
111                    double   r)
112 {
113         cairo_move_to (cr, x + r, y);
114         cairo_line_to (cr, x + w - r, y);
115         cairo_curve_to (cr, x + w, y,
116                         x + w, y,
117                         x + w, y + r);
118         cairo_line_to (cr, x + w, y + h - r);
119         cairo_curve_to (cr, x + w, y + h,
120                         x + w, y + h,
121                         x + w - r, y + h);
122         cairo_line_to (cr, x + r, y + h);
123         cairo_curve_to (cr, x, y + h,
124                         x, y + h,
125                         x, y + h - r);
126         cairo_line_to (cr, x, y + r);
127         cairo_curve_to (cr, x, y,
128                         x, y,
129                         x + r, y);
130 }
131
132 static gboolean
133 expose_event (GtkWidget *self, GdkEventExpose *event)
134 {
135         ELHomeAppletPrivate *priv = EL_HOME_APPLET(self)->priv;
136
137         cairo_t *cr;
138         GdkColor color;
139         float red, green, blue;
140
141         /* find theme active color */
142         gtk_style_lookup_color (self->style, "ActiveTextColor", &color);
143         red = color.red/(float)G_MAXUINT16;
144         green = color.green/(float)G_MAXUINT16;
145         blue = color.blue/(float)G_MAXUINT16;
146
147         cr = gdk_cairo_create (self->window);
148         gdk_cairo_region (cr, event->region);
149         cairo_clip (cr);
150
151         /* draw bound box */
152         cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
153
154         cairo_set_source_rgba (cr, 0.4f, 0.4f, 0.4f, 0.1f);
155         cairo_set_line_width (cr, 3.0f);
156
157         rounded_rectangle (cr,
158                            C_X,
159                            C_Y,
160                            BOX_WIDTH - 2*C_X,
161                            BOX_HEIGHT - 2*C_Y,
162                            BOX_RADIOUS);
163
164         cairo_close_path(cr);
165         cairo_stroke (cr);
166
167         /* draw header */
168         cairo_set_line_width (cr, 1.0f);
169
170         cairo_translate (cr, C_X, C_Y);
171         cairo_move_to (cr, 0, HEADER_HEIGHT);
172         cairo_line_to (cr, 0, BOX_RADIOUS);
173         cairo_curve_to (cr, 0, 0, 0, 0, BOX_RADIOUS, 0);
174         cairo_line_to (cr, C_WIDTH - BOX_RADIOUS, 0);
175         cairo_curve_to (cr, C_WIDTH, 0, C_WIDTH, 0, C_WIDTH, BOX_RADIOUS);
176         cairo_line_to (cr, C_WIDTH, HEADER_HEIGHT);
177         cairo_line_to (cr, 0, HEADER_HEIGHT);
178
179         cairo_close_path(cr);
180
181         cairo_set_source_rgba (cr, 0.2f, 0.2f, 0.2f, 0.8f);
182         cairo_fill_preserve (cr);
183         cairo_set_source_rgba (cr, red, green, blue, 1.0f);
184         cairo_stroke (cr);
185
186         /* draw body */
187         cairo_move_to (cr, 0, HEADER_HEIGHT);
188         cairo_line_to (cr, 0, C_HEIGHT - BOX_RADIOUS);
189         cairo_curve_to (cr, 0, C_HEIGHT, 0, C_HEIGHT, BOX_RADIOUS, C_HEIGHT);
190         cairo_line_to (cr, C_WIDTH - BOX_RADIOUS, C_HEIGHT);
191         cairo_curve_to (cr, C_WIDTH, C_HEIGHT, C_WIDTH, C_HEIGHT, C_WIDTH, C_HEIGHT - BOX_RADIOUS);
192         cairo_line_to (cr, C_WIDTH, HEADER_HEIGHT);
193         cairo_line_to (cr, 0, HEADER_HEIGHT);
194         cairo_close_path(cr);
195
196         /* draw body filling depending on (in)active state */
197         cairo_pattern_t *grad;
198         grad = cairo_pattern_create_linear(0, HEADER_HEIGHT,
199                                            0, C_HEIGHT);
200
201         if (priv->active){
202                 cairo_pattern_add_color_stop_rgba (grad, 0.5f,
203                                                    red, green, blue, 0.8f);
204                 cairo_pattern_add_color_stop_rgba (grad, 1.0f,
205                                                    red/2, green/2, blue/2, 0.8f);
206         }
207         else {
208                 cairo_pattern_add_color_stop_rgba (grad, 0.5f,
209                                                    0.4f, 0.4f, 0.4f, 0.8f);
210                 cairo_pattern_add_color_stop_rgba (grad, 1.0f,
211                                                    0.2f, 0.2f, 0.2f, 0.8f);
212         }
213         cairo_set_source (cr, grad);
214         cairo_fill (cr);
215
216         /* cairo_set_source_rgba (cr, red, green, blue, 1.0f); */
217         /* cairo_translate (cr, -C_X, -C_Y); */
218         /* rounded_rectangle (cr, */
219         /*                    C_X, */
220         /*                    C_Y, */
221         /*                    BOX_WIDTH - 2*C_X, */
222         /*                    BOX_HEIGHT - 2*C_Y, */
223         /*                    BOX_RADIOUS); */
224         /* cairo_close_path(cr); */
225         /* cairo_stroke (cr); */
226         cairo_pattern_destroy (grad);
227         cairo_destroy (cr);
228
229         return GTK_WIDGET_CLASS (el_home_applet_parent_class)->expose_event (self, event);
230 }
231
232 static void
233 dispose (GObject *self)
234 {
235         ELHomeAppletPrivate *priv = EL_HOME_APPLET(self)->priv;
236
237         if (priv->idle_id){
238                 g_source_remove (priv->idle_id);
239                 priv->idle_id = 0;
240         }
241         if (priv->eventlogger){
242                 g_object_unref (priv->eventlogger);
243                 priv->eventlogger = NULL;
244         }
245
246         G_OBJECT_CLASS (el_home_applet_parent_class)->dispose (self);
247 }
248
249 static void
250 finalize (GObject *self)
251 {
252         G_OBJECT_CLASS (el_home_applet_parent_class)->finalize (self);
253 }
254
255 static gchar*
256 format_time (time_t t)
257 {
258         static const guint RESULT_SIZE = 32;
259
260         time_t now;
261         struct tm now_tm, t_tm;
262         const gchar *format = "%Y.%m.%d %T";
263         gchar *result = g_malloc0 (RESULT_SIZE);
264
265         now = time (NULL);
266         localtime_r (&now, &now_tm);
267         localtime_r (&t, &t_tm);
268
269         if ((now_tm.tm_year == t_tm.tm_year) &&
270             (now_tm.tm_mon  == t_tm.tm_mon) &&
271             (now_tm.tm_mday == t_tm.tm_mday))
272                 format = "%T";
273
274         strftime (result, RESULT_SIZE, format, &t_tm);
275
276         return result;
277 }
278
279 static void
280 show_event (ELHomeApplet *self, RTComElIter *it)
281 {
282         ELHomeAppletPrivate *priv = self->priv;
283
284         gchar *message = NULL;
285         gchar *remote = NULL;
286         gchar *received = NULL;
287         const gchar *icon_name = NULL;
288
289         if (it && rtcom_el_iter_first (it)){
290                 rtcom_el_iter_dup_string (it, "free-text", &message);
291                 if (message){
292                         const gchar *service;
293                         time_t received_t;
294
295                         rtcom_el_iter_get_int (it, "id", &priv->event_id);
296                         if (rtcom_el_iter_get_int (it, "start-time", (gint*)&received_t))
297                                 received = format_time (received_t);
298
299                         if(!rtcom_el_iter_dup_string (it, "remote-name", &remote))
300                                 rtcom_el_iter_dup_string (it, "remote-id", &remote);
301                         service = rtcom_el_iter_get_service (it);
302                         if (!g_strcmp0 (service, "RTCOM_EL_SERVICE_SMS"))
303                                 icon_name = "chat_unread_sms";
304                         else if (!g_strcmp0 (service, "RTCOM_EL_SERVICE_CHAT"))
305                                 icon_name = "chat_unread_chat";
306                 }
307         }
308         else{
309                 priv->event_id = -1;
310         }
311
312         gtk_label_set_text (GTK_LABEL (priv->message), message);
313         gtk_label_set_text (GTK_LABEL (priv->sender), remote);
314         gtk_label_set_text (GTK_LABEL (priv->received), received);
315
316         if (icon_name){
317                 const gchar *current_icon_name;
318                 gtk_image_get_icon_name (GTK_IMAGE (priv->icon),
319                                          &current_icon_name,
320                                          NULL);
321                 if (g_strcmp0 (current_icon_name, icon_name))
322                         gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon),
323                                                       icon_name,
324                                                       HILDON_ICON_SIZE_FINGER);
325                 gtk_widget_show (priv->icon);
326         }
327         else
328                 gtk_widget_hide (priv->icon);
329
330         g_free (message);
331         g_free (remote);
332 }
333
334 static RTComElIter*
335 make_query (RTComEl *el, gint event_id)
336 {
337         RTComElQuery *query = NULL;
338         RTComElIter *it = NULL;
339
340         static const gchar *services[] = {"RTCOM_EL_SERVICE_SMS",
341                                           "RTCOM_EL_SERVICE_CHAT",
342                                           NULL};
343         static const gchar *event_types[] = {"RTCOM_EL_EVENTTYPE_SMS_INBOUND",
344                                              "RTCOM_EL_EVENTTYPE_CHAT_INBOUND",
345                                              NULL};
346
347         query = rtcom_el_query_new (el);
348         rtcom_el_query_set_limit (query, 1);
349         if (event_id >= 0){
350                 rtcom_el_query_prepare (query,
351                                         "is-read", FALSE, RTCOM_EL_OP_EQUAL,
352                                         "id", event_id, RTCOM_EL_OP_EQUAL,
353                                         "service", services, RTCOM_EL_OP_IN_STRV,
354                                         "event-type", event_types, RTCOM_EL_OP_IN_STRV,
355                                         NULL);
356         }
357         else{
358                 rtcom_el_query_prepare (query,
359                                         "is-read", FALSE, RTCOM_EL_OP_EQUAL,
360                                         "service", services, RTCOM_EL_OP_IN_STRV,
361                                         "event-type", event_types, RTCOM_EL_OP_IN_STRV,
362                                         NULL);
363         }
364         it = rtcom_el_get_events (el, query);
365         g_object_unref(query);
366
367         return it;
368 }
369
370 static void
371 update_unread_label (ELHomeApplet *self)
372 {
373         ELHomeAppletPrivate *priv = self->priv;
374         gchar *text;
375
376         text = g_strdup_printf ("%d", priv->unread_count);
377         gtk_label_set_text (GTK_LABEL (priv->unread), text);
378         g_free (text);
379 }
380
381 static gint
382 query_unread_events (RTComEl *el)
383 {
384         sqlite3 *db;
385         sqlite3_stmt *stmt;
386         int ret;
387         gint count = 0;
388
389         g_object_get (el, "db", &db, NULL);
390
391         if (sqlite3_prepare_v2 (db,
392                                 "SELECT SUM(total_events)-SUM(read_events) FROM GroupCache;",
393                                 -1,
394                                 &stmt,
395                                 NULL) != SQLITE_OK){
396                 g_error ("%s: can't compile SQL", G_STRFUNC);
397                 return -1;
398         }
399
400         while (SQLITE_BUSY == (ret = sqlite3_step (stmt)));
401
402         if (ret == SQLITE_ROW){
403                 count = sqlite3_column_int (stmt, 0);
404         }
405         else{
406                 g_error ("%s: error while executing SQL", G_STRFUNC);
407         }
408
409         sqlite3_finalize (stmt);
410
411         return count;
412 }
413
414 static void
415 read_event (ELHomeApplet *self)
416 {
417         ELHomeAppletPrivate *priv = self->priv;
418         RTComElIter *it = NULL;
419
420         it = make_query (priv->eventlogger, -1);
421         show_event (self, it);
422         if (it) g_object_unref (it);
423 }
424
425 static void
426 mark_as_read (ELHomeApplet *self)
427 {
428         ELHomeAppletPrivate *priv = self->priv;
429
430         if (priv->event_id >= 0){
431                 rtcom_el_set_read_event (priv->eventlogger,
432                                          priv->event_id,
433                                          TRUE,
434                                          NULL);
435                 read_event (self);
436                 priv->unread_count--;
437                 update_unread_label (self);
438         }
439 }
440
441 static gboolean
442 read_new_event (ELHomeApplet *self)
443 {
444         ELHomeAppletPrivate *priv = self->priv;
445
446         if (priv->new_event_id >= 0){
447                 RTComElIter *it = NULL;
448                 it = make_query (priv->eventlogger, priv->new_event_id);
449                 if (it){
450                         if (rtcom_el_iter_first (it))
451                                 show_event (self, it);
452                         g_object_unref (it);
453                 }
454                 priv->unread_count = query_unread_events (priv->eventlogger);
455                 update_unread_label (self);
456         }
457         priv->new_event_id = -1;
458         priv->idle_id = 0;
459
460         return FALSE;
461 }
462
463 static void
464 add_new_idle (ELHomeApplet *self)
465 {
466         ELHomeAppletPrivate *priv = self->priv;
467
468         if (priv->idle_id)
469                 g_source_remove (priv->idle_id);
470         priv->idle_id = g_idle_add ((GSourceFunc)read_new_event,
471                                     self);
472 }
473
474 static void
475 new_event_cb (RTComEl      *backend,
476               gint          event_id,
477               const gchar  *local_uid,
478               const gchar  *remote_uid,
479               const gchar  *remote_ebook_uid,
480               const gchar  *group_uid,
481               const gchar  *service,
482               ELHomeApplet *self)
483 {
484         ELHomeAppletPrivate *priv = self->priv;
485
486         priv->new_event_id = event_id;
487         add_new_idle (self);
488 }
489
490 static gboolean
491 button_release_event_cb (GtkWidget      *widget,
492                          GdkEventButton *event,
493                          ELHomeApplet   *self)
494 {
495         ELHomeAppletPrivate *priv = self->priv;
496
497         if (priv->active){
498                 priv->active = FALSE;
499                 gtk_widget_queue_draw (widget);
500 #ifndef DEBUG_LAYOUT
501                 mark_as_read (self);
502 #endif
503         }
504
505         return TRUE;
506 }
507
508 static gboolean
509 button_press_event_cb (GtkWidget      *widget,
510                        GdkEventButton *event,
511                        ELHomeApplet   *self)
512 {
513         ELHomeAppletPrivate *priv = self->priv;
514
515         if (priv->event_id > 0){
516                 priv->active = TRUE;
517                 gtk_widget_queue_draw (widget);
518         }
519
520         return TRUE;
521 }
522
523 static gboolean
524 leave_notify_event_cb (GtkWidget        *widget,
525                        GdkEventCrossing *event,
526                        ELHomeApplet     *self)
527 {
528         ELHomeAppletPrivate *priv = self->priv;
529
530         if (priv->active){
531                 priv->active = FALSE;
532                 gtk_widget_queue_draw (widget);
533         }
534
535         return FALSE;
536 }
537
538 static void
539 el_home_applet_init (ELHomeApplet *self)
540 {
541         ELHomeAppletPrivate *priv;
542         GtkWidget *event_box;
543         GtkWidget *hbox, *vbox, *align;
544
545         self->priv = EL_HOME_APPLET_GET_PRIVATE (self);
546         priv = self->priv;
547
548         gtk_widget_set_app_paintable (GTK_WIDGET (self), TRUE);
549
550         priv->unread = gtk_label_new ("12");
551         hildon_helper_set_logical_color (priv->unread,
552                                          GTK_RC_FG,
553                                          GTK_STATE_NORMAL,
554                                          "ActiveTextColor");
555         gtk_misc_set_alignment (GTK_MISC (priv->unread),
556                                 1.0f,
557                                 0.5f);
558         gtk_widget_set_size_request (priv->unread,
559                                      -1,
560                                      HEADER_HEIGHT);
561
562         priv->icon = gtk_image_new_from_icon_name ("chat_unread_sms",
563                                                    HILDON_ICON_SIZE_FINGER);
564         gtk_misc_set_alignment (GTK_MISC (priv->icon),
565                                 0.5f,
566                                 0.5f);
567
568         priv->sender = gtk_label_new ("asdf asdf asdf asdf asdf");
569         gtk_misc_set_alignment (GTK_MISC (priv->sender),
570                                 0.5f,
571                                 0.5f);
572         gtk_label_set_ellipsize (GTK_LABEL (priv->sender),
573                                  PANGO_ELLIPSIZE_END);
574         gtk_widget_set_name (priv->sender, "hildon-shadow-label");
575         hildon_helper_set_logical_font (priv->sender, "SystemFont");
576
577         priv->message = g_object_new (GTK_TYPE_LABEL,
578                                       "label", "asdf asdf adsf asdf asdf asdf asdf asdf",
579                                       "wrap", TRUE,
580                                       "wrap-mode", PANGO_WRAP_WORD_CHAR,
581                                       NULL);
582
583         gtk_misc_set_alignment (GTK_MISC (priv->message),
584                                 0.0f,
585                                 0.0f);
586         gtk_widget_set_size_request (priv->message,
587                                      MESSAGE_WIDTH,
588                                      MESSAGE_HEIGHT);
589         gtk_widget_set_name (priv->message, "hildon-shadow-label");
590
591         priv->received = gtk_label_new ("aewf aewf aewf awef");
592         gtk_misc_set_alignment (GTK_MISC (priv->received),
593                                 1.0f,
594                                 0.5f);
595         gtk_widget_set_size_request (priv->received,
596                                      MESSAGE_WIDTH,
597                                      -1);
598         hildon_helper_set_logical_font (priv->received, "SmallSystemFont");
599         gtk_widget_set_name (priv->received, "hildon-shadow-label");
600
601         hbox = gtk_hbox_new (FALSE, 0);
602         gtk_box_pack_start (GTK_BOX (hbox), priv->unread, FALSE, FALSE, 0);
603         gtk_box_pack_start (GTK_BOX (hbox), priv->icon, FALSE, FALSE, 0);
604         gtk_box_pack_start (GTK_BOX (hbox), priv->sender, TRUE, TRUE, 0);
605
606         vbox = gtk_vbox_new (FALSE, 0);
607         gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
608         gtk_box_pack_start (GTK_BOX (vbox), priv->message, TRUE, TRUE, 0);
609         gtk_box_pack_start (GTK_BOX (vbox), priv->received, FALSE, FALSE, 0);
610
611         align = gtk_alignment_new (0.5f, 0.0f, 1.0f, 1.0f);
612         gtk_alignment_set_padding (GTK_ALIGNMENT (align),
613                                    0, 0, HILDON_MARGIN_DEFAULT, HILDON_MARGIN_DEFAULT);
614
615         gtk_container_set_border_width (GTK_CONTAINER (vbox), HILDON_MARGIN_HALF);
616
617         event_box = gtk_event_box_new ();
618         gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
619         gtk_widget_set_size_request (event_box, BOX_WIDTH, BOX_HEIGHT);
620
621         gtk_container_add (GTK_CONTAINER (align), vbox);
622         gtk_container_add (GTK_CONTAINER (event_box), align);
623         gtk_container_add (GTK_CONTAINER (self), event_box);
624
625         g_signal_connect (event_box, "button-press-event",
626                 G_CALLBACK (button_press_event_cb), self);
627         g_signal_connect (event_box, "button-release-event",
628                 G_CALLBACK (button_release_event_cb), self);
629         g_signal_connect (event_box, "leave-notify-event",
630                 G_CALLBACK (leave_notify_event_cb), self);
631
632         gtk_widget_show_all (GTK_WIDGET (event_box));
633
634 #ifndef DEBUG_LAYOUT
635         priv->eventlogger = rtcom_el_new ();
636         g_signal_connect (priv->eventlogger,
637                           "new-event",
638                           G_CALLBACK (new_event_cb),
639                           self);
640         g_signal_connect (priv->eventlogger,
641                           "event-updated",
642                           G_CALLBACK (new_event_cb),
643                           self);
644
645         read_event (self);
646         priv->unread_count = query_unread_events (priv->eventlogger);
647         update_unread_label (self);
648 #endif
649 }
650
651 static void
652 el_home_applet_class_init (ELHomeAppletClass *klass)
653 {
654         GObjectClass *object_class = G_OBJECT_CLASS (klass);
655         GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
656
657         object_class->dispose = dispose;
658         object_class->finalize = finalize;
659         widget_class->expose_event = expose_event;
660         widget_class->realize = el_home_applet_realize;
661
662         g_type_class_add_private (klass, sizeof (ELHomeAppletPrivate));
663 }
664