root/trunk/third/nautilus/components/services/summary/nautilus-view/nautilus-summary-view.c @ 15547

Revision 15547, 36.5 KB (checked in by ghudson, 9 years ago)

This commit was generated by cvs2svn to compensate for changes in r15546,
which included commits to RCS files with non-trunk default branches.

Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3/*
4 * Copyright (C) 2000 Eazel, Inc
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 * Author: J Shane Culpepper <pepper@eazel.com>
22 */
23
24#include <config.h>
25
26#include <gnome-xml/tree.h>
27#include <bonobo/bonobo-control.h>
28#include <libgnomevfs/gnome-vfs-utils.h>
29
30#include <libnautilus-extensions/nautilus-background.h>
31#include <libnautilus-extensions/nautilus-bonobo-extensions.h>
32#include <libnautilus-extensions/nautilus-caption-table.h>
33#include <libnautilus-extensions/nautilus-file-utilities.h>
34#include <libnautilus-extensions/nautilus-gdk-extensions.h>
35#include <libnautilus-extensions/nautilus-glib-extensions.h>
36#include <libnautilus-extensions/nautilus-global-preferences.h>
37#include <libnautilus-extensions/nautilus-gnome-extensions.h>
38#include <libnautilus-extensions/nautilus-gtk-extensions.h>
39#include <libnautilus-extensions/nautilus-gtk-macros.h>
40#include <libnautilus-extensions/nautilus-stock-dialogs.h>
41#include <libnautilus-extensions/nautilus-string.h>
42#include <libnautilus-extensions/nautilus-tabs.h>
43#include <libnautilus-extensions/nautilus-label.h>
44#include <libnautilus-extensions/nautilus-viewport.h>
45
46#include <gnome.h>
47#include <libgnomeui/gnome-stock.h>
48#include <stdio.h>
49#include <unistd.h>
50
51#include <orb/orbit.h>
52#include <liboaf/liboaf.h>
53#include <libtrilobite/trilobite-redirect.h>
54#include <libtrilobite/eazelproxy.h>
55#include <libtrilobite/libammonite.h>
56#include <bonobo/bonobo-main.h>
57
58#include "nautilus-summary-view.h"
59
60#include "eazel-summary-shared.h"
61#include "eazel-services-footer.h"
62#include "eazel-services-header.h"
63#include "eazel-services-extensions.h"
64
65#include "nautilus-summary-callbacks.h"
66#include "nautilus-summary-menu-items.h"
67#include "nautilus-summary-dialogs.h"
68#include "nautilus-summary-footer.h"
69#include "nautilus-summary-view-private.h"
70
71#define notDEBUG_TEST   1
72#define notDEBUG_PEPPER 1
73
74#define SUMMARY_TEXT_HEADER_SIZE_REL (+2)
75#define SUMMARY_TEXT_BODY_SIZE_REL (-2)
76
77#ifdef DEBUG_TEST
78        #undef URL_REDIRECT_TABLE_HOME
79        #define URL_REDIRECT_TABLE_HOME         "http://localhost/redirects.xml"
80#endif
81
82static void     nautilus_summary_view_initialize_class (NautilusSummaryViewClass   *klass);
83static void     nautilus_summary_view_initialize       (NautilusSummaryView        *view);
84static void     nautilus_summary_view_destroy          (GtkObject                  *object);
85static void     summary_load_location_callback         (NautilusView               *nautilus_view,
86                                                        const char                 *location,
87                                                        NautilusSummaryView        *view);
88static void     generate_summary_form                  (NautilusSummaryView        *view);
89static void     generate_service_entry_row             (NautilusSummaryView        *view,
90                                                        int                         row);
91static void     generate_eazel_news_entry_row          (NautilusSummaryView        *view,
92                                                        int                         row);
93static void     generate_update_news_entry_row         (NautilusSummaryView        *view,
94                                                        int                         row);
95static void     goto_service_cb                        (GtkWidget                  *button,
96                                                        ServicesButtonCallbackData *cbdata);
97static void     goto_update_cb                         (GtkWidget                  *button,
98                                                        ServicesButtonCallbackData *cbdata);
99
100NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusSummaryView, nautilus_summary_view, GTK_TYPE_EVENT_BOX)
101
102static const char *footer_online_items[] =
103{
104        N_("Register"),
105        N_("Login"),
106        N_("Terms of Use"),
107        N_("Privacy Statement")
108};
109
110static const char *footer_offline_items[] =
111{
112        N_("Account Preferences"),
113        N_("Logout"),
114        N_("Terms of Use"),
115        N_("Privacy Statement")
116};
117
118static void
119generate_summary_form (NautilusSummaryView      *view)
120{
121
122        GtkWidget               *frame;
123        GtkWidget               *title;
124        GtkWidget               *footer;
125        GtkWidget               *notebook, *notebook_tabs;
126        GtkWidget               *temp_box;
127        ServicesData            *service_node;
128        EazelNewsData           *eazel_news_node;
129        UpdateNewsData          *update_news_node;
130        GList                   *iterator;
131        GtkWidget               *temp_scrolled_window;
132        GtkWidget               *viewport;
133        GtkWidget               *temp_hbox;
134        GtkWidget               *temp_vbox;
135        GtkWidget               *notebook_vbox;
136        GtkWidget               *temp_label;
137        GtkWidget               *separator;
138        gboolean                has_news;
139       
140        view->details->current_service_row = 0;
141        view->details->current_news_row = 0;
142        view->details->current_update_row = 0;
143
144        if (view->details->form != NULL) {
145                gtk_container_remove (GTK_CONTAINER (view), view->details->form);
146                view->details->form = NULL;
147        }
148
149#ifdef DEBUG_pepper
150        g_print ("Start summary view load.\n");
151
152#endif
153        /* allocate the parent box to hold everything */
154        view->details->form = gtk_vbox_new (FALSE, 0);
155        gtk_container_add (GTK_CONTAINER (view), view->details->form);
156
157        /* setup the title */
158#ifdef DEBUG_pepper
159        g_print ("Start title load.\n");
160#endif
161        title = eazel_services_header_title_new ("");
162
163        if (view->details->logged_in) {
164                char *text;
165                g_free (view->details->user_name);
166                view->details->user_name = ammonite_get_default_user_username (view->details->user_control);
167                text = g_strdup_printf (_("Welcome Back %s!"), view->details->user_name);
168                eazel_services_header_set_left_text (EAZEL_SERVICES_HEADER (title), text);
169                g_free (text);
170        }
171        else {
172                eazel_services_header_set_left_text (EAZEL_SERVICES_HEADER (title),
173                                                     _("You are not logged in!"));
174        }
175        gtk_box_pack_start (GTK_BOX (view->details->form), title, FALSE, FALSE, 0);
176        gtk_widget_show (title);
177#ifdef DEBUG_pepper
178        g_print ("end title load.\n");
179#endif
180       
181        /* create the news section only if there's some news */
182#ifdef DEBUG_pepper
183        g_print ("start news load.\n");
184#endif
185        has_news = FALSE;
186        if (view->details->xml_data->eazel_news_list) {
187                eazel_news_node = (EazelNewsData*) view->details->xml_data->eazel_news_list->data;
188                has_news = eazel_news_node->message != NULL;
189        }
190       
191        if (has_news) {
192                /* Create the Service News Frame */     
193                frame = gtk_vbox_new (FALSE, 0);
194                gtk_widget_show (frame);               
195                gtk_box_pack_start (GTK_BOX (view->details->form), frame, TRUE, TRUE, 0);
196               
197                /* create the service news scroll widget */
198               
199                temp_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
200                gtk_widget_show (temp_scrolled_window);
201                viewport = nautilus_viewport_new (NULL, NULL);
202                widget_set_nautilus_background_color (viewport, DEFAULT_SUMMARY_BACKGROUND_COLOR_SPEC);
203                gtk_widget_show (viewport);
204                gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);
205                gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (temp_scrolled_window),
206                                                GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
207               
208                /* create the parent service news box and a table to hold the data */
209                temp_box = gtk_vbox_new (FALSE, 0);
210                gtk_widget_show (temp_box);
211
212                /* build the eazel news table from the xml file */
213                for (iterator = view->details->xml_data->eazel_news_list; iterator; iterator = g_list_next (iterator)) {
214
215                        view->details->service_news_row = gtk_hbox_new (FALSE, 0);
216                        gtk_widget_show (view->details->service_news_row);
217
218                        view->details->current_news_row++;
219                        eazel_news_node = iterator->data;
220                        view->details->news_icon_name = eazel_news_node->icon;
221                        view->details->news_date = eazel_news_node->date;
222                        view->details->news_description_body = g_strdup(eazel_news_node->message);
223
224                        generate_eazel_news_entry_row (view, view->details->current_news_row);
225                        gtk_box_pack_start (GTK_BOX (temp_box), GTK_WIDGET (view->details->service_news_row), FALSE, FALSE, 0);
226
227                        if (iterator->next != NULL || view->details->current_news_row > 1) {
228                                separator = gtk_hseparator_new ();
229                                gtk_box_pack_start (GTK_BOX (temp_box), separator, FALSE, FALSE, 8);
230                                gtk_widget_show (separator);
231                        }
232                        /* FIXME: is this a leak?  who frees the constituent strings? */
233                        g_free (eazel_news_node);
234                }
235
236                g_list_free (view->details->xml_data->eazel_news_list);
237
238                /* draw parent vbox and connect it to the service news frame */
239                gtk_container_add (GTK_CONTAINER (viewport), temp_box);
240                gtk_container_add (GTK_CONTAINER (temp_scrolled_window), viewport);
241                gtk_box_pack_start (GTK_BOX (frame), temp_scrolled_window, TRUE, TRUE, 0);             
242        }
243#ifdef DEBUG_pepper
244        g_print ("end news load.\n");
245#endif
246       
247        /* add a set of tabs to control the notebook page switching */
248#ifdef DEBUG_pepper
249        g_print ("start tab load.\n");
250#endif
251        notebook_tabs = nautilus_tabs_new ();
252        gtk_widget_show (notebook_tabs);
253        gtk_box_pack_start (GTK_BOX (view->details->form), notebook_tabs, FALSE, FALSE, 0);
254
255        /* Create the notebook container for services */
256        notebook = gtk_notebook_new ();
257        gtk_widget_show (notebook);
258        gtk_box_pack_start (GTK_BOX (view->details->form), notebook, TRUE, TRUE, 0);
259       
260        gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
261        view->details->services_notebook = notebook;
262        gtk_signal_connect (GTK_OBJECT (notebook_tabs), "tab_selected", service_tab_selected_callback, view);
263       
264        /* add the tab */
265        nautilus_tabs_add_tab (NAUTILUS_TABS (notebook_tabs), _("Your Services"), 0);
266#ifdef DEBUG_pepper
267        g_print ("end tab load.\n");
268#endif
269       
270        /* Create the Services Listing Box */
271#ifdef DEBUG_pepper
272        g_print ("start services load.\n");
273#endif
274        frame = gtk_vbox_new (FALSE, 0);
275        gtk_widget_show (frame);
276        gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, NULL);
277
278        /* create the services scroll widget */
279        temp_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
280        gtk_widget_show (temp_scrolled_window);
281        viewport = nautilus_viewport_new (NULL, NULL);
282        widget_set_nautilus_background_color (viewport, DEFAULT_SUMMARY_BACKGROUND_COLOR_SPEC);
283        gtk_widget_show (viewport);
284        gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);
285
286        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (temp_scrolled_window),
287                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
288
289        /* create the parent services list box */
290        temp_box = gtk_vbox_new (FALSE, 0);
291        gtk_widget_show (temp_box);
292
293        /* build the services table from the xml file */
294        for (iterator = view->details->xml_data->services_list; iterator; iterator = g_list_next (iterator)) {
295
296                view->details->services_row = gtk_hbox_new (FALSE, 0);
297                gtk_widget_show (GTK_WIDGET (view->details->services_row));
298
299                view->details->current_service_row++;
300                service_node = iterator->data;
301                view->details->services_icon_name = service_node->icon;
302                view->details->services_description_header = service_node->description_header;
303                view->details->services_description_body = service_node->description;
304                view->details->services_goto_label = g_strdup (_(GOTO_BUTTON_LABEL));
305                view->details->services_button_enabled = service_node->enabled;
306                view->details->services_redirects[view->details->current_service_row - 1] = service_node->uri;
307
308                generate_service_entry_row (view, view->details->current_service_row);
309                gtk_box_pack_start (GTK_BOX (temp_box), GTK_WIDGET (view->details->services_row), FALSE, FALSE, 4);
310
311                if (iterator->next != NULL || view->details->current_service_row > 1) {
312                        separator = gtk_hseparator_new ();
313                        gtk_box_pack_start (GTK_BOX (temp_box), separator, FALSE, FALSE, 8);
314                        gtk_widget_show (separator);
315                }
316
317                g_free (service_node);
318
319        }
320
321        g_list_free (view->details->xml_data->services_list);
322
323        /* draw parent vbox and connect it to the login frame */
324        gtk_container_add (GTK_CONTAINER (viewport), temp_box);
325        gtk_container_add (GTK_CONTAINER (temp_scrolled_window), viewport);
326        gtk_box_pack_start (GTK_BOX (frame), temp_scrolled_window, TRUE, TRUE, 0);
327
328        /* create the Additional Services pane */
329        nautilus_tabs_add_tab (NAUTILUS_TABS (notebook_tabs), _("Additional Services"), 1);
330
331        temp_vbox = gtk_vbox_new (TRUE, 0);
332        gtk_widget_show (temp_vbox);
333        gtk_notebook_append_page (GTK_NOTEBOOK (notebook), temp_vbox, NULL);
334
335        temp_hbox = gtk_hbox_new (TRUE, 0);
336        gtk_widget_show (temp_hbox);
337
338        /* create the services scroll widget */
339        temp_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
340        gtk_widget_show (temp_scrolled_window);
341        viewport = nautilus_viewport_new (NULL, NULL);
342        widget_set_nautilus_background_color (viewport, DEFAULT_SUMMARY_BACKGROUND_COLOR_SPEC);
343        gtk_widget_show (viewport);
344        gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);
345
346        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (temp_scrolled_window),
347                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
348       
349        temp_label = eazel_services_label_new (_("\nCheck back here for new system management\nservices that will help make Linux easier to use."),
350                                               0,
351                                               0.5,
352                                               0.5,
353                                               0,
354                                               0,
355                                               DEFAULT_SUMMARY_TEXT_COLOR_RGB,
356                                               DEFAULT_SUMMARY_BACKGROUND_COLOR_RGB,
357                                               NULL,
358                                               SUMMARY_TEXT_HEADER_SIZE_REL,
359                                               TRUE);
360
361        gtk_widget_show (temp_label);
362        gtk_box_pack_start (GTK_BOX (temp_hbox), temp_label, TRUE, TRUE, 0);
363       
364        gtk_container_add (GTK_CONTAINER (viewport), temp_hbox);
365        gtk_container_add (GTK_CONTAINER (temp_scrolled_window), viewport);
366        gtk_box_pack_start (GTK_BOX (temp_vbox), temp_scrolled_window, TRUE, TRUE, 0);
367
368        /* add a set of tabs to control the updates page switching */
369        notebook_vbox = gtk_vbox_new (FALSE, 0);
370        gtk_widget_show (notebook_vbox);
371       
372        notebook_tabs = nautilus_tabs_new ();
373        gtk_widget_show (notebook_tabs);
374        gtk_box_pack_start (GTK_BOX (notebook_vbox), notebook_tabs, FALSE, FALSE, 0);
375#ifdef DEBUG_pepper
376        g_print ("end services load.\n");
377#endif
378
379        /* Create the notebook container for updates */
380#ifdef DEBUG_pepper
381        g_print ("start updates load.\n");
382#endif
383        notebook = gtk_notebook_new ();
384        gtk_widget_show (notebook);
385        gtk_container_add (GTK_CONTAINER (notebook_vbox), notebook);
386        gtk_box_pack_start (GTK_BOX (view->details->form), notebook_vbox, TRUE, TRUE, 0);
387       
388        gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
389        view->details->updates_notebook = notebook;
390        gtk_signal_connect (GTK_OBJECT (notebook_tabs), "tab_selected", updates_tab_selected_callback, view);
391       
392        /* add the tab */
393        nautilus_tabs_add_tab (NAUTILUS_TABS (notebook_tabs), _("Current Updates"), 0);
394
395        /* Create the Update News Frame */
396        frame = gtk_vbox_new (FALSE, 0);
397        gtk_widget_show (frame);
398        gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, NULL);
399
400        /* create the update news scroll widget */
401        temp_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
402        gtk_widget_show (temp_scrolled_window);
403       
404        viewport = nautilus_viewport_new (NULL, NULL);
405        widget_set_nautilus_background_color (viewport, DEFAULT_SUMMARY_BACKGROUND_COLOR_SPEC);
406        gtk_widget_show (viewport);
407        gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);
408        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (temp_scrolled_window),
409                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
410
411        /* create the parent update news box and a table to hold the labels and text entries */
412        temp_box = gtk_vbox_new (FALSE, 0);
413        gtk_widget_show (temp_box);
414
415        /* build the updates table from the xml file */
416        for (iterator = view->details->xml_data->update_news_list; iterator; iterator = g_list_next (iterator)) {
417
418                /* create the default update table */
419                view->details->updates_row = gtk_hbox_new (FALSE, 0);
420                gtk_widget_show (GTK_WIDGET (view->details->updates_row));
421
422                view->details->current_update_row++;
423                update_news_node = iterator->data;
424                view->details->update_icon_name = update_news_node->icon;
425                view->details->update_description_header = update_news_node->name;
426                view->details->update_description_version = g_strdup_printf (_("Version %s"), update_news_node->version);
427                view->details->update_description_body = update_news_node->description;
428                view->details->update_goto_label = g_strdup (_(INSTALL_GOTO_BUTTON_LABEL));
429                view->details->update_softcat_goto_label = g_strdup (_(SOFTCAT_GOTO_BUTTON_LABEL));
430                view->details->update_redirects[view->details->current_update_row - 1] = update_news_node->uri;
431                view->details->update_softcat_redirects[view->details->current_update_row - 1] = update_news_node->softcat_uri;
432
433                generate_update_news_entry_row (view, view->details->current_update_row);
434                gtk_box_pack_start (GTK_BOX (temp_box), GTK_WIDGET (view->details->updates_row), FALSE, FALSE, 4);
435
436                if (iterator->next != NULL || view->details->current_update_row > 1) {
437                        separator = gtk_hseparator_new ();
438                        gtk_box_pack_start (GTK_BOX (temp_box), separator, FALSE, FALSE, 8);
439                        gtk_widget_show (separator);
440                }
441               
442
443                g_free (update_news_node);
444
445        }
446
447        g_list_free (view->details->xml_data->update_news_list);
448
449        g_free (view->details->xml_data);
450        view->details->xml_data = NULL;
451
452#ifdef DEBUG_pepper
453        g_print ("start updates load.\n");
454
455        g_print ("start footer load.\n");
456#endif
457        footer = eazel_services_footer_new ();
458        gtk_signal_connect (GTK_OBJECT (footer), "item_clicked", GTK_SIGNAL_FUNC (footer_item_clicked_callback), view);
459
460        if (view->details->logged_in) {
461                eazel_services_footer_update (EAZEL_SERVICES_FOOTER (footer),
462                                              footer_offline_items,
463                                              NAUTILUS_N_ELEMENTS (footer_online_items));
464        }
465        else {
466                eazel_services_footer_update (EAZEL_SERVICES_FOOTER (footer),
467                                              footer_online_items,
468                                              NAUTILUS_N_ELEMENTS (footer_online_items));
469        }
470
471        gtk_box_pack_start (GTK_BOX (view->details->form), footer, FALSE, FALSE, 0);
472        gtk_widget_show (footer);
473#ifdef DEBUG_pepper
474        g_print ("end footer load.\n");
475#endif
476
477        /* draw parent vbox and connect it to the update news frame */
478        gtk_container_add (GTK_CONTAINER (viewport), temp_box);
479        gtk_container_add (GTK_CONTAINER (temp_scrolled_window), viewport);
480        gtk_box_pack_start (GTK_BOX (frame), temp_scrolled_window, TRUE, TRUE, 0);
481
482        /* Finally, show the form that hold everything */
483        gtk_widget_show (view->details->form);
484#ifdef DEBUG_pepper
485        g_print ("Load summary view end.\n");
486#endif
487}
488
489static void
490generate_service_entry_row  (NautilusSummaryView        *view, int      row)
491{
492        GtkWidget                       *temp_vbox;
493        GtkWidget                       *temp_hbox;
494        ServicesButtonCallbackData      *cbdata;
495
496        cbdata = g_new0 (ServicesButtonCallbackData, 1);
497
498        /* Generate first box with service icon */
499        view->details->services_icon_container = gtk_vbox_new (FALSE, 4);
500        gtk_widget_show (view->details->services_icon_container);
501        view->details->services_icon_widget = 
502                eazel_services_image_new_from_uri (view->details->services_icon_name,
503                                                   NULL,
504                                                   DEFAULT_SUMMARY_BACKGROUND_COLOR_RGB,
505                                                   MAX_IMAGE_WIDTH,
506                                                   MAX_IMAGE_HEIGHT);
507
508        g_assert (view->details->services_icon_widget != NULL);
509        gtk_box_pack_start (GTK_BOX (view->details->services_icon_container), view->details->services_icon_widget, 0, 0, 0);
510        gtk_widget_show (view->details->services_icon_widget);
511        gtk_box_pack_start (GTK_BOX (view->details->services_row), view->details->services_icon_container, FALSE, FALSE, 2);
512
513        /* Generate second box with service title and summary */
514        temp_vbox = gtk_vbox_new (FALSE, 0);
515        gtk_widget_show (temp_vbox);
516        /* Header */
517        temp_hbox = gtk_hbox_new (FALSE, 0);
518        gtk_widget_show (temp_hbox);
519        view->details->services_description_header_widget = 
520                eazel_services_label_new (view->details->services_description_header,
521                                          0,
522                                          0.5,
523                                          0.5,
524                                          0,
525                                          0,
526                                          DEFAULT_SUMMARY_TEXT_COLOR_RGB,
527                                          DEFAULT_SUMMARY_BACKGROUND_COLOR_RGB,
528                                          NULL,
529                                          SUMMARY_TEXT_BODY_SIZE_REL,
530                                          TRUE);
531        gtk_widget_show (view->details->services_description_header_widget);
532        g_free (view->details->services_description_header);
533        view->details->services_description_header = NULL;
534        gtk_box_pack_start (GTK_BOX (temp_hbox), view->details->services_description_header_widget, FALSE, FALSE, 2);
535        gtk_box_pack_start (GTK_BOX (temp_vbox), temp_hbox, FALSE, FALSE, 2);
536       
537        /* Body */
538        temp_hbox = gtk_hbox_new (FALSE, 0);
539        gtk_widget_show (temp_hbox);
540        view->details->services_description_body_widget = 
541                eazel_services_label_new (view->details->services_description_body,
542                                          0,
543                                          0.5,
544                                          0.5,
545                                          0,
546                                          0,
547                                          DEFAULT_SUMMARY_TEXT_COLOR_RGB,
548                                          DEFAULT_SUMMARY_BACKGROUND_COLOR_RGB,
549                                          NULL,
550                                          SUMMARY_TEXT_BODY_SIZE_REL,
551                                          FALSE);
552
553        nautilus_label_set_wrap (NAUTILUS_LABEL (view->details->services_description_body_widget), TRUE);
554        nautilus_label_set_justify (NAUTILUS_LABEL (view->details->services_description_body_widget), GTK_JUSTIFY_LEFT);
555
556        gtk_widget_show (view->details->services_description_body_widget);
557        g_free (view->details->services_description_body);
558        view->details->services_description_body = NULL;
559        gtk_box_pack_start (GTK_BOX (temp_hbox), view->details->services_description_body_widget, FALSE, FALSE, 2);
560        gtk_box_pack_start (GTK_BOX (temp_vbox), temp_hbox, FALSE, FALSE, 2);
561        gtk_box_pack_start (GTK_BOX (view->details->services_row), temp_vbox, FALSE, FALSE, 0);
562
563        /* Add the redirect button to the third box */
564
565        temp_vbox = gtk_vbox_new (TRUE, 0);
566        gtk_widget_show (temp_vbox);
567
568        view->details->services_button_container = gtk_hbox_new (FALSE, 0);
569        gtk_widget_show (view->details->services_button_container);
570        view->details->services_goto_button = gtk_button_new ();
571        gtk_widget_show (view->details->services_goto_button);
572        gtk_widget_set_usize (view->details->services_goto_button, 80, -1);
573        view->details->services_goto_label_widget = gtk_label_new (view->details->services_goto_label);
574        gtk_widget_show (view->details->services_goto_label_widget);
575        g_free (view->details->services_goto_label);
576        view->details->services_goto_label = NULL;
577       
578        gtk_container_add (GTK_CONTAINER (view->details->services_goto_button), view->details->services_goto_label_widget);
579        gtk_box_pack_end (GTK_BOX (view->details->services_button_container), view->details->services_goto_button, FALSE, FALSE, 3);
580       
581        cbdata->nautilus_view = view->details->nautilus_view;
582        cbdata->uri = view->details->services_redirects[view->details->current_service_row - 1];
583        gtk_signal_connect_full (GTK_OBJECT (view->details->services_goto_button), "clicked",
584                                 GTK_SIGNAL_FUNC (goto_service_cb), NULL,
585                                 cbdata, g_free, FALSE, FALSE);
586       
587        gtk_box_pack_start (GTK_BOX (temp_vbox), view->details->services_button_container, FALSE, FALSE, 2);   
588        gtk_box_pack_end (GTK_BOX (view->details->services_row), temp_vbox, FALSE, FALSE, 2);
589
590}
591
592#if 0
593/* FIXME well, we want to resize the text, but I don't know how */
594static void
595text_resize_callback      (GtkWidget *widget,
596                                GtkAllocation *allocation,
597                                gpointer user_data)
598{
599        NautilusLabel *label;
600
601        g_return_if_fail (NAUTILUS_IS_LABEL (user_data));
602
603        g_print ("text_resize New size %u\n", (unsigned) allocation->width);
604
605        label = NAUTILUS_LABEL (user_data);
606
607        nautilus_label_set_smooth_line_wrap_width (label, allocation->width);
608}
609#endif
610
611static void
612generate_eazel_news_entry_row  (NautilusSummaryView     *view, int      row)
613{
614        GtkWidget *item_box;
615       
616        /* Generate first box with icon */
617        view->details->news_icon_container = gtk_vbox_new (FALSE, 2);
618        gtk_widget_show (view->details->news_icon_container);
619        view->details->news_icon_widget = 
620                eazel_services_image_new_from_uri (view->details->news_icon_name,
621                                                   NULL,
622                                                   DEFAULT_SUMMARY_BACKGROUND_COLOR_RGB,
623                                                   MAX_IMAGE_WIDTH,
624                                                   MAX_IMAGE_HEIGHT);
625       
626        g_assert (view->details->news_icon_widget != NULL);
627        gtk_box_pack_start (GTK_BOX (view->details->news_icon_container), view->details->news_icon_widget, 0, 0, 0);
628        gtk_widget_show (view->details->news_icon_widget);
629        gtk_box_pack_start (GTK_BOX (view->details->service_news_row), view->details->news_icon_container, FALSE, FALSE, 3);
630       
631        /* generate second box with bold type date and the actual contents */
632        item_box = gtk_vbox_new (FALSE, 0);
633        gtk_widget_show (item_box);
634       
635        view->details->news_date_widget = 
636                eazel_services_label_new (view->details->news_date,
637                                          0,
638                                          0,
639                                          0.5,
640                                          0,
641                                          0,
642                                          DEFAULT_SUMMARY_TEXT_COLOR_RGB,
643                                          DEFAULT_SUMMARY_BACKGROUND_COLOR_RGB,
644                                          NULL,
645                                          SUMMARY_TEXT_BODY_SIZE_REL,
646                                          TRUE);
647
648        nautilus_label_set_justify (NAUTILUS_LABEL (view->details->news_date_widget), GTK_JUSTIFY_LEFT);
649
650        gtk_box_pack_start (GTK_BOX (item_box), view->details->news_date_widget, FALSE, FALSE, 2);
651        gtk_box_pack_start (GTK_BOX (view->details->service_news_row), item_box, TRUE, TRUE, 2);
652        gtk_widget_show (view->details->news_date_widget);
653       
654        g_free (view->details->news_date);
655        view->details->news_date = NULL;
656       
657        /* Generate the actual content */
658        view->details->news_description_body_widget = 
659                eazel_services_label_new (view->details->news_description_body,
660                                          0,
661                                          0,
662                                          0.5,
663                                          0,
664                                          0,
665                                          DEFAULT_SUMMARY_TEXT_COLOR_RGB,
666                                          DEFAULT_SUMMARY_BACKGROUND_COLOR_RGB,
667                                          NULL,
668                                          SUMMARY_TEXT_BODY_SIZE_REL,
669                                          FALSE);
670
671        nautilus_label_set_wrap (NAUTILUS_LABEL (view->details->news_description_body_widget), TRUE);
672        nautilus_label_set_justify (NAUTILUS_LABEL (view->details->news_description_body_widget), GTK_JUSTIFY_LEFT);
673        /*
674        nautilus_label_set_wrap_width (NAUTILUS_LABEL (view->details->news_description_body_widget), -1);
675        */
676       
677        gtk_box_pack_start (GTK_BOX (item_box), view->details->news_description_body_widget, TRUE, TRUE, 2);
678
679#if 0
680        /* FIXME see above */
681        gtk_signal_connect (GTK_OBJECT (view->details->service_news_row), "size-allocate", text_resize_callback, view->details->news_description_body_widget);
682#endif
683
684        gtk_widget_show (view->details->news_description_body_widget);
685       
686        g_free (view->details->news_description_body);
687        view->details->news_description_body = NULL;
688
689}
690
691static void
692generate_update_news_entry_row  (NautilusSummaryView    *view, int      row)
693{
694        GtkWidget                       *temp_vbox;
695        GtkWidget                       *temp_hbox;
696        ServicesButtonCallbackData      *cbdata;
697        ServicesButtonCallbackData      *cbdata_2;
698
699        cbdata = g_new0 (ServicesButtonCallbackData, 1);
700        cbdata_2 = g_new0 (ServicesButtonCallbackData, 1);
701
702        /* Generate first box with icon */
703        view->details->update_icon_container = gtk_vbox_new (FALSE, 4);
704        gtk_widget_show (view->details->update_icon_container);
705        view->details->update_icon_widget = 
706                eazel_services_image_new_from_uri (view->details->update_icon_name,
707                                                   NULL,
708                                                   DEFAULT_SUMMARY_BACKGROUND_COLOR_RGB,
709                                                   MAX_IMAGE_WIDTH,
710                                                   MAX_IMAGE_HEIGHT);
711        g_assert (view->details->update_icon_widget != NULL);
712        gtk_box_pack_start (GTK_BOX (view->details->update_icon_container), view->details->update_icon_widget, FALSE, FALSE, 0);
713        gtk_box_pack_start (GTK_BOX (view->details->updates_row), view->details->update_icon_container, FALSE, FALSE, 0);
714        gtk_widget_show (view->details->update_icon_widget);
715
716        /* Generate second box with update title, summary, and version */
717        temp_vbox = gtk_vbox_new (FALSE, 0);
718        gtk_widget_show (temp_vbox);
719       
720        /* Header */
721        temp_hbox = gtk_hbox_new (FALSE, 4);
722        gtk_widget_show (temp_hbox);
723        view->details->update_description_header_widget = 
724                eazel_services_label_new (view->details->update_description_header,
725                                          0,
726                                          0.5,
727                                          0.5,
728                                          0,
729                                          0,
730                                          DEFAULT_SUMMARY_TEXT_COLOR_RGB,
731                                          DEFAULT_SUMMARY_BACKGROUND_COLOR_RGB,
732                                          NULL,
733                                          SUMMARY_TEXT_BODY_SIZE_REL,
734                                          TRUE);
735
736        gtk_widget_show (view->details->update_description_header_widget);
737        g_free (view->details->update_description_header);
738        view->details->update_description_header = NULL;
739        gtk_box_pack_start (GTK_BOX (temp_hbox), view->details->update_description_header_widget, FALSE, FALSE, 4);     
740        gtk_box_pack_start (GTK_BOX (temp_vbox), temp_hbox, FALSE, FALSE, 4);
741       
742        /* Body */
743        temp_hbox = gtk_hbox_new (FALSE, 6);
744        gtk_widget_show (temp_hbox);
745        view->details->update_description_body_widget = 
746                eazel_services_label_new (view->details->update_description_body,
747                                          0,
748                                          0.5,
749                                          0.5,
750                                          0,
751                                          0,
752                                          DEFAULT_SUMMARY_TEXT_COLOR_RGB,
753                                          DEFAULT_SUMMARY_BACKGROUND_COLOR_RGB,
754                                          NULL,
755                                          SUMMARY_TEXT_BODY_SIZE_REL,
756                                          FALSE);
757       
758        nautilus_label_set_wrap (NAUTILUS_LABEL (view->details->update_description_body_widget), TRUE);
759        nautilus_label_set_justify (NAUTILUS_LABEL (view->details->update_description_body_widget), GTK_JUSTIFY_LEFT);
760        gtk_widget_show (view->details->update_description_body_widget);
761
762        g_free (view->details->update_description_body);
763        view->details->update_description_body = NULL;
764        gtk_box_pack_start (GTK_BOX (temp_hbox), view->details->update_description_body_widget, FALSE, FALSE, 6);
765        gtk_box_pack_start (GTK_BOX (temp_vbox), temp_hbox, FALSE, FALSE, 4);
766       
767        /* Version */
768        temp_hbox = gtk_hbox_new (FALSE, 4);
769        gtk_widget_show (temp_hbox);
770        view->details->update_description_version_widget = 
771                eazel_services_label_new (view->details->update_description_version,
772                                          0,
773                                          0.5,
774                                          0.5,
775                                          0,
776                                          0,
777                                          DEFAULT_SUMMARY_TEXT_COLOR_RGB,
778                                          DEFAULT_SUMMARY_BACKGROUND_COLOR_RGB,
779                                          NULL,
780                                          SUMMARY_TEXT_BODY_SIZE_REL,
781                                          TRUE);
782
783        gtk_widget_show (view->details->update_description_version_widget);
784        g_free (view->details->update_description_version);
785        view->details->update_description_version = NULL;
786       
787        gtk_box_pack_start (GTK_BOX (temp_hbox), view->details->update_description_version_widget, FALSE, FALSE, 1);
788        gtk_box_pack_start (GTK_BOX (temp_vbox), temp_hbox, FALSE, FALSE, 0);
789
790        gtk_box_pack_start (GTK_BOX (view->details->updates_row), temp_vbox, FALSE, FALSE, 0);
791
792        /* Add the redirect button and softcat button to the third box */
793        temp_vbox = gtk_vbox_new (FALSE, 0);
794        gtk_widget_show (temp_vbox);
795
796        view->details->update_button_container = gtk_hbox_new (TRUE, 0);
797        gtk_widget_show (view->details->update_button_container);
798        view->details->update_softcat_goto_button = gtk_button_new ();
799        gtk_widget_show (view->details->update_softcat_goto_button);
800        gtk_widget_set_usize (view->details->update_softcat_goto_button, 80, -1);
801       
802        view->details->update_softcat_goto_label_widget = gtk_label_new (view->details->update_softcat_goto_label);
803       
804        gtk_widget_show (view->details->update_softcat_goto_label_widget);
805        g_free (view->details->update_softcat_goto_label);
806        view->details->update_softcat_goto_label = NULL;
807
808        gtk_container_add (GTK_CONTAINER (view->details->update_softcat_goto_button), view->details->update_softcat_goto_label_widget);
809        gtk_box_pack_start (GTK_BOX (view->details->update_button_container), view->details->update_softcat_goto_button, FALSE, FALSE, 4);
810        cbdata->nautilus_view = view->details->nautilus_view;
811        cbdata->uri = view->details->update_softcat_redirects[view->details->current_update_row - 1];
812        gtk_signal_connect (GTK_OBJECT (view->details->update_softcat_goto_button), "clicked", GTK_SIGNAL_FUNC (goto_update_cb), cbdata);
813        gtk_box_pack_start (GTK_BOX (temp_vbox), view->details->update_button_container, FALSE, FALSE, 4);
814
815        view->details->update_button_container = gtk_hbox_new (TRUE, 0);
816        gtk_widget_show (view->details->update_button_container);
817        view->details->update_goto_button = gtk_button_new ();
818        gtk_widget_show (view->details->update_goto_button);
819        gtk_widget_set_usize (view->details->update_goto_button, 80, -1);
820        view->details->update_goto_label_widget = gtk_label_new (view->details->update_goto_label);
821        gtk_widget_show (view->details->update_goto_label_widget);
822        g_free (view->details->update_goto_label);
823        view->details->update_goto_label = NULL;
824       
825        gtk_container_add (GTK_CONTAINER (view->details->update_goto_button), view->details->update_goto_label_widget);
826        gtk_box_pack_start (GTK_BOX (view->details->update_button_container), view->details->update_goto_button, FALSE, FALSE,  4);
827        cbdata_2->nautilus_view = view->details->nautilus_view;
828        cbdata_2->uri = view->details->update_redirects[view->details->current_update_row - 1];
829        gtk_signal_connect (GTK_OBJECT (view->details->update_goto_button), "clicked", GTK_SIGNAL_FUNC (goto_update_cb), cbdata_2);
830        gtk_box_pack_start (GTK_BOX (temp_vbox), view->details->update_button_container, FALSE, FALSE, 4);
831
832        gtk_box_pack_end (GTK_BOX (view->details->updates_row), temp_vbox, FALSE, FALSE, 0);
833
834}
835
836/* callback to handle the goto a service button. */
837static void
838goto_service_cb (GtkWidget      *button, ServicesButtonCallbackData     *cbdata)
839{
840       
841        nautilus_view_open_location_in_this_window (cbdata->nautilus_view, cbdata->uri);
842
843}
844
845/* callback to handle update buttons. */
846static void
847goto_update_cb (GtkWidget      *button, ServicesButtonCallbackData      *cbdata)
848{
849       
850        nautilus_view_open_location_in_this_window (cbdata->nautilus_view, cbdata->uri);
851
852}
853
854static void
855nautilus_summary_view_initialize_class (NautilusSummaryViewClass *klass)
856{
857
858        GtkObjectClass  *object_class;
859        GtkWidgetClass  *widget_class;
860       
861        object_class = GTK_OBJECT_CLASS (klass);
862        widget_class = GTK_WIDGET_CLASS (klass);
863        parent_class = gtk_type_class (gtk_event_box_get_type ());
864        object_class->destroy = nautilus_summary_view_destroy;
865
866}
867
868static void
869nautilus_summary_view_initialize (NautilusSummaryView *view)
870{
871        CORBA_Environment ev;
872
873        CORBA_exception_init (&ev);
874       
875        view->details = g_new0 (NautilusSummaryViewDetails, 1);
876        view->details->nautilus_view = nautilus_view_new (GTK_WIDGET (view));
877        gtk_signal_connect (GTK_OBJECT (view->details->nautilus_view), 
878                            "load_location",
879                            GTK_SIGNAL_FUNC (summary_load_location_callback), 
880                            view);
881
882        view->details->user_control = ammonite_get_user_control();
883
884        if ( CORBA_NO_EXCEPTION != ev._major ) {
885                /* FIXME bugzilla.eazel.com 2740: user should be warned that Ammonite may not be installed */
886                g_warning ("Couldn't instantiate eazel-proxy\n");
887                view->details->user_control = CORBA_OBJECT_NIL;
888        }
889
890        /* get notified when we are activated so we can merge in our menu items */
891        gtk_signal_connect (GTK_OBJECT (nautilus_view_get_bonobo_control
892                                        (view->details->nautilus_view)),
893                            "activate",
894                            merge_bonobo_menu_items,
895                            view);
896
897        gtk_widget_show (GTK_WIDGET (view));
898
899        CORBA_exception_free (&ev);
900
901}
902
903static void
904nautilus_summary_view_destroy (GtkObject *object)
905{
906
907        NautilusSummaryView     *view;
908        CORBA_Environment ev;
909
910        CORBA_exception_init (&ev);
911
912        view = NAUTILUS_SUMMARY_VIEW (object);
913
914        if (view->details->uri) {
915                g_free (view->details->uri);
916        }
917
918        g_assert (Pending_None == view->details->pending_operation);
919
920        g_free (view->details);
921       
922        NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
923
924        CORBA_exception_free (&ev);
925
926}
927
928NautilusView *
929nautilus_summary_view_get_nautilus_view (NautilusSummaryView *view)
930{
931
932        return view->details->nautilus_view;
933
934}
935
936void
937nautilus_summary_view_load_uri (NautilusSummaryView     *view,
938                                const char              *uri)
939{
940        char            *url;
941        char            *user_name;
942        gboolean        got_url_table;
943
944        url = NULL;
945
946        /* set up some sanity values for error control */
947        view->details->attempt_number = 0;
948        view->details->current_attempt = initial;
949
950        /* dispose of any old uri and copy in the new one */   
951        g_free (view->details->uri);
952        view->details->uri = g_strdup (uri);
953
954        /* get xml data and verify network connections */
955#ifdef DEBUG_pepper
956        g_print ("start load\n");
957#endif
958
959        user_name = ammonite_get_default_user_username (view->details->user_control);
960        view->details->logged_in = (NULL != user_name);
961        g_free (user_name);
962        user_name = NULL;
963
964#ifdef DEBUG_pepper
965        g_print ("start xml table fetch\n");
966#endif
967        got_url_table = trilobite_redirect_fetch_table
968                (view->details->logged_in
969                 ? URL_REDIRECT_TABLE_HOME_2
970                 : URL_REDIRECT_TABLE_HOME);
971
972        if (!got_url_table) {
973                /* FIXME bugzilla.eazel.com 3743:
974                 * We should do more to figure out why this failed so we can
975                 * present a much more helpful message. There are several different
976                 * reasons why it might have failed.
977                 */
978                generate_error_dialog
979                        (view, _("Unable to connect to Eazel's server. "
980                                 "The server might be unavailable right now, "
981                                 "or your computer might be configured incorrectly."
982                                 "You could try again later."));
983        } else {
984#ifdef DEBUG_pepper
985                g_print ("end xml table fetch\n");
986                /* fetch and parse the xml file */
987                g_print ("start xml config fetch\n");
988#endif
989                url = trilobite_redirect_lookup (SUMMARY_XML_KEY);
990                if (!url) {
991                        g_assert ("Failed to get summary xml home !\n");
992                }
993                view->details->xml_data = parse_summary_xml_file (url);
994                g_free (url);
995                if (view->details->xml_data == NULL) {
996                        generate_error_dialog
997                                (view, _("Found problem with data on Eazel servers. "
998                                         "Please contact support@eazel.com."));
999                } else {
1000#ifdef DEBUG_pepper
1001                        g_print ("end xml config fetch\n");
1002                        g_print ("start summary draw\n");
1003#endif
1004                        generate_summary_form (view);           
1005#ifdef DEBUG_pepper
1006                        g_print ("end summary draw\n");
1007#endif
1008                        if (!view->details->logged_in) {
1009                                generate_login_dialog (view);
1010                        }
1011                }
1012        }
1013}
1014
1015static void
1016summary_load_location_callback (NautilusView            *nautilus_view, 
1017                                const char              *location,
1018                                NautilusSummaryView     *view)
1019{
1020       
1021        g_assert (nautilus_view == view->details->nautilus_view);
1022       
1023        nautilus_view_report_load_underway (nautilus_view);
1024
1025        nautilus_view_set_title (nautilus_view, "Eazel Services");
1026       
1027        nautilus_summary_view_load_uri (view, location);
1028
1029        nautilus_view_report_load_complete (nautilus_view);
1030
1031}
1032
Note: See TracBrowser for help on using the browser.