Beispiel #1
0
void
on_unstage_button_clicked (GtkAction *action, Git *plugin)
{
	GList *paths;
	GitResetFilesCommand *reset_command;

	paths = git_status_pane_get_checked_commit_items (GIT_STATUS_PANE (plugin->status_pane),
	                                                  ANJUTA_VCS_STATUS_ALL);

	if (paths)
	{
		reset_command = git_reset_files_command_new (plugin->project_root_directory,
		                                             GIT_RESET_FILES_HEAD,
		                                             paths);

		anjuta_util_glist_strings_free (paths);

		g_signal_connect (G_OBJECT (reset_command), "command-finished",
		                  G_CALLBACK (git_pane_report_errors),
		                  plugin);


		g_signal_connect (G_OBJECT (reset_command), "command-finished",
		                  G_CALLBACK (g_object_unref),
		                  NULL);

		anjuta_command_start (ANJUTA_COMMAND (reset_command));
	}
	else
		anjuta_util_dialog_error (NULL, _("No staged files selected."));
}
Beispiel #2
0
NPWDruid*
npw_druid_new (NPWPlugin* plugin, GFile *templates)
{
	NPWDruid* druid;

	/* Check if autogen is present */
	if (!anjuta_check_autogen())
	{
		anjuta_util_dialog_error (NULL, _("Could not find autogen version 5; please install the autogen package. You can get it from http://autogen.sourceforge.net."));
		return NULL;
	}

	druid = g_new0(NPWDruid, 1);
	druid->plugin = plugin;
	druid->project_file = NULL;
	druid->busy = FALSE;
	druid->no_selection = FALSE;
	druid->page_list = g_queue_new ();
	druid->values = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_free);
	druid->gen = anjuta_autogen_new ();
	plugin->druid = druid;
	druid->error_extra_widget = NULL;

	if (npw_druid_create_assistant (druid, templates) == NULL)
	{
		npw_druid_free (druid);

		return NULL;
	}

	npw_druid_add_default_property (druid);

	return druid;
}
Beispiel #3
0
static void
checkout_finished (AnjutaAsyncNotify *async_notify, gpointer user_data)
{
	CheckoutData *ch = (CheckoutData *)user_data;
	GError *err;

	err = NULL;
	anjuta_async_notify_get_error (async_notify, &err);
	if (err)
	{
		gchar *vcs_uri;

		/* show the dialog since it's hidden */
		gtk_widget_show (GTK_WIDGET (ch->import_dialog));
		
		vcs_uri = project_import_dialog_get_vcs_uri (ch->import_dialog);
		anjuta_util_dialog_error (GTK_WINDOW (ch->import_dialog),
		                          _("Couldn't check out the supplied URI "
		                          "\"%s\". The error returned was: \"%s\""),
		                          vcs_uri, err->message);

		g_free (vcs_uri);
		g_error_free (err);

		goto cleanup;
	}

	project_import_import_project (ch->import_plugin, ch->import_dialog, ch->checkout_dir);

cleanup:
	g_object_unref (ch->checkout_dir);
	g_slice_free (CheckoutData, ch);
}
Beispiel #4
0
static void
attach_process_update (AttachProcess * ap)
{
	gchar *tmp, *tmp1, *cmd;
	gchar *shell;
	gchar *argv[4];
	GError *err = NULL;
	GtkTreeStore *store;
	gboolean result;

	g_return_if_fail (ap);
	store = GTK_TREE_STORE (gtk_tree_view_get_model
							(GTK_TREE_VIEW (ap->treeview)));
	g_return_if_fail (store);
	
	if (anjuta_util_prog_is_installed ("ps", TRUE) == FALSE)
		return;

	tmp = anjuta_util_get_a_tmp_file ();
#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
	cmd = g_strconcat ("ps axw -o pid,user,lstart,args > ", tmp, NULL);
#else
	cmd = g_strconcat ("ps axw -H -o pid,user,start_time,args > ", tmp, NULL);
#endif
	shell = anjuta_util_user_shell ();
	argv[0] = shell;
	argv[1] = "-c";
	argv[2] = cmd;
	argv[3] = NULL;
	if (!g_spawn_sync (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL, NULL, &err))
	{
		anjuta_util_dialog_error (NULL, _("Unable to execute: \"%s\". "
		                                  "The returned error was: \"%s\"."), cmd, err->message);
		g_error_free (err);
		g_free (tmp);
		g_free (cmd);
		return;
	}

	g_free (cmd);

	result = g_file_get_contents (tmp, &tmp1, NULL, NULL);
	remove (tmp);
	g_free (tmp);
	if (! result)
	{
		anjuta_util_dialog_error_system (NULL, errno,
										 _("Unable to open the file: %s\n"),
										 tmp);
		return;
	}

	attach_process_clear (ap, CLEAR_UPDATE);
	ap->ps_output = anjuta_util_convert_to_utf8 (tmp1);
	g_free (tmp1);
	if (ap->ps_output)
	{
		attach_process_review (ap);
	}
}
Beispiel #5
0
static void
project_import_checkout_project (AnjutaProjectImportPlugin *import_plugin,
                                 ProjectImportDialog *import_dialog)
{
	CheckoutData *ch_data;
	AnjutaAsyncNotify *async_notify;
	gchar *vcs_uri, *plugin_id, *name;
	GFile *dest_dir, *checkout_dir;
	AnjutaPluginManager *plugin_manager;
	IAnjutaVcs *ivcs;
	GError *err;

	name = project_import_dialog_get_name (import_dialog);
	dest_dir = project_import_dialog_get_dest_dir (import_dialog);
	checkout_dir = g_file_get_child (dest_dir, name);

	g_object_unref (dest_dir);
	g_free (name);
	
	ch_data = g_slice_new (CheckoutData);
	ch_data->import_plugin = import_plugin;
	ch_data->import_dialog = import_dialog;
	ch_data->checkout_dir = checkout_dir;
	
	async_notify = anjuta_async_notify_new ();
	g_signal_connect (async_notify, "finished", G_CALLBACK (checkout_finished),
	                  ch_data);

	vcs_uri = project_import_dialog_get_vcs_uri (import_dialog);
	plugin_id = project_import_dialog_get_vcs_id (import_dialog);

	plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN (import_plugin)->shell, NULL);
	ivcs = IANJUTA_VCS (anjuta_plugin_manager_get_plugin_by_id (plugin_manager, plugin_id));

	err = NULL;
	ianjuta_vcs_checkout (ivcs, vcs_uri, checkout_dir, NULL, async_notify, &err);
	if (err)
	{
		anjuta_util_dialog_error (GTK_WINDOW (import_dialog),
		                          _("Couldn't check out the supplied URI "
		                            "\"%s\". The error returned was: \"%s\""),
		                          vcs_uri, err->message);

		g_error_free (err);
		
		goto cleanup;
	}

	/* hide the import dialog */
	gtk_widget_hide (GTK_WIDGET (import_dialog));

cleanup:
	g_free (vcs_uri);
	g_free (plugin_id);
}
Beispiel #6
0
void
on_commit_diff_button_clicked (GtkAction *action, Git *plugin)
{
	GitRevision *revision;
	gchar *sha;
	gchar *short_sha;
	gchar *editor_name;
	IAnjutaDocumentManager *document_manager;
	IAnjutaEditor *editor;
	GitDiffTreeCommand *diff_command;
	
	revision = git_log_pane_get_selected_revision (GIT_LOG_PANE (plugin->log_pane));
	
	if (revision)
	{
		sha = git_revision_get_sha (revision);
		short_sha = git_revision_get_short_sha (revision);
		/* Translators: file name for an existing commits diff, %s is an SHASUM of a commit */
		editor_name = g_strdup_printf (_("Commit %s.diff"), short_sha);
		
		document_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
													   IAnjutaDocumentManager, 
													   NULL);
		editor = ianjuta_document_manager_add_buffer (document_manager, 
													  editor_name,
													  "", NULL);
		
		diff_command = git_diff_tree_command_new (plugin->project_root_directory,
												  sha);
		
		g_signal_connect (G_OBJECT (diff_command), "data-arrived",
						  G_CALLBACK (git_pane_send_raw_output_to_editor),
						  editor);
		
		g_signal_connect (G_OBJECT (diff_command), "command-finished",
						  G_CALLBACK (git_pane_report_errors),
						  plugin);

		g_signal_connect (G_OBJECT (diff_command), "command-finished",
						  G_CALLBACK (g_object_unref),
						  NULL);

		
		anjuta_command_start (ANJUTA_COMMAND (diff_command));

		g_object_unref (revision);
		g_free (sha);
		g_free (short_sha);
		g_free (editor_name);
	}
	else
		anjuta_util_dialog_error (NULL, _("No revision selected"));
}
Beispiel #7
0
BuildContext*
build_compile_file (BasicAutotoolsPlugin *plugin, GFile *file)
{
	BuildContext *context = NULL;
	BuildProgram *prog;
	GFile *object;
	gchar *target_name;

	g_return_val_if_fail (file != NULL, FALSE);

	object = build_object_from_file (plugin, file);
	if (object != NULL)
	{
		GFile *build_dir;
		BuildConfiguration *config;
		GList *vars;

		config = build_configuration_list_get_selected (plugin->configurations);
		vars = build_configuration_get_variables (config);

		/* Find target directory */
		build_dir = build_file_from_file (plugin, object, &target_name);

		prog = build_program_new_with_command (build_dir, "%s %s",
	    	                                   CHOOSE_COMMAND(plugin, COMPILE),
	        	                               (target_name == NULL) ? "" : target_name);
		g_free (target_name);
		g_object_unref (build_dir);

		build_program_add_env_list (prog, vars);

		context = build_save_and_execute_command (plugin, prog, TRUE, NULL);
		g_object_unref (object);
	}
	else
	{
		/* FIXME: Prompt the user to create a Makefile with a wizard
		   (if there is no Makefile in the directory) or to add a target
		   rule in the above hash table, eg. editing the preferences, if
		   there is target extension defined for that file extension.
		*/
		GtkWindow *window;
		gchar *filename;

		filename = g_file_get_path (file);
		window = GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell);
		anjuta_util_dialog_error (window, _("Cannot compile \"%s\": No compile rule defined for this file type."), filename);
		g_free (filename);
	}

	return context;
}
Beispiel #8
0
void
report_errors (AnjutaCommand *command, guint return_code)
{
	gchar *message;
	
	if (return_code != 0)
	{
		message = anjuta_command_get_error_message (command);
		
		anjuta_util_dialog_error (NULL, message);
		g_free (message);
	}
}
Beispiel #9
0
void
on_cvs_remove_response(GtkDialog* dialog, gint response, CVSData* data)
{
	GFile* file;

	if (is_busy(data->plugin, dialog))
		return;
	
	switch (response)
	{
	case GTK_RESPONSE_OK:
	{
		GtkWidget* fileentry = GTK_WIDGET(gtk_builder_get_object(data->bxml, "cvs_remove_filename"));
		const gchar* filename = gtk_entry_get_text(GTK_ENTRY(fileentry));
		
		if (!check_filename(dialog, filename))
			break;

		file = g_file_new_for_uri(gtk_entry_get_text(GTK_ENTRY(fileentry)));
		if (!g_file_delete(file, NULL, NULL))
		{
			anjuta_util_dialog_error
				(GTK_WINDOW(dialog),_("Unable to delete file"), NULL);
			gtk_widget_destroy(GTK_WIDGET(dialog));
			cvs_data_free(data);
			break;
		}
		g_object_unref(G_OBJECT(file));
	
		anjuta_cvs_remove(ANJUTA_PLUGIN(data->plugin), filename, NULL);
		gtk_widget_destroy (GTK_WIDGET(dialog));
		cvs_data_free(data);
		break;
		}
	default:
		cvs_data_free(data);
		gtk_widget_destroy (GTK_WIDGET(dialog));
	}
}
Beispiel #10
0
static gchar *
get_local_directory (GtkWindow *parent, const gchar *uri)
{
	const gchar *err_msg = NULL;
	gchar *local = NULL;

	if (uri != NULL)
	{
		local = anjuta_util_get_local_path_from_uri (uri);
		if (local == NULL)
		{
			/* Only local directory are supported */
			err_msg = _("Program directory '%s' is not local");
		}
	}
	
	if (err_msg)
	{
		anjuta_util_dialog_error (parent, err_msg, uri);
	}
	
	return local;
}
Beispiel #11
0
static gchar *
get_local_executable (GtkWindow *parent, const gchar *uri)
{
	const gchar *err_msg = NULL;
	gchar *local = NULL;

	if (uri != NULL)
	{
		local = anjuta_util_get_local_path_from_uri (uri);
		if (local == NULL)
		{
			/* Only local program are supported */
			err_msg = _("Program '%s' is not a local file");
		}
		else
		{
			if (g_file_test (local, G_FILE_TEST_EXISTS) == FALSE)
			{
				err_msg = _("Program '%s' does not exist");
			}
			else if (g_file_test (local, G_FILE_TEST_IS_EXECUTABLE) == FALSE)
			{
				err_msg = _("Program '%s' does not have execution permission");
			}
		}
	}

	if (err_msg)
	{	
		anjuta_util_dialog_error (parent, err_msg, local == NULL ? uri : local);
		g_free (local);
		local = NULL;
	}
	
	return local;
}
Beispiel #12
0
static gboolean
project_import_generate_file (AnjutaPluginDescription *backend, ProjectImportDialog *import_dialog,
                              GFile *project_file)
{
	/* Of course we could do some more intelligent stuff here
	 * and check which plugins are really needed */
	
	GFile* source_file = NULL;
	gchar *backend_id = NULL;
	GError* error = NULL;

	if (!anjuta_plugin_description_get_string (backend, "Project", "Supported-Project-Types", &backend_id))
	{
		if (!strcmp (backend_id, "automake"))
			source_file = g_file_new_for_path (AM_PROJECT_FILE);
		else if (!strcmp (backend_id, "make"))
			source_file = g_file_new_for_path (MKFILE_PROJECT_FILE);
		else if (!strcmp (backend_id, "directory"))
			source_file = g_file_new_for_path (DIRECTORY_PROJECT_FILE);
	}
	g_free (backend_id);
	
	if (source_file != NULL)
	{
		/* Use a default project file */
		if (!g_file_copy (source_file, project_file, 
				G_FILE_COPY_NONE,
				NULL,
				NULL,
				NULL,
				&error))
		{
			if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_EXISTS)
			{
				gchar *prjfile = g_file_get_parse_name (project_file);
				if (anjuta_util_dialog_boolean_question (GTK_WINDOW (import_dialog), FALSE,
						_("A file named \"%s\" already exists. "
						  "Do you want to replace it?"), prjfile))
				{
					g_error_free (error);
					error = NULL;
					g_file_copy (source_file, project_file,
							G_FILE_COPY_OVERWRITE,
							NULL,
							NULL,
							NULL,
							&error);
				}
				g_free (prjfile);
			}
		}

		if (!error)
		{
			time_t ctime = time(NULL);
			GFileInfo* file_info = g_file_info_new();
			g_file_info_set_attribute_uint64(file_info, 
					"time::modified",
					ctime);
			g_file_info_set_attribute_uint64(file_info, 
					"time::created",
					ctime);
			g_file_info_set_attribute_uint64(file_info, 
					"time::access",
					ctime);
			g_file_set_attributes_from_info (project_file, 
					file_info,
					G_FILE_QUERY_INFO_NONE,
					NULL, NULL);

			g_object_unref (G_OBJECT(file_info));;
		}
	}
	else
	{
		/* For unknown project backend we use the directory project file and
		 * replace the backend plugin with the right one */

		gchar *content;
		gsize length;

		source_file = g_file_new_for_path (DIRECTORY_PROJECT_FILE);
		if (g_file_load_contents (source_file, NULL, &content, &length, NULL, &error))
		{
			GString *buffer;
			const gchar *pos;
			const gchar *plugin;
			const gchar *end_plugin;
			gssize len;

			buffer = g_string_new_len (content, length);
			pos = buffer->str;
			len = buffer->len;
			for (;;)
			{
				plugin = g_strstr_len (pos, len, "<plugin ");
				if (plugin == NULL) break;
				
				end_plugin = g_strstr_len (plugin, len - (plugin - pos), "</plugin>");
				if (end_plugin == NULL) break;
				
				if (g_strstr_len (plugin, end_plugin - plugin, "\"IAnjutaProjectBackend\"") != NULL) break;

				pos = end_plugin + 9;
				len -= (end_plugin + 9 - pos);
			}

			if ((plugin == NULL) || (end_plugin == NULL))
			{
				g_set_error (&error, ianjuta_project_backend_error_quark(),0, "Unable to find backend plugin");
			}
			else
			{
				/* Replace directory backend with right one */
				GString *str;
				GFileOutputStream *stream;
				gchar *name = NULL;
				gchar *plugin_id = NULL;

				anjuta_plugin_description_get_string (backend, "Anjuta Plugin", "Name", &name);
				anjuta_plugin_description_get_string (backend, "Anjuta Plugin", "Location", &plugin_id);

				str = g_string_new (NULL);
				g_string_printf (str, "<plugin name= \"%s\"\n"
				                 "            mandatory=\"yes\">\n"
				                 "         <require group=\"Anjuta Plugin\"\n"
				                 "                  attribute=\"Location\"\n"
				                 "                  value=\"%s\"/>\n"
				                 "         <require group=\"Anjuta Plugin\"\n"
				                 "                  attribute=\"Interfaces\"\n"
				                 "                  value=\"IAnjutaProjectBackend\"/>\n"
				                 "    ", name, plugin_id);
					
				g_string_erase (buffer, plugin - buffer->str, end_plugin - plugin);
				g_string_insert_len (buffer, plugin - buffer->str, str->str, str->len);

				g_string_free (str, TRUE);

				stream = g_file_create (project_file, G_FILE_CREATE_NONE, NULL, &error);
				if (stream == NULL && error->domain == G_IO_ERROR && error->code == G_IO_ERROR_EXISTS)
				{
					gchar *prjfile = g_file_get_parse_name (project_file);
					if (anjuta_util_dialog_boolean_question (GTK_WINDOW (import_dialog), FALSE,
							_("A file named \"%s\" already exists. "
							  "Do you want to replace it?"), prjfile))
					{
						g_error_free (error);
						error = NULL;
						stream = g_file_replace (project_file, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error);
					}
					g_free (prjfile);
				}
					
				if (stream != NULL)
				{
					gsize written;
					
					g_output_stream_write_all (G_OUTPUT_STREAM (stream), buffer->str, buffer->len, &written, NULL, &error);
					g_output_stream_close (G_OUTPUT_STREAM (stream), NULL, NULL);
				}
			}

			g_string_free (buffer, TRUE);
			g_free (content);
		}
	}
	g_object_unref (source_file);

	if (error)
	{
		gchar *prjfile;

		prjfile = g_file_get_parse_name (project_file);
		
		/* show the dialog since it may be hidden */
		gtk_widget_show (GTK_WIDGET (import_dialog));
		
		anjuta_util_dialog_error (GTK_WINDOW (import_dialog),
				_("A file named \"%s\" cannot be written: %s. "
				  "Check if you have write access to the project directory."),
				  prjfile, error->message);
		g_free (prjfile);
		g_error_free (error);
		
		return FALSE;

	}

	return TRUE;
}
Beispiel #13
0
static void
build_configure_after_autogen (GObject *sender,
							   IAnjutaBuilderHandle handle,
							   GError *error,
							   gpointer user_data)
{
	BuildConfigureAndBuild *pack = (BuildConfigureAndBuild *)user_data;

	if (error == NULL)
	{
		BuildContext *context = (BuildContext *)handle;
		BuildConfiguration *config;
		GList *vars;
		BasicAutotoolsPlugin *plugin = (BasicAutotoolsPlugin *)build_context_get_plugin (context);
		struct stat conf_stat, log_stat;
		gchar *root_path;
		gchar *filename;
		gboolean has_configure;

		root_path = g_file_get_path (plugin->project_root_dir);
		filename = g_build_filename (root_path, "configure", NULL);
		has_configure = stat (filename, &conf_stat) == 0;
		g_free (filename);

		if (has_configure)
		{
			gboolean older;

			config = build_configuration_list_get_selected (plugin->configurations);
			vars = build_configuration_get_variables (config);

			filename = g_build_filename (build_context_get_work_dir (context), "config.status", NULL);
			older =(stat (filename, &log_stat) != 0) || (log_stat.st_mtime < conf_stat.st_mtime);
			g_free (filename);

			if (older)
			{
				/* configure has not be run, run it */
				BuildProgram *prog;
				gchar *quote;
				GFile *work_file;

				quote = shell_quotef ("%s%s%s",
					     	root_path,
					       	G_DIR_SEPARATOR_S,
					       	CHOOSE_COMMAND (plugin, CONFIGURE));

				work_file = g_file_new_for_path (build_context_get_work_dir (context));
				prog = build_program_new_with_command (work_file,
													   "%s %s",
													   quote,
													   pack != NULL ? pack->args : NULL);
				g_object_unref (work_file);
				g_free (quote);
				build_program_set_callback (prog, build_project_configured, pack);
				build_program_add_env_list (prog, vars);

				build_set_command_in_context (context, prog);
				build_execute_command_in_context (context, NULL);
			}
			else
			{
				/* run next command if needed */
				build_project_configured (sender, handle, NULL, pack);
			}

			g_free (root_path);
			return;
		}
		else
		{
			anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell), _("Cannot configure project: Missing configure script in %s."), root_path);
			g_free (root_path);
		}
	}

	if (pack)
	{
		g_free (pack->args);
		if (pack->file != NULL) g_object_unref (pack->file);
		g_free (pack);
	}
}
Beispiel #14
0
void gtkpod_init(int argc, char *argv[]) {
    AnjutaPluginManager *plugin_manager;
    AnjutaProfileManager *profile_manager;
    AnjutaApp *app;
    AnjutaStatus *status;
    AnjutaProfile *profile;
    GFile *session_profile;
    GError *error = NULL;

    gchar *default_profile_file = NULL;
    gchar *user_profile_file = NULL;

    gchar *ui_file = NULL;
    gchar *remembered_plugins = NULL;
    gchar *session_dir = NULL;
    gchar *splash = NULL;

    /* Initialise important directories */
    init_directories(argv);

    register_stock_icon(GTKPOD_ICON, GTKPOD_ICON_STOCK_ID);

    /* Initialise the ui file */
    ui_file = g_build_filename(get_ui_dir(), "gtkpod.ui", NULL);
    anjuta_set_ui_file_path(ui_file);

    /* Register the application icon */
    register_stock_icon("gtkpod", GTKPOD_APP_ICON_STOCK_ID);

    /* Initialize application class instance*/
    app = ANJUTA_APP(anjuta_app_new());
    gtkpod_app = GTKPOD_APP(app);

    /* Initialise the preferences as required for the display of the splash screen */
    prefs_init(argc, argv);

    /* Show some progress as the app is initialised */
    status = anjuta_shell_get_status(ANJUTA_SHELL(app), NULL);
    anjuta_status_progress_add_ticks(status, 1);

    /* Show the splash screen if user requires */
    if (! prefs_get_int(DISABLE_SPLASH_SCREEN)) {
        splash = g_build_filename(get_icon_dir(), "gtkpod-splash.png", NULL);
        if (g_file_test(splash, G_FILE_TEST_IS_REGULAR))
            anjuta_status_set_splash(status, splash, 100);
        else {
            anjuta_status_disable_splash(status, TRUE);
        }

        g_free(splash);
    }

    /*
     * initialise gtkpod library items. Needs to be safety threaded due
     * to splash screen.
     */
    gdk_threads_enter();
    gp_init(argc, argv);
    gdk_threads_leave();

    /* Add blocking widgets from the framework */
    add_blocked_widget(app->toolbar);
    add_blocked_widget(app->view_menu);

    /* Set up shutdown signals */
    g_signal_connect(G_OBJECT(app), "delete_event", G_CALLBACK(
                    on_gtkpod_delete_event), NULL);
    g_signal_connect(G_OBJECT(app), "destroy", G_CALLBACK(on_gtkpod_destroy),
            NULL);

    plugin_manager = anjuta_shell_get_plugin_manager(ANJUTA_SHELL(app), NULL);
    profile_manager = anjuta_shell_get_profile_manager(ANJUTA_SHELL(app), NULL);

    /* Restore remembered plugins */
    remembered_plugins = g_settings_get_string(app->settings, GTKPOD_REMEMBERED_PLUGINS);
    if (remembered_plugins)
        anjuta_plugin_manager_set_remembered_plugins(plugin_manager, remembered_plugins);
    g_free(remembered_plugins);

    /* Load default profile */
    default_profile_file = get_default_profile_path();
    profile = anjuta_profile_new(USER_PROFILE_NAME, plugin_manager);
    session_profile = g_file_new_for_path(default_profile_file);
    anjuta_profile_add_plugins_from_xml(profile, session_profile, TRUE, &error);
    if (error) {
        anjuta_util_dialog_error(GTK_WINDOW(app), "%s", error->message);
        g_error_free(error);
        error = NULL;
    }
    g_object_unref(session_profile);
    g_free(default_profile_file);

    /* Load user session profile */
    user_profile_file = get_user_profile_path();
    session_profile = g_file_new_for_path(user_profile_file);
    if (g_file_query_exists(session_profile, NULL)) {
        anjuta_profile_add_plugins_from_xml(profile, session_profile, FALSE, &error);
        if (error) {
            anjuta_util_dialog_error(GTK_WINDOW(app), "%s", error->message);
            g_error_free(error);
            error = NULL;
        }
    }
    anjuta_profile_set_sync_file(profile, session_profile);
    g_object_unref(session_profile);
    g_free(user_profile_file);

    /* Load profile */
    anjuta_profile_manager_freeze(profile_manager);
    anjuta_profile_manager_push(profile_manager, profile, &error);
    if (error) {
        anjuta_util_dialog_error(GTK_WINDOW(app), "%s", error->message);
        g_error_free(error);
        error = NULL;
    }

    /* Prepare for session save and load on profile change */
    g_signal_connect (profile_manager, "profile-scoped",
            G_CALLBACK (on_profile_scoped), app);

    anjuta_profile_manager_thaw(profile_manager, &error);

    if (error) {
        anjuta_util_dialog_error(GTK_WINDOW(app), "%s", error->message);
        g_error_free(error);
        error = NULL;
    }

    g_signal_connect (profile_manager, "profile-descoped",
            G_CALLBACK (on_profile_descoped), app);

    gdk_threads_enter();
    gp_init_itdbs();
    gdk_threads_leave();

    /* Load layout.*/
    session_dir = get_user_session_dir();
    if (!g_file_test(session_dir, G_FILE_TEST_IS_DIR))
        session_dir = g_strdup(get_data_dir());

    /* Restore session */
    anjuta_shell_session_load(ANJUTA_SHELL(app), session_dir, NULL);
    g_free(session_dir);

    anjuta_status_progress_tick(status, NULL, _("Loaded Session..."));
    anjuta_status_disable_splash(status, TRUE);

    gtk_window_set_default_icon_name("gtkpod");
    gtk_window_set_auto_startup_notification(TRUE);

    gtk_window_set_role(GTK_WINDOW(app), "gtkpod-app");
    gtk_widget_show(GTK_WIDGET(app));
}
Beispiel #15
0
/* Fill project selection page */
static gboolean
npw_druid_fill_selection_page (NPWDruid* druid, GFile *templates)
{
	gchar* dir;
	const gchar * const * sys_dir;

	/* Remove all previous data */
	gtk_notebook_remove_page(druid->project_book, 0);
	npw_header_list_free (druid->header_list);
	anjuta_autogen_clear_library_path (druid->gen);

	/* Create list of projects */
	druid->header_list = npw_header_list_new ();

	if (templates != NULL)
	{
		if (g_file_query_file_type (templates, 0, NULL) == G_FILE_TYPE_DIRECTORY)
		{
			/* Read project template only in specified directory,
		 	 * other directories can still be used to get included
		 	 * files */
			gchar *directory = g_file_get_path (templates);

			npw_header_list_readdir (&druid->header_list, directory);
			anjuta_autogen_set_library_path (druid->gen, directory);
			g_free (directory);
		}
		else
		{
			/* templates is a file, so read only it as a project template */
			gchar *filename = g_file_get_path (templates);
			npw_header_list_read (&druid->header_list, filename);
			g_free (filename);
		}
	}

	dir = g_build_filename (g_get_user_data_dir (), "anjuta", "templates", NULL);
	if (templates == NULL)
	{
		/* Read project template in user directory,
		 * normally ~/.local/share/anjuta/templates,
	 	* the first template read override the others */
		npw_header_list_readdir (&druid->header_list, dir);
	}
	anjuta_autogen_set_library_path (druid->gen, dir);
	g_free (dir);

	for (sys_dir = g_get_system_data_dirs (); *sys_dir != NULL; sys_dir++)
	{
		dir = g_build_filename (*sys_dir, "anjuta", "templates", NULL);
		if (templates == NULL)
		{
			/* Read project template in system directory */
			npw_header_list_readdir (&druid->header_list, dir);
		}
		anjuta_autogen_set_library_path (druid->gen, dir);
		g_free (dir);
	}

	if (templates == NULL)
	{
		/* Read anjuta installation directory */
		npw_header_list_readdir (&druid->header_list, PROJECT_WIZARD_DIRECTORY);
	}
	anjuta_autogen_set_library_path (druid->gen, PROJECT_WIZARD_DIRECTORY);

	switch (g_list_length (druid->header_list))
	{
	case 0:
		anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (druid->plugin)->shell),_("Unable to find any project template in %s"), PROJECT_WIZARD_DIRECTORY);
		return FALSE;
	case 1:
		druid->header = (NPWHeader *)((GList *)druid->header_list->data)->data;
		druid->no_selection = TRUE;
		gtk_container_remove (GTK_CONTAINER (druid->window), druid->project_page);
		gtk_assistant_insert_page (GTK_ASSISTANT (druid->window), druid->progress_page, 0);
		npw_druid_set_busy (druid, FALSE);
		break;
	default:
		/* Add all necessary notebook page */
		druid->no_selection = FALSE;
		g_list_foreach (druid->header_list, cb_druid_insert_project_page, druid);
		gtk_widget_show_all (GTK_WIDGET (druid->project_book));
	}

	return TRUE;
}
Beispiel #16
0
static gboolean
project_import_import_project (AnjutaProjectImportPlugin *import_plugin, ProjectImportDialog *import_dialog,
                               GFile *source_dir)
{
	AnjutaPluginManager *plugin_manager;
	GList *descs = NULL;
	GList *desc;
	AnjutaPluginDescription *backend;
	gchar *name, *project_file_name;

	/* Search for all valid project backend */
	plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN(import_plugin)->shell, NULL);
	descs = anjuta_plugin_manager_query (plugin_manager,
										 "Anjuta Plugin",
										 "Interfaces",
										 "IAnjutaProjectBackend",
										 NULL);	
	for (desc = g_list_first (descs); desc != NULL;) {
		IAnjutaProjectBackend *plugin;
		gchar *location = NULL;
		GList *next;
		
		backend = (AnjutaPluginDescription *)desc->data;
		anjuta_plugin_description_get_string (backend, "Anjuta Plugin", "Location", &location);
		plugin = (IAnjutaProjectBackend *)anjuta_plugin_manager_get_plugin_by_id (plugin_manager, location);
		g_free (location);

		next = g_list_next (desc);
		
		/* Probe the project directory to find if the backend can handle it */
		if (ianjuta_project_backend_probe (plugin, source_dir, NULL) <= 0)
		{
			/* Remove invalid backend */
			descs = g_list_delete_link (descs, desc);
		}

		desc = next;
	}

	if (descs == NULL)
	{
		backend = NULL;
	}
	else if (g_list_next (descs) == NULL)
	{
		backend =  (AnjutaPluginDescription *)descs->data;
	}
	else
	{
		/* Several backend are possible, ask the user to select one */
		gchar *path = project_import_dialog_get_name (import_dialog);
		gchar* message = g_strdup_printf (_("Please select a project backend to open %s."), path);
		
		g_free (path);
		
        backend = anjuta_plugin_manager_select (plugin_manager,
		    _("Open With"),
		    message,
		    descs);
		g_free (message);
	}
	g_list_free (descs);

	if (backend == NULL)
	{
		gchar *path = project_import_dialog_get_name (import_dialog);

		/* show the dialog since it may be hidden */
		gtk_widget_show (GTK_WIDGET (import_dialog));

		anjuta_util_dialog_error (GTK_WINDOW (import_dialog),
		                          _("Could not find a valid project backend for the "
		                            "given directory (%s). Please select a different "
		                            "directory, or try upgrading to a newer version of "
		                            "Anjuta."), path);

		g_free (path);

		return FALSE;
	}


	name = project_import_dialog_get_name (import_dialog);
	project_file_name = g_strconcat (name, ".", "anjuta", NULL);
	GFile *project_file = g_file_get_child (source_dir, project_file_name);

	g_free (name);
	g_free (project_file_name);
	
	IAnjutaFileLoader* loader;
	
	if (!project_import_generate_file (backend, import_dialog, project_file))
	{
		g_object_unref (project_file);
		return FALSE;
	}
	
	loader = anjuta_shell_get_interface (ANJUTA_PLUGIN (import_plugin)->shell,
	                                     IAnjutaFileLoader, NULL);
	if (!loader)
	{
		g_warning("No IAnjutaFileLoader interface! Cannot open project file!");
		g_object_unref (project_file);
		return TRUE;
	}
	
	ianjuta_file_loader_load (loader, project_file, FALSE, NULL);

	g_object_unref (project_file);
	
	return TRUE;
}
Beispiel #17
0
static gboolean
run_program (RunProgramPlugin *plugin)
{
	gchar *target;
	gchar *quote_target;
	gchar *dir = NULL;
	gchar *dir_uri = NULL;
	gchar *args = NULL;
	gchar **env = NULL;
	gchar *cmd;
	gboolean run_in_terminal = 0;
	AnjutaPreferences *prefs;
	GPid pid;
	
	target = get_local_executable (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
								plugin->build_uri);
	g_free (plugin->build_uri);
	plugin->build_uri = NULL;
	if (target == NULL) return FALSE;

	/* Get directory from shell */
	anjuta_shell_get (ANJUTA_PLUGIN (plugin)->shell,
					RUN_PROGRAM_DIR, G_TYPE_STRING, &dir_uri,
					NULL);
	if (dir_uri != NULL)
	{
		dir = get_local_directory (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
									dir_uri);
		g_free (dir_uri);
		if (dir == NULL) return FALSE;
	}
	else
	{
		dir = g_path_get_dirname (target);
	}
	
	/* Get other parameters from shell */
	anjuta_shell_get (ANJUTA_PLUGIN (plugin)->shell,
					RUN_PROGRAM_ARGS, G_TYPE_STRING, &args,
					RUN_PROGRAM_ENV, G_TYPE_STRV, &env,
					RUN_PROGRAM_NEED_TERM, G_TYPE_BOOLEAN, &run_in_terminal,
					NULL);
	
	/* Quote target name */
	quote_target = g_shell_quote (target);
	g_free (target);
	
	if (args && strlen (args) > 0)
		cmd = g_strconcat (quote_target, " ", args, NULL);
	else
		cmd = g_strdup (quote_target);
	g_free (args);
	g_free (quote_target);

	/* Take care of scratchbox */
	prefs = anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell, NULL);
	if (anjuta_preferences_get_bool (prefs , PREF_USE_SB))
	{
		const gchar* sb_path = anjuta_preferences_get(prefs, PREF_SB_PATH);
		/* we need to skip the /scratchbox/users part, maybe could be done more clever */
		const gchar* real_dir = strstr(dir, "/home");
		gchar* oldcmd = cmd;
		gchar* olddir = dir;
		
		cmd = g_strdup_printf("%s/login -d %s \"%s\"", sb_path,
									  real_dir, oldcmd);
		g_free(oldcmd);
		dir = g_strdup(real_dir);
		g_free (olddir);
	}
	
	if (run_in_terminal)
	{
		pid = execute_with_terminal (plugin, dir, cmd, env);
		if (!pid)
		{
			pid = execute_without_terminal (plugin, dir, cmd, env);
		}
	}
	else
	{
		pid = execute_without_terminal (plugin, dir, cmd, env);
	}
	
	if (pid == 0)
	{
		anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
								  "Unable to execute %s", cmd);
	}
	run_plugin_update_menu_sensitivity (plugin);
	
	g_free (dir);
	g_strfreev (env);
	g_free (cmd);

	return TRUE;
}