r474 - in trunk/src/target/OM-2007/applications/openmoko-appmanager: . src
caowai_song at gta01.hmw-consulting.de
caowai_song at gta01.hmw-consulting.de
Thu Dec 28 01:58:34 CET 2006
Author: caowai_song
Date: 2006-12-28 01:56:41 +0100 (Thu, 28 Dec 2006)
New Revision: 474
Modified:
trunk/src/target/OM-2007/applications/openmoko-appmanager/configure.ac
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/install-dialog.c
trunk/src/target/OM-2007/applications/openmoko-appmanager/src/install-dialog.h
trunk/src/target/OM-2007/applications/openmoko-appmanager/src/package-list.c
trunk/src/target/OM-2007/applications/openmoko-appmanager/src/package-list.h
trunk/src/target/OM-2007/applications/openmoko-appmanager/src/tool-box.c
Log:
Create a new thread to install/upgrade/remove the packages
Modified: trunk/src/target/OM-2007/applications/openmoko-appmanager/configure.ac
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-appmanager/configure.ac 2006-12-26 10:16:18 UTC (rev 473)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/configure.ac 2006-12-28 00:56:41 UTC (rev 474)
@@ -15,7 +15,9 @@
AC_MSG_ERROR([*** Required OpenMoko Libraries >= 0.0.1 not installed ***]))
PKG_CHECK_MODULES(LIBIPKG, libipkg,,
exit)
-LIBS="$LIBS $GTK_LIBS $LIBIPKG_LIBS"
+PKG_CHECK_MODULES(GTHREAD, gthread-2.0,,
+ exit)
+LIBS="$LIBS $GTK_LIBS $LIBIPKG_LIBS $GTHREAD_LIBS"
CFLAGS="$CFLAGS $OPENMOKO_CFLAGS $LIBIPKG_CFLAGS -DIPKG_LIB"
# output stuff
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-26 10:16:18 UTC (rev 473)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-data.c 2006-12-28 00:56:41 UTC (rev 474)
@@ -48,6 +48,7 @@
data->nosecpkglist = NULL;
data->currentlist = NULL;
data->selectedlist = NULL;
+ data->installdialog = NULL;
for (i = 0; i < N_COUNT_PKG_STATUS; i++)
{
@@ -285,6 +286,20 @@
}
/**
+ * @brief Set the install dialog to the application manager data
+ * @param appdata The application manager data struct
+ * @param installdialog The install dialog
+ */
+void
+application_manager_data_set_install_dialog (ApplicationManagerData *appdata,
+ GtkWidget *installdialog)
+{
+ g_return_if_fail (MOKO_IS_APPLICATION_MANAGER_DATA (appdata));
+
+ appdata->installdialog = installdialog;
+}
+
+/**
* @brief Init the pixbuf list.
*
* Load all pixbuf from the appointed file, and set the pixbuf to the
@@ -547,3 +562,16 @@
return appdata->searchhistory;
}
+
+/**
+ * @brief Get the install dialog from the application manager data
+ * @param appdata The application manager data
+ * @return The install dialog
+ */
+GtkWidget *
+application_manager_data_get_install_dialog (ApplicationManagerData *appdata)
+{
+ g_return_val_if_fail (MOKO_IS_APPLICATION_MANAGER_DATA (appdata), NULL);
+
+ return appdata->installdialog;
+}
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-26 10:16:18 UTC (rev 473)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/appmanager-data.h 2006-12-28 00:56:41 UTC (rev 474)
@@ -69,6 +69,7 @@
gpointer currentlist; ///<! The current list that display on the navigation list
GdkPixbuf *statuspix[N_COUNT_PKG_STATUS]; ///<! The all pixbufs that need by the package list store
gchar *searchhistory; ///<! The search history
+ GtkWidget *installdialog; ///<! The install dialog
} ApplicationManagerData;
/**
@@ -127,6 +128,9 @@
void application_manager_data_set_search_history (ApplicationManagerData *appdata,
gchar *searchhistory);
+void application_manager_data_set_install_dialog (ApplicationManagerData *appdata,
+ GtkWidget *installdialog);
+
MokoPanedWindow *
application_manager_get_main_window (ApplicationManagerData *appdata);
@@ -173,6 +177,9 @@
gchar *
application_manager_data_get_search_history (ApplicationManagerData *appdata);
+GtkWidget *
+ application_manager_data_get_install_dialog (ApplicationManagerData *appdata);
+
G_END_DECLS
#endif
Modified: trunk/src/target/OM-2007/applications/openmoko-appmanager/src/install-dialog.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-appmanager/src/install-dialog.c 2006-12-26 10:16:18 UTC (rev 473)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/install-dialog.c 2006-12-28 00:56:41 UTC (rev 474)
@@ -19,6 +19,7 @@
* @author Chaowei Song (songcw at fic-sh.com.cn)
*/
#include <libmokoui/moko-tree-view.h>
+#include <string.h>
#include "install-dialog.h"
#include "appmanager-window.h"
@@ -47,11 +48,13 @@
gint displaystatus; ///<! The status of the display process
gboolean requestcancel; ///<! Cancel the install status by user choice
GtkWidget *textview; ///<! The textview in the dialog
+ gint pkgnum; ///<! The number of packages that need be installed/upgraded/removed
} InstallDialogPriv;
static void
install_dialog_class_init (InstallDialogClass *klass)
{
+ g_type_class_add_private (klass, sizeof (InstallDialogPriv));
}
static void
@@ -75,7 +78,7 @@
priv->requestcancel = FALSE;
// Init the dialog
- gtk_widget_set_size_request (GTK_WIDGET (self), 300, 480);
+ gtk_widget_set_size_request (GTK_WIDGET (self), 480, 480);
gtk_window_set_title (GTK_WINDOW (self), _("dialog1"));
gtk_window_set_type_hint (GTK_WINDOW (self), GDK_WINDOW_TYPE_HINT_DIALOG);
@@ -129,6 +132,7 @@
g_debug ("Can not malloc memory for the install dialog");
return NULL;
}
+ priv->pkgnum = pkgnum;
g_timeout_add (100, (GSourceFunc)install_dialog_time_out, dialog);
return dialog;
@@ -228,6 +232,8 @@
/**
* @brief Set the install status of the install dialog
+ * @param dialog The install dialog
+ * @param status The status
*/
void
install_dialog_set_install_status (InstallDialog *dialog,
@@ -241,3 +247,49 @@
g_return_if_fail ((status >= STATUS_INSTALL) && (status <= STATUS_COMPLETE));
priv->installstatus = status;
}
+
+/**
+ * @brief Add a prepare infomation to the dialog infomation
+ * @param dialog The install dialog
+ * @param info The infomation string
+ */
+void
+install_dialog_add_prepare_info (InstallDialog *dialog,
+ const gchar *info)
+{
+ InstallDialogPriv *priv;
+
+ g_return_if_fail (MOKO_IS_INSTALL_DIALOG (dialog));
+ priv = MOKO_INSTALL_DIALOG_GET_PRIVATE (dialog);
+
+ g_return_if_fail (priv->preparenum < priv->pkgnum);
+
+ priv->prepareinfolist[priv->preparenum] = g_malloc (strlen (info) +1);
+ g_return_if_fail (priv->prepareinfolist[priv->preparenum] != NULL);
+
+ strcpy (priv->prepareinfolist[priv->preparenum], info);
+ priv->preparenum ++;
+}
+
+/**
+ * @brief Add a install infomation to the dialog infomation
+ * @param dialog The install dialog
+ * @param info The infomation string
+ */
+void
+install_dialog_add_install_info (InstallDialog *dialog,
+ const gchar *info)
+{
+ InstallDialogPriv *priv;
+
+ g_return_if_fail (MOKO_IS_INSTALL_DIALOG (dialog));
+ priv = MOKO_INSTALL_DIALOG_GET_PRIVATE (dialog);
+
+ g_return_if_fail (priv->installnum < priv->pkgnum);
+
+ priv->installinfolist[priv->installnum] = g_malloc (strlen (info) +1);
+ g_return_if_fail (priv->installinfolist[priv->installnum] != NULL);
+
+ strcpy (priv->installinfolist[priv->installnum], info);
+ priv->installnum ++;
+}
Modified: trunk/src/target/OM-2007/applications/openmoko-appmanager/src/install-dialog.h
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-appmanager/src/install-dialog.h 2006-12-26 10:16:18 UTC (rev 473)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/install-dialog.h 2006-12-28 00:56:41 UTC (rev 474)
@@ -71,7 +71,12 @@
InstallDialog *install_dialog_new (ApplicationManagerData *appdata, gint pkgnum);
void install_dialog_set_install_status (InstallDialog *dialog,
gint status);
+void install_dialog_add_prepare_info (InstallDialog *dialog,
+ const gchar *info);
+void install_dialog_add_install_info (InstallDialog *dialog,
+ const gchar *info);
+
G_END_DECLS
#endif
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-26 10:16:18 UTC (rev 473)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/package-list.c 2006-12-28 00:56:41 UTC (rev 474)
@@ -17,6 +17,7 @@
*
* @author Chaowei Song (songcw at fic-sh.com.cn)
*/
+#include <gtk/gtk.h>
#include "appmanager-data.h"
#include "package-list.h"
@@ -24,6 +25,7 @@
#include "filter-menu.h"
#include "errorcode.h"
#include "navigation-area.h"
+#include "install-dialog.h"
/**
* @brief The structor of Package list node
@@ -45,6 +47,7 @@
} SectionList;
static gint package_list_insert_node_without_check (PackageList *pkglist, IPK_PACKAGE *pkg);
+static void package_list_free_all_dynamic (ApplicationManagerData *appdata);
/**
* @brief Version compare
@@ -1204,3 +1207,254 @@
tmplist = tmplist->next;
}// end while
}
+
+/**
+ * @brief Install/upgrade/remove pacakges that belong to the selected list
+ * @param data The application manager data
+ */
+gpointer
+package_list_execute_change (gpointer data)
+{
+ ApplicationManagerData *appdata;
+ GtkWidget *installdialog;
+ PackageList *pkglist;
+ PackageList *tmplist;
+ char *newname = NULL;
+ gchar tmpstr[256];
+ gchar *errstr;
+ int ret;
+ int res;
+ gboolean change;
+
+ g_return_val_if_fail (MOKO_IS_APPLICATION_MANAGER_DATA (data), NULL);
+ appdata = MOKO_APPLICATION_MANAGER_DATA (data);
+
+ installdialog = application_manager_data_get_install_dialog(appdata);
+ g_return_val_if_fail (MOKO_IS_INSTALL_DIALOG (installdialog), NULL);
+
+ pkglist = application_manager_data_get_selectedlist (appdata);
+ g_return_val_if_fail (pkglist != NULL, NULL);
+
+ tmplist = pkglist->next;
+ change = FALSE;
+
+ g_debug ("Begin to execute the marked packages");
+
+ while (tmplist != pkglist)
+ {
+ switch (tmplist->pkg->mark)
+ {
+ case PKG_STATUS_AVAILABLE_MARK_FOR_INSTALL:
+ snprintf (tmpstr, 255,
+ "Begin install package \"%s\"\n",
+ tmplist->pkg->name);
+ install_dialog_add_prepare_info (MOKO_INSTALL_DIALOG (installdialog),
+ tmpstr);
+ //FIXME The newname of the packages are not used now.
+ g_debug ("Begin to install:%s", tmplist->pkg->name);
+ ret = ipkg_install_cmd (tmplist->pkg->name, "root", &newname);
+ g_debug ("************************************************");
+ g_debug ("Install:%s complete, ret=%d", tmplist->pkg->name, ret);
+ if (ret == 0)
+ {
+ snprintf (tmpstr, 255,
+ "Install package \"%s\" success.\n",
+ tmplist->pkg->name);
+ install_dialog_add_install_info (MOKO_INSTALL_DIALOG (installdialog),
+ tmpstr);
+ }
+ else
+ {
+ res = strlen (get_error_msg ());
+ errstr = g_malloc (res + 100);
+ if (errstr == NULL)
+ {
+ // FIXME Add error manager code here
+ g_debug ("errstr malloc menory NULL");
+ install_dialog_add_install_info (MOKO_INSTALL_DIALOG (installdialog),
+ get_error_msg ());
+ break;
+ }
+ snprintf (errstr, res + 100,
+ "Install package \"%s\" error, the error message is:\n%s\n",
+ tmplist->pkg->name,
+ get_error_msg ());
+ install_dialog_add_install_info (MOKO_INSTALL_DIALOG (installdialog),
+ errstr);
+ g_debug ("prepare free errstr");
+ g_debug ("err =%s", errstr);
+ g_free (errstr);
+ g_debug ("after free errstr");
+ errstr = NULL;
+ }
+ break;
+
+ case PKG_STATUS_UPGRADEABLE_MARK_FOR_UPGRADE:
+ snprintf (tmpstr, 255,
+ "Begin upgrade package \"%s\"\n",
+ tmplist->pkg->name);
+ install_dialog_add_prepare_info (MOKO_INSTALL_DIALOG (installdialog),
+ tmpstr);
+ //FIXME The newname of the packages are not used now.
+ ret = ipkg_install_cmd (tmplist->pkg->name, "root", &newname);
+ if (ret == 0)
+ {
+ snprintf (tmpstr, 255,
+ "Upgrade package \"%s\" success.\n",
+ tmplist->pkg->name);
+ install_dialog_add_install_info (MOKO_INSTALL_DIALOG (installdialog),
+ tmpstr);
+ }
+ else
+ {
+ res = strlen (get_error_msg ());
+ errstr = g_malloc (res + 100);
+ if (errstr == NULL)
+ {
+ // FIXME Add error manager code here
+ install_dialog_add_install_info (MOKO_INSTALL_DIALOG (installdialog),
+ get_error_msg ());
+ break;
+ }
+ snprintf (errstr, res + 100,
+ "Upgrade package \"%s\" error, the error message is:\n%s\n",
+ tmplist->pkg->name,
+ get_error_msg ());
+ install_dialog_add_install_info (MOKO_INSTALL_DIALOG (installdialog),
+ errstr);
+ g_free (errstr);
+ errstr = NULL;
+ }
+ break;
+
+ case PKG_STATUS_INSTALLED_MARK_FOR_REMOVE:
+ case PKG_STATUS_UPGRADEABLE_MARK_FOR_REMOVE:
+ snprintf (tmpstr, 255,
+ "Begin remove package \"%s\"\n",
+ tmplist->pkg->name);
+ install_dialog_add_prepare_info (MOKO_INSTALL_DIALOG (installdialog),
+ tmpstr);
+ //FIXME The newname of the packages are not used now.
+ ret = ipkg_remove_cmd (tmplist->pkg->name);
+ if (ret == 0)
+ {
+ snprintf (tmpstr, 255,
+ "Remove package \"%s\" success.\n",
+ tmplist->pkg->name);
+ install_dialog_add_install_info (MOKO_INSTALL_DIALOG (installdialog),
+ tmpstr);
+ }
+ else
+ {
+ res = strlen (get_error_msg ());
+ errstr = g_malloc (res + 100);
+ if (errstr == NULL)
+ {
+ // FIXME Add error manager code here
+ install_dialog_add_install_info (MOKO_INSTALL_DIALOG (installdialog),
+ get_error_msg ());
+ break;
+ }
+ snprintf (errstr, res + 100,
+ "Remove package \"%s\" error, the error message is:\n%s\n",
+ tmplist->pkg->name,
+ get_error_msg ());
+ install_dialog_add_install_info (MOKO_INSTALL_DIALOG (installdialog),
+ errstr);
+ g_free (errstr);
+ errstr = NULL;
+ }
+ break;
+
+ default :
+ break;
+ if (ret == 0)
+ {
+ change = TRUE;
+ if (newname != NULL)
+ {
+ g_debug ("free new name");
+ free (newname);
+ g_debug ("free new name success");
+ newname = NULL;
+ }
+ }
+ }
+ tmplist = tmplist->next;
+ }
+
+ if (change)
+ {
+ install_dialog_set_install_status (MOKO_INSTALL_DIALOG (installdialog),
+ STATUS_REINIT);
+ package_list_free_all_dynamic (appdata);
+
+ ret = init_package_list (appdata);
+ if (ret != OP_SUCCESS)
+ {
+ g_debug ("Can not initial the libipkg, the result is%d", ret);
+ return NULL;
+ }
+ ret = package_list_build_index (appdata);
+ if (ret != OP_SUCCESS)
+ {
+ g_debug ("Can not build index for packages");
+ return NULL;
+ }
+ // FIXME Add reinit filter menu code late
+ }
+
+ install_dialog_set_install_status (MOKO_INSTALL_DIALOG (installdialog),
+ STATUS_COMPLETE);
+
+ return NULL;
+}
+
+/**
+ * @brief Free all dynamic data
+ * @param appdata The application manager data
+ */
+static void
+package_list_free_all_dynamic (ApplicationManagerData *appdata)
+{
+ PKG_LIST_HEAD *pkgheader;
+
+ g_return_if_fail (MOKO_IS_APPLICATION_MANAGER_DATA (appdata));
+
+ pkgheader = application_manager_data_get_pkglist (appdata);
+ if (pkgheader != NULL)
+ {
+ free_pkg_list (pkgheader);
+ g_free (pkgheader);
+ application_manager_data_set_pkglist (appdata, NULL);
+ }
+
+ package_list_clear_old_index (appdata);
+}
+
+/**
+ * @brief Get the number of packages in the selected list
+ * @param appdata The application manager data
+ */
+gint
+package_list_get_number_of_selected (ApplicationManagerData *appdata)
+{
+ PackageList *pkglist;
+ PackageList *tmplist;
+ gint number;
+
+ g_return_val_if_fail (MOKO_IS_APPLICATION_MANAGER_DATA (appdata), -1);
+
+ pkglist = application_manager_data_get_selectedlist (appdata);
+ g_return_val_if_fail (pkglist != NULL, 0);
+
+ number = 0;
+ tmplist = pkglist->next;
+ while (tmplist != pkglist)
+ {
+ number ++;
+ tmplist = tmplist->next;
+ }
+
+ return number;
+}
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-26 10:16:18 UTC (rev 473)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/package-list.h 2006-12-28 00:56:41 UTC (rev 474)
@@ -68,4 +68,9 @@
gpointer *selectedlist,
gint column);
void package_list_mark_all_upgradeable (ApplicationManagerData *appdata);
+
+gpointer package_list_execute_change (gpointer data);
+
+gint package_list_get_number_of_selected (ApplicationManagerData *appdata);
+
#endif
Modified: trunk/src/target/OM-2007/applications/openmoko-appmanager/src/tool-box.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-appmanager/src/tool-box.c 2006-12-26 10:16:18 UTC (rev 473)
+++ trunk/src/target/OM-2007/applications/openmoko-appmanager/src/tool-box.c 2006-12-28 00:56:41 UTC (rev 474)
@@ -24,6 +24,7 @@
#include "package-list.h"
#include "appmanager-window.h"
#include "apply-dialog.h"
+#include "install-dialog.h"
/**
* @brief The callback function of the button "upgrade"
@@ -55,7 +56,10 @@
on_apply_clicked (GtkButton *bapply, gpointer data)
{
GtkWidget *dialog;
+ InstallDialog *installdialog;
gint res;
+ gint number;
+
g_debug ("Clicked the button apply");
if (package_list_check_marked_list_empty (
@@ -75,7 +79,26 @@
res = gtk_dialog_run (GTK_DIALOG (dialog));
//FIXME Add code to install/remove/upgrade package
+ if (res == GTK_RESPONSE_OK)
+ {
+ g_debug ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+ g_debug ("Check the number of the selected list");
+ number = package_list_get_number_of_selected (MOKO_APPLICATION_MANAGER_DATA (data));
+ installdialog = install_dialog_new (MOKO_APPLICATION_MANAGER_DATA (data), number);
+ application_manager_data_set_install_dialog (MOKO_APPLICATION_MANAGER_DATA (data),
+ GTK_WIDGET (installdialog));
+ g_debug ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+ g_debug ("Begin to install/upgrade/remove packages");
+ if (!g_thread_supported ())
+ {
+ g_thread_init (NULL);
+ }
+ g_thread_create (package_list_execute_change, data, TRUE, NULL);
+ gtk_dialog_run (GTK_DIALOG (installdialog));
+ gtk_widget_destroy (GTK_WIDGET (installdialog));
+ }
+
gtk_widget_destroy (dialog);
}
More information about the commitlog
mailing list