r3433 - in trunk/src/target/OM-2007.2/applications/openmoko-appmanager2: . src
thomas at sita.openmoko.org
thomas at sita.openmoko.org
Fri Nov 16 17:54:47 CET 2007
Author: thomas
Date: 2007-11-16 17:54:45 +0100 (Fri, 16 Nov 2007)
New Revision: 3433
Modified:
trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/ChangeLog
trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/ipkg-utils.c
trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/ipkg-utils.h
trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/ipkgapi.c
trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/tool-box.c
Log:
* src/ipkg-utils.c: (update_package_list):
* src/ipkg-utils.h:
* src/ipkgapi.c: (def_ipkg_message_callback):
* src/tool-box.c:
Add check for upgradeable packages
Modified: trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/ChangeLog
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/ChangeLog 2007-11-16 14:43:44 UTC (rev 3432)
+++ trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/ChangeLog 2007-11-16 16:54:45 UTC (rev 3433)
@@ -1,5 +1,14 @@
2007-11-16 Thomas Wood <thomas at openedhand.com>
+ * src/ipkg-utils.c: (update_package_list):
+ * src/ipkg-utils.h:
+ * src/ipkgapi.c: (def_ipkg_message_callback):
+ * src/tool-box.c:
+
+ Add check for upgradeable packages
+
+2007-11-16 Thomas Wood <thomas at openedhand.com>
+
* data/openmoko-appmanager.desktop: Update application name and summary
2007-11-16 Thomas Wood <thomas at openedhand.com>
Modified: trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/ipkg-utils.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/ipkg-utils.c 2007-11-16 14:43:44 UTC (rev 3432)
+++ trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/ipkg-utils.c 2007-11-16 16:54:45 UTC (rev 3433)
@@ -29,6 +29,8 @@
gboolean remove; /* true if we want to remove the package */
} ThreadData;
+static int verrevcmp(const char *val, const char *ref);
+
static gpointer
install_thread_func (ThreadData *data)
{
@@ -168,3 +170,103 @@
gtk_dialog_run (GTK_DIALOG (dlg));
gtk_widget_destroy (dlg);
}
+
+gboolean
+check_for_upgrade (IPK_PACKAGE *package, PKG_LIST_HEAD *list)
+{
+ IPK_PACKAGE *p;
+
+ p = list->pkg_list;
+
+ while (p)
+ {
+ if (g_str_equal (package->name, p->name))
+ {
+ gint ret;
+
+ ret = verrevcmp (package->version, p->version);
+
+ if (ret > 0)
+ return TRUE;
+ else
+ return FALSE;
+ }
+ p = p->next;
+ }
+ return FALSE;
+}
+
+GList *
+get_upgrade_list ()
+{
+ /* find duplicate package names in the available packages list and compare versions */
+ IPK_PACKAGE *p;
+ PKG_LIST_HEAD list;
+ GList *upgradelist = NULL;
+ gint ret;
+
+ ret = ipkg_list_available_cmd (&list);
+
+ p = list.pkg_list;
+ while (p)
+ {
+ if (check_for_upgrade (p, &list))
+ {
+ upgradelist = g_list_prepend (upgradelist, p);
+ g_debug ("Found upgradeable package: %p", p->name);
+ }
+ p = p->next;
+ }
+ return upgradelist;
+}
+
+/*
+ * @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;
+ }
+}
Modified: trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/ipkg-utils.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/ipkg-utils.h 2007-11-16 14:43:44 UTC (rev 3432)
+++ trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/ipkg-utils.h 2007-11-16 16:54:45 UTC (rev 3433)
@@ -22,5 +22,6 @@
void install_package (ApplicationManagerData *data, gchar *name);
void remove_package (ApplicationManagerData *data, gchar *name);
void update_package_list (ApplicationManagerData *data);
+GList * get_upgrade_list ();
#endif /* IPKG_UTILS_H */
Modified: trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/ipkgapi.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/ipkgapi.c 2007-11-16 14:43:44 UTC (rev 3432)
+++ trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/ipkgapi.c 2007-11-16 16:54:45 UTC (rev 3433)
@@ -101,7 +101,8 @@
DBG(msg);
strcat(errMsg, msg);
} else {
- DBG(msg);
+ DBG(msg);
+ printf ("IPKG <%d>: %s", level, msg);
}
return 0;
}
Modified: trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/tool-box.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/tool-box.c 2007-11-16 14:43:44 UTC (rev 3432)
+++ trunk/src/target/OM-2007.2/applications/openmoko-appmanager2/src/tool-box.c 2007-11-16 16:54:45 UTC (rev 3433)
@@ -32,7 +32,26 @@
void
on_upgrade_clicked (GtkButton *bupgrade, gpointer data)
{
+ GList *list;
+ int upgrades;
+
update_package_list (data);
+
+ list = get_upgrade_list ();
+
+ if ((upgrades = g_list_length (list)) > 0)
+ {
+ GtkWidget *dlg;
+
+ dlg = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_YES_NO,
+ "There are %d updates available. Would you like to install them now?",
+ upgrades);
+ gtk_dialog_run (GTK_DIALOG (dlg));
+ gtk_widget_destroy (dlg);
+ }
+
+ g_list_free (list);
+
/*
GtkWidget *dialog;
More information about the commitlog
mailing list