static void show_view_project_loaded_cb (MrpProject *project, PlannerShowView *view) { GtkTreeModel *model; GList *task_list; MrpTaskManager *task_manager; //g_free(pertnodes);//pretend more load action that this list add unexcepted tasks //g_free(firsttasklist);//the same as above firsttasklist = NULL; project = planner_window_get_project(PLANNER_VIEW (view) ->main_window); task_manager = imrp_project_get_task_manager(project); task_list = mrp_task_manager_get_all_tasks(task_manager); firsttasklist = sortTasklistsByFinishTime(task_list); tasklistlength = g_list_length(task_list); prosses = tasklistlength; model = GTK_TREE_MODEL (planner_gantt_model_new (project)); planner_task_tree_set_model(PLANNER_TASK_TREE (view->priv->tree), PLANNER_GANTT_MODEL (model) ); planner_gantt_chart_set_model(PLANNER_GANTT_CHART (view->priv->gantt), model); view->priv->expose_id = g_signal_connect_after (view->priv->gantt, "expose_event", G_CALLBACK (show_view_expose_cb), view); //task_view_pert_chart_on_load(view); g_object_unref(model); }
PlannerCmd * planner_resource_cmd_insert (PlannerWindow *main_window, MrpResource *resource) { PlannerCmd *cmd_base; ResourceCmdInsert *cmd; cmd_base = planner_cmd_new (ResourceCmdInsert, _("Insert resource"), resource_cmd_insert_do, resource_cmd_insert_undo, resource_cmd_insert_free); cmd = (ResourceCmdInsert *) cmd_base; if (resource == NULL) { cmd->resource = g_object_new (MRP_TYPE_RESOURCE, NULL); } else { cmd->resource = g_object_ref (resource); } cmd->project = planner_window_get_project (main_window); planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (main_window), cmd_base); return cmd_base; }
static PlannerCmd * phase_cmd_insert (PlannerWindow *main_window, const gchar *phase, gint position_hint) { PlannerCmd *cmd_base; PhaseCmdInsert *cmd; cmd_base = planner_cmd_new (PhaseCmdInsert, _("Insert phase"), phase_cmd_insert_do, phase_cmd_insert_undo, phase_cmd_insert_free); cmd = (PhaseCmdInsert *) cmd_base; cmd->project = planner_window_get_project (main_window); cmd->phase = g_strdup (phase); cmd->position = position_hint; planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (main_window), cmd_base); return cmd_base; }
static void task_view_pert_chart_on_load (PlannerShowView *view) { GtkWidget *layout; MrpTask *root; GList *task_list; GList *l; MrpTaskManager *task_manager; //PlannerShowView *view; PlannerShowViewPriv *priv; MrpProject *project; pertnodes = NULL; priv = view->priv; layout = priv->pertlayout; project = planner_window_get_project(PLANNER_VIEW(view)->main_window); task_manager = imrp_project_get_task_manager(project); root = mrp_task_manager_get_root (task_manager); task_list = mrp_task_manager_get_all_tasks(task_manager); // g_print("______________________22222222222222222222_______________________"); l = planner_pertchart_nodes_creat(task_list); task_manager_build_dependency_graph_for_node (task_manager); l = setPertNodesPosition(); avoidCrossingNode(); avoidCrossingLine(); removeEmptyColumn(); getposition(l); getArrowPosition(pertnodes); drawtask(layout,project); }
GList * getSortedTaskListByView(PlannerShowView *view) { GList *task_list; GList *sortedtasks; MrpTaskManager *task_manager; MrpProject *project; project = planner_window_get_project (PLANNER_VIEW (view)->main_window); task_manager = imrp_project_get_task_manager(project); task_list = mrp_task_manager_get_all_tasks(task_manager); sortedtasks = sortTasklistsByFinishTime(task_list); return sortedtasks; }
static gint show_view_next_task_cb(GtkWidget *button, PlannerShowView *view) { GList *task_list; GList *sortedtasks; GList *l; MrpTaskManager *task_manager; PlannerShowViewPriv *priv; MrpProject *project; MrpTask *currenttask; gchar *str; gint currentdurationtime; project = planner_window_get_project (PLANNER_VIEW (view)->main_window); task_manager = imrp_project_get_task_manager(project); task_list = mrp_task_manager_get_all_tasks(task_manager); priv = view->priv; //root = mrp_task_manager_get_root (task_manager); //task_list = mrp_task_manager_get_all_tasks(task_manager); //sortedtasks = sortTasklistsByFinishTime(task_list); tasklistlength--; if(!gtk_widget_get_sensitive(priv->deleteresourcebutton)) gtk_widget_set_sensitive(priv->deleteresourcebutton,TRUE); if (tasklistlength < 0) { gtk_button_set_label(priv->nextstepbutton, "整体审计计划模拟推演完毕"); gtk_widget_set_sensitive(priv->nextstepbutton, FALSE); return 0; } currentdurationtime = totalduration(project); priv->firsttotalduration = currentdurationtime; //g_print("%d",totalduration(project)); str = planner_format_float(currentdurationtime, 2, FALSE); gtk_entry_set_text(GTK_ENTRY (priv->currentdurationentry), str); timertag = g_timeout_add_full(G_PRIORITY_HIGH, 1000, show_view_simul_task_delay_cb, view, show_view_timeout_remove_cb); timer = gtk_timeout_add(1000, timeout_callback, priv->progressbar); return 1; }
static void task_view_edit_custom_props_cb (GtkAction *action, gpointer data) { PlannerTaskView *view; GtkWidget *dialog; MrpProject *project; view = PLANNER_TASK_VIEW (data); project = planner_window_get_project (PLANNER_VIEW (view)->main_window); dialog = planner_property_dialog_new (PLANNER_VIEW (view)->main_window, project, MRP_TYPE_TASK, _("Edit custom task properties")); gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 300); gtk_widget_show (dialog); }
static PlannerCmd * phase_cmd_remove (PlannerWindow *window, const gchar *phase) { PlannerCmd *cmd_base; PhaseCmdRemove *cmd; cmd_base = planner_cmd_new (PhaseCmdRemove, _("Remove phase"), phase_cmd_remove_do, phase_cmd_remove_undo, phase_cmd_remove_free); cmd = (PhaseCmdRemove *) cmd_base; cmd->project = planner_window_get_project (window); cmd->phase = g_strdup (phase); planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (window), cmd_base); return cmd_base; }
/* FIXME: Undo support */ G_MODULE_EXPORT void plugin_init (PlannerPlugin *plugin) { PlannerPluginPriv *priv; GtkUIManager *ui; gchar *filename; priv = g_new0 (PlannerPluginPriv, 1); plugin->priv = priv; priv->project = planner_window_get_project (plugin->main_window); priv->actions = gtk_action_group_new ("EDS plugin actions"); gtk_action_group_set_translation_domain (priv->actions, GETTEXT_PACKAGE); gtk_action_group_add_actions (priv->actions, action_entries, n_action_entries, plugin); ui = planner_window_get_ui_manager (plugin->main_window); gtk_ui_manager_insert_action_group (ui, priv->actions, 0); filename = mrp_paths_get_ui_dir ("eds-plugin.ui"); gtk_ui_manager_add_ui_from_file (ui, filename, NULL); g_free (filename); gtk_ui_manager_ensure_update (ui); }
static void html_plugin_export_do (PlannerPlugin *plugin, const gchar *path, gboolean show_in_browser) { MrpProject *project; GtkWidget *dialog; project = planner_window_get_project (plugin->main_window); if (!mrp_project_export (project, path, "Planner HTML", TRUE, NULL)) { dialog = gtk_message_dialog_new (GTK_WINDOW (plugin->main_window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not export to HTML")); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } else if (show_in_browser) { html_plugin_show_url (plugin, path); } }
static gboolean msp_plugin_transform (PlannerPlugin *plugin, const gchar *input_filename) { xsltStylesheet *stylesheet; xmlDoc *doc; xmlDoc *final_doc; gint fd; FILE *file; gchar *tmp_name, *uri; MrpProject *project; gchar *filename; /* libxml housekeeping */ xmlSubstituteEntitiesDefault (1); xmlLoadExtDtdDefaultValue = 1; exsltRegisterAll (); filename = mrp_paths_get_stylesheet_dir ("msp2planner.xsl"); stylesheet = xsltParseStylesheetFile (filename); g_free (filename); doc = xmlParseFile (input_filename); if (!doc) { xsltFreeStylesheet (stylesheet); return FALSE; } final_doc = xsltApplyStylesheet (stylesheet, doc, NULL); xmlFree (doc); if (!final_doc) { xsltFreeStylesheet (stylesheet); return FALSE; } filename = mrp_paths_get_dtd_dir ("mrproject-0.6.dtd"); if (!xml_validate (final_doc, filename)) { GtkWidget *dialog; xsltFreeStylesheet (stylesheet); xmlFree (final_doc); dialog = gtk_message_dialog_new (GTK_WINDOW (plugin->main_window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Couldn't import file.")); gtk_widget_show (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_free (filename); return FALSE; } g_free (filename); fd = g_file_open_tmp ("planner-msp-XXXXXX", &tmp_name, NULL); if (fd == -1) { xsltFreeStylesheet (stylesheet); xmlFree (final_doc); return FALSE; } file = fdopen (fd, "w"); if (file == NULL) { xsltFreeStylesheet (stylesheet); xmlFree (final_doc); close (fd); g_free (tmp_name); return FALSE; } if (xsltSaveResultToFile (file, final_doc, stylesheet) == -1) { xsltFreeStylesheet (stylesheet); xmlFree (final_doc); fclose (file); g_free (tmp_name); return FALSE; } xsltFreeStylesheet (stylesheet); xmlFree (final_doc); uri = g_filename_to_uri (tmp_name, NULL, NULL); if (uri) { planner_window_open_in_existing_or_new (plugin->main_window, uri, TRUE); project = planner_window_get_project (plugin->main_window) ; mrp_project_set_uri (project, NULL); } unlink (tmp_name); fclose (file); g_free (tmp_name); g_free (uri); return TRUE; }
static void xml_planner_plugin_export (GtkAction *action, gpointer user_data) { PlannerPlugin *plugin; MrpProject *project; GError *error = NULL; GtkWidget *file_chooser; GtkWidget *dialog; gint response; gchar *filename = NULL; gchar *real_filename; gchar *last_dir; plugin = PLANNER_PLUGIN (user_data); try_again: file_chooser = gtk_file_chooser_dialog_new (_("Export"), GTK_WINDOW (plugin->main_window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); gtk_window_set_modal (GTK_WINDOW (file_chooser), TRUE); last_dir = get_last_dir (); gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (file_chooser), last_dir); g_free (last_dir); response = gtk_dialog_run (GTK_DIALOG (file_chooser)); if (response == GTK_RESPONSE_OK) { filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER (file_chooser)); } gtk_widget_destroy (file_chooser); if (filename) { if (!g_str_has_suffix (filename, ".mrproject") && !g_str_has_suffix (filename, ".planner")) { /* Add the old extension for old format files. */ real_filename = g_strconcat (filename, ".mrproject", NULL); } else { real_filename = g_strdup (filename); } if (g_file_test (real_filename, G_FILE_TEST_EXISTS)) { dialog = gtk_message_dialog_new (GTK_WINDOW (plugin->main_window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO, _("File \"%s\" exists, " "do you want to overwrite it?"), real_filename); response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); switch (response) { case GTK_RESPONSE_YES: break; default: g_free (real_filename); goto try_again; } } } if (!filename) { return; } project = planner_window_get_project (plugin->main_window); if (!mrp_project_export (project, real_filename, "Planner XML pre-0.12", TRUE, &error)) { g_warning ("Error while export to Planner XML: %s", error->message); } last_dir = g_path_get_dirname (real_filename); planner_conf_set_string (CONF_MAIN_LAST_XML_EXPORT_DIR, last_dir, NULL); g_free (last_dir); g_free (real_filename); g_free (filename); }
static GtkWidget * task_view_get_widget (PlannerView *view) { PlannerTaskViewPriv *priv; MrpProject *project; GtkWidget *sw; PlannerGanttModel *model; priv = PLANNER_TASK_VIEW (view)->priv; if (priv->tree == NULL) { project = planner_window_get_project (view->main_window); g_signal_connect (project, "loaded", G_CALLBACK (task_view_project_loaded_cb), view); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); priv->frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), GTK_SHADOW_IN); gtk_container_add (GTK_CONTAINER (priv->frame), sw); model = planner_gantt_model_new (project); priv->tree = planner_task_tree_new (view->main_window, model, TRUE, FALSE, /* i18n: WBS is sort for work breakdown structure, and is a * project management term. You might want to leave it * untranslated unless there is a localized term for it. */ COL_WBS, _("WBS"), COL_NAME, _("Name"), COL_START, _("Start"), COL_FINISH, _("Finish"), COL_WORK, _("Work"), COL_DURATION, _("Duration"), COL_SLACK, _("Slack"), COL_COST, _("Cost"), COL_ASSIGNED_TO, _("Assigned to"), /* i18n: The string "% Complete" will be used in the header * of a column containing values from 0 upto 100, indicating * what part of a task has been completed. * xgettext:no-c-format */ COL_COMPLETE, _("% Complete"), -1); g_object_unref (model); task_view_load_columns (view); gtk_container_add (GTK_CONTAINER (sw), priv->tree); g_signal_connect (priv->tree, "columns-changed", G_CALLBACK (task_view_tree_view_columns_changed_cb), view); g_signal_connect (priv->tree, "destroy", G_CALLBACK (task_view_tree_view_destroy_cb), view); g_signal_connect (priv->tree, "selection-changed", G_CALLBACK (task_view_selection_changed_cb), view); g_signal_connect (priv->tree, "relation-added", G_CALLBACK (task_view_relations_changed_cb), view); g_signal_connect (priv->tree, "relation-removed", G_CALLBACK (task_view_relations_changed_cb), view); gtk_widget_show (priv->tree); gtk_widget_show (sw); gtk_widget_show (priv->frame); } return priv->frame; }
static void sql_plugin_save (GtkAction *action, gpointer user_data) { GdaClient *client; GdaConnection *conn; PlannerPlugin *plugin = user_data; MrpProject *project; GObject *object; gchar *server = NULL; gchar *port = NULL; gchar *database = NULL; gchar *login = NULL; gchar *password = NULL; gchar *uri = NULL; const gchar *uri_plan = NULL; GError *error = NULL; gchar *db_txt; const gchar *dsn_name = "planner-auto"; const gchar *provider = "PostgreSQL"; project = planner_window_get_project (plugin->main_window); if (!sql_plugin_retrieve_db_values (plugin, _("Save to Database"), &server, &port, &database, &login, &password)) { return; } db_txt = g_strdup_printf (CONNECTION_FORMAT_STRING,server,database); gda_config_save_data_source (dsn_name, provider, db_txt, "planner project", login, password, FALSE); g_free (db_txt); client = gda_client_new (); conn = sql_get_tested_connection (dsn_name, server, database, client, plugin); if (conn == NULL) { g_object_unref (client); return; } gda_connection_close (conn); g_object_unref (client); /* This code is prepared for getting support for selecting a project to * save over. Needs finishing though. Pass project id -1 for now (always * create a new project). */ uri_plan = mrp_project_get_uri (project); /* First time project */ if (uri_plan == NULL) { uri = create_sql_uri (server, port, database, login, password, -1); if (!mrp_project_save_as (project, uri, FALSE, &error)) { show_error_dialog (plugin, error->message); g_clear_error (&error); goto fail; } g_free (uri); } /* Project was in database */ else if (strncmp (uri_plan, "sql://", 6) == 0) { if (!mrp_project_save (project, FALSE, &error)) { show_error_dialog (plugin, error->message); g_clear_error (&error); goto fail; } } /* Project wasn't in database */ else { uri = create_sql_uri (server, port, database, login, password, -1); if (!mrp_project_save_as (project, uri, FALSE, &error)) { show_error_dialog (plugin, error->message); g_clear_error (&error); goto fail; } g_free (uri); } object = G_OBJECT (plugin->main_window); g_object_set_data_full (object, SERVER, server, g_free); g_object_set_data_full (object, DATABASE, database, g_free); g_object_set_data_full (object, LOGIN, login, g_free); g_object_set_data_full (object, PASSWORD, password, g_free); return; fail: g_free (server); g_free (port); g_free (database); g_free (login); g_free (password); g_free (uri); }
static void sql_plugin_open (GtkAction *action, gpointer user_data) { PlannerPlugin *plugin = user_data; PlannerApplication *application; GtkWidget *window; MrpProject *project; gchar *server = NULL; gchar *port = NULL; gchar *database = NULL; gchar *login = NULL; gchar *password = NULL; gint project_id = -1; gchar *uri = NULL; GError *error = NULL; if (!sql_plugin_retrieve_db_values (plugin, _("Open from Database"), &server, &port, &database, &login, &password)) { return; } project_id = sql_plugin_retrieve_project_id (plugin, server, port, database, login, password); if (project_id == -1) { goto fail; } /* Note: The project can change or disappear between the call above and * below. We handle that case though. */ uri = create_sql_uri (server, port, database, login, password, project_id); project = planner_window_get_project (plugin->main_window); window = GTK_WIDGET (plugin->main_window); application = planner_window_get_application (plugin->main_window); if (mrp_project_is_empty (project)) { GObject *object = G_OBJECT (window); if (!mrp_project_load (project, uri, &error)) { show_error_dialog (plugin, error->message); g_clear_error (&error); goto fail; } /* Note: Those aren't used for anything right now. */ g_object_set_data_full (object, SERVER, server, g_free); g_object_set_data_full (object, DATABASE, database, g_free); g_object_set_data_full (object, LOGIN, login, g_free); g_object_set_data_full (object, PASSWORD, password, g_free); g_free (uri); return; } else { GObject *object; window = planner_application_new_window (application); project = planner_window_get_project (PLANNER_WINDOW (window)); object = G_OBJECT (window); /* We must get the new plugin object for the new window, * otherwise we'll pass the wrong window around... a bit * hackish. */ plugin = g_object_get_data (G_OBJECT (window), "sql-plugin"); if (!mrp_project_load (project, uri, &error)) { g_warning ("Error: %s", error->message); g_clear_error (&error); gtk_widget_destroy (window); goto fail; } g_object_set_data_full (object, SERVER, server, g_free); g_object_set_data_full (object, DATABASE, database, g_free); g_object_set_data_full (object, LOGIN, login, g_free); g_object_set_data_full (object, PASSWORD, password, g_free); g_free (uri); gtk_widget_show_all (window); return; } fail: g_free (server); g_free (port); g_free (database); g_free (login); g_free (password); g_free (uri); }
static GtkWidget * usage_view_create_widget (PlannerView *view) { PlannerUsageViewPriv *priv; MrpProject *project; GtkWidget *hpaned; GtkWidget *left_frame; GtkWidget *right_frame; PlannerUsageModel *model; GtkWidget *tree; GtkWidget *vbox; GtkWidget *sw; GtkWidget *chart; GtkAdjustment *hadj, *vadj; project = planner_window_get_project (view->main_window); priv = PLANNER_USAGE_VIEW (view)->priv; priv->project = project; g_signal_connect (project, "loaded", G_CALLBACK (usage_view_project_loaded_cb), view); g_signal_connect (project, "resource_added", G_CALLBACK (usage_view_resource_added_cb), view); model = planner_usage_model_new (project); tree = planner_usage_tree_new (view->main_window, model); priv->tree = tree; left_frame = gtk_frame_new (NULL); right_frame = gtk_frame_new (NULL); vbox = gtk_vbox_new (FALSE, 3); gtk_box_pack_start (GTK_BOX (vbox), tree, TRUE, TRUE, 0); hadj = gtk_tree_view_get_hadjustment (GTK_TREE_VIEW (tree)); gtk_box_pack_start (GTK_BOX (vbox), gtk_hscrollbar_new (hadj), FALSE, TRUE, 0); gtk_container_add (GTK_CONTAINER (left_frame), vbox); hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 0, 90, 250, 2000)); vadj = gtk_tree_view_get_vadjustment (GTK_TREE_VIEW (tree)); chart = planner_usage_chart_new_with_model (GTK_TREE_MODEL (model)); priv->chart = PLANNER_USAGE_CHART (chart); planner_usage_chart_set_view (PLANNER_USAGE_CHART (priv->chart), PLANNER_USAGE_TREE (priv->tree)); gtk_widget_set_events (GTK_WIDGET (priv->chart), GDK_SCROLL_MASK); g_signal_connect (priv->chart, "scroll-event", G_CALLBACK (usage_view_chart_scroll_event), view); sw = gtk_scrolled_window_new (hadj, vadj); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_ALWAYS, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (right_frame), sw); gtk_container_add (GTK_CONTAINER (sw), chart); hpaned = gtk_hpaned_new (); gtk_frame_set_shadow_type (GTK_FRAME (left_frame), GTK_SHADOW_IN); gtk_frame_set_shadow_type (GTK_FRAME (right_frame), GTK_SHADOW_IN); gtk_paned_add1 (GTK_PANED (hpaned), left_frame); gtk_paned_add2 (GTK_PANED (hpaned), right_frame); usage_view_load_columns (PLANNER_USAGE_VIEW (view)); g_signal_connect (tree, "columns-changed", G_CALLBACK (usage_view_tree_view_columns_changed_cb), view); g_signal_connect (tree, "destroy", G_CALLBACK (usage_view_tree_view_destroy_cb), view); g_signal_connect (tree, "row_expanded", G_CALLBACK (usage_view_row_expanded), chart); g_signal_connect (tree, "row_collapsed", G_CALLBACK (usage_view_row_collapsed), chart); g_signal_connect (tree, "expand_all", G_CALLBACK (usage_view_expand_all), chart); g_signal_connect (tree, "collapse_all", G_CALLBACK (usage_view_collapse_all), chart); g_signal_connect (chart, "status_updated", G_CALLBACK (usage_view_usage_status_updated), view); g_signal_connect_after (tree, "size_request", G_CALLBACK (usage_view_tree_view_size_request_cb), NULL); g_signal_connect_after (tree, "scroll_event", G_CALLBACK (usage_view_tree_view_scroll_event_cb), view); g_signal_connect (tree, "style_set", G_CALLBACK (usage_view_tree_style_set_cb), view); gtk_tree_view_expand_all (GTK_TREE_VIEW (tree)); planner_usage_chart_expand_all (PLANNER_USAGE_CHART (chart)); g_object_unref (model); return hpaned; }
static void show_view_simul_task_delay_cb (PlannerShowView *view) { GList *tasklist; MrpProject *project; gint probability; MrpTask *currenttask; gchar *currenttaskname; gint delayedtime; gint chengeddurationtime; gchar *str1; gchar *str2; PlannerShowViewPriv *priv; mrptime duration; mrptime delayedduration; currenttasknumber++; priv = view->priv; // tasklist = getSortedTaskListByView(view); // currenttask = g_list_nth_data(tasklist,currenttasknumber); currenttask = g_list_nth_data(firsttasklist,currenttasknumber); //setDelayedDuration(currenttask); probability = mrp_task_get_probability(currenttask); currenttaskname = mrp_task_get_name(currenttask); duration = mrp_task_get_duration(currenttask); g_printf("%s, %d",currenttaskname,probability); gtk_entry_set_text (GTK_ENTRY (priv->currenttaskentry), currenttaskname); project = planner_window_get_project (PLANNER_VIEW (view)->main_window); //random task delay if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->randomtogglebutton)) && ((5 == currenttasknumber) || (1 == currenttasknumber))) // if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->randomtogglebutton)) // && (randomtasknumber == currenttasknumber) && (randomtasknumber+3 == currenttasknumber)) { //srand((int) time(0)); //MrpTask *randomtask = getRandomTask(firsttasklist); delayedduration = duration*1.5; g_object_set (currenttask, "sched",1,NULL); g_object_set (currenttask, "duration", delayedduration, NULL); gtk_widget_set_sensitive(priv->deleteresourcebutton, FALSE); gchar *a = g_strconcat(currenttaskname, "当前审计任务被随机设置延迟!", NULL ); gtk_button_set_label(priv->deleteresourcebutton, a); } //manual set task delay GdkColor color1; if(probability) { if (probability >= 30 && probability <= 60) { color1.red = 50000; color1.green = 20000; color1.blue = 15000; gtk_widget_modify_bg(priv->deleteresourcebutton, GTK_STATE_INSENSITIVE, &color1); gtk_widget_modify_fg(priv->currentdelayentry, GTK_STATE_NORMAL, &color1); gtk_widget_set_sensitive(priv->deleteresourcebutton, FALSE); gchar *a = g_strconcat(currenttaskname, "当前审计任务被手动设置延迟!延迟小于60%", NULL ); gtk_button_set_label(priv->deleteresourcebutton, a); } else{ if (probability > 60) { color1.red = 55000; color1.green = 5000; color1.blue = 5000; gtk_widget_modify_bg(priv->deleteresourcebutton, GTK_STATE_INSENSITIVE, &color1); gtk_widget_modify_bg(priv->currentdelayentry, GTK_STATE_NORMAL, &color1); gtk_widget_set_sensitive(priv->deleteresourcebutton, FALSE); gchar *a = g_strconcat(currenttaskname, "当前审计任务被手动设置延迟!延迟大于60%", NULL ); gtk_button_set_label(priv->deleteresourcebutton, a); } else{ color1.red = 5000; color1.green = 35000; color1.blue = 55000; gtk_widget_modify_bg(priv->deleteresourcebutton, GTK_STATE_INSENSITIVE, &color1); gtk_widget_set_sensitive(priv->deleteresourcebutton, FALSE); gchar *a = g_strconcat(currenttaskname, "当前审计任务被手动设置延迟!延迟小于30%",NULL ); gtk_button_set_label(priv->deleteresourcebutton, a); } } delayedduration = duration*(probability*0.01+1); g_object_set (currenttask, "sched",1,NULL); g_object_set (currenttask, "duration", delayedduration, NULL); } //set task delayed time delayedtime =(delayedduration - duration) / (60 * 60 * 8); if(delayedtime >= 0){ str1 = planner_format_float(delayedtime, 2, FALSE); gtk_entry_set_text(GTK_ENTRY (priv->currentdelayentry), str1); } else{ str1 = planner_format_float(0, 2, FALSE); gtk_entry_set_text(GTK_ENTRY (priv->currentdelayentry), str1); } //delete resource // if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->deleteresourcetogglebutton)) // && (randomresourcenumber == currenttasknumber)) if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->deleteresourcetogglebutton)) && (2 == currenttasknumber)) { MrpResource *delresource = getDelRandomResourceFromTask(currenttask); gchar *s1 = mrp_task_get_name(currenttask); gchar *s2 = mrp_resource_get_name(delresource); g_printf("随机选取审计任务为 %s,退出该任务的审计人员为 %s\n", s1, s2); gtk_entry_set_text (GTK_ENTRY (priv->deleteresourceentry), s2); MrpAssignment *assignment = mrp_task_get_assignment(currenttask,delresource); mrp_object_removed(MRP_OBJECT (assignment)); currenttaskname = mrp_task_get_name(currenttask); gtk_widget_set_sensitive(priv->deleteresourcebutton,FALSE); gchar *a = g_strconcat("审计任务",s1,"的",s2,"退出该任务执行!",NULL); gtk_button_set_label(priv->deleteresourcebutton, a); } //caculat the duration chengeddurationtime = totalduration(project); priv->lasttotalduration = chengeddurationtime; str2 = planner_format_float(chengeddurationtime, 2, FALSE); gtk_entry_set_text(GTK_ENTRY (priv->lastdurationentry), str2); displayTotalDuration(view); g_source_remove (timertag); }
GtkWidget * planner_phase_dialog_new (PlannerWindow *window) { DialogData *data; GladeXML *glade; GtkWidget *dialog; GtkTreeSelection *selection; gchar *filename; g_return_val_if_fail (PLANNER_IS_WINDOW (window), NULL); filename = mrp_paths_get_glade_dir ("project-properties.glade"); glade = glade_xml_new (filename, "phase_dialog", GETTEXT_PACKAGE); g_free (filename); if (!glade) { g_warning ("Could not create phase dialog."); return NULL; } dialog = glade_xml_get_widget (glade, "phase_dialog"); data = g_new0 (DialogData, 1); data->main_window = window; data->project = planner_window_get_project (window); data->dialog = dialog; g_signal_connect_object (window, "destroy", G_CALLBACK (phase_dialog_parent_destroy_cb), dialog, 0); data->remove_button = glade_xml_get_widget (glade, "remove_button"); data->tree_view = glade_xml_get_widget (glade, "phase_treeview"); phase_dialog_setup_tree_view (data); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->tree_view)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); g_signal_connect (selection, "changed", G_CALLBACK (phase_dialog_selection_changed_cb), data); g_signal_connect (dialog, "response", G_CALLBACK (phase_dialog_response_cb), data); g_object_set_data_full (G_OBJECT (dialog), "data", data, g_free); return dialog; }
static void html_plugin_export (GtkAction *action, gpointer user_data) { PlannerPlugin *plugin; MrpProject *project; const gchar *uri; gchar *filename; gchar *basename; gint res; GtkWidget *filechooser; GtkWidget *dialog; GtkWidget *show_button; gboolean show; plugin = PLANNER_PLUGIN (user_data); filechooser = gtk_file_chooser_dialog_new (_("Export to HTML"), GTK_WINDOW (plugin->main_window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (filechooser), GTK_RESPONSE_OK); project = planner_window_get_project (plugin->main_window); uri = mrp_project_get_uri (project); if (!uri) { gchar *cwd, *tmp; cwd = g_get_current_dir (); tmp = g_strconcat (_("Unnamed"), ".html", NULL); filename = g_build_filename (cwd, tmp, NULL); g_free (cwd); g_free (tmp); } else { gchar *tmp; if (g_str_has_suffix (uri, ".planner")) { tmp = g_strndup (uri, strlen (uri) - strlen (".planner")); } else if (g_str_has_suffix (uri, ".mrproject")) { tmp = g_strndup (uri, strlen (uri) - strlen (".mrproject")); } else { tmp = g_strdup (uri); } filename = g_strconcat (tmp, ".html", NULL); g_free (tmp); } gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filechooser), filename); basename = g_path_get_basename (filename); gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (filechooser), basename); show_button = gtk_check_button_new_with_label (_("Show result in browser")); gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (filechooser), show_button); g_free (basename); g_free (filename); try_again: res = gtk_dialog_run (GTK_DIALOG (filechooser)); switch (res) { case GTK_RESPONSE_OK: filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser)); if (g_file_test (filename, G_FILE_TEST_EXISTS)) { dialog = gtk_message_dialog_new (GTK_WINDOW (filechooser), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO, _("File \"%s\" exists, do you want to overwrite it?"), filename); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES); res = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); switch (res) { case GTK_RESPONSE_YES: break; case GTK_RESPONSE_NO: case GTK_RESPONSE_DELETE_EVENT: g_free (filename); goto try_again; default: g_assert_not_reached (); } } show = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (show_button)); gtk_widget_destroy (filechooser); html_plugin_export_do (plugin, filename, show); g_free (filename); break; case GTK_RESPONSE_CANCEL: gtk_widget_destroy (filechooser); break; } }
static GtkWidget * show_view_create_widget (PlannerShowView *view) { PlannerShowViewPriv *priv; GtkWidget *pertlayout; GtkWidget *tree; GtkWidget *sw; GtkWidget *frame; GtkWidget *layout; GtkWidget *vpaned; GtkAdjustment *hadj, *vadj; GtkTreeModel *model; MrpTaskManager *task_manager; GtkLabel *label; GtkEntry *entry; GtkButton *button; GtkWidget *hbox,*vbox,*vbox2; GtkWidget *progressbar; GtkWidget *randomtogglebutton; GtkWidget *deleteresourcetogglebutton; GtkWidget *ganttcharttogglebutton; GtkWidget *manulsettogglebutton; GtkWidget *table; MrpProject *project; GtkTreeSelection *selection; GList *task_list; project = planner_window_get_project (PLANNER_VIEW (view)->main_window); task_manager = imrp_project_get_task_manager(project); priv = view->priv; g_signal_connect (project, "loaded", G_CALLBACK (show_view_project_loaded_cb), view); model = GTK_TREE_MODEL (planner_gantt_model_new (project)); tree = planner_task_tree_new (PLANNER_VIEW (view)->main_window, PLANNER_GANTT_MODEL (model), FALSE, TRUE, COL_WBS, _("WBS"), COL_NAME, _("Name"), COL_START, _("Start"), COL_FINISH, _("Finish"), COL_WORK, _("Work"), COL_DURATION, _("Duration"), COL_SLACK, _("Slack"), COL_COST, _("Cost"), COL_ASSIGNED_TO, _("Assigned to"), COL_COMPLETE, _("% Complete"), -1); priv->tree = tree; priv->gantt = planner_gantt_chart_new_with_model (model); g_object_set (priv->gantt, "header_height", 50, NULL); planner_gantt_chart_set_view (PLANNER_GANTT_CHART (priv->gantt), PLANNER_TASK_TREE (tree)); //********************* //events sensitive on gantt widget gtk_widget_set_events (GTK_WIDGET (priv->gantt), GDK_SCROLL_MASK); g_signal_connect (priv->gantt, "scroll-event", G_CALLBACK (show_view_chart_scroll_event), view); g_object_unref (model); g_signal_connect (priv->gantt, "status_updated", G_CALLBACK (show_view_gantt_status_updated_cb), view); g_signal_connect (priv->gantt, "resource_clicked", G_CALLBACK (show_view_gantt_resource_clicked_cb), view); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); //g_signal_connect (tree, //"style_set", //G_CALLBACK (show_view_tree_style_set_cb), //view); //********************* //interface design //GtkVPaned // GtkFrame -> GtkScrollWindow ->GtkLayout (pert view showed here)A // GtkHBox // GtkVBox -> GtkHBox (show run-in-time data showed here)B // GtkLabel // GtkEntry // GtkScrollWindow (gantt view showed here)C //interface design in A //GtkScrollWindow, let its scrollbar displayed if needed, put the pert view inside layout = gtk_layout_new(NULL,NULL); priv->pertlayout = layout; sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_ALWAYS, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (sw), priv->pertlayout); //GtkFrame, put the GtkScrollWindow in the GtkFrame frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); gtk_container_add (GTK_CONTAINER (frame), sw); //GtkVPaned, add the GtkFrame in the GtkVPaned vpaned = gtk_vpaned_new (); gtk_paned_add1 (GTK_PANED (vpaned), frame); //interface design in B //GtkVBox, holds labels and entry and buttons vbox = gtk_vbox_new(FALSE, 0); vbox2 = gtk_vbox_new(FALSE,0); progressbar = gtk_progress_bar_new(); //GtkLabel, "The Current Task Is: " label = gtk_label_new("当前执行审计任务: "); gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (label), FALSE, FALSE, 0); //GtkEntry, holds task name entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (entry), FALSE, FALSE, 0); priv->currenttaskentry = entry; //GtkLabel, "The Current Delay Is:: " label = gtk_label_new("当前审计延迟时间: "); gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (label), FALSE, FALSE, 0); //GtkEntry, holds task delay entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (entry), FALSE, FALSE, 0); priv->currentdelayentry = entry; //GtkLabel, "The Current duration is " label = gtk_label_new("当前审计总时间: "); gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (label), FALSE, FALSE, 0); //GtkEntry, holds total duration entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (entry), FALSE, FALSE, 0); priv->currentdurationentry = entry; //GtkLabel, "The Duration has changed :: " label = gtk_label_new("延迟后审计总时间: "); gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (label), FALSE, FALSE, 0); //GtkEntry, The Duration has changed to entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (entry), FALSE, FALSE, 0); priv->lastdurationentry = entry; lastdurationentry = entry; //GtkLabel, "delete resource" label = gtk_label_new("调整的审计人员: "); gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (label), FALSE, FALSE, 0); //GtkEntry, delete resource entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (entry), FALSE, FALSE, 0); priv->deleteresourceentry = entry; GtkWidget *labelChild; PangoFontDescription *font1; short fontSize = 8; //GtkButton, delete resource button = gtk_button_new_with_label("重大事项显示"); GdkColor color; color.red = 50000; color.green = 20000; color.blue = 15000; gtk_widget_modify_bg(button, GTK_STATE_INSENSITIVE, &color); // font1 = pango_font_description_from_string("Sans");//"Sans"字体名 //pango_font_description_set_size(font1, fontSize * PANGO_SCALE);//设置字体大小 // labelChild = gtk_bin_get_child(GTK_BIN(button));//取出GtkButton里的label gtk_widget_modify_font(GTK_WIDGET(labelChild), font1);//设置label的字体, 这样这个GtkButton上面显示的字体就变了 gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (button), FALSE,FALSE, 0); g_signal_connect (button, "clicked", G_CALLBACK (show_view_delete_resource_cb), view); priv->deleteresourcebutton = button; //total duration display button = gtk_button_new_with_label("审计总时间无延迟"); GdkColor color1; color1.red = 50000; color1.green = 20000; color1.blue = 15000; gtk_widget_modify_bg(button, GTK_STATE_INSENSITIVE, &color1); // font1 = pango_font_description_from_string("Sans");//"Sans"字体名 // pango_font_description_set_size(font1, fontSize * PANGO_SCALE);//设置字体大小 // labelChild = gtk_bin_get_child(GTK_BIN(button));//取出GtkButton里的label gtk_widget_modify_font(GTK_WIDGET(labelChild), font1);//设置label的字体, 这样这个GtkButton上面显示的字体就变了 gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (button), FALSE,FALSE, 0); g_signal_connect(button, "clicked", G_CALLBACK (show_view_delete_resource_cb), view); priv->displaytotaldurationbutton = button; //GtkButton, go to next task button = gtk_button_new_with_label("执行下一审计任务"); GdkColor color2; color2.red = 50000; color2.green = 10000; color2.blue = 10000; gtk_widget_modify_bg(button, GTK_STATE_INSENSITIVE, &color2); // font1 = pango_font_description_from_string("Sans");//"Sans"字体名 // pango_font_description_set_size(font1, fontSize * PANGO_SCALE);//设置字体大小 // labelChild = gtk_bin_get_child(GTK_BIN(button));//取出GtkButton里的label gtk_widget_modify_font(GTK_WIDGET(labelChild), font1);//设置label的字体, 这样这个GtkButton上面显示的字体就变了 gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (button), FALSE,FALSE, 0); g_signal_connect (button, "clicked", G_CALLBACK (show_view_next_task_cb), view); priv->nextstepbutton = button; table = gtk_table_new(2, 2, FALSE); manulsettogglebutton = gtk_toggle_button_new_with_label("手动设置审计任务延迟"); gtk_widget_set_size_request(manulsettogglebutton,5,7); font1 = pango_font_description_from_string("Sans");//"Sans"字体名 pango_font_description_set_size(font1, fontSize * PANGO_SCALE);//设置字体大小 labelChild = gtk_bin_get_child(GTK_BIN( manulsettogglebutton));//取出GtkButton里的label gtk_widget_modify_font(GTK_WIDGET(labelChild), font1);//设置label的字体, 这样这个GtkButton上面显示的字体就变了 randomtogglebutton = gtk_toggle_button_new_with_label("随机设置审计任务延迟"); font1 = pango_font_description_from_string("Sans");//"Sans"字体名 pango_font_description_set_size(font1, fontSize * PANGO_SCALE);//设置字体大小 labelChild = gtk_bin_get_child(GTK_BIN( randomtogglebutton));//取出GtkButton里的label gtk_widget_modify_font(GTK_WIDGET(labelChild), font1);//设置label的字体, 这样这个GtkButton上面显示的字体就变了 deleteresourcetogglebutton = gtk_toggle_button_new_with_label("参审人员随机调整"); font1 = pango_font_description_from_string("Sans");//"Sans"字体名 pango_font_description_set_size(font1, fontSize * PANGO_SCALE);//设置字体大小 labelChild = gtk_bin_get_child(GTK_BIN( deleteresourcetogglebutton));//取出GtkButton里的label gtk_widget_modify_font(GTK_WIDGET(labelChild), font1);//设置label的字体, 这样这个GtkButton上面显示的字体就变了 ganttcharttogglebutton = gtk_toggle_button_new_with_label("干特图路径选择"); font1 = pango_font_description_from_string("Sans");//"Sans"字体名 pango_font_description_set_size(font1, fontSize * PANGO_SCALE);//设置字体大小 labelChild = gtk_bin_get_child(GTK_BIN( ganttcharttogglebutton));//取出GtkButton里的label gtk_widget_modify_font(GTK_WIDGET(labelChild), font1);//设置label的字体, 这样这个GtkButton上面显示的字体就变了 gtk_table_set_row_spacings(GTK_TABLE(table), 2); gtk_table_set_col_spacings(GTK_TABLE(table), 2); gtk_table_attach_defaults(GTK_TABLE(table), manulsettogglebutton, 0, 1, 0,1); gtk_table_attach_defaults(GTK_TABLE(table), randomtogglebutton, 0, 1, 1, 2); gtk_table_attach_defaults(GTK_TABLE(table), deleteresourcetogglebutton, 1, 2, 0, 1); gtk_table_attach_defaults(GTK_TABLE(table), ganttcharttogglebutton, 1, 2, 1, 2); gtk_signal_connect(GTK_OBJECT(randomtogglebutton), "toggle", GTK_SIGNAL_FUNC(select_random_task), view); gtk_signal_connect(GTK_OBJECT(deleteresourcetogglebutton), "toggle", GTK_SIGNAL_FUNC(select_deleteresource), view); priv->manulsettogglebutton = manulsettogglebutton; priv->randomtogglebutton = randomtogglebutton; priv->deleteresourcetogglebutton = deleteresourcetogglebutton; priv->ganttcharttogglebutton = ganttcharttogglebutton; //gtk_table_attach_defaults(GTK_TABLE(table), labelprobability,1,2,2,3); // gtk_table_attach_defaults(GTK_TABLE(table), togglebutton,0,2,3,4); gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (table), FALSE, FALSE, 0); //GtkButton, auto optimization button = gtk_button_new_with_label("Auto Optimization"); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_ALWAYS, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (sw), priv->gantt); gtk_box_pack_start(GTK_BOX (vbox2), GTK_WIDGET (sw), TRUE, TRUE,0); gtk_widget_set_size_request(progressbar,150,36); gtk_box_pack_start(GTK_BOX (vbox2), GTK_WIDGET (progressbar), FALSE, FALSE, 0); priv->progressbar = progressbar; //put the GtkHBox in the GtkFrame, put the GtkVBox and GtkScrollWindow in the GtkHBox hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX (hbox), GTK_WIDGET (vbox), FALSE,TRUE, 0); gtk_box_pack_end(GTK_BOX (hbox), GTK_WIDGET (vbox2), TRUE, TRUE, 10); frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (hbox)); //add the GtkFrame in the GtkVPaned gtk_paned_add2 (GTK_PANED (vpaned), frame); gtk_paned_set_position (GTK_PANED (vpaned), 250); g_signal_connect (tree, "row_expanded", G_CALLBACK (show_view_row_expanded), priv->gantt); g_signal_connect (tree, "row_collapsed", G_CALLBACK (show_view_row_collapsed), priv->gantt); gtk_tree_view_expand_all (GTK_TREE_VIEW (tree)); return vpaned; }