gtranslator r3599 - in trunk/src: . dialogs
- From: icq svn gnome org
- To: svn-commits-list gnome org
- Subject: gtranslator r3599 - in trunk/src: . dialogs
- Date: Mon, 22 Sep 2008 09:38:31 +0000 (UTC)
Author: icq
Date: Mon Sep 22 09:38:31 2008
New Revision: 3599
URL: http://svn.gnome.org/viewvc/gtranslator?rev=3599&view=rev
Log:
Applyed patch with the profiles feature.
Modified:
trunk/src/actions-file.c
trunk/src/application.c
trunk/src/application.h
trunk/src/dialogs/preferences-dialog.c
trunk/src/dialogs/preferences-dialog.glade
trunk/src/dialogs/preferences-dialog.h
trunk/src/dialogs/profile-dialog.c
trunk/src/dialogs/profile-dialog.h
trunk/src/main.c
trunk/src/profile.c
trunk/src/profile.h
Modified: trunk/src/actions-file.c
==============================================================================
--- trunk/src/actions-file.c (original)
+++ trunk/src/actions-file.c Mon Sep 22 09:38:31 2008
@@ -26,6 +26,7 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <string.h>
#include <gio/gio.h>
@@ -35,6 +36,7 @@
#include "file-dialogs.h"
#include "notebook.h"
#include "po.h"
+#include "profile.h"
#include "statusbar.h"
#include "tab.h"
#include "window.h"
@@ -675,7 +677,22 @@
GtranslatorPo *po;
gint pages;
GList *list = NULL;
-
+ gchar *config_folder;
+ gchar *filename;
+ GFile *file;
+
+ config_folder = gtranslator_utils_get_user_config_dir ();
+ filename = g_build_filename (config_folder,
+ "profiles.xml",
+ NULL);
+
+ file = g_file_new_for_path (filename);
+
+ if (g_file_query_exists (file, NULL)) {
+ g_file_delete (file, NULL, NULL);
+ gtranslator_profile_save_profiles_in_xml (filename);
+ }
+
nb = gtranslator_window_get_notebook (window);
pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK(nb));
Modified: trunk/src/application.c
==============================================================================
--- trunk/src/application.c (original)
+++ trunk/src/application.c Mon Sep 22 09:38:31 2008
@@ -24,6 +24,7 @@
#include "utils.h"
#include "window.h"
#include "egg-toolbars-model.h"
+#include "dialogs/preferences-dialog.h"
#include <glib.h>
#include <glib-object.h>
@@ -42,7 +43,12 @@
{
GList *windows;
GtranslatorWindow *active_window;
+
+ GList *profiles;
+ GtranslatorProfile *active_profile;
+ GtranslatorPreferencesDialog *preferences_dialog;
+
gchar *toolbars_file;
EggToolbarsModel *toolbars_model;
Modified: trunk/src/application.h
==============================================================================
--- trunk/src/application.h (original)
+++ trunk/src/application.h Mon Sep 22 09:38:31 2008
@@ -23,7 +23,9 @@
#include <glib-object.h>
#include <gtk/gtk.h>
+#include "profile.h"
#include "window.h"
+#include "dialogs/preferences-dialog.h"
G_BEGIN_DECLS
@@ -81,7 +83,24 @@
GtranslatorWindow *gtranslator_application_get_active_window (GtranslatorApplication * app);
-const GList *gtranslator_application_get_windows (GtranslatorApplication *app);
+const GList *gtranslator_application_get_windows (GtranslatorApplication *app);
+
+GtranslatorProfile *gtranslator_application_get_active_profile (GtranslatorApplication *app);
+
+void gtranslator_application_set_active_profile (GtranslatorApplication *app,
+ GtranslatorProfile *profile);
+
+GList *gtranslator_application_get_profiles (GtranslatorApplication *app);
+
+void gtranslator_application_set_profiles (GtranslatorApplication *app,
+ GList *profiles);
+
+GtranslatorPreferencesDialog *
+gtranslator_application_get_preferences_dialog (GtranslatorApplication *app);
+
+void
+gtranslator_application_set_preferences_dialog (GtranslatorApplication *app,
+ GtranslatorPreferencesDialog *dlg);
void gtranslator_application_register_icon (GtranslatorApplication *app,
const gchar *icon,
Modified: trunk/src/dialogs/preferences-dialog.c
==============================================================================
--- trunk/src/dialogs/preferences-dialog.c (original)
+++ trunk/src/dialogs/preferences-dialog.c Mon Sep 22 09:38:31 2008
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2007 Ignacio Casal Quinteiro <nacho resa gmail com>
+ * 2008 Pablo Sanxiao <psanxiao gmail com>
*
* 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
@@ -20,14 +21,18 @@
#include <config.h>
#endif
+#include "application.h"
#include "preferences-dialog.h"
#include "prefs-manager.h"
+#include "profile.h"
#include "utils.h"
#include "plugin-manager.h"
+#include "profile-dialog.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <glib-object.h>
+#include <gio/gio.h>
#include <gtk/gtk.h>
@@ -93,6 +98,13 @@
GtkWidget *plugins_box;
};
+static void setup_profile_pages (GtranslatorPreferencesDialog *dlg);
+
+GtkWidget *gtranslator_preferences_dialog_get_treeview (GtranslatorPreferencesDialog *dlg)
+{
+ return dlg->priv->profile_treeview;
+}
+
/***************Files pages****************/
static void
@@ -390,75 +402,158 @@
setup_editor_contents(dlg);
}
-/***************PO header pages****************/
+/***************Profile pages****************/
static void
-name_entry_changed(GObject *gobject,
- GParamSpec *arg1,
+active_toggled_cb (GtkCellRendererToggle *cell_renderer,
+ gchar *path_str,
GtranslatorPreferencesDialog *dlg)
{
- const gchar *text;
-
- g_return_if_fail(GTK_ENTRY(gobject) == GTK_ENTRY(dlg->priv->name_entry));
-
- text = gtk_entry_get_text(GTK_ENTRY(gobject));
-
- if(text)
- gtranslator_prefs_manager_set_name(text);
-}
-
-static void
-email_entry_changed(GObject *gobject,
- GParamSpec *arg1,
- GtranslatorPreferencesDialog *dlg)
-{
- const gchar *text;
-
- g_return_if_fail(GTK_ENTRY(gobject) == GTK_ENTRY(dlg->priv->email_entry));
-
- text = gtk_entry_get_text(GTK_ENTRY(gobject));
-
- if(text)
- gtranslator_prefs_manager_set_email(text);
-}
-
-static void
-setup_po_header_personal_information_page(GtranslatorPreferencesDialog *dlg)
-{
- const gchar *value;
-
- /*Set initial value*/
- value = gtranslator_prefs_manager_get_name();
- if(value)
- gtk_entry_set_text(GTK_ENTRY(dlg->priv->name_entry),
- value);
- value = gtranslator_prefs_manager_get_email();
- if(value)
- gtk_entry_set_text(GTK_ENTRY(dlg->priv->email_entry),
- value);
-
- /*Connect signals*/
- g_signal_connect(dlg->priv->name_entry, "notify::text",
- G_CALLBACK(name_entry_changed),
- dlg);
- g_signal_connect(dlg->priv->email_entry, "notify::text",
- G_CALLBACK(email_entry_changed),
- dlg);
-}
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GtkTreeModel *model;
+ gboolean active;
+ gchar *profile_row;
+ GtranslatorProfile *old_profile_active;
+ GList *l = NULL, *profiles_list = NULL;
+ gchar *filename;
+ gchar *config_folder;
+ GFile *file;
+
+
+ config_folder = gtranslator_utils_get_user_config_dir ();
+ filename = g_build_filename (config_folder,
+ "profiles.xml",
+ NULL);
+ file = g_file_new_for_path (filename);
+
+ path = gtk_tree_path_new_from_string (path_str);
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (dlg->priv->profile_treeview));
+ g_return_if_fail (model != NULL);
+
+ gtk_tree_model_get_iter (model, &iter, path);
+
+ gtk_tree_model_get (model, &iter, TOGGLE_COL, &active, -1);
+
+ if (!active) {
+
+ old_profile_active = gtranslator_application_get_active_profile (GTR_APP);
+
+ gtk_list_store_set (GTK_LIST_STORE (model),
+ &iter,
+ TRUE,
+ TOGGLE_COL,
+ -1);
+
+ gtk_tree_model_get (model, &iter, PROFILE_NAME_COL, &profile_row, -1);
+ profiles_list = gtranslator_application_get_profiles (GTR_APP);
+
+ for (l = profiles_list; l; l = l->next) {
+ GtranslatorProfile *profile;
+ profile = (GtranslatorProfile *)l->data;
+ if (!strcmp (gtranslator_profile_get_name (profile), profile_row)) {
+ gtranslator_application_set_active_profile (GTR_APP, profile);
+ }
+ }
+ }
+ gtk_list_store_clear (GTK_LIST_STORE(model));
+ gtranslator_preferences_fill_profile_treeview (dlg, model);
+ gtk_tree_path_free (path);
+}
+
+void gtranslator_preferences_fill_profile_treeview (GtranslatorPreferencesDialog *dlg,
+ GtkTreeModel *model)
+{
+ GtkTreeIter iter;
+ GtranslatorProfile *active_profile;
+ GList *l = NULL, *profiles_list = NULL;
+
+ gtk_list_store_clear (GTK_LIST_STORE (model));
+
+ profiles_list = gtranslator_application_get_profiles (GTR_APP);
+ active_profile = gtranslator_application_get_active_profile (GTR_APP);
+
+ for (l = profiles_list; l; l = l->next) {
+
+ GtranslatorProfile *profile;
+ gchar *profile_name;
+
+ profile = (GtranslatorProfile *)l->data;
+
+ profile_name = gtranslator_profile_get_name (profile);
+ gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+
+ if (!strcmp (gtranslator_profile_get_name (active_profile), profile_name)) {
+ gtk_list_store_set (GTK_LIST_STORE (model),
+ &iter,
+ PROFILE_NAME_COL,
+ profile_name,
+ TOGGLE_COL,
+ TRUE,
+ -1);
+ } else {
+ gtk_list_store_set (GTK_LIST_STORE (model),
+ &iter,
+ PROFILE_NAME_COL,
+ profile_name,
+ -1);
+ }
+ }
+}
+
+static void
+setup_profile_pages (GtranslatorPreferencesDialog *dlg)
+{
+
+ GtkTreeViewColumn *name_column, *toggle_column;
+ GtkCellRenderer *text_renderer, *toggle_renderer;
+ GtkListStore *model;
+
+ model = gtk_list_store_new (N_COLUMNS_PROFILES, G_TYPE_STRING, G_TYPE_BOOLEAN);
+
+ gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->profile_treeview),
+ GTK_TREE_MODEL (model));
+
+ g_object_unref (model);
+
+ text_renderer = gtk_cell_renderer_text_new ();
+ toggle_renderer = gtk_cell_renderer_toggle_new ();
+
+ g_signal_connect (toggle_renderer,
+ "toggled",
+ G_CALLBACK (active_toggled_cb),
+ dlg);
+
+ g_object_set (toggle_renderer,
+ "mode",
+ GTK_CELL_RENDERER_MODE_ACTIVATABLE,
+ NULL);
-static void
-setup_po_header_language_settings_page(GtranslatorPreferencesDialog *dlg)
-{
-}
+ name_column = gtk_tree_view_column_new_with_attributes ("Profile",
+ text_renderer,
+ "text",
+ PROFILE_NAME_COL,
+ NULL);
+
+ toggle_column = gtk_tree_view_column_new_with_attributes ("Active",
+ toggle_renderer,
+ "active",
+ TOGGLE_COL,
+ NULL);
+
+ gtk_tree_view_column_set_resizable (toggle_column, TRUE);
+ gtk_tree_view_column_set_resizable (name_column, TRUE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->profile_treeview), name_column);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->profile_treeview), toggle_column);
+
+ g_object_set (name_column,
+ "expand",
+ TRUE,
+ NULL);
-static void
-setup_po_header_pages(GtranslatorPreferencesDialog *dlg)
-{
- /*Children*/
- setup_po_header_personal_information_page(dlg);
- setup_po_header_language_settings_page(dlg);
+ gtranslator_preferences_fill_profile_treeview (dlg,GTK_TREE_MODEL(model));
}
-
/***************Interface pages****************/
static void
style_changed_cb (GtkComboBox *combobox,
@@ -516,9 +611,153 @@
}
static void
-add_button_pulsed (GtkWidget *button, GtranslatorPreferencesDialog *dlg)
+add_button_pulsed (GtkWidget *button,
+ GtranslatorPreferencesDialog *dlg)
+{
+ GtranslatorProfile *profile;
+ profile = gtranslator_profile_new ();
+ gtranslator_show_profile_dialog(dlg, profile, NEW_PROFILE);
+}
+
+static void
+edit_button_pulsed (GtkWidget *button,
+ GtranslatorPreferencesDialog *dlg)
{
- gtranslator_show_profile_dialog(dlg);
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ GtkTreeSelection *selection;
+ gchar *profile_row, *old_profile_name;
+ GtranslatorProfile *edited_profile;
+ GtranslatorProfile *active_profile;
+ GList *profiles_list = NULL, *l = NULL;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (dlg->priv->profile_treeview));
+ g_return_if_fail (model != NULL);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->profile_treeview));
+
+ if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
+
+ gtk_tree_model_get (model, &iter, PROFILE_NAME_COL, &profile_row, -1);
+
+ profiles_list = gtranslator_application_get_profiles (GTR_APP);
+ active_profile = gtranslator_application_get_active_profile (GTR_APP);
+
+ for (l = profiles_list; l; l = l->next) {
+ GtranslatorProfile *profile;
+ profile = (GtranslatorProfile *)l->data;
+ if (!strcmp (gtranslator_profile_get_name (profile), profile_row)) {
+ old_profile_name = gtranslator_profile_get_name (profile);
+ edited_profile = profile;
+ }
+ }
+ gtranslator_show_profile_dialog (dlg, edited_profile, EDIT_PROFILE);
+ }
+}
+
+static void
+delete_confirm_dialog_cb (GtkWidget *dialog,
+ gint response_id,
+ GtranslatorPreferencesDialog *dlg)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ GtkTreeSelection *selection;
+ gchar *profile_row;
+ GList *profiles_list = NULL, *l = NULL;
+ GList *new_list = NULL;
+
+ if (response_id == GTK_RESPONSE_YES) {
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (dlg->priv->profile_treeview));
+ g_return_if_fail (model != NULL);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->profile_treeview));
+
+ if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
+
+ gtk_tree_model_get (model, &iter, PROFILE_NAME_COL, &profile_row, -1);
+
+ profiles_list = gtranslator_application_get_profiles (GTR_APP);
+
+ for (l = profiles_list; l; l = l->next) {
+ GtranslatorProfile *profile;
+ profile = (GtranslatorProfile *)l->data;
+ if (!strcmp (gtranslator_profile_get_name (profile), profile_row)) {
+ new_list = g_list_remove (profiles_list, profile);
+ gtranslator_application_set_profiles (GTR_APP, new_list);
+ }
+ }
+ gtranslator_preferences_fill_profile_treeview (dlg, model);
+ }
+ gtk_widget_destroy (dialog);
+ } else {
+ gtk_widget_destroy (dialog);
+ }
+}
+
+static void
+delete_button_pulsed (GtkWidget *button,
+ GtranslatorPreferencesDialog *dlg)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ GtkTreeSelection *selection;
+ gchar *profile_row;
+ GtranslatorProfile *active_profile;
+ GtkWidget *dialog;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (dlg->priv->profile_treeview));
+ g_return_if_fail (model != NULL);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->profile_treeview));
+
+ if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
+
+ gtk_tree_model_get (model, &iter, PROFILE_NAME_COL, &profile_row, -1);
+
+ active_profile = gtranslator_application_get_active_profile (GTR_APP);
+
+ if (!strcmp (gtranslator_profile_get_name (active_profile), profile_row)) {
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (dlg),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ NULL);
+
+ gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
+ _("<span weight=\"bold\" size=\"large\">Impossible to remove the active profile</span>"));
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("Another profile should be selected as active before"));
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ } else {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (dlg),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ NULL);
+
+ gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
+ _("<span weight=\"bold\" size=\"large\">Are you sure you want to delete this profile?</span>"));
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ GTK_STOCK_DELETE,
+ GTK_RESPONSE_YES);
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+
+ g_signal_connect (GTK_DIALOG (dialog), "response",
+ G_CALLBACK (delete_confirm_dialog_cb),
+ dlg);
+ }
+ }
}
static void
@@ -585,17 +824,6 @@
"edit_button", &dlg->priv->edit_button,
"delete_button", &dlg->priv->delete_button,
- /*"name_entry", &dlg->priv->name_entry,
- "email_entry", &dlg->priv->email_entry,
-
- "language_comboentry", &dlg->priv->language_comboentry,
- "langcode_comboentry", &dlg->priv->langcode_comboentry,
- "charset_comboentry", &dlg->priv->charset_comboentry,
- "encoding_comboentry", &dlg->priv->encoding_comboentry,
- "team_email_comboentry", &dlg->priv->team_email_comboentry,
- "number_plurals_spinbutton", &dlg->priv->number_plurals_spinbutton,
- "plurals_entry", &dlg->priv->plurals_entry,
- */
"gdl_combobox", &dlg->priv->gdl_combobox,
"plugins_box", &dlg->priv->plugins_box,
@@ -618,13 +846,23 @@
gtk_container_set_border_width (GTK_CONTAINER (dlg->priv->notebook), 5);
g_signal_connect (dlg->priv->add_button,
- "clicked",
- G_CALLBACK (add_button_pulsed),
- dlg);
+ "clicked",
+ G_CALLBACK (add_button_pulsed),
+ dlg);
+
+ g_signal_connect (dlg->priv->delete_button,
+ "clicked",
+ G_CALLBACK (delete_button_pulsed),
+ dlg);
+
+ g_signal_connect (dlg->priv->edit_button,
+ "clicked",
+ G_CALLBACK (edit_button_pulsed),
+ dlg);
setup_files_pages(dlg);
setup_editor_pages(dlg);
- setup_po_header_pages(dlg);
+ setup_profile_pages(dlg);
setup_interface_pages(dlg);
setup_plugin_pages(dlg);
}
@@ -668,5 +906,7 @@
GTK_WINDOW (window));
}
+ gtranslator_application_set_preferences_dialog (GTR_APP, GTR_PREFERENCES_DIALOG(dlg));
+
gtk_window_present (GTK_WINDOW (dlg));
}
Modified: trunk/src/dialogs/preferences-dialog.glade
==============================================================================
--- trunk/src/dialogs/preferences-dialog.glade (original)
+++ trunk/src/dialogs/preferences-dialog.glade Mon Sep 22 09:38:31 2008
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.1 on Sun Mar 9 23:45:30 2008 -->
+<!--Generated with glade3 3.4.5 on Fri Jun 27 12:18:15 2008 -->
<glade-interface>
<widget class="GtkDialog" id="preferences_dialog">
<property name="border_width">5</property>
@@ -493,125 +493,86 @@
</packing>
</child>
<child>
- <widget class="GtkVBox" id="vbox8">
+ <widget class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <child>
- <widget class="GtkHBox" id="hbox5">
- <property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <child>
- <widget class="GtkLabel" id="label15">
- <property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="padding">6</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label13">
- <property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="xalign">0</property>
- <property name="ypad">4</property>
- <property name="label" translatable="yes"><b>Name</b></property>
- <property name="use_markup">True</property>
- </widget>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <widget class="GtkVSeparator" id="vseparator1">
- <property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label14">
- <property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="xpad">12</property>
- <property name="label" translatable="yes"><b>Active</b></property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_JUSTIFY_RIGHT</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">3</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- </packing>
- </child>
- <child>
- <widget class="GtkTreeView" id="profile_treeview">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="headers_clickable">True</property>
- </widget>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
+ <property name="top_padding">12</property>
+ <property name="bottom_padding">12</property>
+ <property name="left_padding">12</property>
+ <property name="right_padding">12</property>
<child>
- <widget class="GtkHBox" id="hbox6">
+ <widget class="GtkVBox" id="vbox8">
<property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="spacing">6</property>
<child>
- <widget class="GtkButton" id="add_button">
+ <widget class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="label" translatable="yes">gtk-add</property>
- <property name="use_stock">True</property>
- <property name="response_id">0</property>
+ <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <child>
+ <widget class="GtkViewport" id="viewport1">
+ <property name="visible">True</property>
+ <property name="resize_mode">GTK_RESIZE_QUEUE</property>
+ <child>
+ <widget class="GtkTreeView" id="profile_treeview">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="headers_clickable">True</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
</widget>
</child>
<child>
- <widget class="GtkButton" id="edit_button">
+ <widget class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="label" translatable="yes">gtk-edit</property>
- <property name="use_stock">True</property>
- <property name="response_id">0</property>
+ <property name="spacing">6</property>
+ <property name="layout_style">GTK_BUTTONBOX_END</property>
+ <child>
+ <widget class="GtkButton" id="add_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="label" translatable="yes">gtk-add</property>
+ <property name="use_stock">True</property>
+ <property name="response_id">0</property>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkButton" id="edit_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="label" translatable="yes">gtk-edit</property>
+ <property name="use_stock">True</property>
+ <property name="response_id">0</property>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkButton" id="delete_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="label" translatable="yes">gtk-delete</property>
+ <property name="use_stock">True</property>
+ <property name="response_id">0</property>
+ </widget>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
</widget>
<packing>
+ <property name="expand">False</property>
+ <property name="pack_type">GTK_PACK_END</property>
<property name="position">1</property>
</packing>
</child>
- <child>
- <widget class="GtkButton" id="delete_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="label" translatable="yes">gtk-delete</property>
- <property name="use_stock">True</property>
- <property name="response_id">0</property>
- </widget>
- <packing>
- <property name="position">2</property>
- </packing>
- </child>
</widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">2</property>
- </packing>
</child>
</widget>
<packing>
Modified: trunk/src/dialogs/preferences-dialog.h
==============================================================================
--- trunk/src/dialogs/preferences-dialog.h (original)
+++ trunk/src/dialogs/preferences-dialog.h Mon Sep 22 09:38:31 2008
@@ -19,11 +19,18 @@
#ifndef __PREFERENCES_DIALOG_H__
#define __PREFERENCES_DIALOG_H__
+#include "application.h"
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include "window.h"
+enum {
+ PROFILE_NAME_COL,
+ TOGGLE_COL,
+ N_COLUMNS_PROFILES
+ };
+
G_BEGIN_DECLS
/*
@@ -71,6 +78,11 @@
void gtranslator_show_preferences_dialog (GtranslatorWindow *window);
+GtkWidget *gtranslator_preferences_dialog_get_treeview (GtranslatorPreferencesDialog *dlg);
+
+void gtranslator_preferences_fill_profile_treeview (GtranslatorPreferencesDialog *dlg,
+ GtkTreeModel *model);
+
G_END_DECLS
#endif /* __PREFERENCES_DIALOG_H__ */
Modified: trunk/src/dialogs/profile-dialog.c
==============================================================================
--- trunk/src/dialogs/profile-dialog.c (original)
+++ trunk/src/dialogs/profile-dialog.c Mon Sep 22 09:38:31 2008
@@ -20,14 +20,17 @@
#include <config.h>
#endif
+#include "application.h"
#include "profile-dialog.h"
#include "preferences-dialog.h"
+#include "profile.h"
#include "utils.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <glib-object.h>
#include <gtk/gtk.h>
+#include <libxml/tree.h>
#define GTR_PROFILE_DIALOG_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ( \
@@ -55,6 +58,11 @@
GtkWidget *plurals_forms_entry;
};
+struct data {
+ GtranslatorProfile *old_profile;
+ GtranslatorProfile *new_profile;
+};
+
static void gtranslator_profile_dialog_finalize (GObject *object)
{
G_OBJECT_CLASS (gtranslator_profile_dialog_parent_class)->finalize (object);
@@ -69,6 +77,235 @@
object_class->finalize = gtranslator_profile_dialog_finalize;
}
+/***************PROFILES****************/
+static void
+profile_name_entry_changed (GObject *gobject,
+ GParamSpec *arg1,
+ GtranslatorProfile *profile)
+{
+ const gchar *text;
+
+ /*g_return_if_fail (GTK_ENTRY (gobject) == GTK_ENTRY (dlg->priv->profile_name_entry));*/
+
+ text = gtk_entry_get_text (GTK_ENTRY (gobject));
+
+ if (text)
+ gtranslator_profile_set_name (profile, (gchar *)text);
+}
+
+static void
+author_name_entry_changed (GObject *gobject,
+ GParamSpec *arg1,
+ GtranslatorProfile *profile)
+{
+ const gchar *text;
+
+ /*g_return_if_fail (GTK_ENTRY (gobject) == GTK_ENTRY (dlg->priv->author_name_entry));*/
+
+ text = gtk_entry_get_text (GTK_ENTRY (gobject));
+
+ if (text)
+ gtranslator_profile_set_author_name (profile, (gchar *)text);
+}
+
+static void
+author_email_entry_changed (GObject *gobject,
+ GParamSpec *arg1,
+ GtranslatorProfile *profile)
+{
+ const gchar *text;
+
+ /*g_return_if_fail (GTK_ENTRY (gobject) == GTK_ENTRY (dlg->priv->author_email_entry));*/
+
+ text = gtk_entry_get_text (GTK_ENTRY (gobject));
+
+ if (text)
+ gtranslator_profile_set_author_email (profile, (gchar *)text);
+}
+
+static void
+language_name_entry_changed (GObject *gobject,
+ GParamSpec *arg1,
+ GtranslatorProfile *profile)
+{
+ const gchar *text;
+
+ /*g_return_if_fail (GTK_ENTRY (gobject) == GTK_ENTRY (dlg->priv->profile_name_entry));*/
+
+ text = gtk_entry_get_text (GTK_ENTRY (gobject));
+
+ if (text)
+ gtranslator_profile_set_language_name (profile, (gchar *)text);
+}
+
+static void
+language_code_entry_changed (GObject *gobject,
+ GParamSpec *arg1,
+ GtranslatorProfile *profile)
+{
+ const gchar *text;
+
+ /*g_return_if_fail (GTK_ENTRY (gobject) == GTK_ENTRY (dlg->priv->profile_name_entry));*/
+
+ text = gtk_entry_get_text (GTK_ENTRY (gobject));
+
+ if (text)
+ gtranslator_profile_set_language_code (profile, (gchar *)text);
+}
+
+static void
+charset_entry_changed (GObject *gobject,
+ GParamSpec *arg1,
+ GtranslatorProfile *profile)
+{
+ const gchar *text;
+
+ /*g_return_if_fail (GTK_ENTRY (gobject) == GTK_ENTRY (dlg->priv->profile_name_entry));*/
+
+ text = gtk_entry_get_text (GTK_ENTRY (gobject));
+
+ if (text)
+ gtranslator_profile_set_charset (profile, (gchar *)text);
+}
+
+static void
+encoding_entry_changed (GObject *gobject,
+ GParamSpec *arg1,
+ GtranslatorProfile *profile)
+{
+ const gchar *text;
+
+ /*g_return_if_fail (GTK_ENTRY (gobject) == GTK_ENTRY (dlg->priv->profile_name_entry));*/
+
+ text = gtk_entry_get_text (GTK_ENTRY (gobject));
+
+ if (text)
+ gtranslator_profile_set_encoding (profile, (gchar *)text);
+}
+
+static void
+group_email_entry_changed (GObject *gobject,
+ GParamSpec *arg1,
+ GtranslatorProfile *profile)
+{
+ const gchar *text;
+
+ /*g_return_if_fail (GTK_ENTRY (gobject) == GTK_ENTRY (dlg->priv->profile_name_entry));*/
+
+ text = gtk_entry_get_text (GTK_ENTRY (gobject));
+
+ if (text)
+ gtranslator_profile_set_group_email (profile, (gchar *)text);
+}
+
+static void
+plurals_entry_changed (GObject *gobject,
+ GParamSpec *arg1,
+ GtranslatorProfile *profile)
+{
+ const gchar *text;
+
+ /*g_return_if_fail (GTK_ENTRY (gobject) == GTK_ENTRY (dlg->priv->profile_name_entry));*/
+
+ text = gtk_entry_get_text (GTK_ENTRY (gobject));
+
+ if (text)
+ gtranslator_profile_set_plurals (profile, (gchar *)text);
+}
+
+static void save_new_profile (GtkWidget *widget, GtranslatorProfile *profile)
+{
+ GList *profiles_list = NULL, *l = NULL;
+ GtranslatorPreferencesDialog *dlg;
+ gboolean profile_exists;
+ GtkWidget *treeview;
+ GtkTreeModel *model;
+ profile_exists = FALSE;
+
+ profiles_list = gtranslator_application_get_profiles (GTR_APP);
+
+ for (l = profiles_list; l; l = l->next) {
+ GtranslatorProfile *profile_in_list;
+ profile_in_list = (GtranslatorProfile *)l->data;
+ if (!strcmp (gtranslator_profile_get_name (profile_in_list),
+ gtranslator_profile_get_name (profile)))
+ profile_exists = TRUE;
+ }
+
+ if (profile_exists) {
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_ancestor (widget, GTK_TYPE_DIALOG)),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ NULL);
+
+ gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
+ _("<span weight=\"bold\" size=\"large\">The profile name already exists</span>"));
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ } else {
+ /*
+ * Add new profile to profiles list in memory
+ */
+ g_list_append (profiles_list, profile);
+ }
+
+ /*
+ *Reload the preferences dialog
+ */
+ dlg = gtranslator_application_get_preferences_dialog (GTR_APP);
+
+ treeview = gtranslator_preferences_dialog_get_treeview (dlg);
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
+ g_return_if_fail (GTK_IS_LIST_STORE (model));
+
+ gtk_widget_destroy (gtk_widget_get_ancestor (widget, GTK_TYPE_DIALOG));
+
+ gtranslator_preferences_fill_profile_treeview (dlg, model);
+}
+
+static void save_modified_profile (GtkWidget *widget,
+ GtranslatorProfile *profile)
+{
+ GtkWidget *treeview;
+ GtkTreeModel *model;
+ GtranslatorPreferencesDialog *dlg;
+
+ dlg = gtranslator_application_get_preferences_dialog (GTR_APP);
+
+ treeview = gtranslator_preferences_dialog_get_treeview (dlg);
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
+ g_return_if_fail (GTK_IS_LIST_STORE (model));
+
+ gtk_widget_destroy (gtk_widget_get_ancestor (widget, GTK_TYPE_DIALOG));
+
+ gtranslator_preferences_fill_profile_treeview (dlg, model);
+}
+
+static void destroy_without_changes (GtkWidget *widget,
+ gpointer data)
+{
+ struct data* sdata;
+
+ sdata = (struct data*) data;
+
+ gtranslator_profile_set_name (sdata->new_profile, gtranslator_profile_get_name (sdata->old_profile));
+ gtranslator_profile_set_author_name (sdata->new_profile, gtranslator_profile_get_author_name (sdata->old_profile));
+ gtranslator_profile_set_author_email (sdata->new_profile, gtranslator_profile_get_author_email (sdata->old_profile));
+ gtranslator_profile_set_language_name (sdata->new_profile, gtranslator_profile_get_language_name (sdata->old_profile));
+ gtranslator_profile_set_language_code (sdata->new_profile, gtranslator_profile_get_language_code (sdata->old_profile));
+ gtranslator_profile_set_charset (sdata->new_profile, gtranslator_profile_get_charset (sdata->old_profile));
+ gtranslator_profile_set_encoding (sdata->new_profile, gtranslator_profile_get_encoding (sdata->old_profile));
+ gtranslator_profile_set_group_email (sdata->new_profile, gtranslator_profile_get_group_email (sdata->old_profile));
+ gtranslator_profile_set_plurals (sdata->new_profile, gtranslator_profile_get_plurals (sdata->old_profile));
+
+ gtk_widget_destroy (gtk_widget_get_ancestor (widget, GTK_TYPE_DIALOG));
+}
+
static void gtranslator_profile_dialog_init (GtranslatorProfileDialog *dlg)
{
gboolean ret;
@@ -78,16 +315,6 @@
tips = g_object_new(GTK_TYPE_TOOLTIPS, NULL);
dlg->priv = GTR_PROFILE_DIALOG_GET_PRIVATE (dlg);
-
- gtk_dialog_add_buttons (GTK_DIALOG (dlg),
- GTK_STOCK_OK,
- GTK_RESPONSE_OK,
- NULL);
-
- gtk_dialog_add_buttons (GTK_DIALOG (dlg),
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL,
- NULL);
gtk_window_set_title (GTK_WINDOW (dlg), _("gtranslator Profile"));
gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE);
@@ -97,11 +324,6 @@
gtk_container_set_border_width (GTK_CONTAINER (dlg), 5);
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dlg)->vbox), 2);
- g_signal_connect (dlg,
- "response",
- G_CALLBACK (gtk_widget_destroy),
- NULL);
-
ret = gtranslator_utils_get_glade_widgets(DATADIR"/profile-dialog.glade",
"profiles_dialog",
&error_widget,
@@ -132,23 +354,39 @@
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox),
dlg->priv->main_box, FALSE, FALSE, 0);
gtk_window_set_modal (GTK_WINDOW (dlg), TRUE);
+
}
-void gtranslator_show_profile_dialog (GtranslatorPreferencesDialog *dialog)
+void gtranslator_show_profile_dialog (GtranslatorPreferencesDialog *dialog,
+ GtranslatorProfile *profile,
+ gint action)
{
-
+ struct data *data;
+ data = (struct data *) malloc(sizeof(struct data));
+
static GtkWidget *dlg = NULL;
+ GtkButton *ok_button, *cancel_button;
+ GtranslatorProfile *old_profile;
+
+ old_profile = gtranslator_profile_new ();
+
+ cancel_button = GTK_BUTTON (gtk_button_new_from_stock (GTK_STOCK_CANCEL));
+ ok_button = GTK_BUTTON (gtk_button_new_from_stock (GTK_STOCK_OK));
g_return_if_fail(GTR_IS_PREFERENCES_DIALOG(dialog));
if(dlg == NULL)
{
- dlg = GTK_WIDGET (g_object_new (GTR_TYPE_PROFILE_DIALOG, NULL));
- g_signal_connect (dlg,
- "destroy",
- G_CALLBACK (gtk_widget_destroyed),
- &dlg);
- gtk_widget_show_all(dlg);
+ dlg = GTK_WIDGET (g_object_new (GTR_TYPE_PROFILE_DIALOG, NULL));
+ g_signal_connect (dlg,
+ "destroy",
+ G_CALLBACK (gtk_widget_destroyed),
+ &dlg);
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dlg)->action_area), GTK_WIDGET (cancel_button));
+
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dlg)->action_area), GTK_WIDGET (ok_button));
+
+ gtk_widget_show_all(dlg);
}
if (GTK_WINDOW (dialog) != gtk_window_get_transient_for (GTK_WINDOW (dlg)))
@@ -156,7 +394,115 @@
gtk_window_set_transient_for (GTK_WINDOW (dlg),
GTK_WINDOW (dialog));
}
+
+ if (gtranslator_profile_get_name (profile) != NULL) {
+ gtk_entry_set_text (GTK_ENTRY (GTR_PROFILE_DIALOG (dlg)->priv->profile_name_entry),
+ gtranslator_profile_get_name (profile));
+ gtranslator_profile_set_name (old_profile, gtranslator_profile_get_name (profile));
+ }
- gtk_window_present (GTK_WINDOW (dlg));
+ if (gtranslator_profile_get_author_name (profile) != NULL) {
+ gtk_entry_set_text (GTK_ENTRY (GTR_PROFILE_DIALOG (dlg)->priv->author_name_entry),
+ gtranslator_profile_get_author_name (profile));
+ gtranslator_profile_set_author_name (old_profile, gtranslator_profile_get_author_name (profile));
+ }
+
+ if (gtranslator_profile_get_author_email (profile) != NULL) {
+ gtk_entry_set_text (GTK_ENTRY (GTR_PROFILE_DIALOG (dlg)->priv->author_email_entry),
+ gtranslator_profile_get_author_email (profile));
+ gtranslator_profile_set_author_email (old_profile, gtranslator_profile_get_author_email (profile));
+ }
+
+ if (gtranslator_profile_get_language_name (profile) != NULL) {
+ gtk_entry_set_text (GTK_ENTRY (GTR_PROFILE_DIALOG (dlg)->priv->language_name_entry),
+ gtranslator_profile_get_language_name (profile));
+ gtranslator_profile_set_language_name (old_profile, gtranslator_profile_get_language_name (profile));
+ }
+
+ if (gtranslator_profile_get_language_code (profile) != NULL) {
+ gtk_entry_set_text (GTK_ENTRY (GTR_PROFILE_DIALOG (dlg)->priv->language_code_entry),
+ gtranslator_profile_get_language_code (profile));
+ gtranslator_profile_set_language_code (old_profile, gtranslator_profile_get_language_code (profile));
+ }
+
+ if (gtranslator_profile_get_charset (profile) != NULL) {
+ gtk_entry_set_text (GTK_ENTRY (GTR_PROFILE_DIALOG (dlg)->priv->charset_entry),
+ gtranslator_profile_get_charset (profile));
+ gtranslator_profile_set_charset (old_profile, gtranslator_profile_get_charset (profile));
+ }
+
+ if (gtranslator_profile_get_encoding (profile) != NULL) {
+ gtk_entry_set_text (GTK_ENTRY (GTR_PROFILE_DIALOG (dlg)->priv->encoding_entry),
+ gtranslator_profile_get_encoding (profile));
+ gtranslator_profile_set_encoding (old_profile, gtranslator_profile_get_encoding (profile));
+ }
+
+ if (gtranslator_profile_get_group_email (profile) != NULL) {
+ gtk_entry_set_text (GTK_ENTRY (GTR_PROFILE_DIALOG (dlg)->priv->language_email_entry),
+ gtranslator_profile_get_group_email (profile));
+ gtranslator_profile_set_group_email (old_profile, gtranslator_profile_get_group_email (profile));
+ }
+
+ if (gtranslator_profile_get_plurals (profile) != NULL) {
+ gtk_entry_set_text (GTK_ENTRY (GTR_PROFILE_DIALOG (dlg)->priv->plurals_forms_entry),
+ gtranslator_profile_get_plurals (profile));
+ gtranslator_profile_set_plurals (old_profile, gtranslator_profile_get_plurals (profile));
+}
+
+ data->old_profile = old_profile;
+ data->new_profile = profile;
+
+ /* Connect entry signals */
+ g_signal_connect (GTR_PROFILE_DIALOG (dlg)->priv->profile_name_entry, "notify::text",
+ G_CALLBACK (profile_name_entry_changed),
+ profile);
+ g_signal_connect (GTR_PROFILE_DIALOG (dlg)->priv->author_name_entry, "notify::text",
+ G_CALLBACK (author_name_entry_changed),
+ profile);
+ g_signal_connect (GTR_PROFILE_DIALOG (dlg)->priv->author_email_entry, "notify::text",
+ G_CALLBACK (author_email_entry_changed),
+ profile);
+ g_signal_connect (GTR_PROFILE_DIALOG (dlg)->priv->language_name_entry, "notify::text",
+ G_CALLBACK (language_name_entry_changed),
+ profile);
+ g_signal_connect (GTR_PROFILE_DIALOG (dlg)->priv->language_code_entry, "notify::text",
+ G_CALLBACK (language_code_entry_changed),
+ profile);
+ g_signal_connect (GTR_PROFILE_DIALOG (dlg)->priv->charset_entry, "notify::text",
+ G_CALLBACK (charset_entry_changed),
+ profile);
+ g_signal_connect (GTR_PROFILE_DIALOG (dlg)->priv->encoding_entry, "notify::text",
+ G_CALLBACK (encoding_entry_changed),
+ profile);
+ g_signal_connect (GTR_PROFILE_DIALOG (dlg)->priv->language_email_entry, "notify::text",
+ G_CALLBACK (group_email_entry_changed),
+ profile);
+ g_signal_connect (GTR_PROFILE_DIALOG (dlg)->priv->plurals_forms_entry, "notify::text",
+ G_CALLBACK (plurals_entry_changed),
+ profile);
+
+ /*
+ * Connect signals to dialog buttons.
+ */
+
+ g_signal_connect (cancel_button,
+ "clicked",
+ G_CALLBACK (destroy_without_changes),
+ data);
+
+ if (action == NEW_PROFILE) {
+ g_signal_connect (ok_button,
+ "clicked",
+ G_CALLBACK (save_new_profile),
+ profile);
+ } else {
+ if (action == EDIT_PROFILE) {
+ g_signal_connect (ok_button,
+ "clicked",
+ G_CALLBACK (save_modified_profile),
+ profile);
+ }
+ }
+
}
Modified: trunk/src/dialogs/profile-dialog.h
==============================================================================
--- trunk/src/dialogs/profile-dialog.h (original)
+++ trunk/src/dialogs/profile-dialog.h Mon Sep 22 09:38:31 2008
@@ -23,9 +23,15 @@
#include <glib-object.h>
#include <gtk/gtk.h>
+#include "profile.h"
#include "window.h"
#include "preferences-dialog.h"
+enum {
+ NEW_PROFILE,
+ EDIT_PROFILE
+ };
+
/*
* Type checking and casting macros
*/
@@ -69,6 +75,8 @@
GType gtranslator_profile_dialog_register_type (GTypeModule * module);
-void gtranslator_show_profile_dialog (GtranslatorPreferencesDialog *dialog);
+void gtranslator_show_profile_dialog (GtranslatorPreferencesDialog *dialog,
+ GtranslatorProfile *profile,
+ gint action);
#endif
Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c (original)
+++ trunk/src/main.c Mon Sep 22 09:38:31 2008
@@ -95,7 +95,11 @@
GtranslatorWindow *window;
GSList *file_list = NULL;
GOptionContext *context;
-
+ gchar *filename;
+ gchar *config_folder;
+ GList *profiles_list = NULL;
+ GFile *file;
+
/*
* Initialize gettext.
*/
@@ -158,6 +162,21 @@
gtk_about_dialog_set_url_hook (gtranslator_utils_activate_url, NULL, NULL);
+ /*
+ * Load profiles list
+ */
+ config_folder = gtranslator_utils_get_user_config_dir ();
+ filename = g_build_filename (config_folder,
+ "profiles.xml",
+ NULL);
+ file = g_file_new_for_path (filename);
+
+ if (g_file_query_exists (file, NULL)) {
+ profiles_list = gtranslator_profile_get_profiles_from_xml_file (filename);
+ }
+
+ gtranslator_application_set_profiles (GTR_APP, profiles_list);
+
/*
* Create the main app-window.
*/
Modified: trunk/src/profile.c
==============================================================================
--- trunk/src/profile.c (original)
+++ trunk/src/profile.c Mon Sep 22 09:38:31 2008
@@ -15,7 +15,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
+
+#include "application.h"
#include "profile.h"
#include "preferences-dialog.h"
#include "utils.h"
@@ -304,13 +305,19 @@
{
GList *profiles_list = NULL;
GtranslatorProfile *profile;
- xmlNodePtr root, child;
+ xmlNodePtr root, child, active;
xmlDocPtr doc;
+ gchar *active_profile;
+ GList *l;
doc = gtranslator_xml_open_file (filename);
root = xmlDocGetRootElement (doc);
child = root->xmlChildrenNode;
+ active = child->xmlChildrenNode;
+
+ active_profile = xmlNodeGetContent (active);
+ child = child->next;
while (child != NULL) {
profile = gtranslator_profile_xml_get_entry (child);
@@ -318,5 +325,39 @@
child = child->next;
}
+ for (l = profiles_list; l; l = l->next) {
+ GtranslatorProfile *profile;
+ profile = (GtranslatorProfile *)l->data;
+ if (!strcmp(gtranslator_profile_get_name (profile), active_profile))
+ gtranslator_application_set_active_profile (GTR_APP, profile);
+ }
+
return profiles_list;
}
+
+void gtranslator_profile_save_profiles_in_xml (gchar *filename) {
+
+ xmlNodePtr root, child, active;
+ xmlDocPtr doc;
+ GList *profiles_list, *l;
+ GtranslatorProfile *active_profile;
+
+ doc = gtranslator_xml_new_doc ("list_of_profiles");
+
+ profiles_list = gtranslator_application_get_profiles (GTR_APP);
+ active_profile = gtranslator_application_get_active_profile (GTR_APP);
+
+ root = xmlDocGetRootElement (doc);
+ child = root->xmlChildrenNode;
+ active = child->xmlChildrenNode;
+
+ xmlNewChild (root, NULL, "active", gtranslator_profile_get_name (active_profile));
+
+ for (l = profiles_list; l; l = l->next) {
+ GtranslatorProfile *profile;
+ profile = (GtranslatorProfile *)l->data;
+ gtranslator_profile_xml_new_entry (doc, profile);
+ }
+
+ xmlSaveFile (filename, doc);
+}
Modified: trunk/src/profile.h
==============================================================================
--- trunk/src/profile.h (original)
+++ trunk/src/profile.h Mon Sep 22 09:38:31 2008
@@ -102,4 +102,6 @@
GList *gtranslator_profile_get_profiles_from_xml_file (gchar *filename);
+void gtranslator_profile_save_profiles_in_xml (gchar *filename);
+
#endif /* __PROFILE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]