[maemo-commits] [maemo-commits] r13444 - in projects/haf/trunk/hildon-desktop: . data libhildondesktop src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Wed Aug 29 10:57:05 EEST 2007
Author: jobi
Date: 2007-08-29 10:57:03 +0300 (Wed, 29 Aug 2007)
New Revision: 13444

Modified:
   projects/haf/trunk/hildon-desktop/ChangeLog
   projects/haf/trunk/hildon-desktop/data/applications.menu
   projects/haf/trunk/hildon-desktop/libhildondesktop/libhildonmenu.c
   projects/haf/trunk/hildon-desktop/libhildondesktop/libhildonmenu.h
   projects/haf/trunk/hildon-desktop/src/hd-applications-menu.c
Log:

2007-08-29  Johan Bilien  <johan.bilien at nokia.com>

	* libhildondesktop/libhildonmenu.c:
	- use "<All/>" to mark the default folder
	- do not create Extras if no unallocated items
	* src/hd-applications-menu.c: added safegard against
	destroying NULL window
	* data/applications.menu: mark the Extras menu as being the default.
	Fixes: NB#63084



Modified: projects/haf/trunk/hildon-desktop/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-desktop/ChangeLog	2007-08-28 14:49:48 UTC (rev 13443)
+++ projects/haf/trunk/hildon-desktop/ChangeLog	2007-08-29 07:57:03 UTC (rev 13444)
@@ -1,3 +1,13 @@
+2007-08-29  Johan Bilien  <johan.bilien at nokia.com>
+
+	* libhildondesktop/libhildonmenu.c:
+	- use "<All/>" to mark the default folder
+	- do not create Extras if no unallocated items
+	* src/hd-applications-menu.c: added safegard against
+	destroying NULL window
+	* data/applications.menu: mark the Extras menu as being the default.
+	Fixes: NB#63084
+
 2007-08-28  Johan Bilien  <johan.bilien at nokia.com>
 
 	* src/hd-desktop.c:

Modified: projects/haf/trunk/hildon-desktop/data/applications.menu
===================================================================
--- projects/haf/trunk/hildon-desktop/data/applications.menu	2007-08-28 14:49:48 UTC (rev 13443)
+++ projects/haf/trunk/hildon-desktop/data/applications.menu	2007-08-29 07:57:03 UTC (rev 13444)
@@ -72,6 +72,7 @@
   // Extras submenu 
   <Menu>
     <Name>tana_fi_extras</Name>
+    <All/>
     <Include>
       <Filename>chess_startup.desktop</Filename>
       <Filename>maemoblocks.desktop</Filename>

Modified: projects/haf/trunk/hildon-desktop/libhildondesktop/libhildonmenu.c
===================================================================
--- projects/haf/trunk/hildon-desktop/libhildondesktop/libhildonmenu.c	2007-08-28 14:49:48 UTC (rev 13443)
+++ projects/haf/trunk/hildon-desktop/libhildondesktop/libhildonmenu.c	2007-08-29 07:57:03 UTC (rev 13444)
@@ -527,6 +527,8 @@
                        item->text_domain,
                        TREE_MODEL_COMMENT,
                        item->comment,
+                       TREE_MODEL_DEFAULT,
+                       FALSE,
                        -1);
 
     if ( app_icon ){
@@ -671,14 +673,20 @@
 					"",
 					TREE_MODEL_COMMENT,
 					"",
+                                        TREE_MODEL_DEFAULT,
+                                        FALSE,
 					-1);
 
-			if ( strcmp((const char *) key, EXTRAS_MENU_STRING ) == 0 ) {
-				extras_iter = *iterator;
-			}
-
 			xmlFree(key);
 
+                } else if (strcmp((char *)current_element->name, "All") == 0) {
+
+                        extras_iter = *iterator;
+                        gtk_tree_store_set (menu_tree, iterator,
+                                            TREE_MODEL_DEFAULT,
+                                            TRUE,
+                                            -1);
+
 		} else if (strcmp((const char *) current_element->name, "MergeFile") == 0) {
 
 			/* FIXME: skip this for now */
@@ -729,6 +737,7 @@
                                         add_desktop_entry(item, menu_tree, iterator);
                                         xmlFree(key);
                                 }
+                                                            
                                 else if (strcmp((char *)child_element->name, "And") == 0) {
                                   xmlNodePtr cat_element = NULL;
                                   GSList *items, *i;
@@ -795,6 +804,8 @@
 					SEPARATOR_STRING,
 					TREE_MODEL_COMMENT,
 					SEPARATOR_STRING,
+                                        TREE_MODEL_DEFAULT,
+                                        FALSE,
 					-1);
 		}
 
@@ -806,38 +817,6 @@
             /* The doc handle was created in this call */
             xmlFreeDoc(doc);
 
-
-            /* Create the extras menu if it does not exist */
-            if ( !gtk_tree_store_iter_is_valid(menu_tree, &extras_iter ) ) {
-
-                gtk_tree_store_append( menu_tree,
-                                       &extras_iter,
-                                       NULL );
-
-                gtk_tree_store_set(menu_tree,
-                                   &extras_iter,
-                                   TREE_MODEL_NAME,
-                                   EXTRAS_MENU_STRING,
-                                   TREE_MODEL_LOCALIZED_NAME,
-                                   dgettext (GETTEXT_PACKAGE,
-                                             EXTRAS_MENU_STRING),
-                                   TREE_MODEL_ICON,
-                                   folder_icon,
-                                   TREE_MODEL_THUMB_ICON,
-                                   folder_thumb_icon,
-                                   TREE_MODEL_EMBLEM_EXPANDER_OPEN,
-                                   folder_open_icon,
-                                   TREE_MODEL_EMBLEM_EXPANDER_CLOSED,
-                                   folder_closed_icon,
-                                   TREE_MODEL_EXEC,
-                                   "",
-                                   TREE_MODEL_SERVICE,
-                                   "",
-                                   TREE_MODEL_DESKTOP_ID,
-                                   "",
-                                   -1 );
-            }
-
             l = desktop_files;
             while ( l ) {
                 desktop_entry_t *item;
@@ -845,27 +824,65 @@
                 item = l->data;
 
                 if ( item->allocated == FALSE ) {
+                        /* Create the extras menu if it does not exist */
+                        if ( !gtk_tree_store_iter_is_valid(menu_tree, &extras_iter ) ) {
+
+                                gtk_tree_store_append( menu_tree,
+                                                       &extras_iter,
+                                                       NULL );
+
+                                gtk_tree_store_set(menu_tree,
+                                                   &extras_iter,
+                                                   TREE_MODEL_NAME,
+                                                   EXTRAS_MENU_STRING,
+                                                   TREE_MODEL_LOCALIZED_NAME,
+                                                   dgettext (GETTEXT_PACKAGE,
+                                                             EXTRAS_MENU_STRING),
+                                                   TREE_MODEL_ICON,
+                                                   folder_icon,
+                                                   TREE_MODEL_THUMB_ICON,
+                                                   folder_thumb_icon,
+                                                   TREE_MODEL_EMBLEM_EXPANDER_OPEN,
+                                                   folder_open_icon,
+                                                   TREE_MODEL_EMBLEM_EXPANDER_CLOSED,
+                                                   folder_closed_icon,
+                                                   TREE_MODEL_EXEC,
+                                                   "",
+                                                   TREE_MODEL_SERVICE,
+                                                   "",
+                                                   TREE_MODEL_DESKTOP_ID,
+                                                   "",
+                                                   TREE_MODEL_DEFAULT,
+                                                   TRUE,
+                                                   -1 );
+                        }
+
                         add_desktop_entry( item, menu_tree, &extras_iter );
                 }
 
                 l = l->next;
             }
-        }
 
-        /* We don't need our reference to the folder icon pixbuf anymore */
-        if ( folder_icon ) {
-          g_object_unref( G_OBJECT( folder_icon ) );
-          folder_icon = NULL;
-        }
+            /* We don't need our reference to the folder icon pixbuf anymore */
+            if ( folder_icon ) {
+            g_object_unref( G_OBJECT( folder_icon ) );
+            folder_icon = NULL;
+            }
 
-        if ( folder_open_icon ) {
-          g_object_unref( G_OBJECT( folder_open_icon ) );
-          folder_open_icon = NULL;
-        }
+            if ( folder_thumb_icon ) {
+            g_object_unref( G_OBJECT( folder_thumb_icon ) );
+            folder_thumb_icon = NULL;
+            }
 
-        if ( folder_closed_icon ) {
-          g_object_unref( G_OBJECT( folder_closed_icon ) );
-          folder_closed_icon = NULL;
+            if ( folder_open_icon ) {
+            g_object_unref( G_OBJECT( folder_open_icon ) );
+            folder_open_icon = NULL;
+            }
+
+            if ( folder_closed_icon ) {
+            g_object_unref( G_OBJECT( folder_closed_icon ) );
+            folder_closed_icon = NULL;
+            }
         }
 	return;
 }
@@ -892,7 +909,8 @@
 			G_TYPE_STRING,	   /* Service  */
 			G_TYPE_STRING,	   /* Desktop ID */
 			G_TYPE_STRING,     /* Comment */
-			G_TYPE_STRING	   /* Text domain */
+			G_TYPE_STRING,	   /* Text domain */
+			G_TYPE_BOOLEAN	   /* Default category */
 			);
 
 	/* Get $HOME */
@@ -934,6 +952,8 @@
 	gchar *name = NULL;
 	gchar *desktop_id = NULL;
 
+        gboolean default_category;
+
 	/* Make sure we have a valid iterator */
 	if (!gtk_tree_store_iter_is_valid( menu_tree, iterator) ) {
 		g_warning(  "write_menu_conf: invalid iterator." );
@@ -948,6 +968,8 @@
 				&name,
 				TREE_MODEL_DESKTOP_ID,
 				&desktop_id,
+                                TREE_MODEL_DEFAULT,
+                                &default_category,
 				-1 );
 
 		if ( !desktop_id || strlen( desktop_id ) == 0 ) {
@@ -986,6 +1008,12 @@
 				g_debug( "write_menu_conf: <Name>%s</Name>", name );
 			}
 
+                        if (default_category)
+                        {
+                                g_debug ("%s is default", name);
+                                xmlTextWriterWriteElement( writer, (const xmlChar *) "All", "" );
+                        }
+
 			GtkTreeIter child_iterator;
 
 			/* Has children.. */
@@ -1104,338 +1132,6 @@
 	return return_value;
 }
 
-
-void find_first_and_last_root_level_folders( GtkTreeModel *model,
-		GtkTreePath **first_folder, GtkTreePath **last_folder )
-{
-	g_assert( GTK_IS_TREE_MODEL( model ) );
-
-	if ( first_folder == NULL && last_folder == NULL ) {
-		g_debug( "find_first_and_last_root_level_folders: "
-				"first_folder and last_folder are both "
-				"NULL. Doing nothing." );
-		return;
-	}
-
-	GtkTreeIter top_iter;
-	GtkTreeIter child_iter;
-	GtkTreeIter last_iter;
-
-	if ( !gtk_tree_model_get_iter_first( model, &top_iter ) ) {
-		g_warning( "find_first_and_last_root_level_folders: model is empty." );
-		return;
-	}
-
-	if ( !gtk_tree_model_iter_children( model, &child_iter, &top_iter ) ) {
-		g_warning( "find_first_and_last_root_level_folders: tree is empty." );
-		return;
-	}
-
-
-	/* "Reset" the paths */
-	if ( first_folder != NULL ) {
-		*first_folder = NULL;
-	}
-
-	if ( last_folder != NULL ) {
-		*last_folder = NULL;
-	}
-
-	/* Loop through the children of root level and get the
-	 * paths of first and last folders.
-	 *
-	 * NOTE:
-	 *
-	 * if user gave NULL for **first_folder or **last_folder then
-	 * it will be ignored.
-	 * 
-	 * If there are no folders *first_folder and *last_folder
-	 * will be NULL after the loop finishes.
-	 *
-	 * if there's only one folder *last_folder will be  NULL 
-	 * after the loop finishes. */
-	do {
-        gchar *desktop_id = NULL;
-      
-		gtk_tree_model_get( model, &child_iter,
-				TREE_MODEL_DESKTOP_ID,
-				&desktop_id,
-				-1 );
-
-		/* If it's a folder.. */
-		if ( !desktop_id || strlen( desktop_id ) == 0 ) {
-			/* Get the first folder path */
-			if ( first_folder != NULL && *first_folder == NULL ) {
-				*first_folder = gtk_tree_model_get_path(
-						model, &child_iter );
-			}
-           
-            last_iter = child_iter;
-		}
-
-        g_free( desktop_id );
-	} while ( gtk_tree_model_iter_next( model, &child_iter ) );
-
-    *last_folder = gtk_tree_model_get_path( model, &last_iter );
-}
-
-
-gboolean set_separators( GtkTreeModel *model )
-{
-	g_assert( GTK_IS_TREE_MODEL( model ) );
-
-	GtkTreeIter top_iter;
-	GtkTreeIter child_iter;
-
-	if ( !gtk_tree_model_get_iter_first( model, &top_iter ) ) {
-		g_warning( "set_separators: model is empty." );
-		return FALSE;
-	}
-
-	if ( !gtk_tree_model_iter_children( model, &child_iter, &top_iter ) ) {
-		g_warning( "set_separators: tree is empty." );
-		return FALSE;
-	}
-
-	gchar *name = NULL;
-	gchar *desktop_id = NULL;
-
-
-	/* Value 0 = not set yet
-	 * Value 1 = Application
-	 * Value 2 = Folder
-	 */
-	guint first_item = 0;
-	guint last_item  = 0;
-
-	GtkTreeRowReference *first_separator = NULL;
-	GtkTreeRowReference *last_separator = NULL;
-
-	GtkTreeRowReference *first_folder = NULL;
-	GtkTreeRowReference *last_folder = NULL;
-
-	GtkTreeRowReference *empty_extras_folder = NULL;
-
-	GtkTreePath *path;
-
-	/* Loop through the items on depth 1 (where the separators should be)
-	 * and get GtkTreeRowReferences for separators and first and last 
-	 * folders and also for Extras folder in case it is empty.
-	 *
-	 * After the loop we will add the new separators as necessary 
-	 * and remove the old ones and the empty Extras folder.
-	 *
-	 * We could also just move the separators, but that would require 
-	 * additional checking for the existence of the separators. If a 
-	 * separator is needed and does not exist already we would have to 
-	 * create it anyway.
-	 */
-	do {
-		path = gtk_tree_model_get_path(
-				model, &child_iter );
-
-		gtk_tree_model_get( model, &child_iter,
-				TREE_MODEL_NAME,
-				&name,
-				TREE_MODEL_DESKTOP_ID,
-				&desktop_id,
-				-1 );
-
-		if ( strcmp( name, SEPARATOR_STRING ) == 0 &&
-				strcmp( desktop_id, SEPARATOR_STRING ) == 0 ) {
-
-			if ( first_separator == NULL ) {
-				first_separator = gtk_tree_row_reference_new(
-						model, path );
-				g_debug( "set_separators: found first separator." );
-			} else if ( last_separator == NULL ) {
-				last_separator = gtk_tree_row_reference_new(
-						model, path );
-				g_debug( "set_separators: found last separator." );
-			} else {
-				g_warning( "set_separators: more than two separators." );
-			}
-		} else {
-			if ( !desktop_id || strlen( desktop_id ) == 0 ) {
-				g_debug( "set_separators: "
-						"item is a folder '%s'", name );
-
-				/* Empty Extras -folder is ignored */
-				if ( name && strcmp( name,
-							EXTRAS_MENU_STRING ) == 0 ) {
-					if ( !gtk_tree_model_iter_has_child(
-								model, &child_iter ) ) {
-						empty_extras_folder =
-							gtk_tree_row_reference_new(
-								model, path );
-						g_debug( "set_separators: "
-						            "found empty Extras -folder." );
-						continue;
-					}
-				}
-
-				/* It's a folder */
-				if ( first_item == 0 ) {
-					first_item = 2;
-				}
-
-				/* Get the reference */
-				if ( first_folder == NULL ) {
-					first_folder = gtk_tree_row_reference_new(
-							model, path );
-				}
-
-				/* So far the last item is a folder */
-				last_item = 2;
-
-				/* Update the reference */
-				if ( last_folder != NULL ) {
-					gtk_tree_row_reference_free( last_folder );
-				}
-
-				last_folder = gtk_tree_row_reference_new(
-						model, path );
-			} else {
-				g_debug( "set_separators: "
-						"item is an application '%s'", name );
-
-				/* It's an application */
-				if ( first_item == 0 ) {
-					first_item = 1;
-				}
-
-				/* So far the last item is nn application */
-				last_item = 1;
-			}
-		}
-		if ( name ) {
-			g_free( name );
-			name = NULL;
-		}
-
-		if ( desktop_id ) {
-			g_free( desktop_id );
-			desktop_id = NULL;
-		}
-
-		gtk_tree_path_free( path );
-
-	} while ( gtk_tree_model_iter_next( model, &child_iter ) );
-
-	/* Add the top separator if needed */
-	if ( first_item == 2 ) {
-		g_debug( "set_separators: first item is a folder, no top separator." );
-	} else if ( first_item == 1 ) {
-
-		/* Get the iterators */
-		GtkTreeIter iter;
-		GtkTreeIter sibling;
-
-		GtkTreePath *tmp_path = gtk_tree_row_reference_get_path( first_folder );
-		gtk_tree_model_get_iter( model, &sibling, tmp_path );
-		gtk_tree_path_free( tmp_path );
-
-		/* Add the separator */
-		gtk_tree_store_insert_before( GTK_TREE_STORE( model ),
-				&iter, NULL, &sibling );
-
-		gtk_tree_store_set( GTK_TREE_STORE( model ), &iter,
-				TREE_MODEL_NAME,
-				SEPARATOR_STRING,
-				TREE_MODEL_ICON,
-				NULL,
-				TREE_MODEL_EMBLEM_EXPANDER_OPEN,
-				NULL,
-				TREE_MODEL_EMBLEM_EXPANDER_CLOSED,
-				NULL,
-				TREE_MODEL_EXEC,
-				SEPARATOR_STRING,
-				TREE_MODEL_SERVICE,
-				SEPARATOR_STRING,
-				TREE_MODEL_DESKTOP_ID,
-				SEPARATOR_STRING, -1 );
-
-		g_debug( "set_separators: first item is an app, top separator added." );
-	} else {
-		g_debug( "set_separators: menu is empty?" );
-	}
-
-	/* Add the nottom separator if needed */
-	if ( last_item == 2 ) {
-		g_debug( "set_separators: last item is a folder, no bottom separator." );
-	} else if ( last_item == 1 ) {
-		/* Get the iterators */
-		GtkTreeIter iter;
-		GtkTreeIter sibling;
-
-		GtkTreePath *tmp_path = gtk_tree_row_reference_get_path( last_folder );
-		gtk_tree_model_get_iter( model, &sibling, tmp_path );
-		gtk_tree_path_free( tmp_path );
-
-		/* Add the separator */
-		gtk_tree_store_insert_after( GTK_TREE_STORE( model ),
-				&iter, NULL, &sibling );
-
-		gtk_tree_store_set( GTK_TREE_STORE( model ), &iter,
-				TREE_MODEL_NAME,
-				SEPARATOR_STRING,
-				TREE_MODEL_ICON,
-				NULL,
-				TREE_MODEL_EMBLEM_EXPANDER_OPEN,
-				NULL,
-				TREE_MODEL_EMBLEM_EXPANDER_CLOSED,
-				NULL,
-				TREE_MODEL_EXEC,
-				SEPARATOR_STRING,
-				TREE_MODEL_SERVICE,
-				SEPARATOR_STRING,
-				TREE_MODEL_DESKTOP_ID,
-				SEPARATOR_STRING, -1 );
-
-		g_debug( "set_separators: last item is an app, bottom separator added." );
-	} else {
-		g_debug( "set_separators: menu is empty?" );
-	}
-
-	/* Remove the original separators */
-	if ( first_separator != NULL ) {
-		GtkTreePath *tmp_path =
-			gtk_tree_row_reference_get_path( first_separator );
-		GtkTreeIter tmp_iter;
-		gtk_tree_model_get_iter( model, &tmp_iter, tmp_path );
-		gtk_tree_store_remove( GTK_TREE_STORE( model ), &tmp_iter );
-		gtk_tree_path_free( tmp_path );
-	}
-
-	if ( last_separator != NULL ) {
-		GtkTreePath *tmp_path =
-			gtk_tree_row_reference_get_path( last_separator );
-		GtkTreeIter tmp_iter;
-		gtk_tree_model_get_iter( model, &tmp_iter, tmp_path );
-		gtk_tree_store_remove( GTK_TREE_STORE( model ), &tmp_iter );
-		gtk_tree_path_free( tmp_path );
-	}
-
-	/* Remove empty Extras folder */
-	if ( empty_extras_folder != NULL ) {
-		GtkTreePath *tmp_path =
-			gtk_tree_row_reference_get_path( empty_extras_folder );
-		GtkTreeIter tmp_iter;
-		gtk_tree_model_get_iter( model, &tmp_iter, tmp_path );
-		gtk_tree_store_remove( GTK_TREE_STORE( model ), &tmp_iter );
-		gtk_tree_path_free( tmp_path );
-	}
-	
-	gtk_tree_row_reference_free( first_separator );
-	gtk_tree_row_reference_free( last_separator );
-	gtk_tree_row_reference_free( first_folder );
-	gtk_tree_row_reference_free( last_folder );
-	gtk_tree_row_reference_free( empty_extras_folder );
-
-	return TRUE;
-}
-
-
 gboolean set_menu_contents( GtkTreeModel *model )
 {
 	g_assert( GTK_IS_TREE_MODEL( model ) );
@@ -1494,6 +1190,8 @@
                goto cleanup_and_exit;
         }
 
+        xmlTextWriterSetIndent( writer, 1 );
+
 	/* End the document */
 	if ( xmlTextWriterEndDocument( writer ) ) {
 		g_warning( "et_menu_contents: failed to end the document." );

Modified: projects/haf/trunk/hildon-desktop/libhildondesktop/libhildonmenu.h
===================================================================
--- projects/haf/trunk/hildon-desktop/libhildondesktop/libhildonmenu.h	2007-08-28 14:49:48 UTC (rev 13443)
+++ projects/haf/trunk/hildon-desktop/libhildondesktop/libhildonmenu.h	2007-08-29 07:57:03 UTC (rev 13444)
@@ -78,6 +78,7 @@
 	TREE_MODEL_DESKTOP_ID,
 	TREE_MODEL_COMMENT,
 	TREE_MODEL_TEXT_DOMAIN,
+	TREE_MODEL_DEFAULT,
 	TREE_MODEL_COLUMNS
 };
 

Modified: projects/haf/trunk/hildon-desktop/src/hd-applications-menu.c
===================================================================
--- projects/haf/trunk/hildon-desktop/src/hd-applications-menu.c	2007-08-28 14:49:48 UTC (rev 13443)
+++ projects/haf/trunk/hildon-desktop/src/hd-applications-menu.c	2007-08-29 07:57:03 UTC (rev 13444)
@@ -1213,7 +1213,8 @@
 
   button->priv->monitor_update_timeout = 0;
 
-  hildon_desktop_popup_window_popdown (button->priv->popup_window);
+  if (button->priv->popup_window)
+    hildon_desktop_popup_window_popdown (button->priv->popup_window);
   
   hd_applications_menu_create_menu (button);
   


More information about the maemo-commits mailing list