r316 - trunk/src/target/OM-2007/applications/openmoko-appmanager/src
caowai_song at gta01.hmw-consulting.de
caowai_song at gta01.hmw-consulting.de
Wed Dec 6 11:04:28 CET 2006
Author: caowai_song
Date: 2006-12-06 10:04:10 +0000 (Wed, 06 Dec 2006)
New Revision: 316
Modified:
trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-data.c
trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-data.h
trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-window.c
trunk/src/target/OM-2007/applications/openmoko-appmanager/src/filter-menu.c
trunk/src/target/OM-2007/applications/openmoko-appmanager/src/package-list.c
trunk/src/target/OM-2007/applications/openmoko-appmanager/src/package-list.h
Log:
Add init package list and build index code
Modified: trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-data.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-data.c 2006-12-06 08:07:34 UTC (rev 315)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-data.c 2006-12-06 10:04:10 UTC (rev 316)
@@ -43,6 +43,7 @@
data->sectionlist = NULL;
data->installedlist = NULL;
data->upgradelist = NULL;
+ data->nosecpkglist = NULL;
data->selectedlist = NULL;
for (i = 0; i < N_COUNT_PKG_STATUS; i++)
@@ -52,33 +53,6 @@
}
-GType
-moko_type_application_manager_data_get_type (void)
-{
- static GType self_type = 0;
-
- if (!self_type)
- {
- static const GTypeInfo self_info =
- {
- sizeof (ApplicationManagerDataClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) application_manager_data_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (ApplicationManagerData),
- 0,
- (GInstanceInitFunc) application_manager_data_init,
- };
-
- // add the type of your parent class here
- self_type = g_type_register_static (G_TYPE_OBJECT, "ApplicationManagerData", &self_info, 0);
- }
-
- return self_type;
-}
-
/**
* @brief Create a new ApplicationManagerData
* @return The ApplicationManagerData. If fail to create, it will return NULL.
@@ -87,7 +61,7 @@
application_manager_data_new (void)
{
return MOKO_APPLICATION_MANAGER_DATA (g_object_new \
- (moko_type_application_manager_data_get_type (), \
+ (MOKO_TYPE_APPLICATION_MANAGER_DATA, \
NULL));
}
@@ -219,6 +193,21 @@
}
/**
+ * @brief Set the header of the package list whose section name is null
+ * to the application manager data
+ * @param appdata The application manager data struct
+ * @param nosecpkglist The header of the selected list
+ */
+void
+application_manager_data_set_nosecpkg_list (ApplicationManagerData *appdata,
+ gpointer nosecpkglist)
+{
+ g_return_if_fail (MOKO_IS_APPLICATION_MANAGER_DATA (appdata));
+
+ appdata->nosecpkglist = nosecpkglist;
+}
+
+/**
* @brief Set the pixbuf to the pixbuf list in the application manager data
* @param appdata The application manager data struct
* @param pixbuf A GdkPixbuf
@@ -419,6 +408,19 @@
}
/**
+ * @brief Get the nosecpkg list from the application manager data
+ * @param appdata The application manager data
+ * @return The selected list
+ */
+gpointer
+application_manager_data_get_nosecpkglist (ApplicationManagerData *appdata)
+{
+ g_return_val_if_fail (MOKO_IS_APPLICATION_MANAGER_DATA (appdata), NULL);
+
+ return appdata->nosecpkglist;
+}
+
+/**
* @brief Get the appointed pixbuf from the application manager data
* @param appdata The application manager data
* @param id The status id
Modified: trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-data.h
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-data.h 2006-12-06 08:07:34 UTC (rev 315)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-data.h 2006-12-06 10:04:10 UTC (rev 316)
@@ -27,7 +27,7 @@
G_BEGIN_DECLS
-#define MOKO_TYPE_APPLICATION_MANAGER_DATA (moko_type_application_manager_data_get_type ())
+#define MOKO_TYPE_APPLICATION_MANAGER_DATA (application_manager_data_get_type ())
#define MOKO_APPLICATION_MANAGER_DATA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
MOKO_TYPE_APPLICATION_MANAGER_DATA, \
ApplicationManagerData))
@@ -63,6 +63,7 @@
gpointer installedlist; ///<! The list of all installed packages
gpointer upgradelist; ///<! The list of all upgradeable packages
gpointer selectedlist; ///<! The list of packages that user selected
+ gpointer nosecpkglist; ///<! The list of packages whose section name is NULL
GdkPixbuf *statuspix[N_COUNT_PKG_STATUS]; ///<! The all pixbufs that need by the package list store
} ApplicationManagerData;
@@ -73,7 +74,7 @@
GObjectClass parent_class; ///<! The parent class
} ApplicationManagerDataClass;
-GType moko_type_application_manager_data_get_type (void);
+GType application_manager_data_get_type (void);
ApplicationManagerData *application_manager_data_new (void);
@@ -105,6 +106,9 @@
void application_manager_data_set_selected_list (ApplicationManagerData *appdata,
gpointer selectedlist);
+void application_manager_data_set_nosecpkg_list (ApplicationManagerData *appdata,
+ gpointer nosecpkglist);
+
void init_pixbuf_list (ApplicationManagerData *appdata);
MokoPanedWindow *
@@ -134,10 +138,14 @@
gpointer
application_manager_data_get_selectedlist (ApplicationManagerData *appdata);
+gpointer
+ application_manager_data_get_nosecpkglist (ApplicationManagerData *appdata);
+
GdkPixbuf *
application_manager_data_get_status_pixbuf (ApplicationManagerData *appdata,
guint id);
+
G_END_DECLS
#endif
Modified: trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-window.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-window.c 2006-12-06 08:07:34 UTC (rev 315)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-window.c 2006-12-06 10:04:10 UTC (rev 316)
@@ -30,7 +30,7 @@
#include "navigation-area.h"
#include "tool-box.h"
#include "detail-area.h"
-//#include "appmanager-data.h"
+#include "appmanager-data.h"
#include "errorcode.h"
#include "package-list.h"
@@ -82,6 +82,7 @@
filtermenu = filter_menu_new (appdata);
moko_paned_window_set_filter_menu (window, filtermenu);
+ application_manager_data_set_filter_menu (appdata, filtermenu);
navigation = navigation_area_new (appdata);
moko_paned_window_set_upper_pane (window, navigation);
@@ -93,14 +94,21 @@
moko_paned_window_set_lower_pane (window, detail);
//Load the list of all package in the memory
- /*
ret = init_package_list (appdata);
if (ret != OP_SUCCESS)
{
g_debug ("Can not initial the libipkg, the result is%d", ret);
return -1;
}
- */
+ ret = package_list_build_index (appdata);
+ if (ret != OP_SUCCESS)
+ {
+ g_debug ("Can not build index for packages");
+ return -1;
+ }
+
+ package_list_add_section_to_filter_menu (appdata);
+
ret = navigation_area_insert_test_data (appdata);
gtk_widget_show_all (GTK_WIDGET (window));
Modified: trunk/src/target/OM-2007/applications/openmoko-appmanager/src/filter-menu.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-appmanager/src/filter-menu.c 2006-12-06 08:07:34 UTC (rev 315)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/filter-menu.c 2006-12-06 10:04:10 UTC (rev 316)
@@ -128,6 +128,7 @@
GtkWidget *dymenuitem;
g_return_if_fail (GTK_IS_MENU (filtermenu));
+ g_debug ("Insert filter menu:%s", name);
dymenuitem = gtk_menu_item_new_with_label (name);
gtk_widget_show (dymenuitem);
Modified: trunk/src/target/OM-2007/applications/openmoko-appmanager/src/package-list.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-appmanager/src/package-list.c 2006-12-06 08:07:34 UTC (rev 315)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/package-list.c 2006-12-06 10:04:10 UTC (rev 316)
@@ -21,6 +21,7 @@
#include "appmanager-data.h"
#include "package-list.h"
#include "ipkgapi.h"
+#include "filter-menu.h"
#include "errorcode.h"
/**
@@ -42,7 +43,60 @@
struct section_list *next; ///<The next section list node
} SectionList;
+static gint package_list_insert_node_without_check (PackageList *pkglist, IPK_PACKAGE *pkg);
+
/**
+ * @brief Version compare
+ *
+ * This function is copy from ipkg.(pkg.c)
+ * The verrevcmp() function compares the two version string "val" and
+ * "ref". It returns an integer less than, equal to, or greater than
+ * zero if "val" is found, respectively, to be less than, to match, or
+ * be greater than "ref".
+ */
+static int
+verrevcmp(const char *val, const char *ref)
+{
+ int vc, rc;
+ long vl, rl;
+ const char *vp, *rp;
+ const char *vsep, *rsep;
+
+ if (!val) val= "";
+ if (!ref) ref= "";
+ for (;;)
+ {
+ vp= val; while (*vp && !isdigit(*vp)) vp++;
+ rp= ref; while (*rp && !isdigit(*rp)) rp++;
+ for (;;)
+ {
+ vc= (val == vp) ? 0 : *val++;
+ rc= (ref == rp) ? 0 : *ref++;
+ if (!rc && !vc) break;
+ if (vc && !isalpha(vc)) vc += 256;
+ if (rc && !isalpha(rc)) rc += 256;
+ if (vc != rc) return vc - rc;
+ }
+ val= vp;
+ ref= rp;
+ vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
+ rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
+ if (vl != rl) return vl - rl;
+
+ vc = *val;
+ rc = *ref;
+ vsep = strchr(".-", vc);
+ rsep = strchr(".-", rc);
+ if (vsep && !rsep) return -1;
+ if (!vsep && rsep) return +1;
+
+ if (!*val && !*ref) return 0;
+ if (!*val) return -1;
+ if (!*ref) return +1;
+ }
+}
+
+/**
* @brief Get the list of all packages from lib ipkg
* @param appdata The application manager data
* @return If success, return OP_SUCCESS, else return error code
@@ -246,6 +300,7 @@
PackageList *installed = NULL;
PackageList *upgrade = NULL;
PackageList *selected = NULL;
+ PackageList *nosecpkg = NULL;
// Get the section list from the application manager data
// If the section list is not NULL, clear it.
@@ -289,10 +344,230 @@
selected = NULL;
application_manager_data_set_upgrade_list (appdata, selected);
}
+
+ // Get the nosecpkg list from the application manager data
+ // If the selected list is not NULL, clear it.
+ nosecpkg = (PackageList *)application_manager_data_get_upgradelist (appdata);
+ if (nosecpkg != NULL)
+ {
+ package_list_free_package_list (nosecpkg);
+ g_free (nosecpkg);
+ nosecpkg = NULL;
+ application_manager_data_set_upgrade_list (appdata, nosecpkg);
+ }
}
+/**
+ * @brief Inist the SectionList struct
+ */
+static void
+section_list_init_node (SectionList *sec)
+{
+ sec->name = NULL;
+ sec->next = NULL;
+ sec->head.pkg = NULL;
+ sec->head.pre = &(sec->head);
+ sec->head.next = &(sec->head);
+}
/**
+ * @brief Init the PackageList struct
+ */
+static void
+package_list_init_node (PackageList *pkg)
+{
+ pkg->pkg = NULL;
+ pkg->pre = pkg;
+ pkg->next = pkg;
+}
+
+/**
+ * @brief Check the packages, if the installed package is upgradeable,
+ * put them to the "upgrade" package list.
+ *
+ * @param pkglist The package list
+ * @param pkg The package node
+ */
+static gint
+check_package_upgradeable (PackageList *pkglist, IPK_PACKAGE *pkg,
+ PackageList *upgrade)
+{
+ IPK_PACKAGE *tmp;
+ gint ret;
+
+ tmp = pkglist->pkg;
+ if (tmp->state_status != SS_INSTALLED)
+ {
+ // If the package in the list is not installed,
+ // check the other one.
+ if (pkg->state_status == SS_INSTALLED)
+ {
+ // If the other one is installed, exchange them
+ pkglist->pkg = pkg;
+ pkg = tmp;
+ tmp = pkglist->pkg;
+ }
+ else
+ {
+ // If the other one is not installed either,
+ // set the package with high version to the list.
+ ret = verrevcmp (tmp->version, pkg->version);
+ if (ret < 0)
+ {
+ pkglist->pkg = pkg;
+ }
+ return OP_SUCCESS;
+ }
+ }
+
+ ret = verrevcmp (tmp->version, pkg->version);
+ if (ret >= 0)
+ {
+ return OP_SUCCESS;
+ }
+
+ tmp->mark = PKG_STATUS_UPGRADEABLE;
+ ret = package_list_insert_node_without_check (upgrade, tmp);
+ if (ret == OP_SUCCESS)
+ {
+ return OP_SUCCESS;
+ }
+
+ return ret;
+}
+
+/**
+ * @brief Insert a package node to the package list without check whether
+ * the package is upgradeable
+ *
+ * @param pkglist The package list
+ * @param pkg The package node
+ * @return The result code
+ */
+static gint
+package_list_insert_node_without_check (PackageList *pkglist, IPK_PACKAGE *pkg)
+{
+ PackageList *tmp;
+ PackageList *ins;
+ gint ret;
+
+ tmp = pkglist->pre;
+
+ while ((tmp != pkglist) && (tmp != NULL))
+ {
+ ret = strcmp (pkg->name, tmp->pkg->name);
+
+ if (ret > 0)
+ {
+ //The name of package is larger then the name of node
+ ins = (PackageList *) g_malloc (sizeof (PackageList));
+ if (ins == NULL)
+ {
+ g_debug ("Can not malloc memory for package node, the package name is:%s", pkg->name);
+ return OP_MAMORY_MALLOC_ERROR;
+ }
+ ins->pkg = pkg;
+ ins->pre = tmp;
+ ins->next = tmp->next;
+
+ tmp->next->pre = ins;
+ tmp->next = ins;
+
+ return OP_SUCCESS;
+ }
+ // FIXME Ignore the names of two packages are equal
+ // At this condition, if there are two packages with the same name,
+ // add every of them to the package list
+
+ //The name of package is small then the name of node, search the pre node.
+ tmp = tmp->pre;
+ }
+
+ ins = (PackageList *) g_malloc (sizeof (PackageList));
+ if (ins == NULL)
+ {
+ g_debug ("Can not malloc memory for package node, the package name is:%s", pkg->name);
+ return OP_MAMORY_MALLOC_ERROR;
+ }
+ ins->pkg = pkg;
+ ins->pre = tmp;
+ ins->next = tmp->next;
+
+ tmp->next->pre = ins;
+ tmp->next = ins;
+
+ return OP_SUCCESS;
+}
+
+/**
+ * @brief Insert a package node to the package list.
+ *
+ * @param pkglist The package list
+ * @param pkg The package node
+ * @param upgrade The package list of upgradeable packages
+ * @return The result code
+ */
+static gint
+package_list_insert_node (PackageList *pkglist, IPK_PACKAGE *pkg, PackageList *upgrade)
+{
+ PackageList *tmp;
+ PackageList *ins;
+ gint ret;
+
+ tmp = pkglist->pre;
+
+ while ((tmp != pkglist) && (tmp != NULL))
+ {
+ ret = strcmp (pkg->name, tmp->pkg->name);
+
+ if (ret > 0)
+ {
+ //The name of package is larger then the name of node
+ ins = (PackageList *) g_malloc (sizeof (PackageList));
+ if (ins == NULL)
+ {
+ g_debug ("Can not malloc memory for package node, the package name is:%s", pkg->name);
+ return OP_MAMORY_MALLOC_ERROR;
+ }
+ ins->pkg = pkg;
+ ins->pre = tmp;
+ ins->next = tmp->next;
+
+ tmp->next->pre = ins;
+ tmp->next = ins;
+
+ return OP_SUCCESS;
+ }
+ else if (ret == 0)
+ {
+ //The name of package is equal to the name of node.
+ //The package maybe an upgradeable package.
+ g_debug ("The package maybe upgradeable. Package name is:%s", pkg->name);
+ g_debug ("The pkg version 1 is:%s, The version 2 is:%s", tmp->pkg->version, pkg->version);
+ return check_package_upgradeable (tmp, pkg, upgrade);
+ }
+
+ //The name of package is small then the name of node, search the pre node.
+ tmp = tmp->pre;
+ }
+
+ ins = (PackageList *) g_malloc (sizeof (PackageList));
+ if (ins == NULL)
+ {
+ g_debug ("Can not malloc memory for package node, the package name is:%s", pkg->name);
+ return OP_MAMORY_MALLOC_ERROR;
+ }
+ ins->pkg = pkg;
+ ins->pre = tmp;
+ ins->next = tmp->next;
+
+ tmp->next->pre = ins;
+ tmp->next = ins;
+
+ return OP_SUCCESS;
+}
+
+/**
* @brief Build a detailed index for the packages list in the application
* manager data
* @param appdata The application manager data
@@ -302,12 +577,17 @@
package_list_build_index (ApplicationManagerData *appdata)
{
PKG_LIST_HEAD *pkglist;
+ IPK_PACKAGE *pkg;
- SectionList *sectionlist = NULL;
- PackageList *installed = NULL;
- PackageList *upgrade = NULL;
- PackageList *selected = NULL;
+ SectionList *sectionlist = NULL;
+ PackageList *installed = NULL;
+ PackageList *upgrade = NULL;
+ PackageList *selected = NULL;
+ PackageList *nosecpkg = NULL;
+ SectionList *tmpsec = NULL;
+ gint ret;
+
// Get the package list from application manager data
pkglist = (PKG_LIST_HEAD *) application_manager_data_get_pkglist (appdata);
if (pkglist == NULL)
@@ -322,36 +602,164 @@
return OP_ERROR;
}
+ // Clear the old data
package_list_clear_old_index (appdata);
+ // Malloc memory for the head
sectionlist = g_malloc (sizeof (SectionList));
if (sectionlist == NULL)
{
g_debug ("Can not malloc memory for the section list");
- return OP_ERROR;
+ return OP_MAMORY_MALLOC_ERROR;
}
installed = g_malloc (sizeof (PackageList));
if (installed == NULL)
{
g_debug ("Can not malloc memory for the package list");
- return OP_ERROR;
+ g_free (sectionlist);
+ return OP_MAMORY_MALLOC_ERROR;
}
upgrade = g_malloc (sizeof (PackageList));
if (upgrade == NULL)
{
g_debug ("Can not malloc memory for the package list");
- return OP_ERROR;
+ g_free (sectionlist);
+ g_free (installed);
+ return OP_MAMORY_MALLOC_ERROR;
}
selected = g_malloc (sizeof (PackageList));
if (selected == NULL)
{
g_debug ("Can not malloc memory for the package list");
- return OP_ERROR;
+ g_free (sectionlist);
+ g_free (installed);
+ g_free (upgrade);
+ return OP_MAMORY_MALLOC_ERROR;
}
+ nosecpkg = g_malloc (sizeof (PackageList));
+ if (nosecpkg == NULL)
+ {
+ g_debug ("Can not malloc memory for the package list");
+ g_free (sectionlist);
+ g_free (installed);
+ g_free (upgrade);
+ g_free (selected);
+ return OP_MAMORY_MALLOC_ERROR;
+ }
+
+ // Init each list
+ g_debug ("Begin init each list");
+
+ section_list_init_node (sectionlist);
+
+ package_list_init_node (installed);
+ package_list_init_node (upgrade);
+ package_list_init_node (selected);
+ package_list_init_node (nosecpkg);
+
+ // Set the header of each list to the application manager data
+ application_manager_data_set_section_list (appdata, sectionlist);
+ application_manager_data_set_installed_list (appdata, installed);
+ application_manager_data_set_upgrade_list (appdata, upgrade);
+ application_manager_data_set_selected_list (appdata, selected);
+ application_manager_data_set_nosecpkg_list (appdata, nosecpkg);
+
+ // Start to build the index for all packages
+ pkg = pkglist->pkg_list;
+
+ while (pkg != NULL)
+ {
+ // Check wheather the package was installed
+ if (pkg->state_status == SS_INSTALLED)
+ {
+ pkg->mark = PKG_STATUS_INSTALLED;
+ ret = package_list_insert_node_without_check (installed, pkg);
+ if (ret != OP_SUCCESS)
+ {
+ return ret;
+ }
+ }
+ else
+ {
+ pkg->mark = PKG_STATUS_AVAILABLE;
+ }
+
+ //Search the section node of package.
+ ret = package_list_search_section_node (pkg->section, &tmpsec, sectionlist);
+ if (ret == OP_SUCCESS)
+ {
+ ret = package_list_insert_node (&(tmpsec->head), pkg, upgrade);
+ if (ret != OP_SUCCESS)
+ {
+ return ret;
+ }
+ }
+ else if (ret == OP_SECTION_NAME_NULL)
+ {
+ ret = package_list_insert_node (nosecpkg, pkg, upgrade);
+ if (ret != OP_SUCCESS)
+ {
+ return ret;
+ }
+ }
+ else
+ {
+ return ret;
+ }
+
+ pkg = pkg->next;
+ }
+
return OP_SUCCESS;
}
+/**
+ * @brief Add the sections to the filter menu
+ *
+ * @param appdata The application manager data
+ */
+void
+package_list_add_section_to_filter_menu (ApplicationManagerData *appdata)
+{
+ SectionList *seclist;
+ SectionList *tmpsec;
+ GtkMenu *filtermenu;
+ PackageList *tmppkg;
+
+ seclist = application_manager_data_get_sectionlist (appdata);
+ if (seclist == NULL)
+ {
+ g_debug ("Section list is empty, not need add anything to filter menu");
+ return;
+ }
+
+ filtermenu = application_manager_get_filter_menu (appdata);
+ if (filtermenu == NULL)
+ {
+ g_debug ("Filter menu not init correctly");
+ return;
+ }
+
+ tmpsec = seclist->next;
+
+ while (tmpsec != NULL)
+ {
+ filter_menu_add_item (filtermenu, tmpsec->name, appdata);
+ tmpsec = tmpsec->next;
+ }
+
+ tmppkg = application_manager_data_get_nosecpkglist (appdata);
+ if (tmppkg == NULL)
+ {
+ return;
+ }
+
+ if (tmppkg->next != tmppkg)
+ {
+ filter_menu_add_item (filtermenu, "no section", appdata);
+ }
+}
Modified: trunk/src/target/OM-2007/applications/openmoko-appmanager/src/package-list.h
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-appmanager/src/package-list.h 2006-12-06 08:07:34 UTC (rev 315)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/package-list.h 2006-12-06 10:04:10 UTC (rev 316)
@@ -24,4 +24,8 @@
gint init_package_list (ApplicationManagerData *appdata);
+gint package_list_build_index (ApplicationManagerData *appdata);
+
+void package_list_add_section_to_filter_menu (ApplicationManagerData *appdata);
+
#endif
More information about the commitlog
mailing list