[anjuta/newproject] Improve dialog for adding packages and add missing file
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta/newproject] Improve dialog for adding packages and add missing file
- Date: Wed, 24 Mar 2010 20:53:41 +0000 (UTC)
commit 793b6349224f15a0e58fed9f60f3b7ba46e82084
Author: Sébastien Granjoux <seb sfo free fr>
Date: Wed Mar 24 21:44:53 2010 +0100
Improve dialog for adding packages and add missing file
plugins/project-manager/create_dialogs.ui | 3 +-
plugins/project-manager/gbf-project-util.c | 119 ++++++++++++++-------------
plugins/project-manager/gbf-project-util.h | 2 +-
plugins/project-manager/pkg-config.c | 87 ++++++++++++++++++++
plugins/project-manager/pkg-config.h | 40 +++++++++
5 files changed, 192 insertions(+), 59 deletions(-)
---
diff --git a/plugins/project-manager/create_dialogs.ui b/plugins/project-manager/create_dialogs.ui
index f00e266..fe00719 100644
--- a/plugins/project-manager/create_dialogs.ui
+++ b/plugins/project-manager/create_dialogs.ui
@@ -594,7 +594,7 @@
</child>
<child>
<object class="GtkButton" id="new_package_button">
- <property name="label" translatable="yes">_Add new package…</property>
+ <property name="label" translatable="yes">_Add package…</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -678,6 +678,7 @@
<action-widgets>
<action-widget response="-6">button1</action-widget>
<action-widget response="-5">ok_module_button</action-widget>
+ <action-widget response="1">new_package_button</action-widget>
</action-widgets>
</object>
<object class="GtkDialog" id="add_package_dialog">
diff --git a/plugins/project-manager/gbf-project-util.c b/plugins/project-manager/gbf-project-util.c
index 21b69a7..32b07e0 100644
--- a/plugins/project-manager/gbf-project-util.c
+++ b/plugins/project-manager/gbf-project-util.c
@@ -884,11 +884,6 @@ gbf_project_util_replace_by_file (GList* list)
}
static void
-new_package_button_clicked_cb (GtkWidget *widget, gpointer user_data)
-{
-}
-
-static void
on_cursor_changed(GtkTreeView* view, gpointer data)
{
GtkWidget* button = GTK_WIDGET(data);
@@ -933,10 +928,6 @@ gbf_project_util_add_module (GbfProjectModel *model,
new_button = GTK_WIDGET (gtk_builder_get_object (gui, "new_package_button"));
ok_button = GTK_WIDGET (gtk_builder_get_object (gui, "ok_module_button"));
-
- g_signal_connect (new_button, "clicked",
- G_CALLBACK (new_package_button_clicked_cb),modules_view);
-
setup_targets_treeview (model, targets_view, default_target);
gtk_widget_show (targets_view);
setup_modules_treeview (model, modules_view, NULL);
@@ -969,7 +960,14 @@ gbf_project_util_add_module (GbfProjectModel *model,
while (!finished) {
response = gtk_dialog_run (GTK_DIALOG (dialog));
+ g_message ("response %d", response);
switch (response) {
+ case 1:
+ {
+ gbf_project_util_add_package (model, parent, NULL, NULL);
+
+ break;
+ }
case GTK_RESPONSE_OK:
{
AnjutaProjectNode *target;
@@ -1102,7 +1100,7 @@ on_changed_disconnect (GtkEditable* entry, gpointer data)
g_signal_handlers_block_by_func (G_OBJECT (data), on_cursor_changed_set_entry, entry);
}
-AnjutaProjectNode*
+GList*
gbf_project_util_add_package (GbfProjectModel *model,
GtkWindow *parent,
GtkTreeIter *default_module,
@@ -1115,13 +1113,11 @@ gbf_project_util_add_package (GbfProjectModel *model,
GtkWidget *packages_view;
GtkCellRenderer* renderer;
GtkListStore *store;
- GList *modules;
- GList *node;
+ GList *packages = NULL;
GtkTreeViewColumn *col;
gint response;
IAnjutaProject *project;
gboolean finished = FALSE;
- AnjutaProjectNode* module = NULL;
GtkTreeSelection *package_selection;
GtkTreeIter root;
gboolean valid;
@@ -1159,7 +1155,7 @@ gbf_project_util_add_package (GbfProjectModel *model,
GtkTreeIter iter;
gint pos = 0;
GbfTreeData *data;
- GtkTreePath *default_path = gtk_tree_model_get_path(GTK_TREE_MODEL (model), default_module);
+ GtkTreePath *default_path = default_module != NULL ? gtk_tree_model_get_path(GTK_TREE_MODEL (model), default_module) : NULL;
gtk_tree_model_get (GTK_TREE_MODEL (model), &root, GBF_PROJECT_MODEL_COLUMN_DATA, &data, -1);
@@ -1169,16 +1165,14 @@ gbf_project_util_add_package (GbfProjectModel *model,
gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, GBF_PROJECT_MODEL_COLUMN_DATA, &data, -1);
- g_message ("module %p name %s type %d module %d", data, data != NULL ? data->name : "(null)", data != NULL ? data->type : -1, GBF_TREE_NODE_MODULE);
if (data && (data->type == GBF_TREE_NODE_MODULE))
{
GtkTreeIter list_iter;
GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL (model), &iter);
- g_message ("append name %s", data->name);
gtk_list_store_append (store, &list_iter);
gtk_list_store_set (store, &list_iter, 0, data->name, -1);
- if (gtk_tree_path_compare (path, default_path) == 0)
+ if ((default_path != NULL) && (gtk_tree_path_compare (path, default_path) == 0))
{
default_pos = pos;
}
@@ -1186,11 +1180,11 @@ gbf_project_util_add_package (GbfProjectModel *model,
pos++;
}
}
- gtk_tree_path_free (default_path);
+ if (default_path != NULL) gtk_tree_path_free (default_path);
}
gtk_combo_box_set_model (GTK_COMBO_BOX(module_entry), GTK_TREE_MODEL(store));
gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (module_entry), 0);
-// g_object_unref (store);
+ g_object_unref (store);
if (default_pos >= 0)
{
gtk_combo_box_set_active (GTK_COMBO_BOX (module_entry), default_pos);
@@ -1228,6 +1222,8 @@ gbf_project_util_add_package (GbfProjectModel *model,
on_cursor_changed (GTK_TREE_VIEW (packages_view), ok_button);
g_signal_connect (G_OBJECT(packages_view), "cursor-changed",
G_CALLBACK(on_cursor_changed), ok_button);
+ package_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (packages_view));
+ gtk_tree_selection_set_mode (package_selection, GTK_SELECTION_MULTIPLE);
if (parent) {
gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
@@ -1240,60 +1236,69 @@ gbf_project_util_add_package (GbfProjectModel *model,
switch (response) {
case GTK_RESPONSE_OK:
{
- AnjutaProjectNode *target;
+ gchar *module;
-#if 0
- target = gbf_project_view_find_selected (GBF_PROJECT_VIEW (targets_view),
- ANJUTA_PROJECT_TARGET);
- if (target) {
+ module = gtk_combo_box_get_active_text (GTK_COMBO_BOX (module_entry));
+ if (module)
+ {
GString *err_mesg = g_string_new (NULL);
GList *list;
GList *node;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
- list = gbf_project_view_get_all_selected (GBF_PROJECT_VIEW (modules_view));
- for (node = g_list_first (list); node != NULL; node = g_list_next (node))
+ list = gtk_tree_selection_get_selected_rows (package_selection, &model);
+ for (node = list; node != NULL; node = g_list_next (node))
{
- GError *err = NULL;
- AnjutaProjectNode* selected_module = (AnjutaProjectNode *)node->data;
- AnjutaProjectNode* new_module;
- gchar* uri = NULL;
- GFile* module_file;
-
- /*module_file = gbf_tree_data_get_file (selected_module);
- new_module = ianjuta_project_add_module (project,
- target,
- module_file,
- &err);
- g_object_unref (module_file);*/
- new_module = NULL;
- if (err) {
- gchar *str = g_strdup_printf ("%s: %s\n",
- uri,
- err->message);
- g_string_append (err_mesg, str);
- g_error_free (err);
- g_free (str);
+ if (gtk_tree_model_get_iter (model, &iter, (GtkTreePath *)(node->data)))
+ {
+ gchar *name;
+ AnjutaProjectNode* new_package;
+ GError *err = NULL;
+
+ gtk_tree_model_get (model, &iter, COL_PKG_PACKAGE, &name, -1);
+
+ /*new_package = ianjuta_project_add_package (project,
+ module,
+ name,
+ &err);*/
+ new_package = NULL;
+ if (err)
+ {
+ gchar *str = g_strdup_printf ("%s: %s\n",
+ name,
+ err->message);
+ g_string_append (err_mesg, str);
+ g_error_free (err);
+ g_free (str);
+ }
+ else
+ {
+ packages = g_list_append (packages,
+ new_package);
+ }
+ g_free (name);
}
- else
- new_modules = g_list_append (new_modules,
- new_module);
-
- g_free (uri);
}
+ g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
g_list_free (list);
- if (err_mesg->str && strlen (err_mesg->str) > 0) {
+ if (err_mesg->str && strlen (err_mesg->str) > 0)
+ {
error_dialog (parent, _("Cannot add packages"),
"%s", err_mesg->str);
- } else {
+ }
+ else
+ {
finished = TRUE;
}
g_string_free (err_mesg, TRUE);
- } else {
+ }
+ else
+ {
error_dialog (parent, _("Cannot add packages"),
- "%s", _("No target has been selected"));
+ "%s", _("No module has been selected"));
}
-#endif
break;
}
default:
@@ -1306,5 +1311,5 @@ gbf_project_util_add_package (GbfProjectModel *model,
gtk_widget_destroy (dialog);
g_object_unref (gui);
- return module;
+ return packages;
}
diff --git a/plugins/project-manager/gbf-project-util.h b/plugins/project-manager/gbf-project-util.h
index 18d928b..94b8cc2 100644
--- a/plugins/project-manager/gbf-project-util.h
+++ b/plugins/project-manager/gbf-project-util.h
@@ -50,7 +50,7 @@ GList* gbf_project_util_add_module (GbfProjectModel *model,
GtkTreeIter *default_target,
const gchar *default_module_name_to_add);
-AnjutaProjectNode* gbf_project_util_add_package(GbfProjectModel *model,
+GList* gbf_project_util_add_package (GbfProjectModel *model,
GtkWindow *parent,
GtkTreeIter *default_module,
GList *packages_to_add);
diff --git a/plugins/project-manager/pkg-config.c b/plugins/project-manager/pkg-config.c
new file mode 100644
index 0000000..016b384
--- /dev/null
+++ b/plugins/project-manager/pkg-config.c
@@ -0,0 +1,87 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/* pkg-config.c
+ *
+ * Copyright (C) 2005 Naba Kumar
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "pkg-config.h"
+
+#include <ctype.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+GtkListStore *
+packages_get_pkgconfig_list (void)
+{
+ GtkListStore *store;
+ GtkTreeIter iter;
+ gchar line[1024];
+ gchar *tmpfile, *pkg_cmd;
+ FILE *pkg_fd;
+
+ store = gtk_list_store_new (N_PKG_COLUMNS, G_TYPE_STRING,
+ G_TYPE_STRING);
+
+ /* Now get all the pkg-config info */
+ tmpfile = g_strdup_printf ("%s%cpkgmodules--%d", g_get_tmp_dir (),
+ G_DIR_SEPARATOR, getpid());
+ pkg_cmd = g_strconcat ("pkg-config --list-all 2>/dev/null | sort > ",
+ tmpfile, NULL);
+ if (system (pkg_cmd) == -1)
+ return store;
+ pkg_fd = fopen (tmpfile, "r");
+ if (!pkg_fd) {
+ g_warning ("Can not open %s for reading", tmpfile);
+ g_free (tmpfile);
+ return store;
+ }
+ while (fgets (line, 1024, pkg_fd)) {
+ gchar *name_end;
+ gchar *desc_start;
+ gchar *description;
+ gchar *name;
+
+ if (line[0] == '\0')
+ continue;
+
+ name_end = line;
+ while (!isspace(*name_end))
+ name_end++;
+ desc_start = name_end;
+ while (isspace(*desc_start))
+ desc_start++;
+
+ name = g_strndup (line, name_end-line);
+ description = g_strndup (desc_start, strlen (desc_start)-1);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COL_PKG_PACKAGE, name,
+ COL_PKG_DESCRIPTION, description,
+ -1);
+ }
+ fclose (pkg_fd);
+ unlink (tmpfile);
+ g_free (tmpfile);
+ return store;
+}
diff --git a/plugins/project-manager/pkg-config.h b/plugins/project-manager/pkg-config.h
new file mode 100644
index 0000000..ae16fa9
--- /dev/null
+++ b/plugins/project-manager/pkg-config.h
@@ -0,0 +1,40 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/* pkg-config.h
+ *
+ * Copyright (C) 2005 Naba Kumar
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _PKG_CONFIG_H_
+#define _PKG_CONFIG_H_
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+enum {
+ COL_PKG_PACKAGE,
+ COL_PKG_DESCRIPTION,
+ N_PKG_COLUMNS
+};
+
+GtkListStore *packages_get_pkgconfig_list (void);
+
+G_END_DECLS
+
+#endif /* _PKG_CONFIG_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]