static gpointer gw_installprogresswindow_install_thread (gpointer data) { //Declarations GwInstallProgressWindow *window; GwInstallProgressWindowPrivate *priv; GwApplication *application; GwDictionaryList *dictionarylist; GList *link; LwDictionary *dictionary; GError *error; gulong signalid; GCancellable *cancellable; //Initializations window = GW_INSTALLPROGRESSWINDOW (data); if (window == NULL) return NULL; priv = window->priv; application = gw_window_get_application (GW_WINDOW (window)); dictionarylist = gw_application_get_installable_dictionarylist (application); cancellable = priv->cancellable; error = NULL; link = lw_dictionarylist_get_list (LW_DICTIONARYLIST (dictionarylist)); //Do the installation g_timeout_add (100, gw_installprogresswindow_update_ui_timeout, window); while (link != NULL && error == NULL) { dictionary = LW_DICTIONARY (link->data); if (dictionary != NULL && lw_dictionary_is_selected (dictionary)) { g_mutex_lock (&priv->mutex); priv->dictionary = dictionary; g_mutex_unlock (&priv->mutex); signalid = g_signal_connect (dictionary, "progress-changed", G_CALLBACK (gw_installprogresswindow_update_dictionary_cb), window); lw_dictionary_install (dictionary, cancellable, &error); if (g_signal_handler_is_connected (dictionary, signalid)) g_signal_handler_disconnect (dictionary, signalid); } link = link->next; } gw_application_set_error (application, error); error = NULL; g_mutex_lock (&priv->mutex); //This will clue the progress window to close itself priv->dictionary = NULL; g_mutex_unlock (&priv->mutex); return NULL; }
G_MODULE_EXPORT void gw_installprogresswindow_cancel_cb (GtkWidget *widget, gpointer data) { GwInstallProgressWindow *window; GwApplication *application; LwDictInstList *dictinstlist; window = GW_INSTALLPROGRESSWINDOW (gtk_widget_get_ancestor (GTK_WIDGET (data), GW_TYPE_INSTALLPROGRESSWINDOW)); if (window == NULL) return; application = gw_window_get_application (GW_WINDOW (window)); dictinstlist = gw_application_get_dictinstlist (application); lw_dictinstlist_set_cancel_operations (dictinstlist, TRUE); }
static void gw_installprogresswindow_finalize (GObject *object) { GwInstallProgressWindow *window; GwInstallProgressWindowPrivate *priv; window = GW_INSTALLPROGRESSWINDOW (object); priv = window->priv; g_mutex_clear (&priv->mutex); priv->label = NULL; priv->sublabel = NULL; priv->progressbar = NULL; if (priv->cancellable != NULL) g_object_unref (priv->cancellable); priv->cancellable = NULL; G_OBJECT_CLASS (gw_installprogresswindow_parent_class)->finalize (object); }
//! //! @brief Sets up the variables in main-interface.c and main-callbacks.c for use //! GtkWindow* gw_installprogresswindow_new (GtkApplication *application) { g_assert (application != NULL); //Declarations GwInstallProgressWindow *window; //Initializations window = GW_INSTALLPROGRESSWINDOW (g_object_new (GW_TYPE_INSTALLPROGRESSWINDOW, "type", GTK_WINDOW_TOPLEVEL, "application", GW_APPLICATION (application), "ui-xml", "installprogresswindow.ui", NULL)); return GTK_WINDOW (window); }
static void gw_installprogresswindow_constructed (GObject *object) { //Declarations GwInstallProgressWindow *window; GwInstallProgressWindowPrivate *priv; GtkAccelGroup *accelgroup; //Chain the parent class { G_OBJECT_CLASS (gw_installprogresswindow_parent_class)->constructed (object); } window = GW_INSTALLPROGRESSWINDOW (object); priv = window->priv; accelgroup = gw_window_get_accel_group (GW_WINDOW (window)); g_mutex_init (&priv->mutex); priv->label = GTK_LABEL (gw_window_get_object (GW_WINDOW (window), "progress_label")); priv->sublabel = GTK_LABEL (gw_window_get_object (GW_WINDOW (window), "sub_progress_label")); priv->progressbar = GTK_PROGRESS_BAR (gw_window_get_object (GW_WINDOW (window), "progress_progressbar")); priv->cancel_button = GTK_BUTTON (gw_window_get_object (GW_WINDOW (window), "cancel_button")); priv->cancellable = g_cancellable_new (); gtk_window_set_title (GTK_WINDOW (window), gettext("Installing Dictionaries...")); gtk_window_set_resizable (GTK_WINDOW (window), TRUE); gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DIALOG); gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), TRUE); gtk_window_set_skip_pager_hint (GTK_WINDOW (window), TRUE); gtk_window_set_destroy_with_parent (GTK_WINDOW (window), TRUE); gtk_window_set_icon_name (GTK_WINDOW (window), "gwaei"); gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER_ON_PARENT); gtk_window_set_modal (GTK_WINDOW (window), TRUE); gtk_window_set_default_size (GTK_WINDOW (window), 500, -1); gtk_window_set_has_resize_grip (GTK_WINDOW (window), FALSE); gtk_container_set_border_width (GTK_CONTAINER (window), 4); gtk_widget_add_accelerator (GTK_WIDGET (priv->cancel_button), "activate", accelgroup, (GDK_KEY_W), GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); gtk_widget_add_accelerator (GTK_WIDGET (priv->cancel_button), "activate", accelgroup, (GDK_KEY_Escape), 0, GTK_ACCEL_VISIBLE); gw_window_unload_xml (GW_WINDOW (window)); }
G_MODULE_EXPORT int gw_installprogresswindow_update_dictinst_cb (double fraction, gpointer data) { //Declarations GwInstallProgressWindow *window; GwInstallProgressWindowPrivate *priv; //Initializations window = GW_INSTALLPROGRESSWINDOW (gtk_widget_get_ancestor (GTK_WIDGET (data), GW_TYPE_INSTALLPROGRESSWINDOW)); if (window == NULL) return 0; priv = window->priv; g_mutex_lock (priv->mutex); priv->install_fraction = lw_dictinst_get_total_progress (priv->di, fraction); g_mutex_unlock (priv->mutex); return 0; }
//! //! @brief Callback to update the install dialog progress. The data passed to it should be //! in the form of a LwDictInst. If it is NULL, the progress window will be closed. //! G_MODULE_EXPORT gboolean gw_installprogresswindow_update_ui_timeout (gpointer data) { //Sanity check g_assert (data != NULL); //Declarations GwInstallProgressWindow *window; GwInstallProgressWindowPrivate *priv; GtkWindow *settingswindow; GwApplication *application; LwDictInstList *dictinstlist; GwDictInfoList *dictinfolist; LwDictInst *di; GList *iter; int current_to_install; int total_to_install; char *text_installing; char *text_installing_markup; char *text_left; char *text_left_markup; char *text_progressbar; //Initializations window = GW_INSTALLPROGRESSWINDOW (gtk_widget_get_ancestor (GTK_WIDGET (data), GW_TYPE_INSTALLPROGRESSWINDOW)); if (window == NULL) return FALSE; application = gw_window_get_application (GW_WINDOW (window)); dictinstlist = gw_application_get_dictinstlist (application); priv = window->priv; current_to_install = 0; total_to_install = 0; //The install is complete close the window if (priv->di == NULL) { settingswindow = gtk_window_get_transient_for (GTK_WINDOW (window)); dictinfolist = gw_application_get_dictinfolist (application); gw_dictinfolist_reload (dictinfolist); gtk_widget_destroy (GTK_WIDGET (window)); gw_application_handle_error (application, GTK_WINDOW (settingswindow), TRUE, NULL); lw_dictinstlist_set_cancel_operations (dictinstlist, FALSE); gw_settingswindow_check_for_dictionaries (GW_SETTINGSWINDOW (settingswindow)); return FALSE; } g_mutex_lock (priv->mutex); //Calculate the number of dictionaries left to install for (iter = dictinstlist->list; iter != NULL; iter = iter->next) { di = LW_DICTINST (iter->data); if (di != NULL && di->selected) { current_to_install++; } if (iter->data == priv->di) break; } //Calculate the number of dictionaries left to install for (iter = dictinstlist->list; iter != NULL; iter = iter->next) { di = LW_DICTINST (iter->data); if (di->selected) { total_to_install++; } } di = priv->di; text_progressbar = g_markup_printf_escaped (gettext("Installing %s..."), di->filename); text_left = g_strdup_printf (gettext("Installing dictionary %d of %d..."), current_to_install, total_to_install); text_left_markup = g_markup_printf_escaped ("<big><b>%s</b></big>", text_left); text_installing = lw_dictinst_get_status_string (di, TRUE); text_installing_markup = g_markup_printf_escaped ("<small>%s</small>", text_installing); gtk_label_set_markup (priv->label, text_left_markup); gtk_label_set_markup (priv->sublabel, text_installing_markup); gtk_progress_bar_set_fraction (priv->progressbar, priv->install_fraction); gtk_progress_bar_set_text (priv->progressbar, text_progressbar); g_mutex_unlock (priv->mutex); //Cleanup g_free (text_progressbar); g_free (text_left); g_free (text_left_markup); g_free (text_installing); g_free (text_installing_markup); return TRUE; }